Commit 424f24eb025a39e7054d3acd0e90fb855bb15818
1 parent
9314d941
implemented skimming
Showing
9 changed files
with
461 additions
and
42 deletions
Show diff stats
applyGenericFEI.py
| ... | ... | @@ -39,7 +39,8 @@ class FEI(object): |
| 39 | 39 | self.pths = paths |
| 40 | 40 | self.path = paths['main_path'] |
| 41 | 41 | self.verbose = verbose |
| 42 | - self.fei_path = None | |
| 42 | + self.fei_path = [] | |
| 43 | + self.skim_list = [] | |
| 43 | 44 | |
| 44 | 45 | add_aliases(aliases) |
| 45 | 46 | |
| ... | ... | @@ -56,8 +57,14 @@ class FEI(object): |
| 56 | 57 | database = self.fei['database']['db_location'] |
| 57 | 58 | database_txt = self.fei['database']['db_txt_location'] |
| 58 | 59 | prefix = self.fei['database']['prefix'] |
| 60 | + | |
| 61 | + if 'central' in self.fei['database']['db_type']: | |
| 62 | + | |
| 63 | + use_central_database(database_txt, LogLevel.WARNING, | |
| 64 | + 'fei_database') | |
| 65 | + else: | |
| 59 | 66 | |
| 60 | - use_local_database(database_txt, database, | |
| 67 | + use_local_database(database_txt, database, | |
| 61 | 68 | True, LogLevel.WARNING) |
| 62 | 69 | |
| 63 | 70 | b_cuts = build_cuts(self.fei['params']['B_extra_cut']) |
| ... | ... | @@ -123,6 +130,40 @@ class FEI(object): |
| 123 | 130 | |
| 124 | 131 | |
| 125 | 132 | |
| 133 | + def fei_skim(self, *args, **kwargs): | |
| 134 | + | |
| 135 | + if self.fei.get('fei_skimming', False): | |
| 136 | + | |
| 137 | + self.skim_list = [] | |
| 138 | + skimming = self.fei['fei_skimming'].get('particles', {}) | |
| 139 | + | |
| 140 | + for particle in skimming.keys(): | |
| 141 | + | |
| 142 | + for tag in skimming[particle].keys(): | |
| 143 | + | |
| 144 | + list_name = particle + ':' + tag | |
| 145 | + | |
| 146 | + if list_name not in self.skim_list: | |
| 147 | + | |
| 148 | + self.skim_list.append(str(list_name)) | |
| 149 | + | |
| 150 | + for module in skimming[particle][tag].keys(): | |
| 151 | + | |
| 152 | + if str(module) in 'cuts': | |
| 153 | + | |
| 154 | + cuts = build_cuts(skimming[particle][tag]['cuts']) | |
| 155 | + | |
| 156 | + applyCuts(list_name, | |
| 157 | + cuts, | |
| 158 | + path = self.path) | |
| 159 | + else: | |
| 160 | + loose_mc_match = skimming[particle][tag]\ | |
| 161 | + [module].get('looseMCMatch', False) | |
| 162 | + | |
| 163 | + self.path.add_module(module, list_name, | |
| 164 | + looseMCMatching = loose_mc_match) | |
| 165 | + | |
| 166 | + | |
| 126 | 167 | |
| 127 | 168 | def apply_configuration(self, *args, **kwargs): |
| 128 | 169 | |
| ... | ... | @@ -131,6 +172,7 @@ class FEI(object): |
| 131 | 172 | |
| 132 | 173 | self.load_FEI() |
| 133 | 174 | self.filter_FEI() |
| 175 | + self.fei_skim() | |
| 134 | 176 | else: |
| 135 | 177 | |
| 136 | 178 | message(self.verbose, 'FEI implementation has been disabled.' +\ | ... | ... |
configureReconstruction.py
| 1 | 1 | import basf2 |
| 2 | 2 | from basf2 import * |
| 3 | 3 | |
| 4 | -from stdCharged import * | |
| 5 | -from stdPi0s import * | |
| 6 | 4 | from ipython_tools import handler |
| 7 | 5 | import numpy as np |
| 8 | 6 | from matplotlib import pyplot as plt |
| ... | ... | @@ -24,11 +22,12 @@ from config import load_config |
| 24 | 22 | from aux_functions import * |
| 25 | 23 | from reconstructDecays import ReconstructDecays |
| 26 | 24 | from applyGenericFEI import FEI |
| 25 | +from skimming import Skimming | |
| 27 | 26 | |
| 28 | 27 | from reconstruction import add_reconstruction, add_mdst_output |
| 29 | -from ipython_tools import handler | |
| 28 | +from beamparameters import add_beamparameters | |
| 29 | + | |
| 30 | 30 | |
| 31 | -#TODO: implement skimming and inporting/outputting udst files | |
| 32 | 31 | |
| 33 | 32 | class ConfigureReconstruction(object): |
| 34 | 33 | |
| ... | ... | @@ -123,6 +122,8 @@ class ConfigureReconstruction(object): |
| 123 | 122 | |
| 124 | 123 | if confs['reconstruction'] is not None: |
| 125 | 124 | self.recon = load_config(confs['reconstruction']) |
| 125 | + if not self.recon.get('implement', False): | |
| 126 | + self.recon = False | |
| 126 | 127 | else: |
| 127 | 128 | message(verbose, 'No decay reconstruction config\ |
| 128 | 129 | given. Will not preform signal side\ |
| ... | ... | @@ -131,13 +132,24 @@ class ConfigureReconstruction(object): |
| 131 | 132 | |
| 132 | 133 | if confs['fei'] is not None: |
| 133 | 134 | self.fei = load_config(confs['fei']) |
| 135 | + if not self.fei.get('implement', False): | |
| 136 | + self.fei = False | |
| 134 | 137 | else: |
| 135 | 138 | message(verbose, 'No FEI parameters given. \ |
| 136 | 139 | Will not apply FEI.') |
| 137 | 140 | self.fei = False |
| 138 | 141 | |
| 139 | 142 | if confs['skimming'] is not None: |
| 143 | + | |
| 140 | 144 | self.skimming = load_config(confs['skimming']) |
| 145 | + self.truth_skim_path = create_path() | |
| 146 | + self.fei_skim_path = create_path() | |
| 147 | + | |
| 148 | + self.fei_particle_list = [] | |
| 149 | + self.truth_particle_list = [] | |
| 150 | + | |
| 151 | + if not self.skimming.get('implement', False): | |
| 152 | + self.skimming = False | |
| 141 | 153 | else: |
| 142 | 154 | message(verbose, 'Skimming config not specified.') |
| 143 | 155 | self.skimming = False |
| ... | ... | @@ -163,10 +175,23 @@ class ConfigureReconstruction(object): |
| 163 | 175 | self.fei_tag = False |
| 164 | 176 | |
| 165 | 177 | if self.recon: |
| 166 | - if self.recon.get('FEI_tag', False): | |
| 178 | + if self.recon.get('FEI_tag', False) and \ | |
| 179 | + self.recon.get('implement', False): | |
| 167 | 180 | |
| 168 | 181 | self.fei_tag = True |
| 169 | - self.in_files['SIG'] = self.in_files['FEI'] | |
| 182 | + | |
| 183 | + if self.in_files.get('SIG', False) and \ | |
| 184 | + self.in_files.get('FEI', False): | |
| 185 | + | |
| 186 | + self.in_files['SIG'] = self.in_files['FEI'] | |
| 187 | + | |
| 188 | + self.skim_fei_tag = False | |
| 189 | + | |
| 190 | + if self.skimming: | |
| 191 | + if self.skimming.get('FEI_tag', False): | |
| 192 | + | |
| 193 | + self.skim_fei_tag = True | |
| 194 | + self.in_files | |
| 170 | 195 | |
| 171 | 196 | |
| 172 | 197 | |
| ... | ... | @@ -174,12 +199,21 @@ class ConfigureReconstruction(object): |
| 174 | 199 | |
| 175 | 200 | def input_files(self, path, files, *args, **kwargs): |
| 176 | 201 | |
| 177 | - inputMdstList(files['type'], # type of data to be run on | |
| 178 | - files['file_list'], # list of data filenames | |
| 179 | - path, # the analysis path | |
| 180 | - skipNEvents = files.get('skip_n_events', 0)) # num evts | |
| 181 | - # to skip | |
| 202 | + file_type = files.get('file_type', 'mdst') | |
| 203 | + skip_evts = files.get('skip_n_events', 0) | |
| 204 | + | |
| 205 | + 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 | |
| 210 | + 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 | |
| 182 | 215 | |
| 216 | + | |
| 183 | 217 | |
| 184 | 218 | |
| 185 | 219 | |
| ... | ... | @@ -198,8 +232,62 @@ class ConfigureReconstruction(object): |
| 198 | 232 | processed but will instead be appended to the signal path and the |
| 199 | 233 | final file will be outputed after the signal side analysis.''' |
| 200 | 234 | |
| 235 | + if self.skimming: | |
| 236 | + | |
| 237 | + confs = {'skimming': self.skimming} | |
| 238 | + paths = {'fei_main_path': self.fei_skim_path, | |
| 239 | + 'truth_main_path': self.truth_skim_path} | |
| 240 | + | |
| 241 | + if self.skimming.get('fei_skimming', False): | |
| 242 | + | |
| 243 | + self.input_files(self.fei_skim_path, | |
| 244 | + self.in_files['fei_skim']) | |
| 245 | + | |
| 246 | + if self.skimming.get('truth_skimming', False) and \ | |
| 247 | + not self.skim_fei_tag: | |
| 248 | + | |
| 249 | + self.input_files(self.truth_skim_path, | |
| 250 | + self.in_files['truth_skim']) | |
| 251 | + | |
| 252 | + skim = Skimming(confs, paths, verbose = self.verbose) | |
| 253 | + skim.apply_configuration() | |
| 254 | + | |
| 255 | + if self.skimming.get('fei_skimming', False): | |
| 256 | + | |
| 257 | + self.fei_particle_list = skim.fei_skim_list | |
| 258 | + | |
| 259 | + if self.skim_fei_tag: | |
| 260 | + self.truth_skim_path.add_path(self.fei_skim_path) | |
| 261 | + else: | |
| 262 | + | |
| 263 | + self.build_output_files(self.fei_skim_path, | |
| 264 | + skim, | |
| 265 | + 'fei_skimming', | |
| 266 | + self.fei_particle_list) | |
| 267 | + | |
| 268 | + summaryOfLists(self.fei_particle_list) | |
| 269 | + | |
| 270 | + self.do_analysis(self.fei_skim_path) | |
| 271 | + | |
| 272 | + | |
| 273 | + if self.skimming.get('truth_skimming', False): | |
| 274 | + | |
| 275 | + self.truth_particle_list = skim.truth_skim_list | |
| 276 | + | |
| 277 | + self.build_output_files(self.truth_skim_path, | |
| 278 | + skim, | |
| 279 | + 'truth_skimming', | |
| 280 | + self.truth_particle_list) | |
| 281 | + | |
| 282 | + summaryOfLists(self.truth_particle_list) | |
| 283 | + | |
| 284 | + self.do_analysis(self.truth_skim_path) | |
| 285 | + | |
| 286 | + | |
| 201 | 287 | if self.fei and self.fei.get('implement', False): |
| 202 | 288 | |
| 289 | + #beam_params = add_beamparameters(self.fei_path, 'SuperKEKB') | |
| 290 | + | |
| 203 | 291 | confs = {'fei': self.fei} |
| 204 | 292 | paths = {'main_path': self.fei_path} |
| 205 | 293 | |
| ... | ... | @@ -214,7 +302,7 @@ class ConfigureReconstruction(object): |
| 214 | 302 | self.sig_path.add_path(self.fei_path) |
| 215 | 303 | else: |
| 216 | 304 | self.build_output_files(self.fei_path, |
| 217 | - reconstruction, 'FEI') | |
| 305 | + reconstruction, 'FEI', []) | |
| 218 | 306 | self.do_analysis(self.fei_path) |
| 219 | 307 | |
| 220 | 308 | |
| ... | ... | @@ -225,6 +313,8 @@ class ConfigureReconstruction(object): |
| 225 | 313 | |
| 226 | 314 | if not self.fei_tag: |
| 227 | 315 | self.input_files(self.sig_path, self.in_files['SIG']) |
| 316 | + #beam_params = add_beamparameters(self.sig_path, 'SuperKEKB') | |
| 317 | + | |
| 228 | 318 | |
| 229 | 319 | reconstruction = ReconstructDecays(confs, paths, |
| 230 | 320 | verbose = self.verbose) |
| ... | ... | @@ -232,7 +322,7 @@ class ConfigureReconstruction(object): |
| 232 | 322 | reconstruction.apply_configuration() |
| 233 | 323 | |
| 234 | 324 | self.build_output_files(self.sig_path, |
| 235 | - reconstruction, 'SIG') | |
| 325 | + reconstruction, 'SIG', []) | |
| 236 | 326 | self.do_analysis(self.sig_path) |
| 237 | 327 | |
| 238 | 328 | |
| ... | ... | @@ -240,7 +330,7 @@ class ConfigureReconstruction(object): |
| 240 | 330 | |
| 241 | 331 | |
| 242 | 332 | def build_output_files(self, path, reconstruction, |
| 243 | - recon_tag, *args, **kwargs): | |
| 333 | + recon_tag, lists, *args, **kwargs): | |
| 244 | 334 | |
| 245 | 335 | '''Builds the output files according to the specifications in the |
| 246 | 336 | configs. Will only build them if the output configs are given. |
| ... | ... | @@ -248,6 +338,47 @@ class ConfigureReconstruction(object): |
| 248 | 338 | Params: |
| 249 | 339 | @path: (B2Path) the analysis path that is to be ''' |
| 250 | 340 | |
| 341 | + if 'skimming' in recon_tag: | |
| 342 | + | |
| 343 | + self.build_udst_file(path, reconstruction, recon_tag, lists) | |
| 344 | + | |
| 345 | + else: | |
| 346 | + | |
| 347 | + self.build_mdst_file(path, reconstruction, recon_tag) | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + def build_udst_file(self, path, reconstruction, recon_tag, lists): | |
| 353 | + | |
| 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'] | |
| 360 | + | |
| 361 | + if file_path[-1] is not '/': | |
| 362 | + file_path += '/' | |
| 363 | + | |
| 364 | + output_file_tag = file_path + filetag | |
| 365 | + else: | |
| 366 | + message(self.verbose, 'WARNING: No output filename given! Will not | |
| 367 | + create output files!') | |
| 368 | + | |
| 369 | + output_list = self.out_variables.get(recon_tag, []) | |
| 370 | + | |
| 371 | + skimOutputUdst(self.skimming[recon_tag].get('decay_mode', recon_tag), | |
| 372 | + skimParticleLists = lists, | |
| 373 | + outputParticleLists = output_list, | |
| 374 | + outputFile = output_file_tag) | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + def build_mdst_file(self, path, reconstruction, | |
| 380 | + recon_tag, *args, **kwargs): | |
| 381 | + | |
| 251 | 382 | output = self.out_files.get(recon_tag, False) |
| 252 | 383 | |
| 253 | 384 | if output: | ... | ... |
No preview for this file type
No preview for this file type
example_configs/fei.yaml
| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | +--- | |
| 2 | +# --------------- | |
| 3 | +# Skimming Config | |
| 4 | +# --------------- | |
| 5 | + | |
| 6 | +implement: True | |
| 7 | +aliases: | |
| 8 | + sigProb: 'extraInfo(SignalProbability)' | |
| 9 | +fei_skimming: | |
| 10 | + database: | |
| 11 | + db_type: | |
| 12 | + db_location: | |
| 13 | + db_txt_location: | |
| 14 | + prefix: | |
| 15 | + KLong: False | |
| 16 | + chargedB: True | |
| 17 | + neutralB: False | |
| 18 | + semileptonic: False | |
| 19 | + hadronic: True | |
| 20 | + params: | |
| 21 | + B_extra_cut: | |
| 22 | + - | |
| 23 | + - | |
| 24 | + specific: False | |
| 25 | + convertedFromBelle: False | |
| 26 | + training: False | |
| 27 | + monitor: False | |
| 28 | + b2bii: False | |
| 29 | + particles: | |
| 30 | + <name>: | |
| 31 | + <coded_list_name>: | |
| 32 | + <module_to_add>: | |
| 33 | + looseMCMatch: True | |
| 34 | + cuts: | |
| 35 | + - | |
| 36 | + <other_particle_name>: | |
| 37 | + <coded_list_name>: | |
| 38 | + cuts: | |
| 39 | + - | |
| 40 | + | |
| 41 | +truth_skimming: | |
| 42 | + extra_skim_list: | |
| 43 | + - | |
| 44 | + - | |
| 45 | + FSParticles: | |
| 46 | + type: loose | |
| 47 | + | |
| 48 | + SIG: | |
| 49 | + Step0: | |
| 50 | + Upsilon(4S): | |
| 51 | + mu_cands: | |
| 52 | + ch1: 'B-:sig_mu B+:generic' | |
| 53 | + BuildRestOfEvent: | |
| 54 | + cuts: | |
| 55 | + - | |
| 56 | + Step1: | |
| 57 | + B-: | |
| 58 | + sig_mu: | |
| 59 | + ch1: 'D0:all mu-:loose' | |
| 60 | + cuts: | |
| 61 | + - | |
| 62 | + Step2: | |
| 63 | + D0: | |
| 64 | + all: | |
| 65 | + ch1: 'K-:loose pi+:loose' | |
| 66 | + ch2: 'K-:loose pi+:loose pi0:veryLoose' | |
| 67 | + ch3: 'K-:loose pi+:loose pi-:loose pi+:loose' | |
| 68 | + ch4: 'pi-:loose pi+:loose ' | |
| 69 | + ch5: 'K_S0:all pi+:loose pi-:loose' | |
| 70 | + ch6: 'K_S0:all pi+:loose pi-:loose pi0:veryLoose' | |
| 71 | + ch7: 'K_S0:all pi0:veryLoose' | |
| 72 | + ch8: 'K+:loose K-:loose' | |
| 73 | + ch9: 'pi+:loose pi-:loose' | |
| 74 | + ch10: 'K_S0:all K_S0:all' | |
| 75 | + cut: | |
| 76 | + - '0.86 < M < 3.0' | ... | ... |
load_configure_reconstruction.py
| ... | ... | @@ -13,8 +13,8 @@ parser = argparse.ArgumentParser() |
| 13 | 13 | |
| 14 | 14 | parser.add_argument('--path', |
| 15 | 15 | dest = 'path', |
| 16 | - default = '/home/bernanda/honours/FEI/generic/' +\ | |
| 17 | - '1st_trial_run/configs/', | |
| 16 | + default = '~/honours/FEI/generic/skims/phase2/' + \ | |
| 17 | + 'MC9/charged/configs/run1', | |
| 18 | 18 | type = str, |
| 19 | 19 | help = 'The directory of the config files (str).') |
| 20 | 20 | ... | ... |
reconstructDecays.py
| ... | ... | @@ -3,11 +3,14 @@ from basf2 import * |
| 3 | 3 | from stdCharged import * |
| 4 | 4 | from stdPi0s import * |
| 5 | 5 | from stdPhotons import * |
| 6 | +from stdV0s import * | |
| 7 | + | |
| 6 | 8 | |
| 7 | 9 | from ipython_tools import handler |
| 8 | 10 | import numpy as np |
| 9 | 11 | from matplotlib import pyplot as plt |
| 10 | 12 | import scipy as sp |
| 13 | +import re | |
| 11 | 14 | |
| 12 | 15 | import ROOT |
| 13 | 16 | from ROOT import Belle2 |
| ... | ... | @@ -19,6 +22,7 @@ import os.path |
| 19 | 22 | import sys |
| 20 | 23 | |
| 21 | 24 | from modularAnalysis import * |
| 25 | +from vertex import * | |
| 22 | 26 | import fei |
| 23 | 27 | from fei import backward_compatibility_layer |
| 24 | 28 | |
| ... | ... | @@ -64,6 +68,7 @@ class ReconstructDecays(object): |
| 64 | 68 | self.verbose = verbose |
| 65 | 69 | self.tags = {} |
| 66 | 70 | self.particles = {} |
| 71 | + self.skim_list = [] | |
| 67 | 72 | |
| 68 | 73 | add_aliases(aliases) |
| 69 | 74 | |
| ... | ... | @@ -91,14 +96,18 @@ class ReconstructDecays(object): |
| 91 | 96 | stdLooseMu(path = self.path) |
| 92 | 97 | stdLooseK(path = self.path) |
| 93 | 98 | stdPi0s(listtype = 'veryLoose', path = self.path) |
| 99 | + stdPhotons(listtype = 'loose', path = self.path) | |
| 100 | + stdKshorts(path = self.path) | |
| 94 | 101 | |
| 95 | - elif 'std' in typ: | |
| 102 | + elif 'std' in typ or 'tight' in typ: | |
| 96 | 103 | |
| 97 | 104 | stdE(path = self.path) |
| 98 | 105 | stdPi(path = self.path) |
| 99 | 106 | stdMu(path = self.path) |
| 100 | 107 | stdK(path = self.path) |
| 101 | 108 | stdPi0(listtype = 'loose', path = self.path) |
| 109 | + stdPhotons(listtype = 'tight', path = self.path) | |
| 110 | + stdKshorts(path = self.path) | |
| 102 | 111 | |
| 103 | 112 | elif 'custom' is typ: |
| 104 | 113 | |
| ... | ... | @@ -136,7 +145,7 @@ class ReconstructDecays(object): |
| 136 | 145 | |
| 137 | 146 | channel_list = list(particle.keys()) |
| 138 | 147 | |
| 139 | - return [x for x in channel_list if x[:-1]=='ch'] | |
| 148 | + return [x for x in channel_list if re.split(r'\d+', x)[0]=='ch'] | |
| 140 | 149 | |
| 141 | 150 | |
| 142 | 151 | |
| ... | ... | @@ -157,6 +166,31 @@ class ReconstructDecays(object): |
| 157 | 166 | |
| 158 | 167 | |
| 159 | 168 | |
| 169 | + def vertex_fit(self, sig, step, particle, main_channel, | |
| 170 | + channel, path, *args, **kwargs): | |
| 171 | + | |
| 172 | + prt = sig[step][particle][main_channel] | |
| 173 | + vertexing = prt.get('fit_vertex', False) | |
| 174 | + | |
| 175 | + if vertexing: | |
| 176 | + | |
| 177 | + list_name = particle + ':' + main_channel + '_' + channel | |
| 178 | + | |
| 179 | + decay_str = '' | |
| 180 | + if prt.get('decay_str_selection', False): | |
| 181 | + | |
| 182 | + decay_str = list_name + '->' + sig[step][particle]\ | |
| 183 | + [main_channel][channel] | |
| 184 | + | |
| 185 | + vertexKFit(list_name, | |
| 186 | + vertexing.get('acceptance_level', 0.0), | |
| 187 | + decay_string = decay_str, | |
| 188 | + constraint = vertexing.get('constraint', ''), | |
| 189 | + path = self.path) | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 160 | 194 | |
| 161 | 195 | def reconstruct_in_channels(self, sig, step, particle, |
| 162 | 196 | main_channel, channels, *args, **kwargs): |
| ... | ... | @@ -171,15 +205,20 @@ class ReconstructDecays(object): |
| 171 | 205 | |
| 172 | 206 | cuts = build_cuts(sig[step][particle]\ |
| 173 | 207 | [main_channel].get('cuts', [])) |
| 208 | + | |
| 209 | + particle_and_tag = particle + ':' + main_channel + '_' + channel | |
| 174 | 210 | |
| 175 | - decay_str = particle + ':' + main_channel + '_' + channel + ' -> '\ | |
| 176 | - + sig[step][particle][main_channel][channel] | |
| 211 | + decay_str = particle_and_tag + ' -> ' +\ | |
| 212 | + sig[step][particle][main_channel][channel] | |
| 177 | 213 | |
| 178 | 214 | reconstructDecay(decay_str, |
| 179 | 215 | cuts, |
| 180 | - dmID = int(channel[-1]), | |
| 216 | + dmID = int(channel.split('ch')[1]), | |
| 181 | 217 | path = self.path) |
| 182 | 218 | |
| 219 | + self.vertex_fit(sig, step, particle, | |
| 220 | + main_channel, channel, self.path) | |
| 221 | + | |
| 183 | 222 | |
| 184 | 223 | |
| 185 | 224 | |
| ... | ... | @@ -213,7 +252,8 @@ class ReconstructDecays(object): |
| 213 | 252 | self._append_to_ls(self.tags[step][particle][main_channel], |
| 214 | 253 | main_channel) |
| 215 | 254 | |
| 216 | - message(self.verbose, ' Main channel: ' + main_channel) | |
| 255 | + message(self.verbose, ' Main channel: ' +\ | |
| 256 | + main_channel) | |
| 217 | 257 | |
| 218 | 258 | particle_list_name = particle + ':' + main_channel |
| 219 | 259 | prt_list = [particle + ':' + main_channel + '_'\ |
| ... | ... | @@ -238,39 +278,62 @@ class ReconstructDecays(object): |
| 238 | 278 | |
| 239 | 279 | '''Reconstructs decay given in reconstruction config''' |
| 240 | 280 | |
| 241 | - message(self.verbose, 'Preforming reconstruction...') | |
| 281 | + if self.cfgs['recon'].get('implement', False): | |
| 242 | 282 | |
| 243 | - sig = self.cfgs['recon']['SIG'] | |
| 283 | + message(self.verbose, 'Preforming reconstruction...') | |
| 284 | + | |
| 285 | + sig = self.cfgs['recon']['SIG'] | |
| 286 | + | |
| 287 | + self.load_fs_particles() | |
| 288 | + | |
| 289 | + steps = self.get_steps() | |
| 290 | + n_steps = len(steps) | |
| 291 | + | |
| 292 | + for step_num in range(n_steps): | |
| 293 | + | |
| 294 | + step = 'Step' + str(n_steps - step_num - 1) | |
| 295 | + message(self.verbose, 'SIG RECON: ' + step) | |
| 296 | + | |
| 297 | + self.particles[step] = {} | |
| 298 | + self.tags[step] = {} | |
| 299 | + | |
| 300 | + self.reconstruct_in_particles(sig, step) | |
| 301 | + | |
| 302 | + if self.cfgs['recon'].get('truth_skimming', False): | |
| 303 | + | |
| 304 | + self.get_skim_list(sig) | |
| 244 | 305 | |
| 245 | - self.load_fs_particles() | |
| 306 | + else: | |
| 307 | + message(self.verbose, 'Signal reconstruction disabled.' +\ | |
| 308 | + 'Will not preform signal reconstruction') | |
| 246 | 309 | |
| 247 | - steps = self.get_steps() | |
| 248 | - n_steps = len(steps) | |
| 249 | 310 | |
| 250 | - for step_num in range(n_steps): | |
| 251 | 311 | |
| 252 | - step = 'Step' + str(n_steps - step_num - 1) | |
| 253 | - message(self.verbose, 'SIG RECON: ' + step) | |
| 312 | + def get_skim_list(self, sig, *args, **kwargs): | |
| 254 | 313 | |
| 255 | - self.particles[step] = {} | |
| 256 | - self.tags[step] = {} | |
| 314 | + for particle in sig.get('Step0', {}).keys(): | |
| 257 | 315 | |
| 258 | - self.reconstruct_in_particles(sig, step) | |
| 316 | + for list_name in sig['Step0'][particle].keys(): | |
| 317 | + | |
| 318 | + particle_list_name = particle + ':' + list_name | |
| 259 | 319 | |
| 320 | + self._append_to_ls(self.skim_list, particle_list_name) | |
| 260 | 321 | |
| 261 | 322 | |
| 323 | + extra_lists = self.cfgs['recon'].get('extra_skim_lists', False) | |
| 262 | 324 | |
| 263 | - def apply_configuration(self): | |
| 325 | + if extra_lists: | |
| 264 | 326 | |
| 265 | - add_aliases(self.cfgs['recon'].get('aliases', {})) | |
| 327 | + for ls in extra_lists: | |
| 328 | + self._append_to_ls(self.skim_list, ls) | |
| 266 | 329 | |
| 267 | - if self.cfgs['recon'].get('implement', False): | |
| 268 | 330 | |
| 269 | - self.reconstruct_decay() | |
| 270 | 331 | |
| 271 | - else: | |
| 272 | - message(self.verbose, 'Signal reconstruction disabled.' +\ | |
| 273 | - 'Will not preform signal reconstruction') | |
| 332 | + def apply_configuration(self): | |
| 333 | + | |
| 334 | + add_aliases(self.cfgs['recon'].get('aliases', {})) | |
| 335 | + | |
| 336 | + self.reconstruct_decay() | |
| 274 | 337 | |
| 275 | 338 | |
| 276 | 339 | ... | ... |
| ... | ... | @@ -0,0 +1,106 @@ |
| 1 | +#!/usr/bin/env python3 | |
| 2 | + | |
| 3 | +from basf2 import * | |
| 4 | +from modularAnalysis import * | |
| 5 | + | |
| 6 | +import sys | |
| 7 | +sys.path.append('/home/bernanda/honours/scripts/') | |
| 8 | +from applyGenericFEI import FEI | |
| 9 | +from reconstructDecays import ReconstructDecays | |
| 10 | +from aux_functions import * | |
| 11 | + | |
| 12 | + | |
| 13 | +class Skimming(object): | |
| 14 | + | |
| 15 | + def __init__(self, configs, paths, aliases = {}, | |
| 16 | + verbose = False, *args, **kwargs): | |
| 17 | + | |
| 18 | + self.cfgs = configs | |
| 19 | + self.skimming = configs['skimming'] | |
| 20 | + self.paths = paths | |
| 21 | + self.truth_path = paths['truth_main_path'] | |
| 22 | + self.fei_path = paths['fei_main_path'] | |
| 23 | + self.aliases = aliases | |
| 24 | + self.verbose = verbose | |
| 25 | + | |
| 26 | + self.fei_skim_list = [] | |
| 27 | + self.truth_skim_list = [] | |
| 28 | + | |
| 29 | + add_aliases(self.aliases) | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + def build_fei_config(self, *args, **kwargs): | |
| 34 | + | |
| 35 | + config = {} | |
| 36 | + config['fei'] = {} | |
| 37 | + | |
| 38 | + config['fei'] = self.skimming['fei_skimming'] | |
| 39 | + config['fei']['implement'] = True | |
| 40 | + | |
| 41 | + return config | |
| 42 | + | |
| 43 | + | |
| 44 | + def build_truth_config(self, *args, **kwargs): | |
| 45 | + | |
| 46 | + config = {} | |
| 47 | + config['recon'] = {} | |
| 48 | + | |
| 49 | + config['recon']['SIG'] = self.skimming['truth_skimming'] | |
| 50 | + config['recon']['implement'] = True | |
| 51 | + config['recon']['truth_skimming'] = True | |
| 52 | + | |
| 53 | + return config | |
| 54 | + | |
| 55 | + def build_paths(self, path, *args, **kwargs): | |
| 56 | + | |
| 57 | + config = {} | |
| 58 | + config = self.paths | |
| 59 | + config['main_path'] = path | |
| 60 | + | |
| 61 | + return config | |
| 62 | + | |
| 63 | + | |
| 64 | + def skim(self, *args, **kwargs): | |
| 65 | + | |
| 66 | + if self.skimming.get('implement', False): | |
| 67 | + | |
| 68 | + if self.skimming.get('aliases', False): | |
| 69 | + add_aliases(self.skimming['aliases']) | |
| 70 | + | |
| 71 | + if self.skimming.get('fei_skimming', False): | |
| 72 | + | |
| 73 | + message(self.verbose, 'Preforming FEI skimming.') | |
| 74 | + | |
| 75 | + configs = self.build_fei_config() | |
| 76 | + paths = self.build_paths(self.fei_path) | |
| 77 | + | |
| 78 | + fei_skimming = FEI(configs, paths, | |
| 79 | + aliases = self.aliases, | |
| 80 | + verbose = self.verbose) | |
| 81 | + | |
| 82 | + fei_skimming.apply_configuration() | |
| 83 | + | |
| 84 | + self.fei_skim_list = fei_skimming.skim_list | |
| 85 | + | |
| 86 | + if self.skimming.get('truth_skimming', False): | |
| 87 | + | |
| 88 | + message(self.verbose, 'Preforming truth skimming.') | |
| 89 | + | |
| 90 | + configs = self.build_truth_config() | |
| 91 | + paths = self.build_paths(self.truth_path) | |
| 92 | + | |
| 93 | + truth_skimming = ReconstructDecays(configs, paths, | |
| 94 | + aliases = self.aliases, | |
| 95 | + verbose = self.verbose) | |
| 96 | + truth_skimming.apply_configuration() | |
| 97 | + | |
| 98 | + self.truth_skim_list = truth_skimming.skim_list | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + def apply_configuration(self, *args, **kwargs): | |
| 103 | + | |
| 104 | + self.skim() | |
| 105 | + | |
| 106 | + | ... | ... |