File indexing completed on 2026-04-17 07:51:37
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 #include "ActionInitialization.hh"
0028 #include "ActionInitializationMessenger.hh"
0029
0030 #include "globals.hh"
0031 #include "PrimaryGeneratorAction.hh"
0032 #include "RunAction.hh"
0033 #include "SteppingAction.hh"
0034 #include "G4RunManager.hh"
0035 #include "G4Threading.hh"
0036
0037 #include "G4IAEAphspReader.hh"
0038 #include "G4IAEAphspWriterStack.hh"
0039
0040
0041
0042
0043 ActionInitialization::ActionInitialization()
0044 : G4VUserActionInitialization()
0045 {
0046
0047 fMessenger = new ActionInitializationMessenger(this);
0048
0049
0050 fIAEAphspReaderName = "";
0051 fNumberOfThreads = G4RunManager::GetRunManager()->GetNumberOfThreads();
0052
0053
0054 fIAEAphspWriterNamePrefix = "";
0055
0056
0057 fZphspVec = new std::vector<G4double>;
0058 }
0059
0060
0061
0062 ActionInitialization::~ActionInitialization()
0063 {
0064 if (fZphspVec) {
0065 fZphspVec->clear();
0066 delete fZphspVec;
0067 }
0068 if (fMessenger) delete fMessenger;
0069 }
0070
0071
0072
0073 void ActionInitialization::BuildForMaster() const
0074 {
0075
0076 SetUserAction(new RunAction());
0077 }
0078
0079
0080
0081 void ActionInitialization::Build() const
0082 {
0083
0084 G4cout << "IAEAphsp file to read is \"" << fIAEAphspReaderName << "\"."
0085 << G4endl;
0086
0087 PrimaryGeneratorAction* prim = new PrimaryGeneratorAction(fNumberOfThreads);
0088 if ( !fIAEAphspReaderName.empty() )
0089 prim->SetIAEAphspReader(fIAEAphspReaderName);
0090 SetUserAction(prim);
0091
0092 RunAction* runAct = new RunAction();
0093 if (fIAEAphspWriterNamePrefix != "") {
0094
0095
0096 runAct->SetIAEAphspWriterStack(fIAEAphspWriterNamePrefix);
0097
0098 if (fZphspVec->size() > 0) {
0099 for (const auto& zphsp : (*fZphspVec))
0100 runAct->AddZphsp(zphsp);
0101 }
0102 else {
0103 G4ExceptionDescription msg;
0104 msg << "IAEAphsp output file name provided, but no zphsp values "
0105 << "have been registered!" << G4endl;
0106 G4Exception("ActionInitialization::Build()",
0107 "ActionInit001", FatalException, msg);
0108 }
0109 }
0110 SetUserAction(runAct);
0111
0112 SteppingAction *steppingAction = new SteppingAction();
0113 SetUserAction(steppingAction);
0114 }
0115
0116
0117
0118
0119 void ActionInitialization::SetIAEAphspReader(const G4String& name)
0120 {
0121 fIAEAphspReaderName = name;
0122
0123 if ( !(G4Threading::IsMultithreadedApplication()) ) {
0124
0125
0126
0127 const G4VUserPrimaryGeneratorAction* basePrim =
0128 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction();
0129 if (!basePrim) return;
0130
0131
0132 const auto* myConstPrim =
0133 dynamic_cast<const PrimaryGeneratorAction*>(basePrim);
0134 if (!myConstPrim) return;
0135
0136
0137 auto* myPrim = const_cast<PrimaryGeneratorAction*>(myConstPrim);
0138 myPrim->SetIAEAphspReader(name);
0139 }
0140 }
0141
0142
0143
0144
0145 void ActionInitialization::SetIAEAphspWriterPrefix(const G4String& prefix)
0146 {
0147 fIAEAphspWriterNamePrefix = prefix;
0148
0149 if ( !(G4Threading::IsMultithreadedApplication()) ) {
0150
0151
0152 const G4UserRunAction* baseRA =
0153 G4RunManager::GetRunManager()->GetUserRunAction();
0154 if (!baseRA) return;
0155
0156
0157 const auto* myConstRA = dynamic_cast<const RunAction*>(baseRA);
0158 if (!myConstRA) return;
0159
0160
0161 auto* myRA = const_cast<RunAction*>(myConstRA);
0162 myRA->SetIAEAphspWriterStack(prefix);
0163 }
0164 }
0165
0166
0167
0168
0169 void ActionInitialization::AddZphsp(const G4double zphsp)
0170 {
0171 fZphspVec->push_back(zphsp);
0172
0173 if ( !(G4Threading::IsMultithreadedApplication()) ) {
0174
0175
0176 const G4UserRunAction* baseRA =
0177 G4RunManager::GetRunManager()->GetUserRunAction();
0178 if (!baseRA) return;
0179
0180
0181 const auto* myConstRA = dynamic_cast<const RunAction*>(baseRA);
0182 if (!myConstRA) return;
0183
0184
0185 auto* myRA = const_cast<RunAction*>(myConstRA);
0186 myRA->AddZphsp(zphsp);
0187 }
0188 }