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=[], action="append", |
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('./config7TeV_ZZ') |
41 |
> |
config.read(opts.config) |
42 |
> |
anaTag = config.get("Analysis","tag") |
43 |
|
|
44 |
|
#get locations: |
45 |
|
Wdir=config.get('Directories','Wdir') |
46 |
< |
|
47 |
< |
MVAdir=config.get('Directories','MVAdir') |
46 |
> |
MVASubdir=config.get('Directories','MVAdir') |
47 |
> |
samplesinfo=config.get('Directories','samplesinfo') |
48 |
|
|
49 |
|
#systematics |
50 |
|
systematics=config.get('systematics','systematics') |
59 |
|
###################### |
60 |
|
#Evaluate multi: Must Have same treeVars!!! |
61 |
|
|
62 |
< |
Apath=sys.argv[1] |
63 |
< |
arglist=sys.argv[2] #RTight_blavla,bsbsb |
62 |
> |
Apath=opts.path |
63 |
> |
infofile = open(samplesinfo,'r') |
64 |
> |
info = pickle.load(infofile) |
65 |
> |
infofile.close() |
66 |
> |
arglist=opts.discr #RTight_blavla,bsbsb |
67 |
|
|
68 |
< |
namelistIN=sys.argv[3] |
68 |
> |
namelistIN=opts.names |
69 |
|
namelist=namelistIN.split(',') |
70 |
|
|
71 |
< |
doinfo=bool(int(sys.argv[4])) |
71 |
> |
doinfo=bool(int(opts.update)) |
72 |
|
|
73 |
|
MVAlist=arglist.split(',') |
74 |
+ |
MVAdir=config.get('Directories','vhbbpath') |
75 |
|
|
76 |
|
#CONFIG |
77 |
|
#factory |
85 |
|
#MVAinfofiles=[] |
86 |
|
MVAinfos=[] |
87 |
|
for MVAname in MVAlist: |
88 |
< |
MVAinfofile = open(Wdir+'/weights/'+factoryname+'_'+MVAname+'.info','r') |
88 |
> |
MVAinfofile = open(MVAdir+'/data/'+factoryname+'_'+MVAname+'.info','r') |
89 |
|
MVAinfos.append(pickle.load(MVAinfofile)) |
90 |
|
MVAinfofile.close() |
91 |
|
|
124 |
|
# reader.AddSpectator(spectators[i],MVA_spectator_buffer[i]) |
125 |
|
#Load raeder |
126 |
|
for i in range(0,len(readers)): |
127 |
< |
readers[i].BookMVA(MVAinfos[i].MVAname,MVAinfos[i].getweightfile()) |
127 |
> |
readers[i].BookMVA(MVAinfos[i].MVAname,MVAdir+'/data/'+MVAinfos[i].getweightfile()) |
128 |
|
#--> Now the MVA is booked |
129 |
|
|
130 |
|
#Apply samples |
131 |
< |
infofile = open(Apath+'/samples.info','r') |
131 |
> |
infofile = open(samplesinfo,'r') |
132 |
|
Ainfo = pickle.load(infofile) |
133 |
|
infofile.close() |
134 |
|
|
137 |
|
if eval(job.active): |
138 |
|
if job.name in namelist: |
139 |
|
#get trees: |
140 |
< |
input = TFile.Open(job.getpath(),'read') |
141 |
< |
outfile = TFile.Open(job.path+'/'+MVAdir+job.prefix+job.identifier+'.root','recreate') |
140 |
> |
input = TFile.Open(Apath+'/'+job.getpath(),'read') |
141 |
> |
outfile = TFile.Open(Apath+'/'+MVASubdir+job.prefix+job.identifier+'.root','recreate') |
142 |
|
input.cd() |
143 |
|
obj = ROOT.TObject |
144 |
|
for key in ROOT.gDirectory.GetListOfKeys(): |
172 |
|
MVAbranches=[] |
173 |
|
MVAbranches4=[] |
174 |
|
for i in range(0,len(readers)): |
175 |
< |
MVAbranches.append(array('f',[0]*9)) |
176 |
< |
MVAbranches4.append(array('f',[0]*9)) |
177 |
< |
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') |
178 |
< |
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') |
175 |
> |
MVAbranches.append(array('f',[0]*11)) |
176 |
> |
MVAbranches4.append(array('f',[0]*11)) |
177 |
> |
newtree.Branch(MVAinfos[i].MVAname,MVAbranches[i],'nominal:JER_up:JER_down:JES_up:JES_down:beff_up:beff_down:bmis_up:bmis_down:beff1_up:beff1_down/F') |
178 |
> |
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:beff1_up:beff1_down/F') |
179 |
|
print '\n--> ' + job.name +':' |
180 |
|
#progbar setup |
181 |
|
if nEntries >= longe: |
254 |
|
for MVAinfo in MVAinfos: |
255 |
|
job.addcomment('Added MVA %s'%MVAinfo.MVAname) |
256 |
|
job.addpath(MVAdir) |
257 |
< |
infofile = open(Apath+MVAdir+'/samples.info','w') |
257 |
> |
infofile = open(samplesinfo,'w') |
258 |
|
pickle.dump(Ainfo,infofile) |
259 |
|
infofile.close() |
260 |
|
|