File indexing completed on 2025-07-15 09:08:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef ROOSTATS_HypoTestResult
0011 #define ROOSTATS_HypoTestResult
0012
0013 #include "RooStats/RooStatsUtils.h"
0014 #include "RooStats/SamplingDistribution.h"
0015
0016 #include "TNamed.h"
0017
0018 #include <memory>
0019
0020 namespace RooStats {
0021
0022 class HypoTestResult : public TNamed {
0023
0024 public:
0025
0026
0027 explicit HypoTestResult(const char *name = nullptr);
0028
0029
0030 HypoTestResult(const HypoTestResult& other);
0031
0032
0033 HypoTestResult(const char* name, double nullp, double altp);
0034
0035
0036 TObject* Clone(const char* newname = nullptr) const override {
0037 auto out = new HypoTestResult(*this);
0038 if(newname && strlen(newname)) out->SetName(newname);
0039 return out;
0040 }
0041
0042
0043 ~HypoTestResult() override;
0044
0045
0046 HypoTestResult & operator=(const HypoTestResult& other);
0047
0048
0049 virtual void Append(const HypoTestResult *other);
0050
0051
0052 virtual double NullPValue() const { return fNullPValue; }
0053
0054
0055 virtual double AlternatePValue() const { return fAlternatePValue; }
0056
0057
0058 virtual double CLb() const { return !fBackgroundIsAlt ? NullPValue() : AlternatePValue(); }
0059
0060
0061 virtual double CLsplusb() const { return !fBackgroundIsAlt ? AlternatePValue() : NullPValue(); }
0062
0063
0064 virtual double CLs() const {
0065 double thisCLb = CLb();
0066 if (thisCLb == 0) {
0067 std::cout << "Error: Cannot compute CLs because CLb = 0. Returning CLs = -1\n";
0068 return -1;
0069 }
0070 double thisCLsb = CLsplusb();
0071 return thisCLsb / thisCLb;
0072 }
0073
0074
0075 virtual double Significance() const {return RooStats::PValueToSignificance( NullPValue() ); }
0076
0077 SamplingDistribution* GetNullDistribution(void) const { return fNullDistr.get(); }
0078 SamplingDistribution* GetAltDistribution(void) const { return fAltDistr.get(); }
0079 RooDataSet* GetNullDetailedOutput(void) const { return fNullDetailedOutput.get(); }
0080 RooDataSet* GetAltDetailedOutput(void) const { return fAltDetailedOutput.get(); }
0081 RooDataSet* GetFitInfo() const { return fFitInfo.get(); }
0082 double GetTestStatisticData(void) const { return fTestStatisticData; }
0083 const RooArgList* GetAllTestStatisticsData(void) const { return fAllTestStatisticsData.get(); }
0084 bool HasTestStatisticData(void) const;
0085
0086 void SetNullPValue(double pvalue) { fNullPValue = pvalue; }
0087 void SetNullPValueError(double err) { fNullPValueError = err; }
0088 void SetAltPValue(double pvalue) { fAlternatePValue = pvalue; }
0089 void SetAltPValueError(double err) { fAlternatePValueError = err; }
0090 void SetAltDistribution(SamplingDistribution *alt);
0091 void SetNullDistribution(SamplingDistribution *null);
0092 void SetAltDetailedOutput(RooDataSet* d) { fAltDetailedOutput.reset(d); }
0093 void SetNullDetailedOutput(RooDataSet* d) { fNullDetailedOutput.reset(d); }
0094 void SetFitInfo(RooDataSet* d) { fFitInfo.reset(d); }
0095 void SetTestStatisticData(const double tsd);
0096 void SetAllTestStatisticsData(const RooArgList* tsd);
0097
0098 void SetPValueIsRightTail(bool pr);
0099 bool GetPValueIsRightTail(void) const { return fPValueIsRightTail; }
0100
0101 void SetBackgroundAsAlt(bool l = true) { fBackgroundIsAlt = l; }
0102 bool GetBackGroundIsAlt(void) const { return fBackgroundIsAlt; }
0103
0104
0105 double CLbError() const;
0106
0107
0108 double CLsplusbError() const;
0109
0110
0111 double CLsError() const;
0112
0113
0114 double NullPValueError() const;
0115
0116
0117 double SignificanceError() const;
0118
0119
0120 void Print(const Option_t* = "") const override;
0121
0122 private:
0123 void UpdatePValue(const SamplingDistribution* distr, double &pvalue, double &perror, bool pIsRightTail);
0124
0125
0126 protected:
0127
0128 mutable double fNullPValue;
0129 mutable double fAlternatePValue;
0130 mutable double fNullPValueError;
0131 mutable double fAlternatePValueError;
0132 double fTestStatisticData;
0133 std::unique_ptr<const RooArgList> fAllTestStatisticsData;
0134 std::unique_ptr<SamplingDistribution> fNullDistr;
0135 std::unique_ptr<SamplingDistribution> fAltDistr;
0136 std::unique_ptr<RooDataSet> fNullDetailedOutput;
0137 std::unique_ptr<RooDataSet> fAltDetailedOutput;
0138 std::unique_ptr<RooDataSet> fFitInfo;
0139 bool fPValueIsRightTail;
0140 bool fBackgroundIsAlt;
0141
0142 ClassDefOverride(HypoTestResult,5)
0143
0144 };
0145 }
0146
0147
0148 #endif