Belle II Software  release-08-01-10
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 
15 #include <TClonesArray.h>
16 #include <Math/Vector3D.h>
17 #include <Math/Vector4D.h>
18 
19 #include <cmath>
20 #include <climits>
21 #include <vector>
22 
23 
24 namespace Belle2 {
32  class MCParticle: public RelationsObject {
33  public:
34 
35  //Define exceptions
37  BELLE2_DEFINE_EXCEPTION(LastChildIndexOutOfRangError, "Last child index out of range!")
39  BELLE2_DEFINE_EXCEPTION(NoParticleListSetError, "No Particle list set, cannot determine related particles!")
41  BELLE2_DEFINE_EXCEPTION(ParticlePDGNotKnownError, "The pdg value (%1%) of the MCParticle is not known!")
42 
43 
44 
45  enum StatusBit {
51  c_LeftDetector = 1 << 2,
55  c_IsVirtual = 1 << 4,
57  c_Initial = 1 << 5,
59  c_IsISRPhoton = 1 << 6,
61  c_IsFSRPhoton = 1 << 7,
63  c_IsPHOTOSPhoton = 1 << 8,
66  };
67 
68 
73  m_plist(0), m_index(0), m_status(0),
74  m_pdg(0), m_mass(0), m_energy(0),
81  m_mother(0),
84  m_seenIn() {}
85 
94  MCParticle(TClonesArray* plist, const MCParticle& p):
95  m_plist(plist), m_index(p.m_index), m_status(p.m_status),
103  m_mother(p.m_mother),
106  m_seenIn(p.m_seenIn) {}
107 
112  int getPDG() const { return m_pdg; }
113 
122  unsigned int getStatus(unsigned short int bitmask = USHRT_MAX) const { return m_status & bitmask; }
123 
129  bool hasStatus(unsigned short int bitmask) const { return (m_status & bitmask) == bitmask; }
130 
135  float getMass() const { return m_mass; }
136 
141  float getCharge() const;
142 
147  float getEnergy() const { return m_energy; }
148 
153  bool hasValidVertex() const { return m_validVertex; }
154 
159  float getProductionTime() const { return m_productionTime; }
160 
168  float getDecayTime() const { return m_decayTime; }
169 
177  float getLifetime() const { return m_decayTime - m_productionTime; }
178 
183  ROOT::Math::XYZVector getVertex() const { return getProductionVertex(); }
184 
189  ROOT::Math::XYZVector getProductionVertex() const
190  {
191  return ROOT::Math::XYZVector(m_productionVertex_x, m_productionVertex_y, m_productionVertex_z);
192  }
193 
198  ROOT::Math::XYZVector getMomentum() const
199  {
200  return ROOT::Math::XYZVector(m_momentum_x, m_momentum_y, m_momentum_z);
201  }
202 
207  ROOT::Math::PxPyPzEVector get4Vector() const
208  {
209  return ROOT::Math::PxPyPzEVector(m_momentum_x, m_momentum_y, m_momentum_z, m_energy);
210  }
211 
212 
219  ROOT::Math::XYZVector getDecayVertex() const
220  {
221  return ROOT::Math::XYZVector(m_decayVertex_x, m_decayVertex_y, m_decayVertex_z);
222  }
223 
230  int getIndex() const { fixParticleList(); return m_index; }
231 
244  int getArrayIndex() const { fixParticleList(); return m_index - 1; }
245 
251  int getFirstDaughter() const { return m_firstDaughter; }
252 
253 
259  int getLastDaughter() const { return m_lastDaughter; }
260 
269  std::vector<Belle2::MCParticle*> getDaughters() const;
270  //Need namespace qualifier because ROOT CINT has troubles otherwise
271 
273  const MCParticle* getDaughter(int i) const;
274 
276  int getNDaughters() const;
277 
284  MCParticle* getMother() const;
285 
298 
304 
310  bool hasSeenInDetector(Const::DetectorSet set) const { return m_seenIn.contains(set); }
311 
316  bool isVirtual() const;
317 
322  bool isInitial() const;
323 
329  bool isPrimaryParticle() const;
330 
335  void setPDG(int pdg) { m_pdg = pdg; }
336 
340  void setMassFromPDG();
341 
346  void setStatus(unsigned short int status) { m_status = status; }
347 
353  void addStatus(unsigned short int bitmask) { m_status |= bitmask; }
354 
360  void removeStatus(unsigned short int bitmask) { m_status &= (~bitmask); }
361 
366  void setMass(float mass) { m_mass = mass; }
367 
372  void setEnergy(float energy) { m_energy = energy; }
373 
378  void setValidVertex(bool valid) { m_validVertex = valid; }
379 
384  void setProductionTime(float time) { m_productionTime = time; }
385 
390  void setDecayTime(float time) { m_decayTime = time; }
391 
396  void setProductionVertex(const ROOT::Math::XYZVector& vertex)
397  {
398  m_productionVertex_x = vertex.X(); m_productionVertex_y = vertex.Y(), m_productionVertex_z = vertex.Z();
399  }
400 
408  void setProductionVertex(float x, float y, float z)
409  {
411  }
412 
417  void setMomentum(const ROOT::Math::XYZVector& momentum)
418  {
419  m_momentum_x = momentum.X(); m_momentum_y = momentum.Y(), m_momentum_z = momentum.Z();
420  }
421 
429  void setMomentum(float px, float py, float pz)
430  {
431  m_momentum_x = px, m_momentum_y = py; m_momentum_z = pz;
432  }
433 
438  void set4Vector(const ROOT::Math::PxPyPzEVector& p4)
439  {
440  m_momentum_x = p4.px(); m_momentum_y = p4.py(); m_momentum_z = p4.pz(); m_energy = p4.energy();
441  }
442 
447  void setDecayVertex(const ROOT::Math::XYZVector& vertex)
448  {
449  m_decayVertex_x = vertex.X(); m_decayVertex_y = vertex.Y(), m_decayVertex_z = vertex.Z();
450  }
451 
459  void setDecayVertex(float x, float y, float z)
460  {
462  }
463 
468  void setSecondaryPhysicsProcess(int physicsProcess) { m_secondaryPhysicsProcess = physicsProcess; }
469 
475 
481 
487 
495  void fixParticleList() const;
496 
501 
506 
508  virtual std::string getName() const override;
509 
511  virtual std::string getInfoHTML() const override;
512 
521  const MCParticle* getParticleFromGeneralizedIndexString(const std::string& generalizedIndex) const;
522 
523  protected:
524 
532  TClonesArray* m_plist;
533 
538  int m_index;
539 
540  unsigned short int m_status;
541  int m_pdg;
542  float m_mass;
543  float m_energy;
544  float m_momentum_x;
545  float m_momentum_y;
546  float m_momentum_z;
555  float m_decayTime;
560  int m_mother;
563  static const double c_epsilon;
571  friend class FixMergedObjectsModule;
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:226
If the content of two DataStores are merged using the 'MergeDataStoreModule', then Relations of the o...
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
float getEnergy() const
Return particle energy in GeV.
Definition: MCParticle.h:147
StatusBit
Exception is thrown if the requested index for the last child is out of range.
Definition: MCParticle.h:45
@ c_IsFSRPhoton
bit 7: Particle is from finial state radiation
Definition: MCParticle.h:61
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
Definition: MCParticle.h:57
@ c_IsPHOTOSPhoton
bit 8: Particle is an radiative photon from PHOTOS
Definition: MCParticle.h:63
@ c_IsRadiativePhoton
combined flag to test whether the particle is radiative
Definition: MCParticle.h:65
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
@ c_LeftDetector
bit 2: Particle left the detector (the simulation volume).
Definition: MCParticle.h:51
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
Definition: MCParticle.h:55
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:49
@ c_StoppedInDetector
bit 3: Particle was stopped in the detector (the simulation volume).
Definition: MCParticle.h:53
@ c_IsISRPhoton
bit 6: Particle is from initial state radiation
Definition: MCParticle.h:59
void setDecayTime(float time)
Set decay time.
Definition: MCParticle.h:390
void setMass(float mass)
Set particle mass.
Definition: MCParticle.h:366
void setDecayVertex(const ROOT::Math::XYZVector &vertex)
Set decay vertex.
Definition: MCParticle.h:447
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:562
void removeSeenInDetector(Const::DetectorSet set)
Unflag/Remove the bit if the MC particle is not seen in a specific subdetector.
Definition: MCParticle.h:486
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:230
void setInitial()
Set particle to initial.
Definition: MCParticle.h:505
ROOT::Math::XYZVector getDecayVertex() const
Return decay vertex.
Definition: MCParticle.h:219
float m_productionVertex_x
production vertex of particle, x component
Definition: MCParticle.h:551
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:561
float m_mass
mass of the particle
Definition: MCParticle.h:542
void setDecayVertex(float x, float y, float z)
Set decay vertex.
Definition: MCParticle.h:459
float m_decayVertex_z
decay vertex of particle, z component
Definition: MCParticle.h:558
virtual std::string getName() const override
Return name of this particle.
Definition: MCParticle.cc:117
float getLifetime() const
Return the lifetime in ns.
Definition: MCParticle.h:177
void setMomentum(float px, float py, float pz)
Set particle momentum.
Definition: MCParticle.h:429
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
Definition: MCParticle.h:353
void setEnergy(float energy)
Set energy.
Definition: MCParticle.h:372
Const::DetectorSet getSeenInDetector() const
Return the seen-in flags of the entire Belle II subdetectors for an MC particle.
Definition: MCParticle.h:303
float m_decayTime
decay time
Definition: MCParticle.h:555
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:408
bool hasSeenInDetector(Const::DetectorSet set) const
Return if the seen-in flag for a specific subdetector is set or not.
Definition: MCParticle.h:310
void setSeenInDetector(Const::DetectorSet set)
Set the seen-in flags for the entire Belle II subdetectors for an Monte Carlo particle.
Definition: MCParticle.h:474
float m_productionVertex_z
production vertex of particle, z component
Definition: MCParticle.h:553
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:135
float m_energy
energy of the particle
Definition: MCParticle.h:543
static const double c_epsilon
limit of precision for two doubles to be the same.
Definition: MCParticle.h:563
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
Definition: MCParticle.h:129
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition: MCParticle.h:183
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:244
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
Definition: MCParticle.h:189
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:168
void setValidVertex(bool valid)
Set indication wether vertex and time information is valid or just default.
Definition: MCParticle.h:378
float m_productionVertex_y
production vertex of particle, y component
Definition: MCParticle.h:552
int m_pdg
PDG-Code of the particle.
Definition: MCParticle.h:541
int m_mother
1-based index of the mother particle
Definition: MCParticle.h:560
void setProductionVertex(const ROOT::Math::XYZVector &vertex)
Set production vertex position.
Definition: MCParticle.h:396
float m_momentum_x
momentum of particle, x component
Definition: MCParticle.h:544
void setSecondaryPhysicsProcess(int physicsProcess)
Sets the physics process type of a secondary particle.
Definition: MCParticle.h:468
float m_decayVertex_x
decay vertex of particle, x component
Definition: MCParticle.h:556
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:153
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:360
unsigned int getStatus(unsigned short int bitmask=USHRT_MAX) const
Return status code of particle.
Definition: MCParticle.h:122
unsigned short int m_status
transient 1-based index of particle
Definition: MCParticle.h:540
int getLastDaughter() const
Get 1-based index of last daughter, 0 if no daughters.
Definition: MCParticle.h:259
float getCharge() const
Return the particle charge defined in TDatabasePDG.
Definition: MCParticle.cc:36
void setVirtual()
Set particle to virtual.
Definition: MCParticle.h:500
float m_momentum_z
momentum of particle, z component
Definition: MCParticle.h:546
MCParticle(TClonesArray *plist, const MCParticle &p)
Construct MCParticle from a another MCParticle and the TClonesArray it is stored in.
Definition: MCParticle.h:94
ROOT::Math::PxPyPzEVector get4Vector() const
Return 4Vector of particle.
Definition: MCParticle.h:207
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:335
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:112
float getProductionTime() const
Return production time in ns.
Definition: MCParticle.h:159
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets the 4Vector of particle.
Definition: MCParticle.h:438
int m_secondaryPhysicsProcess
physics process type of a secondary particle
Definition: MCParticle.h:565
ROOT::Math::XYZVector getMomentum() const
Return momentum.
Definition: MCParticle.h:198
bool m_validVertex
indication wether vertex and time information is useful or just default
Definition: MCParticle.h:548
void setMomentum(const ROOT::Math::XYZVector &momentum)
Set particle momentum.
Definition: MCParticle.h:417
float m_productionTime
production time
Definition: MCParticle.h:550
int m_index
transient pointer to particle list
Definition: MCParticle.h:538
void setStatus(unsigned short int status)
Set Status code for the particle.
Definition: MCParticle.h:346
void addSeenInDetector(Const::DetectorSet set)
Flag/Add a bit if the MC particle is seen in a specific subdetector.
Definition: MCParticle.h:480
float m_momentum_y
momentum of particle, y component
Definition: MCParticle.h:545
MCParticle()
Default constructor for ROOT.
Definition: MCParticle.h:72
Const::DetectorSet m_seenIn
Each bit is a seen-in flag for the corresoponding subdetector of Belle II.
Definition: MCParticle.h:567
TClonesArray * m_plist
Internal pointer to DataStore Array containing particles belonging to this collection.
Definition: MCParticle.h:532
int getFirstDaughter() const
Get 1-based index of first daughter, 0 if no daughters.
Definition: MCParticle.h:251
void setProductionTime(float time)
Set production time.
Definition: MCParticle.h:384
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:557
int getSecondaryPhysicsProcess() const
Returns the physics process type of a secondary particle.
Definition: MCParticle.h:297
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.