Belle II Software development
Belle2::KlongId Namespace Reference

Helper functions for all klid modules to improve readability of the code. More...

Functions

int BelleTrackFlag (const Belle2::KLMCluster &cluster, const float angle=0.26)
 get Belle stle track flag
 
int BelleECLFlag (const Belle2::KLMCluster &cluster, const float angle=0.26)
 get Belle stle ECL flag
 
int mcParticleIsBeamBKG (const Belle2::MCParticle *part)
 return if MCparticle is beambkg
 
int mcParticleIsKlong (Belle2::MCParticle *part)
 return the mc hirachy of the klong 0:not a klong 1:final particle, 2: klong is mother etc
 
bool isKLMClusterSignal (const Belle2::KLMCluster &cluster, float mcWeigthCut=0.66)
 checks if a cluster is signal under the mcWeightcondition (mcWeight = energy deposition)
 
bool isECLClusterSignal (const Belle2::ECLCluster &cluster, float mcWeigthCut=0.66)
 checks if a cluster is signal under the mcWeightcondition (mcWeight = energy deposition)
 
int isMCParticlePDG (Belle2::MCParticle *part, int pdg)
 return if mc particle has a certain pdg in the decay chain
 
int getPrimaryPDG (Belle2::MCParticle *part)
 return if mc particles primary pdg.
 
std::pair< Belle2::ECLCluster *, double > findClosestECLCluster (const ROOT::Math::XYZVector &klmClusterPosition, const Belle2::ECLCluster::EHypothesisBit eclhypothesis=Belle2::ECLCluster::EHypothesisBit::c_neutralHadron)
 Find the closest ECLCluster with a neutral hadron hypothesis, and return it with its distance.
 
std::tuple< const Belle2::KLMCluster *, double, double > findClosestKLMCluster (const ROOT::Math::XYZVector &klmClusterPosition)
 find nearest KLMCluster, tis distance and the av intercluster distance
 
std::tuple< Belle2::RecoTrack *, double, std::unique_ptr< const ROOT::Math::XYZVector > > findClosestTrack (const ROOT::Math::XYZVector &clusterPosition, float cutAngle)
 find nearest genfit track and return it and its distance

 

Detailed Description

Helper functions for all klid modules to improve readability of the code.

Function Documentation

◆ BelleECLFlag()

int BelleECLFlag ( const Belle2::KLMCluster cluster,
const float  angle = 0.26 
)

get Belle stle ECL flag

Definition at line 49 of file KlId.h.

50 {
51 const ROOT::Math::XYZVector& pos = cluster.getClusterPosition();
53
54 for (const Belle2::ECLCluster& eclcluster : eclclusters) {
55
56 const ROOT::Math::XYZVector& clusterPos = eclcluster.getClusterPosition();
57
58 double clusterAngle = ROOT::Math::VectorUtil::Angle(clusterPos, pos);
59 if (clusterAngle < angle) {
60 B2DEBUG(20, "BelleFlagECLAngle::" << clusterAngle);
61 return 1;
62 }
63 }
64 return 0;
65 }
ECL cluster data.
Definition: ECLCluster.h:27
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113

◆ BelleTrackFlag()

int BelleTrackFlag ( const Belle2::KLMCluster cluster,
const float  angle = 0.26 
)

get Belle stle track flag

Definition at line 30 of file KlId.h.

31 {
32 const ROOT::Math::XYZVector& pos = cluster.getClusterPosition();
33
35 for (const Belle2::TrackFitResult& track : tracks) {
36 const ROOT::Math::XYZVector& trackPos = track.getPosition();
37
38 double trackAngle = ROOT::Math::VectorUtil::Angle(trackPos, pos);
39 if (trackAngle < angle) {
40 B2DEBUG(20, "BelleFlagTracklAngle::" << trackAngle);
41 return 1;
42 }
43 }
44 return 0;
45 }
Values of the result of a track fit with a given particle hypothesis.

◆ findClosestECLCluster()

std::pair< Belle2::ECLCluster *, double > findClosestECLCluster ( const ROOT::Math::XYZVector &  klmClusterPosition,
const Belle2::ECLCluster::EHypothesisBit  eclhypothesis = Belle2::ECLCluster::EHypothesisBit::c_neutralHadron 
)

Find the closest ECLCluster with a neutral hadron hypothesis, and return it with its distance.

If there are no suitabile ECLClusters, a nullptr is returned.

Definition at line 203 of file KlId.h.

205 {
206
207 Belle2::ECLCluster* closestECL = nullptr;
208 double closestECLAngleDist = 1e10;
210
211 if (eclClusters.getEntries() > 0) {
212 int index = 0;
213 int indexOfClosestCluster = -1;
214 for (Belle2::ECLCluster& eclcluster : eclClusters) {
215
216 if (eclcluster.hasHypothesis(eclhypothesis)) {
217
218 const ROOT::Math::XYZVector& eclclusterPos = eclcluster.getClusterPosition();
219 double angularDist = ROOT::Math::VectorUtil::Angle(
220 eclclusterPos, klmClusterPosition);
221 if (angularDist < closestECLAngleDist) {
222 closestECLAngleDist = angularDist;
223 indexOfClosestCluster = index;
224 }
225 }
226 ++index;
227 }
228 if (indexOfClosestCluster > -1)
229 closestECL = eclClusters[indexOfClosestCluster];
230 }
231 return std::make_pair(closestECL, closestECLAngleDist);
232 }
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216

◆ findClosestKLMCluster()

std::tuple< const Belle2::KLMCluster *, double, double > findClosestKLMCluster ( const ROOT::Math::XYZVector &  klmClusterPosition)

find nearest KLMCluster, tis distance and the av intercluster distance

Definition at line 236 of file KlId.h.

237 {
238
240 const Belle2::KLMCluster* closestKLM = nullptr;
241 double closestKLMDist = 1e10;
242 double avInterClusterDist = 0;
243 double nKLMCluster = klmClusters.getEntries();
244
245 if (nKLMCluster > 1) {
246
247 unsigned int index = 0;
248 unsigned int indexOfClosestCluster = 0;
249 for (const Belle2::KLMCluster& nextCluster : klmClusters) {
250
251 const ROOT::Math::XYZVector& nextClusterPos = nextCluster.getClusterPosition();
252 const ROOT::Math::XYZVector& clustDistanceVec = nextClusterPos - klmClusterPosition;
253
254 double nextClusterDist = clustDistanceVec.Mag2();
255 avInterClusterDist = avInterClusterDist + nextClusterDist;
256
257 if ((nextClusterDist < closestKLMDist) and not(nextClusterDist == 0)) {
258 closestKLMDist = nextClusterDist ;
259 indexOfClosestCluster = index;
260 }
261 ++index;
262 }// for next_cluster
263
264 closestKLM = klmClusters[indexOfClosestCluster];
265 avInterClusterDist = avInterClusterDist / (1. * nKLMCluster);
266 }
267
268 return std::make_tuple(closestKLM, closestKLMDist, avInterClusterDist);
269 }
KLM cluster data.
Definition: KLMCluster.h:28

◆ findClosestTrack()

std::tuple< Belle2::RecoTrack *, double, std::unique_ptr< const ROOT::Math::XYZVector > > findClosestTrack ( const ROOT::Math::XYZVector &  clusterPosition,
float  cutAngle 
)

find nearest genfit track and return it and its distance

Definition at line 273 of file KlId.h.

276 {
278 double oldDistance = 10000000;//dont wanna use infty cos that kills tmva...
279 Belle2::RecoTrack* closestTrack = nullptr;
280 ROOT::Math::XYZVector poca = ROOT::Math::XYZVector(0, 0, 0);
281
282
283 for (Belle2::RecoTrack& track : genfitTracks) {
284
285 try {
286 genfit::MeasuredStateOnPlane state;
287 genfit::MeasuredStateOnPlane state_for_cut;
288 state_for_cut = track.getMeasuredStateOnPlaneFromFirstHit();
289
290 // only use tracks that are close cos the extrapolation takes ages
291 double angle = ROOT::Math::VectorUtil::Angle(clusterPosition, state_for_cut.getPos());
292 if (angle < cutAngle) {
293 state = track.getMeasuredStateOnPlaneFromLastHit();
294 state.extrapolateToPoint(XYZToTVector(clusterPosition));
295 const ROOT::Math::XYZVector& trackPos = ROOT::Math::XYZVector(state.getPos());
296
297 const ROOT::Math::XYZVector& distanceVecCluster = clusterPosition - trackPos;
298 double newDistance = distanceVecCluster.Mag2();
299
300 // overwrite old distance
301 if (newDistance < oldDistance) {
302 oldDistance = newDistance;
303 closestTrack = &track;
304 poca = trackPos;
305 }
306 }
307 } catch (genfit::Exception& e) {
308 }// try
309 }// for gftrack
310
311 if (not closestTrack) {
312 return std::make_tuple(nullptr, oldDistance, std::unique_ptr<const ROOT::Math::XYZVector>(nullptr));
313 } else {
314 // actually this is fine because of the datastore
315 // cppcheck-suppress returnDanglingLifetime
316 return std::make_tuple(closestTrack, oldDistance, std::unique_ptr<const ROOT::Math::XYZVector>(new ROOT::Math::XYZVector(poca)));
317 }
318 }
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79

◆ getPrimaryPDG()

int getPrimaryPDG ( Belle2::MCParticle part)

return if mc particles primary pdg.

this is very imprecise but sufficient to understand if the backgrounds are charged, hadronic or gammas which is whats relevant for klid investigations.

Definition at line 151 of file KlId.h.

152 {
153
154 if (mcParticleIsBeamBKG(part)) {
155 return -999;
156 }
157
158 bool stop = false;
159 while (!stop) {
160 if (isMCParticlePDG(part, Const::Klong.getPDGCode())) {
161 return Const::Klong.getPDGCode();
162 }
163 if (isMCParticlePDG(part, Const::Kshort.getPDGCode())) {
164 return Const::Kshort.getPDGCode();
165 }
166 if (isMCParticlePDG(part, Const::kaon.getPDGCode())) {
167 return Const::kaon.getPDGCode();
168 }
169 if (isMCParticlePDG(part, Const::neutron.getPDGCode())) {
170 return Const::neutron.getPDGCode();
171 }
172 if (isMCParticlePDG(part, Const::proton.getPDGCode())) {
173 return Const::proton.getPDGCode();
174 }
175 if (isMCParticlePDG(part, Const::pion.getPDGCode())) {
176 return Const::pion.getPDGCode();
177 }
178 if (isMCParticlePDG(part, Const::pi0.getPDGCode())) {
179 return Const::pi0.getPDGCode();
180 }
181 if (isMCParticlePDG(part, Const::muon.getPDGCode())) {
182 return Const::muon.getPDGCode();
183 }
184 if (isMCParticlePDG(part, Const::electron.getPDGCode())) {
185 return Const::electron.getPDGCode();
186 }
187 if (isMCParticlePDG(part, Const::photon.getPDGCode())) {
188 return Const::photon.getPDGCode();
189 }
190 if ((part -> getMother() == nullptr)) {
191 stop = true;
192 } else {
193 part = part -> getMother();
194 }
195 }
196 return part ->getPDG();
197 }
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:112
int mcParticleIsBeamBKG(const Belle2::MCParticle *part)
return if MCparticle is beambkg
Definition: KlId.h:68
int isMCParticlePDG(Belle2::MCParticle *part, int pdg)
return if mc particle has a certain pdg in the decay chain
Definition: KlId.h:128

◆ isECLClusterSignal()

bool isECLClusterSignal ( const Belle2::ECLCluster cluster,
float  mcWeigthCut = 0.66 
)

checks if a cluster is signal under the mcWeightcondition (mcWeight = energy deposition)

Definition at line 114 of file KlId.h.

115 {
116 const auto mcParticleWeightPair = cluster.getRelatedToWithWeight<Belle2::MCParticle>();
117 Belle2::MCParticle* part = mcParticleWeightPair.first;
118 if (!part) {return false; }
119 float mcWeight = mcParticleWeightPair.second;
120 if (mcParticleIsKlong(part) && (mcWeight > mcWeigthCut)) {
121 return true;
122 } else {
123 return false;
124 }
125 }
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32

◆ isKLMClusterSignal()

bool isKLMClusterSignal ( const Belle2::KLMCluster cluster,
float  mcWeigthCut = 0.66 
)

checks if a cluster is signal under the mcWeightcondition (mcWeight = energy deposition)

Definition at line 100 of file KlId.h.

101 {
102 const auto mcParticleWeightPair = cluster.getRelatedToWithWeight<Belle2::MCParticle>();
103 Belle2::MCParticle* part = mcParticleWeightPair.first;
104 if (!part) {return false; }
105 float mcWeight = mcParticleWeightPair.second;
106 if (mcParticleIsKlong(part) && (mcWeight > mcWeigthCut)) {
107 return true;
108 } else {
109 return false;
110 }
111 }

◆ isMCParticlePDG()

int isMCParticlePDG ( Belle2::MCParticle part,
int  pdg 
)

return if mc particle has a certain pdg in the decay chain

Definition at line 128 of file KlId.h.

129 {
130 bool stop = false;
131 while (!stop) {
132 if (std::abs(part -> getPDG()) == pdg) {
133 return true;
134 }
135 if ((part -> getMother() == nullptr)) {
136 stop = true;
137 } else {
138 part = part -> getMother();
139 }
140 }
141 return false;
142 }

◆ mcParticleIsBeamBKG()

int mcParticleIsBeamBKG ( const Belle2::MCParticle part)

return if MCparticle is beambkg

Definition at line 68 of file KlId.h.

69 {
70 if (part == nullptr) {
71 return 1;
72 } else {
73 return 0;
74 }
75 }

◆ mcParticleIsKlong()

int mcParticleIsKlong ( Belle2::MCParticle part)

return the mc hirachy of the klong 0:not a klong 1:final particle, 2: klong is mother etc

Definition at line 78 of file KlId.h.

79 {
80 unsigned int hirachy_counter = 0;
81 if (mcParticleIsBeamBKG(part)) {
82 return 0;
83 }
84 bool stop = false;
85 while (!stop) {
86 ++hirachy_counter;
87 if (part -> getPDG() == Const::Klong.getPDGCode()) {
88 return hirachy_counter;
89 }
90 if ((part -> getMother() == nullptr)) {
91 stop = true;
92 } else {
93 part = part -> getMother();
94 }
95 }
96 return 0;
97 }