File indexing completed on 2026-09-13 08:30:05
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 "SD.hh"
0030
0031 #include "G4AccumulableManager.hh"
0032 #include "G4HCofThisEvent.hh"
0033 #include "G4SDManager.hh"
0034 #include "G4Step.hh"
0035 #include "G4ThreeVector.hh"
0036
0037 #include "Hit.hh"
0038 #include "Manager.hh"
0039 #include "VRadiobiologicalAccumulable.hh"
0040
0041 namespace RadioBio
0042 {
0043
0044
0045
0046 SD::SD(const G4String& name, const G4String& hitsCollectionName) : G4VSensitiveDetector(name)
0047 {
0048 collectionName.insert(hitsCollectionName);
0049 }
0050
0051
0052
0053 void SD::Initialize(G4HCofThisEvent* hce)
0054 {
0055
0056 fHitsCollection = new RadioBioHitsCollection(SensitiveDetectorName, collectionName[0]);
0057
0058
0059 G4int hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0060 hce->AddHitsCollection(hcID, fHitsCollection);
0061 }
0062
0063
0064
0065 G4bool SD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0066 {
0067
0068 RadioBio::Hit* newHit = new RadioBio::Hit();
0069
0070
0071 G4double eKinPre = aStep->GetPreStepPoint()->GetKineticEnergy();
0072
0073 G4double eKinPost = aStep->GetPostStepPoint()->GetKineticEnergy();
0074
0075 G4double eKinMean = (eKinPre + eKinPost) * 0.5;
0076
0077 const std::vector<const G4Track*>* secondary = aStep->GetSecondaryInCurrentStep();
0078
0079 size_t SecondarySize = (*secondary).size();
0080 G4double EnergySecondary = 0.;
0081
0082
0083 if (SecondarySize)
0084 {
0085 for (size_t numsec = 0; numsec < SecondarySize; numsec++) {
0086
0087 G4int PDGSecondary = (*secondary)[numsec]->GetDefinition()->GetPDGEncoding();
0088
0089 if (PDGSecondary == 11)
0090 {
0091
0092 EnergySecondary += (*secondary)[numsec]->GetKineticEnergy();
0093 }
0094 }
0095 }
0096
0097
0098 newHit->SetTrackID(aStep->GetTrack()->GetTrackID());
0099 newHit->SetPartType(aStep->GetTrack()->GetParticleDefinition());
0100 newHit->SetEkinMean(eKinMean);
0101 newHit->SetDeltaE(aStep->GetTotalEnergyDeposit());
0102 newHit->SetEinit(aStep->GetPreStepPoint()->GetKineticEnergy());
0103 newHit->SetTrackLength(aStep->GetStepLength());
0104 newHit->SetElectronEnergy(EnergySecondary);
0105 newHit->SetPhysicalVolume(aStep->GetPreStepPoint()->GetPhysicalVolume());
0106 newHit->SetVoxelIndexes(aStep->GetPreStepPoint()->GetTouchableHandle());
0107
0108
0109 fHitsCollection->insert(newHit);
0110
0111
0112 for (G4int i = 0; i < G4AccumulableManager::Instance()->GetNofAccumulables(); ++i) {
0113
0114 G4VAccumulable* GenAcc = G4AccumulableManager::Instance()->GetAccumulable(i);
0115
0116
0117 auto q = Manager::GetInstance()->GetQuantity(GenAcc->GetName());
0118
0119 VRadiobiologicalAccumulable* radioAcc = dynamic_cast<VRadiobiologicalAccumulable*>(GenAcc);
0120
0121
0122
0123 if (radioAcc == nullptr) continue;
0124
0125
0126 if (q->IsCalculationEnabled()) radioAcc->Accumulate(newHit);
0127 }
0128
0129 return true;
0130 }
0131
0132
0133
0134 void SD::EndOfEvent(G4HCofThisEvent*)
0135 {
0136 if (verboseLevel > 1) {
0137 G4int nofHits = fHitsCollection->entries();
0138 G4cout << G4endl << "-------->Hits Collection: in this event they are " << nofHits
0139 << " hits in the detector slices: " << G4endl;
0140 for (G4int i = 0; i < nofHits; i++)
0141 (*fHitsCollection)[i]->Print();
0142 }
0143 }
0144
0145
0146
0147 }