Dear root experts,
I am trying to get a subset of 2D histogram from a bigger one.
The original histogram is the following:
The histogram is defined as following:
TH2D* tempHist2D = new TH2D(" tempHist2D","" , 30,30,120,30,10,40);
Now I would like to have sub-set of this 2D histogram as following:
TH2D* tempHist2DBis = new TH2D("tempHist2DBis","" , 2,105,111,2,30,32);
Here the code I wrote for that:
TH2D *tempHist2D;
//TH2D* tempHist2DBis = new TH2D("tempHist2DBis","" , 30,30,120,30,10,40);
TH2D* tempHist2DBis = new TH2D("tempHist2DBis","" , 2,105,111,2,30,32);
TFile *myfile = new TFile("inputFiles/BRscaled_gaussiansignal_4echannel_mZd31_mH108GeV.root");
tempHist2D =(TH2D*)myfile->Get("Nominal/sig");
int Nbinx = tempHist2D->GetNbinsX();
int Nbiny = tempHist2D->GetNbinsY();
int binxy,x,y,z;
for (int i =0; i < Nbinx; i++)
{
for (int j =0; j< Nbiny; j++)
{
binxy = tempHist2D->GetBin(i,j);
tempHist2D->GetBinXYZ(binxy,x, y,z);
if ( tempHist2D->GetXaxis()->GetBinCenter(i) >= 105 && tempHist2D->GetXaxis()->GetBinCenter(i) <= 111)
{
if (tempHist2D->GetYaxis()->GetBinCenter(j) >= 30 && tempHist2D->GetYaxis()->GetBinCenter(j) <= 32) {
tempHist2DBis->SetBinContent(i,j,tempHist2D->GetBinContent(i,j));
}
}
}
}
tempHist2DBis->Draw("colz");
It gives me this:
Which is not what I want because the range is the same as the original one.
I was trying to change the tempHist2DBis definition by this:
TH2D* tempHist2DBis = new TH2D("tempHist2DBis","" , 2,105,111,2,30,32);
But this results to an empty histogram.
Do you have any idea?
SetRangeUser doesn’t seem to help, since this seem to change only the visualization.
I attached the root file.
BRscaled_gaussiansignal_4echannel_mZd31_mH108GeV.root (12.0 KB)
Best,
Diallo.