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