Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
17
19 : ROOT::Minuit2::MnTraceObject(parNumber), TNamed("Minuit2TraceObject", "ROOT Trace Object for Minuit2"),
20 fIterOffset(0), fHistoFval(nullptr), fHistoEdm(nullptr), fHistoParList(nullptr), fOldPad(nullptr), fMinuitPad(nullptr)
21{
22}
23
25{
26 // rest previous pad but do not delete histograms
27 if (fOldPad && gPad && fOldPad != gPad)
28 gPad = fOldPad;
29 int niter = -1;
30 if (fHistoFval) {
31 niter = int(fHistoFval->GetEntries() + 0.5);
33 }
34 if (fHistoEdm)
36 if (fHistoParList) {
37 for (int i = 0; i < fHistoParList->GetSize(); ++i) {
38 TH1 *h1 = (TH1 *)fHistoParList->At(i);
39 if (h1)
40 h1->GetXaxis()->SetRange(1, niter);
41 }
42 }
43}
44
46{
47
49
50 fIterOffset = 0;
51
52 // build debug histogram
53 if (fHistoFval)
54 delete fHistoFval;
55 if (fHistoEdm)
56 delete fHistoEdm;
57 if (fHistoParList) {
59 delete fHistoParList;
60 }
61 if (fMinuitPad)
62 delete fMinuitPad;
63
64 fHistoFval = new TH1D("minuit2_hist_fval", "Function Value/iteration", 2, 0, 1);
65 fHistoEdm = new TH1D("minuit2_hist_edm", "Edm/iteration", 2, 0, 1);
68
69 // create histos for all parameters
70 fHistoParList = new TList();
71 for (unsigned int ipar = 0; ipar < state.Params().size(); ++ipar) {
72 if (state.Parameter(ipar).IsFixed() || state.Parameter(ipar).IsConst())
73 continue;
74 TH1D *h1 = new TH1D(TString::Format("minuit2_hist_par%d", ipar),
75 TString::Format("Value of %s/iteration", state.Name(ipar)), 2, 0, 1);
78 }
79
80 if (gPad)
81 fOldPad = gPad;
82
83 // fMinuitPad = new TCanvas("c1_minuit2","TMinuit2 Progress",2);
84 // fMinuitPad->Divide(1,3);
85 // fMinuitPad->cd(1); fHistoFval->Draw();
86 // fMinuitPad->cd(2); fHistoEdm->Draw();
87 // fMinuitPad->cd(3); fHistoPar->Draw();
88 fHistoFval->Draw("hist");
90}
91
93{
94 // action for each iteration: fill histograms
95 // if iteration number is < 0 add at the end of current histograms
96 // if offset is > 0 start filling from end of previous histogram
97
98 int lastIter = int(fHistoFval->GetEntries() + 0.5);
99 if (iter < 0)
100 iter = lastIter;
101 else {
102 if (iter == 0 && lastIter > 0)
104
105 iter += fIterOffset;
106 }
107
109
110 fHistoFval->SetBinContent(iter + 1, state.Fval());
111 fHistoEdm->SetBinContent(iter + 1, state.Edm());
112
113 for (unsigned int ipar = 0; ipar < state.Vec().size(); ++ipar) {
114 double eval = UserState().Trafo().Int2ext(ipar, state.Vec()(ipar));
115 TH1 *histoPar = (TH1 *)fHistoParList->At(ipar);
116 histoPar->SetBinContent(iter + 1, eval);
117 }
118
119 if (fMinuitPad) {
120 if (ParNumber() == -2)
121 fHistoEdm->Draw();
122 else if (ParNumber() >= 0 && ParNumber() < fHistoParList->GetSize()) {
124 } else
125 fHistoFval->Draw();
126 }
127}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gPad
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
const MnAlgebraicVector & Vec() const
virtual void operator()(int i, const MinimumState &state)
virtual void Init(const MnUserParameterState &state)
const MnUserParameterState & UserState() const
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
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:1045
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:927
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
@ kAllAxes
Definition TH1.h:126
TAxis * GetXaxis()
Definition TH1.h:572
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3037
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:9247
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4400
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:6684
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:467
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:354
void Init(const ROOT::Minuit2::MnUserParameterState &state) override
TMinuit2TraceObject(int parNumber=-1)
void operator()(int i, const ROOT::Minuit2::MinimumState &state) override
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
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:2384
TH1F * h1
Definition legend1.C:5
th1 Draw()