Commit c138403711037df8279c15fb3a6f312531009444

Authored by Bernanda Telalovic
1 parent 424f24eb

fixing data loading bug

Showing 2 changed files with 117 additions and 48 deletions   Show diff stats
configureReconstruction.py
... ... @@ -10,6 +10,7 @@ from variables import variables
10 10 import os
11 11 import os.path
12 12 import sys
  13 +from datetime import datetime
13 14  
14 15 from modularAnalysis import *
15 16 import fei
... ... @@ -176,7 +177,8 @@ class ConfigureReconstruction(object):
176 177  
177 178 if self.recon:
178 179 if self.recon.get('FEI_tag', False) and \
179   - self.recon.get('implement', False):
  180 + self.recon.get('implement', False) and \
  181 + self.fei:
180 182  
181 183 self.fei_tag = True
182 184  
... ... @@ -193,6 +195,8 @@ class ConfigureReconstruction(object):
193 195 self.skim_fei_tag = True
194 196 self.in_files
195 197  
  198 + self.data = False
  199 +
196 200  
197 201  
198 202  
... ... @@ -200,18 +204,24 @@ class ConfigureReconstruction(object):
200 204 def input_files(self, path, files, *args, **kwargs):
201 205  
202 206 file_type = files.get('file_type', 'mdst')
  207 + data_type = files.get('type', 'default')
  208 +
  209 + if 'data' in data_type:
  210 + self.data = True
  211 + data_type = 'default'
  212 +
203 213 skip_evts = files.get('skip_n_events', 0)
204 214  
205 215 if 'mdst' in file_type:
206   - inputMdstList(files['type'], # type of data to be run on
207   - files['file_list'], # list of data filenames
208   - path, # the analysis path
209   - skipNEvents = skip_evts) # num evts to skip
  216 + inputMdstList(data_type, # type of data to be run on
  217 + files['file_list'], # list of data filenames
  218 + path, # the analysis path
  219 + skipNEvents = skip_evts)# num evts to skip
210 220 elif 'udst' in file_type:
211   - inputMdstList(files['type'], # type of data to be run on
212   - files['file_list'], # list of data filenames
213   - path, # the analysis path
214   - skipNEvents = skip_evts) # num evts to skip
  221 + inputMdstList(data_type, # type of data to be run on
  222 + files['file_list'], # list of data filenames
  223 + path, # the analysis path
  224 + skipNEvents = skip_evts)# num evts to skip
215 225  
216 226  
217 227  
... ... @@ -249,7 +259,8 @@ class ConfigureReconstruction(object):
249 259 self.input_files(self.truth_skim_path,
250 260 self.in_files['truth_skim'])
251 261  
252   - skim = Skimming(confs, paths, verbose = self.verbose)
  262 + skim = Skimming(confs, paths,
  263 + verbose = self.verbose, data = self.data)
253 264 skim.apply_configuration()
254 265  
255 266 if self.skimming.get('fei_skimming', False):
... ... @@ -294,7 +305,8 @@ class ConfigureReconstruction(object):
294 305 self.input_files(self.fei_path, self.in_files['FEI'])
295 306  
296 307 reconstruction = FEI(confs, paths,
297   - verbose = self.verbose)
  308 + verbose = self.verbose,
  309 + data = self.data)
298 310  
299 311 reconstruction.apply_configuration()
300 312  
... ... @@ -317,7 +329,8 @@ class ConfigureReconstruction(object):
317 329  
318 330  
319 331 reconstruction = ReconstructDecays(confs, paths,
320   - verbose = self.verbose)
  332 + verbose = self.verbose,
  333 + data = self.data)
321 334  
322 335 reconstruction.apply_configuration()
323 336  
... ... @@ -347,31 +360,61 @@ class ConfigureReconstruction(object):
347 360 self.build_mdst_file(path, reconstruction, recon_tag)
348 361  
349 362  
  363 + def build_output_name(self, output, *args, **kwargs):
350 364  
  365 + ''' '''
351 366  
352   - def build_udst_file(self, path, reconstruction, recon_tag, lists):
  367 + filename = ''
353 368  
354   - output = self.out_files.get(recon_tag, False)
355   - output_file_tag = None
356   -
357   - if output:
358   - filetag = output['filetag']
359   - file_path = output['path']
  369 + if output:
  370 + filetag = output.get('filetag', 'unnamedfile_' +\
  371 + str(datetime.today()))
  372 + file_path = output.get('path', self.config_path)
360 373  
361 374 if file_path[-1] is not '/':
362 375 file_path += '/'
363 376  
364   - output_file_tag = file_path + filetag
  377 + if not '.root' in filetag:
  378 + filetag = filetag + '.root'
  379 +
  380 + filename = file_path + filetag
  381 + directory = os.path.dirname(filename)
  382 +
  383 + if not os.path.exists(directory):
  384 + os.makedirs(directory)
  385 +
  386 + if os.path.isfile(filename):
  387 + filename = filename.split('.root')[0] +\
  388 + str(datetime.today()) + '.root'
  389 +
  390 + message(self.verbose, 'Outputting file with name ' + filename)
  391 +
365 392 else:
366   - message(self.verbose, 'WARNING: No output filename given! Will not
367   - create output files!')
  393 + filename = self.config_path + 'unnamed_file_' +\
  394 + str(datetime.today()) + '.root'
  395 +
  396 + message(self.verbose, 'WARNING: No output filename given!' +\
  397 + 'Will output to cofig directory with name '+ filename)
  398 +
  399 + return filename
  400 +
  401 +
  402 +
  403 +
  404 + def build_udst_file(self, path, reconstruction, recon_tag, lists):
  405 +
  406 + output = self.out_files.get(recon_tag, False)
  407 + output_file_tag = 'unnamedfile_'
  408 +
  409 + output_file_tag = self.build_output_name(output)
368 410  
369 411 output_list = self.out_variables.get(recon_tag, [])
370 412  
371 413 skimOutputUdst(self.skimming[recon_tag].get('decay_mode', recon_tag),
372 414 skimParticleLists = lists,
373 415 outputParticleLists = output_list,
374   - outputFile = output_file_tag)
  416 + outputFile = output_file_tag,
  417 + path = path)
375 418  
376 419  
377 420  
... ... @@ -382,16 +425,8 @@ class ConfigureReconstruction(object):
382 425 output = self.out_files.get(recon_tag, False)
383 426  
384 427 if output:
385   - filetag = output['filetag']
386   - file_path = output['path']
387   -
388   - if file_path[-1] is not '/':
389   - file_path += '/'
390   -
391   - if '.root' in filetag:
392   - file_name = file_path + filetag
393   - else:
394   - file_name = file_path + file_tag + '.root'
  428 +
  429 + file_name = self.build_output_name(output)
395 430  
396 431 ntupleFile(file_name, path = path)
397 432  
... ...
reconstructDecays.py
... ... @@ -40,7 +40,7 @@ from ipython_tools import handler
40 40 class ReconstructDecays(object):
41 41  
42 42 def __init__(self, configs, paths, aliases = {},
43   - verbose = False, *args, **kwargs):
  43 + verbose = False, data = False, *args, **kwargs):
44 44  
45 45 '''Preforms decay reconstruction for the signal side, given
46 46 configurations. It is called by ConfigureReconstruction. This module
... ... @@ -69,10 +69,49 @@ class ReconstructDecays(object):
69 69 self.tags = {}
70 70 self.particles = {}
71 71 self.skim_list = []
  72 + self.data = data
  73 +
  74 + message(self.verbose, 'We are working on data: ' + str(self.data))
72 75  
73 76 add_aliases(aliases)
74 77  
75 78  
  79 + def load_pi0s(self, fsp = {}, *args, **kwargs):
  80 +
  81 + ''''''
  82 +
  83 + given_lists = fsp.get('type', 'loose')
  84 + types = given_lists.split(' ')
  85 +
  86 + lists = ['loose', 'std', 'tight']
  87 +
  88 + list_types = [x for x in lists if x in types]
  89 +
  90 + tags = {'loose': ['veryLoose', 'pi0eff60'],
  91 + 'std': ['loose', 'pi0eff40'],
  92 + 'tight': ['loose', 'pi0eff40']}
  93 + mass_cuts = {'veryLoose': '0.075 < M < 0.175',
  94 + 'loose': '0.124 < M < 0.140'}
  95 +
  96 + for list_type in list_types:
  97 +
  98 + tag = tags[list_type][0]
  99 + gamm_tag = tags[list_type][1]
  100 +
  101 + if self.data:
  102 +
  103 + stdPhotons(gamm_tag, path = self.path)
  104 + decay_string = 'pi0:' + tag + ' -> gamma:' + \
  105 + gamm_tag + ' gamma:' + gamm_tag
  106 +
  107 + mass_cut = mass_cuts[tag]
  108 +
  109 + reconstructDecay(decay_string, mass_cut, 1,
  110 + True, self.path)
  111 + else:
  112 + stdPi0s(listtype = list_type, path = self.path)
  113 +
  114 +
76 115  
77 116  
78 117 def load_fs_particles(self, *args, **kwargs):
... ... @@ -84,10 +123,9 @@ class ReconstructDecays(object):
84 123  
85 124 fs_particles = self.cfgs['recon']['FSParticles']
86 125  
87   - if fs_particles.get('type', False):
88   - typ = fs_particles['type']
89   - else:
90   - typ = 'loose'
  126 + typ = fs_particles.get('type', 'loose')
  127 +
  128 + self.load_pi0s(fs_particles)
91 129  
92 130 if 'loose' in typ:
93 131  
... ... @@ -95,25 +133,21 @@ class ReconstructDecays(object):
95 133 stdLoosePi(path = self.path)
96 134 stdLooseMu(path = self.path)
97 135 stdLooseK(path = self.path)
98   - stdPi0s(listtype = 'veryLoose', path = self.path)
99   - stdPhotons(listtype = 'loose', path = self.path)
  136 + stdPhotons(listtype = 'all', path = self.path)
100 137 stdKshorts(path = self.path)
101 138  
102   - elif 'std' in typ or 'tight' in typ:
  139 + if 'std' in typ or 'tight' in typ:
103 140  
104 141 stdE(path = self.path)
105 142 stdPi(path = self.path)
106 143 stdMu(path = self.path)
107 144 stdK(path = self.path)
108   - stdPi0(listtype = 'loose', path = self.path)
109   - stdPhotons(listtype = 'tight', path = self.path)
  145 + stdPhotons(listtype = 'all', path = self.path)
110 146 stdKshorts(path = self.path)
111 147  
112   - elif 'custom' is typ:
  148 + if 'custom' in typ:
113 149  
114   - message(self.verbose, 'WARNING: Loading custom fs particles.' +\
115   - 'If not all fs particles are specified in the list,' +\
116   - 'I will crash.')
  150 + message(self.verbose, 'Loading custom fs particles...')
117 151  
118 152 for particle in fs_particles['particles'].keys():
119 153  
... ... @@ -126,7 +160,7 @@ class ReconstructDecays(object):
126 160 list_name = particle + ':' + fs_particles['particles']\
127 161 [particle]['list_name']
128 162  
129   - fillParticleListFromMC(list_name, cuts, path = self.path)
  163 + fillParticleList(list_name, cuts, writeOut = True, path = self.path)
130 164  
131 165  
132 166  
... ...