Belle II Software
development
track_to_mcparticle_relation_test.py
1
#!/usr/bin/env python3
2
3
10
11
12
from
basf2
import
set_random_seed, create_path, process, Module
13
from
ROOT
import
Belle2
14
from
simulation
import
add_simulation
15
from
reconstruction
import
add_reconstruction
16
import
logging
17
18
19
class
CheckPresenceOfTrackToMCParticleRelation
(Module):
20
"""Class to check the presence of a relation between a Track and an MCParticle"""
21
22
def
initialize
(self):
23
"""Initialise the required StoreArrays and variables"""
24
25
self.
Tracks
=
Belle2.PyStoreArray
(
'Tracks'
)
26
self.
Tracks
.isRequired()
27
28
self.
MCParticles
=
Belle2.PyStoreArray
(
'MCParticles'
)
29
self.
MCParticles
.isRequired()
30
31
self.
eventCount
= 1
32
33
def
event
(self):
34
"""Event loop"""
35
assert
self.
MCParticles
.getEntries() > 0,
"Size of MCParticles StoreArray is 0."
36
assert
self.
Tracks
.getEntries() > 0,
"Size of Tracks StoreArray is 0."
37
for
track
in
self.
Tracks
:
38
track_to_mcparticle_relations = track.getRelationsTo(
'MCParticles'
)
39
assert
track_to_mcparticle_relations.size() > 0,
"Somehow there are no relations from this track to an MCParticle. \
40
Why? I don't know. Likely the track is from a fake RecoTrack."
41
42
self.
eventCount
+= 1
43
44
45
def
main
():
46
"""Main function to be executed if this script is run to avoid running if it's just imported."""
47
set_random_seed(12345)
48
49
main = create_path()
50
51
# specify number of events to be generated
52
main.add_module(
'EventInfoSetter'
, expList=[0], evtNumList=[5], runList=[1])
53
main.add_module(
'ParticleGun'
,
54
pdgCodes=[211],
55
nTracks=1,
56
momentumGeneration=
'fixed'
,
57
momentumParams=[1.618034],
58
phiGeneration=
'fixed'
,
59
phiParams=[27.182818],
60
thetaGeneration=
'fixed'
,
61
thetaParams=[62.83185])
62
add_simulation(main, bkgfiles=
None
)
63
add_reconstruction(main)
64
65
main.add_module(
CheckPresenceOfTrackToMCParticleRelation
())
66
67
main.add_module(
'Progress'
)
68
process(main)
69
70
71
if
__name__ ==
"__main__"
:
72
logging.basicConfig(level=logging.INFO)
73
main
()
Belle2::PyStoreArray
A (simplified) python wrapper for StoreArray.
Definition
PyStoreArray.h:73
track_to_mcparticle_relation_test.CheckPresenceOfTrackToMCParticleRelation
Definition
track_to_mcparticle_relation_test.py:19
track_to_mcparticle_relation_test.CheckPresenceOfTrackToMCParticleRelation.initialize
initialize(self)
Definition
track_to_mcparticle_relation_test.py:22
track_to_mcparticle_relation_test.CheckPresenceOfTrackToMCParticleRelation.eventCount
int eventCount
Count the event number to jump the bad events.
Definition
track_to_mcparticle_relation_test.py:31
track_to_mcparticle_relation_test.CheckPresenceOfTrackToMCParticleRelation.MCParticles
MCParticles
MCParticles StoreArray.
Definition
track_to_mcparticle_relation_test.py:28
track_to_mcparticle_relation_test.CheckPresenceOfTrackToMCParticleRelation.Tracks
Tracks
Tracks StoreArray.
Definition
track_to_mcparticle_relation_test.py:25
track_to_mcparticle_relation_test.CheckPresenceOfTrackToMCParticleRelation.event
event(self)
Definition
track_to_mcparticle_relation_test.py:33
main
Definition
main.py:1
tracking
tests
track_to_mcparticle_relation_test.py
Generated on Mon Sep 1 2025 02:59:14 for Belle II Software by
1.13.2