Belle II Software  light-2205-abys
MCParticle.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 
9 #pragma once
10 
11 #include <framework/gearbox/Const.h>
12 #include <framework/core/FrameworkExceptions.h>
13 #include <framework/datastore/RelationsObject.h>
14 #include <framework/geometry/B2Vector3.h>
15 
16 #include <TClonesArray.h>
17 #include <TVector3.h>
18 #include <Math/Vector3D.h>
19 #include <Math/Vector4D.h>
20 
21 #include <cmath>
22 #include <climits>
23 #include <vector>
24 
25 
26 namespace Belle2 {
34  class MCParticle: public RelationsObject {
35  public:
36 
37  //Define exceptions
39  BELLE2_DEFINE_EXCEPTION(LastChildIndexOutOfRangError, "Last child index out of range!")
41  BELLE2_DEFINE_EXCEPTION(NoParticleListSetError, "No Particle list set, cannot determine related particles!")
43  BELLE2_DEFINE_EXCEPTION(ParticlePDGNotKnownError, "The pdg value (%1%) of the MCParticle is not known!")
44 
45 
46 
47  enum StatusBit {
53  c_LeftDetector = 1 << 2,
57  c_IsVirtual = 1 << 4,
59  c_Initial = 1 << 5,
61  c_IsISRPhoton = 1 << 6,
63  c_IsFSRPhoton = 1 << 7,
65  c_IsPHOTOSPhoton = 1 << 8,
68  };
69 
70 
75  m_plist(0), m_index(0), m_status(0),
76  m_pdg(0), m_mass(0), m_energy(0),
83  m_mother(0),
86  m_seenIn() {}
87 
96  MCParticle(TClonesArray* plist, const MCParticle& p):
97  m_plist(plist), m_index(p.m_index), m_status(p.m_status),
105  m_mother(p.m_mother),
108  m_seenIn(p.m_seenIn) {}
109 
114  int getPDG() const { return m_pdg; }
115 
124  unsigned int getStatus(unsigned short int bitmask = USHRT_MAX) const { return m_status & bitmask; }
125 
131  bool hasStatus(unsigned short int bitmask) const { return (m_status & bitmask) == bitmask; }
132 
137  float getMass() const { return m_mass; }
138 
143  float getCharge() const;
144 
149  float getEnergy() const { return m_energy; }
150 
155  bool hasValidVertex() const { return m_validVertex; }
156 
161  float getProductionTime() const { return m_productionTime; }
162 
170  float getDecayTime() const { return m_decayTime; }
171 
179  float getLifetime() const { return m_decayTime - m_productionTime; }
180 
185  ROOT::Math::XYZVector getVertex() const { return getProductionVertex(); }
186 
191  ROOT::Math::XYZVector getProductionVertex() const
192  {
193  return ROOT::Math::XYZVector(m_productionVertex_x, m_productionVertex_y, m_productionVertex_z);
194  }
195 
200  TVector3 getMomentum() const
201  {
202  return TVector3(m_momentum_x, m_momentum_y, m_momentum_z);
203  }
204 
209  ROOT::Math::PxPyPzEVector get4Vector() const
210  {
211  return ROOT::Math::PxPyPzEVector(m_momentum_x, m_momentum_y, m_momentum_z, m_energy);
212  }
213 
214 
221  TVector3 getDecayVertex() const
222  {
224  }
225 
232  int getIndex() const { fixParticleList(); return m_index; }
233 
246  int getArrayIndex() const { fixParticleList(); return m_index - 1; }
247 
253  int getFirstDaughter() const { return m_firstDaughter; }
254 
255 
261  int getLastDaughter() const { return m_lastDaughter; }
262 
271  std::vector<Belle2::MCParticle*> getDaughters() const;
272  //Need namespace qualifier because ROOT CINT has troubles otherwise
273 
275  const MCParticle* getDaughter(int i) const;
276 
278  int getNDaughters() const;
279 
286  MCParticle* getMother() const;
287 
300 
306 
312  bool hasSeenInDetector(Const::DetectorSet set) const { return m_seenIn.contains(set); }
313 
318  bool isVirtual() const;
319 
324  bool isInitial() const;
325 
331  bool isPrimaryParticle() const;
332 
337  void setPDG(int pdg) { m_pdg = pdg; }
338 
342  void setMassFromPDG();
343 
348  void setStatus(unsigned short int status) { m_status = status; }
349 
355  void addStatus(unsigned short int bitmask) { m_status |= bitmask; }
356 
362  void removeStatus(unsigned short int bitmask) { m_status &= (~bitmask); }
363 
368  void setMass(float mass) { m_mass = mass; }
369 
374  void setEnergy(float energy) { m_energy = energy; }
375 
380  void setValidVertex(bool valid) { m_validVertex = valid; }
381 
386  void setProductionTime(float time) { m_productionTime = time; }
387 
392  void setDecayTime(float time) { m_decayTime = time; }
393 
398  void setProductionVertex(const TVector3& vertex)
399  {
400  m_productionVertex_x = vertex.X(); m_productionVertex_y = vertex.Y(), m_productionVertex_z = vertex.Z();
401  }
402 
410  void setProductionVertex(float x, float y, float z)
411  {
413  }
414 
419  void setMomentum(const TVector3& momentum)
420  {
421  m_momentum_x = momentum.X(); m_momentum_y = momentum.Y(), m_momentum_z = momentum.Z();
422  }
423 
431  void setMomentum(float px, float py, float pz)
432  {
433  m_momentum_x = px, m_momentum_y = py; m_momentum_z = pz;
434  }
435 
440  void set4Vector(const ROOT::Math::PxPyPzEVector& p4)
441  {
442  m_momentum_x = p4.px(); m_momentum_y = p4.py(); m_momentum_z = p4.pz(); m_energy = p4.energy();
443  }
444 
449  void setDecayVertex(const TVector3& vertex)
450  {
451  m_decayVertex_x = vertex.X(); m_decayVertex_y = vertex.Y(), m_decayVertex_z = vertex.Z();
452  }
453 
461  void setDecayVertex(float x, float y, float z)
462  {
464  }
465 
470  void setSecondaryPhysicsProcess(int physicsProcess) { m_secondaryPhysicsProcess = physicsProcess; }
471 
477 
483 
489 
497  void fixParticleList() const;
498 
503 
508 
510  virtual std::string getName() const override;
511 
513  virtual std::string getInfoHTML() const override;
514 
523  const MCParticle* getParticleFromGeneralizedIndexString(const std::string& generalizedIndex) const;
524 
525  protected:
526 
534  TClonesArray* m_plist;
535 
540  int m_index;
541 
542  unsigned short int m_status;
543  int m_pdg;
544  float m_mass;
545  float m_energy;
546  float m_momentum_x;
547  float m_momentum_y;
548  float m_momentum_z;
557  float m_decayTime;
562  int m_mother;
565  static const double c_epsilon;
572  };
573 
574 
575  inline bool MCParticle::isVirtual() const
576  {
577  bool virtuality = hasStatus(c_IsVirtual);
578  if (!virtuality) {
579  double E2 = m_energy * m_energy;
580  double m2 = m_mass * m_mass;
581  double p2 = m_momentum_x * m_momentum_x;
582  p2 += m_momentum_y * m_momentum_y;
583  p2 += m_momentum_z * m_momentum_z;
584 
585  virtuality = (fabs(E2 - (p2 + m2)) > c_epsilon * E2);
586  }
587  return virtuality;
588  }
589 
590  inline bool MCParticle::isInitial() const
591  {
592  return hasStatus(c_Initial);
593  }
594 
595  inline bool MCParticle::isPrimaryParticle() const
596  {
598  }
599 
601  {
602  if (m_mother == 0)
603  return nullptr;
604  fixParticleList();
605  return static_cast<MCParticle*>(m_plist->At(m_mother - 1));
606  }
607 
609 } // end namespace Belle2
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:71
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:121
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:34
void setMomentum(const TVector3 &momentum)
Set particle momentum.
Definition: MCParticle.h:419
float getEnergy() const
Return particle energy in GeV.
Definition: MCParticle.h:149
StatusBit
Exception is thrown if the requested index for the last child is out of range.
Definition: MCParticle.h:47
@ c_IsFSRPhoton
bit 7: Particle is from finial state radiation
Definition: MCParticle.h:63
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
Definition: MCParticle.h:59
@ c_IsPHOTOSPhoton
bit 8: Particle is an radiative photon from PHOTOS
Definition: MCParticle.h:65
@ c_IsRadiativePhoton
combined flag to test whether the particle is radiative
Definition: MCParticle.h:67
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:49
@ c_LeftDetector
bit 2: Particle left the detector (the simulation volume).
Definition: MCParticle.h:53
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
Definition: MCParticle.h:57
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:51
@ c_StoppedInDetector
bit 3: Particle was stopped in the detector (the simulation volume).
Definition: MCParticle.h:55
@ c_IsISRPhoton
bit 6: Particle is from initial state radiation
Definition: MCParticle.h:61
void setDecayTime(float time)
Set decay time.
Definition: MCParticle.h:392
void setMass(float mass)
Set particle mass.
Definition: MCParticle.h:368
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:564
void removeSeenInDetector(Const::DetectorSet set)
Unflag/Remove the bit if the MC particle is not seen in a specific subdetector.
Definition: MCParticle.h:488
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:232
void setInitial()
Set particle to initial.
Definition: MCParticle.h:507
float m_productionVertex_x
production vertex of particle, x component
Definition: MCParticle.h:553
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:563
float m_mass
mass of the particle
Definition: MCParticle.h:544
void setDecayVertex(float x, float y, float z)
Set decay vertex.
Definition: MCParticle.h:461
float m_decayVertex_z
decay vertex of particle, z component
Definition: MCParticle.h:560
virtual std::string getName() const override
Return name of this particle.
Definition: MCParticle.cc:117
void setProductionVertex(const TVector3 &vertex)
Set production vertex position.
Definition: MCParticle.h:398
float getLifetime() const
Return the lifetime in ns.
Definition: MCParticle.h:179
void setMomentum(float px, float py, float pz)
Set particle momentum.
Definition: MCParticle.h:431
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
Definition: MCParticle.h:355
void setEnergy(float energy)
Set energy.
Definition: MCParticle.h:374
Const::DetectorSet getSeenInDetector() const
Return the seen-in flags of the entire Belle II subdetectors for an MC particle.
Definition: MCParticle.h:305
float m_decayTime
decay time
Definition: MCParticle.h:557
void setDecayVertex(const TVector3 &vertex)
Set decay vertex.
Definition: MCParticle.h:449
const MCParticle * getParticleFromGeneralizedIndexString(const std::string &generalizedIndex) const
Explores the decay tree of the MC particle and returns the (grand^n)daughter identified by a generali...
Definition: MCParticle.cc:152
void setProductionVertex(float x, float y, float z)
Set production vertex position.
Definition: MCParticle.h:410
bool hasSeenInDetector(Const::DetectorSet set) const
Return if the seen-in flag for a specific subdetector is set or not.
Definition: MCParticle.h:312
void setSeenInDetector(Const::DetectorSet set)
Set the seen-in flags for the entire Belle II subdetectors for an Monte Carlo particle.
Definition: MCParticle.h:476
float m_productionVertex_z
production vertex of particle, z component
Definition: MCParticle.h:555
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
Definition: MCParticle.cc:52
float getMass() const
Return the particle mass in GeV.
Definition: MCParticle.h:137
float m_energy
energy of the particle
Definition: MCParticle.h:545
static const double c_epsilon
limit of precision for two doubles to be the same.
Definition: MCParticle.h:565
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
Definition: MCParticle.h:131
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition: MCParticle.h:185
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:246
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
Definition: MCParticle.h:191
virtual std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
Definition: MCParticle.cc:125
float getDecayTime() const
Return the decay time in ns.
Definition: MCParticle.h:170
void setValidVertex(bool valid)
Set indication wether vertex and time information is valid or just default.
Definition: MCParticle.h:380
TVector3 getMomentum() const
Return momentum.
Definition: MCParticle.h:200
float m_productionVertex_y
production vertex of particle, y component
Definition: MCParticle.h:554
int m_pdg
PDG-Code of the particle.
Definition: MCParticle.h:543
int m_mother
1-based index of the mother particle
Definition: MCParticle.h:562
float m_momentum_x
momentum of particle, x component
Definition: MCParticle.h:546
void setSecondaryPhysicsProcess(int physicsProcess)
Sets the physics process type of a secondary particle.
Definition: MCParticle.h:470
float m_decayVertex_x
decay vertex of particle, x component
Definition: MCParticle.h:558
const MCParticle * getDaughter(int i) const
Return i-th daughter.
Definition: MCParticle.cc:67
bool hasValidVertex() const
Indication whether vertex and time information is useful or just default.
Definition: MCParticle.h:155
int getNDaughters() const
Return number of daughter MCParticles.
Definition: MCParticle.cc:75
void removeStatus(unsigned short int bitmask)
Remove bitmask from current status.
Definition: MCParticle.h:362
unsigned int getStatus(unsigned short int bitmask=USHRT_MAX) const
Return status code of particle.
Definition: MCParticle.h:124
unsigned short int m_status
transient 1-based index of particle
Definition: MCParticle.h:542
TVector3 getDecayVertex() const
Return decay vertex.
Definition: MCParticle.h:221
int getLastDaughter() const
Get 1-based index of last daughter, 0 if no daughters.
Definition: MCParticle.h:261
float getCharge() const
Return the particle charge defined in TDatabasePDG.
Definition: MCParticle.cc:36
void setVirtual()
Set particle to virtual.
Definition: MCParticle.h:502
float m_momentum_z
momentum of particle, z component
Definition: MCParticle.h:548
MCParticle(TClonesArray *plist, const MCParticle &p)
Construct MCParticle from a another MCParticle and the TClonesArray it is stored in.
Definition: MCParticle.h:96
ROOT::Math::PxPyPzEVector get4Vector() const
Return 4Vector of particle.
Definition: MCParticle.h:209
void fixParticleList() const
Search the DataStore for the corresponding MCParticle array.
Definition: MCParticle.cc:82
void setPDG(int pdg)
Set PDG code of the particle.
Definition: MCParticle.h:337
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:114
float getProductionTime() const
Return production time in ns.
Definition: MCParticle.h:161
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets the 4Vector of particle.
Definition: MCParticle.h:440
int m_secondaryPhysicsProcess
physics process type of a secondary particle
Definition: MCParticle.h:567
bool m_validVertex
indication wether vertex and time information is useful or just default
Definition: MCParticle.h:550
float m_productionTime
production time
Definition: MCParticle.h:552
int m_index
transient pointer to particle list
Definition: MCParticle.h:540
void setStatus(unsigned short int status)
Set Status code for the particle.
Definition: MCParticle.h:348
void addSeenInDetector(Const::DetectorSet set)
Flag/Add a bit if the MC particle is seen in a specific subdetector.
Definition: MCParticle.h:482
float m_momentum_y
momentum of particle, y component
Definition: MCParticle.h:547
MCParticle()
Default constructor for ROOT.
Definition: MCParticle.h:74
Const::DetectorSet m_seenIn
Each bit is a seen-in flag for the corresoponding subdetector of Belle II.
Definition: MCParticle.h:569
TClonesArray * m_plist
Internal pointer to DataStore Array containing particles belonging to this collection.
Definition: MCParticle.h:534
int getFirstDaughter() const
Get 1-based index of first daughter, 0 if no daughters.
Definition: MCParticle.h:253
void setProductionTime(float time)
Set production time.
Definition: MCParticle.h:386
ClassDefOverride(MCParticle, 5)
A Class to store the Monte Carlo particle information.
void setMassFromPDG()
Sets the mass for the particle from the particle's PDG code.
Definition: MCParticle.cc:28
float m_decayVertex_y
decay vertex of particle, y component
Definition: MCParticle.h:559
int getSecondaryPhysicsProcess() const
Returns the physics process type of a secondary particle.
Definition: MCParticle.h:299
Defines interface for accessing relations of objects in StoreArray.
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
bool isInitial() const
Check if particle is an initial particle such as ISR.
Definition: MCParticle.h:590
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition: MCParticle.h:600
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Definition: MCParticle.h:595
bool isVirtual() const
Check if particle is virtual.
Definition: MCParticle.h:575
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:23