source: trunk/examples/extended/electromagnetic/TestEm0/src/RunAction.cc @ 1279

Last change on this file since 1279 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

File size: 12.9 KB
Line 
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// $Id: RunAction.cc,v 1.10 2007/12/17 17:22:44 maire Exp $
27// GEANT4 tag $Name: geant4-09-03-cand-01 $
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
36#include "G4Run.hh"
37#include "G4ProcessManager.hh"
38#include "G4UnitsTable.hh"
39#include "G4EmCalculator.hh"
40#include "G4Electron.hh"
41
42#include <vector>
43
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45
46RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin)
47:detector(det), primary(kin)
48{ }
49
50//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51
52RunAction::~RunAction()
53{ }
54
55//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56
57void RunAction::BeginOfRunAction(const G4Run*)
58{
59  //set precision for printing
60  G4int prec = G4cout.precision(6);
61 
62  //instanciate EmCalculator
63  G4EmCalculator emCal;
64  //  emCal.SetVerbose(2);
65     
66  // get particle
67  G4ParticleDefinition* particle = primary->GetParticleGun()
68                                          ->GetParticleDefinition();
69  G4String partName = particle->GetParticleName();
70  G4double charge   = particle->GetPDGCharge();   
71  G4double energy   = primary->GetParticleGun()->GetParticleEnergy();
72 
73  // get material
74  G4Material* material = detector->GetMaterial();
75  G4String matName     = material->GetName();
76  G4double density     = material->GetDensity();
77  G4double radl        = material->GetRadlen(); 
78
79  G4cout << "\n " << partName << " ("
80         << G4BestUnit(energy,"Energy") << ") in " 
81         << material->GetName() << " (density: " 
82         << G4BestUnit(density,"Volumic Mass") << ";   radiation length: "
83         << G4BestUnit(radl,   "Length")       << ")" << G4endl;
84
85  // get cuts   
86  GetCuts();
87  if (charge != 0.) {
88   G4cout << "\n  Range cuts : \t gamma " 
89                      << std::setw(8) << G4BestUnit(rangeCut[0],"Length")
90          << "\t e- " << std::setw(8) << G4BestUnit(rangeCut[1],"Length");
91   G4cout << "\n Energy cuts : \t gamma " 
92                      << std::setw(8) << G4BestUnit(energyCut[0],"Energy")
93          << "\t e- " << std::setw(8) << G4BestUnit(energyCut[1],"Energy")
94          << G4endl;
95   }
96   
97  // max energy transfert
98  if (charge != 0.) {
99  G4double Mass_c2 = particle->GetPDGMass();
100  G4double moverM = electron_mass_c2/Mass_c2;
101  G4double gamM1 = energy/Mass_c2, gam = gamM1 + 1., gamP1 = gam + 1.;
102  G4double Tmax = 
103            (2*electron_mass_c2*gamM1*gamP1)/(1.+2*gam*moverM+moverM*moverM);
104  G4double range = emCal.GetCSDARange(Tmax,G4Electron::Electron(),material);
105 
106  G4cout << "\n Max_energy _transferable : " << G4BestUnit(Tmax,"Energy")
107         << " (" << G4BestUnit(range,"Length") << ")" << G4endl;           
108  }
109         
110  // get processList and extract EM processes (but not MultipleScattering)
111  G4ProcessVector* plist = particle->GetProcessManager()->GetProcessList();
112  G4String procName;
113  G4double cut;
114  std::vector<G4String> emName;
115  std::vector<G4double> enerCut;
116  size_t length = plist->size();
117  for (size_t j=0; j<length; j++) {
118     procName = (*plist)[j]->GetProcessName();
119     cut = energyCut[1];
120     if ((procName == "eBrem")||(procName == "muBrems")) cut = energyCut[0];
121     if (((*plist)[j]->GetProcessType() == fElectromagnetic) &&
122         (procName != "msc")) {
123       emName.push_back(procName);
124       enerCut.push_back(cut);
125     } 
126  }
127 
128  // print list of processes
129  G4cout << "\n  processes :                ";
130  for (size_t j=0; j<emName.size();j++)
131    G4cout << "\t" << std::setw(13) << emName[j] << "\t";
132  G4cout << "\t" << std::setw(13) <<"total";
133 
134  //compute cross section per atom (only for single material)
135  if (material->GetNumberOfElements() == 1) {
136    G4double Z = material->GetZ();
137    G4double A = material->GetA();
138     
139    std::vector<G4double> sigma0;
140    G4double sig, sigtot = 0.;
141
142    for (size_t j=0; j<emName.size();j++) {
143      sig = emCal.ComputeCrossSectionPerAtom
144                      (energy,particle,emName[j],Z,A,enerCut[j]);
145      sigtot += sig;                         
146      sigma0.push_back(sig);           
147    }
148    sigma0.push_back(sigtot);
149
150    G4cout << "\n \n  cross section per atom   : ";
151    for (size_t j=0; j<sigma0.size();j++) {         
152      G4cout << "\t" << std::setw(13) << G4BestUnit(sigma0[j], "Surface");
153    }
154    G4cout << G4endl;
155  }
156   
157  //get cross section per volume
158  std::vector<G4double> sigma1;
159  std::vector<G4double> sigma2; 
160  G4double Sig, Sigtot = 0.;
161
162  for (size_t j=0; j<emName.size();j++) {
163    Sig = emCal.GetCrossSectionPerVolume(energy,particle,emName[j],material);
164    if (Sig == 0.) Sig = emCal.ComputeCrossSectionPerVolume
165                     (energy,particle,emName[j],material,enerCut[j]);
166    Sigtot += Sig;                           
167    sigma1.push_back(Sig);
168    sigma2.push_back(Sig/density);                     
169  }
170  sigma1.push_back(Sigtot);
171  sigma2.push_back(Sigtot/density);       
172   
173  //print cross sections
174  G4cout << "\n \n  cross section per volume : ";
175  for (size_t j=0; j<sigma1.size();j++) {           
176    G4cout << "\t" << std::setw(13) << sigma1[j]*cm << " cm^-1";
177  }
178 
179  G4cout << "\n  cross section per mass   : ";
180  for (size_t j=0; j<sigma2.size();j++) {
181    G4cout << "\t" << std::setw(13) << G4BestUnit(sigma2[j], "Surface/Mass");
182  }
183   
184  //print mean free path
185 
186  G4double lambda;
187 
188  G4cout << "\n \n  mean free path           : ";
189  for (size_t j=0; j<sigma1.size();j++) {
190    lambda = DBL_MAX; 
191    if (sigma1[j] > 0.) lambda = 1/sigma1[j];
192    G4cout << "\t" << std::setw(13) << G4BestUnit( lambda, "Length");
193  }
194 
195  //mean free path (g/cm2)
196  G4cout << "\n        (g/cm2)            : "; 
197  for (size_t j=0; j<sigma2.size();j++) {
198    lambda =  DBL_MAX;
199    if (sigma2[j] > 0.) lambda = 1/sigma2[j];                       
200    G4cout << "\t" << std::setw(13) << G4BestUnit( lambda, "Mass/Surface");   
201  }
202  G4cout << G4endl;
203 
204  if (charge == 0.) {
205    G4cout.precision(prec);
206    G4cout << "\n-------------------------------------------------------------\n"
207           << G4endl;
208    return;
209  }
210 
211  //get stopping power
212  std::vector<G4double> dedx1;
213  std::vector<G4double> dedx2; 
214  G4double dedx, dedxtot = 0.;
215
216  for (size_t j=0; j<emName.size();j++) {
217    dedx = emCal.ComputeDEDX(energy,particle,emName[j],material,enerCut[j]);
218    dedx1.push_back(dedx);
219    dedx2.push_back(dedx/density);                     
220  }
221  dedxtot = emCal.GetDEDX(energy,particle,material);
222  dedx1.push_back(dedxtot);
223  dedx2.push_back(dedxtot/density);       
224   
225  //print stopping power
226  G4cout << "\n \n  restricted dE/dx         : ";
227  for (size_t j=0; j<sigma1.size();j++) {           
228    G4cout << "\t" << std::setw(13) << G4BestUnit(dedx1[j],"Energy/Length");
229  }
230 
231  G4cout << "\n      (MeV/g/cm2)          : ";
232  for (size_t j=0; j<sigma2.size();j++) {
233  G4cout << "\t" << std::setw(13) << G4BestUnit(dedx2[j],"Energy*Surface/Mass");
234  }
235 
236  //get range from restricted dedx
237  G4double range1 = emCal.GetRangeFromRestricteDEDX(energy,particle,material);
238  G4double range2 = range1*density;
239 
240   //get range from full dedx
241  G4double Range1 = emCal.GetCSDARange(energy,particle,material);
242  G4double Range2 = Range1*density;
243 
244  //print range
245  G4cout << "\n \n  range from restrict dE/dx: " 
246         << "\t" << std::setw(8) << G4BestUnit(range1,"Length")
247         << " (" << std::setw(8) << G4BestUnit(range2,"Mass/Surface") << ")";
248         
249  G4cout << "\n  range from full dE/dx    : " 
250         << "\t" << std::setw(8) << G4BestUnit(Range1,"Length")
251         << " (" << std::setw(8) << G4BestUnit(Range2,"Mass/Surface") << ")";
252         
253  //get transport mean free path (for multiple scattering)
254  G4double MSmfp1 = emCal.GetMeanFreePath(energy,particle,"msc",material);
255  G4double MSmfp2 = MSmfp1*density;
256 
257  //print transport mean free path
258  G4cout << "\n \n  transport mean free path : " 
259         << "\t" << std::setw(8) << G4BestUnit(MSmfp1,"Length")
260         << " (" << std::setw(8) << G4BestUnit(MSmfp2,"Mass/Surface") << ")";
261
262  if (particle == G4Electron::Electron()) CriticalEnergy();
263         
264  G4cout << "\n-------------------------------------------------------------\n";
265  G4cout << G4endl;
266       
267 // reset default precision
268 G4cout.precision(prec);   
269}
270
271//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
272
273void RunAction::EndOfRunAction(const G4Run* )
274{ }
275
276//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
277
278#include "G4ProductionCutsTable.hh"
279
280//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
281
282void RunAction::GetCuts()
283{ 
284  G4ProductionCutsTable* theCoupleTable =
285        G4ProductionCutsTable::GetProductionCutsTable();
286       
287  size_t numOfCouples = theCoupleTable->GetTableSize();
288  const G4MaterialCutsCouple* couple = 0;
289  G4int index = 0;
290  for (size_t i=0; i<numOfCouples; i++) {
291     couple = theCoupleTable->GetMaterialCutsCouple(i);
292     if (couple->GetMaterial() == detector->GetMaterial()) {index = i; break;}
293  }
294 
295  rangeCut[0] =
296         (*(theCoupleTable->GetRangeCutsVector(idxG4GammaCut)))[index];
297  rangeCut[1] =     
298         (*(theCoupleTable->GetRangeCutsVector(idxG4ElectronCut)))[index];
299  rangeCut[2] =     
300         (*(theCoupleTable->GetRangeCutsVector(idxG4PositronCut)))[index]; 
301
302  energyCut[0] =
303         (*(theCoupleTable->GetEnergyCutsVector(idxG4GammaCut)))[index];
304  energyCut[1] =     
305         (*(theCoupleTable->GetEnergyCutsVector(idxG4ElectronCut)))[index];
306  energyCut[2] =     
307         (*(theCoupleTable->GetEnergyCutsVector(idxG4PositronCut)))[index];
308
309}
310
311//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
312
313void RunAction::CriticalEnergy()
314{
315  // compute e- critical energy (Rossi definition) and Moliere radius.
316  // Review of Particle Physics - Eur. Phys. J. C3 (1998) page 147
317  //
318  G4EmCalculator emCal;
319   
320  const G4Material* material = detector->GetMaterial();
321  const G4double radl = material->GetRadlen();
322  G4double ekin = 5*MeV;
323  G4double deioni;
324  G4double err  = 1., errmax = 0.001;
325  G4int    iter = 0 , itermax = 10; 
326  while (err > errmax && iter < itermax) {
327    iter++;         
328    deioni  = radl*
329              emCal.ComputeDEDX(ekin,G4Electron::Electron(),"eIoni",material);
330    err = std::abs(deioni - ekin)/ekin;
331    ekin = deioni;
332  }
333  G4cout << "\n \n  critical energy (Rossi)  : " 
334         << "\t" << std::setw(8) << G4BestUnit(ekin,"Energy");
335         
336  //Pdg formula (only for single material)
337  G4double pdga[2] = { 610*MeV, 710*MeV };
338  G4double pdgb[2] = { 1.24, 0.92 };
339  G4double EcPdg = 0.;
340 
341  if (material->GetNumberOfElements() == 1) {
342    G4int istat = 0;
343    if (material->GetState() == kStateGas) istat = 1; 
344    G4double Zeff = material->GetZ() + pdgb[istat];
345    EcPdg = pdga[istat]/Zeff;
346    G4cout << "\t\t\t (from Pdg formula : " 
347           << std::setw(8) << G4BestUnit(EcPdg,"Energy") << ")";   
348  }
349     
350 const G4double Es = 21.2052*MeV;
351 G4double rMolier1 = Es/ekin, rMolier2 = rMolier1*radl;
352 G4cout << "\n  Moliere radius           : "
353        << "\t" << std::setw(8) << rMolier1 << " X0 "   
354        << "= " << std::setw(8) << G4BestUnit(rMolier2,"Length");
355       
356 if (material->GetNumberOfElements() == 1) {
357    G4double rMPdg = radl*Es/EcPdg;
358    G4cout << "\t (from Pdg formula : " 
359           << std::setw(8) << G4BestUnit(rMPdg,"Length") << ")";   
360  }     
361}
362
363//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.