try:
import ROOT
except:
print("It seems that pyROOT isn't properly configured")
return
"""
Create a HistFactory measurement from python
"""
InputFile = "./data/example.root"
if (ROOT.gSystem.AccessPathName(InputFile)) :
ROOT.Info("example.py", InputFile+" does not exist")
exit()
meas = ROOT.RooStats.HistFactory.Measurement("meas", "meas")
meas.SetOutputFilePrefix( "./results/example_UsingPy" )
meas.SetPOI( "SigXsecOverSM" )
meas.AddConstantParam("Lumi")
meas.AddConstantParam("alpha_syst1")
meas.SetLumi( 1.0 )
meas.SetLumiRelErr( 0.10 )
meas.SetExportOnly( False )
chan = ROOT.RooStats.HistFactory.Channel( "channel1" )
chan.SetData( "data", InputFile )
chan.SetStatErrorConfig( 0.05, "Poisson" )
signal = ROOT.RooStats.HistFactory.Sample( "signal", "signal", InputFile )
signal.AddOverallSys( "syst1", 0.95, 1.05 )
signal.AddNormFactor( "SigXsecOverSM", 1, 0, 3 )
chan.AddSample( signal )
background1 = ROOT.RooStats.HistFactory.Sample( "background1", "background1", InputFile )
background1.ActivateStatError( "background1_statUncert", InputFile )
background1.AddOverallSys( "syst2", 0.95, 1.05 )
chan.AddSample( background1 )
background2 = ROOT.RooStats.HistFactory.Sample( "background2", "background2", InputFile )
background2.ActivateStatError()
background2.AddOverallSys( "syst3", 0.95, 1.05 )
chan.AddSample( background2 )
meas.AddChannel( chan )
meas.CollectHistograms()
meas.PrintTree();
meas.PrintXML( "xmlFromPy", meas.GetOutputFilePrefix() );
ROOT.RooStats.HistFactory.MakeModelAndMeasurementFast( meas );
pass
if __name__ == "__main__":