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
Binary file added .plotAllMCFlavor.py.swo
Binary file not shown.
1 change: 1 addition & 0 deletions RooUnfold
Submodule RooUnfold added at 633a24
1,017 changes: 1,017 additions & 0 deletions dataCollection.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import sys
import copy

path = "../files/"
path = "/depot/cms/users/schul105/files/"
#path="/depot/cms/users/minxi/"



Expand All @@ -22,6 +23,7 @@
# ~ "muons":1.0
}


crossSections = {
"dyInclusive50":5765.4,
"dy50to120":2112.90,
Expand Down
67 changes: 36 additions & 31 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,43 @@ def negWeightFractions(path,muon=True):


def binning(channel='muon'):
if channel == 'muon':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not break the functionality of other programs! To have a different binning for the AFB plot, please give the function another argument as a switch.


return [60., 65.43046396, 71.3524269, 77.81037328, 84.85281374, 92.53264952, 100.90756983, 110.04048518, 120., 129.95474058, 140.73528833, 152.41014904, 165.0535115, 178.74571891, 193.57377942, 209.63191906, 227.02218049, 245.85507143, 266.2502669, 288.3373697,
312.25673399, 338.16035716, 366.21284574, 396.59246138, 429.49225362, 465.12128666, 503.70596789, 545.49148654, 590.74337185, 639.74918031, 692.82032303, 750.29404456, 812.53556599, 879.94040575, 952.93689296,
1031.98888927, 1117.59873655, 1210.310449, 1310.71317017, 1419.4449167,
1537.19663264, 1664.71658012, 1802.81509423, 1952.36973236, 2114.3308507, 2289.72764334, 2479.6746824, 2685.37900061, 2908.14776151, 3149.39656595, 3410.65844758, 3693.59361467, 4000. ]
if channel == 'electron':
# ~ return ([j for j in range(50, 120, 5)] +
# ~ [j for j in range(120, 150, 5)] +
# ~ [j for j in range(150, 200, 10)] +
# ~ [j for j in range(200, 600, 20)]+
# ~ [j for j in range(600, 900, 30) ]+
# ~ [j for j in range(900, 1250, 50)] +
# ~ [j for j in range(1250, 1600, 60) ] +
# ~ [j for j in range(1600, 1900, 70) ] +
# ~ [j for j in range(1900, 4000, 80) ] +
# ~ [j for j in range(4000, 5000, 100) ] +
# ~ [5000])
return ([j for j in range(50, 120, 5)] +
[j for j in range(120, 150, 5)] +
[j for j in range(150, 200, 10)] +
[j for j in range(200, 600, 20)]+
[j for j in range(600, 900, 30) ]+
[j for j in range(900, 1250, 50)] +
[j for j in range(1250, 1610, 60) ] +
[j for j in range(1610, 1890, 70) ] +
[j for j in range(1890, 3970, 80) ] +
[j for j in range(3970, 6070, 100) ] +
[6070])
if channel == 'muon' or 'electron':
#return [60,120,400,600,900,1300,1800,6000]
return [50, 120,150,200,300,400,500,690,900,1250,1610, 2000, 3000,4000, 6070]# 152.41014904, 165.0535115, 178.74571891, 193.57377942, 209.63191906, 227.02218049, 245.85507143, 266.2502669, 288.3373697,
#312.25673399, 338.16035716, 366.21284574, 396.59246138, 429.49225362, 465.12128666, 503.70596789, 545.49148654, 590.74337185, 639.74918031, 692.82032303, 750.29404456, 812.53556599, 879.94040575, 952.93689296,
#1031.98888927, 1117.59873655, 1210.310449, 1310.71317017, 1419.4449167,
#1537.19663264, 1664.71658012, 1802.81509423, 1952.36973236, 2114.3308507, 2289.72764334, 2479.6746824, 2685.37900061, 2908.14776151, 3149.39656595, 3410.65844758, 3693.59361467, 4000. ]
#if channel == 'electron':
# return ([j for j in range(50, 120, 5)] +
# [j for j in range(120, 150, 5)] +
# [j for j in range(150, 200, 10)] +
# [j for j in range(200, 600, 20)]+
# [j for j in range(600, 900, 30) ]+
# [j for j in range(900, 1250, 50)] +
# [j for j in range(1250, 1600, 60) ] +
# [j for j in range(1600, 1900, 70) ] +
# [j for j in range(1900, 4000, 80) ] +
# [j for j in range(4000, 5000, 100) ] +
# [5000])
#return ([j for j in range(50, 120, 5)] +
# [j for j in range(120, 150, 5)] +
# [j for j in range(150, 200, 10)] +
# [j for j in range(200, 600, 20)]+
# [j for j in range(600, 900, 30) ]+
# [j for j in range(900, 1250, 50)] +
# [j for j in range(1250, 1610, 60) ] +
# [j for j in range(1610, 1890, 70) ] +
# [j for j in range(1890, 3970, 80) ] +
# [j for j in range(3970, 6070, 100) ] +
# [6070])
# Calculate logarithmic bins
# ~ width = (math.log(m_max) - math.log(m_min)) / nbins
# ~ logbins = [] # ~ # Exceed m_max to start with Z' binning, but reach 5 TeV
# ~ for i in range(0, nbins + 8):
# ~ logbins.append(int(math.exp(math.log(m_min) + width * i)))

# ~ return logbins

# return [j for j in range(50,6071,5)]
def loadHistoFromFile(fileName,histName,rebin,muon=True,logBins=False):
"""
returns histogram from file
Expand Down Expand Up @@ -128,7 +128,10 @@ def loadHistoFromFile(fileName,histName,rebin,muon=True,logBins=False):
bng = binning("electron")
else:
bng = binning("muon")

#for i in range(0,result.GetNbinsX()):
# print(result.GetBinLowEdge(i))
#print(histName)
#print(len(bng) - 1)
result = result.Rebin(len(bng) - 1, 'hist_' + uuid.uuid4().hex, array('d', bng))

for i in range(0,result.GetNbinsX()):
Expand Down Expand Up @@ -373,6 +376,8 @@ def __init__(self,processes,lumi,plot,zScaleFac):
self.theHistogram = temphist.Clone()
else:
self.theHistogram.Add(temphist.Clone())
def Add(self,addstack):
self.theHistogram.Add(addstack.theHistogram.Clone())

class TheStackRun2:
from ROOT import THStack
Expand Down
116 changes: 116 additions & 0 deletions histHandle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import ROOT
from copy import deepcopy


class histHandle(object):

def __init__(self,name,layers):
self.name=name
self.layers=layers
self.nodes={}
self.__tree={}
ROOT.TH1.AddDirectory(0)
ROOT.TH2.AddDirectory(0)
for layer in layers:
self.nodes[layer]=set([])

def __addLeaf(self,histName,nodes,h,tree="none"):
if tree=="none":
tree=self.__tree
if len(nodes)>1:
if nodes[0] not in tree.keys():
#print nodes[0]
tree[nodes[0]]={}
self.__addLeaf(histName,nodes[1:],h,tree[nodes[0]])
else:
if nodes[0] in tree.keys():
#print nodes[0]
if "hist" in tree[nodes[0]].keys():
tree[nodes[0]]["hist"].Add(h.Clone())
else:
tree[nodes[0]]["hist"]=h.Clone(histName)
else:
tree[nodes[0]]={"hist":h.Clone(histName)}

def __loopOver(self,node,func,selection=[]):
flag=True
for key in node.keys():
#print key
if key =="hist":
func(node[key])
elif key in selection:
self.__loopOver(node[key],func,selection)
flag=False
if flag:
for key in node.keys():
#print key
if key !="hist":
self.__loopOver(node[key],func,selection)

def loadHist(self,filename,histName,leafPath):
f=ROOT.TFile.Open(filename)
hist=f.Get(histName)
layerNum=len(leafPath)
for key in leafPath.keys():
self.nodes[key].add(leafPath[key])
subLayers=self.layers[0:layerNum]
nodes=[]
for layer in subLayers:
nodes.append(leafPath[layer])
s="_"
histName=s.join(nodes)
#print histName
self.__addLeaf(histName,nodes,histm)
f.Close()

def addHist(self,hist,leafPath):
layerNum=len(leafPath)
for key in leafPath.keys():
self.nodes[key].add(leafPath[key])
subLayers=self.layers[0:layerNum]
nodes=[]
for layer in subLayers:
nodes.append(leafPath[layer])
s="_"
histName=s.join(nodes)
#print histName
self.__addLeaf(histName,nodes,hist)

def loadHists(self,filename,histList):
for dual in histList:
self.loadHist(filename,dual[0],dual[1])

def getHist(self,leafPath):
tree=self.__tree.copy()
nodes=[]
num=len(leafPath)
layers=self.layers[0:num]
for layer in layers:
nodes.append(leafPath[layer])
#print nodes
for node in nodes:
#print tree
tree=tree[node].copy()
h=tree["hist"].Clone()
return h
def process(self,func,leafPath):
tree=self.__tree.copy()
num=len(leafPath)
layers=self.layers[0:num]
nodes=[]
for layer in layers:
nodes.append(leafPath[layer])
for node in nodes:
tree=tree[node].copy()
func(tree["hist"])
def processes(self,func,selection=""):
tree=self.__tree.copy()
if selection=="":
self.__loopOver(tree,func)
else:
self.__loopOver(tree,func,selection)
def saveHists(self,filename,selection=""):
f=ROOT.TFile(filename,"RECREATE")
def saveHist(hist):
hist.Write()
self.processes(saveHist,selection)
Loading