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