Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VRangeToEnergyConverter Class Referenceabstract

#include <G4VRangeToEnergyConverter.hh>

+ Inheritance diagram for G4VRangeToEnergyConverter:

Public Member Functions

 G4VRangeToEnergyConverter ()
 
 G4VRangeToEnergyConverter (const G4VRangeToEnergyConverter &r)
 
G4VRangeToEnergyConverteroperator= (const G4VRangeToEnergyConverter &r)
 
virtual ~G4VRangeToEnergyConverter ()
 
G4bool operator== (const G4VRangeToEnergyConverter &r) const
 
G4bool operator!= (const G4VRangeToEnergyConverter &r) const
 
virtual G4double Convert (G4double rangeCut, const G4Material *material)
 
const G4ParticleDefinitionGetParticleType () const
 
const G4PhysicsTableGetLossTable () const
 
virtual void Reset ()
 
void SetVerboseLevel (G4int value)
 
G4int GetVerboseLevel () const
 

Static Public Member Functions

static void SetEnergyRange (G4double lowedge, G4double highedge)
 
static G4double GetLowEdgeEnergy ()
 
static G4double GetHighEdgeEnergy ()
 
static G4double GetMaxEnergyCut ()
 
static void SetMaxEnergyCut (G4double value)
 

Protected Types

using G4LossVector = G4PhysicsLogVector
 
using G4RangeVector = G4PhysicsLogVector
 
using G4LossTable = G4PhysicsTable
 

Protected Member Functions

virtual void BuildLossTable ()
 
virtual G4double ComputeLoss (G4double AtomicNumber, G4double KineticEnergy)=0
 
virtual void BuildRangeVector (const G4Material *aMaterial, G4RangeVector *rangeVector)
 
G4double ConvertCutToKineticEnergy (G4RangeVector *theRangeVector, G4double theCutInLength, std::size_t materialIndex) const
 

Protected Attributes

G4double fMaxEnergyCut = 0.0
 
const G4ParticleDefinitiontheParticle = nullptr
 
G4LossTabletheLossTable = nullptr
 
G4int NumberOfElements = 0
 
const G4int TotBin = 300
 
std::vector< G4RangeVector * > fRangeVectorStore
 

Static Protected Attributes

static G4double LowestEnergy = 0.99e-3*MeV
 
static G4double HighestEnergy = 100.0e6*MeV
 
static G4double MaxEnergyCut = 10.0*GeV
 

Detailed Description

Definition at line 51 of file G4VRangeToEnergyConverter.hh.

Member Typedef Documentation

◆ G4LossTable

◆ G4LossVector

◆ G4RangeVector

Constructor & Destructor Documentation

◆ G4VRangeToEnergyConverter() [1/2]

G4VRangeToEnergyConverter::G4VRangeToEnergyConverter ( )

Definition at line 45 of file G4VRangeToEnergyConverter.cc.

46{
47}

◆ G4VRangeToEnergyConverter() [2/2]

G4VRangeToEnergyConverter::G4VRangeToEnergyConverter ( const G4VRangeToEnergyConverter r)

Definition at line 50 of file G4VRangeToEnergyConverter.cc.

52{
53 *this = right;
54}

◆ ~G4VRangeToEnergyConverter()

G4VRangeToEnergyConverter::~G4VRangeToEnergyConverter ( )
virtual

Definition at line 116 of file G4VRangeToEnergyConverter.cc.

117{
118 Reset();
119}

Member Function Documentation

◆ BuildLossTable()

void G4VRangeToEnergyConverter::BuildLossTable ( )
protectedvirtual

Definition at line 295 of file G4VRangeToEnergyConverter.cc.

296{
297 // Create Energy Loss Table for charged particles
298 // (cross-section table for neutral)
299
300 if (std::size_t(NumberOfElements) == G4Element::GetNumberOfElements()) return;
301
302 // clear Loss table and Range vectors
303 Reset();
304
305 // Build dE/dx tables for elements
309#ifdef G4VERBOSE
310 if (GetVerboseLevel()>3)
311 {
312 G4cout << "G4VRangeToEnergyConverter::BuildLossTable() - ";
313 G4cout << "Create theLossTable[" << theLossTable << "]";
314 G4cout << " NumberOfElements=" << NumberOfElements << G4endl;
315 }
316#endif
317
318 // fill the loss table
319 for (std::size_t j=0; j<std::size_t(NumberOfElements); ++j)
320 {
321 G4double Value;
322 G4LossVector* aVector = nullptr;
324 for (std::size_t i=0; i<=std::size_t(TotBin); ++i)
325 {
326 Value = ComputeLoss( (*G4Element::GetElementTable())[j]->GetZ(),
327 aVector->Energy(i) );
328 aVector->PutValue(i,Value);
329 }
330 theLossTable->insert(aVector);
331 }
332}
double G4double
Definition: G4Types.hh:83
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:397
static size_t GetNumberOfElements()
Definition: G4Element.cc:404
void insert(G4PhysicsVector *)
virtual G4double ComputeLoss(G4double AtomicNumber, G4double KineticEnergy)=0

Referenced by Convert().

◆ BuildRangeVector()

void G4VRangeToEnergyConverter::BuildRangeVector ( const G4Material aMaterial,
G4RangeVector rangeVector 
)
protectedvirtual

Reimplemented in G4RToEConvForGamma.

Definition at line 337 of file G4VRangeToEnergyConverter.cc.

339{
340 // create range vector for a material
341
342 const G4ElementVector* elementVector
343 = aMaterial->GetElementVector();
344 const G4double* atomicNumDensityVector
345 = aMaterial->GetAtomicNumDensityVector();
346 G4int NumEl = aMaterial->GetNumberOfElements();
347
348 // calculate parameters of the low energy part first
349 std::size_t i;
350 std::vector<G4double> lossV;
351 for ( std::size_t ib=0; ib<=std::size_t(TotBin); ++ib)
352 {
353 G4double loss=0.;
354 for (i=0; i<std::size_t(NumEl); ++i)
355 {
356 G4int IndEl = (*elementVector)[i]->GetIndex();
357 loss += atomicNumDensityVector[i]*
358 (*((*theLossTable)[IndEl]))[ib];
359 }
360 lossV.push_back(loss);
361 }
362
363 // Integrate with Simpson formula with logarithmic binning
364 G4double dltau = 1.0;
365 if (LowestEnergy>0.)
366 {
367 G4double ltt =std::log(MaxEnergyCut/LowestEnergy);
368 dltau = ltt/TotBin;
369 }
370
371 G4double s0 = 0.;
372 G4double Value;
373 for ( i=0; i<=std::size_t(TotBin); ++i )
374 {
375 G4double t = rangeVector->GetLowEdgeEnergy(i);
376 G4double q = t/lossV[i];
377 if (i==0) s0 += 0.5*q;
378 else s0 += q;
379
380 if (i==0)
381 {
382 Value = (s0 + 0.5*q)*dltau ;
383 }
384 else
385 {
386 Value = (s0 - 0.5*q)*dltau ;
387 }
388 rangeVector->PutValue(i,Value);
389 }
390}
std::vector< G4Element * > G4ElementVector
int G4int
Definition: G4Types.hh:85
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:188
size_t GetNumberOfElements() const
Definition: G4Material.hh:184
const G4double * GetAtomicNumDensityVector() const
Definition: G4Material.hh:214

Referenced by Convert().

◆ ComputeLoss()

virtual G4double G4VRangeToEnergyConverter::ComputeLoss ( G4double  AtomicNumber,
G4double  KineticEnergy 
)
protectedpure virtual

◆ Convert()

G4double G4VRangeToEnergyConverter::Convert ( G4double  rangeCut,
const G4Material material 
)
virtual

Reimplemented in G4RToEConvForProton.

Definition at line 138 of file G4VRangeToEnergyConverter.cc.

140{
141#ifdef G4VERBOSE
142 if (GetVerboseLevel()>3)
143 {
144 G4cout << "G4VRangeToEnergyConverter::Convert() - ";
145 G4cout << "Convert for " << material->GetName()
146 << " with Range Cut " << rangeCut/mm << "[mm]" << G4endl;
147 }
148#endif
149
150 G4double theKineticEnergyCuts = 0.;
151
153 {
155 // clear loss table and range vectors
156 Reset();
157 }
158
159 // Build the energy loss table
161
162 // Build range vector for every material, convert cut into energy-cut,
163 // fill theKineticEnergyCuts and delete the range vector
164 static const G4double tune = 0.025*mm*g/cm3, lowen = 30.*keV ;
165
166 // check density
167 G4double density = material->GetDensity() ;
168 if(density <= 0.)
169 {
170#ifdef G4VERBOSE
171 if (GetVerboseLevel()>0)
172 {
173 G4cout << "G4VRangeToEnergyConverter::Convert() - ";
174 G4cout << material->GetName() << "has zero density "
175 << "( " << density << ")" << G4endl;
176 }
177#endif
178 return 0.;
179 }
180
181 // initialise RangeVectorStore
183 G4int ext_size = table->size() - fRangeVectorStore.size();
184 for (G4int i=0; i<ext_size; ++i) fRangeVectorStore.push_back(nullptr);
185
186 // Build Range Vector
187 G4int idx = material->GetIndex();
188 G4RangeVector* rangeVector = fRangeVectorStore.at(idx);
189 if (rangeVector == nullptr)
190 {
191 rangeVector = new G4RangeVector(LowestEnergy, MaxEnergyCut, TotBin);
192 BuildRangeVector(material, rangeVector);
193 fRangeVectorStore.at(idx) = rangeVector;
194 }
195
196 // Convert Range Cut ro Kinetic Energy Cut
197 theKineticEnergyCuts = ConvertCutToKineticEnergy(rangeVector, rangeCut, idx);
198
199 if( ((theParticle->GetParticleName()=="e-")
200 ||(theParticle->GetParticleName()=="e+"))
201 &&(theKineticEnergyCuts < lowen) )
202 {
203 // corr. should be switched on smoothly
204 theKineticEnergyCuts /= (1.+(1.-theKineticEnergyCuts/lowen)
205 * tune/(rangeCut*density));
206 }
207
208 if(theKineticEnergyCuts < LowestEnergy)
209 {
210 theKineticEnergyCuts = LowestEnergy;
211 }
212 else if(theKineticEnergyCuts > MaxEnergyCut)
213 {
214 theKineticEnergyCuts = MaxEnergyCut;
215 }
216
217 return theKineticEnergyCuts;
218}
std::vector< G4Material * > G4MaterialTable
G4double GetDensity() const
Definition: G4Material.hh:178
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:637
const G4String & GetName() const
Definition: G4Material.hh:175
size_t GetIndex() const
Definition: G4Material.hh:258
const G4String & GetParticleName() const
std::vector< G4RangeVector * > fRangeVectorStore
virtual void BuildRangeVector(const G4Material *aMaterial, G4RangeVector *rangeVector)
G4double ConvertCutToKineticEnergy(G4RangeVector *theRangeVector, G4double theCutInLength, std::size_t materialIndex) const
const G4ParticleDefinition * theParticle

Referenced by G4ProductionCutsTable::ConvertRangeToEnergy(), and G4ProductionCutsTable::UpdateCoupleTable().

◆ ConvertCutToKineticEnergy()

G4double G4VRangeToEnergyConverter::ConvertCutToKineticEnergy ( G4RangeVector theRangeVector,
G4double  theCutInLength,
std::size_t  materialIndex 
) const
protected

Definition at line 395 of file G4VRangeToEnergyConverter.cc.

404{
405 const G4double epsilon = 0.01;
406
407 // find max. range and the corresponding energy (rmax,Tmax)
408 G4double rmax= -1.e10*mm;
409
411 G4double r1 =(*rangeVector)[0] ;
412
414
415 // check theCutInLength < r1
416 if ( theCutInLength <= r1 ) { return T1; }
417
418 // scan range vector to find nearest bin
419 // ( suppose that r(Ti) > r(Tj) if Ti >Tj )
420 for (std::size_t ibin=0; ibin<=std::size_t(TotBin); ++ibin)
421 {
422 G4double T=rangeVector->GetLowEdgeEnergy(ibin);
423 G4double r=(*rangeVector)[ibin];
424 if ( r>rmax ) rmax=r;
425 if (r <theCutInLength )
426 {
427 T1 = T;
428 r1 = r;
429 }
430 else if (r >theCutInLength )
431 {
432 T2 = T;
433 break;
434 }
435 }
436
437 // check cut in length is smaller than range max
438 if ( theCutInLength >= rmax )
439 {
440#ifdef G4VERBOSE
441 if (GetVerboseLevel()>2)
442 {
443 G4cout << "G4VRangeToEnergyConverter::ConvertCutToKineticEnergy ";
444 G4cout << " for " << theParticle->GetParticleName() << G4endl;
445 G4cout << "The cut in range [" << theCutInLength/mm << " (mm)] ";
446 G4cout << " is too big " ;
447 G4cout << " for material idx=" << materialIndex <<G4endl;
448 }
449#endif
450 return MaxEnergyCut;
451 }
452
453 // convert range to energy
454 G4double T3 = std::sqrt(T1*T2);
455 G4double r3 = rangeVector->Value(T3);
456 const std::size_t MAX_LOOP = 1000;
457 for (std::size_t loop_count=0; loop_count<MAX_LOOP; ++loop_count)
458 {
459 if (std::fabs(1.-r3/theCutInLength)<epsilon ) break;
460 if ( theCutInLength <= r3 )
461 {
462 T2 = T3;
463 }
464 else
465 {
466 T1 = T3;
467 }
468 T3 = std::sqrt(T1*T2);
469 r3 = rangeVector->Value(T3);
470 }
471 return T3;
472}
double epsilon(double density, double temperature)

Referenced by Convert().

◆ GetHighEdgeEnergy()

G4double G4VRangeToEnergyConverter::GetHighEdgeEnergy ( )
static

Definition at line 251 of file G4VRangeToEnergyConverter.cc.

252{
253 return HighestEnergy;
254}

Referenced by G4ProductionCutsTable::GetHighEdgeEnergy().

◆ GetLossTable()

const G4PhysicsTable * G4VRangeToEnergyConverter::GetLossTable ( ) const

◆ GetLowEdgeEnergy()

G4double G4VRangeToEnergyConverter::GetLowEdgeEnergy ( )
static

Definition at line 245 of file G4VRangeToEnergyConverter.cc.

246{
247 return LowestEnergy;
248}

Referenced by G4ProductionCutsTable::GetLowEdgeEnergy().

◆ GetMaxEnergyCut()

G4double G4VRangeToEnergyConverter::GetMaxEnergyCut ( )
static

Definition at line 259 of file G4VRangeToEnergyConverter.cc.

260{
261 return MaxEnergyCut;
262}

Referenced by G4ProductionCutsTable::GetMaxEnergyCut().

◆ GetParticleType()

const G4ParticleDefinition * G4VRangeToEnergyConverter::GetParticleType ( ) const
inline

Definition at line 161 of file G4VRangeToEnergyConverter.hh.

162{
163 return theParticle;
164}

◆ GetVerboseLevel()

◆ operator!=()

G4bool G4VRangeToEnergyConverter::operator!= ( const G4VRangeToEnergyConverter r) const

Definition at line 130 of file G4VRangeToEnergyConverter.cc.

131{
132 return this != &r;
133}

◆ operator=()

G4VRangeToEnergyConverter & G4VRangeToEnergyConverter::operator= ( const G4VRangeToEnergyConverter r)

Definition at line 58 of file G4VRangeToEnergyConverter.cc.

59{
60 if (this == &right) return *this;
61
62 if (theLossTable != nullptr)
63 {
65 delete theLossTable;
66 }
67
68 fMaxEnergyCut = right.fMaxEnergyCut;
69 NumberOfElements = right.NumberOfElements;
70 theParticle = right.theParticle;
71 verboseLevel = right.verboseLevel;
72
73 // create the loss table
76 // fill the loss table
77 for (std::size_t j=0; j<std::size_t(NumberOfElements); ++j)
78 {
80 for (std::size_t i=0; i<=std::size_t(TotBin); ++i)
81 {
82 G4double Value = (*((*right.theLossTable)[j]))[i];
83 aVector->PutValue(i,Value);
84 }
85 theLossTable->insert(aVector);
86 }
87
88 // clean up range vector store
89 for (std::size_t idx=0; idx<fRangeVectorStore.size(); ++idx)
90 {
91 delete fRangeVectorStore.at(idx);
92 }
93 fRangeVectorStore.clear();
94
95 // copy range vector store
96 for (std::size_t j=0; j<((right.fRangeVectorStore).size()); ++j)
97 {
98 G4RangeVector* vector = (right.fRangeVectorStore).at(j);
99 G4RangeVector* rangeVector = nullptr;
100 if (vector != nullptr )
101 {
102 rangeVector = new G4RangeVector(LowestEnergy, MaxEnergyCut, TotBin);
104 for (std::size_t i=0; i<=std::size_t(TotBin); ++i)
105 {
106 G4double Value = (*vector)[i];
107 rangeVector->PutValue(i,Value);
108 }
109 }
110 fRangeVectorStore.push_back(rangeVector);
111 }
112 return *this;
113}
void clearAndDestroy()

◆ operator==()

G4bool G4VRangeToEnergyConverter::operator== ( const G4VRangeToEnergyConverter r) const

Definition at line 123 of file G4VRangeToEnergyConverter.cc.

124{
125 return this == &r;
126}

◆ Reset()

void G4VRangeToEnergyConverter::Reset ( )
virtual

Reimplemented in G4RToEConvForProton.

Definition at line 273 of file G4VRangeToEnergyConverter.cc.

274{
275 // delete loss table
276 if (theLossTable != nullptr)
277 {
279 delete theLossTable;
280 }
281 theLossTable = nullptr;
283
284 // clear RangeVectorStore
285 for (std::size_t idx=0; idx<fRangeVectorStore.size(); ++idx)
286 {
287 delete fRangeVectorStore.at(idx);
288 }
289 fRangeVectorStore.clear();
290}

Referenced by BuildLossTable(), Convert(), G4ProductionCutsTable::ResetConverters(), and ~G4VRangeToEnergyConverter().

◆ SetEnergyRange()

void G4VRangeToEnergyConverter::SetEnergyRange ( G4double  lowedge,
G4double  highedge 
)
static

Definition at line 223 of file G4VRangeToEnergyConverter.cc.

225{
226 // check LowestEnergy/ HighestEnergy
227 if ( (lowedge<0.0)||(highedge<=lowedge) )
228 {
229#ifdef G4VERBOSE
230 G4cerr << "Error in G4VRangeToEnergyConverter::SetEnergyRange()";
231 G4cerr << ": illegal energy range" << "(" << lowedge/GeV;
232 G4cerr << "," << highedge/GeV << ") [GeV]" << G4endl;
233#endif
234 G4Exception( "G4VRangeToEnergyConverter::SetEnergyRange()",
235 "ProcCuts101", JustWarning, "Illegal energy range");
236 }
237 else
238 {
239 LowestEnergy = lowedge;
240 HighestEnergy = highedge;
241 }
242}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
G4GLOB_DLL std::ostream G4cerr

Referenced by G4ProductionCutsTable::SetEnergyRange().

◆ SetMaxEnergyCut()

void G4VRangeToEnergyConverter::SetMaxEnergyCut ( G4double  value)
static

Definition at line 265 of file G4VRangeToEnergyConverter.cc.

266{
267 MaxEnergyCut = value;
268}

Referenced by G4ProductionCutsTable::SetMaxEnergyCut().

◆ SetVerboseLevel()

void G4VRangeToEnergyConverter::SetVerboseLevel ( G4int  value)
inline

Definition at line 149 of file G4VRangeToEnergyConverter.hh.

150{
151 verboseLevel = value;
152}

Referenced by G4ProductionCutsTable::SetVerboseLevel(), and G4ProductionCutsTable::UpdateCoupleTable().

Member Data Documentation

◆ fMaxEnergyCut

G4double G4VRangeToEnergyConverter::fMaxEnergyCut = 0.0
protected

Definition at line 129 of file G4VRangeToEnergyConverter.hh.

Referenced by Convert(), and operator=().

◆ fRangeVectorStore

std::vector< G4RangeVector* > G4VRangeToEnergyConverter::fRangeVectorStore
protected

Definition at line 137 of file G4VRangeToEnergyConverter.hh.

Referenced by Convert(), operator=(), and Reset().

◆ HighestEnergy

G4double G4VRangeToEnergyConverter::HighestEnergy = 100.0e6*MeV
staticprotected

Definition at line 127 of file G4VRangeToEnergyConverter.hh.

Referenced by GetHighEdgeEnergy(), and SetEnergyRange().

◆ LowestEnergy

G4double G4VRangeToEnergyConverter::LowestEnergy = 0.99e-3*MeV
staticprotected

◆ MaxEnergyCut

G4double G4VRangeToEnergyConverter::MaxEnergyCut = 10.0*GeV
staticprotected

◆ NumberOfElements

G4int G4VRangeToEnergyConverter::NumberOfElements = 0
protected

Definition at line 133 of file G4VRangeToEnergyConverter.hh.

Referenced by BuildLossTable(), operator=(), and Reset().

◆ theLossTable

G4LossTable* G4VRangeToEnergyConverter::theLossTable = nullptr
protected

◆ theParticle

◆ TotBin

const G4int G4VRangeToEnergyConverter::TotBin = 300
protected

The documentation for this class was generated from the following files: