Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MarkovChain.h
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Authors: Kevin Belasco 17/06/2009
3// Authors: Kyle Cranmer 17/06/2009
4/*************************************************************************
5 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOSTATS_MarkovChain
13#define ROOSTATS_MarkovChain
14
15#include "Rtypes.h"
16
17#include "TNamed.h"
18
19#include "RooRealVar.h"
20#include "RooDataSet.h"
21#include "RooDataHist.h"
22#include "THnSparse.h"
23
24#include <ROOT/RConfig.hxx> // for the R__DEPRECATED macro
25
26//#include "RooArgSet.h"
27//#include "RooMsgService.h"
28//#include "RooRealVar.h"
29
30
31namespace RooStats {
32
33 class MarkovChain : public TNamed {
34
35 public:
37 MarkovChain(RooArgSet& parameters);
38 MarkovChain(const char* name, const char* title, RooArgSet& parameters);
39
40 /// safely add an entry to the chain
41 virtual void Add(RooArgSet& entry, double nllValue, double weight = 1.0);
42 /// add an entry to the chain ONLY IF you have constructed with parameters
43 /// or called SetParameters
44 virtual void AddFast(RooArgSet& entry, double nllValue, double weight = 1.0);
45 /// add another markov chain
46 virtual void AddWithBurnIn(MarkovChain& otherChain, Int_t burnIn = 0);
47 /// add another markov chain
48 virtual void Add(MarkovChain& otherChain, double discardEntries = 0.0);
49 /// set which of your parameters this chain should store
50 virtual void SetParameters(RooArgSet& parameters);
51 /// get the number of steps in the chain
52 virtual Int_t Size() const { return fChain ? fChain->numEntries() : 0; }
53 /// get the entry at position i
54 virtual const RooArgSet* Get(Int_t i) const { return fChain->get(i); }
55 /// get the entry at the current position
56 virtual const RooArgSet* Get() const { return fChain->get(); }
57 /// get the weight of the current (last indexed) entry
58 virtual double Weight() const;
59 /// get the weight of entry at position i
60 virtual double Weight(Int_t i) const;
61 /// get the NLL value of entry at position i
62 virtual double NLL(Int_t i) const;
63 /// get the NLL value of the current (last indexed) entry
64 virtual double NLL() const;
65
66 /// get this MarkovChain as a RooDataSet whose entries contain the values
67 /// of whichVars. Call with whichVars = nullptr (default) to get values of
68 /// all variables (including NLL value and weight);
69 /// Note: caller owns the returned data set
70 virtual RooFit::OwningPtr<RooDataSet> GetAsDataSet(RooArgSet* whichVars = nullptr) const;
71
72 /// Get a clone of the markov chain on which this interval is based
73 /// as a RooDataSet. You own the returned RooDataSet*
74 /// \deprecated Will be removed in ROOT 6.36.
76 const RooCmdArg& arg2={}, const RooCmdArg& arg3={},
77 const RooCmdArg& arg4={}, const RooCmdArg& arg5={},
78 const RooCmdArg& arg6={}, const RooCmdArg& arg7={},
79 const RooCmdArg& arg8={} ) const
80 R__DEPRECATED(6,36, "This functionality can be implemented by calling RooAbsData::reduce on the Markov Chain's RooDataSet* (obtained using MarkovChain::GetAsConstDataSet)");
81
82 virtual const RooDataSet* GetAsConstDataSet() const { return fChain; }
83
84 /// get this MarkovChain as a RooDataHist whose entries contain the values
85 /// of whichVars. Call with whichVars = nullptr (default) to get values of
86 /// all variables (including NLL value and weight);
87 /// Note: caller owns the returned data hist
88 virtual RooFit::OwningPtr<RooDataHist> GetAsDataHist(RooArgSet* whichVars = nullptr) const;
89
90 /// Get a clone of the markov chain on which this interval is based
91 /// as a RooDataHist. You own the returned RooDataHist*
92 /// \deprecated Will be removed in ROOT 6.36.
94 const RooCmdArg& arg2={}, const RooCmdArg& arg3={},
95 const RooCmdArg& arg4={}, const RooCmdArg& arg5={},
96 const RooCmdArg& arg6={}, const RooCmdArg& arg7={},
97 const RooCmdArg& arg8={} ) const
98 R__DEPRECATED(6,36, "This functionality can be implemented by calling RooAbsData::reduce on the Markov Chain's RooDataSet* (obtained using MarkovChain::GetAsConstDataSet) and then obtaining its binned clone.");
99
100 /// Get a clone of the markov chain on which this interval is based
101 /// as a sparse histogram. You own the returned THnSparse*
102 virtual THnSparse* GetAsSparseHist(RooAbsCollection* whichVars = nullptr) const;
103 virtual THnSparse* GetAsSparseHist(RooAbsCollection& whichVars) const
104 { return GetAsSparseHist(&whichVars); }
105
106 /// get a clone of the NLL variable
107 virtual RooRealVar* GetNLLVar() const
108 { return (RooRealVar*)fNLL->Clone(); }
109
110 /// get a clone of the weight variable
111 virtual RooRealVar* GetWeightVar() const
112 { return static_cast<RooRealVar*>(fChain->weightVar()->Clone()); }
113
114 ~MarkovChain() override
115 {
116 delete fParameters;
117 delete fDataEntry;
118 delete fChain;
119 }
120
121 protected:
124 RooDataSet *fChain = nullptr;
125 RooRealVar *fNLL = nullptr;
126
128 };
129}
130
131#endif
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:504
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
char name[80]
Definition TGX11.cxx:110
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:91
Abstract container object that can hold multiple RooAbsArg objects.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
Container class to hold unbinned data.
Definition RooDataSet.h:33
const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
RooRealVar * weightVar() const
Returns a pointer to the weight variable (if set).
Definition RooDataSet.h:84
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Stores the steps in a Markov Chain of points.
Definition MarkovChain.h:33
virtual RooRealVar * GetWeightVar() const
get a clone of the weight variable
virtual THnSparse * GetAsSparseHist(RooAbsCollection &whichVars) const
virtual void AddFast(RooArgSet &entry, double nllValue, double weight=1.0)
add an entry to the chain ONLY IF you have constructed with parameters or called SetParameters
virtual double NLL() const
get the NLL value of the current (last indexed) entry
virtual void AddWithBurnIn(MarkovChain &otherChain, Int_t burnIn=0)
add another markov chain
virtual RooFit::OwningPtr< RooDataHist > GetAsDataHist(RooArgSet *whichVars=nullptr) const
get this MarkovChain as a RooDataHist whose entries contain the values of whichVars.
virtual void Add(RooArgSet &entry, double nllValue, double weight=1.0)
safely add an entry to the chain
virtual RooFit::OwningPtr< RooDataSet > GetAsDataSet(RooArgSet *whichVars=nullptr) const
get this MarkovChain as a RooDataSet whose entries contain the values of whichVars.
RooArgSet * fParameters
virtual THnSparse * GetAsSparseHist(RooAbsCollection *whichVars=nullptr) const
Get a clone of the markov chain on which this interval is based as a sparse histogram.
virtual const RooArgSet * Get() const
get the entry at the current position
Definition MarkovChain.h:56
virtual void SetParameters(RooArgSet &parameters)
set which of your parameters this chain should store
virtual RooRealVar * GetNLLVar() const
get a clone of the NLL variable
virtual const RooArgSet * Get(Int_t i) const
get the entry at position i
Definition MarkovChain.h:54
virtual double Weight() const
get the weight of the current (last indexed) entry
virtual const RooDataSet * GetAsConstDataSet() const
Definition MarkovChain.h:82
virtual Int_t Size() const
get the number of steps in the chain
Definition MarkovChain.h:52
Efficient multidimensional histogram.
Definition THnSparse.h:37
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
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
Namespace for the RooStats classes.
Definition Asimov.h:19