Read a TTree from a root file

Hello ROOT experts,
I am trying to read a tree “reco” from a file.root.
I am using the script beneath:

#include "TFile.h
#include "TH1F.h
#include "TTreeReader.h
#include "TTreeReaderValue.h

TH1F *h1 = new TH1F(“h1”, “h1 title”, 1000, -100, 100);

TFile *myFile = TFile::Open("$ROOTSYS/macros/crazy.10.root");
TTreeReader reader(“reco”, &myfile);

TTreeReaderValue<Float_t> llratio(reader, “llratio”);
TTreeReaderValue<Float_t> llratioE(reader, “llratioE”);
TTreeReaderValue<Float_t> enew(reader, “enew”);

TH1F *hpx = new TH1F(“hpx”,“px distribution”,100,-3,3);

TH2F *hpxpy = new TH2F(“hpxpy”,“py vs px”,30,-3,3,30,-3,3);

while (reader.Next()) {
h1->Fill(*enew + *llratio);



But root isn’t drawing the histogram. What am I doing wrong? :\


I assume this is a macro and not a program you compiled.
Most likely the issue is that the histogram is being drawn but immediately deleted after leaving the scope. You can draw a clone of the histogram (DrawClone()) in order to have the painted entity survive the scope.


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