If I want to reset the x axis limit of a merged histogram, I would like to get “hist->GetNbinsX()” as the last bin that has an entry > 0, but I couldn’t get the value after changing the x limits.I need a histogram whose upper edge is exactly equal to the last bin that has an entry.
void test4()
{
int nfile=10;
TList*list=new TList;
for(int i=1;i<=nfile;i++){
string fname="pp"+to_string(i)+".root";
TFile*file=TFile::Open(fname.c_str());
TTree*T=(TTree*)file->Get("T");
T->Draw("multiplicity>>h","","goff");
TH1F*h=(TH1F*)gDirectory->Get("h");
list->Add(h);
}
TH1F*hist=new TH1F;
hist->Reset();
hist->Merge(list);
double lastbin;
for(int i=1;i<hist->GetNbinsX();i++){
if(hist->GetBinContent(i) <= 0 )continue;
lastbin=i;
}
cout<<lastbin<<endl;
hist->SetAxisRange(0,lastbin);
hist->Draw();
cout<<hist->GetNbinsX()<<endl;
}
I don’t know the correct function that can give an answer.
Thank you…