Logo ROOT   6.14/05
Reference Guide
mntplot.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 /* mnplot.F -- translated by f2c (version 20010320).
11  You must link the resulting object file with the libraries:
12  -lf2c -lm (in that order)
13 */
14 
15 #include <math.h>
16 #include <stdio.h>
17 #include <string.h>
18 
19 namespace ROOT {
20 
21  namespace Minuit2 {
22 
23 
24 void mnbins(double, double, int, double&, double&, int&, double&);
25 
26 void mnplot(double* xpt, double* ypt, char* chpt, int nxypt, int npagwd, int npagln) {
27  //*-*-*-*Plots points in array xypt onto one page with labelled axes*-*-*-*-*
28  //*-* ===========================================================
29  //*-* NXYPT is the number of points to be plotted
30  //*-* XPT(I) = x-coord. of ith point
31  //*-* YPT(I) = y-coord. of ith point
32  //*-* CHPT(I) = character to be plotted at this position
33  //*-* the input point arrays XPT, YPT, CHPT are destroyed.
34  //*-*
35  //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
36 
37 // char cdot[] = ".";
38 // char cslash[] = "/";
39 
40  /* Local variables */
41  double xmin, ymin, xmax, ymax, savx, savy, yprt;
42  double bwidx, bwidy, xbest, ybest, ax, ay, bx, by;
43  double xvalus[12], any, dxx, dyy;
44  int iten, i, j, k, maxnx, maxny, iquit, ni, linodd;
45  int nxbest, nybest, km1, ibk, isp1, nx, ny, ks, ix;
46  char ctemp[120];
47  bool overpr;
48  char cline[120];
49  char chsav, chbest;
50 
51  /* Function Body */
52  //*-* Computing MIN
53  maxnx = npagwd-20 < 100 ? npagwd-20 : 100;
54  if (maxnx < 10) maxnx = 10;
55  maxny = npagln;
56  if (maxny < 10) maxny = 10;
57  if (nxypt <= 1) return;
58  xbest = xpt[0];
59  ybest = ypt[0];
60  chbest = chpt[0];
61  //*-*- order the points by decreasing y
62  km1 = nxypt - 1;
63  for (i = 1; i <= km1; ++i) {
64  iquit = 0;
65  ni = nxypt - i;
66  for (j = 1; j <= ni; ++j) {
67  if (ypt[j-1] > ypt[j]) continue;
68  savx = xpt[j-1];
69  xpt[j-1] = xpt[j];
70  xpt[j] = savx;
71  savy = ypt[j-1];
72  ypt[j-1] = ypt[j];
73  ypt[j] = savy;
74  chsav = chpt[j-1];
75  chpt[j-1]= chpt[j];
76  chpt[j] = chsav;
77  iquit = 1;
78  }
79  if (iquit == 0) break;
80  }
81  //*-*- find extreme values
82  xmax = xpt[0];
83  xmin = xmax;
84  for (i = 1; i <= nxypt; ++i) {
85  if (xpt[i-1] > xmax) xmax = xpt[i-1];
86  if (xpt[i-1] < xmin) xmin = xpt[i-1];
87  }
88  dxx = (xmax - xmin)*.001;
89  xmax += dxx;
90  xmin -= dxx;
91  mnbins(xmin, xmax, maxnx, xmin, xmax, nx, bwidx);
92  ymax = ypt[0];
93  ymin = ypt[nxypt-1];
94  if (ymax == ymin) ymax = ymin + 1;
95  dyy = (ymax - ymin)*.001;
96  ymax += dyy;
97  ymin -= dyy;
98  mnbins(ymin, ymax, maxny, ymin, ymax, ny, bwidy);
99  any = (double) ny;
100  //*-*- if first point is blank, it is an 'origin'
101  if (chbest == ' ') goto L50;
102  xbest = (xmax + xmin)*.5;
103  ybest = (ymax + ymin)*.5;
104 L50:
105  //*-*- find Scale constants
106  ax = 1 / bwidx;
107  ay = 1 / bwidy;
108  bx = -ax*xmin + 2;
109  by = -ay*ymin - 2;
110  //*-*- convert points to grid positions
111  for (i = 1; i <= nxypt; ++i) {
112  xpt[i-1] = ax*xpt[i-1] + bx;
113  ypt[i-1] = any - ay*ypt[i-1] - by;
114  }
115  nxbest = int((ax*xbest + bx));
116  nybest = int((any - ay*ybest - by));
117  //*-*- print the points
118  ny += 2;
119  nx += 2;
120  isp1 = 1;
121  linodd = 1;
122  overpr = false;
123  for (i = 1; i <= ny; ++i) {
124  for (ibk = 1; ibk <= nx; ++ibk) { cline[ibk-1] = ' '; }
125  cline[nx] = '\0';
126  cline[nx+1] = '\0';
127  cline[0] = '.';
128  // not needed - but to avoid a wrongly reported compiler warning (see ROOT-6496)
129  if (nx>0) cline[nx-1] = '.';
130  cline[nxbest-1] = '.';
131  if (i != 1 && i != nybest && i != ny) goto L320;
132  for (j = 1; j <= nx; ++j) { cline[j-1] = '.'; }
133 L320:
134  yprt = ymax - double(i-1)*bwidy;
135  if (isp1 > nxypt) goto L350;
136  //*-*- find the points to be plotted on this line
137  for (k = isp1; k <= nxypt; ++k) {
138  ks = int(ypt[k-1]);
139  if (ks > i) goto L345;
140  ix = int(xpt[k-1]);
141  if (cline[ix-1] == '.') goto L340;
142  if (cline[ix-1] == ' ') goto L340;
143  if (cline[ix-1] == chpt[k-1]) continue;
144  overpr = true;
145  //*-*- OVERPR is true if one or more positions contains more than
146  //*-*- one point
147  cline[ix-1] = '&';
148  continue;
149 L340:
150  cline[ix-1] = chpt[k-1];
151  }
152  isp1 = nxypt + 1;
153  goto L350;
154 L345:
155  isp1 = k;
156 L350:
157  if (linodd == 1 || i == ny) goto L380;
158  linodd = 1;
159  memcpy(ctemp, cline, 120);
160  printf(" %s",(const char*)ctemp);
161  goto L400;
162 L380:
163  // ctemp = cline;
164  memcpy(ctemp, cline, 120);
165  printf(" %14.7g ..%s",yprt,(const char*)ctemp);
166  linodd = 0;
167 L400:
168  printf("\n");
169  }
170  //*-*- print labels on x-axis every ten columns
171  for (ibk = 1; ibk <= nx; ++ibk) {
172  cline[ibk-1] = ' ';
173  if (ibk % 10 == 1) cline[ibk-1] = '/';
174  }
175  printf(" %s",cline);
176  printf("\n");
177 
178  for (ibk = 1; ibk <= 12; ++ibk) {
179  xvalus[ibk-1] = xmin + double(ibk-1)*10*bwidx;
180  }
181  printf(" ");
182  iten = (nx + 9) / 10;
183  for (ibk = 1; ibk <= iten; ++ibk) {
184  printf(" %9.4g", xvalus[ibk-1]);
185  }
186  printf("\n");
187 
188  if (overpr) {
189  char chmess[] = " Overprint character is &";
190  printf(" ONE COLUMN=%13.7g%s",bwidx,(const char*)chmess);
191  } else {
192  char chmess[] = " ";
193  printf(" ONE COLUMN=%13.7g%s",bwidx,(const char*)chmess);
194  }
195  printf("\n");
196 
197 } /* mnplot_ */
198 
199  } // namespace Minuit2
200 
201 } // namespace ROOT
float xmin
Definition: THbookFile.cxx:93
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
float ymin
Definition: THbookFile.cxx:93
void mnbins(double a1, double a2, int naa, double &bl, double &bh, int &nb, double &bwid)
Definition: mnbins.cxx:17
float ymax
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
void mnplot(double *xpt, double *ypt, char *chpt, int nxypt, int npagwd, int npagln)
Definition: mntplot.cxx:26