Belle II Software  release-08-01-10
BParticle.cc
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 
9 #include "masterclass/dataobjects/BParticle.h"
10 #include <iostream>
11 #include <cmath>
12 
13 BParticle::BParticle(float px, float py, float pz, float e,
14  float charge, SIMPLEPID pid,
15  float logL_e, float logL_mu, float logL_pi, float logL_k, float logL_p, float logL_d)
16 {
17  m_px = px;
18  m_py = py;
19  m_pz = pz;
20  m_e = e;
21  m_charge = charge;
22  m_pid = pid;
23  m_logL_e = logL_e;
26  m_logL_k = logL_k;
27  m_logL_p = logL_p;
28  m_logL_d = logL_d;
29 }
30 
32 {
33  m_px += a.px();
34  m_py += a.py();
35  m_pz += a.pz();
36  m_e += a.e();
37  m_charge += a.charge();
38  m_pid = PHOTON; // wrong
40  return *this;
41 }
42 
44 {
45  return a += b;
46 }
47 
48 float BParticle::GetLogL(SIMPLEPID pid)
49 {
50  switch (pid) {
51  case ELECTRON: return m_logL_e;
52  case PION: return m_logL_pi;
53  case MUON: return m_logL_mu;
54  case KAON: return m_logL_k;
55  case PROTON: return m_logL_p;
56  case DEUTERON: return m_logL_d;
57  default: return 0;
58  }
59 }
60 
61 float BParticle::GetPID(SIMPLEPID pid)
62 {
63  float sum = 0;
64  for (int i = 0; i < 6; i++) {
65  sum += exp(GetLogL(SIMPLEPID(i)));
66  }
67  sum -= exp(GetLogL(pid));
68  return exp(GetLogL(pid)) / sum;
69 }
70 
71 float BParticle::GetBinPID(SIMPLEPID pid1, SIMPLEPID pid2)
72 {
73  return exp(GetLogL(pid1)) / (exp(GetLogL(pid1)) + exp(GetLogL(pid2)));
74 }
75 
76 float BParticle::GetMass(SIMPLEPID pid)
77 {
78 
79  switch (pid) {
80  case PHOTON: return 0;
81  case ELECTRON: return 0.00051;
82  case PION: return 0.139;
83  case MUON: return 0.105;
84  case KAON: return 0.497;
85  case PROTON: return 0.938;
86  case JPSI: return 3.1;
87  case D: return 1.86;
88  case DSTAR: return 2.01;
89  case B: return 5.27;
90  case PHI: return 1.02;
91  case LAMBDA0: return 1.115683;
92  case DEUTERON: return 1.8756;
93  case ALL: return -1;
94  default: return 0;
95  }
96 
97 }
98 
100 {
101  float m2 = m_e * m_e - m_px * m_px - m_py * m_py - m_pz * m_pz;
102  if (m2 < 0) m2 = 0;
103  return sqrt(m2);
104 }
105 
107 {
108  if (mass < 0) return;
109  m_e = sqrt(mass * mass + m_px * m_px + m_py * m_py + m_pz * m_pz);
110 
111 }
112 
114 {
116 }
117 
118 int SelectParticles(TClonesArray* pin, int charge, SIMPLEPID type, TClonesArray* pout)
119 {
120  pout->Clear();
121  int nprt = 0;
122 
123  for (TIter next(pin); BParticle* p = dynamic_cast<BParticle*>(next());) {
124  if (p->charge() == charge && p->pid() == type) {
125  TClonesArray& list = *pout;
126  new (list[nprt++]) BParticle(*p);
127  }
128  }
129  return nprt;
130 }
131 
132 int CombineParticles(TClonesArray* plist1, TClonesArray* plist2, int same, float masslow, float massup, SIMPLEPID pid,
133  TClonesArray* pout)
134 {
135 // Loop over all the particles in both lists.
136  pout->Clear();
137  int nprt = 0;
138 
139  for (TIter next1(plist1); const BParticle* p1 = dynamic_cast<BParticle*>(next1());) {
140  // the second loop
141  for (TIter next2 = (plist1 != plist2
142  && same == 0) ? TIter(plist2) : TIter(next1) ; const BParticle* p2 = dynamic_cast<BParticle*>(next2());) {
143  BParticle p = *p1 + *p2; // Combine two particles into a new particle
144  if (p.InMassRange(masslow, massup)) {
145  p.SetPid(pid);
146  TClonesArray& list = *pout;
147  new (list[nprt++]) BParticle(p); // create a new entry in kslist list of particles
148  }
149 
150  }
151 
152  }
153  return nprt;
154 }
155 
156 
157 
The Class for Masterclass particle information This class provides the data structure of the particle...
Definition: BParticle.h:18
float m_logL_pi
log likelihood of the pion hypothesis
Definition: BParticle.h:29
void SetEnergyFromMass(float mass)
Recalculate energy from particle mass and momentum.
Definition: BParticle.cc:106
SIMPLEPID pid() const
Get the particle identity.
Definition: BParticle.h:101
float m_logL_p
log likelihood of the proton hypothesis
Definition: BParticle.h:31
float GetLogL(SIMPLEPID pid)
Get the log likelihood for a particle hypothesis.
Definition: BParticle.cc:48
float logL_pi() const
Get the log likelihood for pion hypothesis.
Definition: BParticle.h:116
float GetPID(SIMPLEPID pid)
Get the log likelihood ratio for a particle hypothesis with respect to all other hypotheses.
Definition: BParticle.cc:61
float m_e
energy of the particle
Definition: BParticle.h:24
SIMPLEPID m_pid
particle identity
Definition: BParticle.h:26
float m_logL_mu
log likelihood of the muon hypothesis
Definition: BParticle.h:28
float m_py
y component of the particle momentum
Definition: BParticle.h:22
float m_charge
charge of the particle
Definition: BParticle.h:25
float px() const
Definition: BParticle.h:67
void SetEnergyFromPid()
Recalculate energy from particle identity and momentum.
Definition: BParticle.cc:113
float m_logL_e
log likelihood of the electron hypothesis
Definition: BParticle.h:27
BParticle & operator+=(const BParticle &)
Operator to add particle.
Definition: BParticle.cc:31
float charge() const
Get the particle charge.
Definition: BParticle.h:94
float GetBinPID(SIMPLEPID pid1, SIMPLEPID pid2)
Get the binary log likelihood ratio for a particle hypothesis with respect to a second hypothesis.
Definition: BParticle.cc:71
float logL_p() const
Get the log likelihood for proton hypothesis.
Definition: BParticle.h:126
float m_pz
z component of the particle momentum
Definition: BParticle.h:23
float logL_e() const
Get the log likelihood for electron hypothesis.
Definition: BParticle.h:106
float e() const
Definition: BParticle.h:79
float logL_mu() const
Get the log likelihood for muon hypothesis.
Definition: BParticle.h:111
float m_px
x component of the particle momentum
Definition: BParticle.h:21
float logL_k() const
Get the log likelihood for kaon hypothesis.
Definition: BParticle.h:121
BParticle()
Default constructor.
Definition: BParticle.h:36
float py() const
Definition: BParticle.h:71
float m_logL_k
log likelihood of the kaon hypothesis
Definition: BParticle.h:30
float GetMass()
Get the mass of the particle.
Definition: BParticle.cc:99
float m_logL_d
log likelihood of the deuteron hypothesis
Definition: BParticle.h:32
float logL_d() const
Get the log likelihood for deuteron hypothesis.
Definition: BParticle.h:131
float pz() const
z
Definition: BParticle.h:75
FourVector operator+(const FourVector &lhs, const FourVector &rhs)
Sum of two four vectors.
Definition: FourVector.h:188
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28