Plot histogram from TREE

Hi everyone,

I am trying to plot a histogram from a root file. This root file contains four tree,0,1,2,3 and each tree has many branches such as px,py,pz etc. The code I used to plot the px is shown below:

{
gROOT->LoadMacro(“AtlasStyle.C”);
gROOT->LoadMacro(“AtlasUtils.C”);

SetAtlasStyle();

TFile *myFile = new TFile(“test.root”);
TTree Tree0 = (TTree)myFile->Get(“Tree0”);
Float_t px;
Tree0->SetBranchAddress(“px”,&px);
TH1F *hpx = new TH1F(“px”,“px”,100,-100,12500);

Int_t nentries = (Int_t)Tree0->GetEntries();
for (Int_t i=0; i<nentries; i++){
Tree0->GetEntry(i);
hpx->Fill(px);
}

TCanvas c1;
c1.SetGridx();
c1.SetGridy();

Tree0->Draw();
if (gROOT->IsBatch()) return;

}

Although there is no error when I run root px.C, no plot is shown. I wonder whether there are any mistakes?

Thanks

Try

or

[quote=“pamputt”]Try

or

Thanks, it does not work for first suggestion but works for the second one. Cheers!

[quote=“pamputt”]Try

or

Hi, I have also try to draw two branches px and py into a histogram, and it works. But now I would like to sum px and py to get average plot, do you have any idea how to do it?

Hi,

Do you meanTree0->Draw("(px+py)>>hpx(100,-100,12500)");?

Philippe.