DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4GeneratorWrapper.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
16 
17 #include <DD4hep/InstanceCount.h>
18 #include <DD4hep/Plugins.h>
19 #include <DD4hep/Printout.h>
20 #include <DDG4/Geant4Context.h>
21 #include <DDG4/Geant4Primary.h>
23 
24 // Geant4 include files
25 #include <G4Event.hh>
26 #include <G4PrimaryVertex.hh>
27 #include <G4PrimaryParticle.hh>
28 #include <G4VPrimaryGenerator.hh>
29 
30 // C/C++ include files
31 #include <stdexcept>
32 #include <set>
33 
34 using namespace dd4hep::sim;
35 
38  : Geant4GeneratorAction(ctxt,nam)
39 {
40  declareProperty("Uses", m_generatorType);
41  declareProperty("Mask", m_mask = 1);
43 }
44 
47  detail::deletePtr(m_generator);
49 }
50 
51 G4VPrimaryGenerator* Geant4GeneratorWrapper::generator() {
52  if ( 0 == m_generator ) {
53  m_generator = PluginService::Create<G4VPrimaryGenerator*>(m_generatorType);
54  if ( 0 == m_generator ) {
55  PluginDebug dbg;
56  m_generator = PluginService::Create<G4VPrimaryGenerator*>(m_generatorType);
57  if ( !m_generator ) {
58  except("Geant4GeneratorWrapper: FATAL Failed to create G4VPrimaryGenerator of type %s.",
59  m_generatorType.c_str());
60  }
61  }
62  }
63  return m_generator;
64 }
65 
67 void Geant4GeneratorWrapper::operator()(G4Event* event) {
70  std::set<G4PrimaryVertex*> primaries;
71 
72  // Now generate the new interaction
73  generator()->GeneratePrimaryVertex(event);
74 
76  for(G4PrimaryVertex* v=event->GetPrimaryVertex(); v; v=v->GetNext())
77  primaries.insert(v);
78 
79  // Add all the missing interactions (primary vertices) to the primary event record.
80  Geant4PrimaryInteraction* inter = createPrimary(m_mask, primaryMap, primaries);
81  prim->add(m_mask, inter);
82 }
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::Geant4GeneratorWrapper::Geant4GeneratorWrapper
Geant4GeneratorWrapper(Geant4Context *context, const std::string &nam)
Standard constructor.
v
View * v
Definition: MultiView.cpp:28
dd4hep::sim::Geant4PrimaryInteraction
Class modelling a single interaction with multiple primary vertices and particles.
Definition: Geant4Primary.h:95
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4GeneratorWrapper::m_mask
int m_mask
Property: interaction identifier mask. name: "Mask".
Definition: Geant4GeneratorWrapper.h:52
dd4hep::sim::Geant4Context::event
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Definition: Geant4Context.cpp:84
Geant4InputHandling.h
dd4hep::sim::Geant4GeneratorWrapper::~Geant4GeneratorWrapper
virtual ~Geant4GeneratorWrapper()
Default destructor.
dd4hep::sim::Geant4GeneratorWrapper::m_generator
G4VPrimaryGenerator * m_generator
Reference to the implementation instance.
Definition: Geant4GeneratorWrapper.h:55
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::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4GeneratorAction
Concrete implementation of the Geant4 generator action base class.
Definition: Geant4GeneratorAction.h:47
Plugins.h
dd4hep::sim::Geant4GeneratorWrapper::operator()
virtual void operator()(G4Event *event) override
Event generation action callback.
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4GeneratorWrapper::generator
G4VPrimaryGenerator * generator()
Access the G4VPrimaryGenerator instance.
Geant4Primary.h
dd4hep::sim::Geant4GeneratorWrapper::m_generatorType
std::string m_generatorType
Property: Type name of the implementation instance. name: "Uses".
Definition: Geant4GeneratorWrapper.h:50
InstanceCount.h
Printout.h
Geant4Context.h
dd4hep::sim::Geant4PrimaryEvent::add
void add(int id, Geant4PrimaryInteraction *interaction)
Add a new interaction object to the event.
Definition: Geant4Primary.cpp:92
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
Geant4GeneratorWrapper.h