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