How are multiple TTree->Draw()s done?

When I compile (.L MyTree.C++) and run this code:

   void MyTree::Plots(){
       TCanvas* c1 = new TCanvas("A","A");
       fChain->Draw("A");
       TCanvas* c2 = new TCanvas("B","B");
       c2->Divide(4,1);      
       c2->cd(1);fChain->Draw("b[0]);
       c2->cd(2);fChain->Draw("b[1]);
       c2->cd(3);fChain->Draw("b[2]);
       c2->cd(4);fChain->Draw("b[3]);
       TCanvas* c3 = new TCanvas("C","C");
       fChain->Draw("C");
   }

the first thing that happens is that the canvas are created. Now I wonder how Draw() works behind the scenes. Is the tree/chain passed through for each call to TTree::Draw()? If yes, what is the best way to pass through the tree only once (without changing the code too much)?

Hello,

Yes

The best would be to write a TSelector and do fill the histograms you need inside in one pass.
Otherwise you can try to reduce to two Draw calls by filling 2d and 3d histos with your variables and taking the relevant 1d projections.

G Ganis

Thanks a lot for your answer.
I did not ignore it, I just did not have time yet to take a closer look. I would like to try what can be done with a TSelector before marking this post as “solved”.