Belle II Software development
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
45 enum StatusBit {
55 c_IsVirtual = 1 << 4,
57 c_Initial = 1 << 5,
59 c_IsISRPhoton = 1 << 6,
61 c_IsFSRPhoton = 1 << 7,
66 };
67
68
73
82 MCParticle(TClonesArray* plist, const MCParticle& p):
83 m_plist(plist),
95 m_seenIn(p.m_seenIn) {}
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 int getArrayIndex() const { fixParticleList(); return m_index - 1; }
234
240 int getFirstDaughter() const { return m_firstDaughter; }
241
242
248 int getLastDaughter() const { return m_lastDaughter; }
249
258 std::vector<Belle2::MCParticle*> getDaughters() const;
259 //Need namespace qualifier because ROOT CINT has troubles otherwise
260
262 const MCParticle* getDaughter(int i) const;
263
265 int getNDaughters() const;
266
273 MCParticle* getMother() const;
274
287
293
299 bool hasSeenInDetector(Const::DetectorSet set) const { return m_seenIn.contains(set); }
300
305 bool isVirtual() const;
306
311 bool isInitial() const;
312
318 bool isPrimaryParticle() const;
319
324 void setPDG(int pdg) { m_pdg = pdg; }
325
329 void setMassFromPDG();
330
335 void setStatus(unsigned short int status) { m_status = status; }
336
342 void addStatus(unsigned short int bitmask) { m_status |= bitmask; }
343
349 void removeStatus(unsigned short int bitmask) { m_status &= (~bitmask); }
350
355 void setMass(float mass) { m_mass = mass; }
356
361 void setEnergy(float energy) { m_energy = energy; }
362
367 void setValidVertex(bool valid) { m_validVertex = valid; }
368
373 void setProductionTime(float time) { m_productionTime = time; }
374
379 void setDecayTime(float time) { m_decayTime = time; }
380
385 void setProductionVertex(const ROOT::Math::XYZVector& vertex)
386 {
387 m_productionVertex_x = vertex.X(); m_productionVertex_y = vertex.Y(), m_productionVertex_z = vertex.Z();
388 }
389
397 void setProductionVertex(float x, float y, float z)
398 {
400 }
401
406 void setMomentum(const ROOT::Math::XYZVector& momentum)
407 {
408 m_momentum_x = momentum.X(); m_momentum_y = momentum.Y(), m_momentum_z = momentum.Z();
409 }
410
418 void setMomentum(float px, float py, float pz)
419 {
420 m_momentum_x = px, m_momentum_y = py; m_momentum_z = pz;
421 }
422
427 void set4Vector(const ROOT::Math::PxPyPzEVector& p4)
428 {
429 m_momentum_x = p4.px(); m_momentum_y = p4.py(); m_momentum_z = p4.pz(); m_energy = p4.energy();
430 }
431
436 void setDecayVertex(const ROOT::Math::XYZVector& vertex)
437 {
438 m_decayVertex_x = vertex.X(); m_decayVertex_y = vertex.Y(), m_decayVertex_z = vertex.Z();
439 }
440
448 void setDecayVertex(float x, float y, float z)
449 {
451 }
452
457 void setSecondaryPhysicsProcess(int physicsProcess) { m_secondaryPhysicsProcess = physicsProcess; }
458
464
470
476
484 void fixParticleList() const;
485
490
495
497 virtual std::string getName() const override;
498
500 virtual std::string getInfoHTML() const override;
501
510 const MCParticle* getParticleFromGeneralizedIndexString(const std::string& generalizedIndex) const;
511
512 protected:
513
521 TClonesArray* m_plist = nullptr;
522
528 float m_decayTime = 0;
529 float m_decayVertex_x = 0;
530 float m_decayVertex_y = 0;
531 float m_decayVertex_z = 0;
533 int m_pdg = 0;
534 float m_mass = 0;
535 float m_energy = 0;
536 float m_momentum_x = 0;
537 float m_momentum_y = 0;
538 float m_momentum_z = 0;
544 int m_index = 0;
545
546 int m_mother = 0;
552 unsigned short int m_status = 0;
554 bool m_validVertex = false;
555 static const double c_epsilon;
561 friend class FixMergedObjectsModule;
562 };
563
564
565 inline bool MCParticle::isVirtual() const
566 {
567 bool virtuality = hasStatus(c_IsVirtual);
568 if (!virtuality) {
569 double E2 = m_energy * m_energy;
570 double m2 = m_mass * m_mass;
571 double p2 = m_momentum_x * m_momentum_x;
574
575 virtuality = (fabs(E2 - (p2 + m2)) > c_epsilon * E2);
576 }
577 return virtuality;
578 }
579
580 inline bool MCParticle::isInitial() const
581 {
582 return hasStatus(c_Initial);
583 }
584
586 {
588 }
589
591 {
592 if (m_mother == 0)
593 return nullptr;
595 return static_cast<MCParticle*>(m_plist->At(m_mother - 1));
596 }
597
599} // end namespace Belle2
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:80
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:235
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: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:379
void setMass(float mass)
Set particle mass.
Definition: MCParticle.h:355
void setDecayVertex(const ROOT::Math::XYZVector &vertex)
Set decay vertex.
Definition: MCParticle.h:436
int m_lastDaughter
1-based index of last daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:548
void removeSeenInDetector(Const::DetectorSet set)
Unflag/Remove the bit if the MC particle is not seen in a specific subdetector.
Definition: MCParticle.h:475
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:494
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:524
int m_firstDaughter
1-based index of first daughter particle in collection, 0 if no daughters
Definition: MCParticle.h:547
float m_mass
mass of the particle
Definition: MCParticle.h:534
void setDecayVertex(float x, float y, float z)
Set decay vertex.
Definition: MCParticle.h:448
float m_decayVertex_z
decay vertex of particle, z component
Definition: MCParticle.h:531
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:166
void setMomentum(float px, float py, float pz)
Set particle momentum.
Definition: MCParticle.h:418
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
Definition: MCParticle.h:342
void setEnergy(float energy)
Set energy.
Definition: MCParticle.h:361
Const::DetectorSet getSeenInDetector() const
Return the seen-in flags of the entire Belle II subdetectors for an MC particle.
Definition: MCParticle.h:292
float m_decayTime
decay time
Definition: MCParticle.h:528
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:397
bool hasSeenInDetector(Const::DetectorSet set) const
Return if the seen-in flag for a specific subdetector is set or not.
Definition: MCParticle.h:299
void setSeenInDetector(Const::DetectorSet set)
Set the seen-in flags for the entire Belle II subdetectors for an Monte Carlo particle.
Definition: MCParticle.h:463
float m_productionVertex_z
production vertex of particle, z component
Definition: MCParticle.h:526
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:124
float m_energy
energy of the particle
Definition: MCParticle.h:535
static const double c_epsilon
limit of precision for two doubles to be the same.
Definition: MCParticle.h:555
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:233
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.
Definition: MCParticle.cc:125
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:367
float m_productionVertex_y
production vertex of particle, y component
Definition: MCParticle.h:525
int m_pdg
PDG-Code of the particle.
Definition: MCParticle.h:533
int m_mother
transient 1-based index of particle
Definition: MCParticle.h:546
void setProductionVertex(const ROOT::Math::XYZVector &vertex)
Set production vertex position.
Definition: MCParticle.h:385
float m_momentum_x
momentum of particle, x component
Definition: MCParticle.h:536
void setSecondaryPhysicsProcess(int physicsProcess)
Sets the physics process type of a secondary particle.
Definition: MCParticle.h:457
float m_decayVertex_x
decay vertex of particle, x component
Definition: MCParticle.h:529
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:142
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:349
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:552
int getLastDaughter() const
Get 1-based index of last daughter, 0 if no daughters.
Definition: MCParticle.h:248
float getCharge() const
Return the particle charge defined in TDatabasePDG.
Definition: MCParticle.cc:36
void setVirtual()
Set particle to virtual.
Definition: MCParticle.h:489
float m_momentum_z
momentum of particle, z component
Definition: MCParticle.h:538
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:82
void setPDG(int pdg)
Set PDG code of the particle.
Definition: MCParticle.h:324
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:427
int m_secondaryPhysicsProcess
physics process type of a secondary particle
Definition: MCParticle.h:550
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:554
void setMomentum(const ROOT::Math::XYZVector &momentum)
Set particle momentum.
Definition: MCParticle.h:406
float m_productionTime
transient pointer to particle list
Definition: MCParticle.h:523
int m_index
1-based index of the particle, will be set automatically after deserialisation if needed.
Definition: MCParticle.h:544
void setStatus(unsigned short int status)
Set Status code for the particle.
Definition: MCParticle.h:335
void addSeenInDetector(Const::DetectorSet set)
Flag/Add a bit if the MC particle is seen in a specific subdetector.
Definition: MCParticle.h:469
float m_momentum_y
momentum of particle, y component
Definition: MCParticle.h:537
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:557
TClonesArray * m_plist
Internal pointer to DataStore Array containing particles belonging to this collection.
Definition: MCParticle.h:521
int getFirstDaughter() const
Get 1-based index of first daughter, 0 if no daughters.
Definition: MCParticle.h:240
void setProductionTime(float time)
Set production time.
Definition: MCParticle.h:373
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:530
int getSecondaryPhysicsProcess() const
Returns the physics process type of a secondary particle.
Definition: MCParticle.h:286
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:580
MCParticle * getMother() const
Returns a pointer to the mother particle.
Definition: MCParticle.h:590
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Definition: MCParticle.h:585
bool isVirtual() const
Check if particle is virtual.
Definition: MCParticle.h:565
Abstract base class for different kinds of events.