Belle II Software development
utilities.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <analysis/dataobjects/ParticleList.h>
11
12#include <mdst/dataobjects/ECLCluster.h>
13#include <tracking/dataobjects/RecoTrack.h>
14
15#include <analysis/utility/PCmsLabTransform.h>
16#include <analysis/ClusterUtility/ClusterUtils.h>
17
18namespace Belle2 {
23 namespace SoftwareTrigger {
25 template<class T>
26 inline ROOT::Math::PxPyPzEVector getFourVector(const T& item);
27
29 template<>
30 inline ROOT::Math::PxPyPzEVector getFourVector(const std::reference_wrapper<const ECLCluster>& cluster)
31 {
32 ClusterUtils C;
33 const ROOT::Math::PxPyPzEVector& v = C.Get4MomentumFromCluster(&(cluster.get()), ECLCluster::EHypothesisBit::c_nPhotons);
34 return ROOT::Math::PxPyPzEVector(v.Px(), v.Py(), v.Pz(), v.E());
35 }
36
38 template<>
39 inline ROOT::Math::PxPyPzEVector getFourVector(const RecoTrack& track)
40 {
41 const ROOT::Math::XYZVector& positionSeed = track.getPositionSeed();
42 return ROOT::Math::PxPyPzEVector(positionSeed.X(), positionSeed.Y(), positionSeed.Z(),
43 sqrt(positionSeed.Mag2() + Const::pionMass * Const::pionMass));
44 }
45
47 template<class AnEntityType>
48 inline const AnEntityType* getElementFromParticle(const Particle& particle);
49
51 template<>
52 inline const Particle* getElementFromParticle(const Particle& particle)
53 {
54 return &particle;
55 }
56
58 template<>
59 inline const ECLCluster* getElementFromParticle(const Particle& particle)
60 {
61 return particle.getECLCluster();
62 }
63
65 inline double BeamEnergyCMS()
66 {
67 PCmsLabTransform T;
68 return T.getCMSEnergy() / 2.0;
69 }
70
72 template<class AnEntity>
73 inline double getRho(const AnEntity* entity)
74 {
75 if (not entity) {
76 return -1;
77 }
78
79 const ROOT::Math::PxPyPzEVector& fourVector = entity->get4Vector();
80 return PCmsLabTransform::labToCms(fourVector).P();
81 }
82
83 // Template specialization for ECLCluster
84 template<>
85 inline double getRho(const ECLCluster* entity)
86 {
87 if (not entity) {
88 return -1;
89 }
90
91 ClusterUtils C;
92 return PCmsLabTransform::labToCms(C.Get4MomentumFromCluster(entity, ECLCluster::EHypothesisBit::c_nPhotons)).P();
93 }
94
99 template<class AReturnType>
100 static const AReturnType* getElementWithMaximumRhoBelow(const StoreObjPtr<ParticleList>& particles,
101 const double belowLimit)
102 {
103 const AReturnType* elementMaximumRho = nullptr;
104 double maximumRho = -1.;
105 for (const Particle& currentParticle : *particles) {
106 const auto currentElement = getElementFromParticle<AReturnType>(currentParticle);
107 const double& currentRho = getRho(currentElement);
108 if (currentRho >= belowLimit) {
109 continue;
110 }
111 if (currentRho > maximumRho) {
112 maximumRho = currentRho;
113 elementMaximumRho = currentElement;
114 }
115 }
116 return elementMaximumRho;
117 }
118
120 template<class AReturnType>
121 inline const AReturnType* getElementWithMaximumRho(const StoreObjPtr<ParticleList>& particles)
122 {
123 return getElementWithMaximumRhoBelow<AReturnType>(particles, std::nan(""));
124 }
125
126 extern double getRhoOfECLClusterWithMaximumRhoBelow(const StoreObjPtr<ParticleList>& pions,
127 const StoreObjPtr<ParticleList>& gammas,
128 const double belowLimit);
129
131 inline double getRhoOfECLClusterWithMaximumRho(const StoreObjPtr<ParticleList>& pionshlt,
132 const StoreObjPtr<ParticleList>& gammahlt)
133 {
134 return getRhoOfECLClusterWithMaximumRhoBelow(pionshlt, gammahlt, std::nan(""));
135 }
136 }
138}
static const double pionMass
charged pion mass
Definition: Const.h:687
@ c_nPhotons
CR is split into n photons (N1)
static ROOT::Math::PxPyPzMVector labToCms(const ROOT::Math::PxPyPzMVector &vec)
Transforms Lorentz vector into CM System.
GeneralVector< T > getFourVector(T energy, T angleX, T angleY, bool isHER)
get 4-momentum from energy and angles of beam
Definition: beamHelpers.h:220
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.