[807] | 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 | // |
---|
[1337] | 26 | // $Id: RunAction.cc,v 1.20 2010/04/06 11:11:24 maire Exp $ |
---|
| 27 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
[807] | 28 | // |
---|
| 29 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 31 | |
---|
| 32 | #include "RunAction.hh" |
---|
| 33 | #include "DetectorConstruction.hh" |
---|
| 34 | #include "PrimaryGeneratorAction.hh" |
---|
| 35 | #include "HistoManager.hh" |
---|
| 36 | |
---|
| 37 | #include "G4Run.hh" |
---|
| 38 | #include "G4RunManager.hh" |
---|
| 39 | #include "G4UnitsTable.hh" |
---|
| 40 | #include "G4EmCalculator.hh" |
---|
| 41 | |
---|
| 42 | #include "Randomize.hh" |
---|
| 43 | #include <iomanip> |
---|
| 44 | |
---|
| 45 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 46 | |
---|
| 47 | RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin, |
---|
| 48 | HistoManager* histo) |
---|
[1337] | 49 | :detector(det), primary(kin), histoManager(histo) |
---|
[807] | 50 | { } |
---|
| 51 | |
---|
| 52 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 53 | |
---|
| 54 | RunAction::~RunAction() |
---|
| 55 | { } |
---|
| 56 | |
---|
| 57 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 58 | |
---|
| 59 | void RunAction::BeginOfRunAction(const G4Run* aRun) |
---|
| 60 | { |
---|
| 61 | G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; |
---|
| 62 | |
---|
| 63 | // save Rndm status |
---|
| 64 | G4RunManager::GetRunManager()->SetRandomNumberStore(true); |
---|
| 65 | CLHEP::HepRandom::showEngineStatus(); |
---|
| 66 | |
---|
| 67 | NbOfTraks0 = NbOfTraks1 = NbOfSteps0 = NbOfSteps1 = 0; |
---|
| 68 | edep = 0.; |
---|
| 69 | trueRange = trueRange2 = 0.; |
---|
| 70 | projRange = projRange2 = 0.; |
---|
| 71 | transvDev = transvDev2 = 0.; |
---|
| 72 | |
---|
| 73 | //histograms |
---|
| 74 | // |
---|
| 75 | histoManager->book(); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 79 | |
---|
| 80 | void RunAction::EndOfRunAction(const G4Run* aRun) |
---|
| 81 | { |
---|
| 82 | G4int NbOfEvents = aRun->GetNumberOfEvent(); |
---|
| 83 | if (NbOfEvents == 0) return; |
---|
| 84 | G4double dNbOfEvents = double(NbOfEvents); |
---|
| 85 | |
---|
| 86 | G4ParticleDefinition* particle = primary->GetParticleGun() |
---|
| 87 | ->GetParticleDefinition(); |
---|
| 88 | G4String partName = particle->GetParticleName(); |
---|
| 89 | G4double energy = primary->GetParticleGun()->GetParticleEnergy(); |
---|
| 90 | |
---|
| 91 | G4double length = detector->GetSize(); |
---|
| 92 | G4Material* material = detector->GetMaterial(); |
---|
| 93 | G4double density = material->GetDensity(); |
---|
| 94 | |
---|
| 95 | G4cout << "\n ======================== run summary ======================\n"; |
---|
| 96 | |
---|
| 97 | G4int prec = G4cout.precision(5); |
---|
| 98 | |
---|
| 99 | G4cout << "\n The run was: " << NbOfEvents << " " << partName << " of " |
---|
| 100 | << G4BestUnit(energy,"Energy") << " through " |
---|
| 101 | << G4BestUnit(length,"Length") << " of " |
---|
| 102 | << material->GetName() << " (density: " |
---|
| 103 | << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; |
---|
| 104 | |
---|
| 105 | G4cout << "\n ============================================================\n"; |
---|
| 106 | |
---|
| 107 | G4cout << "\n total energy deposit: " |
---|
| 108 | << G4BestUnit(edep/dNbOfEvents, "Energy") << G4endl; |
---|
| 109 | |
---|
| 110 | //nb of tracks and steps per event |
---|
| 111 | // |
---|
| 112 | G4cout << "\n nb tracks/event" |
---|
| 113 | << " neutral: " << std::setw(10) << NbOfTraks0/dNbOfEvents |
---|
| 114 | << " charged: " << std::setw(10) << NbOfTraks1/dNbOfEvents |
---|
| 115 | << "\n nb steps/event" |
---|
| 116 | << " neutral: " << std::setw(10) << NbOfSteps0/dNbOfEvents |
---|
| 117 | << " charged: " << std::setw(10) << NbOfSteps1/dNbOfEvents |
---|
| 118 | << G4endl; |
---|
| 119 | |
---|
[1337] | 120 | //frequency of processes call |
---|
| 121 | std::map<G4String,G4int>::iterator it; |
---|
| 122 | G4cout << "\n nb of process calls per event: \n "; |
---|
| 123 | for (it = procCounter.begin(); it != procCounter.end(); it++) |
---|
| 124 | G4cout << std::setw(12) << it->first; |
---|
[807] | 125 | |
---|
| 126 | G4cout << "\n "; |
---|
[1337] | 127 | for (it = procCounter.begin(); it != procCounter.end(); it++) |
---|
| 128 | G4cout << std::setw(12) << (it->second)/dNbOfEvents; |
---|
[807] | 129 | G4cout << G4endl; |
---|
| 130 | |
---|
| 131 | //compute true and projected ranges, and transverse dispersion |
---|
| 132 | // |
---|
| 133 | trueRange /= NbOfEvents; trueRange2 /= NbOfEvents; |
---|
| 134 | G4double trueRms = trueRange2 - trueRange*trueRange; |
---|
| 135 | if (trueRms>0.) trueRms = std::sqrt(trueRms); else trueRms = 0.; |
---|
| 136 | |
---|
| 137 | projRange /= NbOfEvents; projRange2 /= NbOfEvents; |
---|
| 138 | G4double projRms = projRange2 - projRange*projRange; |
---|
| 139 | if (projRms>0.) projRms = std::sqrt(projRms); else projRms = 0.; |
---|
| 140 | |
---|
| 141 | transvDev /= 2*NbOfEvents; transvDev2 /= 2*NbOfEvents; |
---|
| 142 | G4double trvsRms = transvDev2 - transvDev*transvDev; |
---|
| 143 | if (trvsRms>0.) trvsRms = std::sqrt(trvsRms); else trvsRms = 0.; |
---|
| 144 | |
---|
| 145 | //compare true range with csda range from PhysicsTables |
---|
| 146 | // |
---|
| 147 | G4EmCalculator emCalculator; |
---|
| 148 | G4double rangeTable = 0.; |
---|
| 149 | if (particle->GetPDGCharge() != 0.) |
---|
| 150 | rangeTable = emCalculator.GetCSDARange(energy,particle,material); |
---|
| 151 | |
---|
| 152 | G4cout << "\n---------------------------------------------------------\n"; |
---|
| 153 | G4cout << " Primary particle : " ; |
---|
| 154 | G4cout << "\n true Range = " << G4BestUnit(trueRange,"Length") |
---|
| 155 | << " rms = " << G4BestUnit(trueRms, "Length"); |
---|
| 156 | |
---|
| 157 | G4cout << "\n proj Range = " << G4BestUnit(projRange,"Length") |
---|
| 158 | << " rms = " << G4BestUnit(projRms, "Length"); |
---|
| 159 | |
---|
| 160 | G4cout << "\n proj/true = " << projRange/trueRange; |
---|
| 161 | |
---|
| 162 | G4cout << "\n transverse dispersion at end = " |
---|
| 163 | << G4BestUnit(trvsRms,"Length"); |
---|
| 164 | |
---|
| 165 | G4cout << "\n mass true Range from simulation = " |
---|
| 166 | << G4BestUnit(trueRange*density, "Mass/Surface") |
---|
| 167 | << "\n from PhysicsTable (csda range) = " |
---|
| 168 | << G4BestUnit(rangeTable*density, "Mass/Surface"); |
---|
| 169 | G4cout << "\n---------------------------------------------------------\n"; |
---|
| 170 | G4cout << G4endl; |
---|
| 171 | |
---|
| 172 | // reset default precision |
---|
| 173 | G4cout.precision(prec); |
---|
| 174 | |
---|
[1337] | 175 | // remove all contents in procCounter |
---|
| 176 | procCounter.clear(); |
---|
| 177 | |
---|
[807] | 178 | //save histograms |
---|
| 179 | histoManager->save(); |
---|
| 180 | |
---|
| 181 | // show Rndm status |
---|
| 182 | CLHEP::HepRandom::showEngineStatus(); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|