Back to home page

EIC code displayed by LXR

 
 

    


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

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 Markus Frank
0011 //  \date   2015-11-09
0012 //
0013 //==========================================================================
0014 
0015 // Framework include files
0016 #include <DDG4/Geant4DetectorConstruction.h>
0017 
0018 /// Namespace for the AIDA detector description toolkit
0019 namespace dd4hep {
0020 
0021   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0022   namespace sim {
0023 
0024     /// Class to create Geant4 detector geometry from TGeo representation in memory
0025     /**
0026      *  On demand the sensitive detectors are created and attached to all sensitive
0027      *  volumes. The relevant  callback is executed when the call to 
0028      *  ConstructSDandField() of the corresponding G4VUserDetectorConstruction
0029      *  instance is called. The call is thread-local!
0030      *
0031      *  \author  M.Frank
0032      *  \version 1.0
0033      *  \ingroup DD4HEP_SIMULATION
0034      */
0035     class Geant4DetectorSensitivesConstruction : public Geant4DetectorConstruction   {
0036     public:
0037       /// Initializing constructor for DDG4
0038       Geant4DetectorSensitivesConstruction(Geant4Context* ctxt, const std::string& nam);
0039       /// Default destructor
0040       virtual ~Geant4DetectorSensitivesConstruction();
0041       /// Sensitives construction callback. Called at "ConstructSDandField()"
0042       void constructSensitives(Geant4DetectorConstructionContext* ctxt);
0043     };
0044   }    // End namespace sim
0045 }      // End namespace dd4hep
0046 
0047 
0048 // Framework include files
0049 #include <DD4hep/InstanceCount.h>
0050 #include <DD4hep/Printout.h>
0051 #include <DD4hep/Plugins.h>
0052 #include <DD4hep/Detector.h>
0053 
0054 #include <DDG4/Geant4Mapping.h>
0055 #include <DDG4/Geant4Kernel.h>
0056 #include <DDG4/Factories.h>
0057 
0058 // ROOT include files
0059 #include <TGeoManager.h>
0060 // Geant4 include files
0061 #include <G4SDManager.hh>
0062 #include <G4PVPlacement.hh>
0063 #include <G4VSensitiveDetector.hh>
0064 
0065 using namespace dd4hep::sim;
0066 
0067 DECLARE_GEANT4ACTION(Geant4DetectorSensitivesConstruction)
0068 
0069 /// Initializing constructor for other clients
0070 Geant4DetectorSensitivesConstruction::Geant4DetectorSensitivesConstruction(Geant4Context* ctxt, const std::string& nam)
0071 : Geant4DetectorConstruction(ctxt,nam)
0072 {
0073   InstanceCount::increment(this);
0074 }
0075 
0076 /// Default destructor
0077 Geant4DetectorSensitivesConstruction::~Geant4DetectorSensitivesConstruction() {
0078   InstanceCount::decrement(this);
0079 }
0080 
0081 /// Sensitive detector construction callback. Called at "ConstructSDandField()"
0082 void Geant4DetectorSensitivesConstruction::constructSensitives(Geant4DetectorConstructionContext* ctxt)   {
0083   Geant4GeometryInfo* p = Geant4Mapping::instance().ptr();
0084   const Geant4Kernel& kernel = context()->kernel();
0085   const auto&         types  = kernel.sensitiveDetectorTypes();
0086   const std::string&  dflt   = kernel.defaultSensitiveDetectorType();
0087   for( const auto& iv : p->sensitives )  {
0088     SensitiveDetector sd = iv.first;
0089     std::string nam  = sd.name();
0090     auto        iter = types.find(nam);
0091     std::string typ  = (iter != types.end()) ? (*iter).second : dflt;
0092     G4VSensitiveDetector* g4sd = this->createSensitiveDetector(typ, nam);
0093     for( const TGeoVolume* vol : iv.second )  {
0094       G4LogicalVolume* g4v = p->g4Volumes[vol];
0095       if( !g4v )  {
0096         except("ConstructSDandField: Failed to access G4LogicalVolume for SD %s of type %s.",
0097                nam.c_str(), typ.c_str());
0098       }
0099       ctxt->setSensitiveDetector(g4v, g4sd);
0100     }
0101   }
0102   print("+++ Handled %ld sensitive detectors.",p->sensitives.size());
0103 }