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 // ------------------------------------------- 27 // ------------------------------------------- 28 29 #include "RunAction.hh" 30 #include "G4Run.hh" 31 #include "TrackingAction.hh" 32 #include "G4ParticleDefinition.hh" 33 #include "G4RunManager.hh" 34 #include "G4AnalysisManager.hh" 35 #include "G4Threading.hh" 36 37 void PrintNParticles(std::map<const G4Particle 38 39 //....oooOO0OOooo........oooOO0OOooo........oo 40 41 RunAction::RunAction() 42 { 43 fFileName = "microelectronics"; 44 fpTrackingAction = 0; 45 fInitialized = 0; 46 fDebug = false; 47 } 48 49 //....oooOO0OOooo........oooOO0OOooo........oo 50 51 RunAction::~RunAction() 52 {} 53 54 //....oooOO0OOooo........oooOO0OOooo........oo 55 56 void RunAction::BeginOfRunAction(const G4Run* 57 { 58 // In this example, we considered that the s 59 // used for both master and worker threads. 60 // However, in case the run action is long, 61 // for better code review, this practice is 62 // 63 64 if(isMaster) // WARNING : in sequential mode 65 BeginMaster(run); 66 else 67 BeginWorker(run); 68 } 69 70 //....oooOO0OOooo........oooOO0OOooo........oo 71 72 void RunAction::EndOfRunAction(const G4Run* ru 73 { 74 if(isMaster) 75 EndMaster(run); 76 else 77 EndWorker(run); 78 } 79 80 81 //....oooOO0OOooo........oooOO0OOooo........oo 82 83 void RunAction::BeginMaster(const G4Run* run) 84 { 85 bool sequential = (G4RunManager::GetRunManag 86 87 if(fDebug) 88 { 89 G4cout << "°°°°°°°°°°°°°° 90 if(!sequential) 91 G4cout << "°°°°°°°°°°°°°°°° 92 PrintRunInfo(run); 93 G4cout << "°°°°°°°°°°°°°° 94 } 95 96 if(sequential) 97 { 98 if(!fInitialized) 99 InitializeWorker(run); 100 // Note: fpTrackingAction could be used 101 102 CreateHistogram(); 103 } 104 } 105 106 //....oooOO0OOooo........oooOO0OOooo........oo 107 108 void RunAction::BeginWorker(const G4Run* run) 109 { 110 if(fDebug) 111 { 112 G4cout << "°°°°°°°°°°°°°° 113 G4cout << "°°°°°°°°°°°°°° 114 PrintRunInfo(run); 115 G4cout << "°°°°°°°°°°°°°° 116 } 117 if(!fInitialized) 118 InitializeWorker(run); 119 120 CreateHistogram(); 121 } 122 123 //....oooOO0OOooo........oooOO0OOooo........oo 124 125 void RunAction::EndMaster(const G4Run* run) 126 { 127 bool sequential = (G4RunManager::GetRunManag 128 == G4RunManager::sequentialRM); 129 if(sequential) 130 EndWorker(run); 131 } 132 133 //....oooOO0OOooo........oooOO0OOooo........oo 134 135 void RunAction::EndWorker(const G4Run* run) 136 { 137 if(fDebug) 138 { 139 PrintRunInfo(run); 140 } 141 142 G4int nofEvents = run->GetNumberOfEvent(); 143 if ( nofEvents == 0 ) 144 { 145 if(fDebug) 146 { 147 G4cout << "°°°°°°°°°°°°°°° 148 } 149 return; 150 } 151 152 /////////////// 153 // Write Histo 154 // 155 WriteHistogram(); 156 157 /////////////// 158 // Complete cleanup 159 // 160 G4AnalysisManager* analysisManager = G4Analy 161 analysisManager->Clear(); 162 163 /////////////// 164 // Printouts 165 // 166 std::map<const G4ParticleDefinition*, int>& 167 particlesCreatedInWorld = fpTrackingAction 168 169 G4cout << "Number and type of particles crea 170 171 PrintNParticles(particlesCreatedInWorld); 172 173 G4cout << "_______________________" << G4end 174 175 std::map<const G4ParticleDefinition*, int>& 176 particlesCreatedInTarget = fpTrackingActio 177 178 G4cout << "Number and type of particles crea 179 180 PrintNParticles(particlesCreatedInTarget); 181 182 } 183 184 //....oooOO0OOooo........oooOO0OOooo........oo 185 186 void RunAction::InitializeWorker(const G4Run*) 187 { 188 if (fpTrackingAction == 0) 189 { 190 fpTrackingAction = (TrackingAction*) G4Run 191 192 if(fpTrackingAction == 0 && isMaster == fa 193 { 194 G4ExceptionDescription exDescrption ; 195 exDescrption << "fpTrackingAction is a n 196 G4Exception("RunAction::BeginOfRunAction 197 } 198 } 199 200 fInitialized = true; 201 } 202 203 //....oooOO0OOooo........oooOO0OOooo........oo 204 205 void RunAction::CreateHistogram() 206 { 207 // Book histograms, ntuple 208 209 // Create analysis manager 210 // The choice of analysis technology is done 211 // in Analysis.hh 212 213 G4cout << "##### Create analysis manager " < 214 G4AnalysisManager* analysisManager = G4Analy 215 analysisManager->SetDefaultFileType("root"); 216 217 G4cout << "Using " << analysisManager->GetTy 218 219 // Create directories 220 221 //analysisManager->SetHistoDirectoryName("hi 222 //analysisManager->SetNtupleDirectoryName("n 223 analysisManager->SetVerboseLevel(1); 224 225 // Open an output file 226 227 analysisManager->OpenFile(fFileName); 228 229 // Creating ntuple 230 231 analysisManager->CreateNtuple("microelectron 232 analysisManager->CreateNtupleDColumn("flagPa 233 analysisManager->CreateNtupleDColumn("flagPr 234 analysisManager->CreateNtupleDColumn("x"); 235 analysisManager->CreateNtupleDColumn("y"); 236 analysisManager->CreateNtupleDColumn("z"); 237 analysisManager->CreateNtupleDColumn("totalE 238 analysisManager->CreateNtupleDColumn("stepLe 239 analysisManager->CreateNtupleDColumn("kineti 240 analysisManager->FinishNtuple(); 241 } 242 243 //....oooOO0OOooo........oooOO0OOooo........oo 244 245 void RunAction::WriteHistogram() 246 { 247 // print histogram statistics 248 // 249 G4AnalysisManager* analysisManager = G4Analy 250 251 // save histograms 252 // 253 analysisManager->Write(); 254 analysisManager->CloseFile(); 255 } 256 257 //....oooOO0OOooo........oooOO0OOooo........oo 258 259 void RunAction::PrintRunInfo(const G4Run* run) 260 { 261 G4cout << "°°°°°°°°°°°°°°°° 262 G4cout << "°°°°°°°°°°°°°°°° 263 G4cout << "°°°°°°°°°°°°°°°° 264 G4cout << "°°°°°°°°°°°°°°°° 265 } 266 267 //....oooOO0OOooo........oooOO0OOooo........oo 268 void PrintNParticles(std::map<const G4Particle 269 { 270 std::map<const G4ParticleDefinition*, int> 271 for(it = container.begin() ; 272 it != container.end(); it ++) 273 { 274 G4cout << "N " << it->first->GetPartic 275 } 276 } 277 278 //....oooOO0OOooo........oooOO0OOooo........oo 279