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
Geant4Particle.h
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 #ifndef DD4HEP_GEANT4PARTICLE_H
16 #define DD4HEP_GEANT4PARTICLE_H
17 
18 // Framework include files
19 #include "DD4hep/Memory.h"
20 
21 // ROOT includes
22 #include "Math/Vector4D.h"
23 
24 // Geant4 forward declarations
25 class G4ParticleDefinition;
26 class G4VProcess;
27 
28 // C/C++ include files
29 #include <set>
30 #include <map>
31 
33 namespace DD4hep {
34 
36  namespace Simulation {
37 
38  // Forward declarations
39  class Geant4Particle;
40 
42 
48  public:
52  virtual ~ParticleExtension();
53  };
54 
68 
69  // Generator status for a given particles: bit 0...3 come from LCIO, rest is internal
70  G4PARTICLE_GEN_EMPTY = 1<<0, // Empty line
71  G4PARTICLE_GEN_STABLE = 1<<1, // undecayed particle, stable in the generator
72  G4PARTICLE_GEN_DECAYED = 1<<2, // particle decayed in the generator
73  G4PARTICLE_GEN_DOCUMENTATION = 1<<3, // documentation line
74 
75  G4PARTICLE_GEN_GENERATOR = // Particle comes from generator
78  G4PARTICLE_GEN_STATUS = 0x3FF, // Mask for generator status (bit 0...9)
79 
80  // Simulation status of a given particle
81  G4PARTICLE_SIM_CREATED = 1<<10, // True if the particle has been created by the simulation program (rather than the generator)
82  G4PARTICLE_SIM_BACKSCATTER = 1<<11, // True if the particle is the result of a backscatter from a calorimeter shower.
83  G4PARTICLE_SIM_DECAY_CALO = 1<<12, // True if the particle has interacted in a calorimeter region.
84  G4PARTICLE_SIM_DECAY_TRACKER = 1<<13, // True if the particle has interacted in a tracking region.
85  G4PARTICLE_SIM_STOPPED = 1<<14, // True if the particle has been stopped by the simulation program.
86  G4PARTICLE_SIM_LEFT_DETECTOR = 1<<15, // True if the particle has left the world volume undecayed.
87  G4PARTICLE_SIM_PARENT_RADIATED = 1<<16, // True if the particle's vertex is not the endpoint of the parent particle.
88  G4PARTICLE_SIM_OVERLAY = 1<<17, // True if the particle has been overlayed by the simulation (or digitization) program.
89 
91  };
92 
93 
94 
96 
102  private:
104  Geant4Particle(const Geant4Particle& c);
105  public:
106  typedef std::set<int> Particles;
108  int ref;
111  int status, colorFlow[2];
112  char charge, _spare[3];
113  float spin[3];
114  // 12 ints + 4 floats should be aligned to 8 bytes....
115  double vsx, vsy, vsz;
116  double vex, vey, vez;
117  double psx, psy, psz;
118  double pex, pey, pez;
119  double mass, time, properTime;
123 
125 #ifdef DD4HEP_DD4HEP_PTR_AUTO
127 #else
129 #endif
130  const G4VProcess *process;
131  Geant4Particle();
134  Geant4Particle(int part_id);
136  virtual ~Geant4Particle();
139  ++ref;
140  return this;
141  }
143  void release();
147  void removeDaughter(int id_daughter);
149  int charge3() const { return charge; }
150  };
151 
152 #ifndef __DDG4_STANDALONE_DICTIONARIES__
153 
155 
161  public:
162  typedef ROOT::Math::PxPyPzM4D<double> FourVector;
163  typedef ROOT::Math::Cartesian3D<double> ThreeVector;
164  protected:
167  public:
175  Geant4Particle* operator->() const;
177  operator Geant4Particle*() const;
179  size_t numParent() const;
181  size_t numDaughter() const;
183  double momentum2() const;
185  double energy() const;
187  double momentum() const { return std::sqrt(momentum2()); }
189  double charge() const { return double(particle->charge); }
191  double mass() const { return particle->mass; }
193  double time() const { return particle->time; }
195  std::string particleName() const;
197  std::string particleType() const;
199  std::string processName() const;
201  std::string processTypeName() const;
203  FourVector pxPyPzM() const;
205  ThreeVector startVertex() const;
207  ThreeVector endVertex() const;
209  const G4ParticleDefinition *definition() const;
210 
212 
214  void dump1(int level, const std::string& src, const char* tag) const;
216  void dump2(int level, const std::string& src, const char* tag, int g4id, bool inrec) const;
218  void dumpWithVertex(int level, const std::string& src, const char* tag) const;
219  void dumpWithMomentum(int level, const std::string& src, const char* tag) const;
220  void dumpWithMomentumAndVertex(int level, const std::string& src, const char* tag) const;
221  void dump4(int level, const std::string& src, const char* tag) const;
222 
224 
226  void offset(int off) const;
227 
228  };
229 
231  : particle(c.particle) {
232  }
233 
236  : particle(p) {
237  }
238 
241  return particle;
242  }
245  particle = part;
246  return *this;
247  }
249  inline Geant4ParticleHandle::operator Geant4Particle*() const {
250  return particle;
251  }
253  inline size_t Geant4ParticleHandle::numParent() const {
254  return particle->parents.size();
255  }
257  inline size_t Geant4ParticleHandle::numDaughter() const {
258  return particle->daughters.size();
259  }
261  inline ROOT::Math::PxPyPzM4D<double> Geant4ParticleHandle::pxPyPzM() const {
262  const Geant4Particle* p = particle;
263  return ROOT::Math::PxPyPzM4D<double>(p->psx,p->psy,p->psz,p->mass);
264  }
265 
267  inline ROOT::Math::Cartesian3D<double> Geant4ParticleHandle::startVertex() const {
268  const Geant4Particle* p = particle;
269  return ROOT::Math::Cartesian3D<double>(p->vsx,p->vsy,p->vsz);
270  }
271 
273  inline ROOT::Math::Cartesian3D<double> Geant4ParticleHandle::endVertex() const {
274  const Geant4Particle* p = particle;
275  return ROOT::Math::Cartesian3D<double>(p->vex,p->vey,p->vez);
276  }
277 
279  inline double Geant4ParticleHandle::energy() const {
280  const Geant4Particle* p = particle;
281  ROOT::Math::PxPyPzM4D<double> v(p->psx,p->psy,p->psz,p->mass);
282  return v.E();
283  }
284 
286  inline double Geant4ParticleHandle::momentum2() const {
287  const Geant4Particle* p = particle;
288  return (p->psx*p->psx + p->psy*p->psy + p->psz*p->psz);
289  }
290 
292 
309  public:
311  typedef std::map<int,Particle*> ParticleMap;
312  typedef std::map<int,int> TrackEquivalents;
317 
321  virtual ~Geant4ParticleMap();
323  bool isValid() const;
325  void dump() const;
327  void clear();
329  void adopt(ParticleMap& pm, TrackEquivalents& equiv);
331  const ParticleMap& particles() const { return particleMap; }
333  const TrackEquivalents& equivalents() const { return equivalentTracks; }
335  int particleID(int track, bool throw_if_not_found=true) const;
336  };
337 #endif
338 
339  } // End namespace Simulation
340 } // End namespace DD4hep
341 #endif // DD4HEP_GEANT4PARTICLE_H
ROOT::Math::PxPyPzM4D< double > FourVector
Geant4Particle * addRef()
Increase reference count.
const G4VProcess * process
not persisten. ROOT cannot handle
size_t numDaughter() const
Accessor to the number of particle daughters.
dd4hep_ptr< ParticleExtension > extension
User data extension if required.
std::map< int, Particle * > ParticleMap
void offset(int off) const
Handlers.
Data structure to store the MC particle information.
void adopt(ParticleMap &pm, TrackEquivalents &equiv)
Adopt particle maps.
void removeDaughter(int id_daughter)
Remove daughter from set.
void dumpWithVertex(int level, const std::string &src, const char *tag) const
Output type 3:+++ "tag" ID: 0 e- status:00000014 type: 11 Vertex:(+0.00e+00,+0.00e+00,+0.00e+00) [mm] time: +0.00e+00 [ns] #Par: 0 #Dau: 4.
double momentum() const
Scalar particle momentum.
ThreeVector endVertex() const
Access patricle momentum, energy as 4 vector.
Geant4ParticleHandle(Geant4Particle *part)
Default constructor.
FourVector pxPyPzM() const
Access patricle momentum, energy as 4 vector.
int charge3() const
Charge accessor (for python etc.)
int particleID(int track, bool throw_if_not_found=true) const
Access the equivalent track id (shortcut to the usage of TrackEquivalents)
void dump4(int level, const std::string &src, const char *tag) const
void dump2(int level, const std::string &src, const char *tag, int g4id, bool inrec) const
Output type 2:+++ "tag" 20 G4: 7 def:0xde4eaa8 [gamma , gamma] reason: 20 E:+3.304035e+01 in record:Y...
const ParticleMap & particles() const
Access the particle map.
Out version of the std auto_ptr implementation base either on auto_ptr or unique_ptr.
Definition: Memory.h:43
const TrackEquivalents & equivalents() const
Access the map of track equivalents.
Geant4ParticleMap()
Default constructor.
ThreeVector startVertex() const
Access patricle momentum, energy as 4 vector.
Base class to extend the basic particle class used by DDG4 with user information. ...
Particles parents
The list of daughters of this MC particle.
Geant4ParticleProperties
Track properties.
Data structure to map particles produced during the generation and the simulation.
const G4ParticleDefinition * definition() const
Access the Geant4 particle definition object (expensive!)
virtual ~ParticleExtension()
Default destructor.
ParticleExtension()
Default constructor.
std::string particleName() const
Access to the Geant4 particle name.
void clear()
Clear particle maps.
double time() const
Geant4 time of the particle.
Geant4ParticleHandle & operator=(Geant4Particle *part)
Assignment operator.
std::string particleType() const
Access to the Geant4 particle type.
size_t numParent() const
Accessor to the number of particle parents.
Geant4Particle * operator->() const
Overloaded -> operator to access particle details.
Data structure to access derived MC particle information.
ROOT::Math::Cartesian3D< double > ThreeVector
double energy() const
Scalar particle energy.
double momentum2() const
Scalar particle momentum squared.
void dumpWithMomentumAndVertex(int level, const std::string &src, const char *tag) const
Output type 3:+++ <tag> ID: 0 e- status:00000014 type: 11 Vertex:(+0.00e+00,+0.00e+00,+0.00e+00) [mm] time: +0.00e+00 [ns] #Par: 0 #Dau: 4.
virtual ~Geant4ParticleMap()
Default destructor.
View * v
Definition: MultiView.cpp:30
Geant4Particle & get_data(Geant4Particle &c)
Assignment operator.
bool isValid() const
Check if the particle map was ever filled (ie. some particle handler was present) ...
virtual ~Geant4Particle()
Default destructor.
void dump1(int level, const std::string &src, const char *tag) const
Various output formats:
std::string processName() const
Access to the creator process name.
Geant4Particle * particle
Particle pointer.
ParticleMap particleMap
Mapping of particles of this event.
TrackEquivalents equivalentTracks
Map associating the G4Track identifiers with identifiers of existing MCParticles. ...
void dump() const
Dump content.
double charge() const
Geant4 charge of the particle.
Geant4Particle()
Default constructor.
void dumpWithMomentum(int level, const std::string &src, const char *tag) const
Output type 3:+++ <tag> ID: 0 e- status:00000014 type: 11 Vertex:(+0.00e+00,+0.00e+00,+0.00e+00) [mm] time: +0.00e+00 [ns] #Par: 0 #Dau: 4.
std::string processTypeName() const
Access to the creator process type name.
double mass() const
Geant4 mass of the particle.
void release()
Decrease reference count. Deletes object if NULL.