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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/TestEm14/src/RunAction.cc (Version 11.3.0) and /examples/extended/electromagnetic/TestEm14/src/RunAction.cc (Version 10.0.p4)


  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 RunAction.cc                         <<  26 /// \file electromagnetic/TestEm14/src/RunAction.cc
 27 /// \brief Implementation of the RunAction cla     27 /// \brief Implementation of the RunAction class
 28 //                                                 28 //
 29 //                                             <<  29 // $Id: RunAction.cc 68313 2013-03-21 18:15:21Z maire $
                                                   >>  30 // 
 30 //....oooOO0OOooo........oooOO0OOooo........oo     31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 31 //....oooOO0OOooo........oooOO0OOooo........oo     32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32                                                    33 
 33 #include "RunAction.hh"                            34 #include "RunAction.hh"
 34                                                    35 
 35 #include "DetectorConstruction.hh"                 36 #include "DetectorConstruction.hh"
 36 #include "HistoManager.hh"                     << 
 37 #include "PrimaryGeneratorAction.hh"               37 #include "PrimaryGeneratorAction.hh"
 38 #include "Run.hh"                              <<  38 #include "HistoManager.hh"
 39                                                    39 
 40 #include "G4EmCalculator.hh"                   << 
 41 #include "G4Run.hh"                                40 #include "G4Run.hh"
                                                   >>  41 #include "G4RunManager.hh"
 42 #include "G4UnitsTable.hh"                         42 #include "G4UnitsTable.hh"
 43 #include "Randomize.hh"                        <<  43 #include "G4EmCalculator.hh"
                                                   >>  44 #include "G4Gamma.hh"
 44                                                    45 
                                                   >>  46 #include "G4SystemOfUnits.hh"
                                                   >>  47 #include "Randomize.hh"
 45 #include <iomanip>                                 48 #include <iomanip>
 46                                                    49 
 47 //....oooOO0OOooo........oooOO0OOooo........oo     50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 48                                                    51 
 49 RunAction::RunAction(DetectorConstruction* det <<  52 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* prim)
 50   : fDetector(det), fPrimary(kin)              <<  53   : G4UserRunAction(),fDetector(det), fPrimary(prim), fHistoManager(0)
 51 {                                                  54 {
 52   fHistoManager = new HistoManager();          <<  55   fHistoManager = new HistoManager(); 
 53 }                                                  56 }
 54                                                    57 
 55 //....oooOO0OOooo........oooOO0OOooo........oo     58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 56                                                    59 
 57 RunAction::~RunAction()                            60 RunAction::~RunAction()
 58 {                                              <<  61 { 
 59   delete fHistoManager;                            62   delete fHistoManager;
 60 }                                                  63 }
 61                                                    64 
 62 //....oooOO0OOooo........oooOO0OOooo........oo     65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 63                                                    66 
 64 G4Run* RunAction::GenerateRun()                <<  67 void RunAction::BeginOfRunAction(const G4Run* aRun)
 65 {                                              <<  68 {  
 66   fRun = new Run(fDetector);                   <<  69   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
 67   return fRun;                                 <<  70   
 68 }                                              <<  71   // save Rndm status
 69 //....oooOO0OOooo........oooOO0OOooo........oo <<  72   G4RunManager::GetRunManager()->SetRandomNumberStore(false);
 70                                                <<  73   CLHEP::HepRandom::showEngineStatus();
 71 void RunAction::BeginOfRunAction(const G4Run*) <<  74 
 72 {                                              <<  75   fTotalCount = 0;
 73   // show Rndm status                          <<  76   fSumTrack = fSumTrack2 = 0.;
 74   if (isMaster) G4Random::showEngineStatus();  <<  77   fEnTransfer = 0.;
 75                                                <<  78      
 76   // keep run condition                        <<  79   //histograms
 77   if (fPrimary) {                              << 
 78     G4ParticleDefinition* particle = fPrimary- << 
 79     G4double energy = fPrimary->GetParticleGun << 
 80     fRun->SetPrimary(particle, energy);        << 
 81   }                                            << 
 82                                                << 
 83   // histograms                                << 
 84   //                                               80   //
 85   G4AnalysisManager* analysisManager = G4Analy     81   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
 86   if (analysisManager->IsActive()) {           <<  82   if ( analysisManager->IsActive() ) {
 87     analysisManager->OpenFile();                   83     analysisManager->OpenFile();
 88   }                                            <<  84   }     
 89 }                                                  85 }
 90                                                    86 
 91 //....oooOO0OOooo........oooOO0OOooo........oo     87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 92                                                    88 
 93 void RunAction::EndOfRunAction(const G4Run*)   <<  89 void RunAction::EndOfRunAction(const G4Run* aRun)
 94 {                                                  90 {
 95   // compute and print statistic               <<  91   G4int NbOfEvents = aRun->GetNumberOfEvent();
 96   if (isMaster) fRun->EndOfRun();              <<  92   if (NbOfEvents == 0) return;
 97                                                <<  93   
 98   // save histograms                           <<  94   G4int  prec = G4cout.precision(5);
 99   G4AnalysisManager* analysisManager = G4Analy <<  95     
100   if (analysisManager->IsActive()) {           <<  96   G4Material* material = fDetector->GetMaterial();
                                                   >>  97   G4double density = material->GetDensity();
                                                   >>  98   G4int survive = 0;
                                                   >>  99    
                                                   >> 100   G4ParticleDefinition* particle = 
                                                   >> 101                             fPrimary->GetParticleGun()->GetParticleDefinition();
                                                   >> 102   G4String Particle = particle->GetParticleName();    
                                                   >> 103   G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
                                                   >> 104   G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of "
                                                   >> 105          << G4BestUnit(energy,"Energy") << " through " 
                                                   >> 106          << G4BestUnit(fDetector->GetSize(),"Length") << " of "
                                                   >> 107          << material->GetName() << " (density: " 
                                                   >> 108          << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
                                                   >> 109   
                                                   >> 110   //frequency of processes
                                                   >> 111   G4cout << "\n Process calls frequency --->";
                                                   >> 112   std::map<G4String,G4int>::iterator it;  
                                                   >> 113   for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
                                                   >> 114      G4String procName = it->first;
                                                   >> 115      G4int    count    = it->second;
                                                   >> 116      G4cout << "\t" << procName << " = " << count;
                                                   >> 117      if (procName == "Transportation") survive = count;
                                                   >> 118   }
                                                   >> 119       
                                                   >> 120   if (survive > 0) {
                                                   >> 121     G4cout << "\n\n Nb of incident particles surviving after "
                                                   >> 122            << G4BestUnit(fDetector->GetSize(),"Length") << " of "
                                                   >> 123            << material->GetName() << " : " << survive << G4endl;
                                                   >> 124   }
                                                   >> 125   
                                                   >> 126   if (fTotalCount == 0) fTotalCount = 1;   //force printing anyway
                                                   >> 127   
                                                   >> 128   //compute mean free path and related quantities
                                                   >> 129   //
                                                   >> 130   G4double MeanFreePath = fSumTrack /fTotalCount;     
                                                   >> 131   G4double MeanTrack2   = fSumTrack2/fTotalCount;     
                                                   >> 132   G4double rms = std::sqrt(std::fabs(MeanTrack2 - MeanFreePath*MeanFreePath));
                                                   >> 133   G4double CrossSection = 1./MeanFreePath;     
                                                   >> 134   G4double massicMFP = MeanFreePath*density;
                                                   >> 135   G4double massicCS  = 1./massicMFP;
                                                   >> 136    
                                                   >> 137   G4cout << "\n\n MeanFreePath:\t"   << G4BestUnit(MeanFreePath,"Length")
                                                   >> 138          << " +- "                   << G4BestUnit( rms,"Length")
                                                   >> 139          << "\tmassic: "             << G4BestUnit(massicMFP, "Mass/Surface")
                                                   >> 140          << "\n CrossSection:\t"     << CrossSection*cm << " cm^-1 "
                                                   >> 141          << "\t\t\tmassic: "         << G4BestUnit(massicCS, "Surface/Mass")
                                                   >> 142          << G4endl;
                                                   >> 143          
                                                   >> 144   //compute energy transfer coefficient
                                                   >> 145   //
                                                   >> 146   G4double MeanTransfer   = fEnTransfer/fTotalCount;
                                                   >> 147   G4double massTransfCoef = massicCS*MeanTransfer/energy;
                                                   >> 148    
                                                   >> 149   G4cout << "\n mean energy of charged secondaries: " 
                                                   >> 150          << G4BestUnit(MeanTransfer, "Energy")
                                                   >> 151          << "\tmass_energy_transfer coef: "          
                                                   >> 152    << G4BestUnit(massTransfCoef, "Surface/Mass")
                                                   >> 153          << G4endl;       
                                                   >> 154  
                                                   >> 155   //check cross section from G4EmCalculator
                                                   >> 156   //
                                                   >> 157   G4cout << "\n Verification : "
                                                   >> 158          << "crossSections from G4EmCalculator \n";
                                                   >> 159   
                                                   >> 160   G4EmCalculator emCalculator;
                                                   >> 161   G4double sumc = 0.0;  
                                                   >> 162   for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
                                                   >> 163     G4String procName = it->first;      
                                                   >> 164     G4double massSigma = 
                                                   >> 165     emCalculator.GetCrossSectionPerVolume(energy,particle,
                                                   >> 166                                               procName,material)/density;
                                                   >> 167     if (particle == G4Gamma::Gamma())
                                                   >> 168        massSigma = 
                                                   >> 169        emCalculator.ComputeCrossSectionPerVolume(energy,particle,
                                                   >> 170                                               procName,material)/density;
                                                   >> 171     sumc += massSigma;
                                                   >> 172     G4cout << "\t" << procName << "= " 
                                                   >> 173            << G4BestUnit(massSigma, "Surface/Mass");
                                                   >> 174   }             
                                                   >> 175   G4cout << "\ttotal= " 
                                                   >> 176          << G4BestUnit(sumc, "Surface/Mass") << G4endl;
                                                   >> 177                   
                                                   >> 178   //restore default format         
                                                   >> 179   G4cout.precision(prec);
                                                   >> 180            
                                                   >> 181   // remove all contents in fProcCounter 
                                                   >> 182   fProcCounter.clear();
                                                   >> 183     
                                                   >> 184   //save histograms      
                                                   >> 185   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();  
                                                   >> 186   if ( analysisManager->IsActive() ) {
101     analysisManager->Write();                     187     analysisManager->Write();
102     analysisManager->CloseFile();                 188     analysisManager->CloseFile();
103   }                                            << 189   }     
104                                                   190 
105   // show Rndm status                             191   // show Rndm status
106   if (isMaster) G4Random::showEngineStatus();  << 192   CLHEP::HepRandom::showEngineStatus();
107 }                                                 193 }
108                                                   194 
109 //....oooOO0OOooo........oooOO0OOooo........oo    195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110                                                   196