Logo ROOT   6.16/01
Reference Guide
example.C
Go to the documentation of this file.
1
4#include "TFile.h"
5#include "TROOT.h"
6
7using namespace RooStats;
8using namespace HistFactory;
9
10
11/*
12
13 A ROOT script demonstrating
14 an example of writing a HistFactory
15 model using c++ only.
16
17 This example was written to match
18 the example.xml analysis in
19 $ROOTSYS/tutorials/histfactory/
20
21 Written by George Lewis
22
23 */
24
25
26void example() {
27
28
29 std::string InputFile = "./data/example.root";
30 // in case the file is not found
31 bool bfile = gSystem->AccessPathName(InputFile.c_str());
32 if (bfile) {
33 std::cout << "Input file is not found - run prepareHistFactory script " << std::endl;
34 gROOT->ProcessLine(".! prepareHistFactory .");
35 bfile = gSystem->AccessPathName(InputFile.c_str());
36 if (bfile) {
37 std::cout << "Still no " << InputFile << ", giving up.\n";
38 exit(1);
39 }
40 }
41
42 // Create the measurement
43 Measurement meas("meas", "meas");
44
45 meas.SetOutputFilePrefix( "./results/example_UsingC" );
46 meas.SetPOI( "SigXsecOverSM" );
47 meas.AddConstantParam("alpha_syst1");
48 meas.AddConstantParam("Lumi");
49
50 meas.SetLumi( 1.0 );
51 meas.SetLumiRelErr( 0.10 );
52 meas.SetExportOnly( false );
53 meas.SetBinHigh( 2 );
54
55 // Create a channel
56
57 Channel chan( "channel1" );
58 chan.SetData( "data", InputFile );
59 chan.SetStatErrorConfig( 0.05, "Poisson" );
60
61
62 // Now, create some samples
63
64
65 // Create the signal sample
66 Sample signal( "signal", "signal", InputFile );
67 signal.AddOverallSys( "syst1", 0.95, 1.05 );
68 signal.AddNormFactor( "SigXsecOverSM", 1, 0, 3 );
69 chan.AddSample( signal );
70
71 // Background 1
72 Sample background1( "background1", "background1", InputFile );
73 background1.ActivateStatError( "background1_statUncert", InputFile );
74 background1.AddOverallSys( "syst2", 0.95, 1.05 );
75 chan.AddSample( background1 );
76
77
78 // Background 1
79 Sample background2( "background2", "background2", InputFile );
80 background2.ActivateStatError();
81 background2.AddOverallSys( "syst3", 0.95, 1.05 );
82 chan.AddSample( background2 );
83
84
85 // Done with this channel
86 // Add it to the measurement:
87 meas.AddChannel( chan );
88
89 // Collect the histograms from their files,
90 // print some output,
91 meas.CollectHistograms();
92 meas.PrintTree();
93
94 // One can print XML code to an
95 // output directory:
96 // meas.PrintXML( "xmlFromCCode", meas.GetOutputFilePrefix() );
97
98 // Now, do the measurement
100
101
102}
#define gROOT
Definition: TROOT.h:410
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
This class encapsulates all information for the statistical interpretation of one experiment.
Definition: Channel.h:26
void SetData(const RooStats::HistFactory::Data &data)
set data object
Definition: Channel.h:50
void AddSample(RooStats::HistFactory::Sample sample)
Definition: Channel.cxx:65
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
Definition: Channel.cxx:201
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
Definition: Measurement.h:30
void SetExportOnly(bool ExportOnly)
do not produce any plots or tables, just save the model
Definition: Measurement.h:98
void SetLumi(double Lumi)
set integrated luminosity used to normalise histograms (if NormalizeByTheory is true for this sample)
Definition: Measurement.h:84
void AddChannel(RooStats::HistFactory::Channel chan)
add a completely configured channel
Definition: Measurement.h:108
void SetOutputFilePrefix(const std::string &prefix)
set output prefix
Definition: Measurement.h:40
void PrintTree(std::ostream &=std::cout)
void SetPOI(const std::string &POI)
insert PoI at beginning of vector of PoIs
Definition: Measurement.h:45
void AddConstantParam(const std::string &param)
Add a parameter to be set as constant (Similar to ParamSetting method below)
Definition: Measurement.cxx:59
void SetLumiRelErr(double RelErr)
set relative uncertainty on luminosity
Definition: Measurement.h:86
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:1286
void example()
Definition: example.C:26
RooWorkspace * MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement)
Make a model from histograms.
@(#)root/roostats:$Id$ Author: George Lewis, Kyle Cranmer
Definition: Asimov.h:20