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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/electromagnetic/TestEm1/src/RunAction.cc (Version 11.3.0) and /examples/extended/electromagnetic/TestEm1/src/RunAction.cc (Version 9.1.p3)


  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 /// \file electromagnetic/TestEm1/src/RunActio <<  26 // $Id: RunAction.cc,v 1.19 2006/06/29 16:37:25 gunter Exp $
 27 /// \brief Implementation of the RunAction cla <<  27 // GEANT4 tag $Name: geant4-09-01-patch-03 $
 28 //                                             <<  28 // 
 29 //                                             << 
 30 //....oooOO0OOooo........oooOO0OOooo........oo     29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 31 //....oooOO0OOooo........oooOO0OOooo........oo     30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32                                                    31 
 33 #include "RunAction.hh"                            32 #include "RunAction.hh"
 34                                                << 
 35 #include "DetectorConstruction.hh"                 33 #include "DetectorConstruction.hh"
 36 #include "HistoManager.hh"                     << 
 37 #include "PrimaryGeneratorAction.hh"               34 #include "PrimaryGeneratorAction.hh"
 38 #include "Run.hh"                              <<  35 #include "HistoManager.hh"
 39                                                    36 
 40 #include "G4Run.hh"                                37 #include "G4Run.hh"
                                                   >>  38 #include "G4RunManager.hh"
 41 #include "G4UnitsTable.hh"                         39 #include "G4UnitsTable.hh"
                                                   >>  40 #include "G4EmCalculator.hh"
                                                   >>  41 
 42 #include "Randomize.hh"                            42 #include "Randomize.hh"
                                                   >>  43 #include <iomanip>
 43                                                    44 
 44 //....oooOO0OOooo........oooOO0OOooo........oo     45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 45                                                    46 
 46 RunAction::RunAction(const DetectorConstructio <<  47 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin,
 47   : fDetector(det), fPrimary(kin)              <<  48                      HistoManager* histo)
 48 {                                              <<  49 :detector(det), primary(kin), ProcCounter(0), histoManager(histo)
 49   fHistoManager = new HistoManager();          <<  50 { }
 50 }                                              << 
 51                                                    51 
 52 //....oooOO0OOooo........oooOO0OOooo........oo     52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 53                                                    53 
 54 RunAction::~RunAction()                            54 RunAction::~RunAction()
 55 {                                              <<  55 { }
 56   delete fHistoManager;                        << 
 57 }                                              << 
 58                                                    56 
 59 //....oooOO0OOooo........oooOO0OOooo........oo     57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 60                                                    58 
 61 G4Run* RunAction::GenerateRun()                <<  59 void RunAction::BeginOfRunAction(const G4Run* aRun)
 62 {                                              <<  60 {  
 63   fRun = new Run(fDetector);                   <<  61   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
 64   return fRun;                                 <<  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   ProcCounter = new ProcessesCount;
                                                   >>  73      
                                                   >>  74   //histograms
                                                   >>  75   //
                                                   >>  76   histoManager->book();
 65 }                                                  77 }
                                                   >>  78 
 66 //....oooOO0OOooo........oooOO0OOooo........oo     79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 67                                                    80 
 68 void RunAction::BeginOfRunAction(const G4Run*) <<  81 void RunAction::CountProcesses(G4String procName)
 69 {                                                  82 {
 70   // show Rndm status                          <<  83    //does the process  already encounted ?
 71   if (isMaster) G4Random::showEngineStatus();  <<  84    size_t nbProc = ProcCounter->size();
                                                   >>  85    size_t i = 0;
                                                   >>  86    while ((i<nbProc)&&((*ProcCounter)[i]->GetName()!=procName)) i++;
                                                   >>  87    if (i == nbProc) ProcCounter->push_back( new OneProcessCount(procName));
 72                                                    88 
 73   // keep run condition                        <<  89    (*ProcCounter)[i]->Count();
 74   if (fPrimary) {                              << 
 75     G4ParticleDefinition* particle = fPrimary- << 
 76     G4double energy = fPrimary->GetParticleGun << 
 77     fRun->SetPrimary(particle, energy);        << 
 78   }                                            << 
 79                                                << 
 80   // histograms                                << 
 81   //                                           << 
 82   G4AnalysisManager* analysisManager = G4Analy << 
 83   if (analysisManager->IsActive()) {           << 
 84     analysisManager->OpenFile();               << 
 85   }                                            << 
 86 }                                                  90 }
 87                                                    91 
 88 //....oooOO0OOooo........oooOO0OOooo........oo     92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 89                                                    93 
 90 void RunAction::EndOfRunAction(const G4Run*)   <<  94 void RunAction::EndOfRunAction(const G4Run* aRun)
 91 {                                              <<  95 { 
 92   // compute and print statistic               <<  96   G4int NbOfEvents = aRun->GetNumberOfEvent();
 93   if (isMaster) fRun->EndOfRun();              <<  97   if (NbOfEvents == 0) return;
 94                                                <<  98   G4double dNbOfEvents = double(NbOfEvents);
 95   // save histograms                           <<  99     
 96   G4AnalysisManager* analysisManager = G4Analy << 100   G4ParticleDefinition* particle = primary->GetParticleGun()
 97   if (analysisManager->IsActive()) {           << 101                                           ->GetParticleDefinition();
 98     analysisManager->Write();                  << 102   G4String partName = particle->GetParticleName();    
 99     analysisManager->CloseFile();              << 103   G4double energy   = primary->GetParticleGun()->GetParticleEnergy();
                                                   >> 104   
                                                   >> 105   G4double length      = detector->GetSize();    
                                                   >> 106   G4Material* material = detector->GetMaterial();
                                                   >> 107   G4double density     = material->GetDensity();
                                                   >> 108    
                                                   >> 109   G4cout << "\n ======================== run summary ======================\n";
                                                   >> 110   
                                                   >> 111   G4int prec = G4cout.precision(5);
                                                   >> 112   
                                                   >> 113   G4cout << "\n The run was: " << NbOfEvents << " " << partName << " of "
                                                   >> 114          << G4BestUnit(energy,"Energy") << " through " 
                                                   >> 115    << G4BestUnit(length,"Length") << " of "
                                                   >> 116    << material->GetName() << " (density: " 
                                                   >> 117    << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
                                                   >> 118    
                                                   >> 119  G4cout << "\n ============================================================\n";
                                                   >> 120  
                                                   >> 121  G4cout << "\n total energy deposit: " 
                                                   >> 122         << G4BestUnit(edep/dNbOfEvents, "Energy") << G4endl;
                                                   >> 123        
                                                   >> 124  //nb of tracks and steps per event
                                                   >> 125  //           
                                                   >> 126  G4cout << "\n nb tracks/event"
                                                   >> 127         << "   neutral: " << std::setw(10) << NbOfTraks0/dNbOfEvents
                                                   >> 128         << "   charged: " << std::setw(10) << NbOfTraks1/dNbOfEvents
                                                   >> 129         << "\n nb  steps/event"
                                                   >> 130         << "   neutral: " << std::setw(10) << NbOfSteps0/dNbOfEvents
                                                   >> 131         << "   charged: " << std::setw(10) << NbOfSteps1/dNbOfEvents
                                                   >> 132         << G4endl;
                                                   >> 133       
                                                   >> 134  //frequency of processes call       
                                                   >> 135  G4cout << "\n nb of process calls per event: \n   ";       
                                                   >> 136  for (size_t i=0; i< ProcCounter->size();i++)
                                                   >> 137      G4cout << std::setw(12) << (*ProcCounter)[i]->GetName();
                                                   >> 138            
                                                   >> 139  G4cout << "\n   ";       
                                                   >> 140  for (size_t j=0; j< ProcCounter->size();j++)
                                                   >> 141  G4cout << std::setw(12) << ((*ProcCounter)[j]->GetCounter())/dNbOfEvents;
                                                   >> 142  G4cout << G4endl;
                                                   >> 143       
                                                   >> 144  //compute true and projected ranges, and transverse dispersion
                                                   >> 145  //
                                                   >> 146  trueRange /= NbOfEvents; trueRange2 /= NbOfEvents;
                                                   >> 147  G4double trueRms = trueRange2 - trueRange*trueRange;        
                                                   >> 148  if (trueRms>0.) trueRms = std::sqrt(trueRms); else trueRms = 0.;
                                                   >> 149       
                                                   >> 150  projRange /= NbOfEvents; projRange2 /= NbOfEvents;
                                                   >> 151  G4double projRms = projRange2 - projRange*projRange;        
                                                   >> 152  if (projRms>0.) projRms = std::sqrt(projRms); else projRms = 0.;
                                                   >> 153        
                                                   >> 154  transvDev /= 2*NbOfEvents; transvDev2 /= 2*NbOfEvents;
                                                   >> 155  G4double trvsRms = transvDev2 - transvDev*transvDev;        
                                                   >> 156  if (trvsRms>0.) trvsRms = std::sqrt(trvsRms); else trvsRms = 0.;
                                                   >> 157  
                                                   >> 158  //compare true range with csda range from PhysicsTables
                                                   >> 159  //
                                                   >> 160  G4EmCalculator emCalculator;
                                                   >> 161  G4double rangeTable = 0.;
                                                   >> 162  if (particle->GetPDGCharge() != 0.)
                                                   >> 163    rangeTable = emCalculator.GetCSDARange(energy,particle,material);
                                                   >> 164       
                                                   >> 165  G4cout << "\n---------------------------------------------------------\n";
                                                   >> 166  G4cout << " Primary particle : " ;
                                                   >> 167  G4cout << "\n true Range = " << G4BestUnit(trueRange,"Length")
                                                   >> 168         << "   rms = "        << G4BestUnit(trueRms,  "Length");
                                                   >> 169 
                                                   >> 170  G4cout << "\n proj Range = " << G4BestUnit(projRange,"Length")
                                                   >> 171         << "   rms = "        << G4BestUnit(projRms,  "Length");
                                                   >> 172        
                                                   >> 173  G4cout << "\n proj/true  = " << projRange/trueRange;
                                                   >> 174              
                                                   >> 175  G4cout << "\n transverse dispersion at end = " 
                                                   >> 176         << G4BestUnit(trvsRms,"Length");
                                                   >> 177   
                                                   >> 178  G4cout << "\n      mass true Range from simulation = " 
                                                   >> 179         << G4BestUnit(trueRange*density, "Mass/Surface")
                                                   >> 180   << "\n       from PhysicsTable (csda range) = " 
                                                   >> 181         << G4BestUnit(rangeTable*density, "Mass/Surface");  
                                                   >> 182  G4cout << "\n---------------------------------------------------------\n";
                                                   >> 183  G4cout << G4endl;
                                                   >> 184  
                                                   >> 185  // reset default precision
                                                   >> 186  G4cout.precision(prec);
                                                   >> 187                                     
                                                   >> 188   // delete and remove all contents in ProcCounter 
                                                   >> 189   while (ProcCounter->size()>0){
                                                   >> 190     OneProcessCount* aProcCount=ProcCounter->back();
                                                   >> 191     ProcCounter->pop_back();
                                                   >> 192     delete aProcCount;
100   }                                               193   }
101                                                << 194   delete ProcCounter;
                                                   >> 195   
                                                   >> 196   //save histograms      
                                                   >> 197   histoManager->save();
                                                   >> 198   
102   // show Rndm status                             199   // show Rndm status
103   if (isMaster) G4Random::showEngineStatus();  << 200   CLHEP::HepRandom::showEngineStatus(); 
104 }                                                 201 }
105                                                   202 
106 //....oooOO0OOooo........oooOO0OOooo........oo    203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
107                                                   204