Logo ROOT   6.14/05
Reference Guide
example.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #
4 # A pyROOT script demonstrating
5 # an example of writing a HistFactory
6 # model using python
7 #
8 # This example was written to match
9 # the example.xml analysis in
10 # $ROOTSYS/tutorials/histfactory/
11 #
12 # Written by George Lewis
13 #
14 
15 
16 def main():
17 
18  try:
19  import ROOT
20  except:
21  print "It seems that pyROOT isn't properly configured"
22  return
23 
24  """
25  Create a HistFactory measurement from python
26  """
27 
28  InputFile = "./data/example.root"
29 
30  # Create the measurement
31  meas = ROOT.RooStats.HistFactory.Measurement("meas", "meas")
32 
33  meas.SetOutputFilePrefix( "./results/example_UsingPy" )
34  meas.SetPOI( "SigXsecOverSM" )
35  meas.AddConstantParam("Lumi")
36  meas.AddConstantParam("alpha_syst1")
37 
38  meas.SetLumi( 1.0 )
39  meas.SetLumiRelErr( 0.10 )
40  meas.SetExportOnly( False )
41 
42  # Create a channel
43 
44  chan = ROOT.RooStats.HistFactory.Channel( "channel1" )
45  chan.SetData( "data", InputFile )
46  chan.SetStatErrorConfig( 0.05, "Poisson" )
47 
48  # Now, create some samples
49 
50  # Create the signal sample
51  signal = ROOT.RooStats.HistFactory.Sample( "signal", "signal", InputFile )
52  signal.AddOverallSys( "syst1", 0.95, 1.05 )
53  signal.AddNormFactor( "SigXsecOverSM", 1, 0, 3 )
54  chan.AddSample( signal )
55 
56 
57  # Background 1
58  background1 = ROOT.RooStats.HistFactory.Sample( "background1", "background1", InputFile )
59  background1.ActivateStatError( "background1_statUncert", InputFile )
60  background1.AddOverallSys( "syst2", 0.95, 1.05 )
61  chan.AddSample( background1 )
62 
63 
64  # Background 1
65  background2 = ROOT.RooStats.HistFactory.Sample( "background2", "background2", InputFile )
66  background2.ActivateStatError()
67  background2.AddOverallSys( "syst3", 0.95, 1.05 )
68  chan.AddSample( background2 )
69 
70 
71  # Done with this channel
72  # Add it to the measurement:
73 
74  meas.AddChannel( chan )
75 
76  # Collect the histograms from their files,
77  # print some output,
78  meas.CollectHistograms()
79  meas.PrintTree();
80 
81  # One can print XML code to an
82  # output directory:
83  # meas.PrintXML( "xmlFromCCode", meas.GetOutputFilePrefix() );
84 
85  meas.PrintXML( "xmlFromPy", meas.GetOutputFilePrefix() );
86 
87  # Now, do the measurement
88  ROOT.RooStats.HistFactory.MakeModelAndMeasurementFast( meas );
89 
90  pass
91 
92 
93 if __name__ == "__main__":
94  main()
def main()
Definition: example.py:16