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
18
20 : ROOT::Minuit2::MnTraceObject(parNumber), TNamed("Minuit2TraceObject", "ROOT Trace Object for Minuit2"),
21 fIterOffset(0), fHistoFval(nullptr), fHistoEdm(nullptr), fHistoParList(nullptr), fOldPad(nullptr), fMinuitPad(nullptr)
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");
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}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassImp(name)
Definition Rtypes.h:377
#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
const MnUserTransformation & Trafo() 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 using bin numbers.
Definition TAxis.cxx:1052
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:664
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
@ kAllAxes
Definition TH1.h:76
TAxis * GetXaxis()
Definition TH1.h:324
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3062
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:9186
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4419
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:6613
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:468
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:355
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:2378
TH1F * h1
Definition legend1.C:5
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
th1 Draw()