Belle II Software development
eclTrackBremFinderTest.py
1#!/usr/bin/env python3
2
3
10
11"""
12Test for checking if a generated bremsstrahlung cluster is assigned correctly
13to the primary ECL cluster generated by an electron.
14The test is quite delicate: with the current settings the check fails 10% of the times.
15"""
16
17import basf2 as b2
18from ROOT import Belle2
19from ROOT import TVector3
20
21import simulation
22import reconstruction
23
24b2.set_random_seed(42)
25
26
28 """
29 Module which checks if a generated bremsstrahlung cluster is assigned correctly
30 to the primary ECL cluster generated by an electron.
31 """
32
33 def event(self):
34 """
35 Load the one track from the data store and check if the relation to the brem cluster
36 can been set correctly.
37 """
38 eventMetaData = Belle2.PyStoreObj("EventMetaData")
39 clusters = Belle2.PyStoreArray("ECLClusters")
40 bremCluster = None
41 for cluster in clusters:
42 # this is the primary of the electron
43 if cluster.isTrack() and cluster.hasHypothesis(Belle2.ECLCluster.EHypothesisBit.c_nPhotons):
44 # is there a relation to our secondary cluster?
45 bremCluster = cluster.getRelated("ECLClusters")
46
47 bad_events = []
48 if (eventMetaData.getEvent() in bad_events):
49 # the check fails on some events. Instead of finding new settings,
50 # check if the bremCluster is None only for the bad_events
51 assert(not bremCluster)
52 else:
53 # for all the other events, there must be a bremCluster
54 assert(bremCluster)
55
56
57class SearchForHits(b2.Module):
58 """
59 Module used to define the position and direction of the 'virtual' bremsstrahlung photon
60 generated by the particle gun
61 Not used at the moment (only for fit location)
62 """
63
64 def event(self):
65 """Process event"""
66
67 reco_tracks = Belle2.PyStoreArray("RecoTracks")
68
69 for recoTrack in reco_tracks:
70 # hit = recoTrack.getMeasuredStateOnPlaneFromFirstHit()
71 print("!!!!!!!!!!!!!!!!!!!!!!!!!Position!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
72 hit = recoTrack.getMeasuredStateOnPlaneClosestTo(TVector3(10, 5, -2))
73 hit_pos = hit.getPos()
74 print(hit_pos.X())
75 print(hit_pos.Y())
76 print(hit_pos.Z())
77 print(hit.getMom().Phi())
78 print(hit.getMom().Theta())
79
80
81# to run the framework the used modules need to be registered
82main = b2.create_path()
83
84# generates 4 events (but then, the check is skipped for the 1st one)
85main.add_module('EventInfoSetter', evtNumList=[4])
86
87# generates electron with given direction
88main.add_module('ParticleGun',
89 pdgCodes=[11],
90 nTracks=1,
91 momentumGeneration='fixed',
92 momentumParams=0.5,
93 thetaGeneration='fixed',
94 thetaParams=95,
95 phiGeneration='fixed',
96 phiParams=30)
97
98
99# generates a photon which characteristics are chosen that it would be a bremsstrahlung photon radiated by the electron
100main.add_module('ParticleGun',
101 pdgCodes=[22],
102 nTracks=1,
103 momentumGeneration='fixed',
104 momentumParams=0.1,
105 thetaGeneration='fixed',
106 thetaParams=1.6614126908216453 * 180 / 3.1415,
107 phiGeneration='fixed',
108 phiParams=0.6210485691762964 * 180 / 3.1415,
109 xVertexParams=[9.27695426703659],
110 yVertexParams=[5.949838410158973],
111 zVertexParams=[-0.9875516764256207],
112 )
113
115
117
118main.add_module(CheckRelationBremClusterTestModule())
119
120# Process events
121b2.process(main)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
def add_reconstruction(path, components=None, pruneTracks=True, add_trigger_calculation=True, skipGeometryAdding=False, trackFitHypotheses=None, addClusterExpertModules=True, use_second_cdc_hits=False, add_muid_hits=False, reconstruct_cdst=None, event_abort=default_event_abort, use_random_numbers_for_hlt_prescale=True, pxd_filtering_offline=False, create_intercepts_for_pxd_ckf=False, append_full_grid_cdc_eventt0=True, legacy_ecl_charged_pid=False, emulate_HLT=False, skip_full_grid_cdc_eventt0_if_svd_time_present=True)
def add_simulation(path, components=None, bkgfiles=None, bkgOverlay=True, forceSetPXDDataReduction=False, usePXDDataReduction=True, cleanupPXDDataReduction=True, generate_2nd_cdc_hits=False, simulateT0jitter=True, isCosmics=False, FilterEvents=False, usePXDGatedMode=False, skipExperimentCheckForBG=False, save_slow_pions_in_mc=False)
Definition: simulation.py:126