Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
example.py
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 Python.
4##
5## \macro_code
6## \macro_output
7##
8## \author George Lewis
9
10def main():
11
12 try:
13 import ROOT
14 except:
15 print("It seems that pyROOT isn't properly configured")
16 return
17
18 """
19 Create a HistFactory measurement from python
20 """
21
22 InputFile = "./data/example.root"
23
24 # Create the measurement
25 meas = ROOT.RooStats.HistFactory.Measurement("meas", "meas")
26
27 meas.SetOutputFilePrefix( "./results/example_UsingPy" )
28 meas.SetPOI( "SigXsecOverSM" )
29 meas.AddConstantParam("Lumi")
30 meas.AddConstantParam("alpha_syst1")
31
32 meas.SetLumi( 1.0 )
33 meas.SetLumiRelErr( 0.10 )
34 meas.SetExportOnly( False )
35
36 # Create a channel
37
38 chan = ROOT.RooStats.HistFactory.Channel( "channel1" )
39 chan.SetData( "data", InputFile )
40 chan.SetStatErrorConfig( 0.05, "Poisson" )
41
42 # Now, create some samples
43
44 # Create the signal sample
45 signal = ROOT.RooStats.HistFactory.Sample( "signal", "signal", InputFile )
46 signal.AddOverallSys( "syst1", 0.95, 1.05 )
47 signal.AddNormFactor( "SigXsecOverSM", 1, 0, 3 )
48 chan.AddSample( signal )
49
50
51 # Background 1
52 background1 = ROOT.RooStats.HistFactory.Sample( "background1", "background1", InputFile )
53 background1.ActivateStatError( "background1_statUncert", InputFile )
54 background1.AddOverallSys( "syst2", 0.95, 1.05 )
55 chan.AddSample( background1 )
56
57
58 # Background 1
59 background2 = ROOT.RooStats.HistFactory.Sample( "background2", "background2", InputFile )
60 background2.ActivateStatError()
61 background2.AddOverallSys( "syst3", 0.95, 1.05 )
62 chan.AddSample( background2 )
63
64
65 # Done with this channel
66 # Add it to the measurement:
67
68 meas.AddChannel( chan )
69
70 # Collect the histograms from their files,
71 # print some output,
72 meas.CollectHistograms()
73 meas.PrintTree();
74
75 # One can print XML code to an
76 # output directory:
77 # meas.PrintXML( "xmlFromCCode", meas.GetOutputFilePrefix() );
78
79 meas.PrintXML( "xmlFromPy", meas.GetOutputFilePrefix() );
80
81 # Now, do the measurement
82 ROOT.RooStats.HistFactory.MakeModelAndMeasurementFast( meas );
83
84 pass
85
86
87if __name__ == "__main__":
88 main()
int main()
Definition Prototype.cxx:12