Geant4  10.03
XVCrystalIntegratedDensity.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 //
28 //
29 
31 
33  fNumberOfPoints = 512;
34  fIntegrationPoints[0] = 32;
35  fIntegrationPoints[1] = 32;
36  fIntegrationPoints[2] = 32;
37 }
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
40 
42 }
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
45 
47 SetIntegrationPoints(unsigned int vIndex,
48  unsigned int vIntegrationPoints){
49  if(vIndex<3) {
50  if(vIntegrationPoints > 0){
51  fIntegrationPoints[vIndex] = vIntegrationPoints;
52  }
53  }
54 }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
57 
59 GetIntegrationPoints(unsigned int vIndex){
60  if(vIndex<3) {
61  return fIntegrationPoints[vIndex];
62  }
63  else{
64  return 0;
65  }
66 }
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
69 
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
75 
77 SetNumberOfPoints(unsigned int vNumberOfPoints){
78  fNumberOfPoints = vNumberOfPoints;
79 }
80 
81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
82 
84  return fNumberOfPoints;
85 }
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
88 
91  fPotential = vPotential;
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
95 
97  return fPotential;
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
101 
104  fDensity = vDensity;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
108 
110  return fDensity;
111 }
112 
113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
114 
117  fLattice = vLattice;
118 }
119 
120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
121 
123  return fLattice;
124 }
125 
126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
127 
129  fParticleCharge = vParticleCharge;
130 }
131 
132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
133 
135  return fParticleCharge;
136 }
137 
138 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
139 
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
145 
148  G4int vParticleCharge){
149  //now it checks only of the table is initialized,
150  //it does not check if the particular crystal is initialized.
151  //To be changed in the future!
152  if(fTableVector->GetVectorLength() == 0) return false;
153  else if(vLattice!=fLattice) return false;
154  else if(vParticleCharge!=fParticleCharge) return false;
155  else return true;
156 }
157 
158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
159 
162  if(fParticleCharge < 0.){
164  }
165 
167  if(fParticleCharge < 0.){
169  }
170 
172 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
175 
177 
179 
180  G4cout << "XVCrystalIntegratedDensity::InitializeTable()::";
181  G4cout << "Potential Range = " << fPotentialRange/CLHEP::eV;
182  G4cout << " - Minimum = " << fPotentialMinimum / CLHEP::eV;
183  G4cout << " - Maximum " << fPotentialMaximum / CLHEP::eV << G4endl;
184 
185  G4double vPotentialInitial = 0.;
186 
187  fTableVector =
188  new G4PhysicsLinearVector(0.,
191 
192  G4double vValue = 0;
193  for(unsigned int i=0;i<GetNumberOfPoints();i++){
194  vPotentialInitial = (fPotentialMinimum +
197  vValue = ComputeIntegratedDensity(vPotentialInitial,fParticleCharge);
198  fTableVector->PutValue(i,vValue);
199  }
200 }
201 
202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
203 
206  XPhysicalLattice* vLattice,
207  G4int vParticleCharge){
208 
209  G4double vPotentialModified = vPotential /
210  std::fabs(G4double(vParticleCharge)) - fPotentialMinimum;
211 
212  // if the crystal has not been initialized return -1 -> Error!
213  if(!HasBeenInitialized(vLattice,vParticleCharge))
214  return -1.;
215  // if the potential is higher than the maximum the average density
216  // is equal to the one of the amorphous material
217  else if(vPotentialModified >= std::fabs(fPotentialMaximum - fPotentialMinimum))
218  return 1.;
219  // if the value is less than zero (because of possible variation
220  // due to centrifugal force) take the zero value
221  else if(vPotentialModified < 0.) return fTableVector->Value(0.);
222  //else if(vPotentialModified < 1. && vParticleCharge < 0.) return 1.;
223  else{
224  return fTableVector->Value(vPotentialModified);
225  }
226 }
227 
228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
229 
232  G4int){
233 
234  unsigned int i1,i2,i3;
235  i1 = i2 = i3 = 0;
236 
237  G4ThreeVector vPositionTemp = G4ThreeVector(0.,0.,0.);
238  G4double vDensity = 0.;
239 
241  while(i1<fIntegrationPoints[2]){
242  vPositionTemp.setY(G4double(G4double(i3)/
243  G4double(fIntegrationPoints[2])*vSize.z()));
244  while(i1<fIntegrationPoints[1]){
245  vPositionTemp.setZ(G4double(G4double(i2)/
246  G4double(fIntegrationPoints[1])*vSize.y()));
247  while(i1<fIntegrationPoints[0]){
248  vPositionTemp.setX(G4double(G4double(i1)/
249  G4double(fIntegrationPoints[0])*vSize.x()));
250  if(fPotential->GetEC(vPositionTemp,fLattice).x()
251  < vPotentialInitial){
252  vDensity += fDensity->GetEC(vPositionTemp,fLattice).x();
253  }
254  i1++;
255  };
256  i2++;
257  };
258  i3++;
259  };
260 
261  vDensity *= fLattice->GetXUnitCell()->ComputeVolume();
262  vDensity /= GetIntegrationPoints();
263 
264  return vDensity;
265 }
266 
267 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
268 
271  G4double &p1,
272  G4double &p2,
273  G4double &p3,
274  G4double &x)
275 {
276  double a0, a1 , a2 , a3 , x2;
277 
278  x2 = x * x;
279  a0 = -0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3;
280  a1 = p0 - 2.5 * p1 + 2.0 * p2 - 0.5 * p3;
281  a2 = -0.5 * p0 + 0.5 * p2;
282  a3 = p1;
283 
284  return (a0 * x * x2 + a1 * x2 + a2 * x + a3);
285 }
286 
287 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
288 
290  std::ofstream vFileOut;
291  vFileOut.open(filename);
292  G4double vStep = GetStep();
293 
294  vFileOut << "energy,dens" << std::endl;
295  for(unsigned int i = 0;i < fNumberOfPoints;i++){
296  vFileOut << i * vStep / CLHEP::eV;
297  vFileOut << " , ";
298  vFileOut << GetIntegratedDensity((i+1) * vStep
300  vFileOut << std::endl;
301  }
302  vFileOut.close();
303 }
304 
305 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
306 
308  std::ifstream vFileIn;
309  vFileIn.open(filename);
310  if(!vFileIn){
311  G4cout << "XVCrystalIntegratedDensity::";
312  G4cout << "ReadFromFile - ERROR READING FILE!!!!! ";
313  G4cout << filename << G4endl;
314  }
315 
318  G4double vDensity = 0.;
319 
320  vFileIn >> fPotentialMinimum;
321  vFileIn >> fPotentialMaximum;
322 
323  fPotentialMinimum *= CLHEP::eV;
324  fPotentialMaximum *= CLHEP::eV;
325 
326  std::vector<G4double> fTable;
327 
328  while(!vFileIn.eof()){
329  vFileIn >> vDensity;
330  if(vDensity < 1.E-2) {
331  vDensity = 1.E-2;
332  }
333  fTable.push_back(vDensity);
334  };
335 
336  fNumberOfPoints = fTable.size();
337 
338  fTableVector =
339  new G4PhysicsLinearVector(0.,
340  std::fabs(fPotentialMaximum - fPotentialMinimum),
342 
343  for(unsigned int i=0;i<fTable.size();i++){
344  fTableVector->PutValue(i,fTable.at(i));
345  }
346 
347  fPotentialRange = std::fabs(fPotentialMaximum - fPotentialMinimum);
348 
349  G4cout << "XVCrystalIntegratedDensity::InitializeTable()::";
350  G4cout << "Potential Range = " << fPotentialRange/CLHEP::eV;
351  G4cout << " - Minimum = " << fPotentialMinimum / CLHEP::eV;
352  G4cout << " - Maximum " << fPotentialMaximum / CLHEP::eV << G4endl;
353  vFileIn.close();
354 }
355 
356 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
const G4double a0
void SetIntegrationPoints(unsigned int, unsigned int)
G4PhysicsLinearVector * fTableVector
CLHEP::Hep3Vector G4ThreeVector
virtual G4double ComputeIntegratedDensity(G4double, G4int)
G4double FindCatmullRomInterpolate(G4double &p0, G4double &p1, G4double &p2, G4double &p3, G4double &x)
size_t GetVectorLength() const
G4double GetIntegratedDensity(G4double, XPhysicalLattice *, G4int)
int G4int
Definition: G4Types.hh:78
G4double ComputeVolume()
Definition: XUnitCell.cc:108
virtual G4double GetMinimum(XPhysicalLattice *)
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4ThreeVector GetSize()
Definition: XUnitCell.cc:51
void PutValue(size_t index, G4double theValue)
static constexpr double eV
Definition: G4SIunits.hh:215
XUnitCell * GetXUnitCell()
G4double Value(G4double theEnergy, size_t &lastidx) const
void SetXPhysicalLattice(XPhysicalLattice *)
void SetDensity(XVCrystalCharacteristic *)
G4ThreeVector GetEC(G4ThreeVector, XPhysicalLattice *)
virtual G4double GetMaximum(XPhysicalLattice *)
G4bool HasBeenInitialized(XPhysicalLattice *, G4int)
void SetPotential(XVCrystalCharacteristic *)
XVCrystalCharacteristic * GetDensity()
XVCrystalCharacteristic * GetPotential()
#define G4endl
Definition: G4ios.hh:61
Definition of the XVCrystalIntegratedDensity class.
double G4double
Definition: G4Types.hh:76
XVCrystalCharacteristic * fDensity
#define DBL_MAX
Definition: templates.hh:83
XVCrystalCharacteristic * fPotential