File indexing completed on 2025-01-18 09:55:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef DDG4_GEANT4PARTICLE_H
0015 #define DDG4_GEANT4PARTICLE_H
0016
0017
0018
0019
0020 #include <Math/Vector4D.h>
0021
0022
0023 class G4ParticleDefinition;
0024 class G4VProcess;
0025
0026
0027 #include <set>
0028 #include <map>
0029 #include <vector>
0030 #include <memory>
0031
0032
0033 namespace dd4hep {
0034
0035
0036 namespace sim {
0037
0038
0039 class Geant4Particle;
0040
0041
0042
0043
0044
0045
0046
0047 class ParticleExtension {
0048 public:
0049
0050 ParticleExtension() {}
0051
0052 virtual ~ParticleExtension();
0053 };
0054
0055
0056 enum Geant4ParticleProperties {
0057 G4PARTICLE_CREATED_HIT = 1<<1,
0058 G4PARTICLE_PRIMARY = 1<<2,
0059 G4PARTICLE_HAS_SECONDARIES = 1<<3,
0060 G4PARTICLE_ABOVE_ENERGY_THRESHOLD = 1<<4,
0061 G4PARTICLE_KEEP_PROCESS = 1<<5,
0062 G4PARTICLE_KEEP_PARENT = 1<<6,
0063 G4PARTICLE_CREATED_CALORIMETER_HIT = 1<<7,
0064 G4PARTICLE_CREATED_TRACKER_HIT = 1<<8,
0065 G4PARTICLE_KEEP_USER = 1<<9,
0066 G4PARTICLE_KEEP_ALWAYS = 1<<10,
0067 G4PARTICLE_FORCE_KILL = 1<<11,
0068
0069
0070 G4PARTICLE_GEN_EMPTY = 1<<0,
0071 G4PARTICLE_GEN_STABLE = 1<<1,
0072 G4PARTICLE_GEN_DECAYED = 1<<2,
0073 G4PARTICLE_GEN_DOCUMENTATION = 1<<3,
0074 G4PARTICLE_GEN_BEAM = 1<<4,
0075
0076 G4PARTICLE_GEN_OTHER = 1<<9,
0077
0078 G4PARTICLE_GEN_GENERATOR =
0079 ( G4PARTICLE_GEN_EMPTY+G4PARTICLE_GEN_STABLE+
0080 G4PARTICLE_GEN_DECAYED+G4PARTICLE_GEN_DOCUMENTATION+
0081 G4PARTICLE_GEN_BEAM+G4PARTICLE_GEN_OTHER),
0082 G4PARTICLE_GEN_STATUS = 0x3FF,
0083 G4PARTICLE_GEN_STATUS_MASK = 0xFFFF,
0084
0085 G4PARTICLE_SIM_CREATED = 1<<10,
0086 G4PARTICLE_SIM_BACKSCATTER = 1<<11,
0087 G4PARTICLE_SIM_DECAY_CALO = 1<<12,
0088 G4PARTICLE_SIM_DECAY_TRACKER = 1<<13,
0089 G4PARTICLE_SIM_STOPPED = 1<<14,
0090 G4PARTICLE_SIM_LEFT_DETECTOR = 1<<15,
0091 G4PARTICLE_SIM_PARENT_RADIATED = 1<<16,
0092 G4PARTICLE_SIM_OVERLAY = 1<<17,
0093
0094 G4PARTICLE_LAST_NOTHING = 1<<31
0095 };
0096
0097
0098
0099
0100
0101
0102
0103 class Geant4Particle {
0104 public:
0105 typedef std::set<int> Particles;
0106
0107 int ref { 0 };
0108 int id { 0 };
0109 int originalG4ID { 0 };
0110 int g4Parent { 0 };
0111 int reason { 0 };
0112 int mask { 0 };
0113 int steps { 0 };
0114 int secondaries { 0 };
0115 int pdgID { 0 };
0116 int status { 0 };
0117 int colorFlow[2] { 0, 0 };
0118 unsigned short genStatus { 0 };
0119 char charge { 0 };
0120 char _spare[1] { 0 };
0121 float spin[3] { 0E0,0E0,0E0 };
0122
0123
0124 double vsx = 0E0, vsy = 0E0, vsz = 0E0;
0125
0126 double vex = 0E0, vey = 0E0, vez = 0E0;
0127
0128 double psx = 0E0, psy = 0E0, psz = 0E0;
0129
0130 double pex = 0E0, pey = 0E0, pez = 0E0;
0131
0132 double mass { 0E0 };
0133
0134 double time { 0E0 };
0135
0136 double properTime { 0E0 };
0137
0138 Particles parents;
0139
0140 Particles daughters;
0141
0142
0143 std::unique_ptr<ParticleExtension> extension { };
0144
0145 const G4VProcess *process = 0;
0146
0147 public:
0148
0149 Geant4Particle();
0150
0151 Geant4Particle(int part_id);
0152
0153 Geant4Particle(const Geant4Particle& copy) = delete;
0154
0155 virtual ~Geant4Particle();
0156
0157 Geant4Particle& operator=(const Geant4Particle& copy) = delete;
0158
0159 Geant4Particle* addRef() {
0160 ++ref;
0161 return this;
0162 }
0163
0164 void release();
0165
0166 Geant4Particle& get_data(Geant4Particle& c);
0167
0168 void removeDaughter(int id_daughter);
0169
0170 int charge3() const { return charge; }
0171 };
0172
0173 #ifndef __DDG4_STANDALONE_DICTIONARIES__
0174
0175
0176
0177
0178
0179
0180
0181 class Geant4ParticleHandle {
0182 public:
0183 typedef ROOT::Math::PxPyPzM4D<double> FourVector;
0184 typedef ROOT::Math::Cartesian3D<double> ThreeVector;
0185 protected:
0186
0187 Geant4Particle* particle;
0188
0189 public:
0190
0191 Geant4ParticleHandle(Geant4Particle* part);
0192
0193 Geant4ParticleHandle(const Geant4ParticleHandle& h);
0194
0195 Geant4ParticleHandle& operator=(Geant4Particle* part);
0196
0197 Geant4Particle* operator->() const;
0198
0199 operator Geant4Particle*() const;
0200
0201 size_t numParent() const;
0202
0203 size_t numDaughter() const;
0204
0205 double momentum2() const;
0206
0207 double energy() const;
0208
0209 double momentum() const { return std::sqrt(momentum2()); }
0210
0211 double charge() const { return double(particle->charge); }
0212
0213 double mass() const { return particle->mass; }
0214
0215 double time() const { return particle->time; }
0216
0217 std::string particleName() const;
0218
0219 std::string particleType() const;
0220
0221 std::string processName() const;
0222
0223 std::string processTypeName() const;
0224
0225 FourVector pxPyPzM() const;
0226
0227 template <typename T> std::vector<T> pxPyPzM(T unit) const;
0228
0229 ThreeVector startVertex() const;
0230
0231 ThreeVector endVertex() const;
0232
0233 const G4ParticleDefinition *definition() const;
0234
0235
0236
0237
0238 void dump1(int level, const std::string& src, const char* tag) const;
0239
0240 void dump2(int level, const std::string& src, const char* tag, int g4id, bool inrec) const;
0241
0242 void dumpWithVertex(int level, const std::string& src, const char* tag) const;
0243 void dumpWithMomentum(int level, const std::string& src, const char* tag) const;
0244 void dumpWithMomentumAndVertex(int level, const std::string& src, const char* tag) const;
0245 static void header4(int level, const std::string& src, const char* tag);
0246 void dump4(int level, const std::string& src, const char* tag) const;
0247
0248
0249
0250
0251 void offset(int off) const;
0252
0253
0254 static std::vector<G4ParticleDefinition*> g4DefinitionsRegEx(const std::string& expression);
0255
0256 static G4ParticleDefinition* g4DefinitionsExact(const std::string& expression);
0257 };
0258
0259 inline Geant4ParticleHandle::Geant4ParticleHandle(const Geant4ParticleHandle& c)
0260 : particle(c.particle) {
0261 }
0262
0263
0264 inline Geant4ParticleHandle::Geant4ParticleHandle(Geant4Particle* p)
0265 : particle(p) {
0266 }
0267
0268
0269 inline Geant4Particle* Geant4ParticleHandle::operator->() const {
0270 return particle;
0271 }
0272
0273 inline Geant4ParticleHandle& Geant4ParticleHandle::operator=(Geant4Particle* part) {
0274 particle = part;
0275 return *this;
0276 }
0277
0278 inline Geant4ParticleHandle::operator Geant4Particle*() const {
0279 return particle;
0280 }
0281
0282 inline size_t Geant4ParticleHandle::numParent() const {
0283 return particle->parents.size();
0284 }
0285
0286 inline size_t Geant4ParticleHandle::numDaughter() const {
0287 return particle->daughters.size();
0288 }
0289
0290 inline ROOT::Math::PxPyPzM4D<double> Geant4ParticleHandle::pxPyPzM() const {
0291 const Geant4Particle* p = particle;
0292 return ROOT::Math::PxPyPzM4D<double>(p->psx,p->psy,p->psz,p->mass);
0293 }
0294
0295
0296 inline ROOT::Math::Cartesian3D<double> Geant4ParticleHandle::startVertex() const {
0297 const Geant4Particle* p = particle;
0298 return ROOT::Math::Cartesian3D<double>(p->vsx,p->vsy,p->vsz);
0299 }
0300
0301
0302 inline ROOT::Math::Cartesian3D<double> Geant4ParticleHandle::endVertex() const {
0303 const Geant4Particle* p = particle;
0304 return ROOT::Math::Cartesian3D<double>(p->vex,p->vey,p->vez);
0305 }
0306
0307
0308 inline double Geant4ParticleHandle::energy() const {
0309 const Geant4Particle* p = particle;
0310 ROOT::Math::PxPyPzM4D<double> v(p->psx,p->psy,p->psz,p->mass);
0311 return v.E();
0312 }
0313
0314
0315 inline double Geant4ParticleHandle::momentum2() const {
0316 const Geant4Particle* p = particle;
0317 return (p->psx*p->psx + p->psy*p->psy + p->psz*p->psz);
0318 }
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337 class Geant4ParticleMap {
0338 public:
0339 typedef Geant4Particle Particle;
0340 typedef std::map<int,Particle*> ParticleMap;
0341 typedef std::map<int,int> TrackEquivalents;
0342
0343 ParticleMap particleMap;
0344
0345 TrackEquivalents equivalentTracks;
0346
0347 public:
0348
0349 Geant4ParticleMap() {}
0350
0351 virtual ~Geant4ParticleMap();
0352
0353 bool isValid() const;
0354
0355 void dump() const;
0356
0357 void clear();
0358
0359 void adopt(ParticleMap& pm, TrackEquivalents& equiv);
0360
0361 const ParticleMap& particles() const { return particleMap; }
0362
0363 const TrackEquivalents& equivalents() const { return equivalentTracks; }
0364
0365 int particleID(int track, bool throw_if_not_found=true) const;
0366 };
0367 #endif
0368
0369 }
0370 }
0371 #endif