SHiP Data Model
Event data model for the SHiP experiment: C++ data classes with ROOT dictionary support.
Loading...
Searching...
No Matches
MCParticle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <cstdint>
6#include <vector>
7
8namespace SHiP {
9
48struct MCParticle {
49 std::int32_t pdg_code{0};
50 std::array<double, 3> vertex{0, 0, 0};
51 std::array<double, 3> momentum{0, 0, 0};
52 double energy{0};
53 double time{0};
54 std::int32_t mother_id{-1};
55 std::vector<std::int32_t> mothers{};
56 std::int32_t status{1};
57
58 bool operator==(MCParticle const&) const = default;
59};
60
68inline bool mothers_are_consistent(std::vector<MCParticle> const& particles) {
69 auto const size = static_cast<std::int32_t>(particles.size());
70 for (std::int32_t i = 0; i < size; ++i) {
71 auto const& mothers = particles[i].mothers;
72 if (particles[i].mother_id < -1 || particles[i].mother_id >= size) {
73 return false;
74 }
75 if (mothers.empty()) {
76 continue;
77 }
78 if (mothers.front() != particles[i].mother_id) {
79 return false;
80 }
81 for (auto m = mothers.begin(); m != mothers.end(); ++m) {
82 if (*m < 0 || *m >= size || *m == i) {
83 return false;
84 }
85 // Mother lists hold a handful of entries at most, so scanning the
86 // prefix already seen beats allocating a set.
87 if (std::find(mothers.begin(), m, *m) != m) {
88 return false;
89 }
90 }
91 }
92 return true;
93}
94
101inline bool mothers_are_populated(std::vector<MCParticle> const& particles) {
102 for (auto const& p : particles) {
103 if (p.mother_id >= 0 && p.mothers.empty()) {
104 return false;
105 }
106 }
107 return mothers_are_consistent(particles);
108}
109
110} // namespace SHiP
Canonical ShipSoft unit vocabulary.
Definition CaloHit.hpp:4
bool mothers_are_consistent(std::vector< MCParticle > const &particles)
True when the mother indices of a whole collection are self-consistent, i.e.
Definition MCParticle.hpp:68
bool mothers_are_populated(std::vector< MCParticle > const &particles)
True when, on top of mothers_are_consistent(), every entry that has a mother carries the full list — ...
Definition MCParticle.hpp:101
Monte Carlo particle — input to simulation.
Definition MCParticle.hpp:48
bool operator==(MCParticle const &) const =default
std::array< double, 3 > vertex
Production vertex [mm].
Definition MCParticle.hpp:50
double time
Production time [ns].
Definition MCParticle.hpp:53
std::int32_t status
HepMC status (see above)
Definition MCParticle.hpp:56
std::array< double, 3 > momentum
Momentum (px, py, pz) [GeV/c].
Definition MCParticle.hpp:51
double energy
Total energy [GeV].
Definition MCParticle.hpp:52
std::int32_t mother_id
First mother (-1 = none)
Definition MCParticle.hpp:54
std::vector< std::int32_t > mothers
All mothers (see above)
Definition MCParticle.hpp:55
std::int32_t pdg_code
Definition MCParticle.hpp:49