Geant4  10.01.p03
G4VEmModel.cc
Go to the documentation of this file.
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: G4VEmModel.cc 88981 2015-03-17 10:14:15Z gcosmo $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 Class file
31 //
32 //
33 // File name: G4VEmModel
34 //
35 // Author: Vladimir Ivanchenko
36 //
37 // Creation date: 25.07.2005
38 //
39 // Modifications:
40 // 25.10.2005 Set default highLimit=100.TeV (V.Ivanchenko)
41 // 06.02.2006 add method ComputeMeanFreePath() (mma)
42 // 16.02.2009 Move implementations of virtual methods to source (VI)
43 //
44 //
45 // Class Description:
46 //
47 // Abstract interface to energy loss models
48 
49 // -------------------------------------------------------------------
50 //
51 
52 #include "G4VEmModel.hh"
53 #include "G4ElementData.hh"
54 #include "G4LossTableManager.hh"
55 #include "G4ProductionCutsTable.hh"
58 #include "G4SystemOfUnits.hh"
59 #include "G4Log.hh"
60 #include "Randomize.hh"
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66 const G4double log106 = 6*G4Log(10.);
67 
69  flucModel(0),anglModel(0), name(nam), lowLimit(0.1*CLHEP::keV),
70  highLimit(100.0*CLHEP::TeV),eMinActive(0.0),eMaxActive(DBL_MAX),
71  polarAngleLimit(CLHEP::pi),secondaryThreshold(DBL_MAX),
72  theLPMflag(false),flagDeexcitation(false),flagForceBuildTable(false),
73  isMaster(true),fElementData(0),pParticleChange(0),xSectionTable(0),
74  theDensityFactor(0),theDensityIdx(0),fCurrentCouple(0),fCurrentElement(0),
75  fCurrentIsotope(0),nsec(5)
76 {
77  xsec.resize(nsec);
78  nSelectors = 0;
79  elmSelectors = 0;
80  localElmSelectors = true;
81  localTable = true;
82  useAngularGenerator = false;
83  idxTable = 0;
84 
86  fManager->Register(this);
87 
88  rndmEngineMod = G4Random::getTheEngine();
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
94 {
95  if(localElmSelectors) {
96  if(nSelectors > 0) {
97  for(G4int i=0; i<nSelectors; ++i) {
98  delete (*elmSelectors)[i];
99  }
100  }
101  delete elmSelectors;
102  }
103  delete anglModel;
104 
105  if(localTable && xSectionTable) {
107  delete xSectionTable;
108  xSectionTable = 0;
109  }
110  if(isMaster && fElementData) {
111  delete fElementData;
112  fElementData = 0;
113  }
114 
115  fManager->DeRegister(this);
116 }
117 
118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 
121 {
123  if (pParticleChange) {
124  p = static_cast<G4ParticleChangeForLoss*>(pParticleChange);
125  } else {
126  p = new G4ParticleChangeForLoss();
127  pParticleChange = p;
128  }
129  return p;
130 }
131 
132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133 
135 {
137  if (pParticleChange) {
138  p = static_cast<G4ParticleChangeForGamma*>(pParticleChange);
139  } else {
140  p = new G4ParticleChangeForGamma();
141  pParticleChange = p;
142  }
143  return p;
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147 
149  const G4DataVector& cuts)
150 {
151  // using spline for element selectors should be investigated in details
152  // because small number of points may provide biased results
153  // large number of points requires significant increase of memory
154  //G4bool spline = fManager->SplineFlag();
155  G4bool spline = false;
156 
157  //G4cout << "IES: for " << GetName() << " Emin(MeV)= " << lowLimit/MeV
158  // << " Emax(MeV)= " << highLimit/MeV << G4endl;
159 
160  // two times less bins because probability functon is normalized
161  // so correspondingly is more smooth
162  if(highLimit <= lowLimit) { return; }
163 
164  G4ProductionCutsTable* theCoupleTable=
166  G4int numOfCouples = theCoupleTable->GetTableSize();
167 
168  // prepare vector
169  if(!elmSelectors) {
170  elmSelectors = new std::vector<G4EmElementSelector*>;
171  }
172  if(numOfCouples > nSelectors) {
173  for(G4int i=nSelectors; i<numOfCouples; ++i) {
174  elmSelectors->push_back(0);
175  }
176  nSelectors = numOfCouples;
177  }
178 
179  // initialise vector
180  for(G4int i=0; i<numOfCouples; ++i) {
181 
182  // no need in element selectors for infionite cuts
183  if(cuts[i] == DBL_MAX) { continue; }
184 
185  fCurrentCouple = theCoupleTable->GetMaterialCutsCouple(i);
186  const G4Material* material = fCurrentCouple->GetMaterial();
187 
188  // selector already exist check if should be deleted
189  G4bool create = true;
190  if((*elmSelectors)[i]) {
191  if(material == ((*elmSelectors)[i])->GetMaterial()) { create = false; }
192  else { delete (*elmSelectors)[i]; }
193  }
194  if(create) {
195  G4double emin = std::max(lowLimit,
196  MinPrimaryEnergy(material, part, cuts[i]));
197  G4double emax = std::max(highLimit, 10*emin);
199  *G4Log(emax/emin)/log106);
200  nbins = std::max(nbins, 3);
201 
202  (*elmSelectors)[i] = new G4EmElementSelector(this,material,nbins,
203  emin,emax,spline);
204  }
205  ((*elmSelectors)[i])->Initialise(part, cuts[i]);
206  /*
207  G4cout << "G4VEmModel::InitialiseElmSelectors i= " << i
208  << " idx= " << fCurrentCouple->GetIndex()
209  << " " << part->GetParticleName()
210  << " for " << GetName() << " cut= " << cuts[i]
211  << " " << (*elmSelectors)[i] << G4endl;
212  ((*elmSelectors)[i])->Dump(part);
213  */
214  }
215 }
216 
217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218 
220  G4VEmModel*)
221 {}
222 
223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
224 
226  const G4Material* material)
227 {
228  if(material) {
229  const G4ElementVector* theElementVector = material->GetElementVector();
230  G4int n = material->GetNumberOfElements();
231  for(G4int i=0; i<n; ++i) {
232  G4int Z = G4lrint(((*theElementVector)[i])->GetZ());
233  InitialiseForElement(part, Z);
234  }
235  } else {
236  //G4cout << "G4VEmModel::InitialiseForMaterial for " << GetName();
237  //if(part) { G4cout << " and " << part->GetParticleName(); }
238  //G4cout << " with no material" << G4endl;
239  }
240 }
241 
242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
243 
245 {}
246 
247 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
248 
250  const G4ParticleDefinition*,
252 {
253  return 0.0;
254 }
255 
256 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
257 
259  const G4ParticleDefinition* p,
260  G4double ekin,
261  G4double emin,
262  G4double emax)
263 {
264  SetupForMaterial(p, material, ekin);
265  G4double cross = 0.0;
266  const G4ElementVector* theElementVector = material->GetElementVector();
267  const G4double* theAtomNumDensityVector =
268  material->GetVecNbOfAtomsPerVolume();
269  G4int nelm = material->GetNumberOfElements();
270  if(nelm > nsec) {
271  xsec.resize(nelm);
272  nsec = nelm;
273  }
274  for (G4int i=0; i<nelm; ++i) {
275  cross += theAtomNumDensityVector[i]*
276  ComputeCrossSectionPerAtom(p,(*theElementVector)[i],ekin,emin,emax);
277  xsec[i] = cross;
278  }
279  return cross;
280 }
281 
282 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
283 
285 {
286  rndmEngineMod = G4Random::getTheEngine();
287 }
288 
289 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
290 
292  const G4ParticleDefinition* pd,
293  G4double kinEnergy,
294  G4double tcut,
295  G4double tmax)
296 {
297  const G4ElementVector* theElementVector = material->GetElementVector();
298  G4int n = material->GetNumberOfElements() - 1;
299  fCurrentElement = (*theElementVector)[n];
300  if (n > 0) {
301  G4double x = rndmEngineMod->flat()*
302  G4VEmModel::CrossSectionPerVolume(material,pd,kinEnergy,tcut,tmax);
303  for(G4int i=0; i<n; ++i) {
304  if (x <= xsec[i]) {
305  fCurrentElement = (*theElementVector)[i];
306  break;
307  }
308  }
309  }
310  return fCurrentElement;
311 }
312 
313 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
314 
318 {
319  return 0.0;
320 }
321 
322 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
323 
325 {}
326 
327 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
328 
330 {
332  track.GetMaterial(), track.GetKineticEnergy());
333 }
334 
335 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
336 
338  const G4Material*, G4double)
339 {
340  G4double q = p->GetPDGCharge()*inveplus;
341  return q*q;
342 }
343 
344 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
345 
347  const G4Material*, G4double)
348 {
349  return p->GetPDGCharge();
350 }
351 
352 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
353 
355  const G4DynamicParticle*,
357 {}
358 
359 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
360 
362  const G4ParticleDefinition* p, G4double e)
363 {
364  SetCurrentCouple(couple);
365  return e*e*CrossSectionPerVolume(couple->GetMaterial(),p,e,0.0,DBL_MAX);
366 }
367 
368 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
369 
371  const G4ParticleDefinition*,
372  G4double)
373 {
374  return 0.0;
375 }
376 
377 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
378 
380  const G4MaterialCutsCouple*)
381 {
382  return 0.0;
383 }
384 
385 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
386 
388  G4double kineticEnergy)
389 {
390  return kineticEnergy;
391 }
392 
393 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
394 
396  const G4Material*, G4double)
397 {}
398 
399 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
400 
401 void
403 {
404  if(p && pParticleChange != p) { pParticleChange = p; }
405  flucModel = f;
406 }
407 
408 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
409 
411 {
412  if(p != xSectionTable) {
413  if(xSectionTable && localTable) {
415  delete xSectionTable;
416  }
417  xSectionTable = p;
418  }
419  localTable = isLocal;
420 }
421 
422 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool localTable
Definition: G4VEmModel.hh:392
size_t idxTable
Definition: G4VEmModel.hh:407
virtual G4double CrossSectionPerVolume(const G4Material *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy=0.0, G4double maxEnergy=DBL_MAX)
Definition: G4VEmModel.cc:258
virtual void InitialiseForElement(const G4ParticleDefinition *, G4int Z)
Definition: G4VEmModel.cc:244
virtual void StartTracking(G4Track *)
Definition: G4VEmModel.cc:284
static G4LossTableManager * Instance()
G4ParticleChangeForLoss * GetParticleChangeForLoss()
Definition: G4VEmModel.cc:120
std::vector< G4Element * > G4ElementVector
virtual void CorrectionsAlongStep(const G4MaterialCutsCouple *, const G4DynamicParticle *, G4double &eloss, G4double &niel, G4double length)
Definition: G4VEmModel.cc:354
void InitialiseElementSelectors(const G4ParticleDefinition *, const G4DataVector &)
Definition: G4VEmModel.cc:148
void DeRegister(G4VEnergyLossProcess *p)
virtual void DefineForRegion(const G4Region *)
Definition: G4VEmModel.cc:324
G4String name
Definition: TRTMaterials.hh:40
G4bool isMaster
Definition: G4VEmModel.hh:390
virtual G4double MinPrimaryEnergy(const G4Material *, const G4ParticleDefinition *, G4double cut=0.0)
Definition: G4VEmModel.cc:370
const G4double pi
virtual void InitialiseLocal(const G4ParticleDefinition *, G4VEmModel *masterModel)
Definition: G4VEmModel.cc:219
virtual void SetupForMaterial(const G4ParticleDefinition *, const G4Material *, G4double kineticEnergy)
Definition: G4VEmModel.cc:395
virtual G4double MinEnergyCut(const G4ParticleDefinition *, const G4MaterialCutsCouple *)
Definition: G4VEmModel.cc:379
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:190
int G4int
Definition: G4Types.hh:78
const G4Element * fCurrentElement
Definition: G4VEmModel.hh:416
G4VEmFluctuationModel * flucModel
Definition: G4VEmModel.hh:375
G4VEmModel(const G4String &nam)
Definition: G4VEmModel.cc:68
G4int nSelectors
Definition: G4VEmModel.hh:395
G4LossTableManager * fManager
Definition: G4VEmModel.hh:414
virtual void Initialise(const G4ParticleDefinition *, const G4DataVector &)=0
const G4double * GetVecNbOfAtomsPerVolume() const
Definition: G4Material.hh:206
G4double GetKineticEnergy() const
virtual void InitialiseForMaterial(const G4ParticleDefinition *, const G4Material *)
Definition: G4VEmModel.cc:225
CLHEP::HepRandomEngine * rndmEngineMod
Definition: G4VEmModel.hh:400
void SetParticleChange(G4VParticleChange *, G4VEmFluctuationModel *f=0)
Definition: G4VEmModel.cc:402
const G4MaterialCutsCouple * fCurrentCouple
Definition: G4VEmModel.hh:415
std::vector< G4EmElementSelector * > * elmSelectors
Definition: G4VEmModel.hh:396
bool G4bool
Definition: G4Types.hh:79
static const G4double inveplus
Definition: G4VEmModel.hh:408
const G4ParticleDefinition * GetParticleDefinition() const
virtual ~G4VEmModel()
Definition: G4VEmModel.cc:93
G4VEmAngularDistribution * anglModel
Definition: G4VEmModel.hh:376
void SetCrossSectionTable(G4PhysicsTable *, G4bool isLocal)
Definition: G4VEmModel.cc:410
void Register(G4VEnergyLossProcess *p)
const G4int n
G4int nsec
Definition: G4VEmModel.hh:419
virtual G4double ComputeCrossSectionPerAtom(const G4ParticleDefinition *, G4double kinEnergy, G4double Z, G4double A=0., G4double cutEnergy=0.0, G4double maxEnergy=DBL_MAX)
Definition: G4VEmModel.cc:315
virtual G4double ChargeSquareRatio(const G4Track &)
Definition: G4VEmModel.cc:329
G4Material * GetMaterial() const
G4double G4Log(G4double x)
Definition: G4Log.hh:230
std::vector< G4double > xsec
Definition: G4VEmModel.hh:420
virtual G4double GetChargeSquareRatio(const G4ParticleDefinition *, const G4Material *, G4double kineticEnergy)
Definition: G4VEmModel.cc:337
virtual G4double GetParticleCharge(const G4ParticleDefinition *, const G4Material *, G4double kineticEnergy)
Definition: G4VEmModel.cc:346
static G4ProductionCutsTable * GetProductionCutsTable()
virtual G4double ComputeDEDXPerVolume(const G4Material *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy=DBL_MAX)
Definition: G4VEmModel.cc:249
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
int G4lrint(double ad)
Definition: templates.hh:163
G4bool localElmSelectors
Definition: G4VEmModel.hh:393
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4int GetNumberOfBinsPerDecade() const
void SetCurrentCouple(const G4MaterialCutsCouple *)
Definition: G4VEmModel.hh:426
G4double highLimit
Definition: G4VEmModel.hh:382
G4bool useAngularGenerator
Definition: G4VEmModel.hh:394
G4double lowLimit
Definition: G4VEmModel.hh:381
G4VParticleChange * pParticleChange
Definition: G4VEmModel.hh:403
const G4double log106
Definition: G4VEmModel.cc:66
virtual G4double MaxSecondaryEnergy(const G4ParticleDefinition *, G4double kineticEnergy)
Definition: G4VEmModel.cc:387
static const double TeV
Definition: G4SIunits.hh:197
size_t GetNumberOfElements() const
Definition: G4Material.hh:186
static const double keV
Definition: G4SIunits.hh:195
G4PhysicsTable * xSectionTable
Definition: G4VEmModel.hh:404
double G4double
Definition: G4Types.hh:76
static const double eplus
Definition: G4SIunits.hh:178
G4double GetPDGCharge() const
#define DBL_MAX
Definition: templates.hh:83
G4ElementData * fElementData
Definition: G4VEmModel.hh:402
const G4Element * SelectRandomAtom(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy=0.0, G4double maxEnergy=DBL_MAX)
Definition: G4VEmModel.hh:526
void clearAndDestroy()
G4ParticleChangeForGamma * GetParticleChangeForGamma()
Definition: G4VEmModel.cc:134
virtual G4double Value(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy)
Definition: G4VEmModel.cc:361
const G4Material * GetMaterial() const