I want to draw the mean values from each histograms

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Dear Experts,
I have two root files(1.root and 2.root) and each root file contains one directory. The directories name for both the cases are same(peakTime). Both the directories contains one histogram. They have also identical name(peakTime_3.1.1.). Each histogram has its mean value. I want plot the two mean values only. So that I can compare how the mean values are varying.
I am very much new to the root. Can anybody suggest me a macro to do this ?
I can draw the two histogram in a single canvas with the following code. But I want to plot their mean values.
Need help !

void run()
TFile *f1 = new TFile("/home/souvik/svd/01930/beam1.root") ;
TFile *f2 = new TFile("/home/souvik/svd/02627/beam2.root") ;
TH1F h1 = (TH1F)f1->Get(“peaktime/peaktime_3.1.1”);
TH1F h2 = (TH1F)f2->Get(“peaktime/peaktime_3.1.1”);

Thanks in Advance

Hi @souvik,
you need a TGraph and to get the mean of your histogram.

So just declare a TGraph and use the TH1::GetMean() method of the TH1F

So is just like this:

TGraph *gr = new TGraph()

TCanvas *c = new TCanvas("c","c",600,400);

I declared a new canvas in order to avoid tu superimpose the TGraph to the histograms.

I add just two suggestions

  1. Give always a look to the documentation of the class you are using.
  2. When you post code enclose it between ```, in this way will appear as my piece of code above.


Thank you very much. It is working. But what are these corresponding to: 0,1 and 1,2 ?

You can have a look a the TGraph::SetPoint() method, the first parameter is an int and it’s the point number, and the second and the third fields are respectively the x and the y of the point i.
If the graph has no point and you are adding it, you should always start from 0 e go on.


1 Like

Now, I have a directory (name: outputfiles), inside that there are many sub-directories(names are like 00529,03433, 02523, 03456, etc). Each directory contains one root file and each root file contains one directory and inside it one histogram(like I stated earlier). Now I want to take all the mean values from the histogram. I don’t wanna write the directories name explicitely every time. Is there any way that I can loop over all the directories and get the mean values ?

I’m sorry but I don’t know how to answer this question. Maybe you should open another topic for this issue, given that the question of this topic is solved.

…and @souvik did, and thus I close this topic.