9 |
|
#suppres the EvalInstace conversion warning bug |
10 |
|
import warnings |
11 |
|
warnings.filterwarnings( action='ignore', category=RuntimeWarning, message='creating converter.*' ) |
12 |
+ |
from optparse import OptionParser |
13 |
|
from BetterConfigParser import BetterConfigParser |
14 |
|
from samplesclass import sample |
15 |
|
from mvainfos import mvainfo |
20 |
|
#CONFIGURE |
21 |
|
|
22 |
|
#load config |
23 |
+ |
#os.mkdir(path+'/sys') |
24 |
+ |
argv = sys.argv |
25 |
+ |
parser = OptionParser() |
26 |
+ |
parser.add_option("-U", "--update", dest="update", default=0, |
27 |
+ |
help="update infofile") |
28 |
+ |
parser.add_option("-D", "--discr", dest="discr", default="", |
29 |
+ |
help="discriminators to be added") |
30 |
+ |
parser.add_option("-P", "--path", dest="path", default="", |
31 |
+ |
help="path to samples") |
32 |
+ |
parser.add_option("-S", "--samples", dest="names", default="", |
33 |
+ |
help="samples you want to run on") |
34 |
+ |
parser.add_option("-C", "--config", dest="config", default="", |
35 |
+ |
help="configuration file") |
36 |
+ |
(opts, args) = parser.parse_args(argv) |
37 |
+ |
if opts.config =="": |
38 |
+ |
opts.config = "config" |
39 |
|
config = BetterConfigParser() |
40 |
< |
config.read('./config') |
40 |
> |
config.read(opts.config) |
41 |
> |
anaTag = config.get("Analysis","tag") |
42 |
|
|
43 |
|
#get locations: |
44 |
|
Wdir=config.get('Directories','Wdir') |
50 |
|
systematics=systematics.split(' ') |
51 |
|
|
52 |
|
#TreeVar Array |
53 |
< |
MVA_Vars={} |
54 |
< |
for systematic in systematics: |
55 |
< |
MVA_Vars[systematic]=config.get('treeVars',systematic) |
56 |
< |
MVA_Vars[systematic]=MVA_Vars[systematic].split(' ') |
53 |
> |
#MVA_Vars={} |
54 |
> |
#for systematic in systematics: |
55 |
> |
# MVA_Vars[systematic]=config.get('treeVars',systematic) |
56 |
> |
# MVA_Vars[systematic]=MVA_Vars[systematic].split(' ') |
57 |
|
|
58 |
|
###################### |
59 |
|
#Evaluate multi: Must Have same treeVars!!! |
60 |
|
|
61 |
< |
Apath=sys.argv[1] |
62 |
< |
arglist=sys.argv[2] #RTight_blavla,bsbsb |
61 |
> |
Apath=opts.path |
62 |
> |
infofile = open(Apath+'/samples.info','r') |
63 |
> |
info = pickle.load(infofile) |
64 |
> |
infofile.close() |
65 |
> |
arglist=opts.discr #RTight_blavla,bsbsb |
66 |
|
|
67 |
< |
namelistIN=sys.argv[3] |
67 |
> |
namelistIN=opts.names |
68 |
|
namelist=namelistIN.split(',') |
69 |
|
|
70 |
< |
doinfo=bool(int(sys.argv[4])) |
70 |
> |
doinfo=bool(int(opts.update)) |
71 |
|
|
72 |
|
MVAlist=arglist.split(',') |
73 |
|
|
132 |
|
|
133 |
|
#eval |
134 |
|
for job in Ainfo: |
135 |
< |
|
136 |
< |
if job.name in namelist: |
137 |
< |
#get trees: |
138 |
< |
input = TFile.Open(job.getpath(),'read') |
139 |
< |
outfile = TFile.Open(job.path+'/'+MVAdir+job.prefix+job.identifier+'.root','recreate') |
119 |
< |
input.cd() |
120 |
< |
obj = ROOT.TObject |
121 |
< |
for key in ROOT.gDirectory.GetListOfKeys(): |
135 |
> |
if eval(job.active): |
136 |
> |
if job.name in namelist: |
137 |
> |
#get trees: |
138 |
> |
input = TFile.Open(job.getpath(),'read') |
139 |
> |
outfile = TFile.Open(job.path+'/'+MVAdir+job.prefix+job.identifier+'.root','recreate') |
140 |
|
input.cd() |
141 |
< |
obj = key.ReadObj() |
142 |
< |
#print obj.GetName() |
143 |
< |
if obj.GetName() == job.tree: |
144 |
< |
continue |
141 |
> |
obj = ROOT.TObject |
142 |
> |
for key in ROOT.gDirectory.GetListOfKeys(): |
143 |
> |
input.cd() |
144 |
> |
obj = key.ReadObj() |
145 |
> |
#print obj.GetName() |
146 |
> |
if obj.GetName() == job.tree: |
147 |
> |
continue |
148 |
> |
outfile.cd() |
149 |
> |
#print key.GetName() |
150 |
> |
obj.Write(key.GetName()) |
151 |
> |
tree = input.Get(job.tree) |
152 |
> |
nEntries = tree.GetEntries() |
153 |
|
outfile.cd() |
154 |
< |
#print key.GetName() |
155 |
< |
obj.Write(key.GetName()) |
156 |
< |
tree = input.Get(job.tree) |
157 |
< |
nEntries = tree.GetEntries() |
158 |
< |
outfile.cd() |
159 |
< |
newtree = tree.CloneTree(0) |
160 |
< |
|
161 |
< |
#MCs: |
162 |
< |
if job.type != 'DATA': |
163 |
< |
MVA_formulas={} |
164 |
< |
MVA_formulas4={} |
165 |
< |
for systematic in systematics: |
166 |
< |
#print '\t\t - ' + systematic |
167 |
< |
MVA_formulas[systematic]=[] |
168 |
< |
MVA_formulas4[systematic]=[] |
154 |
> |
newtree = tree.CloneTree(0) |
155 |
> |
|
156 |
> |
#MCs: |
157 |
> |
if job.type != 'DATA': |
158 |
> |
MVA_formulas={} |
159 |
> |
MVA_formulas4={} |
160 |
> |
for systematic in systematics: |
161 |
> |
#print '\t\t - ' + systematic |
162 |
> |
MVA_formulas[systematic]=[] |
163 |
> |
MVA_formulas4[systematic]=[] |
164 |
> |
#create TTreeFormulas |
165 |
> |
for j in range(len( MVA_Vars['Nominal'])): |
166 |
> |
MVA_formulas[systematic].append(ROOT.TTreeFormula("MVA_formula%s_%s"%(j,systematic),MVA_Vars[systematic][j],tree)) |
167 |
> |
MVA_formulas4[systematic].append(ROOT.TTreeFormula("MVA_formula4%s_%s"%(j,systematic),MVA_Vars['Nominal'][j]+'+('+MVA_Vars[systematic][j]+'-'+MVA_Vars['Nominal'][j]+')*4',tree))#HERE change |
168 |
> |
outfile.cd() |
169 |
> |
#Setup Branches |
170 |
> |
MVAbranches=[] |
171 |
> |
MVAbranches4=[] |
172 |
> |
for i in range(0,len(readers)): |
173 |
> |
MVAbranches.append(array('f',[0]*9)) |
174 |
> |
MVAbranches4.append(array('f',[0]*9)) |
175 |
> |
newtree.Branch(MVAinfos[i].MVAname,MVAbranches[i],'nominal:JER_up:JER_down:JES_up:JES_down:beff_up:beff_down:bmis_up:bmis_down/F') |
176 |
> |
newtree.Branch(MVAinfos[i].MVAname+'_4',MVAbranches4[i],'nominal:JER_up:JER_down:JES_up:JES_down:beff_up:beff_down:bmis_up:bmis_down/F') |
177 |
> |
print '\n--> ' + job.name +':' |
178 |
> |
#progbar setup |
179 |
> |
if nEntries >= longe: |
180 |
> |
step=int(nEntries/longe) |
181 |
> |
long=longe |
182 |
> |
else: |
183 |
> |
long=nEntries |
184 |
> |
step = 1 |
185 |
> |
bar=progbar(long) |
186 |
> |
#Fill event by event: |
187 |
> |
for entry in range(0,nEntries): |
188 |
> |
if entry % step == 0: |
189 |
> |
bar.move() |
190 |
> |
#load entry |
191 |
> |
tree.GetEntry(entry) |
192 |
> |
for systematic in systematics: |
193 |
> |
for j in range(len( MVA_Vars['Nominal'])): |
194 |
> |
MVA_var_buffer[j][0] = MVA_formulas[systematic][j].EvalInstance() |
195 |
> |
|
196 |
> |
for j in range(0,len(readers)): |
197 |
> |
MVAbranches[j][systematics.index(systematic)] = readers[j].EvaluateMVA(MVAinfos[j].MVAname) |
198 |
> |
|
199 |
> |
for j in range(len( MVA_Vars['Nominal'])): |
200 |
> |
MVA_var_buffer[j][0] = MVA_formulas4[systematic][j].EvalInstance() |
201 |
> |
|
202 |
> |
for j in range(0,len(readers)): |
203 |
> |
MVAbranches4[j][systematics.index(systematic)] = readers[j].EvaluateMVA(MVAinfos[j].MVAname) |
204 |
> |
#Fill: |
205 |
> |
newtree.Fill() |
206 |
> |
newtree.AutoSave() |
207 |
> |
outfile.Close() |
208 |
> |
|
209 |
> |
#DATA: |
210 |
> |
if job.type == 'DATA': |
211 |
> |
#MVA Formulas |
212 |
> |
MVA_formulas_Nominal = [] |
213 |
|
#create TTreeFormulas |
214 |
|
for j in range(len( MVA_Vars['Nominal'])): |
215 |
< |
MVA_formulas[systematic].append(ROOT.TTreeFormula("MVA_formula%s_%s"%(j,systematic),MVA_Vars[systematic][j],tree)) |
216 |
< |
MVA_formulas4[systematic].append(ROOT.TTreeFormula("MVA_formula4%s_%s"%(j,systematic),MVA_Vars['Nominal'][j]+'+('+MVA_Vars[systematic][j]+'-'+MVA_Vars['Nominal'][j]+')*4',tree))#HERE change |
217 |
< |
outfile.cd() |
218 |
< |
#Setup Branches |
219 |
< |
MVAbranches=[] |
220 |
< |
MVAbranches4=[] |
221 |
< |
for i in range(0,len(readers)): |
222 |
< |
MVAbranches.append(array('f',[0]*9)) |
223 |
< |
MVAbranches4.append(array('f',[0]*9)) |
224 |
< |
newtree.Branch(MVAinfos[i].MVAname,MVAbranches[i],'nominal:JER_up:JER_down:JES_up:JES_down:beff_up:beff_down:bmis_up:bmis_down/F') |
225 |
< |
newtree.Branch(MVAinfos[i].MVAname+'_4',MVAbranches4[i],'nominal:JER_up:JER_down:JES_up:JES_down:beff_up:beff_down:bmis_up:bmis_down/F') |
226 |
< |
print '\n--> ' + job.name +':' |
227 |
< |
#progbar setup |
228 |
< |
if nEntries >= longe: |
229 |
< |
step=int(nEntries/longe) |
230 |
< |
long=longe |
231 |
< |
else: |
232 |
< |
long=nEntries |
233 |
< |
step = 1 |
234 |
< |
bar=progbar(long) |
235 |
< |
#Fill event by event: |
236 |
< |
for entry in range(0,nEntries): |
237 |
< |
if entry % step == 0: |
168 |
< |
bar.move() |
169 |
< |
#load entry |
170 |
< |
tree.GetEntry(entry) |
171 |
< |
for systematic in systematics: |
172 |
< |
for j in range(len( MVA_Vars['Nominal'])): |
173 |
< |
MVA_var_buffer[j][0] = MVA_formulas[systematic][j].EvalInstance() |
174 |
< |
|
175 |
< |
for j in range(0,len(readers)): |
176 |
< |
MVAbranches[j][systematics.index(systematic)] = readers[j].EvaluateMVA(MVAinfos[j].MVAname) |
177 |
< |
|
215 |
> |
MVA_formulas_Nominal.append(ROOT.TTreeFormula("MVA_formula%s_Nominal"%j, MVA_Vars['Nominal'][j],tree)) |
216 |
> |
outfile.cd() |
217 |
> |
MVAbranches=[] |
218 |
> |
for i in range(0,len(readers)): |
219 |
> |
MVAbranches.append(array('f',[0])) |
220 |
> |
newtree.Branch(MVAinfos[i].MVAname,MVAbranches[i],'nominal/F') |
221 |
> |
newtree.Branch(MVAinfos[i].MVAname+'_4',MVAbranches[i],'nominal/F') |
222 |
> |
#progbar |
223 |
> |
print '\n--> ' + job.name +':' |
224 |
> |
if nEntries >= longe: |
225 |
> |
step=int(nEntries/longe) |
226 |
> |
long=longe |
227 |
> |
else: |
228 |
> |
long=nEntries |
229 |
> |
step = 1 |
230 |
> |
bar=progbar(long) |
231 |
> |
#Fill event by event: |
232 |
> |
for entry in range(0,nEntries): |
233 |
> |
if entry % step == 0: |
234 |
> |
bar.move() |
235 |
> |
#load entry |
236 |
> |
tree.GetEntry(entry) |
237 |
> |
#nominal: |
238 |
|
for j in range(len( MVA_Vars['Nominal'])): |
239 |
< |
MVA_var_buffer[j][0] = MVA_formulas4[systematic][j].EvalInstance() |
240 |
< |
|
239 |
> |
MVA_var_buffer[j][0] = MVA_formulas_Nominal[j].EvalInstance() |
240 |
> |
|
241 |
|
for j in range(0,len(readers)): |
242 |
< |
MVAbranches4[j][systematics.index(systematic)] = readers[j].EvaluateMVA(MVAinfos[j].MVAname) |
243 |
< |
#Fill: |
244 |
< |
newtree.Fill() |
245 |
< |
newtree.AutoSave() |
186 |
< |
outfile.Close() |
187 |
< |
|
188 |
< |
#DATA: |
189 |
< |
if job.type == 'DATA': |
190 |
< |
#MVA Formulas |
191 |
< |
MVA_formulas_Nominal = [] |
192 |
< |
#create TTreeFormulas |
193 |
< |
for j in range(len( MVA_Vars['Nominal'])): |
194 |
< |
MVA_formulas_Nominal.append(ROOT.TTreeFormula("MVA_formula%s_Nominal"%j, MVA_Vars['Nominal'][j],tree)) |
195 |
< |
outfile.cd() |
196 |
< |
MVAbranches=[] |
197 |
< |
for i in range(0,len(readers)): |
198 |
< |
MVAbranches.append(array('f',[0])) |
199 |
< |
newtree.Branch(MVAinfos[i].MVAname,MVAbranches[i],'nominal/F') |
200 |
< |
newtree.Branch(MVAinfos[i].MVAname+'_4',MVAbranches[i],'nominal/F') |
201 |
< |
#progbar |
202 |
< |
print '\n--> ' + job.name +':' |
203 |
< |
if nEntries >= longe: |
204 |
< |
step=int(nEntries/longe) |
205 |
< |
long=longe |
206 |
< |
else: |
207 |
< |
long=nEntries |
208 |
< |
step = 1 |
209 |
< |
bar=progbar(long) |
210 |
< |
#Fill event by event: |
211 |
< |
for entry in range(0,nEntries): |
212 |
< |
if entry % step == 0: |
213 |
< |
bar.move() |
214 |
< |
#load entry |
215 |
< |
tree.GetEntry(entry) |
216 |
< |
#nominal: |
217 |
< |
for j in range(len( MVA_Vars['Nominal'])): |
218 |
< |
MVA_var_buffer[j][0] = MVA_formulas_Nominal[j].EvalInstance() |
219 |
< |
|
220 |
< |
for j in range(0,len(readers)): |
221 |
< |
MVAbranches[j][0]= readers[j].EvaluateMVA(MVAinfos[j].MVAname) |
222 |
< |
newtree.Fill() |
223 |
< |
newtree.AutoSave() |
224 |
< |
outfile.Close() |
242 |
> |
MVAbranches[j][0]= readers[j].EvaluateMVA(MVAinfos[j].MVAname) |
243 |
> |
newtree.Fill() |
244 |
> |
newtree.AutoSave() |
245 |
> |
outfile.Close() |
246 |
|
|
247 |
|
print '\n' |
248 |
|
|