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     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
0014 #define DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
0015 
0016 // Framework include files
0017 #include <DD4hep/DetElement.h>
0018 #include <DDG4/Geant4SensDetAction.h>
0019 #include <DDG4/Geant4SteppingAction.h>
0020 
0021 /// Namespace for the AIDA detector description toolkit
0022 namespace dd4hep {
0023 
0024   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0025   namespace sim {
0026 
0027     /// Class to measure the energy of escaping tracks
0028     /** Class to measure the energy of escaping tracks of a detector using Geant 4
0029      * Measure escaping energy....
0030      *
0031      *  \author  M.Frank
0032      *  \version 1.0
0033      *  \ingroup DD4HEP_SIMULATION
0034      */
0035     class Geant4EscapeCounter : /* virtual public Geant4SteppingAction, virtual */ public Geant4Sensitive {
0036       /// Collection identifiers
0037       size_t m_collectionID;
0038       /// Detector name set
0039       std::vector<std::string> m_detectorNames;
0040 
0041     public:
0042       /// Standard constructor
0043       Geant4EscapeCounter(Geant4Context* ctxt, const std::string& name, DetElement det, Detector& description);
0044       /// Default destructor
0045       virtual ~Geant4EscapeCounter();
0046       /// G4VSensitiveDetector interface: Method for generating hit(s) using the information of G4Step object.
0047       virtual bool process(const G4Step* step, G4TouchableHistory* history)  override;
0048     };
0049 
0050   }    // End namespace sim
0051 }      // End namespace dd4hep
0052 
0053 #endif /* DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H */
0054 
0055 //====================================================================
0056 //  AIDA Detector description implementation 
0057 //--------------------------------------------------------------------
0058 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0059 // All rights reserved.
0060 //
0061 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0062 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0063 //
0064 // Author     : M.Frank
0065 //
0066 //====================================================================
0067 // Framework include files
0068 #include <DD4hep/Printout.h>
0069 #include <DD4hep/InstanceCount.h>
0070 
0071 #include <DDG4/Geant4TouchableHandler.h>
0072 #include <DDG4/Geant4TrackHandler.h>
0073 #include <DDG4/Geant4StepHandler.h>
0074 #include <DDG4/Geant4Mapping.h>
0075 #include <DDG4/Geant4Data.h>
0076 
0077 #include <CLHEP/Units/SystemOfUnits.h>
0078 #include <G4VProcess.hh>
0079 
0080 using namespace dd4hep::sim;
0081 
0082 /// Standard constructor
0083 Geant4EscapeCounter::Geant4EscapeCounter(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& description_ref)
0084   : Geant4Sensitive(ctxt, nam, det, description_ref)
0085 {
0086   std::string coll_name = name()+"Hits";
0087   m_needsControl = true;
0088   declareProperty("Shells",m_detectorNames);
0089   m_collectionID = defineCollection<SimpleTracker::Hit>(coll_name);
0090   InstanceCount::increment(this);
0091 }
0092 
0093 /// Default destructor
0094 Geant4EscapeCounter::~Geant4EscapeCounter() {
0095   InstanceCount::decrement(this);
0096 }
0097 
0098 /// G4VSensitiveDetector interface: Method for generating hit(s) using the information of G4Step object.
0099 bool Geant4EscapeCounter::process(const G4Step* step, G4TouchableHistory* /* history */)   {
0100   Geant4StepHandler  h(step);
0101   Geant4TrackHandler th(h.track);
0102   Geant4TouchableHandler handler(step);
0103   std::string hdlr_path  = handler.path();
0104   Position prePos     = h.prePos();
0105   Geant4HitCollection* coll = collection(m_collectionID);
0106   SimpleTracker::Hit*  hit = new SimpleTracker::Hit();
0107   hit->g4ID          = th.id();
0108   hit->energyDeposit = h.deposit();
0109   hit->cellID        = volumeID(step);
0110   hit->energyDeposit = th.energy();
0111   hit->position      = prePos;
0112   hit->momentum      = h.trkMom();
0113   hit->length        = (h.postPos()-prePos).R();
0114   hit->truth.trackID = th.id();
0115   hit->truth.deposit = h.deposit();
0116   hit->truth.pdgID   = th.pdgID();
0117   hit->truth.deposit = h.deposit();
0118   hit->truth.time    = th.time();
0119   hit->truth.length  = hit->length;
0120   hit->truth.x       = hit->position.x();
0121   hit->truth.y       = hit->position.y();
0122   hit->truth.z       = hit->position.z();
0123   coll->add(hit);
0124   mark(h.track);
0125 
0126   print("+++ Track:%4d  %8.2f MeV [%s] %s Geant4 path:%s",
0127         h.trkID(),h.trkEnergy()/CLHEP::MeV,th.name().c_str(),
0128         th.creatorName().c_str(),hdlr_path.c_str());
0129   // Kill track, so that it does no longer participate in the propagation
0130   step->GetTrack()->SetTrackStatus(fStopAndKill);
0131   return true;
0132 }
0133 
0134 #include <DDG4/Factories.h>
0135 DECLARE_GEANT4SENSITIVE(Geant4EscapeCounter)
0136