Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:24

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     : F.Gaede, DESY
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <Exceptions.h>
0016 #include <IMPL/LCCollectionVec.h>
0017 #include <IMPL/SimTrackerHitImpl.h>
0018 #include <IMPL/SimCalorimeterHitImpl.h>
0019 #include <IMPL/MCParticleImpl.h>
0020 #include <UTIL/Operators.h>
0021 #include <UTIL/ILDConf.h>
0022 
0023 #include <DDG4/Geant4SensDetAction.h>
0024 #include <DDG4/Geant4Data.h>
0025 #include <DDG4/Geant4StepHandler.h>
0026 
0027 #include <DD4hep/Printout.h>
0028 #include <DD4hep/InstanceCount.h>
0029 
0030 using namespace dd4hep::sim;
0031 using namespace dd4hep;
0032 
0033 /// Test namespace.
0034 namespace  Tests {
0035 
0036   // copied from Geant4SDActions.cpp (why is this not a public class ??????)
0037 
0038   /// Deprecated: Simple SensitiveAction class ...
0039   /**
0040    *  \deprecated
0041    *  \author  M.Frank
0042    *  \version 1.0
0043    */
0044   template <typename T> class Geant4SensitiveAction : public Geant4Sensitive  {
0045   protected:
0046     typedef Geant4Sensitive Base;
0047     /// Collection identifiers
0048     size_t m_collectionID;
0049 
0050     // properties:
0051     bool _detailedHitsStoring ;
0052 
0053   public:
0054     //    typedef SimpleHit::Contribution HitContribution;
0055     // Standard , initializing constructor
0056     Geant4SensitiveAction(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& description_ref)
0057       : Geant4Sensitive(ctxt,nam,det,description_ref), m_collectionID(0) {
0058       declareProperty("detailedHitsStoring", _detailedHitsStoring ) ;
0059       defineCollections();
0060       InstanceCount::increment(this);
0061     }
0062     /// Default destructor
0063     virtual ~Geant4SensitiveAction(){
0064       InstanceCount::decrement(this);
0065     }
0066     /// Define collections created by this sensitivie action object
0067     virtual void defineCollections()   override   {}
0068     /// G4VSensitiveDetector interface: Method invoked at the begining of each event.
0069     virtual void begin(G4HCofThisEvent* hce)   override   {
0070       Base::begin(hce);
0071     }
0072     /// G4VSensitiveDetector interface: Method invoked at the end of each event.
0073     virtual void end(G4HCofThisEvent* hce)   override   {
0074       Base::end(hce);
0075     }
0076     /// G4VSensitiveDetector interface: Method for generating hit(s) using the G4Step object.
0077     virtual bool process(const G4Step* step, G4TouchableHistory* history)  override   {
0078       return Base::process(step,history);
0079     }
0080     /// GFlash/FastSim interface: Method for generating hit(s) using the G4Step object.
0081     virtual bool processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history)  override {
0082       return Base::processFastSim(spot,history);
0083     }
0084     /// G4VSensitiveDetector interface: Method invoked if the event was aborted.
0085     virtual void clear(G4HCofThisEvent* hce)  override   {
0086       Base::clear(hce);
0087     }
0088   };
0089 
0090 
0091   // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0092   //               Geant4SensitiveAction<SimpleTracker>
0093   // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0094 
0095   /// Deprecated: Simple SensitiveAction class ...
0096   /**
0097    *  \deprecated
0098    *  \author  M.Frank
0099    *  \version 1.0
0100    */
0101   class LcioTestTracker {};
0102 
0103   /// Define collections created by this sensitivie action object
0104   template <> void Geant4SensitiveAction<LcioTestTracker>::defineCollections() {
0105     m_collectionID = Base::defineCollection<lcio::SimTrackerHitImpl>(m_sensitive.readout().name());
0106   }
0107 
0108   /// Method for generating hit(s) using the information of G4Step object.
0109   template <> bool Geant4SensitiveAction<LcioTestTracker>::process(const G4Step* step,G4TouchableHistory* /*hist*/ ) {
0110     Geant4StepHandler h(step);
0111 
0112     Position prePos    = h.prePos();
0113     Position postPos   = h.postPos();
0114     Position direction = postPos - prePos;
0115     Position position  = mean_direction(prePos,postPos);
0116     double   hit_len   = direction.R();
0117 
0118     if (hit_len > 0) {
0119       double new_len = mean_length(h.preMom(),h.postMom())/hit_len;
0120       direction *= new_len/hit_len;
0121     }
0122 
0123     lcio::SimTrackerHitImpl* hit = new lcio::SimTrackerHitImpl;
0124     //    (h.track->GetTrackID(),
0125     // h.track->GetDefinition()->GetPDGEncoding(),
0126     // step->GetTotalEnergyDeposit(),
0127     // h.track->GetGlobalTime());
0128 
0129     // HitContribution contrib = Hit::extractContribution(step);
0130 
0131     VolumeID cell = volumeID( step ) ;
0132     hit->setCellID0( cell & 0xffffffff   ) ;
0133     hit->setCellID1( ( cell >> 32 ) & 0xffffffff   ) ;
0134 
0135     printout(INFO,"LcioTestTracker","%s> Add hit with deposit:%f  Pos:%f %f %f - cellID0: 0x%x cellID1: 0x%x",
0136              c_name(),step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z() , hit->getCellID0() ,hit->getCellID1() );
0137 
0138     double pos[3] = {position.x(), position.y(), position.z()};
0139     hit->setPosition( pos  ) ;
0140 
0141     // hit->energyDeposit = contrib.deposit ;
0142     // hit->position      = position;
0143     // hit->momentum      = direction;
0144     // hit->length        = hit_len;
0145     collection(m_collectionID)->add(hit);
0146     return true;
0147   }
0148 
0149   /// Method for generating hit(s) using the information of G4Step object.
0150   template <> bool 
0151   Geant4SensitiveAction<LcioTestTracker>::processFastSim(const Geant4FastSimSpot*  /* spot */,
0152                              G4TouchableHistory* /*hist*/ )
0153   {
0154     except("Not implemented");
0155     return true;
0156   }
0157 
0158   
0159   typedef Geant4SensitiveAction<LcioTestTracker> LcioTestTrackerAction;
0160 } // namespace
0161 
0162 #include <DDG4/Factories.h>
0163 DECLARE_GEANT4SENSITIVE_NS(Tests,LcioTestTrackerAction)