Average of histograms

Hi everyone?
I want to ask how to get average histogram from single histogram
For example: I have 3 histogram.
TH1Da with a_mean = 11 and a_rms = sqrt(11)) (rms is error for a value)
b with a_mean = 12 and b_rms = sqrt(12))
TH1Dc with a_mean = 13 and c_rms = sqrt(13))
I want to get TH1D
avergage from a,b,c to get average_mean and average_rms.
Thank you very much,

Hi @Jessica.PQ , I moved your post to a new topic as you originally replied to an old conversation.

These other threads might help:


it is my code.
include_errror_data.C (2.4 KB)
What I want to calculated is the average histogram " TH1D *his_event_average = new TH1D(“event_average”, “”, 100, 0, 50);". I don’t know how to calculate average values I used is right or not but I can’t run it yet.

Hi @Jessica.PQ ,
if I understand your script correctly you are calculating the histogram of the average values. That’s different from calculating the average of the histograms. Which one do you need?

Note that event_aver is a double (i.e. just a number) so you can’t do event_aver->Scale(1.0 / 3.0) but you can simply divide it by 3: event_aver = event_aver / 3..


For example: a belongs to histo 1, b belongs to histo2, c belongs to his3 → his_event_average = average(a,b,c)

Ok so a histogram filled with the average of a, b and c? I think you just have to apply my fix for event_aver above.

Can you run this code?
I just fix as event_aver = event_aver / 3. . but I can’t run it.

Can you send the updated version please?

Thanks Enrico. I can fix this error.
I have a problem. In this code, I can draw a graph with the attached data file.
combine_data.zip (85.7 KB)
Now I want to add a point which has coordinates (0.528, 0.0604) in the same plot. How can I do that?

to draw a point on a canvas you can do:

TGraph g;
g.SetPoint(0, 0.528, 0.0604);
g.Draw("SAME"); // to draw on the same canvas


I added TGraphError with structure:
TGraphErrors*real = new TGraphErrors(1, 0.528, 0.0726091, 0.0465, 0.0138799);
real-> SetMarkerStyle(21);
real-> SetMarkerColor(4);
real-> Draw(“ALP”);
But I don’t know what is my fault?
error: no matching constructor for initialization of ‘TGraphErrors’
…= new TGraphErrors(1, 0.528, 0.0726091, 0.0465, 0.0138799);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It should be:

   TGraphErrors *real = new TGraphErrors();
   real->SetPoint(0,0.528, 0.0726091);
   real->SetPointError(0,0.0465, 0.0138799);
   real-> SetMarkerStyle(21);
   real-> SetMarkerColor(4);
   real-> Draw("ALP");

you will get:

So you get the errors in addition, that’s not a single marker. For a single marker you should do what Enrico suggested. Or use TMarker:

TMarker m(0.528, 0.0604, 21);

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