3 #include "HepMC/GenEvent.h" 4 #include "HepMC/Units.h" 5 #include "HepPDT/ParticleDataTable.hh" 26 genParticleIterator_(genEvent_->particles_begin()),
27 genParticleEnd_(genEvent_->particles_end()),
29 particleDataTable_(&particleDataTable),
45 momentumUnitConversionFactor_(conversion_factor(genEvent_->momentum_unit(),
HepMC::Units::GEV)),
46 lengthUnitConversionFactor_(conversion_factor(genEvent_->length_unit(),
HepMC::Units::LengthUnit::CM)),
47 lengthUnitConversionFactor2_(lengthUnitConversionFactor_ * lengthUnitConversionFactor_),
65 std::unique_ptr<fastsim::Particle> particle;
68 if (!particleBuffer_.empty()) {
69 particle =
std::move(particleBuffer_.back());
70 particleBuffer_.pop_back();
74 particle = nextGenParticle();
80 if (!particleFilter_->accepts(*particle)) {
81 return nextParticle(random);
85 if (!particle->remainingProperLifeTimeIsSet() || !particle->chargeIsSet()) {
91 particle->setRemainingProperLifeTimeC(0.);
92 particle->setCharge(0.);
96 if (!particle->remainingProperLifeTimeIsSet()) {
99 double width = particleData->totalWidth().value();
101 particle->setRemainingProperLifeTimeC(-
log(random.
flatShoot()) * 6.582119
e-25 /
width / 10.);
103 particle->setStable();
108 if (!particle->chargeIsSet()) {
109 particle->setCharge(particleData->charge());
114 unsigned simTrackIndex = addSimTrack(particle.get());
115 particle->setSimTrackIndex(simTrackIndex);
122 int parentSimTrackIndex,
123 std::vector<std::unique_ptr<Particle> >& secondaries,
126 if (!particleFilter_->acceptsVtx(vertexPosition)) {
131 if (secondaries.empty()) {
136 unsigned simVertexIndex = addSimVertex(vertexPosition, parentSimTrackIndex);
143 for (
auto& secondary : secondaries) {
145 if (secondary->getMotherDeltaR() != -1) {
146 if (secondary->getMotherDeltaR() > deltaRchargedMother_) {
148 secondary->resetMother();
150 if (secondary->getMotherDeltaR() <
distMin) {
151 distMin = secondary->getMotherDeltaR();
160 for (
auto& secondary : secondaries) {
164 if (secondary->getMotherDeltaR() != -1 &&
idx != idxMin) {
165 secondary->resetMother();
170 secondary->setSimVertexIndex(simVertexIndex);
173 secondary->setOnLayer(
layer->isForward(),
layer->index());
176 particleBuffer_.push_back(
std::move(secondary));
185 int simVertexIndex = simVertices_->size();
186 simVertices_->emplace_back(
position.Vect(),
position.T(), parentSimTrackIndex, simVertexIndex);
187 return simVertexIndex;
191 int simTrackIndex = simTracks_->size();
192 simTracks_->emplace_back(
194 simTracks_->back().setTrackId(simTrackIndex);
195 return simTrackIndex;
206 for (; genParticleIterator_ != genParticleEnd_; ++genParticleIterator_, ++genParticleIndex_) {
209 const HepMC::GenVertex* productionVertex = particle.production_vertex();
210 const HepMC::GenVertex* endVertex = particle.end_vertex();
213 if (!productionVertex) {
216 if (
std::abs(particle.pdg_id()) < 10 ||
std::abs(particle.pdg_id()) == 21) {
221 const bool decayedWithinBeamPipe =
222 endVertex && endVertex->position().perp2() * lengthUnitConversionFactor2_ < beamPipeRadius2_;
224 if (decayedWithinBeamPipe) {
230 int exoticRelativeId = 0;
231 const bool producedWithinBeamPipe =
232 productionVertex->position().perp2() * lengthUnitConversionFactor2_ < beamPipeRadius2_;
233 if (!producedWithinBeamPipe && useFastSimsDecayer_) {
234 exoticRelativesChecker(productionVertex, exoticRelativeId, 0);
240 if (!producedWithinBeamPipe && useFastSimsDecayer_) {
241 exoticRelativesChecker(productionVertex, exoticRelativeId, 0);
246 if (producedWithinBeamPipe && !decayedWithinBeamPipe && useFastSimsDecayer_) {
247 exoticRelativesChecker(productionVertex, exoticRelativeId, 0);
251 std::unique_ptr<Particle> newParticle(
254 productionVertex->position().y() * lengthUnitConversionFactor_,
255 productionVertex->position().z() * lengthUnitConversionFactor_,
256 productionVertex->position().t() * timeUnitConversionFactor_),
258 particle.momentum().y() * momentumUnitConversionFactor_,
259 particle.momentum().z() * momentumUnitConversionFactor_,
260 particle.momentum().e() * momentumUnitConversionFactor_)));
261 newParticle->setGenParticleIndex(genParticleIndex_);
263 newParticle->setMotherPdgId(exoticRelativeId);
268 double labFrameLifeTime =
269 (endVertex->position().t() - productionVertex->position().t()) * timeUnitConversionFactor_;
270 newParticle->setRemainingProperLifeTimeC(labFrameLifeTime / newParticle->gamma() *
276 bool foundVtx =
false;
277 for (
const auto& simVtx : *simVertices_) {
278 if (
std::abs(simVtx.position().x() - newParticle->position().x()) < 1E-3 &&
279 std::abs(simVtx.position().y() - newParticle->position().y()) < 1E-3 &&
280 std::abs(simVtx.position().z() - newParticle->position().z()) < 1E-3) {
281 newParticle->setSimVertexIndex(simVtx.vertexId());
287 newParticle->setSimVertexIndex(addSimVertex(newParticle->position(), -1));
290 ++genParticleIterator_;
296 return std::unique_ptr<Particle>();
300 int& exoticRelativeId_,
302 if (ngendepth > 99 || exoticRelativeId_ == -1 ||
isExotic(
std::abs(exoticRelativeId_)))
305 std::vector<HepMC::GenParticle*>::const_iterator relativesIterator_ = originVertex->particles_in_const_begin();
306 std::vector<HepMC::GenParticle*>::const_iterator relativesIteratorEnd_ = originVertex->particles_in_const_end();
307 for (; relativesIterator_ != relativesIteratorEnd_; ++relativesIterator_) {
310 exoticRelativeId_ = genRelative.pdg_id();
311 if (ngendepth == 100)
312 exoticRelativeId_ = -1;
315 const HepMC::GenVertex* vertex_ = genRelative.production_vertex();
318 exoticRelativesChecker(vertex_, exoticRelativeId_, ngendepth);
Implementation of a generic detector layer (base class for forward/barrel layers).
HepPDT::ParticleDataTable ParticleDataTable
static double constexpr speedOfLight
Speed of light [cm / ns].
const math::XYZTLorentzVector & position() const
Return position of the particle.
const HepMC::GenEvent *const genEvent_
The GenEvent.
unsigned addSimTrack(const Particle *particle)
Add a simTrack (simTrack contains some basic info about the particle, e.g. pdgId).
constexpr std::array< uint8_t, layerIndexSize > layer
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
bool isExotic(int pdgid_)
~ParticleManager()
Default destructor.
Abs< T >::type abs(const T &t)
void addSecondaries(const math::XYZTLorentzVector &vertexPosition, int motherSimTrackId, std::vector< std::unique_ptr< Particle > > &secondaries, const SimplifiedGeometry *layer=nullptr)
Adds secondaries that are produced by any of the interactions (or particle decay) to the buffer...
std::unique_ptr< Particle > nextParticle(const RandomEngineAndDistribution &random)
Returns the next particle that has to be propagated (secondary or genParticle).
void exoticRelativesChecker(const HepMC::GenVertex *originVertex, int &hasExoticAssociation, int ngendepth)
int simTrackIndex() const
Return index of the SimTrack.
HepPDT::ParticleData ParticleData
int simVertexIndex() const
Return index of the origin vertex.
int pdgId() const
Return pdgId of the particle.
std::unique_ptr< Particle > nextGenParticle()
Returns next particle from the GenEvent that has to be propagated.
const math::XYZTLorentzVector & momentum() const
Return momentum of the particle.
double lengthUnitConversionFactor_
Convert pythia unis to cm (FastSim standard)
double timeUnitConversionFactor_
Convert pythia unis to ns (FastSim standard)
static int position[264][3]
(Kinematic) cuts on the particles that are propagated.
double flatShoot(double xmin=0.0, double xmax=1.0) const
Definition of a generic FastSim Particle which can be propagated through the detector (formerly Parti...
ParticleManager(const HepMC::GenEvent &genEvent, const HepPDT::ParticleDataTable &particleDataTable, double beamPipeRadius, double deltaRchargedMother, const ParticleFilter &particleFilter, std::vector< SimTrack > &simTracks, std::vector< SimVertex > &simVertices, bool useFastSimsDecayer)
Constructor.
unsigned addSimVertex(const math::XYZTLorentzVector &position, int motherIndex)
Add a simVertex (simVertex contains information about the track it was produced). ...
unsigned addEndVertex(const Particle *particle)
Necessary to add an end vertex to a particle.
int genParticleIndex() const
Return index of the particle in the genParticle vector.