@@ -71,75 +71,86 @@ Int_t THLimitsFinder::FindGoodLimits(TH1 *h, Double_t xmin, Double_t xmax)
7171}
7272
7373// //////////////////////////////////////////////////////////////////////////////
74- // / Compute the best axis limits for the X and Y axis.
74+ // / Compute the best axis limits for the X and Y axis
75+ // / (if the corresponding newbins variable is set to 0 ie default).
7576// /
7677// / If the bit kIsInteger is set, the number of channels is also recomputed.
7778// / The axis parameters are replaced by the optimized parameters
7879
79- Int_t THLimitsFinder::FindGoodLimits (TH1 *h, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax)
80+ Int_t THLimitsFinder::FindGoodLimits (TH1 *h, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Int_t newbinsx,
81+ Int_t newbinsy)
8082{
81- Int_t newbinsx,newbinsy;
8283 TAxis *xaxis = h->GetXaxis ();
8384 TAxis *yaxis = h->GetYaxis ();
8485
85- if (xmin >= xmax) {
86+ const Bool_t xbinAuto = newbinsx != 0 ;
87+ const Bool_t ybinAuto = newbinsy != 0 ;
88+
89+ if (xbinAuto && xmin >= xmax) {
8690 if (xaxis->GetLabels ()) {xmin = 0 ; xmax = xmin +xaxis->GetNbins ();}
8791 else {xmin -= 1 ; xmax += 1 ;}
8892 }
89- if (ymin >= ymax) {
93+ if (ybinAuto && ymin >= ymax) {
9094 if (yaxis->GetLabels ()) {ymin = 0 ; ymax = ymin +yaxis->GetNbins ();}
9195 else {ymin -= 1 ; ymax += 1 ;}
9296 }
9397
94- THLimitsFinder::OptimizeLimits (xaxis->GetNbins (),
95- newbinsx,xmin,xmax,
96- xaxis->TestBit (TAxis::kIsInteger ));
97-
98- THLimitsFinder::OptimizeLimits (yaxis->GetNbins (),
99- newbinsy,ymin,ymax,
100- yaxis->TestBit (TAxis::kIsInteger ));
98+ if (xbinAuto)
99+ THLimitsFinder::OptimizeLimits (xaxis->GetNbins (),
100+ newbinsx,xmin,xmax,
101+ xaxis->TestBit (TAxis::kIsInteger ));
102+ if (ybinAuto)
103+ THLimitsFinder::OptimizeLimits (yaxis->GetNbins (),
104+ newbinsy,ymin,ymax,
105+ yaxis->TestBit (TAxis::kIsInteger ));
101106
102107 h->SetBins (newbinsx,xmin,xmax,newbinsy,ymin,ymax);
103108 return 0 ;
104109}
105110
106111// //////////////////////////////////////////////////////////////////////////////
107- // / Compute the best axis limits for the X, Y and Z axis.
112+ // / Compute the best axis limits and bins for the X, Y and Z axis
113+ // / (if the corresponding newbins variable is set to 0 ie default).
108114// /
109115// / If the bit kIsInteger is set, the number of channels is also recomputed.
110116// / The axis parameters are replaced by the optimized parameters
111117
112- Int_t THLimitsFinder::FindGoodLimits (TH1 *h, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax)
118+ Int_t THLimitsFinder::FindGoodLimits (TH1 *h, Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin,
119+ Double_t zmax, Int_t newbinsx, Int_t newbinsy, Int_t newbinsz)
113120{
114- Int_t newbinsx,newbinsy,newbinsz;
115121 TAxis *xaxis = h->GetXaxis ();
116122 TAxis *yaxis = h->GetYaxis ();
117123 TAxis *zaxis = h->GetZaxis ();
118124
119- if (xmin >= xmax) {
125+ const Bool_t xbinAuto = newbinsx != 0 ;
126+ const Bool_t ybinAuto = newbinsy != 0 ;
127+ const Bool_t zbinAuto = newbinsz != 0 ;
128+
129+ if (xbinAuto && xmin >= xmax) {
120130 if (xaxis->GetLabels ()) {xmin = 0 ; xmax = xmin +xaxis->GetNbins ();}
121131 else {xmin -= 1 ; xmax += 1 ;}
122132 }
123- if (ymin >= ymax) {
133+ if (ybinAuto && ymin >= ymax) {
124134 if (yaxis->GetLabels ()) {ymin = 0 ; ymax = ymin +yaxis->GetNbins ();}
125135 else {ymin -= 1 ; ymax += 1 ;}
126136 }
127- if (zmin >= zmax) {
137+ if (zbinAuto && zmin >= zmax) {
128138 if (zaxis->GetLabels ()) {zmin = 0 ; zmax = zmin +zaxis->GetNbins ();}
129139 else {zmin -= 1 ; zmax += 1 ;}
130140 }
131141
132- THLimitsFinder::OptimizeLimits (xaxis->GetNbins (),
133- newbinsx,xmin,xmax,
134- xaxis->TestBit (TAxis::kIsInteger ));
135-
136- THLimitsFinder::OptimizeLimits (yaxis->GetNbins (),
137- newbinsy,ymin,ymax,
138- yaxis->TestBit (TAxis::kIsInteger ));
139-
140- THLimitsFinder::OptimizeLimits (zaxis->GetNbins (),
141- newbinsz,zmin,zmax,
142- zaxis->TestBit (TAxis::kIsInteger ));
142+ if (xbinAuto)
143+ THLimitsFinder::OptimizeLimits (xaxis->GetNbins (),
144+ newbinsx,xmin,xmax,
145+ xaxis->TestBit (TAxis::kIsInteger ));
146+ if (ybinAuto)
147+ THLimitsFinder::OptimizeLimits (yaxis->GetNbins (),
148+ newbinsy,ymin,ymax,
149+ yaxis->TestBit (TAxis::kIsInteger ));
150+ if (zbinAuto)
151+ THLimitsFinder::OptimizeLimits (zaxis->GetNbins (),
152+ newbinsz,zmin,zmax,
153+ zaxis->TestBit (TAxis::kIsInteger ));
143154
144155 h->SetBins (newbinsx,xmin,xmax,newbinsy,ymin,ymax,newbinsz,zmin,zmax);
145156 return 0 ;
0 commit comments