Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // This example is provided by the Geant4-DNA 26 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained us << 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collabo 28 // shall cite the following Geant4-DNA collaboration publication: 29 // Med. Phys. 37 (2010) 4692-4708 29 // Med. Phys. 37 (2010) 4692-4708 30 // The Geant4-DNA web site is available at htt 30 // The Geant4-DNA web site is available at http://geant4-dna.org 31 // 31 // 32 /// \file RunAction.cc 32 /// \file RunAction.cc 33 /// \brief Implementation of the RunAction cla 33 /// \brief Implementation of the RunAction class 34 34 35 #include "RunAction.hh" 35 #include "RunAction.hh" 36 << 37 #include "CommandLineParser.hh" << 38 << 39 #include "G4AnalysisManager.hh" << 40 #include "G4Run.hh" 36 #include "G4Run.hh" 41 #include "G4RunManager.hh" 37 #include "G4RunManager.hh" >> 38 #include "Analysis.hh" 42 #include "G4Threading.hh" 39 #include "G4Threading.hh" >> 40 #include "CommandLineParser.hh" 43 41 44 using namespace G4DNAPARSER; 42 using namespace G4DNAPARSER; 45 43 46 void PrintNParticles(std::map<const G4Particle 44 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container); 47 45 48 //....oooOO0OOooo........oooOO0OOooo........oo 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 47 50 RunAction::RunAction() : G4UserRunAction(), fI << 48 RunAction::RunAction() : G4UserRunAction(), >> 49 fInitialized(0), fDebug(false) >> 50 {} 51 51 52 //....oooOO0OOooo........oooOO0OOooo........oo 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 53 54 RunAction::~RunAction() {} << 54 RunAction::~RunAction() >> 55 {} 55 56 56 //....oooOO0OOooo........oooOO0OOooo........oo 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 58 58 void RunAction::BeginOfRunAction(const G4Run* 59 void RunAction::BeginOfRunAction(const G4Run* run) 59 { 60 { 60 // In this example, we considered that the s 61 // In this example, we considered that the same class was 61 // used for both master and worker threads. 62 // used for both master and worker threads. 62 // However, in case the run action is long, 63 // However, in case the run action is long, 63 // for better code review, this practice is 64 // for better code review, this practice is not recommanded. 64 // 65 // 65 // Please note, in the example provided with 66 // Please note, in the example provided with the Geant4 X beta version, 66 // this RunAction class were not used by the 67 // this RunAction class were not used by the master thread. 67 68 68 bool sequential = << 69 (G4RunManager::GetRunManager()->GetRunMana << 70 69 71 if (isMaster && sequential == false) << 70 bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == >> 71 G4RunManager::sequentialRM); >> 72 >> 73 if(isMaster && sequential == false ) 72 // WARNING : in sequential mode, isMaster == 74 // WARNING : in sequential mode, isMaster == true 73 { 75 { 74 BeginMaster(run); 76 BeginMaster(run); 75 } 77 } 76 else << 78 else BeginWorker(run); 77 BeginWorker(run); << 78 } 79 } 79 80 80 //....oooOO0OOooo........oooOO0OOooo........oo 81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 81 82 82 void RunAction::EndOfRunAction(const G4Run* ru 83 void RunAction::EndOfRunAction(const G4Run* run) 83 { 84 { 84 bool sequential = << 85 (G4RunManager::GetRunManager()->GetRunMana << 86 85 87 if (isMaster && sequential == false) { << 86 bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == >> 87 G4RunManager::sequentialRM); >> 88 >> 89 if(isMaster && sequential == false) >> 90 { 88 EndMaster(run); 91 EndMaster(run); 89 } 92 } 90 else { << 93 else >> 94 { 91 EndWorker(run); 95 EndWorker(run); 92 } 96 } 93 } 97 } 94 98 95 //....oooOO0OOooo........oooOO0OOooo........oo 99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 96 100 97 void RunAction::BeginMaster(const G4Run* run) 101 void RunAction::BeginMaster(const G4Run* run) 98 { 102 { 99 if (fDebug) { << 103 if(fDebug) 100 bool sequential = << 104 { 101 (G4RunManager::GetRunManager()->GetRunMa << 105 bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == >> 106 G4RunManager::sequentialRM); 102 G4cout << "=============================== 107 G4cout << "===================================" << G4endl; 103 if (!sequential) G4cout << "============== << 108 if(!sequential) >> 109 G4cout << "================ RunAction::BeginMaster" << G4endl; 104 PrintRunInfo(run); 110 PrintRunInfo(run); 105 G4cout << "=============================== 111 G4cout << "===================================" << G4endl; 106 } 112 } 107 } 113 } 108 114 109 //....oooOO0OOooo........oooOO0OOooo........oo 115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 110 116 111 void RunAction::BeginWorker(const G4Run* run) 117 void RunAction::BeginWorker(const G4Run* run) 112 { 118 { 113 if (fDebug) { << 119 if (fDebug) >> 120 { 114 G4cout << "=============================== 121 G4cout << "===================================" << G4endl; 115 G4cout << "================ RunAction::Beg 122 G4cout << "================ RunAction::BeginWorker" << G4endl; 116 PrintRunInfo(run); 123 PrintRunInfo(run); 117 G4cout << "=============================== 124 G4cout << "===================================" << G4endl; 118 } 125 } 119 if (fInitialized == false) InitializeWorker( << 126 if(fInitialized == false) InitializeWorker(run); 120 127 121 CreateNtuple(); 128 CreateNtuple(); 122 } 129 } 123 130 124 //....oooOO0OOooo........oooOO0OOooo........oo 131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 125 132 126 void RunAction::EndMaster(const G4Run*) {} << 133 void RunAction::EndMaster(const G4Run*) >> 134 { >> 135 } 127 136 128 //....oooOO0OOooo........oooOO0OOooo........oo 137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 129 138 130 void RunAction::EndWorker(const G4Run* run) 139 void RunAction::EndWorker(const G4Run* run) 131 { 140 { 132 if (fDebug) { << 141 if(fDebug) >> 142 { 133 PrintRunInfo(run); 143 PrintRunInfo(run); 134 } 144 } 135 145 136 G4int nofEvents = run->GetNumberOfEvent(); 146 G4int nofEvents = run->GetNumberOfEvent(); 137 if (nofEvents == 0) { << 147 if ( nofEvents == 0 ) 138 if (fDebug) { << 148 { 139 G4cout << "================ NO EVENTS TR << 149 if(fDebug) >> 150 { >> 151 G4cout << "================ NO EVENTS TREATED IN THIS RUN ==> Exit" >> 152 << G4endl; 140 } 153 } 141 return; 154 return; 142 } 155 } 143 156 144 /////////////// 157 /////////////// 145 // Write Ntuple 158 // Write Ntuple 146 // 159 // 147 WriteNtuple(); 160 WriteNtuple(); >> 161 >> 162 /////////////// >> 163 // Complete cleanup >> 164 // >> 165 delete G4AnalysisManager::Instance(); 148 } 166 } 149 167 150 //....oooOO0OOooo........oooOO0OOooo........oo 168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 151 169 152 void RunAction::InitializeWorker(const G4Run*) 170 void RunAction::InitializeWorker(const G4Run*) 153 { 171 { 154 // Initialize worker here 172 // Initialize worker here 155 // example: you want to retrieve pointers to 173 // example: you want to retrieve pointers to other user actions 156 fInitialized = true; 174 fInitialized = true; 157 } 175 } 158 176 159 //....oooOO0OOooo........oooOO0OOooo........oo 177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 160 178 161 void RunAction::CreateNtuple() 179 void RunAction::CreateNtuple() 162 { 180 { 163 // Book histograms, ntuple 181 // Book histograms, ntuple 164 182 165 // Create analysis manager 183 // Create analysis manager >> 184 // The choice of analysis technology is done via selection of a namespace >> 185 // in Analysis.hh 166 186 167 CommandLineParser* parser = CommandLineParse 187 CommandLineParser* parser = CommandLineParser::GetParser(); 168 Command* command(0); 188 Command* command(0); 169 if ((command = parser->GetCommandIfActive("- << 189 if((command = parser->GetCommandIfActive("-out"))==0) return; 170 190 171 G4cout << "##### Create analysis manager " << 191 G4cout << "##### Create analysis manager " << " " << this << G4endl; 172 << " " << this << G4endl; << 173 G4AnalysisManager* analysisManager = G4Analy 192 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 174 analysisManager->SetDefaultFileType("root"); << 193 // if(!analysisManager->IsActive()) {return; } 175 // if(!analysisManager->IsActive()) {return << 176 194 177 G4cout << "Using " << analysisManager->GetTy << 195 G4cout << "Using " << analysisManager->GetType() << >> 196 " analysis manager" << G4endl; 178 197 179 // Create directories 198 // Create directories 180 199 181 // analysisManager->SetHistoDirectoryName("h << 200 //analysisManager->SetHistoDirectoryName("histograms"); 182 // analysisManager->SetNtupleDirectoryName(" << 201 //analysisManager->SetNtupleDirectoryName("ntuple"); 183 analysisManager->SetVerboseLevel(1); 202 analysisManager->SetVerboseLevel(1); 184 203 185 // Open an output file 204 // Open an output file 186 G4String fileName; 205 G4String fileName; 187 if (command->GetOption().empty() == false) { << 206 if(command->GetOption().empty() == false) >> 207 { 188 fileName = command->GetOption(); 208 fileName = command->GetOption(); 189 } 209 } 190 else { << 210 else 191 fileName = "wholeNuclearDNA"; << 211 { 192 // fileName = command->GetDefaultOption( << 212 fileName = "wholeNuclearDNA"; >> 213 // fileName = command->GetDefaultOption(); // should work as well 193 } 214 } 194 analysisManager->OpenFile(fileName); 215 analysisManager->OpenFile(fileName); 195 216 196 // Creating ntuple 217 // Creating ntuple 197 analysisManager->CreateNtuple("ntuple", "geo 218 analysisManager->CreateNtuple("ntuple", "geom_dna"); 198 analysisManager->CreateNtupleDColumn("flagPa 219 analysisManager->CreateNtupleDColumn("flagParticle"); 199 analysisManager->CreateNtupleDColumn("flagPr 220 analysisManager->CreateNtupleDColumn("flagProcess"); 200 analysisManager->CreateNtupleDColumn("flagVo 221 analysisManager->CreateNtupleDColumn("flagVolume"); 201 analysisManager->CreateNtupleDColumn("x"); 222 analysisManager->CreateNtupleDColumn("x"); 202 analysisManager->CreateNtupleDColumn("y"); 223 analysisManager->CreateNtupleDColumn("y"); 203 analysisManager->CreateNtupleDColumn("z"); 224 analysisManager->CreateNtupleDColumn("z"); 204 analysisManager->CreateNtupleDColumn("edep") 225 analysisManager->CreateNtupleDColumn("edep"); 205 analysisManager->CreateNtupleDColumn("stepLe 226 analysisManager->CreateNtupleDColumn("stepLength"); 206 227 207 analysisManager->FinishNtuple(); 228 analysisManager->FinishNtuple(); >> 229 208 } 230 } 209 231 210 //....oooOO0OOooo........oooOO0OOooo........oo 232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 211 233 212 void RunAction::WriteNtuple() 234 void RunAction::WriteNtuple() 213 { 235 { 214 CommandLineParser* parser = CommandLineParse 236 CommandLineParser* parser = CommandLineParser::GetParser(); 215 Command* commandLine(0); 237 Command* commandLine(0); 216 if ((commandLine = parser->GetCommandIfActiv << 238 if((commandLine = parser->GetCommandIfActive("-out"))==0) return; 217 239 218 // print histogram statistics 240 // print histogram statistics 219 // 241 // 220 G4AnalysisManager* analysisManager = G4Analy 242 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 221 // if(!analysisManager->IsActive()) {return << 243 // if(!analysisManager->IsActive()) {return; } 222 244 223 // save histograms 245 // save histograms 224 // 246 // 225 analysisManager->Write(); 247 analysisManager->Write(); 226 analysisManager->CloseFile(); 248 analysisManager->CloseFile(); 227 analysisManager->Clear(); << 228 } 249 } 229 250 230 //....oooOO0OOooo........oooOO0OOooo........oo 251 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 231 252 232 void RunAction::PrintRunInfo(const G4Run* run) 253 void RunAction::PrintRunInfo(const G4Run* run) 233 { 254 { 234 G4cout << "================ Run is = " << ru << 255 G4cout << "================ Run is = " 235 G4cout << "================ Run type is = " << 256 << run->GetRunID() << G4endl; 236 << G4endl; << 257 G4cout << "================ Run type is = " 237 G4cout << "================ Event processed << 258 << G4RunManager::GetRunManager()->GetRunManagerType() << G4endl; 238 G4cout << "================ Nevent = " << ru << 259 G4cout << "================ Event processed = " >> 260 << run->GetNumberOfEventToBeProcessed() << G4endl; >> 261 G4cout << "================ Nevent = " >> 262 << run->GetNumberOfEvent() << G4endl; 239 } 263 } 240 //....oooOO0OOooo........oooOO0OOooo........oo 264 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 241 265