Change of axis range

Hey,

I’m wrking with a TH2F histogram, which I define very early where I do not exactly know where I’ve entries.
It often happens that the area where I’ve entries is quite small in comparision with the whole range of the histogram.

When I create Plots, I am just interested in the area with entries.
Is there an easy way to “automatic” set the range to this area?
I just found the workaround with projectX/projectY and look for the first bin which has an entry.
Here the idea for the x axis:

 TH2D histo(......
....
//Flill histo
...
// set range
 TH1D* hProj=histo.ProjectionX();
    int binxMin=0;
    for(binxMin=0;binxMin<hProj->GetNbinsX();binxMin++)if(hProj->GetBinContent(binxMin))break;
    int binxMax;
    for(binxMax=hProj->GetNbinsX();binxMax>0;binxMax--)if(hProj->GetBinContent(binxMax))break;
    histo.GetXaxis()->SetRangeUser(hProj->GetBinLowEdge(binxMin),hProj->GetBinLowEdge(binxMax+1));
    delete hProj;

I think this is not a reallyh nice way…
Is there a nicer way to find the right axis range?

Cheers,
Felix

I do not think there is an automatic way to find the “no empty space” but simple loops along X and
Y axis will do the job. You can make a smalle generic function doing that.