11from ROOT
import Belle2
18 from scipy.special
import erf
25 erf_ufunc = np.frompyfunc(math.erf, 1, 1)
28 result = erf_ufunc(*args)
29 return np.asfarray(result)
36prob = np.frompyfunc(ROOT.TMath.Prob, 2, 1)
39def is_primary(mc_particle):
40 """Indicates if the given MCParticle is primary.
45 MCParticle to be checked"""
47 return mc_particle.hasStatus(Belle2.MCParticle.c_PrimaryParticle)
50def is_stable_in_generator(mc_particle):
51 """Indicates if the given MCParticle is stable in the generator
56 MCParticle to be checked"""
58 return mc_particle.hasStatus(Belle2.MCParticle.c_StableInGenerator)
61def getObjectList(pointerVec):
62 """ This is a temporary work-around for the new externals v01-10-00
63 A direct iteration on a vector of pointers creates significant memory leak
64 This can be avoid by a range based loop
68 pointerVec : pointerVec
72 for i
in range(len(pointerVec)):
73 objList.append(pointerVec[i])
77def get_det_hit_ids(reco_track, det_ids=[Belle2.Const.PXD, Belle2.Const.SVD, Belle2.Const.CDC]):
78 """Retrieves the hit ids contained in the track for the given detector ids
82 reco_track : RecoTrack
85 List of the detector ids for which the hit ids should be retrieved
90 A set of pairs like (det_id, hit_id) representing the hit content of the track
93 for det_id
in det_ids:
94 if det_id == Belle2.Const.CDC:
95 hits = getObjectList(reco_track.getCDCHitList())
96 elif det_id == Belle2.Const.SVD:
97 hits = getObjectList(reco_track.getSVDHitList())
98 elif det_id == Belle2.Const.PXD:
99 hits = getObjectList(reco_track.getPXDHitList())
101 raise ValueError(
"DET ID not known.")
105 det_hit_ids |= {(det_id, hit.getArrayIndex())
for hit
in hits}
110def calc_ndf_from_det_hit_ids(det_hit_ids,
111 ndf_by_det_id={Belle2.Const.PXD: 2,
113 Belle2.Const.CDC: 1}):
114 """For a set of detector and hit ids calculate the total number of degrees of freedom
118 det_hit_ids : set( (int, int) )
119 A set of pairs like (det_id, hit_id) representing the hit content of a track
120 ndf_by_det_ids : dict(int=int)
121 A map from detector ids to the number of degrees of freedom one hit
in this detector represents.
126 Total number of degrees of freedom represented by the hit set
128 return sum(ndf_by_det_id[det_id]
for det_id, hit_id
in det_hit_ids)
131def calc_hit_efficiency(det_hit_ids,
133 ndf_by_det_id={Belle2.Const.PXD: 2,
135 Belle2.Const.CDC: 1}):
136 """Calculates the fraction of detector and hits ids in a reference (MC) set that are also
137 present in a reconstructed (PR) set.
139 The ratio
is given
in terms of degrees of freedom the hits represent
143 det_hit_ids : set( (int, int) )
144 A set of pairs like (det_id, hit_id) representing the hit content of a reconstructed (PR) track
145 mc_det_hit_ids : set( (int, int) )
146 A set of pairs like (det_id, hit_id) representing the hit content of a reference (MC) track
147 ndf_by_det_ids : dict(int=int)
148 A map
from detector ids to the number of degrees of freedom one hit
in this detector represents.
153 Fraction of hits
in the reference (MC) track that are also present
in the reconstructed (PR) track
154 in terms of number of degrees of freedom.
156 common_det_hit_ids = det_hit_ids & mc_det_hit_ids
157 return np.divide(1.0 * calc_ndf_from_det_hit_ids(common_det_hit_ids),
158 calc_ndf_from_det_hit_ids(mc_det_hit_ids))
161def getHelixFromMCParticle(mc_particle):
162 position = mc_particle.getVertex()
163 momentum = mc_particle.getMomentum()
164 charge_sign = (-1
if mc_particle.getCharge() < 0
else 1)
167 seed_helix =
Belle2.Helix(position, momentum, charge_sign, b_field)
171def getSeedTrackFitResult(reco_track):
172 position = reco_track.getPositionSeed()
173 momentum = reco_track.getMomentumSeed()
174 cartesian_covariance = reco_track.getSeedCovariance()
175 charge_sign = (-1
if reco_track.getChargeSeed() < 0
else 1)
177 particle_type = Belle2.Const.pion
178 p_value = float(
'nan')
188 cartesian_covariance,
198 return track_fit_result
A Class to store the Monte Carlo particle information.
Values of the result of a track fit with a given particle hypothesis.
static void getField(const double *pos, double *field)
return the magnetic field at a given position.