3 #include "HepMC/GenEvent.h"
4 #include "HepMC/Units.h"
5 #include "HepPDT/ParticleDataTable.hh"
25 genParticleIterator_(genEvent_->particles_begin()),
26 genParticleEnd_(genEvent_->particles_end()),
28 particleDataTable_(&particleDataTable),
43 momentumUnitConversionFactor_(conversion_factor(genEvent_->momentum_unit(),
HepMC::Units::GEV)),
44 lengthUnitConversionFactor_(conversion_factor(genEvent_->length_unit(),
HepMC::Units::LengthUnit::CM)),
45 lengthUnitConversionFactor2_(lengthUnitConversionFactor_ * lengthUnitConversionFactor_),
63 std::unique_ptr<fastsim::Particle> particle;
66 if (!particleBuffer_.empty()) {
67 particle =
std::move(particleBuffer_.back());
68 particleBuffer_.pop_back();
72 particle = nextGenParticle();
78 if (!particleFilter_->accepts(*particle)) {
79 return nextParticle(random);
83 if (!particle->remainingProperLifeTimeIsSet() || !particle->chargeIsSet()) {
89 particle->setRemainingProperLifeTimeC(0.);
90 particle->setCharge(0.);
94 if (!particle->remainingProperLifeTimeIsSet()) {
97 double width = particleData->totalWidth().value();
99 particle->setRemainingProperLifeTimeC(-
log(random.
flatShoot()) * 6.582119
e-25 /
width / 10.);
101 particle->setStable();
106 if (!particle->chargeIsSet()) {
107 particle->setCharge(particleData->charge());
112 unsigned simTrackIndex = addSimTrack(particle.get());
113 particle->setSimTrackIndex(simTrackIndex);
120 int parentSimTrackIndex,
121 std::vector<std::unique_ptr<Particle> >& secondaries,
124 if (!particleFilter_->acceptsVtx(vertexPosition)) {
129 if (secondaries.empty()) {
134 unsigned simVertexIndex = addSimVertex(vertexPosition, parentSimTrackIndex);
141 for (
auto& secondary : secondaries) {
143 if (secondary->getMotherDeltaR() != -1) {
144 if (secondary->getMotherDeltaR() > deltaRchargedMother_) {
146 secondary->resetMother();
148 if (secondary->getMotherDeltaR() <
distMin) {
149 distMin = secondary->getMotherDeltaR();
158 for (
auto& secondary : secondaries) {
162 if (secondary->getMotherDeltaR() != -1 &&
idx != idxMin) {
163 secondary->resetMother();
168 secondary->setSimVertexIndex(simVertexIndex);
174 particleBuffer_.push_back(
std::move(secondary));
183 int simVertexIndex = simVertices_->size();
184 simVertices_->emplace_back(
position.Vect(),
position.T(), parentSimTrackIndex, simVertexIndex);
185 return simVertexIndex;
189 int simTrackIndex = simTracks_->size();
190 simTracks_->emplace_back(
192 simTracks_->back().setTrackId(simTrackIndex);
193 return simTrackIndex;
204 for (; genParticleIterator_ != genParticleEnd_; ++genParticleIterator_, ++genParticleIndex_) {
207 const HepMC::GenVertex* productionVertex = particle.production_vertex();
208 const HepMC::GenVertex* endVertex = particle.end_vertex();
211 if (!productionVertex) {
216 if (productionVertex->position().perp2() * lengthUnitConversionFactor2_ > beamPipeRadius2_) {
221 if (endVertex && endVertex->position().perp2() * lengthUnitConversionFactor2_ < beamPipeRadius2_) {
226 std::unique_ptr<Particle> newParticle(
229 productionVertex->position().y() * lengthUnitConversionFactor_,
230 productionVertex->position().z() * lengthUnitConversionFactor_,
231 productionVertex->position().t() * timeUnitConversionFactor_),
233 particle.momentum().y() * momentumUnitConversionFactor_,
234 particle.momentum().z() * momentumUnitConversionFactor_,
235 particle.momentum().e() * momentumUnitConversionFactor_)));
236 newParticle->setGenParticleIndex(genParticleIndex_);
240 double labFrameLifeTime =
241 (endVertex->position().t() - productionVertex->position().t()) * timeUnitConversionFactor_;
242 newParticle->setRemainingProperLifeTimeC(labFrameLifeTime / newParticle->gamma() *
248 bool foundVtx =
false;
249 for (
const auto& simVtx : *simVertices_) {
250 if (
std::abs(simVtx.position().x() - newParticle->position().x()) < 1E-3 &&
251 std::abs(simVtx.position().y() - newParticle->position().y()) < 1E-3 &&
252 std::abs(simVtx.position().z() - newParticle->position().z()) < 1E-3) {
253 newParticle->setSimVertexIndex(simVtx.vertexId());
259 newParticle->setSimVertexIndex(addSimVertex(newParticle->position(), -1));
262 ++genParticleIterator_;
268 return std::unique_ptr<Particle>();