DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Primary.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
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;
28 using namespace DD4hep::Simulation;
29 
32 }
33 
37 }
38 
40 void Geant4PrimaryMap::insert(G4PrimaryParticle* g4,Geant4Particle* p) {
41  m_primaryMap.insert(std::make_pair(g4,p->addRef()));
42 }
43 
45 Geant4Particle* Geant4PrimaryMap::get(const G4PrimaryParticle* particle) {
46  Primaries::iterator i=m_primaryMap.find(particle);
47  return i != m_primaryMap.end() ? (*i).second : 0;
48 }
49 
51 const Geant4Particle* Geant4PrimaryMap::get(const G4PrimaryParticle* particle) const {
52  Primaries::const_iterator i=m_primaryMap.find(particle);
53  return i != m_primaryMap.end() ? (*i).second : 0;
54 }
55 
60 }
61 
64  return ++next_particle_identifier;
65 }
66 
69  next_particle_identifier = new_value-1;
70 }
71 
74  if ( vertices.size() <= 1 ) {
75  Geant4PrimaryInteraction::ParticleMap::iterator ip, ipend;
76  for( ip=particles.begin(), ipend=particles.end(); ip != ipend; ++ip )
77  (*ip).second->mask = mask;
78 
79  Geant4PrimaryInteraction::VertexMap::iterator iv, ivend;
80  for( iv=vertices.begin(), ivend=vertices.end(); iv != ivend; ++iv )
81  (*iv).second->mask = mask;
82  return true;
83  }
84  return false;
85 }
86 
90 }
91 
94  if ( interaction ) {
95  Interactions::iterator i = m_interactions.find(id);
96  if ( i == m_interactions.end() ) {
97  interaction->mask = id;
98  m_interactions.insert(std::make_pair(id,interaction));
99  return;
100  }
101  char text[132];
102  ::snprintf(text,sizeof(text),"Geant4PrimaryEvent: Interaction with ID '%d' "
103  "exists and cannot be added twice!",id);
104  throw std::runtime_error(text);
105  }
106  throw std::runtime_error("Geant4PrimaryEvent: CANNOT add invalid Interaction!");
107 }
108 
111  Interactions::const_iterator i = m_interactions.find(mask);
112  if ( i != m_interactions.end() ) {
113  return (*i).second;
114  }
115  return 0;
116 }
117 
119 std::vector<Geant4PrimaryEvent::Interaction*> Geant4PrimaryEvent::interactions() const {
120  std::vector<Interaction*> v;
121  for(Interactions::const_iterator i=m_interactions.begin(); i!=m_interactions.end(); ++i)
122  v.push_back((*i).second);
123  return v;
124 }
125 
VertexMap vertices
The map of primary vertices for the particles.
Geant4Particle * addRef()
Increase reference count.
int nextPID()
Access a new particle identifier within the interaction.
void setNextPID(int value)
Set the next PID value.
Data structure to store the MC particle information.
int next_particle_identifier
Next PID indentifier.
virtual ~Geant4PrimaryMap()
Default destructor.
Class modelling a single interaction with multiple primary vertices and particles.
Definition: Geant4Primary.h:96
Geant4PrimaryInteraction * get(int id) const
Retrieve an interaction by it's ID.
Interactions m_interactions
Set of primary interactions.
bool applyMask()
Apply mask to all contained vertices (max. 1) and particles.
ParticleMap particles
The map of particles participating in this primary interaction.
void destroyObjects(M &m)
Definition: Primitives.h:293
void releaseObjects(M &m)
Definition: Primitives.h:344
Geant4Particle * get(const G4PrimaryParticle *particle)
Access DDG4 particle by G4 primary particle.
Primaries m_primaryMap
Mapping of primary particles of this event.
Definition: Geant4Primary.h:70
virtual ~Geant4PrimaryEvent()
Default destructor.
std::vector< Geant4PrimaryInteraction * > interactions() const
Retrieve all interactions.
void insert(G4PrimaryParticle *g4_particle, Geant4Particle *particle)
Add a new object pair (G4 primary particle, DDG4 particle) into the maps.
int mask
User mask to flag the interaction. Also unique identifier.
View * v
Definition: MultiView.cpp:30
void add(int id, Geant4PrimaryInteraction *interaction)
Add a new interaction object to the event.
virtual ~Geant4PrimaryInteraction()
Default destructor.
virtual ~PrimaryExtension()
Default destructor.