Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RooProfileLL.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2 * Project: RooFit *
3 * *
4 * Copyright (c) 2000-2005, Regents of the University of California *
5 * and Stanford University. All rights reserved. *
6 * *
7 * Redistribution and use in source and binary forms, *
8 * with or without modification, are permitted according to the terms *
9 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
10 *****************************************************************************/
11
12/**
13\file RooProfileLL.cxx
14\class RooProfileLL
15\ingroup Roofitcore
16
17Implements the profile likelihood estimator for
18a given likelihood and set of parameters of interest. The value return by
19RooProfileLL is the input likelihood nll minimized w.r.t all nuisance parameters
20(which are all parameters except for those listed in the constructor) minus
21the -log(L) of the best fit. Note that this function is slow to evaluate
22as a MIGRAD minimization step is executed for each function evaluation
23**/
24
25#include "Riostream.h"
26
27#include "RooProfileLL.h"
28#include "RooAbsReal.h"
29#include "RooMinimizer.h"
30#include "RooMsgService.h"
31#include "RooRealVar.h"
32
34
35
36////////////////////////////////////////////////////////////////////////////////
37/// Default constructor
38/// Should only be used by proof.
39
41 : RooAbsReal("RooProfileLL", "RooProfileLL"),
42 _obs("paramOfInterest", "Parameters of interest", this),
43 _par("nuisanceParam", "Nuisance parameters", this, false, false)
44{
45}
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Constructor of profile likelihood given input likelihood nll w.r.t
50/// the given set of variables. The input log likelihood is minimized w.r.t
51/// to all other variables of the likelihood at each evaluation and the
52/// value of the global log likelihood minimum is always subtracted.
53
54RooProfileLL::RooProfileLL(const char *name, const char *title,
55 RooAbsReal& nllIn, const RooArgSet& observables) :
56 RooAbsReal(name,title),
57 _nll("input","-log(L) function",this,nllIn),
58 _obs("paramOfInterest","Parameters of interest",this),
59 _par("nuisanceParam","Nuisance parameters",this,false,false)
60{
61 // Determine actual parameters and observables
62 nllIn.getObservables(&observables, _obs) ;
63 nllIn.getParameters(&observables, _par) ;
64}
65
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// Copy constructor
70
73 _nll("nll", this, other._nll),
74 _obs("obs", this, other._obs),
75 _par("par", this, other._par),
76 _startFromMin(other._startFromMin),
77 _paramFixed(other._paramFixed)
78{
79 _paramAbsMin.addClone(other._paramAbsMin) ;
80 _obsAbsMin.addClone(other._obsAbsMin) ;
81
82}
83
84
85////////////////////////////////////////////////////////////////////////////////
86
88{
90 return _paramAbsMin ;
91}
92
93
94////////////////////////////////////////////////////////////////////////////////
95
97{
99 return _obsAbsMin ;
100}
101
102
103
104
105////////////////////////////////////////////////////////////////////////////////
106/// Optimized implementation of createProfile for profile likelihoods.
107/// Return profile of original function in terms of stated parameters
108/// of interest rather than profiling recursively.
109
114
115
116
117
118////////////////////////////////////////////////////////////////////////////////
119
121{
122 coutI(Minimization) << "RooProfileLL::evaluate(" << GetName() << ") Creating instance of MINUIT" << std::endl;
123
124 bool smode = RooMsgService::instance().silentMode() ;
125 RooMsgService::instance().setSilentMode(true) ;
126 _minimizer = std::make_unique<RooMinimizer>(const_cast<RooAbsReal&>(_nll.arg())) ;
127 if (!smode) RooMsgService::instance().setSilentMode(false) ;
128
129}
130
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Evaluate profile likelihood by minimizing likelihood w.r.t. all
135/// parameters that are not considered observables of this profile
136/// likelihood object.
137
139{
140 // Instantiate minimizer if we haven't done that already
141 if (!_minimizer) {
143 }
144
145 // Save current value of observables
148
150
151
152 // Set all observables constant in the minimization
153 const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",true) ;
154 ccoutP(Eval) << "." ; ccoutP(Eval).flush() ;
155
156 // If requested set initial parameters to those corresponding to absolute minimum
157 if (_startFromMin) {
159 }
160
161 _minimizer->zeroEvalCount() ;
162
163 _minimizer->migrad() ;
164 _neval = _minimizer->evalCounter() ;
165
166 // Restore original values and constant status of observables
167 for(auto const& arg : obsSetOrig) {
168 assert(dynamic_cast<RooRealVar*>(arg));
169 auto var = static_cast<RooRealVar*>(arg);
170 auto target = static_cast<RooRealVar*>(_obs.find(var->GetName())) ;
171 target->setVal(var->getVal()) ;
172 target->setConstant(var->isConstant()) ;
173 }
174
175 return _nll - _absMin ;
176}
177
178
179
180////////////////////////////////////////////////////////////////////////////////
181/// Check that parameters and likelihood value for 'best fit' are still valid. If not,
182/// because the best fit has never been calculated, or because constant parameters have
183/// changed value or parameters have changed const/float status, the minimum is recalculated
184
186{
187 // Check if constant status of any of the parameters have changed
188 if (_absMinValid) {
189 for(auto const& par : _par) {
190 if (_paramFixed[par->GetName()] != par->isConstant()) {
191 cxcoutI(Minimization) << "RooProfileLL::evaluate(" << GetName() << ") constant status of parameter " << par->GetName() << " has changed from "
192 << (_paramFixed[par->GetName()]?"fixed":"floating") << " to " << (par->isConstant()?"fixed":"floating")
193 << ", recalculating absolute minimum" << std::endl;
195 break ;
196 }
197 }
198 }
199
200
201 // If we don't have the absolute minimum w.r.t all observables, calculate that first
202 if (!_absMinValid) {
203
204 cxcoutI(Minimization) << "RooProfileLL::evaluate(" << GetName() << ") determining minimum likelihood for current configurations w.r.t all observable" << std::endl;
205
206
207 if (!_minimizer) {
209 }
210
211 // Save current values of non-marginalized parameters
213 _obs.snapshot(obsStart, false) ;
214
215 // Start from previous global minimum
216 if (!_paramAbsMin.empty()) {
217 const_cast<RooSetProxy&>(_par).assignValueOnly(_paramAbsMin) ;
218 }
219 if (!_obsAbsMin.empty()) {
220 const_cast<RooSetProxy&>(_obs).assignValueOnly(_obsAbsMin) ;
221 }
222
223 // Find minimum with all observables floating
224 const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",false) ;
225
226 _minimizer->migrad() ;
227
228 // Save value and remember
229 _absMin = _nll ;
231
232 // Save parameter values at abs minimum as well
234
235 // Only store non-constant parameters here!
236 _paramAbsMin.addClone(*std::unique_ptr<RooArgSet>{_par.selectByAttrib("Constant", false)});
237
239
240 // Save constant status of all parameters
241 for(auto const& par : _par) {
242 _paramFixed[par->GetName()] = par->isConstant() ;
243 }
244
245 if (dologI(Minimization)) {
246 cxcoutI(Minimization) << "RooProfileLL::evaluate(" << GetName() << ") minimum found at (" ;
247
248 bool first=true ;
249 for(auto const& arg : _obs) {
250 ccxcoutI(Minimization) << (first?"":", ") << arg->GetName() << "="
251 << static_cast<RooAbsReal const*>(arg)->getVal() ;
252 first=false ;
253 }
254 ccxcoutI(Minimization) << ")" << std::endl;
255 }
256
257 // Restore original parameter values
259
260 }
261}
262
263
264
265////////////////////////////////////////////////////////////////////////////////
266
#define coutI(a)
#define cxcoutI(a)
#define ccoutP(a)
#define dologI(a)
#define ccxcoutI(a)
#define ClassImp(name)
Definition Rtypes.h:382
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
char name[80]
Definition TGX11.cxx:110
R__DEPRECATED(6, 36, "Use getObservables().") RooFit R__DEPRECATED(6, 36, "Use getObservables().") RooFit R__DEPRECATED(6, 36, "Use getObservables().") RooFit const RooAbsArg &testArg const
Definition RooAbsArg.h:145
Abstract container object that can hold multiple RooAbsArg objects.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Function that is called at the end of redirectServers().
virtual RooFit::OwningPtr< RooAbsReal > createProfile(const RooArgSet &paramsOfInterest)
Create a RooProfileLL object that eliminates all nuisance parameters in the present function.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:159
RooArgSet * selectByAttrib(const char *name, bool value) const
Use RooAbsCollection::selectByAttrib(), but return as RooArgSet.
Definition RooArgSet.h:144
static RooMsgService & instance()
Return reference to singleton instance.
Implements the profile likelihood estimator for a given likelihood and set of parameters of interest.
const RooArgSet & bestFitObs() const
RooArgSet _paramAbsMin
Parameter values at absolute minimum.
RooSetProxy _obs
Parameters of profile likelihood.
Int_t _neval
Number evaluations used in last minimization.
RooProfileLL()
Default constructor Should only be used by proof.
void initializeMinimizer() const
RooAbsReal & nll()
bool _absMinValid
flag if absmin is up-to-date
std::map< std::string, bool > _paramFixed
Parameter constant status at last time of use.
bool _startFromMin
Always start minimization for global minimum?
std::unique_ptr< RooMinimizer > _minimizer
! Internal minimizer instance
RooArgSet _obsAbsMin
Observable values at absolute minimum.
void validateAbsMin() const
Check that parameters and likelihood value for 'best fit' are still valid.
RooSetProxy _par
Marginalised parameters of likelihood.
double _absMin
absolute minimum of -log(L)
double evaluate() const override
Evaluate profile likelihood by minimizing likelihood w.r.t.
RooFit::OwningPtr< RooAbsReal > createProfile(const RooArgSet &paramsOfInterest) override
Optimized implementation of createProfile for profile likelihoods.
RooRealProxy _nll
Input -log(L) function.
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
Function that is called at the end of redirectServers().
const RooArgSet & bestFitParams() const
Variable that can be changed from the outside.
Definition RooRealVar.h:37
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35