Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
534 changes: 335 additions & 199 deletions Dumbledraw/dumbledraw.py

Large diffs are not rendered by default.

856 changes: 521 additions & 335 deletions Dumbledraw/labels.yaml

Large diffs are not rendered by default.

45 changes: 28 additions & 17 deletions Dumbledraw/rootfile_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
import logging
import ROOT
import copy

logger = logging.getLogger(__name__)


class Rootfile_parser(object):
def __init__(self, inputrootfilename, mode="CombineHarvester"):
def __init__(self, inputrootfilename, mode="CombineHarvester", prefit=False):
self._rootfilename = inputrootfilename
self._rootfile = ROOT.TFile(self._rootfilename, "READ")
self._type = "control"
content = [entry.GetName() for entry in self._rootfile.GetListOfKeys()]
for entry in content:
if entry.endswith("prefit"):
self._type = "prefit"
for entry in content:
if entry.endswith("postfit"):
self._type = "postfit"
logger.debug("Identified rootfile %s as %s shapes" %
(inputrootfilename, self._type))
if not prefit:
for entry in content:
if entry.endswith("postfit"):
self._type = "postfit"
logger.debug(
"Identified rootfile %s as %s shapes" % (inputrootfilename, self._type)
)
if mode == "standard":
self._hist_hash = "{channel}_{category}{plottype}/{process}{unc}"
elif mode == "CombineHarvester":
Expand All @@ -36,41 +39,49 @@ def rootfile(self):

def get(self, era, channel, category, process, syst=None):
if syst != None and self._type != "control":
logger.fatal(
"Uncertainty shapes are only available in control plots!")
logger.fatal("Uncertainty shapes are only available in control plots!")
raise Exception
hist_hash = self._hist_hash.format(
era=era,
channel=channel,
category=category,
process=process,
plottype="{plottype}",
unc="{unc}")
unc="{unc}",
)
if self._type == "control":
syst = "" if syst == None else "_" + syst
hist_hash = hist_hash.format(plottype="", unc=syst)
else:
hist_hash = hist_hash.format(plottype="_" + self._type, unc="")
logger.debug(
"Try to access %s in %s" % (hist_hash, self._rootfilename))
logger.debug("Try to access %s in %s" % (hist_hash, self._rootfilename))
# perform check if file is available and otherwise return some dummy TH1F
available_processes = [entry.GetName() for entry in self._rootfile.Get(hist_hash.split('/')[0]).GetListOfKeys()]
if hist_hash.split('/')[1] in available_processes:
available_processes = [
entry.GetName()
for entry in self._rootfile.Get(hist_hash.split("/")[0]).GetListOfKeys()
]
if hist_hash.split("/")[1] in available_processes:
return self._rootfile.Get(hist_hash)
elif len(available_processes) != 0:
logger.warning("%s in %s does not exist !" % (hist_hash, self._rootfilename))
logger.warning(
"%s in %s does not exist !" % (hist_hash, self._rootfilename)
)
logger.debug(" Available Histograms are: %s" % available_processes)
logger.debug(" Returning a dummy histogram ")
dummy = self._rootfile.Get('{}/{}'.format(hist_hash.split('/')[0],available_processes[0]))
dummy = self._rootfile.Get(
"{}/{}".format(hist_hash.split("/")[0], available_processes[0])
)
dummy.Reset()
dummy.SetTitle(process)
dummy.SetName(hist_hash)
return dummy
else:
logger.fatal(" None of the requested Histograms are available in %s. Aborting." % hist_hash.split('/')[0])
logger.fatal(
" None of the requested Histograms are available in %s. Aborting."
% hist_hash.split("/")[0]
)
raise Exception


def get_bins(self, era, channel, category, process, syst=None):
hist = self.get(era, channel, category, process, syst)
nbins = hist.GetNbinsX()
Expand Down
9 changes: 5 additions & 4 deletions Dumbledraw/rootfile_parser_inputshapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import ROOT
import copy

logger = logging.getLogger(__name__)


Expand All @@ -29,10 +30,10 @@ def get(self, channel, category, process):
analysis=self._analysis,
epoch=self._epoch,
variable=self._variable,
mass=self._mass)
logger.debug("Try to access %s in %s" % (hist_hash,
self._rootfilename))
print "rootfile: " , self._rootfile.Get(hist_hash), " hash: ", hist_hash
mass=self._mass,
)
logger.debug("Try to access %s in %s" % (hist_hash, self._rootfilename))
print("rootfile: ", self._rootfile.Get(hist_hash), " hash: ", hist_hash)

return self._rootfile.Get(hist_hash)

Expand Down
213 changes: 213 additions & 0 deletions Dumbledraw/rootfile_parser_ntuple_processor_inputshapes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

import logging
import ROOT
import copy

logger = logging.getLogger(__name__)


class Rootfile_parser(object):

_dataset_map = {
"data": "data",
"ZTT": "DY",
"ZL": "DY",
"ZJ": "DY",
"TTT": "TT",
"TTL": "TT",
"TTJ": "TT",
"VVT": "VV",
"VVL": "VV",
"VVJ": "VV",
"W": "W",
"EMB": "EMB",
"QCDEMB": "QCD",
"QCD": "QCDMC",
"jetFakesEMB": "jetFakes",
"jetFakes": "jetFakesMC",
"ggH125": "ggH",
"qqH125": "qqH",
"wFakes": "wFakes",
"embminus2p5": "embminus2p5",
"embminus2p4": "embminus2p4",
"embminus2p3": "embminus2p3",
"embminus2p2": "embminus2p2",
"embminus2p1": "embminus2p1",
"embminus2p0": "embminus2p0",
"embminus1p9": "embminus1p9",
"embminus1p8": "embminus1p8",
"embminus1p7": "embminus1p7",
"embminus1p6": "embminus1p6",
"embminus1p5": "embminus1p5",
"embminus1p4": "embminus1p4",
"embminus1p3": "embminus1p3",
"embminus1p2": "embminus1p2",
"embminus1p1": "embminus1p1",
"embminus1p0": "embminus1p0",
"embminus0p9": "embminus0p9",
"embminus0p8": "embminus0p8",
"embminus0p7": "embminus0p7",
"embminus0p6": "embminus0p6",
"embminus0p5": "embminus0p5",
"embminus0p4": "embminus0p4",
"embminus0p3": "embminus0p3",
"embminus0p2": "embminus0p2",
"embminus0p1": "embminus0p1",
"emb0p0": "emb0p0",
"emb0p1": "emb0p1",
"emb0p2": "emb0p2",
"emb0p3": "emb0p3",
"emb0p4": "emb0p4",
"emb0p5": "emb0p5",
"emb0p6": "emb0p6",
"emb0p7": "emb0p7",
"emb0p8": "emb0p8",
"emb0p9": "emb0p9",
"emb1p0": "emb1p0",
"emb1p1": "emb1p1",
"emb1p2": "emb1p2",
"emb1p3": "emb1p3",
"emb1p4": "emb1p4",
"emb1p5": "emb1p5",
"emb1p6": "emb1p6",
"emb1p7": "emb1p7",
"emb1p8": "emb1p8",
"emb1p9": "emb1p9",
"emb2p0": "emb2p0",
"emb2p1": "emb2p1",
"emb2p2": "emb2p2",
"emb2p3": "emb2p3",
"emb2p4": "emb2p4",
"emb2p5": "emb2p5",
}

_process_map = {
"data": "data",
"ZTT": "DY-ZTT",
"ZL": "DY-ZL",
"ZJ": "DY-ZJ",
"TTT": "TT-TTT",
"TTL": "TT-TTL",
"TTJ": "TT-TTJ",
"VVT": "VV-VVT",
"VVL": "VV-VVL",
"VVJ": "VV-VVJ",
"W": "W",
"EMB": "Embedded",
"QCDEMB": "QCD",
"QCD": "QCDMC",
"jetFakesEMB": "jetFakes",
"jetFakes": "jetFakesMC",
"ggH125": "ggH125",
"qqH125": "qqH125",
"wFakes": "wFakes",
"embminus2p5": "Embedded",
"embminus2p4": "Embedded",
"embminus2p3": "Embedded",
"embminus2p2": "Embedded",
"embminus2p1": "Embedded",
"embminus2p0": "Embedded",
"embminus1p9": "Embedded",
"embminus1p8": "Embedded",
"embminus1p7": "Embedded",
"embminus1p6": "Embedded",
"embminus1p5": "Embedded",
"embminus1p4": "Embedded",
"embminus1p3": "Embedded",
"embminus1p2": "Embedded",
"embminus1p1": "Embedded",
"embminus1p0": "Embedded",
"embminus0p9": "Embedded",
"embminus0p8": "Embedded",
"embminus0p7": "Embedded",
"embminus0p6": "Embedded",
"embminus0p5": "Embedded",
"embminus0p4": "Embedded",
"embminus0p3": "Embedded",
"embminus0p2": "Embedded",
"embminus0p1": "Embedded",
"emb0p0": "Embedded",
"emb0p1": "Embedded",
"emb0p2": "Embedded",
"emb0p3": "Embedded",
"emb0p4": "Embedded",
"emb0p5": "Embedded",
"emb0p6": "Embedded",
"emb0p7": "Embedded",
"emb0p8": "Embedded",
"emb0p9": "Embedded",
"emb1p0": "Embedded",
"emb1p1": "Embedded",
"emb1p2": "Embedded",
"emb1p3": "Embedded",
"emb1p4": "Embedded",
"emb1p5": "Embedded",
"emb1p6": "Embedded",
"emb1p7": "Embedded",
"emb1p8": "Embedded",
"emb1p9": "Embedded",
"emb2p0": "Embedded",
"emb2p1": "Embedded",
"emb2p2": "Embedded",
"emb2p3": "Embedded",
"emb2p4": "Embedded",
"emb2p5": "Embedded",
}

def __init__(self, inputrootfilename, variable):
self._rootfilename = inputrootfilename
self._rootfile = ROOT.TFile(self._rootfilename, "READ")
self._variable = variable

@property
def rootfile(self):
return self._rootfile

def get(self, channel, process, category=None, shape_type="Nominal"):
dataset = self._dataset_map[process]
if category is None:
category = "" if "data" in process else "-" + self._process_map[process]
else:
category = (
"-" + category
if "data" in process
else "-" + "-".join([self._process_map[process], category])
)
hist_hash = "{dataset}#{channel}{category}#{shape_type}#{variable}".format(
dataset=dataset,
channel=channel,
category=category,
shape_type=shape_type,
variable=self._variable,
)
logger.debug("Try to access %s in %s" % (hist_hash, self._rootfilename))
print("rootfile: ", self._rootfile.Get(hist_hash), " hash: ", hist_hash)

return self._rootfile.Get(hist_hash)

def list_contents(self):
return [key.GetTitle() for key in self._rootfile.GetListOfKeys()]

def get_bins(self, channel, category):
hist = self.get(channel, category)
nbins = hist.GetNbinsX()
bins = []
for i in range(nbins):
bins.append(hist.GetBinLowEdge(i + 1))
bins.append(hist.GetBinLowEdge(i + 1) + hist.GetBinWidth(i + 1))
return bins

def get_values(self, channel, category):
hist = self.get(channel, category)
nbins = hist.GetNbinsX()
values = []
for i in range(nbins):
values.append(hist.GetBinContent(i + 1))
return values

def __del__(self):
logger.debug("Closing rootfile %s" % (self._rootfilename))
self._rootfile.Close()
21 changes: 10 additions & 11 deletions Dumbledraw/sf_rootfile_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import ROOT
import copy

logger = logging.getLogger(__name__)


Expand All @@ -13,24 +14,22 @@ def __init__(self, inputrootfilename):
self._rootfile = ROOT.TFile(self._rootfilename, "READ")
content = [entry.GetName() for entry in self._rootfile.GetListOfKeys()]
self.Nbins = len(content)
logger.debug("Identified {} histograms in rootfile {} ".format(len(content), inputrootfilename))
logger.debug(
"Identified {} histograms in rootfile {} ".format(
len(content), inputrootfilename
)
)
self._hist_hash = "{variable}_projx_{etabin}"

@property
def rootfile(self):
return self._rootfile



def get(self, variable, etabin):
hist_hash = self._hist_hash.format(
variable=variable,
etabin=etabin)
logger.debug(
"Try to access %s in %s" % (hist_hash, self._rootfilename))
hist_hash = self._hist_hash.format(variable=variable, etabin=etabin)
logger.debug("Try to access %s in %s" % (hist_hash, self._rootfilename))
return self._rootfile.Get(hist_hash)


def get_bins(self, variable, etabin):
hist = self.get(self, variable, etabin)
nbins = hist.GetNbinsX()
Expand All @@ -50,8 +49,8 @@ def get_values(self, variable, etabin):

def get_values_up(self, variable, etabin):
hist = self.get(self, variable, etabin)
nbins=hist.GetNbinsX()
values=[]
nbins = hist.GetNbinsX()
values = []
for i in range(nbins):
values.append(hist.GetBinErrDown(i + 1))
return values
Expand Down
Loading