DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4InputHandling.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>
17 #include <DDG4/Geant4Primary.h>
18 #include <DDG4/Geant4Context.h>
19 #include <DDG4/Geant4Action.h>
21 #include <CLHEP/Units/SystemOfUnits.h>
22 #include <CLHEP/Units/PhysicalConstants.h>
23 
24 // Geant4 include files
25 #include <G4Event.hh>
26 #include <G4PrimaryVertex.hh>
27 #include <G4PrimaryParticle.hh>
28 #include <G4ParticleDefinition.hh>
29 
30 // C/C++ include files
31 #include <stdexcept>
32 #include <limits>
33 #include <cmath>
34 
35 using namespace dd4hep::sim;
36 using PropertyMask = dd4hep::detail::ReferenceBitMask<int>;
37 
39 Geant4Vertex* dd4hep::sim::createPrimary(const G4PrimaryVertex* g4) {
40  Geant4Vertex* v = new Geant4Vertex();
41  v->x = g4->GetX0();
42  v->y = g4->GetY0();
43  v->z = g4->GetZ0();
44  v->time = g4->GetT0();
45  return v;
46 }
47 
50 dd4hep::sim::createPrimary(int particle_id,
51  const Geant4Vertex* v,
52  const G4PrimaryParticle* g4p)
53 {
55  p->id = particle_id;
56  p->reason = 0;
57  p->pdgID = g4p->GetPDGcode();
58  p->psx = g4p->GetPx();
59  p->psy = g4p->GetPy();
60  p->psz = g4p->GetPz();
61  p->time = g4p->GetProperTime();
62  p->properTime = g4p->GetProperTime();
63  p->vsx = v->x;
64  p->vsy = v->y;
65  p->vsz = v->z;
66  p->vex = v->x;
67  p->vey = v->y;
68  p->vez = v->z;
69  //p->definition = g4p->GetG4code();
70  //p->process = 0;
71  p->spin[0] = 0;
72  p->spin[1] = 0;
73  p->spin[2] = 0;
74  p->colorFlow[0] = 0;
75  p->colorFlow[0] = 0;
76  p->mass = g4p->GetMass();
77  p->charge = int(3.0 * g4p->GetCharge());
78  PropertyMask status(p->status);
79  status.set(G4PARTICLE_GEN_STABLE);
80  return p;
81 }
82 
84 static void collectPrimaries(Geant4PrimaryMap* pm,
85  Geant4PrimaryInteraction* interaction,
86  Geant4Vertex* particle_origine,
87  G4PrimaryParticle* gp)
88 {
89  //if the particle is in the map, we do not have to do anything
90  if ( pm->get(gp) ) {
91  return;
92  }
93 
94  int pid = int(interaction->particles.size());
95  Geant4Particle* p = createPrimary(pid,particle_origine,gp);
96  G4PrimaryParticle* dau = gp->GetDaughter();
97  PropertyMask status(p->status);
98  int mask = interaction->mask;
99 
100  interaction->particles.emplace(p->id,p);
101  status.set(G4PARTICLE_PRIMARY);
102  p->mask = mask;
103  particle_origine->out.insert(p->id);
104  // Insert pair in map. Do not forget to increase reference count!
105  pm->insert(gp,p);
106 
107  if ( dau ) {
108  Geant4Vertex* dv = new Geant4Vertex(*particle_origine);
109  PropertyMask reason(p->reason);
110  reason.set(G4PARTICLE_HAS_SECONDARIES);
111 
112  dv->mask = mask;
113  dv->in.insert(p->id);
114 
115  interaction->vertices[mask].emplace_back(dv) ;
116 
117  for(; dau; dau = dau->GetNext())
118  collectPrimaries(pm, interaction, dv, dau);
119  }
120 }
121 
125  Geant4PrimaryMap* pm,
126  std::set<G4PrimaryVertex*>const& primaries)
127 {
129  interaction->locked = true;
130  interaction->mask = mask;
131  for (auto const& gv: primaries) {
133  v->mask = mask;
134  interaction->vertices[mask].emplace_back(v);
135  for (G4PrimaryParticle *gp = gv->GetPrimary(); gp; gp = gp->GetNext()) {
136  collectPrimaries(pm, interaction, v, gp);
137  }
138  }
139  return interaction;
140 }
141 
144  const Geant4Context* context)
145 {
151  context->event().addExtension(new Geant4PrimaryMap());
152 
153  // The final set of created particles in the simulation.
154  context->event().addExtension(new Geant4ParticleMap());
155 
156  //
157  // The Geant4PrimaryEvent extension contains a whole set of
158  // Geant4PrimaryInteraction objects each may represent a complete
159  // interaction. Particles and vertices may be unbiased.
160  // This is the input to the translator forming the final
161  // Geant4PrimaryInteraction (see below) containing rebiased particle
162  // and vertex maps.
164  context->event().addExtension(evt);
165  //
166  // The Geant4PrimaryInteraction extension contains the final
167  // vertices and particles ready to be injected to Geant4.
169  inter->setNextPID(-1);
170  context->event().addExtension(inter);
171  return 1;
172 }
173 
175 static void appendInteraction(const Geant4Action* caller,
176  Geant4PrimaryInteraction* output,
178 {
179  Geant4PrimaryInteraction::ParticleMap::iterator ip, ipend;
180  for( ip=input->particles.begin(), ipend=input->particles.end(); ip != ipend; ++ip ) {
181  Geant4Particle* p = (*ip).second;
182  output->particles.emplace(p->id,p->addRef());
183  }
184  Geant4PrimaryInteraction::VertexMap::iterator ivfnd, iv, ivend;
185  for( iv=input->vertices.begin(), ivend=input->vertices.end(); iv != ivend; ++iv ) {
186  int theMask = input->mask;
187  ivfnd = output->vertices.find(theMask);
188  if ( ivfnd != output->vertices.end() ) {
189  caller->abortRun("Duplicate primary interaction identifier!",
190  "Cannot handle 2 interactions with identical identifiers!");
191  }
192  for(Geant4Vertex* vtx : (*iv).second )
193  output->vertices[theMask].emplace_back( vtx->addRef() );
194  }
195 }
196 
197 static void rebaseParticles(Geant4PrimaryInteraction::ParticleMap& particles, int &offset) {
198  Geant4PrimaryInteraction::ParticleMap::iterator ip, ipend;
199  int mx_id = offset;
200  // Now move begin and end-vertex of all primary and generator particles accordingly
201  for( ip=particles.begin(), ipend=particles.end(); ip != ipend; ++ip ) {
202  Geant4ParticleHandle p((*ip).second);
203  p.offset(offset);
204  mx_id = p->id+1 > mx_id ? p->id+1 : mx_id;
205  }
206  offset = mx_id;
207 }
208 
209 static void rebaseVertices(Geant4PrimaryInteraction::VertexMap& vertices, int part_offset) {
210  Geant4PrimaryInteraction::VertexMap::iterator iv, ivend;
211  std::set<int> in, out;
212  std::set<int>::iterator i;
213  // Now move begin and end-vertex of all primary vertices accordingly
214  for(iv=vertices.begin(), ivend=vertices.end(); iv != ivend; ++iv) {
215  for( Geant4Vertex* v : (*iv).second ){
216  in = v->in;
217  out = v->out;
218  for(in=v->in, i=in.begin(), v->in.clear(); i != in.end(); ++i)
219  v->in.insert((*i)+part_offset);
220  for(out=v->out, i=out.begin(), v->out.clear(); i != out.end(); ++i)
221  v->out.insert((*i)+part_offset);
222  }
223  }
224 }
227  const Geant4Context* context)
228 {
229  typedef Geant4PrimaryEvent::Interaction Interaction;
230  typedef std::vector<Interaction*> Interactions;
231  Geant4Event& event = context->event();
233  Interaction* output = event.extension<Interaction>();
234  Interactions inter = evt->interactions();
235  int particle_offset = 0;
236 
237  for(Interactions::const_iterator i=inter.begin(); i != inter.end(); ++i) {
238  Interaction* interaction = *i;
239  int vertex_offset = particle_offset;
240  if ( !interaction->applyMask() ) {
241  caller->abortRun("Found single interaction with multiple primary vertices!",
242  "Cannot merge individual interactions with more than one primary!");
243  }
244  rebaseParticles(interaction->particles,particle_offset);
245  rebaseVertices(interaction->vertices,vertex_offset);
246  appendInteraction(caller,output,interaction);
247  }
248  output->setNextPID(particle_offset);
249  Geant4PrimaryInteraction::ParticleMap::iterator ip, ipend;
250  caller->debug("+++ Merging MC input record from %d interactions:",(int)inter.size());
251  for( ip=output->particles.begin(), ipend=output->particles.end(); ip != ipend; ++ip )
252  Geant4ParticleHandle((*ip).second).dump1(DEBUG,caller->name(),"Merged particles");
253  return 1;
254 }
255 
259  double alpha)
260 {
261 #define SQR(x) (x*x)
262  Geant4PrimaryEvent::Interaction::VertexMap::iterator iv;
263  Geant4PrimaryEvent::Interaction::ParticleMap::iterator ip;
264  double gamma = std::sqrt(1 + SQR(tan(alpha)));
265  double betagamma = std::tan(alpha);
266 
267  if ( inter->locked ) {
268  caller->abortRun("Locked interactions may not be boosted!",
269  "Cannot boost interactions with a native G4 primary record!");
270  }
271  else if ( alpha != 0.0 ) {
272  // Now move begin and end-vertex of all primary vertices accordingly
273  for(iv=inter->vertices.begin(); iv != inter->vertices.end(); ++iv){
274  for( Geant4Vertex* v : (*iv).second ) {
275  double t = gamma * v->time + betagamma * v->x / CLHEP::c_light;
276  double x = gamma * v->x + betagamma * CLHEP::c_light * v->time;
277  double y = v->y;
278  double z = v->z;
279  v->x = x;
280  v->y = y;
281  v->z = z;
282  v->time = t;
283  }
284  }
285  // Now move begin and end-vertex of all primary and generator particles accordingly
286  for(ip=inter->particles.begin(); ip != inter->particles.end(); ++ip) {
287  Geant4ParticleHandle p = (*ip).second;
288  double t = gamma * p->time + betagamma * p->vsx / CLHEP::c_light;
289  double x = gamma * p->vsx + betagamma * CLHEP::c_light * p->time;
290  double y = p->vsy;
291  double z = p->vsz;
292 
293  double m = p->mass;
294  double e2 = SQR(p->psx)+SQR(p->psy)+SQR(p->psz)+SQR(m);
295  double px = betagamma * std::sqrt(e2) + gamma * p->psx;
296  double py = p->psy;
297  double pz = p->psz;
298 
299  p->vsx = x;
300  p->vsy = y;
301  p->vsz = z;
302  p->time = t;
303 
304  p->psx = px;
305  p->psy = py;
306  p->psz = pz;
307  }
308  }
309  return 1;
310 }
311 
315  double dx, double dy, double dz, double dt)
316 {
317  Geant4PrimaryEvent::Interaction::VertexMap::iterator iv;
318  Geant4PrimaryEvent::Interaction::ParticleMap::iterator ip;
319 
320  if ( inter->locked ) {
321  caller->abortRun("Locked interactions may not be smeared!",
322  "Cannot smear interactions with a native G4 primary record!");
323  }
324 
325  // Now move begin and end-vertex of all primary vertices accordingly
326  for(iv=inter->vertices.begin(); iv != inter->vertices.end(); ++iv) {
327  for( Geant4Vertex* v : (*iv).second ){
328  v->x += dx;
329  v->y += dy;
330  v->z += dz;
331  v->time += dt;
332  }
333  }
334  // Now move begin and end-vertex of all primary and generator particles accordingly
335  for(ip=inter->particles.begin(); ip != inter->particles.end(); ++ip) {
336  Geant4Particle* p = (*ip).second;
337  p->vsx += dx;
338  p->vsy += dy;
339  p->vsz += dz;
340  p->vex += dx;
341  p->vey += dy;
342  p->vez += dz;
343  p->time += dt;
344  }
345  return 1;
346 }
347 
348 static G4PrimaryParticle* createG4Primary(const Geant4ParticleHandle p) {
349  G4PrimaryParticle* g4 = 0;
350  const G4ParticleDefinition* def = p.definition();
352  double energy = p.energy();
353  double mom2 = (p->psx*p->psx) + (p->psy*p->psy) + (p->psz*p->psz);
354  double mass2 = energy*energy - mom2;
355  if ( mass2 < 0e0 ) {
356  if ( def ) {
357  mass2 = def->GetPDGMass() * def->GetPDGMass();
358  }
359  energy = std::sqrt(mom2 + mass2);
360  if ( std::fabs(p.energy()-energy) > 0e0 /* 1e-10 */ ) {
361  dd4hep::printout(dd4hep::INFO,"createG4Primary",
362  "Change particle %s energy from %10.5f MeV by %g ppm to avoid negative Energy^2",
363  (def) ? def->GetParticleName().c_str() : "???", p.energy(), std::fabs(p.energy()-energy)*1e6);
364  }
365  }
366  if ( 0 != p->pdgID ) {
367  // For ions we use the pdgID of the definition, in case we had to zero the excitation level, see Geant4Particle.cpp
368  const int pdgID = p->pdgID < 1000000000 ? p->pdgID : p.definition()->GetPDGEncoding();
369  g4 = new G4PrimaryParticle(pdgID, p->psx, p->psy, p->psz, energy);
370  }
371  else {
372  g4 = new G4PrimaryParticle(def, p->psx, p->psy, p->psz, energy);
373  g4->SetCharge(double(p.charge())/3.0);
374  }
375  // The particle is fully defined with the 4-vector set above, setting the mass isn't necessary, not
376  // using the 4-vector, means the PDG mass is used, and the momentum is scaled if the mass is set here
377  // g4->SetMass(p->mass);
378  return g4;
379 }
380 
381 static std::vector< std::pair<Geant4Particle*,G4PrimaryParticle*> >
382 getRelevant(std::set<int>& visited,
383  std::map<int,G4PrimaryParticle*>& prim,
385  const Geant4PrimaryConfig& primaryConfig,
386  const Geant4ParticleHandle p)
387 {
388  typedef std::vector< std::pair<Geant4Particle*,G4PrimaryParticle*> > Primaries;
389  using dd4hep::printout;
390 
391  Primaries res;
392  visited.insert(p->id);
393  PropertyMask status(p->status);
394  if ( status.isSet(G4PARTICLE_GEN_STABLE) ) {
395  bool rejectParticle = false
396  or (primaryConfig.m_rejectPDGs.count(abs(p->pdgID)) != 0) // quarks, gluon, "strings", W, Z etc.
397  ;
398  printout(dd4hep::DEBUG, "Input",
399  "Checking rejection of stable: PDG(%-10d), Definition(%s), reject(%s)",
400  p->pdgID,
401  p.definition() ? "true" : "false",
402  rejectParticle ? "true" : "false");
403  if (not rejectParticle and prim.find(p->id) == prim.end() ) {
404  G4PrimaryParticle* p4 = createG4Primary(p);
405  prim[p->id] = p4;
406  res.emplace_back(p,p4);
407  }
408  }
409  else if ( p->daughters.size() > 0 ) {
410  const Geant4Particle::Particles& dau = p->daughters;
411  int first_daughter = *(dau.begin());
412  Geant4ParticleHandle dp = pm[first_daughter];
413  double en = p.energy();
414  double me = en > std::numeric_limits<double>::epsilon() ? p->mass / en : 0.0;
415  // fix by S.Morozov for real != 0
416  double proper_time = fabs(dp->time-p->time) * me;
417  double proper_time_Precision = pow(10.,-DBL_DIG)*fabs(me)*fmax(fabs(p->time),fabs(dp->time));
418  bool isProperTimeZero = (fabs(proper_time) <= fabs(proper_time_Precision));
419 
420  // -- remove original if ---
421  bool rejectParticle = not p.definition() // completely unknown to geant4
422  or (primaryConfig.m_rejectPDGs.count(abs(p->pdgID)) != 0) // quarks, gluon, "strings", W, Z etc.
423  or (isProperTimeZero and p.definition()->GetPDGStable() ) // initial state electrons, etc.
424  or (isProperTimeZero and primaryConfig.m_zeroTimePDGs.count(abs(p->pdgID)) != 0 ) // charged 'documentation' leptons, e.g. in lepton pairs w/ FSR
425  or (status.isSet(G4PARTICLE_GEN_DOCUMENTATION) || status.isSet(G4PARTICLE_GEN_BEAM) || status.isSet(G4PARTICLE_GEN_OTHER)) // documentation generator status
426  or false;
427 
428  printout(dd4hep::DEBUG, "Input",
429  "Checking rejection: PDG(%-10d), Definition(%s), isProperTimeZero(%s, %3.15f), stable(%s), doc(%s), reject(%s)",
430  p->pdgID,
431  p.definition() ? "true" : "false",
432  isProperTimeZero ? "true" : "false", proper_time,
433  (bool(p.definition()) ? p.definition()->GetPDGStable() : false) ? "true" : "false",
434  status.isSet(G4PARTICLE_GEN_DOCUMENTATION) || status.isSet(G4PARTICLE_GEN_BEAM) || status.isSet(G4PARTICLE_GEN_OTHER) ? "true" : "false",
435  rejectParticle ? "true" : "false");
436  // end running simulation if we have a really inconsistent record, that is unrejected stable particle with children
437  bool failStableWithChildren = (not rejectParticle and p.definition()->GetPDGStable());
438  if (failStableWithChildren) {
439  printout(dd4hep::FATAL,"Input",
440  "+++ Stable particle (PDG: %-10d) with daughters! check your MC record, adapt particle.tbl file...",
441  p->pdgID);
442  throw std::runtime_error("Cannot Simmulate this MC Record");
443  }
444  if (not rejectParticle) {
445  std::map<int, G4PrimaryParticle*>::iterator ip4 = prim.find(p->id);
446  G4PrimaryParticle* p4 = (ip4 == prim.end()) ? 0 : (*ip4).second;
447  if ( !p4 ) {
448  p4 = createG4Primary(p);
449  p4->SetProperTime(proper_time);
450  prim[p->id] = p4;
451  Primaries daughters;
452  for(Geant4Particle::Particles::const_iterator i=dau.begin(); i!=dau.end(); ++i) {
453  if ( visited.find(*i) == visited.end() ) {
454  Primaries tmp = getRelevant(visited,prim,pm,primaryConfig,pm[*i]);
455  daughters.insert(daughters.end(), tmp.begin(),tmp.end());
456  }
457  }
458  for(Primaries::iterator i=daughters.begin(); i!=daughters.end(); ++i)
459  p4->SetDaughter((*i).second);
460  }
461  res.emplace_back(p,p4);
462  }
463  else {
464  for(Geant4Particle::Particles::const_iterator i=dau.begin(); i!=dau.end(); ++i) {
465  if ( visited.find(*i) == visited.end() ) {
466  Primaries tmp = getRelevant(visited,prim,pm,primaryConfig,pm[*i]);
467  res.insert(res.end(), tmp.begin(),tmp.end());
468  }
469  }
470  }
471  }
472  return res;
473 }
474 
477  const Geant4Context* context,
478  G4Event* event)
479 {
480  typedef std::vector< std::pair<Geant4Particle*,G4PrimaryParticle*> > Primaries;
481  typedef Geant4PrimaryInteraction Interaction;
482  Geant4PrimaryMap* primaries = context->event().extension<Geant4PrimaryMap>();
483  Interaction* interaction = context->event().extension<Interaction>();
484  Interaction::ParticleMap& pm = interaction->particles;
485  Interaction::VertexMap& vm = interaction->vertices;
486  std::map<int,G4PrimaryParticle*> prim;
487  std::set<int> visited;
488 
489  auto const* primHandler = dynamic_cast<const Geant4PrimaryHandler*>(caller);
490  auto const& primaryConfig = primHandler ? primHandler->m_primaryConfig : Geant4PrimaryConfig();
491 
492  caller->debug("PrimaryConfiguration:%s", primaryConfig.toString().c_str());
493 
494  if ( interaction->locked ) {
495  caller->abortRun("Locked interactions may not be used to generate primaries!",
496  "Cannot handle a native G4 primary record!");
497  return 0;
498  }
499  else {
500  Geant4PrimaryInteraction::VertexMap::iterator ivfnd, iv, ivend;
501  for(Interaction::VertexMap::const_iterator iend=vm.end(),i=vm.begin(); i!=iend; ++i) {
502  for( Geant4Vertex* v : (*i).second ){
503 
504  int num_part = 0;
505  G4PrimaryVertex* v4 = new G4PrimaryVertex(v->x,v->y,v->z,v->time);
506  event->AddPrimaryVertex(v4);
507  caller->print("+++++ G4PrimaryVertex at (%+.2e,%+.2e,%+.2e) [mm] %+.2e [ns]",
508  v->x/CLHEP::mm,v->y/CLHEP::mm,v->z/CLHEP::mm,v->time/CLHEP::ns);
509  for(Geant4Vertex::Particles::const_iterator ip=v->out.begin(); ip!=v->out.end(); ++ip) {
510  Geant4ParticleHandle p = pm[*ip];
511  if ( p->daughters.size() > 0 ) {
512  PropertyMask mask(p->reason);
513  mask.set(G4PARTICLE_HAS_SECONDARIES);
514  }
515  if ( p->parents.size() == 0 ) {
516  Primaries relevant = getRelevant(visited,prim,pm,primaryConfig,p);
517  for(Primaries::const_iterator j=relevant.begin(); j!= relevant.end(); ++j) {
518  Geant4ParticleHandle r = (*j).first;
519  G4PrimaryParticle* p4 = (*j).second;
520  PropertyMask reason(r->reason);
521  char text[64];
522 
523  reason.set(G4PARTICLE_PRIMARY);
524  v4->SetPrimary(p4);
525  ::snprintf(text,sizeof(text),"-> G4Primary[%3d]",num_part);
526  r.dumpWithMomentum(caller->outputLevel()-1,caller->name(),text);
527  ++num_part;
528  }
529  }
530  }
531  if(caller->outputLevel() <= VERBOSE){
532  v4->Print();
533  }
534  }
535  }
536  for( const auto& vtx : prim ) {
537  Geant4ParticleHandle p = pm[vtx.first];
538  primaries->insert(vtx.second, p);
539  }
540  }
541  return 1;
542 }
dd4hep::sim::createPrimary
Geant4Vertex * createPrimary(const G4PrimaryVertex *g4)
Create a vertex object from its G4 counterpart.
Definition: Geant4InputHandling.cpp:39
dd4hep::sim::Geant4PrimaryEvent
Class modelling a complete primary event with multiple interactions.
Definition: Geant4Primary.h:143
dd4hep::sim::Geant4PrimaryMap
Data structure to map primaries to particles.
Definition: Geant4Primary.h:64
dd4hep::sim::Geant4PrimaryConfig::m_rejectPDGs
std::set< int > m_rejectPDGs
particles with these PDG IDs are not passed to geant for simulation
Definition: Geant4PrimaryHandler.h:42
dd4hep::sim::Geant4Particle::vsz
double vsz
Definition: Geant4Particle.h:124
dd4hep::sim::Geant4Particle::reason
int reason
Definition: Geant4Particle.h:111
dd4hep::sim::Geant4ParticleHandle::dump1
void dump1(int level, const std::string &src, const char *tag) const
Various output formats:
Definition: Geant4Particle.cpp:264
dd4hep::sim::G4PARTICLE_GEN_STABLE
@ G4PARTICLE_GEN_STABLE
Definition: Geant4Particle.h:71
v
View * v
Definition: MultiView.cpp:28
dd4hep::sim::Geant4Particle::mass
double mass
Particle mass.
Definition: Geant4Particle.h:132
dd4hep::sim::Geant4Particle::vey
double vey
Definition: Geant4Particle.h:126
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::Geant4PrimaryConfig
Geant4PrimaryConfig to hold configuration for PrimaryHandlers.
Definition: Geant4PrimaryHandler.h:39
dd4hep::sim::Geant4Particle::addRef
Geant4Particle * addRef()
Increase reference count.
Definition: Geant4Particle.h:159
Geant4PrimaryHandler.h
dd4hep::sim::Geant4PrimaryInteraction::locked
int locked
Flag that the event is locked for G4 native generators.
Definition: Geant4Primary.h:118
dd4hep::sim::Geant4Particle::id
int id
not persistent
Definition: Geant4Particle.h:108
dd4hep::sim::mergeInteractions
int mergeInteractions(const Geant4Action *caller, const Geant4Context *context)
Merge all interactions present in the context.
Definition: Geant4InputHandling.cpp:226
dd4hep::sim::Geant4Action::abortRun
void abortRun(const std::string &exception, const char *fmt,...) const
Abort Geant4 Run by throwing a G4Exception with type RunMustBeAborted.
Definition: Geant4Action.cpp:266
dd4hep::sim::Geant4Vertex::mask
int mask
Vertex mask to associate particles from collision.
Definition: Geant4Vertex.h:51
dd4hep::sim::generationInitialization
int generationInitialization(const Geant4Action *caller, const Geant4Context *context)
Initialize the generation of one event.
Definition: Geant4InputHandling.cpp:143
dd4hep::sim::Geant4PrimaryInteraction::vertices
VertexMap vertices
The map of primary vertices for the particles.
Definition: Geant4Primary.h:110
dd4hep::sim::Geant4Particle::pdgID
int pdgID
Definition: Geant4Particle.h:115
dd4hep::sim::Geant4Vertex::addRef
Geant4Vertex * addRef()
Increase reference count.
Definition: Geant4Vertex.cpp:58
dd4hep::sim::Geant4Particle::psz
double psz
Definition: Geant4Particle.h:128
dd4hep::sim::Geant4PrimaryInteraction::particles
ParticleMap particles
The map of particles participating in this primary interaction.
Definition: Geant4Primary.h:112
dd4hep::sim::Geant4Context::event
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Definition: Geant4Context.cpp:84
dd4hep::sim::Geant4PrimaryInteraction::mask
int mask
User mask to flag the interaction. Also unique identifier.
Definition: Geant4Primary.h:116
Geant4InputHandling.h
dd4hep::sim::G4PARTICLE_GEN_DOCUMENTATION
@ G4PARTICLE_GEN_DOCUMENTATION
Definition: Geant4Particle.h:73
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
Geant4PrimaryHandler
Geant4Action to convert the particle information to Geant4.
dd4hep::sim::generatePrimaries
int generatePrimaries(const Geant4Action *caller, const Geant4Context *context, G4Event *event)
Generate all primary vertices corresponding to the merged interaction.
Definition: Geant4InputHandling.cpp:476
epsilon
const double epsilon
Definition: test_cellid_position_converter.cpp:41
dd4hep::sim::Geant4ParticleHandle::charge
double charge() const
Geant4 charge of the particle.
Definition: Geant4Particle.h:211
dd4hep::sim::Geant4ParticleMap
Data structure to map particles produced during the generation and the simulation.
Definition: Geant4Particle.h:337
dd4hep::sim::Geant4Event::extension
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Definition: Geant4Context.h:151
dd4hep::sim::Geant4Particle::Particles
std::set< int > Particles
Definition: Geant4Particle.h:105
dd4hep::sim::Geant4Particle::vez
double vez
Definition: Geant4Particle.h:126
dd4hep::sim::Geant4Particle::colorFlow
int colorFlow[2]
Definition: Geant4Particle.h:117
dd4hep::sim::Geant4Particle::spin
float spin[3]
Definition: Geant4Particle.h:121
dd4hep::sim::Geant4Particle::status
int status
Definition: Geant4Particle.h:116
dd4hep::sim::Geant4Particle::daughters
Particles daughters
The list of daughters of this MC particle.
Definition: Geant4Particle.h:140
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4Particle::mask
int mask
Definition: Geant4Particle.h:112
dd4hep::sim::Geant4Particle::time
double time
Particle creation time.
Definition: Geant4Particle.h:134
SQR
#define SQR(x)
dd4hep::sim::Geant4Action::outputLevel
PrintLevel outputLevel() const
Access the output level.
Definition: Geant4Action.h:296
dd4hep::sim::Geant4PrimaryConfig::toString
std::string toString() const
Definition: Geant4PrimaryHandler.h:46
dd4hep::sim::Geant4Vertex::out
Particles out
The list of outgoing particles.
Definition: Geant4Vertex.h:55
dd4hep::sim::Geant4Action::print
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
Definition: Geant4Action.cpp:144
dd4hep::sim::G4PARTICLE_HAS_SECONDARIES
@ G4PARTICLE_HAS_SECONDARIES
Definition: Geant4Particle.h:59
dd4hep::sim::Geant4Particle::vex
double vex
The end vertex.
Definition: Geant4Particle.h:126
dd4hep::sim::Geant4Particle::vsx
double vsx
The starting vertex.
Definition: Geant4Particle.h:124
dd4hep::sim::Geant4Particle::psx
double psx
The track momentum at the start vertex.
Definition: Geant4Particle.h:128
dd4hep::sim::G4PARTICLE_GEN_BEAM
@ G4PARTICLE_GEN_BEAM
Definition: Geant4Particle.h:74
dd4hep::sim::Geant4ParticleHandle::definition
const G4ParticleDefinition * definition() const
Access the Geant4 particle definition object (expensive!)
Definition: Geant4Particle.cpp:116
dd4hep::sim::Geant4Event::addExtension
void * addExtension(unsigned long long int k, ExtensionEntry *e)
Add an extension object to the detector element.
Definition: Geant4Context.h:140
dd4hep::sim::smearInteraction
int smearInteraction(const Geant4Action *caller, Geant4PrimaryEvent::Interaction *inter, double dx, double dy, double dz, double dt)
Smear the primary vertex of an interaction.
Definition: Geant4InputHandling.cpp:313
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
PropertyMask
dd4hep::detail::ReferenceBitMask< int > PropertyMask
Definition: HepMC3EventReader.cpp:37
Geant4Primary.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4ParticleHandle
Data structure to access derived MC particle information.
Definition: Geant4Particle.h:181
dd4hep::sim::Geant4ParticleHandle::dumpWithMomentum
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,...
Definition: Geant4Particle.cpp:331
dd4hep::sim::Geant4Particle::parents
Particles parents
The list of parents of this MC particle.
Definition: Geant4Particle.h:138
dd4hep::sim::Geant4Vertex::in
Particles in
The list of incoming particles.
Definition: Geant4Vertex.h:57
dd4hep::sim::Geant4Particle::vsy
double vsy
Definition: Geant4Particle.h:124
dd4hep::sim::boostInteraction
int boostInteraction(const Geant4Action *caller, Geant4PrimaryEvent::Interaction *inter, double alpha)
Boost particles of one interaction identified by its mask.
Definition: Geant4InputHandling.cpp:257
dd4hep::sim::Geant4Action::debug
void debug(const char *fmt,...) const
Support of debug messages.
Definition: Geant4Action.cpp:207
dd4hep::sim::Geant4PrimaryEvent::extension
ExtensionHandle extension
User data extension if required.
Definition: Geant4Primary.h:161
dd4hep::sim::Geant4PrimaryInteraction::ParticleMap
std::map< int, Particle * > ParticleMap
Definition: Geant4Primary.h:105
dd4hep::sim::G4PARTICLE_PRIMARY
@ G4PARTICLE_PRIMARY
Definition: Geant4Particle.h:58
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::Geant4Particle::charge
char charge
Definition: Geant4Particle.h:119
dd4hep::sim::Geant4ParticleHandle::energy
double energy() const
Scalar particle energy.
Definition: Geant4Particle.h:308
dd4hep::sim::Geant4PrimaryMap::get
Geant4Particle * get(const G4PrimaryParticle *particle)
Access DDG4 particle by G4 primary particle.
Definition: Geant4Primary.cpp:44
dd4hep::sim::Geant4Particle::psy
double psy
Definition: Geant4Particle.h:128
dd4hep::sim::Geant4Event
User event context for DDG4.
Definition: Geant4Context.h:121
dd4hep::sim::G4PARTICLE_GEN_OTHER
@ G4PARTICLE_GEN_OTHER
Definition: Geant4Particle.h:76
Printout.h
Geant4Context.h
dd4hep::sim::Geant4PrimaryInteraction::extension
ExtensionHandle extension
User data extension if required.
Definition: Geant4Primary.h:114
Geant4Action.h
dd4hep::sim::Geant4Particle::properTime
double properTime
Proper time.
Definition: Geant4Particle.h:136
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4PrimaryInteraction::VertexMap
std::map< int, std::vector< Vertex * > > VertexMap
Definition: Geant4Primary.h:106