9 |
|
import sys |
10 |
|
|
11 |
|
|
12 |
< |
#load config |
13 |
< |
config = BetterConfigParser() |
14 |
< |
config.read('./config7TeV_ZZ') |
15 |
< |
|
16 |
< |
#get locations: |
17 |
< |
Wdir=config.get('Directories','Wdir') |
18 |
< |
anaTag=config.get('Analysis','tag') |
19 |
< |
|
20 |
< |
|
21 |
< |
|
22 |
< |
def getScale(job,path,rescale,subsample=-1): |
23 |
< |
input = TFile.Open(path+'/'+job.getpath()) |
24 |
< |
CountWithPU = input.Get("CountWithPU") |
25 |
< |
CountWithPU2011B = input.Get("CountWithPU2011B") |
12 |
> |
def getScale(job,path,config,rescale,subsample=-1): |
13 |
> |
anaTag=config.get('Analysis','tag') |
14 |
> |
inputfile = TFile.Open(path+'/'+job.getpath()) |
15 |
> |
CountWithPU = inputfile.Get("CountWithPU") |
16 |
> |
CountWithPU2011B = inputfile.Get("CountWithPU2011B") |
17 |
|
#print lumi*xsecs[i]/hist.GetBinContent(1) |
18 |
|
|
19 |
|
if subsample>-1: |
20 |
< |
xsec=float(job.xsec[subsample]) |
20 |
> |
if type(job.xsec[subsample]) == str: xsec=float(eval(job.xsec[subsample])) |
21 |
> |
else: xsec=float(job.xsec[subsample]) |
22 |
|
sf=float(job.sf[subsample]) |
23 |
|
else: |
24 |
< |
xsec=float(job.xsec) |
24 |
> |
if type(job.xsec) == str: xsec=float(eval(job.xsec)) |
25 |
> |
else: xsec=float(job.xsec) |
26 |
|
sf=float(job.sf) |
27 |
|
|
28 |
|
|
31 |
|
theScale = float(job.lumi)*xsec*sf/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*rescale/float(job.split) |
32 |
|
elif anaTag == '8TeV': |
33 |
|
theScale = float(job.lumi)*xsec*sf/(CountWithPU.GetBinContent(1))*rescale/float(job.split) |
34 |
+ |
inputfile.Close() |
35 |
|
return theScale |
36 |
|
|
37 |
< |
def getHistoFromTree(job,path,options,rescale=1,subsample=-1): |
37 |
> |
def getHistoFromTree(job,path,config,options,rescale=1,subsample=-1,which_weightF='weightF'): |
38 |
|
|
39 |
|
#print job.getpath() |
40 |
|
#print options |
50 |
|
nBins=int(options[3]) |
51 |
|
xMin=float(options[4]) |
52 |
|
xMax=float(options[5]) |
53 |
+ |
#addOverFlow=eval(config.get('Plot_general','addOverFlow')) |
54 |
+ |
addOverFlow = False |
55 |
+ |
|
56 |
+ |
TrainFlag = eval(config.get('Analysis','TrainFlag')) |
57 |
+ |
if TrainFlag: traincut = " & EventForTraining == 0" |
58 |
+ |
if not TrainFlag: traincut="" |
59 |
|
|
60 |
|
if job.type != 'DATA': |
61 |
< |
cutcut=config.get('Cuts',options[7]) |
61 |
> |
|
62 |
> |
if type(options[7])==str: |
63 |
> |
cutcut=config.get('Cuts',options[7]) |
64 |
> |
elif type(options[7])==list: |
65 |
> |
cutcut=config.get('Cuts',options[7][0]) |
66 |
> |
cutcut=cutcut.replace(options[7][1],options[7][2]) |
67 |
> |
#print cutcut |
68 |
|
if subsample>-1: |
69 |
< |
treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample]) |
69 |
> |
treeCut='%s & %s%s'%(cutcut,job.subcuts[subsample],traincut) |
70 |
|
else: |
71 |
< |
treeCut='%s & EventForTraining == 0'%(cutcut) |
71 |
> |
treeCut='%s%s'%(cutcut,traincut) |
72 |
|
|
73 |
|
elif job.type == 'DATA': |
74 |
|
cutcut=config.get('Cuts',options[8]) |
82 |
|
#Tree.SetDirectory(0) |
83 |
|
|
84 |
|
#Tree=tmpTree.Clone() |
85 |
< |
weightF=config.get('Weights','weightF') |
85 |
> |
weightF=config.get('Weights',which_weightF) |
86 |
|
#hTree = ROOT.TH1F('%s'%name,'%s'%title,nBins,xMin,xMax) |
87 |
|
#hTree.SetDirectory(0) |
88 |
|
#hTree.Sumw2() |
112 |
|
#print job.name + ' Sumw2', hTree.GetEntries() |
113 |
|
|
114 |
|
if job.type != 'DATA': |
115 |
< |
ScaleFactor = getScale(job,path,rescale,subsample) |
115 |
> |
ScaleFactor = getScale(job,path,config,rescale,subsample) |
116 |
|
if ScaleFactor != 0: |
117 |
|
hTree.Scale(ScaleFactor) |
118 |
+ |
|
119 |
+ |
if addOverFlow: |
120 |
+ |
print 'Adding overflow' |
121 |
+ |
uFlow = hTree.GetBinContent(0)+hTree.GetBinContent(1) |
122 |
+ |
oFlow = hTree.GetBinContent(hTree.GetNbinsX()+1)+hTree.GetBinContent(hTree.GetNbinsX()) |
123 |
+ |
uFlowErr = ROOT.TMath.Sqrt(ROOT.TMath.Power(hTree.GetBinError(0),2)+ROOT.TMath.Power(hTree.GetBinError(1),2)) |
124 |
+ |
oFlowErr = ROOT.TMath.Sqrt(ROOT.TMath.Power(hTree.GetBinError(hTree.GetNbinsX()),2)+ROOT.TMath.Power(hTree.GetBinError(hTree.GetNbinsX()+1),2)) |
125 |
+ |
hTree.SetBinContent(1,uFlow) |
126 |
+ |
hTree.SetBinContent(hTree.GetNbinsX(),oFlow) |
127 |
+ |
hTree.SetBinError(1,uFlowErr) |
128 |
+ |
hTree.SetBinError(hTree.GetNbinsX(),oFlowErr) |
129 |
+ |
|
130 |
|
|
131 |
|
print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral()) |
132 |
|
|
133 |
|
hTree.SetDirectory(0) |
134 |
|
input.Close() |
135 |
|
|
118 |
– |
|
119 |
– |
|
136 |
|
return hTree, group |
137 |
|
|
138 |
|
|
148 |
|
num=[0]*len(setup) |
149 |
|
for i in range(0,len(setup)): |
150 |
|
for j in range(0,len(histos)): |
151 |
< |
if typs[j] in setup[i]: |
151 |
> |
if typs[j] == setup[i]: |
152 |
|
num[i]+=1 |
153 |
|
ordnung.append(histos[j]) |
154 |
|
ordnungtyp.append(typs[j]) |
159 |
|
histos=ordnung |
160 |
|
typs=ordnungtyp |
161 |
|
|
162 |
+ |
print typs |
163 |
+ |
|
164 |
|
for k in range(0,len(num)): |
165 |
|
for m in range(0,num[k]): |
166 |
|
if m > 0: |