RE: [ROOT] how to access Taxis from TH1F histo

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Feb 07 2002 - 02:02:53 MET


Hi,

To make you code general you can use TH1x::GetXAxis() and TAxis::GetLast

  TFile *f = new TFile("MyRootFile.root");
  TH1F* myHisto = SomeHisto;
  Int_t maxBin;
  TAxis * Xaxis = myHisto->GetXAxis(); 
  for(int i = Xaxis->GetLast(); 
	myHisto->GetBinContent(i) == 0  && i>= Xaxis->GetFirst(); 
	i-- ){     
      maxBin = i;
  }
  Int_t minBin = 0;
  Int_t numberOfBins = maxBin - minBin +1;
  myHisto->SetBins(numberOfBins, minBin, maxBin);

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Stanley Forrester
Sent: Wednesday, February 06, 2002 4:59 PM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] how to access Taxis from TH1F histo



Given a preexisting histogram how can one determine the min and max bin 
number in the histogram?   I'm producing effiecncy plots, but need 
to change the x axis limits on histos to exclude high ranges with no data.
Right now I am just assuming that the max bin number is 200, but would 
like to be able to access the Taxis inline function GetXmax() to make this 
a more general function.  I'd also like to add a empty low range exclusion 
as well.

Currently I am resizing histograms with the following code

  TFile *f = new TFile("MyRootFile.root");
  TH1F* myHisto = SomeHisto;
  Int_t maxBin;   
  for(int i = 200; myHisto->GetBinContent(i) == 0 ; i-- ){     
      maxBin = i;}
  Int_t minBin = 0;
  Int_t numberOfBins = maxBin - minBin +1;
  myHisto->SetBins(numberOfBins, minBin, maxBin);


-- 
Stanley S. Forrester
sforrest@lifshitz.ucdavis.edu

[The movement] seeks no victory over anyone. It seeks 
to liberate American society and to share in the 
self-liberation of all the people. 

		Martin Luther King Jr.
		Nobel Lecture, December 11, 1964 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:41 MET