Belle II Software  release-05-02-19
MCParticle.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef MCPARTICLE_H
12 #define MCPARTICLE_H
13 
14 #include <framework/gearbox/Const.h>
15 #include <framework/core/FrameworkExceptions.h>
16 #include <framework/datastore/RelationsObject.h>
17 
18 #include <TClonesArray.h>
19 #include <TVector3.h>
20 #include <TLorentzVector.h>
21 
22 #include <cmath>
23 #include <climits>
24 #include <vector>
25 
26 
27 namespace Belle2 {
35  class MCParticle: public RelationsObject {
36  public:
37 
38  //Define exceptions
40  BELLE2_DEFINE_EXCEPTION(LastChildIndexOutOfRangError, "Last child index out of range!")
42  BELLE2_DEFINE_EXCEPTION(NoParticleListSetError, "No Particle list set, cannot determine related particles!")
44  BELLE2_DEFINE_EXCEPTION(ParticlePDGNotKnownError, "The pdg value (%1%) of the MCParticle is not known!")
45 
46 
48  enum StatusBit {
50  c_PrimaryParticle = 1 << 0,
52  c_StableInGenerator = 1 << 1,
54  c_LeftDetector = 1 << 2,
58  c_IsVirtual = 1 << 4,
60  c_Initial = 1 << 5,
62  c_IsISRPhoton = 1 << 6,
64  c_IsFSRPhoton = 1 << 7,
66  c_IsPHOTOSPhoton = 1 << 8,
69  };
70 
71 
75  MCParticle():
76  m_plist(0), m_index(0), m_status(0),
77  m_pdg(0), m_mass(0), m_energy(0),
84  m_mother(0),
87  m_seenIn() {}
88 
97  MCParticle(TClonesArray* plist, const MCParticle& p):
98  m_plist(plist), m_index(p.m_index), m_status(p.m_status),
106  m_mother(p.m_mother),
109  m_seenIn(p.m_seenIn) {}
110 
115  int getPDG() const { return m_pdg; }
116 
125  unsigned int getStatus(unsigned short int bitmask = USHRT_MAX) const { return m_status & bitmask; }
126 
132  bool hasStatus(unsigned short int bitmask) const { return (m_status & bitmask) == bitmask; }
133 
138  float getMass() const { return m_mass; }
139 
144  float getCharge() const;
145 
150  float getEnergy() const { return m_energy; }
151 
156  bool hasValidVertex() const { return m_validVertex; }
157 
162  float getProductionTime() const { return m_productionTime; }
163 
171  float getDecayTime() const { return m_decayTime; }
172 
180  float getLifetime() const { return m_decayTime - m_productionTime; }
181 
186  TVector3 getVertex() const { return getProductionVertex(); }
187 
192  TVector3 getProductionVertex() const
193  {
195  }
196 
201  TVector3 getMomentum() const
202  {
203  return TVector3(m_momentum_x, m_momentum_y, m_momentum_z);
204  }
205 
210  TLorentzVector get4Vector() const
211  {
212  TLorentzVector vec; vec.SetXYZM(m_momentum_x, m_momentum_y, m_momentum_z, m_mass); return vec;
213  }
214 
215 
222  TVector3 getDecayVertex() const
223  {
225  }
226 
233  int getIndex() const { fixParticleList(); return m_index; }
234 
247  int getArrayIndex() const { fixParticleList(); return m_index - 1; }
248 
254  int getFirstDaughter() const { return m_firstDaughter; }
255 
256 
262  int getLastDaughter() const { return m_lastDaughter; }
263 
272  std::vector<Belle2::MCParticle*> getDaughters() const;
273  //Need namespace qualifier because ROOT CINT has troubles otherwise
274 
276  int getNDaughters() const;
277 
284  MCParticle* getMother() const;
285 
298 
303  Const::DetectorSet getSeenInDetector() const { return m_seenIn; }
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 TVector3& 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 TVector3& 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 TLorentzVector& p4) { setMomentum(p4.Vect()); m_energy = p4.Energy(); }
439 
444  void setDecayVertex(const TVector3& vertex)
445  {
446  m_decayVertex_x = vertex.X(); m_decayVertex_y = vertex.Y(), m_decayVertex_z = vertex.Z();
447  }
448 
456  void setDecayVertex(float x, float y, float z)
457  {
459  }
460 
465  void setSecondaryPhysicsProcess(int physicsProcess) { m_secondaryPhysicsProcess = physicsProcess; }
466 
471  void setSeenInDetector(Const::DetectorSet set) { m_seenIn = set; }
472 
477  void addSeenInDetector(Const::DetectorSet set) { m_seenIn += set; }
478 
483  void removeSeenInDetector(Const::DetectorSet set) { m_seenIn -= set; }
484 
492  void fixParticleList() const;
493 
497  void setVirtual() { addStatus(c_IsVirtual); }
498 
502  void setInitial() { addStatus(c_Initial); }
503 
505  virtual std::string getName() const;
506 
508  virtual std::string getInfoHTML() const;
509 
510  protected:
511 
519  TClonesArray* m_plist;
520 
525  int m_index;
526 
527  unsigned short int m_status;
528  int m_pdg;
529  float m_mass;
530  float m_energy;
531  float m_momentum_x;
532  float m_momentum_y;
533  float m_momentum_z;
542  float m_decayTime;
544  float m_decayVertex_y;
547  int m_mother;
549  int m_lastDaughter;
550  static const double c_epsilon;
557  };
558 
559 
560  inline bool MCParticle::isVirtual() const
561  {
562  bool virtuality = hasStatus(c_IsVirtual);
563  if (!virtuality) {
564  double E2 = m_energy * m_energy;
565  double m2 = m_mass * m_mass;
566  double p2 = m_momentum_x * m_momentum_x;
567  p2 += m_momentum_y * m_momentum_y;
569 
570  virtuality = (fabs(E2 - (p2 + m2)) > c_epsilon * E2);
571  }
572  return virtuality;
573  }
574 
575  inline bool MCParticle::isInitial() const
576  {
577  return hasStatus(c_Initial);
578  }
579 
580  inline bool MCParticle::isPrimaryParticle() const
581  {
583  }
584 
585  inline MCParticle* MCParticle::getMother() const
586  {
587  if (m_mother == 0) return NULL;
589  return static_cast<MCParticle*>(m_plist->At(m_mother - 1));
590  }
591 
593 } // end namespace Belle2
594 
595 #endif
Belle2::MCParticle::getFirstDaughter
int getFirstDaughter() const
Get 1-based index of first daughter, 0 if no daughters.
Definition: MCParticle.h:262
Belle2::MCParticle::getIndex
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:241
Belle2::MCParticle::getEnergy
float getEnergy() const
Return particle energy in GeV.
Definition: MCParticle.h:158
Belle2::MCParticle::m_productionVertex_y
float m_productionVertex_y
production vertex of particle, y component
Definition: MCParticle.h:547
Belle2::MCParticle::m_lastDaughter
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:557
Belle2::MCParticle::c_StoppedInDetector
@ c_StoppedInDetector
bit 3: Particle was stopped in the detector (the simulation volume).
Definition: MCParticle.h:64
Belle2::MCParticle::getCharge
float getCharge() const
Return the particle charge defined in TDatabasePDG.
Definition: MCParticle.cc:35
Belle2::MCParticle::c_IsPHOTOSPhoton
@ c_IsPHOTOSPhoton
bit 8: Particle is an radiative photon from PHOTOS
Definition: MCParticle.h:74
Belle2::MCParticle::getInfoHTML
virtual std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
Definition: MCParticle.cc:116
Belle2::MCParticle::getDecayTime
float getDecayTime() const
Return the decay time in ns.
Definition: MCParticle.h:179
Belle2::MCParticle::StatusBit
StatusBit
Exception is thrown if the requested index for the last child is out of range.
Definition: MCParticle.h:56
Belle2::MCParticle::setMassFromPDG
void setMassFromPDG()
Sets the mass for the particle from the particle's PDG code.
Definition: MCParticle.cc:28
Belle2::MCParticle::m_plist
TClonesArray * m_plist
Internal pointer to DataStore Array containing particles belonging to this collection.
Definition: MCParticle.h:527
Belle2::MCParticle::setSeenInDetector
void setSeenInDetector(Const::DetectorSet set)
Set the seen-in flags for the entire Belle II subdetectors for an Monte Carlo particle.
Definition: MCParticle.h:479
Belle2::MCParticle::fixParticleList
void fixParticleList() const
Search the DataStore for the corresponding MCParticle array.
Definition: MCParticle.cc:73
Belle2::MCParticle::c_IsFSRPhoton
@ c_IsFSRPhoton
bit 7: Particle is from finial state radiation
Definition: MCParticle.h:72
Belle2::MCParticle::m_decayVertex_y
float m_decayVertex_y
decay vertex of particle, y component
Definition: MCParticle.h:552
Belle2::MCParticle::c_IsVirtual
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
Definition: MCParticle.h:66
Belle2::MCParticle::m_productionVertex_x
float m_productionVertex_x
production vertex of particle, x component
Definition: MCParticle.h:546
Belle2::MCParticle::c_IsISRPhoton
@ c_IsISRPhoton
bit 6: Particle is from initial state radiation
Definition: MCParticle.h:70
Belle2::MCParticle::setVirtual
void setVirtual()
Set particle to virtual.
Definition: MCParticle.h:505
Belle2::MCParticle::setDecayVertex
void setDecayVertex(const TVector3 &vertex)
Set decay vertex.
Definition: MCParticle.h:452
Belle2::MCParticle::m_productionVertex_z
float m_productionVertex_z
production vertex of particle, z component
Definition: MCParticle.h:548
Belle2::MCParticle::hasSeenInDetector
bool hasSeenInDetector(Const::DetectorSet set) const
Return if the seen-in flag for a specific subdetector is set or not.
Definition: MCParticle.h:318
Belle2::MCParticle::setStatus
void setStatus(unsigned short int status)
Set Status code for the particle.
Definition: MCParticle.h:354
Belle2::Const::DetectorSet
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:66
Belle2::MCParticle::removeSeenInDetector
void removeSeenInDetector(Const::DetectorSet set)
Unflag/Remove the bit if the MC particle is not seen in a specific subdetector.
Definition: MCParticle.h:491
Belle2::MCParticle::getArrayIndex
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:255
Belle2::MCParticle::getSecondaryPhysicsProcess
int getSecondaryPhysicsProcess() const
Returns the physics process type of a secondary particle.
Definition: MCParticle.h:305
Belle2::MCParticle::setInitial
void setInitial()
Set particle to initial.
Definition: MCParticle.h:510
Belle2::MCParticle::isPrimaryParticle
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Definition: MCParticle.h:588
Belle2::MCParticle::c_LeftDetector
@ c_LeftDetector
bit 2: Particle left the detector (the simulation volume).
Definition: MCParticle.h:62
Belle2::MCParticle::addSeenInDetector
void addSeenInDetector(Const::DetectorSet set)
Flag/Add a bit if the MC particle is seen in a specific subdetector.
Definition: MCParticle.h:485
Belle2::MCParticle::isInitial
bool isInitial() const
Check if particle is an initial particle such as ISR.
Definition: MCParticle.h:583
Belle2::MCParticle::getDecayVertex
TVector3 getDecayVertex() const
Return decay vertex.
Definition: MCParticle.h:230
Belle2::MCParticle::hasValidVertex
bool hasValidVertex() const
Indication whether vertex and time information is useful or just default.
Definition: MCParticle.h:164
Belle2::MCParticle::getName
virtual std::string getName() const
Return name of this particle.
Definition: MCParticle.cc:108
Belle2::MCParticle::m_momentum_x
float m_momentum_x
momentum of particle, x component
Definition: MCParticle.h:539
Belle2::MCParticle::hasStatus
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
Definition: MCParticle.h:140
Belle2::MCParticle::getStatus
unsigned int getStatus(unsigned short int bitmask=USHRT_MAX) const
Return status code of particle.
Definition: MCParticle.h:133
Belle2::MCParticle::setProductionTime
void setProductionTime(float time)
Set production time.
Definition: MCParticle.h:392
Belle2::MCParticle::m_mass
float m_mass
mass of the particle
Definition: MCParticle.h:537
Belle2::MCParticle::m_decayVertex_x
float m_decayVertex_x
decay vertex of particle, x component
Definition: MCParticle.h:551
Belle2::MCParticle::m_decayVertex_z
float m_decayVertex_z
decay vertex of particle, z component
Definition: MCParticle.h:553
Belle2::MCParticle::setSecondaryPhysicsProcess
void setSecondaryPhysicsProcess(int physicsProcess)
Sets the physics process type of a secondary particle.
Definition: MCParticle.h:473
Belle2::MCParticle::m_decayTime
float m_decayTime
decay time
Definition: MCParticle.h:550
Belle2::MCParticle::m_firstDaughter
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:556
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCParticle::getVertex
TVector3 getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition: MCParticle.h:194
Belle2::MCParticle::m_status
unsigned short int m_status
transient 1-based index of particle
Definition: MCParticle.h:535
Belle2::MCParticle::setPDG
void setPDG(int pdg)
Set PDG code of the particle.
Definition: MCParticle.h:343
Belle2::MCParticle::c_Initial
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
Definition: MCParticle.h:68
Belle2::MCParticle::m_momentum_z
float m_momentum_z
momentum of particle, z component
Definition: MCParticle.h:541
Belle2::MCParticle::getProductionVertex
TVector3 getProductionVertex() const
Return production vertex position.
Definition: MCParticle.h:200
Belle2::MCParticle::getPDG
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:123
Belle2::MCParticle::setProductionVertex
void setProductionVertex(const TVector3 &vertex)
Set production vertex position.
Definition: MCParticle.h:404
Belle2::MCParticle::addStatus
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
Definition: MCParticle.h:361
Belle2::MCParticle::getMass
float getMass() const
Return the particle mass in GeV.
Definition: MCParticle.h:146
Belle2::MCParticle::getMother
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition: MCParticle.h:593
Belle2::MCParticle::getLastDaughter
int getLastDaughter() const
Get 1-based index of last daughter, 0 if no daughters.
Definition: MCParticle.h:270
Belle2::MCParticle::isVirtual
bool isVirtual() const
Check if particle is virtual.
Definition: MCParticle.h:568
Belle2::MCParticle::m_index
int m_index
transient pointer to particle list
Definition: MCParticle.h:533
Belle2::MCParticle::getSeenInDetector
Const::DetectorSet getSeenInDetector() const
Return the seen-in flags of the entire Belle II subdetectors for an MC particle.
Definition: MCParticle.h:311
Belle2::MCParticle::c_StableInGenerator
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:60
Belle2::MCParticle::removeStatus
void removeStatus(unsigned short int bitmask)
Remove bitmask from current status.
Definition: MCParticle.h:368
Belle2::MCParticle::MCParticle
MCParticle()
Default constructor for ROOT.
Definition: MCParticle.h:83
Belle2::MCParticle::getDaughters
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
Definition: MCParticle.cc:51
Belle2::MCParticle::c_IsRadiativePhoton
@ c_IsRadiativePhoton
combined flag to test whether the particle is radiative
Definition: MCParticle.h:76
Belle2::MCParticle::setEnergy
void setEnergy(float energy)
Set energy.
Definition: MCParticle.h:380
Belle2::MCParticle::m_pdg
int m_pdg
PDG-Code of the particle.
Definition: MCParticle.h:536
Belle2::MCParticle::get4Vector
TLorentzVector get4Vector() const
Return 4Vector of particle.
Definition: MCParticle.h:218
Belle2::MCParticle::m_seenIn
Const::DetectorSet m_seenIn
Each bit is a seen-in flag for the corresoponding subdetector of Belle II.
Definition: MCParticle.h:562
Belle2::RelationsObject
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
Definition: RelationsObject.h:443
Belle2::MCParticle::getLifetime
float getLifetime() const
Return the lifetime in ns.
Definition: MCParticle.h:188
Belle2::MCParticle::m_productionTime
float m_productionTime
production time
Definition: MCParticle.h:545
Belle2::MCParticle::getMomentum
TVector3 getMomentum() const
Return momentum.
Definition: MCParticle.h:209
Belle2::MCParticle::setMass
void setMass(float mass)
Set particle mass.
Definition: MCParticle.h:374
Belle2::MCParticle::set4Vector
void set4Vector(const TLorentzVector &p4)
Sets the 4Vector of particle.
Definition: MCParticle.h:446
Belle2::Const::DetectorSet::contains
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:116
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::MCParticle::c_epsilon
static const double c_epsilon
limit of precision for two doubles to be the same.
Definition: MCParticle.h:558
BELLE2_DEFINE_EXCEPTION
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Definition: FrameworkExceptions.h:46
Belle2::MCParticle::getNDaughters
int getNDaughters() const
Return number of daughter MCParticles.
Definition: MCParticle.cc:66
Belle2::MCParticle::setDecayTime
void setDecayTime(float time)
Set decay time.
Definition: MCParticle.h:398
Belle2::MCParticle::m_energy
float m_energy
energy of the particle
Definition: MCParticle.h:538
Belle2::MCParticle::m_validVertex
bool m_validVertex
indication wether vertex and time information is useful or just default
Definition: MCParticle.h:543
Belle2::MCParticle::setMomentum
void setMomentum(const TVector3 &momentum)
Set particle momentum.
Definition: MCParticle.h:425
Belle2::MCParticle::m_secondaryPhysicsProcess
int m_secondaryPhysicsProcess
physics process type of a secondary particle
Definition: MCParticle.h:560
Belle2::MCParticle::setValidVertex
void setValidVertex(bool valid)
Set indication wether vertex and time information is valid or just default.
Definition: MCParticle.h:386
Belle2::MCParticle::c_PrimaryParticle
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:58
Belle2::MCParticle::getProductionTime
float getProductionTime() const
Return production time in ns.
Definition: MCParticle.h:170
Belle2::MCParticle::m_mother
int m_mother
1-based index of the mother particle
Definition: MCParticle.h:555
Belle2::MCParticle::m_momentum_y
float m_momentum_y
momentum of particle, y component
Definition: MCParticle.h:540
Belle2::MCParticle::ClassDef
ClassDef(MCParticle, 5)
A Class to store the Monte Carlo particle information.