Home | News | Documentation | Download

How to select the histogram inside my root file in TBrowser?

Dear All,

I have a root file in which I am able to see all the 24 histograms in “TBrowser”. Now while writing the macro for calibration I have to select only one spectrum. Could you please help?
What should be the small macro for which it only takes that selected histogram?

Thanks and have a nice day.

auto f = new TFile("Eu_26Dec.001.root");
TH1F* h = (TH1F*)f->Get("hist_name");

Thanks @couet
The above issue is resolved.
Now I am facing another issue which is following:
I am using the attached macro which is perfect for doing calibration.
eff_1.C (1.7 KB)
This macro is finding the position of all the peaks and marking the energy for every peak.
Till now everything is perfect.
The problem arises when I need to fit all the peaks and calculate the area for each peak. I know how to calculate the area of a peak using the following command:
TF1 *f = new TF1("f", "gausn(0) + pol1(3)", 0., 1.); // linear background f->SetRange(395, 420.); f->SetParameters(5e+4, 407., 2., 1200., 0., 0.); h->Fit(f, "ILR+"); // e.g. "ILR+" or "IR+" or "LR+" or "R+"
But what I want is that if I again use this method then I have to write this command (Set Range and Parameters)again and again to find the area of peaks at different positions.
Even if I write down for all the eight peaks. Still I am fine. I have no problems.
Again when I change the histogram in the macro from CL02_E1 to CL02_E2 what I have to take care

  1. Threshold for finding all the peaks.(which is not a big issue)
  2. I have to set the parameters and set the range for all the peaks again and again.
    The whole process becomes so cumbersome.
    Is there any way that one can find the area of all the peaks without setting range and parameters every time if one knows the mean position of every peak??

Hi Robert,

Could you in the future open new topics for new issues? Else we (and other readers) get lost which problem is being solved. Thanks!

Cheers, Axel.

Why don’t you store the peak positions in a vector, and then do a loop over the peaks, calling SetParameter with each vector element? This really looks more like a coding question than a question about ROOT, btw…

Thanks @Axel
Actually I have never used vectors in root macro.
Can you please tell me that how can I use vectors in my macro to store the peak positions?
Does using vectors helps in not seting parameters and range again and again?

@moneta
Can you please resolve my query?