ROOT
v6-32
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
10
def
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
if
(
ROOT.gSystem.AccessPathName
(InputFile)) :
24
ROOT.Info
(
"example.py"
, InputFile+
" does not exist"
)
25
exit
()
26
27
# Create the measurement
28
meas =
ROOT.RooStats.HistFactory.Measurement
(
"meas"
,
"meas"
)
29
30
meas.SetOutputFilePrefix
(
"./results/example_UsingPy"
)
31
meas.SetPOI
(
"SigXsecOverSM"
)
32
meas.AddConstantParam
(
"Lumi"
)
33
meas.AddConstantParam
(
"alpha_syst1"
)
34
35
meas.SetLumi
( 1.0 )
36
meas.SetLumiRelErr
( 0.10 )
37
meas.SetExportOnly
(
False
)
38
39
# Create a channel
40
41
chan =
ROOT.RooStats.HistFactory.Channel
(
"channel1"
)
42
chan.SetData
(
"data"
, InputFile )
43
chan.SetStatErrorConfig
( 0.05,
"Poisson"
)
44
45
# Now, create some samples
46
47
# Create the signal sample
48
signal =
ROOT.RooStats.HistFactory.Sample
(
"signal"
,
"signal"
, InputFile )
49
signal.AddOverallSys
(
"syst1"
, 0.95, 1.05 )
50
signal.AddNormFactor
(
"SigXsecOverSM"
, 1, 0, 3 )
51
chan.AddSample
( signal )
52
53
54
# Background 1
55
background1 =
ROOT.RooStats.HistFactory.Sample
(
"background1"
,
"background1"
, InputFile )
56
background1.ActivateStatError
(
"background1_statUncert"
, InputFile )
57
background1.AddOverallSys
(
"syst2"
, 0.95, 1.05 )
58
chan.AddSample
( background1 )
59
60
61
# Background 1
62
background2 =
ROOT.RooStats.HistFactory.Sample
(
"background2"
,
"background2"
, InputFile )
63
background2.ActivateStatError
()
64
background2.AddOverallSys
(
"syst3"
, 0.95, 1.05 )
65
chan.AddSample
( background2 )
66
67
68
# Done with this channel
69
# Add it to the measurement:
70
71
meas.AddChannel
( chan )
72
73
# Collect the histograms from their files,
74
# print some output,
75
meas.CollectHistograms
()
76
meas.PrintTree
();
77
78
# One can print XML code to an
79
# output directory:
80
# meas.PrintXML( "xmlFromCCode", meas.GetOutputFilePrefix() );
81
82
meas.PrintXML
(
"xmlFromPy"
,
meas.GetOutputFilePrefix
() );
83
84
# Now, do the measurement
85
ROOT.RooStats.HistFactory.MakeModelAndMeasurementFast
( meas );
86
87
pass
88
89
90
if
__name__ ==
"__main__"
:
91
main
()
main
int main()
Definition
Prototype.cxx:12
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
tutorials
histfactory
example.py
ROOT v6-32 - Reference Guide Generated on Mon Feb 17 2025 04:40:36 (GVA Time) using Doxygen 1.10.0