File indexing completed on 2026-04-04 07:53: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
0032
0033
0034
0035
0036 #include "RunAction.hh"
0037
0038 #include "CommandLineParser.hh"
0039
0040 #include "G4AnalysisManager.hh"
0041 #include "G4Run.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4Threading.hh"
0044
0045 using namespace G4DNAPARSER;
0046
0047 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container);
0048
0049
0050
0051 RunAction::RunAction() : G4UserRunAction(), fInitialized(0), fDebug(false) {}
0052
0053
0054
0055 RunAction::~RunAction() {}
0056
0057
0058
0059 void RunAction::BeginOfRunAction(const G4Run* run)
0060 {
0061
0062
0063
0064
0065
0066
0067
0068
0069 bool sequential =
0070 (G4RunManager::GetRunManager()->GetRunManagerType() == G4RunManager::sequentialRM);
0071
0072 if (isMaster && sequential == false)
0073
0074 {
0075 BeginMaster(run);
0076 }
0077 else
0078 BeginWorker(run);
0079 }
0080
0081
0082
0083 void RunAction::EndOfRunAction(const G4Run* run)
0084 {
0085 bool sequential =
0086 (G4RunManager::GetRunManager()->GetRunManagerType() == G4RunManager::sequentialRM);
0087
0088 if (isMaster && sequential == false) {
0089 EndMaster(run);
0090 }
0091 else {
0092 EndWorker(run);
0093 }
0094 }
0095
0096
0097
0098 void RunAction::BeginMaster(const G4Run* run)
0099 {
0100 if (fDebug) {
0101 bool sequential =
0102 (G4RunManager::GetRunManager()->GetRunManagerType() == G4RunManager::sequentialRM);
0103 G4cout << "===================================" << G4endl;
0104 if (!sequential) G4cout << "================ RunAction::BeginMaster" << G4endl;
0105 PrintRunInfo(run);
0106 G4cout << "===================================" << G4endl;
0107 }
0108 }
0109
0110
0111
0112 void RunAction::BeginWorker(const G4Run* run)
0113 {
0114 if (fDebug) {
0115 G4cout << "===================================" << G4endl;
0116 G4cout << "================ RunAction::BeginWorker" << G4endl;
0117 PrintRunInfo(run);
0118 G4cout << "===================================" << G4endl;
0119 }
0120 if (fInitialized == false) InitializeWorker(run);
0121
0122 CreateNtuple();
0123 }
0124
0125
0126
0127 void RunAction::EndMaster(const G4Run*) {}
0128
0129
0130
0131 void RunAction::EndWorker(const G4Run* run)
0132 {
0133 if (fDebug) {
0134 PrintRunInfo(run);
0135 }
0136
0137 G4int nofEvents = run->GetNumberOfEvent();
0138 if (nofEvents == 0) {
0139 if (fDebug) {
0140 G4cout << "================ NO EVENTS TREATED IN THIS RUN ==> Exit" << G4endl;
0141 }
0142 return;
0143 }
0144
0145
0146
0147
0148 WriteNtuple();
0149 }
0150
0151
0152
0153 void RunAction::InitializeWorker(const G4Run*)
0154 {
0155
0156
0157 fInitialized = true;
0158 }
0159
0160
0161
0162 void RunAction::CreateNtuple()
0163 {
0164
0165
0166
0167
0168 CommandLineParser* parser = CommandLineParser::GetParser();
0169 Command* command(0);
0170 if ((command = parser->GetCommandIfActive("-out")) == 0) return;
0171
0172 G4cout << "##### Create analysis manager "
0173 << " " << this << G4endl;
0174 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0175 analysisManager->SetDefaultFileType("root");
0176
0177
0178 G4cout << "Using " << analysisManager->GetType() << " analysis manager" << G4endl;
0179
0180
0181
0182
0183
0184 analysisManager->SetVerboseLevel(1);
0185
0186
0187 G4String fileName;
0188 if (command->GetOption().empty() == false) {
0189 fileName = command->GetOption();
0190 }
0191 else {
0192 fileName = "wholeNuclearDNA";
0193
0194 }
0195 analysisManager->OpenFile(fileName);
0196
0197
0198 analysisManager->CreateNtuple("ntuple", "geom_dna");
0199 analysisManager->CreateNtupleDColumn("flagParticle");
0200 analysisManager->CreateNtupleDColumn("flagProcess");
0201 analysisManager->CreateNtupleDColumn("flagVolume");
0202 analysisManager->CreateNtupleDColumn("x");
0203 analysisManager->CreateNtupleDColumn("y");
0204 analysisManager->CreateNtupleDColumn("z");
0205 analysisManager->CreateNtupleDColumn("edep");
0206 analysisManager->CreateNtupleDColumn("stepLength");
0207
0208 analysisManager->FinishNtuple();
0209 }
0210
0211
0212
0213 void RunAction::WriteNtuple()
0214 {
0215 CommandLineParser* parser = CommandLineParser::GetParser();
0216 Command* commandLine(0);
0217 if ((commandLine = parser->GetCommandIfActive("-out")) == 0) return;
0218
0219
0220
0221 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0222
0223
0224
0225
0226 analysisManager->Write();
0227 analysisManager->CloseFile();
0228 analysisManager->Clear();
0229 }
0230
0231
0232
0233 void RunAction::PrintRunInfo(const G4Run* run)
0234 {
0235 G4cout << "================ Run is = " << run->GetRunID() << G4endl;
0236 G4cout << "================ Run type is = " << G4RunManager::GetRunManager()->GetRunManagerType()
0237 << G4endl;
0238 G4cout << "================ Event processed = " << run->GetNumberOfEventToBeProcessed() << G4endl;
0239 G4cout << "================ Nevent = " << run->GetNumberOfEvent() << G4endl;
0240 }
0241