tree->Draw does not work

Dear experts,
I want to use “tree->Draw(“var>>hist”);” then draw the hist in a canvas. I have the code (1) and the root file (2) to be add ate line 13. I have a default canvas which appears, but nothing on the canvas that I asked line 104, 108 and 116. Do you see what is wrong?
Regards

(1)
http://calpas.web.cern.ch/calpas/plot.cc

(2)
http://calpas.web.cern.ch/calpas/sumWeightsFromTree.root

The “hist” in the “tree->Draw(“var>>hist”);” MUST be the NAME of the histogram.

Dear Coyote,
I used the name and it’s still does not work: http://calpas.web.cern.ch/calpas/plot.cc
Regards

Before the first usage of “>>”, try to add “gROOT->cd();” (that’s where you created your histograms).

I start to have something but it’s not the distribution. Looks like only the 1st bin is fill…
Regards

hist[var] = new TH1F(name.c_str(), name.c_str(), 100, 0, 0); // automatic binning

Dear Coyote,
it works fine with the “automatic binning”. Do you know how to switch off the default canvas?
Regards

tree->Project(“hist”, “var”);

Dear Coyote,

  • it works fine. Thank you.
  • To compare the hist of 2 root files, as you can see at line 56 of (1) I loop over the root file, and I use the Draw(“same”) at line 102 for example, but it does not work, I have only on hist which is draw. Am I doing something wrong?
    Regards

(1)
http://calpas.web.cern.ch/calpas/plot.cc

Dear Coyotte,
the input hist seems to match so there should be one hidden by the other…
Thank you for your help.
Regards

Dear experts,
when I use my code (1) to plot the “lep_E_0” variable for example, it plots only the last once. As you can see if you check the root file (2), these variable are different, so the “same” in the Draw function does not work. Do you see what is wrong?
Regards

(1)
http://calpas.web.cern.ch/calpas/plot.cc

(2)
http://calpas.web.cern.ch/calpas/r21_first_production_00310872
http://calpas.web.cern.ch/calpas/v29_gfw2_2017-06-22_00310872.root

Remove gROOT->cd(); and move:

  TH1F *hist[nvar];
  for(int var=0; var<vhname.size(); var++){
    hist[var] = new TH1F(vhname[var].c_str(), vhname[var].c_str(), 100, 0, 0);
    //cout<<"histname: "<<hist[var]->GetName()<<endl;
    hist[var]->SetStats(0);
  }

to a place right before TTree *tree = (TTree*)file->Get("nominal");.

Dear Coyote.
thank you it fixed the issue.
Regards

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