11#include <framework/datastore/StoreArray.h>
12#include <mdst/dataobjects/MCParticle.h>
13#include <mdst/dataobjects/KLMCluster.h>
14#include <mdst/dataobjects/ECLCluster.h>
15#include <mdst/dataobjects/TrackFitResult.h>
17#include <framework/gearbox/Const.h>
18#include <framework/geometry/VectorUtil.h>
19#include <framework/logging/Logger.h>
20#include <tracking/dataobjects/RecoTrack.h>
21#include <genfit/Exception.h>
24#include <Math/VectorUtil.h>
32 const ROOT::Math::XYZVector& pos = cluster.getClusterPosition();
36 const ROOT::Math::XYZVector& trackPos = track.getPosition();
38 double trackAngle = ROOT::Math::VectorUtil::Angle(trackPos, pos);
39 if (trackAngle < angle) {
40 B2DEBUG(20,
"BelleFlagTracklAngle::" << trackAngle);
51 const ROOT::Math::XYZVector& pos = cluster.getClusterPosition();
56 const ROOT::Math::XYZVector& clusterPos = eclcluster.getClusterPosition();
58 double clusterAngle = ROOT::Math::VectorUtil::Angle(clusterPos, pos);
59 if (clusterAngle < angle) {
60 B2DEBUG(20,
"BelleFlagECLAngle::" << clusterAngle);
70 if (part ==
nullptr) {
80 unsigned int hirachy_counter = 0;
88 return hirachy_counter;
90 if ((part -> getMother() ==
nullptr)) {
93 part = part -> getMother();
102 const auto mcParticleWeightPair = cluster.getRelatedToWithWeight<
Belle2::MCParticle>();
104 if (!part) {
return false; }
105 float mcWeight = mcParticleWeightPair.second;
116 const auto mcParticleWeightPair = cluster.getRelatedToWithWeight<
Belle2::MCParticle>();
118 if (!part) {
return false; }
119 float mcWeight = mcParticleWeightPair.second;
132 if (std::abs(part -> getPDG()) == pdg) {
135 if ((part -> getMother() ==
nullptr)) {
138 part = part -> getMother();
190 if ((part -> getMother() ==
nullptr)) {
193 part = part -> getMother();
208 double closestECLAngleDist = 1e10;
213 int indexOfClosestCluster = -1;
216 if (eclcluster.hasHypothesis(eclhypothesis)) {
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;
228 if (indexOfClosestCluster > -1)
229 closestECL = eclClusters[indexOfClosestCluster];
231 return std::make_pair(closestECL, closestECLAngleDist);
236 std::tuple<const Belle2::KLMCluster*, double, double>
findClosestKLMCluster(
const ROOT::Math::XYZVector& klmClusterPosition)
241 double closestKLMDist = 1e10;
242 double avInterClusterDist = 0;
243 double nKLMCluster = klmClusters.
getEntries();
245 if (nKLMCluster > 1) {
247 unsigned int index = 0;
248 unsigned int indexOfClosestCluster = 0;
251 const ROOT::Math::XYZVector& nextClusterPos = nextCluster.getClusterPosition();
252 const ROOT::Math::XYZVector& clustDistanceVec = nextClusterPos - klmClusterPosition;
254 double nextClusterDist = clustDistanceVec.Mag2();
255 avInterClusterDist = avInterClusterDist + nextClusterDist;
257 if ((nextClusterDist < closestKLMDist) and not(nextClusterDist == 0)) {
258 closestKLMDist = nextClusterDist ;
259 indexOfClosestCluster = index;
264 closestKLM = klmClusters[indexOfClosestCluster];
265 avInterClusterDist = avInterClusterDist / (1. * nKLMCluster);
268 return std::make_tuple(closestKLM, closestKLMDist, avInterClusterDist);
273 std::tuple<Belle2::RecoTrack*, double, std::unique_ptr<const ROOT::Math::XYZVector> >
findClosestTrack(
274 const ROOT::Math::XYZVector& clusterPosition,
278 double oldDistance = 10000000;
280 ROOT::Math::XYZVector poca = ROOT::Math::XYZVector(0, 0, 0);
286 genfit::MeasuredStateOnPlane state;
287 genfit::MeasuredStateOnPlane state_for_cut;
288 state_for_cut = track.getMeasuredStateOnPlaneFromFirstHit();
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());
297 const ROOT::Math::XYZVector& distanceVecCluster = clusterPosition - trackPos;
298 double newDistance = distanceVecCluster.Mag2();
301 if (newDistance < oldDistance) {
302 oldDistance = newDistance;
303 closestTrack = &track;
307 }
catch (genfit::Exception& e) {
311 if (not closestTrack) {
312 return std::make_tuple(
nullptr, oldDistance, std::unique_ptr<const ROOT::Math::XYZVector>(
nullptr));
316 return std::make_tuple(closestTrack, oldDistance, std::unique_ptr<const ROOT::Math::XYZVector>(
new ROOT::Math::XYZVector(poca)));
int getPDGCode() const
PDG code.
static const ParticleType neutron
neutron particle
static const ParticleType pi0
neutral pion particle
static const ChargedStable muon
muon particle
static const ChargedStable pion
charged pion particle
static const ParticleType Klong
K^0_L particle.
static const ChargedStable proton
proton particle
static const ParticleType Kshort
K^0_S particle.
static const ChargedStable kaon
charged kaon particle
static const ParticleType photon
photon particle
static const ChargedStable electron
electron particle
EHypothesisBit
The hypothesis bits for this ECLCluster (Connected region (CR) is split using this hypothesis.
@ c_neutralHadron
CR is reconstructed as a neutral hadron (N2)
A Class to store the Monte Carlo particle information.
int getPDG() const
Return PDG code of particle.
This is the Reconstruction Event-Data Model Track.
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
Values of the result of a track fit with a given particle hypothesis.
static constexpr auto XYZToTVector
Helper function to convert XYZVector to TVector3.
Helper functions for all klid modules to improve readability of the code.
bool isKLMClusterSignal(const Belle2::KLMCluster &cluster, float mcWeigthCut=0.66)
checks if a cluster is signal under the mcWeightcondition (mcWeight = energy deposition)
int BelleECLFlag(const Belle2::KLMCluster &cluster, const float angle=0.26)
get Belle stle ECL flag
int BelleTrackFlag(const Belle2::KLMCluster &cluster, const float angle=0.26)
get Belle stle track flag
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
int mcParticleIsBeamBKG(const Belle2::MCParticle *part)
return if MCparticle is beambkg
std::tuple< const Belle2::KLMCluster *, double, double > findClosestKLMCluster(const ROOT::Math::XYZVector &klmClusterPosition)
find nearest KLMCluster, tis distance and the av intercluster distance
int isMCParticlePDG(Belle2::MCParticle *part, int pdg)
return if mc particle has a certain pdg in the decay chain
bool isECLClusterSignal(const Belle2::ECLCluster &cluster, float mcWeigthCut=0.66)
checks if a cluster is signal under the mcWeightcondition (mcWeight = energy deposition)
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.
int getPrimaryPDG(Belle2::MCParticle *part)
return if mc particles primary pdg.
int mcParticleIsKlong(Belle2::MCParticle *part)
return the mc hirachy of the klong 0:not a klong 1:final particle, 2: klong is mother etc