GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4FitMinuitResult.cxx
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4FitMinuitResult.h"
15 
16 #include <iostream>
17 
18 #include "TMinuit.h"
19 #include "TArrayC.h"
20 #include "TArrayD.h"
21 
23  : TNamed(), ParValues(nullptr), ParError(nullptr), EPLUS(nullptr), EMINUS(nullptr), EPARAB(nullptr), GLOBCC(nullptr),
24  ERRORMATRIX(nullptr), CONTOX(nullptr), CONTOY(nullptr), CONTOCH(nullptr)
25 {
26 }
27 
28 TGo4FitMinuitResult::TGo4FitMinuitResult(const char *iName, const char *iTitle)
29  : TNamed(iName, iTitle), ParValues(nullptr), ParError(nullptr), EPLUS(nullptr), EMINUS(nullptr), EPARAB(nullptr),
30  GLOBCC(nullptr), ERRORMATRIX(nullptr), CONTOX(nullptr), CONTOY(nullptr), CONTOCH(nullptr)
31 {
32 }
33 
35 {
36  if (ParValues)
37  delete ParValues;
38  if (ParError)
39  delete ParError;
40  if (EPLUS)
41  delete EPLUS;
42  if (EMINUS)
43  delete EMINUS;
44  if (EPARAB)
45  delete EPARAB;
46  if (GLOBCC)
47  delete GLOBCC;
48  if (ERRORMATRIX)
49  delete ERRORMATRIX;
50  if (CONTOX)
51  delete CONTOX;
52  if (CONTOY)
53  delete CONTOY;
54  if (CONTOCH)
55  delete CONTOCH;
56 }
57 
58 void TGo4FitMinuitResult::CallMNSTAT(TMinuit *fMinuit)
59 {
60  fMinuit->mnstat(FMIN, FEDM, ERRDEF, NPARI, NPARX, ISTAT);
61 }
62 
63 void TGo4FitMinuitResult::CallMNPOUT(TMinuit *fMinuit, Int_t nPars)
64 {
65  if (ParValues)
66  delete ParValues;
67  if (ParError)
68  delete ParError;
69 
70  ParValues = new TArrayD(nPars);
71  ParError = new TArrayD(nPars);
72  for (Int_t n = 0; n < nPars; n++)
73  fMinuit->GetParameter(n, (*ParValues)[n], (*ParError)[n]);
74 }
75 
76 void TGo4FitMinuitResult::CallMNERRS(TMinuit *fMinuit, Int_t nPars)
77 {
78  if (EPLUS)
79  delete EPLUS;
80  if (EMINUS)
81  delete EMINUS;
82  if (EPARAB)
83  delete EPARAB;
84  if (GLOBCC)
85  delete GLOBCC;
86 
87  EPLUS = new TArrayD(nPars);
88  EMINUS = new TArrayD(nPars);
89  EPARAB = new TArrayD(nPars);
90  GLOBCC = new TArrayD(nPars);
91 
92  for (Int_t n = 0; n < nPars; n++)
93  fMinuit->mnerrs(n, (*EPLUS)[n], (*EMINUS)[n], (*EPARAB)[n], (*GLOBCC)[n]);
94 }
95 
96 void TGo4FitMinuitResult::CallMNEMAT(TMinuit *fMinuit, Int_t nPars, Bool_t DoTransform)
97 {
98  if (ERRORMATRIX)
99  delete ERRORMATRIX;
100 
101  // ERRORMATRIX = new TMatrixD(nPars,nPars);
102  // fMinuit->mnemat(ERRORMATRIX->GetElements(), nPars);
103 
104  Double_t *matrix = new Double_t[nPars * nPars];
105  fMinuit->mnemat(matrix, nPars);
106  ERRORMATRIX = new TMatrixD(nPars, nPars, matrix);
107 
108  if (DoTransform)
109  for (Int_t npar = 0; npar < nPars; npar++) {
110  TString name;
111  Double_t val, err, bnd1, bnd2;
112  Int_t fixed = 0;
113  fMinuit->mnpout(npar, name, val, err, bnd1, bnd2, fixed);
114 
115  if (fixed == 0) {
116  for (Int_t n = nPars - 2; n >= npar - 1; n--)
117  for (Int_t i = 0; i < nPars; i++)
118  (*ERRORMATRIX)(i, n + 1) = (*ERRORMATRIX)(i, n);
119  for (Int_t i = 0; i < nPars; i++)
120  (*ERRORMATRIX)(i, npar - 1) = 0;
121 
122  for (Int_t n = nPars - 2; n >= npar - 1; n--)
123  for (Int_t i = 0; i < nPars; i++)
124  (*ERRORMATRIX)(n + 1, i) = (*ERRORMATRIX)(n, i);
125  for (Int_t i = 0; i < nPars; i++)
126  (*ERRORMATRIX)(npar - 1, i) = 0;
127  }
128  }
129 
130  delete[] matrix;
131 }
132 
134 {
135  Int_t sz = strlen(fMinuit->fChpt);
136  if (sz == 0)
137  return;
138  CONTOX = new TArrayD(sz);
139  CONTOY = new TArrayD(sz);
140  CONTOCH = new TArrayC(sz);
141  for (Int_t i = 0; i < sz; i++) {
142  (*CONTOX)[i] = fMinuit->fXpt[i];
143  (*CONTOY)[i] = fMinuit->fYpt[i];
144  (*CONTOCH)[i] = fMinuit->fChpt[i];
145  }
146 }
147 
148 void TGo4FitMinuitResult::Print(Option_t *option) const
149 {
150  TNamed::Print(option);
151  std::cout << std::endl << "Minuit status:" << std::endl;
152  std::cout << " The best function value found so far " << FMIN << std::endl;
153  std::cout << " The estimated vertical distance remaining to minimum " << FEDM << std::endl;
154  std::cout << " The value of UP defining parameter uncertaintiesd " << ERRDEF << std::endl;
155  std::cout << " The number of currently variable parameters " << NPARI << std::endl;
156  std::cout << " The highest defined parameter number " << NPARX << std::endl;
157  std::cout << " Goodness of covariance matrix: " << std::endl << " ";
158  switch (ISTAT) {
159  case 1: std::cout << "Diagonal approximation only, not accurate" << std::endl; break;
160  case 2: std::cout << "Full matrix, but forced positive-defined" << std::endl; break;
161  case 3: std::cout << "Full accurate covariance matrix (after MIGRAD)" << std::endl; break;
162  default: std::cout << "Not calculated at all" << std::endl;
163  }
164 
165  if (ParValues && ParError) {
166  std::cout << "Current parameters valules and errors:" << std::endl;
167  for (Int_t n = 0; n < ParValues->GetSize(); n++)
168  std::cout << " " << n << " " << ParValues->At(n) << " " << ParError->At(n) << std::endl;
169  }
170 
171  if (EPLUS && EMINUS && EPARAB && GLOBCC) {
172  std::cout << "Parameters errors, defined by MINOS routine" << std::endl;
173  std::cout << " NUM EPLUS EMINUS EPARAB GLOBCC" << std::endl;
174  for (Int_t n = 0; n < EPLUS->GetSize(); n++)
175  std::cout << " " << n << " " << EPLUS->At(n) << " " << EMINUS->At(n) << " " << EPARAB->At(n) << " "
176  << GLOBCC->At(n) << std::endl;
177  }
178 
179  if (ERRORMATRIX) {
180  std::cout << "Error matrix" << std::endl;
181  ERRORMATRIX->Print();
182  }
183 
184  std::cout << std::endl;
185 }
void Print(Option_t *option="") const override
void GetContourPlot(TMinuit *fMinuit)
void CallMNERRS(TMinuit *fMinuit, Int_t nPars)
void CallMNEMAT(TMinuit *fMinuit, Int_t nPars, Bool_t DoTransform=kTRUE)
void CallMNSTAT(TMinuit *fMinuit)
void CallMNPOUT(TMinuit *fMinuit, Int_t nPars)