File indexing completed on 2025-11-03 09:04:58
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 
0032 
0033 
0034 
0035 
0036 
0037 #include "TimeStepAction.hh"
0038 
0039 #include "G4MolecularConfiguration.hh"
0040 #include "G4Molecule.hh"
0041 #include "G4MoleculeTable.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4UnitsTable.hh"
0044 
0045 #include <G4Scheduler.hh>
0046 
0047 TimeStepAction::TimeStepAction() : G4UserTimeStepAction()
0048 {
0049   
0050 
0051 
0052 
0053 
0054 
0055 
0056   AddTimeStep(1 * picosecond, 0.1 * picosecond);
0057   AddTimeStep(10 * picosecond, 1 * picosecond);
0058   AddTimeStep(100 * picosecond, 3 * picosecond);
0059   AddTimeStep(1000 * picosecond, 10 * picosecond);
0060   AddTimeStep(10000 * picosecond, 100 * picosecond);
0061 }
0062 
0063 
0064 
0065 void TimeStepAction::UserPostTimeStepAction()
0066 {
0067   if (G4Scheduler::Instance()->GetGlobalTime() > 99 * ns) {
0068     G4cout << "_________________" << G4endl;
0069     G4cout << "At : " << G4BestUnit(G4Scheduler::Instance()->GetGlobalTime(), "Time") << G4endl;
0070 
0071     auto species = G4MoleculeTable::Instance()->GetConfiguration("°OH");
0072     PrintSpecieInfo(species);
0073   }
0074 }
0075 
0076 
0077 
0078 void TimeStepAction::UserReactionAction(const G4Track& reactantA, const G4Track& reactantB,
0079                                         const std::vector<G4Track*>* products)
0080 {
0081   
0082   G4cout << G4endl;
0083 
0084   G4cout << "At : " << G4Scheduler::Instance()->GetGlobalTime() / ns
0085          << " (ns) reactantA = " << GetMolecule(reactantA)->GetName()
0086          << " (ID number = " << reactantA.GetTrackID() << ")"
0087          << " at position : " << reactantA.GetPosition() / nm
0088          << " reacts with reactantB = " << GetMolecule(&reactantB)->GetName()
0089          << " (ID number = " << reactantB.GetTrackID() << ")"
0090          << " at position : " << reactantA.GetPosition() / nm << G4endl;
0091 
0092   if (products) {
0093     auto nbProducts = (G4int)products->size();
0094     for (G4int i = 0; i < nbProducts; i++) {
0095       G4cout << "      creating product " << i + 1 << " =" << GetMolecule((*products)[i])->GetName()
0096              << " position : " << (*products)[i]->GetPosition() << G4endl;
0097     }
0098   }
0099   G4cout << G4endl;
0100 }
0101 
0102 void TimeStepAction::PrintSpecieInfo(G4MolecularConfiguration* molconf)
0103 {
0104   
0105   auto moleculeID = molconf->GetMoleculeID();
0106   const G4String& moleculeName = molconf->GetFormatedName();
0107   G4cout << "Get inf of : " << moleculeName << G4endl;
0108   auto trackList = G4ITTrackHolder::Instance()->GetMainList(moleculeID);
0109 
0110   if (trackList == nullptr) {
0111     G4cout << "No species" << G4endl;
0112     return;
0113   }
0114   G4TrackList::iterator it = trackList->begin();
0115   G4TrackList::iterator end = trackList->end();
0116   for (; it != end; ++it) {
0117     auto track = *it;
0118     G4cout << "TrackID: " << track->GetTrackID() << "  position : " << track->GetPosition() / nm
0119            << G4endl;
0120   }
0121 }