Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
xRooFit.h
Go to the documentation of this file.
1/*
2 * Project: xRooFit
3 * Author:
4 * Will Buttinger, RAL 2022
5 *
6 * Copyright (c) 2022, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#include "Config.h"
14
15// when not using the namespace will use the once pragma.
16// when using the namespace (as happens in the ROOT build of xRooFit) then
17// will effectively use an include guard
18#ifdef XROOFIT_USE_PRAGMA_ONCE
19#pragma once
20#endif
21#if !defined(XROOFIT_XROOFIT_H) || defined(XROOFIT_USE_PRAGMA_ONCE)
22#ifndef XROOFIT_USE_PRAGMA_ONCE
23#define XROOFIT_XROOFIT_H
24#endif
25
26/**
27 * This is the main include for the xRooFit project.
28 * Including this should give you access to all xRooFit features
29 */
30
31class RooAbsData;
33class RooFitResult;
34class RooAbsPdf;
35class RooAbsReal;
36class RooLinkedList;
37class RooWorkspace;
38
39#include "Fit/FitConfig.h"
40
41#include "RooCmdArg.h"
42
43class TCanvas;
44
45#include <memory>
46
48
49class xRooNLLVar;
50
51class xRooFit {
52
53public:
54 // Extra options for NLL creation:
55 static RooCmdArg ReuseNLL(bool flag); // if should try to reuse the NLL object when it changes dataset
56
57 // Static methods that work with the 'first class' object types:
58 // Pdfs: RooAbsPdf
59 // Datasets: std::pair<RooAbsData,const RooAbsCollection>
60 // NLLOptions: RooLinkedList
61 // FitOptions: ROOT::Fit::FitConfig
62
63 // fit result flags in its constPars list which are global observables with the "global" attribute
64 static std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
65 generateFrom(RooAbsPdf &pdf, const std::shared_ptr<const RooFitResult> &fr, bool expected = false, int seed = 0);
66 static std::shared_ptr<const RooFitResult>
67 fitTo(RooAbsPdf &pdf, const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &data,
68 const RooLinkedList &nllOpts, const ROOT::Fit::FitConfig &fitConf);
69 static std::shared_ptr<const RooFitResult> fitTo(RooAbsPdf &pdf,
70 const std::pair<RooAbsData *, const RooAbsCollection *> &data,
71 const RooLinkedList &nllOpts, const ROOT::Fit::FitConfig &fitConf);
72
73 static xRooNLLVar createNLL(const std::shared_ptr<RooAbsPdf> pdf, const std::shared_ptr<RooAbsData> data,
74 const RooLinkedList &nllOpts);
75 static xRooNLLVar createNLL(RooAbsPdf &pdf, RooAbsData *data, const RooLinkedList &nllOpts);
76 static xRooNLLVar createNLL(RooAbsPdf &pdf, RooAbsData *data, const RooCmdArg &arg1 = RooCmdArg::none(),
77 const RooCmdArg &arg2 = RooCmdArg::none(), const RooCmdArg &arg3 = RooCmdArg::none(),
78 const RooCmdArg &arg4 = RooCmdArg::none(), const RooCmdArg &arg5 = RooCmdArg::none(),
79 const RooCmdArg &arg6 = RooCmdArg::none(), const RooCmdArg &arg7 = RooCmdArg::none(),
80 const RooCmdArg &arg8 = RooCmdArg::none());
81
82 static std::shared_ptr<ROOT::Fit::FitConfig> createFitConfig(); // obtain instance of default fit configuration
83 static std::shared_ptr<RooLinkedList> createNLLOptions(); // obtain instance of default nll options
84
85 static std::shared_ptr<const RooFitResult>
86 minimize(RooAbsReal &nll, const std::shared_ptr<ROOT::Fit::FitConfig> &fitConfig = nullptr);
87 static int minos(RooAbsReal &nll, const RooFitResult &ufit, const char *parName = "",
88 const std::shared_ptr<ROOT::Fit::FitConfig> &_fitConfig = nullptr);
89
91
92 public:
93 typedef std::vector<std::pair<double, int>> IncompatFunc;
94
95 enum PLLType {
96 TwoSided = 0,
97 OneSidedPositive, // for exclusions
98 OneSidedNegative, // for discovery
99 OneSidedAbsolute, // for exclusions by magnitude
100 Uncapped, // for discovery with interest in deficits as well as excesses
101 Unknown
102 };
103
104 // The incompatibility function (taking mu_hat as an input) is defined by its transitions
105 // it takes values of -1, 0, or 1 ... when it 0 that means mu_hat is compatible with the hypothesis
106 // Standard incompatibility functions are parameterized by mu
107 // Note: the default value is taken to be 1, so an empty vector is function=1
109 {
110 std::vector<std::pair<double, int>> out;
111 if (type == TwoSided) {
112 // standard PLL
113 } else if (type == OneSidedPositive) {
114 out.emplace_back(std::make_pair(mu, 0)); // becomes compatible @ mu_hat = mu
115 } else if (type == OneSidedNegative) {
116 out.emplace_back(std::make_pair(-std::numeric_limits<double>::infinity(), 0)); // compatible at -inf
117 out.emplace_back(std::make_pair(mu, 1)); // becomes incompatible at mu_hat = mu
118 } else if (type == OneSidedAbsolute) {
119 out.emplace_back(std::make_pair(-std::numeric_limits<double>::infinity(), 0)); // compatible at -inf
120 out.emplace_back(std::make_pair(-mu, 1)); // incompatible @ mu_hat = -mu
121 out.emplace_back(std::make_pair(mu, 0)); // compatible again @ mu_hat = mu
122 } else if (type == Uncapped) {
123 out.emplace_back(std::make_pair(-std::numeric_limits<double>::infinity(), -1)); // reversed at -inf
124 out.emplace_back(std::make_pair(mu, 1)); // becomes normal @ mu_hat = mu
125 } else {
126 throw std::runtime_error("Unknown PLL Type");
127 }
128 return out;
129 }
130
131 // inverse of PValue function
132 static Double_t k(const IncompatFunc &compatRegions, double pValue, double poiVal, double poiPrimeVal,
133 double sigma_mu = 0, double mu_low = -std::numeric_limits<double>::infinity(),
134 double mu_high = std::numeric_limits<double>::infinity());
135
136 static Double_t k(const PLLType &pllType, double pValue, double mu, double mu_prime, double sigma_mu = 0,
137 double mu_low = -std::numeric_limits<double>::infinity(),
138 double mu_high = std::numeric_limits<double>::infinity())
139 {
140 return k(IncompatibilityFunction(pllType, mu), pValue, mu, mu_prime, sigma_mu, mu_low, mu_high);
141 }
142
143 // Recommend sigma_mu = |mu - mu_prime|/sqrt(pll_mu(asimov_mu_prime))
144 static Double_t PValue(const IncompatFunc &compatRegions, double k, double mu, double mu_prime,
145 double sigma_mu = 0, double mu_low = -std::numeric_limits<double>::infinity(),
146 double mu_high = std::numeric_limits<double>::infinity());
147
148 static Double_t PValue(const PLLType &pllType, double k, double mu, double mu_prime, double sigma_mu = 0,
149 double mu_low = -std::numeric_limits<double>::infinity(),
150 double mu_high = std::numeric_limits<double>::infinity())
151 {
152 return PValue(IncompatibilityFunction(pllType, mu), k, mu, mu_prime, sigma_mu, mu_low, mu_high);
153 }
154
155 static Double_t Phi_m(double mu, double mu_prime, double a, double sigma, const IncompatFunc &compatRegions);
156
157 static int CompatFactor(const IncompatFunc &func, double mu_hat);
158
159 static int CompatFactor(int type, double mu, double mu_hat)
160 {
161 return CompatFactor(IncompatibilityFunction((PLLType)type, mu), mu_hat);
162 }
163
164 // converts pvalues to significances and finds where they equal the target pvalue
165 // return is x-axis value with potentially an error on that value if input pVals had errors
166 // static RooRealVar FindLimit(TGraph *pVals, double target_pVal = 0.05);
167 };
168
169 // Run hypothesis test(s) on the given pdf
170 // Uses hypoPoint binning on model parameters to determine points to scan
171 // if hypoPoint binning has nBins==0 then will auto-scan (assumes CL=95%, can override with setStringAttribute)
172 // TODO: specifying number of null and alt toys per point
173 static TCanvas *
174 hypoTest(RooWorkspace &w, const xRooFit::Asymptotics::PLLType &pllType = xRooFit::Asymptotics::Unknown)
175 {
176 return hypoTest(w, 0, 0, pllType);
177 }
178 static TCanvas *hypoTest(RooWorkspace &w, int nToysNull, int nToysAlt,
179 const xRooFit::Asymptotics::PLLType &pllType = xRooFit::Asymptotics::Unknown);
180};
181
183
184#include "xRooHypoSpace.h"
185#include "xRooNLLVar.h"
186#include "xRooNode.h"
187
188#endif // include guard
#define a(i)
Definition RSha256.hxx:99
Int_t minos()
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition FitConfig.h:47
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:59
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition RooCmdArg.h:26
static const RooCmdArg & none()
Return reference to null argument.
Definition RooCmdArg.cxx:51
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
std::vector< std::pair< double, int > > IncompatFunc
Definition xRooFit.h:93
static Double_t k(const IncompatFunc &compatRegions, double pValue, double poiVal, double poiPrimeVal, double sigma_mu=0, double mu_low=-std::numeric_limits< double >::infinity(), double mu_high=std::numeric_limits< double >::infinity())
static Double_t PValue(const IncompatFunc &compatRegions, double k, double mu, double mu_prime, double sigma_mu=0, double mu_low=-std::numeric_limits< double >::infinity(), double mu_high=std::numeric_limits< double >::infinity())
static IncompatFunc IncompatibilityFunction(const PLLType &type, double mu)
Definition xRooFit.h:108
static Double_t k(const PLLType &pllType, double pValue, double mu, double mu_prime, double sigma_mu=0, double mu_low=-std::numeric_limits< double >::infinity(), double mu_high=std::numeric_limits< double >::infinity())
Definition xRooFit.h:136
static Double_t PValue(const PLLType &pllType, double k, double mu, double mu_prime, double sigma_mu=0, double mu_low=-std::numeric_limits< double >::infinity(), double mu_high=std::numeric_limits< double >::infinity())
Definition xRooFit.h:148
static int CompatFactor(int type, double mu, double mu_hat)
Definition xRooFit.h:159
static TCanvas * hypoTest(RooWorkspace &w, const xRooFit::Asymptotics::PLLType &pllType=xRooFit::Asymptotics::Unknown)
Definition xRooFit.h:174
static TCanvas * hypoTest(RooWorkspace &w, int nToysNull, int nToysAlt, const xRooFit::Asymptotics::PLLType &pllType=xRooFit::Asymptotics::Unknown)
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
The RooWorkspace is a persistable container for RooFit projects.
The Canvas class.
Definition TCanvas.h:23
const Double_t sigma
#define BEGIN_XROOFIT_NAMESPACE
Definition Config.h:24
#define END_XROOFIT_NAMESPACE
Definition Config.h:25