Skip to content

Commit

Permalink
Merge pull request #16 from kit-cn-cms/dev_philip
Browse files Browse the repository at this point in the history
Dev philip
  • Loading branch information
pkausw authored Nov 23, 2018
2 parents 0589eeb + fddf3d0 commit b38bf99
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
49 changes: 33 additions & 16 deletions src/categoryObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def observation(self, data_obs):
s = "Will generate observation with name '%s'" % data_obs
s+= " in category %s" % self._name
print s
self._data_obs = self.create_process(process_name = data_obs)
self._create_process(processName = data_obs)
else:
print "ERROR: Cannot add object of type %s as observation!" % type(data_obs)

Expand All @@ -115,6 +115,11 @@ def signal_processes(self):
def background_processes(self):
return self._bkgprocs

@property
def process_list(self):
return self._signalprocs.keys() + self._bkgprocs.keys()



@property
def generic_key_nominal_hist(self):
Expand Down Expand Up @@ -208,7 +213,7 @@ def create_background_process( self, processName, rootfile = None,
systkey = systkey)


def _create_process(self, processName, dic, rootfile = None,
def _create_process(self, processName, dic = None, rootfile = None,
histoname = None, systkey = None):
categoryName=self.name
if histoname is None:
Expand All @@ -226,8 +231,10 @@ def _create_process(self, processName, dic, rootfile = None,
pathToRootfile = rootfile,
nominal_hist_key = histoname,
systematic_hist_key = systkey)
self._add_process(dic=dic, process=processObj)

if dic is None:
self._data_obs = processObj
else:
self._add_process(dic=dic, process=processObj)

def add_signal_process( self, process):
"""
Expand Down Expand Up @@ -264,8 +271,7 @@ def _add_process(self, dic, process):
def delete_processes(self,list_of_processes):
for process in list_of_processes:
self.delete_process(processName=process)
if self._debug>30:
print "DEBUG: deleted process %s" % processName


def delete_process(self,processName):
if processName in self._signalprocs:
Expand Down Expand Up @@ -314,14 +320,14 @@ def add_from_csv(self,pathToFile,signaltag="ttH",lumi=1.025, bgnorm=1.5):
initialize processes
"""
for process in processes:
clear_procname = process.strip()
if not process in self:
if signaltag in process:
self.create_signal_process(processName=process)
if signaltag in clear_procname:
self.create_signal_process(processName=clear_procname)
else:
self.create_background_process(processName=process)
self.create_background_process(processName=clear_procname)
else:
print "found process", process
temp_process = self[process]
print "found process", clear_procname
"""
add uncertainties to process
"""
Expand All @@ -330,7 +336,7 @@ def add_from_csv(self,pathToFile,signaltag="ttH",lumi=1.025, bgnorm=1.5):
typ = typ.strip()
uncertainty = uncertainty.strip()
if self._debug >= 99:
print "DEBUG: adding combination ({0},\t{1},\t{2}) for {3}".format(uncertainty,typ,value, process)
print "DEBUG: adding combination ({0},\t{1},\t{2}) for {3}".format(uncertainty,typ,value, clear_procname)
"""
lumi and bgnorm uncertainties can be used as an argument, not set in CSV files
"""
Expand All @@ -340,13 +346,14 @@ def add_from_csv(self,pathToFile,signaltag="ttH",lumi=1.025, bgnorm=1.5):
elif "bgnorm" in uncertainty and (value == "x" or value == "X"):
value = bgnorm
print "changing value to", value

if not value is "-":
if uncertainty in self[process]._uncertainties:
if uncertainty in self[clear_procname]._uncertainties:
if self._debug >=30:
print "DEBUG: setting {0} to \t{1} and \t{2} for process {3}".format(uncertainty,typ,value, process)
self[process].set_uncertainty(syst=uncertainty,typ=typ,value=value)
print "DEBUG: setting {0} to \t{1} and \t{2} for process {3}".format(uncertainty,typ,value, clear_procname)
self[clear_procname].set_uncertainty(syst=uncertainty,typ=typ,value=value)
else:
self[process].add_uncertainty(syst=uncertainty,typ=typ,value=value)
self[clear_procname].add_uncertainty(syst=uncertainty,typ=typ,value=value)

"""
overloaded get, in and for operator to get better access to processes in
Expand Down Expand Up @@ -384,11 +391,21 @@ def __str__(self):
s = []
s.append("Category Name:\t%s" % self._name)
s.append("Default source file:\t%s" % self._default_file)
if self.observation:
oname = self.observation.name
ocount = str(self.observation.eventcount)
else:
oname = "Not set"
ocount = oname
s.append("Observations: %s (yield: %s)" % (oname, ocount))
s.append("List of signal processes:")
for sig in self._signalprocs:
s.append("\t%s" % self._signalprocs[sig])

s.append("List of background processes:")
for bkg in self._bkgprocs:
s.append("\t%s" % self._bkgprocs[bkg])


return "\n".join(s)

10 changes: 4 additions & 6 deletions src/datacardMaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ def init_variables(self):

def __init__( self, analysis,
outputpath = "", replacefiles=False,
hardcodenumbers=False,
processIdentifier = "$PROCESS",
channelIdentifier = "$CHANNEL",
systIdentifier = "$SYSTEMATIC"):
hardcodenumbers=False):
self.init_variables()
if replacefiles:
self.replace_files = replacefiles
Expand Down Expand Up @@ -310,7 +307,7 @@ def create_observation_block(self,analysis):
bins.append("%s" % category)
data_obs = analysis[category].observation
if isinstance(data_obs, processObject):
if self._hardcode_numbers:
if not self._hardcode_numbers:
observation.append("-1")
else:
observation.append("%s" % str(data_obs.eventcount))
Expand Down Expand Up @@ -445,7 +442,8 @@ def create_systematics_block(self,analysis):

lines = []

for systematic in analysis.systematics:

for systematic in sorted(analysis.systematics):
temp="%s" % systematic.ljust(size)
temp+="%s" % str(analysis.systematics[systematic].type).ljust(size)
for category in analysis.categories:
Expand Down

0 comments on commit b38bf99

Please sign in to comment.