File indexing completed on 2026-05-13 08:06:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "Par04ParallelFastSensitiveDetector.hh"
0030
0031 #include "Par04EventInformation.hh" // for Par04EventInformation
0032 #include "Par04Hit.hh" // for Par04Hit, Par04HitsCollection
0033
0034 #include "G4Event.hh" // for G4Event
0035 #include "G4EventManager.hh" // for G4EventManager
0036 #include "G4HCofThisEvent.hh" // for G4HCofThisEvent
0037 #include "G4SDManager.hh" // for G4SDManager
0038 #include "G4Step.hh" // for G4Step
0039 #include "G4Track.hh" // for G4Track
0040
0041 #include <CLHEP/Vector/Rotation.h> // for HepRotation
0042 #include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
0043 #include <G4CollectionNameVector.hh> // for G4CollectionNameVector
0044 #include <G4FastHit.hh> // for G4FastHit
0045 #include <G4FastTrack.hh> // for G4FastTrack
0046 #include <G4RotationMatrix.hh> // for G4RotationMatrix
0047 #include <G4StepPoint.hh> // for G4StepPoint
0048 #include <G4THitsCollection.hh> // for G4THitsCollection
0049 #include <G4ThreeVector.hh> // for G4ThreeVector
0050 #include <G4VSensitiveDetector.hh> // for G4VSensitiveDetector
0051 #include <G4VUserEventInformation.hh> // for G4VUserEventInformation
0052 #include <cmath> // for floor
0053 #include <cstddef> // for size_t
0054 #include <vector> // for vector
0055
0056
0057
0058 Par04ParallelFastSensitiveDetector::Par04ParallelFastSensitiveDetector(G4String aName)
0059 : G4VSensitiveDetector(aName)
0060 {
0061 collectionName.insert("physicalCellsFastSim");
0062 }
0063
0064
0065 Par04ParallelFastSensitiveDetector::Par04ParallelFastSensitiveDetector(G4String aName,
0066 G4int aNbOfLayers,
0067 G4int aNbOfSlices)
0068 : G4VSensitiveDetector(aName), fNbOfLayers(aNbOfLayers), fNbOfSlices(aNbOfSlices)
0069 {
0070 collectionName.insert("physicalCellsFastSim");
0071 }
0072
0073
0074
0075 Par04ParallelFastSensitiveDetector::~Par04ParallelFastSensitiveDetector() = default;
0076
0077
0078
0079 void Par04ParallelFastSensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
0080 {
0081 fHitsCollection = new Par04HitsCollection(SensitiveDetectorName, collectionName[0]);
0082 if (fHitCollectionID < 0) {
0083 fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0084 }
0085 aHCE->AddHitsCollection(fHitCollectionID, fHitsCollection);
0086 }
0087
0088
0089 G4bool Par04ParallelFastSensitiveDetector::ProcessHits(G4Step*, G4TouchableHistory*)
0090 {
0091 return true;
0092 }
0093
0094
0095 G4bool Par04ParallelFastSensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTrack*,
0096 G4TouchableHistory* aTouchable)
0097 {
0098 G4double edep = aHit->GetEnergy();
0099 if (edep == 0.) return true;
0100
0101 G4int layerNo = aTouchable->GetCopyNumber(0);
0102 G4int sliceNo = aTouchable->GetCopyNumber(1);
0103 G4int rowNo = aTouchable->GetCopyNumber(2);
0104
0105 G4int hitID = fNbOfLayers * fNbOfSlices * rowNo + fNbOfLayers * sliceNo + layerNo;
0106 auto hit = fHitsMap[hitID].get();
0107 if (hit == nullptr) {
0108 fHitsMap[hitID] = std::unique_ptr<Par04Hit>(new Par04Hit());
0109 hit = fHitsMap[hitID].get();
0110 hit->SetPhiId(sliceNo);
0111 hit->SetRhoId(layerNo);
0112 hit->SetZid(rowNo);
0113 }
0114 if (layerNo != hit->GetRhoId()) {
0115 G4cout << "ERROR, problem with Layer IDs: " << layerNo << " != " << hit->GetRhoId() << G4endl;
0116 return false;
0117 }
0118 if (sliceNo != hit->GetPhiId()) {
0119 G4cout << "ERROR, problem with Slice IDs: " << sliceNo << " != " << hit->GetPhiId() << G4endl;
0120 return false;
0121 }
0122 if (rowNo != hit->GetZid()) {
0123 G4cout << "ERROR, problem with Row IDs: " << rowNo << " != " << hit->GetZid() << G4endl;
0124 return false;
0125 }
0126
0127
0128 hit->AddEdep(edep);
0129
0130 hit->AddNdep(1);
0131
0132
0133 hit->SetType(3);
0134
0135 return true;
0136 }
0137
0138
0139 void Par04ParallelFastSensitiveDetector::EndOfEvent(G4HCofThisEvent*)
0140 {
0141 for (const auto& hits : fHitsMap) {
0142 fHitsCollection->insert(new Par04Hit(*hits.second.get()));
0143 }
0144 fHitsMap.clear();
0145 }