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"
16
18
19TMinuit2TraceObject::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;
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);
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);
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");
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() ) {
116 }
117 else
118 fHistoFval->Draw();
119
120 }
121}
122
#define ClassImp(name)
Definition: Rtypes.h:361
#define gPad
Definition: TVirtualPad.h:287
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
const MnAlgebraicVector & Vec() const
Definition: MinimumState.h:59
virtual void operator()(int i, const MinimumState &state)
virtual void Init(const MnUserParameterState &state)
Definition: MnTraceObject.h:30
const MnUserParameterState & UserState() const
Definition: MnTraceObject.h:34
class which holds the external user and/or internal Minuit representation of the parameters and error...
const MinuitParameter & Parameter(unsigned int i) const
const char * Name(unsigned int) const
const MnUserTransformation & Trafo() const
std::vector< double > Params() const
double Int2ext(unsigned int, double) const
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
Definition: TAxis.cxx:914
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:614
The TH1 histogram class.
Definition: TH1.h:56
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:316
@ kAllAxes
Definition: TH1.h:73
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:8678
virtual Double_t GetEntries() const
Return the current number of entries.
Definition: TH1.cxx:4302
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:6291
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2998
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:356
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
virtual void Init(const ROOT::Minuit2::MnUserParameterState &state)
TMinuit2TraceObject(int parNumber=-1)
virtual void operator()(int i, const ROOT::Minuit2::MinimumState &state)
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
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:2311
TH1F * h1
Definition: legend1.C:5
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21