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


  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/TestEm12/src/RunActi <<  26 // $Id: RunAction.cc,v 1.7 2007/04/27 10:38:11 maire Exp $
 27 /// \brief Implementation of the RunAction cla <<  27 // GEANT4 tag $Name: geant4-09-00 $
 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 "PhysicsList.hh"                          34 #include "PhysicsList.hh"
 38 #include "PrimaryGeneratorAction.hh"           << 
 39 #include "Run.hh"                              << 
 40 #include "StepMax.hh"                              35 #include "StepMax.hh"
                                                   >>  36 #include "PrimaryGeneratorAction.hh"
                                                   >>  37 #include "HistoManager.hh"
 41                                                    38 
                                                   >>  39 #include "G4Run.hh"
                                                   >>  40 #include "G4RunManager.hh"
                                                   >>  41 #include "G4UnitsTable.hh"
 42 #include "G4EmCalculator.hh"                       42 #include "G4EmCalculator.hh"
 43 #include "G4EmParameters.hh"                   <<  43 
 44 #include "Randomize.hh"                            44 #include "Randomize.hh"
                                                   >>  45 #include <iomanip>
 45                                                    46 
 46 //....oooOO0OOooo........oooOO0OOooo........oo     47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 47                                                    48 
 48 RunAction::RunAction(DetectorConstruction* det <<  49 RunAction::RunAction(DetectorConstruction* det, PhysicsList* phys,
 49   : fDetector(det), fPhysics(phys), fPrimary(k <<  50                      PrimaryGeneratorAction* kin, HistoManager* histo)
 50 {                                              <<  51 :detector(det),physics(phys),kinematic(kin),histoManager(histo)
 51   // Book predefined histograms                <<  52 { }
 52   fHistoManager = new HistoManager();          << 
 53 }                                              << 
 54                                                    53 
 55 //....oooOO0OOooo........oooOO0OOooo........oo     54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 56                                                    55 
 57 RunAction::~RunAction()                            56 RunAction::~RunAction()
 58 {                                              <<  57 { }
 59   delete fHistoManager;                        << 
 60 }                                              << 
 61                                                    58 
 62 //....oooOO0OOooo........oooOO0OOooo........oo     59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 63                                                    60 
 64 G4Run* RunAction::GenerateRun()                <<  61 void RunAction::BeginOfRunAction(const G4Run* aRun)
 65 {                                              <<  62 {  
 66   fRun = new Run(fDetector);                   <<  63   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
 67   return fRun;                                 <<  64   
                                                   >>  65   // save Rndm status
                                                   >>  66   G4RunManager::GetRunManager()->SetRandomNumberStore(true);
                                                   >>  67   CLHEP::HepRandom::showEngineStatus();
                                                   >>  68   
                                                   >>  69   //initialize total energy deposit
                                                   >>  70   //
                                                   >>  71   Edeposit = Edeposit2 = 0.; 
                                                   >>  72    
                                                   >>  73   //initialize track legth of primary
                                                   >>  74   //
                                                   >>  75   trackLen = trackLen2 = 0.;
                                                   >>  76     
                                                   >>  77   //initialize projected range
                                                   >>  78   //
                                                   >>  79   projRange = projRange2 = 0.;
                                                   >>  80     
                                                   >>  81   //initialize mean step size
                                                   >>  82   //
                                                   >>  83   nbOfSteps = nbOfSteps2 = 0;  stepSize = stepSize2 = 0.;
                                                   >>  84   
                                                   >>  85   //get csdaRange from EmCalculator
                                                   >>  86   //
                                                   >>  87   G4EmCalculator emCalculator;
                                                   >>  88   G4Material* material = detector->GetAbsorMaterial();
                                                   >>  89   G4ParticleDefinition* particle = kinematic->GetParticleGun()
                                                   >>  90                                           ->GetParticleDefinition();
                                                   >>  91   G4double energy = kinematic->GetParticleGun()->GetParticleEnergy();
                                                   >>  92   csdaRange = 0.;
                                                   >>  93   if (particle->GetPDGCharge() != 0.)
                                                   >>  94     csdaRange = emCalculator.GetCSDARange(energy,particle,material);
                                                   >>  95             
                                                   >>  96   //histograms
                                                   >>  97   //
                                                   >>  98   histoManager->book(csdaRange);
                                                   >>  99   
                                                   >> 100   //set StepMax from histos
                                                   >> 101   //
                                                   >> 102   G4double stepMax = histoManager->GetStepMax();
                                                   >> 103   physics->GetStepMaxProcess()->SetMaxStep(stepMax);
 68 }                                                 104 }
 69                                                   105 
 70 //....oooOO0OOooo........oooOO0OOooo........oo    106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 71                                                   107 
 72 void RunAction::BeginOfRunAction(const G4Run*) << 108 void RunAction::EndOfRunAction(const G4Run* aRun)
 73 {                                                 109 {
 74   // show Rndm status                          << 110   std::ios::fmtflags mode = G4cout.flags();
 75   if (isMaster) {                              << 111   G4cout.setf(std::ios::fixed,std::ios::floatfield);
 76     G4Random::showEngineStatus();              << 112   
 77     G4EmParameters::Instance()->Dump();        << 113   G4int NbofEvents = aRun->GetNumberOfEvent();
 78   }                                            << 114   if (NbofEvents == 0) return;
 79   // histograms                                << 115   G4double fNbofEvents = double(NbofEvents);
 80   //                                           << 116 
 81   G4AnalysisManager* analysisManager = G4Analy << 117   //run conditions
 82   if (analysisManager->IsActive()) {           << 118   //  
 83     analysisManager->OpenFile();               << 119   G4Material* material = detector->GetAbsorMaterial();
 84   }                                            << 120   G4double density = material->GetDensity();
 85                                                << 121    
 86   if (!fPrimary) return;                       << 122   G4ParticleDefinition* particle = kinematic->GetParticleGun()
 87                                                << 123                                           ->GetParticleDefinition();
 88   // keep run condition                        << 124   G4String partName = particle->GetParticleName();                 
 89   G4ParticleDefinition* particle = fPrimary->G << 125   G4double energy = kinematic->GetParticleGun()->GetParticleEnergy();
 90   G4double energy = fPrimary->GetParticleGun() << 126   
 91   fRun->SetPrimary(particle, energy);          << 127   G4cout << "\n ======================== run summary ======================\n";
 92                                                << 128   
 93   // get CsdaRange from EmCalculator           << 129   G4int prec = G4cout.precision(2);
                                                   >> 130   
                                                   >> 131   G4cout << "\n The run consists of " << NbofEvents << " "<< partName << " of "
                                                   >> 132          << G4BestUnit(energy,"Energy") << " through " 
                                                   >> 133    << G4BestUnit(detector->GetAbsorRadius(),"Length") << " of "
                                                   >> 134    << material->GetName() << " (density: " 
                                                   >> 135    << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
                                                   >> 136    
                                                   >> 137   G4cout << "\n ============================================================\n";
                                                   >> 138   
                                                   >> 139   //compute total energy deposit
 94   //                                              140   //
 95   G4EmCalculator emCalculator;                 << 141   Edeposit /= NbofEvents; Edeposit2 /= NbofEvents;
 96   G4Material* material = fDetector->GetAbsorMa << 142   G4double rms = Edeposit2 - Edeposit*Edeposit;        
 97                                                << 143   if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
 98   G4double csdaRange = DBL_MAX;                << 144 
 99   if (particle->GetPDGCharge() != 0.) {        << 145   G4cout.precision(3);       
100     csdaRange = emCalculator.GetCSDARange(ener << 146   G4cout 
101     fRun->SetCsdaRange(csdaRange);             << 147     << "\n Total Energy deposited        = " << G4BestUnit(Edeposit,"Energy")
102   }                                            << 148     << " +- "                               << G4BestUnit( rms,"Energy")
103                                                << 149     << G4endl;
104   // set StepMax from histos 1 and 8           << 150        
                                                   >> 151   //compute track length of primary track
                                                   >> 152   //
                                                   >> 153   trackLen /= NbofEvents; trackLen2 /= NbofEvents;
                                                   >> 154   rms = trackLen2 - trackLen*trackLen;        
                                                   >> 155   if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
                                                   >> 156 
                                                   >> 157   G4cout.precision(3);       
                                                   >> 158   G4cout 
                                                   >> 159     << "\n Track length of primary track = " << G4BestUnit(trackLen,"Length")
                                                   >> 160     << " +- "                               << G4BestUnit( rms,"Length");
                                                   >> 161     
                                                   >> 162   //compare with csda range
                                                   >> 163   //
                                                   >> 164   //G4EmCalculator emCalculator;
                                                   >> 165   //G4double csdaRange = 0.;
                                                   >> 166   //if (particle->GetPDGCharge() != 0.)
                                                   >> 167   //  csdaRange = emCalculator.GetCSDARange(energy,particle,material);
                                                   >> 168   G4cout 
                                                   >> 169     << "\n Range from EmCalculator       = " << G4BestUnit(csdaRange,"Length")
                                                   >> 170     << " (from full dE/dx)" << G4endl;
                                                   >> 171        
                                                   >> 172   //compute projected range of primary track
                                                   >> 173   //
                                                   >> 174   projRange /= NbofEvents; projRange2 /= NbofEvents;
                                                   >> 175   rms = projRange2 - projRange*projRange;        
                                                   >> 176   if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
                                                   >> 177    
                                                   >> 178   G4cout 
                                                   >> 179     << "\n Projected range               = " << G4BestUnit(projRange,"Length")
                                                   >> 180     << " +- "                                << G4BestUnit( rms,"Length")    
                                                   >> 181     << G4endl;
                                                   >> 182     
                                                   >> 183   //nb of steps and step size of primary track
                                                   >> 184   //
                                                   >> 185   G4double fNbSteps = nbOfSteps/fNbofEvents, fNbSteps2 = nbOfSteps2/fNbofEvents;
                                                   >> 186   rms = fNbSteps2 - fNbSteps*fNbSteps;       
                                                   >> 187   if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
                                                   >> 188 
                                                   >> 189   G4cout.precision(2);       
                                                   >> 190   G4cout << "\n Nb of steps of primary track  = " << fNbSteps << " +- " << rms;
                                                   >> 191     
                                                   >> 192   stepSize /= NbofEvents; stepSize2 /= NbofEvents;
                                                   >> 193   rms = stepSize2 - stepSize*stepSize;        
                                                   >> 194   if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
                                                   >> 195 
                                                   >> 196   G4cout.precision(3);       
                                                   >> 197   G4cout 
                                                   >> 198     << "\t Step size= " << G4BestUnit(stepSize,"Length")
                                                   >> 199     << " +- "           << G4BestUnit( rms,"Length")
                                                   >> 200     << G4endl;
                                                   >> 201      
                                                   >> 202   // normalize histogram of longitudinal energy profile
105   //                                              203   //
106   G4double stepMax = csdaRange;                << 
107   G4int ih = 1;                                   204   G4int ih = 1;
108   if (analysisManager->GetH1Activation(ih))    << 205   G4double binWidth = histoManager->GetBinWidth(ih);
109     stepMax = analysisManager->GetH1Width(ih)  << 206   G4double fac = (1./(NbofEvents*binWidth))*(mm/MeV);
                                                   >> 207   histoManager->Scale(ih,fac);
                                                   >> 208   
                                                   >> 209   // normalize histogram d(E/E0)/d(r/r0)
                                                   >> 210   //
110   ih = 8;                                         211   ih = 8;
111   if (analysisManager->GetH1Activation(ih)) {  << 212   binWidth = histoManager->GetBinWidth(ih);
112     G4double width = analysisManager->GetH1Wid << 213   fac = 1./(NbofEvents*binWidth*energy);
113     stepMax = std::min(stepMax, width * csdaRa << 214   histoManager->Scale(ih,fac);
114   }                                            << 215     
115   fPhysics->GetStepMaxProcess()->SetMaxStep2(s << 216    // reset default formats
116                                                << 217   G4cout.setf(mode,std::ios::floatfield);
117   /// G4cout << "\n---> stepMax from histos 1  << 218   G4cout.precision(prec);
118   ///        << G4BestUnit(stepMax,"Length") < << 219   
119 }                                              << 
120                                                << 
121 //....oooOO0OOooo........oooOO0OOooo........oo << 
122                                                << 
123 void RunAction::EndOfRunAction(const G4Run*)   << 
124 {                                              << 
125   if (isMaster) fRun->EndOfRun();              << 
126                                                << 
127   // save histograms                              220   // save histograms
128   G4AnalysisManager* analysisManager = G4Analy << 221   histoManager->save();
129   if (analysisManager->IsActive()) {           << 222  
130     analysisManager->Write();                  << 
131     analysisManager->CloseFile();              << 
132   }                                            << 
133                                                << 
134   // show Rndm status                             223   // show Rndm status
135   if (isMaster) G4Random::showEngineStatus();  << 224   CLHEP::HepRandom::showEngineStatus();
136 }                                                 225 }
137                                                   226 
138 //....oooOO0OOooo........oooOO0OOooo........oo    227 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
139                                                   228