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