Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:23

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 #ifndef DDG4_GEANT4FASTSIMHANDLER_H
0014 #define DDG4_GEANT4FASTSIMHANDLER_H
0015 
0016 // Framework include files
0017 #include <DDG4/Geant4HitHandler.h>
0018 #include <DDG4/Geant4FastSimSpot.h>
0019 
0020 // Geant4 include files
0021 #include <G4VTouchable.hh>
0022 #include <G4VSensitiveDetector.hh>
0023 
0024 /// Namespace for the AIDA detector description toolkit
0025 namespace dd4hep {
0026 
0027   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0028   namespace sim {
0029 
0030     // Forward declarations;
0031     class Geant4FastSimHandler;
0032 
0033     /// Helper class to ease the extraction of information from a G4FastSimSpot object.
0034     /**
0035      *
0036      * Helper/utility class to easily access Geant4 gflashspot/fast simulation information.
0037      * Born by lazyness: Avoid typing millions of statements!
0038      *
0039      *  \author  M.Frank
0040      *  \version 1.0
0041      *  \ingroup DD4HEP_SIMULATION
0042      */
0043     class Geant4FastSimHandler  : public Geant4HitHandler  {
0044     public:
0045       const Geant4FastSimSpot* spot { nullptr };
0046 
0047       /// Inhibit default constructor
0048       Geant4FastSimHandler() = delete;
0049       /// Initializing constructor
0050       Geant4FastSimHandler(const Geant4FastSimSpot* sp)
0051         : Geant4HitHandler(sp->primary, sp->touchable), spot(sp)
0052       {
0053       }
0054       /// No copy constructor
0055       Geant4FastSimHandler(const Geant4FastSimHandler& copy) = delete;
0056       /// No move constructor
0057       Geant4FastSimHandler(Geant4FastSimHandler&& copy) = delete;
0058       /// Assignment operator inhibited. Should not be copied
0059       Geant4FastSimHandler& operator=(const Geant4FastSimHandler& copy) = delete;
0060       /// Move operator inhibited. Should not be copied
0061       Geant4FastSimHandler& operator=(Geant4FastSimHandler&& copy) = delete;
0062       /// Returns total energy deposit
0063       double energy() const  {
0064         return spot->hit->GetEnergy();
0065       }
0066       /// Return track momentum in DD4hep notation
0067       Momentum momentum() const {
0068         const G4ThreeVector& p = track->GetMomentum();
0069         return Momentum(p.x(), p.y(), p.z());
0070       }
0071       /// Returns the pre-gflashspot position
0072       Position avgPosition() const {
0073         const G4ThreeVector p = spot->hit->GetPosition();
0074         return Position(p.x(), p.y(), p.z());
0075       }
0076       /// Returns the post-step position as a G4ThreeVector
0077       G4ThreeVector avgPositionG4() const {
0078         return spot->hit->GetPosition();
0079       }
0080       /// Direction calculated from the post- and pre-position ofthe gflashspot
0081       Position direction()  const  {
0082         const G4ThreeVector p = track->GetMomentumDirection();
0083         return Position(p.x(), p.y(), p.z());
0084       }
0085       /// Returns the track momentum as a G4ThreeVector
0086       G4ThreeVector momentumG4() const {
0087         return track->GetMomentum();
0088       }
0089       /// Access the enery deposit of the energy spot
0090       double deposit() const  {
0091         return spot->hit->GetEnergy();
0092       }
0093       G4VPhysicalVolume* volume() const {
0094         return touchable()->GetVolume();
0095       }
0096       G4LogicalVolume* logvol() const {
0097         return volume()->GetLogicalVolume();
0098       }
0099       G4VSolid* solid() const {
0100         return touchable()->GetSolid();
0101       }
0102       G4VSensitiveDetector* sd()  const {
0103         G4LogicalVolume* lv = logvol();
0104         return lv ? lv->GetSensitiveDetector() : 0;
0105       }
0106       std::string sdName(const std::string& undefined = "") const {
0107         G4VSensitiveDetector* s = sd();
0108         return s ? s->GetName() : undefined;
0109       }
0110       bool isSensitive() const {
0111         G4LogicalVolume* lv = logvol();
0112         return lv ? (0 != lv->GetSensitiveDetector()) : false;
0113       }
0114     };
0115 
0116   }    // End namespace sim
0117 }      // End namespace dd4hep
0118 #endif // DDG4_GEANT4FASTSIMHANDLER_H