9 |
|
import sys |
10 |
|
|
11 |
|
class HistoMaker: |
12 |
< |
def __init__(self, path, config, optionsList,rescale=1,which_weightF='weightF'): |
12 |
> |
def __init__(self, path, config, region, optionsList,rescale=1,which_weightF='weightF'): |
13 |
|
self.path = path |
14 |
|
self.config = config |
15 |
|
self.optionsList = optionsList |
16 |
|
self.rescale = rescale |
17 |
|
self.which_weightF=which_weightF |
18 |
< |
|
19 |
< |
|
18 |
> |
self.region = region |
19 |
> |
self.lumi=0. |
20 |
|
|
21 |
|
def getScale(self,job,subsample=-1): |
22 |
|
anaTag=self.config.get('Analysis','tag') |
24 |
|
CountWithPU = input.Get("CountWithPU") |
25 |
|
CountWithPU2011B = input.Get("CountWithPU2011B") |
26 |
|
#print lumi*xsecs[i]/hist.GetBinContent(1) |
27 |
– |
|
27 |
|
if subsample>-1: |
28 |
|
xsec=float(job.xsec[subsample]) |
29 |
|
sf=float(job.sf[subsample]) |
30 |
|
else: |
31 |
|
xsec=float(job.xsec) |
32 |
|
sf=float(job.sf) |
34 |
– |
|
35 |
– |
|
33 |
|
theScale = 1. |
34 |
|
if anaTag == '7TeV': |
35 |
< |
theScale = float(job.lumi)*xsec*sf/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*self.rescale/float(job.split) |
35 |
> |
theScale = float(self.lumi)*xsec*sf/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*self.rescale/float(job.split) |
36 |
|
elif anaTag == '8TeV': |
37 |
< |
theScale = float(job.lumi)*xsec*sf/(CountWithPU.GetBinContent(1))*self.rescale/float(job.split) |
37 |
> |
theScale = float(self.lumi)*xsec*sf/(CountWithPU.GetBinContent(1))*self.rescale/float(job.split) |
38 |
|
return theScale |
39 |
|
|
40 |
|
|
41 |
|
def getHistoFromTree(self,job,subsample=-1): |
42 |
< |
|
42 |
> |
if self.lumi == 0: raise Exception("You're trying to plot with no lumi") |
43 |
> |
|
44 |
|
hTreeList=[] |
45 |
|
groupList=[] |
46 |
|
|
47 |
< |
output=TFile.Open(self.path+'/tmp_%s.root'%job.name,'recreate') |
47 |
> |
|
48 |
> |
plot_path = self.config.get('Directories','plotpath') |
49 |
> |
|
50 |
> |
# define treeCut |
51 |
|
if job.type != 'DATA': |
52 |
< |
|
53 |
< |
if type(self.optionsList[0][7])==str: |
54 |
< |
cutcut=self.config.get('Cuts',self.optionsList[0][7]) |
55 |
< |
elif type(self.optionsList[0][7])==list: |
56 |
< |
cutcut=self.config.get('Cuts',self.optionsList[0][7][0]) |
57 |
< |
cutcut=cutcut.replace(self.optionsList[0][7][1],self.optionsList[0][7][2]) |
58 |
< |
print cutcut |
52 |
> |
if type(self.region)==str: |
53 |
> |
cutcut=self.config.get('Cuts',self.region) |
54 |
> |
elif type(self.region)==list: |
55 |
> |
#replace vars with other vars in the cutstring (used in DC writer) |
56 |
> |
cutcut=self.config.get('Cuts',self.region[0]) |
57 |
> |
cutcut=cutcut.replace(self.region[1],self.region[2]) |
58 |
> |
#print cutcut |
59 |
|
if subsample>-1: |
60 |
|
treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample]) |
61 |
|
else: |
62 |
|
treeCut='%s & EventForTraining == 0'%(cutcut) |
62 |
– |
|
63 |
|
elif job.type == 'DATA': |
64 |
< |
cutcut=self.config.get('Cuts',self.optionsList[0][8]) |
64 |
> |
cutcut=self.config.get('Cuts',self.region) |
65 |
|
treeCut='%s'%(cutcut) |
66 |
+ |
|
67 |
+ |
# get and skim the Trees |
68 |
+ |
output=TFile.Open(plot_path+'/tmp_plotCache_%s_%s.root'%(self.region,job.identifier),'recreate') |
69 |
|
input = TFile.Open(self.path+'/'+job.getpath(),'read') |
70 |
|
Tree = input.Get(job.tree) |
71 |
+ |
output.cd() |
72 |
+ |
CuttedTree=Tree.CopyTree(treeCut) |
73 |
+ |
|
74 |
+ |
# get all Histos at once |
75 |
|
weightF=self.config.get('Weights',self.which_weightF) |
69 |
– |
if job.type != 'DATA': |
70 |
– |
#if Tree.GetEntries(): |
71 |
– |
output.cd() |
72 |
– |
CuttedTree=Tree.CopyTree(treeCut) |
73 |
– |
elif job.type == 'DATA': |
74 |
– |
|
75 |
– |
output.cd() |
76 |
– |
CuttedTree=Tree.CopyTree(treeCut) |
77 |
– |
|
76 |
|
for options in self.optionsList: |
79 |
– |
|
77 |
|
if subsample>-1: |
78 |
|
name=job.subnames[subsample] |
79 |
|
group=job.group[subsample] |
80 |
|
else: |
81 |
|
name=job.name |
82 |
|
group=job.group |
86 |
– |
|
87 |
– |
|
83 |
|
treeVar=options[0] |
84 |
|
name=options[1] |
85 |
|
nBins=int(options[3]) |
94 |
|
else: |
95 |
|
full=False |
96 |
|
elif job.type == 'DATA': |
102 |
– |
|
97 |
|
if options[11] == 'blind': |
98 |
|
output.cd() |
99 |
|
CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeVar+'<0', "goff,e") |
107 |
|
output.cd() |
108 |
|
hTree = ROOT.TH1F('%s'%name,'%s'%name,nBins,xMin,xMax) |
109 |
|
hTree.Sumw2() |
116 |
– |
|
110 |
|
if job.type != 'DATA': |
111 |
|
ScaleFactor = self.getScale(job,subsample) |
112 |
|
if ScaleFactor != 0: |
113 |
|
hTree.Scale(ScaleFactor) |
121 |
– |
|
114 |
|
#print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral()) |
115 |
|
hTree.SetDirectory(0) |
116 |
|
input.Close() |