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