GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4FitMinuitResult.cxx
Go to the documentation of this file.
1 // $Id: TGo4FitMinuitResult.cxx 2769 2020-04-16 14:54:23Z linev $
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(),
24  ParValues(0),
25  ParError(0),
26  EPLUS(0),
27  EMINUS(0),
28  EPARAB(0),
29  GLOBCC(0),
30  ERRORMATRIX(0),
31  CONTOX(0),
32  CONTOY(0),
33  CONTOCH(0) {
34 }
35 
36 TGo4FitMinuitResult::TGo4FitMinuitResult(const char* iName, const char* iTitle) :
37  TNamed(iName,iTitle),
38  ParValues(0),
39  ParError(0),
40  EPLUS(0),
41  EMINUS(0),
42  EPARAB(0),
43  GLOBCC(0),
44  ERRORMATRIX(0),
45  CONTOX(0),
46  CONTOY(0),
47  CONTOCH(0) {
48 }
49 
51  if(ParValues) delete ParValues;
52  if(ParError) delete ParError;
53  if(EPLUS) delete EPLUS;
54  if(EMINUS) delete EMINUS;
55  if(EPARAB) delete EPARAB;
56  if(GLOBCC) delete GLOBCC;
57  if(ERRORMATRIX) delete ERRORMATRIX;
58  if(CONTOX) delete CONTOX;
59  if(CONTOY) delete CONTOY;
60  if(CONTOCH) delete CONTOCH;
61 }
62 
63 void TGo4FitMinuitResult::CallMNSTAT(TMinuit* fMinuit) {
64  fMinuit->mnstat(FMIN,FEDM,ERRDEF,NPARI,NPARX,ISTAT);
65 }
66 
67 void TGo4FitMinuitResult::CallMNPOUT(TMinuit* fMinuit, Int_t nPars) {
68  if(ParValues) delete ParValues;
69  if(ParError) delete ParError;
70 
71  ParValues = new TArrayD(nPars);
72  ParError = new TArrayD(nPars);
73  for(Int_t n=0;n<nPars;n++)
74  fMinuit->GetParameter(n, (*ParValues)[n], (*ParError)[n]);
75 }
76 
77 void TGo4FitMinuitResult::CallMNERRS(TMinuit* fMinuit, Int_t nPars) {
78  if(EPLUS) delete EPLUS;
79  if(EMINUS) delete EMINUS;
80  if(EPARAB) delete EPARAB;
81  if(GLOBCC) delete GLOBCC;
82 
83  EPLUS = new TArrayD(nPars);
84  EMINUS = new TArrayD(nPars);
85  EPARAB = new TArrayD(nPars);
86  GLOBCC = new TArrayD(nPars);
87 
88  for(Int_t n=0;n<nPars;n++)
89  fMinuit->mnerrs(n, (*EPLUS)[n], (*EMINUS)[n], (*EPARAB)[n], (*GLOBCC)[n]);
90 
91 }
92 
93 void TGo4FitMinuitResult::CallMNEMAT(TMinuit* fMinuit, Int_t nPars, Bool_t DoTransform)
94 {
95  if(ERRORMATRIX) delete ERRORMATRIX;
96 
97 // ERRORMATRIX = new TMatrixD(nPars,nPars);
98 // fMinuit->mnemat(ERRORMATRIX->GetElements(), nPars);
99 
100  Double_t* matrix = new Double_t[nPars*nPars];
101  fMinuit->mnemat(matrix, nPars);
102  ERRORMATRIX = new TMatrixD(nPars, nPars, matrix);
103 
104  if(DoTransform)
105  for(Int_t npar=0;npar<nPars;npar++) {
106  TString name;
107  Double_t val,err,bnd1,bnd2;
108  Int_t fixed = 0;
109  fMinuit->mnpout(npar,name,val,err,bnd1,bnd2,fixed);
110 
111  if (fixed==0) {
112  for(Int_t n=nPars-2;n>=npar-1;n--)
113  for(Int_t i=0;i<nPars;i++)
114  (*ERRORMATRIX)(i,n+1) = (*ERRORMATRIX)(i,n);
115  for(Int_t i=0;i<nPars;i++)
116  (*ERRORMATRIX)(i,npar-1) = 0;
117 
118  for(Int_t n=nPars-2;n>=npar-1;n--)
119  for(Int_t i=0;i<nPars;i++)
120  (*ERRORMATRIX)(n+1,i) = (*ERRORMATRIX)(n,i);
121  for(Int_t i=0;i<nPars;i++)
122  (*ERRORMATRIX)(npar-1,i) = 0;
123  }
124  }
125 
126  delete[] matrix;
127 }
128 
129 void TGo4FitMinuitResult::GetContourPlot(TMinuit* fMinuit) {
130  Int_t sz = strlen(fMinuit->fChpt);
131  if (sz == 0) return;
132  CONTOX = new TArrayD(sz);
133  CONTOY = new TArrayD(sz);
134  CONTOCH = new TArrayC(sz);
135  for (Int_t i=0;i<sz;i++) {
136  (*CONTOX)[i] = fMinuit->fXpt[i];
137  (*CONTOY)[i] = fMinuit->fYpt[i];
138  (*CONTOCH)[i] = fMinuit->fChpt[i];
139  }
140 
141 }
142 
143 void TGo4FitMinuitResult::Print(Option_t* option) const {
144  TNamed::Print(option);
145  std::cout << std::endl << "Minuit status:" << std::endl;
146  std::cout << " The best function value found so far " << FMIN << std::endl;
147  std::cout << " The estimated vertical distance remaining to minimum " << FEDM << std::endl;
148  std::cout << " The value of UP defining parameter uncertaintiesd " << ERRDEF << std::endl;
149  std::cout << " The number of currently variable parameters " << NPARI << std::endl;
150  std::cout << " The highest defined parameter number " << NPARX << std::endl;
151  std::cout << " Goodness of covariance matrix: " << std::endl << " ";
152  switch (ISTAT) {
153  case 1: std::cout << "Diagonal approximation only, not accurate" << std::endl; break;
154  case 2: std::cout << "Full matrix, but forced positive-defined" << std::endl; break;
155  case 3: std::cout << "Full accurate covariance matrix (after MIGRAD)" << std::endl; break;
156  default: std::cout << "Not calculated at all" << std::endl;
157  }
158 
159  if (ParValues && ParError) {
160  std::cout << "Current parameters valules and errors:" << std::endl;
161  for(Int_t n=0;n<ParValues->GetSize();n++)
162  std::cout << " " << n << " " << ParValues->At(n) << " " << ParError->At(n) << std::endl;
163  }
164 
165  if (EPLUS && EMINUS && EPARAB && GLOBCC) {
166  std::cout << "Parameters errors, defined by MINOS routine" << std::endl;
167  std::cout << " NUM EPLUS EMINUS EPARAB GLOBCC" << std::endl;
168  for(Int_t n=0;n<EPLUS->GetSize();n++)
169  std::cout << " " << n << " " << EPLUS->At(n) << " " << EMINUS->At(n) << " " << EPARAB->At(n) << " " << GLOBCC->At(n) << std::endl;
170  }
171 
172  if (ERRORMATRIX) {
173  std::cout << "Error matrix" << std::endl;
174  ERRORMATRIX->Print();
175  }
176 
177  std::cout << std::endl;
178 }
void GetContourPlot(TMinuit *fMinuit)
virtual void Print(Option_t *option) const
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)