Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // @(#)root/roostats:$Id: FrequentistCalculator.h 37084 2010-11-29 21:37:13Z moneta $
0002 // Author: Sven Kreiss, Kyle Cranmer   Nov 2010
0003 /*************************************************************************
0004  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOSTATS_FrequentistCalculator
0012 #define ROOSTATS_FrequentistCalculator
0013 
0014 
0015 #include "RooStats/HypoTestCalculatorGeneric.h"
0016 
0017 #include "RooStats/ToyMCSampler.h"
0018 
0019 #include "RooStats/DetailedOutputAggregator.h"
0020 
0021 #include "RooFitResult.h"
0022 
0023 namespace RooStats {
0024 
0025    class FrequentistCalculator : public HypoTestCalculatorGeneric {
0026 
0027    public:
0028       FrequentistCalculator(
0029                         const RooAbsData &data,
0030                         const ModelConfig &altModel,
0031                         const ModelConfig &nullModel,
0032                         TestStatSampler* sampler=nullptr
0033       ) :
0034          HypoTestCalculatorGeneric(data, altModel, nullModel, sampler),
0035          fNToysNull(-1),
0036          fNToysAlt(-1),
0037          fNToysNullTail(0),
0038          fNToysAltTail(0),
0039     fFitInfo(nullptr),
0040     fStoreFitInfo(false)
0041       {
0042       }
0043 
0044       ~FrequentistCalculator() override {
0045          if( fConditionalMLEsNull ) delete fConditionalMLEsNull;
0046          if( fConditionalMLEsAlt ) delete fConditionalMLEsAlt;
0047          if( fFitInfo ) delete fFitInfo;
0048       }
0049 
0050 
0051       /// set number of toys
0052       void SetToys(int toysNull, int toysAlt) { fNToysNull = toysNull; fNToysAlt = toysAlt; }
0053 
0054       /// set least number of toys in tails
0055       void SetNToysInTails(int toysNull, int toysAlt) { fNToysNullTail = toysNull; fNToysAltTail = toysAlt; }
0056 
0057       /// set given nuisance parameters to a specific value that will be used instead of their
0058       /// profiled value for Null toys
0059       void SetConditionalMLEsNull( const RooArgSet* c ) {
0060          if( fConditionalMLEsNull ) delete fConditionalMLEsNull;
0061 
0062          if( c ) fConditionalMLEsNull = (const RooArgSet*)c->snapshot();
0063          else fConditionalMLEsNull = nullptr;
0064       }
0065 
0066       /// set given nuisance parameters to a specific value that will be used instead of their
0067       /// profiled value for Alternate toys
0068       void SetConditionalMLEsAlt( const RooArgSet* c ) {
0069          if( fConditionalMLEsAlt ) delete fConditionalMLEsAlt;
0070 
0071          if( c ) fConditionalMLEsAlt = (const RooArgSet*)c->snapshot();
0072          else fConditionalMLEsAlt = nullptr;
0073       }
0074 
0075       void StoreFitInfo(bool val = true) {
0076          fStoreFitInfo = val;
0077       }
0078 
0079       const RooArgSet* GetFitInfo() const override {
0080          return fFitInfo;
0081       }
0082 
0083    protected:
0084       /// configure TestStatSampler for the Null run
0085       int PreNullHook(RooArgSet *parameterPoint, double obsTestStat) const override;
0086 
0087       /// configure TestStatSampler for the Alt run
0088       int PreAltHook(RooArgSet *parameterPoint, double obsTestStat) const override;
0089 
0090       void PreHook() const override;
0091       void PostHook() const override;
0092 
0093    protected:
0094       // MLE inputs
0095       const RooArgSet* fConditionalMLEsNull = nullptr;
0096       const RooArgSet* fConditionalMLEsAlt = nullptr;
0097 
0098       // different number of toys for null and alt
0099       int fNToysNull;
0100       int fNToysAlt;
0101 
0102       // adaptive sampling
0103       int fNToysNullTail;
0104       int fNToysAltTail;
0105 
0106    private:
0107       mutable RooArgSet* fFitInfo;
0108       bool fStoreFitInfo;
0109 
0110    protected:
0111       ClassDefOverride(FrequentistCalculator,0)
0112    };
0113 }
0114 
0115 #endif