Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:25

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DDG4/Geant4GeneratorWrapper.h>
0016 
0017 #include <DD4hep/InstanceCount.h>
0018 #include <DD4hep/Plugins.h>
0019 #include <DD4hep/Printout.h>
0020 #include <DDG4/Geant4Context.h>
0021 #include <DDG4/Geant4Primary.h>
0022 #include <DDG4/Geant4InputHandling.h>
0023 
0024 // Geant4 include files
0025 #include <G4Event.hh>
0026 #include <G4PrimaryVertex.hh>
0027 #include <G4PrimaryParticle.hh>
0028 #include <G4VPrimaryGenerator.hh>
0029 
0030 // C/C++ include files
0031 #include <stdexcept>
0032 #include <set>
0033 
0034 using namespace dd4hep::sim;
0035 
0036 /// Standard constructor
0037 Geant4GeneratorWrapper::Geant4GeneratorWrapper(Geant4Context* ctxt, const std::string& nam)
0038   : Geant4GeneratorAction(ctxt,nam)
0039 {
0040   declareProperty("Uses", m_generatorType);
0041   declareProperty("Mask", m_mask = 1);
0042   InstanceCount::increment(this);
0043 }
0044   
0045 /// Default destructor
0046 Geant4GeneratorWrapper::~Geant4GeneratorWrapper()  {
0047   detail::deletePtr(m_generator);
0048   InstanceCount::decrement(this);
0049 }
0050 
0051 G4VPrimaryGenerator* Geant4GeneratorWrapper::generator()   {
0052   if ( 0 == m_generator )  {
0053     m_generator = PluginService::Create<G4VPrimaryGenerator*>(m_generatorType);
0054     if ( 0 == m_generator )  {
0055       PluginDebug dbg;
0056       m_generator = PluginService::Create<G4VPrimaryGenerator*>(m_generatorType);
0057       if ( !m_generator )  {
0058         except("Geant4GeneratorWrapper: FATAL Failed to create G4VPrimaryGenerator of type %s.",
0059                m_generatorType.c_str());
0060       }
0061     }
0062   }
0063   return m_generator;
0064 }
0065 
0066 /// Event generation action callback
0067 void Geant4GeneratorWrapper::operator()(G4Event* event)  {
0068   Geant4PrimaryEvent* prim = context()->event().extension<Geant4PrimaryEvent>();
0069   Geant4PrimaryMap*   primaryMap = context()->event().extension<Geant4PrimaryMap>();
0070   std::set<G4PrimaryVertex*> primaries;
0071   
0072   // Now generate the new interaction
0073   generator()->GeneratePrimaryVertex(event);
0074 
0075   /// Collect all existing interactions (primary vertices)
0076   for(G4PrimaryVertex* v=event->GetPrimaryVertex(); v; v=v->GetNext())
0077     primaries.insert(v);
0078 
0079   // Add all the missing interactions (primary vertices) to the primary event record.
0080   Geant4PrimaryInteraction* inter = createPrimary(m_mask, primaryMap, primaries);
0081   prim->add(m_mask, inter);
0082 }