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 |
> |
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)*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)*xsec*sf/(CountWithPU.GetBinContent(1))*rescale/float(job.split) |
32 |
> |
return theScale |
33 |
|
|
34 |
+ |
def getHistoFromTree(job,path,config,options,rescale=1,subsample=-1): |
35 |
|
|
36 |
< |
def getHistoFromTree(job,options,rescale=1): |
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]) |
50 |
|
|
51 |
|
if job.type != 'DATA': |
52 |
|
cutcut=config.get('Cuts',options[7]) |
53 |
< |
treeCut='%s & EventForTraining == 0'%cutcut |
53 |
> |
if subsample>-1: |
54 |
> |
treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample]) |
55 |
> |
else: |
56 |
> |
treeCut='%s & EventForTraining == 0'%(cutcut) |
57 |
|
|
58 |
|
elif job.type == 'DATA': |
59 |
< |
treeCut=config.get('Cuts',options[8]) |
59 |
> |
cutcut=config.get('Cuts',options[8]) |
60 |
> |
treeCut='%s'%(cutcut) |
61 |
|
|
62 |
< |
input = TFile.Open(job.getpath(),'read') |
62 |
> |
|
63 |
> |
input = TFile.Open(path+'/'+job.getpath(),'read') |
64 |
|
|
65 |
|
Tree = input.Get(job.tree) |
66 |
|
#Tree=tmpTree.CloneTree() |
97 |
|
#print job.name + ' Sumw2', hTree.GetEntries() |
98 |
|
|
99 |
|
if job.type != 'DATA': |
100 |
< |
ScaleFactor = getScale(job,rescale) |
100 |
> |
ScaleFactor = getScale(job,path,config,rescale,subsample) |
101 |
|
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 |
< |
input.Close() |
108 |
< |
return hTree, job.group |
107 |
> |
input.Close() |
108 |
> |
|
109 |
> |
|
110 |
> |
|
111 |
> |
return hTree, group |
112 |
|
|
113 |
|
|
114 |
|
###################### |