Logo ROOT  
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 
18 
20  : ROOT::Minuit2::MnTraceObject(parNumber), TNamed("Minuit2TraceObject", "ROOT Trace Object for Minuit2"),
21  fIterOffset(0), fHistoFval(0), fHistoEdm(0), fHistoParList(0), fOldPad(0), fMinuitPad(0)
22 {
23 }
24 
26 {
27  // rest previous pad but do not delete histograms
28  if (fOldPad && gPad && fOldPad != gPad)
29  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)
36  fHistoEdm->GetXaxis()->SetRange(1, niter);
37  if (fHistoParList) {
38  for (int i = 0; i < fHistoParList->GetSize(); ++i) {
39  TH1 *h1 = (TH1 *)fHistoParList->At(i);
40  if (h1)
41  h1->GetXaxis()->SetRange(1, niter);
42  }
43  }
44 }
45 
47 {
48 
50 
51  fIterOffset = 0;
52 
53  // build debug histogram
54  if (fHistoFval)
55  delete fHistoFval;
56  if (fHistoEdm)
57  delete fHistoEdm;
58  if (fHistoParList) {
60  delete fHistoParList;
61  }
62  if (fMinuitPad)
63  delete fMinuitPad;
64 
65  fHistoFval = new TH1D("minuit2_hist_fval", "Function Value/iteration", 2, 0, 1);
66  fHistoEdm = new TH1D("minuit2_hist_edm", "Edm/iteration", 2, 0, 1);
69 
70  // create histos for all parameters
71  fHistoParList = new TList();
72  for (unsigned int ipar = 0; ipar < state.Params().size(); ++ipar) {
73  if (state.Parameter(ipar).IsFixed() || state.Parameter(ipar).IsConst())
74  continue;
75  TH1D *h1 = new TH1D(TString::Format("minuit2_hist_par%d", ipar),
76  TString::Format("Value of %s/iteration", state.Name(ipar)), 2, 0, 1);
79  }
80 
81  if (gPad)
82  fOldPad = gPad;
83 
84  // fMinuitPad = new TCanvas("c1_minuit2","TMinuit2 Progress",2);
85  // fMinuitPad->Divide(1,3);
86  // fMinuitPad->cd(1); fHistoFval->Draw();
87  // fMinuitPad->cd(2); fHistoEdm->Draw();
88  // fMinuitPad->cd(3); fHistoPar->Draw();
89  fHistoFval->Draw("hist");
90  fMinuitPad = gPad;
91 }
92 
94 {
95  // action for each iteration: fill histograms
96  // if iteration number is < 0 add at the end of current histograms
97  // if offset is > 0 start filling from end of previous histogram
98 
99  int lastIter = int(fHistoFval->GetEntries() + 0.5);
100  if (iter < 0)
101  iter = lastIter;
102  else {
103  if (iter == 0 && lastIter > 0)
104  fIterOffset = lastIter;
105 
106  iter += fIterOffset;
107  }
108 
110 
111  fHistoFval->SetBinContent(iter + 1, state.Fval());
112  fHistoEdm->SetBinContent(iter + 1, state.Edm());
113 
114  for (unsigned int ipar = 0; ipar < state.Vec().size(); ++ipar) {
115  double eval = UserState().Trafo().Int2ext(ipar, state.Vec()(ipar));
116  TH1 *histoPar = (TH1 *)fHistoParList->At(ipar);
117  histoPar->SetBinContent(iter + 1, eval);
118  }
119 
120  if (fMinuitPad) {
121  if (ParNumber() == -2)
122  fHistoEdm->Draw();
123  else if (ParNumber() >= 0 && ParNumber() < fHistoParList->GetSize()) {
125  } else
126  fHistoFval->Draw();
127  }
128 }
TMinuit2TraceObject::fHistoParList
TList * fHistoParList
Definition: TMinuit2TraceObject.h:48
ROOT::Minuit2::MinimumState::Edm
double Edm() const
Definition: MinimumState.h:57
ROOT::Minuit2::MnUserTransformation::Int2ext
double Int2ext(unsigned int, double) const
Definition: MnUserTransformation.cxx:99
ROOT::Minuit2::MinimumState
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
ROOT::Minuit2::MnTraceObject::UserState
const MnUserParameterState & UserState() const
Definition: MnTraceObject.h:31
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TH1D
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:618
TH1::SetCanExtend
virtual UInt_t SetCanExtend(UInt_t extendBitMask)
Make the histogram axes extendable / not extendable according to the bit mask returns the previous bi...
Definition: TH1.cxx:6609
MnUserParameterState.h
TMinuit2TraceObject::fHistoEdm
TH1 * fHistoEdm
Definition: TMinuit2TraceObject.h:47
TH1::GetEntries
virtual Double_t GetEntries() const
Return the current number of entries.
Definition: TH1.cxx:4386
TH1::SetBinContent
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition: TH1.cxx:9062
TList.h
TMinuit2TraceObject::fHistoFval
TH1 * fHistoFval
Definition: TMinuit2TraceObject.h:46
TString::Format
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:2333
TMinuit2TraceObject::fMinuitPad
TVirtualPad * fMinuitPad
Definition: TMinuit2TraceObject.h:50
h1
TH1F * h1
Definition: legend1.C:5
TMinuit2TraceObject::operator()
virtual void operator()(int i, const ROOT::Minuit2::MinimumState &state)
Definition: TMinuit2TraceObject.cxx:93
ROOT::Minuit2::MinuitParameter::IsConst
bool IsConst() const
Definition: MinuitParameter.h:151
TH1::kAllAxes
@ kAllAxes
Definition: TH1.h:75
TList::At
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:357
TMinuit2TraceObject.h
TAxis::SetRange
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition: TAxis.cxx:920
TMinuit2TraceObject::fOldPad
TVirtualPad * fOldPad
Definition: TMinuit2TraceObject.h:49
ROOT::Minuit2::MnUserParameterState::Name
const char * Name(unsigned int) const
Definition: MnUserParameterState.cxx:473
size
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Minuit2::MnUserParameterState::Trafo
const MnUserTransformation & Trafo() const
Definition: MnUserParameterState.h:104
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
ROOT::Minuit2::MinimumState::Fval
double Fval() const
Definition: MinimumState.h:56
ROOT::Minuit2::MnUserParameterState::Params
std::vector< double > Params() const
Definition: MnUserParameterState.cxx:219
TMinuit2TraceObject::~TMinuit2TraceObject
virtual ~TMinuit2TraceObject()
Definition: TMinuit2TraceObject.cxx:25
ROOT::Minuit2::MnTraceObject::operator()
virtual void operator()(int i, const MinimumState &state)
Definition: MnTraceObject.cxx:20
ROOT::Minuit2::MinuitParameter::IsFixed
bool IsFixed() const
Definition: MinuitParameter.h:152
TMinuit2TraceObject
Definition: TMinuit2TraceObject.h:30
TVirtualPad.h
ROOT::Minuit2::MnTraceObject::Init
virtual void Init(const MnUserParameterState &state)
Definition: MnTraceObject.h:27
TMinuit2TraceObject::Init
virtual void Init(const ROOT::Minuit2::MnUserParameterState &state)
Definition: TMinuit2TraceObject.cxx:46
TMinuit2TraceObject::fIterOffset
int fIterOffset
Definition: TMinuit2TraceObject.h:45
ROOT::Minuit2::MinimumState::Vec
const MnAlgebraicVector & Vec() const
Definition: MinimumState.h:51
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
ROOT::Minuit2::MnUserParameterState
class which holds the external user and/or internal Minuit representation of the parameters and error...
Definition: MnUserParameterState.h:33
ROOT::Minuit2::MnUserParameterState::Parameter
const MinuitParameter & Parameter(unsigned int i) const
Definition: MnUserParameterState.cxx:230
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TMinuit2TraceObject::TMinuit2TraceObject
TMinuit2TraceObject(int parNumber=-1)
Definition: TMinuit2TraceObject.cxx:19
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TH1
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
gPad
#define gPad
Definition: TVirtualPad.h:287
ROOT::Minuit2::MnTraceObject::ParNumber
int ParNumber() const
Definition: MnTraceObject.h:35
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:320
TH1.h
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
TList
A doubly linked list.
Definition: TList.h:44
MinimumState.h
int
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3073