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.
First, I just know the Branch Name and of course the root file.
Ex: B.dc.u1.wire ( 0<=x<=144 )
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.
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));