File indexing completed on 2026-03-28 07:49:53
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 "GB03HodoSD.hh"
0030
0031 #include "GB03DetectorConstruction.hh"
0032 #include "GB03Run.hh"
0033
0034 #include "G4RunManager.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4Step.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4Track.hh"
0039
0040
0041
0042 GB03HodoSD::GB03HodoSD(G4String name) : G4VSensitiveDetector(name)
0043 {
0044 collectionName.insert("Leaving");
0045 }
0046
0047
0048
0049 void GB03HodoSD::Initialize(G4HCofThisEvent* hce)
0050 {
0051 auto rm = G4RunManager::GetRunManager();
0052 fRun = static_cast<GB03Run*>(rm->GetNonConstCurrentRun());
0053 auto det = static_cast<const GB03DetectorConstruction*>(rm->GetUserDetectorConstruction());
0054 fVerbose = det->GetVerboseLevel();
0055
0056 fHitsCollection = new GB03HodoHitsCollection(SensitiveDetectorName, collectionName[0]);
0057
0058
0059 auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0060 hce->AddHitsCollection(hcID, fHitsCollection);
0061 }
0062
0063
0064
0065 G4bool GB03HodoSD::ProcessHits(G4Step* step, G4TouchableHistory*)
0066 {
0067 if (!step->IsFirstStepInVolume()) return false;
0068
0069 auto track = step->GetTrack();
0070 auto preStepPoint = step->GetPreStepPoint();
0071 auto pname = track->GetParticleDefinition()->GetParticleName();
0072 auto pid = track->GetParticleDefinition()->GetPDGEncoding();
0073 auto weight = preStepPoint->GetWeight();
0074 auto Ekin = preStepPoint->GetKineticEnergy() / MeV;
0075 auto pos = preStepPoint->GetPosition();
0076
0077 fRun->CountParticle(pname, weight, Ekin);
0078
0079 auto hodoHit = new GB03HodoHit();
0080 hodoHit->Set(pid, Ekin, weight, pos);
0081 fHitsCollection->insert(hodoHit);
0082
0083 if (fVerbose > 1) {
0084 G4cout << std::setw(7) << pid << std::setw(14) << pname
0085 << ", kinetic energy (MeV) = " << std::setw(12) << Ekin
0086 << ", position (cm) = " << pos / cm << std::setw(10) << "weight = " << std::setw(10)
0087 << weight << G4endl;
0088 }
0089 return true;
0090 }
0091
0092 void GB03HodoSD::PrintAll()
0093 {
0094 G4cout << GetFullPathName() << " No of Col " << GetNumberOfCollections() << G4endl;
0095 }
0096
0097