Belle II Software light-2607-kasei
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
24namespace Belle2 {
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
67
68
73
96
101 int getPDG() const { return m_pdg; }
102
111 unsigned int getStatus(unsigned short int bitmask = USHRT_MAX) const { return m_status & bitmask; }
112
118 bool hasStatus(unsigned short int bitmask) const { return (m_status & bitmask) == bitmask; }
119
124 float getMass() const { return m_mass; }
125
130 float getCharge() const;
131
136 float getEnergy() const { return m_energy; }
137
142 bool hasValidVertex() const { return m_validVertex; }
143
148 float getProductionTime() const { return m_productionTime; }
149
157 float getDecayTime() const { return m_decayTime; }
158
166 float getLifetime() const { return m_decayTime - m_productionTime; }
167
172 ROOT::Math::XYZVector getVertex() const { return getProductionVertex(); }
173
178 ROOT::Math::XYZVector getProductionVertex() const
179 {
180 return ROOT::Math::XYZVector(m_productionVertex_x, m_productionVertex_y, m_productionVertex_z);
181 }
182
187 ROOT::Math::XYZVector getMomentum() const
188 {
189 return ROOT::Math::XYZVector(m_momentum_x, m_momentum_y, m_momentum_z);
190 }
191
196 ROOT::Math::PxPyPzEVector get4Vector() const
197 {
198 return ROOT::Math::PxPyPzEVector(m_momentum_x, m_momentum_y, m_momentum_z, m_energy);
199 }
200
201
208 ROOT::Math::XYZVector getDecayVertex() const
209 {
210 return ROOT::Math::XYZVector(m_decayVertex_x, m_decayVertex_y, m_decayVertex_z);
211 }
212
219 int getIndex() const { fixParticleList(); return m_index; }
220
233 // cppcheck-suppress duplInheritedMember ; intentionally hides the base class version
234 int getArrayIndex() const { fixParticleList(); return m_index - 1; }
235
241 int getFirstDaughter() const { return m_firstDaughter; }
242
243
249 int getLastDaughter() const { return m_lastDaughter; }
250
259 std::vector<Belle2::MCParticle*> getDaughters() const;
260 //Need namespace qualifier because ROOT CINT has troubles otherwise
261
263 const MCParticle* getDaughter(int i) const;
264
266 int getNDaughters() const;
267
274 MCParticle* getMother() const;
275
288
294
300 bool hasSeenInDetector(Const::DetectorSet set) const { return m_seenIn.contains(set); }
301
306 bool isVirtual() const;
307
312 bool isInitial() const;
313
319 bool isPrimaryParticle() const;
320
325 void setPDG(int pdg) { m_pdg = pdg; }
326
330 void setMassFromPDG();
331
336 void setStatus(unsigned short int status) { m_status = status; }
337
343 void addStatus(unsigned short int bitmask) { m_status |= bitmask; }
344
350 void removeStatus(unsigned short int bitmask) { m_status &= (~bitmask); }
351
356 void setMass(float mass) { m_mass = mass; }
357
362 void setEnergy(float energy) { m_energy = energy; }
363
368 void setValidVertex(bool valid) { m_validVertex = valid; }
369
374 void setProductionTime(float time) { m_productionTime = time; }
375
380 void setDecayTime(float time) { m_decayTime = time; }
381
386 void setProductionVertex(const ROOT::Math::XYZVector& vertex)
387 {
388 m_productionVertex_x = vertex.X(); m_productionVertex_y = vertex.Y(), m_productionVertex_z = vertex.Z();
389 }
390
398 void setProductionVertex(float x, float y, float z)
399 {
401 }
402
407 void setMomentum(const ROOT::Math::XYZVector& momentum)
408 {
409 m_momentum_x = momentum.X(); m_momentum_y = momentum.Y(), m_momentum_z = momentum.Z();
410 }
411
419 void setMomentum(float px, float py, float pz)
420 {
421 m_momentum_x = px, m_momentum_y = py; m_momentum_z = pz;
422 }
423
428 void set4Vector(const ROOT::Math::PxPyPzEVector& p4)
429 {
430 m_momentum_x = p4.px(); m_momentum_y = p4.py(); m_momentum_z = p4.pz(); m_energy = p4.energy();
431 }
432
437 void setDecayVertex(const ROOT::Math::XYZVector& vertex)
438 {
439 m_decayVertex_x = vertex.X(); m_decayVertex_y = vertex.Y(), m_decayVertex_z = vertex.Z();
440 }
441
449 void setDecayVertex(float x, float y, float z)
450 {
452 }
453
458 void setSecondaryPhysicsProcess(int physicsProcess) { m_secondaryPhysicsProcess = physicsProcess; }
459
465
471
477
485 void fixParticleList() const;
486
491
496
498 virtual std::string getName() const override;
499
501 virtual std::string getInfoHTML() const override;
502
511 const MCParticle* getParticleFromGeneralizedIndexString(const std::string& generalizedIndex) const;
512
513 protected:
514
522 TClonesArray* m_plist = nullptr;
523
528
529 float m_decayTime = 0;
530 float m_decayVertex_x = 0;
531 float m_decayVertex_y = 0;
532 float m_decayVertex_z = 0;
533
534 int m_pdg = 0;
535 float m_mass = 0;
536 float m_energy = 0;
537 float m_momentum_x = 0;
538 float m_momentum_y = 0;
539 float m_momentum_z = 0;
540
545 int m_index = 0;
546
547 int m_mother = 0;
550
552
553 unsigned short int m_status = 0;
554
555 bool m_validVertex = false;
556 static constexpr double c_epsilon = 10e-7;
557
559
561
562 friend class FixMergedObjectsModule;
563 };
564
565
566 inline bool MCParticle::isVirtual() const
567 {
568 bool virtuality = hasStatus(c_IsVirtual);
569 if (!virtuality) {
570 double E2 = static_cast<double>(m_energy) * m_energy;
571 double m2 = static_cast<double>(m_mass) * m_mass;
572 double p2 = static_cast<double>(m_momentum_x) * m_momentum_x;
573 p2 += static_cast<double>(m_momentum_y) * m_momentum_y;
574 p2 += static_cast<double>(m_momentum_z) * m_momentum_z;
575
576 virtuality = (fabs(E2 - (p2 + m2)) > c_epsilon * E2);
577 }
578 return virtuality;
579 }
580
581 inline bool MCParticle::isInitial() const
582 {
583 return hasStatus(c_Initial);
584 }
585
587 {
589 }
590
592 {
593 if (m_mother == 0)
594 return nullptr;
596 return static_cast<MCParticle*>(m_plist->At(m_mother - 1));
597 }
598
600} // end namespace Belle2
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition Const.h:80
A Class to store the Monte Carlo particle information.
Definition MCParticle.h:32
float getEnergy() const
Return particle energy in GeV.
Definition MCParticle.h:136
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 final 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:380
void setMass(float mass)
Set particle mass.
Definition MCParticle.h:356
void setDecayVertex(const ROOT::Math::XYZVector &vertex)
Set decay vertex.
Definition MCParticle.h:437
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
Definition MCParticle.h:549
void removeSeenInDetector(Const::DetectorSet set)
Unflag/Remove the bit if the MC particle is not seen in a specific subdetector.
Definition MCParticle.h:476
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition MCParticle.h:219
void setInitial()
Set particle to initial.
Definition MCParticle.h:495
ROOT::Math::XYZVector getDecayVertex() const
Return decay vertex.
Definition MCParticle.h:208
float m_productionVertex_x
production vertex of particle, x component
Definition MCParticle.h:525
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
Definition MCParticle.h:548
float m_mass
mass of the particle
Definition MCParticle.h:535
void setDecayVertex(float x, float y, float z)
Set decay vertex.
Definition MCParticle.h:449
float m_decayVertex_z
decay vertex of particle, z component
Definition MCParticle.h:532
virtual std::string getName() const override
Return name of this particle.
float getLifetime() const
Return the lifetime in ns.
Definition MCParticle.h:166
void setMomentum(float px, float py, float pz)
Set particle momentum.
Definition MCParticle.h:419
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
Definition MCParticle.h:343
void setEnergy(float energy)
Set energy.
Definition MCParticle.h:362
Const::DetectorSet getSeenInDetector() const
Return the seen-in flags of the entire Belle II subdetectors for an MC particle.
Definition MCParticle.h:293
float m_decayTime
decay time
Definition MCParticle.h:529
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...
void setProductionVertex(float x, float y, float z)
Set production vertex position.
Definition MCParticle.h:398
bool hasSeenInDetector(Const::DetectorSet set) const
Return if the seen-in flag for a specific subdetector is set or not.
Definition MCParticle.h:300
void setSeenInDetector(Const::DetectorSet set)
Set the seen-in flags for the entire Belle II subdetectors for an Monte Carlo particle.
Definition MCParticle.h:464
float m_productionVertex_z
production vertex of particle, z component
Definition MCParticle.h:527
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:124
float m_energy
energy of the particle
Definition MCParticle.h:536
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
Definition MCParticle.h:118
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
Definition MCParticle.h:172
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition MCParticle.h:234
ROOT::Math::XYZVector getProductionVertex() const
Return production vertex position.
Definition MCParticle.h:178
virtual std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
float getDecayTime() const
Return the decay time in ns.
Definition MCParticle.h:157
void setValidVertex(bool valid)
Set indication whether vertex and time information is valid or just default.
Definition MCParticle.h:368
float m_productionVertex_y
production vertex of particle, y component
Definition MCParticle.h:526
int m_pdg
PDG-Code of the particle.
Definition MCParticle.h:534
int m_mother
transient 1-based index of particle
Definition MCParticle.h:547
void setProductionVertex(const ROOT::Math::XYZVector &vertex)
Set production vertex position.
Definition MCParticle.h:386
float m_momentum_x
momentum of particle, x component
Definition MCParticle.h:537
void setSecondaryPhysicsProcess(int physicsProcess)
Sets the physics process type of a secondary particle.
Definition MCParticle.h:458
float m_decayVertex_x
decay vertex of particle, x component
Definition MCParticle.h:530
const MCParticle * getDaughter(int i) const
Return i-th daughter.
Definition MCParticle.cc:65
bool hasValidVertex() const
Indication whether vertex and time information is useful or just default.
Definition MCParticle.h:142
int getNDaughters() const
Return number of daughter MCParticles.
Definition MCParticle.cc:73
void removeStatus(unsigned short int bitmask)
Remove bitmask from current status.
Definition MCParticle.h:350
unsigned int getStatus(unsigned short int bitmask=USHRT_MAX) const
Return status code of particle.
Definition MCParticle.h:111
unsigned short int m_status
status code
Definition MCParticle.h:553
int getLastDaughter() const
Get 1-based index of last daughter, 0 if no daughters.
Definition MCParticle.h:249
float getCharge() const
Return the particle charge defined in TDatabasePDG.
Definition MCParticle.cc:34
void setVirtual()
Set particle to virtual.
Definition MCParticle.h:490
float m_momentum_z
momentum of particle, z component
Definition MCParticle.h:539
MCParticle(TClonesArray *plist, const MCParticle &p)
Construct MCParticle from a another MCParticle and the TClonesArray it is stored in.
Definition MCParticle.h:82
ROOT::Math::PxPyPzEVector get4Vector() const
Return 4Vector of particle.
Definition MCParticle.h:196
void fixParticleList() const
Search the DataStore for the corresponding MCParticle array.
Definition MCParticle.cc:80
void setPDG(int pdg)
Set PDG code of the particle.
Definition MCParticle.h:325
int getPDG() const
Return PDG code of particle.
Definition MCParticle.h:101
float getProductionTime() const
Return production time in ns.
Definition MCParticle.h:148
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets the 4Vector of particle.
Definition MCParticle.h:428
int m_secondaryPhysicsProcess
physics process type of a secondary particle
Definition MCParticle.h:551
ROOT::Math::XYZVector getMomentum() const
Return momentum.
Definition MCParticle.h:187
bool m_validVertex
indication whether vertex and time information is useful or just default
Definition MCParticle.h:555
void setMomentum(const ROOT::Math::XYZVector &momentum)
Set particle momentum.
Definition MCParticle.h:407
float m_productionTime
transient pointer to particle list
Definition MCParticle.h:524
static constexpr double c_epsilon
limit of precision for two doubles to be the same.
Definition MCParticle.h:556
int m_index
1-based index of the particle, will be set automatically after deserialisation if needed.
Definition MCParticle.h:545
void setStatus(unsigned short int status)
Set Status code for the particle.
Definition MCParticle.h:336
void addSeenInDetector(Const::DetectorSet set)
Flag/Add a bit if the MC particle is seen in a specific subdetector.
Definition MCParticle.h:470
float m_momentum_y
momentum of particle, y component
Definition MCParticle.h:538
MCParticle()
Default constructor for ROOT.
Definition MCParticle.h:72
ClassDefOverride(MCParticle, 6)
A Class to store the Monte Carlo particle information.
Const::DetectorSet m_seenIn
Each bit is a seen-in flag for the corresoponding subdetector of Belle II.
Definition MCParticle.h:558
TClonesArray * m_plist
Internal pointer to DataStore Array containing particles belonging to this collection.
Definition MCParticle.h:522
int getFirstDaughter() const
Get 1-based index of first daughter, 0 if no daughters.
Definition MCParticle.h:241
void setProductionTime(float time)
Set production time.
Definition MCParticle.h:374
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:531
int getSecondaryPhysicsProcess() const
Returns the physics process type of a secondary particle.
Definition MCParticle.h:287
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
bool isInitial() const
Check if particle is an initial particle such as ISR.
Definition MCParticle.h:581
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition MCParticle.h:591
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Definition MCParticle.h:586
bool isVirtual() const
Check if particle is virtual.
Definition MCParticle.h:566
Abstract base class for different kinds of events.