Geant4  10.03
G4PAIModel.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: G4PAIModel.cc 96934 2016-05-18 09:10:41Z gcosmo $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 Class
31 // File name: G4PAIModel.cc
32 //
33 // Author: Vladimir.Grichine@cern.ch on base of V.Ivanchenko model interface
34 //
35 // Creation date: 05.10.2003
36 //
37 // Modifications:
38 //
39 // 17.08.04 V.Grichine, bug fixed for Tkin<=0 in SampleSecondary
40 // 16.08.04 V.Grichine, bug fixed in massRatio for DEDX, CrossSection,
41 // SampleSecondary
42 // 08.04.05 Major optimisation of internal interfaces (V.Ivantchenko)
43 // 26.07.09 Fixed logic to work with several materials (V.Ivantchenko)
44 // 21.11.10 V. Grichine verbose flag for protons and G4PAYySection to
45 // check sandia table
46 // 12.06.13 V. Grichine Bug fixed in SampleSecondaries for scaled Tkin
47 // (fMass -> proton_mass_c2)
48 // 19.08.13 V.Ivanchenko extract data handling to G4PAIModelData class
49 // added sharing of internal data between threads (MT migration)
50 //
51 
52 #include "G4PAIModel.hh"
53 
54 #include "G4SystemOfUnits.hh"
55 #include "G4PhysicalConstants.hh"
56 #include "G4Region.hh"
57 #include "G4MaterialCutsCouple.hh"
58 #include "G4MaterialTable.hh"
59 #include "G4RegionStore.hh"
60 
61 #include "Randomize.hh"
62 #include "G4Electron.hh"
63 #include "G4Positron.hh"
64 #include "G4Poisson.hh"
65 #include "G4Step.hh"
66 #include "G4Material.hh"
67 #include "G4DynamicParticle.hh"
68 #include "G4ParticleDefinition.hh"
70 #include "G4PAIModelData.hh"
71 #include "G4DeltaAngle.hh"
72 
74 
75 using namespace std;
76 
79  fVerbose(0),
80  fModelData(nullptr),
81  fParticle(nullptr)
82 {
85 
86  fParticleChange = nullptr;
87 
88  if(p) { SetParticle(p); }
89  else { SetParticle(fElectron); }
90 
91  // default generator
93 }
94 
96 
98 {
99  if(IsMaster()) { delete fModelData; }
100 }
101 
103 
105  const G4DataVector& cuts)
106 {
107  if(fVerbose > 0) {
108  G4cout<<"G4PAIModel::Initialise for "<<p->GetParticleName()<<G4endl;
109  }
110  SetParticle(p);
112 
113  if(IsMaster()) {
114 
115  delete fModelData;
116  fMaterialCutsCoupleVector.clear();
117  if(fVerbose > 0) {
118  G4cout << "G4PAIModel instantiates data for " << p->GetParticleName()
119  << G4endl;
120  }
121  G4double tmin = LowEnergyLimit()*fRatio;
123  fModelData = new G4PAIModelData(tmin, tmax, fVerbose);
124 
125  // Prepare initialization
126  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
127  size_t numOfMat = G4Material::GetNumberOfMaterials();
128  size_t numRegions = fPAIRegionVector.size();
129 
130  // protect for unit tests
131  if(0 == numRegions) {
132  G4Exception("G4PAIModel::Initialise()","em0106",JustWarning,
133  "no G4Regions are registered for the PAI model - World is used");
135  ->GetRegion("DefaultRegionForTheWorld", false));
136  numRegions = 1;
137  }
138 
139  if(fVerbose > 0) {
140  G4cout << "G4PAIModel is defined for " << numRegions << " regions "
141  << G4endl;
142  G4cout << " total number of materials " << numOfMat << G4endl;
143  }
144  for(size_t iReg = 0; iReg<numRegions; ++iReg) {
145  const G4Region* curReg = fPAIRegionVector[iReg];
146  G4Region* reg = const_cast<G4Region*>(curReg);
147 
148  for(size_t jMat = 0; jMat<numOfMat; ++jMat) {
149  G4Material* mat = (*theMaterialTable)[jMat];
150  const G4MaterialCutsCouple* cutCouple = reg->FindCouple(mat);
151  size_t n = fMaterialCutsCoupleVector.size();
152  /*
153  G4cout << "Region: " << reg->GetName() << " " << reg
154  << " Couple " << cutCouple
155  << " PAI defined for " << n << " couples"
156  << " jMat= " << jMat << " " << mat->GetName()
157  << G4endl;
158  */
159  if(cutCouple) {
160  if(fVerbose > 0) {
161  G4cout << "Region <" << curReg->GetName() << "> mat <"
162  << mat->GetName() << "> CoupleIndex= "
163  << cutCouple->GetIndex()
164  << " " << p->GetParticleName()
165  << " cutsize= " << cuts.size() << G4endl;
166  }
167  // check if this couple is not already initialized
168  G4bool isnew = true;
169  if(0 < n) {
170  for(size_t i=0; i<n; ++i) {
171  if(cutCouple == fMaterialCutsCoupleVector[i]) {
172  isnew = false;
173  break;
174  }
175  }
176  }
177  // initialise data banks
178  //G4cout << " isNew: " << isnew << " " << cutCouple << G4endl;
179  if(isnew) {
180  fMaterialCutsCoupleVector.push_back(cutCouple);
181  fModelData->Initialise(cutCouple, this);
182  }
183  }
184  }
185  }
187  }
188 }
189 
191 
193  G4VEmModel* masterModel)
194 {
195  SetParticle(p);
196  fModelData = static_cast<G4PAIModel*>(masterModel)->GetPAIModelData();
198  static_cast<G4PAIModel*>(masterModel)->GetVectorOfCouples();
200 }
201 
203 
205  const G4ParticleDefinition* p,
206  G4double kineticEnergy,
207  G4double cutEnergy)
208 {
209  //G4cout << "===1=== " << CurrentCouple()
210  // << " idx= " << CurrentCouple()->GetIndex()
211  // << " " << fMaterialCutsCoupleVector[0]
212  // << G4endl;
213  G4int coupleIndex = FindCoupleIndex(CurrentCouple());
214  //G4cout << "===2=== " << coupleIndex << G4endl;
215  if(0 > coupleIndex) { return 0.0; }
216 
217  G4double cut = std::min(MaxSecondaryEnergy(p, kineticEnergy), cutEnergy);
218 
219  G4double scaledTkin = kineticEnergy*fRatio;
220 
221  return fChargeSquare*fModelData->DEDXPerVolume(coupleIndex, scaledTkin,
222  cut);
223 }
224 
226 
228  const G4ParticleDefinition* p,
229  G4double kineticEnergy,
230  G4double cutEnergy,
231  G4double maxEnergy )
232 {
233  //G4cout << "===3=== " << CurrentCouple()
234  // << " idx= " << CurrentCouple()->GetIndex()
235  // << " " << fMaterialCutsCoupleVector[0]
236  // << G4endl;
237  G4int coupleIndex = FindCoupleIndex(CurrentCouple());
238  //G4cout << "===4=== " << coupleIndex << G4endl;
239  if(0 > coupleIndex) { return 0.0; }
240 
241  G4double tmax = std::min(MaxSecondaryEnergy(p, kineticEnergy), maxEnergy);
242  if(tmax <= cutEnergy) { return 0.0; }
243 
244  G4double scaledTkin = kineticEnergy*fRatio;
245 
246  return fChargeSquare*fModelData->CrossSectionPerVolume(coupleIndex,
247  scaledTkin,
248  cutEnergy,
249  tmax);
250 }
251 
253 //
254 // It is analog of PostStepDoIt in terms of secondary electron.
255 //
256 
257 void G4PAIModel::SampleSecondaries(std::vector<G4DynamicParticle*>* vdp,
258  const G4MaterialCutsCouple* matCC,
259  const G4DynamicParticle* dp,
260  G4double tmin,
261  G4double maxEnergy)
262 {
263  G4int coupleIndex = FindCoupleIndex(matCC);
264 
265  //G4cout << "G4PAIModel::SampleSecondaries: coupleIndex= "<<coupleIndex<<G4endl;
266  if(0 > coupleIndex) { return; }
267 
268  SetParticle(dp->GetDefinition());
269  G4double kineticEnergy = dp->GetKineticEnergy();
270 
271  G4double tmax = MaxSecondaryEnergy(fParticle, kineticEnergy);
272  if(maxEnergy < tmax) { tmax = maxEnergy; }
273  if(tmin >= tmax) { return; }
274 
275  G4ThreeVector direction= dp->GetMomentumDirection();
276  G4double scaledTkin = kineticEnergy*fRatio;
277  G4double totalEnergy = kineticEnergy + fMass;
278  G4double totalMomentum = sqrt(kineticEnergy*(totalEnergy+fMass));
279 
280  G4double deltaTkin =
281  fModelData->SamplePostStepTransfer(coupleIndex, scaledTkin, tmin, tmax);
282 
283  //G4cout<<"G4PAIModel::SampleSecondaries; deltaKIn = "<<deltaTkin/keV
284  // <<" keV "<< " Escaled(MeV)= " << scaledTkin << G4endl;
285 
286  if( !(deltaTkin <= 0.) && !(deltaTkin > 0)) {
287  G4cout<<"G4PAIModel::SampleSecondaries; deltaKIn = "<<deltaTkin/keV
288  <<" keV "<< " Escaled(MeV)= " << scaledTkin << G4endl;
289  return;
290  }
291  if( deltaTkin <= 0.) { return; }
292 
293  if( deltaTkin > tmax) { deltaTkin = tmax; }
294 
295  const G4Element* anElement = SelectRandomAtom(matCC,fParticle,kineticEnergy);
296  G4int Z = G4lrint(anElement->GetZ());
297 
299  GetAngularDistribution()->SampleDirection(dp, deltaTkin,
300  Z, matCC->GetMaterial()),
301  deltaTkin);
302 
303  // primary change
304  kineticEnergy -= deltaTkin;
305  G4ThreeVector dir = totalMomentum*direction - deltaRay->GetMomentum();
306  direction = dir.unit();
309 
310  vdp->push_back(deltaRay);
311 }
312 
314 
316  const G4DynamicParticle* aParticle,
317  G4double tmax, G4double step,
318  G4double eloss)
319 {
320  G4int coupleIndex = FindCoupleIndex(matCC);
321  if(0 > coupleIndex) { return eloss; }
322 
323  SetParticle(aParticle->GetDefinition());
324 
325  /*
326  G4cout << "G4PAIModel::SampleFluctuations step(mm)= "<< step/mm
327  << " Eloss(keV)= " << eloss/keV << " in "
328  << matCC->Getmaterial()->GetName() << G4endl;
329  */
330 
331  G4double Tkin = aParticle->GetKineticEnergy();
332  G4double scaledTkin = Tkin*fRatio;
333 
334  G4double loss = fModelData->SampleAlongStepTransfer(coupleIndex, Tkin,
335  scaledTkin, tmax,
336  step*fChargeSquare);
337 
338  // G4cout<<"PAIModel AlongStepLoss = "<<loss/keV<<" keV, on step = "
339  //<<step/mm<<" mm"<<G4endl;
340  return loss;
341 
342 }
343 
345 //
346 // Returns the statistical estimation of the energy loss distribution variance
347 //
348 
349 
351  const G4DynamicParticle* aParticle,
352  G4double tmax,
353  G4double step )
354 {
355  G4double particleMass = aParticle->GetMass();
356  G4double electronDensity = material->GetElectronDensity();
357  G4double kineticEnergy = aParticle->GetKineticEnergy();
358  G4double q = aParticle->GetCharge()/eplus;
359  G4double etot = kineticEnergy + particleMass;
360  G4double beta2 = kineticEnergy*(kineticEnergy + 2.0*particleMass)/(etot*etot);
361  G4double siga = (1.0/beta2 - 0.5) * twopi_mc2_rcl2 * tmax * step
362  * electronDensity * q * q;
363 
364  return siga;
365 }
366 
368 
370  G4double kinEnergy)
371 {
372  SetParticle(p);
373  G4double tmax = kinEnergy;
374  if(p == fElectron) { tmax *= 0.5; }
375  else if(p != fPositron) {
376  G4double ratio= electron_mass_c2/fMass;
377  G4double gamma= kinEnergy/fMass + 1.0;
378  tmax = 2.0*electron_mass_c2*(gamma*gamma - 1.) /
379  (1. + 2.0*gamma*ratio + ratio*ratio);
380  }
381  return tmax;
382 }
383 
385 
387 {
388  fPAIRegionVector.push_back(r);
389 }
390 
392 
const std::vector< const G4MaterialCutsCouple * > & GetVectorOfCouples()
Definition: G4PAIModel.hh:161
G4double LowEnergyLimit() const
Definition: G4VEmModel.hh:640
G4PAIModelData * GetPAIModelData()
Definition: G4PAIModel.hh:155
G4PAIModel(const G4ParticleDefinition *p=nullptr, const G4String &nam="PAI")
Definition: G4PAIModel.cc:77
std::vector< const G4MaterialCutsCouple * > fMaterialCutsCoupleVector
Definition: G4PAIModel.hh:142
const G4String & GetName() const
const G4ParticleDefinition * fPositron
Definition: G4PAIModel.hh:147
virtual void SampleSecondaries(std::vector< G4DynamicParticle * > *, const G4MaterialCutsCouple *, const G4DynamicParticle *, G4double tmin, G4double maxEnergy) final
Definition: G4PAIModel.cc:257
G4ParticleChangeForLoss * GetParticleChangeForLoss()
Definition: G4VEmModel.cc:118
G4int FindCoupleIndex(const G4MaterialCutsCouple *)
Definition: G4PAIModel.hh:176
G4double fMass
Definition: G4PAIModel.hh:150
G4double GetKineticEnergy() const
CLHEP::Hep3Vector G4ThreeVector
void InitialiseElementSelectors(const G4ParticleDefinition *, const G4DataVector &)
Definition: G4VEmModel.cc:146
virtual void Initialise(const G4ParticleDefinition *, const G4DataVector &) final
Definition: G4PAIModel.cc:104
G4double HighEnergyLimit() const
Definition: G4VEmModel.hh:633
std::vector< const G4Region * > fPAIRegionVector
Definition: G4PAIModel.hh:143
G4double fRatio
Definition: G4PAIModel.hh:151
virtual G4double CrossSectionPerVolume(const G4Material *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy, G4double maxEnergy) final
Definition: G4PAIModel.cc:227
const G4String & GetName() const
Definition: G4Material.hh:178
G4double GetZ() const
Definition: G4Element.hh:131
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
std::vector< G4Material * > G4MaterialTable
G4VEmAngularDistribution * GetAngularDistribution()
Definition: G4VEmModel.hh:616
G4int fVerbose
Definition: G4PAIModel.hh:138
G4bool IsMaster() const
Definition: G4VEmModel.hh:717
G4ParticleDefinition * GetDefinition() const
virtual G4double Dispersion(const G4Material *, const G4DynamicParticle *, G4double, G4double) final
Definition: G4PAIModel.cc:350
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
static const G4double reg
G4double SampleAlongStepTransfer(G4int coupleIndex, G4double kinEnergy, G4double scaledTkin, G4double tmax, G4double stepFactor) const
static G4RegionStore * GetInstance()
void SetParticle(const G4ParticleDefinition *p)
Definition: G4PAIModel.hh:189
virtual G4double SampleFluctuations(const G4MaterialCutsCouple *, const G4DynamicParticle *, G4double, G4double, G4double) final
Definition: G4PAIModel.cc:315
const G4ParticleDefinition * fParticle
Definition: G4PAIModel.hh:145
G4double DEDXPerVolume(G4int coupleIndex, G4double scaledTkin, G4double cut) const
const G4MaterialCutsCouple * CurrentCouple() const
Definition: G4VEmModel.hh:451
G4GLOB_DLL std::ostream G4cout
G4double fChargeSquare
Definition: G4PAIModel.hh:152
G4double GetElectronDensity() const
Definition: G4Material.hh:217
G4double GetMass() const
G4PAIModelData * fModelData
Definition: G4PAIModel.hh:140
bool G4bool
Definition: G4Types.hh:79
const G4ThreeVector & GetMomentumDirection() const
virtual void DefineForRegion(const G4Region *r) final
Definition: G4PAIModel.cc:386
G4double GetCharge() const
static constexpr double eplus
Definition: G4SIunits.hh:199
void SetProposedKineticEnergy(G4double proposedKinEnergy)
G4MaterialCutsCouple * FindCouple(G4Material *mat)
const G4int n
std::vector< G4EmElementSelector * > * GetElementSelectors()
Definition: G4VEmModel.hh:801
static size_t GetNumberOfMaterials()
Definition: G4Material.cc:594
const G4ParticleDefinition * fElectron
Definition: G4PAIModel.hh:146
void SetProposedMomentumDirection(const G4ThreeVector &dir)
virtual void InitialiseLocal(const G4ParticleDefinition *, G4VEmModel *masterModel) final
Definition: G4PAIModel.cc:192
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4double ComputeDEDXPerVolume(const G4Material *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy) final
Definition: G4PAIModel.cc:204
G4double CrossSectionPerVolume(G4int coupleIndex, G4double scaledTkin, G4double tcut, G4double tmax) const
G4ParticleChangeForLoss * fParticleChange
Definition: G4PAIModel.hh:148
static G4Positron * Positron()
Definition: G4Positron.cc:94
void SetElementSelectors(std::vector< G4EmElementSelector * > *)
Definition: G4VEmModel.hh:809
virtual ~G4PAIModel()
Definition: G4PAIModel.cc:97
int G4lrint(double ad)
Definition: templates.hh:163
virtual G4double MaxSecondaryEnergy(const G4ParticleDefinition *, G4double kinEnergy) final
Definition: G4PAIModel.cc:369
void SetAngularDistribution(G4VEmAngularDistribution *)
Definition: G4VEmModel.hh:623
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
static G4Electron * Electron()
Definition: G4Electron.cc:94
#define G4endl
Definition: G4ios.hh:61
G4double SamplePostStepTransfer(G4int coupleIndex, G4double scaledTkin, G4double tmin, G4double tmax) const
double G4double
Definition: G4Types.hh:76
void Initialise(const G4MaterialCutsCouple *, G4PAIModel *)
static constexpr double keV
Definition: G4SIunits.hh:216
const G4Element * SelectRandomAtom(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy, G4double cutEnergy=0.0, G4double maxEnergy=DBL_MAX)
Definition: G4VEmModel.hh:541
const G4Material * GetMaterial() const