Geant4  10.01
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 84661 2014-10-17 14:30:16Z 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 //#include "G4MTHepRandom.hh"
62 
63 #if __clang__
64  #if (defined(G4MULTITHREADED) && !defined(G4USE_STD11) && \
65  !__has_feature(cxx_thread_local))
66  #define CLANG_NOSTDTLS
67  #endif
68 #endif
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 
74 const G4double log106 = 6*G4Log(10.);
75 
77  flucModel(0),anglModel(0), name(nam), lowLimit(0.1*CLHEP::keV),
78  highLimit(100.0*CLHEP::TeV),eMinActive(0.0),eMaxActive(DBL_MAX),
79  polarAngleLimit(CLHEP::pi),secondaryThreshold(DBL_MAX),
80  theLPMflag(false),flagDeexcitation(false),flagForceBuildTable(false),
81  isMaster(true),fElementData(0),pParticleChange(0),xSectionTable(0),
82  theDensityFactor(0),theDensityIdx(0),fCurrentCouple(0),fCurrentElement(0),
83  fCurrentIsotope(0),nsec(5)
84 {
85  xsec.resize(nsec);
86  nSelectors = 0;
87  elmSelectors = 0;
88  localElmSelectors = true;
89  localTable = true;
90  useAngularGenerator = false;
91  idxTable = 0;
92 
94  fManager->Register(this);
95 
96 #if (defined(G4MULTITHREADED) && !defined(G4USE_STD11)) || \
97  (defined(CLANG_NOSTDTLS))
99 #else // Sequential mode or supporting C++11 standard
100  rndmEngineMod = CLHEP::HepRandom::getTheEngine();
101 #endif
102 }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 
107 {
108  if(localElmSelectors) {
109  if(nSelectors > 0) {
110  for(G4int i=0; i<nSelectors; ++i) {
111  delete (*elmSelectors)[i];
112  }
113  }
114  delete elmSelectors;
115  }
116  delete anglModel;
117 
118  if(localTable && xSectionTable) {
120  delete xSectionTable;
121  xSectionTable = 0;
122  }
123  if(isMaster && fElementData) {
124  delete fElementData;
125  fElementData = 0;
126  }
127 
128  fManager->DeRegister(this);
129 }
130 
131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
132 
134 {
136  if (pParticleChange) {
137  p = static_cast<G4ParticleChangeForLoss*>(pParticleChange);
138  } else {
139  p = new G4ParticleChangeForLoss();
140  pParticleChange = p;
141  }
142  return p;
143 }
144 
145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
146 
148 {
150  if (pParticleChange) {
151  p = static_cast<G4ParticleChangeForGamma*>(pParticleChange);
152  } else {
153  p = new G4ParticleChangeForGamma();
154  pParticleChange = p;
155  }
156  return p;
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160 
162  const G4DataVector& cuts)
163 {
164  // using spline for element selectors should be investigated in details
165  // because small number of points may provide biased results
166  // large number of points requires significant increase of memory
167  //G4bool spline = fManager->SplineFlag();
168  G4bool spline = false;
169 
170  //G4cout << "IES: for " << GetName() << " Emin(MeV)= " << lowLimit/MeV
171  // << " Emax(MeV)= " << highLimit/MeV << G4endl;
172 
173  // two times less bins because probability functon is normalized
174  // so correspondingly is more smooth
175  if(highLimit <= lowLimit) { return; }
176 
177  G4ProductionCutsTable* theCoupleTable=
179  G4int numOfCouples = theCoupleTable->GetTableSize();
180 
181  // prepare vector
182  if(!elmSelectors) {
183  elmSelectors = new std::vector<G4EmElementSelector*>;
184  }
185  if(numOfCouples > nSelectors) {
186  for(G4int i=nSelectors; i<numOfCouples; ++i) {
187  elmSelectors->push_back(0);
188  }
189  nSelectors = numOfCouples;
190  }
191 
192  // initialise vector
193  for(G4int i=0; i<numOfCouples; ++i) {
194 
195  // no need in element selectors for infionite cuts
196  if(cuts[i] == DBL_MAX) { continue; }
197 
198  fCurrentCouple = theCoupleTable->GetMaterialCutsCouple(i);
199  const G4Material* material = fCurrentCouple->GetMaterial();
200 
201  // selector already exist check if should be deleted
202  G4bool create = true;
203  if((*elmSelectors)[i]) {
204  if(material == ((*elmSelectors)[i])->GetMaterial()) { create = false; }
205  else { delete (*elmSelectors)[i]; }
206  }
207  if(create) {
208  G4double emin = std::max(lowLimit,
209  MinPrimaryEnergy(material, part, cuts[i]));
210  G4double emax = std::max(highLimit, 10*emin);
212  *G4Log(emax/emin)/log106);
213  nbins = std::max(nbins, 3);
214 
215  (*elmSelectors)[i] = new G4EmElementSelector(this,material,nbins,
216  emin,emax,spline);
217  }
218  ((*elmSelectors)[i])->Initialise(part, cuts[i]);
219  /*
220  G4cout << "G4VEmModel::InitialiseElmSelectors i= " << i
221  << " idx= " << fCurrentCouple->GetIndex()
222  << " " << part->GetParticleName()
223  << " for " << GetName() << " cut= " << cuts[i]
224  << " " << (*elmSelectors)[i] << G4endl;
225  ((*elmSelectors)[i])->Dump(part);
226  */
227  }
228 }
229 
230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
231 
233  G4VEmModel*)
234 {}
235 
236 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
237 
239  const G4Material* material)
240 {
241  if(material) {
242  const G4ElementVector* theElementVector = material->GetElementVector();
243  G4int n = material->GetNumberOfElements();
244  for(G4int i=0; i<n; ++i) {
245  G4int Z = G4lrint(((*theElementVector)[i])->GetZ());
246  InitialiseForElement(part, Z);
247  }
248  } else {
249  //G4cout << "G4VEmModel::InitialiseForMaterial for " << GetName();
250  //if(part) { G4cout << " and " << part->GetParticleName(); }
251  //G4cout << " with no material" << G4endl;
252  }
253 }
254 
255 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
256 
258 {}
259 
260 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
261 
263  const G4ParticleDefinition*,
265 {
266  return 0.0;
267 }
268 
269 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
270 
272  const G4ParticleDefinition* p,
273  G4double ekin,
274  G4double emin,
275  G4double emax)
276 {
277  SetupForMaterial(p, material, ekin);
278  G4double cross = 0.0;
279  const G4ElementVector* theElementVector = material->GetElementVector();
280  const G4double* theAtomNumDensityVector =
281  material->GetVecNbOfAtomsPerVolume();
282  G4int nelm = material->GetNumberOfElements();
283  if(nelm > nsec) {
284  xsec.resize(nelm);
285  nsec = nelm;
286  }
287  for (G4int i=0; i<nelm; ++i) {
288  cross += theAtomNumDensityVector[i]*
289  ComputeCrossSectionPerAtom(p,(*theElementVector)[i],ekin,emin,emax);
290  xsec[i] = cross;
291  }
292  return cross;
293 }
294 
295 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
296 
298 {}
299 
300 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
301 
303  const G4ParticleDefinition* pd,
304  G4double kinEnergy,
305  G4double tcut,
306  G4double tmax)
307 {
308  const G4ElementVector* theElementVector = material->GetElementVector();
309  G4int n = material->GetNumberOfElements() - 1;
310  fCurrentElement = (*theElementVector)[n];
311  if (n > 0) {
312  G4double x = rndmEngineMod->flat()*
313  G4VEmModel::CrossSectionPerVolume(material,pd,kinEnergy,tcut,tmax);
314  for(G4int i=0; i<n; ++i) {
315  if (x <= xsec[i]) {
316  fCurrentElement = (*theElementVector)[i];
317  break;
318  }
319  }
320  }
321  return fCurrentElement;
322 }
323 
324 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
325 
329 {
330  return 0.0;
331 }
332 
333 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
334 
336 {}
337 
338 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
339 
341 {
343  track.GetMaterial(), track.GetKineticEnergy());
344 }
345 
346 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
347 
349  const G4Material*, G4double)
350 {
351  G4double q = p->GetPDGCharge()*inveplus;
352  return q*q;
353 }
354 
355 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
356 
358  const G4Material*, G4double)
359 {
360  return p->GetPDGCharge();
361 }
362 
363 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
364 
366  const G4DynamicParticle*,
368 {}
369 
370 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
371 
373  const G4ParticleDefinition* p, G4double e)
374 {
375  SetCurrentCouple(couple);
376  return e*e*CrossSectionPerVolume(couple->GetMaterial(),p,e,0.0,DBL_MAX);
377 }
378 
379 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
380 
382  const G4ParticleDefinition*,
383  G4double)
384 {
385  return 0.0;
386 }
387 
388 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
389 
391  const G4MaterialCutsCouple*)
392 {
393  return 0.0;
394 }
395 
396 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
397 
399  G4double kineticEnergy)
400 {
401  return kineticEnergy;
402 }
403 
404 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
405 
407  const G4Material*, G4double)
408 {}
409 
410 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
411 
412 void
414 {
415  if(p && pParticleChange != p) { pParticleChange = p; }
416  flucModel = f;
417 }
418 
419 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
420 
422 {
423  if(p != xSectionTable) {
424  if(xSectionTable && localTable) {
426  delete xSectionTable;
427  }
428  xSectionTable = p;
429  }
430  localTable = isLocal;
431 }
432 
433 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool localTable
Definition: G4VEmModel.hh:392
size_t idxTable
Definition: G4VEmModel.hh:407
static CLHEP::HepRandomEngine * getTheEngine()
virtual G4double CrossSectionPerVolume(const G4Material *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy=0.0, G4double maxEnergy=DBL_MAX)
Definition: G4VEmModel.cc:271
virtual void InitialiseForElement(const G4ParticleDefinition *, G4int Z)
Definition: G4VEmModel.cc:257
virtual void StartTracking(G4Track *)
Definition: G4VEmModel.cc:297
static G4LossTableManager * Instance()
G4ParticleChangeForLoss * GetParticleChangeForLoss()
Definition: G4VEmModel.cc:133
std::vector< G4Element * > G4ElementVector
virtual void CorrectionsAlongStep(const G4MaterialCutsCouple *, const G4DynamicParticle *, G4double &eloss, G4double &niel, G4double length)
Definition: G4VEmModel.cc:365
void InitialiseElementSelectors(const G4ParticleDefinition *, const G4DataVector &)
Definition: G4VEmModel.cc:161
void DeRegister(G4VEnergyLossProcess *p)
virtual void DefineForRegion(const G4Region *)
Definition: G4VEmModel.cc:335
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:381
const G4double pi
virtual void InitialiseLocal(const G4ParticleDefinition *, G4VEmModel *masterModel)
Definition: G4VEmModel.cc:232
virtual void SetupForMaterial(const G4ParticleDefinition *, const G4Material *, G4double kineticEnergy)
Definition: G4VEmModel.cc:406
virtual G4double MinEnergyCut(const G4ParticleDefinition *, const G4MaterialCutsCouple *)
Definition: G4VEmModel.cc:390
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:188
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:76
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:204
G4double GetKineticEnergy() const
virtual void InitialiseForMaterial(const G4ParticleDefinition *, const G4Material *)
Definition: G4VEmModel.cc:238
CLHEP::HepRandomEngine * rndmEngineMod
Definition: G4VEmModel.hh:400
void SetParticleChange(G4VParticleChange *, G4VEmFluctuationModel *f=0)
Definition: G4VEmModel.cc:413
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:106
G4VEmAngularDistribution * anglModel
Definition: G4VEmModel.hh:376
void SetCrossSectionTable(G4PhysicsTable *, G4bool isLocal)
Definition: G4VEmModel.cc:421
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:326
virtual G4double ChargeSquareRatio(const G4Track &)
Definition: G4VEmModel.cc:340
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:348
virtual G4double GetParticleCharge(const G4ParticleDefinition *, const G4Material *, G4double kineticEnergy)
Definition: G4VEmModel.cc:357
static G4ProductionCutsTable * GetProductionCutsTable()
virtual G4double ComputeDEDXPerVolume(const G4Material *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy=DBL_MAX)
Definition: G4VEmModel.cc:262
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:74
virtual G4double MaxSecondaryEnergy(const G4ParticleDefinition *, G4double kineticEnergy)
Definition: G4VEmModel.cc:398
static const double TeV
Definition: G4SIunits.hh:197
size_t GetNumberOfElements() const
Definition: G4Material.hh:184
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:525
void clearAndDestroy()
G4ParticleChangeForGamma * GetParticleChangeForGamma()
Definition: G4VEmModel.cc:147
virtual G4double Value(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy)
Definition: G4VEmModel.cc:372
const G4Material * GetMaterial() const