Read a root file

Please how can I read a root file containing a folder called ntupleProducer. This ntupleProducer contains two trees: tree;1 and tree2; ?
I used the code attached to read this root file but it does not work (I used different methods!). When I use the second method, I get this message: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
tree->Draw(“genParticlePx>>hist1”, cut1);

tree_example2.C (2.3 KB)

The root file is available here:

For me, after removing the line hist1->Draw("colz");, it works well, I get this plot.pdf:


1 Like

Basically your macro is:

void tree_example2() {
   auto f    = new TFile("ntuple_array.root");
   auto tree = (TTree*)f->Get("ntupleProducer/tree;1");
   auto c    = new TCanvas();

   TCut cut1 = "genParticleCharge != 0";

   auto hist1 = new TH1F("hist1", "hist1", 100, -200., 200.);
   tree->Draw("genParticlePx >> hist1",cut1,"goff");



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