void CalibrateSpectrum(TString filename,double A[256][256],double B[256][256],double C[256][256],double T[256][256],TH1D *histo,double offset=0){

	TFile * file = TFile::Open(filename,"open");

	TTreeReader myReader("pixels", file);

	TTreeReaderValue<Int_t> col(myReader, "col");
	TTreeReaderValue<Int_t> row(myReader, "row");
	TTreeReaderValue<Int_t> tot(myReader, "tot");


	int cnt = 0 ;
	while (myReader.Next()) {
		cnt++;

		if (cnt%1000==0) cout << "Event " << cnt << endl;
		//if (cnt==1000000) break;

		if(A[*col][*row]!=0){
			histo->Fill(TOTtoE(*tot-offset,A[*col][*row],B[*col][*row],C[*col][*row],T[*col][*row]));
		}
		else {
			histo->Fill(TOTtoE(*tot-offset,29.8,534.1,1817,0.7));

		}
	}
}
Example #2
0
void hsimpleReader() {
   // Create a histogram for the values we read.
   TH1F *myHist = new TH1F("h1","ntuple",100,-4,4);

   // Open the file containing the tree.
   TFile *myFile = TFile::Open("$ROOTSYS/tutorials/hsimple.root");
   if (!myFile || myFile->IsZombie()) {
      gROOT->ProcessLine(".x $ROOTSYS/tutorials/hsimple.C");
      myFile = TFile::Open("$ROOTSYS/tutorials/hsimple.root");
      if (!myFile || myFile->IsZombie()) {
         return;
      }
   }
   // Create a TTreeReader for the tree, for instance by passing the
   // TTree's name and the TDirectory / TFile it is in.
   TTreeReader myReader("ntuple", myFile);

   // The branch "px" contains floats; access them as myPx.
   TTreeReaderValue<Float_t> myPx(myReader, "px");
   // The branch "py" contains floats, too; access those as myPy.
   TTreeReaderValue<Float_t> myPy(myReader, "py");

   // Loop over all entries of the TTree or TChain.
   while (myReader.Next()) {
      // Just access the data as if myPx and myPy were iterators (note the '*'
      // in front of them):
      myHist->Fill(*myPx + *myPy);
   }

   myHist->Draw();
}
int main(int argc, const char * argv[]) {
    
    std::ofstream fs("testObj.txt");
    fs << "//Objective function values and constraints violations\n";
    fs << "2		/number of objectives (Jeff, feel free to skip this line if no_obj is input elsewhere)\n";
    fs << "1.111 	/objective 1 value\n";
    fs << "2.222 	/objective 2 value\n";
    fs << "7		/number of constraints (Jeff, feel free to skip this line if no_cons is input elsewhere)\n";
    fs << "1.0		/cons - value returned for constrained MUSIC outputs\n";
    fs << "1.0          \n";
    fs << "1.0\n";
    fs << "1.0\n";
    fs << "0.0\n";
    fs << "0.0\n";
    fs << "0.0\n";
    fs << "0.0\n";
    fs << "0.0		/ overallcons - threshold for constrained MUSIC outputs - constraint met if = 0.0, constraint violated if > 0.0\n";
    fs << "0.0\n";
    fs << "0.0\n";
    fs << "0.0\n";
    fs << "0.0\n";
    fs << "0.0\n";
    fs << "0.0\n";
    fs.close();
    
    Ascii2ObjectiveValues<double, double> myReader("testObj.txt", true, true);
    std::shared_ptr<ObjectivesAndConstraints<double, double> > obj_and_cnstr = myReader();
    
    if (obj_and_cnstr->objectives[0] == 1.111
        && obj_and_cnstr->objectives[1] == 2.222
        && obj_and_cnstr->constraints[0] == 1.0
        && obj_and_cnstr->constraints[1] == 1.0
        && obj_and_cnstr->constraints[2] == 1.0
        && obj_and_cnstr->constraints[3] == 1.0
        && obj_and_cnstr->constraints[4] == 0.0
        && obj_and_cnstr->constraints[5] == 0.0
        && obj_and_cnstr->constraints[6] == 0.0)
    {
        return EXIT_SUCCESS;
    }
    
    return EXIT_FAILURE;
}
Example #4
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //------------------------------------------------

    QDir homeDir = QDir::homePath();

    if(!homeDir.exists(".justdoit"))
    {
        homeDir.mkdir(".justdoit");
    }

    QDir savePath = homeDir.absolutePath() + "/.justdoit";

    TaskXmlReader myReader(savePath.absolutePath() + "/tasks.xml");

    UserData *myUd = 0;

    if(savePath.exists("tasks.xml"))
    {
        myReader.readDocument();
        myUd = myReader.uData();
    }
    else
    {
        myUd = new UserData(QProcessEnvironment::systemEnvironment().value("USER"));
    }

    //------------------------------------------------

    MainWindow w;

    QSettings settings("JustDoIt", "JustDoIt");

    settings.beginGroup("MainWindow");
    bool startVisible = settings.value("isVisibleOnStart").toBool();
    settings.endGroup();

//    QxtGlobalShortcut* shortcut = new QxtGlobalShortcut(&w);
//    QObject::connect(shortcut, SIGNAL(activated()), &w, SLOT(toggleVisibility()));
//    shortcut->setShortcut(QKeySequence("Ctrl+Shift+F11"));

    w.setUsrData(myUd);
    w.setSaveFileName(savePath.absolutePath() + "/tasks.xml");

    if(startVisible)
    {
        w.show();
    }

    return a.exec();
}
void CalibrateSpectrumGlobal(TString filename,double A,double B,double C,double T,TH1D *histo,double offset=0){


	TFile * file = TFile::Open(filename,"open");

	TTreeReader myReader("pixels", file);

	TTreeReaderValue<Int_t> col(myReader, "col");
	TTreeReaderValue<Int_t> row(myReader, "row");
	TTreeReaderValue<Int_t> tot(myReader, "tot");


	int cnt = 0 ;
	while (myReader.Next()) {
		cnt++;
		if (cnt%1000==0) cout << "Event " << cnt << endl;
		//if (cnt==1000000) break;

		histo->Fill(TOTtoE(*tot-offset,A,B,C,T));

	}
}
Example #6
0
int assertIntroTut()
{
   // open the file
   TFile *f = TFile::Open("http://lcg-heppkg.web.cern.ch/lcg-heppkg/ROOT/eventdata.root");
   if (f == 0) {
      // if we cannot open the file, print an error message and return immediatly
      printf("Error: cannot open http://lcg-heppkg.web.cern.ch/lcg-heppkg/ROOT/eventdata.root!\n");
      return 1;
   }

   // Create tyhe tree reader and its data containers
   TTreeReader myReader("EventTree", f);
   // The branch "fPosX" contains doubles; access them as particlesPosX.
   TTreeReaderArray<Double_t> particlesPosX(myReader, "fParticles.fPosX");
   // The branch "fMomentum" contains doubles, too; access those as particlesMomentum.
   TTreeReaderArray<Double_t> particlesMomentum(myReader, "fParticles.fMomentum");

   // create the TH1F histogram
   TH1F *hPosX = new TH1F("hPosX", "Position in X", 20, -5, 5);
   // enable bin errors:
   hPosX->Sumw2();

   // Loop over all entries of the TTree or TChain.
   while (myReader.Next()) {
      // Do the analysis...
      for (int iParticle = 0; iParticle < particlesPosX.GetSize(); ++iParticle) {
         if (particlesMomentum[iParticle] > 40.0)
            hPosX->Fill(particlesPosX[iParticle]);
      }
      // For testing purposes, re-run with begin / end (ROOT-7362)
      for (auto i = particlesPosX.begin(), e = particlesPosX.end(); i != e; ++i) {
         if (*i > 40.0)
            hPosX->Fill(*i);
      }
      // For testing purposes, re-run with range-for
      for (double i: particlesPosX) {
         if (i > 40.0)
            hPosX->Fill(i);
      }
   }

   // Fit the histogram:
   hPosX->Fit("pol2");
   // and draw it:
   hPosX->Draw();


   // This would enable the loop below:
   // myReader.Restart();
   TTreeReaderValue<Int_t> eventSize(myReader, "fEventSize"); // should warn
   // Variables used to store the data
   Int_t totalSize = 0; // Sum of data size (in bytes) of all events
   // Loop over all entries of the TTree or TChain.
   while (myReader.Next()) {
      // Get the data from the current TTree entry by getting
      // the value from the connected reader (eventSize):
      totalSize += *eventSize;
      printf("This loop should not be entered!\n");
      return 2;
   }

   return 0;
}