# Getting the mean value of the y-axis

**URL:** <https://root-forum.cern.ch/t/getting-the-mean-value-of-the-y-axis/49954>\
**Category:** Newbie\
**Created:** [May 12, 2022, 8:56am UTC](https://root-forum.cern.ch/t/getting-the-mean-value-of-the-y-axis/49954 "2022-05-12T08:56:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wfelix](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/a8b319/32.png) [@wfelix](https://root-forum.cern.ch/u/wfelix)\
**Post date:** [May 12, 2022, 8:56am UTC](https://root-forum.cern.ch/t/getting-the-mean-value-of-the-y-axis/49954/1 "2022-05-12T08:56:03Z")

</div>

Hello,

I am trying to get the mean value for my y-axis. I tried the method GetMean(2) but I only get zeros.  
Basically what I am trying to do: I want to get the mean value for an efficiency in a range from 3-10 GeV in the x-axis, that’s why I used the setrange option.  
TH1D\* effprojectionmb[nbins];  
TH1D\* effprojectiontrdmb[nbins];  
TH1D\* efficrun;  
efficrun = new TH1D(“efficrun”,“Eff vs Run”,nbins,271000, 295000);  
TH1D\* meanefficiency[nbins];

Double\_t meaneff[nbins];

for (Int\_t i = 1; i \<= nbins; i++) {  
Int\_t e1 = i;  
Int\_t e2 = i;  
cout \<\< e1 \<\< " " \<\< e1 \<\< endl;  
effprojectionmb[i+1] = (TH1D\*) effsamples[0]-\>ProjectionY(Form("projectionmb ef%i ",i+1 ),e1,e2);  
effprojectiontrdmb[i+1] = (TH1D\*) effsamples[2]-\>ProjectionY(Form("projectiontrdmb ef%i ",i+1 ),e1,e2);  
effprojectionmb[i+1]-\>Sumw2();  
effprojectiontrdmb[i+1]-\>Sumw2();  
DrawPrettyHist1(effprojectionmb[i+1], “Projection of RunNo on p\_{T}”, “p\_{T} [GeV/c]”, “Entries”);

```
// calculate efficiency per run
meanefficiency[i+1] = (TH1D*)effprojectionmb[i+1]->Clone(Form("eff for run %i", i+1));
meanefficiency[i+1]->Divide(effprojectiontrdmb[i+1], effprojectionmb[i+1]);

// get mean value
meanefficiency[i+1]->GetXaxis()->SetRange(meanefficiency[i+1]->FindBin(3),meanefficiency[i+1]->FindBin(10));
meaneff[i+1] = meanefficiency[i+1]->GetMean(2);
cout << meaneff[i+1] << endl;
// fill histogram
efficrun->SetBinContent(i, meaneff[i+1]);
efficrun->SetBinError(i, 0.001);
}

```

Does anyone have a tip on how I can do this?

Thank you,  
Felix

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 12, 2022, 9:29am UTC](https://root-forum.cern.ch/t/getting-the-mean-value-of-the-y-axis/49954/2 "2022-05-12T09:29:09Z")

</div>

The y axis of a 1D histogram is not binned, so you cannot use GetMean(2) on it; you would need a TH2D for that. I suppose `effsamples[i]` are TH2D? maybe what you want is to use GetMean on them?
