DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Primary.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Printout.h>
16 #include <DD4hep/Primitives.h>
17 #include <DD4hep/InstanceCount.h>
18 #include <DDG4/Geant4Primary.h>
19 
20 // Geant4 include files
21 #include <G4PrimaryParticle.hh>
22 
23 // C/C++ include files
24 #include <stdexcept>
25 #include <cstdio>
26 
27 using namespace dd4hep::sim;
28 
31 }
32 
35  detail::releaseObjects(m_primaryMap);
36 }
37 
39 void Geant4PrimaryMap::insert(G4PrimaryParticle* g4,Geant4Particle* p) {
40  m_primaryMap.emplace(g4,p->addRef());
41 }
42 
44 Geant4Particle* Geant4PrimaryMap::get(const G4PrimaryParticle* particle) {
45  Primaries::iterator i=m_primaryMap.find(particle);
46  return i != m_primaryMap.end() ? (*i).second : 0;
47 }
48 
50 const Geant4Particle* Geant4PrimaryMap::get(const G4PrimaryParticle* particle) const {
51  Primaries::const_iterator i=m_primaryMap.find(particle);
52  return i != m_primaryMap.end() ? (*i).second : 0;
53 }
54 
57  for(const auto& iv : vertices) {
58  for( Geant4Vertex* vtx : iv.second )
59  detail::ReleaseObject<Geant4Vertex*>()( vtx );
60  }
61  detail::releaseObjects(particles);
62 }
63 
66  return ++next_particle_identifier;
67 }
68 
71  next_particle_identifier = new_value-1;
72 }
73 
76  for(auto& ip : particles)
77  ip.second->mask = mask;
78 
79  for(auto& iv : vertices ) {
80  for(auto* vtx : iv.second )
81  vtx->mask = mask;
82  }
83  return true;
84 }
85 
88  detail::destroyObjects(m_interactions);
89 }
90 
93  if ( interaction ) {
94  Interactions::iterator i = m_interactions.find(id);
95  if ( i == m_interactions.end() ) {
96  interaction->mask = id;
97  m_interactions.emplace(id,interaction);
98  return;
99  }
100  except("Geant4PrimaryEvent","+++ Interaction with ID '%d' "
101  "exists and cannot be added twice!",id);
102  }
103  except("Geant4PrimaryEvent","+++ CANNOT add invalid Interaction!");
104 }
105 
108  Interactions::const_iterator i = m_interactions.find(mask);
109  return (i != m_interactions.end()) ? (*i).second : 0;
110 }
111 
113 std::vector<Geant4PrimaryEvent::Interaction*> Geant4PrimaryEvent::interactions() const {
114  std::vector<Interaction*> v;
115  v.reserve(m_interactions.size());
116  for(const auto& i : m_interactions)
117  v.emplace_back(i.second);
118  return v;
119 }
120 
dd4hep::sim::Geant4PrimaryInteraction::nextPID
int nextPID()
Access a new particle identifier within the interaction.
Definition: Geant4Primary.cpp:65
v
View * v
Definition: MultiView.cpp:28
dd4hep::sim::Geant4PrimaryEvent::interactions
std::vector< Geant4PrimaryInteraction * > interactions() const
Retrieve all interactions.
Definition: Geant4Primary.cpp:113
dd4hep::sim::Geant4PrimaryInteraction
Class modelling a single interaction with multiple primary vertices and particles.
Definition: Geant4Primary.h:95
dd4hep::sim::Geant4Particle::addRef
Geant4Particle * addRef()
Increase reference count.
Definition: Geant4Particle.h:159
dd4hep::sim::Geant4PrimaryInteraction::vertices
VertexMap vertices
The map of primary vertices for the particles.
Definition: Geant4Primary.h:110
dd4hep::sim::Geant4PrimaryInteraction::applyMask
bool applyMask()
Apply mask to all contained vertices (max. 1) and particles.
Definition: Geant4Primary.cpp:75
dd4hep::sim::Geant4PrimaryInteraction::particles
ParticleMap particles
The map of particles participating in this primary interaction.
Definition: Geant4Primary.h:112
dd4hep::sim::Geant4PrimaryInteraction::mask
int mask
User mask to flag the interaction. Also unique identifier.
Definition: Geant4Primary.h:116
dd4hep::sim::Geant4PrimaryInteraction::setNextPID
void setNextPID(int value)
Set the next PID value.
Definition: Geant4Primary.cpp:70
dd4hep::sim::Geant4PrimaryMap::insert
void insert(G4PrimaryParticle *g4_particle, Geant4Particle *particle)
Add a new object pair (G4 primary particle, DDG4 particle) into the maps.
Definition: Geant4Primary.cpp:39
dd4hep::sim::Geant4PrimaryEvent::m_interactions
Interactions m_interactions
Set of primary interactions.
Definition: Geant4Primary.h:157
dd4hep::sim::Geant4PrimaryInteraction::next_particle_identifier
int next_particle_identifier
Next PID indentifier.
Definition: Geant4Primary.h:120
dd4hep::sim::Geant4PrimaryMap::~Geant4PrimaryMap
virtual ~Geant4PrimaryMap()
Default destructor.
Definition: Geant4Primary.cpp:34
dd4hep::sim::PrimaryExtension::~PrimaryExtension
virtual ~PrimaryExtension()
Default destructor.
Definition: Geant4Primary.cpp:30
Primitives.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
Geant4Primary.h
dd4hep::sim::Geant4Particle
Data structure to store the MC particle information.
Definition: Geant4Particle.h:103
dd4hep::sim::Geant4Vertex
Data structure to store the MC vertex information.
Definition: Geant4Vertex.h:45
dd4hep::sim::Geant4PrimaryInteraction::~Geant4PrimaryInteraction
virtual ~Geant4PrimaryInteraction()
Default destructor.
Definition: Geant4Primary.cpp:56
InstanceCount.h
dd4hep::sim::Geant4PrimaryMap::m_primaryMap
Primaries m_primaryMap
Mapping of primary particles of this event.
Definition: Geant4Primary.h:69
dd4hep::sim::Geant4PrimaryEvent::~Geant4PrimaryEvent
virtual ~Geant4PrimaryEvent()
Default destructor.
Definition: Geant4Primary.cpp:87
dd4hep::sim::Geant4PrimaryMap::get
Geant4Particle * get(const G4PrimaryParticle *particle)
Access DDG4 particle by G4 primary particle.
Definition: Geant4Primary.cpp:44
Printout.h
dd4hep::sim::Geant4PrimaryEvent::add
void add(int id, Geant4PrimaryInteraction *interaction)
Add a new interaction object to the event.
Definition: Geant4Primary.cpp:92
dd4hep::sim::Geant4PrimaryEvent::get
Geant4PrimaryInteraction * get(int id) const
Retrieve an interaction by its ID.
Definition: Geant4Primary.cpp:107