-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunModel_monox.py
69 lines (54 loc) · 2.84 KB
/
runModel_monox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#########################################################################################
# Setup the basics ----> USER DEFINED SECTION HERE ------------------------------------//
fOutName = "combined_model.root" # --> Output file
fName = "mono-x.root" # --> input file (i.e output from previous)
#fName = "mono-x-smoothed.root" # --> input file (i.e output from previous)
categories = ["monox_doublebp_mass0","monox_doublebf_mass0","monox_doublebp_mass1","monox_doublebf_mass1","monox_doublebp_mass2","monox_doublebf_mass2","monox_doublebp_mass3","monox_doublebf_mass3"] # --> Should be labeled as in original config
controlregions_def = ["Z_constraints_monox","W_constraints_monox","Top_constraints_monox"] # --> configuration configs for control region fits.
# Note if one conrol region def depends on another (i,e if setDependant() is called) it must come AFTER its
# the one it depends on in this list!
#--------------------------------------------------------------------------------------//
#########################################################################################
# Leave the following alone!
# Headers
#from combineControlRegions import *
from pullPlot import pullPlot
from counting_experiment import *
from convert import *
from HiggsAnalysis.CombinedLimit.ModelTools import *
import ROOT as r
ROOT.gSystem.AddIncludePath("-I$CMSSW_BASE/src/ ");
ROOT.gSystem.AddIncludePath("-I$ROOFITSYS/include");
#ROOT.gSystem.AddIncludePath("-I$ROOSYS/include");
ROOT.gSystem.Load("libRooFit.so")
ROOT.gSystem.Load("libRooFitCore.so")
#ROOT.gSystem.AddIncludePath("-I$ROOTSYS/include -I$ROOFITSYS/include");
#ROOT.gSystem.Load("libRooFit");
r.gROOT.SetBatch(1)
r.gROOT.ProcessLine(".L diagonalizer.cc+")
from ROOT import diagonalizer
_fOut = r.TFile(fOutName,"RECREATE")
_f = r.TFile.Open(fName)
out_ws = r.RooWorkspace("combinedws")
out_ws._import = SafeWorkspaceImporter(out_ws)
sampleType = r.RooCategory("bin_number","Bin Number");
obs = r.RooRealVar("observed","Observed Events bin",1)
out_ws._import(sampleType) # Global variables for dataset
out_ws._import(obs)
diag_combined = diagonalizer(out_ws)
obsargset = r.RooArgSet(out_ws.var("observed"),out_ws.cat("bin_number"))
cmb_categories = []
for crd,crn in enumerate(controlregions_def):
x = __import__(crn)
for cid,cn in enumerate(categories):
_fDir = _fOut.mkdir("%s_category_%s"%(crn,cn))
cmb_categories.append(x.cmodel(cn,crn,_f,_fDir,out_ws,diag_combined))
for cid,cn in enumerate(cmb_categories):
cn.init_channels()
channels = cn.ret_channels()
# Save a Pre-fit snapshot
out_ws.saveSnapshot("PRE_EXT_FIT_Clean",out_ws.allVars())
# Now convert workspace to combine friendly workspace
convertToCombineWorkspace(out_ws,_f,categories,cmb_categories,controlregions_def)
_fOut.WriteTObject(out_ws)
print "Produced constraints model in --> ", _fOut.GetName()