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);
32 fHistoFval->GetXaxis()->SetRange(1, niter);
33 }
34 if (fHistoEdm)
35 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)
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) {
58 fHistoParList->Delete();
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);
66 fHistoFval->SetCanExtend(TH1::kAllAxes);
67 fHistoEdm->SetCanExtend(TH1::kAllAxes);
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);
76 h1->SetCanExtend(TH1::kAllAxes);
77 fHistoParList->Add(h1);
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)
103 fIterOffset = lastIter;
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()) {
123 fHistoParList->At(ParNumber())->Draw();
124 } else
125 fHistoFval->Draw();
126 }
127}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#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
MnTraceObject(int parNumber=-1)
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
double Int2ext(unsigned int, double) const
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:926
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
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:9356
@ kAllAxes
Definition TH1.h:126
A doubly linked list.
Definition TList.h:38
void Init(const ROOT::Minuit2::MnUserParameterState &state) override
TMinuit2TraceObject(int parNumber=-1)
void operator()(int i, const ROOT::Minuit2::MinimumState &state) override
TNamed()
Definition TNamed.h:38
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:2385
TH1F * h1
Definition legend1.C:5