Logo ROOT  
Reference Guide
hf001_example.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_histfactory
3 /// A ROOT script demonstrating an example of writing a HistFactory model using c++ only.
4 ///
5 /// \macro_code
6 /// \macro_output
7 ///
8 /// \author George Lewis
9 
10 
13 #include "TFile.h"
14 #include "TROOT.h"
15 
16 using namespace RooStats;
17 using namespace HistFactory;
18 
19 void hf001_example() {
20 
21 
22  std::string InputFile = "./data/example.root";
23  // in case the file is not found
24  bool bfile = gSystem->AccessPathName(InputFile.c_str());
25  if (bfile) {
26  std::cout << "Input file is not found - run prepareHistFactory script " << std::endl;
27  gROOT->ProcessLine(".! prepareHistFactory .");
28  bfile = gSystem->AccessPathName(InputFile.c_str());
29  if (bfile) {
30  std::cout << "Still no " << InputFile << ", giving up.\n";
31  exit(1);
32  }
33  }
34 
35  // Create the measurement
36  Measurement meas("meas", "meas");
37 
38  meas.SetOutputFilePrefix( "./results/example_UsingC" );
39  meas.SetPOI( "SigXsecOverSM" );
40  meas.AddConstantParam("alpha_syst1");
41  meas.AddConstantParam("Lumi");
42 
43  meas.SetLumi( 1.0 );
44  meas.SetLumiRelErr( 0.10 );
45  meas.SetExportOnly( false );
46  meas.SetBinHigh( 2 );
47 
48  // Create a channel
49 
50  Channel chan( "channel1" );
51  chan.SetData( "data", InputFile );
52  chan.SetStatErrorConfig( 0.05, "Poisson" );
53 
54 
55  // Now, create some samples
56 
57 
58  // Create the signal sample
59  Sample signal( "signal", "signal", InputFile );
60  signal.AddOverallSys( "syst1", 0.95, 1.05 );
61  signal.AddNormFactor( "SigXsecOverSM", 1, 0, 3 );
62  chan.AddSample( signal );
63 
64  // Background 1
65  Sample background1( "background1", "background1", InputFile );
66  background1.ActivateStatError( "background1_statUncert", InputFile );
67  background1.AddOverallSys( "syst2", 0.95, 1.05 );
68  chan.AddSample( background1 );
69 
70 
71  // Background 1
72  Sample background2( "background2", "background2", InputFile );
73  background2.ActivateStatError();
74  background2.AddOverallSys( "syst3", 0.95, 1.05 );
75  chan.AddSample( background2 );
76 
77 
78  // Done with this channel
79  // Add it to the measurement:
80  meas.AddChannel( chan );
81 
82  // Collect the histograms from their files,
83  // print some output,
84  meas.CollectHistograms();
85  meas.PrintTree();
86 
87  // One can print XML code to an
88  // output directory:
89  // meas.PrintXML( "xmlFromCCode", meas.GetOutputFilePrefix() );
90 
91  // Now, do the measurement
93 
94 
95 }
TSystem::AccessPathName
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:1295
RooFit::HistFactory
@ HistFactory
Definition: RooGlobalFunc.h:62
TFile.h
MakeModelAndMeasurementsFast.h
TROOT.h
Measurement.h
RooStats::HistFactory::MakeModelAndMeasurementFast
RooWorkspace * MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement)
Definition: MakeModelAndMeasurementsFast.cxx:104
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
RooStats
Namespace for the RooStats classes.
Definition: Asimov.h:19
gROOT
#define gROOT
Definition: TROOT.h:404