File indexing completed on 2025-01-18 09:14:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/Primitives.h>
0017 #include <DD4hep/InstanceCount.h>
0018 #include <DDG4/Geant4Primary.h>
0019
0020
0021 #include <G4PrimaryParticle.hh>
0022
0023
0024 #include <stdexcept>
0025 #include <cstdio>
0026
0027 using namespace dd4hep::sim;
0028
0029
0030 PrimaryExtension::~PrimaryExtension() {
0031 }
0032
0033
0034 Geant4PrimaryMap::~Geant4PrimaryMap() {
0035 detail::releaseObjects(m_primaryMap);
0036 }
0037
0038
0039 void Geant4PrimaryMap::insert(G4PrimaryParticle* g4,Geant4Particle* p) {
0040 m_primaryMap.emplace(g4,p->addRef());
0041 }
0042
0043
0044 Geant4Particle* Geant4PrimaryMap::get(const G4PrimaryParticle* particle) {
0045 Primaries::iterator i=m_primaryMap.find(particle);
0046 return i != m_primaryMap.end() ? (*i).second : 0;
0047 }
0048
0049
0050 const Geant4Particle* Geant4PrimaryMap::get(const G4PrimaryParticle* particle) const {
0051 Primaries::const_iterator i=m_primaryMap.find(particle);
0052 return i != m_primaryMap.end() ? (*i).second : 0;
0053 }
0054
0055
0056 Geant4PrimaryInteraction::~Geant4PrimaryInteraction() {
0057 for(const auto& iv : vertices) {
0058 for( Geant4Vertex* vtx : iv.second )
0059 detail::ReleaseObject<Geant4Vertex*>()( vtx );
0060 }
0061 detail::releaseObjects(particles);
0062 }
0063
0064
0065 int Geant4PrimaryInteraction::nextPID() {
0066 return ++next_particle_identifier;
0067 }
0068
0069
0070 void Geant4PrimaryInteraction::setNextPID(int new_value) {
0071 next_particle_identifier = new_value-1;
0072 }
0073
0074
0075 bool Geant4PrimaryInteraction::applyMask() {
0076 for(auto& ip : particles)
0077 ip.second->mask = mask;
0078
0079 for(auto& iv : vertices ) {
0080 for(auto* vtx : iv.second )
0081 vtx->mask = mask;
0082 }
0083 return true;
0084 }
0085
0086
0087 Geant4PrimaryEvent::~Geant4PrimaryEvent() {
0088 detail::destroyObjects(m_interactions);
0089 }
0090
0091
0092 void Geant4PrimaryEvent::add(int id, Geant4PrimaryInteraction* interaction) {
0093 if ( interaction ) {
0094 Interactions::iterator i = m_interactions.find(id);
0095 if ( i == m_interactions.end() ) {
0096 interaction->mask = id;
0097 m_interactions.emplace(id,interaction);
0098 return;
0099 }
0100 except("Geant4PrimaryEvent","+++ Interaction with ID '%d' "
0101 "exists and cannot be added twice!",id);
0102 }
0103 except("Geant4PrimaryEvent","+++ CANNOT add invalid Interaction!");
0104 }
0105
0106
0107 Geant4PrimaryEvent::Interaction* Geant4PrimaryEvent::get(int mask) const {
0108 Interactions::const_iterator i = m_interactions.find(mask);
0109 return (i != m_interactions.end()) ? (*i).second : 0;
0110 }
0111
0112
0113 std::vector<Geant4PrimaryEvent::Interaction*> Geant4PrimaryEvent::interactions() const {
0114 std::vector<Interaction*> v;
0115 v.reserve(m_interactions.size());
0116 for(const auto& i : m_interactions)
0117 v.emplace_back(i.second);
0118 return v;
0119 }
0120