File indexing completed on 2026-09-15 08:29:04
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 "TimeStepAction.hh"
0030
0031 #include "DetectorConstruction.hh"
0032 #include "G4AnalysisManager.hh"
0033 #include "G4IT.hh"
0034 #include "G4ITTrackHolder.hh"
0035 #include "G4RunManager.hh"
0036 #include "G4Scheduler.hh"
0037 #include "G4SystemOfUnits.hh"
0038
0039 TimeStepAction::TimeStepAction()
0040 {
0041 fpDetector = dynamic_cast<const DetectorConstruction *>(
0042 G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0043 }
0044
0045
0046
0047 void TimeStepAction::Save(const G4MolecularConfiguration *molconf)
0048 {
0049 const G4int moleculeID = molconf->GetMoleculeID();
0050 const G4String &moleculeName = molconf->GetFormatedName();
0051 G4TrackList *trackList = G4ITTrackHolder::Instance()->GetMainList(moleculeID);
0052
0053 if (trackList == nullptr) return;
0054
0055 for(const G4Track* track : *trackList)
0056 {
0057 SaveMoleculeInfo(track, moleculeID, moleculeName);
0058 }
0059 }
0060
0061
0062
0063 void TimeStepAction::
0064 SaveMoleculeInfo(const G4Track *track, const G4int molID,
0065 const G4String & )
0066 {
0067 G4AnalysisManager *analysisManager = G4AnalysisManager::Instance();
0068 if (!analysisManager->IsActive()) {
0069 return;
0070 }
0071
0072 const G4ThreeVector &position = track->GetPosition();
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 const G4double xp = position.x();
0083 const G4double yp = position.y();
0084 const G4double zp = position.z();
0085 const G4double R = std::sqrt(xp * xp + yp * yp + zp * zp) / nm;
0086 if (molID < 7) {
0087 constexpr G4int offset = 10;
0088 analysisManager->FillH1(molID + offset, R);
0089 } else {
0090 analysisManager->FillH1(17, R);
0091 }
0092 }
0093
0094
0095
0096 void TimeStepAction::UserPreTimeStepAction()
0097 {
0098
0099 G4ConfigurationIterator it =
0100 G4MoleculeTable::Instance()->GetConfigurationIterator();
0101
0102 const G4double time = G4Scheduler::Instance()->GetGlobalTime();
0103
0104 if (time == 1. * us) {
0105 while (it()) {
0106 const G4MolecularConfiguration *molconf = it.value();
0107 Save(molconf);
0108 }
0109 }
0110 }
0111
0112