Belle II Software  release-06-01-15
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 <TVector3.h>
17 #include <TLorentzVector.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  TVector3 getVertex() const { return getProductionVertex(); }
184 
189  TVector3 getProductionVertex() const
190  {
192  }
193 
198  TVector3 getMomentum() const
199  {
200  return TVector3(m_momentum_x, m_momentum_y, m_momentum_z);
201  }
202 
207  TLorentzVector get4Vector() const
208  {
209  TLorentzVector vec; vec.SetXYZM(m_momentum_x, m_momentum_y, m_momentum_z, m_mass); return vec;
210  }
211 
212 
219  TVector3 getDecayVertex() const
220  {
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  int getNDaughters() const;
274 
281  MCParticle* getMother() const;
282 
295 
301 
307  bool hasSeenInDetector(Const::DetectorSet set) const { return m_seenIn.contains(set); }
308 
313  bool isVirtual() const;
314 
319  bool isInitial() const;
320 
326  bool isPrimaryParticle() const;
327 
332  void setPDG(int pdg) { m_pdg = pdg; }
333 
337  void setMassFromPDG();
338 
343  void setStatus(unsigned short int status) { m_status = status; }
344 
350  void addStatus(unsigned short int bitmask) { m_status |= bitmask; }
351 
357  void removeStatus(unsigned short int bitmask) { m_status &= (~bitmask); }
358 
363  void setMass(float mass) { m_mass = mass; }
364 
369  void setEnergy(float energy) { m_energy = energy; }
370 
375  void setValidVertex(bool valid) { m_validVertex = valid; }
376 
381  void setProductionTime(float time) { m_productionTime = time; }
382 
387  void setDecayTime(float time) { m_decayTime = time; }
388 
393  void setProductionVertex(const TVector3& vertex)
394  {
395  m_productionVertex_x = vertex.X(); m_productionVertex_y = vertex.Y(), m_productionVertex_z = vertex.Z();
396  }
397 
405  void setProductionVertex(float x, float y, float z)
406  {
408  }
409 
414  void setMomentum(const TVector3& momentum)
415  {
416  m_momentum_x = momentum.X(); m_momentum_y = momentum.Y(), m_momentum_z = momentum.Z();
417  }
418 
426  void setMomentum(float px, float py, float pz)
427  {
428  m_momentum_x = px, m_momentum_y = py; m_momentum_z = pz;
429  }
430 
435  void set4Vector(const TLorentzVector& p4) { setMomentum(p4.Vect()); m_energy = p4.Energy(); }
436 
441  void setDecayVertex(const TVector3& vertex)
442  {
443  m_decayVertex_x = vertex.X(); m_decayVertex_y = vertex.Y(), m_decayVertex_z = vertex.Z();
444  }
445 
453  void setDecayVertex(float x, float y, float z)
454  {
456  }
457 
462  void setSecondaryPhysicsProcess(int physicsProcess) { m_secondaryPhysicsProcess = physicsProcess; }
463 
469 
475 
481 
489  void fixParticleList() const;
490 
495 
500 
502  virtual std::string getName() const override;
503 
505  virtual std::string getInfoHTML() const override;
506 
507  protected:
508 
516  TClonesArray* m_plist;
517 
522  int m_index;
523 
524  unsigned short int m_status;
525  int m_pdg;
526  float m_mass;
527  float m_energy;
528  float m_momentum_x;
529  float m_momentum_y;
530  float m_momentum_z;
539  float m_decayTime;
544  int m_mother;
547  static const double c_epsilon;
554  };
555 
556 
557  inline bool MCParticle::isVirtual() const
558  {
559  bool virtuality = hasStatus(c_IsVirtual);
560  if (!virtuality) {
561  double E2 = m_energy * m_energy;
562  double m2 = m_mass * m_mass;
563  double p2 = m_momentum_x * m_momentum_x;
564  p2 += m_momentum_y * m_momentum_y;
565  p2 += m_momentum_z * m_momentum_z;
566 
567  virtuality = (fabs(E2 - (p2 + m2)) > c_epsilon * E2);
568  }
569  return virtuality;
570  }
571 
572  inline bool MCParticle::isInitial() const
573  {
574  return hasStatus(c_Initial);
575  }
576 
577  inline bool MCParticle::isPrimaryParticle() const
578  {
580  }
581 
583  {
584  if (m_mother == 0)
585  return nullptr;
586  fixParticleList();
587  return static_cast<MCParticle*>(m_plist->At(m_mother - 1));
588  }
589 
591 } // 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:32
void setMomentum(const TVector3 &momentum)
Set particle momentum.
Definition: MCParticle.h:414
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:387
void set4Vector(const TLorentzVector &p4)
Sets the 4Vector of particle.
Definition: MCParticle.h:435
void setMass(float mass)
Set particle mass.
Definition: MCParticle.h:363
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:546
void removeSeenInDetector(Const::DetectorSet set)
Unflag/Remove the bit if the MC particle is not seen in a specific subdetector.
Definition: MCParticle.h:480
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:499
float m_productionVertex_x
production vertex of particle, x component
Definition: MCParticle.h:535
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:545
float m_mass
mass of the particle
Definition: MCParticle.h:526
void setDecayVertex(float x, float y, float z)
Set decay vertex.
Definition: MCParticle.h:453
float m_decayVertex_z
decay vertex of particle, z component
Definition: MCParticle.h:542
virtual std::string getName() const override
Return name of this particle.
Definition: MCParticle.cc:107
void setProductionVertex(const TVector3 &vertex)
Set production vertex position.
Definition: MCParticle.h:393
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:426
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
Definition: MCParticle.h:350
void setEnergy(float energy)
Set energy.
Definition: MCParticle.h:369
Const::DetectorSet getSeenInDetector() const
Return the seen-in flags of the entire Belle II subdetectors for an MC particle.
Definition: MCParticle.h:300
float m_decayTime
decay time
Definition: MCParticle.h:539
void setDecayVertex(const TVector3 &vertex)
Set decay vertex.
Definition: MCParticle.h:441
void setProductionVertex(float x, float y, float z)
Set production vertex position.
Definition: MCParticle.h:405
bool hasSeenInDetector(Const::DetectorSet set) const
Return if the seen-in flag for a specific subdetector is set or not.
Definition: MCParticle.h:307
void setSeenInDetector(Const::DetectorSet set)
Set the seen-in flags for the entire Belle II subdetectors for an Monte Carlo particle.
Definition: MCParticle.h:468
float m_productionVertex_z
production vertex of particle, z component
Definition: MCParticle.h:537
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
Definition: MCParticle.cc:50
float getMass() const
Return the particle mass in GeV.
Definition: MCParticle.h:135
float m_energy
energy of the particle
Definition: MCParticle.h:527
static const double c_epsilon
limit of precision for two doubles to be the same.
Definition: MCParticle.h:547
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
Definition: MCParticle.h:129
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:244
virtual std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
Definition: MCParticle.cc:115
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:375
TVector3 getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition: MCParticle.h:183
TVector3 getMomentum() const
Return momentum.
Definition: MCParticle.h:198
float m_productionVertex_y
production vertex of particle, y component
Definition: MCParticle.h:536
int m_pdg
PDG-Code of the particle.
Definition: MCParticle.h:525
int m_mother
1-based index of the mother particle
Definition: MCParticle.h:544
float m_momentum_x
momentum of particle, x component
Definition: MCParticle.h:528
void setSecondaryPhysicsProcess(int physicsProcess)
Sets the physics process type of a secondary particle.
Definition: MCParticle.h:462
float m_decayVertex_x
decay vertex of particle, x component
Definition: MCParticle.h:540
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:65
void removeStatus(unsigned short int bitmask)
Remove bitmask from current status.
Definition: MCParticle.h:357
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:524
TVector3 getDecayVertex() const
Return decay vertex.
Definition: MCParticle.h:219
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:34
void setVirtual()
Set particle to virtual.
Definition: MCParticle.h:494
float m_momentum_z
momentum of particle, z component
Definition: MCParticle.h:530
MCParticle(TClonesArray *plist, const MCParticle &p)
Construct MCParticle from a another MCParticle and the TClonesArray it is stored in.
Definition: MCParticle.h:94
void fixParticleList() const
Search the DataStore for the corresponding MCParticle array.
Definition: MCParticle.cc:72
void setPDG(int pdg)
Set PDG code of the particle.
Definition: MCParticle.h:332
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:112
float getProductionTime() const
Return production time in ns.
Definition: MCParticle.h:159
int m_secondaryPhysicsProcess
physics process type of a secondary particle
Definition: MCParticle.h:549
TLorentzVector get4Vector() const
Return 4Vector of particle.
Definition: MCParticle.h:207
bool m_validVertex
indication wether vertex and time information is useful or just default
Definition: MCParticle.h:532
float m_productionTime
production time
Definition: MCParticle.h:534
int m_index
transient pointer to particle list
Definition: MCParticle.h:522
TVector3 getProductionVertex() const
Return production vertex position.
Definition: MCParticle.h:189
void setStatus(unsigned short int status)
Set Status code for the particle.
Definition: MCParticle.h:343
void addSeenInDetector(Const::DetectorSet set)
Flag/Add a bit if the MC particle is seen in a specific subdetector.
Definition: MCParticle.h:474
float m_momentum_y
momentum of particle, y component
Definition: MCParticle.h:529
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:551
TClonesArray * m_plist
Internal pointer to DataStore Array containing particles belonging to this collection.
Definition: MCParticle.h:516
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:381
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:26
float m_decayVertex_y
decay vertex of particle, y component
Definition: MCParticle.h:541
int getSecondaryPhysicsProcess() const
Returns the physics process type of a secondary particle.
Definition: MCParticle.h:294
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:572
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition: MCParticle.h:582
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Definition: MCParticle.h:577
bool isVirtual() const
Check if particle is virtual.
Definition: MCParticle.h:557
Abstract base class for different kinds of events.