This question is somehow related to my last one. I have a really big tree and I realized that all my histograms that I have always created in a very nice looking way via TTree::Draw() have to loop over all the data to be created. So creating several histograms produces several loops.
I suppose there is no way, to “load” a command and to run the loop only once? Somthing like this:
TTree::LoadDraw(“myvalue_x >> myhist1(100,0,1)”, “mycut”); // set one draw command
TTree::LoadDraw(“myvalue_y >> myhist2(100,0,1)”, “mycut”); // set the next one
TTree::LoadDraw(“myvalue_z >> myhist3(100,0,1)”, “mycut”);
TTree:DrawLoaded(); // perform all the operations before in only one loop
TH1* myhist1 = (TH1*)gDirectory->Get(“myhist1”);
TH1* myhist2 = (TH1*)gDirectory->Get(“myhist2”);
TH1* myhist3 = (TH1*)gDirectory->Get(“myhist3”);
I guess this would lead to consistency problems with simultanious drawing to Pads as well as the program structure itself -> I have to change my code to a loop of my own
for (int i = 0; i < tree->GetEntries(); i++){
tree->GetEntry(i);
if (mycut){
hist1->Fill(myvalue_x);
}
if (mycut){
hist2->Fill(myvalue_y);
}
//etc.
}
void multihist_Terminate() {
// Display the histograms, in this example, all on the same pad.
myhist1->Draw();
myhist2->Draw(“SAME”);
myhist3->Draw(“SAME”);
}[/code]and use:tree->Draw("multihist.C","","nohist");
The ‘nohist’ is to suppress the creation of the default histogram which would contains the return value of the function multihist().
Alternatively you could use a TEntryList:mytree->Draw(">>cutlist","mycut","entrylist");
TEntryList *cutlist = (TEntryList*)gDirectory->Get("mycut");
mytree->SetEntryList(cutlist);
mytree->Draw("myvalue_x >> myhist1(100,0,1)", "");
mytree->Draw("myvalue_y >> myhist2(100,0,1)", "");
mytree->Draw("myvalue_z >> myhist3(100,0,1)", "");