How to get the nbins from one branch?

I am trying to Project one branch to a histogram. And also need to set nbins for histogram.
Is there any easy way to get nbins when I just know the branch name? I tried the T->GetEntry()
, but it’s too slow.

Ex:
Branch: B.dc.u1.wire
Histogram: htemp=new TH1F(“bla”, nbins, 0, nbins);

Thanks in advance.

Could you explain precisely what you want?
When using TTree::Draw you can specify the number of bins and limits of the output histogram, eg

tree.Draw("myvar>>h(50,-2,3)"); see doc of TTree::Draw for more details
root.cern.ch/root/html/TTreePlay … DrawSelect

Rene

  1. First, I just know the Branch Name and of course the root file.
    Ex: B.dc.u1.wire ( 0<=x<=144 )

  2. Then I will create a histogram, let’s say
    TH1F* htemp=TH1F(“name”, nbins,0, nbins);
    Here, nbins is unkown. I try to get this number from the known Branch. Finally, let x_max=144,
    x_min=0.
    In other words, try to set nbins dynamically depending on the different Branch.

Hi,

The branch does not record the maximum value of their data set.
So in order to do what you want you will need to process the data twice.
For example something like:tree->Draw("B.dc.u1.wire>>htemp"); Int_t xmax = htemp->GetXaxis()->GetXmax(); TH1F* htemp=TH1F("name", xmax,0, xmax);
You could also try to default behavior when extending the range of analysis by calling tree->SetEstimate(tree->GetEntries));

Cheers,
Philippe

It works. Thanks a lot.