File indexing completed on 2025-12-16 10:29:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ROOSTATS_HypoTestInverter
0012 #define ROOSTATS_HypoTestInverter
0013
0014
0015 #include "RooStats/IntervalCalculator.h"
0016
0017
0018 #include "RooStats/HypoTestInverterResult.h"
0019
0020 class RooRealVar;
0021 class TGraphErrors;
0022
0023 #include <memory>
0024 #include <string>
0025
0026 namespace RooStats {
0027
0028
0029 class HybridCalculator;
0030 class FrequentistCalculator;
0031 class AsymptoticCalculator;
0032 class HypoTestCalculatorGeneric;
0033 class TestStatistic;
0034
0035
0036 class HypoTestInverter : public IntervalCalculator {
0037
0038 public:
0039
0040 enum ECalculatorType { kUndefined = 0, kHybrid = 1, kFrequentist = 2, kAsymptotic = 3};
0041
0042
0043 HypoTestInverter();
0044
0045
0046 HypoTestInverter( HypoTestCalculatorGeneric & hc,
0047 RooRealVar* scannedVariable =nullptr,
0048 double size = 0.05) ;
0049
0050
0051
0052 HypoTestInverter( HybridCalculator & hc,
0053 RooRealVar* scannedVariable = nullptr,
0054 double size = 0.05) ;
0055
0056
0057 HypoTestInverter( FrequentistCalculator & hc,
0058 RooRealVar* scannedVariable,
0059 double size = 0.05) ;
0060
0061
0062 HypoTestInverter( AsymptoticCalculator & hc,
0063 RooRealVar* scannedVariable,
0064 double size = 0.05) ;
0065
0066
0067
0068 HypoTestInverter( RooAbsData& data, ModelConfig &sb, ModelConfig &b,
0069 RooRealVar * scannedVariable = nullptr, ECalculatorType type = kFrequentist,
0070 double size = 0.05) ;
0071
0072
0073 HypoTestInverterResult* GetInterval() const override;
0074
0075 void Clear();
0076
0077
0078
0079
0080
0081
0082 void SetFixedScan(int nBins, double xMin = 1, double xMax = -1, bool scanLog = false ) {
0083 fNBins = nBins;
0084 fXmin = xMin; fXmax = xMax;
0085 fScanLog = scanLog;
0086 }
0087
0088
0089 void SetAutoScan() { SetFixedScan(0); }
0090
0091
0092
0093
0094
0095
0096 bool RunFixedScan( int nBins, double xMin, double xMax, bool scanLog = false ) const;
0097
0098 bool RunOnePoint( double thisX, bool adaptive = false, double clTarget = -1 ) const;
0099
0100
0101
0102 bool RunLimit(double &limit, double &limitErr, double absTol = 0, double relTol = 0, const double *hint=nullptr) const;
0103
0104 void UseCLs( bool on = true) { fUseCLs = on; if (fResults) fResults->UseCLs(on); }
0105
0106 void SetData(RooAbsData &) override;
0107
0108 void SetModel(const ModelConfig &) override { }
0109
0110
0111 void SetTestSize(double size) override {fSize = size; if (fResults) fResults->SetTestSize(size); }
0112
0113 void SetConfidenceLevel(double cl) override {fSize = 1.-cl; if (fResults) fResults->SetConfidenceLevel(cl); }
0114
0115 double Size() const override {return fSize;}
0116
0117 double ConfidenceLevel() const override {return 1.-fSize;}
0118
0119
0120 ~HypoTestInverter() override ;
0121
0122
0123
0124 HypoTestCalculatorGeneric * GetHypoTestCalculator() const { return fCalculator0; }
0125
0126
0127 SamplingDistribution * GetLowerLimitDistribution(bool rebuild=false, int nToys = 100);
0128 SamplingDistribution * GetUpperLimitDistribution(bool rebuild=false, int nToys = 100);
0129
0130
0131 SamplingDistribution * RebuildDistributions(bool isUpper=true, int nToys = 100,
0132 TList *clsDist = nullptr, TList *clsbDist = nullptr, TList *clbDist = nullptr, const char *outputfile = "HypoTestInverterRebuiltDist.root");
0133
0134
0135 TestStatistic * GetTestStatistic() const;
0136
0137
0138 bool SetTestStatistic(TestStatistic& stat);
0139
0140
0141 void SetVerbose(int level=1) { fVerbose = level; }
0142
0143
0144 void SetMaximumToys(int ntoys) { fMaxToys = ntoys;}
0145
0146
0147 void SetNumErr(double err) { fNumErr = err; }
0148
0149 protected:
0150
0151
0152 HypoTestInverter(const HypoTestInverter & rhs);
0153
0154
0155 HypoTestInverter & operator=(const HypoTestInverter & rhs);
0156
0157 void CreateResults() const;
0158
0159
0160 HypoTestResult * Eval( HypoTestCalculatorGeneric &hc, bool adaptive , double clsTarget) const;
0161
0162
0163 static RooRealVar * GetVariableToScan(const HypoTestCalculatorGeneric &hc);
0164 static void CheckInputModels(const HypoTestCalculatorGeneric &hc, const RooRealVar & scanVar);
0165
0166 private:
0167
0168
0169 static unsigned int fgNToys;
0170 static double fgCLAccuracy;
0171 static double fgAbsAccuracy;
0172 static double fgRelAccuracy;
0173 static std::string fgAlgo;
0174
0175
0176 mutable std::unique_ptr<TGraphErrors> fLimitPlot;
0177
0178
0179
0180 mutable int fTotalToysRun;
0181 int fMaxToys;
0182
0183 HypoTestCalculatorGeneric* fCalculator0;
0184 std::unique_ptr<HypoTestCalculatorGeneric> fHC;
0185 RooRealVar* fScannedVariable;
0186 mutable HypoTestInverterResult* fResults;
0187
0188 bool fUseCLs;
0189 bool fScanLog;
0190 double fSize;
0191 int fVerbose;
0192 ECalculatorType fCalcType;
0193 int fNBins;
0194 double fXmin;
0195 double fXmax;
0196 double fNumErr;
0197
0198 protected:
0199
0200 ClassDefOverride(HypoTestInverter,4)
0201
0202 };
0203
0204 }
0205
0206 #endif