File indexing completed on 2025-01-31 09:22:10
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
0030
0031 #include "SensitiveDetector.hh"
0032 #include "G4HCofThisEvent.hh"
0033 #include "G4Step.hh"
0034 #include "G4ThreeVector.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4ios.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4RunManager.hh"
0039
0040 SensitiveDetector::SensitiveDetector(const G4String& name,
0041 const G4String& hitsCollectionName,
0042 G4bool isThisAMicrodosimeter,
0043 AnalysisManager* analysis_manager)
0044 : G4VSensitiveDetector(name),
0045 fHitsCollection(NULL)
0046 {
0047 collectionName.insert(hitsCollectionName);
0048 analysis = analysis_manager;
0049 isMicrod = isThisAMicrodosimeter;
0050 }
0051
0052 SensitiveDetector::~SensitiveDetector()
0053 {}
0054
0055 void SensitiveDetector::Initialize(G4HCofThisEvent* hce)
0056 {
0057
0058
0059 fHitsCollection
0060 = new SensitiveDetectorHitsCollection(SensitiveDetectorName, collectionName[0]);
0061
0062
0063
0064 G4int hcID
0065 = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0066 hce->AddHitsCollection( hcID, fHitsCollection );
0067 }
0068
0069 G4bool SensitiveDetector::ProcessHits(G4Step* aStep,
0070 G4TouchableHistory*)
0071 {
0072
0073 G4double edep = aStep->GetTotalEnergyDeposit();
0074
0075 if (edep==0.) return false;
0076
0077
0078
0079
0080
0081
0082
0083
0084 SensitiveDetectorHit* newHit = new SensitiveDetectorHit();
0085
0086 newHit -> SetEdep(edep);
0087
0088
0089 G4double len = aStep->GetStepLength();
0090
0091
0092 const G4ParticleDefinition* thisParticle = aStep ->
0093 GetTrack() -> GetParticleDefinition() ;
0094 G4String particleName = thisParticle -> GetParticleName();
0095 G4int particleZ = thisParticle -> GetAtomicNumber();
0096
0097 if ( (particleZ < 1) && (particleName != "neutron"))
0098 len = 0.;
0099
0100 newHit->SetPath(len);
0101
0102 fHitsCollection -> insert( newHit );
0103
0104 return true;
0105 }
0106
0107 void SensitiveDetector::EndOfEvent(G4HCofThisEvent*)
0108 {
0109 #ifdef ANALYSIS_USE
0110
0111 G4double totalEdepInOneEvent=0;
0112 G4double totalPathLengthInOneEvent=0;
0113
0114 G4int NbHits = fHitsCollection->entries();
0115
0116
0117 G4double edep, len;
0118
0119 for (G4int i=0;i<NbHits;i++)
0120 {
0121 edep = (*fHitsCollection)[i]->GetEdep();
0122 totalEdepInOneEvent = totalEdepInOneEvent + edep;
0123
0124 len = (*fHitsCollection)[i]->GetPath();
0125 totalPathLengthInOneEvent = totalPathLengthInOneEvent + len;
0126 }
0127
0128 G4int eventID = G4RunManager::GetRunManager() ->
0129 GetCurrentEvent() -> GetEventID();
0130
0131
0132 if (totalEdepInOneEvent!=0)
0133 {
0134 if (isMicrod==true) analysis -> StoreEnergyDeposition(totalEdepInOneEvent/keV, totalPathLengthInOneEvent/um, eventID);
0135 else analysis -> StoreSecondStageEnergyDeposition(totalEdepInOneEvent/keV, eventID);
0136 }
0137 #endif
0138 }