Facing error while plotting histograms


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: 6.30.04
Platform: Not Provided
Compiler: Not Provided


Hi,
I have a root file from which i have created a rdataframe. I wanted to have jet transverse momentum histograms plot. So for this, i defined a new column and assigned it required values. But while running the file, it is giving errors.
Following is some snapshot of my root file.


Also i have the following code.

void file()
{
using namespace ROOT;
ROOT::RDataFrame df(“events”, “events_029930132.root”);

auto rdf = df.Define(“pt”, “sqrt((Jet.momentum.x)(Jet.momentum.x) + (Jet.momentum.y)(Jet.momentum.y))”);

auto h1 = rdf.Histo1D(“Jet.energy”);
auto h2 = rdf.Histo1D(“Jet.mass”);
auto h3 = rdf.Histo1D(“pt”);

h1->GetXaxis()->SetTitle(“Jet energy”);
h2->GetXaxis()->SetTitle(“Jet mass”);
h3->GetXaxis()->SetTitle(“Jet transverse momentum”);

h1->Draw();
h2->Draw();
h3->Draw();

}

The output is giving me a blank canvas.
How this can be resolved?

Use DrawCopy so they don’t die once the macro ends, and draw them in a canvas (either one for each histo, or all in one with the option “same” or dividing the canvas or using a THStack); for separate canvases, e.g.:

  auto c1 = new TCanvas("c1");
  //c1->Draw();
  //c1->cd();
  h1->DrawCopy();
  auto c2 = new TCanvas("c2");
  //c2->Draw();
  //c2->cd();
  h2->DrawCopy();
  auto c3 = new TCanvas("c3");
  //c3->Draw();
  //c3->cd();
  h3->DrawCopy();

Thanks a lot @dastudillo . It worked.