Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleHPVector Class Reference

#include <G4ParticleHPVector.hh>

Public Member Functions

 G4ParticleHPVector ()
 
 G4ParticleHPVector (G4int n)
 
 ~G4ParticleHPVector ()
 
G4ParticleHPVectoroperator= (const G4ParticleHPVector &right)
 
void SetVerbose (G4int ff)
 
void Times (G4double factor)
 
void SetPoint (G4int i, const G4ParticleHPDataPoint &it)
 
void SetData (G4int i, G4double x, G4double y)
 
void SetX (G4int i, G4double e)
 
void SetEnergy (G4int i, G4double e)
 
void SetY (G4int i, G4double x)
 
void SetXsec (G4int i, G4double x)
 
G4double GetEnergy (G4int i) const
 
G4double GetXsec (G4int i)
 
G4double GetX (G4int i) const
 
const G4ParticleHPDataPointGetPoint (G4int i) const
 
void Hash ()
 
void ReHash ()
 
G4double GetXsec (G4double e)
 
G4double GetXsec (G4double e, G4int min)
 
G4double GetY (G4double x)
 
G4int GetVectorLength () const
 
G4double GetY (G4int i)
 
G4double GetY (G4int i) const
 
void Dump ()
 
void InitInterpolation (std::istream &aDataFile)
 
void Init (std::istream &aDataFile, G4int total, G4double ux=1., G4double uy=1.)
 
void Init (std::istream &aDataFile, G4double ux=1., G4double uy=1.)
 
void ThinOut (G4double precision)
 
void SetLabel (G4double aLabel)
 
G4double GetLabel ()
 
void CleanUp ()
 
void Merge (G4ParticleHPVector *active, G4ParticleHPVector *passive)
 
void Merge (G4InterpolationScheme aScheme, G4double aValue, G4ParticleHPVector *active, G4ParticleHPVector *passive)
 
G4double SampleLin ()
 
G4double Sample ()
 
G4doubleDebug ()
 
void IntegrateAndNormalise ()
 
void Integrate ()
 
G4double GetIntegral ()
 
void SetInterpolationManager (const G4InterpolationManager &aManager)
 
const G4InterpolationManagerGetInterpolationManager () const
 
void SetInterpolationManager (G4InterpolationManager &aMan)
 
void SetScheme (G4int aPoint, const G4InterpolationScheme &aScheme)
 
G4InterpolationScheme GetScheme (G4int anIndex)
 
G4double GetMeanX ()
 
G4double GetMaxY (G4double emin, G4double emax)
 
std::vector< G4doubleGetBlocked ()
 
std::vector< G4doubleGetBuffered ()
 
G4double Get15percentBorder ()
 
G4double Get50percentBorder ()
 

Friends

G4ParticleHPVectoroperator+ (G4ParticleHPVector &left, G4ParticleHPVector &right)
 

Detailed Description

Definition at line 56 of file G4ParticleHPVector.hh.

Constructor & Destructor Documentation

◆ G4ParticleHPVector() [1/2]

G4ParticleHPVector::G4ParticleHPVector ( )

Definition at line 80 of file G4ParticleHPVector.cc.

81{
82 theData = new G4ParticleHPDataPoint[20];
83 nPoints = 20;
84 nEntries = 0;
85 Verbose = 0;
86 theIntegral = nullptr;
87 totalIntegral = -1;
88 isFreed = 0;
89 maxValue = -DBL_MAX;
90 the15percentBorderCash = -DBL_MAX;
91 the50percentBorderCash = -DBL_MAX;
92 label = -DBL_MAX;
93}
#define DBL_MAX
Definition templates.hh:62

◆ G4ParticleHPVector() [2/2]

G4ParticleHPVector::G4ParticleHPVector ( G4int n)

Definition at line 95 of file G4ParticleHPVector.cc.

96{
97 nPoints = std::max(n, 20);
98 theData = new G4ParticleHPDataPoint[nPoints];
99 nEntries = 0;
100 Verbose = 0;
101 theIntegral = nullptr;
102 totalIntegral = -1;
103 isFreed = 0;
104 maxValue = -DBL_MAX;
105 the15percentBorderCash = -DBL_MAX;
106 the50percentBorderCash = -DBL_MAX;
107 label = -DBL_MAX;
108}

◆ ~G4ParticleHPVector()

G4ParticleHPVector::~G4ParticleHPVector ( )

Definition at line 110 of file G4ParticleHPVector.cc.

111{
112 // if(Verbose==1)G4cout <<"G4ParticleHPVector::~G4ParticleHPVector"<<G4endl;
113 delete[] theData;
114 // if(Verbose==1)G4cout <<"Vector: delete theData"<<G4endl;
115 delete[] theIntegral;
116 // if(Verbose==1)G4cout <<"Vector: delete theIntegral"<<G4endl;
117 theHash.Clear();
118 isFreed = 1;
119}

Member Function Documentation

◆ CleanUp()

void G4ParticleHPVector::CleanUp ( )
inline

Definition at line 233 of file G4ParticleHPVector.hh.

234 {
235 nEntries = 0;
236 theManager.CleanUp();
237 maxValue = -DBL_MAX;
238 theHash.Clear();
239 // 080811 TK DB
240 delete[] theIntegral;
241 theIntegral = nullptr;
242 }

Referenced by Merge(), and Merge().

◆ Debug()

G4double * G4ParticleHPVector::Debug ( )
inline

Definition at line 339 of file G4ParticleHPVector.hh.

339{ return theIntegral; }

◆ Dump()

void G4ParticleHPVector::Dump ( )

Definition at line 194 of file G4ParticleHPVector.cc.

195{
196 G4cout << nEntries << G4endl;
197 for (G4int i = 0; i < nEntries; i++) {
198 G4cout << theData[i].GetX() << " ";
199 G4cout << theData[i].GetY() << " ";
200 // if (i!=1&&i==5*(i/5)) G4cout << G4endl;
201 G4cout << G4endl;
202 }
203 G4cout << G4endl;
204}
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

◆ Get15percentBorder()

G4double G4ParticleHPVector::Get15percentBorder ( )

Definition at line 460 of file G4ParticleHPVector.cc.

461{
462 if (the15percentBorderCash > -DBL_MAX / 2.) return the15percentBorderCash;
463 G4double result;
464 if (GetVectorLength() == 1) {
465 result = theData[0].GetX();
466 the15percentBorderCash = result;
467 }
468 else {
469 if (theIntegral == nullptr) {
471 }
472 G4int i;
473 result = theData[GetVectorLength() - 1].GetX();
474 for (i = 0; i < GetVectorLength(); i++) {
475 if (theIntegral[i] / theIntegral[GetVectorLength() - 1] > 0.15) {
476 result = theData[std::min(i + 1, GetVectorLength() - 1)].GetX();
477 the15percentBorderCash = result;
478 break;
479 }
480 }
481 the15percentBorderCash = result;
482 }
483 return result;
484}
double G4double
Definition G4Types.hh:83
G4int GetVectorLength() const

◆ Get50percentBorder()

G4double G4ParticleHPVector::Get50percentBorder ( )

Definition at line 486 of file G4ParticleHPVector.cc.

487{
488 if (the50percentBorderCash > -DBL_MAX / 2.) return the50percentBorderCash;
489 G4double result;
490 if (GetVectorLength() == 1) {
491 result = theData[0].GetX();
492 the50percentBorderCash = result;
493 }
494 else {
495 if (theIntegral == nullptr) {
497 }
498 G4int i;
499 G4double x = 0.5;
500 result = theData[GetVectorLength() - 1].GetX();
501 for (i = 0; i < GetVectorLength(); i++) {
502 if (theIntegral[i] / theIntegral[GetVectorLength() - 1] > x) {
503 G4int it;
504 it = i;
505 if (it == GetVectorLength() - 1) {
506 result = theData[GetVectorLength() - 1].GetX();
507 }
508 else {
509 G4double x1, x2, y1, y2;
510 x1 = theIntegral[i - 1] / theIntegral[GetVectorLength() - 1];
511 x2 = theIntegral[i] / theIntegral[GetVectorLength() - 1];
512 y1 = theData[i - 1].GetX();
513 y2 = theData[i].GetX();
514 result = theLin.Lin(x, x1, x2, y1, y2);
515 }
516 the50percentBorderCash = result;
517 break;
518 }
519 }
520 the50percentBorderCash = result;
521 }
522 return result;
523}
G4double Lin(G4double x, G4double x1, G4double x2, G4double y1, G4double y2)

◆ GetBlocked()

std::vector< G4double > G4ParticleHPVector::GetBlocked ( )
inline

Definition at line 494 of file G4ParticleHPVector.hh.

494{ return theBlocked; }

◆ GetBuffered()

std::vector< G4double > G4ParticleHPVector::GetBuffered ( )
inline

Definition at line 495 of file G4ParticleHPVector.hh.

495{ return theBuffered; }

◆ GetEnergy()

G4double G4ParticleHPVector::GetEnergy ( G4int i) const
inline

◆ GetIntegral()

G4double G4ParticleHPVector::GetIntegral ( )
inline

Definition at line 440 of file G4ParticleHPVector.hh.

441 {
442 if (totalIntegral < -0.5) Integrate();
443 return totalIntegral;
444 }

◆ GetInterpolationManager()

const G4InterpolationManager & G4ParticleHPVector::GetInterpolationManager ( ) const
inline

Definition at line 451 of file G4ParticleHPVector.hh.

451{ return theManager; }

Referenced by G4ParticleHPLabAngularEnergy::Sample().

◆ GetLabel()

G4double G4ParticleHPVector::GetLabel ( )
inline

Definition at line 231 of file G4ParticleHPVector.hh.

231{ return label; }

Referenced by Merge(), G4ParticleHPArbitaryTab::Sample(), and G4ParticleHPLabAngularEnergy::Sample().

◆ GetMaxY()

G4double G4ParticleHPVector::GetMaxY ( G4double emin,
G4double emax )

Definition at line 525 of file G4ParticleHPVector.cc.

526{
527 G4double xsmax = 0.;
528 if (emin > emax || nEntries == 0) return xsmax;
529 if (emin >= theData[nEntries - 1].GetX()) {
530 xsmax = theData[nEntries - 1].GetY();
531 return xsmax;
532 }
533 if (emax <= theData[0].GetX()) {
534 xsmax = theData[0].GetY();
535 return xsmax;
536 }
537 if (!theHash.Prepared() && !G4Threading::IsWorkerThread()) Hash();
538 // Find the lowest index, low, where x(energy) is higher than emin
539 G4int i = theHash.GetMinIndex(emin);
540 for (; i < nEntries; ++i) {
541 if (theData[i].GetX() >= emin) break;
542 }
543 G4int low = i;
544 // Find the lowest index, high, where x(energy) is higher than emax
545 i = theHash.GetMinIndex(emax);
546 for (; i < nEntries; ++i) {
547 if (theData[i].GetX() >= emax) break;
548 }
549 G4int high = i;
550 xsmax = GetXsec(emin); // Set xsmax as low border
551 // Find the highest cross-section
552 for (i = low; i < high; ++i) {
553 if (xsmax < theData[i].GetY()) xsmax = theData[i].GetY();
554 }
555 // Check if it is smaller than the high border (e.g. as for a monotonic increasing cross-section)
556 G4double highborder = GetXsec(emax);
557 if (xsmax < highborder) xsmax = highborder;
558
559 if (xsmax == 0.) {
560 throw G4HadronicException(__FILE__, __LINE__,
561 "G4ParticleHPVector::GetMaxY : called "
562 "G4Nucleus::GetBiasedThermalNucleus for DBRC, xsmax==0.");
563 }
564
565 return xsmax;
566}
G4bool Prepared() const
G4int GetMinIndex(G4double e) const
G4double GetXsec(G4int i)
G4double GetY(G4double x)
G4double GetX(G4int i) const
G4bool IsWorkerThread()

◆ GetMeanX()

G4double G4ParticleHPVector::GetMeanX ( )
inline

Definition at line 462 of file G4ParticleHPVector.hh.

463 {
464 G4double result;
465 G4double running = 0;
466 G4double weighted = 0;
467 for (G4int i = 1; i < nEntries; i++) {
468 running +=
469 theInt.GetBinIntegral(theManager.GetScheme(i - 1), theData[i - 1].GetX(),
470 theData[i].GetX(), theData[i - 1].GetY(), theData[i].GetY());
471 weighted += theInt.GetWeightedBinIntegral(theManager.GetScheme(i - 1),
472 theData[i - 1].GetX(), theData[i].GetX(),
473 theData[i - 1].GetY(), theData[i].GetY());
474 }
475 result = weighted / running;
476 return result;
477 }
G4InterpolationScheme GetScheme(G4int index) const
G4double GetWeightedBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
G4double GetBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)

Referenced by G4ParticleHPLabAngularEnergy::Sample().

◆ GetPoint()

const G4ParticleHPDataPoint & G4ParticleHPVector::GetPoint ( G4int i) const
inline

Definition at line 126 of file G4ParticleHPVector.hh.

126{ return theData[i]; }

Referenced by G4ParticleHPIsoData::FillChannelData(), and operator=().

◆ GetScheme()

G4InterpolationScheme G4ParticleHPVector::GetScheme ( G4int anIndex)
inline

Definition at line 460 of file G4ParticleHPVector.hh.

460{ return theManager.GetScheme(anIndex); }

Referenced by Merge(), and Merge().

◆ GetVectorLength()

◆ GetX()

◆ GetXsec() [1/3]

G4double G4ParticleHPVector::GetXsec ( G4double e)

Definition at line 143 of file G4ParticleHPVector.cc.

144{
145 if (nEntries == 0) return 0;
146 // if(!theHash.Prepared()) Hash();
147 if (!theHash.Prepared()) {
149 ;
150 }
151 else {
152 Hash();
153 }
154 }
155 G4int min = theHash.GetMinIndex(e);
156 G4int i;
157 for (i = min; i < nEntries; i++) {
158 // if(theData[i].GetX()>e) break;
159 if (theData[i].GetX() >= e) break;
160 }
161 G4int low = i - 1;
162 G4int high = i;
163 if (i == 0) {
164 low = 0;
165 high = 1;
166 }
167 else if (i == nEntries) {
168 low = nEntries - 2;
169 high = nEntries - 1;
170 }
171 G4double y;
172 if (e < theData[nEntries - 1].GetX()) {
173 // Protect against doubled-up x values
174 // if( (theData[high].GetX()-theData[low].GetX())/theData[high].GetX() < 0.000001)
175 if (theData[high].GetX() != 0
176 // 080808 TKDB
177 //&&( theData[high].GetX()-theData[low].GetX())/theData[high].GetX() < 0.000001)
178 && (std::abs((theData[high].GetX() - theData[low].GetX()) / theData[high].GetX())
179 < 0.000001))
180 {
181 y = theData[low].GetY();
182 }
183 else {
184 y = theInt.Interpolate(theManager.GetScheme(high), e, theData[low].GetX(),
185 theData[high].GetX(), theData[low].GetY(), theData[high].GetY());
186 }
187 }
188 else {
189 y = theData[nEntries - 1].GetY();
190 }
191 return y;
192}
G4double Interpolate(G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
T min(const T t1, const T t2)
brief Return the smallest of the two arguments

◆ GetXsec() [2/3]

G4double G4ParticleHPVector::GetXsec ( G4double e,
G4int min )
inline

Definition at line 148 of file G4ParticleHPVector.hh.

149 {
150 G4int i;
151 for (i = min; i < nEntries; i++) {
152 if (theData[i].GetX() > e) break;
153 }
154 G4int low = i - 1;
155 G4int high = i;
156 if (i == 0) {
157 low = 0;
158 high = 1;
159 }
160 else if (i == nEntries) {
161 low = nEntries - 2;
162 high = nEntries - 1;
163 }
164 G4double y;
165 if (e < theData[nEntries - 1].GetX()) {
166 // Protect against doubled-up x values
167 if ((theData[high].GetX() - theData[low].GetX()) / theData[high].GetX() < 0.000001) {
168 y = theData[low].GetY();
169 }
170 else {
171 y = theInt.Interpolate(theManager.GetScheme(high), e, theData[low].GetX(),
172 theData[high].GetX(), theData[low].GetY(), theData[high].GetY());
173 }
174 }
175 else {
176 y = theData[nEntries - 1].GetY();
177 }
178 return y;
179 }

◆ GetXsec() [3/3]

◆ GetY() [1/3]

◆ GetY() [2/3]

G4double G4ParticleHPVector::GetY ( G4int i)
inline

Definition at line 184 of file G4ParticleHPVector.hh.

185 {
186 if (i < 0) i = 0;
187 if (i >= GetVectorLength()) i = GetVectorLength() - 1;
188 return theData[i].GetY();
189 }

◆ GetY() [3/3]

G4double G4ParticleHPVector::GetY ( G4int i) const
inline

Definition at line 191 of file G4ParticleHPVector.hh.

192 {
193 if (i < 0) i = 0;
194 if (i >= GetVectorLength()) i = GetVectorLength() - 1;
195 return theData[i].GetY();
196 }

◆ Hash()

void G4ParticleHPVector::Hash ( )
inline

Definition at line 128 of file G4ParticleHPVector.hh.

129 {
130 G4int i;
131 G4double x, y;
132 for (i = 0; i < nEntries; i++) {
133 if (0 == (i + 1) % 10) {
134 x = GetX(i);
135 y = GetY(i);
136 theHash.SetData(i, x, y);
137 }
138 }
139 }
void SetData(G4int index, G4double x, G4double y)

Referenced by G4ParticleHPPartial::DoneSetXY(), G4ParticleHPIsoData::FillChannelData(), GetMaxY(), GetXsec(), G4ParticleHPProduct::Init(), G4ParticleHPPartial::InitData(), G4ParticleHPChannel::Register(), and ReHash().

◆ Init() [1/2]

void G4ParticleHPVector::Init ( std::istream & aDataFile,
G4double ux = 1.,
G4double uy = 1. )
inline

Definition at line 215 of file G4ParticleHPVector.hh.

216 {
217 G4int total;
218 aDataFile >> total;
219 delete[] theData;
220 theData = new G4ParticleHPDataPoint[total];
221 nPoints = total;
222 nEntries = 0;
223 theManager.Init(aDataFile);
224 Init(aDataFile, total, ux, uy);
225 }
void Init(G4int aScheme, G4int aRange)
void Init(std::istream &aDataFile, G4int total, G4double ux=1., G4double uy=1.)
G4double total(Particle const *const p1, Particle const *const p2)

◆ Init() [2/2]

◆ InitInterpolation()

void G4ParticleHPVector::InitInterpolation ( std::istream & aDataFile)
inline

Definition at line 199 of file G4ParticleHPVector.hh.

199{ theManager.Init(aDataFile); }

Referenced by G4ParticleHPPartial::InitData(), and G4ParticleHPPartial::InitInterpolation().

◆ Integrate()

void G4ParticleHPVector::Integrate ( )
inline

Definition at line 393 of file G4ParticleHPVector.hh.

394 {
395 G4int i;
396 if (nEntries == 1) {
397 totalIntegral = 0;
398 return;
399 }
400 G4double sum = 0;
401 for (i = 1; i < GetVectorLength(); i++) {
402 if (std::abs((theData[i].GetX() - theData[i - 1].GetX()) / theData[i].GetX()) > 0.0000001) {
403 G4double x1 = theData[i - 1].GetX();
404 G4double x2 = theData[i].GetX();
405 G4double y1 = theData[i - 1].GetY();
406 G4double y2 = theData[i].GetY();
407 G4InterpolationScheme aScheme = theManager.GetScheme(i);
408 if (aScheme == LINLIN || aScheme == CLINLIN || aScheme == ULINLIN) {
409 sum += 0.5 * (y2 + y1) * (x2 - x1);
410 }
411 else if (aScheme == LINLOG || aScheme == CLINLOG || aScheme == ULINLOG) {
412 G4double a = y1;
413 G4double b = (y2 - y1) / (G4Log(x2) - G4Log(x1));
414 sum += (a - b) * (x2 - x1) + b * (x2 * G4Log(x2) - x1 * G4Log(x1));
415 }
416 else if (aScheme == LOGLIN || aScheme == CLOGLIN || aScheme == ULOGLIN) {
417 G4double a = G4Log(y1);
418 G4double b = (G4Log(y2) - G4Log(y1)) / (x2 - x1);
419 sum += (G4Exp(a) / b) * (G4Exp(b * x2) - G4Exp(b * x1));
420 }
421 else if (aScheme == HISTO || aScheme == CHISTO || aScheme == UHISTO) {
422 sum += y1 * (x2 - x1);
423 }
424 else if (aScheme == LOGLOG || aScheme == CLOGLOG || aScheme == ULOGLOG) {
425 G4double a = G4Log(y1);
426 G4double b = (G4Log(y2) - G4Log(y1)) / (G4Log(x2) - G4Log(x1));
427 sum +=
428 (G4Exp(a) / (b + 1))
429 * (G4Pow::GetInstance()->powA(x2, b + 1) - G4Pow::GetInstance()->powA(x1, b + 1));
430 }
431 else {
433 __FILE__, __LINE__, "Unknown interpolation scheme in G4ParticleHPVector::Integrate");
434 }
435 }
436 }
437 totalIntegral = sum;
438 }
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition G4Exp.hh:180
G4InterpolationScheme
G4double G4Log(G4double x)
Definition G4Log.hh:227
static G4Pow * GetInstance()
Definition G4Pow.cc:41
G4double powA(G4double A, G4double y) const
Definition G4Pow.hh:230

Referenced by GetIntegral().

◆ IntegrateAndNormalise()

void G4ParticleHPVector::IntegrateAndNormalise ( )
inline

Definition at line 341 of file G4ParticleHPVector.hh.

342 {
343 G4int i;
344 if (theIntegral != nullptr) return;
345 theIntegral = new G4double[nEntries];
346 if (nEntries == 1) {
347 theIntegral[0] = 1;
348 return;
349 }
350 theIntegral[0] = 0;
351 G4double sum = 0;
352 G4double x1 = 0;
353 G4double x0 = 0;
354 for (i = 1; i < GetVectorLength(); i++) {
355 x1 = theData[i].GetX();
356 x0 = theData[i - 1].GetX();
357 if (std::abs(x1 - x0) > std::abs(x1 * 0.0000001)) {
358 //********************************************************************
359 // EMendoza -> the interpolation scheme is not always lin-lin
360 /*
361 sum+= 0.5*(theData[i].GetY()+theData[i-1].GetY())*
362 (x1-x0);
363 */
364 //********************************************************************
365 G4InterpolationScheme aScheme = theManager.GetScheme(i);
366 G4double y0 = theData[i - 1].GetY();
367 G4double y1 = theData[i].GetY();
368 G4double integ = theInt.GetBinIntegral(aScheme, x0, x1, y0, y1);
369#if defined WIN32 - VC
370 if (!_finite(integ)) {
371 integ = 0;
372 }
373#elif defined __IBMCPP__
374 if (isinf(integ) || isnan(integ)) {
375 integ = 0;
376 }
377#else
378 if (std::isinf(integ) || std::isnan(integ)) {
379 integ = 0;
380 }
381#endif
382 sum += integ;
383 //********************************************************************
384 }
385 theIntegral[i] = sum;
386 }
387 G4double total = theIntegral[GetVectorLength() - 1];
388 for (i = 1; i < GetVectorLength(); i++) {
389 theIntegral[i] /= total;
390 }
391 }

Referenced by Get15percentBorder(), Get50percentBorder(), G4ParticleHPArbitaryTab::Init(), Sample(), and SampleLin().

◆ Merge() [1/2]

void G4ParticleHPVector::Merge ( G4InterpolationScheme aScheme,
G4double aValue,
G4ParticleHPVector * active,
G4ParticleHPVector * passive )

Definition at line 222 of file G4ParticleHPVector.cc.

224{
225 // interpolate between labels according to aScheme, cut at aValue,
226 // continue in unknown areas by substraction of the last difference.
227
228 CleanUp();
229 G4int s_tmp = 0, n = 0, m_tmp = 0;
231 G4int a = s_tmp, p = n, t;
232 while (a < active->GetVectorLength()) // Loop checking, 11.05.2015, T. Koi
233 {
234 if (active->GetEnergy(a) <= passive->GetEnergy(p)) {
235 G4double xa = active->GetEnergy(a);
236 G4double yy = theInt.Interpolate(aScheme, aValue, active->GetLabel(), passive->GetLabel(),
237 active->GetXsec(a), passive->GetXsec(xa));
238 SetData(m_tmp, xa, yy);
239 theManager.AppendScheme(m_tmp, active->GetScheme(a));
240 m_tmp++;
241 a++;
242 G4double xp = passive->GetEnergy(p);
243 // if( std::abs(std::abs(xp-xa)/xa)<0.0000001&&a<active->GetVectorLength() )
244 if (xa != 0 && std::abs(std::abs(xp - xa) / xa) < 0.0000001 && a < active->GetVectorLength())
245 {
246 p++;
247 tmp = active;
248 t = a;
249 active = passive;
250 a = p;
251 passive = tmp;
252 p = t;
253 }
254 }
255 else {
256 tmp = active;
257 t = a;
258 active = passive;
259 a = p;
260 passive = tmp;
261 p = t;
262 }
263 }
264
265 G4double deltaX = passive->GetXsec(GetEnergy(m_tmp - 1)) - GetXsec(m_tmp - 1);
266 while (p != passive->GetVectorLength()
267 && passive->GetEnergy(p) <= aValue) // Loop checking, 11.05.2015, T. Koi
268 {
269 G4double anX;
270 anX = passive->GetXsec(p) - deltaX;
271 if (anX > 0) {
272 // if(std::abs(GetEnergy(m-1)-passive->GetEnergy(p))/passive->GetEnergy(p)>0.0000001)
273 if (passive->GetEnergy(p) == 0
274 || std::abs(GetEnergy(m_tmp - 1) - passive->GetEnergy(p)) / passive->GetEnergy(p)
275 > 0.0000001)
276 {
277 SetData(m_tmp, passive->GetEnergy(p), anX);
278 theManager.AppendScheme(m_tmp++, passive->GetScheme(p));
279 }
280 }
281 p++;
282 }
283 // Rebuild the Hash;
284 if (theHash.Prepared()) {
285 ReHash();
286 }
287}
void AppendScheme(G4int aPoint, const G4InterpolationScheme &aScheme)
G4InterpolationScheme GetScheme(G4int anIndex)
G4double GetEnergy(G4int i) const

◆ Merge() [2/2]

void G4ParticleHPVector::Merge ( G4ParticleHPVector * active,
G4ParticleHPVector * passive )
inline

Definition at line 245 of file G4ParticleHPVector.hh.

246 {
247 CleanUp();
248 G4int s_tmp = 0, n = 0, m_tmp = 0;
250 G4int a = s_tmp, p = n, t;
251 while (a < active->GetVectorLength()
252 && p < passive->GetVectorLength()) // Loop checking, 11.05.2015, T. Koi
253 {
254 if (active->GetEnergy(a) <= passive->GetEnergy(p)) {
255 G4double xa = active->GetEnergy(a);
256 G4double yy = active->GetXsec(a);
257 SetData(m_tmp, xa, yy);
258 theManager.AppendScheme(m_tmp, active->GetScheme(a));
259 m_tmp++;
260 a++;
261 G4double xp = passive->GetEnergy(p);
262
263 // 080409 TKDB
264 // if( std::abs(std::abs(xp-xa)/xa)<0.001 ) p++;
265 if (!(xa == 0) && std::abs(std::abs(xp - xa) / xa) < 0.001) p++;
266 }
267 else {
268 tmp = active;
269 t = a;
270 active = passive;
271 a = p;
272 passive = tmp;
273 p = t;
274 }
275 }
276 while (a != active->GetVectorLength()) // Loop checking, 11.05.2015, T. Koi
277 {
278 SetData(m_tmp, active->GetEnergy(a), active->GetXsec(a));
279 theManager.AppendScheme(m_tmp++, active->GetScheme(a));
280 a++;
281 }
282 while (p != passive->GetVectorLength()) // Loop checking, 11.05.2015, T. Koi
283 {
284 if (std::abs(GetEnergy(m_tmp - 1) - passive->GetEnergy(p)) / passive->GetEnergy(p) > 0.001)
285 // if(std::abs(GetEnergy(m)-passive->GetEnergy(p))/passive->GetEnergy(p)>0.001)
286 {
287 SetData(m_tmp, passive->GetEnergy(p), passive->GetXsec(p));
288 theManager.AppendScheme(m_tmp++, active->GetScheme(p));
289 }
290 p++;
291 }
292 }

Referenced by G4ParticleHPDiscreteTwoBody::Sample(), and G4ParticleHPLabAngularEnergy::Sample().

◆ operator=()

G4ParticleHPVector & G4ParticleHPVector::operator= ( const G4ParticleHPVector & right)

Definition at line 121 of file G4ParticleHPVector.cc.

122{
123 if (&right == this) return *this;
124
125 G4int i;
126
127 totalIntegral = right.totalIntegral;
128 if (right.theIntegral != nullptr) theIntegral = new G4double[right.nEntries];
129 for (i = 0; i < right.nEntries; i++) {
130 SetPoint(i, right.GetPoint(i)); // copy theData
131 if (right.theIntegral != nullptr) theIntegral[i] = right.theIntegral[i];
132 }
133 theManager = right.theManager;
134 label = right.label;
135
136 Verbose = right.Verbose;
137 the15percentBorderCash = right.the15percentBorderCash;
138 the50percentBorderCash = right.the50percentBorderCash;
139 theHash = right.theHash;
140 return *this;
141}
const G4ParticleHPDataPoint & GetPoint(G4int i) const
void SetPoint(G4int i, const G4ParticleHPDataPoint &it)

◆ ReHash()

void G4ParticleHPVector::ReHash ( )
inline

Definition at line 141 of file G4ParticleHPVector.hh.

142 {
143 theHash.Clear();
144 Hash();
145 }

Referenced by Merge(), and ThinOut().

◆ Sample()

G4double G4ParticleHPVector::Sample ( )

Definition at line 363 of file G4ParticleHPVector.cc.

364{
365 G4double result = 0.;
366 G4int j;
367 for (j = 0; j < GetVectorLength(); j++) {
368 if (GetY(j) < 0) SetY(j, 0);
369 }
370
371 if (!theBuffered.empty() && G4UniformRand() < 0.5) {
372 result = theBuffered[0];
373 theBuffered.erase(theBuffered.begin());
374 if (result < GetX(GetVectorLength() - 1)) return result;
375 }
376 if (GetVectorLength() == 1) {
377 result = theData[0].GetX();
378 }
379 else {
380 if (theIntegral == nullptr) {
382 }
383 G4int icounter = 0;
384 G4int icounter_max = 1024;
385 do {
386 icounter++;
387 if (icounter > icounter_max) {
388 G4cout << "Loop-counter exceeded the threshold value at " << __LINE__ << "th line of "
389 << __FILE__ << "." << G4endl;
390 break;
391 }
392 // 080808
393 /*
394 G4double rand;
395 G4double value, test, baseline;
396 baseline = theData[GetVectorLength()-1].GetX()-theData[0].GetX();
397 do
398 {
399 value = baseline*G4UniformRand();
400 value += theData[0].GetX();
401 test = GetY(value)/maxValue;
402 rand = G4UniformRand();
403 }
404 //while(test<rand);
405 while( test < rand && test > 0 );
406 result = value;
407 */
408 G4double rand;
409 G4double value = 0., test;
410 G4int jcounter = 0;
411 G4int jcounter_max = 1024;
412 do {
413 jcounter++;
414 if (jcounter > jcounter_max) {
415 G4cout << "Loop-counter exceeded the threshold value at " << __LINE__ << "th line of "
416 << __FILE__ << "." << G4endl;
417 break;
418 }
419 rand = G4UniformRand();
420 G4int ibin = -1;
421 for (G4int i = 0; i < GetVectorLength(); i++) {
422 if (rand < theIntegral[i]) {
423 ibin = i;
424 break;
425 }
426 }
427 if (ibin < 0) G4cout << "TKDB 080807 " << rand << G4endl;
428 // result
429 rand = G4UniformRand();
430 G4double x1, x2;
431 if (ibin == 0) {
432 x1 = theData[ibin].GetX();
433 value = x1;
434 break;
435 }
436 x1 = theData[ibin - 1].GetX();
437
438 x2 = theData[ibin].GetX();
439 value = rand * (x2 - x1) + x1;
440 //***********************************************************************
441 /*
442 test = GetY ( value ) / std::max ( GetY( ibin-1 ) , GetY ( ibin ) );
443 */
444 //***********************************************************************
445 // EMendoza - Always linear interpolation:
446 G4double y1 = theData[ibin - 1].GetY();
447 G4double y2 = theData[ibin].GetY();
448 G4double mval = (y2 - y1) / (x2 - x1);
449 G4double bval = y1 - mval * x1;
450 test = (mval * value + bval) / std::max(GetY(ibin - 1), GetY(ibin));
451 //***********************************************************************
452 } while (G4UniformRand() > test); // Loop checking, 11.05.2015, T. Koi
453 result = value;
454 // 080807
455 } while (IsBlocked(result)); // Loop checking, 11.05.2015, T. Koi
456 }
457 return result;
458}
#define G4UniformRand()
Definition Randomize.hh:52
void SetY(G4int i, G4double x)

Referenced by G4ParticleHPPhotonDist::GetPhotons(), G4ParticleHPArbitaryTab::Sample(), G4ParticleHPContAngularPar::Sample(), G4ParticleHPDiscreteTwoBody::Sample(), G4ParticleHPEvapSpectrum::Sample(), G4ParticleHPLabAngularEnergy::Sample(), and G4ParticleHPPartial::Sample().

◆ SampleLin()

G4double G4ParticleHPVector::SampleLin ( )
inline

Definition at line 297 of file G4ParticleHPVector.hh.

298 {
299 G4double result;
300 if (theIntegral == nullptr) IntegrateAndNormalise();
301 if (GetVectorLength() == 1) {
302 result = theData[0].GetX();
303 }
304 else {
305 G4int i;
306 G4double rand = G4UniformRand();
307
308 // this was replaced
309 // for(i=1;i<GetVectorLength();i++)
310 // {
311 // if(rand<theIntegral[i]/theIntegral[GetVectorLength()-1]) break;
312 // }
313
314 // by this (begin)
315 for (i = GetVectorLength() - 1; i >= 0; i--) {
316 if (rand > theIntegral[i] / theIntegral[GetVectorLength() - 1]) break;
317 }
318 if (i != GetVectorLength() - 1) i++;
319 // until this (end)
320
321 G4double x1, x2, y1, y2;
322 y1 = theData[i - 1].GetX();
323 x1 = theIntegral[i - 1];
324 y2 = theData[i].GetX();
325 x2 = theIntegral[i];
326 if (std::abs((y2 - y1) / y2)
327 < 0.0000001) // not really necessary, since the case is excluded by construction
328 {
329 y1 = theData[i - 2].GetX();
330 x1 = theIntegral[i - 2];
331 }
332 result = theLin.Lin(rand, x1, x2, y1, y2);
333 }
334 return result;
335 }

◆ SetData()

void G4ParticleHPVector::SetData ( G4int i,
G4double x,
G4double y )
inline

Definition at line 89 of file G4ParticleHPVector.hh.

90 {
91 // G4cout <<"G4ParticleHPVector::SetData called"<<nPoints<<" "<<nEntries<<G4endl;
92 Check(i);
93 if (y > maxValue) maxValue = y;
94 theData[i].SetData(x, y);
95 }
void SetData(G4double e, G4double x)

Referenced by Init(), Merge(), Merge(), G4ParticleHPDiscreteTwoBody::Sample(), G4ParticleHPLabAngularEnergy::Sample(), G4ParticleHPLegendreStore::Sample(), and SetPoint().

◆ SetEnergy()

void G4ParticleHPVector::SetEnergy ( G4int i,
G4double e )
inline

Definition at line 101 of file G4ParticleHPVector.hh.

102 {
103 Check(i);
104 theData[i].SetX(e);
105 }

◆ SetInterpolationManager() [1/2]

void G4ParticleHPVector::SetInterpolationManager ( const G4InterpolationManager & aManager)
inline

◆ SetInterpolationManager() [2/2]

void G4ParticleHPVector::SetInterpolationManager ( G4InterpolationManager & aMan)
inline

Definition at line 453 of file G4ParticleHPVector.hh.

453{ theManager = aMan; }

◆ SetLabel()

void G4ParticleHPVector::SetLabel ( G4double aLabel)
inline

Definition at line 229 of file G4ParticleHPVector.hh.

229{ label = aLabel; }

Referenced by G4ParticleHPArbitaryTab::Init(), and G4ParticleHPLabAngularEnergy::Init().

◆ SetPoint()

void G4ParticleHPVector::SetPoint ( G4int i,
const G4ParticleHPDataPoint & it )
inline

Definition at line 82 of file G4ParticleHPVector.hh.

83 {
84 G4double x = it.GetX();
85 G4double y = it.GetY();
86 SetData(i, x, y);
87 }

Referenced by G4ParticleHPIsoData::FillChannelData(), and operator=().

◆ SetScheme()

void G4ParticleHPVector::SetScheme ( G4int aPoint,
const G4InterpolationScheme & aScheme )
inline

Definition at line 455 of file G4ParticleHPVector.hh.

456 {
457 theManager.AppendScheme(aPoint, aScheme);
458 }

Referenced by G4ParticleHPPartial::Sample().

◆ SetVerbose()

void G4ParticleHPVector::SetVerbose ( G4int ff)
inline

Definition at line 69 of file G4ParticleHPVector.hh.

69{ Verbose = ff; }

◆ SetX()

void G4ParticleHPVector::SetX ( G4int i,
G4double e )
inline

◆ SetXsec()

void G4ParticleHPVector::SetXsec ( G4int i,
G4double x )
inline

Definition at line 112 of file G4ParticleHPVector.hh.

113 {
114 Check(i);
115 if (x > maxValue) maxValue = x;
116 theData[i].SetY(x);
117 }

◆ SetY()

void G4ParticleHPVector::SetY ( G4int i,
G4double x )
inline

Definition at line 106 of file G4ParticleHPVector.hh.

107 {
108 Check(i);
109 if (x > maxValue) maxValue = x;
110 theData[i].SetY(x);
111 }

Referenced by G4ParticleHPContAngularPar::Sample(), G4ParticleHPDiscreteTwoBody::Sample(), G4ParticleHPLabAngularEnergy::Sample(), G4ParticleHPPartial::Sample(), Sample(), and G4ParticleHPPartial::SetY().

◆ ThinOut()

void G4ParticleHPVector::ThinOut ( G4double precision)

Definition at line 289 of file G4ParticleHPVector.cc.

290{
291 // anything in there?
292 if (GetVectorLength() == 0) return;
293 // make the new vector
294 auto aBuff = new G4ParticleHPDataPoint[nPoints];
295 G4double x, x1, x2, y, y1, y2;
296 G4int count = 0, current = 2, start = 1;
297
298 // First element always goes and is never tested.
299 aBuff[0] = theData[0];
300
301 // Find the rest
302 while (current < GetVectorLength()) // Loop checking, 11.05.2015, T. Koi
303 {
304 x1 = aBuff[count].GetX();
305 y1 = aBuff[count].GetY();
306 x2 = theData[current].GetX();
307 y2 = theData[current].GetY();
308
309 if (x1 - x2 == 0) {
310 // Following block added for avoiding div 0 error on Release + G4FPE_DEBUG
311 for (G4int j = start; j < current; j++) {
312 y = (y2 + y1) / 2.;
313 if (std::abs(y - theData[j].GetY()) > precision * y) {
314 aBuff[++count] = theData[current - 1]; // for this one, everything was fine
315 start = current; // the next candidate
316 break;
317 }
318 }
319 }
320 else {
321 for (G4int j = start; j < current; j++) {
322 x = theData[j].GetX();
323 if (x1 - x2 == 0)
324 y = (y2 + y1) / 2.;
325 else
326 y = theInt.Lin(x, x1, x2, y1, y2);
327 if (std::abs(y - theData[j].GetY()) > precision * y) {
328 aBuff[++count] = theData[current - 1]; // for this one, everything was fine
329 start = current; // the next candidate
330 break;
331 }
332 }
333 }
334 current++;
335 }
336 // The last one also always goes, and is never tested.
337 aBuff[++count] = theData[GetVectorLength() - 1];
338 delete[] theData;
339 theData = aBuff;
340 nEntries = count + 1;
341
342 // Rebuild the Hash;
343 if (theHash.Prepared()) {
344 ReHash();
345 }
346}

Referenced by G4ParticleHPElementData::Init(), and G4ParticleHPIsoData::ThinOut().

◆ Times()

void G4ParticleHPVector::Times ( G4double factor)
inline

Definition at line 71 of file G4ParticleHPVector.hh.

72 {
73 G4int i;
74 for (i = 0; i < nEntries; i++) {
75 theData[i].SetY(theData[i].GetY() * factor);
76 }
77 if (theIntegral != nullptr) {
78 theIntegral[i] *= factor;
79 }
80 }

Referenced by G4ParticleHPChannel::UpdateData().

Friends And Related Symbol Documentation

◆ operator+

G4ParticleHPVector & operator+ ( G4ParticleHPVector & left,
G4ParticleHPVector & right )
friend

Definition at line 41 of file G4ParticleHPVector.cc.

42{
43 auto result = new G4ParticleHPVector;
44 G4int j = 0;
45 G4double x;
46 G4double y;
47 G4int running = 0;
48 for (G4int i = 0; i < left.GetVectorLength(); i++) {
49 while (j < right.GetVectorLength()) // Loop checking, 11.05.2015, T. Koi
50 {
51 if (right.GetX(j) < left.GetX(i) * 1.001) {
52 x = right.GetX(j);
53 y = right.GetY(j) + left.GetY(x);
54 result->SetData(running++, x, y);
55 j++;
56 }
57 // else if(std::abs((right.GetX(j)-left.GetX(i))/(left.GetX(i)+right.GetX(j)))>0.001)
58 else if (left.GetX(i) + right.GetX(j) == 0
59 || std::abs((right.GetX(j) - left.GetX(i)) / (left.GetX(i) + right.GetX(j))) > 0.001)
60 {
61 x = left.GetX(i);
62 y = left.GetY(i) + right.GetY(x);
63 result->SetData(running++, x, y);
64 break;
65 }
66 else {
67 break;
68 }
69 }
70 if (j == right.GetVectorLength()) {
71 x = left.GetX(i);
72 y = left.GetY(i) + right.GetY(x);
73 result->SetData(running++, x, y);
74 }
75 }
76 result->ThinOut(0.02);
77 return *result;
78}

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