Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
StandardFeldmanCousinsDemo.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Standard demo of the Feldman-Cousins calculator StandardFeldmanCousinsDemo

This is a standard demo that can be used with any ROOT file prepared in the standard way. You specify:

  • name for input ROOT file
  • name of workspace inside ROOT file that holds model and data
  • name of ModelConfig that specifies details for calculator tools
  • name of dataset

With default parameters the macro will attempt to run the standard hist2workspace example and read the ROOT file that it produces.

The actual heart of the demo is only about 10 lines long.

The FeldmanCousins tools is a classical frequentist calculation based on the Neyman Construction. The test statistic can be generalized for nuisance parameters by using the profile likelihood ratio. But unlike the ProfileLikelihoodCalculator, this tool explicitly builds the sampling distribution of the test statistic via toy Monte Carlo.

=== Using the following for ModelConfig ===
Observables: RooArgSet:: = (obs_x_channel1,channelCat)
Parameters of Interest: RooArgSet:: = (SigXsecOverSM)
Nuisance Parameters: RooArgSet:: = (alpha_syst2,alpha_syst3,gamma_stat_channel1_bin_0,gamma_stat_channel1_bin_1)
Global Observables: RooArgSet:: = (nominalLumi,nom_alpha_syst1,nom_alpha_syst2,nom_alpha_syst3,nom_gamma_stat_channel1_bin_0,nom_gamma_stat_channel1_bin_1)
PDF: RooSimultaneous::simPdf[ indexCat=channelCat channel1=model_channel1 ] = 0.190787
FeldmanCousins: ntoys per point: adaptive
FeldmanCousins: nEvents per toy will fluctuate about expectation
FeldmanCousins: Model has nuisance parameters, will do profile construction
FeldmanCousins: # points to test = 10
lookup index = 0
NeymanConstruction: Prog: 1/10 total MC = 78 this test stat = 1.32297
SigXsecOverSM=0.15 alpha_syst2=0.602143 alpha_syst3=0.227772 gamma_stat_channel1_bin_0=1.03121 gamma_stat_channel1_bin_1=1.04626 [-inf, 3.00302] in interval = 1
NeymanConstruction: Prog: 2/10 total MC = 78 this test stat = 0.622271
SigXsecOverSM=0.45 alpha_syst2=0.407504 alpha_syst3=0.166261 gamma_stat_channel1_bin_0=1.0207 gamma_stat_channel1_bin_1=1.03105 [-inf, 2.56102] in interval = 1
NeymanConstruction: Prog: 3/10 total MC = 78 this test stat = 0.185599
SigXsecOverSM=0.75 alpha_syst2=0.213102 alpha_syst3=0.0987913 gamma_stat_channel1_bin_0=1.01077 gamma_stat_channel1_bin_1=1.01853 [-inf, 1.34636] in interval = 1
NeymanConstruction: Prog: 4/10 total MC = 78 this test stat = 0.00589021
SigXsecOverSM=1.05 alpha_syst2=0.0285809 alpha_syst3=0.0409103 gamma_stat_channel1_bin_0=1.00142 gamma_stat_channel1_bin_1=1.00599 [-inf, 1.11873] in interval = 1
NeymanConstruction: Prog: 5/10 total MC = 78 this test stat = 0.0746369
SigXsecOverSM=1.35 alpha_syst2=-0.137558 alpha_syst3=-0.0496314 gamma_stat_channel1_bin_0=0.993073 gamma_stat_channel1_bin_1=0.994154 [-inf, 2.18034] in interval = 1
NeymanConstruction: Prog: 6/10 total MC = 78 this test stat = 0.383697
SigXsecOverSM=1.65 alpha_syst2=-0.307933 alpha_syst3=-0.098712 gamma_stat_channel1_bin_0=0.984872 gamma_stat_channel1_bin_1=0.982202 [-inf, 1.23693] in interval = 1
NeymanConstruction: Prog: 7/10 total MC = 78 this test stat = 0.924084
SigXsecOverSM=1.95 alpha_syst2=-0.46183 alpha_syst3=-0.162016 gamma_stat_channel1_bin_0=0.977442 gamma_stat_channel1_bin_1=0.970551 [-inf, 1.89854] in interval = 1
NeymanConstruction: Prog: 8/10 total MC = 78 this test stat = 1.68896
SigXsecOverSM=2.25 alpha_syst2=-0.604401 alpha_syst3=-0.223564 gamma_stat_channel1_bin_0=0.970553 gamma_stat_channel1_bin_1=0.959142 [-inf, 2.02832] in interval = 1
NeymanConstruction: Prog: 9/10 total MC = 234 this test stat = 2.66964
SigXsecOverSM=2.55 alpha_syst2=-0.735442 alpha_syst3=-0.283315 gamma_stat_channel1_bin_0=0.964167 gamma_stat_channel1_bin_1=0.947986 [-inf, 2.14774] in interval = 0
NeymanConstruction: Prog: 10/10 total MC = 234 this test stat = 3.85849
SigXsecOverSM=2.85 alpha_syst2=-0.855772 alpha_syst3=-0.341177 gamma_stat_channel1_bin_0=0.958246 gamma_stat_channel1_bin_1=0.937094 [-inf, 2.28493] in interval = 0
[#1] INFO:Eval -- 8 points in interval
95% interval on SigXsecOverSM is : [0.15, 2.25]
#include "TFile.h"
#include "TROOT.h"
#include "TH1F.h"
#include "TSystem.h"
#include "RooWorkspace.h"
#include "RooAbsData.h"
using namespace RooFit;
using namespace RooStats;
void StandardFeldmanCousinsDemo(const char *infile = "", const char *workspaceName = "combined",
const char *modelConfigName = "ModelConfig", const char *dataName = "obsData")
{
// -------------------------------------------------------
// First part is just to access a user-defined file
// or create the standard example file if it doesn't exist
const char *filename = "";
if (!strcmp(infile, "")) {
filename = "results/example_combined_GaussExample_model.root";
bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code
// if file does not exists generate with histfactory
if (!fileExist) {
// Normally this would be run on the command line
cout << "will run standard hist2workspace example" << endl;
gROOT->ProcessLine(".! prepareHistFactory .");
gROOT->ProcessLine(".! hist2workspace config/example.xml");
cout << "\n\n---------------------" << endl;
cout << "Done creating example input" << endl;
cout << "---------------------\n\n" << endl;
}
} else
filename = infile;
// Try to open the file
// if input file was specified byt not found, quit
if (!file) {
cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
return;
}
// -------------------------------------------------------
// Tutorial starts here
// -------------------------------------------------------
// get the workspace out of the file
RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
if (!w) {
cout << "workspace not found" << endl;
return;
}
// get the modelConfig out of the file
ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);
// get the modelConfig out of the file
RooAbsData *data = w->data(dataName);
// make sure ingredients are found
if (!data || !mc) {
w->Print();
cout << "data or ModelConfig was not found" << endl;
return;
}
// -------------------------------------------------------
// create and use the FeldmanCousins tool
// to find and plot the 95% confidence interval
// on the parameter of interest as specified
// in the model config
FeldmanCousins fc(*data, *mc);
fc.SetConfidenceLevel(0.95); // 95% interval
// fc.AdditionalNToysFactor(0.1); // to speed up the result
fc.UseAdaptiveSampling(true); // speed it up a bit
fc.SetNBins(10); // set how many points per parameter of interest to scan
fc.CreateConfBelt(true); // save the information in the belt for plotting
// Since this tool needs to throw toy MC the PDF needs to be
// extended or the tool needs to know how many entries in a dataset
// per pseudo experiment.
// In the 'number counting form' where the entries in the dataset
// are counts, and not values of discriminating variables, the
// datasets typically only have one entry and the PDF is not
// extended.
if (!mc->GetPdf()->canBeExtended()) {
if (data->numEntries() == 1)
fc.FluctuateNumDataEntries(false);
else
cout << "Not sure what to do about this model" << endl;
}
// Now get the interval
PointSetInterval *interval = fc.GetInterval();
ConfidenceBelt *belt = fc.GetConfidenceBelt();
// print out the interval on the first Parameter of Interest
cout << "\n95% interval on " << firstPOI->GetName() << " is : [" << interval->LowerLimit(*firstPOI) << ", "
<< interval->UpperLimit(*firstPOI) << "] " << endl;
// ---------------------------------------------
// No nice plots yet, so plot the belt by hand
// Ask the calculator which points were scanned
RooDataSet *parameterScan = (RooDataSet *)fc.GetPointsToScan();
RooArgSet *tmpPoint;
// make a histogram of parameter vs. threshold
TH1F *histOfThresholds =
new TH1F("histOfThresholds", "", parameterScan->numEntries(), firstPOI->getMin(), firstPOI->getMax());
// loop through the points that were tested and ask confidence belt
// what the upper/lower thresholds were.
// For FeldmanCousins, the lower cut off is always 0
for (Int_t i = 0; i < parameterScan->numEntries(); ++i) {
tmpPoint = (RooArgSet *)parameterScan->get(i)->clone("temp");
double arMax = belt->GetAcceptanceRegionMax(*tmpPoint);
double arMin = belt->GetAcceptanceRegionMax(*tmpPoint);
double poiVal = tmpPoint->getRealValue(firstPOI->GetName());
histOfThresholds->Fill(poiVal, arMax);
}
histOfThresholds->SetMinimum(0);
histOfThresholds->Draw();
}
int Int_t
Definition RtypesCore.h:45
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 filename
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
double getRealValue(const char *name, double defVal=0.0, bool verbose=false) const
Get value of a RooAbsReal stored in set with given name.
RooAbsArg * first() const
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
Definition RooAbsPdf.h:218
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
TObject * clone(const char *newname) const override
Definition RooArgSet.h:111
Container class to hold unbinned data.
Definition RooDataSet.h:34
const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
ConfidenceBelt is a concrete implementation of the ConfInterval interface.
double GetAcceptanceRegionMax(RooArgSet &, double cl=-1., double leftside=-1.)
The FeldmanCousins class (like the Feldman-Cousins technique) is essentially a specific configuration...
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition ModelConfig.h:35
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return nullptr if pdf has not been specified or does not exist)
PointSetInterval is a concrete implementation of the ConfInterval interface.
double UpperLimit(RooRealVar &param)
return upper limit on a given parameter
double LowerLimit(RooRealVar &param)
return lower limit on a given parameter
Persistable container for RooFit projects.
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4086
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3346
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3068
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:406
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1296
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:64
Namespace for the RooStats classes.
Definition CodegenImpl.h:58
Author
Kyle Cranmer

Definition in file StandardFeldmanCousinsDemo.C.