Retrive the information from TBranch

Dears,

I have a root file with many TTree, which has many TBranch. I have to extract the y value from one of the TBranch. So what I did is draw the Branch as:
my_tree->Draw(“my_branch”);
then I have assigned the temporary histogram to an histogram, as:
TH1Dhtemp= (TH1D) gPad->GetPrimitive(“htemp”);
I drawn also this histogram:
htemp->Draw();
and at the and I want to extract the y value from the only one bin that the histogram has, doing:
Double_t y_val= htemp->GetBinContent(1);

But it doesn’t work. Until the 3rd passage it works, because I tried to save the htemp into a root file and it works.
Someone can help me? In attached there is the root file containing the htemp. htemp.root (5.5 KB)

Thanks a lot in advance!! :slight_smile:

{ TFile *f = TFile::Open("htemp.root"); if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution f->ls(); TH1F *h; f->GetObject("htemp", h); // it's TH1F and not TH1D if (!h) { delete f; return; } // just a precaution h->Print("all"); std::cout << h->GetBinContent( 1 ) << std::endl; std::cout << h->GetBinContent( h->FindFixBin(1.0) ) << std::endl; }

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