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