How to draw branch from Tree/TChain onto histogram array

Continuing the discussion from Tree->Draw("var>>hist"):

_ROOT Version:5.34.36
Platform: Not Provided
Compiler: Not Provided

Dear ROOT,
I declare many histograms in a loop, e.g.

for(Int_t j=0; j<20; j++){
    hists[j] = new TH1F(Form("hist_%d",j),Form("hist_%d",j),200,0.,3.0);

and I am trying to draw a branch stored in a TChain

TChain *ch = new TChain("tree1");

onto each of these histograms in a loop:

for (Int_t nx=0;nx<binx;nx++){
       for (Int_t ny=0;ny<biny;ny++){
          // ch->Draw("missingmass>>hists[biny*nx+ny]",CUTS); //doesnt work
             ch->Draw(Form("missingmass>>%s",hists[biny*nx+ny]->GetName()),CUTS); //doesnt work

Is there some other way to cast the string into the "missing_mass >> hist " or do I have to “SetBranchAddress” on each of the variables on the TChain and proceed with filling the histograms via hists[j]->Fill(missingmass) way? (I have way more branches to define and set cuts on…so I wanted to see if there was an easier way…such as this that can work/is shorter).



I think that you identified one among the best ways of achieving the result you are interested in using TTree::Draw.
If you wish something more sophisticated, you can try out RDataFrame.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.