1 |
peller |
1.1 |
from samplesclass import sample
|
2 |
|
|
from printcolor import printc
|
3 |
|
|
import pickle
|
4 |
|
|
import ROOT
|
5 |
|
|
from ROOT import TFile, TTree
|
6 |
|
|
import ROOT
|
7 |
|
|
from array import array
|
8 |
nmohr |
1.3 |
from BetterConfigParser import BetterConfigParser
|
9 |
peller |
1.1 |
import sys
|
10 |
|
|
|
11 |
|
|
|
12 |
nmohr |
1.10 |
def getScale(job,path,config,rescale,subsample=-1):
|
13 |
|
|
anaTag=config.get('Analysis','tag')
|
14 |
nmohr |
1.9 |
input = TFile.Open(path+'/'+job.getpath())
|
15 |
peller |
1.1 |
CountWithPU = input.Get("CountWithPU")
|
16 |
|
|
CountWithPU2011B = input.Get("CountWithPU2011B")
|
17 |
|
|
#print lumi*xsecs[i]/hist.GetBinContent(1)
|
18 |
peller |
1.7 |
|
19 |
|
|
if subsample>-1:
|
20 |
|
|
xsec=float(job.xsec[subsample])
|
21 |
|
|
sf=float(job.sf[subsample])
|
22 |
|
|
else:
|
23 |
|
|
xsec=float(job.xsec)
|
24 |
|
|
sf=float(job.sf)
|
25 |
|
|
|
26 |
|
|
|
27 |
nmohr |
1.6 |
theScale = 1.
|
28 |
|
|
if anaTag == '7TeV':
|
29 |
peller |
1.7 |
theScale = float(job.lumi)*xsec*sf/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*rescale/float(job.split)
|
30 |
nmohr |
1.6 |
elif anaTag == '8TeV':
|
31 |
peller |
1.7 |
theScale = float(job.lumi)*xsec*sf/(CountWithPU.GetBinContent(1))*rescale/float(job.split)
|
32 |
nmohr |
1.6 |
return theScale
|
33 |
peller |
1.1 |
|
34 |
nmohr |
1.10 |
def getHistoFromTree(job,path,config,options,rescale=1,subsample=-1):
|
35 |
peller |
1.8 |
|
36 |
|
|
#print job.getpath()
|
37 |
|
|
#print options
|
38 |
peller |
1.1 |
treeVar=options[0]
|
39 |
peller |
1.7 |
if subsample>-1:
|
40 |
|
|
name=job.subnames[subsample]
|
41 |
|
|
group=job.group[subsample]
|
42 |
|
|
else:
|
43 |
|
|
name=job.name
|
44 |
|
|
group=job.group
|
45 |
|
|
|
46 |
peller |
1.1 |
#title=job.plotname()
|
47 |
|
|
nBins=int(options[3])
|
48 |
|
|
xMin=float(options[4])
|
49 |
|
|
xMax=float(options[5])
|
50 |
|
|
|
51 |
|
|
if job.type != 'DATA':
|
52 |
|
|
cutcut=config.get('Cuts',options[7])
|
53 |
peller |
1.8 |
if subsample>-1:
|
54 |
peller |
1.7 |
treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample])
|
55 |
|
|
else:
|
56 |
|
|
treeCut='%s & EventForTraining == 0'%(cutcut)
|
57 |
peller |
1.1 |
|
58 |
|
|
elif job.type == 'DATA':
|
59 |
peller |
1.5 |
cutcut=config.get('Cuts',options[8])
|
60 |
peller |
1.8 |
treeCut='%s'%(cutcut)
|
61 |
peller |
1.5 |
|
62 |
peller |
1.1 |
|
63 |
nmohr |
1.9 |
input = TFile.Open(path+'/'+job.getpath(),'read')
|
64 |
peller |
1.1 |
|
65 |
|
|
Tree = input.Get(job.tree)
|
66 |
|
|
#Tree=tmpTree.CloneTree()
|
67 |
|
|
#Tree.SetDirectory(0)
|
68 |
|
|
|
69 |
|
|
#Tree=tmpTree.Clone()
|
70 |
|
|
weightF=config.get('Weights','weightF')
|
71 |
|
|
#hTree = ROOT.TH1F('%s'%name,'%s'%title,nBins,xMin,xMax)
|
72 |
|
|
#hTree.SetDirectory(0)
|
73 |
|
|
#hTree.Sumw2()
|
74 |
|
|
#print 'drawing...'
|
75 |
|
|
if job.type != 'DATA':
|
76 |
|
|
#print treeCut
|
77 |
|
|
#print job.name
|
78 |
|
|
if Tree.GetEntries():
|
79 |
|
|
Tree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),'(%s)*(%s)' %(treeCut,weightF), "goff,e")
|
80 |
|
|
full=True
|
81 |
|
|
else:
|
82 |
|
|
full=False
|
83 |
|
|
elif job.type == 'DATA':
|
84 |
|
|
|
85 |
|
|
if len(options)>10:
|
86 |
|
|
if options[11] == 'blind':
|
87 |
|
|
treeCut = treeCut + '&'+treeVar+'<0'
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
Tree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeCut, "goff,e")
|
91 |
|
|
full = True
|
92 |
|
|
if full:
|
93 |
|
|
hTree = ROOT.gDirectory.Get(name)
|
94 |
|
|
else:
|
95 |
|
|
hTree = ROOT.TH1F('%s'%name,'%s'%name,nBins,xMin,xMax)
|
96 |
|
|
hTree.Sumw2()
|
97 |
|
|
#print job.name + ' Sumw2', hTree.GetEntries()
|
98 |
|
|
|
99 |
|
|
if job.type != 'DATA':
|
100 |
nmohr |
1.10 |
ScaleFactor = getScale(job,path,config,rescale,subsample)
|
101 |
peller |
1.1 |
if ScaleFactor != 0:
|
102 |
|
|
hTree.Scale(ScaleFactor)
|
103 |
|
|
|
104 |
|
|
print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral())
|
105 |
|
|
|
106 |
|
|
hTree.SetDirectory(0)
|
107 |
peller |
1.7 |
input.Close()
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
return hTree, group
|
112 |
peller |
1.1 |
|
113 |
|
|
|
114 |
|
|
######################
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
def orderandadd(histos,typs,setup):
|
119 |
|
|
#ORDER AND ADD TOGETHER
|
120 |
|
|
|
121 |
|
|
ordnung=[]
|
122 |
|
|
ordnungtyp=[]
|
123 |
|
|
num=[0]*len(setup)
|
124 |
|
|
for i in range(0,len(setup)):
|
125 |
|
|
for j in range(0,len(histos)):
|
126 |
peller |
1.2 |
if typs[j] in setup[i]:
|
127 |
peller |
1.1 |
num[i]+=1
|
128 |
|
|
ordnung.append(histos[j])
|
129 |
|
|
ordnungtyp.append(typs[j])
|
130 |
|
|
|
131 |
|
|
del histos
|
132 |
|
|
del typs
|
133 |
|
|
|
134 |
|
|
histos=ordnung
|
135 |
|
|
typs=ordnungtyp
|
136 |
|
|
|
137 |
|
|
for k in range(0,len(num)):
|
138 |
|
|
for m in range(0,num[k]):
|
139 |
|
|
if m > 0:
|
140 |
|
|
|
141 |
|
|
#add
|
142 |
|
|
histos[k].Add(histos[k+1],1)
|
143 |
peller |
1.2 |
printc('magenta','','\t--> added %s to %s'%(typs[k],typs[k+1]))
|
144 |
peller |
1.1 |
del histos[k+1]
|
145 |
|
|
del typs[k+1]
|
146 |
|
|
|
147 |
|
|
del histos[len(setup):]
|
148 |
|
|
del typs[len(setup):]
|
149 |
|
|
|
150 |
|
|
return histos, typs
|
151 |
|
|
|
152 |
|
|
|