Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 /// \file optical/OpNovice2/src/RunAction.cc 27 /// \brief Implementation of the RunAction class 28 // 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 33 #include "RunAction.hh" 34 35 #include "HistoManager.hh" 36 #include "PrimaryGeneratorAction.hh" 37 #include "Run.hh" 38 39 #include "G4Run.hh" 40 #include "G4UnitsTable.hh" 41 42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 43 44 RunAction::RunAction(PrimaryGeneratorAction* prim) 45 : G4UserRunAction(), fRun(nullptr), fHistoManager(nullptr), fPrimary(prim) 46 { 47 fHistoManager = new HistoManager(); 48 } 49 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 52 RunAction::~RunAction() 53 { 54 delete fHistoManager; 55 } 56 57 G4Run* RunAction::GenerateRun() 58 { 59 fRun = new Run(); 60 return fRun; 61 } 62 63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 64 65 void RunAction::BeginOfRunAction(const G4Run*) 66 { 67 if (fPrimary) { 68 G4ParticleDefinition* particle = fPrimary->GetParticleGun()->GetParticleDefinition(); 69 G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy(); 70 G4bool polarized = fPrimary->GetPolarized(); 71 G4double polarization = fPrimary->GetPolarization(); 72 fRun->SetPrimary(particle, energy, polarized, polarization); 73 } 74 75 // histograms 76 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 77 if (analysisManager->IsActive()) { 78 analysisManager->OpenFile(); 79 } 80 } 81 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 83 84 void RunAction::EndOfRunAction(const G4Run*) 85 { 86 if (isMaster) fRun->EndOfRun(); 87 88 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 89 90 G4cout << G4endl << " Histogram statistics for the "; 91 if (isMaster) { 92 G4cout << "entire run:" << G4endl << G4endl; 93 } 94 else { 95 G4cout << "local thread:" << G4endl << G4endl; 96 } 97 98 G4int id = analysisManager->GetH1Id("Cerenkov spectrum"); 99 if (analysisManager->GetH1Activation(id)) { 100 G4cout << " Cerenkov spectrum: mean = " << analysisManager->GetH1(id)->mean() 101 << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl; 102 } 103 id = analysisManager->GetH1Id("Scintillation spectrum"); 104 if (analysisManager->GetH1Activation(id)) { 105 G4cout << " Scintillation spectrum: mean = " << analysisManager->GetH1(id)->mean() 106 << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl; 107 } 108 id = analysisManager->GetH1Id("Scintillation time"); 109 if (analysisManager->GetH1Activation(id)) { 110 G4cout << " Scintillation time: mean = " << analysisManager->GetH1(id)->mean() 111 << " ns; rms = " << analysisManager->GetH1(id)->rms() << " ns." << G4endl; 112 } 113 id = analysisManager->GetH1Id("WLS abs"); 114 if (analysisManager->GetH1Activation(id)) { 115 G4cout << " WLS absorption spectrum: mean = " << analysisManager->GetH1(id)->mean() 116 << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl; 117 } 118 id = analysisManager->GetH1Id("WLS em"); 119 if (analysisManager->GetH1Activation(id)) { 120 G4cout << " WLS emission spectrum: mean = " << analysisManager->GetH1(id)->mean() 121 << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl; 122 } 123 id = analysisManager->GetH1Id("WLS time"); 124 if (analysisManager->GetH1Activation(id)) { 125 G4cout << " WLS emission time: mean = " << analysisManager->GetH1(id)->mean() 126 << " ns; rms = " << analysisManager->GetH1(id)->rms() << " ns." << G4endl; 127 } 128 id = analysisManager->GetH1Id("WLS2 abs"); 129 if (analysisManager->GetH1Activation(id)) { 130 G4cout << " WLS emission time: mean = " << analysisManager->GetH1(id)->mean() 131 << " ns; rms = " << analysisManager->GetH1(id)->rms() << " ns." << G4endl; 132 } 133 id = analysisManager->GetH1Id("WLS2 em"); 134 if (analysisManager->GetH1Activation(id)) { 135 G4cout << " WLS2 emission spectrum: mean = " << analysisManager->GetH1(id)->mean() 136 << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl; 137 } 138 id = analysisManager->GetH1Id("WLS2 time"); 139 if (analysisManager->GetH1Activation(id)) { 140 G4cout << " WLS2 emission time: mean = " << analysisManager->GetH1(id)->mean() 141 << " ns; rms = " << analysisManager->GetH1(id)->rms() << " ns." << G4endl; 142 } 143 id = analysisManager->GetH1Id("x_backward"); 144 if (analysisManager->GetH1Activation(id)) { 145 G4cout << " X momentum dir of backward-going photons: mean = " 146 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 147 << G4endl; 148 } 149 id = analysisManager->GetH1Id("y_backward"); 150 if (analysisManager->GetH1Activation(id)) { 151 G4cout << " Y momentum dir of backward-going photons: mean = " 152 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 153 << G4endl; 154 } 155 id = analysisManager->GetH1Id("z_backward"); 156 if (analysisManager->GetH1Activation(id)) { 157 G4cout << " Z momentum dir of backward-going photons: mean = " 158 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 159 << G4endl; 160 } 161 id = analysisManager->GetH1Id("x_forward"); 162 if (analysisManager->GetH1Activation(id)) { 163 G4cout << " X momentum dir of forward-going photons: mean = " 164 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 165 << G4endl; 166 } 167 id = analysisManager->GetH1Id("y_forward"); 168 if (analysisManager->GetH1Activation(id)) { 169 G4cout << " Y momentum dir of forward-going photons: mean = " 170 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 171 << G4endl; 172 } 173 id = analysisManager->GetH1Id("z_forward"); 174 if (analysisManager->GetH1Activation(id)) { 175 G4cout << " Z momentum dir of forward-going photons: mean = " 176 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 177 << G4endl; 178 } 179 id = analysisManager->GetH1Id("x_fresnel"); 180 if (analysisManager->GetH1Activation(id)) { 181 G4cout << " X momentum dir of Fresnel-refracted photons: mean = " 182 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 183 << G4endl; 184 } 185 id = analysisManager->GetH1Id("y_fresnel"); 186 if (analysisManager->GetH1Activation(id)) { 187 G4cout << " Y momentum dir of Fresnel-refracted photons: mean = " 188 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 189 << G4endl; 190 } 191 id = analysisManager->GetH1Id("z_fresnel"); 192 if (analysisManager->GetH1Activation(id)) { 193 G4cout << " Z momentum dir of Fresnel-refracted photons: mean = " 194 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 195 << G4endl; 196 } 197 id = analysisManager->GetH1Id("Transmitted"); 198 if (analysisManager->GetH1Activation(id)) { 199 G4cout << " Angle of transmitted photons: mean = " << analysisManager->GetH1(id)->mean() 200 << "; rms = " << analysisManager->GetH1(id)->rms() << G4endl; 201 } 202 id = analysisManager->GetH1Id("Fresnel reflection"); 203 if (analysisManager->GetH1Activation(id)) { 204 G4cout << " Angle of Fresnel-reflected photons: mean = " << analysisManager->GetH1(id)->mean() 205 << "; rms = " << analysisManager->GetH1(id)->rms() << G4endl; 206 } 207 id = analysisManager->GetH1Id("Total internal reflection"); 208 if (analysisManager->GetH1Activation(id)) { 209 G4cout << " Angle of total internal reflected photons: mean = " 210 << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms() 211 << G4endl; 212 } 213 214 id = analysisManager->GetH1Id("Fresnel refraction"); 215 if (analysisManager->GetH1Activation(id)) { 216 G4cout << " Angle of Fresnel-refracted photons: mean = " << analysisManager->GetH1(id)->mean() 217 << "; rms = " << analysisManager->GetH1(id)->rms() << G4endl; 218 } 219 220 id = analysisManager->GetH1Id("Absorption"); 221 if (analysisManager->GetH1Activation(id)) { 222 G4cout << " Angle of absorbed photons: mean = " << analysisManager->GetH1(id)->mean() 223 << "; rms = " << analysisManager->GetH1(id)->rms() << G4endl; 224 } 225 226 G4cout << G4endl; 227 228 if (analysisManager->IsActive()) { 229 analysisManager->Write(); 230 analysisManager->CloseFile(); 231 } 232 } 233 234 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 235