Belle II Software  release-06-01-15
cdst_reprocessTOP.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 from ROOT import Belle2
14 from reconstruction import add_top_modules, add_cdst_output
15 
16 # ---------------------------------------------------------------------------------------
17 # Example of reprocessing cdst files with new TOP calibration constants
18 #
19 # Note: replace local database name/location before running or comment it out
20 # check the global tag: it must be the same as used in production of input file(s)
21 # ---------------------------------------------------------------------------------------
22 
23 
24 class ReplaceTOPLikelihoods(b2.Module):
25  ''' replacing TOP likelihoods in PIDLikelihoods with new values '''
26 
27  def event(self):
28  ''' event function '''
29 
30  chargedStableSet = [Belle2.Const.electron,
31  Belle2.Const.muon,
32  Belle2.Const.pion,
33  Belle2.Const.kaon,
34  Belle2.Const.proton,
35  Belle2.Const.deuteron]
36 
37  for track in Belle2.PyStoreArray('Tracks'):
38  pid = track.getRelated('PIDLikelihoods')
39  # should unset TOP in PIDLikelihoods first, but such function is not available
40  top = track.getRelated('TOPLikelihoods')
41  if top and pid:
42  if top.getFlag() == 1:
43  for chargedStable in chargedStableSet:
44  logL = top.getLogL(chargedStable)
45  pid.setLogLikelihood(Belle2.Const.TOP, chargedStable, logL)
46 
47 
48 # Database:
49 # - replace the name and location of the local DB before running!
50 # - payloads are searched for in the reverse order of DB's given below;
51 # therefore the new calibration, if provided, is taken from the local DB.
52 # - one can even use several local DB's
53 b2.use_central_database('data_reprocessing_proc7') # global tag used in production of cdst
54 b2.use_local_database('localDB/localDB.txt', 'localDB/') # new calibration
55 
56 # Create path
57 main = b2.create_path()
58 
59 # input: cdst file(s)
60 roinput = b2.register_module('RootInput')
61 main.add_module(roinput)
62 
63 # Initialize TOP geometry parameters (creation of Geant geometry is not needed)
64 main.add_module('TOPGeometryParInitializer')
65 
66 # Time Recalibrator
67 recalibrator = b2.register_module('TOPTimeRecalibrator')
68 recalibrator.param('subtractBunchTime', False)
69 main.add_module(recalibrator)
70 
71 # TOP reconstruction
72 add_top_modules(main)
73 for m in main.modules():
74  if m.type() == "TOPBunchFinder":
75  m.param('usePIDLikelihoods', True)
76 
77 # Replace TOP in PID likelihoods with new values
78 main.add_module(ReplaceTOPLikelihoods())
79 
80 # output: cdst file
81 add_cdst_output(main)
82 
83 # Print progress
84 progress = b2.register_module('Progress')
85 main.add_module(progress)
86 
87 # Process events
88 b2.process(main)
89 
90 # Print statistics
91 print(b2.statistics)
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:56