-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from kit-cn-cms/dev
Dev
- Loading branch information
Showing
14 changed files
with
1,854 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
# datacardMaker | ||
repo for object-oriented datacard maker | ||
|
||
Writes Datacards | ||
|
||
Current structure: | ||
- src/datacardMaker.py: Wrapper to automatically create data cards from category/process/systematic objects | ||
- src/categoryObject.py: Object for categories that contains processes | ||
- src/processObject.py: Object for process (e.g. ttH_hbb), contains uncertainties corresponding to the process | ||
- src/systematicObject.py: object for nuisance parameters (e.g. bgnorm_ttbarPlusBBbar) | ||
- base/fileHandler.py: fileHandler class manages all access to files required for the analysis | ||
- base/identificationLogic: identificationLogic class is meant to handle all logic concerning | ||
the key handling for the different categories required in datacards | ||
- base/valueConventions.py: checks if value is allowed for systematic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# datacardMaker | ||
repo for object-oriented datacard maker | ||
|
||
- base/fileHandler.py: fileHandler class manages all access to files required for the analysis | ||
- base/identificationLogic: identificationLogic class is meant to handle all logic concerning | ||
the key handling for the different categories required in datacards | ||
- base/valueConventions.py: checks if value is allowed for systematic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
from ROOT import TFile, TH1 | ||
from os import path as opath | ||
|
||
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 | ||
|
||
def init_variables(self): | ||
self._filepath = "/path/to/file" | ||
self._file = None | ||
|
||
def __init__(self): | ||
if self._debug >= 10: | ||
print "Initializing fileHandler" | ||
self.init_variables() | ||
if opath.exists(self._filepath): | ||
self._file = self.load_file(filepath) | ||
|
||
def __del__(self): | ||
self.close_file() | ||
|
||
def is_file_open(self): | ||
if self._debug >= 99: | ||
print "DEBUG: checking for open file" | ||
if not self._file is None and isinstance(self._file, TFile): | ||
return self._file.IsOpen() | ||
if self._debug >= 99: | ||
print "DEBUG: file is not a TFile!" | ||
return False | ||
|
||
def close_file(self): | ||
if self._debug >= 99: | ||
print "DEBUG: Closing file if it's open" | ||
if self.is_file_open(): | ||
self._file.Close() | ||
|
||
def open_file(self, path): | ||
if self._debug >= 99: | ||
print "opening file '%s'" % path | ||
if opath.exists(path): | ||
f = TFile.Open(path) | ||
if self.is_intact_file(f): | ||
self._file = f | ||
self._filepath = path | ||
else: | ||
if self._debug >= 3: | ||
print "Could not open file '%s'" % path | ||
else: | ||
if self._debug >= 3: | ||
print "File '%s' does not exist!" % path | ||
return None | ||
|
||
@property | ||
def filepath(self): | ||
return self._filepath | ||
@filepath.setter | ||
def filepath(self, path): | ||
if self._debug >= 20: | ||
print "trying to set file path to", path | ||
|
||
self.close_file() | ||
self.open_file(path) | ||
|
||
def is_intact_file(self, f): | ||
|
||
if f and isinstance(f, TFile): | ||
if f.IsOpen(): | ||
if not f.IsZombie(): | ||
if not f.TestBit(TFile.kRecovered): | ||
return True | ||
else: | ||
if self._debug >= 99: | ||
print "ERROR: file '%s' is recovered!" % f.GetName() | ||
else: | ||
if self._debug >= 99: | ||
print "ERROR: file '%s' is zombie!" % f.GetName() | ||
else: | ||
if self._debug >= 99: | ||
print "ERROR: file '%s' is not open" % f.GetName() | ||
return False | ||
|
||
def load_histogram(self, histname): | ||
if self._debug >= 99: | ||
print "DEBUG: entering 'fileHandler.load_histogram'" | ||
if self._file: | ||
if self._debug >= 10: | ||
print "DEBUG: loading histogram '%s' from '%s'" % (histname, file) | ||
h = self._file.Get(histname) | ||
if isinstance(h, TH1): | ||
return h | ||
else: | ||
print ("WARNING: histogram '%s' does not exist in '%s'" | ||
% (histname, file)) | ||
else: | ||
print "ERROR: In fileHandler - file is not set!" | ||
return None | ||
|
||
def histogram_exists(self, histname): | ||
h = self.load_histogram(histname = histname) | ||
if self._debug >= 99: | ||
print "found histogram at", h | ||
if h: | ||
return True | ||
return False | ||
|
||
def get_integral(self, histname): | ||
h = self.load_histogram(histname = histname) | ||
if h: | ||
return h.Integral() | ||
else: | ||
return -1 |
Oops, something went wrong.