Logo ROOT   6.14/05
Reference Guide
mnbins.cxx
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 #include <math.h>
11 
12 namespace ROOT {
13 
14  namespace Minuit2 {
15 
16 
17 void mnbins(double a1, double a2, int naa, double& bl, double& bh, int& nb, double& bwid) {
18 
19 //*-*-*-*-*-*-*-*-*-*-*Compute reasonable histogram intervals*-*-*-*-*-*-*-*-*
20 //*-* ======================================
21 //*-* Function TO DETERMINE REASONABLE HISTOGRAM INTERVALS
22 //*-* GIVEN ABSOLUTE UPPER AND LOWER BOUNDS A1 AND A2
23 //*-* AND DESIRED MAXIMUM NUMBER OF BINS NAA
24 //*-* PROGRAM MAKES REASONABLE BINNING FROM BL TO BH OF WIDTH BWID
25 //*-* F. JAMES, AUGUST, 1974 , stolen for Minuit, 1988
26 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
27 
28  /* Local variables */
29  double awid,ah, al, sigfig, sigrnd, alb;
30  int kwid, lwid, na=0, log_;
31 
32  al = a1 < a2 ? a1 : a2;
33  // al = std::min(a1,a2);
34  // ah = std::max(a1,a2);
35  ah = a1 > a2 ? a1 : a2;
36  if (al == ah) ah = al + 1;
37 
38  //*-*- IF NAA .EQ. -1 , PROGRAM USES BWID INPUT FROM CALLING ROUTINE
39  if (naa == -1) goto L150;
40 L10:
41  na = naa - 1;
42  if (na < 1) na = 1;
43 
44  //*-*- GET NOMINAL BIN WIDTH IN EXPON FORM
45 L20:
46  awid = (ah-al) / double(na);
47  log_ = int(log10(awid));
48  if (awid <= 1) --log_;
49  sigfig = awid*pow(10.0, -log_);
50  //*-*- ROUND MANTISSA UP TO 2, 2.5, 5, OR 10
51  if (sigfig > 2) goto L40;
52  sigrnd = 2;
53  goto L100;
54 L40:
55  if (sigfig > 2.5) goto L50;
56  sigrnd = 2.5;
57  goto L100;
58 L50:
59  if (sigfig > 5) goto L60;
60  sigrnd = 5;
61  goto L100;
62 L60:
63  sigrnd = 1;
64  ++log_;
65 L100:
66  bwid = sigrnd*pow(10.0, log_);
67  goto L200;
68  //*-*- GET NEW BOUNDS FROM NEW WIDTH BWID
69 L150:
70  if (bwid <= 0) goto L10;
71 L200:
72  alb = al / bwid;
73  lwid = int(alb);
74  if (alb < 0) --lwid;
75  bl = bwid*double(lwid);
76  alb = ah / bwid + 1;
77  kwid = int(alb);
78  if (alb < 0) --kwid;
79  bh = bwid*double(kwid);
80  nb = kwid - lwid;
81  if (naa > 5) goto L240;
82  if (naa == -1) return;
83  //*-*- REQUEST FOR ONE BIN IS DIFFICULT CASE
84  if (naa > 1 || nb == 1) return;
85  bwid *= 2;
86  nb = 1;
87  return;
88 L240:
89  if (nb << 1 != naa) return;
90  ++na;
91  goto L20;
92 } /* mnbins_ */
93 
94  } // namespace Minuit2
95 
96 } // namespace ROOT
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
void mnbins(double a1, double a2, int naa, double &bl, double &bh, int &nb, double &bwid)
Definition: mnbins.cxx:17
double log10(double)
double pow(double, double)