Hello co-rooters!
I am trying to create a 2D histogram, by stacking 1D histograms on it.
The 1D histograms have in x-axis time in us.
The weird thing about them is that the first bin isn’t 0, but something greater (usally around 8.1 us)
The code that creates the 2D histogram is the following
[code]TH2F* mean_Gamma_Flash() {
gStyle->SetPalette(52); //Use Grayscale palette–51-59
//Load File.
TFile *f = new TFile(“FIMG5_300.root”);
//Loop over each histogram and store pointer in vector.
std::vector<TH1F*> hists;
for (int i=0;i<3;i++) {
TH1F hIndv = (TH1F)f->Get(Form(“FIMG5_EV_%d;1”,i));
if (hIndv)
hists.push_back(hIndv);
}
TH2F *hStack = Stack(hists);
hStack->SetStats(kFALSE);
hStack->Draw(“COLZ”);
Pad->SetLogz();
gPad->Update();
return hStack;
}
TH2F Stack(std::vector<TH1F> hists) {
TH2F *hStack = new TH2F(“hStack”,“Stack”,hists[1]->GetNbinsX(),0,hists[1]->GetNbinsX(),300,0,300);
for (size_t i=0;i < hists.size(); i++) {
for (int bin = 0; bin < hists[i]->GetNbinsX(); bin++) {
int resultBin = hStack->FindBin(bin, hists[i]->GetBinContent(bin));
int binContent = hStack->GetBinContent(resultBin) + 1;
hStack->SetBinContent(resultBin,binContent);
}
}
return hStack;
}[/code]
The resutling 2D histogram doesn’t adopt the binning of the original 1D histograms. I suspect the reason is that the 1D histograms don’t start counting from 0.
Any idea on how keep the same bin numbers, the same first and last bin on the 2D histogram?
Thank you very much in advance!
P.S. You can find the root file here
https://www.dropbox.com/s/1y3j5rkcswsejm2/FIMG5.root?dl=0