Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/DDG4/Geant4SensDetAction.inl is written in an unsupported language. File is not indexed.

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/Geant4SensDetAction.h>
0016 #include <DD4hep/Detector.h>
0017 #include <DD4hep/InstanceCount.h>
0018 #include <DD4hep/detail/ObjectsInterna.h>
0019 
0020 #include <DDG4/Geant4ReadoutVolumeFilter.h>
0021 #include <DDG4/Geant4Data.h>
0022 
0023 /// Namespace for the AIDA detector description toolkit
0024 namespace dd4hep {
0025 
0026   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0027   namespace sim   {
0028 
0029     /// Standard , initializing constructor
0030     template <typename T>
0031     Geant4SensitiveAction<T>::Geant4SensitiveAction(Geant4Context* ctxt,
0032                                                     const std::string& nam,
0033                                                     DetElement det,
0034                                                     Detector& description_ref)
0035       : Geant4Sensitive(ctxt,nam,det,description_ref), m_collectionName(), m_collectionID(0)
0036     {
0037       declareProperty("ReadoutName",    m_readoutName);
0038       declareProperty("CollectionName", m_collectionName);
0039       initialize();
0040       InstanceCount::increment(this);
0041     }
0042 
0043     /// Default destructor
0044     template <typename T> Geant4SensitiveAction<T>::~Geant4SensitiveAction()  {
0045       finalize();
0046       InstanceCount::decrement(this);
0047     }
0048 
0049     /// Initialization overload for specialization
0050     template <typename T> void Geant4SensitiveAction<T>::initialize()   {
0051     }
0052 
0053     /// Finalization overload for specialization
0054     template <typename T> void Geant4SensitiveAction<T>::finalize()   {
0055     }
0056 
0057     /// Access the readout object. Note: if m_readoutName is set, the m_readout != m_sensitive.readout()
0058     template <typename T> Readout Geant4SensitiveAction<T>::readout()    {
0059       if ( !m_readoutName.empty() && m_sensitive.readout() == m_readout )  {
0060         m_readout = detectorDescription().readout(m_readoutName);
0061         if ( !m_readout.isValid() )  {
0062           except("+++ Failed to access parallel readout '%s'",m_sensitive.name());
0063         }
0064         m_segmentation = m_readout.segmentation();
0065         if ( !m_segmentation.isValid() )  {
0066           except("+++ Failed to access segmentation for readout '%s'",m_readout.name());
0067         }
0068       }
0069       return m_readout;
0070     }
0071 
0072     /// G4VSensitiveDetector interface: Method invoked at the begining of each event.
0073     template <typename T> void Geant4SensitiveAction<T>::begin(G4HCofThisEvent* hce)  {
0074       Geant4Sensitive::begin(hce);
0075     }
0076 
0077     /// G4VSensitiveDetector interface: Method invoked at the end of each event.
0078     template <typename T> void Geant4SensitiveAction<T>::end(G4HCofThisEvent* hce)  {
0079       Geant4Sensitive::end(hce);
0080     }
0081 
0082     /// G4VSensitiveDetector interface: Method invoked if the event was aborted.
0083     template <typename T> void Geant4SensitiveAction<T>::clear(G4HCofThisEvent* hce)  {
0084       Geant4Sensitive::clear(hce);
0085     }
0086 
0087     /// Define collections created by this sensitivie action object
0088     template <typename T> void Geant4SensitiveAction<T>::defineCollections()  {
0089     }
0090 
0091     /// Define readout specific hit collection. matching name must be present in readout structure
0092     template <typename T> template <typename HIT> 
0093     std::size_t Geant4SensitiveAction<T>::defineReadoutCollection(const std::string match_name)  {
0094       auto ro = readout();
0095       for(const auto& c : ro->hits )  {
0096         if ( c.name == match_name )  {
0097           std::size_t coll_id = defineCollection<HIT>(match_name);
0098           Geant4Filter* filter = new Geant4ReadoutVolumeFilter(context(),name()+"_"+c.name,ro,c.name);
0099           adopt_front(filter);
0100           return coll_id;
0101         }
0102       }
0103       except("+++ Custom collection name '%s' not defined in the Readout object: %s.",
0104              m_collectionName.c_str(), ro.name());
0105       return 0; // Anyhow not reachable. Exception thrown before
0106     }
0107 
0108     /// Define readout specific hit collection with volume ID filtering
0109     template <typename T> template <typename HIT> 
0110     std::size_t Geant4SensitiveAction<T>::declareReadoutFilteredCollection()   {
0111       if ( m_collectionName.empty() )  {
0112         return defineCollection<HIT>(readout().name());
0113       }
0114       return defineReadoutCollection<HIT>(m_collectionName);
0115     }
0116 
0117     /// G4VSensitiveDetector interface: Method for generating hit(s) using the G4Step object.
0118     template <typename T> bool Geant4SensitiveAction<T>::process(const G4Step* step,G4TouchableHistory* history)  {
0119       return Geant4Sensitive::process(step, history);
0120     }
0121     
0122     /// GFlash/Fast Simulation interface: Method for generating hit(s) using the information from fast simulation
0123     template <typename T> bool Geant4SensitiveAction<T>::processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history)  {
0124       return Geant4Sensitive::processFastSim(spot, history);
0125     }
0126 
0127     // Forward declarations
0128     typedef Geant4HitData::Contribution HitContribution;
0129 
0130 
0131   }    // End namespace sim
0132 }      // End namespace dd4hep
0133 
0134 
0135 #include <DD4hep/Printout.h>
0136 #include <DDG4/Geant4TouchableHandler.h>
0137 #include <DDG4/Geant4StepHandler.h>
0138 #include <DDG4/Geant4VolumeManager.h>