Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:45

0001 // @(#)root/roostats:$Id$
0002 // Authors: Kevin Belasco        17/06/2009
0003 // Authors: Kyle Cranmer         17/06/2009
0004 /*************************************************************************
0005  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOSTATS_MarkovChain
0013 #define ROOSTATS_MarkovChain
0014 
0015 #include "Rtypes.h"
0016 
0017 #include "TNamed.h"
0018 
0019 #include "RooRealVar.h"
0020 #include "RooDataSet.h"
0021 #include "RooDataHist.h"
0022 #include "THnSparse.h"
0023 
0024 namespace RooStats {
0025 
0026    class MarkovChain : public TNamed {
0027 
0028    public:
0029       MarkovChain();
0030       MarkovChain(RooArgSet& parameters);
0031       MarkovChain(const char* name, const char* title, RooArgSet& parameters);
0032 
0033       /// safely add an entry to the chain
0034       virtual void Add(RooArgSet& entry, double nllValue, double weight = 1.0);
0035       /// add an entry to the chain ONLY IF you have constructed with parameters
0036       /// or called SetParameters
0037       virtual void AddFast(RooArgSet& entry, double nllValue, double weight = 1.0);
0038       /// add another markov chain
0039       virtual void AddWithBurnIn(MarkovChain& otherChain, Int_t burnIn = 0);
0040       /// add another markov chain
0041       virtual void Add(MarkovChain& otherChain, double discardEntries = 0.0);
0042       /// set which of your parameters this chain should store
0043       virtual void SetParameters(RooArgSet& parameters);
0044       /// get the number of steps in the chain
0045       virtual Int_t Size() const { return fChain ? fChain->numEntries() : 0; }
0046       /// get the entry at position i
0047       virtual const RooArgSet* Get(Int_t i) const { return fChain->get(i); }
0048       /// get the entry at the current position
0049       virtual const RooArgSet* Get() const { return fChain->get(); }
0050       /// get the weight of the current (last indexed) entry
0051       virtual double Weight() const;
0052       /// get the weight of entry at position i
0053       virtual double Weight(Int_t i) const;
0054       /// get the NLL value of entry at position i
0055       virtual double NLL(Int_t i) const;
0056       /// get the NLL value of the current (last indexed) entry
0057       virtual double NLL() const;
0058 
0059       /// get this MarkovChain as a RooDataSet whose entries contain the values
0060       /// of whichVars.  Call with whichVars = nullptr (default) to get values of
0061       /// all variables (including NLL value and weight);
0062       /// Note: caller owns the returned data set
0063       virtual RooFit::OwningPtr<RooDataSet> GetAsDataSet(RooArgSet* whichVars = nullptr) const;
0064       virtual const RooDataSet* GetAsConstDataSet() const { return fChain; }
0065 
0066       /// get this MarkovChain as a RooDataHist whose entries contain the values
0067       /// of whichVars.  Call with whichVars = nullptr (default) to get values of
0068       /// all variables (including NLL value and weight);
0069       /// Note: caller owns the returned data hist
0070       virtual RooFit::OwningPtr<RooDataHist> GetAsDataHist(RooArgSet* whichVars = nullptr) const;
0071 
0072       /// Get a clone of the markov chain on which this interval is based
0073       /// as a sparse histogram.  You own the returned THnSparse*
0074       virtual THnSparse* GetAsSparseHist(RooAbsCollection* whichVars = nullptr) const;
0075       virtual THnSparse* GetAsSparseHist(RooAbsCollection& whichVars) const
0076       { return GetAsSparseHist(&whichVars); }
0077 
0078       /// get a clone of the NLL variable
0079       virtual RooRealVar* GetNLLVar() const
0080       { return (RooRealVar*)fNLL->Clone(); }
0081 
0082       /// get a clone of the weight variable
0083       virtual RooRealVar* GetWeightVar() const
0084       { return static_cast<RooRealVar*>(fChain->weightVar()->Clone()); }
0085 
0086       ~MarkovChain() override
0087       {
0088          delete fParameters;
0089          delete fDataEntry;
0090          delete fChain;
0091       }
0092 
0093    protected:
0094       RooArgSet *fParameters = nullptr;
0095       RooArgSet *fDataEntry = nullptr;
0096       RooDataSet *fChain = nullptr;
0097       RooRealVar *fNLL = nullptr;
0098 
0099       ClassDefOverride(MarkovChain,2);
0100    };
0101 }
0102 
0103 #endif