Skip to content

Commit

Permalink
Merge pull request #23 from kit-cn-cms/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
pkausw authored Jan 13, 2019
2 parents a1dcca0 + d278321 commit b846975
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 151 deletions.
6 changes: 3 additions & 3 deletions base/fileHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class fileHandler(object):
The fileHandler class manages all access to files required for the analysis
TODO: Improve memory handling by cleverly closing files
"""
_debug = 200
_debug = 0

def init_variables(self):
self._filepath = "/path/to/file"
Expand Down Expand Up @@ -87,13 +87,13 @@ def load_histogram(self, histname):
print "DEBUG: entering 'fileHandler.load_histogram'"
if self._file:
if self._debug >= 10:
print "DEBUG: loading histogram '%s' from '%s'" % (histname, file)
print "DEBUG: loading histogram '%s' from '%s'" % (histname, self._file.GetName())
h = self._file.Get(histname)
if isinstance(h, TH1):
return h
else:
print ("WARNING: histogram '%s' does not exist in '%s'"
% (histname, file))
% (histname, self._file.GetName()))
else:
print "ERROR: In fileHandler - file is not set!"
return None
Expand Down
33 changes: 18 additions & 15 deletions base/identificationLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class identificationLogic(object):
, e.g. $SYSTEMATIC
(member variable: _systIden)
"""
_debug = 100
_debug = 0
_allowed_dependencies = ["process", "channel"]
def init_variables(self):
"""
Expand Down Expand Up @@ -66,11 +66,11 @@ def generic_nominal_key(self):
return self._generic_nom_key
@generic_nominal_key.setter
def generic_nominal_key(self, key):
if not self._procIden in key and self._debug >= 3:
if not self._procIden in key and self._debug >= 30:
s = "WARNING: process identification keyword '%s'" % self._procIden
s+= " is not part of new nominal key '%s'!" % key
print s
if not self._chIden in key and self._debug >= 3:
if not self._chIden in key and self._debug >= 30:
s = "WARNING: channel identification keyword '%s'" % self._chIden
s+= " is not part of new nominal key '%s'!" % key
print s
Expand All @@ -81,15 +81,15 @@ def generic_systematics_key(self):
return self._generic_syst_key
@generic_systematics_key.setter
def generic_systematics_key(self, key):
if not self._procIden in key:
if not self._procIden in key and self._debug >= 30:
s = "WARNING: process identification keyword '%s'" % self._procIden
s+= " is not part of new systematics key '%s'!" % key
print s
if not self._chIden in key:
if not self._chIden in key and self._debug >= 30:
s = "WARNING: channel identification keyword '%s'" % self._chIden
s+= " is not part of new systematics key '%s'!" % key
print s
if not self._systIden in key:
if not self._systIden in key and self._debug >= 30:
s = "WARNING: systematics ID keyword '%s'" % self._procIden
s+= " is not part of new systematics key '%s'!" % key
print s
Expand Down Expand Up @@ -132,17 +132,18 @@ def insert_channel(self, channel_name, base_key):
"""
build a key from 'base_key' for a specific channel 'channel_name'.
"""
print "-"*130
print "DEBUG Identification_logic INSERT_CHANNEL: entering function"
print "-"*130
if self._debug >= 90:
print "-"*130
print "DEBUG Identification_logic INSERT_CHANNEL: entering function"
print "-"*130
if base_key is None or base_key == "":
print "unsuitable base_key!"
return ""
print channel_name
if not channel_name == "" and not channel_name is None:
print "-"*130
print base_key
print "-"*130
if self._debug >= 90:
print "-"*130
print base_key
print "-"*130
if self._chIden in base_key:
s = base_key.replace(self._chIden, channel_name)
if self._debug >= 30:
Expand Down Expand Up @@ -186,10 +187,12 @@ def build_nominal_histo_name( self, process_name, channel_name = "",
base_key = self._generic_nom_key
key = self.insert_process( process_name=process_name,
base_key = base_key)
print "DEBUG: Identification_logic - build_nominal_histo_name : key =", key
if self._debug >= 90:
print "DEBUG: Identification_logic - build_nominal_histo_name : key =", key
key = self.insert_channel( channel_name = channel_name,
base_key = key)
print "DEBUG: Identification_logic - build_nominal_histo_name : key =", key
if self._debug >= 90:
print "DEBUG: Identification_logic - build_nominal_histo_name : key =", key
return key

def build_systematic_histo_name_down( self, process_name = "",
Expand Down
82 changes: 46 additions & 36 deletions base/valueConventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,51 @@
spath.append(basedir)

class valueConventions(object):
"""docstring for valueConventions"""
def __init__(self):

print "Initializing valueConventions"
self._allowed_types = ["lnN", "shape"]
self._debug = 99
"""docstring for valueConventions"""
def __init__(self):
self._debug = 0
self._allowed_types = ["lnN", "shape"]
if self._debug>=30:
print "Initializing valueConventions"



def isfloat(self, value):
try:
float(value)
return True
except ValueError:
return False

def is_good_systval(self, value):
"""
check if 'value' is a format allowed for systematic uncertainties
"""
is_good = False
if value is None: return is_good
if value == "-":
is_good = True
elif isinstance(value,float) or isinstance(value,int):
is_good = True
elif isinstance(value,str):
totest = value.split("/")
if len(totest) in [1,2]:
is_good = all(self.isfloat(v) for v in totest)
if not is_good:
print "Given value not suitable for an uncertainty in a datacard!"
return is_good

def is_allowed_type(self, typ):
if typ in self._allowed_types:
return True
if self._debug >= 99:
print "ERROR: Uncertainty type '%s' is not allowed"
return False
@property
def allowed_types(self):
return self._allowed_types
@allowed_types.setter
def allowed_types(self, list_of_allowed_types):
self._allowed_types=list_of_allowed_types

def isfloat(self, value):
try:
float(value)
return True
except ValueError:
return False

def is_good_systval(self, value):
"""
check if 'value' is a format allowed for systematic uncertainties
"""
is_good = False
if value is None: return is_good
if value == "-":
is_good = True
elif isinstance(value,float) or isinstance(value,int):
is_good = True
elif isinstance(value,str):
totest = value.split("/")
if len(totest) in [1,2]:
is_good = all(self.isfloat(v) for v in totest)
if not is_good:
print "Given value not suitable for an uncertainty in a datacard!"
return is_good

def is_allowed_type(self, typ):
if typ in self._allowed_types:
return True
if self._debug >= 99:
print "ERROR: Uncertainty type '%s' is not allowed"
return False
Loading

0 comments on commit b846975

Please sign in to comment.