Belle II Software  release-05-01-25
utilities.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <analysis/dataobjects/ParticleList.h>
13 
14 #include <mdst/dataobjects/ECLCluster.h>
15 #include <tracking/dataobjects/RecoTrack.h>
16 
17 #include <analysis/utility/PCmsLabTransform.h>
18 #include <analysis/ClusterUtility/ClusterUtils.h>
19 #include <TLorentzVector.h>
20 
21 namespace Belle2 {
26  namespace SoftwareTrigger {
28  template<class T>
29  inline TLorentzVector getFourVector(const T& item);
30 
32  template<>
33  inline TLorentzVector getFourVector(const std::reference_wrapper<const ECLCluster>& cluster)
34  {
35  ClusterUtils C;
36  const TLorentzVector& v = C.Get4MomentumFromCluster(&(cluster.get()), ECLCluster::EHypothesisBit::c_nPhotons);
37  return TLorentzVector(v.Px(), v.Py(), v.Pz(), v.E());
38  }
39 
41  template<>
42  inline TLorentzVector getFourVector(const RecoTrack& track)
43  {
44  const TVector3& positionSeed = track.getPositionSeed();
45  return TLorentzVector(positionSeed.X(), positionSeed.Y(), positionSeed.Z(),
46  sqrt(positionSeed.Mag2() + Const::pionMass * Const::pionMass));
47  }
48 
50  template<class AnEntityType>
51  inline const AnEntityType* getElementFromParticle(const Particle& particle);
52 
54  template<>
55  inline const Particle* getElementFromParticle(const Particle& particle)
56  {
57  return &particle;
58  }
59 
61  template<>
62  inline const ECLCluster* getElementFromParticle(const Particle& particle)
63  {
64  return particle.getECLCluster();
65  }
66 
68  inline double BeamEnergyCMS()
69  {
70  PCmsLabTransform T;
71  return T.getCMSEnergy() / 2.0;
72  }
73 
75  template<class AnEntity>
76  inline double getRho(const AnEntity* entity)
77  {
78  if (not entity) {
79  return -1;
80  }
81 
82  const TLorentzVector& fourVector = entity->get4Vector();
83  return PCmsLabTransform::labToCms(fourVector).Rho();
84  }
85 
86  // Template specialization for ECLCluster
87  template<>
88  inline double getRho(const ECLCluster* entity)
89  {
90  if (not entity) {
91  return -1;
92  }
93 
94  ClusterUtils C;
95  return PCmsLabTransform::labToCms(C.Get4MomentumFromCluster(entity, ECLCluster::EHypothesisBit::c_nPhotons)).Rho();
96  }
97 
102  template<class AReturnType>
103  static const AReturnType* getElementWithMaximumRhoBelow(const StoreObjPtr<ParticleList>& particles,
104  const double belowLimit)
105  {
106  const AReturnType* elementMaximumRho = nullptr;
107  double maximumRho = -1.;
108  for (const Particle& currentParticle : *particles) {
109  const auto currentElement = getElementFromParticle<AReturnType>(currentParticle);
110  const double& currentRho = getRho(currentElement);
111  if (currentRho >= belowLimit) {
112  continue;
113  }
114  if (currentRho > maximumRho) {
115  maximumRho = currentRho;
116  elementMaximumRho = currentElement;
117  }
118  }
119  return elementMaximumRho;
120  }
121 
123  template<class AReturnType>
124  inline const AReturnType* getElementWithMaximumRho(const StoreObjPtr<ParticleList>& particles)
125  {
126  return getElementWithMaximumRhoBelow<AReturnType>(particles, std::nan(""));
127  }
128 
129  extern double getRhoOfECLClusterWithMaximumRhoBelow(const StoreObjPtr<ParticleList>& pions,
130  const StoreObjPtr<ParticleList>& gammas,
131  const double belowLimit);
132 
134  inline double getRhoOfECLClusterWithMaximumRho(const StoreObjPtr<ParticleList>& pionshlt,
135  const StoreObjPtr<ParticleList>& gammahlt)
136  {
137  return getRhoOfECLClusterWithMaximumRhoBelow(pionshlt, gammahlt, std::nan(""));
138  }
139  }
141 }
Belle2::PCmsLabTransform::labToCms
static TLorentzVector labToCms(const TLorentzVector &vec)
Transforms Lorentz vector into CM System.
Definition: PCmsLabTransform.cc:15
Belle2::ECLCluster::EHypothesisBit::c_nPhotons
@ c_nPhotons
CR is split into n photons (N1)
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Const::pionMass
static const double pionMass
charged pion mass
Definition: Const.h:560