File indexing completed on 2025-01-30 09:17:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
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
0034 namespace Tests {
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 template <typename T> class Geant4SensitiveAction : public Geant4Sensitive {
0045 protected:
0046 typedef Geant4Sensitive Base;
0047
0048 size_t m_collectionID;
0049
0050
0051 bool _detailedHitsStoring ;
0052
0053 public:
0054
0055
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
0063 virtual ~Geant4SensitiveAction(){
0064 InstanceCount::decrement(this);
0065 }
0066
0067 virtual void defineCollections() override {}
0068
0069 virtual void begin(G4HCofThisEvent* hce) override {
0070 Base::begin(hce);
0071 }
0072
0073 virtual void end(G4HCofThisEvent* hce) override {
0074 Base::end(hce);
0075 }
0076
0077 virtual bool process(const G4Step* step, G4TouchableHistory* history) override {
0078 return Base::process(step,history);
0079 }
0080
0081 virtual bool processFastSim(const Geant4FastSimSpot* spot, G4TouchableHistory* history) override {
0082 return Base::processFastSim(spot,history);
0083 }
0084
0085 virtual void clear(G4HCofThisEvent* hce) override {
0086 Base::clear(hce);
0087 }
0088 };
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 class LcioTestTracker {};
0102
0103
0104 template <> void Geant4SensitiveAction<LcioTestTracker>::defineCollections() {
0105 m_collectionID = Base::defineCollection<lcio::SimTrackerHitImpl>(m_sensitive.readout().name());
0106 }
0107
0108
0109 template <> bool Geant4SensitiveAction<LcioTestTracker>::process(const G4Step* step,G4TouchableHistory* ) {
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
0125
0126
0127
0128
0129
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
0142
0143
0144
0145 collection(m_collectionID)->add(hit);
0146 return true;
0147 }
0148
0149
0150 template <> bool
0151 Geant4SensitiveAction<LcioTestTracker>::processFastSim(const Geant4FastSimSpot* ,
0152 G4TouchableHistory* )
0153 {
0154 except("Not implemented");
0155 return true;
0156 }
0157
0158
0159 typedef Geant4SensitiveAction<LcioTestTracker> LcioTestTrackerAction;
0160 }
0161
0162 #include <DDG4/Factories.h>
0163 DECLARE_GEANT4SENSITIVE_NS(Tests,LcioTestTrackerAction)