Logo ROOT   6.12/07
Reference Guide
example.C
Go to the documentation of this file.
1 
4 #include "TFile.h"
5 #include "TROOT.h"
6 
7 using namespace RooStats;
8 using 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 
26 void 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 }
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:1276
void SetData(const RooStats::HistFactory::Data &data)
Definition: Channel.h:50
void SetPOI(const std::string &POI)
Definition: Measurement.h:45
void SetStatErrorConfig(double RelErrorThreshold, Constraint::Type ConstraintType)
Definition: Channel.cxx:206
void ActivateStatError()
Note that histogram name should not include the path of the histogram in the file.
Definition: Sample.cxx:293
RooWorkspace * MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement)
void SetOutputFilePrefix(const std::string &prefix)
Definition: Measurement.h:40
#define gROOT
Definition: TROOT.h:402
void SetExportOnly(bool ExportOnly)
Definition: Measurement.h:98
void AddChannel(RooStats::HistFactory::Channel chan)
Definition: Measurement.h:108
void example()
Definition: example.C:26
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
void AddConstantParam(const std::string &param)
Definition: Measurement.cxx:65
void AddOverallSys(std::string Name, Double_t Low, Double_t High)
Definition: Sample.cxx:314
void AddSample(RooStats::HistFactory::Sample sample)
Definition: Channel.cxx:70
void AddNormFactor(std::string Name, Double_t Val, Double_t Low, Double_t High, bool Const=false)
Definition: Sample.cxx:329
Namespace for the RooStats classes.
Definition: Asimov.h:20
void SetLumiRelErr(double RelErr)
Definition: Measurement.h:86
void PrintTree(std::ostream &=std::cout)