Hi @diboye,
there is quite some confusion with the indices there
I think the easiest would be to:
- Figure out the bin coordinates for each bin in your new subset histogram
- Look up the bin content for that coordinates in the full hist
- Set the bin content (and maybe errors too) of the subset histogram accordingly
TFile* file = TFile::Open(
"BRscaled_gaussiansignal_4echannel_mZd31_mH108GeV.root");
TH2F* tempHist2D = file->Get<TH2F>("Nominal/sig");
TH2D* tempHist2DBis =
new TH2D("tempHist2DBis", "", 2, 105, 111, 2, 30, 32);
// Starting with 1 because bin zero is the underflow bin
for (int i = 1; i <= tempHist2DBis->GetNbinsX(); i++) {
for (int j = 1; j <= tempHist2DBis->GetNbinsY(); j++) {
double x = tempHist2DBis->GetXaxis()->GetBinCenter(i);
double y = tempHist2DBis->GetYaxis()->GetBinCenter(j);
double content =
tempHist2D->GetBinContent(tempHist2D->FindBin(x, y));
tempHist2DBis->SetBinContent(i, j, 0, content);
}
}
tempHist2DBis->Draw("colz text");
I hope that helps!
Cheers,
Jonas
PS: Not I added text to the bins in the drawing, which is quite useful for checks.