Hello ROOTers,
NB: I’ve looked extensively through the forums for this topic and while there are many answers that hint at what I need to accomplish, there are still gaps. Please be gentle.
I have a TTree with branches “tof” (time of flight) and “energy”. I’d like to set up a nested for loop or some other script that iterates through varying energy ranges, makes a histogram of the tof data, does some analysis on the tof TH1F, and goes to the next energy range iteration.
void test_macro(string filename)
{
//open files to compare
TFile *_file0 = TFile::Open(filename.c_str());
// use nested for loop to iterate over energy ranges where i
// is the lower bound and j the upper
for (double i = 0.; i < 1000.; i = i + 200.) {
for (double j = 0.; j < 1000.; j = j + 200.) {
if (j > i) {
TTree *tree=(TTree*)_file0->GetObjectChecked("tree","TTree");
TH1D *NoTgt_tof=new TH1D("NoTgt_tof","EJ-315 ToF Gammas",200,8,200);
TCanvas *c=new TCanvas();
c->cd(1);
tree->Draw("tof>>NoTgt_tof", "energy > i && energy < j ","");
// do analysis on the tof histogram
}
}
}
}
Some things that I’ve tried without success:
tree->Draw("tof>>NoTgt_tof", Form("Energy > %d",i),"");
This would work except that I need two iterators (eventually I’ll need four!) and I can’t get the Form( workaround to work with both i and j.
I’ve also tried:
TCut cut1 = Form("Energy > %d",i);
TCut cut2 = Form("Energy < %d",j);
tree->Draw("tof>>NoTgt_tof", cut1 && cut2,"");
This also doesn’t work because the i and j in the TCut never iterate.
I understand I can’t pass a local variable to the Draw() method, but I truly don’t need to draw the histograms to do the required analysis. So if I could either append the iterators to the TTree every loop, or if there were some analysis method that allowed me to conditionally fill a TH1F where I pass it local variables – that’d be swell.
Thanks for your help everyone.
_
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.26/02
Platform: Windows
Compiler: VS