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