I am using a root file which consists of histograms.
What I want to do is to find the average of those histograms.
To do that I am creating a 2D histogram with all the 1D histograms on top of the other.
Then I am using TProfile to get the average of the histogram like the following image shows
What I would like to do is “force” the average to be inside the white region of the 2D histogram. In order to do that I would need to compute the average ignoring the smaller z-values.
Is this possible?
Thank you very much in advance!
My code is the following
[code]#include “Riostream.h”
#include
#include
#include “TH1F.h”
#include “TH2F.h”
#include “TProfile.h”
TH2F* mean_Gamma_Flash() {
gStyle->SetPalette(52); //Use Grayscale palette–51-59
//Load File.
TFile *f = new TFile(“FIMG5.root”);
//Loop over each histogram and store pointer in vector.
std::vector<TH1F*> hists;
for (int i=0;i<305;i++) {
TH1F hIndv = (TH1F)f->Get(Form(“FIMG5_EV_%d;1”,i));
if (hIndv)
hists.push_back(hIndv);
}
//Compute average
TH2F *hAvg = Average(hists);
TProfile *hProf = hAvg->ProfileX(“hProf”);//Average histogram
//Turn off stats
hAvg->SetStats(kFALSE);
//Draw the 2D hist with the average prof on top.
hProf->SetLineColor(kRed);
hProf->SetMarkerColor(kRed);
//hAvg->Draw(“COLZ”);
//hProf->Draw(“SAME”);
//Use a log scale in Z
gPad->SetLogz();
gPad->Update();
TString histfilename = "mean_gamma.txt";
SingleExportAscii(hProf,histfilename);
return hAvg;
}
TH2F Average(std::vector<TH1F> hists) {
TH2F *hAvg = new TH2F(“hAvg”,“Avg”,8000,0,8000,300,0,300);
for (size_t i=0;i < hists.size(); i++) {
for (int bin = 0; bin < hists[i]->GetNbinsX(); bin++) {
int resultBin = hAvg->FindBin(bin, hists[i]->GetBinContent(bin));
int binContent = hAvg->GetBinContent(resultBin) + 1;
hAvg->SetBinContent(resultBin,binContent);
}
}
return hAvg;
}[/code]