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