Logo ROOT   6.13/01
Reference Guide
TMinuit2TraceObject.cxx
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Author: L. Moneta 2012
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2012 LCG ROOT Math team, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 #include "TMinuit2TraceObject.h"
11 #include "TH1.h"
12 #include "TVirtualPad.h"
13 #include "TList.h"
15 #include "Minuit2/MinimumState.h"
16 
17 ClassImp(TMinuit2TraceObject);
18 
19 TMinuit2TraceObject::TMinuit2TraceObject(int parNumber) : ROOT::Minuit2::MnTraceObject(parNumber),
20  TNamed("Minuit2TraceObject","ROOT Trace Object for Minuit2"),
21  fIterOffset(0),
22  fHistoFval(0), fHistoEdm(0), fHistoParList(0),
23  fOldPad(0), fMinuitPad(0)
24 {
25 }
26 
28  // rest previous pad but do not delete histograms
29  if (fOldPad && gPad && fOldPad != gPad) gPad = fOldPad;
30  int niter = -1;
31  if (fHistoFval) {
32  niter = int(fHistoFval->GetEntries()+0.5);
33  fHistoFval->GetXaxis()->SetRange(1,niter);
34  }
35  if (fHistoEdm) fHistoEdm->GetXaxis()->SetRange(1,niter);
36  if (fHistoParList) {
37  for (int i=0; i < fHistoParList->GetSize(); ++i) {
38  TH1 * h1 = (TH1*) fHistoParList->At(i);
39  if (h1) h1->GetXaxis()->SetRange(1,niter);
40  }
41  }
42 }
43 
45 
47 
48  fIterOffset = 0;
49 
50  // build debug histogram
51  if (fHistoFval) delete fHistoFval;
52  if (fHistoEdm) delete fHistoEdm;
53  if (fHistoParList) { fHistoParList->Delete(); delete fHistoParList; }
54  if (fMinuitPad) delete fMinuitPad;
55 
56  fHistoFval = new TH1D("minuit2_hist_fval","Function Value/iteration",2,0,1);
57  fHistoEdm = new TH1D("minuit2_hist_edm","Edm/iteration",2,0,1);
58  fHistoFval->SetCanExtend(TH1::kAllAxes);
59  fHistoEdm->SetCanExtend(TH1::kAllAxes);
60 
61  // create histos for all parameters
62  fHistoParList = new TList();
63  for (unsigned int ipar = 0; ipar < state.Params().size(); ++ipar) {
64  if (state.Parameter(ipar).IsFixed() || state.Parameter(ipar).IsConst() ) continue;
65  TH1D * h1 = new TH1D(TString::Format("minuit2_hist_par%d",ipar),TString::Format("Value of %s/iteration",state.Name(ipar)),2,0,1);
66  h1->SetCanExtend(TH1::kAllAxes);
67  fHistoParList->Add(h1);
68  }
69 
70 
71 
72  if (gPad) fOldPad = gPad;
73 
74  //fMinuitPad = new TCanvas("c1_minuit2","TMinuit2 Progress",2);
75  // fMinuitPad->Divide(1,3);
76  // fMinuitPad->cd(1); fHistoFval->Draw();
77  // fMinuitPad->cd(2); fHistoEdm->Draw();
78  // fMinuitPad->cd(3); fHistoPar->Draw();
79  fHistoFval->Draw("hist");
80  fMinuitPad = gPad;
81 }
82 
84  // action for each iteration: fill histograms
85  // if iteration number is < 0 add at the end of current histograms
86  // if offset is > 0 start filling from end of previous histogram
87 
88  int lastIter = int( fHistoFval->GetEntries()+0.5);
89  if (iter < 0)
90  iter = lastIter;
91  else {
92  if (iter == 0 && lastIter > 0)
93  fIterOffset = lastIter;
94 
95  iter += fIterOffset;
96  }
97 
98 
100 
101 
102  fHistoFval->SetBinContent(iter+1,state.Fval());
103  fHistoEdm->SetBinContent(iter+1,state.Edm());
104 
105  for (unsigned int ipar = 0; ipar < state.Vec().size(); ++ipar) {
106  double eval = UserState().Trafo().Int2ext(ipar, state.Vec()(ipar) );
107  TH1 * histoPar = (TH1*) fHistoParList->At(ipar);
108  histoPar->SetBinContent(iter+1,eval);
109  }
110 
111  if (fMinuitPad) {
112  if (ParNumber() == -2)
113  fHistoEdm->Draw();
114  else if ( ParNumber() >= 0 && ParNumber() < fHistoParList->GetSize() ) {
115  fHistoParList->At(ParNumber() )->Draw();
116  }
117  else
118  fHistoFval->Draw();
119 
120  }
121 }
122 
virtual void Init(const MnUserParameterState &state)
Definition: MnTraceObject.h:30
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
double Int2ext(unsigned int, double) const
virtual void operator()(int i, const MinimumState &state)
const MinuitParameter & Parameter(unsigned int i) const
std::vector< double > Params() const
const MnUserTransformation & Trafo() const
class which holds the external user and/or internal Minuit representation of the parameters and error...
unsigned int size() const
Definition: LAVector.h:198
const MnUserParameterState & UserState() const
Definition: MnTraceObject.h:34
const char * Name(unsigned int) const
virtual void operator()(int i, const ROOT::Minuit2::MinimumState &state)
virtual void Init(const ROOT::Minuit2::MnUserParameterState &state)
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
TMinuit2TraceObject(int parNumber=-1)
const MnAlgebraicVector & Vec() const
Definition: MinimumState.h:59