ROOT  6.06/04
Reference Guide
TMinuit.cxx
Go to the documentation of this file.
1 // @(#)root/minuit:$Id$
2 // Author: Rene Brun, Frederick James 12/08/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /**
13 
14  \defgroup MinuitOld TMinuit
15  \ingroup Math
16 
17  The Minuit Minimization package.
18  Direct C++ implementation of the Minuit minimization package.
19  This package was originally written in Fortran by Fred James
20  and part of PACKLIB (patch D506)
21  It has been converted to a C++ class, TMinuit, by R.Brun.
22 */
23 
24 /**
25  \class TMinuit
26 
27  Implementation in C++ of the Minuit package written by F. James.
28  Thjis is a straightforward conversion
29  of the original Fortran version.
30  The main changes are:
31 
32  - The variables in the various Minuit labelled common blocks
33  have been changed to the TMinuit class data members.
34  - The internal arrays with a maximum dimension depending on the
35  maximum number of parameters are now data members arrays with
36  a dynamic dimension such that one can fit very large problems
37  by simply initialising the TMinuit constructor with the maximum
38  number of parameters.
39  - The include file Minuit.h has been commented as much as possible
40  using existing comments in the code or the printed documentation
41  - The original Minuit subroutines are now member functions.
42  - Constructors and destructor have been added.
43  - Instead of passing the FCN function in the argument
44  list, the addresses of this function is stored as pointer
45  in the data members of the class. This is by far more elegant
46  and flexible in an interactive environment.
47  The member function SetFCN can be used to define this pointer.
48  - The ROOT static function Printf is provided to replace all
49  format statements and to print on currently defined output file.
50  - The functions SetObjectFit(TObject * obj)/GetObjectFit() can be
51  used inside the FCN function to set/get a referenced object
52  instead of using global variables.
53 
54 <P>
55 <H2><A NAME=H2Basic-concepts-of-MINUIT.html>Basic concepts of MINUIT</A></H2>
56 <P>
57 The <A HREF="http://wwwinfo.cern.ch/asdoc/minuit/minmain.html"> MINUIT</A> package acts on a multiparameter Fortran function to which one
58 must give the generic name <TT>FCN</TT>. In the ROOT implementation,
59 the function <TT>FCN</TT> is defined via the MINUIT SetFCN member function
60 when an Histogram.Fit command is invoked.
61 The value of <TT>FCN</TT> will in general depend on one
62 or more variable parameters.
63 <P>
64 To take a simple example, in case of ROOT histograms (classes TH1C,TH1S,TH1F,TH1D)
65 the Fit function defines the Minuit fitting function as being H1FitChisquare
66 or H1FitLikelihood depending on the options selected.
67 H1FitChisquare
68 calculates the chisquare between the user fitting function (gaussian, polynomial,
69 user defined,etc) and the data for given values of the parameters.
70 It is the task of MINUIT to find those values of the parameters
71 which give the lowest value of chisquare.
72 <P>
73 <H3>Basic concepts - The transformation for parameters with limits.</H3>
74 <P>
75 For variable parameters with limits, MINUIT uses the following
76 transformation:
77 <P>
78 <PRE>
79  P = arcsin(2((P -a)/(b- a))-1) P = a+((b- a)/(2))(sinP +1)
80  int ext ext int
81 </PRE>
82 <P>
83 so that the internal value P can take on any value, while the external
84  int
85 value P can take on values only between the lower limit a and the
86  ext
87 upper limit b. Since the transformation is necessarily non-linear, it
88 would transform a nice linear problem into a nasty non-linear one, which
89 is the reason why limits should be avoided if not necessary. In addition,
90 the transformation does require some computer time, so it slows down the
91 computation a little bit, and more importantly, it introduces additional
92 numerical inaccuracy into the problem in addition to what is introduced in
93 the numerical calculation of the <TT>FCN</TT> value. The effects of
94 non-linearity and numerical roundoff both become more important as the
95 external value gets closer to one of the limits (expressed as the distance
96 to nearest limit divided by distance between limits). The user must
97 therefore be aware of the fact that, for example, if they put limits of
98 (0,10^10 ) on a parameter, then the values 0.0 and 1. 0 will be
99 indistinguishable to the accuracy of most machines.
100 <P>
101 The transformation also affects the parameter error matrix, of course, so
102 MINUIT does a transformation of the error matrix (and the ``parabolic''
103 parameter errors) when there are parameter limits. Users should however
104 realize that the transformation is only a linear approximation, and that
105 it cannot give a meaningful result if one or more parameters is very close
106 to a limit, where partial Pext /partial Pint #0. Therefore, it is
107 recommended that:
108 <P>
109 <OL>
110 <LI>Limits on variable parameters should be used only when needed in order
111 to prevent the parameter from taking on unphysical values.
112 <LI>When a satisfactory minimum has been found using limits, the limits
113 should then be removed if possible, in order to perform or re-perform the
114 error analysis without limits.
115 </OL>
116 <P>
117 <H3>How to get the right answer from MINUIT.</H3>
118 <P>
119 MINUIT offers the user a choice of several minimization algorithms. The
120 MIGRAD algorithm is in general the best minimizer for
121 nearly all functions. It is a variable-metric method with inexact line
122 search, a stable metric updating scheme, and checks for
123 positive-definiteness. Its main weakness is that it depends heavily on
124 knowledge of the first derivatives, and fails miserably if they are very
125 inaccurate.
126 <P>
127 If parameter limits are needed, in spite of the side effects, then the
128 user should be aware of the following techniques to alleviate problems
129 caused by limits:
130 <P>
131 <H4>Getting the right minimum with limits.</H4>
132 <P>
133 If MIGRAD converges normally to a point where no parameter is near one of
134 its limits, then the existence of limits has probably not prevented MINUIT
135 from finding the right minimum. On the other hand, if one or more
136 parameters is near its limit at the minimum, this may be because the true
137 minimum is indeed at a limit, or it may be because the minimizer has
138 become ``blocked'' at a limit. This may normally happen only if the
139 parameter is so close to a limit (internal value at an odd multiple of #((pi)/(2))
140 that MINUIT prints a warning to this effect when it prints
141 the parameter values.
142 
143 The minimizer can become blocked at a limit, because at a limit the
144 derivative seen by the minimizer partial F/partial Pint is zero no matter
145 what the real derivative partial F/partial Pext is.
146 <P>
147 <P>
148 <PRE>
149 ((partial F)/(partial P ))= ((partial F)/(partial P ))((partial P )/(partial P )) =((partial F)/(partial P ))= 0
150  int ext ext int ext
151 </PRE>
152 <P>
153 <P>
154 <H4>Getting the right parameter errors with limits.</H4>
155 <P>
156 In the best case, where the minimum is far from any limits, MINUIT will
157 correctly transform the error matrix, and the parameter errors it reports
158 should be accurate and very close to those you would have got without
159 limits. In other cases (which should be more common, since otherwise you
160 wouldn't need limits), the very meaning of parameter errors becomes
161 problematic. Mathematically, since the limit is an absolute constraint on
162 the parameter, a parameter at its limit has no error, at least in one
163 direction. The error matrix, which can assign only symmetric errors, then
164 becomes essentially meaningless.
165 <P>
166 <H3>Interpretation of Parameter Errors:</H3>
167 <P>
168 There are two kinds of problems that can arise: the reliability of
169 MINUIT's error estimates, and their statistical interpretation, assuming
170 they are accurate.
171 <P>
172 <H3>Statistical interpretation:</H3>
173 <P>
174 For discussuion of basic concepts, such as the meaning of the elements of
175 the error matrix, or setting of exact confidence levels see:
176 <ol>
177  <li>F.James.
178  Determining the statistical Significance of experimental Results.
179  Technical Report DD/81/02 and CERN Report 81-03, CERN, 1981.</li>
180 
181  <li>W.T.Eadie, D.Drijard, F.James, M.Roos, and B.Sadoulet.
182  Statistical Methods in Experimental Physics.
183  North-Holland, 1971.</li>
184 </ol>
185 <P>
186 <H3>Reliability of MINUIT error estimates.</H3>
187 <P>
188 MINUIT always carries around its own current estimates of the parameter
189 errors, which it will print out on request, no matter how accurate they
190 are at any given point in the execution. For example, at initialization,
191 these estimates are just the starting step sizes as specified by the user.
192 After a HESSE step, the errors are usually quite accurate,
193 unless there has been a problem. MINUIT, when it prints out error values,
194 also gives some indication of how reliable it thinks they are. For
195 example, those marked <TT>CURRENT GUESS ERROR</TT> are only working values
196 not to be believed, and <TT>APPROXIMATE ERROR</TT> means that they have
197 been calculated but there is reason to believe that they may not be
198 accurate.
199 <P>
200 If no mitigating adjective is given, then at least MINUIT believes the
201 errors are accurate, although there is always a small chance that MINUIT
202 has been fooled. Some visible signs that MINUIT may have been fooled are:
203 <P>
204 <OL>
205 <LI>Warning messages produced during the minimization or error analysis.
206 <LI>Failure to find new minimum.
207 <LI>Value of <TT>EDM</TT> too big (estimated Distance to Minimum).
208 <LI>Correlation coefficients exactly equal to zero, unless some parameters
209 are known to be uncorrelated with the others.
210 <LI>Correlation coefficients very close to one (greater than 0.99). This
211 indicates both an exceptionally difficult problem, and one which has been
212 badly parameterized so that individual errors are not very meaningful
213 because they are so highly correlated.
214 <LI>Parameter at limit. This condition, signalled by a MINUIT warning
215 message, may make both the function minimum and parameter errors
216 unreliable. See the discussion above ``Getting the right parameter errors
217 with limits''.
218 </OL>
219 <P>
220 The best way to be absolutely sure of the errors, is to use
221 ``independent'' calculations and compare them, or compare the calculated
222 errors with a picture of the function. Theoretically, the covariance
223 matrix for a ``physical'' function must be positive-definite at the
224 minimum, although it may not be so for all points far away from the
225 minimum, even for a well-determined physical problem. Therefore, if MIGRAD
226 reports that it has found a non-positive-definite covariance matrix, this
227 may be a sign of one or more of the following:
228 <P>
229 <H5>A non-physical region:</H5>
230 <P>
231 On its way to the minimum, MIGRAD may have traversed a region which has
232 unphysical behaviour, which is of course not a serious problem as long as
233 it recovers and leaves such a region.
234 <P>
235 <H5>An underdetermined problem:</H5>
236 <P>
237 If the matrix is not positive-definite even at the minimum, this may mean
238 that the solution is not well-defined, for example that there are more
239 unknowns than there are data points, or that the parameterization of the
240 fit contains a linear dependence. If this is the case, then MINUIT (or any
241 other program) cannot solve your problem uniquely, and the error matrix
242 will necessarily be largely meaningless, so the user must remove the
243 underdeterminedness by reformulating the parameterization. MINUIT cannot
244 do this itself.
245 <P>
246 <H5>Numerical inaccuracies:</H5>
247 <P>
248 It is possible that the apparent lack of positive-definiteness is in fact
249 only due to excessive roundoff errors in numerical calculations in the
250 user function or not enough precision. This is unlikely in general, but
251 becomes more likely if the number of free parameters is very large, or if
252 
253 the parameters are badly scaled (not all of the same order of magnitude),
254 and correlations are also large. In any case, whether the
255 non-positive-definiteness is real or only numerical is largely irrelevant,
256 since in both cases the error matrix will be unreliable and the minimum
257 suspicious.
258 <P>
259 <H5>An ill-posed problem:</H5>
260 <P>
261 For questions of parameter dependence, see the discussion above on
262 positive-definiteness.
263 <P>
264 Possible other mathematical problems are the following:
265 <P>
266 <H5>Excessive numerical roundoff:</H5>
267 <P>
268 Be especially careful of exponential and factorial functions which get big
269 very quickly and lose accuracy.
270 <P>
271 <H5>Starting too far from the solution:</H5>
272 <P>
273 The function may have unphysical local minima, especially at infinity in
274 some variables.
275 
276 <H5>Minuit parameter errors in the presence of limits</H5>
277 This concerns the way Minuit reports the symmetric (or parabolic) errors
278 on parameters. It does not apply to the errors reported from Minos, which
279 are in general asymmetric.
280 <P>
281 The symmetric errors reported by Minuit are always calculated from
282 the covariance matrix, assuming that this matrix has been calculated,
283 usually as the result of a Migrad minimization or a direct
284 calculation by Hesse which inverts the second derivative matrix.
285 <P>
286 When there are no limits on the parameter in question, the error reported
287 by Minuit should therefore be exactly equal to the square root of the
288 corresponding diagonal element of the error matrix reported by Minuit.
289 <P>
290 However, when there are limits on the parameter, there is a transformation
291 between the internal parameter values seen by Minuit (which are unbounded)
292 and the external parameter values seen by the user in FCN (which remain
293 inside the desired limits). Therefore the internal error matrix kept by
294 Minuit must be transformed to an external error matrix for the user.
295 This is done by multiplying the (I,J)th element by DEXDIN(I)*DEXDIN(J),
296 where DEXDIN is the derivative of the external value with respect to the
297 internal value at the minimum. This is a linearization of the
298 transformation, and is the only way to produce an error matrix in external
299 coordinates meaningful to the user. But when reporting the individual
300 parabolic errors for limited parameters, Minuit can do a little better, so
301 it does. In this case, Minuit actually transforms the ends of the
302 internal "error bar" to external coordinates and reports the length of
303 this transformed interval. Strictly speaking, it is now asymmetric, but
304 since the origin of the asymmetry is only an artificial transformation it
305 does not make much sense, so the transformed errors are symmetrized.
306 <P>
307 The result of all the above is that for parameters with limits, the error
308 reported by Minuit is not exactly equal to the square root of the diagonal
309 element of the error matrix. The difference is a measure of how much the
310 limits deform the problem. If possible, it is suggested not to use limits
311 on parameters, and the problem goes away. If for some reason limits are
312 necessary, and you are sensitive to the difference between the two ways of
313 calculating the errors, it is suggested to use Minos errors which take
314 into account the non-linearities much more precisely.
315 
316 @ingroup MinuitOld
317 
318 */
319 
320 #include <stdlib.h>
321 #include <stdio.h>
322 
323 #include "TROOT.h"
324 #include "TMinuit.h"
325 #include "TMath.h"
326 #include "TError.h"
327 #include "TPluginManager.h"
328 #include "TClass.h"
329 #include "TInterpreter.h"
330 
332 
333 const char charal[29] = " .ABCDEFGHIJKLMNOPQRSTUVWXYZ";
334 
336 
337 ////////////////////////////////////////////////////////////////////////////////
338 ///*-*-*-*-*-*-*-*-*-*-*Minuit normal constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
339 ///*-* ========================
340 
341 TMinuit::TMinuit(): TNamed("MINUIT","The Minimization package")
342 {
343  if (TMinuit::Class()->IsCallingNew() != TClass::kRealNew) {
344  //preset all pointers to null
345  fCpnam = 0;
346  fU = 0;
347  fAlim = 0;
348  fBlim = 0;
349  fPstar = 0;
350  fGin = 0;
351  fNvarl = 0;
352  fNiofex = 0;
353 
354  fNexofi = 0;
355  fIpfix = 0;
356  fErp = 0;
357  fErn = 0;
358  fWerr = 0;
359  fGlobcc = 0;
360  fX = 0;
361  fXt = 0;
362  fDirin = 0;
363  fXs = 0;
364  fXts = 0;
365  fDirins = 0;
366  fGrd = 0;
367  fG2 = 0;
368  fGstep = 0;
369  fDgrd = 0;
370  fGrds = 0;
371  fG2s = 0;
372  fGsteps = 0;
373  fPstst = 0;
374  fPbar = 0;
375  fPrho = 0;
376  fWord7 = 0;
377  fVhmat = 0;
378  fVthmat = 0;
379  fP = 0;
380  fXpt = 0;
381  fYpt = 0;
382  fChpt = 0;
383  fCONTgcc = 0;
384  fCONTw = 0;
385  fFIXPyy = 0;
386  fGRADgf = 0;
387  fHESSyy = 0;
388  fIMPRdsav = 0;
389  fIMPRy = 0;
390  fMATUvline = 0;
391  fMIGRflnu = 0;
392  fMIGRstep = 0;
393  fMIGRgs = 0;
394  fMIGRvg = 0;
395  fMIGRxxs = 0;
396  fMNOTxdev = 0;
397  fMNOTw = 0;
398  fMNOTgcc = 0;
399  fPSDFs = 0;
400  fSEEKxmid = 0;
401  fSEEKxbest = 0;
402  fSIMPy = 0;
403  fVERTq = 0;
404  fVERTs = 0;
405  fVERTpp = 0;
406  fCOMDplist = 0;
407  fPARSplist = 0;
408 
409  fUp = 0;
410  fEpsi = 0;
411  fApsi = 0;
412  fXmidcr = 0;
413  fYmidcr = 0;
414  fXdircr = 0;
415  fYdircr = 0;
416 
417  fStatus = 0;
418  fEmpty = 0;
419  fObjectFit = 0;
420  fMethodCall = 0;
421  fPlot = 0;
422  fGraphicsMode = kTRUE;
423 
424  } else {
425  BuildArrays(25);
426 
427  fUp = 0;
428  fEpsi = 0;
429  fApsi = 0;
430  fXmidcr = 0;
431  fYmidcr = 0;
432  fXdircr = 0;
433  fYdircr = 0;
434 
435  fStatus = 0;
436  fEmpty = 0;
437  fObjectFit = 0;
438  fMethodCall = 0;
439  fPlot = 0;
440  fGraphicsMode = kTRUE;
441  SetMaxIterations();
442  mninit(5,6,7);
443  }
444 
445  fFCN = 0;
446  gMinuit = this;
447  {
449  gROOT->GetListOfSpecials()->Add(gMinuit);
450  }
451 }
452 
453 ////////////////////////////////////////////////////////////////////////////////
454 ///*-*-*-*-*-*-*-*-*-*-*Minuit normal constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
455 ///*-* ========================
456 ///
457 /// maxpar is the maximum number of parameters used with this TMinuit object.
458 
459 TMinuit::TMinuit(Int_t maxpar): TNamed("MINUIT","The Minimization package")
460 {
461  fFCN = 0;
462 
463  BuildArrays(maxpar);
464 
465  fStatus = 0;
466  fEmpty = 0;
467  fObjectFit = 0;
468  fMethodCall = 0;
469  fPlot = 0;
472 
473  mninit(5,6,7);
474  gMinuit = this;
475  {
477  gROOT->GetListOfSpecials()->Add(gMinuit);
478  }
479 }
480 
481 ////////////////////////////////////////////////////////////////////////////////
482 /// Private TMinuit copy ctor. TMinuit can not be copied.
483 
484 TMinuit::TMinuit(const TMinuit &minuit) : TNamed(minuit)
485 {
486  Error("TMinuit", "can not copy construct TMinuit");
487 }
488 
489 ////////////////////////////////////////////////////////////////////////////////
490 ///*-*-*-*-*-*-*-*-*-*-*Minuit default destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
491 ///*-* =========================
492 
494 {
495  DeleteArrays();
496  delete fPlot;
497  delete fMethodCall;
498  {
500  if (gROOT != 0 && gROOT->GetListOfSpecials() != 0) gROOT->GetListOfSpecials()->Remove(this);
501  }
502  if (gMinuit == this) gMinuit = 0;
503 }
504 
505 ////////////////////////////////////////////////////////////////////////////////
506 ///*-*-*-*-*-*-*Create internal Minuit arrays for the maxpar parameters*-*-*-*
507 ///*-* =======================================================
508 
510 {
511  fMaxpar = 25;
512  if (maxpar >= fMaxpar) fMaxpar = maxpar+1;
513  fMaxpar1= fMaxpar*(fMaxpar+1);
514  fMaxpar2= 2*fMaxpar;
515  fMaxpar5= fMaxpar1/2;
516  fMaxcpt = 101;
517  fCpnam = new TString[fMaxpar2];
518  fU = new Double_t[fMaxpar2];
519  fAlim = new Double_t[fMaxpar2];
520  fBlim = new Double_t[fMaxpar2];
521  fPstar = new Double_t[fMaxpar2];
522  fGin = new Double_t[fMaxpar2];
523  fNvarl = new Int_t[fMaxpar2];
524  fNiofex = new Int_t[fMaxpar2];
525 
526  fNexofi = new Int_t[fMaxpar];
527  fIpfix = new Int_t[fMaxpar];
528  fErp = new Double_t[fMaxpar];
529  fErn = new Double_t[fMaxpar];
530  fWerr = new Double_t[fMaxpar];
531  fGlobcc = new Double_t[fMaxpar];
532  fX = new Double_t[fMaxpar];
533  fXt = new Double_t[fMaxpar];
534  fDirin = new Double_t[fMaxpar];
535  fXs = new Double_t[fMaxpar];
536  fXts = new Double_t[fMaxpar];
537  fDirins = new Double_t[fMaxpar];
538  fGrd = new Double_t[fMaxpar];
539  fG2 = new Double_t[fMaxpar];
540  fGstep = new Double_t[fMaxpar];
541  fDgrd = new Double_t[fMaxpar];
542  fGrds = new Double_t[fMaxpar];
543  fG2s = new Double_t[fMaxpar];
544  fGsteps = new Double_t[fMaxpar];
545  fPstst = new Double_t[fMaxpar];
546  fPbar = new Double_t[fMaxpar];
547  fPrho = new Double_t[fMaxpar];
548  fWord7 = new Double_t[fMaxpar];
549  fVhmat = new Double_t[fMaxpar5];
550  fVthmat = new Double_t[fMaxpar5];
551  fP = new Double_t[fMaxpar1];
552  fXpt = new Double_t[fMaxcpt];
553  fYpt = new Double_t[fMaxcpt];
554  fChpt = new char[fMaxcpt+1];
555  // initialisation of dynamic arrays used internally in some functions
556  // these arrays had a fix dimension in Minuit
557  fCONTgcc = new Double_t[fMaxpar];
558  fCONTw = new Double_t[fMaxpar];
559  fFIXPyy = new Double_t[fMaxpar];
560  fGRADgf = new Double_t[fMaxpar];
561  fHESSyy = new Double_t[fMaxpar];
562  fIMPRdsav = new Double_t[fMaxpar];
563  fIMPRy = new Double_t[fMaxpar];
564  fMATUvline = new Double_t[fMaxpar];
565  fMIGRflnu = new Double_t[fMaxpar];
566  fMIGRstep = new Double_t[fMaxpar];
567  fMIGRgs = new Double_t[fMaxpar];
568  fMIGRvg = new Double_t[fMaxpar];
569  fMIGRxxs = new Double_t[fMaxpar];
570  fMNOTxdev = new Double_t[fMaxpar];
571  fMNOTw = new Double_t[fMaxpar];
572  fMNOTgcc = new Double_t[fMaxpar];
573  fPSDFs = new Double_t[fMaxpar];
574  fSEEKxmid = new Double_t[fMaxpar];
575  fSEEKxbest = new Double_t[fMaxpar];
576  fSIMPy = new Double_t[fMaxpar];
577  fVERTq = new Double_t[fMaxpar];
578  fVERTs = new Double_t[fMaxpar];
579  fVERTpp = new Double_t[fMaxpar];
580  fCOMDplist = new Double_t[fMaxpar];
581  fPARSplist = new Double_t[fMaxpar];
582 
583  for (int i = 0; i < fMaxpar; i++) {
584  fErp[i] = 0;
585  fErn[i] = 0;
586  }
587 }
588 
589 
590 ////////////////////////////////////////////////////////////////////////////////
591 /// Make a clone of an object using the Streamer facility.
592 /// Function pointer is copied to Clone
593 
594 TObject *TMinuit::Clone(const char *newname) const
595 {
596  TMinuit *named = (TMinuit*)TNamed::Clone(newname);
597  named->fFCN=fFCN;
598  return named;
599 }
600 
601 
602 ////////////////////////////////////////////////////////////////////////////////
603 /// execute a Minuit command
604 /// Equivalent to MNEXCM except that the command is given as a
605 /// character string.
606 /// See TMinuit::mnhelp for the full list of available commands
607 /// See also http://wwwasdoc.web.cern.ch/wwwasdoc/minuit/node18.html for
608 /// a complete documentation of all the available commands
609 ///
610 /// Returns the status of the execution:
611 /// = 0: command executed normally
612 /// 1: command is blank, ignored
613 /// 2: command line unreadable, ignored
614 /// 3: unknown command, ignored
615 /// 4: abnormal termination (e.g., MIGRAD not converged)
616 /// 5: command is a request to read PARAMETER definitions
617 /// 6: 'SET INPUT' command
618 /// 7: 'SET TITLE' command
619 /// 8: 'SET COVAR' command
620 /// 9: reserved
621 /// 10: END command
622 /// 11: EXIT or STOP command
623 /// 12: RETURN command
624 ///
625 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
626 
627 Int_t TMinuit::Command(const char *command)
628 {
629  Int_t status = 0;
630  mncomd(command,status);
631  return status;
632 }
633 
634 ////////////////////////////////////////////////////////////////////////////////
635 /// Creates a TGraph object describing the n-sigma contour of a
636 /// TMinuit fit. The contour of the parameters pa1 and pa2 is calculated
637 /// unsing npoints (>=4) points. The TMinuit status will be
638 /// 0 on success and
639 /// -1 if errors in the calling sequence (pa1, pa2 not variable)
640 /// 1 if less than four points can be found
641 /// 2 if npoints<4
642 /// n>3 if only n points can be found (n < npoints)
643 /// The status can be obtained via TMinuit::GetStatus().
644 ///
645 /// To get the n-sigma contour the ERRDEF parameter in Minuit has to set
646 /// to n^2. The fcn function has to be set before the routine is called.
647 ///
648 /// The TGraph object is created via the interpreter. The user must cast it
649 /// to a TGraph*. Note that the TGraph is created with npoints+1 in order to
650 /// close the contour (setting last point equal to first point).
651 ///
652 /// You can find an example in $ROOTSYS/tutorials/fit/fitcont.C
653 
655 {
656  if (npoints<4) {
657  // we need at least 4 points
658  fStatus= 2;
659  return (TObject *)0;
660  }
661  Int_t npfound;
662  Double_t *xcoor = new Double_t[npoints+1];
663  Double_t *ycoor = new Double_t[npoints+1];
664  mncont(pa1,pa2,npoints,xcoor,ycoor,npfound);
665  if (npfound<4) {
666  // mncont did go wrong
667  Warning("Contour","Cannot find more than 4 points, no TGraph returned");
668  fStatus= (npfound==0 ? 1 : npfound);
669  delete [] xcoor;
670  delete [] ycoor;
671  return (TObject *)0;
672  }
673  if (npfound!=npoints) {
674  // mncont did go wrong
675  Warning("Contour","Returning a TGraph with %d points only",npfound);
676  npoints = npfound;
677  }
678  fStatus=0;
679  // create graph via the PluginManager
680  xcoor[npoints] = xcoor[0]; // add first point at end to get closed polyline
681  ycoor[npoints] = ycoor[0];
682  TObject *gr = 0;
683  TPluginHandler *h;
684  if ((h = gROOT->GetPluginManager()->FindHandler("TMinuitGraph"))) {
685  if (h->LoadPlugin() != -1)
686  gr = (TObject*)h->ExecPlugin(3,npoints+1,xcoor,ycoor);
687  }
688  delete [] xcoor;
689  delete [] ycoor;
690  return gr;
691 }
692 
693 ////////////////////////////////////////////////////////////////////////////////
694 /// Define a parameter
695 
696 Int_t TMinuit::DefineParameter( Int_t parNo, const char *name, Double_t initVal, Double_t initErr, Double_t lowerLimit, Double_t upperLimit )
697 {
698  Int_t err;
699 
700  TString sname = name;
701  mnparm( parNo, sname, initVal, initErr, lowerLimit, upperLimit, err);
702 
703  return err;
704 }
705 
706 ////////////////////////////////////////////////////////////////////////////////
707 ///*-*-*-*-*-*-*-*-*-*-*-*Delete internal Minuit arrays*-*-*-*-*-*-*-*-*
708 ///*-* =============================
709 
711 {
712  if (fEmpty) return;
713  delete [] fCpnam;
714  delete [] fU;
715  delete [] fAlim;
716  delete [] fBlim;
717  delete [] fErp;
718  delete [] fErn;
719  delete [] fWerr;
720  delete [] fGlobcc;
721  delete [] fNvarl;
722  delete [] fNiofex;
723  delete [] fNexofi;
724  delete [] fX;
725  delete [] fXt;
726  delete [] fDirin;
727  delete [] fXs;
728  delete [] fXts;
729  delete [] fDirins;
730  delete [] fGrd;
731  delete [] fG2;
732  delete [] fGstep;
733  delete [] fGin;
734  delete [] fDgrd;
735  delete [] fGrds;
736  delete [] fG2s;
737  delete [] fGsteps;
738  delete [] fIpfix;
739  delete [] fVhmat;
740  delete [] fVthmat;
741  delete [] fP;
742  delete [] fPstar;
743  delete [] fPstst;
744  delete [] fPbar;
745  delete [] fPrho;
746  delete [] fWord7;
747  delete [] fXpt;
748  delete [] fYpt;
749  delete [] fChpt;
750 
751  delete [] fCONTgcc;
752  delete [] fCONTw;
753  delete [] fFIXPyy;
754  delete [] fGRADgf;
755  delete [] fHESSyy;
756  delete [] fIMPRdsav;
757  delete [] fIMPRy;
758  delete [] fMATUvline;
759  delete [] fMIGRflnu;
760  delete [] fMIGRstep;
761  delete [] fMIGRgs;
762  delete [] fMIGRvg;
763  delete [] fMIGRxxs;
764  delete [] fMNOTxdev;
765  delete [] fMNOTw;
766  delete [] fMNOTgcc;
767  delete [] fPSDFs;
768  delete [] fSEEKxmid;
769  delete [] fSEEKxbest;
770  delete [] fSIMPy;
771  delete [] fVERTq;
772  delete [] fVERTs;
773  delete [] fVERTpp;
774  delete [] fCOMDplist;
775  delete [] fPARSplist;
776 
777  fEmpty = 1;
778 }
779 
780 ////////////////////////////////////////////////////////////////////////////////
781 /// Evaluate the minimisation function
782 /// Input parameters:
783 /// npar: number of currently variable parameters
784 /// par: array of (constant and variable) parameters
785 /// flag: Indicates what is to be calculated (see example below)
786 /// grad: array of gradients
787 /// Output parameters:
788 /// fval: The calculated function value.
789 /// grad: The (optional) vector of first derivatives).
790 ///
791 /// The meaning of the parameters par is of course defined by the user,
792 /// who uses the values of those parameters to calculate their function value.
793 /// The starting values must be specified by the user.
794 /// Later values are determined by Minuit as it searches for the minimum
795 /// or performs whatever analysis is requested by the user.
796 ///
797 /// Note that this virtual function may be redefined in a class derived from TMinuit.
798 /// The default function calls the function specified in SetFCN
799 ///
800 /// Example of Minimisation function:
801 
803 {
804 /*
805  if (flag == 1) {
806  read input data,
807  calculate any necessary constants, etc.
808  }
809  if (flag == 2) {
810  calculate GRAD, the first derivatives of FVAL
811  (this is optional)
812  }
813  Always calculate the value of the function, FVAL,
814  which is usually a chisquare or log likelihood.
815  if (iflag == 3) {
816  will come here only after the fit is finished.
817  Perform any final calculations, output fitted data, etc.
818  }
819 */
820 // See concrete examples in TH1::H1FitChisquare, H1FitLikelihood
821 
822  if (fFCN) (*fFCN)(npar,grad,fval,par,flag);
823  return 0;
824 }
825 
826 ////////////////////////////////////////////////////////////////////////////////
827 /// fix a parameter
828 
830 {
831  Int_t err;
832  Double_t tmp[1];
833  tmp[0] = parNo+1; //set internal Minuit numbering
834 
835  mnexcm( "FIX", tmp, 1, err );
836 
837  return err;
838 }
839 
840 ////////////////////////////////////////////////////////////////////////////////
841 /// return parameter value and error
842 
843 Int_t TMinuit::GetParameter( Int_t parNo, Double_t &currentValue, Double_t &currentError ) const
844 {
845  Int_t err;
846  TString name; // ignored
847  Double_t bnd1, bnd2; // ignored
848 
849  mnpout( parNo, name, currentValue, currentError, bnd1, bnd2, err );
850 
851  return err;
852 }
853 
854 ////////////////////////////////////////////////////////////////////////////////
855 /// returns the number of currently fixed parameters
856 
858 {
859  return fNpfix;
860 }
861 
862 ////////////////////////////////////////////////////////////////////////////////
863 /// returns the number of currently free parameters
864 
866 {
867  return fNpar;
868 }
869 
870 ////////////////////////////////////////////////////////////////////////////////
871 /// returns the total number of parameters that have been defined
872 /// as fixed or free. The constant parameters are not counted.
873 
875 {
876  return fNpar + fNpfix;
877 }
878 
879 ////////////////////////////////////////////////////////////////////////////////
880 /// invokes the MIGRAD minimizer
881 
883 {
884  Int_t err;
885  Double_t tmp[1];
886  tmp[0] = 0;
887 
888  mnexcm( "MIGRAD", tmp, 0, err );
889 
890  return err;
891 }
892 
893 ////////////////////////////////////////////////////////////////////////////////
894 /// release a parameter
895 
897 {
898  Int_t err;
899  Double_t tmp[1];
900  tmp[0] = parNo+1; //set internal Minuit numbering
901 
902  mnexcm( "RELEASE", tmp, 1, err );
903 
904  return err;
905 }
906 
907 ////////////////////////////////////////////////////////////////////////////////
908 /// To get the n-sigma contour the error def parameter "up" has to set to n^2.
909 
911 {
912  Int_t err;
913 
914  mnexcm( "SET ERRDEF", &up, 1, err );
915 
916  return err;
917 }
918 
919 ////////////////////////////////////////////////////////////////////////////////
920 ///*-*-*-*-*-*-*To set the address of the minimization function*-*-*-*-*-*-*-*
921 ///*-* ===============================================
922 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
923 
924 void TMinuit::SetFCN(void (*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
925 {
926  fFCN = fcn;
927 }
928 
929 ////////////////////////////////////////////////////////////////////////////////
930 ///*-*-*-*-*-*-*Static function called when SetFCN is called in interactive mode
931 ///*-* ===============================================
932 
933 void InteractiveFCNm(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
934 {
935  TMethodCall *m = gMinuit->GetMethodCall();
936  if (!m) return;
937 
938  Long_t args[5];
939  args[0] = (Long_t)&npar;
940  args[1] = (Long_t)gin;
941  args[2] = (Long_t)&f;
942  args[3] = (Long_t)u;
943  args[4] = (Long_t)flag;
944  m->SetParamPtrs(args);
946  m->Execute(result);
947 }
948 
949 ////////////////////////////////////////////////////////////////////////////////
950 ///*-*-*-*-*-*-*To set the address of the minimization function*-*-*-*-*-*-*-*
951 ///*-* ===============================================
952 /// this function is called by CINT instead of the function above
953 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
954 
955 void TMinuit::SetFCN(void *fcn)
956 {
957  if (!fcn) return;
958 
959  const char *funcname = gCling->Getp2f2funcname(fcn);
960  if (funcname) {
961  fMethodCall = new TMethodCall();
962  fMethodCall->InitWithPrototype(funcname,"Int_t&,Double_t*,Double_t&,Double_t*,Int_t");
963  }
965  {
967  }
968  gMinuit = this; //required by InteractiveFCNm
969 }
970 
971 ////////////////////////////////////////////////////////////////////////////////
972 ///set Minuit print level
973 /// printlevel = -1 quiet (also suppresse all warnings)
974 /// = 0 normal
975 /// = 1 verbose
976 
978 {
979  Int_t err;
980  Double_t tmp[1];
981  tmp[0] = printLevel;
982 
983  mnexcm( "SET PRINT", tmp, 1, err );
984 
985  if (printLevel <=-1) mnexcm("SET NOWarnings",tmp,0,err);
986 
987  return err;
988 }
989 
990 ////////////////////////////////////////////////////////////////////////////////
991 ///*-*-*-*-*-*-*-*-*-*-*-*-*Initialize AMIN*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
992 ///*-* ===============
993 ///*-*C Called from many places. Initializes the value of AMIN by
994 ///*-*C calling the user function. Prints out the function value and
995 ///*-*C parameter values if Print Flag value is high enough.
996 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
997 
999 {
1000  /* Local variables */
1001  Double_t fnew;
1002  Int_t nparx;
1003 
1004  nparx = fNpar;
1005  if (fISW[4] >= 1) {
1006  Printf(" FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.");
1007  }
1008  mnexin(fX);
1009  Eval(nparx, fGin, fnew, fU, 4); ++fNfcn;
1010  fAmin = fnew;
1011  fEDM = fBigedm;
1012 } /* mnamin_ */
1013 
1014 ////////////////////////////////////////////////////////////////////////////////
1015 ///*-*-*-*-*-*-*-*-*-*-*Compute reasonable histogram intervals*-*-*-*-*-*-*-*-*
1016 ///*-* ======================================
1017 ///*-* Function TO DETERMINE REASONABLE HISTOGRAM INTERVALS
1018 ///*-* GIVEN ABSOLUTE UPPER AND LOWER BOUNDS A1 AND A2
1019 ///*-* AND DESIRED MAXIMUM NUMBER OF BINS NAA
1020 ///*-* PROGRAM MAKES REASONABLE BINNING FROM BL TO BH OF WIDTH BWID
1021 ///*-* F. JAMES, AUGUST, 1974 , stolen for Minuit, 1988
1022 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1023 
1024 void TMinuit::mnbins(Double_t a1, Double_t a2, Int_t naa, Double_t &bl, Double_t &bh, Int_t &nb, Double_t &bwid)
1025 {
1026  /* Local variables */
1027  Double_t awid,ah, al, sigfig, sigrnd, alb;
1028  Int_t kwid, lwid, na=0, log_;
1029 
1030  al = TMath::Min(a1,a2);
1031  ah = TMath::Max(a1,a2);
1032  if (al == ah) ah = al + 1;
1033 
1034 //*-*- IF NAA .EQ. -1 , PROGRAM USES BWID INPUT FROM CALLING ROUTINE
1035  if (naa == -1) goto L150;
1036 L10:
1037  na = naa - 1;
1038  if (na < 1) na = 1;
1039 
1040 //*-*- GET NOMINAL BIN WIDTH IN EXPON FORM
1041 L20:
1042  awid = (ah-al) / Double_t(na);
1043  log_ = Int_t(TMath::Log10(awid));
1044  if (awid <= 1) --log_;
1045  sigfig = awid*TMath::Power(10, -log_);
1046 //*-*- ROUND MANTISSA UP TO 2, 2.5, 5, OR 10
1047  if (sigfig > 2) goto L40;
1048  sigrnd = 2;
1049  goto L100;
1050 L40:
1051  if (sigfig > 2.5) goto L50;
1052  sigrnd = 2.5;
1053  goto L100;
1054 L50:
1055  if (sigfig > 5) goto L60;
1056  sigrnd = 5;
1057  goto L100;
1058 L60:
1059  sigrnd = 1;
1060  ++log_;
1061 L100:
1062  bwid = sigrnd*TMath::Power(10, log_);
1063  goto L200;
1064 //*-*- GET NEW BOUNDS FROM NEW WIDTH BWID
1065 L150:
1066  if (bwid <= 0) goto L10;
1067 L200:
1068  alb = al / bwid;
1069  lwid = Int_t(alb);
1070  if (alb < 0) --lwid;
1071  bl = bwid*Double_t(lwid);
1072  alb = ah / bwid + 1;
1073  kwid = Int_t(alb);
1074  if (alb < 0) --kwid;
1075  bh = bwid*Double_t(kwid);
1076  nb = kwid - lwid;
1077  if (naa > 5) goto L240;
1078  if (naa == -1) return;
1079 //*-*- REQUEST FOR ONE BIN IS DIFFICULT CASE
1080  if (naa > 1 || nb == 1) return;
1081  bwid *= 2;
1082  nb = 1;
1083  return;
1084 L240:
1085  if (nb << 1 != naa) return;
1086  ++na;
1087  goto L20;
1088 } /* mnbins_ */
1089 
1090 ////////////////////////////////////////////////////////////////////////////////
1091 ///*-*-*-*-*-*-*-*-*-*Transform FCN to find further minima*-*-*-*-*-*-*-*-*-*
1092 ///*-* ====================================
1093 ///*-* Called only from MNIMPR. Transforms the function FCN
1094 ///*-* by dividing out the quadratic part in order to find further
1095 ///*-* minima. Calculates ycalf = (f-fmin)/(x-xmin)*v*(x-xmin)
1096 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1097 
1098 void TMinuit::mncalf(Double_t *pvec, Double_t &ycalf)
1099 {
1100  /* Local variables */
1101  Int_t ndex, i, j, m, n, nparx;
1102  Double_t denom, f;
1103 
1104  nparx = fNpar;
1105  mninex(&pvec[0]);
1106  Eval(nparx, fGin, f, fU, 4); ++fNfcn;
1107  for (i = 1; i <= fNpar; ++i) {
1108  fGrd[i-1] = 0;
1109  for (j = 1; j <= fNpar; ++j) {
1110  m = TMath::Max(i,j);
1111  n = TMath::Min(i,j);
1112  ndex = m*(m-1) / 2 + n;
1113  fGrd[i-1] += fVthmat[ndex-1]*(fXt[j-1] - pvec[j-1]);
1114  }
1115  }
1116  denom = 0;
1117  for (i = 1; i <= fNpar; ++i) {denom += fGrd[i-1]*(fXt[i-1] - pvec[i-1]); }
1118  if (denom <= 0) {
1119  fDcovar = 1;
1120  fISW[1] = 0;
1121  denom = 1;
1122  }
1123  ycalf = (f - fApsi) / denom;
1124 } /* mncalf_ */
1125 
1126 ////////////////////////////////////////////////////////////////////////////////
1127 ///*-*-*-*-*-*-*-*-*-*-*Resets the parameter list to UNDEFINED*-*-*-*-*-*-*-*
1128 ///*-* ======================================
1129 ///*-* Called from MINUIT and by option from MNEXCM
1130 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1131 
1133 {
1134  Int_t i;
1135 
1136  fNpfix = 0;
1137  fNu = 0;
1138  fNpar = 0;
1139  fNfcn = 0;
1140  fNwrmes[0] = 0;
1141  fNwrmes[1] = 0;
1142  for (i = 1; i <= fMaxext; ++i) {
1143  fU[i-1] = 0;
1144  fCpnam[i-1] = fCundef;
1145  fNvarl[i-1] = -1;
1146  fNiofex[i-1] = 0;
1147  }
1148  mnrset(1);
1149  fCfrom = "CLEAR ";
1150  fNfcnfr = fNfcn;
1151  fCstatu = "UNDEFINED ";
1152  fLnolim = kTRUE;
1153  fLphead = kTRUE;
1154 } /* mncler_ */
1155 
1156 ////////////////////////////////////////////////////////////////////////////////
1157 ///*-*-*-*-*Print function contours in two variables, on line printer*-*-*-*-*
1158 ///*-* =========================================================
1159 ///*-*
1160 ///*-* input arguments: parx, pary, devs, ngrid
1161 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1162 
1163 void TMinuit::mncntr(Int_t ike1, Int_t ike2, Int_t &ierrf)
1164 {
1165  static TString clabel = "0123456789ABCDEFGHIJ";
1166 
1167  /* Local variables */
1168  Double_t d__1, d__2;
1169  Double_t fcna[115], fcnb[115], contur[20];
1170  Double_t ylabel, fmn, fmx, xlo, ylo, xup, yup;
1171  Double_t devs, xsav, ysav, bwidx, bwidy, unext, ff, xb4;
1172  Int_t i, ngrid, ixmid, nparx, ix, nx, ny, ki1, ki2, ixzero, iy, ics;
1173  TString chmid, chln, chzero;
1174 
1175  Int_t ke1 = ike1+1;
1176  Int_t ke2 = ike2+1;
1177  if (ke1 <= 0 || ke2 <= 0) goto L1350;
1178  if (ke1 > fNu || ke2 > fNu) goto L1350;
1179  ki1 = fNiofex[ke1-1];
1180  ki2 = fNiofex[ke2-1];
1181  if (ki1 <= 0 || ki2 <= 0) goto L1350;
1182  if (ki1 == ki2) goto L1350;
1183 
1184  if (fISW[1] < 1) {
1185  mnhess();
1186  mnwerr();
1187  }
1188  nparx = fNpar;
1189  xsav = fU[ke1-1];
1190  ysav = fU[ke2-1];
1191  devs = fWord7[2];
1192  if (devs <= 0) devs = 2;
1193  xlo = fU[ke1-1] - devs*fWerr[ki1-1];
1194  xup = fU[ke1-1] + devs*fWerr[ki1-1];
1195  ylo = fU[ke2-1] - devs*fWerr[ki2-1];
1196  yup = fU[ke2-1] + devs*fWerr[ki2-1];
1197  ngrid = Int_t(fWord7[3]);
1198  if (ngrid <= 0) {
1199  ngrid = 25;
1200 //*-* Computing MIN
1201  nx = TMath::Min(fNpagwd - 15,ngrid);
1202 //*-* Computing MIN
1203  ny = TMath::Min(fNpagln - 7,ngrid);
1204  } else {
1205  nx = ngrid;
1206  ny = ngrid;
1207  }
1208  if (nx < 11) nx = 11;
1209  if (ny < 11) ny = 11;
1210  if (nx >= 115) nx = 114;
1211 
1212 //*-*- ask if parameter outside limits
1213  if (fNvarl[ke1-1] > 1) {
1214  if (xlo < fAlim[ke1-1]) xlo = fAlim[ke1-1];
1215  if (xup > fBlim[ke1-1]) xup = fBlim[ke1-1];
1216  }
1217  if (fNvarl[ke2-1] > 1) {
1218  if (ylo < fAlim[ke2-1]) ylo = fAlim[ke2-1];
1219  if (yup > fBlim[ke2-1]) yup = fBlim[ke2-1];
1220  }
1221  bwidx = (xup - xlo) / Double_t(nx);
1222  bwidy = (yup - ylo) / Double_t(ny);
1223  ixmid = Int_t(((xsav - xlo)*Double_t(nx) / (xup - xlo)) + 1);
1224  if (ixmid < 1) ixmid = 1;
1225  if (fAmin == fUndefi) mnamin();
1226 
1227  for (i = 1; i <= 20; ++i) { contur[i-1] = fAmin + fUp*(i-1)*(i-1); }
1228  contur[0] += fUp*.01;
1229 //*-*- fill FCNB to prepare first row, and find column zero/
1230  fU[ke2-1] = yup;
1231  ixzero = 0;
1232  xb4 = 1;
1233 //TH
1234  chmid.Resize(nx+1);
1235  chzero.Resize(nx+1);
1236  chln.Resize(nx+1);
1237  for (ix = 1; ix <= nx + 1; ++ix) {
1238  fU[ke1-1] = xlo + Double_t(ix-1)*bwidx;
1239  Eval(nparx, fGin, ff, fU, 4);
1240  fcnb[ix-1] = ff;
1241  if (xb4 < 0 && fU[ke1-1] > 0) ixzero = ix - 1;
1242  xb4 = fU[ke1-1];
1243  chmid[ix-1] = '*';
1244  chzero[ix-1] = '-';
1245  }
1246  Printf(" Y-AXIS: PARAMETER %3d: %s",ke2,(const char*)fCpnam[ke2-1]);
1247  if (ixzero > 0) {
1248  chzero[ixzero-1] = '+';
1249  chln = " ";
1250  Printf(" X=0");
1251  }
1252 //*-*- loop over rows
1253  for (iy = 1; iy <= ny; ++iy) {
1254  unext = fU[ke2-1] - bwidy;
1255 //*-*- prepare this line background pattern for contour
1256  chln = " ";
1257 // TH
1258  chln.Resize(nx+1);
1259  chln[ixmid-1] = '*';
1260  if (ixzero != 0) chln[ixzero-1] = ':';
1261  if (fU[ke2-1] > ysav && unext < ysav) chln = chmid;
1262  if (fU[ke2-1] > 0 && unext < 0) chln = chzero;
1263  fU[ke2-1] = unext;
1264  ylabel = fU[ke2-1] + bwidy*.5;
1265 //*-*- move FCNB to FCNA and fill FCNB with next row
1266  for (ix = 1; ix <= nx + 1; ++ix) {
1267  fcna[ix-1] = fcnb[ix-1];
1268  fU[ke1-1] = xlo + Double_t(ix-1)*bwidx;
1269  Eval(nparx, fGin, ff, fU, 4);
1270  fcnb[ix-1] = ff;
1271  }
1272 //*-*- look for contours crossing the FCNxy squares
1273  for (ix = 1; ix <= nx; ++ix) {
1274  d__1 = TMath::Max(fcna[ix-1],fcnb[ix-1]),
1275  d__2 = TMath::Max(fcna[ix],fcnb[ix]);
1276  fmx = TMath::Max(d__1,d__2);
1277  d__1 = TMath::Min(fcna[ix-1],fcnb[ix-1]),
1278  d__2 = TMath::Min(fcna[ix],fcnb[ix]);
1279  fmn = TMath::Min(d__1,d__2);
1280  for (ics = 1; ics <= 20; ++ics) {
1281  if (contur[ics-1] > fmn) goto L240;
1282  }
1283  continue;
1284 L240:
1285  if (contur[ics-1] < fmx) chln[ix-1] = clabel[ics-1];
1286  }
1287 //*-*- print a row of the contour plot
1288  Printf(" %12.4g %s",ylabel,(const char*)chln);
1289  }
1290 //*-*- contours printed, label x-axis
1291  chln = " ";
1292  chln(0,1) = 'I';
1293  chln(ixmid-1,1) = 'I';
1294  chln(nx-1,1) = 'I';
1295  Printf(" %s",(const char*)chln);
1296 
1297 //*-*- the hardest of all: print x-axis scale!
1298  chln = " ";
1299  if (nx <= 26) {
1300  Printf(" %12.4g%s%12.4g",xlo,(const char*)chln,xup);
1301  Printf(" %s%12.4g",(const char*)chln,xsav);
1302  } else {
1303  Printf(" %12.4g%s%12.4g%s%12.4g",xlo,(const char*)chln,xsav,(const char*)chln,xup);
1304  }
1305  Printf(" X-AXIS: PARAMETER %3d %s ONE COLUMN=%12.4g"
1306  ,ke1,(const char*)fCpnam[ke1-1],bwidx);
1307  Printf(" FUNCTION VALUES: F(I)=%12.4g +%12.4g *I**2",fAmin,fUp);
1308 //*-*- finished. reset input values
1309  fU[ke1-1] = xsav;
1310  fU[ke2-1] = ysav;
1311  ierrf = 0;
1312  return;
1313 L1350:
1314  Printf(" INVALID PARAMETER NUMBER(S) REQUESTED. IGNORED.");
1315  ierrf = 1;
1316 } /* mncntr_ */
1317 
1318 ////////////////////////////////////////////////////////////////////////////////
1319 ///*-*-*-*-*-*-*-*-*-*-*Reads a command string and executes*-*-*-*-*-*-*-*-*-*
1320 ///*-* ===================================
1321 ///*-* Called by user. 'Reads' a command string and executes.
1322 ///*-* Equivalent to MNEXCM except that the command is given as a
1323 ///*-* character string.
1324 ///*-*
1325 ///*-* ICONDN = 0: command executed normally
1326 ///*-* 1: command is blank, ignored
1327 ///*-* 2: command line unreadable, ignored
1328 ///*-* 3: unknown command, ignored
1329 ///*-* 4: abnormal termination (e.g., MIGRAD not converged)
1330 ///*-* 5: command is a request to read PARAMETER definitions
1331 ///*-* 6: 'SET INPUT' command
1332 ///*-* 7: 'SET TITLE' command
1333 ///*-* 8: 'SET COVAR' command
1334 ///*-* 9: reserved
1335 ///*-* 10: END command
1336 ///*-* 11: EXIT or STOP command
1337 ///*-* 12: RETURN command
1338 ///*-*
1339 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1340 
1341 void TMinuit::mncomd(const char *crdbin, Int_t &icondn)
1342 {
1343  /* Local variables */
1344  Int_t ierr, ipos, i, llist, lenbuf, lnc;
1345  Bool_t leader;
1346  TString comand, crdbuf, ctemp;
1347 
1348  crdbuf = crdbin;
1349  crdbuf.ToUpper();
1350  lenbuf = crdbuf.Length();
1351  icondn = 0;
1352 //*-*- record not case-sensitive, get upper case, strip leading blanks
1353  leader = kTRUE;
1354  ipos = 1;
1355  for (i = 1; i <= TMath::Min(20,lenbuf); ++i) {
1356  if (crdbuf[i-1] == '\'') break;
1357  if (crdbuf[i-1] == ' ') {
1358  if (leader) ++ipos;
1359  continue;
1360  }
1361  leader = kFALSE;
1362  }
1363 
1364 //*-*- blank or null command
1365  if (ipos > lenbuf) {
1366  Printf(" BLANK COMMAND IGNORED.");
1367  icondn = 1;
1368  return;
1369  }
1370 //*-*- . . preemptive commands
1371 //*-*- if command is 'PARAMETER'
1372  if (crdbuf(ipos-1,3) == "PAR") {
1373  icondn = 5;
1374  fLphead = kTRUE;
1375  return;
1376  }
1377 //*-*- if command is 'SET INPUT'
1378  if (crdbuf(ipos-1,3) == "SET INP") {
1379  icondn = 6;
1380  fLphead = kTRUE;
1381  return;
1382  }
1383 //*-*- if command is 'SET TITLE'
1384  if (crdbuf(ipos-1,7) == "SET TIT") {
1385  icondn = 7;
1386  fLphead = kTRUE;
1387  return;
1388  }
1389 //*-*- if command is 'SET COVARIANCE'
1390  if (crdbuf(ipos-1,7) == "SET COV") {
1391  icondn = 8;
1392  fLphead = kTRUE;
1393  return;
1394  }
1395 //*-*- crack the command . . . . . . . . . . . . . . . .
1396  ctemp = crdbuf(ipos-1,lenbuf-ipos+1);
1397  mncrck(ctemp, 20, comand, lnc, fMaxpar, fCOMDplist, llist, ierr, fIsyswr);
1398  if (ierr > 0) {
1399  Printf(" COMMAND CANNOT BE INTERPRETED");
1400  icondn = 2;
1401  return;
1402  }
1403 
1404  mnexcm(comand.Data(), fCOMDplist, llist, ierr);
1405  icondn = ierr;
1406 } /* mncomd_ */
1407 
1408 ////////////////////////////////////////////////////////////////////////////////
1409 ///*-*-*-*-*-*-*Find points along a contour where FCN is minimum*-*-*-*-*-*-*
1410 ///*-* ================================================
1411 ///*-* Find NPTU points along a contour where the function
1412 ///*-* FMIN (X(KE1),X(KE2)) = AMIN+UP
1413 ///*-* where FMIN is the minimum of FCN with respect to all
1414 ///*-* the other NPAR-2 variable parameters (if any).
1415 ///*-* IERRF on return will be equal to the number of points found:
1416 ///*-* NPTU if normal termination with NPTU points found
1417 ///*-* -1 if errors in the calling sequence (KE1, KE2 not variable)
1418 ///*-* 0 if less than four points can be found (using MNMNOT)
1419 ///*-* n>3 if only n points can be found (n < NPTU)
1420 ///*-*
1421 ///*-* input arguments: parx, pary, devs, ngrid
1422 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1423 
1424 void TMinuit::mncont(Int_t ike1, Int_t ike2, Int_t nptu, Double_t *xptu, Double_t *yptu, Int_t &ierrf)
1425 {
1426  /* System generated locals */
1427  Int_t i__1;
1428 
1429  /* Local variables */
1430  Double_t d__1, d__2;
1431  Double_t dist, xdir, ydir, aopt, u1min, u2min;
1432  Double_t abest, scalx, scaly;
1433  Double_t a1, a2, val2mi, val2pl, dc, sclfac, bigdis, sigsav;
1434  Int_t nall, iold, line, mpar, ierr, inew, move, next, i, j, nfcol, iercr;
1435  Int_t idist=0, npcol, kints, i2, i1, lr, nfcnco=0, ki1, ki2, ki3, ke3;
1436  Int_t nowpts, istrav, nfmxin, isw2, isw4;
1437  Bool_t ldebug;
1438 
1439  /* Function Body */
1440  Int_t ke1 = ike1+1;
1441  Int_t ke2 = ike2+1;
1442  ldebug = fIdbg[6] >= 1;
1443  if (ke1 <= 0 || ke2 <= 0) goto L1350;
1444  if (ke1 > fNu || ke2 > fNu) goto L1350;
1445  ki1 = fNiofex[ke1-1];
1446  ki2 = fNiofex[ke2-1];
1447  if (ki1 <= 0 || ki2 <= 0) goto L1350;
1448  if (ki1 == ki2) goto L1350;
1449  if (nptu < 4) goto L1400;
1450 
1451  nfcnco = fNfcn;
1452  fNfcnmx = (nptu + 5)*100*(fNpar + 1);
1453 //*-*- The minimum
1454  mncuve();
1455  u1min = fU[ke1-1];
1456  u2min = fU[ke2-1];
1457  ierrf = 0;
1458  fCfrom = "MNContour ";
1459  fNfcnfr = nfcnco;
1460  if (fISW[4] >= 0) {
1461  Printf(" START MNCONTOUR CALCULATION OF %4d POINTS ON CONTOUR.",nptu);
1462  if (fNpar > 2) {
1463  if (fNpar == 3) {
1464  ki3 = 6 - ki1 - ki2;
1465  ke3 = fNexofi[ki3-1];
1466  Printf(" EACH POINT IS A MINIMUM WITH RESPECT TO PARAMETER %3d %s",ke3,(const char*)fCpnam[ke3-1]);
1467  } else {
1468  Printf(" EACH POINT IS A MINIMUM WITH RESPECT TO THE OTHER %3d VARIABLE PARAMETERS.",fNpar - 2);
1469  }
1470  }
1471  }
1472 
1473 //*-*- Find the first four points using MNMNOT
1474 //*-*- ........................ first two points
1475  mnmnot(ke1, ke2, val2pl, val2mi);
1476  if (fErn[ki1-1] == fUndefi) {
1477  xptu[0] = fAlim[ke1-1];
1478  mnwarn("W", "MNContour ", "Contour squeezed by parameter limits.");
1479  } else {
1480  if (fErn[ki1-1] >= 0) goto L1500;
1481  xptu[0] = u1min + fErn[ki1-1];
1482  }
1483  yptu[0] = val2mi;
1484 
1485  if (fErp[ki1-1] == fUndefi) {
1486  xptu[2] = fBlim[ke1-1];
1487  mnwarn("W", "MNContour ", "Contour squeezed by parameter limits.");
1488  } else {
1489  if (fErp[ki1-1] <= 0) goto L1500;
1490  xptu[2] = u1min + fErp[ki1-1];
1491  }
1492  yptu[2] = val2pl;
1493  scalx = 1 / (xptu[2] - xptu[0]);
1494 //*-*- ........................... next two points
1495  mnmnot(ke2, ke1, val2pl, val2mi);
1496  if (fErn[ki2-1] == fUndefi) {
1497  yptu[1] = fAlim[ke2-1];
1498  mnwarn("W", "MNContour ", "Contour squeezed by parameter limits.");
1499  } else {
1500  if (fErn[ki2-1] >= 0) goto L1500;
1501  yptu[1] = u2min + fErn[ki2-1];
1502  }
1503  xptu[1] = val2mi;
1504  if (fErp[ki2-1] == fUndefi) {
1505  yptu[3] = fBlim[ke2-1];
1506  mnwarn("W", "MNContour ", "Contour squeezed by parameter limits.");
1507  } else {
1508  if (fErp[ki2-1] <= 0) goto L1500;
1509  yptu[3] = u2min + fErp[ki2-1];
1510  }
1511  xptu[3] = val2pl;
1512  scaly = 1 / (yptu[3] - yptu[1]);
1513  nowpts = 4;
1514  next = 5;
1515  if (ldebug) {
1516  Printf(" Plot of four points found by MINOS");
1517  fXpt[0] = u1min;
1518  fYpt[0] = u2min;
1519  fChpt[0] = ' ';
1520 //*-* Computing MIN
1521  nall = TMath::Min(nowpts + 1,101);
1522  for (i = 2; i <= nall; ++i) {
1523  fXpt[i-1] = xptu[i-2];
1524  fYpt[i-1] = yptu[i-2];
1525  }
1526  sprintf(fChpt,"%s"," ABCD");
1527  mnplot(fXpt, fYpt, fChpt, nall, fNpagwd, fNpagln);
1528  }
1529 
1530 //*-*- ..................... save some values before fixing
1531  isw2 = fISW[1];
1532  isw4 = fISW[3];
1533  sigsav = fEDM;
1534  istrav = fIstrat;
1535  dc = fDcovar;
1536  fApsi = fEpsi*.5;
1537  abest = fAmin;
1538  mpar = fNpar;
1539  nfmxin = fNfcnmx;
1540  for (i = 1; i <= mpar; ++i) { fXt[i-1] = fX[i-1]; }
1541  i__1 = mpar*(mpar + 1) / 2;
1542  for (j = 1; j <= i__1; ++j) { fVthmat[j-1] = fVhmat[j-1]; }
1543  for (i = 1; i <= mpar; ++i) {
1544  fCONTgcc[i-1] = fGlobcc[i-1];
1545  fCONTw[i-1] = fWerr[i-1];
1546  }
1547 //*-*- fix the two parameters in question
1548  kints = fNiofex[ke1-1];
1549  mnfixp(kints-1, ierr);
1550  kints = fNiofex[ke2-1];
1551  mnfixp(kints-1, ierr);
1552 //*-*- ......................Fill in the rest of the points
1553  for (inew = next; inew <= nptu; ++inew) {
1554 //*-* find the two neighbouring points with largest separation
1555  bigdis = 0;
1556  for (iold = 1; iold <= inew - 1; ++iold) {
1557  i2 = iold + 1;
1558  if (i2 == inew) i2 = 1;
1559  d__1 = scalx*(xptu[iold-1] - xptu[i2-1]);
1560  d__2 = scaly*(yptu[iold-1] - yptu[i2-1]);
1561  dist = d__1*d__1 + d__2*d__2;
1562  if (dist > bigdis) {
1563  bigdis = dist;
1564  idist = iold;
1565  }
1566  }
1567  i1 = idist;
1568  i2 = i1 + 1;
1569  if (i2 == inew) i2 = 1;
1570 //*-*- next point goes between I1 and I2
1571  a1 = .5;
1572  a2 = .5;
1573 L300:
1574  fXmidcr = a1*xptu[i1-1] + a2*xptu[i2-1];
1575  fYmidcr = a1*yptu[i1-1] + a2*yptu[i2-1];
1576  xdir = yptu[i2-1] - yptu[i1-1];
1577  ydir = xptu[i1-1] - xptu[i2-1];
1578  sclfac = TMath::Max(TMath::Abs(xdir*scalx),TMath::Abs(ydir*scaly));
1579  fXdircr = xdir / sclfac;
1580  fYdircr = ydir / sclfac;
1581  fKe1cr = ke1;
1582  fKe2cr = ke2;
1583 //*-*- Find the contour crossing point along DIR
1584  fAmin = abest;
1585  mncros(aopt, iercr);
1586  if (iercr > 1) {
1587 //*-*- If cannot find mid-point, try closer to point 1
1588  if (a1 > .5) {
1589  if (fISW[4] >= 0) {
1590  Printf(" MNCONT CANNOT FIND NEXT POINT ON CONTOUR. ONLY %3d POINTS FOUND.",nowpts);
1591  }
1592  goto L950;
1593  }
1594  mnwarn("W", "MNContour ", "Cannot find midpoint, try closer.");
1595  a1 = .75;
1596  a2 = .25;
1597  goto L300;
1598  }
1599 //*-*- Contour has been located, insert new point in list
1600  for (move = nowpts; move >= i1 + 1; --move) {
1601  xptu[move] = xptu[move-1];
1602  yptu[move] = yptu[move-1];
1603  }
1604  ++nowpts;
1605  xptu[i1] = fXmidcr + fXdircr*aopt;
1606  yptu[i1] = fYmidcr + fYdircr*aopt;
1607  }
1608 L950:
1609 
1610  ierrf = nowpts;
1611  fCstatu = "SUCCESSFUL";
1612  if (nowpts < nptu) fCstatu = "INCOMPLETE";
1613 
1614 //*-*- make a lineprinter plot of the contour
1615  if (fISW[4] >= 0) {
1616  fXpt[0] = u1min;
1617  fYpt[0] = u2min;
1618  fChpt[0] = ' ';
1619  nall = TMath::Min(nowpts + 1,101);
1620  for (i = 2; i <= nall; ++i) {
1621  fXpt[i-1] = xptu[i-2];
1622  fYpt[i-1] = yptu[i-2];
1623  fChpt[i-1] = 'X';
1624  }
1625  fChpt[nall] = 0;
1626  Printf(" Y-AXIS: PARAMETER %3d %s",ke2,(const char*)fCpnam[ke2-1]);
1627 
1628  mnplot(fXpt, fYpt, fChpt, nall, fNpagwd, fNpagln);
1629 
1630  Printf(" X-AXIS: PARAMETER %3d %s",ke1,(const char*)fCpnam[ke1-1]);
1631  }
1632 //*-*- print out the coordinates around the contour
1633  if (fISW[4] >= 1) {
1634  npcol = (nowpts + 1) / 2;
1635  nfcol = nowpts / 2;
1636  Printf("%5d POINTS ON CONTOUR. FMIN=%13.5e ERRDEF=%11.3g",nowpts,abest,fUp);
1637  Printf(" %s%s%s%s",(const char*)fCpnam[ke1-1],
1638  (const char*)fCpnam[ke2-1],
1639  (const char*)fCpnam[ke1-1],
1640  (const char*)fCpnam[ke2-1]);
1641  for (line = 1; line <= nfcol; ++line) {
1642  lr = line + npcol;
1643  Printf(" %5d%13.5e%13.5e %5d%13.5e%13.5e",line,xptu[line-1],yptu[line-1],lr,xptu[lr-1],yptu[lr-1]);
1644  }
1645  if (nfcol < npcol) {
1646  Printf(" %5d%13.5e%13.5e",npcol,xptu[npcol-1],yptu[npcol-1]);
1647  }
1648  }
1649 //*-*- . . contour finished. reset v
1650  fItaur = 1;
1651  mnfree(1);
1652  mnfree(1);
1653  i__1 = mpar*(mpar + 1) / 2;
1654  for (j = 1; j <= i__1; ++j) { fVhmat[j-1] = fVthmat[j-1]; }
1655  for (i = 1; i <= mpar; ++i) {
1656  fGlobcc[i-1] = fCONTgcc[i-1];
1657  fWerr[i-1] = fCONTw[i-1];
1658  fX[i-1] = fXt[i-1];
1659  }
1660  mninex(fX);
1661  fEDM = sigsav;
1662  fAmin = abest;
1663  fISW[1] = isw2;
1664  fISW[3] = isw4;
1665  fDcovar = dc;
1666  fItaur = 0;
1667  fNfcnmx = nfmxin;
1668  fIstrat = istrav;
1669  fU[ke1-1] = u1min;
1670  fU[ke2-1] = u2min;
1671  goto L2000;
1672 //*-*- Error returns
1673 L1350:
1674  Printf(" INVALID PARAMETER NUMBERS.");
1675  goto L1450;
1676 L1400:
1677  Printf(" LESS THAN FOUR POINTS REQUESTED.");
1678 L1450:
1679  ierrf = -1;
1680  fCstatu = "USER ERROR";
1681  goto L2000;
1682 L1500:
1683  Printf(" MNCONT UNABLE TO FIND FOUR POINTS.");
1684  fU[ke1-1] = u1min;
1685  fU[ke2-1] = u2min;
1686  ierrf = 0;
1687  fCstatu = "FAILED";
1688 L2000:
1689  fCfrom = "MNContour ";
1690  fNfcnfr = nfcnco;
1691 } /* mncont_ */
1692 
1693 ////////////////////////////////////////////////////////////////////////////////
1694 ///*-*-*-*-*-*-*-*-*-*-*-*Cracks the free-format input*-*-*-*-*-*-*-*-*-*-*-*-*
1695 ///*-* ============================
1696 ///*-* Cracks the free-format input, expecting zero or more
1697 ///*-* alphanumeric fields (which it joins into COMAND(1:LNC))
1698 ///*-* followed by one or more numeric fields separated by
1699 ///*-* blanks and/or one comma. The numeric fields are put into
1700 ///*-* the LLIST (but at most MXP) elements of PLIST.
1701 ///*-* IERR = 0 if no errors,
1702 ///*-* = 1 if error(s).
1703 ///*-*
1704 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1705 
1706 void TMinuit::mncrck(TString cardbuf, Int_t maxcwd, TString &comand, Int_t &lnc,
1707  Int_t mxp, Double_t *plist, Int_t &llist, Int_t &ierr, Int_t)
1708 {
1709  /* Initialized data */
1710 
1711  char *cnull = 0;
1712  const char *cnumer = "123456789-.0+";
1713 
1714  /* Local variables */
1715  Int_t ifld, iend, lend, left, nreq, ipos, kcmnd, nextb, ic, ibegin, ltoadd;
1716  Int_t ielmnt, lelmnt[25], nelmnt;
1717  TString ctemp;
1718  char *celmnt[25];
1719  char command[25];
1720 
1721  /* Function Body */
1722  char *crdbuf = (char*)cardbuf.Data();
1723  lend = cardbuf.Length();
1724  ielmnt = 0;
1725  nextb = 1;
1726  ierr = 0;
1727 //*-*- . . . . loop over words CELMNT
1728 L10:
1729  for (ipos = nextb; ipos <= lend; ++ipos) {
1730  ibegin = ipos;
1731  if (crdbuf[ipos-1] == ' ') continue;
1732  if (crdbuf[ipos-1] == ',') goto L250;
1733  goto L150;
1734  }
1735  goto L300;
1736 L150:
1737 //*-*- found beginning of word, look for end
1738  for (ipos = ibegin + 1; ipos <= lend; ++ipos) {
1739  if (crdbuf[ipos-1] == ' ') goto L250;
1740  if (crdbuf[ipos-1] == ',') goto L250;
1741  }
1742  ipos = lend + 1;
1743 L250:
1744  iend = ipos - 1;
1745  ++ielmnt;
1746  if (iend >= ibegin) celmnt[ielmnt-1] = &crdbuf[ibegin-1];
1747  else celmnt[ielmnt-1] = cnull;
1748  lelmnt[ielmnt-1] = iend - ibegin + 1;
1749  if (lelmnt[ielmnt-1] > 19) {
1750  Printf(" MINUIT WARNING: INPUT DATA WORD TOO LONG.");
1751  ctemp = cardbuf(ibegin-1,iend-ibegin+1);
1752  Printf(" ORIGINAL:%s",ctemp.Data());
1753  Printf(" TRUNCATED TO:%s",celmnt[ielmnt-1]);
1754  lelmnt[ielmnt-1] = 19;
1755  }
1756  if (ipos >= lend) goto L300;
1757  if (ielmnt >= 25) goto L300;
1758 //*-*- look for comma or beginning of next word
1759  for (ipos = iend + 1; ipos <= lend; ++ipos) {
1760  if (crdbuf[ipos-1] == ' ') continue;
1761  nextb = ipos;
1762  if (crdbuf[ipos-1] == ',') nextb = ipos + 1;
1763  goto L10;
1764  }
1765 //*-*- All elements found, join the alphabetic ones to
1766 //*-*- form a command
1767 L300:
1768  nelmnt = ielmnt;
1769  command[0] = ' '; command[1] = 0;
1770  lnc = 1;
1771  plist[0] = 0;
1772  llist = 0;
1773  if (ielmnt == 0) goto L900;
1774  kcmnd = 0;
1775  for (ielmnt = 1; ielmnt <= nelmnt; ++ielmnt) {
1776  if ( celmnt[ielmnt-1] == cnull) goto L450;
1777  for (ic = 1; ic <= 13; ++ic) {
1778  if (*celmnt[ielmnt-1] == cnumer[ic-1]) goto L450;
1779  }
1780  if (kcmnd >= maxcwd) continue;
1781  left = maxcwd - kcmnd;
1782  ltoadd = lelmnt[ielmnt-1];
1783  if (ltoadd > left) ltoadd = left;
1784  strncpy(&command[kcmnd],celmnt[ielmnt-1],ltoadd);
1785  kcmnd += ltoadd;
1786  if (kcmnd == maxcwd) continue;
1787  command[kcmnd] = ' ';
1788  ++kcmnd;
1789  command[kcmnd] = 0;
1790  }
1791  lnc = kcmnd;
1792  goto L900;
1793 L450:
1794  lnc = kcmnd;
1795 //*-*- . . . . we have come to a numeric field
1796  llist = 0;
1797  for (ifld = ielmnt; ifld <= nelmnt; ++ifld) {
1798  ++llist;
1799  if (llist > mxp) {
1800  nreq = nelmnt - ielmnt + 1;
1801  Printf(" MINUIT WARNING IN MNCRCK: ");
1802  Printf(" COMMAND HAS INPUT %5d NUMERIC FIELDS, BUT MINUIT CAN ACCEPT ONLY%3d",nreq,mxp);
1803  goto L900;
1804  }
1805  if (celmnt[ifld-1] == cnull) plist[llist-1] = 0;
1806  else {
1807  sscanf(celmnt[ifld-1],"%lf",&plist[llist-1]);
1808  }
1809  }
1810 //*-*- end loop over numeric fields
1811 L900:
1812  if (lnc <= 0) lnc = 1;
1813  comand = command;
1814 } /* mncrck_ */
1815 
1816 ////////////////////////////////////////////////////////////////////////////////
1817 ///*-*-*-*-*-*-*-*-*-*-*Find point where MNEVAL=AMIN+UP*-*-*-*-*-*-*-*-*-*-*-*
1818 ///*-* ===============================
1819 ///*-* Find point where MNEVAL=AMIN+UP, along the line through
1820 ///*-* XMIDCR,YMIDCR with direction XDIRCR,YDIRCR, where X and Y
1821 ///*-* are parameters KE1CR and KE2CR. If KE2CR=0 (from MINOS),
1822 ///*-* only KE1CR is varied. From MNCONT, both are varied.
1823 ///*-* Crossing point is at
1824 ///*-* (U(KE1),U(KE2)) = (XMID,YMID) + AOPT*(XDIR,YDIR)
1825 ///*-*
1826 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1827 
1828 void TMinuit::mncros(Double_t &aopt, Int_t &iercr)
1829 {
1830  /* Local variables */
1831  Double_t alsb[3], flsb[3], bmin, bmax, zmid, sdev, zdir, zlim;
1832  Double_t coeff[3], aleft, aulim, fdist, adist, aminsv;
1833  Double_t anext, fnext, slope, s1, s2, x1, x2, ecarmn, ecarmx;
1834  Double_t determ, rt, smalla, aright, aim, tla, tlf, dfda,ecart;
1835  Int_t iout=0, i, ileft, ierev, maxlk, ibest, ik, it;
1836  Int_t noless, iworst=0, iright, itoohi, kex, ipt;
1837  Bool_t ldebug;
1838  const char *chsign;
1839  x2 = 0;
1840 
1841  ldebug = fIdbg[6] >= 1;
1842  aminsv = fAmin;
1843 //*-*- convergence when F is within TLF of AIM and next prediction
1844 //*-*- of AOPT is within TLA of previous value of AOPT
1845  aim = fAmin + fUp;
1846  tlf = fUp*.01;
1847  tla = .01;
1848  fXpt[0] = 0;
1849  fYpt[0] = aim;
1850  fChpt[0] = ' ';
1851  ipt = 1;
1852  if (fKe2cr == 0) {
1853  fXpt[1] = -1;
1854  fYpt[1] = fAmin;
1855  fChpt[1] = '.';
1856  ipt = 2;
1857  }
1858 //*-*- find the largest allowed A
1859  aulim = 100;
1860  for (ik = 1; ik <= 2; ++ik) {
1861  if (ik == 1) {
1862  kex = fKe1cr;
1863  zmid = fXmidcr;
1864  zdir = fXdircr;
1865  } else {
1866  if (fKe2cr == 0) continue;
1867  kex = fKe2cr;
1868  zmid = fYmidcr;
1869  zdir = fYdircr;
1870  }
1871  if (fNvarl[kex-1] <= 1) continue;
1872  if (zdir == 0) continue;
1873  zlim = fAlim[kex-1];
1874  if (zdir > 0) zlim = fBlim[kex-1];
1875  aulim = TMath::Min(aulim,(zlim - zmid) / zdir);
1876  }
1877 //*-*- LSB = Line Search Buffer
1878 //*-*- first point
1879  anext = 0;
1880  aopt = anext;
1881  fLimset = kFALSE;
1882  if (aulim < aopt + tla) fLimset = kTRUE;
1883  mneval(anext, fnext, ierev);
1884 //*-* debug printout:
1885  if (ldebug) {
1886  Printf(" MNCROS: calls=%8d AIM=%10.5f F,A=%10.5f%10.5f",fNfcn,aim,fnext,aopt);
1887  }
1888  if (ierev > 0) goto L900;
1889  if (fLimset && fnext <= aim) goto L930;
1890  ++ipt;
1891  fXpt[ipt-1] = anext;
1892  fYpt[ipt-1] = fnext;
1893  fChpt[ipt-1] = charal[ipt-1];
1894  alsb[0] = anext;
1895  flsb[0] = fnext;
1896  fnext = TMath::Max(fnext,aminsv + fUp*.1);
1897  aopt = TMath::Sqrt(fUp / (fnext - aminsv)) - 1;
1898  if (TMath::Abs(fnext - aim) < tlf) goto L800;
1899 
1900  if (aopt < -.5)aopt = -.5;
1901  if (aopt > 1) aopt = 1;
1902  fLimset = kFALSE;
1903  if (aopt > aulim) {
1904  aopt = aulim;
1905  fLimset = kTRUE;
1906  }
1907  mneval(aopt, fnext, ierev);
1908 //*-* debug printout:
1909  if (ldebug) {
1910  Printf(" MNCROS: calls=%8d AIM=%10.5f F,A=%10.5f%10.5f",fNfcn,aim,fnext,aopt);
1911  }
1912  if (ierev > 0) goto L900;
1913  if (fLimset && fnext <= aim) goto L930;
1914  alsb[1] = aopt;
1915  ++ipt;
1916  fXpt[ipt-1] = alsb[1];
1917  fYpt[ipt-1] = fnext;
1918  fChpt[ipt-1] = charal[ipt-1];
1919  flsb[1] = fnext;
1920  dfda = (flsb[1] - flsb[0]) / (alsb[1] - alsb[0]);
1921 //*-*- DFDA must be positive on the contour
1922  if (dfda > 0) goto L460;
1923 L300:
1924  mnwarn("D", "MNCROS ", "Looking for slope of the right sign");
1925  maxlk = 15 - ipt;
1926  for (it = 1; it <= maxlk; ++it) {
1927  alsb[0] = alsb[1];
1928  flsb[0] = flsb[1];
1929  aopt = alsb[0] + Double_t(it)*.2;
1930  fLimset = kFALSE;
1931  if (aopt > aulim) {
1932  aopt = aulim;
1933  fLimset = kTRUE;
1934  }
1935  mneval(aopt, fnext, ierev);
1936 //*-* debug printout:
1937  if (ldebug) {
1938  Printf(" MNCROS: calls=%8d AIM=%10.5f F,A=%10.5f%10.5f",fNfcn,aim,fnext,aopt);
1939  }
1940  if (ierev > 0) goto L900;
1941  if (fLimset && fnext <= aim) goto L930;
1942  alsb[1] = aopt;
1943  ++ipt;
1944  fXpt[ipt-1] = alsb[1];
1945  fYpt[ipt-1] = fnext;
1946  fChpt[ipt-1] = charal[ipt-1];
1947  flsb[1] = fnext;
1948  dfda = (flsb[1] - flsb[0]) / (alsb[1] - alsb[0]);
1949  if (dfda > 0) goto L450;
1950  }
1951  mnwarn("W", "MNCROS ", "Cannot find slope of the right sign");
1952  goto L950;
1953 L450:
1954 //*-*- we have two points with the right slope
1955 L460:
1956  aopt = alsb[1] + (aim - flsb[1]) / dfda;
1957  fdist = TMath::Min(TMath::Abs(aim - flsb[0]),TMath::Abs(aim - flsb[1]));
1958  adist = TMath::Min(TMath::Abs(aopt - alsb[0]),TMath::Abs(aopt - alsb[1]));
1959  tla = .01;
1960  if (TMath::Abs(aopt) > 1) tla = TMath::Abs(aopt)*.01;
1961  if (adist < tla && fdist < tlf) goto L800;
1962  if (ipt >= 15) goto L950;
1963  bmin = TMath::Min(alsb[0],alsb[1]) - 1;
1964  if (aopt < bmin) aopt = bmin;
1965  bmax = TMath::Max(alsb[0],alsb[1]) + 1;
1966  if (aopt > bmax) aopt = bmax;
1967 //*-*- Try a third point
1968  fLimset = kFALSE;
1969  if (aopt > aulim) {
1970  aopt = aulim;
1971  fLimset = kTRUE;
1972  }
1973  mneval(aopt, fnext, ierev);
1974 //*-* debug printout:
1975  if (ldebug) {
1976  Printf(" MNCROS: calls=%8d AIM=%10.5f F,A=%10.5f%10.5f",fNfcn,aim,fnext,aopt);
1977  }
1978  if (ierev > 0) goto L900;
1979  if (fLimset && fnext <= aim) goto L930;
1980  alsb[2] = aopt;
1981  ++ipt;
1982  fXpt[ipt-1] = alsb[2];
1983  fYpt[ipt-1] = fnext;
1984  fChpt[ipt-1] = charal[ipt-1];
1985  flsb[2] = fnext;
1986 //*-*- now we have three points, ask how many <AIM
1987  ecarmn = TMath::Abs(fnext-aim);
1988  ibest = 3;
1989  ecarmx = 0;
1990  noless = 0;
1991  for (i = 1; i <= 3; ++i) {
1992  ecart = TMath::Abs(flsb[i-1] - aim);
1993  if (ecart > ecarmx) { ecarmx = ecart; iworst = i; }
1994  if (ecart < ecarmn) { ecarmn = ecart; ibest = i; }
1995  if (flsb[i-1] < aim) ++noless;
1996  }
1997 //*-*- if at least one on each side of AIM, fit a parabola
1998  if (noless == 1 || noless == 2) goto L500;
1999 //*-*- if all three are above AIM, third must be closest to AIM
2000  if (noless == 0 && ibest != 3) goto L950;
2001 //*-*- if all three below, and third is not best, then slope
2002 //*-*- has again gone negative, look for positive slope.
2003  if (noless == 3 && ibest != 3) {
2004  alsb[1] = alsb[2];
2005  flsb[1] = flsb[2];
2006  goto L300;
2007  }
2008 //*-*- in other cases, new straight line thru last two points
2009  alsb[iworst-1] = alsb[2];
2010  flsb[iworst-1] = flsb[2];
2011  dfda = (flsb[1] - flsb[0]) / (alsb[1] - alsb[0]);
2012  goto L460;
2013 //*-*- parabola fit
2014 L500:
2015  mnpfit(alsb, flsb, 3, coeff, sdev);
2016  if (coeff[2] <= 0) {
2017  mnwarn("D", "MNCROS ", "Curvature is negative near contour line.");
2018  }
2019  determ = coeff[1]*coeff[1] - coeff[2]*4*(coeff[0] - aim);
2020  if (determ <= 0) {
2021  mnwarn("D", "MNCROS ", "Problem 2, impossible determinant");
2022  goto L950;
2023  }
2024 //*-*- Find which root is the right one
2025  rt = TMath::Sqrt(determ);
2026  x1 = (-coeff[1] + rt) / (coeff[2]*2);
2027  x2 = (-coeff[1] - rt) / (coeff[2]*2);
2028  s1 = coeff[1] + x1*2*coeff[2];
2029  s2 = coeff[1] + x2*2*coeff[2];
2030  if (s1*s2 > 0) {
2031  Printf(" MNCONTour problem 1");
2032  }
2033  aopt = x1;
2034  slope = s1;
2035  if (s2 > 0) {
2036  aopt = x2;
2037  slope = s2;
2038  }
2039 //*-*- ask if converged
2040  tla = .01;
2041  if (TMath::Abs(aopt) > 1) tla = TMath::Abs(aopt)*.01;
2042  if (TMath::Abs(aopt - alsb[ibest-1]) < tla && TMath::Abs(flsb[ibest-1] - aim) < tlf) {
2043  goto L800;
2044  }
2045  if (ipt >= 15) goto L950;
2046 
2047 //*-*- see if proposed point is in acceptable zone between L and R
2048 //*-*- first find ILEFT, IRIGHT, IOUT and IBEST
2049  ileft = 0;
2050  iright = 0;
2051  ibest = 1;
2052  ecarmx = 0;
2053  ecarmn = TMath::Abs(aim - flsb[0]);
2054  for (i = 1; i <= 3; ++i) {
2055  ecart = TMath::Abs(flsb[i-1] - aim);
2056  if (ecart < ecarmn) { ecarmn = ecart; ibest = i; }
2057  if (ecart > ecarmx) { ecarmx = ecart; }
2058  if (flsb[i-1] > aim) {
2059  if (iright == 0) iright = i;
2060  else if (flsb[i-1] > flsb[iright-1]) iout = i;
2061  else { iout = iright; iright = i; }
2062  }
2063  else if (ileft == 0) ileft = i;
2064  else if (flsb[i-1] < flsb[ileft-1]) iout = i;
2065  else { iout = ileft; ileft = i; }
2066  }
2067 //*-*- avoid keeping a very bad point next time around
2068  if (ecarmx > TMath::Abs(flsb[iout-1] - aim)*10) {
2069  aopt = aopt*.5 + (alsb[iright-1] + alsb[ileft-1])*.25;
2070  }
2071 //*-*- knowing ILEFT and IRIGHT, get acceptable window
2072  smalla = tla*.1;
2073  if (slope*smalla > tlf) smalla = tlf / slope;
2074  aleft = alsb[ileft-1] + smalla;
2075  aright = alsb[iright-1] - smalla;
2076 //*-*- move proposed point AOPT into window if necessary
2077  if (aopt < aleft) aopt = aleft;
2078  if (aopt > aright) aopt = aright;
2079  if (aleft > aright) aopt = (aleft + aright)*.5;
2080 
2081 //*-*- see if proposed point outside limits (should be impossible!)
2082  fLimset = kFALSE;
2083  if (aopt > aulim) {
2084  aopt = aulim;
2085  fLimset = kTRUE;
2086  }
2087 //*-*- Evaluate function at new point AOPT
2088  mneval(aopt, fnext, ierev);
2089 //*-* debug printout:
2090  if (ldebug) {
2091  Printf(" MNCROS: calls=%8d AIM=%10.5f F,A=%10.5f%10.5f",fNfcn,aim,fnext,aopt);
2092  }
2093  if (ierev > 0) goto L900;
2094  if (fLimset && fnext <= aim) goto L930;
2095  ++ipt;
2096  fXpt[ipt-1] = aopt;
2097  fYpt[ipt-1] = fnext;
2098  fChpt[ipt-1] = charal[ipt-1];
2099 //*-*- Replace odd point by new one
2100  alsb[iout-1] = aopt;
2101  flsb[iout-1] = fnext;
2102 //*-*- the new point may not be the best, but it is the only one
2103 //*-*- which could be good enough to pass convergence criteria
2104  ibest = iout;
2105  goto L500;
2106 
2107 //*-*- Contour has been located, return point to MNCONT OR MINOS
2108 L800:
2109  iercr = 0;
2110  goto L1000;
2111 //*-*- error in the minimization
2112 L900:
2113  if (ierev == 1) goto L940;
2114  goto L950;
2115 //*-*- parameter up against limit
2116 L930:
2117  iercr = 1;
2118  goto L1000;
2119 //*-*- too many calls to FCN
2120 L940:
2121  iercr = 2;
2122  goto L1000;
2123 //*-*- cannot find next point
2124 L950:
2125  iercr = 3;
2126 //*-*- in any case
2127 L1000:
2128  if (ldebug) {
2129  itoohi = 0;
2130  for (i = 1; i <= ipt; ++i) {
2131  if (fYpt[i-1] > aim + fUp) {
2132  fYpt[i-1] = aim + fUp;
2133  fChpt[i-1] = '+';
2134  itoohi = 1;
2135  }
2136  }
2137  fChpt[ipt] = 0;
2138  chsign = "POSI";
2139  if (fXdircr < 0) chsign = "NEGA";
2140  if (fKe2cr == 0) {
2141  Printf(" %sTIVE MINOS ERROR, PARAMETER %3d",chsign,fKe1cr);
2142  }
2143  if (itoohi == 1) {
2144  Printf("POINTS LABELLED '+' WERE TOO HIGH TO PLOT.");
2145  }
2146  if (iercr == 1) {
2147  Printf("RIGHTMOST POINT IS UP AGAINST LIMIT.");
2148  }
2149  mnplot(fXpt, fYpt, fChpt, ipt, fNpagwd, fNpagln);
2150  }
2151 } /* mncros_ */
2152 
2153 ////////////////////////////////////////////////////////////////////////////////
2154 ///*-*-*-*-*-*-*-*Makes sure that the current point is a local minimum*-*-*-*-*
2155 ///*-* ====================================================
2156 ///*-* Makes sure that the current point is a local
2157 ///*-* minimum and that the error matrix exists,
2158 ///*-* or at least something good enough for MINOS and MNCONT
2159 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2160 
2162 {
2163  /* Local variables */
2164  Double_t dxdi, wint;
2165  Int_t ndex, iext, i, j;
2166 
2167  if (fISW[3] < 1) {
2168  Printf(" FUNCTION MUST BE MINIMIZED BEFORE CALLING %s",(const char*)fCfrom);
2169  fApsi = fEpsi;
2170  mnmigr();
2171  }
2172  if (fISW[1] < 3) {
2173  mnhess();
2174  if (fISW[1] < 1) {
2175  mnwarn("W", fCfrom, "NO ERROR MATRIX. WILL IMPROVISE.");
2176  for (i = 1; i <= fNpar; ++i) {
2177  ndex = i*(i-1) / 2;
2178  for (j = 1; j <= i-1; ++j) {
2179  ++ndex;
2180  fVhmat[ndex-1] = 0;
2181  }
2182  ++ndex;
2183  if (fG2[i-1] <= 0) {
2184  wint = fWerr[i-1];
2185  iext = fNexofi[i-1];
2186  if (fNvarl[iext-1] > 1) {
2187  mndxdi(fX[i-1], i-1, dxdi);
2188  if (TMath::Abs(dxdi) < .001) wint = .01;
2189  else wint /= TMath::Abs(dxdi);
2190  }
2191  fG2[i-1] = fUp / (wint*wint);
2192  }
2193  fVhmat[ndex-1] = 2 / fG2[i-1];
2194  }
2195  fISW[1] = 1;
2196  fDcovar = 1;
2197  } else mnwerr();
2198  }
2199 } /* mncuve_ */
2200 
2201 ////////////////////////////////////////////////////////////////////////////////
2202 ///*-*-*-*-*-*-*-*Calculates the first derivatives of FCN (GRD)*-*-*-*-*-*-*-*
2203 ///*-* =============================================
2204 ///*-* Calculates the first derivatives of FCN (GRD),
2205 ///*-* either by finite differences or by transforming the user-
2206 ///*-* supplied derivatives to internal coordinates,
2207 ///*-* according to whether fISW[2] is zero or one.
2208 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2209 
2211 {
2212  /* Local variables */
2213  Double_t step, dfmin, stepb4, dd, df, fs1;
2214  Double_t tlrstp, tlrgrd, epspri, optstp, stpmax, stpmin, fs2, grbfor=0, d1d2, xtf;
2215  Int_t icyc, ncyc, iint, iext, i, nparx;
2216  Bool_t ldebug;
2217 
2218  nparx = fNpar;
2219  ldebug = fIdbg[2] >= 1;
2220  if (fAmin == fUndefi) mnamin();
2221  if (fISW[2] == 1) goto L100;
2222 
2223  if (ldebug) {
2224 //*-*- make sure starting at the right place
2225  mninex(fX);
2226  nparx = fNpar;
2227  Eval(nparx, fGin, fs1, fU, 4); ++fNfcn;
2228  if (fs1 != fAmin) {
2229  df = fAmin - fs1;
2230  mnwarn("D", "MNDERI", TString::Format("function value differs from AMIN by %12.3g",df));
2231  fAmin = fs1;
2232  }
2233  Printf(" FIRST DERIVATIVE DEBUG PRINTOUT. MNDERI");
2234  Printf(" PAR DERIV STEP MINSTEP OPTSTEP D1-D2 2ND DRV");
2235  }
2236  dfmin = fEpsma2*8*(TMath::Abs(fAmin) + fUp);
2237  if (fIstrat <= 0) {
2238  ncyc = 2;
2239  tlrstp = .5;
2240  tlrgrd = .1;
2241  } else if (fIstrat == 1) {
2242  ncyc = 3;
2243  tlrstp = .3;
2244  tlrgrd = .05;
2245  } else {
2246  ncyc = 5;
2247  tlrstp = .1;
2248  tlrgrd = .02;
2249  }
2250 //*-*- loop over variable parameters
2251  for (i = 1; i <= fNpar; ++i) {
2252  epspri = fEpsma2 + TMath::Abs(fGrd[i-1]*fEpsma2);
2253 //*-*- two-point derivatives always assumed necessary
2254 //*-*- maximum number of cycles over step size depends on strategy
2255  xtf = fX[i-1];
2256  stepb4 = 0;
2257 //*-*- loop as little as possible here!/
2258  for (icyc = 1; icyc <= ncyc; ++icyc) {
2259 //*-*- ........ theoretically best step
2260  optstp = TMath::Sqrt(dfmin / (TMath::Abs(fG2[i-1]) + epspri));
2261 //*-*- step cannot decrease by more than a factor of ten
2262  step = TMath::Max(optstp,TMath::Abs(fGstep[i-1]*.1));
2263 //*-*- but if parameter has limits, max step size = 0.5
2264  if (fGstep[i-1] < 0 && step > .5) step = .5;
2265 //*-*- and not more than ten times the previous step
2266  stpmax = TMath::Abs(fGstep[i-1])*10;
2267  if (step > stpmax) step = stpmax;
2268 //*-*- minimum step size allowed by machine precision
2269  stpmin = TMath::Abs(fEpsma2*fX[i-1])*8;
2270  if (step < stpmin) step = stpmin;
2271 //*-*- end of iterations if step change less than factor 2
2272  if (TMath::Abs((step - stepb4) / step) < tlrstp) goto L50;
2273 //*-*- take step positive
2274  stepb4 = step;
2275  if (fGstep[i-1] > 0) fGstep[i-1] = TMath::Abs(step);
2276  else fGstep[i-1] = -TMath::Abs(step);
2277  stepb4 = step;
2278  fX[i-1] = xtf + step;
2279  mninex(fX);
2280  Eval(nparx, fGin, fs1, fU, 4); ++fNfcn;
2281 //*-*- take step negative
2282  fX[i-1] = xtf - step;
2283  mninex(fX);
2284  Eval(nparx, fGin, fs2, fU, 4); ++fNfcn;
2285  grbfor = fGrd[i-1];
2286  fGrd[i-1] = (fs1 - fs2) / (step*2);
2287  fG2[i-1] = (fs1 + fs2 - fAmin*2) / (step*step);
2288  fX[i-1] = xtf;
2289  if (ldebug) {
2290  d1d2 = (fs1 + fs2 - fAmin*2) / step;
2291  Printf("%4d%11.3g%11.3g%10.2g%10.2g%10.2g%10.2g",i,fGrd[i-1],step,stpmin,optstp,d1d2,fG2[i-1]);
2292  }
2293 //*-*- see if another iteration is necessary
2294  if (TMath::Abs(grbfor - fGrd[i-1]) / (TMath::Abs(fGrd[i-1]) + dfmin/step) < tlrgrd)
2295  goto L50;
2296  }
2297 //*-*- end of ICYC loop. too many iterations
2298  if (ncyc == 1) goto L50;
2299  mnwarn("D", "MNDERI", TString::Format("First derivative not converged. %g%g",fGrd[i-1],grbfor));
2300 L50:
2301  ;
2302  }
2303  mninex(fX);
2304  return;
2305 //*-*- . derivatives calc by fcn
2306 L100:
2307  for (iint = 1; iint <= fNpar; ++iint) {
2308  iext = fNexofi[iint-1];
2309  if (fNvarl[iext-1] <= 1) {
2310  fGrd[iint-1] = fGin[iext-1];
2311  } else {
2312  dd = (fBlim[iext-1] - fAlim[iext-1])*.5*TMath::Cos(fX[iint-1]);
2313  fGrd[iint-1] = fGin[iext-1]*dd;
2314  }
2315  }
2316 } /* mnderi_ */
2317 
2318 ////////////////////////////////////////////////////////////////////////////////
2319 ///*-*-*-*Calculates the transformation factor between ext/internal values*-*
2320 ///*-* =====================================================================
2321 ///*-* calculates the transformation factor between external and
2322 ///*-* internal parameter values. this factor is one for
2323 ///*-* parameters which are not limited. called from MNEMAT.
2324 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2325 
2326 void TMinuit::mndxdi(Double_t pint, Int_t ipar, Double_t &dxdi)
2327 {
2328  Int_t i = fNexofi[ipar];
2329  dxdi = 1;
2330  if (fNvarl[i-1] > 1) {
2331  dxdi = TMath::Abs((fBlim[i-1] - fAlim[i-1])*TMath::Cos(pint))*.5;
2332  }
2333 } /* mndxdi_ */
2334 
2335 ////////////////////////////////////////////////////////////////////////////////
2336 ///*-*-*-*-*-*-*-*-*-*-*-*Compute matrix eigen values*-*-*-*-*-*-*-*-*-*-*-*-*
2337 ///*-* ===========================
2338 
2339 void TMinuit::mneig(Double_t *a, Int_t ndima, Int_t n, Int_t mits, Double_t *work, Double_t precis, Int_t &ifault)
2340 {
2341  /* System generated locals */
2342  Int_t a_offset;
2343  Double_t d__1;
2344 
2345  /* Local variables */
2346  Double_t b, c, f, h, r, s, hh, gl, pr, pt;
2347  Int_t i, j, k, l, m=0, i0, i1, j1, m1, n1;
2348 
2349 //*-*- PRECIS is the machine precision EPSMAC
2350  /* Parameter adjustments */
2351  a_offset = ndima + 1;
2352  a -= a_offset;
2353  --work;
2354 
2355  /* Function Body */
2356  ifault = 1;
2357 
2358  i = n;
2359  for (i1 = 2; i1 <= n; ++i1) {
2360  l = i-2;
2361  f = a[i + (i-1)*ndima];
2362  gl = 0;
2363 
2364  if (l < 1) goto L25;
2365 
2366  for (k = 1; k <= l; ++k) {
2367  d__1 = a[i + k*ndima];
2368  gl += d__1*d__1;
2369  }
2370 L25:
2371  h = gl + f*f;
2372 
2373  if (gl > 1e-35) goto L30;
2374 
2375  work[i] = 0;
2376  work[n + i] = f;
2377  goto L65;
2378 L30:
2379  ++l;
2380  gl = TMath::Sqrt(h);
2381  if (f >= 0) gl = -gl;
2382  work[n + i] = gl;
2383  h -= f*gl;
2384  a[i + (i-1)*ndima] = f - gl;
2385  f = 0;
2386  for (j = 1; j <= l; ++j) {
2387  a[j + i*ndima] = a[i + j*ndima] / h;
2388  gl = 0;
2389  for (k = 1; k <= j; ++k) { gl += a[j + k*ndima]*a[i + k*ndima]; }
2390  if (j >= l) goto L47;
2391  j1 = j + 1;
2392  for (k = j1; k <= l; ++k) { gl += a[k + j*ndima]*a[i + k*ndima]; }
2393 L47:
2394  work[n + j] = gl / h;
2395  f += gl*a[j + i*ndima];
2396  }
2397  hh = f / (h + h);
2398  for (j = 1; j <= l; ++j) {
2399  f = a[i + j*ndima];
2400  gl = work[n + j] - hh*f;
2401  work[n + j] = gl;
2402  for (k = 1; k <= j; ++k) {
2403  a[j + k*ndima] = a[j + k*ndima] - f*work[n + k] - gl*a[i + k*ndima];
2404  }
2405  }
2406  work[i] = h;
2407 L65:
2408  --i;
2409  }
2410  work[1] = 0;
2411  work[n + 1] = 0;
2412  for (i = 1; i <= n; ++i) {
2413  l = i-1;
2414  if (work[i] == 0 || l == 0) goto L100;
2415 
2416  for (j = 1; j <= l; ++j) {
2417  gl = 0;
2418  for (k = 1; k <= l; ++k) { gl += a[i + k*ndima]*a[k + j*ndima]; }
2419  for (k = 1; k <= l; ++k) { a[k + j*ndima] -= gl*a[k + i*ndima]; }
2420  }
2421 L100:
2422  work[i] = a[i + i*ndima];
2423  a[i + i*ndima] = 1;
2424  if (l == 0) continue;
2425 
2426  for (j = 1; j <= l; ++j) {
2427  a[i + j*ndima] = 0;
2428  a[j + i*ndima] = 0;
2429  }
2430  }
2431 
2432  n1 = n - 1;
2433  for (i = 2; i <= n; ++i) {
2434  i0 = n + i-1;
2435  work[i0] = work[i0 + 1];
2436  }
2437  work[n + n] = 0;
2438  b = 0;
2439  f = 0;
2440  for (l = 1; l <= n; ++l) {
2441  j = 0;
2442  h = precis*(TMath::Abs(work[l]) + TMath::Abs(work[n + l]));
2443  if (b < h) b = h;
2444  for (m1 = l; m1 <= n; ++m1) {
2445  m = m1;
2446  if (TMath::Abs(work[n + m]) <= b) goto L150;
2447  }
2448 
2449 L150:
2450  if (m == l) goto L205;
2451 
2452 L160:
2453  if (j == mits) return;
2454  ++j;
2455  pt = (work[l + 1] - work[l]) / (work[n + l]*2);
2456  r = TMath::Sqrt(pt*pt + 1);
2457  pr = pt + r;
2458  if (pt < 0) pr = pt - r;
2459 
2460  h = work[l] - work[n + l] / pr;
2461  for (i = l; i <= n; ++i) { work[i] -= h; }
2462  f += h;
2463  pt = work[m];
2464  c = 1;
2465  s = 0;
2466  m1 = m - 1;
2467  i = m;
2468  for (i1 = l; i1 <= m1; ++i1) {
2469  j = i;
2470  --i;
2471  gl = c*work[n + i];
2472  h = c*pt;
2473  if (TMath::Abs(pt) >= TMath::Abs(work[n + i])) goto L180;
2474 
2475  c = pt / work[n + i];
2476  r = TMath::Sqrt(c*c + 1);
2477  work[n + j] = s*work[n + i]*r;
2478  s = 1 / r;
2479  c /= r;
2480  goto L190;
2481 L180:
2482  c = work[n + i] / pt;
2483  r = TMath::Sqrt(c*c + 1);
2484  work[n + j] = s*pt*r;
2485  s = c / r;
2486  c = 1 / r;
2487 L190:
2488  pt = c*work[i] - s*gl;
2489  work[j] = h + s*(c*gl + s*work[i]);
2490  for (k = 1; k <= n; ++k) {
2491  h = a[k + j*ndima];
2492  a[k + j*ndima] = s*a[k + i*ndima] + c*h;
2493  a[k + i*ndima] = c*a[k + i*ndima] - s*h;
2494  }
2495  }
2496  work[n + l] = s*pt;
2497  work[l] = c*pt;
2498 
2499  if (TMath::Abs(work[n + l]) > b) goto L160;
2500 
2501 L205:
2502  work[l] += f;
2503  }
2504  for (i = 1; i <= n1; ++i) {
2505  k = i;
2506  pt = work[i];
2507  i1 = i + 1;
2508  for (j = i1; j <= n; ++j) {
2509  if (work[j] >= pt) continue;
2510  k = j;
2511  pt = work[j];
2512  }
2513 
2514  if (k == i) continue;
2515 
2516  work[k] = work[i];
2517  work[i] = pt;
2518  for (j = 1; j <= n; ++j) {
2519  pt = a[j + i*ndima];
2520  a[j + i*ndima] = a[j + k*ndima];
2521  a[j + k*ndima] = pt;
2522  }
2523  }
2524  ifault = 0;
2525 } /* mneig_ */
2526 
2527 ////////////////////////////////////////////////////////////////////////////////
2528 /// Calculates the external error matrix from the internal matrix
2529 ///
2530 /// Note that if the matrix is declared like Double_t matrix[5][5]
2531 /// in the calling program, one has to call mnemat with, eg
2532 /// gMinuit->mnemat(&matrix[0][0],5);
2533 
2534 void TMinuit::mnemat(Double_t *emat, Int_t ndim)
2535 {
2536  /* System generated locals */
2537  Int_t emat_dim1, emat_offset;
2538 
2539  /* Local variables */
2540  Double_t dxdi, dxdj;
2541  Int_t i, j, k, npard, k2, kk, iz, nperln, kga, kgb;
2542  TString ctemp;
2543 
2544  /* Parameter adjustments */
2545  emat_dim1 = ndim;
2546  emat_offset = emat_dim1 + 1;
2547  emat -= emat_offset;
2548 
2549  /* Function Body */
2550  if (fISW[1] < 1) return;
2551  if (fISW[4] >= 2) {
2552  Printf(" EXTERNAL ERROR MATRIX. NDIM=%4d NPAR=%3d ERR DEF=%g",ndim,fNpar,fUp);
2553  }
2554 //*-*- size of matrix to be printed
2555  npard = fNpar;
2556  if (ndim < fNpar) {
2557  npard = ndim;
2558  if (fISW[4] >= 0) {
2559  Printf(" USER-DIMENSIONED ARRAY EMAT NOT BIG ENOUGH. REDUCED MATRIX CALCULATED.");
2560  }
2561  }
2562 //*-*- NPERLN is the number of elements that fit on one line
2563 
2564  nperln = (fNpagwd - 5) / 10;
2565  nperln = TMath::Min(nperln,13);
2566  if (fISW[4] >= 1 && npard > nperln) {
2567  Printf(" ELEMENTS ABOVE DIAGONAL ARE NOT PRINTED.");
2568  }
2569 //*-*- I counts the rows of the matrix
2570  for (i = 1; i <= npard; ++i) {
2571  mndxdi(fX[i-1], i-1, dxdi);
2572  kga = i*(i-1) / 2;
2573  for (j = 1; j <= i; ++j) {
2574  mndxdi(fX[j-1], j-1, dxdj);
2575  kgb = kga + j;
2576  emat[i + j*emat_dim1] = dxdi*fVhmat[kgb-1]*dxdj*fUp;
2577  emat[j + i*emat_dim1] = emat[i + j*emat_dim1];
2578  }
2579  }
2580 //*-*- IZ is number of columns to be printed in row I
2581  if (fISW[4] >= 2) {
2582  for (i = 1; i <= npard; ++i) {
2583  iz = npard;
2584  if (npard >= nperln) iz = i;
2585  ctemp = " ";
2586  for (k = 1; nperln < 0 ? k >= iz : k <= iz; k += nperln) {
2587  k2 = k + nperln - 1;
2588  if (k2 > iz) k2 = iz;
2589  for (kk = k; kk <= k2; ++kk) {
2590  ctemp += TString::Format("%10.3e ",emat[i + kk*emat_dim1]);
2591  }
2592  Printf("%s",(const char*)ctemp);
2593  }
2594  }
2595  }
2596 } /* mnemat_ */
2597 
2598 ////////////////////////////////////////////////////////////////////////////////
2599 ///*-*-*-*-*-*-*-*-*-*Utility routine to get MINOS errors*-*-*-*-*-*-*-*-*-*-*
2600 ///*-* ===================================
2601 ///*-* Called by user.
2602 ///*-* NUMBER is the parameter number
2603 ///*-* values returned by MNERRS:
2604 ///*-* EPLUS, EMINUS are MINOS errors of parameter NUMBER,
2605 ///*-* EPARAB is 'parabolic' error (from error matrix).
2606 ///*-* (Errors not calculated are set = 0)
2607 ///*-* GCC is global correlation coefficient from error matrix
2608 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2609 
2610 void TMinuit::mnerrs(Int_t number, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &gcc)
2611 {
2612  Double_t dxdi;
2613  Int_t ndiag, iin, iex;
2614 
2615  iex = number+1;
2616 
2617  if (iex > fNu || iex <= 0) goto L900;
2618  iin = fNiofex[iex-1];
2619  if (iin <= 0) goto L900;
2620 
2621 //*-*- IEX is external number, IIN is internal number
2622  eplus = fErp[iin-1];
2623  if (eplus == fUndefi) eplus = 0;
2624  eminus = fErn[iin-1];
2625  if (eminus == fUndefi) eminus = 0;
2626  mndxdi(fX[iin-1], iin-1, dxdi);
2627  ndiag = iin*(iin + 1) / 2;
2628  eparab = TMath::Abs(dxdi*TMath::Sqrt(TMath::Abs(fUp*fVhmat[ndiag- 1])));
2629 //*-*- global correlation coefficient
2630  gcc = 0;
2631  if (fISW[1] < 2) return;
2632  gcc = fGlobcc[iin-1];
2633  return;
2634 //*-*- ERROR. parameter number not valid
2635 L900:
2636  eplus = 0;
2637  eminus = 0;
2638  eparab = 0;
2639  gcc = 0;
2640 } /* mnerrs_ */
2641 
2642 ////////////////////////////////////////////////////////////////////////////////
2643 ///*-*-*-*-*-*-*Evaluates the function being analyzed by MNCROS*-*-*-*-*-*-*-*
2644 ///*-* ===============================================
2645 ///*-* Evaluates the function being analyzed by MNCROS, which is
2646 ///*-* generally the minimum of FCN with respect to all remaining
2647 ///*-* variable parameters. The class data members contains the
2648 ///*-* data necessary to know the values of U(KE1CR) and U(KE2CR)
2649 ///*-* to be used, namely U(KE1CR) = XMIDCR + ANEXT*XDIRCR
2650 ///*-* and (if KE2CR .NE. 0) U(KE2CR) = YMIDCR + ANEXT*YDIRCR
2651 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2652 
2653 void TMinuit::mneval(Double_t anext, Double_t &fnext, Int_t &ierev)
2654 {
2655  Int_t nparx;
2656 
2657  fU[fKe1cr-1] = fXmidcr + anext*fXdircr;
2658  if (fKe2cr != 0) fU[fKe2cr-1] = fYmidcr + anext*fYdircr;
2659  mninex(fX);
2660  nparx = fNpar;
2661  Eval(nparx, fGin, fnext, fU, 4); ++fNfcn;
2662  ierev = 0;
2663  if (fNpar > 0) {
2664  fItaur = 1;
2665  fAmin = fnext;
2666  fISW[0] = 0;
2667  mnmigr();
2668  fItaur = 0;
2669  fnext = fAmin;
2670  if (fISW[0] >= 1) ierev = 1;
2671  if (fISW[3] < 1) ierev = 2;
2672  }
2673 } /* mneval_ */
2674 
2675 ////////////////////////////////////////////////////////////////////////////////
2676 ///*-*-*-*-*-*Interprets a command and takes appropriate action*-*-*-*-*-*-*-*
2677 ///*-* =================================================
2678 ///*-* either directly by skipping to the corresponding code in
2679 ///*-* MNEXCM, or by setting up a call to a function
2680 ///*-*
2681 ///*-* recognized MINUIT commands:
2682 ///*-* obsolete commands:
2683 ///*-* IERFLG is now (94.5) defined the same as ICONDN in MNCOMD
2684 ///*-* = 0: command executed normally
2685 ///*-* 1: command is blank, ignored
2686 ///*-* 2: command line unreadable, ignored
2687 ///*-* 3: unknown command, ignored
2688 ///*-* 4: abnormal termination (e.g., MIGRAD not converged)
2689 ///*-* 9: reserved
2690 ///*-* 10: END command
2691 ///*-* 11: EXIT or STOP command
2692 ///*-* 12: RETURN command
2693 ///*-*
2694 ///*-* see also http://wwwasdoc.web.cern.ch/wwwasdoc/minuit/node18.html for the possible list
2695 ///*-* of all Minuit commands
2696 ///*-*
2697 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2698 
2699 void TMinuit::mnexcm(const char *command, Double_t *plist, Int_t llist, Int_t &ierflg)
2700 {
2701  /* Initialized data */
2702 
2703  TString comand = command;
2704  static const char *cname[40] = {
2705  "MINImize ",
2706  "SEEk ",
2707  "SIMplex ",
2708  "MIGrad ",
2709  "MINOs ",
2710  "SET xxx ",
2711  "SHOw xxx ",
2712  "TOP of pag",
2713  "FIX ",
2714  "REStore ",
2715  "RELease ",
2716  "SCAn ",
2717  "CONtour ",
2718  "HESse ",
2719  "SAVe ",
2720  "IMProve ",
2721  "CALl fcn ",
2722  "STAndard ",
2723  "END ",
2724  "EXIt ",
2725  "RETurn ",
2726  "CLEar ",
2727  "HELP ",
2728  "MNContour ",
2729  "STOp ",
2730  "JUMp ",
2731  " ",
2732  " ",
2733  " ",
2734  " ",
2735  " ",
2736  " ",
2737  " ",
2738  "COVARIANCE",
2739  "PRINTOUT ",
2740  "GRADIENT ",
2741  "MATOUT ",
2742  "ERROR DEF ",
2743  "LIMITS ",
2744  "PUNCH "};
2745 
2746  Int_t nntot = 40;
2747 
2748  /* Local variables */
2749  Double_t step, xptu[101], yptu[101], f, rno;
2750  Int_t icol, kcol, ierr, iint, iext, lnow, nptu, i, iflag, ierrf;
2751  Int_t ilist, nparx, izero, nf, lk, it, iw, inonde, nsuper;
2752  Int_t it2, ke1, ke2, nowprt, kll, krl;
2753  TString chwhy, c26, cvblnk, cneway, comd;
2754  TString ctemp;
2755  Bool_t lfreed, ltofix, lfixed;
2756 
2757 //*-* alphabetical order of command names!
2758 
2759  /* Function Body */
2760 
2761  lk = comand.Length();
2762  if (lk > 20) lk = 20;
2763  fCword = comand;
2764  fCword.ToUpper();
2765 //*-*- Copy the first MAXP arguments into WORD7, making
2766 //*-*- sure that WORD7(1)=0 if LLIST=0
2767  for (iw = 1; iw <= fMaxpar; ++iw) {
2768  fWord7[iw-1] = 0;
2769  if (iw <= llist) fWord7[iw-1] = plist[iw-1];
2770  }
2771  ++fIcomnd;
2772  fNfcnlc = fNfcn;
2773  if (fCword(0,7) != "SET PRI" || fWord7[0] >= 0) {
2774  if (fISW[4] >= 0) {
2775  lnow = llist;
2776  if (lnow > 4) lnow = 4;
2777  Printf(" **********");
2778  ctemp.Form(" **%5d **%s",fIcomnd,(const char*)fCword);
2779  for (i = 1; i <= lnow; ++i) {
2780  ctemp += TString::Format("%12.4g",plist[i-1]);
2781  }
2782  Printf("%s",(const char*)ctemp);
2783  inonde = 0;
2784  if (llist > lnow) {
2785  kll = llist;
2786  if (llist > fMaxpar) {
2787  inonde = 1;
2788  kll = fMaxpar;
2789  }
2790  Printf(" ***********");
2791  for (i = lnow + 1; i <= kll; ++i) {
2792  Printf("%12.4g",plist[i-1]);
2793  }
2794  }
2795  Printf(" **********");
2796  if (inonde > 0) {
2797  Printf(" ERROR: ABOVE CALL TO MNEXCM TRIED TO PASS MORE THAN %d PARAMETERS.", fMaxpar);
2798  }
2799  }
2800  }
2801  fNfcnmx = Int_t(fWord7[0]);
2802  if (fNfcnmx <= 0) {
2803  fNfcnmx = fNpar*100 + 200 + fNpar*fNpar*5;
2804  }
2805  fEpsi = fWord7[1];
2806  if (fEpsi <= 0) {
2807  fEpsi = fUp*.1;
2808  }
2809  fLnewmn = kFALSE;
2810  fLphead = kTRUE;
2811  fISW[0] = 0;
2812  ierflg = 0;
2813 //*-*- look for command in list CNAME . . . . . . . . . .
2814  ctemp = fCword(0,3);
2815  for (i = 1; i <= nntot; ++i) {
2816  if (strncmp(ctemp.Data(),cname[i-1],3) == 0) goto L90;
2817  }
2818  Printf("UNKNOWN COMMAND IGNORED:%s", comand.Data());
2819  ierflg = 3;
2820  return;
2821 //*-*- normal case: recognized MINUIT command . . . . . . .
2822 L90:
2823  if (fCword(0,4) == "MINO") i = 5;
2824  if (i != 6 && i != 7 && i != 8 && i != 23) {
2825  fCfrom = cname[i-1];
2826  fNfcnfr = fNfcn;
2827  }
2828 //*-*- 1 2 3 4 5 6 7 8 9 10
2829  switch (i) {
2830  case 1: goto L400;
2831  case 2: goto L200;
2832  case 3: goto L300;
2833  case 4: goto L400;
2834  case 5: goto L500;
2835  case 6: goto L700;
2836  case 7: goto L700;
2837  case 8: goto L800;
2838  case 9: goto L900;
2839  case 10: goto L1000;
2840  case 11: goto L1100;
2841  case 12: goto L1200;
2842  case 13: goto L1300;
2843  case 14: goto L1400;
2844  case 15: goto L1500;
2845  case 16: goto L1600;
2846  case 17: goto L1700;
2847  case 18: goto L1800;
2848  case 19: goto L1900;
2849  case 20: goto L1900;
2850  case 21: goto L1900;
2851  case 22: goto L2200;
2852  case 23: goto L2300;
2853  case 24: goto L2400;
2854  case 25: goto L1900;
2855  case 26: goto L2600;
2856  case 27: goto L3300;
2857  case 28: goto L3300;
2858  case 29: goto L3300;
2859  case 30: goto L3300;
2860  case 31: goto L3300;
2861  case 32: goto L3300;
2862  case 33: goto L3300;
2863  case 34: goto L3400;
2864  case 35: goto L3500;
2865  case 36: goto L3600;
2866  case 37: goto L3700;
2867  case 38: goto L3800;
2868  case 39: goto L3900;
2869  case 40: goto L4000;
2870  }
2871 //*-*- . . . . . . . . . . seek
2872 L200:
2873  mnseek();
2874  return;
2875 //*-*- . . . . . . . . . . simplex
2876 L300:
2877  mnsimp();
2878  if (fISW[3] < 1) ierflg = 4;
2879  return;
2880 //*-*- . . . . . . migrad, minimize
2881 L400:
2882  nf = fNfcn;
2883  fApsi = fEpsi;
2884  mnmigr();
2885  mnwerr();
2886  if (fISW[3] >= 1) return;
2887  ierflg = 4;
2888  if (fISW[0] == 1) return;
2889  if (fCword(0,3) == "MIG") return;
2890 
2891  fNfcnmx = fNfcnmx + nf - fNfcn;
2892  nf = fNfcn;
2893  mnsimp();
2894  if (fISW[0] == 1) return;
2895  fNfcnmx = fNfcnmx + nf - fNfcn;
2896  mnmigr();
2897  if (fISW[3] >= 1) ierflg = 0;
2898  mnwerr();
2899  return;
2900 //*-*- . . . . . . . . . . minos
2901 L500:
2902  nsuper = fNfcn + ((fNpar + 1) << 1)*fNfcnmx;
2903 //*-*- possible loop over new minima
2904  fEpsi = fUp*.1;
2905 L510:
2906  fCfrom = cname[i-1]; // ensure that mncuve complains about MINOS not MIGRAD
2907  mncuve();
2908  mnmnos();
2909  if (! fLnewmn) return;
2910  mnrset(0);
2911  mnmigr();
2912  mnwerr();
2913  if (fNfcn < nsuper) goto L510;
2914  Printf(" TOO MANY FUNCTION CALLS. MINOS GIVES UP");
2915  ierflg = 4;
2916  return;
2917 //*-*- . . . . . . . . . .set, show
2918 L700:
2919  mnset();
2920  return;
2921 //*-*- . . . . . . . . . . top of page
2922 
2923 L800:
2924  Printf("1");
2925  return;
2926 //*-*- . . . . . . . . . . fix
2927 L900:
2928  ltofix = kTRUE;
2929 //*-*- . . (also release) ....
2930 L901:
2931  lfreed = kFALSE;
2932  lfixed = kFALSE;
2933  if (llist == 0) {
2934  Printf("%s: NO PARAMETERS REQUESTED ",(const char*)fCword);
2935  return;
2936  }
2937  for (ilist = 1; ilist <= llist; ++ilist) {
2938  iext = Int_t(plist[ilist-1]);
2939  chwhy = " IS UNDEFINED.";
2940  if (iext <= 0) goto L930;
2941  if (iext > fNu) goto L930;
2942  if (fNvarl[iext-1] < 0) goto L930;
2943  chwhy = " IS CONSTANT. ";
2944  if (fNvarl[iext-1] == 0) goto L930;
2945  iint = fNiofex[iext-1];
2946  if (ltofix) {
2947  chwhy = " ALREADY FIXED.";
2948  if (iint == 0) goto L930;
2949  mnfixp(iint-1, ierr);
2950  if (ierr == 0) lfixed = kTRUE;
2951  else ierflg = 4;
2952  } else {
2953  chwhy = " ALREADY VARIABLE.";
2954  if (iint > 0) goto L930;
2955  krl = -abs(iext);
2956  mnfree(krl);
2957  lfreed = kTRUE;
2958  }
2959  continue;
2960 L930:
2961  if (fISW[4] >= 0) Printf(" PARAMETER %4d %s IGNORED.",iext,(const char*)chwhy);
2962  }
2963  if (lfreed || lfixed) mnrset(0);
2964  if (lfreed) {
2965  fISW[1] = 0;
2966  fDcovar = 1;
2967  fEDM = fBigedm;
2968  fISW[3] = 0;
2969  }
2970  mnwerr();
2971  if (fISW[4] > 1) mnprin(5, fAmin);
2972  return;
2973 //*-*- . . . . . . . . . . restore
2974 L1000:
2975  it = Int_t(fWord7[0]);
2976  if (it > 1 || it < 0) goto L1005;
2977  lfreed = fNpfix > 0;
2978  mnfree(it);
2979  if (lfreed) {
2980  mnrset(0);
2981  fISW[1] = 0;
2982  fDcovar = 1;
2983  fEDM = fBigedm;
2984  }
2985  return;
2986 L1005:
2987  Printf(" IGNORED. UNKNOWN ARGUMENT:%4d",it);
2988  ierflg = 3;
2989  return;
2990 //*-*- . . . . . . . . . . release
2991 L1100:
2992  ltofix = kFALSE;
2993  goto L901;
2994 //*-*- . . . . . . . . . . scan . . .
2995 L1200:
2996  iext = Int_t(fWord7[0]);
2997  if (iext <= 0) goto L1210;
2998  it2 = 0;
2999  if (iext <= fNu) it2 = fNiofex[iext-1];
3000  if (it2 <= 0) goto L1250;
3001 
3002 L1210:
3003  mnscan();
3004  return;
3005 L1250:
3006  Printf(" PARAMETER %4d NOT VARIABLE.",iext);
3007  ierflg = 3;
3008  return;
3009 //*-*- . . . . . . . . . . contour
3010 L1300:
3011  ke1 = Int_t(fWord7[0]);
3012  ke2 = Int_t(fWord7[1]);
3013  if (ke1 == 0) {
3014  if (fNpar == 2) {
3015  ke1 = fNexofi[0];
3016  ke2 = fNexofi[1];
3017  } else {
3018  Printf("%s: NO PARAMETERS REQUESTED ",(const char*)fCword);
3019  ierflg = 3;
3020  return;
3021  }
3022  }
3023  fNfcnmx = 1000;
3024  mncntr(ke1-1, ke2-1, ierrf);
3025  if (ierrf > 0) ierflg = 3;
3026  return;
3027 //*-*- . . . . . . . . . . hesse
3028 L1400:
3029  mnhess();
3030  mnwerr();
3031  if (fISW[4] >= 0) mnprin(2, fAmin);
3032  if (fISW[4] >= 1) mnmatu(1);
3033  return;
3034 //*-*- . . . . . . . . . . save
3035 L1500:
3036  mnsave();
3037  return;
3038 //*-*- . . . . . . . . . . improve
3039 L1600:
3040  mncuve();
3041  mnimpr();
3042  if (fLnewmn) goto L400;
3043  ierflg = 4;
3044  return;
3045 //*-*- . . . . . . . . . . call fcn
3046 L1700:
3047  iflag = Int_t(fWord7[0]);
3048  nparx = fNpar;
3049  f = fUndefi;
3050  Eval(nparx, fGin, f, fU, iflag); ++fNfcn;
3051  nowprt = 0;
3052  if (f != fUndefi) {
3053  if (fAmin == fUndefi) {
3054  fAmin = f;
3055  nowprt = 1;
3056  } else if (f < fAmin) {
3057  fAmin = f;
3058  nowprt = 1;
3059  }
3060  if (fISW[4] >= 0 && iflag <= 5 && nowprt == 1) {
3061  mnprin(5, fAmin);
3062  }
3063  if (iflag == 3) fFval3 = f;
3064  }
3065  if (iflag > 5) mnrset(1);
3066  return;
3067 //*-*- . . . . . . . . . . standard
3068 L1800:
3069 // stand();
3070  return;
3071 //*-*- . . . return, stop, end, exit
3072 L1900:
3073  it = Int_t(fWord7[0]);
3074  if (fFval3 != fAmin && it == 0) {
3075  iflag = 3;
3076  if (fISW[4] >= 0) Printf(" CALL TO USER FUNCTION WITH IFLAG = 3");
3077  nparx = fNpar;
3078  Eval(nparx, fGin, f, fU, iflag); ++fNfcn;
3079  }
3080  ierflg = 11;
3081  if (fCword(0,3) == "END") ierflg = 10;
3082  if (fCword(0,3) == "RET") ierflg = 12;
3083  return;
3084 //*-*- . . . . . . . . . . clear
3085 L2200:
3086  mncler();
3087  if (fISW[4] >= 1) {
3088  Printf(" MINUIT MEMORY CLEARED. NO PARAMETERS NOW DEFINED.");
3089  }
3090  return;
3091 //*-*- . . . . . . . . . . help
3092 L2300:
3093  kcol = 0;
3094  for (icol = 5; icol <= lk; ++icol) {
3095  if (fCword[icol-1] == ' ') continue;
3096  kcol = icol;
3097  goto L2320;
3098  }
3099 L2320:
3100  if (kcol == 0) comd = "* ";
3101  else comd = fCword(kcol-1,lk-kcol+1);
3102  mnhelp(comd);
3103  return;
3104 //*-*- . . . . . . . . . . MNContour
3105 L2400:
3106  fEpsi = fUp*.05;
3107  ke1 = Int_t(fWord7[0]);
3108  ke2 = Int_t(fWord7[1]);
3109  if (ke1 == 0 && fNpar == 2) {
3110  ke1 = fNexofi[0];
3111  ke2 = fNexofi[1];
3112  }
3113  nptu = Int_t(fWord7[2]);
3114  if (nptu <= 0) nptu = 20;
3115  if (nptu > 101) nptu = 101;
3116  fNfcnmx = (nptu + 5)*100*(fNpar + 1);
3117  mncont(ke1-1, ke2-1, nptu, xptu, yptu, ierrf);
3118  if (ierrf < nptu) ierflg = 4;
3119  if (ierrf == -1) ierflg = 3;
3120  return;
3121 //*-*- . . . . . . . . . . jump
3122 L2600:
3123  step = fWord7[0];
3124  if (step <= 0) step = 2;
3125  rno = 0;
3126  izero = 0;
3127  for (i = 1; i <= fNpar; ++i) {
3128  mnrn15(rno, izero);
3129  rno = rno*2 - 1;
3130  fX[i-1] += rno*step*fWerr[i-1];
3131  }
3132  mninex(fX);
3133  mnamin();
3134  mnrset(0);
3135  return;
3136 //*-*- . . . . . . . . . . blank line
3137 L3300:
3138  Printf(" BLANK COMMAND IGNORED.");
3139  ierflg = 1;
3140  return;
3141 //*-* . . . . . . . . obsolete commands . . . . . . . . . . . . . .
3142 //*-*- . . . . . . . . . . covariance
3143 L3400:
3144  Printf(" THE *COVARIANCE* COMMAND IS OSBSOLETE. THE COVARIANCE MATRIX IS NOW SAVED IN A DIFFERENT FORMAT WITH THE *SAVE* COMMAND AND READ IN WITH:*SET COVARIANCE*");
3145  ierflg = 3;
3146  return;
3147 //*-*- . . . . . . . . . . printout
3148 L3500:
3149  cneway = "SET PRInt ";
3150  goto L3100;
3151 //*-*- . . . . . . . . . . gradient
3152 L3600:
3153  cneway = "SET GRAd ";
3154  goto L3100;
3155 //*-*- . . . . . . . . . . matout
3156 L3700:
3157  cneway = "SHOW COVar";
3158  goto L3100;
3159 //*-*- . . . . . . . . . error def
3160 L3800:
3161  cneway = "SET ERRdef";
3162  goto L3100;
3163 //*-*- . . . . . . . . . . limits
3164 L3900:
3165  cneway = "SET LIMits";
3166  goto L3100;
3167 //*-*- . . . . . . . . . . punch
3168 L4000:
3169  cneway = "SAVE ";
3170 //*-*- ....... come from obsolete commands
3171 L3100:
3172  Printf(" OBSOLETE COMMAND:%s PLEASE USE:%s",(const char*)fCword
3173  ,(const char*)cneway);
3174  fCword = cneway;
3175  if (fCword == "SAVE ") goto L1500;
3176  goto L700;
3177 //*-* . . . . . . . . . . . . . . . . . .
3178 } /* mnexcm_ */
3179 
3180 ////////////////////////////////////////////////////////////////////////////////
3181 ///*-*-*-*-*Transforms the external parameter values U to internal values*-*-*
3182 ///*-* =============================================================
3183 ///*-* Transforms the external parameter values U to internal
3184 ///*-* values in the dense array PINT.
3185 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
3186 
3188 {
3189  Double_t pinti;
3190  Int_t iint, iext;
3191 
3192  fLimset = kFALSE;
3193  for (iint = 1; iint <= fNpar; ++iint) {
3194  iext = fNexofi[iint-1];
3195  mnpint(fU[iext-1], iext-1, pinti);
3196  pint[iint-1] = pinti;
3197  }
3198 } /* mnexin_ */
3199 
3200 ////////////////////////////////////////////////////////////////////////////////
3201 ///*-*-*-*-*-*-*Removes parameter IINT from the internal parameter list*-*-*
3202 ///*-* =======================================================
3203 ///*-* and arranges the rest of the list to fill the hole.
3204 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
3205 
3206 void TMinuit::mnfixp(Int_t iint1, Int_t &ierr)
3207 {
3208  /* Local variables */
3209  Double_t yyover;
3210  Int_t kold, nold, ndex, knew, iext, i, j, m, n, lc, ik;
3211 
3212 //*-*- first see if it can be done
3213  ierr = 0;
3214  Int_t iint = iint1+1;
3215  if (iint > fNpar || iint <= 0) {
3216  ierr = 1;
3217  Printf(" MINUIT ERROR. ARGUMENT TO MNFIXP=%4d",iint);
3218  return;
3219  }
3220  iext = fNexofi[iint-1];
3221  if (fNpfix >= fMaxpar) {
3222  ierr = 1;
3223  Printf(" MINUIT CANNOT FIX PARAMETER %4d MAXIMUM NUMBER THAT CAN BE FIXED IS %d",iext,fMaxpar);
3224  return;
3225  }
3226 //*-*- reduce number of variable parameters by one
3227 
3228  fNiofex[iext-1] = 0;
3229  nold = fNpar;
3230  --fNpar;
3231 //*-*- save values in case parameter is later restored
3232 
3233  ++fNpfix;
3234  fIpfix[fNpfix-1] = iext;
3235  lc = iint;
3236  fXs[fNpfix-1] = fX[lc-1];
3237  fXts[fNpfix-1] = fXt[lc-1];
3238  fDirins[fNpfix-1] = fWerr[lc-1];
3239  fGrds[fNpfix-1] = fGrd[lc-1];
3240  fG2s[fNpfix-1] = fG2[lc-1];
3241  fGsteps[fNpfix-1] = fGstep[lc-1];
3242 //*-*- shift values for other parameters to fill hole
3243  for (ik = iext + 1; ik <= fNu; ++ik) {
3244  if (fNiofex[ik-1] > 0) {
3245  lc = fNiofex[ik-1] - 1;
3246  fNiofex[ik-1] = lc;
3247  fNexofi[lc-1] = ik;
3248  fX[lc-1] = fX[lc];
3249  fXt[lc-1] = fXt[lc];
3250  fDirin[lc-1] = fDirin[lc];
3251  fWerr[lc-1] = fWerr[lc];
3252  fGrd[lc-1] = fGrd[lc];
3253  fG2[lc-1] = fG2[lc];
3254  fGstep[lc-1] = fGstep[lc];
3255  }
3256  }
3257  if (fISW[1] <= 0) return;
3258 //*-*- remove one row and one column from variance matrix
3259  if (fNpar <= 0) return;
3260  for (i = 1; i <= nold; ++i) {
3261  m = TMath::Max(i,iint);
3262  n = TMath::Min(i,iint);
3263  ndex = m*(m-1) / 2 + n;
3264  fFIXPyy[i-1] = fVhmat[ndex-1];
3265  }
3266  yyover = 1 / fFIXPyy[iint-1];
3267  knew = 0;
3268  kold = 0;
3269  for (i = 1; i <= nold; ++i) {
3270  for (j = 1; j <= i; ++j) {
3271  ++kold;
3272  if (j == iint || i == iint) continue;
3273  ++knew;
3274  fVhmat[knew-1] = fVhmat[kold-1] - fFIXPyy[j-1]*fFIXPyy[i-1]*yyover;
3275  }
3276  }
3277 } /* mnfixp_ */
3278 
3279 ////////////////////////////////////////////////////////////////////////////////
3280 ///*-*-*-*Restores one or more fixed parameter(s) to variable status*-*-*-*-*-*
3281 ///*-* ==========================================================
3282 ///*-* Restores one or more fixed parameter(s) to variable status
3283 ///*-* by inserting it into the internal parameter list at the
3284 ///*-* appropriate place.
3285 ///*-*
3286 ///*-* K = 0 means restore all parameters
3287 ///*-* K = 1 means restore the last parameter fixed
3288 ///*-* K = -I means restore external parameter I (if possible)
3289 ///*-* IQ = fix-location where internal parameters were stored
3290 ///*-* IR = external number of parameter being restored
3291 ///*-* IS = internal number of parameter being restored
3292 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
3293 
3295 {
3296  /* Local variables */
3297  Double_t grdv, xv, dirinv, g2v, gstepv, xtv;
3298  Int_t i, ipsav, ka, lc, ik, iq, ir, is;
3299 
3300  if (k > 1) {
3301  Printf(" CALL TO MNFREE IGNORED. ARGUMENT GREATER THAN ONE");
3302  }
3303  if (fNpfix < 1) {
3304  Printf(" CALL TO MNFREE IGNORED. THERE ARE NO FIXED PARAMETERS");
3305  }
3306  if (k == 1 || k == 0) goto L40;
3307 
3308 //*-*- release parameter with specified external number
3309  ka = abs(k);
3310  if (fNiofex[ka-1] == 0) goto L15;
3311  Printf(" IGNORED. PARAMETER SPECIFIED IS ALREADY VARIABLE.");
3312  return;
3313 L15:
3314  if (fNpfix < 1) goto L21;
3315  for (ik = 1; ik <= fNpfix; ++ik) { if (fIpfix[ik-1] == ka) goto L24; }
3316 L21:
3317  Printf(" PARAMETER %4d NOT FIXED. CANNOT BE RELEASED.",ka);
3318  return;
3319 L24:
3320  if (ik == fNpfix) goto L40;
3321 
3322 //*-*- move specified parameter to end of list
3323  ipsav = ka;
3324  xv = fXs[ik-1];
3325  xtv = fXts[ik-1];
3326  dirinv = fDirins[ik-1];
3327  grdv = fGrds[ik-1];
3328  g2v = fG2s[ik-1];
3329  gstepv = fGsteps[ik-1];
3330  for (i = ik + 1; i <= fNpfix; ++i) {
3331  fIpfix[i-2] = fIpfix[i-1];
3332  fXs[i-2] = fXs[i-1];
3333  fXts[i-2] = fXts[i-1];
3334  fDirins[i-2] = fDirins[i-1];
3335  fGrds[i-2] = fGrds[i-1];
3336  fG2s[i-2] = fG2s[i-1];
3337  fGsteps[i-2] = fGsteps[i-1];
3338  }
3339  fIpfix[fNpfix-1] = ipsav;
3340  fXs[fNpfix-1] = xv;
3341  fXts[fNpfix-1] = xtv;
3342  fDirins[fNpfix-1] = dirinv;
3343  fGrds[fNpfix-1] = grdv;
3344  fG2s[fNpfix-1] = g2v;
3345  fGsteps[fNpfix-1] = gstepv;
3346 //*-*- restore last parameter in fixed list -- IPFIX(NPFIX)
3347 L40:
3348  if (fNpfix < 1) goto L300;
3349  ir = fIpfix[fNpfix-1];
3350  is = 0;
3351  for (ik = fNu; ik >= ir; --ik) {
3352  if (fNiofex[ik-1] > 0) {
3353  lc = fNiofex[ik-1] + 1;
3354  is = lc - 1;
3355  fNiofex[ik-1] = lc;
3356  fNexofi[lc-1] = ik;
3357  fX[lc-1] = fX[lc-2];
3358  fXt[lc-1] = fXt[lc-2];
3359  fDirin[lc-1] = fDirin[lc-2];
3360  fWerr[lc-1] = fWerr[lc-2];
3361  fGrd[lc-1] = fGrd[lc-2];
3362  fG2[lc-1] = fG2[lc-2];
3363  fGstep[lc-1] = fGstep[lc-2];
3364  }
3365  }
3366  ++fNpar;
3367  if (is == 0) is = fNpar;
3368  fNiofex[ir-1] = is;
3369  fNexofi[is-1] = ir;
3370  iq = fNpfix;
3371  fX[is-1] = fXs[iq-1];
3372  fXt[is-1] = fXts[iq-1];
3373  fDirin[is-1] = fDirins[iq-1];
3374  fWerr[is-1] = fDirins[iq-1];
3375  fGrd[is-1] = fGrds[iq-1];
3376  fG2[is-1] = fG2s[iq-1];
3377  fGstep[is-1] = fGsteps[iq-1];
3378  --fNpfix;
3379  fISW[1] = 0;
3380  fDcovar = 1;
3381  if (fISW[4] - fItaur >= 1) {
3382  Printf(" PARAMETER %4d %s RESTORED TO VARIABLE.",ir,
3383  (const char*)fCpnam[ir-1]);
3384  }
3385  if (k == 0) goto L40;
3386 L300:
3387 //*-*- if different from internal, external values are taken
3388  mnexin(fX);
3389 } /* mnfree_ */
3390 
3391 ////////////////////////////////////////////////////////////////////////////////
3392 ///*-*-*-*-*-*-*-*-*-*Interprets the SET GRAD command*-*-*-*-*-*-*-*-*-*-*-*-*
3393 ///*-* ===============================
3394 ///*-* Called from MNSET
3395 ///*-* Interprets the SET GRAD command, which informs MINUIT whether
3396 ///*-* the first derivatives of FCN will be calculated by the user
3397 ///*-* inside FCN. It can check the user derivative calculation
3398 ///*-* by comparing it with a finite difference approximation.
3399 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
3400 
3402 {
3403  /* Local variables */
3404  Double_t fzero, err;
3405  Int_t i, nparx, lc, istsav;
3406  Bool_t lnone;
3407  static TString cwd = " ";
3408 
3409  fISW[2] = 1;
3410  nparx = fNpar;
3411  if (fWord7[0] > 0) goto L2000;
3412 
3413 //*-*- get user-calculated first derivatives from FCN
3414  for (i = 1; i <= fNu; ++i) { fGin[i-1] = fUndefi; }
3415  mninex(fX);
3416  Eval(nparx, fGin, fzero, fU, 2); ++fNfcn;
3417  mnderi();
3418  for (i = 1; i <= fNpar; ++i) { fGRADgf[i-1] = fGrd[i-1]; }
3419 //*-*- get MINUIT-calculated first derivatives
3420  fISW[2] = 0;
3421  istsav = fIstrat;
3422  fIstrat = 2;
3423  mnhes1();
3424  fIstrat = istsav;
3425  Printf(" CHECK OF GRADIENT CALCULATION IN FCN");
3426  Printf(" PARAMETER G(IN FCN) G(MINUIT) DG(MINUIT) AGREEMENT");
3427  fISW[2] = 1;
3428  lnone = kFALSE;
3429  for (lc = 1; lc <= fNpar; ++lc) {
3430  i = fNexofi[lc-1];
3431  cwd = "GOOD";
3432  err = fDgrd[lc-1];
3433  if (TMath::Abs(fGRADgf[lc-1] - fGrd[lc-1]) > err) cwd = " BAD";
3434  if (fGin[i-1] == fUndefi) {
3435  cwd = "NONE";
3436  lnone = kTRUE;
3437  fGRADgf[lc-1] = 0;
3438  }
3439  if (cwd != "GOOD") fISW[2] = 0;
3440  Printf(" %5d %10s%12.4e%12.4e%12.4e %s",i
3441  ,(const char*)fCpnam[i-1]
3442  ,fGRADgf[lc-1],fGrd[lc-1],err,(const char*)cwd);
3443  }
3444  if (lnone) {
3445  Printf(" AGREEMENT=NONE MEANS FCN DID NOT CALCULATE THE DERIVATIVE");
3446  }
3447  if (fISW[2] == 0) {
3448  Printf(" MINUIT DOES NOT ACCEPT DERIVATIVE CALCULATIONS BY FCN");
3449  Printf(" TO FORCE ACCEPTANCE, ENTER *SET GRAD 1*");
3450  }
3451 
3452 L2000:
3453  return;
3454 } /* mngrad_ */
3455 
3456 ////////////////////////////////////////////////////////////////////////////////
3457 ///interface to Minuit help
3458 
3459 void TMinuit::mnhelp(const char *command)
3460 {
3461  TString comd = command;
3462  mnhelp(comd);
3463 }
3464 
3465 ////////////////////////////////////////////////////////////////////////////////
3466 ///*-*-*-*-*-*-*-*HELP routine for MINUIT interactive commands*-*-*-*-*-*-*-*-*
3467 ///*-* ============================================
3468 ///*-*
3469 ///*-* COMD ='*' or "" prints a global help for all commands
3470 ///*-* COMD =Command_name: print detailed help for one command.
3471 ///*-* Note that at least 3 characters must be given for the command
3472 ///*-* name.
3473 ///*-*
3474 ///*-* Author: Rene Brun
3475 ///*-* comments extracted from the MINUIT documentation file.
3476 ///*-*
3477 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
3478 
3480 {
3481 //*-*.......................................................................
3482 //*-*
3483 //*-* Global HELP: Summary of all commands
3484 //*-* ====================================
3485 //*-*
3486  comd.ToUpper();
3487  if( comd.Length() == 0 || comd[0] == '*' || comd[0] == '?' || comd[0] == 0 || comd=="HELP" ) {
3488  Printf(" ==>List of MINUIT Interactive commands:");
3489  Printf(" CLEar Reset all parameter names and values undefined");
3490  Printf(" CONtour Make contour map of the user function");
3491  Printf(" EXIT Exit from Interactive Minuit");
3492  Printf(" FIX Cause parameter(s) to remain constant");
3493  Printf(" HESse Calculate the Hessian or error matrix.");
3494  Printf(" IMPROVE Search for a new minimum around current minimum");
3495  Printf(" MIGrad Minimize by the method of Migrad");
3496  Printf(" MINImize MIGRAD + SIMPLEX method if Migrad fails");
3497  Printf(" MINOs Exact (non-linear) parameter error analysis");
3498  Printf(" MNContour Calculate one MINOS function contour");
3499  Printf(" PARameter Define or redefine new parameters and values");
3500  Printf(" RELease Make previously FIXed parameters variable again");
3501  Printf(" REStore Release last parameter fixed");
3502  Printf(" SAVe Save current parameter values on a file");
3503  Printf(" SCAn Scan the user function by varying parameters");
3504  Printf(" SEEk Minimize by the method of Monte Carlo");
3505  Printf(" SET Set various MINUIT constants or conditions");
3506  Printf(" SHOw Show values of current constants or conditions");
3507  Printf(" SIMplex Minimize by the method of Simplex");
3508  goto L99;
3509  }
3510 
3511 //*-* __________________________________________________________________
3512 //*-*
3513 //*-* -- Command CLEAR
3514 //*-* -- =============
3515 //*-*
3516  if( !strncmp(comd.Data(),"CLE",3) ) {
3517  Printf(" ***>CLEAR");
3518  Printf(" Resets all parameter names and values to undefined.");
3519  Printf(" Must normally be followed by a PARameters command or ");
3520  Printf(" equivalent, in order to define parameter values.");
3521  goto L99;
3522  }
3523 //*-* __________________________________________________________________
3524 //*-* --
3525 //*-* -- Command CONTOUR
3526 //*-* -- ===============
3527 //*-* .
3528  if( !strncmp(comd.Data(),"CON",3) ) {
3529  Printf(" ***>CONTOUR <par1> <par2> [devs] [ngrid]");
3530  Printf(" Instructs Minuit to trace contour lines of the user function");
3531  Printf(" with respect to the two parameters whose external numbers");
3532  Printf(" are <par1> and <par2>.");
3533  Printf(" Other variable parameters of the function, if any, will have");
3534  Printf(" their values fixed at the current values during the contour");
3535  Printf(" tracing. The optional parameter [devs] (default value 2.)");
3536  Printf(" gives the number of standard deviations in each parameter");
3537  Printf(" which should lie entirely within the plotting area.");
3538  Printf(" Optional parameter [ngrid] (default value 25 unless page");
3539  Printf(" size is too small) determines the resolution of the plot,");
3540  Printf(" i.e. the number of rows and columns of the grid at which the");
3541  Printf(" function will be evaluated. [See also MNContour.]");
3542  goto L99;
3543  }
3544 //*-* __________________________________________________________________
3545 //*-* --
3546 //*-* -- Command END
3547 //*-* -- ===========
3548 //*-* .
3549  if( !strncmp(comd.Data(),"END",3) ) {
3550  Printf(" ***>END");
3551  Printf(" Signals the end of a data block (i.e., the end of a fit),");
3552  Printf(" and implies that execution should continue, because another");
3553  Printf(" Data Block follows. A Data Block is a set of Minuit data");
3554  Printf(" consisting of");
3555  Printf(" (1) A Title,");
3556  Printf(" (2) One or more Parameter Definitions,");
3557  Printf(" (3) A blank line, and");
3558  Printf(" (4) A set of Minuit Commands.");
3559  Printf(" The END command is used when more than one Data Block is to");
3560  Printf(" be used with the same FCN function. It first causes Minuit");
3561  Printf(" to issue a CALL FCN with IFLAG=3, in order to allow FCN to");
3562  Printf(" perform any calculations associated with the final fitted");
3563  Printf(" parameter values, unless a CALL FCN 3 command has already");
3564  Printf(" been executed at the current FCN value.");
3565  goto L99;
3566  }
3567 //*-* __________________________________________________________________
3568 //*-* .
3569 //*-* --
3570 //*-* -- Command EXIT
3571 //*-* -- ============
3572  if( !strncmp(comd.Data(),"EXI",3) ) {
3573  Printf(" ***>EXIT");
3574  Printf(" Signals the end of execution.");
3575  Printf(" The EXIT command first causes Minuit to issue a CALL FCN");
3576  Printf(" with IFLAG=3, to allow FCN to perform any calculations");
3577  Printf(" associated with the final fitted parameter values, unless a");
3578  Printf(" CALL FCN 3 command has already been executed.");
3579  goto L99;
3580  }
3581 //*-* __________________________________________________________________
3582 //*-* --
3583 //*-* -- Command FIX
3584 //*-* -- ===========
3585 //*-* .
3586  if( !strncmp(comd.Data(),"FIX",3) ) {
3587  Printf(" ***>FIX} <parno> [parno] ... [parno]");
3588  Printf(" Causes parameter(s) <parno> to be removed from the list of");
3589  Printf(" variable parameters, and their value(s) will remain constant");
3590  Printf(" during subsequent minimizations, etc., until another command");
3591  Printf(" changes their value(s) or status.");
3592  goto L99;
3593  }
3594 //*-* __________________________________________________________________
3595 //*-* --
3596 //*-* -- Command HESSE
3597 //*-* -- =============
3598 //*-* .
3599  if( !strncmp(comd.Data(),"HES",3) ) {
3600  Printf(" ***>HESse [maxcalls]");
3601  Printf(" Calculate, by finite differences, the Hessian or error matrix.");
3602  Printf(" That is, it calculates the full matrix of second derivatives");
3603  Printf(" of the function with respect to the currently variable");
3604  Printf(" parameters, and inverts it, printing out the resulting error");
3605  Printf(" matrix. The optional argument [maxcalls] specifies the");
3606  Printf(" (approximate) maximum number of function calls after which");
3607  Printf(" the calculation will be stopped.");
3608  goto L99;
3609  }
3610 //*-* __________________________________________________________________
3611 //*-* --
3612 //*-* -- Command IMPROVE
3613 //*-* -- ===============
3614 //*-* .
3615  if( !strncmp(comd.Data(),"IMP",3) ) {
3616  Printf(" ***>IMPROVE [maxcalls]");
3617  Printf(" If a previous minimization has converged, and the current");
3618  Printf(" values of the parameters therefore correspond to a local");
3619  Printf(" minimum of the function, this command requests a search for");
3620  Printf(" additional distinct local minima.");
3621  Printf(" The optional argument [maxcalls] specifies the (approximate");
3622  Printf(" maximum number of function calls after which the calculation");
3623  Printf(" will be stopped.");
3624  goto L99;
3625  }
3626 //*-* __________________________________________________________________
3627 //*-* --
3628 //*-* -- Command MIGRAD
3629 //*-* -- ==============
3630 //*-* .
3631  if( !strncmp(comd.Data(),"MIG",3) ) {
3632  Printf(" ***>MIGrad [maxcalls] [tolerance]");
3633  Printf(" Causes minimization of the function by the method of Migrad,");
3634  Printf(" the most efficient and complete single method, recommended");
3635  Printf(" for general functions (see also MINImize).");
3636  Printf(" The minimization produces as a by-product the error matrix");
3637  Printf(" of the parameters, which is usually reliable unless warning");
3638  Printf(" messages are produced.");
3639  Printf(" The optional argument [maxcalls] specifies the (approximate)");
3640  Printf(" maximum number of function calls after which the calculation");
3641  Printf(" will be stopped even if it has not yet converged.");
3642  Printf(" The optional argument [tolerance] specifies required tolerance");
3643  Printf(" on the function value at the minimum.");
3644  Printf(" The default tolerance is 0.1, and the minimization will stop");
3645  Printf(" when the estimated vertical distance to the minimum (EDM) is");
3646  Printf(" less than 0.001*[tolerance]*UP (see [SET ERRordef]).");
3647  goto L99;
3648  }
3649 //*-* __________________________________________________________________
3650 //*-* --
3651 //*-* -- Command MINIMIZE
3652 //*-* -- ================
3653 //*-* .
3654  if( !strncmp(comd.Data(),"MINI",4) ) {
3655  Printf(" ***>MINImize [maxcalls] [tolerance]");
3656  Printf(" Causes minimization of the function by the method of Migrad,");
3657  Printf(" as does the MIGrad command, but switches to the SIMplex method");
3658  Printf(" if Migrad fails to converge. Arguments are as for MIGrad.");
3659  Printf(" Note that command requires four characters to be unambiguous.");
3660  goto L99;
3661  }
3662 //*-* __________________________________________________________________
3663 //*-* --
3664 //*-* -- Command MINOS
3665 //*-* -- =============
3666 //*-* .
3667  if( !strncmp(comd.Data(),"MIN0",4) ) {
3668  Printf(" ***>MINOs [maxcalls] [parno] [parno] ...");
3669  Printf(" Causes a Minos error analysis to be performed on the parameters");
3670  Printf(" whose numbers [parno] are specified. If none are specified,");
3671  Printf(" Minos errors are calculated for all variable parameters.");
3672  Printf(" Minos errors may be expensive to calculate, but are very");
3673  Printf(" reliable since they take account of non-linearities in the");
3674  Printf(" problem as well as parameter correlations, and are in general");
3675  Printf(" asymmetric.");
3676  Printf(" The optional argument [maxcalls] specifies the (approximate)");
3677  Printf(" maximum number of function calls per parameter requested,");
3678  Printf(" after which the calculation will stop for that parameter.");
3679  goto L99;
3680  }
3681 //*-* __________________________________________________________________
3682 //*-* --
3683 //*-* -- Command MNCONTOUR
3684 //*-* -- =================
3685 //*-* .
3686  if( !strncmp(comd.Data(),"MNC",3) ) {
3687  Printf(" ***>MNContour <par1> <par2> [npts]");
3688  Printf(" Calculates one function contour of FCN with respect to");
3689  Printf(" parameters par1 and par2, with FCN minimized always with");
3690  Printf(" respect to all other NPAR-2 variable parameters (if any).");
3691  Printf(" Minuit will try to find npts points on the contour (default 20)");
3692  Printf(" If only two parameters are variable at the time, it is not");
3693  Printf(" necessary to specify their numbers. To calculate more than");
3694  Printf(" one contour, it is necessary to SET ERRordef to the appropriate");
3695  Printf(" value and issue the MNContour command for each contour.");
3696  goto L99;
3697  }
3698 //*-* __________________________________________________________________
3699 //*-* --
3700 //*-* -- Command PARAMETER
3701 //*-* -- =================
3702 //*-* .
3703  if( !strncmp(comd.Data(),"PAR",3) ) {
3704  Printf(" ***>PARameters");
3705  Printf(" followed by one or more parameter definitions.");
3706  Printf(" Parameter definitions are of the form:");
3707  Printf(" <number> ''name'' <value> <step> [lolim] [uplim] ");
3708  Printf(" for example:");
3709  Printf(" 3 ''K width'' 1.2 0.1");
3710  Printf(" the last definition is followed by a blank line or a zero.");
3711  goto L99;
3712  }
3713 //*-* __________________________________________________________________
3714 //*-* --
3715 //*-* -- Command RELEASE
3716 //*-* -- ===============
3717 //*-* .
3718  if( !strncmp(comd.Data(),"REL",3) ) {
3719  Printf(" ***>RELease <parno> [parno] ... [parno]");
3720  Printf(" If <parno> is the number of a previously variable parameter");
3721  Printf(" which has been fixed by a command: FIX <parno>, then that");
3722  Printf(" parameter will return to variable status. Otherwise a warning");
3723  Printf(" message is printed and the command is ignored.");
3724  Printf(" Note that this command operates only on parameters which were");
3725  Printf(" at one time variable and have been FIXed. It cannot make");
3726  Printf(" constant parameters variable; that must be done by redefining");
3727  Printf(" the parameter with a PARameters command.");
3728  goto L99;
3729  }
3730 //*-* __________________________________________________________________
3731 //*-* --
3732 //*-* -- Command RESTORE
3733 //*-* -- ===============
3734 //*-* .
3735  if( !strncmp(comd.Data(),"RES",3) ) {
3736  Printf(" ***>REStore [code]");
3737  Printf(" If no [code] is specified, this command restores all previously");
3738  Printf(" FIXed parameters to variable status. If [code]=1, then only");
3739  Printf(" the last parameter FIXed is restored to variable status.");
3740  Printf(" If code is neither zero nor one, the command is ignored.");
3741  goto L99;
3742  }
3743 //*-* __________________________________________________________________
3744 //*-* --
3745 //*-* -- Command RETURN
3746 //*-* -- ==============
3747 //*-* .
3748  if( !strncmp(comd.Data(),"RET",3) ) {
3749  Printf(" ***>RETURN");
3750  Printf(" Signals the end of a data block, and instructs Minuit to return");
3751  Printf(" to the program which called it. The RETurn command first");
3752  Printf(" causes Minuit to CALL FCN with IFLAG=3, in order to allow FCN");
3753  Printf(" to perform any calculations associated with the final fitted");
3754  Printf(" parameter values, unless a CALL FCN 3 command has already been");
3755  Printf(" executed at the current FCN value.");
3756  goto L99;
3757  }
3758 //*-* __________________________________________________________________
3759 //*-* --
3760 //*-* -- Command SAVE
3761 //*-* -- ============
3762 //*-* .
3763  if( !strncmp(comd.Data(),"SAV",3) ) {
3764  Printf(" ***>SAVe");
3765  Printf(" Causes the current parameter values to be saved on a file in");
3766  Printf(" such a format that they can be read in again as Minuit");
3767  Printf(" parameter definitions. If the covariance matrix exists, it is");
3768  Printf(" also output in such a format. The unit number is by default 7,");
3769  Printf(" or that specified by the user in their call to MINTIO or");
3770  Printf(" MNINIT. The user is responsible for opening the file previous");
3771  Printf(" to issuing the [SAVe] command (except where this can be done");
3772  Printf(" interactively).");
3773  goto L99;
3774  }
3775 //*-* __________________________________________________________________
3776 //*-* --
3777 //*-* -- Command SCAN
3778 //*-* -- ============
3779 //*-* .
3780  if( !strncmp(comd.Data(),"SCA",3) ) {
3781  Printf(" ***>SCAn [parno] [numpts] [from] [to]");
3782  Printf(" Scans the value of the user function by varying parameter");
3783  Printf(" number [parno], leaving all other parameters fixed at the");
3784  Printf(" current value. If [parno] is not specified, all variable");
3785  Printf(" parameters are scanned in sequence.");
3786  Printf(" The number of points [numpts] in the scan is 40 by default,");
3787  Printf(" and cannot exceed 100. The range of the scan is by default");
3788  Printf(" 2 standard deviations on each side of the current best value,");
3789  Printf(" but can be specified as from [from] to [to].");
3790  Printf(" After each scan, if a new minimum is found, the best parameter");
3791  Printf(" values are retained as start values for future scans or");
3792  Printf(" minimizations. The curve resulting from each scan is plotted");
3793  Printf(" on the output unit in order to show the approximate behaviour");
3794  Printf(" of the function.");
3795  Printf(" This command is not intended for minimization, but is sometimes");
3796  Printf(" useful for debugging the user function or finding a");
3797  Printf(" reasonable starting point.");
3798  goto L99;
3799  }
3800 //*-* __________________________________________________________________
3801 //*-* --
3802 //*-* -- Command SEEK
3803 //*-* -- ============
3804 //*-* .
3805  if( !strncmp(comd.Data(),"SEE",3) ) {
3806  Printf(" ***>SEEk [maxcalls] [devs]");
3807  Printf(" Causes a Monte Carlo minimization of the function, by choosing");
3808  Printf(" random values of the variable parameters, chosen uniformly");
3809  Printf(" over a hypercube centered at the current best value.");
3810  Printf(" The region size is by default 3 standard deviations on each");
3811  Printf(" side, but can be changed by specifying the value of [devs].");
3812  goto L99;
3813  }
3814 //*-* __________________________________________________________________
3815 //*-* --
3816 //*-* -- Command SET
3817 //*-* -- ===========
3818 //*-* .
3819  if( !strncmp(comd.Data(),"SET",3) ) {
3820  Printf(" ***>SET <option_name>");
3821  Printf(" SET BATch");
3822  Printf(" Informs Minuit that it is running in batch mode.");
3823 
3824  Printf(" ");
3825  Printf(" SET EPSmachine <accuracy>");
3826  Printf(" Informs Minuit that the relative floating point arithmetic");
3827  Printf(" precision is <accuracy>. Minuit determines the nominal");
3828  Printf(" precision itself, but the SET EPSmachine command can be");
3829  Printf(" used to override Minuit own determination, when the user");
3830  Printf(" knows that the FCN function value is not calculated to");
3831  Printf(" the nominal machine accuracy. Typical values of <accuracy>");
3832  Printf(" are between 10**-5 and 10**-14.");
3833 
3834  Printf(" ");
3835  Printf(" SET ERRordef <up>");
3836  Printf(" Sets the value of UP (default value= 1.), defining parameter");
3837  Printf(" errors. Minuit defines parameter errors as the change");
3838  Printf(" in parameter value required to change the function value");
3839  Printf(" by UP. Normally, for chisquared fits UP=1, and for negative");
3840  Printf(" log likelihood, UP=0.5.");
3841 
3842  Printf(" ");
3843  Printf(" SET GRAdient [force]");
3844  Printf(" Informs Minuit that the user function is prepared to");
3845  Printf(" calculate its own first derivatives and return their values");
3846  Printf(" in the array GRAD when IFLAG=2 (see specs of FCN).");
3847  Printf(" If [force] is not specified, Minuit will calculate");
3848  Printf(" the FCN derivatives by finite differences at the current");
3849  Printf(" point and compare with the user calculation at that point,");
3850  Printf(" accepting the user values only if they agree.");
3851  Printf(" If [force]=1, Minuit does not do its own derivative");
3852  Printf(" calculation, and uses the derivatives calculated in FCN.");
3853 
3854  Printf(" ");
3855  Printf(" SET INPut [unitno] [filename]");
3856  Printf(" Causes Minuit, in data-driven mode only, to read subsequent");
3857  Printf(" commands (or parameter definitions) from a different input");
3858  Printf(" file. If no [unitno] is specified, reading reverts to the");
3859  Printf(" previous input file, assuming that there was one.");
3860  Printf(" If [unitno] is specified, and that unit has not been opened,");
3861  Printf(" then Minuit attempts to open the file [filename]} if a");
3862  Printf(" name is specified. If running in interactive mode and");
3863  Printf(" [filename] is not specified and [unitno] is not opened,");
3864  Printf(" Minuit prompts the user to enter a file name.");
3865  Printf(" If the word REWIND is added to the command (note:no blanks");
3866  Printf(" between INPUT and REWIND), the file is rewound before");
3867  Printf(" reading. Note that this command is implemented in standard");
3868  Printf(" Fortran 77 and the results may depend on the system;");
3869  Printf(" for example, if a filename is given under VM/CMS, it must");
3870  Printf(" be preceded by a slash.");
3871 
3872  Printf(" ");
3873  Printf(" SET INTeractive");
3874  Printf(" Informs Minuit that it is running interactively.");
3875 
3876  Printf(" ");
3877  Printf(" SET LIMits [parno] [lolim] [uplim]");
3878  Printf(" Allows the user to change the limits on one or all");
3879  Printf(" parameters. If no arguments are specified, all limits are");
3880  Printf(" removed from all parameters. If [parno] alone is specified,");
3881  Printf(" limits are removed from parameter [parno].");
3882  Printf(" If all arguments are specified, then parameter [parno] will");
3883  Printf(" be bounded between [lolim] and [uplim].");
3884  Printf(" Limits can be specified in either order, Minuit will take");
3885  Printf(" the smaller as [lolim] and the larger as [uplim].");
3886  Printf(" However, if [lolim] is equal to [uplim], an error condition");
3887  Printf(" results.");
3888 
3889  Printf(" ");
3890  Printf(" SET LINesperpage");
3891  Printf(" Sets the number of lines for one page of output.");
3892  Printf(" Default value is 24 for interactive mode");
3893 
3894  Printf(" ");
3895  Printf(" SET NOGradient");
3896  Printf(" The inverse of SET GRAdient, instructs Minuit not to");
3897  Printf(" use the first derivatives calculated by the user in FCN.");
3898 
3899  Printf(" ");
3900  Printf(" SET NOWarnings");
3901  Printf(" Supresses Minuit warning messages.");
3902 
3903  Printf(" ");
3904  Printf(" SET OUTputfile <unitno>");
3905  Printf(" Instructs Minuit to write further output to unit <unitno>.");
3906 
3907  Printf(" ");
3908  Printf(" SET PAGethrow <integer>");
3909  Printf(" Sets the carriage control character for ``new page'' to");
3910  Printf(" <integer>. Thus the value 1 produces a new page, and 0");
3911  Printf(" produces a blank line, on some devices (see TOPofpage)");
3912 
3913 
3914  Printf(" ");
3915  Printf(" SET PARameter <parno> <value>");
3916  Printf(" Sets the value of parameter <parno> to <value>.");
3917  Printf(" The parameter in question may be variable, fixed, or");
3918  Printf(" constant, but must be defined.");
3919 
3920  Printf(" ");
3921  Printf(" SET PRIntout <level>");
3922  Printf(" Sets the print level, determining how much output will be");
3923  Printf(" produced. Allowed values and their meanings are displayed");
3924  Printf(" after a SHOw PRInt command, and are currently <level>=:");
3925  Printf(" [-1] no output except from SHOW commands");
3926  Printf(" [0] minimum output");
3927  Printf(" [1] default value, normal output");
3928  Printf(" [2] additional output giving intermediate results.");
3929  Printf(" [3] maximum output, showing progress of minimizations.");
3930  Printf(" Note: See also the SET WARnings command.");
3931 
3932  Printf(" ");
3933  Printf(" SET RANdomgenerator <seed>");
3934  Printf(" Sets the seed of the random number generator used in SEEk.");
3935  Printf(" This can be any integer between 10000 and 900000000, for");
3936  Printf(" example one which was output from a SHOw RANdom command of");
3937  Printf(" a previous run.");
3938 
3939  Printf(" ");
3940  Printf(" SET STRategy <level>");
3941  Printf(" Sets the strategy to be used in calculating first and second");
3942  Printf(" derivatives and in certain minimization methods.");
3943  Printf(" In general, low values of <level> mean fewer function calls");
3944  Printf(" and high values mean more reliable minimization.");
3945  Printf(" Currently allowed values are 0, 1 (default), and 2.");
3946 
3947  Printf(" ");
3948  Printf(" SET TITle");
3949  Printf(" Informs Minuit that the next input line is to be considered");
3950  Printf(" the (new) title for this task or sub-task. This is for");
3951  Printf(" the convenience of the user in reading their output.");
3952 
3953  Printf(" ");
3954  Printf(" SET WARnings");
3955  Printf(" Instructs Minuit to output warning messages when suspicious");
3956  Printf(" conditions arise which may indicate unreliable results.");
3957  Printf(" This is the default.");
3958 
3959  Printf(" ");
3960  Printf(" SET WIDthpage");
3961  Printf(" Informs Minuit of the output page width.");
3962  Printf(" Default values are 80 for interactive jobs");
3963  goto L99;
3964  }
3965 //*-* __________________________________________________________________
3966 //*-* --
3967 //*-* -- Command SHOW
3968 //*-* -- ============
3969 //*-* .
3970  if( !strncmp(comd.Data(),"SHO",3) ) {
3971  Printf(" ***>SHOw <option_name>");
3972  Printf(" All SET XXXX commands have a corresponding SHOw XXXX command.");
3973  Printf(" In addition, the SHOw commands listed starting here have no");
3974  Printf(" corresponding SET command for obvious reasons.");
3975 
3976  Printf(" ");
3977  Printf(" SHOw CORrelations");
3978  Printf(" Calculates and prints the parameter correlations from the");
3979  Printf(" error matrix.");
3980 
3981  Printf(" ");
3982  Printf(" SHOw COVariance");
3983  Printf(" Prints the (external) covariance (error) matrix.");
3984 
3985  Printf(" ");
3986  Printf(" SHOw EIGenvalues");
3987  Printf(" Calculates and prints the eigenvalues of the covariance");
3988  Printf(" matrix.");
3989 
3990  Printf(" ");
3991  Printf(" SHOw FCNvalue");
3992  Printf(" Prints the current value of FCN.");
3993  goto L99;
3994  }
3995 //*-* __________________________________________________________________
3996 //*-* --
3997 //*-* -- Command SIMPLEX
3998 //*-* -- ===============
3999 //*-* .
4000  if( !strncmp(comd.Data(),"SIM",3) ) {
4001  Printf(" ***>SIMplex [maxcalls] [tolerance]");
4002  Printf(" Performs a function minimization using the simplex method of");
4003  Printf(" Nelder and Mead. Minimization terminates either when the");
4004  Printf(" function has been called (approximately) [maxcalls] times,");
4005  Printf(" or when the estimated vertical distance to minimum (EDM) is");
4006  Printf(" less than [tolerance].");
4007  Printf(" The default value of [tolerance] is 0.1*UP(see SET ERRordef).");
4008  goto L99;
4009  }
4010 //*-* __________________________________________________________________
4011 //*-* --
4012 //*-* -- Command STANDARD
4013 //*-* -- ================
4014 //*-* .
4015  if( !strncmp(comd.Data(),"STA",3) ) {
4016  Printf(" ***>STAndard");
4017  goto L99;
4018  }
4019 //*-* __________________________________________________________________
4020 //*-* --
4021 //*-* -- Command STOP
4022 //*-* -- ============
4023 //*-* .
4024  if( !strncmp(comd.Data(),"STO",3) ) {
4025  Printf(" ***>STOP");
4026  Printf(" Same as EXIT.");
4027  goto L99;
4028  }
4029 //*-* __________________________________________________________________
4030 //*-* --
4031 //*-* -- Command TOPOFPAGE
4032 //*-* -- =================
4033 //*-* .
4034  if( !strncmp(comd.Data(),"TOP",3) ) {
4035  Printf(" ***>TOPofpage");
4036  Printf(" Causes Minuit to write the character specified in a");
4037  Printf(" SET PAGethrow command (default = 1) to column 1 of the output");
4038  Printf(" file, which may or may not position your output medium to");
4039  Printf(" the top of a page depending on the device and system.");
4040  goto L99;
4041  }
4042 //*-* __________________________________________________________________
4043  Printf(" Unknown MINUIT command. Type HELP for list of commands.");
4044 
4045 L99:
4046  return;
4047 } /* mnhelp_ */
4048 
4049 ////////////////////////////////////////////////////////////////////////////////
4050 ///*-*-*-*-*-*Calculates the full second-derivative matrix of FCN*-*-*-*-*-*-*-*
4051 ///*-* ===================================================
4052 ///*-* by taking finite differences. When calculating diagonal
4053 ///*-* elements, it may iterate so that step size is nearly that
4054 ///*-* which gives function change= UP/10. The first derivatives
4055 ///*-* of course come as a free side effect, but with a smaller
4056 ///*-* step size in order to obtain a known accuracy.
4057 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4058 
4060 {
4061  /* Local variables */
4062  Double_t dmin_, dxdi, elem, wint, tlrg2, d, dlast, ztemp, g2bfor;
4063  Double_t df, aimsag, fs1, tlrstp, fs2, stpinm, g2i, sag=0, xtf, xti, xtj;
4064  Int_t icyc, ncyc, ndex, idrv, iext, npar2, i, j, ifail, npard, nparx, id, multpy;
4065  Bool_t ldebug;
4066 
4067  ldebug = fIdbg[3] >= 1;
4068  if (fAmin == fUndefi) {
4069  mnamin();
4070  }
4071  if (fIstrat <= 0) {
4072  ncyc = 3;
4073  tlrstp = .5;
4074  tlrg2 = .1;
4075  } else if (fIstrat == 1) {
4076  ncyc = 5;
4077  tlrstp = .3;
4078  tlrg2 = .05;
4079  } else {
4080  ncyc = 7;
4081  tlrstp = .1;
4082  tlrg2 = .02;
4083  }
4084  if (fISW[4] >= 2 || ldebug) {
4085  Printf(" START COVARIANCE MATRIX CALCULATION.");
4086  }
4087  fCfrom = "HESSE ";
4088  fNfcnfr = fNfcn;
4089  fCstatu = "OK ";
4090  npard = fNpar;
4091 //*-*- make sure starting at the right place
4092  mninex(fX);
4093  nparx = fNpar;
4094  Eval(nparx, fGin, fs1, fU, 4); ++fNfcn;
4095  if (fs1 != fAmin) {
4096  df = fAmin - fs1;
4097  mnwarn("D", "MNHESS", TString::Format("function value differs from AMIN by %g",df));
4098  }
4099  fAmin = fs1;
4100  if (ldebug) {
4101  Printf(" PAR D GSTEP D G2 GRD SAG ");
4102  }
4103 //*-*- . . . . . . diagonal elements .
4104 
4105 //*-*- fISW[1] = 1 if approx, 2 if not posdef, 3 if ok
4106 //*-*- AIMSAG is the sagitta we are aiming for in second deriv calc.
4107 
4108  aimsag = TMath::Sqrt(fEpsma2)*(TMath::Abs(fAmin) + fUp);
4109 //*-*- Zero the second derivative matrix
4110  npar2 = fNpar*(fNpar + 1) / 2;
4111  for (i = 1; i <= npar2; ++i) { fVhmat[i-1] = 0; }
4112 
4113 //*-*- Loop over variable parameters for second derivatives
4114  idrv = 2;
4115  for (id = 1; id <= npard; ++id) {
4116  i = id + fNpar - npard;
4117  iext = fNexofi[i-1];
4118  if (fG2[i-1] == 0) {
4119  mnwarn("W", "HESSE", Form("Second derivative enters zero, param %d",iext));
4120  wint = fWerr[i-1];
4121  if (fNvarl[iext-1] > 1) {
4122  mndxdi(fX[i-1], i-1, dxdi);
4123  if (TMath::Abs(dxdi) < .001) wint = .01;
4124  else wint /= TMath::Abs(dxdi);
4125  }
4126  fG2[i-1] = fUp / (wint*wint);
4127  }
4128  xtf = fX[i-1];
4129  dmin_ = fEpsma2*8*TMath::Abs(xtf);
4130 
4131 //*-*- find step which gives sagitta = AIMSAG
4132  d = TMath::Abs(fGstep[i-1]);
4133  int skip50 = 0;
4134  for (icyc = 1; icyc <= ncyc; ++icyc) {
4135 //*-*- loop here only if SAG=0
4136  for (multpy = 1; multpy <= 5; ++multpy) {
4137 //*-*- take two steps
4138  fX[i-1] = xtf + d;
4139  mninex(fX);
4140  nparx = fNpar;
4141  Eval(nparx, fGin, fs1, fU, 4); ++fNfcn;
4142  fX[i-1] = xtf - d;
4143  mninex(fX);
4144  Eval(nparx, fGin, fs2, fU, 4); ++fNfcn;
4145  fX[i-1] = xtf;
4146  sag = (fs1 + fs2 - fAmin*2)*.5;
4147  if (sag != 0) goto L30;
4148  if (fGstep[i-1] < 0) {
4149  if (d >= .5) goto L26;
4150  d *= 10;
4151  if (d > .5) d = .51;
4152  continue;
4153  }
4154  d *= 10;
4155  }
4156 L26:
4157  mnwarn("W", "HESSE", TString::Format("Second derivative zero for parameter%d",iext));
4158  goto L390;
4159 //*-*- SAG is not zero
4160 L30:
4161  g2bfor = fG2[i-1];
4162  fG2[i-1] = sag*2 / (d*d);
4163  fGrd[i-1] = (fs1 - fs2) / (d*2);
4164  if (ldebug) {
4165  Printf("%4d%2d%12.5g%12.5g%12.5g%12.5g%12.5g",i,idrv,fGstep[i-1],d,fG2[i-1],fGrd[i-1],sag);
4166  }
4167  if (fGstep[i-1] > 0) fGstep[i-1] = TMath::Abs(d);
4168  else fGstep[i-1] = -TMath::Abs(d);
4169  fDirin[i-1] = d;
4170  fHESSyy[i-1]= fs1;
4171  dlast = d;
4172  d = TMath::Sqrt(aimsag*2 / TMath::Abs(fG2[i-1]));
4173 //*-*- if parameter has limits, max int step size = 0.5
4174  stpinm = .5;
4175  if (fGstep[i-1] < 0) d = TMath::Min(d,stpinm);
4176  if (d < dmin_) d = dmin_;
4177 //*-*- see if converged
4178  if (TMath::Abs((d - dlast) / d) < tlrstp ||
4179  TMath::Abs((fG2[i-1] - g2bfor) / fG2[i-1]) < tlrg2) {
4180  skip50 = 1;
4181  break;
4182  }
4183  d = TMath::Min(d,dlast*102);
4184  d = TMath::Max(d,dlast*.1);
4185  }
4186 //*-*- end of step size loop
4187  if (!skip50)
4188  mnwarn("D", "MNHESS", TString::Format("Second Deriv. SAG,AIM= %d%g%g",iext,sag,aimsag));
4189 
4190  ndex = i*(i + 1) / 2;
4191  fVhmat[ndex-1] = fG2[i-1];
4192  }
4193 //*-*- end of diagonal second derivative loop
4194  mninex(fX);
4195 //*-*- refine the first derivatives
4196  if (fIstrat > 0) mnhes1();
4197  fISW[1] = 3;
4198  fDcovar = 0;
4199 //*-*- . . . . off-diagonal elements
4200 
4201  if (fNpar == 1) goto L214;
4202  for (i = 1; i <= fNpar; ++i) {
4203  for (j = 1; j <= i-1; ++j) {
4204  xti = fX[i-1];
4205  xtj = fX[j-1];
4206  fX[i-1] = xti + fDirin[i-1];
4207  fX[j-1] = xtj + fDirin[j-1];
4208  mninex(fX);
4209  Eval(nparx, fGin, fs1, fU, 4); ++fNfcn;
4210  fX[i-1] = xti;
4211  fX[j-1] = xtj;
4212  elem = (fs1 + fAmin - fHESSyy[i-1] - fHESSyy[j-1]) / (
4213  fDirin[i-1]*fDirin[j-1]);
4214  ndex = i*(i-1) / 2 + j;
4215  fVhmat[ndex-1] = elem;
4216  }
4217  }
4218 L214:
4219  mninex(fX);
4220 //*-*- verify matrix positive-definite
4221  mnpsdf();
4222  for (i = 1; i <= fNpar; ++i) {
4223  for (j = 1; j <= i; ++j) {
4224  ndex = i*(i-1) / 2 + j;
4225  fP[i + j*fMaxpar - fMaxpar-1] = fVhmat[ndex-1];
4226  fP[j + i*fMaxpar - fMaxpar-1] = fP[i + j*fMaxpar - fMaxpar-1];
4227  }
4228  }
4229  mnvert(fP, fMaxint, fMaxint, fNpar, ifail);
4230  if (ifail > 0) {
4231  mnwarn("W", "HESSE", "Matrix inversion fails.");
4232  goto L390;
4233  }
4234 //*-*- . . . . . . . calculate e d m
4235  fEDM = 0;
4236 
4237  for (i = 1; i <= fNpar; ++i) {
4238 //*-*- off-diagonal elements
4239  ndex = i*(i-1) / 2;
4240  for (j = 1; j <= i-1; ++j) {
4241  ++ndex;
4242  ztemp = fP[i + j*fMaxpar - fMaxpar-1]*2;
4243  fEDM += fGrd[i-1]*ztemp*fGrd[j-1];
4244  fVhmat[ndex-1] = ztemp;
4245  }
4246 //*-*- diagonal elements
4247  ++ndex;
4248  fVhmat[ndex-1] = fP[i + i*fMaxpar - fMaxpar-1]*2;
4249  fEDM += fP[i + i*fMaxpar - fMaxpar-1]*(fGrd[i-1]*fGrd[i-1]);
4250  }
4251  if (fISW[4] >= 1 && fISW[1] == 3 && fItaur == 0) {
4252  Printf(" COVARIANCE MATRIX CALCULATED SUCCESSFULLY");
4253  }
4254  goto L900;
4255 //*-*- failure to invert 2nd deriv matrix
4256 L390:
4257  fISW[1] = 1;
4258  fDcovar = 1;
4259  fCstatu = "FAILED ";
4260  if (fISW[4] >= 0) {
4261  Printf(" MNHESS FAILS AND WILL RETURN DIAGONAL MATRIX. ");
4262  }
4263  for (i = 1; i <= fNpar; ++i) {
4264  ndex = i*(i-1) / 2;
4265  for (j = 1; j <= i-1; ++j) {
4266  ++ndex;
4267  fVhmat[ndex-1] = 0;
4268  }
4269  ++ndex;
4270  g2i = fG2[i-1];
4271  if (g2i <= 0) g2i = 1;
4272  fVhmat[ndex-1] = 2 / g2i;
4273  }
4274 L900:
4275  return;
4276 } /* mnhess_ */
4277 
4278 ////////////////////////////////////////////////////////////////////////////////
4279 ///*-*-*-*Calculate first derivatives (GRD) and uncertainties (DGRD)*-*-*-*-*-*
4280 ///*-* ==========================================================
4281 ///*-* and appropriate step sizes GSTEP
4282 ///*-* Called from MNHESS and MNGRAD
4283 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4284 
4286 {
4287  /* Local variables */
4288  Double_t dmin_, d, dfmin, dgmin=0, change, chgold, grdold=0, epspri;
4289  Double_t fs1, optstp, fs2, grdnew=0, sag, xtf;
4290  Int_t icyc, ncyc=0, idrv, i, nparx;
4291  Bool_t ldebug;
4292 
4293  ldebug = fIdbg[5] >= 1;
4294  if (fIstrat <= 0) ncyc = 1;
4295  if (fIstrat == 1) ncyc = 2;
4296  if (fIstrat > 1) ncyc = 6;
4297  idrv = 1;
4298  nparx = fNpar;
4299  dfmin = fEpsma2*4*(TMath::Abs(fAmin) + fUp);
4300 //*-*- main loop over parameters
4301  for (i = 1; i <= fNpar; ++i) {
4302  xtf = fX[i-1];
4303  dmin_ = fEpsma2*4*TMath::Abs(xtf);
4304  epspri = fEpsma2 + TMath::Abs(fGrd[i-1]*fEpsma2);
4305  optstp = TMath::Sqrt(dfmin / (TMath::Abs(fG2[i-1]) + epspri));
4306  d = TMath::Abs(fGstep[i-1])*.2;
4307  if (d > optstp) d = optstp;
4308  if (d < dmin_) d = dmin_;
4309  chgold = 1e4;
4310 //*-*- iterate reducing step size
4311  for (icyc = 1; icyc <= ncyc; ++icyc) {
4312  fX[i-1] = xtf + d;
4313  mninex(fX);
4314  Eval(nparx, fGin, fs1, fU, 4); ++fNfcn;
4315  fX[i-1] = xtf - d;
4316  mninex(fX);
4317  Eval(nparx, fGin, fs2, fU, 4); ++fNfcn;
4318  fX[i-1] = xtf;
4319 //*-*- check if step sizes appropriate
4320  sag = (fs1 + fs2 - fAmin*2)*.5;
4321  grdold = fGrd[i-1];
4322  grdnew = (fs1 - fs2) / (d*2);
4323  dgmin = fEpsmac*(TMath::Abs(fs1) + TMath::Abs(fs2)) / d;
4324  if (ldebug) {
4325  Printf("%4d%2d%12.5g%12.5g%12.5g%12.5g%12.5g",i,idrv,fGstep[i-1],d,fG2[i-1],grdnew,sag);
4326  }
4327  if (grdnew == 0) goto L60;
4328  change = TMath::Abs((grdold - grdnew) / grdnew);
4329  if (change > chgold && icyc > 1) goto L60;
4330  chgold = change;
4331  fGrd[i-1] = grdnew;
4332  if (fGstep[i-1] > 0) fGstep[i-1] = TMath::Abs(d);
4333  else fGstep[i-1] = -TMath::Abs(d);
4334 //*-*- decrease step until first derivative changes by <5%
4335  if (change < .05) goto L60;
4336  if (TMath::Abs(grdold - grdnew) < dgmin) goto L60;
4337  if (d < dmin_) {
4338  mnwarn("D", "MNHES1", "Step size too small for 1st drv.");
4339  goto L60;
4340  }
4341  d *= .2;
4342  }
4343 //*-*- loop satisfied = too many iter
4344  mnwarn("D", "MNHES1", TString::Format("Too many iterations on D1.%g%g",grdold,grdnew));
4345 L60:
4346  fDgrd[i-1] = TMath::Max(dgmin,TMath::Abs(grdold - grdnew));
4347  }
4348 //*-*- end of first deriv. loop
4349  mninex(fX);
4350 } /* mnhes1_ */
4351 
4352 ////////////////////////////////////////////////////////////////////////////////
4353 ///*-*-*-*-*-*-*Attempts to improve on a good local minimum*-*-*-*-*-*-*-*-*-*
4354 ///*-* ===========================================
4355 ///*-* Attempts to improve on a good local minimum by finding a
4356 ///*-* better one. The quadratic part of FCN is removed by MNCALF
4357 ///*-* and this transformed function is minimized using the simplex
4358 ///*-* method from several random starting points.
4359 ///*-* ref. -- Goldstein and Price, Math.Comp. 25, 569 (1971)
4360 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4361 
4363 {
4364  /* Initialized data */
4365 
4366  static Double_t rnum = 0;
4367 
4368  /* Local variables */
4369  Double_t amax, ycalf, ystar, ystst;
4370  Double_t pb, ep, wg, xi, sigsav, reg, sig2;
4371  Int_t npfn, ndex, loop=0, i, j, ifail, iseed=0;
4372  Int_t jhold, nloop, nparx, nparp1, jh, jl, iswtr;
4373 
4374  if (fNpar <= 0) return;
4375  if (fAmin == fUndefi) mnamin();
4376  fCstatu = "UNCHANGED ";
4377  fItaur = 1;
4378  fEpsi = fUp*.1;
4379  npfn = fNfcn;
4380  nloop = Int_t(fWord7[1]);
4381  if (nloop <= 0) nloop = fNpar + 4;
4382  nparx = fNpar;
4383  nparp1 = fNpar + 1;
4384  wg = 1 / Double_t(fNpar);
4385  sigsav = fEDM;
4386  fApsi = fAmin;
4387  iswtr = fISW[4] - 2*fItaur;
4388  for (i = 1; i <= fNpar; ++i) {
4389  fXt[i-1] = fX[i-1];
4390  fIMPRdsav[i-1] = fWerr[i-1];
4391  for (j = 1; j <= i; ++j) {
4392  ndex = i*(i-1) / 2 + j;
4393  fP[i + j*fMaxpar - fMaxpar-1] = fVhmat[ndex-1];
4394  fP[j + i*fMaxpar - fMaxpar-1] = fP[i + j*fMaxpar - fMaxpar-1];
4395  }
4396  }
4397  mnvert(fP, fMaxint, fMaxint, fNpar, ifail);
4398  if (ifail >= 1) goto L280;
4399 //*-*- Save inverted matrix in VT
4400  for (i = 1; i <= fNpar; ++i) {
4401  ndex = i*(i-1) / 2;
4402  for (j = 1; j <= i; ++j) {
4403  ++ndex;
4404  fVthmat[ndex-1] = fP[i + j*fMaxpar - fMaxpar-1];
4405  }
4406  }
4407  loop = 0;
4408 
4409 L20:
4410  for (i = 1; i <= fNpar; ++i) {
4411  fDirin[i-1] = fIMPRdsav[i-1]*2;
4412  mnrn15(rnum, iseed);
4413  fX[i-1] = fXt[i-1] + fDirin[i-1]*2*(rnum - .5);
4414  }
4415  ++loop;
4416  reg = 2;
4417  if (fISW[4] >= 0) {
4418  Printf("START ATTEMPT NO.%2d TO FIND NEW MINIMUM",loop);
4419  }
4420 L30:
4421  mncalf(fX, ycalf);
4422  fAmin = ycalf;
4423 //*-*- . . . . set up random simplex
4424  jl = nparp1;
4425  jh = nparp1;
4426  fIMPRy[nparp1-1] = fAmin;
4427  amax = fAmin;
4428  for (i = 1; i <= fNpar; ++i) {
4429  xi = fX[i-1];
4430  mnrn15(rnum, iseed);
4431  fX[i-1] = xi - fDirin[i-1]*(rnum - .5);
4432  mncalf(fX, ycalf);
4433  fIMPRy[i-1] = ycalf;
4434  if (fIMPRy[i-1] < fAmin) {
4435  fAmin = fIMPRy[i-1];
4436  jl = i;
4437  } else if (fIMPRy[i-1] > amax) {
4438  amax = fIMPRy[i-1];
4439  jh = i;
4440  }
4441  for (j = 1; j <= fNpar; ++j) { fP[j + i*fMaxpar - fMaxpar-1] = fX[j-1]; }
4442  fP[i + nparp1*fMaxpar - fMaxpar-1] = xi;
4443  fX[i-1] = xi;
4444  }
4445 
4446  fEDM = fAmin;
4447  sig2 = fEDM;
4448 //*-*- . . . . . . . start main loop
4449 L50:
4450  if (fAmin < 0) goto L95;
4451  if (fISW[1] <= 2) goto L280;
4452  ep = fAmin*.1;
4453  if (sig2 < ep && fEDM < ep) goto L100;
4454  sig2 = fEDM;
4455  if (fNfcn - npfn > fNfcnmx) goto L300;
4456 //*-*- calculate new point * by reflection
4457  for (i = 1; i <= fNpar; ++i) {
4458  pb = 0;
4459  for (j = 1; j <= nparp1; ++j) { pb += wg*fP[i + j*fMaxpar - fMaxpar-1]; }
4460  fPbar[i-1] = pb - wg*fP[i + jh*fMaxpar - fMaxpar-1];
4461  fPstar[i-1] = fPbar[i-1]*2 - fP[i + jh*fMaxpar - fMaxpar-1]*1;
4462  }
4463  mncalf(fPstar, ycalf);
4464  ystar = ycalf;
4465  if (ystar >= fAmin) goto L70;
4466 //*-*- point * better than jl, calculate new point **
4467  for (i = 1; i <= fNpar; ++i) {
4468  fPstst[i-1] = fPstar[i-1]*2 + fPbar[i- 1]*-1;
4469  }
4470  mncalf(fPstst, ycalf);
4471  ystst = ycalf;
4472  if (ystst < fIMPRy[jl-1]) goto L67;
4473  mnrazz(ystar, fPstar, fIMPRy, jh, jl);
4474  goto L50;
4475 L67:
4476  mnrazz(ystst, fPstst, fIMPRy, jh, jl);
4477  goto L50;
4478 //*-*- point * is not as good as jl
4479 L70:
4480  if (ystar >= fIMPRy[jh-1]) goto L73;
4481  jhold = jh;
4482  mnrazz(ystar, fPstar, fIMPRy, jh, jl);
4483  if (jhold != jh) goto L50;
4484 //*-*- calculate new point **
4485 L73:
4486  for (i = 1; i <= fNpar; ++i) {
4487  fPstst[i-1] = fP[i + jh*fMaxpar - fMaxpar-1]*.5 + fPbar[i-1]*.5;
4488  }
4489  mncalf(fPstst, ycalf);
4490  ystst = ycalf;
4491  if (ystst > fIMPRy[jh-1]) goto L30;
4492 //*-*- point ** is better than jh
4493  if (ystst < fAmin) goto L67;
4494  mnrazz(ystst, fPstst, fIMPRy, jh, jl);
4495  goto L50;
4496 //*-*- . . . . . . end main loop
4497 L95:
4498  if (fISW[4] >= 0) {
4499  Printf(" AN IMPROVEMENT ON THE PREVIOUS MINIMUM HAS BEEN FOUND");
4500  }
4501  reg = .1;
4502 //*-*- . . . . . ask if point is new
4503 L100:
4504  mninex(fX);
4505  Eval(nparx, fGin, fAmin, fU, 4); ++fNfcn;
4506  for (i = 1; i <= fNpar; ++i) {
4507  fDirin[i-1] = reg*fIMPRdsav[i-1];
4508  if (TMath::Abs(fX[i-1] - fXt[i-1]) > fDirin[i-1]) goto L150;
4509  }
4510  goto L230;
4511 L150:
4512  fNfcnmx = fNfcnmx + npfn - fNfcn;
4513  npfn = fNfcn;
4514  mnsimp();
4515  if (fAmin >= fApsi) goto L325;
4516  for (i = 1; i <= fNpar; ++i) {
4517  fDirin[i-1] = fIMPRdsav[i-1]*.1;
4518  if (TMath::Abs(fX[i-1] - fXt[i-1]) > fDirin[i-1]) goto L250;
4519  }
4520 L230:
4521  if (fAmin < fApsi) goto L350;
4522  goto L325;
4523 /* . . . . . . truly new minimum */
4524 L250:
4525  fLnewmn = kTRUE;
4526  if (fISW[1] >= 1) {
4527  fISW[1] = 1;
4528  fDcovar = TMath::Max(fDcovar,.5);
4529  } else fDcovar = 1;
4530  fItaur = 0;
4531  fNfcnmx = fNfcnmx + npfn - fNfcn;
4532  fCstatu = "NEW MINIMU";
4533  if (fISW[4] >= 0) {
4534  Printf(" IMPROVE HAS FOUND A TRULY NEW MINIMUM");
4535  Printf(" *************************************");
4536  }
4537  return;
4538 //*-*- . . . return to previous region
4539 L280:
4540  if (fISW[4] > 0) {
4541  Printf(" COVARIANCE MATRIX WAS NOT POSITIVE-DEFINITE");
4542  }
4543  goto L325;
4544 L300:
4545  fISW[0] = 1;
4546 L325:
4547  for (i = 1; i <= fNpar; ++i) {
4548  fDirin[i-1] = fIMPRdsav[i-1]*.01;
4549  fX[i-1] = fXt[i-1];
4550  }
4551  fAmin = fApsi;
4552  fEDM = sigsav;
4553 L350:
4554  mninex(fX);
4555  if (fISW[4] > 0) {
4556  Printf(" IMPROVE HAS RETURNED TO REGION OF ORIGINAL MINIMUM");
4557  }
4558  fCstatu = "UNCHANGED ";
4559  mnrset(0);
4560  if (fISW[1] < 2) goto L380;
4561  if (loop < nloop && fISW[0] < 1) goto L20;
4562 L380:
4563  if (iswtr >= 0) mnprin(5, fAmin);
4564  fItaur = 0;
4565 } /* mnimpr_ */
4566 
4567 ////////////////////////////////////////////////////////////////////////////////
4568 ///*-*-*-*-*Transforms from internal coordinates (PINT) to external (U)*-*-*-*
4569 ///*-* ===========================================================
4570 ///*-* The minimizing routines which work in
4571 ///*-* internal coordinates call this routine before calling FCN.
4572 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4573 
4575 {
4576  Int_t i, j;
4577 
4578  for (j = 0; j < fNpar; ++j) {
4579  i = fNexofi[j]-1;
4580  if (fNvarl[i] == 1) {
4581  fU[i] = pint[j];
4582  } else {
4583  fU[i] = fAlim[i] + (TMath::Sin(pint[j]) + 1)*.5*(fBlim[i] - fAlim[i]);
4584  }
4585  }
4586 } /* mninex_ */
4587 
4588 ////////////////////////////////////////////////////////////////////////////////
4589 ///*-*-*-*-*-*Main initialization member function for MINUIT*-*-*-*-*-*-*-*-*
4590 ///*-* ==============================================
4591 ///*-* It initializes some constants
4592 ///*-* (including the logical I/O unit nos.),
4593 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4594 
4596 {
4597  /* Local variables */
4598  volatile Double_t epsp1;
4599  Double_t piby2, epstry, epsbak, distnn;
4600  Int_t i, idb;
4601 
4602 //*-*- I/O unit numbers
4603  fIsysrd = i1;
4604  fIsyswr = i2;
4605  fIstkwr[0] = fIsyswr;
4606  fNstkwr = 1;
4607  fIsyssa = i3;
4608  fNstkrd = 0;
4609 //*-*- version identifier
4610  fCvrsn = "95.03++ ";
4611 //*-*- some CONSTANT
4612  fMaxint = fMaxpar;
4613  fMaxext = 2*fMaxpar;
4614  fUndefi = -54321;
4615  fBigedm = 123456;
4616  fCundef = ")UNDEFINED";
4617  fCovmes[0] = "NO ERROR MATRIX ";
4618  fCovmes[1] = "ERR MATRIX APPROXIMATE";
4619  fCovmes[2] = "ERR MATRIX NOT POS-DEF";
4620  fCovmes[3] = "ERROR MATRIX ACCURATE ";
4621 //*-*- some starting values
4622  fNblock = 0;
4623  fIcomnd = 0;
4624  fCtitl = fCundef;
4625  fCfrom = "INPUT ";
4626  fNfcn = 0;
4627  fNfcnfr = fNfcn;
4628  fCstatu = "INITIALIZE";
4629  fISW[2] = 0;
4630  fISW[3] = 0;
4631  fISW[4] = 1;
4632 //*-*- fISW[5]=0 for batch jobs, =1 for interactive jobs
4633 //*-*- =-1 for originally interactive temporarily batch
4634 
4635  fISW[5] = 0;
4636 // if (intrac(&dummy)) fISW[5] = 1;
4637 //*-*- DEBUG options set to default values
4638  for (idb = 0; idb <= 10; ++idb) { fIdbg[idb] = 0; }
4639  fLrepor = kFALSE;
4640  fLwarn = kTRUE;
4641  fLimset = kFALSE;
4642  fLnewmn = kFALSE;
4643  fIstrat = 1;
4644  fItaur = 0;
4645 //*-*- default page dimensions and 'new page' carriage control integer
4646  fNpagwd = 120;
4647  fNpagln = 56;
4648  fNewpag = 1;
4649  if (fISW[5] > 0) {
4650  fNpagwd = 80;
4651  fNpagln = 30;
4652  fNewpag = 0;
4653  }
4654  fUp = 1;
4655  fUpdflt = fUp;
4656 //*-*- determine machine accuracy epsmac
4657  epstry = .5;
4658  for (i = 1; i <= 100; ++i) {
4659  epstry *= .5;
4660  epsp1 = epstry + 1;
4661  mntiny(epsp1, epsbak);
4662  if (epsbak < epstry) goto L35;
4663  }
4664  epstry = 1e-7;
4665  fEpsmac = epstry*4;
4666  Printf(" MNINIT UNABLE TO DETERMINE ARITHMETIC PRECISION. WILL ASSUME:%g",fEpsmac);
4667 L35:
4668  fEpsmac = epstry*8;
4670 //*-*- the vlims are a non-negligible distance from pi/2
4671 //*-*- used by MNPINT to set variables "near" the physical limits
4672  piby2 = TMath::ATan(1)*2;
4673  distnn = TMath::Sqrt(fEpsma2)*8;
4674  fVlimhi = piby2 - distnn;
4675  fVlimlo = -piby2 + distnn;
4676  mncler();
4677 // Printf(" MINUIT RELEASE %s INITIALIZED. DIMENSIONS 100/50 EPSMAC=%g",(const char*)fCvrsn,fEpsmac);
4678 } /* mninit_ */
4679 
4680 ////////////////////////////////////////////////////////////////////////////////
4681 ///*-*-*-*Interprets the SET LIM command, to reset the parameter limits*-*-*-*
4682 ///*-* =============================================================
4683 ///*-* Called from MNSET
4684 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4685 
4687 {
4688  /* Local variables */
4689  Double_t dxdi, snew;
4690  Int_t kint, i2, newcod, ifx=0, inu;
4691 
4692  fCfrom = "SET LIM ";
4693  fNfcnfr = fNfcn;
4694  fCstatu = "NO CHANGE ";
4695  i2 = Int_t(fWord7[0]);
4696  if (i2 > fMaxext || i2 < 0) goto L900;
4697  if (i2 > 0) goto L30;
4698 //*-*- set limits on all parameters
4699  newcod = 4;
4700  if (fWord7[1] == fWord7[2]) newcod = 1;
4701  for (inu = 1; inu <= fNu; ++inu) {
4702  if (fNvarl[inu-1] <= 0) continue;
4703  if (fNvarl[inu-1] == 1 && newcod == 1) continue;
4704  kint = fNiofex[inu-1];
4705 //*-*- see if parameter has been fixed
4706  if (kint <= 0) {
4707  if (fISW[4] >= 0) {
4708  Printf(" LIMITS NOT CHANGED FOR FIXED PARAMETER:%4d",inu);
4709  }
4710  continue;
4711  }
4712  if (newcod == 1) {
4713 //*-*- remove limits from parameter
4714  if (fISW[4] > 0) {
4715  Printf(" LIMITS REMOVED FROM PARAMETER :%3d",inu);
4716  }
4717  fCstatu = "NEW LIMITS";
4718  mndxdi(fX[kint-1], kint-1, dxdi);
4719  snew = fGstep[kint-1]*dxdi;
4720  fGstep[kint-1] = TMath::Abs(snew);
4721  fNvarl[inu-1] = 1;
4722  } else {
4723 //*-*- put limits on parameter
4724  fAlim[inu-1] = TMath::Min(fWord7[1],fWord7[2]);
4725  fBlim[inu-1] = TMath::Max(fWord7[1],fWord7[2]);
4726  if (fISW[4] > 0) {
4727  Printf(" PARAMETER %3d LIMITS SET TO %15.5g%15.5g",inu,fAlim[inu-1],fBlim[inu-1]);
4728  }
4729  fNvarl[inu-1] = 4;
4730  fCstatu = "NEW LIMITS";
4731  fGstep[kint-1] = -.1;
4732  }
4733  }
4734  goto L900;
4735 //*-*- set limits on one parameter
4736 L30:
4737  if (fNvarl[i2-1] <= 0) {
4738  Printf(" PARAMETER %3d IS NOT VARIABLE.", i2);
4739  goto L900;
4740  }
4741  kint = fNiofex[i2-1];
4742 //*-*- see if parameter was fixed
4743  if (kint == 0) {
4744  Printf(" REQUEST TO CHANGE LIMITS ON FIXED PARAMETER:%3d",i2);
4745  for (ifx = 1; ifx <= fNpfix; ++ifx) {
4746  if (i2 == fIpfix[ifx-1]) goto L92;
4747  }
4748  Printf(" MINUIT BUG IN MNLIMS. SEE F. JAMES");
4749 L92:
4750  ;
4751  }
4752  if (fWord7[1] != fWord7[2]) goto L235;
4753 //*-*- remove limits
4754  if (fNvarl[i2-1] != 1) {
4755  if (fISW[4] > 0) {
4756  Printf(" LIMITS REMOVED FROM PARAMETER %2d",i2);
4757  }
4758  fCstatu = "NEW LIMITS";
4759  if (kint <= 0) {
4760  fGsteps[ifx-1] = TMath::Abs(fGsteps[ifx-1]);
4761  } else {
4762  mndxdi(fX[kint-1], kint-1, dxdi);
4763  if (TMath::Abs(dxdi) < .01) dxdi = .01;
4764  fGstep[kint-1] = TMath::Abs(fGstep[kint-1]*dxdi);
4765  fGrd[kint-1] *= dxdi;
4766  }
4767  fNvarl[i2-1] = 1;
4768  } else {
4769  Printf(" NO LIMITS SPECIFIED. PARAMETER %3d IS ALREADY UNLIMITED. NO CHANGE.",i2);
4770  }
4771  goto L900;
4772 //*-*- put on limits
4773 L235:
4774  fAlim[i2-1] = TMath::Min(fWord7[1],fWord7[2]);
4775  fBlim[i2-1] = TMath::Max(fWord7[1],fWord7[2]);
4776  fNvarl[i2-1] = 4;
4777  if (fISW[4] > 0) {
4778  Printf(" PARAMETER %3d LIMITS SET TO %15.5g%15.5g",i2,fAlim[i2-1],fBlim[i2-1]);
4779  }
4780  fCstatu = "NEW LIMITS";
4781  if (kint <= 0) fGsteps[ifx-1] = -.1;
4782  else fGstep[kint-1] = -.1;
4783 
4784 L900:
4785  if (fCstatu != "NO CHANGE ") {
4786  mnexin(fX);
4787  mnrset(1);
4788  }
4789 } /* mnlims_ */
4790 
4791 ////////////////////////////////////////////////////////////////////////////////
4792 ///*-*-*-*-*-*-*-*-*-*Perform a line search from position START*-*-*-*-*-*-*-*
4793 ///*-* =========================================
4794 ///*-* along direction STEP, where the length of vector STEP
4795 ///*-* gives the expected position of minimum.
4796 ///*-* FSTART is value of function at START
4797 ///*-* SLOPE (if non-zero) is df/dx along STEP at START
4798 ///*-* TOLER is initial tolerance of minimum in direction STEP
4799 ///*-*
4800 ///*-* SLAMBG and ALPHA control the maximum individual steps allowed.
4801 ///*-* The first step is always =1. The max length of second step is SLAMBG.
4802 ///*-* The max size of subsequent steps is the maximum previous successful
4803 ///*-* step multiplied by ALPHA + the size of most recent successful step,
4804 ///*-* but cannot be smaller than SLAMBG.
4805 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4806 
4807 void TMinuit::mnline(Double_t *start, Double_t fstart, Double_t *step, Double_t slope, Double_t toler)
4808 {
4809  /* Local variables */
4810  Double_t xpq[12], ypq[12], slam, sdev, coeff[3], denom, flast;
4811  Double_t fvals[3], xvals[3], f1, fvmin, xvmin, ratio, f2, f3 = 0., fvmax;
4812  Double_t toler8, toler9, overal, undral, slamin, slamax, slopem;
4813  Int_t i, nparx=0, nvmax=0, nxypt, kk, ipt;
4814  Bool_t ldebug;
4815  TString cmess;
4816  char chpq[13];
4817  int l65, l70, l80;
4818 
4819  /* Function Body */
4820  l65 = 0; l70 = 0; l80 = 0;
4821  ldebug = fIdbg[1] >= 1;
4822 //*-*- starting values for overall limits on total step SLAM
4823  overal = 1e3;
4824  undral = -100;
4825 //*-*- debug check if start is ok
4826  if (ldebug) {
4827  mninex(&start[0]);
4828  Eval(nparx, fGin, f1, fU, 4); ++fNfcn;
4829  if (f1 != fstart) {
4830  Printf(" MNLINE start point not consistent, F values, parameters=");
4831  for (kk = 1; kk <= fNpar; ++kk) {
4832  Printf(" %14.5e",fX[kk-1]);
4833  }
4834  }
4835  }
4836 //*-*- . set up linear search along STEP
4837  fvmin = fstart;
4838  xvmin = 0;
4839  nxypt = 1;
4840  chpq[0] = charal[0];
4841  xpq[0] = 0;
4842  ypq[0] = fstart;
4843 //*-*- SLAMIN = smallest possible value of ABS(SLAM)
4844  slamin = 0;
4845  for (i = 1; i <= fNpar; ++i) {
4846  if (step[i-1] != 0) {
4847  ratio = TMath::Abs(start[i-1] / step[i-1]);
4848  if (slamin == 0) slamin = ratio;
4849  if (ratio < slamin) slamin = ratio;
4850  }
4851  fX[i-1] = start[i-1] + step[i-1];
4852  }
4853  if (slamin == 0) slamin = fEpsmac;
4854  slamin *= fEpsma2;
4855  nparx = fNpar;
4856 
4857  mninex(fX);
4858  Eval(nparx, fGin, f1, fU, 4); ++fNfcn;
4859  ++nxypt;
4860  chpq[nxypt-1] = charal[nxypt-1];
4861  xpq[nxypt-1] = 1;
4862  ypq[nxypt-1] = f1;
4863  if (f1 < fstart) {
4864  fvmin = f1;
4865  xvmin = 1;
4866  }
4867 //*-*- . quadr interp using slope GDEL and two points
4868  slam = 1;
4869  toler8 = toler;
4870  slamax = 5;
4871  flast = f1;
4872 //*-*- can iterate on two-points (cut) if no imprvmnt
4873 
4874  do {
4875  denom = (flast - fstart - slope*slam)*2 / (slam*slam);
4876  slam = 1;
4877  if (denom != 0) slam = -slope / denom;
4878  if (slam < 0) slam = slamax;
4879  if (slam > slamax) slam = slamax;
4880  if (slam < toler8) slam = toler8;
4881  if (slam < slamin) {
4882  l80 = 1;
4883  break;
4884  }
4885  if (TMath::Abs(slam - 1) < toler8 && f1 < fstart) {
4886  l70 = 1;
4887  break;
4888  }
4889  if (TMath::Abs(slam - 1) < toler8) slam = toler8 + 1;
4890  if (nxypt >= 12) {
4891  l65 = 1;
4892  break;
4893  }
4894  for (i = 1; i <= fNpar; ++i) { fX[i-1] = start[i-1] + slam*step[i-1]; }
4895  mninex(fX);
4896  nparx = fNpar;
4897  Eval(nparx, fGin, f2, fU, 4); ++fNfcn;
4898  ++nxypt;
4899  chpq[nxypt-1] = charal[nxypt-1];
4900  xpq[nxypt-1] = slam;
4901  ypq[nxypt-1] = f2;
4902  if (f2 < fvmin) {
4903  fvmin = f2;
4904  xvmin = slam;
4905  }
4906  if (fstart == fvmin) {
4907  flast = f2;
4908  toler8 = toler*slam;
4909  overal = slam - toler8;
4910  slamax = overal;
4911  }
4912  } while (fstart == fvmin);
4913 
4914  if (!l65 && !l70 && !l80) {
4915 //*-*- . quadr interp using 3 points
4916  xvals[0] = xpq[0];
4917  fvals[0] = ypq[0];
4918  xvals[1] = xpq[nxypt-2];
4919  fvals[1] = ypq[nxypt-2];
4920  xvals[2] = xpq[nxypt-1];
4921  fvals[2] = ypq[nxypt-1];
4922 //*-*- begin iteration, calculate desired step
4923  do {
4924  slamax = TMath::Max(slamax,TMath::Abs(xvmin)*2);
4925  mnpfit(xvals, fvals, 3, coeff, sdev);
4926  if (coeff[2] <= 0) {
4927  slopem = coeff[2]*2*xvmin + coeff[1];
4928  if (slopem <= 0) slam = xvmin + slamax;
4929  else slam = xvmin - slamax;
4930  } else {
4931  slam = -coeff[1] / (coeff[2]*2);
4932  if (slam > xvmin + slamax) slam = xvmin + slamax;
4933  if (slam < xvmin - slamax) slam = xvmin - slamax;
4934  }
4935  if (slam > 0) {
4936  if (slam > overal)
4937  slam = overal;
4938  else if (slam < undral)
4939  slam = undral;
4940  }
4941 
4942 //*-*- come here if step was cut below
4943  do {
4944  toler9 = TMath::Max(toler8,TMath::Abs(toler8*slam));
4945  for (ipt = 1; ipt <= 3; ++ipt) {
4946  if (TMath::Abs(slam - xvals[ipt-1]) < toler9) {
4947  l70 = 1;
4948  break;
4949  }
4950  }
4951  if (l70) break;
4952 //*-*- take the step
4953  if (nxypt >= 12) {
4954  l65 = 1;
4955  break;
4956  }
4957  for (i = 1; i <= fNpar; ++i) { fX[i-1] = start[i-1] + slam*step[i-1]; }
4958  mninex(fX);
4959  Eval(nparx, fGin, f3, fU, 4); ++fNfcn;
4960  ++nxypt;
4961  chpq[nxypt-1] = charal[nxypt-1];
4962  xpq[nxypt-1] = slam;
4963  ypq[nxypt-1] = f3;
4964 //*-*- find worst previous point out of three
4965  fvmax = fvals[0];
4966  nvmax = 1;
4967  if (fvals[1] > fvmax) {
4968  fvmax = fvals[1];
4969  nvmax = 2;
4970  }
4971  if (fvals[2] > fvmax) {
4972  fvmax = fvals[2];
4973  nvmax = 3;
4974  }
4975 //*-*- if latest point worse than all three previous, cut step
4976  if (f3 >= fvmax) {
4977  if (nxypt >= 12) {
4978  l65 = 1;
4979  break;
4980  }
4981  if (slam > xvmin) overal = TMath::Min(overal,slam - toler8);
4982  if (slam < xvmin) undral = TMath::Max(undral,slam + toler8);
4983  slam = (slam + xvmin)*.5;
4984  }
4985  } while (f3 >= fvmax);
4986 
4987 //*-*- prepare another iteration, replace worst previous point
4988  if (l65 || l70) break;
4989 
4990  xvals[nvmax-1] = slam;
4991  fvals[nvmax-1] = f3;
4992  if (f3 < fvmin) {
4993  fvmin = f3;
4994  xvmin = slam;
4995  } else {
4996  if (slam > xvmin) overal = TMath::Min(overal,slam - toler8);
4997  if (slam < xvmin) undral = TMath::Max(undral,slam + toler8);
4998  }
4999  } while (nxypt < 12);
5000  }
5001 
5002 //*-*- . . end of iteration . . .
5003 //*-*- stop because too many iterations
5004  if (!l70 && !l80) {
5005  cmess = " LINE SEARCH HAS EXHAUSTED THE LIMIT OF FUNCTION CALLS ";
5006  if (ldebug) {
5007  Printf(" MNLINE DEBUG: steps=");
5008  for (kk = 1; kk <= fNpar; ++kk) {
5009  Printf(" %12.4g",step[kk-1]);
5010  }
5011  }
5012  }
5013 //*-*- stop because within tolerance
5014  if (l70) cmess = " LINE SEARCH HAS ATTAINED TOLERANCE ";
5015  if (l80) cmess = " STEP SIZE AT ARITHMETICALLY ALLOWED MINIMUM";
5016 
5017  fAmin = fvmin;
5018  for (i = 1; i <= fNpar; ++i) {
5019  fDirin[i-1] = step[i-1]*xvmin;
5020  fX[i-1] = start[i-1] + fDirin[i-1];
5021  }
5022  mninex(fX);
5023  if (xvmin < 0) {
5024  mnwarn("D", "MNLINE", " LINE MINIMUM IN BACKWARDS DIRECTION");
5025  }
5026  if (fvmin == fstart) {
5027  mnwarn("D", "MNLINE", " LINE SEARCH FINDS NO IMPROVEMENT ");
5028  }
5029  if (ldebug) {
5030  Printf(" AFTER %3d POINTS,%s",nxypt,(const char*)cmess);
5031  mnplot(xpq, ypq, chpq, nxypt, fNpagwd, fNpagln);
5032  }
5033 } /* mnline_ */
5034 
5035 ////////////////////////////////////////////////////////////////////////////////
5036 ///*-*-*-*-*-*-*-*Prints the covariance matrix v when KODE=1*-*-*-*-*-*-*-*-*
5037 ///*-* ==========================================
5038 ///*-* always prints the global correlations, and
5039 ///*-* calculates and prints the individual correlation coefficients
5040 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
5041 
5043 {
5044  /* Local variables */
5045  Int_t ndex, i, j, m, n, ncoef, nparm, id, it, ix;
5046  Int_t nsofar, ndi, ndj, iso, isw2, isw5;
5047  TString ctemp;
5048 
5049  isw2 = fISW[1];
5050  if (isw2 < 1) {
5051  Printf("%s",(const char*)fCovmes[isw2]);
5052  return;
5053  }
5054  if (fNpar == 0) {
5055  Printf(" MNMATU: NPAR=0");
5056  return;
5057  }
5058 //*-*- . . . . .external error matrix
5059  if (kode == 1) {
5060  isw5 = fISW[4];
5061  fISW[4] = 2;
5062  mnemat(fP, fMaxint);
5063  if (isw2 < 3) {
5064  Printf("%s",(const char*)fCovmes[isw2]);
5065  }
5066  fISW[4] = isw5;
5067  }
5068 //*-*- . . . . . correlation coeffs. .
5069  if (fNpar <= 1) return;
5070  mnwerr();
5071 //*-*- NCOEF is number of coeff. that fit on one line, not to exceed 20
5072  ncoef = (fNpagwd - 19) / 6;
5073  ncoef = TMath::Min(ncoef,20);
5074  nparm = TMath::Min(fNpar,ncoef);
5075  Printf(" PARAMETER CORRELATION COEFFICIENTS ");
5076  ctemp = " NO. GLOBAL";
5077  for (id = 1; id <= nparm; ++id) {
5078  ctemp += TString::Format(" %6d",fNexofi[id-1]);
5079  }
5080  Printf("%s",(const char*)ctemp);
5081  for (i = 1; i <= fNpar; ++i) {
5082  ix = fNexofi[i-1];
5083  ndi = i*(i + 1) / 2;
5084  for (j = 1; j <= fNpar; ++j) {
5085  m = TMath::Max(i,j);
5086  n = TMath::Min(i,j);
5087  ndex = m*(m-1) / 2 + n;
5088  ndj = j*(j + 1) / 2;
5089  fMATUvline[j-1] = fVhmat[ndex-1] / TMath::Sqrt(TMath::Abs(fVhmat[ndi-1]*fVhmat[ndj-1]));
5090  }
5091  nparm = TMath::Min(fNpar,ncoef);
5092  ctemp.Form(" %3d %7.5f ",ix,fGlobcc[i-1]);
5093  for (it = 1; it <= nparm; ++it) {
5094  ctemp += TString::Format(" %6.3f",fMATUvline[it-1]);
5095  }
5096  Printf("%s",(const char*)ctemp);
5097  if (i <= nparm) continue;
5098  ctemp = " ";
5099  for (iso = 1; iso <= 10; ++iso) {
5100  nsofar = nparm;
5101  nparm = TMath::Min(fNpar,nsofar + ncoef);
5102  for (it = nsofar + 1; it <= nparm; ++it) {
5103  ctemp = ctemp + TString::Format(" %6.3f",fMATUvline[it-1]);
5104  }
5105  Printf("%s",(const char*)ctemp);
5106  if (i <= nparm) break;
5107  }
5108  }
5109  if (isw2 < 3) {
5110  Printf(" %s",(const char*)fCovmes[isw2]);
5111  }
5112 } /* mnmatu_ */
5113 
5114 ////////////////////////////////////////////////////////////////////////////////
5115 ///*-*-*-*-*-*-*-*-*Performs a local function minimization*-*-*-*-*-*-*-*-*-*
5116 ///*-* ======================================
5117 ///*-* Performs a local function minimization using basically the
5118 ///*-* method of Davidon-Fletcher-Powell as modified by Fletcher
5119 ///*-* ref. -- Fletcher, Comp.J. 13,317 (1970) "switching method"
5120 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
5121 
5123 {
5124  /* Local variables */
5125  Double_t gdel, gami, vlen, dsum, gssq, vsum, d;
5126  Double_t fzero, fs, ri, delgam, rhotol;
5127  Double_t gdgssq, gvg, vgi;
5128  Int_t npfn, ndex, iext, i, j, m, n, npsdf, nparx;
5129  Int_t iswtr, lined2, kk, nfcnmg, nrstrt,iter;
5130  Bool_t ldebug;
5131  Double_t toler = 0.05;
5132 
5133  if (fNpar <= 0) return;
5134  if (fAmin == fUndefi) mnamin();
5135  ldebug = kFALSE; if ( fIdbg[4] >= 1) ldebug = kTRUE;
5136  fCfrom = "MIGRAD ";
5137  fNfcnfr = fNfcn;
5138  nfcnmg = fNfcn;
5139  fCstatu = "INITIATE ";
5140  iswtr = fISW[4] - 2*fItaur;
5141  npfn = fNfcn;
5142  nparx = fNpar;
5143  vlen = (Double_t) (fNpar*(fNpar + 1) / 2);
5144  nrstrt = 0;
5145  npsdf = 0;
5146  lined2 = 0;
5147  fISW[3] = -1;
5148  rhotol = fApsi*.001;
5149  if (iswtr >= 1) {
5150  Printf(" START MIGRAD MINIMIZATION. STRATEGY %2d. CONVERGENCE WHEN EDM .LT.%9.2e",fIstrat,rhotol);
5151  }
5152 //*-*- initialization strategy
5153  if (fIstrat < 2 || fISW[1] >= 3) goto L2;
5154 //*-*- come (back) here to restart completely
5155 L1:
5156  if (nrstrt > fIstrat) {
5157  fCstatu = "FAILED ";
5158  fISW[3] = -1;
5159  goto L230;
5160  }
5161 //*-*- . get full covariance and gradient
5162  mnhess();
5163  mnwerr();
5164  npsdf = 0;
5165  if (fISW[1] >= 1) goto L10;
5166 //*-*- . get gradient at start point
5167 L2:
5168  mninex(fX);
5169  if (fISW[2] == 1) {
5170  Eval(nparx, fGin, fzero, fU, 2); ++fNfcn;
5171  }
5172  mnderi();
5173  if (fISW[1] >= 1) goto L10;
5174 //*-*- sometimes start with diagonal matrix
5175  for (i = 1; i <= fNpar; ++i) {
5176  fMIGRxxs[i-1] = fX[i-1];
5177  fMIGRstep[i-1] = 0;
5178  }
5179 //*-*- do line search if second derivative negative
5180  ++lined2;
5181  if (lined2 < (fIstrat + 1)*fNpar) {
5182  for (i = 1; i <= fNpar; ++i) {
5183  if (fG2[i-1] > 0) continue;
5184  if (fGrd[i-1] > 0) fMIGRstep[i-1] = -TMath::Abs(fGstep[i-1]);
5185  else fMIGRstep[i-1] = TMath::Abs(fGstep[i-1]);
5186  gdel = fMIGRstep[i-1]*fGrd[i-1];
5187  fs = fAmin;
5188  mnline(fMIGRxxs, fs, fMIGRstep, gdel, toler);
5189  mnwarn("D", "MNMIGR", "Negative G2 line search");
5190  iext = fNexofi[i-1];
5191  if (ldebug) {
5192  Printf(" Negative G2 line search, param %3d %13.3g%13.3g",iext,fs,fAmin);
5193  }
5194  goto L2;
5195  }
5196  }
5197 //*-*- make diagonal error matrix
5198  for (i = 1; i <= fNpar; ++i) {
5199  ndex = i*(i-1) / 2;
5200  for (j = 1; j <= i-1; ++j) {
5201  ++ndex;
5202  fVhmat[ndex-1] = 0;
5203  }
5204  ++ndex;
5205  if (fG2[i-1] <= 0) fG2[i-1] = 1;
5206  fVhmat[ndex-1] = 2 / fG2[i-1];
5207  }
5208  fDcovar = 1;
5209  if (ldebug) {
5210  Printf(" DEBUG MNMIGR, STARTING MATRIX DIAGONAL, VHMAT=");
5211  for (kk = 1; kk <= Int_t(vlen); ++kk) {
5212  Printf(" %10.2g",fVhmat[kk-1]);
5213  }
5214  }
5215 //*-*- ready to start first iteration
5216 L10:
5217  ++nrstrt;
5218  if (nrstrt > fIstrat + 1) {
5219  fCstatu = "FAILED ";
5220  goto L230;
5221  }
5222  fs = fAmin;
5223 //*-*- . . . get EDM and set up loop
5224  fEDM = 0;
5225  for (i = 1; i <= fNpar; ++i) {
5226  fMIGRgs[i-1] = fGrd[i-1];
5227  fMIGRxxs[i-1] = fX[i-1];
5228  ndex = i*(i-1) / 2;
5229  for (j = 1; j <= i-1; ++j) {
5230  ++ndex;
5231  fEDM += fMIGRgs[i-1]*fVhmat[ndex-1]*fMIGRgs[j-1];
5232  }
5233  ++ndex;
5234  fEDM += fMIGRgs[i-1]*fMIGRgs[i-1]*.5*fVhmat[ndex-1];
5235  }
5236  fEDM = fEDM*.5*(fDcovar*3 + 1);
5237  if (fEDM < 0) {
5238  mnwarn("W", "MIGRAD", "STARTING MATRIX NOT POS-DEFINITE.");
5239  fISW[1] = 0;
5240  fDcovar = 1;
5241  goto L2;
5242  }
5243  if (fISW[1] == 0) fEDM = fBigedm;
5244  iter = 0;
5245  mninex(fX);
5246  mnwerr();
5247  if (iswtr >= 1) mnprin(3, fAmin);
5248  if (iswtr >= 2) mnmatu(0);
5249 //*-*- . . . . . start main loop
5250 L24:
5251  if (fNfcn - npfn >= fNfcnmx) goto L190;
5252  gdel = 0;
5253  gssq = 0;
5254  for (i = 1; i <= fNpar; ++i) {
5255  ri = 0;
5256  gssq += fMIGRgs[i-1]*fMIGRgs[i-1];
5257  for (j = 1; j <= fNpar; ++j) {
5258  m = TMath::Max(i,j);
5259  n = TMath::Min(i,j);
5260  ndex = m*(m-1) / 2 + n;
5261  ri += fVhmat[ndex-1]*fMIGRgs[j-1];
5262  }
5263  fMIGRstep[i-1] = ri*-.5;
5264  gdel += fMIGRstep[i-1]*fMIGRgs[i-1];
5265  }
5266  if (gssq == 0) {
5267  mnwarn("D", "MIGRAD", " FIRST DERIVATIVES OF FCN ARE ALL ZERO");
5268  goto L300;
5269  }
5270 //*-*- if gdel positive, V not posdef
5271  if (gdel >= 0) {
5272  mnwarn("D", "MIGRAD", " NEWTON STEP NOT DESCENT.");
5273  if (npsdf == 1) goto L1;
5274  mnpsdf();
5275  npsdf = 1;
5276  goto L24;
5277  }
5278 //*-*- . . . . do line search
5279  mnline(fMIGRxxs, fs, fMIGRstep, gdel, toler);
5280  if (fAmin == fs) goto L200;
5281  fCfrom = "MIGRAD ";
5282  fNfcnfr = nfcnmg;
5283  fCstatu = "PROGRESS ";
5284 //*-*- . get gradient at new point
5285  mninex(fX);
5286  if (fISW[2] == 1) {
5287  Eval(nparx, fGin, fzero, fU, 2); ++fNfcn;
5288  }
5289  mnderi();
5290 //*-*- . calculate new EDM
5291  npsdf = 0;
5292 L81:
5293  fEDM = 0;
5294  gvg = 0;
5295  delgam = 0;
5296  gdgssq = 0;
5297  for (i = 1; i <= fNpar; ++i) {
5298  ri = 0;
5299  vgi = 0;
5300  for (j = 1; j <= fNpar; ++j) {
5301  m = TMath::Max(i,j);
5302  n = TMath::Min(i,j);
5303  ndex = m*(m-1) / 2 + n;
5304  vgi += fVhmat[ndex-1]*(fGrd[j-1] - fMIGRgs[j-1]);
5305  ri += fVhmat[ndex-1]*fGrd[j-1];
5306  }
5307  fMIGRvg[i-1] = vgi*.5;
5308  gami = fGrd[i-1] - fMIGRgs[i-1];
5309  gdgssq += gami*gami;
5310  gvg += gami*fMIGRvg[i-1];
5311  delgam += fDirin[i-1]*gami;
5312  fEDM += fGrd[i-1]*ri*.5;
5313  }
5314  fEDM = fEDM*.5*(fDcovar*3 + 1);
5315 //*-*- . if EDM negative, not positive-definite
5316  if (fEDM < 0 || gvg <= 0) {
5317  mnwarn("D", "MIGRAD", "NOT POS-DEF. EDM OR GVG NEGATIVE.");
5318  fCstatu = "NOT POSDEF";
5319  if (npsdf == 1) goto L230;
5320  mnpsdf();
5321  npsdf = 1;
5322  goto L81;
5323  }
5324 //*-*- print information about this iteration
5325  ++iter;
5326  if (iswtr >= 3 || (iswtr == 2 && iter % 10 == 1)) {
5327  mnwerr();
5328  mnprin(3, fAmin);
5329  }
5330  if (gdgssq == 0) {
5331  mnwarn("D", "MIGRAD", "NO CHANGE IN FIRST DERIVATIVES OVER LAST STEP");
5332  }
5333  if (delgam < 0) {
5334  mnwarn("D", "MIGRAD", "FIRST DERIVATIVES INCREASING ALONG SEARCH LINE");
5335  }
5336 //*-*- . update covariance matrix
5337  fCstatu = "IMPROVEMNT";
5338  if (ldebug) {
5339  Printf(" VHMAT 1 =");
5340  for (kk = 1; kk <= 10; ++kk) {
5341  Printf(" %10.2g",fVhmat[kk-1]);
5342  }
5343  }
5344  dsum = 0;
5345  vsum = 0;
5346  for (i = 1; i <= fNpar; ++i) {
5347  for (j = 1; j <= i; ++j) {
5348  if(delgam == 0 || gvg == 0) d = 0;
5349  else d = fDirin[i-1]*fDirin[j-1] / delgam - fMIGRvg[i-1]*fMIGRvg[j-1] / gvg;
5350  dsum += TMath::Abs(d);
5351  ndex = i*(i-1) / 2 + j;
5352  fVhmat[ndex-1] += d*2;
5353  vsum += TMath::Abs(fVhmat[ndex-1]);
5354  }
5355  }
5356 //*-*- smooth local fluctuations by averaging DCOVAR
5357  fDcovar = (fDcovar + dsum / vsum)*.5;
5358  if (iswtr >= 3 || ldebug) {
5359  Printf(" RELATIVE CHANGE IN COV. MATRIX=%5.1f per cent",fDcovar*100);
5360  }
5361  if (ldebug) {
5362  Printf(" VHMAT 2 =");
5363  for (kk = 1; kk <= 10; ++kk) {
5364  Printf(" %10.3g",fVhmat[kk-1]);
5365  }
5366  }
5367  if (delgam <= gvg) goto L135;
5368  for (i = 1; i <= fNpar; ++i) {
5369  fMIGRflnu[i-1] = fDirin[i-1] / delgam - fMIGRvg[i-1] / gvg;
5370  }
5371  for (i = 1; i <= fNpar; ++i) {
5372  for (j = 1; j <= i; ++j) {
5373  ndex = i*(i-1) / 2 + j;
5374  fVhmat[ndex-1] += gvg*2*fMIGRflnu[i-1]*fMIGRflnu[j-1];
5375  }
5376  }
5377 L135:
5378 //*-*- and see if converged
5379  if (fEDM < rhotol*.1) goto L300;
5380 //*-*- if not, prepare next iteration
5381  for (i = 1; i <= fNpar; ++i) {
5382  fMIGRxxs[i-1] = fX[i-1];
5383  fMIGRgs[i-1] = fGrd[i-1];
5384  }
5385  fs = fAmin;
5386  if (fISW[1] == 0 && fDcovar < .5) fISW[1] = 1;
5387  if (fISW[1] == 3 && fDcovar > .1) fISW[1] = 1;
5388  if (fISW[1] == 1 && fDcovar < .05) fISW[1] = 3;
5389  goto L24;
5390 //*-*- . . . . . end main loop
5391 //*-*- . . call limit in MNMIGR
5392 L190:
5393  fISW[0] = 1;
5394  if (fISW[4] >= 0) {
5395  Printf(" CALL LIMIT EXCEEDED IN MIGRAD.");
5396  }
5397  fCstatu = "CALL LIMIT";
5398  goto L230;
5399 //*-*- . . fails to improve . .
5400 L200:
5401  if (iswtr >= 1) {
5402  Printf(" MIGRAD FAILS TO FIND IMPROVEMENT");
5403  }
5404  for (i = 1; i <= fNpar; ++i) { fX[i-1] = fMIGRxxs[i-1]; }
5405  if (fEDM < rhotol) goto L300;
5406  if (fEDM < TMath::Abs(fEpsma2*fAmin)) {
5407  if (iswtr >= 0) {
5408  Printf(" MACHINE ACCURACY LIMITS FURTHER IMPROVEMENT.");
5409  }
5410  goto L300;
5411  }
5412  if (fIstrat < 1) {
5413  if (fISW[4] >= 0) {
5414  Printf(" MIGRAD FAILS WITH STRATEGY=0. WILL TRY WITH STRATEGY=1.");
5415  }
5416  fIstrat = 1;
5417  }
5418  goto L1;
5419 //*-*- . . fails to converge
5420 L230:
5421  if (iswtr >= 0) {
5422  Printf(" MIGRAD TERMINATED WITHOUT CONVERGENCE.");
5423  }
5424  if (fISW[1] == 3) fISW[1] = 1;
5425  fISW[3] = -1;
5426  goto L400;
5427 //*-*- . . apparent convergence
5428 L300:
5429  if (iswtr >= 0) {
5430  Printf(" MIGRAD MINIMIZATION HAS CONVERGED.");
5431  }
5432  if (fItaur == 0) {
5433  if (fIstrat >= 2 || (fIstrat == 1 && fISW[1] < 3)) {
5434  if (fISW[4] >= 0) {
5435  Printf(" MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.");
5436  }
5437  mnhess();
5438  mnwerr();
5439  npsdf = 0;
5440  if (fEDM > rhotol) goto L10;
5441  }
5442  }
5443  fCstatu = "CONVERGED ";
5444  fISW[3] = 1;
5445 //*-*- come here in any case
5446 L400:
5447  fCfrom = "MIGRAD ";
5448  fNfcnfr = nfcnmg;
5449  mninex(fX);
5450  mnwerr();
5451  if (iswtr >= 0) mnprin(3, fAmin);
5452  if (iswtr >= 1) mnmatu(1);
5453 } /* mnmigr_ */
5454 
5455 ////////////////////////////////////////////////////////////////////////////////
5456 ///*-*-*-*-*-*-*-*-*-*-*Performs a MINOS error analysis*-*-*-*-*-*-*-*-*-*-*-*
5457 ///*-* ===============================
5458 ///*-* Performs a MINOS error analysis on those parameters for
5459 ///*-* which it is requested on the MINOS command by calling
5460 ///*-* MNMNOT for each parameter requested.
5461 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
5462 
5464 {
5465  /* Local variables */
5466  Double_t val2mi, val2pl;
5467  Int_t nbad, ilax, ilax2, ngood, nfcnmi, iin, knt;
5468 
5469  if (fNpar <= 0) goto L700;
5470  ngood = 0;
5471  nbad = 0;
5472  nfcnmi = fNfcn;
5473 //*-*- . loop over parameters requested
5474  for (knt = 1; knt <= fNpar; ++knt) {
5475  if (Int_t(fWord7[1]) == 0) {
5476  ilax = fNexofi[knt-1];
5477  } else {
5478  if (knt >= 7) break;
5479  ilax = Int_t(fWord7[knt]);
5480  if (ilax == 0) break;
5481  if (ilax > 0 && ilax <= fNu) {
5482  if (fNiofex[ilax-1] > 0) goto L565;
5483  }
5484  Printf(" PARAMETER NUMBER %3d NOT A VARIABLE. IGNORED.",ilax);
5485  continue;
5486  }
5487 L565:
5488 //*-*- calculate one pair of M E s
5489  ilax2 = 0;
5490  mnmnot(ilax, ilax2, val2pl, val2mi);
5491  if (fLnewmn) goto L650;
5492 //*-*- update NGOOD and NBAD
5493  iin = fNiofex[ilax-1];
5494  if (fErp[iin-1] > 0) ++ngood;
5495  else ++nbad;
5496  if (fErn[iin-1] < 0) ++ngood;
5497  else ++nbad;
5498  }
5499 //*-*- end of loop . . . . . . .
5500 //*-*- . . . . printout final values .
5501  fCfrom = "MINOS ";
5502  fNfcnfr = nfcnmi;
5503  fCstatu = "UNCHANGED ";
5504  if (ngood == 0 && nbad == 0) goto L700;
5505  if (ngood > 0 && nbad == 0) fCstatu = "SUCCESSFUL";
5506  if (ngood == 0 && nbad > 0) fCstatu = "FAILURE ";
5507  if (ngood > 0 && nbad > 0) fCstatu = "PROBLEMS ";
5508  if (fISW[4] >= 0) mnprin(4, fAmin);
5509  if (fISW[4] >= 2) mnmatu(0);
5510  return;
5511 //*-*- . . . new minimum found . . . .
5512 L650:
5513  fCfrom = "MINOS ";
5514  fNfcnfr = nfcnmi;
5515  fCstatu = "NEW MINIMU";
5516  if (fISW[4] >= 0) mnprin(4, fAmin);
5517  Printf(" NEW MINIMUM FOUND. GO BACK TO MINIMIZATION STEP.");
5518  Printf(" =================================================");
5519  Printf(" V");
5520  Printf(" V");
5521  Printf(" V");
5522  Printf(" VVVVVVV");
5523  Printf(" VVVVV");
5524  Printf(" VVV");
5525  Printf(" V\n");
5526  return;
5527 L700:
5528  Printf(" THERE ARE NO MINOS ERRORS TO CALCULATE.");
5529 } /* mnmnos_ */
5530 
5531 ////////////////////////////////////////////////////////////////////////////////
5532 ///*-*-*-*-*-*Performs a MINOS error analysis on one parameter*-*-*-*-*-*-*-*-*
5533 ///*-* ================================================
5534 ///*-* The parameter ILAX is varied, and the minimum of the
5535 ///*-* function with respect to the other parameters is followed
5536 ///*-* until it crosses the value FMIN+UP.
5537 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
5538 
5539 void TMinuit::mnmnot(Int_t ilax, Int_t ilax2, Double_t &val2pl, Double_t &val2mi)
5540 {
5541  /* System generated locals */
5542  Int_t i__1;
5543 
5544  /* Local variables */
5545  Double_t delu, aopt, eros;
5546  Double_t abest, xunit, dc, ut, sigsav, du1;
5547  Double_t fac, sig, sav;
5548  Int_t marc, isig, mpar, ndex, imax, indx, ierr, i, j;
5549  Int_t iercr, it, istrav, nfmxin, nlimit, isw2, isw4;
5550  TString csig;
5551 
5552 //*-*- . . save and prepare start vals
5553  isw2 = fISW[1];
5554  isw4 = fISW[3];
5555  sigsav = fEDM;
5556  istrav = fIstrat;
5557  dc = fDcovar;
5558  fLnewmn = kFALSE;
5559  fApsi = fEpsi*.5;
5560  abest = fAmin;
5561  mpar = fNpar;
5562  nfmxin = fNfcnmx;
5563  for (i = 1; i <= mpar; ++i) { fXt[i-1] = fX[i-1]; }
5564  i__1 = mpar*(mpar + 1) / 2;
5565  for (j = 1; j <= i__1; ++j) { fVthmat[j-1] = fVhmat[j-1]; }
5566  for (i = 1; i <= mpar; ++i) {
5567  fMNOTgcc[i-1] = fGlobcc[i-1];
5568  fMNOTw[i-1] = fWerr[i-1];
5569  }
5570  it = fNiofex[ilax-1];
5571  fErp[it-1] = 0;
5572  fErn[it-1] = 0;
5573  mninex(fXt);
5574  ut = fU[ilax-1];
5575  if (fNvarl[ilax-1] == 1) {
5576  fAlim[ilax-1] = ut - fMNOTw[it-1]*100;
5577  fBlim[ilax-1] = ut + fMNOTw[it-1]*100;
5578  }
5579  ndex = it*(it + 1) / 2;
5580  xunit = TMath::Sqrt(fUp / fVthmat[ndex-1]);
5581  marc = 0;
5582  for (i = 1; i <= mpar; ++i) {
5583  if (i == it) continue;
5584  ++marc;
5585  imax = TMath::Max(it,i);
5586  indx = imax*(imax-1) / 2 + TMath::Min(it,i);
5587  fMNOTxdev[marc-1] = xunit*fVthmat[indx-1];
5588  }
5589 //*-*- fix the parameter in question
5590  mnfixp(it-1, ierr);
5591  if (ierr > 0) {
5592  Printf(" MINUIT ERROR. CANNOT FIX PARAMETER %4d INTERNAL %3d",ilax,it);
5593  goto L700;
5594  }
5595 //*-*- . . . . . Nota Bene: from here on, NPAR=MPAR-1
5596 //*-*- Remember: MNFIXP squeezes IT out of X, XT, WERR, and VHMAT,
5597 //*-*- not W, VTHMAT
5598  for (isig = 1; isig <= 2; ++isig) {
5599  if (isig == 1) {
5600  sig = 1;
5601  csig = "POSI";
5602  } else {
5603  sig = -1;
5604  csig = "NEGA";
5605  }
5606 //*-*- . sig=sign of error being calcd
5607  if (fISW[4] > 1) {
5608  Printf(" DETERMINATION OF %sTIVE MINOS ERROR FOR PARAMETER %d %s"
5609  ,(const char*)csig,ilax
5610  ,(const char*)fCpnam[ilax-1]);
5611  }
5612  if (fISW[1] <= 0) {
5613  mnwarn("D", "MINOS", "NO COVARIANCE MATRIX.");
5614  }
5615  nlimit = fNfcn + nfmxin;
5616  fIstrat = TMath::Max(istrav-1,0);
5617  du1 = fMNOTw[it-1];
5618  fU[ilax-1] = ut + sig*du1;
5619  fU[ilax-1] = TMath::Min(fU[ilax-1],fBlim[ilax-1]);
5620  fU[ilax-1] = TMath::Max(fU[ilax-1],fAlim[ilax-1]);
5621  delu = fU[ilax-1] - ut;
5622 //*-*- stop if already at limit with negligible step size
5623  if (TMath::Abs(delu) / (TMath::Abs(ut) + TMath::Abs(fU[ilax-1])) < fEpsmac) goto L440;
5624  fac = delu / fMNOTw[it-1];
5625  for (i = 1; i <= fNpar; ++i) {
5626  fX[i-1] = fXt[i-1] + fac*fMNOTxdev[i-1];
5627  }
5628  if (fISW[4] > 1) {
5629  Printf(" PARAMETER %4d SET TO%11.3e + %10.3e = %12.3e",ilax,ut,delu,fU[ilax-1]);
5630  }
5631 //*-*- loop to hit AMIN+UP
5632  fKe1cr = ilax;
5633  fKe2cr = 0;
5634  fXmidcr = fU[ilax-1];
5635  fXdircr = delu;
5636 
5637  fAmin = abest;
5638  fNfcnmx = nlimit - fNfcn;
5639  mncros(aopt, iercr);
5640  if (abest - fAmin > fUp*.01) goto L650;
5641  if (iercr == 1) goto L440;
5642  if (iercr == 2) goto L450;
5643  if (iercr == 3) goto L460;
5644 //*-*- . error successfully calculated
5645  eros = fXmidcr - ut + aopt*fXdircr;
5646  if (fISW[4] > 1) {
5647  Printf(" THE %4sTIVE MINOS ERROR OF PARAMETER %3d %10s, IS %12.4e"
5648  ,(const char*)csig,ilax
5649  ,(const char*)fCpnam[ilax-1],eros);
5650  }
5651  goto L480;
5652 //*-*- . . . . . . . . failure returns
5653 L440:
5654  if (fISW[4] >= 1) {
5655  Printf(" THE %4sTIVE MINOS ERROR OF PARAMETER %3d, %s EXCEEDS ITS LIMIT."
5656  ,(const char*)csig,ilax
5657  ,(const char*)fCpnam[ilax-1]);
5658  }
5659  eros = fUndefi;
5660  goto L480;
5661 L450:
5662  if (fISW[4] >= 1) {
5663  Printf(" THE %4sTIVE MINOS ERROR %4d REQUIRES MORE THAN %5d FUNCTION CALLS."
5664  ,(const char*)csig,ilax,nfmxin);
5665  }
5666  eros = 0;
5667  goto L480;
5668 L460:
5669  if (fISW[4] >= 1) {
5670  Printf(" %4sTIVE MINOS ERROR NOT CALCULATED FOR PARAMETER %d"
5671  ,(const char*)csig,ilax);
5672  }
5673  eros = 0;
5674 
5675 L480:
5676  if (fISW[4] > 1) {
5677  Printf(" **************************************************************************");
5678  }
5679  if (sig < 0) {
5680  fErn[it-1] = eros;
5681  if (ilax2 > 0 && ilax2 <= fNu) val2mi = fU[ilax2-1];
5682  } else {
5683  fErp[it-1] = eros;
5684  if (ilax2 > 0 && ilax2 <= fNu) val2pl = fU[ilax2-1];
5685  }
5686  }
5687 //*-*- . . parameter finished. reset v
5688 //*-*- normal termination */
5689  fItaur = 1;
5690  mnfree(1);
5691  i__1 = mpar*(mpar + 1) / 2;
5692  for (j = 1; j <= i__1; ++j) { fVhmat[j-1] = fVthmat[j-1]; }
5693  for (i = 1; i <= mpar; ++i) {
5694  fWerr[i-1] = fMNOTw[i-1];
5695  fGlobcc[i-1] = fMNOTgcc[i-1];
5696  fX[i-1] = fXt[i-1];
5697  }
5698  mninex(fX);
5699  fEDM = sigsav;
5700  fAmin = abest;
5701  fISW[1] = isw2;
5702  fISW[3] = isw4;
5703  fDcovar = dc;
5704  goto L700;
5705 //*-*- new minimum
5706 L650:
5707  fLnewmn = kTRUE;
5708  fISW[1] = 0;
5709  fDcovar = 1;
5710  fISW[3] = 0;
5711  sav = fU[ilax-1];
5712  fItaur = 1;
5713  mnfree(1);
5714  fU[ilax-1] = sav;
5715  mnexin(fX);
5716  fEDM = fBigedm;
5717 //*-*- in any case
5718 L700:
5719  fItaur = 0;
5720  fNfcnmx = nfmxin;
5721  fIstrat = istrav;
5722 } /* mnmnot_ */
5723 
5724 ////////////////////////////////////////////////////////////////////////////////
5725 ///*-*-*-*-*-*-*-*-*Implements one parameter definition*-*-*-*-*-*-*-*-*-*-*-*
5726 ///*-* ===================================
5727 ///*-* Called from MNPARS and user-callable
5728 ///*-* Implements one parameter definition, that is:
5729 ///*-* K (external) parameter number
5730 ///*-* CNAMK parameter name
5731 ///*-* UK starting value
5732 ///*-* WK starting step size or uncertainty
5733 ///*-* A, B lower and upper physical parameter limits
5734 ///*-* and sets up (updates) the parameter lists.
5735 ///*-* Output: IERFLG=0 if no problems
5736 ///*-* >0 if MNPARM unable to implement definition
5737 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
5738 
5739 void TMinuit::mnparm(Int_t k1, TString cnamj, Double_t uk, Double_t wk, Double_t a, Double_t b, Int_t &ierflg)
5740 {
5741  /* Local variables */
5742  Double_t vplu, a_small, gsmin, pinti, vminu, danger, sav, sav2;
5743  Int_t ierr, kint, in, ix, ktofix, lastin, kinfix, nvl;
5744  TString cnamk, chbufi;
5745 
5746  Int_t k = k1+1;
5747  cnamk = cnamj;
5748  kint = fNpar;
5749  if (k < 1 || k > fMaxext) {
5750 //*-*- parameter number exceeds allowed maximum value
5751  Printf(" MINUIT USER ERROR. PARAMETER NUMBER IS %3d ALLOWED RANGE IS ONE TO %4d",k,fMaxext);
5752  goto L800;
5753  }
5754 //*-*- normal parameter request
5755  ktofix = 0;
5756  if (fNvarl[k-1] < 0) goto L50;
5757 //*-*- previously defined parameter is being redefined
5758 //*-*- find if parameter was fixed
5759  for (ix = 1; ix <= fNpfix; ++ix) {
5760  if (fIpfix[ix-1] == k) ktofix = k;
5761  }
5762  if (ktofix > 0) {
5763  mnwarn("W", "PARAM DEF", "REDEFINING A FIXED PARAMETER.");
5764  if (kint >= fMaxint) {
5765  Printf(" CANNOT RELEASE. MAX NPAR EXCEEDED.");
5766  goto L800;
5767  }
5768  mnfree(-k);
5769  }
5770 //*-*- if redefining previously variable parameter
5771  if (fNiofex[k-1] > 0) kint = fNpar - 1;
5772 L50:
5773 
5774 //*-*- . . .print heading
5775  if (fLphead && fISW[4] >= 0) {
5776  Printf(" PARAMETER DEFINITIONS:");
5777  Printf(" NO. NAME VALUE STEP SIZE LIMITS");
5778  fLphead = kFALSE;
5779  }
5780  if (wk > 0) goto L122;
5781 //*-*- . . .constant parameter . . . .
5782  if (fISW[4] >= 0) {
5783  Printf(" %5d %-10s %13.5e constant",k,(const char*)cnamk,uk);
5784  }
5785  nvl = 0;
5786  goto L200;
5787 L122:
5788  if (a == 0 && b == 0) {
5789 //*-*- variable parameter without limits
5790  nvl = 1;
5791  if (fISW[4] >= 0) {
5792  Printf(" %5d %-10s %13.5e%13.5e no limits",k,(const char*)cnamk,uk,wk);
5793  }
5794  } else {
5795 //*-*- variable parameter with limits
5796  nvl = 4;
5797  fLnolim = kFALSE;
5798  if (fISW[4] >= 0) {
5799  Printf(" %5d %-10s %13.5e%13.5e %13.5e%13.5e",k,(const char*)cnamk,uk,wk,a,b);
5800  }
5801  }
5802 //*-*- . . request for another variable parameter
5803  ++kint;
5804  if (kint > fMaxint) {
5805  Printf(" MINUIT USER ERROR. TOO MANY VARIABLE PARAMETERS.");
5806  goto L800;
5807  }
5808  if (nvl == 1) goto L200;
5809  if (a == b) {
5810  Printf(" USER ERROR IN MINUIT PARAMETER");
5811  Printf(" DEFINITION");
5812  Printf(" UPPER AND LOWER LIMITS EQUAL.");
5813  goto L800;
5814  }
5815  if (b < a) {
5816  sav = b;
5817  b = a;
5818  a = sav;
5819  mnwarn("W", "PARAM DEF", "PARAMETER LIMITS WERE REVERSED.");
5820  if (fLwarn) fLphead = kTRUE;
5821  }
5822  if (b - a > 1e7) {
5823  mnwarn("W", "PARAM DEF", TString::Format("LIMITS ON PARAM%d TOO FAR APART.",k));
5824  if (fLwarn) fLphead = kTRUE;
5825  }
5826  danger = (b - uk)*(uk - a);
5827  if (danger < 0) {
5828  mnwarn("W", "PARAM DEF", "STARTING VALUE OUTSIDE LIMITS.");
5829  }
5830  if (danger == 0) {
5831  mnwarn("W", "PARAM DEF", "STARTING VALUE IS AT LIMIT.");
5832  }
5833 L200:
5834 //*-*- . . . input OK, set values, arrange lists,
5835 //*-*- calculate step sizes GSTEP, DIRIN
5836  fCfrom = "PARAMETR";
5837  fNfcnfr = fNfcn;
5838  fCstatu = "NEW VALUES";
5839  fNu = TMath::Max(fNu,k);
5840  fCpnam[k-1] = cnamk;
5841  fU[k-1] = uk;
5842  fAlim[k-1] = a;
5843  fBlim[k-1] = b;
5844  fNvarl[k-1] = nvl;
5845  mnrset(1);
5846 //*-*- K is external number of new parameter
5847 //*-*- LASTIN is the number of var. params with ext. param. no.< K
5848  lastin = 0;
5849  for (ix = 1; ix <= k-1; ++ix) { if (fNiofex[ix-1] > 0) ++lastin; }
5850 //*-*- KINT is new number of variable params, NPAR is old
5851  if (kint == fNpar) goto L280;
5852  if (kint > fNpar) {
5853 //*-*- insert new variable parameter in list
5854  for (in = fNpar; in >= lastin + 1; --in) {
5855  ix = fNexofi[in-1];
5856  fNiofex[ix-1] = in + 1;
5857  fNexofi[in] = ix;
5858  fX[in] = fX[in-1];
5859  fXt[in] = fXt[in-1];
5860  fDirin[in] = fDirin[in-1];
5861  fG2[in] = fG2[in-1];
5862  fGstep[in] = fGstep[in-1];
5863  fWerr[in] = fWerr[in-1];
5864  fGrd[in] = fGrd[in-1];
5865  }
5866  } else {
5867 //*-*- remove variable parameter from list
5868  for (in = lastin + 1; in <= kint; ++in) {
5869  ix = fNexofi[in];
5870  fNiofex[ix-1] = in;
5871  fNexofi[in-1] = ix;
5872  fX[in-1] = fX[in];
5873  fXt[in-1] = fXt[in];
5874  fDirin[in-1] = fDirin[in];
5875  fG2[in-1] = fG2[in];
5876  fGstep[in-1] = fGstep[in];
5877  fWerr[in-1] = fWerr[in];
5878  fGrd[in-1] = fGrd[in];
5879  }
5880  }
5881 L280:
5882  ix = k;
5883  fNiofex[ix-1] = 0;
5884  fNpar = kint;
5885 //*-*- lists are now arranged . . . .
5886  if (nvl > 0) {
5887  in = lastin + 1;
5888  fNexofi[in-1] = ix;
5889  fNiofex[ix-1] = in;
5890  sav = fU[ix-1];
5891  mnpint(sav, ix-1, pinti);
5892  fX[in-1] = pinti;
5893  fXt[in-1] = fX[in-1];
5894  fWerr[in-1] = wk;
5895  sav2 = sav + wk;
5896  mnpint(sav2, ix-1, pinti);
5897  vplu = pinti - fX[in-1];
5898  sav2 = sav - wk;
5899  mnpint(sav2, ix-1, pinti);
5900  vminu = pinti - fX[in-1];
5901  fDirin[in-1] = (TMath::Abs(vplu) + TMath::Abs(vminu))*.5;
5902  fG2[in-1] = fUp*2 / (fDirin[in-1]*fDirin[in-1]);
5903  gsmin = fEpsma2*8*TMath::Abs(fX[in-1]);
5904  fGstep[in-1] = TMath::Max(gsmin,fDirin[in-1]*.1);
5905  if (fAmin != fUndefi) {
5906  a_small = TMath::Sqrt(fEpsma2*(fAmin + fUp) / fUp);
5907  fGstep[in-1] = TMath::Max(gsmin,a_small*fDirin[in-1]);
5908  }
5909  fGrd[in-1] = fG2[in-1]*fDirin[in-1];
5910 //*-*- if parameter has limits
5911  if (fNvarl[k-1] > 1) {
5912  if (fGstep[in-1] > .5) fGstep[in-1] = .5;
5913  fGstep[in-1] = -fGstep[in-1];
5914  }
5915  }
5916  if (ktofix > 0) {
5917  ierr = 0;
5918  kinfix = fNiofex[ktofix-1];
5919  if (kinfix > 0) mnfixp(kinfix-1, ierr);
5920  if (ierr > 0) goto L800;
5921  }
5922  ierflg = 0;
5923  return;
5924 //*-*- error on input, unable to implement request . . . .
5925 L800:
5926  ierflg = 1;
5927 } /* mnparm_ */
5928 
5929 ////////////////////////////////////////////////////////////////////////////////
5930 ///*-*-*-*-*-*-*-*Implements one parameter definition*-*-*-*-*-*-*-*-*-*-*-*-*
5931 ///*-* =========== =======================
5932 ///*-* Called from MNREAD and user-callable
5933 ///*-* Implements one parameter definition, that is:
5934 ///*-* parses the string CRDBUF and calls MNPARM
5935 ///*-*
5936 ///*-* output conditions:
5937 ///*-* ICONDN = 0 all OK
5938 ///*-* ICONDN = 1 error, attempt to define parameter is ignored
5939 ///*-* ICONDN = 2 end of parameter definitions
5940 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
5941 
5942 void TMinuit::mnpars(TString &crdbuf, Int_t &icondn)
5943 {
5944  /* Local variables */
5945  Double_t a=0, b=0, fk=0, uk=0, wk=0, xk=0;
5946  Int_t ierr, kapo1, kapo2;
5947  Int_t k, llist, ibegin, lenbuf, istart, lnc, icy;
5948  TString cnamk, comand, celmnt, ctemp;
5949  char stmp[128];
5950 
5951  lenbuf = strlen((const char*)crdbuf);
5952 //*-*- find out whether fixed or free-field format
5953  kapo1 = strspn((const char*)crdbuf, "'");
5954  if (kapo1 == 0) goto L150;
5955  kapo2 = strspn((const char*)crdbuf + kapo1, "'");
5956  if (kapo2 == 0) goto L150;
5957 //*-*- new (free-field) format
5958  kapo2 += kapo1;
5959 //*-*- skip leading blanks if any
5960  for (istart = 1; istart <= kapo1-1; ++istart) {
5961  if (crdbuf(istart-1,1) != ' ') goto L120;
5962  }
5963  goto L210;
5964 L120:
5965 //*-*- parameter number integer
5966  celmnt = crdbuf(istart-1, kapo1-istart);
5967  if (scanf((const char*)celmnt,&fk)) {;}
5968  k = Int_t(fk);
5969  if (k <= 0) goto L210;
5970  cnamk = "PARAM " + celmnt;
5971  if (kapo2 - kapo1 > 1) {
5972  cnamk = crdbuf(kapo1, kapo2-1-kapo1);
5973  }
5974 //*-* special handling if comma or blanks and a comma follow 'name'
5975  for (icy = kapo2 + 1; icy <= lenbuf; ++icy) {
5976  if (crdbuf(icy-1,1) == ',') goto L139;
5977  if (crdbuf(icy-1,1) != ' ') goto L140;
5978  }
5979  uk = 0;
5980  wk = 0;
5981  a = 0;
5982  b = 0;
5983  goto L170;
5984 L139:
5985  ++icy;
5986 L140:
5987  ibegin = icy;
5988  ctemp = crdbuf(ibegin-1,lenbuf-ibegin);
5989  mncrck(ctemp, 20, comand, lnc, fMaxpar, fPARSplist, llist, ierr, fIsyswr);
5990  if (ierr > 0) goto L180;
5991  uk = fPARSplist[0];
5992  wk = 0;
5993  if (llist >= 2) wk = fPARSplist[1];
5994  a = 0;
5995  if (llist >= 3) a = fPARSplist[2];
5996  b = 0;
5997  if (llist >= 4) b = fPARSplist[3];
5998  goto L170;
5999 //*-*- old (fixed-field) format
6000 L150:
6001  if (scanf((const char*)crdbuf,&xk,stmp,&uk,&wk,&a,&b)) {;}
6002  cnamk = stmp;
6003  k = Int_t(xk);
6004  if (k == 0) goto L210;
6005 //*-*- parameter format cracked, implement parameter definition
6006 L170:
6007  mnparm(k-1, cnamk, uk, wk, a, b, ierr);
6008  icondn = ierr;
6009  return;
6010 //*-*- format or other error
6011 L180:
6012  icondn = 1;
6013  return;
6014 //*-*- end of data
6015 L210:
6016  icondn = 2;
6017 } /* mnpars_ */
6018 
6019 ////////////////////////////////////////////////////////////////////////////////
6020 ///*-*-*-*-*-*-*-*-*-*To fit a parabola to npar2p points*-*-*-*-*-*-*-*-*-*-*
6021 ///*-* ==================================
6022 ///*-* npar2p no. of points
6023 ///*-* parx2p(i) x value of point i
6024 ///*-* pary2p(i) y value of point i
6025 ///*-*
6026 ///*-* coef2p(1...3) coefficients of the fitted parabola
6027 ///*-* y=coef2p(1) + coef2p(2)*x + coef2p(3)*x**2
6028 ///*-* sdev2p= variance
6029 ///*-* method : chi**2 = min equation solved explicitly
6030 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6031 
6032 void TMinuit::mnpfit(Double_t *parx2p, Double_t *pary2p, Int_t npar2p, Double_t *coef2p, Double_t &sdev2p)
6033 {
6034  /* Local variables */
6035  Double_t a, f, s, t, y, s2, x2, x3, x4, y2, cz[3], xm, xy, x2y;
6036  x2 = x3 = 0;
6037  Int_t i;
6038 
6039  /* Parameter adjustments */
6040  --coef2p;
6041  --pary2p;
6042  --parx2p;
6043 
6044  /* Function Body */
6045  for (i = 1; i <= 3; ++i) { cz[i-1] = 0; }
6046  sdev2p = 0;
6047  if (npar2p < 3) goto L10;
6048  f = (Double_t) (npar2p);
6049 //*-* --- center x values for reasons of machine precision
6050  xm = 0;
6051  for (i = 1; i <= npar2p; ++i) { xm += parx2p[i]; }
6052  xm /= f;
6053  x2 = 0;
6054  x3 = 0;
6055  x4 = 0;
6056  y = 0;
6057  y2 = 0;
6058  xy = 0;
6059  x2y = 0;
6060  for (i = 1; i <= npar2p; ++i) {
6061  s = parx2p[i] - xm;
6062  t = pary2p[i];
6063  s2 = s*s;
6064  x2 += s2;
6065  x3 += s*s2;
6066  x4 += s2*s2;
6067  y += t;
6068  y2 += t*t;
6069  xy += s*t;
6070  x2y += s2*t;
6071  }
6072  a = (f*x4 - x2*x2)*x2 - f*(x3*x3);
6073  if (a == 0) goto L10;
6074  cz[2] = (x2*(f*x2y - x2*y) - f*x3*xy) / a;
6075  cz[1] = (xy - x3*cz[2]) / x2;
6076  cz[0] = (y - x2*cz[2]) / f;
6077  if (npar2p == 3) goto L6;
6078  sdev2p = y2 - (cz[0]*y + cz[1]*xy + cz[2]*x2y);
6079  if (sdev2p < 0) sdev2p = 0;
6080  sdev2p /= f - 3;
6081 L6:
6082  cz[0] += xm*(xm*cz[2] - cz[1]);
6083  cz[1] -= xm*2*cz[2];
6084 L10:
6085  for (i = 1; i <= 3; ++i) { coef2p[i] = cz[i-1]; }
6086 } /* mnpfit_ */
6087 
6088 ////////////////////////////////////////////////////////////////////////////////
6089 ///*-*-*-*-*-*-*Calculates the internal parameter value PINTI*-*-*-*-*-*-*-*
6090 ///*-* =============================================
6091 ///*-* corresponding to the external value PEXTI for parameter I.
6092 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6093 
6094 void TMinuit::mnpint(Double_t &pexti, Int_t i1, Double_t &pinti)
6095 {
6096  /* Local variables */
6097  Double_t a, alimi, blimi, yy, yy2;
6098  Int_t igo;
6099  TString chbuf2, chbufi;
6100 
6101  Int_t i = i1+1;
6102  pinti = pexti;
6103  igo = fNvarl[i-1];
6104  if (igo == 4) {
6105 //*-* -- there are two limits
6106  alimi = fAlim[i-1];
6107  blimi = fBlim[i-1];
6108  yy = (pexti - alimi)*2 / (blimi - alimi) - 1;
6109  yy2 = yy*yy;
6110  if (yy2 >= 1 - fEpsma2) {
6111  if (yy < 0) {
6112  a = fVlimlo;
6113  chbuf2 = " IS AT ITS LOWER ALLOWED LIMIT.";
6114  } else {
6115  a = fVlimhi;
6116  chbuf2 = " IS AT ITS UPPER ALLOWED LIMIT.";
6117  }
6118  pinti = a;
6119  pexti = alimi + (blimi - alimi)*.5*(TMath::Sin(a) + 1);
6120  fLimset = kTRUE;
6121  if (yy2 > 1) chbuf2 = " BROUGHT BACK INSIDE LIMITS.";
6122  mnwarn("W", fCfrom, TString::Format("VARIABLE%d%s",i,chbuf2.Data()));
6123  } else {
6124  pinti = TMath::ASin(yy);
6125  }
6126  }
6127 } /* mnpint_ */
6128 
6129 ////////////////////////////////////////////////////////////////////////////////
6130 ///*-*-*-*Plots points in array xypt onto one page with labelled axes*-*-*-*-*
6131 ///*-* ===========================================================
6132 ///*-* NXYPT is the number of points to be plotted
6133 ///*-* XPT(I) = x-coord. of ith point
6134 ///*-* YPT(I) = y-coord. of ith point
6135 ///*-* CHPT(I) = character to be plotted at this position
6136 ///*-* the input point arrays XPT, YPT, CHPT are destroyed.
6137 ///*-*
6138 ///*-*
6139 ///*-* If fGraphicsmode is true (default), a TGraph object is produced
6140 ///*-* via the Plug-in handler. To get the plot, you can do:
6141 ///*-* TGraph *gr = (TGraph*)gMinuit->GetPlot();
6142 ///*-* gr->Draw("al");
6143 ///*-*
6144 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6145 
6146 void TMinuit::mnplot(Double_t *xpt, Double_t *ypt, char *chpt, Int_t nxypt, Int_t npagwd, Int_t npagln)
6147 {
6148 
6149  if (fGraphicsMode) {
6150  TPluginHandler *h;
6151  if ((h = gROOT->GetPluginManager()->FindHandler("TMinuitGraph"))) {
6152  //remove the first two points
6153  if (h->LoadPlugin() != -1)
6154  fPlot = (TObject*)h->ExecPlugin(3,nxypt-2,&xpt[2],&ypt[2]);
6155  }
6156  return;
6157  }
6158 
6159  static TString cdot = ".";
6160  static TString cslash = "/";
6161 
6162  /* Local variables */
6163  Double_t xmin, ymin, xmax, ymax, savx, savy, yprt;
6164  Double_t bwidx, bwidy, xbest, ybest, ax, ay, bx, by;
6165  Double_t xvalus[12], any, dxx, dyy;
6166  Int_t iten, i, j, k, maxnx, maxny, iquit, ni, linodd;
6167  Int_t nxbest, nybest, km1, ibk, isp1, nx, ny, ks, ix;
6168  TString chmess, ctemp;
6169  Bool_t overpr;
6170  char cline[120];
6171  char chsav, chbest;
6172 
6173  /* Function Body */
6174  //*-* Computing MIN
6175  maxnx = TMath::Min(npagwd-20,100);
6176  if (maxnx < 10) maxnx = 10;
6177  maxny = npagln;
6178  if (maxny < 10) maxny = 10;
6179  if (nxypt <= 1) return;
6180  xbest = xpt[0];
6181  ybest = ypt[0];
6182  chbest = chpt[0];
6183  //*-*- order the points by decreasing y
6184  km1 = nxypt - 1;
6185  for (i = 1; i <= km1; ++i) {
6186  iquit = 0;
6187  ni = nxypt - i;
6188  for (j = 1; j <= ni; ++j) {
6189  if (ypt[j-1] > ypt[j]) continue;
6190  savx = xpt[j-1];
6191  xpt[j-1] = xpt[j];
6192  xpt[j] = savx;
6193  savy = ypt[j-1];
6194  ypt[j-1] = ypt[j];
6195  ypt[j] = savy;
6196  chsav = chpt[j-1];
6197  chpt[j-1]= chpt[j];
6198  chpt[j] = chsav;
6199  iquit = 1;
6200  }
6201  if (iquit == 0) break;
6202  }
6203  //*-*- find extreme values
6204  xmax = xpt[0];
6205  xmin = xmax;
6206  for (i = 1; i <= nxypt; ++i) {
6207  if (xpt[i-1] > xmax) xmax = xpt[i-1];
6208  if (xpt[i-1] < xmin) xmin = xpt[i-1];
6209  }
6210  dxx = (xmax - xmin)*.001;
6211  xmax += dxx;
6212  xmin -= dxx;
6213  mnbins(xmin, xmax, maxnx, xmin, xmax, nx, bwidx);
6214  ymax = ypt[0];
6215  ymin = ypt[nxypt-1];
6216  if (ymax == ymin) ymax = ymin + 1;
6217  dyy = (ymax - ymin)*.001;
6218  ymax += dyy;
6219  ymin -= dyy;
6220  mnbins(ymin, ymax, maxny, ymin, ymax, ny, bwidy);
6221  any = (Double_t) ny;
6222  //*-*- if first point is blank, it is an 'origin'
6223  if (chbest == ' ') goto L50;
6224  xbest = (xmax + xmin)*.5;
6225  ybest = (ymax + ymin)*.5;
6226 L50:
6227  //*-*- find scale constants
6228  ax = 1 / bwidx;
6229  ay = 1 / bwidy;
6230  bx = -ax*xmin + 2;
6231  by = -ay*ymin - 2;
6232  //*-*- convert points to grid positions
6233  for (i = 1; i <= nxypt; ++i) {
6234  xpt[i-1] = ax*xpt[i-1] + bx;
6235  ypt[i-1] = any - ay*ypt[i-1] - by;
6236  }
6237  nxbest = Int_t((ax*xbest + bx));
6238  nybest = Int_t((any - ay*ybest - by));
6239  //*-*- print the points
6240  ny += 2;
6241  nx += 2;
6242  isp1 = 1;
6243  linodd = 1;
6244  overpr = kFALSE;
6245  for (i = 1; i <= ny; ++i) {
6246  for (ibk = 1; ibk <= nx; ++ibk) { cline[ibk-1] = ' '; }
6247  cline[nx] = '\0';
6248  cline[nx+1] = '\0';
6249  cline[0] = '.';
6250  // not needed - but to avoid a wrongly reported compiler warning (see ROOT-6496)
6251  if (nx>0) cline[nx-1] = '.';
6252  cline[nxbest-1] = '.';
6253  if (i != 1 && i != nybest && i != ny) goto L320;
6254  for (j = 1; j <= nx; ++j) { cline[j-1] = '.'; }
6255 L320:
6256  yprt = ymax - Double_t(i-1)*bwidy;
6257  if (isp1 > nxypt) goto L350;
6258  //*-*- find the points to be plotted on this line
6259  for (k = isp1; k <= nxypt; ++k) {
6260  ks = Int_t(ypt[k-1]);
6261  if (ks > i) goto L345;
6262  ix = Int_t(xpt[k-1]);
6263  if (cline[ix-1] == '.') goto L340;
6264  if (cline[ix-1] == ' ') goto L340;
6265  if (cline[ix-1] == chpt[k-1]) continue;
6266  overpr = kTRUE;
6267  //*-*- OVERPR is true if one or more positions contains more than
6268  //*-*- one point
6269  cline[ix-1] = '&';
6270  continue;
6271 L340:
6272  cline[ix-1] = chpt[k-1];
6273  }
6274  isp1 = nxypt + 1;
6275  goto L350;
6276 L345:
6277  isp1 = k;
6278 L350:
6279  if (linodd == 1 || i == ny) goto L380;
6280  linodd = 1;
6281  ctemp = cline;
6282  Printf(" %s",(const char*)ctemp);
6283  goto L400;
6284 L380:
6285  ctemp = cline;
6286  Printf(" %14.7g ..%s",yprt,(const char*)ctemp);
6287  linodd = 0;
6288 L400:
6289  ;
6290  }
6291  //*-*- print labels on x-axis every ten columns
6292  for (ibk = 1; ibk <= nx; ++ibk) {
6293  cline[ibk-1] = ' ';
6294  if (ibk % 10 == 1) cline[ibk-1] = '/';
6295  }
6296  Printf(" %s",cline);
6297 
6298  for (ibk = 1; ibk <= 12; ++ibk) {
6299  xvalus[ibk-1] = xmin + Double_t(ibk-1)*10*bwidx;
6300  }
6301  iten = (nx + 9) / 10;
6302  for (ibk = 1; ibk <= iten && ibk <= 12; ++ibk) {
6303  snprintf(cline + (ibk-1)*10, 11-(ibk == 12), "%#9.3g ", xvalus[ibk-1]);
6304  }
6305  Printf(" %s", cline);
6306  chmess = " ";
6307  if (overpr) chmess = " Overprint character is &";
6308  Printf(" ONE COLUMN=%13.7g%s",bwidx,(const char*)chmess);
6309 } /* mnplot_ */
6310 
6311 ////////////////////////////////////////////////////////////////////////////////
6312 ///*-*-*-*Provides the user with information concerning the current status*-*-*
6313 ///*-* ================================================================
6314 ///*-* of parameter number IUEXT. Namely, it returns:
6315 ///*-* CHNAM: the name of the parameter
6316 ///*-* VAL: the current (external) value of the parameter
6317 ///*-* ERR: the current estimate of the parameter uncertainty
6318 ///*-* XLOLIM: the lower bound (or zero if no limits)
6319 ///*-* XUPLIM: the upper bound (or zero if no limits)
6320 ///*-* IUINT: the internal parameter number (or zero if not variable,
6321 ///*-* or negative if undefined).
6322 ///*-* Note also: If IUEXT is negative, then it is -internal parameter
6323 ///*-* number, and IUINT is returned as the EXTERNAL number.
6324 ///*-* Except for IUINT, this is exactly the inverse of MNPARM
6325 ///*-* User-called
6326 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6327 
6328 void TMinuit::mnpout(Int_t iuext1, TString &chnam, Double_t &val, Double_t &err, Double_t &xlolim, Double_t &xuplim, Int_t &iuint) const
6329 {
6330  /* Local variables */
6331  Int_t iint, iext, nvl;
6332 
6333  Int_t iuext = iuext1 + 1;
6334  xlolim = 0;
6335  xuplim = 0;
6336  err = 0;
6337  if (iuext == 0) goto L100;
6338  if (iuext < 0) {
6339 //*-*- internal parameter number specified
6340  iint = -(iuext);
6341  if (iint > fNpar) goto L100;
6342  iext = fNexofi[iint-1];
6343  iuint = iext;
6344  } else {
6345 //*-*- external parameter number specified
6346  iext = iuext;
6347  if (iext > fNu) goto L100;
6348  iint = fNiofex[iext-1];
6349  iuint = iint;
6350  }
6351 //*-*- in both cases
6352  nvl = fNvarl[iext-1];
6353  if (nvl < 0) goto L100;
6354  chnam = fCpnam[iext-1];
6355  val = fU[iext-1];
6356  if (iint > 0) err = fWerr[iint-1];
6357  if (nvl == 4) {
6358  xlolim = fAlim[iext-1];
6359  xuplim = fBlim[iext-1];
6360  }
6361  return;
6362 //*-*- parameter is undefined
6363 L100:
6364  iuint = -1;
6365  chnam = "undefined";
6366  val = 0;
6367 } /* mnpout_ */
6368 
6369 ////////////////////////////////////////////////////////////////////////////////
6370 ///*-*-*-*Prints the values of the parameters at the time of the call*-*-*-*-*
6371 ///*-* ===========================================================
6372 ///*-* also prints other relevant information such as function value,
6373 ///*-* estimated distance to minimum, parameter errors, step sizes.
6374 ///*-*
6375 ///*-* According to the value of IKODE, the printout is:/
6376 ///*-* IKODE=INKODE= 0 only info about function value
6377 ///*-* 1 parameter values, errors, limits
6378 ///*-* 2 values, errors, step sizes, internal values
6379 ///*-* 3 values, errors, step sizes, first derivs.
6380 ///*-* 4 values, parabolic errors, MINOS errors
6381 ///*-* when INKODE=5, MNPRIN chooses IKODE=1,2, or 3, according to fISW[1]
6382 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6383 
6384 void TMinuit::mnprin(Int_t inkode, Double_t fval)
6385 {
6386  /* Initialized data */
6387 
6388  static TString cblank = " ";
6389  static TString cnambf = " ";
6390 
6391  /* Local variables */
6392  Double_t dcmax, x1, x2, x3, dc;
6393  x2 = x3 = 0;
6394  Int_t nadd, i, k, l, m, ikode, ic, nc, ntrail, lbl;
6395  TString chedm;
6396  TString colhdl[6], colhdu[6], cx2, cx3, cheval;
6397 
6398  if (fNu == 0) {
6399  Printf(" THERE ARE CURRENTLY NO PARAMETERS DEFINED");
6400  return;
6401  }
6402 //*-*- get value of IKODE based in INKODE, fISW[1]
6403  ikode = inkode;
6404  if (inkode == 5) {
6405  ikode = fISW[1] + 1;
6406  if (ikode > 3) ikode = 3;
6407  }
6408 //*-*- set 'default' column headings
6409  for (k = 1; k <= 6; ++k) {
6410  colhdu[k-1] = "UNDEFINED";
6411  colhdl[k-1] = "COLUMN HEAD";
6412  }
6413 //*-*- print title if Minos errors, and title exists.
6414  if (ikode == 4 && fCtitl != fCundef) {
6415  Printf(" MINUIT TASK: %s",(const char*)fCtitl);
6416  }
6417 //*-*- report function value and status
6418  if (fval == fUndefi) cheval = " unknown ";
6419  else cheval.Form("%g",fval);
6420 
6421  if (fEDM == fBigedm) chedm = " unknown ";
6422  else chedm.Form("%g",fEDM);
6423 
6424  nc = fNfcn - fNfcnfr;
6425  Printf(" FCN=%s FROM %8s STATUS=%10s %6d CALLS %9d TOTAL"
6426  ,(const char*)cheval
6427  ,(const char*)fCfrom
6428  ,(const char*)fCstatu,nc,fNfcn);
6429  m = fISW[1];
6430  if (m == 0 || m == 2 || fDcovar == 0) {
6431  Printf(" EDM=%s STRATEGY=%2d %s"
6432  ,(const char*)chedm,fIstrat
6433  ,(const char*)fCovmes[m]);
6434  } else {
6435  dcmax = 1;
6436  dc = TMath::Min(fDcovar,dcmax)*100;
6437  Printf(" EDM=%s STRATEGY=%2d ERROR MATRIX UNCERTAINTY %5.1f per cent"
6438  ,(const char*)chedm,fIstrat,dc);
6439  }
6440 
6441  if (ikode == 0) return;
6442 //*-*- find longest name (for Rene!)
6443  ntrail = 10;
6444  for (i = 1; i <= fNu; ++i) {
6445  if (fNvarl[i-1] < 0) continue;
6446  for (ic = 10; ic >= 1; --ic) {
6447  if (fCpnam[i-1](ic-1,1) != " ") goto L16;
6448  }
6449  ic = 1;
6450 L16:
6451  lbl = 10 - ic;
6452  if (lbl < ntrail) ntrail = lbl;
6453  }
6454  nadd = ntrail / 2 + 1;
6455  if (ikode == 1) {
6456  colhdu[0] = " ";
6457  colhdl[0] = " ERROR ";
6458  colhdu[1] = " PHYSICAL";
6459  colhdu[2] = " LIMITS ";
6460  colhdl[1] = " NEGATIVE ";
6461  colhdl[2] = " POSITIVE ";
6462  }
6463  if (ikode == 2) {
6464  colhdu[0] = " ";
6465  colhdl[0] = " ERROR ";
6466  colhdu[1] = " INTERNAL ";
6467  colhdl[1] = " STEP SIZE ";
6468  colhdu[2] = " INTERNAL ";
6469  colhdl[2] = " VALUE ";
6470  }
6471  if (ikode == 3) {
6472  colhdu[0] = " ";
6473  colhdl[0] = " ERROR ";
6474  colhdu[1] = " STEP ";
6475  colhdl[1] = " SIZE ";
6476  colhdu[2] = " FIRST ";
6477  colhdl[2] = " DERIVATIVE ";
6478  }
6479  if (ikode == 4) {
6480  colhdu[0] = " PARABOLIC ";
6481  colhdl[0] = " ERROR ";
6482  colhdu[1] = " MINOS ";
6483  colhdu[2] = "ERRORS ";
6484  colhdl[1] = " NEGATIVE ";
6485  colhdl[2] = " POSITIVE ";
6486  }
6487 
6488  if (ikode != 4) {
6489  if (fISW[1] < 3) colhdu[0] = " APPROXIMATE ";
6490  if (fISW[1] < 1) colhdu[0] = " CURRENT GUESS";
6491  }
6492  Printf(" EXT PARAMETER %-14s%-14s%-14s",(const char*)colhdu[0]
6493  ,(const char*)colhdu[1]
6494  ,(const char*)colhdu[2]);
6495  Printf(" NO. NAME VALUE %-14s%-14s%-14s",(const char*)colhdl[0]
6496  ,(const char*)colhdl[1]
6497  ,(const char*)colhdl[2]);
6498 //*-*- . . . loop over parameters . .
6499  for (i = 1; i <= fNu; ++i) {
6500  if (fNvarl[i-1] < 0) continue;
6501  l = fNiofex[i-1];
6502  cnambf = cblank(0,nadd) + fCpnam[i-1];
6503  if (l == 0) goto L55;
6504 //*-*- variable parameter.
6505  x1 = fWerr[l-1];
6506  cx2 = "PLEASE GET X..";
6507  cx3 = "PLEASE GET X..";
6508  if (ikode == 1) {
6509  if (fNvarl[i-1] <= 1) {
6510  Printf("%4d %-11s%14.5e%14.5e",i,(const char*)cnambf,fU[i-1],x1);
6511  continue;
6512  } else {
6513  x2 = fAlim[i-1];
6514  x3 = fBlim[i-1];
6515  }
6516  }
6517  if (ikode == 2) {
6518  x2 = fDirin[l-1];
6519  x3 = fX[l-1];
6520  }
6521  if (ikode == 3) {
6522  x2 = fDirin[l-1];
6523  x3 = fGrd[l-1];
6524  if (fNvarl[i-1] > 1 && TMath::Abs(TMath::Cos(fX[l-1])) < .001) {
6525  cx3 = "** at limit **";
6526  }
6527  }
6528  if (ikode == 4) {
6529  x2 = fErn[l-1];
6530  if (x2 == 0) cx2 = " ";
6531  if (x2 == fUndefi) cx2 = " at limit ";
6532  x3 = fErp[l-1];
6533  if (x3 == 0) cx3 = " ";
6534  if (x3 == fUndefi) cx3 = " at limit ";
6535  }
6536  if (cx2 == "PLEASE GET X..") cx2.Form("%14.5e",x2);
6537  if (cx3 == "PLEASE GET X..") cx3.Form("%14.5e",x3);
6538  Printf("%4d %-11s%14.5e%14.5e%-14s%-14s",i
6539  ,(const char*)cnambf,fU[i-1],x1
6540  ,(const char*)cx2,(const char*)cx3);
6541 
6542 //*-*- check if parameter is at limit
6543  if (fNvarl[i-1] <= 1 || ikode == 3) continue;
6544  if (TMath::Abs(TMath::Cos(fX[l-1])) < .001) {
6545  Printf(" WARNING - - ABOVE PARAMETER IS AT LIMIT.");
6546  }
6547  continue;
6548 
6549 //*-*- print constant or fixed parameter.
6550 L55:
6551  colhdu[0] = " constant ";
6552  if (fNvarl[i-1] > 0) colhdu[0] = " fixed ";
6553  if (fNvarl[i-1] == 4 && ikode == 1) {
6554  Printf("%4d %-11s%14.5e%-14s%14.5e%14.5e",i
6555  ,(const char*)cnambf,fU[i-1]
6556  ,(const char*)colhdu[0],fAlim[i-1],fBlim[i-1]);
6557  } else {
6558  Printf("%4d %-11s%14.5e%s",i
6559  ,(const char*)cnambf,fU[i-1],(const char*)colhdu[0]);
6560  }
6561  }
6562 
6563  if (fUp != fUpdflt) {
6564  Printf(" ERR DEF= %g",fUp);
6565  }
6566  return;
6567 } /* mnprin_ */
6568 
6569 ////////////////////////////////////////////////////////////////////////////////
6570 ///*-*-*-*-*-*Calculates the eigenvalues of v to see if positive-def*-*-*-*-*
6571 ///*-* ======================================================
6572 ///*-* if not, adds constant along diagonal to make positive.
6573 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6574 
6576 {
6577  /* Local variables */
6578  Double_t dgmin, padd, pmin, pmax, dg, epspdf, epsmin;
6579  Int_t ndex, i, j, ndexd, ip, ifault;
6580  TString chbuff, ctemp;
6581 
6582  epsmin = 1e-6;
6583  epspdf = TMath::Max(epsmin,fEpsma2);
6584  dgmin = fVhmat[0];
6585 //*-*- Check if negative or zero on diagonal
6586  for (i = 1; i <= fNpar; ++i) {
6587  ndex = i*(i + 1) / 2;
6588  if (fVhmat[ndex-1] <= 0) {
6589  mnwarn("W", fCfrom, TString::Format("Negative diagonal element %d in Error Matrix",i));
6590  }
6591  if (fVhmat[ndex-1] < dgmin) dgmin = fVhmat[ndex-1];
6592  }
6593  if (dgmin <= 0) {
6594  dg = epspdf + 1 - dgmin;
6595  mnwarn("W", fCfrom, TString::Format("%g added to diagonal of error matrix",dg));
6596  } else {
6597  dg = 0;
6598  }
6599 //*-*- Store VHMAT in P, make sure diagonal pos.
6600  for (i = 1; i <= fNpar; ++i) {
6601  ndex = i*(i-1) / 2;
6602  ndexd = ndex + i;
6603  fVhmat[ndexd-1] += dg;
6604  if (fVhmat[ndexd-1]==0) {
6605  fPSDFs[i-1] = 1 / 1e-19; // a totally arbitrary silly small value
6606  } else {
6607  fPSDFs[i-1] = 1 / TMath::Sqrt(fVhmat[ndexd-1]);
6608  }
6609  for (j = 1; j <= i; ++j) {
6610  ++ndex;
6611  fP[i + j*fMaxpar - fMaxpar-1] = fVhmat[ndex-1]*fPSDFs[i-1]*fPSDFs[j-1];
6612  }
6613  }
6614 //*-*- call eigen (p,p,maxint,npar,pstar,-npar)
6615  mneig(fP, fMaxint, fNpar, fMaxint, fPstar, epspdf, ifault);
6616  pmin = fPstar[0];
6617  pmax = fPstar[0];
6618  for (ip = 2; ip <= fNpar; ++ip) {
6619  if (fPstar[ip-1] < pmin) pmin = fPstar[ip-1];
6620  if (fPstar[ip-1] > pmax) pmax = fPstar[ip-1];
6621  }
6622  pmax = TMath::Max(TMath::Abs(pmax),Double_t(1));
6623  if ((pmin <= 0 && fLwarn) || fISW[4] >= 2) {
6624  Printf(" EIGENVALUES OF SECOND-DERIVATIVE MATRIX:");
6625  ctemp = " ";
6626  for (ip = 1; ip <= fNpar; ++ip) {
6627  ctemp += TString::Format(" %11.4e",fPstar[ip-1]);
6628  }
6629  Printf("%s", ctemp.Data());
6630  }
6631  if (pmin > epspdf*pmax) return;
6632  if (fISW[1] == 3) fISW[1] = 2;
6633  padd = pmax*.001 - pmin;
6634  for (ip = 1; ip <= fNpar; ++ip) {
6635  ndex = ip*(ip + 1) / 2;
6636  fVhmat[ndex-1] *= padd + 1;
6637  }
6638  fCstatu = "NOT POSDEF";
6639  mnwarn("W", fCfrom, Form("MATRIX FORCED POS-DEF BY ADDING %f TO DIAGONAL.",padd));
6640 
6641 } /* mnpsdf_ */
6642 
6643 ////////////////////////////////////////////////////////////////////////////////
6644 ///*-*-*-*-*Called only by MNSIMP (and MNIMPR) to add a new point*-*-*-*-*-*-*
6645 ///*-* =====================================================
6646 ///*-* and remove an old one from the current simplex, and get the
6647 ///*-* estimated distance to minimum.
6648 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6649 
6650 void TMinuit::mnrazz(Double_t ynew, Double_t *pnew, Double_t *y, Int_t &jh, Int_t &jl)
6651 {
6652  /* Local variables */
6653  Double_t pbig, plit;
6654  Int_t i, j, nparp1;
6655 
6656  /* Function Body */
6657  for (i = 1; i <= fNpar; ++i) { fP[i + jh*fMaxpar - fMaxpar-1] = pnew[i-1]; }
6658  y[jh-1] = ynew;
6659  if (ynew < fAmin) {
6660  for (i = 1; i <= fNpar; ++i) { fX[i-1] = pnew[i-1]; }
6661  mninex(fX);
6662  fAmin = ynew;
6663  fCstatu = "PROGRESS ";
6664  jl = jh;
6665  }
6666  jh = 1;
6667  nparp1 = fNpar + 1;
6668  for (j = 2; j <= nparp1; ++j) { if (y[j-1] > y[jh-1]) jh = j; }
6669  fEDM = y[jh-1] - y[jl-1];
6670  if (fEDM <= 0) goto L45;
6671  for (i = 1; i <= fNpar; ++i) {
6672  pbig = fP[i-1];
6673  plit = pbig;
6674  for (j = 2; j <= nparp1; ++j) {
6675  if (fP[i + j*fMaxpar - fMaxpar-1] > pbig) pbig = fP[i + j*fMaxpar - fMaxpar-1];
6676  if (fP[i + j*fMaxpar - fMaxpar-1] < plit) plit = fP[i + j*fMaxpar - fMaxpar-1];
6677  }
6678  fDirin[i-1] = pbig - plit;
6679  }
6680 L40:
6681  return;
6682 L45:
6683  Printf(" FUNCTION VALUE DOES NOT SEEM TO DEPEND ON ANY OF THE %d VARIABLE PARAMETERS.",fNpar);
6684  Printf(" VERIFY THAT STEP SIZES ARE BIG ENOUGH AND CHECK FCN LOGIC.");
6685  Printf(" *******************************************************************************");
6686  Printf(" *******************************************************************************");
6687  goto L40;
6688 } /* mnrazz_ */
6689 
6690 ////////////////////////////////////////////////////////////////////////////////
6691 ///*-*-*-*-*-*-*This is a super-portable random number generator*-*-*-*-*-*-*
6692 ///*-* ================================================
6693 ///*-* It should not overflow on any 32-bit machine.
6694 ///*-* The cycle is only ~10**9, so use with care!
6695 ///*-* Note especially that VAL must not be undefined on input.
6696 ///*-* Set Default Starting Seed
6697 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6698 
6699 void TMinuit::mnrn15(Double_t &val, Int_t &inseed)
6700 {
6701  /* Initialized data */
6702 
6703  static Int_t iseed = 12345;
6704 
6705  Int_t k;
6706 
6707  if (val == 3) goto L100;
6708  inseed = iseed;
6709  k = iseed / 53668;
6710  iseed = (iseed - k*53668)*40014 - k*12211;
6711  if (iseed < 0) iseed += 2147483563;
6712  val = Double_t(iseed*4.656613e-10);
6713  return;
6714 //*-* "entry" to set seed, flag is VAL=3
6715 L100:
6716  iseed = inseed;
6717 } /* mnrn15_ */
6718 
6719 ////////////////////////////////////////////////////////////////////////////////
6720 ///*-*-*-*-*-*-*-*Resets function value and errors to UNDEFINED*-*-*-*-*-*-*-*
6721 ///*-* =============================================
6722 ///*-* If IOPT=1,
6723 ///*-* If IOPT=0, sets only MINOS errors to undefined
6724 ///*-* Called from MNCLER and whenever problem changes, for example
6725 ///*-* after SET LIMITS, SET PARAM, CALL FCN 6
6726 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6727 
6729 {
6730  Int_t iext, i;
6731 
6732  fCstatu = "RESET ";
6733  if (iopt >= 1) {
6734  fAmin = fUndefi;
6735  fFval3 = TMath::Abs(fAmin)*2 + 1;
6736  fEDM = fBigedm;
6737  fISW[3] = 0;
6738  fISW[1] = 0;
6739  fDcovar = 1;
6740  fISW[0] = 0;
6741  }
6742  fLnolim = kTRUE;
6743  for (i = 1; i <= fNpar; ++i) {
6744  iext = fNexofi[i-1];
6745  if (fNvarl[iext-1] >= 4) fLnolim = kFALSE;
6746  fErp[i-1] = 0;
6747  fErn[i-1] = 0;
6748  fGlobcc[i-1] = 0;
6749  }
6750  if (fISW[1] >= 1) {
6751  fISW[1] = 1;
6752  fDcovar = TMath::Max(fDcovar,.5);
6753  }
6754 } /* mnrset_ */
6755 
6756 ////////////////////////////////////////////////////////////////////////////////
6757 ///*-*-*-*Writes current parameter values and step sizes onto file ISYSSA*-*-*
6758 ///*-* ===============================================================
6759 ///*-* in format which can be reread by Minuit for restarting.
6760 ///*-* The covariance matrix is also output if it exists.
6761 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6762 
6764 {
6765  Printf("mnsave is dummy in TMinuit");
6766 
6767 } /* mnsave_ */
6768 
6769 ////////////////////////////////////////////////////////////////////////////////
6770 ///*-*-*-*-*Scans the values of FCN as a function of one parameter*-*-*-*-*-*
6771 ///*-* ======================================================
6772 ///*-* and plots the resulting values as a curve using MNPLOT.
6773 ///*-* It may be called to scan one parameter or all parameters.
6774 ///*-* retains the best function and parameter values found.
6775 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6776 
6778 {
6779  /* Local variables */
6780  Double_t step, uhigh, xhreq, xlreq, ubest, fnext, unext, xh, xl;
6781  Int_t ipar, iint, icall, ncall, nbins, nparx;
6782  Int_t nxypt, nccall, iparwd;
6783 
6784  xlreq = TMath::Min(fWord7[2],fWord7[3]);
6785  xhreq = TMath::Max(fWord7[2],fWord7[3]);
6786  ncall = Int_t((fWord7[1] + .01));
6787  if (ncall <= 1) ncall = 41;
6788  if (ncall > 98) ncall = 98;
6789  nccall = ncall;
6790  if (fAmin == fUndefi) mnamin();
6791  iparwd = Int_t((fWord7[0] + .1));
6792  ipar = TMath::Max(iparwd,0);
6793  fCstatu = "NO CHANGE";
6794  if (iparwd > 0) goto L200;
6795 
6796 //*-*- equivalent to a loop over parameters requested
6797 L100:
6798  ++ipar;
6799  if (ipar > fNu) goto L900;
6800  iint = fNiofex[ipar-1];
6801  if (iint <= 0) goto L100;
6802 //*-*- set up range for parameter IPAR
6803 L200:
6804  iint = fNiofex[ipar-1];
6805  ubest = fU[ipar-1];
6806  fXpt[0] = ubest;
6807  fYpt[0] = fAmin;
6808  fChpt[0] = ' ';
6809  fXpt[1] = ubest;
6810  fYpt[1] = fAmin;
6811  fChpt[1] = 'X';
6812  nxypt = 2;
6813  if (fNvarl[ipar-1] > 1) goto L300;
6814 
6815 //*-*- no limits on parameter
6816  if (xlreq == xhreq) goto L250;
6817  unext = xlreq;
6818  step = (xhreq - xlreq) / Double_t(ncall-1);
6819  goto L500;
6820 L250:
6821  xl = ubest - fWerr[iint-1];
6822  xh = ubest + fWerr[iint-1];
6823  mnbins(xl, xh, ncall, unext, uhigh, nbins, step);
6824  nccall = nbins + 1;
6825  goto L500;
6826 //*-*- limits on parameter
6827 L300:
6828  if (xlreq == xhreq) goto L350;
6829 //*-* Computing MAX
6830  xl = TMath::Max(xlreq,fAlim[ipar-1]);
6831 //*-* Computing MIN
6832  xh = TMath::Min(xhreq,fBlim[ipar-1]);
6833  if (xl >= xh) goto L700;
6834  unext = xl;
6835  step = (xh - xl) / Double_t(ncall-1);
6836  goto L500;
6837 L350:
6838  unext = fAlim[ipar-1];
6839  step = (fBlim[ipar-1] - fAlim[ipar-1]) / Double_t(ncall-1);
6840 //*-*- main scanning loop over parameter IPAR
6841 L500:
6842  for (icall = 1; icall <= nccall; ++icall) {
6843  fU[ipar-1] = unext;
6844  nparx = fNpar;
6845  Eval(nparx, fGin, fnext, fU, 4); ++fNfcn;
6846  ++nxypt;
6847  fXpt[nxypt-1] = unext;
6848  fYpt[nxypt-1] = fnext;
6849  fChpt[nxypt-1] = '*';
6850  if (fnext < fAmin) {
6851  fAmin = fnext;
6852  ubest = unext;
6853  fCstatu = "IMPROVED ";
6854  }
6855  unext += step;
6856  }
6857  fChpt[nccall] = 0;
6858 
6859 //*-*- finished with scan of parameter IPAR
6860  fU[ipar-1] = ubest;
6861  mnexin(fX);
6862  if (fISW[4] >= 1)
6863  Printf("%dSCAN OF PARAMETER NO. %d, %s"
6864  ,fNewpag,ipar,(const char*)fCpnam[ipar-1]);
6865  mnplot(fXpt, fYpt, fChpt, nxypt, fNpagwd, fNpagln);
6866  goto L800;
6867 L700:
6868  Printf(" REQUESTED RANGE OUTSIDE LIMITS FOR PARAMETER %d",ipar);
6869 L800:
6870  if (iparwd <= 0) goto L100;
6871 //*-*- finished with all parameters
6872 L900:
6873  if (fISW[4] >= 0) mnprin(5, fAmin);
6874 } /* mnscan_ */
6875 
6876 ////////////////////////////////////////////////////////////////////////////////
6877 ///*-*-*-*Performs a rough (but global) minimization by monte carlo search*-*
6878 ///*-* ================================================================
6879 ///*-* Each time a new minimum is found, the search area is shifted
6880 ///*-* to be centered at the best value. Random points are chosen
6881 ///*-* uniformly over a hypercube determined by current step sizes.
6882 ///*-* The Metropolis algorithm accepts a worse point with probability
6883 ///*-* exp(-d/UP), where d is the degradation. Improved points
6884 ///*-* are of course always accepted. Actual steps are random
6885 ///*-* multiples of the nominal steps (DIRIN).
6886 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6887 
6889 {
6890  /* Local variables */
6891  Double_t dxdi, rnum, ftry, rnum1, rnum2, alpha;
6892  Double_t flast, bar;
6893  Int_t ipar, iext, j, ifail, iseed=0, nparx, istep, ib, mxfail, mxstep;
6894 
6895  mxfail = Int_t(fWord7[0]);
6896  if (mxfail <= 0) mxfail = fNpar*20 + 100;
6897  mxstep = mxfail*10;
6898  if (fAmin == fUndefi) mnamin();
6899  alpha = fWord7[1];
6900  if (alpha <= 0) alpha = 3;
6901  if (fISW[4] >= 1) {
6902  Printf(" MNSEEK: MONTE CARLO MINIMIZATION USING METROPOLIS ALGORITHM");
6903  Printf(" TO STOP AFTER %6d SUCCESSIVE FAILURES, OR %7d STEPS",mxfail,mxstep);
6904  Printf(" MAXIMUM STEP SIZE IS %9.3f ERROR BARS.",alpha);
6905  }
6906  fCstatu = "INITIAL ";
6907  if (fISW[4] >= 2) mnprin(2, fAmin);
6908  fCstatu = "UNCHANGED ";
6909  ifail = 0;
6910  rnum = 0;
6911  rnum1 = 0;
6912  rnum2 = 0;
6913  nparx = fNpar;
6914  flast = fAmin;
6915 //*-*- set up step sizes, starting values
6916  for (ipar = 1; ipar <= fNpar; ++ipar) {
6917  iext = fNexofi[ipar-1];
6918  fDirin[ipar-1] = alpha*2*fWerr[ipar-1];
6919  if (fNvarl[iext-1] > 1) {
6920 //*-*- parameter with limits
6921  mndxdi(fX[ipar-1], ipar-1, dxdi);
6922  if (dxdi == 0) dxdi = 1;
6923  fDirin[ipar-1] = alpha*2*fWerr[ipar-1] / dxdi;
6924  if (TMath::Abs(fDirin[ipar-1]) > 6.2831859999999997) {
6925  fDirin[ipar-1] = 6.2831859999999997;
6926  }
6927  }
6928  fSEEKxmid[ipar-1] = fX[ipar-1];
6929  fSEEKxbest[ipar-1] = fX[ipar-1];
6930  }
6931 //*-*- search loop
6932  for (istep = 1; istep <= mxstep; ++istep) {
6933  if (ifail >= mxfail) break;
6934  for (ipar = 1; ipar <= fNpar; ++ipar) {
6935  mnrn15(rnum1, iseed);
6936  mnrn15(rnum2, iseed);
6937  fX[ipar-1] = fSEEKxmid[ipar-1] + (rnum1 + rnum2 - 1)*.5*fDirin[ipar-1];
6938  }
6939  mninex(fX);
6940  Eval(nparx, fGin, ftry, fU, 4); ++fNfcn;
6941  if (ftry < flast) {
6942  if (ftry < fAmin) {
6943  fCstatu = "IMPROVEMNT";
6944  fAmin = ftry;
6945  for (ib = 1; ib <= fNpar; ++ib) { fSEEKxbest[ib-1] = fX[ib-1]; }
6946  ifail = 0;
6947  if (fISW[4] >= 2) mnprin(2, fAmin);
6948  }
6949  goto L300;
6950  } else {
6951  ++ifail;
6952 //*-*- Metropolis algorithm
6953  bar = (fAmin - ftry) / fUp;
6954  mnrn15(rnum, iseed);
6955  if (bar < TMath::Log(rnum)) continue;
6956  }
6957 //*-*- Accept new point, move there
6958 L300:
6959  for (j = 1; j <= fNpar; ++j) { fSEEKxmid[j-1] = fX[j-1]; }
6960  flast = ftry;
6961  }
6962 //*-*- end search loop
6963  if (fISW[4] > 1) {
6964  Printf(" MNSEEK: %5d SUCCESSIVE UNSUCCESSFUL TRIALS.",ifail);
6965  }
6966  for (ib = 1; ib <= fNpar; ++ib) { fX[ib-1] = fSEEKxbest[ib-1]; }
6967  mninex(fX);
6968  if (fISW[4] >= 1) mnprin(2, fAmin);
6969  if (fISW[4] == 0) mnprin(0, fAmin);
6970 } /* mnseek_ */
6971 
6972 ////////////////////////////////////////////////////////////////////////////////
6973 ///*-*-*-*-*Interprets the commands that start with SET and SHOW*-*-*-*-*-*-*
6974 ///*-* ====================================================
6975 ///*-* Called from MNEXCM
6976 ///*-* file characteristics for SET INPUT
6977 ///*-* 'SET ' or 'SHOW', 'ON ' or 'OFF', 'SUPPRESSED' or 'REPORTED '
6978 ///*-* explanation of print level numbers -1:3 and strategies 0:2
6979 ///*-* identification of debug options
6980 ///*-* things that can be set or shown
6981 ///*-* options not intended for normal users
6982 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
6983 
6985 {
6986  /* Initialized data */
6987 
6988  static const char *cname[30] = {
6989  "FCN value ",
6990  "PARameters",
6991  "LIMits ",
6992  "COVariance",
6993  "CORrelatio",
6994  "PRInt levl",
6995  "NOGradient",
6996  "GRAdient ",
6997  "ERRor def ",
6998  "INPut file",
6999  "WIDth page",
7000  "LINes page",
7001  "NOWarnings",
7002  "WARnings ",
7003  "RANdom gen",
7004  "TITle ",
7005  "STRategy ",
7006  "EIGenvalue",
7007  "PAGe throw",
7008  "MINos errs",
7009  "EPSmachine",
7010  "OUTputfile",
7011  "BATch ",
7012  "INTeractiv",
7013  "VERsion ",
7014  "reserve ",
7015  "NODebug ",
7016  "DEBug ",
7017  "SHOw ",
7018  "SET "};
7019 
7020  static Int_t nname = 25;
7021  static Int_t nntot = 30;
7022  static TString cprlev[5] = {
7023  "-1: NO OUTPUT EXCEPT FROM SHOW ",
7024  " 0: REDUCED OUTPUT ",
7025  " 1: NORMAL OUTPUT ",
7026  " 2: EXTRA OUTPUT FOR PROBLEM CASES",
7027  " 3: MAXIMUM OUTPUT "};
7028 
7029  static TString cstrat[3] = {
7030  " 0: MINIMIZE THE NUMBER OF CALLS TO FUNCTION",
7031  " 1: TRY TO BALANCE SPEED AGAINST RELIABILITY",
7032  " 2: MAKE SURE MINIMUM TRUE, ERRORS CORRECT "};
7033 
7034  static TString cdbopt[7] = {
7035  "REPORT ALL EXCEPTIONAL CONDITIONS ",
7036  "MNLINE: LINE SEARCH MINIMIZATION ",
7037  "MNDERI: FIRST DERIVATIVE CALCULATIONS ",
7038  "MNHESS: SECOND DERIVATIVE CALCULATIONS ",
7039  "MNMIGR: COVARIANCE MATRIX UPDATES ",
7040  "MNHES1: FIRST DERIVATIVE UNCERTAINTIES ",
7041  "MNCONT: MNCONTOUR PLOT (MNCROS SEARCH) "};
7042 
7043  /* System generated locals */
7044  //Int_t f_inqu();
7045 
7046  /* Local variables */
7047  Double_t val;
7048  Int_t iset, iprm, i, jseed, kname, iseed, iunit, id, ii, kk;
7049  Int_t ikseed, idbopt, igrain=0, iswsav, isw2;
7050  TString cfname, cmode, ckind, cwarn, copt, ctemp, ctemp2;
7051  Bool_t lname=kFALSE;
7052 
7053  for (i = 1; i <= nntot; ++i) {
7054  ctemp = cname[i-1];
7055  ckind = ctemp(0,3);
7056  ctemp2 = fCword(4,6);
7057  if (strstr(ctemp2.Data(),ckind.Data())) goto L5;
7058  }
7059  i = 0;
7060 L5:
7061  kname = i;
7062 
7063 //*-*- Command could be SET xxx, SHOW xxx, HELP SET or HELP SHOW
7064  ctemp2 = fCword(0,3);
7065  if ( ctemp2.Contains("HEL")) goto L2000;
7066  if ( ctemp2.Contains("SHO")) goto L1000;
7067  if (!ctemp2.Contains("SET")) goto L1900;
7068 //*-*- ---
7069  ckind = "SET ";
7070 //*-*- . . . . . . . . . . set unknown
7071  if (kname <= 0) goto L1900;
7072 //*-*- . . . . . . . . . . set known
7073  switch ((int)kname) {
7074  case 1: goto L3000;
7075  case 2: goto L20;
7076  case 3: goto L30;
7077  case 4: goto L40;
7078  case 5: goto L3000;
7079  case 6: goto L60;
7080  case 7: goto L70;
7081  case 8: goto L80;
7082  case 9: goto L90;
7083  case 10: goto L100;
7084  case 11: goto L110;
7085  case 12: goto L120;
7086  case 13: goto L130;
7087  case 14: goto L140;
7088  case 15: goto L150;
7089  case 16: goto L160;
7090  case 17: goto L170;
7091  case 18: goto L3000;
7092  case 19: goto L190;
7093  case 20: goto L3000;
7094  case 21: goto L210;
7095  case 22: goto L220;
7096  case 23: goto L230;
7097  case 24: goto L240;
7098  case 25: goto L3000;
7099  case 26: goto L1900;
7100  case 27: goto L270;
7101  case 28: goto L280;
7102  case 29: goto L290;
7103  case 30: goto L300;
7104  }
7105 
7106 //*-*- . . . . . . . . . . set param
7107 L20:
7108  iprm = Int_t(fWord7[0]);
7109  if (iprm > fNu) goto L25;
7110  if (iprm <= 0) goto L25;
7111  if (fNvarl[iprm-1] < 0) goto L25;
7112  fU[iprm-1] = fWord7[1];
7113  mnexin(fX);
7114  isw2 = fISW[1];
7115  mnrset(1);
7116 //*-*- Keep approximate covariance matrix, even if new param value
7117  fISW[1] = TMath::Min(isw2,1);
7118  fCfrom = "SET PARM";
7119  fNfcnfr = fNfcn;
7120  fCstatu = "NEW VALUES";
7121  return;
7122 L25:
7123  Printf(" UNDEFINED PARAMETER NUMBER. IGNORED.");
7124  return;
7125 //*-*- . . . . . . . . . . set limits
7126 L30:
7127  mnlims();
7128  return;
7129 //*-*- . . . . . . . . . . set covar
7130 L40:
7131 //*-* this command must be handled by MNREAD, and is not Fortran-callable
7132  goto L3000;
7133 //*-*- . . . . . . . . . . set print
7134 L60:
7135  fISW[4] = Int_t(fWord7[0]);
7136  return;
7137 //*-*- . . . . . . . . . . set nograd
7138 L70:
7139  fISW[2] = 0;
7140  return;
7141 //*-*- . . . . . . . . . . set grad
7142 L80:
7143  mngrad();
7144  return;
7145 //*-*- . . . . . . . . . . set errdef
7146 L90:
7147  if (fWord7[0] == fUp) return;
7148  if (fWord7[0] <= 0) {
7149  if (fUp == fUpdflt) return;
7150  fUp = fUpdflt;
7151  } else {
7152  fUp = fWord7[0];
7153  }
7154  for (i = 1; i <= fNpar; ++i) {
7155  fErn[i-1] = 0;
7156  fErp[i-1] = 0;
7157  }
7158  mnwerr();
7159  return;
7160 //*-*- . . . . . . . . . . set input
7161 //*-* This command must be handled by MNREAD. If it gets this far,
7162 //*-*- it is illegal.
7163 L100:
7164  goto L3000;
7165 //*-*- . . . . . . . . . . set width
7166 L110:
7167  fNpagwd = Int_t(fWord7[0]);
7168  fNpagwd = TMath::Max(fNpagwd,50);
7169  return;
7170 
7171 L120:
7172  fNpagln = Int_t(fWord7[0]);
7173  return;
7174 //*-*- . . . . . . . . . . set nowarn
7175 
7176 L130:
7177  fLwarn = kFALSE;
7178  return;
7179 //*-*- . . . . . . . . . . set warn
7180 L140:
7181  fLwarn = kTRUE;
7182  mnwarn("W", "SHO", "SHO");
7183  return;
7184 //*-*- . . . . . . . . . . set random
7185 L150:
7186  jseed = Int_t(fWord7[0]);
7187  val = 3;
7188  mnrn15(val, jseed);
7189  if (fISW[4] > 0) {
7190  Printf(" MINUIT RANDOM NUMBER SEED SET TO %d",jseed);
7191  }
7192  return;
7193 //*-*- . . . . . . . . . . set title
7194 L160:
7195 //*-* this command must be handled by MNREAD, and is not Fortran-callable
7196  goto L3000;
7197 //*-*- . . . . . . . . . set strategy
7198 L170:
7199  fIstrat = Int_t(fWord7[0]);
7200  fIstrat = TMath::Max(fIstrat,0);
7201  fIstrat = TMath::Min(fIstrat,2);
7202  if (fISW[4] > 0) goto L1172;
7203  return;
7204 //*-*- . . . . . . . . . set page throw
7205 L190:
7206  fNewpag = Int_t(fWord7[0]);
7207  goto L1190;
7208 //*-*- . . . . . . . . . . set epsmac
7209 L210:
7210  if (fWord7[0] > 0 && fWord7[0] < .1) {
7211  fEpsmac = fWord7[0];
7212  }
7214  goto L1210;
7215 //*-*- . . . . . . . . . . set outputfile
7216 L220:
7217  iunit = Int_t(fWord7[0]);
7218  fIsyswr = iunit;
7219  fIstkwr[0] = iunit;
7220  if (fISW[4] >= 0) goto L1220;
7221  return;
7222 //*-*- . . . . . . . . . . set batch
7223 L230:
7224  fISW[5] = 0;
7225  if (fISW[4] >= 0) goto L1100;
7226  return;
7227 //*-*- . . . . . . . . . . set interactive
7228 L240:
7229  fISW[5] = 1;
7230  if (fISW[4] >= 0) goto L1100;
7231  return;
7232 //*-*- . . . . . . . . . . set nodebug
7233 L270:
7234  iset = 0;
7235  goto L281;
7236 //*-*- . . . . . . . . . . set debug
7237 L280:
7238  iset = 1;
7239 L281:
7240  idbopt = Int_t(fWord7[0]);
7241  if (idbopt > 6) goto L288;
7242  if (idbopt >= 0) {
7243  fIdbg[idbopt] = iset;
7244  if (iset == 1) fIdbg[0] = 1;
7245  } else {
7246 //*-*- SET DEBUG -1 sets all debug options
7247  for (id = 0; id <= 6; ++id) { fIdbg[id] = iset; }
7248  }
7249  fLrepor = fIdbg[0] >= 1;
7250  mnwarn("D", "SHO", "SHO");
7251  return;
7252 L288:
7253  Printf(" UNKNOWN DEBUG OPTION %d REQUESTED. IGNORED",idbopt);
7254  return;
7255 //*-*- . . . . . . . . . . set show
7256 L290:
7257 //*-*- . . . . . . . . . . set set
7258 L300:
7259  goto L3000;
7260 //*-*- -----------------------------------------------------
7261 L1000:
7262 //*-*- at this point, CWORD must be 'SHOW'
7263  ckind = "SHOW";
7264  if (kname <= 0) goto L1900;
7265 
7266  switch ((int)kname) {
7267  case 1: goto L1010;
7268  case 2: goto L1020;
7269  case 3: goto L1030;
7270  case 4: goto L1040;
7271  case 5: goto L1050;
7272  case 6: goto L1060;
7273  case 7: goto L1070;
7274  case 8: goto L1070;
7275  case 9: goto L1090;
7276  case 10: goto L1100;
7277  case 11: goto L1110;
7278  case 12: goto L1120;
7279  case 13: goto L1130;
7280  case 14: goto L1130;
7281  case 15: goto L1150;
7282  case 16: goto L1160;
7283  case 17: goto L1170;
7284  case 18: goto L1180;
7285  case 19: goto L1190;
7286  case 20: goto L1200;
7287  case 21: goto L1210;
7288  case 22: goto L1220;
7289  case 23: goto L1100;
7290  case 24: goto L1100;
7291  case 25: goto L1250;
7292  case 26: goto L1900;
7293  case 27: goto L1270;
7294  case 28: goto L1270;
7295  case 29: goto L1290;
7296  case 30: goto L1300;
7297  }
7298 
7299 //*-*- . . . . . . . . . . show fcn
7300 L1010:
7301  if (fAmin == fUndefi) mnamin();
7302  mnprin(0, fAmin);
7303  return;
7304 //*-*- . . . . . . . . . . show param
7305 L1020:
7306  if (fAmin == fUndefi) mnamin();
7307  mnprin(5, fAmin);
7308  return;
7309 //*-*- . . . . . . . . . . show limits
7310 L1030:
7311  if (fAmin == fUndefi) mnamin();
7312  mnprin(1, fAmin);
7313  return;
7314 //*-*- . . . . . . . . . . show covar
7315 L1040:
7316  mnmatu(1);
7317  return;
7318 //*-*- . . . . . . . . . . show corre
7319 L1050:
7320  mnmatu(0);
7321  return;
7322 //*-*- . . . . . . . . . . show print
7323 L1060:
7324  if (fISW[4] < -1) fISW[4] = -1;
7325  if (fISW[4] > 3) fISW[4] = 3;
7326  Printf(" ALLOWED PRINT LEVELS ARE:");
7327  Printf(" %s",cprlev[0].Data());
7328  Printf(" %s",cprlev[1].Data());
7329  Printf(" %s",cprlev[2].Data());
7330  Printf(" %s",cprlev[3].Data());
7331  Printf(" %s",cprlev[4].Data());
7332  Printf(" CURRENT PRINTOUT LEVEL IS %s",cprlev[fISW[4]+1].Data());
7333  return;
7334 //*-*- . . . . . . . show nograd, grad
7335 L1070:
7336  if (fISW[2] <= 0) {
7337  Printf(" NOGRAD IS SET. DERIVATIVES NOT COMPUTED IN FCN.");
7338  } else {
7339  Printf(" GRAD IS SET. USER COMPUTES DERIVATIVES IN FCN.");
7340  }
7341  return;
7342 //*-*- . . . . . . . . . . show errdef
7343 L1090:
7344  Printf(" ERRORS CORRESPOND TO FUNCTION CHANGE OF %g",fUp);
7345  return;
7346 //*-*- . . . . . . . . . . show input,
7347 //*-*- batch, or interactive
7348 L1100:
7349 // ioin__1.inerr = 0;
7350 // ioin__1.inunit = fIsysrd;
7351 // ioin__1.infile = 0;
7352 // ioin__1.inex = 0;
7353 // ioin__1.inopen = 0;
7354 // ioin__1.innum = 0;
7355 // ioin__1.innamed = &lname;
7356 // ioin__1.innamlen = 64;
7357 // ioin__1.inname = cfname;
7358 // ioin__1.inacc = 0;
7359 // ioin__1.inseq = 0;
7360 // ioin__1.indir = 0;
7361 // ioin__1.infmt = 0;
7362 // ioin__1.inform = 0;
7363 // ioin__1.inunf = 0;
7364 // ioin__1.inrecl = 0;
7365 // ioin__1.innrec = 0;
7366 // ioin__1.inblank = 0;
7367 // f_inqu(&ioin__1);
7368  cmode = "BATCH MODE ";
7369  if (fISW[5] == 1) cmode = "INTERACTIVE MODE";
7370  if (! lname) cfname = "unknown";
7371  Printf(" INPUT NOW BEING READ IN %s FROM UNIT NO. %d FILENAME: %s"
7372  ,(const char*)cmode,fIsysrd,(const char*)cfname);
7373  return;
7374 //*-*- . . . . . . . . . . show width
7375 L1110:
7376  Printf(" PAGE WIDTH IS SET TO %d COLUMNS",fNpagwd);
7377  return;
7378 //*-*- . . . . . . . . . . show lines
7379 L1120:
7380  Printf(" PAGE LENGTH IS SET TO %d LINES",fNpagln);
7381  return;
7382 //*-*- . . . . . . .show nowarn, warn
7383 L1130:
7384  cwarn = "SUPPRESSED";
7385  if (fLwarn) cwarn = "REPORTED ";
7386  Printf("%s",(const char*)cwarn);
7387  if (! fLwarn) mnwarn("W", "SHO", "SHO");
7388  return;
7389 //*-*- . . . . . . . . . . show random
7390 L1150:
7391  val = 0;
7392  mnrn15(val, igrain);
7393  ikseed = igrain;
7394  Printf(" MINUIT RNDM SEED IS CURRENTLY=%d",ikseed);
7395  val = 3;
7396  iseed = ikseed;
7397  mnrn15(val, iseed);
7398  return;
7399 //*-*- . . . . . . . . . show title
7400 L1160:
7401  Printf(" TITLE OF CURRENT TASK IS:%s",(const char*)fCtitl);
7402  return;
7403 //*-*- . . . . . . . show strategy
7404 L1170:
7405  Printf(" ALLOWED STRATEGIES ARE:");
7406  Printf(" %s",cstrat[0].Data());
7407  Printf(" %s",cstrat[1].Data());
7408  Printf(" %s",cstrat[2].Data());
7409 L1172:
7410  Printf(" NOW USING STRATEGY %s",(const char*)cstrat[fIstrat]);
7411  return;
7412 //*-*- . . . . . show eigenvalues
7413 L1180:
7414  iswsav = fISW[4];
7415  fISW[4] = 3;
7416  if (fISW[1] < 1) {
7417  Printf("%s",(const char*)fCovmes[0]);
7418  } else {
7419  mnpsdf();
7420  }
7421  fISW[4] = iswsav;
7422  return;
7423 //*-*- . . . . . show page throw
7424 L1190:
7425  Printf(" PAGE THROW CARRIAGE CONTROL = %d",fNewpag);
7426  if (fNewpag == 0) {
7427  Printf(" NO PAGE THROWS IN MINUIT OUTPUT");
7428  }
7429  return;
7430 //*-*- . . . . . . show minos errors
7431 L1200:
7432  for (ii = 1; ii <= fNpar; ++ii) {
7433  if (fErp[ii-1] > 0 || fErn[ii-1] < 0) goto L1204;
7434  }
7435  Printf(" THERE ARE NO MINOS ERRORS CURRENTLY VALID.");
7436  return;
7437 L1204:
7438  mnprin(4, fAmin);
7439  return;
7440 //*-*- . . . . . . . . . show epsmac
7441 L1210:
7442  Printf(" FLOATING-POINT NUMBERS ASSUMED ACCURATE TO %g",fEpsmac);
7443  return;
7444 //*-*- . . . . . . show outputfiles
7445 L1220:
7446  Printf(" MINUIT PRIMARY OUTPUT TO UNIT %d",fIsyswr);
7447  return;
7448 //*-*- . . . . . . show version
7449 L1250:
7450  Printf(" THIS IS MINUIT VERSION:%s",(const char*)fCvrsn);
7451  return;
7452 //*-*- . . . . . . show nodebug, debug
7453 L1270:
7454  for (id = 0; id <= 6; ++id) {
7455  copt = "OFF";
7456  if (fIdbg[id] >= 1) copt = "ON ";
7457  Printf(" DEBUG OPTION %3d IS %3s :%s"
7458  ,id,(const char*)copt,(const char*)cdbopt[id]);
7459  }
7460  if (! fLrepor) mnwarn("D", "SHO", "SHO");
7461  return;
7462 //*-*- . . . . . . . . . . show show
7463 L1290:
7464  ckind = "SHOW";
7465  goto L2100;
7466 //*-*- . . . . . . . . . . show set
7467 L1300:
7468  ckind = "SET ";
7469  goto L2100;
7470 //*-*- -----------------------------------------------------
7471 //*-*- UNKNOWN COMMAND
7472 L1900:
7473  Printf(" THE COMMAND:%10s IS UNKNOWN.",(const char*)fCword);
7474  goto L2100;
7475 //*-*- -----------------------------------------------------
7476 //*-*- HELP SHOW, HELP SET, SHOW SET, or SHOW SHOW
7477 L2000:
7478  ckind = "SET ";
7479  ctemp2 = fCword(3,7);
7480  if (strcmp(ctemp2.Data(), "SHO")) ckind = "SHOW";
7481 L2100:
7482  Printf(" THE FORMAT OF THE %4s COMMAND IS:",(const char*)ckind);
7483  Printf(" %s xxx [numerical arguments if any]",(const char*)ckind);
7484  Printf(" WHERE xxx MAY BE ONE OF THE FOLLOWING:");
7485  for (kk = 1; kk <= nname; ++kk) {
7486  Printf(" %s",cname[kk-1]);
7487  }
7488  return;
7489 //*-*- -----------------------------------------------------
7490 //*-*- ILLEGAL COMMAND
7491 L3000:
7492  Printf(" ABOVE COMMAND IS ILLEGAL. IGNORED");
7493 
7494 } /* mnset_ */
7495 
7496 ////////////////////////////////////////////////////////////////////////////////
7497 ///*-*-*-*-*Minimization using the simplex method of Nelder and Mead*-*-*-*-*
7498 ///*-* ========================================================
7499 ///*-* Performs a minimization using the simplex method of Nelder
7500 ///*-* and Mead (ref. -- Comp. J. 7,308 (1965)).
7501 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
7502 
7504 {
7505  /* Initialized data */
7506 
7507  static Double_t alpha = 1;
7508  static Double_t beta = .5;
7509  static Double_t gamma = 2;
7510  static Double_t rhomin = 4;
7511  static Double_t rhomax = 8;
7512 
7513  /* Local variables */
7514  Double_t dmin_, dxdi, yrho, f, ynpp1, aming, ypbar;
7515  Double_t bestx, ystar, y1, y2, ystst, pb, wg;
7516  Double_t absmin, rho, sig2, rho1, rho2;
7517  Int_t npfn, i, j, k, jhold, ncycl, nparx;
7518  Int_t nparp1, kg, jh, nf, jl, ns;
7519 
7520  if (fNpar <= 0) return;
7521  if (fAmin == fUndefi) mnamin();
7522  fCfrom = "SIMPLEX ";
7523  fNfcnfr = fNfcn;
7524  fCstatu = "UNCHANGED ";
7525  npfn = fNfcn;
7526  nparp1 = fNpar + 1;
7527  nparx = fNpar;
7528  rho1 = alpha + 1;
7529  rho2 = rho1 + alpha*gamma;
7530  wg = 1 / Double_t(fNpar);
7531  if (fISW[4] >= 0) {
7532  Printf(" START SIMPLEX MINIMIZATION. CONVERGENCE WHEN EDM .LT. %g",fEpsi);
7533  }
7534  for (i = 1; i <= fNpar; ++i) {
7535  fDirin[i-1] = fWerr[i-1];
7536  mndxdi(fX[i-1], i-1, dxdi);
7537  if (dxdi != 0) fDirin[i-1] = fWerr[i-1] / dxdi;
7538  dmin_ = fEpsma2*TMath::Abs(fX[i-1]);
7539  if (fDirin[i-1] < dmin_) fDirin[i-1] = dmin_;
7540  }
7541 //*-* ** choose the initial simplex using single-parameter searches
7542 L1:
7543  ynpp1 = fAmin;
7544  jl = nparp1;
7545  fSIMPy[nparp1-1] = fAmin;
7546  absmin = fAmin;
7547  for (i = 1; i <= fNpar; ++i) {
7548  aming = fAmin;
7549  fPbar[i-1] = fX[i-1];
7550  bestx = fX[i-1];
7551  kg = 0;
7552  ns = 0;
7553  nf = 0;
7554 L4:
7555  fX[i-1] = bestx + fDirin[i-1];
7556  mninex(fX);
7557  Eval(nparx, fGin, f, fU, 4); ++fNfcn;
7558  if (f <= aming) goto L6;
7559 //*-*- failure
7560  if (kg == 1) goto L8;
7561  kg = -1;
7562  ++nf;
7563  fDirin[i-1] *= -.4;
7564  if (nf < 3) goto L4;
7565  ns = 6;
7566 //*-*- success
7567 L6:
7568  bestx = fX[i-1];
7569  fDirin[i-1] *= 3;
7570  aming = f;
7571  fCstatu = "PROGRESS ";
7572  kg = 1;
7573  ++ns;
7574  if (ns < 6) goto L4;
7575 //*-*- local minimum found in ith direction
7576 L8:
7577  fSIMPy[i-1] = aming;
7578  if (aming < absmin) jl = i;
7579  if (aming < absmin) absmin = aming;
7580  fX[i-1] = bestx;
7581  for (k = 1; k <= fNpar; ++k) { fP[k + i*fMaxpar - fMaxpar-1] = fX[k-1]; }
7582  }
7583  jh = nparp1;
7584  fAmin = fSIMPy[jl-1];
7585  mnrazz(ynpp1, fPbar, fSIMPy, jh, jl);
7586  for (i = 1; i <= fNpar; ++i) { fX[i-1] = fP[i + jl*fMaxpar - fMaxpar-1]; }
7587  mninex(fX);
7588  fCstatu = "PROGRESS ";
7589  if (fISW[4] >= 1) mnprin(5, fAmin);
7590  fEDM = fBigedm;
7591  sig2 = fEDM;
7592  ncycl = 0;
7593 //*-*- . . . . . start main loop
7594 L50:
7595  if (sig2 < fEpsi && fEDM < fEpsi) goto L76;
7596  sig2 = fEDM;
7597  if (fNfcn - npfn > fNfcnmx) goto L78;
7598 //*-*- calculate new point * by reflection
7599  for (i = 1; i <= fNpar; ++i) {
7600  pb = 0;
7601  for (j = 1; j <= nparp1; ++j) { pb += wg*fP[i + j*fMaxpar - fMaxpar-1]; }
7602  fPbar[i-1] = pb - wg*fP[i + jh*fMaxpar - fMaxpar-1];
7603  fPstar[i-1] = (alpha + 1)*fPbar[i-1] - alpha*fP[i + jh*fMaxpar - fMaxpar-1];
7604  }
7605  mninex(fPstar);
7606  Eval(nparx, fGin, ystar, fU, 4); ++fNfcn;
7607  if (ystar >= fAmin) goto L70;
7608 //*-*- point * better than jl, calculate new point **
7609  for (i = 1; i <= fNpar; ++i) {
7610  fPstst[i-1] = gamma*fPstar[i-1] + (1 - gamma)*fPbar[i-1];
7611  }
7612  mninex(fPstst);
7613  Eval(nparx, fGin, ystst, fU, 4); ++fNfcn;
7614 //*-*- try a parabola through ph, pstar, pstst. min = prho
7615  y1 = (ystar - fSIMPy[jh-1])*rho2;
7616  y2 = (ystst - fSIMPy[jh-1])*rho1;
7617  rho = (rho2*y1 - rho1*y2)*.5 / (y1 - y2);
7618  if (rho < rhomin) goto L66;
7619  if (rho > rhomax) rho = rhomax;
7620  for (i = 1; i <= fNpar; ++i) {
7621  fPrho[i-1] = rho*fPbar[i-1] + (1 - rho)*fP[i + jh*fMaxpar - fMaxpar-1];
7622  }
7623  mninex(fPrho);
7624  Eval(nparx, fGin, yrho, fU, 4); ++fNfcn;
7625  if (yrho < fSIMPy[jl-1] && yrho < ystst) goto L65;
7626  if (ystst < fSIMPy[jl-1]) goto L67;
7627  if (yrho > fSIMPy[jl-1]) goto L66;
7628 //*-*- accept minimum point of parabola, PRHO
7629 L65:
7630  mnrazz(yrho, fPrho, fSIMPy, jh, jl);
7631  goto L68;
7632 L66:
7633  if (ystst < fSIMPy[jl-1]) goto L67;
7634  mnrazz(ystar, fPstar, fSIMPy, jh, jl);
7635  goto L68;
7636 L67:
7637  mnrazz(ystst, fPstst, fSIMPy, jh, jl);
7638 L68:
7639  ++ncycl;
7640  if (fISW[4] < 2) goto L50;
7641  if (fISW[4] >= 3 || ncycl % 10 == 0) {
7642  mnprin(5, fAmin);
7643  }
7644  goto L50;
7645 //*-*- point * is not as good as jl
7646 L70:
7647  if (ystar >= fSIMPy[jh-1]) goto L73;
7648  jhold = jh;
7649  mnrazz(ystar, fPstar, fSIMPy, jh, jl);
7650  if (jhold != jh) goto L50;
7651 //*-*- calculate new point **
7652 L73:
7653  for (i = 1; i <= fNpar; ++i) {
7654  fPstst[i-1] = beta*fP[i + jh*fMaxpar - fMaxpar-1] + (1 - beta)*fPbar[i-1];
7655  }
7656  mninex(fPstst);
7657  Eval(nparx, fGin, ystst, fU, 4); ++fNfcn;
7658  if (ystst > fSIMPy[jh-1]) goto L1;
7659 //*-*- point ** is better than jh
7660  if (ystst < fAmin) goto L67;
7661  mnrazz(ystst, fPstst, fSIMPy, jh, jl);
7662  goto L50;
7663 //*-*- . . . . . . end main loop
7664 L76:
7665  if (fISW[4] >= 0) {
7666  Printf(" SIMPLEX MINIMIZATION HAS CONVERGED.");
7667  }
7668  fISW[3] = 1;
7669  goto L80;
7670 L78:
7671  if (fISW[4] >= 0) {
7672  Printf(" SIMPLEX TERMINATES WITHOUT CONVERGENCE.");
7673  }
7674  fCstatu = "CALL LIMIT";
7675  fISW[3] = -1;
7676  fISW[0] = 1;
7677 L80:
7678  for (i = 1; i <= fNpar; ++i) {
7679  pb = 0;
7680  for (j = 1; j <= nparp1; ++j) { pb += wg*fP[i + j*fMaxpar - fMaxpar-1]; }
7681  fPbar[i-1] = pb - wg*fP[i + jh*fMaxpar - fMaxpar-1];
7682  }
7683  mninex(fPbar);
7684  Eval(nparx, fGin, ypbar, fU, 4); ++fNfcn;
7685  if (ypbar < fAmin) mnrazz(ypbar, fPbar, fSIMPy, jh, jl);
7686  mninex(fX);
7687  if (fNfcnmx + npfn - fNfcn < fNpar*3) goto L90;
7688  if (fEDM > fEpsi*2) goto L1;
7689 L90:
7690  if (fISW[4] >= 0) mnprin(5, fAmin);
7691 } /* mnsimp_ */
7692 
7693 ////////////////////////////////////////////////////////////////////////////////
7694 ///*-*-*-*-*Returns concerning the current status of the minimization*-*-*-*-*
7695 ///*-* =========================================================
7696 ///*-* User-called
7697 ///*-* Namely, it returns:
7698 ///*-* FMIN: the best function value found so far
7699 ///*-* FEDM: the estimated vertical distance remaining to minimum
7700 ///*-* ERRDEF: the value of UP defining parameter uncertainties
7701 ///*-* NPARI: the number of currently variable parameters
7702 ///*-* NPARX: the highest (external) parameter number defined by user
7703 ///*-* ISTAT: a status integer indicating how good is the covariance
7704 ///*-* matrix: 0= not calculated at all
7705 ///*-* 1= approximation only, not accurate
7706 ///*-* 2= full matrix, but forced positive-definite
7707 ///*-* 3= full accurate covariance matrix
7708 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
7709 
7710 void TMinuit::mnstat(Double_t &fmin, Double_t &fedm, Double_t &errdef, Int_t &npari, Int_t &nparx, Int_t &istat)
7711 {
7712  fmin = fAmin;
7713  fedm = fEDM;
7714  errdef = fUp;
7715  npari = fNpar;
7716  nparx = fNu;
7717  istat = fISW[1];
7718  if (fEDM == fBigedm) fedm = fUp;
7719  if (fAmin == fUndefi) {
7720  fmin = 0;
7721  fedm = fUp;
7722  istat = 0;
7723  }
7724 } /* mnstat_ */
7725 
7726 ////////////////////////////////////////////////////////////////////////////////
7727 ///*-*-*-*-*-*-*-*To find the machine precision*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
7728 ///*-* =============================
7729 ///*-* Compares its argument with the value 1.0, and returns
7730 ///*-* the value .TRUE. if they are equal. To find EPSMAC
7731 ///*-* safely by foiling the Fortran optimizer
7732 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
7733 
7734 void TMinuit::mntiny(volatile Double_t epsp1, Double_t &epsbak)
7735 {
7736  epsbak = epsp1 - 1;
7737 } /* mntiny_ */
7738 
7739 ////////////////////////////////////////////////////////////////////////////////
7740 ///*-*-*-*-*-*Returns .TRUE. if CFNAME contains unprintable characters*-*-*-*
7741 ///*-* ========================================================
7742 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
7743 
7745 {
7746  Int_t i, l, ic;
7747  Bool_t ret_val;
7748  static TString cpt = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890./;:[]$%*_!@#&+()";
7749 
7750  ret_val = kFALSE;
7751  l = strlen((const char*)cfname);
7752  for (i = 1; i <= l; ++i) {
7753  for (ic = 1; ic <= 80; ++ic) {
7754  if (cfname[i-1] == cpt[ic-1]) goto L100;
7755  }
7756  return kTRUE;
7757 L100:
7758  ;
7759  }
7760  return ret_val;
7761 } /* mnunpt_ */
7762 
7763 ////////////////////////////////////////////////////////////////////////////////
7764 ///*-*-*-*-*-*-*-*-*-*-*-*Inverts a symmetric matrix*-*-*-*-*-*-*-*-*-*-*-*-*
7765 ///*-* ==========================
7766 ///*-* inverts a symmetric matrix. matrix is first scaled to
7767 ///*-* have all ones on the diagonal (equivalent to change of units)
7768 ///*-* but no pivoting is done since matrix is positive-definite.
7769 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
7770 
7772 {
7773  /* System generated locals */
7774  Int_t a_offset;
7775 
7776  /* Local variables */
7777  Double_t si;
7778  Int_t i, j, k, kp1, km1;
7779 
7780  /* Parameter adjustments */
7781  a_offset = l + 1;
7782  a -= a_offset;
7783 
7784  /* Function Body */
7785  ifail = 0;
7786  if (n < 1) goto L100;
7787  if (n > fMaxint) goto L100;
7788 //*-*- scale matrix by sqrt of diag elements
7789  for (i = 1; i <= n; ++i) {
7790  si = a[i + i*l];
7791  if (si <= 0) goto L100;
7792  fVERTs[i-1] = 1 / TMath::Sqrt(si);
7793  }
7794  for (i = 1; i <= n; ++i) {
7795  for (j = 1; j <= n; ++j) {
7796  a[i + j*l] = a[i + j*l]*fVERTs[i-1]*fVERTs[j-1];
7797  }
7798  }
7799 //*-*- . . . start main loop . . . .
7800  for (i = 1; i <= n; ++i) {
7801  k = i;
7802 //*-*- preparation for elimination step1
7803  if (a[k + k*l] != 0) fVERTq[k-1] = 1 / a[k + k*l];
7804  else goto L100;
7805  fVERTpp[k-1] = 1;
7806  a[k + k*l] = 0;
7807  kp1 = k + 1;
7808  km1 = k - 1;
7809  if (km1 < 0) goto L100;
7810  else if (km1 == 0) goto L50;
7811  else goto L40;
7812 L40:
7813  for (j = 1; j <= km1; ++j) {
7814  fVERTpp[j-1] = a[j + k*l];
7815  fVERTq[j-1] = a[j + k*l]*fVERTq[k-1];
7816  a[j + k*l] = 0;
7817  }
7818 L50:
7819  if (k - n < 0) goto L51;
7820  else if (k - n == 0) goto L60;
7821  else goto L100;
7822 L51:
7823  for (j = kp1; j <= n; ++j) {
7824  fVERTpp[j-1] = a[k + j*l];
7825  fVERTq[j-1] = -a[k + j*l]*fVERTq[k-1];
7826  a[k + j*l] = 0;
7827  }
7828 //*-*- elimination proper
7829 L60:
7830  for (j = 1; j <= n; ++j) {
7831  for (k = j; k <= n; ++k) { a[j + k*l] += fVERTpp[j-1]*fVERTq[k-1]; }
7832  }
7833  }
7834 //*-*- elements of left diagonal and unscaling
7835  for (j = 1; j <= n; ++j) {
7836  for (k = 1; k <= j; ++k) {
7837  a[k + j*l] = a[k + j*l]*fVERTs[k-1]*fVERTs[j-1];
7838  a[j + k*l] = a[k + j*l];
7839  }
7840  }
7841  return;
7842 //*-*- failure return
7843 L100:
7844  ifail = 1;
7845 } /* mnvert_ */
7846 
7847 ////////////////////////////////////////////////////////////////////////////////
7848 ///*-*-*-*-*-*-*-*-*-*-*-*Prints Warning messages*-*-*-*-*-*-*-*-*-*-*-*-*-*
7849 ///*-* =======================
7850 ///*-* If COPT='W', CMES is a WARning message from CORG.
7851 ///*-* If COPT='D', CMES is a DEBug message from CORG.
7852 ///*-* If SET WARnings is in effect (the default), this routine
7853 ///*-* prints the warning message CMES coming from CORG.
7854 ///*-* If SET NOWarnings is in effect, the warning message is
7855 ///*-* stored in a circular buffer of length kMAXMES.
7856 ///*-* If called with CORG=CMES='SHO', it prints the messages in
7857 ///*-* the circular buffer, FIFO, and empties the buffer.
7858 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
7859 
7860 void TMinuit::mnwarn(const char *copt1, const char *corg1, const char *cmes1)
7861 {
7862  TString copt = copt1;
7863  TString corg = corg1;
7864  TString cmes = cmes1;
7865 
7866  const Int_t kMAXMES = 10;
7867  Int_t ityp, i, ic, nm;
7868  TString englsh, ctyp;
7869 
7870  if (corg(0,3) != "SHO" || cmes(0,3) != "SHO") {
7871 
7872 //*-*- Either print warning or put in buffer
7873  if (copt == "W") {
7874  ityp = 1;
7875  if (fLwarn) {
7876  Printf(" MINUIT WARNING IN %s",(const char*)corg);
7877  Printf(" ============== %s",(const char*)cmes);
7878  return;
7879  }
7880  } else {
7881  ityp = 2;
7882  if (fLrepor) {
7883  Printf(" MINUIT DEBUG FOR %s",(const char*)corg);
7884  Printf(" =============== %s ",(const char*)cmes);
7885  return;
7886  }
7887  }
7888 //*-*- if appropriate flag is off, fill circular buffer
7889  if (fNwrmes[ityp-1] == 0) fIcirc[ityp-1] = 0;
7890  ++fNwrmes[ityp-1];
7891  ++fIcirc[ityp-1];
7892  if (fIcirc[ityp-1] > 10) fIcirc[ityp-1] = 1;
7893  ic = fIcirc[ityp-1];
7894  fOrigin[ic] = corg;
7895  fWarmes[ic] = cmes;
7896  fNfcwar[ic] = fNfcn;
7897  return;
7898  }
7899 
7900 //*-*- 'SHO WARnings', ask if any suppressed mess in buffer
7901  if (copt == "W") {
7902  ityp = 1;
7903  ctyp = "WARNING";
7904  } else {
7905  ityp = 2;
7906  ctyp = "*DEBUG*";
7907  }
7908  if (fNwrmes[ityp-1] > 0) {
7909  englsh = " WAS SUPPRESSED. ";
7910  if (fNwrmes[ityp-1] > 1) englsh = "S WERE SUPPRESSED.";
7911  Printf(" %5d MINUIT %s MESSAGE%s",fNwrmes[ityp-1]
7912  ,(const char*)ctyp,(const char*)englsh);
7913  nm = fNwrmes[ityp-1];
7914  ic = 0;
7915  if (nm > kMAXMES) {
7916  Printf(" ONLY THE MOST RECENT 10 WILL BE LISTED BELOW.");
7917  nm = kMAXMES;
7918  ic = fIcirc[ityp-1];
7919  }
7920  Printf(" CALLS ORIGIN MESSAGE");
7921  for (i = 1; i <= nm; ++i) {
7922  ++ic;
7923  if (ic > kMAXMES) ic = 1;
7924  Printf(" %6d %s %s", fNfcwar[ic],fOrigin[ic].Data(),fWarmes[ic].Data());
7925  }
7926  fNwrmes[ityp-1] = 0;
7927  Printf(" ");
7928  }
7929 } /* mnwarn_ */
7930 
7931 ////////////////////////////////////////////////////////////////////////////////
7932 ///*-*-*-*-*-*-*-*Calculates the WERR, external parameter errors*-*-*-*-*-*-*
7933 ///*-* ==============================================
7934 ///*-* and the global correlation coefficients, to be called
7935 ///*-* whenever a new covariance matrix is available.
7936 ///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
7937 
7939 {
7940  Double_t denom, ba, al, dx, du1, du2;
7941  Int_t ndex, ierr, i, j, k, l, ndiag, k1, iin;
7942 
7943 //*-*- calculate external error if v exists
7944  if (fISW[1] >= 1) {
7945  for (l = 1; l <= fNpar; ++l) {
7946  ndex = l*(l + 1) / 2;
7947  dx = TMath::Sqrt(TMath::Abs(fVhmat[ndex-1]*fUp));
7948  i = fNexofi[l-1];
7949  if (fNvarl[i-1] > 1) {
7950  al = fAlim[i-1];
7951  ba = fBlim[i-1] - al;
7952  du1 = al + 0.5*(TMath::Sin(fX[l-1] + dx) + 1)*ba - fU[i-1];
7953  du2 = al + 0.5*(TMath::Sin(fX[l-1] - dx) + 1)*ba - fU[i-1];
7954  if (dx > 1) du1 = ba;
7955  dx = 0.5*(TMath::Abs(du1) + TMath::Abs(du2));
7956  }
7957  fWerr[l-1] = dx;
7958  }
7959  }
7960 //*-*- global correlation coefficients
7961  if (fISW[1] >= 1) {
7962  for (i = 1; i <= fNpar; ++i) {
7963  fGlobcc[i-1] = 0;
7964  k1 = i*(i-1) / 2;
7965  for (j = 1; j <= i; ++j) {
7966  k = k1 + j;
7967  fP[i + j*fMaxpar - fMaxpar-1] = fVhmat[k-1];
7968  fP[j + i*fMaxpar - fMaxpar-1] = fP[i + j*fMaxpar - fMaxpar-1];
7969  }
7970  }
7971  mnvert(fP, fMaxint, fMaxint, fNpar, ierr);
7972  if (ierr == 0) {
7973  for (iin = 1; iin <= fNpar; ++iin) {
7974  ndiag = iin*(iin + 1) / 2;
7975  denom = fP[iin + iin*fMaxpar - fMaxpar-1]*fVhmat[ndiag-1];
7976  if (denom <= 1 && denom >= 0) fGlobcc[iin-1] = 0;
7977  else fGlobcc[iin-1] = TMath::Sqrt(1 - 1 / denom);
7978  }
7979  }
7980  }
7981 } /* mnwerr_ */
Double_t * fMNOTw
Definition: TMinuit.h:121
virtual void mnmnos()
*-*-*-*-*-*-*-*-*-*-*Performs a MINOS error analysis*-*-*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:5463
virtual void mnsimp()
*-*-*-*-*Minimization using the simplex method of Nelder and Mead*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:7503
const int nx
Definition: kalman.C:16
TMinuit()
*-*-*-*-*-*-*-*-*-*-*Minuit normal constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:341
Double_t * fBlim
Definition: TMinuit.h:77
Double_t * fXpt
Definition: TMinuit.h:104
TString fCword
Definition: TMinuit.h:176
virtual Int_t GetNumFreePars() const
returns the number of currently free parameters
Definition: TMinuit.cxx:865
double par[1]
Definition: unuranDistr.cxx:38
Int_t fMaxext
Definition: TMinuit.h:49
virtual void mnstat(Double_t &fmin, Double_t &fedm, Double_t &errdef, Int_t &npari, Int_t &nparx, Int_t &istat)
*-*-*-*-*Returns concerning the current status of the minimization*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:7710
Double_t fDcovar
Definition: TMinuit.h:62
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
virtual void mneval(Double_t anext, Double_t &fnext, Int_t &ierev)
*-*-*-*-*-*-*Evaluates the function being analyzed by MNCROS*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:2653
Int_t fIstrat
Definition: TMinuit.h:157
Int_t * fIpfix
Definition: TMinuit.h:136
virtual void mnprin(Int_t inkode, Double_t fval)
*-*-*-*Prints the values of the parameters at the time of the call*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:6384
Double_t * fGlobcc
Definition: TMinuit.h:81
virtual Int_t SetPrintLevel(Int_t printLevel=0)
set Minuit print level printlevel = -1 quiet (also suppresse all warnings) = 0 normal = 1 verbose ...
Definition: TMinuit.cxx:977
float xmin
Definition: THbookFile.cxx:93
Double_t * fP
Definition: TMinuit.h:98
virtual void mnexin(Double_t *pint)
*-*-*-*-*Transforms the external parameter values U to internal values*-*-* *-* =====================...
Definition: TMinuit.cxx:3187
Double_t * fPrho
Definition: TMinuit.h:102
TString fCstatu
Definition: TMinuit.h:174
virtual void mnhes1()
*-*-*-*Calculate first derivatives (GRD) and uncertainties (DGRD)*-*-*-*-*-* *-* ====================...
Definition: TMinuit.cxx:4285
virtual void mnvert(Double_t *a, Int_t l, Int_t m, Int_t n, Int_t &ifail)
*-*-*-*-*-*-*-*-*-*-*-*Inverts a symmetric matrix*-*-*-*-*-*-*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:7771
Implementation in C++ of the Minuit package written by F.
Definition: TMinuit.h:34
Double_t * fCOMDplist
Definition: TMinuit.h:130
Double_t Log(Double_t x)
Definition: TMath.h:526
int idb
Definition: THbookFile.cxx:91
Int_t fKe2cr
Definition: TMinuit.h:163
Double_t * fWord7
Definition: TMinuit.h:103
Ssiz_t Length() const
Definition: TString.h:390
TLine * line
virtual void mnemat(Double_t *emat, Int_t ndim)
Calculates the external error matrix from the internal matrix.
Definition: TMinuit.cxx:2534
Double_t * fXs
Definition: TMinuit.h:85
void(* fFCN)(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
Definition: TMinuit.h:185
Double_t * fGrds
Definition: TMinuit.h:93
Bool_t fLnewmn
Definition: TMinuit.h:168
virtual void mnwarn(const char *copt, const char *corg, const char *cmes)
*-*-*-*-*-*-*-*-*-*-*-*Prints Warning messages*-*-*-*-*-*-*-*-*-*-*-*-*-* *-* =======================...
Definition: TMinuit.cxx:7860
float ymin
Definition: THbookFile.cxx:93
Int_t fIdbg[11]
Definition: TMinuit.h:149
Int_t fIsyswr
Definition: TMinuit.h:139
TH1 * h
Definition: legend2.C:5
Int_t fItaur
Definition: TMinuit.h:156
virtual void mnline(Double_t *start, Double_t fstart, Double_t *step, Double_t slope, Double_t toler)
*-*-*-*-*-*-*-*-*-*Perform a line search from position START*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:4807
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1101
Double_t * fVhmat
Definition: TMinuit.h:96
virtual void mnseek()
*-*-*-*Performs a rough (but global) minimization by monte carlo search*-* *-* ======================...
Definition: TMinuit.cxx:6888
#define gROOT
Definition: TROOT.h:352
Int_t LoadPlugin()
Load the plugin library for this handler.
Int_t fNpagwd
Definition: TMinuit.h:141
Basic string class.
Definition: TString.h:137
Double_t * fMATUvline
Definition: TMinuit.h:114
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
Double_t * fGRADgf
Definition: TMinuit.h:110
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:63
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void mnderi()
*-*-*-*-*-*-*-*Calculates the first derivatives of FCN (GRD)*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:2210
virtual void mncros(Double_t &aopt, Int_t &iercr)
*-*-*-*-*-*-*-*-*-*-*Find point where MNEVAL=AMIN+UP*-*-*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:1828
virtual void mngrad()
*-*-*-*-*-*-*-*-*-*Interprets the SET GRAD command*-*-*-*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:3401
int nbins[3]
Double_t * fMNOTxdev
Definition: TMinuit.h:120
virtual void mnbins(Double_t a1, Double_t a2, Int_t naa, Double_t &bl, Double_t &bh, Int_t &nb, Double_t &bwid)
*-*-*-*-*-*-*-*-*-*-*Compute reasonable histogram intervals*-*-*-*-*-*-*-*-* *-* ====================...
Definition: TMinuit.cxx:1024
Double_t * fX
Definition: TMinuit.h:82
virtual void mnrset(Int_t iopt)
*-*-*-*-*-*-*-*Resets function value and errors to UNDEFINED*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:6728
TObject * fPlot
Definition: TMinuit.h:183
Long_t ExecPlugin(int nargs, const T &...params)
virtual void mntiny(volatile Double_t epsp1, Double_t &epsbak)
*-*-*-*-*-*-*-*To find the machine precision*-*-*-*-*-*-*-*-*-*-*-*-*-*-* *-* =======================...
Definition: TMinuit.cxx:7734
Int_t fNfcnlc
Definition: TMinuit.h:154
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
Int_t fNblock
Definition: TMinuit.h:150
TString fCtitl
Definition: TMinuit.h:175
Int_t fNstkwr
Definition: TMinuit.h:147
Int_t fIcirc[2]
Definition: TMinuit.h:160
Double_t * fXts
Definition: TMinuit.h:86
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:501
Double_t * fDirin
Definition: TMinuit.h:84
double beta(double x, double y)
Calculates the beta function.
virtual Int_t GetNumPars() const
returns the total number of parameters that have been defined as fixed or free.
Definition: TMinuit.cxx:874
TString fOrigin[kMAXWARN]
Definition: TMinuit.h:180
virtual Int_t FixParameter(Int_t parNo)
fix a parameter
Definition: TMinuit.cxx:829
Double_t * fErn
Definition: TMinuit.h:79
virtual Int_t Eval(Int_t npar, Double_t *grad, Double_t &fval, Double_t *par, Int_t flag)
Evaluate the minimisation function Input parameters: npar: number of currently variable parameters pa...
Definition: TMinuit.cxx:802
virtual void mneig(Double_t *a, Int_t ndima, Int_t n, Int_t mits, Double_t *work, Double_t precis, Int_t &ifault)
*-*-*-*-*-*-*-*-*-*-*-*Compute matrix eigen values*-*-*-*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:2339
void SetParamPtrs(void *paramArr, Int_t nparam=-1)
ParamArr is an array containing the function argument values.
const char * Data() const
Definition: TString.h:349
virtual void mnmigr()
*-*-*-*-*-*-*-*-*Performs a local function minimization*-*-*-*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:5122
virtual void SetFCN(void *fcn)
*-*-*-*-*-*-*To set the address of the minimization function*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:955
virtual void mnfree(Int_t k)
*-*-*-*Restores one or more fixed parameter(s) to variable status*-*-*-*-*-* *-* ====================...
Definition: TMinuit.cxx:3294
Double_t * fYpt
Definition: TMinuit.h:105
static const double x2[5]
Double_t fEpsmac
Definition: TMinuit.h:63
Int_t * fNexofi
Definition: TMinuit.h:135
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
Int_t fMaxint
Definition: TMinuit.h:47
void Class()
Definition: Class.C:29
Int_t fNpar
Definition: TMinuit.h:48
Double_t * fPstar
Definition: TMinuit.h:99
Int_t fKe1cr
Definition: TMinuit.h:162
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Double_t * fVERTq
Definition: TMinuit.h:127
Double_t fUndefi
Definition: TMinuit.h:67
virtual void mncrck(TString crdbuf, Int_t maxcwd, TString &comand, Int_t &lnc, Int_t mxp, Double_t *plist, Int_t &llist, Int_t &ierr, Int_t isyswr)
*-*-*-*-*-*-*-*-*-*-*-*Cracks the free-format input*-*-*-*-*-*-*-*-*-*-*-*-* *-* ====================...
Definition: TMinuit.cxx:1706
const int ny
Definition: kalman.C:17
Double_t fBigedm
Definition: TMinuit.h:68
Int_t fIstkwr[10]
Definition: TMinuit.h:146
virtual void mnrn15(Double_t &val, Int_t &inseed)
*-*-*-*-*-*-*This is a super-portable random number generator*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:6699
Double_t * fSIMPy
Definition: TMinuit.h:126
virtual TObject * Contour(Int_t npoints=10, Int_t pa1=0, Int_t pa2=1)
Creates a TGraph object describing the n-sigma contour of a TMinuit fit.
Definition: TMinuit.cxx:654
Double_t Log10(Double_t x)
Definition: TMath.h:529
virtual ~TMinuit()
*-*-*-*-*-*-*-*-*-*-*Minuit default destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:493
static const double x4[22]
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
Definition: vector.h:450
Int_t fMaxpar5
Definition: TMinuit.h:51
virtual void DeleteArrays()
*-*-*-*-*-*-*-*-*-*-*-*Delete internal Minuit arrays*-*-*-*-*-*-*-*-* *-* ===========================...
Definition: TMinuit.cxx:710
std::vector< std::vector< double > > Data
virtual void mncuve()
*-*-*-*-*-*-*-*Makes sure that the current point is a local minimum*-*-*-*-* *-* ====================...
Definition: TMinuit.cxx:2161
Double_t fAmin
Definition: TMinuit.h:56
Double_t * fGrd
Definition: TMinuit.h:88
Int_t fNfcnfr
Definition: TMinuit.h:155
Double_t * fAlim
Definition: TMinuit.h:76
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:63
XFontStruct * id
Definition: TGX11.cxx:108
virtual void BuildArrays(Int_t maxpar=15)
*-*-*-*-*-*-*Create internal Minuit arrays for the maxpar parameters*-*-*-* *-* =====================...
Definition: TMinuit.cxx:509
Method or function calling interface.
Definition: TMethodCall.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
Double_t * fPARSplist
Definition: TMinuit.h:131
Double_t fYdircr
Definition: TMinuit.h:73
TObject * fObjectFit
Definition: TMinuit.h:182
Double_t * fGsteps
Definition: TMinuit.h:95
Int_t * fNvarl
Definition: TMinuit.h:133
virtual void mnmnot(Int_t ilax, Int_t ilax2, Double_t &val2pl, Double_t &val2mi)
*-*-*-*-*-*Performs a MINOS error analysis on one parameter*-*-*-*-*-*-*-*-* *-* ====================...
Definition: TMinuit.cxx:5539
Int_t fNstkrd
Definition: TMinuit.h:145
Int_t fMaxpar1
Definition: TMinuit.h:54
Double_t * fPbar
Definition: TMinuit.h:101
Double_t fYmidcr
Definition: TMinuit.h:71
Double_t * fSEEKxmid
Definition: TMinuit.h:124
TString fCfrom
Definition: TMinuit.h:173
Int_t fNewpag
Definition: TMinuit.h:143
virtual Int_t DefineParameter(Int_t parNo, const char *name, Double_t initVal, Double_t initErr, Double_t lowerLimit, Double_t upperLimit)
Define a parameter.
Definition: TMinuit.cxx:696
double gamma(double x)
virtual void mncont(Int_t ke1, Int_t ke2, Int_t nptu, Double_t *xptu, Double_t *yptu, Int_t &ierrf)
*-*-*-*-*-*-*Find points along a contour where FCN is minimum*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:1424
float ymax
Definition: THbookFile.cxx:93
Int_t fNfcnmx
Definition: TMinuit.h:153
Double_t * fVERTpp
Definition: TMinuit.h:129
TString fCundef
Definition: TMinuit.h:177
TPaveText * pt
Int_t fNpfix
Definition: TMinuit.h:44
ROOT::R::TRInterface & r
Definition: Object.C:4
TString * fCpnam
Character to be plotted at the X,Y contour positions.
Definition: TMinuit.h:172
Double_t * fG2
Definition: TMinuit.h:89
Double_t fEpsi
Definition: TMinuit.h:60
XPoint xy[kMAXMK]
Definition: TGX11.cxx:122
Double_t * fSEEKxbest
Definition: TMinuit.h:125
Int_t fMaxpar2
Definition: TMinuit.h:53
virtual void mncler()
*-*-*-*-*-*-*-*-*-*-*Resets the parameter list to UNDEFINED*-*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:1132
virtual void mnparm(Int_t k, TString cnamj, Double_t uk, Double_t wk, Double_t a, Double_t b, Int_t &ierflg)
*-*-*-*-*-*-*-*-*Implements one parameter definition*-*-*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:5739
virtual Int_t GetParameter(Int_t parNo, Double_t &currentValue, Double_t &currentError) const
return parameter value and error
Definition: TMinuit.cxx:843
virtual void mnfixp(Int_t iint, Int_t &ierr)
*-*-*-*-*-*-*Removes parameter IINT from the internal parameter list*-*-* *-* =======================...
Definition: TMinuit.cxx:3206
Double_t fXmidcr
Definition: TMinuit.h:70
Int_t fStatus
Definition: TMinuit.h:161
virtual void mncalf(Double_t *pvec, Double_t &ycalf)
*-*-*-*-*-*-*-*-*-*Transform FCN to find further minima*-*-*-*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:1098
Double_t * fWerr
Definition: TMinuit.h:80
Double_t * fMIGRgs
Definition: TMinuit.h:117
char * fChpt
Definition: TMinuit.h:171
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2321
Bool_t fLnolim
Definition: TMinuit.h:167
Double_t * fDirins
Definition: TMinuit.h:87
TMarker * m
Definition: textangle.C:8
Double_t * fIMPRdsav
Definition: TMinuit.h:112
char * Form(const char *fmt,...)
Double_t * fPstst
Definition: TMinuit.h:100
virtual Int_t SetErrorDef(Double_t up)
To get the n-sigma contour the error def parameter "up" has to set to n^2.
Definition: TMinuit.cxx:910
Bool_t fLrepor
Definition: TMinuit.h:165
Double_t * fIMPRy
Definition: TMinuit.h:113
Double_t fApsi
Definition: TMinuit.h:61
TLine * l
Definition: textangle.C:4
const std::string sname
Definition: testIO.cxx:45
Double_t * fXt
Definition: TMinuit.h:83
TMethodCall * GetMethodCall() const
Definition: TMinuit.h:200
float xmax
Definition: THbookFile.cxx:93
TMethodCall * fMethodCall
Definition: TMinuit.h:184
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TMinuit.cxx:594
int ncall
Definition: stressTF1.cxx:20
Double_t fUpdflt
Definition: TMinuit.h:69
Double_t * fVERTs
Definition: TMinuit.h:128
virtual void mnerrs(Int_t number, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &gcc)
*-*-*-*-*-*-*-*-*-*Utility routine to get MINOS errors*-*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:2610
virtual void mnhess()
*-*-*-*-*-*Calculates the full second-derivative matrix of FCN*-*-*-*-*-*-*-* *-* ===================...
Definition: TMinuit.cxx:4059
Double_t fFval3
Definition: TMinuit.h:59
Double_t * fGstep
Definition: TMinuit.h:90
Int_t fIsyssa
Definition: TMinuit.h:140
Double_t * fMIGRflnu
Definition: TMinuit.h:115
TGraphErrors * gr
Definition: legend1.C:25
Bool_t fGraphicsMode
Definition: TMinuit.h:170
#define Printf
Definition: TGeoToOCC.h:18
Bool_t fLwarn
Definition: TMinuit.h:164
Double_t * fErp
Definition: TMinuit.h:78
Double_t Cos(Double_t)
Definition: TMath.h:424
Int_t * fNiofex
Definition: TMinuit.h:134
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
#define R__LOCKGUARD2(mutex)
virtual Int_t GetNumFixedPars() const
returns the number of currently fixed parameters
Definition: TMinuit.cxx:857
virtual void mnpsdf()
*-*-*-*-*-*Calculates the eigenvalues of v to see if positive-def*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:6575
virtual void mndxdi(Double_t pint, Int_t ipar, Double_t &dxdi)
*-*-*-*Calculates the transformation factor between ext/internal values*-* *-* ======================...
Definition: TMinuit.cxx:2326
long Long_t
Definition: RtypesCore.h:50
Int_t fNpagln
Definition: TMinuit.h:142
Double_t * fMIGRxxs
Definition: TMinuit.h:119
Double_t fEDM
Definition: TMinuit.h:58
Double_t * fCONTgcc
Definition: TMinuit.h:107
Double_t * fFIXPyy
Definition: TMinuit.h:109
virtual void mnamin()
*-*-*-*-*-*-*-*-*-*-*-*-*Initialize AMIN*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* *-* =============== *-*C Ca...
Definition: TMinuit.cxx:998
Int_t fNfcn
Definition: TMinuit.h:152
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:279
double f(double x)
Double_t * fMNOTgcc
Definition: TMinuit.h:122
Double_t * fCONTw
Definition: TMinuit.h:108
virtual void mnscan()
*-*-*-*-*Scans the values of FCN as a function of one parameter*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:6777
TString fWarmes[kMAXWARN]
Definition: TMinuit.h:181
double Double_t
Definition: RtypesCore.h:55
virtual void mnhelp(TString comd)
*-*-*-*-*-*-*-*HELP routine for MINUIT interactive commands*-*-*-*-*-*-*-*-* *-* ====================...
Definition: TMinuit.cxx:3479
void InteractiveFCNm(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
*-*-*-*-*-*-*Static function called when SetFCN is called in interactive mode *-* ===================...
Definition: TMinuit.cxx:933
virtual Int_t Release(Int_t parNo)
release a parameter
Definition: TMinuit.cxx:896
Int_t fNfcwar[20]
Definition: TMinuit.h:159
Double_t * fG2s
Definition: TMinuit.h:94
Double_t y[n]
Definition: legend1.C:17
Bool_t fLimset
Definition: TMinuit.h:166
virtual void mnpfit(Double_t *parx2p, Double_t *pary2p, Int_t npar2p, Double_t *coef2p, Double_t &sdev2p)
*-*-*-*-*-*-*-*-*-*To fit a parabola to npar2p points*-*-*-*-*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:6032
Double_t * fU
Definition: TMinuit.h:75
virtual void mnlims()
*-*-*-*Interprets the SET LIM command, to reset the parameter limits*-*-*-* *-* =====================...
Definition: TMinuit.cxx:4686
virtual void mnexcm(const char *comand, Double_t *plist, Int_t llist, Int_t &ierflg)
*-*-*-*-*-*Interprets a command and takes appropriate action*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:2699
virtual void mncntr(Int_t ke1, Int_t ke2, Int_t &ierrf)
*-*-*-*-*Print function contours in two variables, on line printer*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:1163
Int_t fMaxcpt
Definition: TMinuit.h:52
virtual void SetMaxIterations(Int_t maxiter=500)
Definition: TMinuit.h:272
virtual void mncomd(const char *crdbin, Int_t &icondn)
*-*-*-*-*-*-*-*-*-*-*Reads a command string and executes*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:1341
#define name(a, b)
Definition: linkTestLib0.cpp:5
Double_t * fGin
Definition: TMinuit.h:91
virtual Int_t Command(const char *command)
execute a Minuit command Equivalent to MNEXCM except that the command is given as a character string...
Definition: TMinuit.cxx:627
virtual void mninit(Int_t i1, Int_t i2, Int_t i3)
*-*-*-*-*-*Main initialization member function for MINUIT*-*-*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:4595
Mother of all ROOT objects.
Definition: TObject.h:58
Double_t * fMIGRstep
Definition: TMinuit.h:116
virtual Int_t Migrad()
invokes the MIGRAD minimizer
Definition: TMinuit.cxx:882
Int_t fIcomnd
Definition: TMinuit.h:151
virtual void mnpars(TString &crdbuf, Int_t &icondn)
*-*-*-*-*-*-*-*Implements one parameter definition*-*-*-*-*-*-*-*-*-*-*-*-* *-* =========== =========...
Definition: TMinuit.cxx:5942
Double_t * fVthmat
Definition: TMinuit.h:97
virtual void mnplot(Double_t *xpt, Double_t *ypt, char *chpt, Int_t nxypt, Int_t npagwd, Int_t npagln)
*-*-*-*Plots points in array xypt onto one page with labelled axes*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:6146
virtual void mnpint(Double_t &pexti, Int_t i, Double_t &pinti)
*-*-*-*-*-*-*Calculates the internal parameter value PINTI*-*-*-*-*-*-*-* *-* =======================...
Definition: TMinuit.cxx:6094
virtual void mnsave()
*-*-*-*Writes current parameter values and step sizes onto file ISYSSA*-*-* *-* =====================...
Definition: TMinuit.cxx:6763
virtual void mninex(Double_t *pint)
*-*-*-*-*Transforms from internal coordinates (PINT) to external (U)*-*-*-* *-* =====================...
Definition: TMinuit.cxx:4574
Double_t * fPSDFs
Definition: TMinuit.h:123
const char charal[29]
Definition: TMinuit.cxx:333
double f2(const double *x)
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition: TMethodCall.h:68
Double_t * fMIGRvg
Definition: TMinuit.h:118
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
Double_t fVlimlo
Definition: TMinuit.h:65
Double_t Sin(Double_t)
Definition: TMath.h:421
TF1 * f1
Definition: legend1.C:11
Double_t fEpsma2
Definition: TMinuit.h:64
TMinuit * gMinuit
Definition: TMinuit.cxx:331
virtual void mnmatu(Int_t kode)
*-*-*-*-*-*-*-*Prints the covariance matrix v when KODE=1*-*-*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:5042
virtual void mnset()
*-*-*-*-*Interprets the commands that start with SET and SHOW*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:6984
Double_t ASin(Double_t)
Definition: TMath.h:439
Double_t fUp
Definition: TMinuit.h:57
Int_t fEmpty
Definition: TMinuit.h:45
Double_t fXdircr
Definition: TMinuit.h:72
int * iq
Definition: THbookFile.cxx:86
Bool_t mnunpt(TString &cfname)
*-*-*-*-*-*Returns .TRUE.
Definition: TMinuit.cxx:7744
Int_t fMaxpar
Definition: TMinuit.h:46
virtual void mnrazz(Double_t ynew, Double_t *pnew, Double_t *y, Int_t &jh, Int_t &jl)
*-*-*-*-*Called only by MNSIMP (and MNIMPR) to add a new point*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:6650
virtual const char * Getp2f2funcname(void *) const
Definition: TInterpreter.h:213
double result[121]
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:504
const Bool_t kTRUE
Definition: Rtypes.h:91
Double_t * fDgrd
Definition: TMinuit.h:92
Bool_t fLphead
Definition: TMinuit.h:169
TString fCvrsn
Definition: TMinuit.h:178
Int_t fIsysrd
Definition: TMinuit.h:138
Int_t fNu
Definition: TMinuit.h:137
Double_t * fHESSyy
Definition: TMinuit.h:111
const Int_t n
Definition: legend1.C:16
Int_t fNwrmes[2]
Definition: TMinuit.h:158
Double_t fVlimhi
Definition: TMinuit.h:66
virtual void mnpout(Int_t iuext, TString &chnam, Double_t &val, Double_t &err, Double_t &xlolim, Double_t &xuplim, Int_t &iuint) const
*-*-*-*Provides the user with information concerning the current status*-*-* *-* ====================...
Definition: TMinuit.cxx:6328
TString fCovmes[4]
Definition: TMinuit.h:179
Definition: drr.cxx:518
virtual void mnimpr()
*-*-*-*-*-*-*Attempts to improve on a good local minimum*-*-*-*-*-*-*-*-*-* *-* =====================...
Definition: TMinuit.cxx:4362
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition: TString.cxx:1058
Int_t fISW[7]
Definition: TMinuit.h:148
static const double x3[11]
Double_t ATan(Double_t)
Definition: TMath.h:451
virtual void mnwerr()
*-*-*-*-*-*-*-*Calculates the WERR, external parameter errors*-*-*-*-*-*-* *-* ======================...
Definition: TMinuit.cxx:7938
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904