3 from ROOT
import Belle2
11 from scipy.special
import erf
18 erf_ufunc = np.frompyfunc(math.erf, 1, 1)
21 result = erf_ufunc(*args)
22 return np.asfarray(result)
29 prob = np.frompyfunc(ROOT.TMath.Prob, 2, 1)
32 def is_primary(mc_particle):
33 """Indicates if the given MCParticle is primary.
37 mc_particle : Belle2.MCParticle
38 MCParticle to be checked"""
40 return mc_particle.hasStatus(Belle2.MCParticle.c_PrimaryParticle)
43 def is_stable_in_generator(mc_particle):
44 """Indicates if the given MCParticle is stable in the generator
48 mc_particle : Belle2.MCParticle
49 MCParticle to be checked"""
51 return mc_particle.hasStatus(Belle2.MCParticle.c_StableInGenerator)
54 def get_det_hit_ids(reco_track, det_ids=[Belle2.Const.PXD, Belle2.Const.SVD, Belle2.Const.CDC]):
55 """Retrieves the hit ids contained in the track for the given detector ids
59 reco_track : RecoTrack
62 List of the detector ids for which the hit ids should be retrieved
67 A set of pairs like (det_id, hit_id) representing the hit content of the track
70 for det_id
in det_ids:
71 if det_id == Belle2.Const.CDC:
72 hits = reco_track.getCDCHitList()
73 elif det_id == Belle2.Const.SVD:
74 hits = reco_track.getSVDHitList()
75 elif det_id == Belle2.Const.PXD:
76 hits = reco_track.getPXDHitList()
78 raise ValueError(
"DET ID not known.")
82 det_hit_ids |= set((det_id, hit.getArrayIndex())
for hit
in hits)
87 def calc_ndf_from_det_hit_ids(det_hit_ids,
88 ndf_by_det_id={Belle2.Const.PXD: 2,
90 Belle2.Const.CDC: 1}):
91 """For a set of detector and hit ids calculate the total number of degrees of freedom
95 det_hit_ids : set( (int, int) )
96 A set of pairs like (det_id, hit_id) representing the hit content of a track
97 ndf_by_det_ids : dict(int=int)
98 A map from detector ids to the number of degrees of freedom one hit in this detector represents.
103 Total number of degrees of freedom represented by the hit set
105 return sum(ndf_by_det_id[det_id]
for det_id, hit_id
in det_hit_ids)
108 def calc_hit_efficiency(det_hit_ids,
110 ndf_by_det_id={Belle2.Const.PXD: 2,
112 Belle2.Const.CDC: 1}):
113 """Calculates the fraction of detector and hits ids in a reference (MC) set that are also
114 present in a reconstructed (PR) set.
116 The ratio is given in terms of degrees of freedom the hits represent
120 det_hit_ids : set( (int, int) )
121 A set of pairs like (det_id, hit_id) representing the hit content of a reconstructed (PR) track
122 mc_det_hit_ids : set( (int, int) )
123 A set of pairs like (det_id, hit_id) representing the hit content of a reference (MC) track
124 ndf_by_det_ids : dict(int=int)
125 A map from detector ids to the number of degrees of freedom one hit in this detector represents.
130 Fraction of hits in the reference (MC) track that are also present in the reconstructed (PR) track
131 in terms of number of degrees of freedom.
133 common_det_hit_ids = det_hit_ids & mc_det_hit_ids
134 return np.divide(1.0 * calc_ndf_from_det_hit_ids(common_det_hit_ids),
135 calc_ndf_from_det_hit_ids(mc_det_hit_ids))
138 def getHelixFromMCParticle(mc_particle):
139 position = mc_particle.getVertex()
140 momentum = mc_particle.getMomentum()
141 charge_sign = (-1
if mc_particle.getCharge() < 0
else 1)
144 seed_helix =
Belle2.Helix(position, momentum, charge_sign, b_field)
148 def getSeedTrackFitResult(reco_track):
149 position = reco_track.getPositionSeed()
150 momentum = reco_track.getMomentumSeed()
151 cartesian_covariance = reco_track.getSeedCovariance()
152 charge_sign = (-1
if reco_track.getChargeSeed() < 0
else 1)
154 particle_type = Belle2.Const.pion
155 p_value = float(
'nan')
165 cartesian_covariance,
175 return track_fit_result