I think i got it running…
But I don’t know what was the problem…
I just commented out all the command that had to do with SetBranchAddress…
At the moment I don’t know how to apply a certain selection, in the variable detn let’s say… I want only the enties that have detn == 6, for instance but I can’t seem to be able to do it…
If I use an if(*detnFIGM==6) statement right after trFIMG.Next(), I get no entries.
If I use a second condition in the BunchNumber while loop (&& *detnFIMG == 6), I still get 0 entries.
And if I use an if statement, right after the while loop (in the BunchNumber) it is running forever…
Any idea on that, because I very puzzled on how the TTReader and .Next() is working… My code is the following
[code]#include “header_c.h”
#include “header_root.h”
#include “TTreeReader.h”
#include “TTreeReaderValue.h”
#include “header_global_variables.h”
#include “header_functions.h”
/*************************
- Load .L Deltat.C++
- Run Delta(runNumber)
*************************/
/** To use ROOT6 run these commands and then execute the macro using root -b -q extrema_root_forum.C
source /afs/cern.ch/sw/lcg/external/gcc/4.8/x86_64-slc6/setup.csh
source /afs/cern.ch/sw/lcg/app/releases/ROOT/6.02.02/x86_64-slc6-gcc48-opt/root/bin/thisroot.csh
*/
int PvsF(int run){
// (1) Define isolethargic Binning
int min = 0;// 1e0 ns
int max = 8;// 1e7 ns
int bpd = 100; // bins per decade
int ndec = max - min;// number of decades
int nbins = (int) ndec*bpd;// number of bins
double step = (double) ndec / nbins;
double tbins[nbins+1];
for(int i=0; i <= nbins; i++) {
tbins[i] = (float) pow(10., step * (double) i + min);
}
// (2) Define histograms
//FIMG
//TH1F *htflash2 = new TH1F(“htflash1”,“Tflash Det. #2 - 238U ; Time (ns); Counts”,nbins, tbins);
//TH1F *htflash3 = new TH1F(“htflash2”,“Tflash Det. #3 - 240Pu ; Time (ns); Counts”,nbins, tbins);
//TH1F *htflash4 = new TH1F(“htflash3”,“Tflash Det. #4 - 240Pu ; Time (ns); Counts”,nbins, tbins);
//TH1F *htflash5 = new TH1F(“htflash4”,“Tflash Det. #5 - 240Pu ; Time (ns); Counts”,nbins, tbins);
//TH1F *htflash6 = new TH1F(“htflash5”,“Tflash Det. #6 - 235U ; Time (ns); Counts”,nbins, tbins);
//PKUP
//TH1F *htflashPKUP = new TH1F(“htflashPKUP”,“Tflash - PKUP ; Time (ns); Counts”,nbins, tbins);
TH1F *htflashPKUP = new TH1F(“htflashPKUP”,“Tflash - PKUP ; Time (ns); Counts”, 1.6e7, 0, 1.6e7);
// PKUP vs FIMG
TH2F *htflashPKUPvsFIMG2 = new TH2F(“htflashPKUPvsFIMG2”,“PKUP vs. tflash 238U; time (ns); time (ns);”,nbins, tbins, nbins, tbins);
TH2F *htflashPKUPvsFIMG3 = new TH2F(“htflashPKUPvsFIMG3”,“PKUP vs. tflash 240Pu; time (ns); time (ns);”,nbins, tbins, nbins, tbins);
TH2F *htflashPKUPvsFIMG4 = new TH2F(“htflashPKUPvsFIMG4”,“PKUP vs. tflash 240Pu; time (ns); time (ns);”,nbins, tbins, nbins, tbins);
TH2F *htflashPKUPvsFIMG5 = new TH2F(“htflashPKUPvsFIMG5”,“PKUP vs. tflash 240Pu; time (ns); time (ns);”,nbins, tbins, nbins, tbins);
TH2F *htflashPKUPvsFIMG6 = new TH2F(“htflashPKUPvsFIMG6”,“PKUP vs. tflash 235U; time (ns); time (ns);”,nbins, tbins, nbins, tbins);
//TFile *foo = TFile::Open(TString::Format(“run_%d_in.root”, run));
TFile *foo = TFile::Open(TString::Format(“run%d.root”, run));
//TTree TFIMG = (TTree)foo->Get(“FIMG”); TTree TPKUP = (TTree)foo->Get(“PKUP”);
//int entriesFIMG = TFIMG->GetEntries(); int entriesPKUP = TPKUP->GetEntries();
//TFIMG->SetBranchStatus("",0); TPKUP->SetBranchStatus("",0);
// variables for reading the TTrees
//double tflash;
//int BunchNumber;//, detn;
// variables for the analysis
//double tflashFIMG, tflashPKUP;
//double tflash2, tflash3, tflash4, tflash5, tflash6;
// FIMG
//TFIMG->SetBranchStatus(“tflash”,1); TFIMG->SetBranchAddress(“tflash”,&tflashFIMG);
//TFIMG->SetBranchStatus(“BunchNumber”,1); TFIMG->SetBranchAddress(“BunchNumberFIMG”,&BunchNumber);
// PKUP
//TPKUP->SetBranchStatus(“tflash”,1); TPKUP->SetBranchAddress(“tflash”,&tflashPKUP);
//TPKUP->SetBranchStatus(“BunchNumber”,1); TPKUP->SetBranchAddress(“BunchNumberPKUP”,&BunchNumber);
// Usefull variables
//int BunchNumber_old;
//*** TEST with TTreeReader ***
TTreeReader trFIMG(“FIMG”);
TTreeReaderValue BunchNumberFIMG(trFIMG, “BunchNumber”);
TTreeReaderValue detnFIMG(trFIMG, “detn”);
TTreeReaderValue tFlashFIMG(trFIMG, “tflash”);
TTreeReader trPKUP(“PKUP”);
TTreeReaderValue BunchNumberPKUP(trPKUP, “BunchNumber”);
TTreeReaderValue tFlashPKUP(trPKUP, “tflash”);
trFIMG.Next(); // “Load” the first entry
cout << *detnFIMG << " " ;
//if (*detnFIMG==6){
while (trPKUP.Next()) { // loop over all entries
//cout << "detn = " << *detnFIMG << endl;
while (*BunchNumberPKUP == *BunchNumberFIMG) {//&& *detnFIMG == 6
//if(*detnFIMG == 6){
//std::cout << *BunchNumberPKUP << " " << *tFlashPKUP << " " << *tFlashFIMG << " " << *detnFIMG << std::endl;
htflashPKUPvsFIMG6->Fill(*tFlashPKUP, *tFlashFIMG);
if (!(trFIMG.Next())) break; // “load” the next entry
//}
}
}
//}
//delete foo;
//htflashPKUP->Draw(“histo”);
htflashPKUPvsFIMG6->Draw(“colz”);
// *** END of TEST with TTreeReader
return 0;
}[/code]