Belle II Software  release-06-01-15
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 #include <TLorentzVector.h>
18 
19 namespace Belle2 {
24  namespace SoftwareTrigger {
26  template<class T>
27  inline TLorentzVector getFourVector(const T& item);
28 
30  template<>
31  inline TLorentzVector getFourVector(const std::reference_wrapper<const ECLCluster>& cluster)
32  {
33  ClusterUtils C;
34  const TLorentzVector& v = C.Get4MomentumFromCluster(&(cluster.get()), ECLCluster::EHypothesisBit::c_nPhotons);
35  return TLorentzVector(v.Px(), v.Py(), v.Pz(), v.E());
36  }
37 
39  template<>
40  inline TLorentzVector getFourVector(const RecoTrack& track)
41  {
42  const TVector3& positionSeed = track.getPositionSeed();
43  return TLorentzVector(positionSeed.X(), positionSeed.Y(), positionSeed.Z(),
44  sqrt(positionSeed.Mag2() + Const::pionMass * Const::pionMass));
45  }
46 
48  template<class AnEntityType>
49  inline const AnEntityType* getElementFromParticle(const Particle& particle);
50 
52  template<>
53  inline const Particle* getElementFromParticle(const Particle& particle)
54  {
55  return &particle;
56  }
57 
59  template<>
60  inline const ECLCluster* getElementFromParticle(const Particle& particle)
61  {
62  return particle.getECLCluster();
63  }
64 
66  inline double BeamEnergyCMS()
67  {
68  PCmsLabTransform T;
69  return T.getCMSEnergy() / 2.0;
70  }
71 
73  template<class AnEntity>
74  inline double getRho(const AnEntity* entity)
75  {
76  if (not entity) {
77  return -1;
78  }
79 
80  const TLorentzVector& fourVector = entity->get4Vector();
81  return PCmsLabTransform::labToCms(fourVector).Rho();
82  }
83 
84  // Template specialization for ECLCluster
85  template<>
86  inline double getRho(const ECLCluster* entity)
87  {
88  if (not entity) {
89  return -1;
90  }
91 
92  ClusterUtils C;
93  return PCmsLabTransform::labToCms(C.Get4MomentumFromCluster(entity, ECLCluster::EHypothesisBit::c_nPhotons)).Rho();
94  }
95 
100  template<class AReturnType>
101  static const AReturnType* getElementWithMaximumRhoBelow(const StoreObjPtr<ParticleList>& particles,
102  const double belowLimit)
103  {
104  const AReturnType* elementMaximumRho = nullptr;
105  double maximumRho = -1.;
106  for (const Particle& currentParticle : *particles) {
107  const auto currentElement = getElementFromParticle<AReturnType>(currentParticle);
108  const double& currentRho = getRho(currentElement);
109  if (currentRho >= belowLimit) {
110  continue;
111  }
112  if (currentRho > maximumRho) {
113  maximumRho = currentRho;
114  elementMaximumRho = currentElement;
115  }
116  }
117  return elementMaximumRho;
118  }
119 
121  template<class AReturnType>
122  inline const AReturnType* getElementWithMaximumRho(const StoreObjPtr<ParticleList>& particles)
123  {
124  return getElementWithMaximumRhoBelow<AReturnType>(particles, std::nan(""));
125  }
126 
127  extern double getRhoOfECLClusterWithMaximumRhoBelow(const StoreObjPtr<ParticleList>& pions,
128  const StoreObjPtr<ParticleList>& gammas,
129  const double belowLimit);
130 
132  inline double getRhoOfECLClusterWithMaximumRho(const StoreObjPtr<ParticleList>& pionshlt,
133  const StoreObjPtr<ParticleList>& gammahlt)
134  {
135  return getRhoOfECLClusterWithMaximumRhoBelow(pionshlt, gammahlt, std::nan(""));
136  }
137  }
139 }
static const double pionMass
charged pion mass
Definition: Const.h:567
@ c_nPhotons
CR is split into n photons (N1)
static TLorentzVector labToCms(const TLorentzVector &vec)
Transforms Lorentz vector into CM System.
Abstract base class for different kinds of events.