67 if (fCache.
Get() == 0) cacheInit();
68 fCache.
Get()->currentMeanEnergy = -2;
69 fCache.
Get()->fresh =
true;
76 theProjectile = projectile;
80 nDiscreteEnergies = 0;
81 nAngularParameters = 0;
92 theProjectile = projectile;
94 aDataFile >> theEnergy >> nEnergies >> nDiscreteEnergies >> nAngularParameters;
98 for (
G4int i = 0; i < nEnergies; i++) {
102 theAngular[i].
Init(aDataFile, nAngularParameters, 1.);
103 theMinEner = std::min(theMinEner,sEnergy);
104 theMaxEner = std::max(theMaxEner,sEnergy);
116 adjustResult =
false;
118 if (fCache.
Get() == 0 ) cacheInit();
138 "G4ParticleHPContAngularPar: Unknown ion case 1");
148 if (angularRep == 1) {
149 if (nDiscreteEnergies != 0) {
152 if (fCache.
Get()->fresh ==
true) {
155 fCache.
Get()->remaining_energy = std::max (theAngular[0].GetLabel(),
156 theAngular[nEnergies-1].GetLabel() );
157 fCache.
Get()->fresh =
false;
162 if (nDiscreteEnergies == nEnergies) {
163 fCache.
Get()->remaining_energy = std::max(fCache.
Get()->remaining_energy,
164 theAngular[nDiscreteEnergies-1].
GetLabel() );
167 for (
G4int j = nDiscreteEnergies; j < nEnergies; j++) {
168 cont_min = theAngular[j].
GetLabel();
169 if (theAngular[j].GetValue(0) != 0.0 )
break;
171 fCache.
Get()->remaining_energy =
172 std::max (fCache.
Get()->remaining_energy,
173 std::min(theAngular[nDiscreteEnergies-1].
GetLabel(), cont_min) );
181 for (
G4int j = 0; j < nDiscreteEnergies; j++) {
183 if (theAngular[j].GetLabel() <= fCache.
Get()->remaining_energy)
185 running[j+1] = running[j] + delta;
188 G4double tot_prob_DIS = std::max( running[nDiscreteEnergies], 0.0 );
191 for (
G4int j = nDiscreteEnergies; j < nEnergies; j++) {
195 if (theAngular[j].GetLabel() <= fCache.
Get()->remaining_energy)
203 if (theAngular[j].GetLabel() != 0) {
204 if (j == nDiscreteEnergies) {
208 e_low = theAngular[j-1].
GetLabel()/eV;
210 e_high = theAngular[j].
GetLabel()/eV;
215 if (theAngular[j].GetLabel() == 0.0) {
216 e_low = theAngular[j].
GetLabel()/eV;
217 if (j != nEnergies-1) {
218 e_high = theAngular[j+1].
GetLabel()/eV;
220 e_high = theAngular[j].
GetLabel()/eV;
221 if (theAngular[j].GetValue(0) != 0.0) {
223 "G4ParticleHPContAngularPar: Unexpected non zero value of theAngular[nEnergies-1].GetValue(0)");
228 running[j+1] = running[j] + ( ( e_high - e_low ) * delta1);
230 G4double tot_prob_CON = std::max( running[ nEnergies ] - running[ nDiscreteEnergies ], 0.0 );
233 if ( tot_prob_DIS == 0.0 && tot_prob_CON == 0.0 )
return result;
236 random *= (tot_prob_DIS + tot_prob_CON);
240 if (random <= (tot_prob_DIS/(tot_prob_DIS + tot_prob_CON) ) || nDiscreteEnergies == nEnergies) {
242 for (
G4int j = 0; j < nDiscreteEnergies; j++) {
244 if (random < running[ j+1 ] ) {
249 fsEnergy = theAngular[ it ].
GetLabel();
252 theStore.
Init(0,fsEnergy,nAngularParameters);
253 for (
G4int j = 0; j < nAngularParameters; j++) {
254 theStore.
SetCoeff(0,j,theAngular[it].GetValue(j));
262 for (
G4int j = nDiscreteEnergies; j < nEnergies; j++) {
264 if (random < running[ j ] ) {
270 if ( it < 1 ) it = 1;
276 if (it != nDiscreteEnergies) y1 = theAngular[it-1].
GetLabel();
283 theStore.
Init(0, y1, nAngularParameters);
284 theStore.
Init(1, y2, nAngularParameters);
287 for (
G4int j = 0; j < nAngularParameters; j++) {
289 if (it == nDiscreteEnergies) itt = it+1;
291 theStore.
SetCoeff(0, j, theAngular[itt-1].GetValue(j) );
292 theStore.
SetCoeff(1, j, theAngular[itt].GetValue(j) );
303 fCache.
Get()->remaining_energy -= fsEnergy;
310 if (fCache.
Get()->fresh ==
true) {
311 fCache.
Get()->remaining_energy = theAngular[ nEnergies-1 ].
GetLabel();
312 fCache.
Get()->fresh =
false;
319 for (i = 1; i < nEnergies; i++) {
320 running[i]=running[i-1];
321 if (fCache.
Get()->remaining_energy >= theAngular[i].
GetLabel() ) {
336 if (nEnergies == 1 || running[nEnergies-1] == 0) {
337 fCache.
Get()->currentMeanEnergy = 0.0;
339 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
342 if (nEnergies == 1) it = 0;
343 if (running[nEnergies-1] != 0) {
344 for (i = 1; i < nEnergies; i++) {
346 if (random < running [i]/running[nEnergies-1] )
break;
350 if (running[nEnergies-1] == 0) it = 0;
351 if (it < nDiscreteEnergies || it == 0) {
353 fsEnergy = theAngular[it].
GetLabel();
355 theStore.
Init(0,fsEnergy,nAngularParameters);
356 for (i = 0; i < nAngularParameters; i++) {
357 theStore.
SetCoeff(0, i, theAngular[it].GetValue(i) );
368 running[it-1]/running[nEnergies-1],
369 running[it]/running[nEnergies-1],
373 theStore.
Init(0,e1,nAngularParameters);
374 theStore.
Init(1,e2,nAngularParameters);
375 for (i = 0; i < nAngularParameters; i++) {
376 theStore.
SetCoeff(0, i, theAngular[it-1].GetValue(i) );
377 theStore.
SetCoeff(1, i, theAngular[it].GetValue(i) );
385 G4double x1 = running[it-1]/running[nEnergies-1];
386 G4double x2 = running[it]/running[nEnergies-1];
392 theStore.
Init(0,y1,nAngularParameters);
393 theStore.
Init(1,y2,nAngularParameters);
395 for (i = 0; i < nAngularParameters; i++) {
396 theStore.
SetCoeff(0, i, theAngular[it-1].GetValue(i));
397 theStore.
SetCoeff(1, i, theAngular[it].GetValue(i));
408 fCache.
Get()->remaining_energy -= fsEnergy;
413 }
else if (angularRep == 2) {
419 for (j = 1; j < nEnergies; j++) {
420 if (j != 0) running[j] = running[j-1];
431 fCache.
Get()->currentMeanEnergy = 0.0;
433 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
437 for (j = 1; j < nEnergies; j++) {
439 if (randkal < running[j]/running[nEnergies-1] )
break;
444 if (itt == 0) itt = 1;
445 x = randkal*running[nEnergies-1];
459 fsEnergy, y1, y2, cLow, cHigh);
461 if (compoundFraction > 1.0) compoundFraction = 1.0;
471 G4int targetA =
G4int(fCache.
Get()->theTargetCode-1000*targetZ);
475 targetA =
G4int ( fCache.
Get()->theTarget->GetMass()/amu_c2 + 0.5 );
476 G4double targetMass = fCache.
Get()->theTarget->GetMass();
477 G4int incidentA=
G4int(incidentMass/amu_c2 + 0.5 );
479 G4int residualA = targetA+incidentA-
A;
480 G4int residualZ = targetZ+incidentZ-
Z;
483 incidentEnergy, incidentMass,
484 productEnergy, productMass,
485 residualMass, residualA, residualZ,
486 targetMass, targetA, targetZ,
487 incidentA,incidentZ,
A,
Z);
488 cosTh = theKallbach.
Sample(anEnergy);
491 }
else if (angularRep > 10 && angularRep < 16) {
496 for (i = 1; i < nEnergies; i++) {
497 if (i != 0) running[i] = running[i-1];
508 fCache.
Get()->currentMeanEnergy = 0.0;
510 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
512 if (nEnergies == 1) it = 0;
513 for (i = 1; i < nEnergies; i++) {
515 if(random<running[i]/running[nEnergies-1])
break;
518 if (it < nDiscreteEnergies || it == 0) {
520 fsEnergy = theAngular[0].
GetLabel();
523 for (
G4int j=1; j<nAngularParameters; j+=2) {
524 theStore.
SetX(aCounter, theAngular[0].GetValue(j));
525 theStore.
SetY(aCounter, theAngular[0].GetValue(j+1));
529 aMan.
Init(angularRep-10, nAngularParameters-1);
531 cosTh = theStore.
Sample();
533 fsEnergy = theAngular[it].
GetLabel();
536 aMan.
Init(angularRep-10, nAngularParameters-1);
540 for (
G4int j=1; j<nAngularParameters; j+=2) {
541 theStore.
SetX(aCounter, theAngular[it].GetValue(j));
542 theStore.
SetY(aCounter,
544 running[it-1]/running[nEnergies-1],
545 running[it]/running[nEnergies-1],
550 cosTh = theStore.
Sample();
554 G4double x1 = running[it-1]/running[nEnergies-1];
555 G4double x2 = running[it]/running[nEnergies-1];
563 aMan.
Init(angularRep-10, nAngularParameters-1);
566 for (i = 0, j = 1; i < nAngularParameters; i++, j+=2) {
567 theBuff1.
SetX(i, theAngular[it-1].GetValue(j));
568 theBuff1.
SetY(i, theAngular[it-1].GetValue(j+1));
569 theBuff2.
SetX(i, theAngular[it].GetValue(j));
570 theBuff2.
SetY(i, theAngular[it].GetValue(j+1));
579 x = theBuff1.
GetX(i);
580 y1 = theBuff1.
GetY(i);
581 y2 = theBuff2.
GetY(i);
583 fsEnergy, theAngular[it-1].
GetLabel(),
588 cosTh = theStore.
Sample();
594 "G4ParticleHPContAngularPar::Sample: Unknown angular representation");
602 G4ThreeVector tempVector(mtot*sinth*std::cos(phi), mtot*sinth*std::sin(phi), mtot*std::cos(theta) );
620 for (
G4int ie = 0; ie < nDiscreteEnergies; ie++) {
623 while (theDiscreteEnergiesOwn.find(myE) != theDiscreteEnergiesOwn.end() ) {
626 theDiscreteEnergiesOwn[myE] = ie;
683 G4int ie, ie1, ie2, ie1Prev, ie2Prev;
687 if (fCache.
Get()->fresh !=
true)
return;
695 nAngularParameters = copyAngpar1.nAngularParameters;
696 theManager = copyAngpar1.theManager;
697 theEnergy = anEnergy;
707 const std::map<G4double,G4int> discEnerOwn1 = copyAngpar1.GetDiscreteEnergiesOwn();
709 std::map<G4double,G4int>::const_iterator itedeo1;
710 std::map<G4double,G4int>::const_iterator itedeo2;
711 std::vector<G4ParticleHPList*> vAngular(discEnerOwn1.size() );
713 for (itedeo1 = discEnerOwn1.cbegin(); itedeo1 != discEnerOwn1.cend(); ++itedeo1) {
714 discEner1 = itedeo1->first;
715 if (discEner1 < theMinEner) {
716 theMinEner = discEner1;
718 if (discEner1 > theMaxEner) {
719 theMaxEner = discEner1;
721 ie1 = itedeo1->second;
722 itedeo2 = discEnerOwn2.find(discEner1);
723 if( itedeo2 == discEnerOwn2.cend() ) {
726 ie2 = itedeo2->second;
729 vAngular[ie1]->SetLabel(copyAngpar1.theAngular[ie1].GetLabel());
731 for (
G4int ip = 0; ip < nAngularParameters; ++ip) {
732 val1 = copyAngpar1.theAngular[ie1].GetValue(ip);
734 val2 = copyAngpar2.theAngular[ie2].
GetValue(ip);
739 copyAngpar1.theEnergy, copyAngpar2.theEnergy,
741 vAngular[ie1]->SetValue(ip, value);
746 std::vector<G4ParticleHPList*>::const_iterator itv;
748 for (itedeo2 = discEnerOwn2.cbegin(); itedeo2 != discEnerOwn2.cend(); ++itedeo2) {
749 discEner2 = itedeo2->first;
750 ie2 = itedeo2->second;
752 itedeo1 = discEnerOwn1.find(discEner2);
753 if (itedeo1 != discEnerOwn1.cend() ) {
758 if (discEner2 < theMinEner) {
759 theMinEner = discEner2;
761 if (discEner2 > theMaxEner) {
762 theMaxEner = discEner2;
765 G4bool isInserted =
false;
767 for (itv = vAngular.cbegin(); itv != vAngular.cend(); ++itv,++ie) {
768 if (discEner2 > (*itv)->GetLabel() ) {
770 (*itv)->SetLabel(copyAngpar2.theAngular[ie2].
GetLabel());
776 ie=(
G4int)vAngular.size();
778 vAngular[ie]->SetLabel(copyAngpar2.theAngular[ie2].
GetLabel());
783 for (
G4int ip = 0; ip < nAngularParameters; ++ip) {
785 val2 = copyAngpar2.theAngular[ie2].
GetValue(ip);
787 copyAngpar1.theEnergy,
788 copyAngpar2.theEnergy,
790 vAngular[ie]->SetValue(ip, value);
796 nDiscreteEnergies = (
G4int)vAngular.size();
797 if (theAngular != 0)
delete [] theAngular;
799 if (nDiscreteEnergies > 0) {
802 theDiscreteEnergiesOwn.clear();
803 theDiscreteEnergies.clear();
804 for (ie = 0; ie < nDiscreteEnergies; ++ie) {
805 theAngular[ie].
SetLabel(vAngular[ie]->GetLabel() );
806 for (
G4int ip = 0; ip < nAngularParameters; ++ip) {
807 theAngular[ie].
SetValue(ip, vAngular[ie]->GetValue(ip));
809 theDiscreteEnergiesOwn[theAngular[ie].
GetLabel()] = ie;
810 theDiscreteEnergies.insert(theAngular[ie].GetLabel());
821 G4double interMinEner = copyAngpar1.GetMinEner() + (theEnergy-copyAngpar1.GetEnergy() )
822 * (copyAngpar2.
GetMinEner() - copyAngpar1.GetMinEner() )
823 / (copyAngpar2.
GetEnergy()-copyAngpar1.GetEnergy() );
824 G4double interMaxEner = copyAngpar1.GetMaxEner() + (theEnergy-copyAngpar1.GetEnergy() )
825 * (copyAngpar2.
GetMaxEner()-copyAngpar1.GetMaxEner() )
826 / (copyAngpar2.
GetEnergy()-copyAngpar1.GetEnergy() );
829 theEnergiesTransformed.clear();
831 G4int nEnergies1 = copyAngpar1.GetNEnergies();
832 G4int nDiscreteEnergies1 = copyAngpar1.GetNDiscreteEnergies();
833 G4double minEner1 = copyAngpar1.GetMinEner();
834 G4double maxEner1 = copyAngpar1.GetMaxEner();
847 for (ie1 = nDiscreteEnergies1; ie1 < nEnergies1; ++ie1) {
848 e1 = copyAngpar1.theAngular[ie1].GetLabel();
849 eTNorm1 = (e1 - minEner1);
850 if (maxEner1 != minEner1) eTNorm1 /= (maxEner1-minEner1);
851 if (eTNorm1 >= 0 && eTNorm1 <= 1) theEnergiesTransformed.insert(eTNorm1);
856 for (ie2 = nDiscreteEnergies2; ie2 < nEnergies2; ++ie2) {
857 e2 = copyAngpar2.theAngular[ie2].
GetLabel();
858 eTNorm2 = (e2 - minEner2);
859 if (maxEner2 != minEner2) eTNorm2 /= (maxEner2-minEner2);
860 if (eTNorm2 >= 0 && eTNorm2 <= 1) theEnergiesTransformed.insert(eTNorm2);
864 nEnergies = nDiscreteEnergies+(
G4int)theEnergiesTransformed.size();
871 if (theAngular != 0) {
872 for (ie = 0; ie < nDiscreteEnergies; ++ie) {
873 theNewAngular[ie].
SetLabel(theAngular[ie].GetLabel());
874 for (
G4int ip = 0; ip < nAngularParameters; ++ip) {
875 theNewAngular[ie].
SetValue(ip,theAngular[ie].GetValue(ip));
878 delete [] theAngular;
880 theAngular = theNewAngular;
883 std::set<G4double>::const_iterator iteet = theEnergiesTransformed.begin();
887 for (ie = nDiscreteEnergies; ie < nEnergies; ++ie, ++iteet) {
891 e1Interp = (maxEner1 - minEner1) * eT + minEner1;
893 for (ie1 = nDiscreteEnergies1; ie1 < nEnergies1; ++ie1) {
894 if ((copyAngpar1.theAngular[ie1].GetLabel() - e1Interp) > 1.E-10*e1Interp)
break;
897 if (ie1 == 0) ++ie1Prev;
898 if (ie1 == nEnergies1) {
904 e2Interp = (maxEner2-minEner2) * eT + minEner2;
906 for (ie2 = nDiscreteEnergies2; ie2 < nEnergies2; ++ie2) {
907 if ((copyAngpar2.theAngular[ie2].
GetLabel() - e2Interp) > 1.E-10*e2Interp)
break;
910 if (ie2 == 0) ++ie2Prev;
911 if (ie2 == nEnergies2) {
917 G4double eN = (interMaxEner-interMinEner) * eT + interMinEner;
920 if (eN < theMinEner) {
923 if (eN > theMaxEner) {
930 for (
G4int ip = 0; ip < nAngularParameters; ++ip) {
933 copyAngpar1.theAngular[ie1Prev].GetLabel(),
934 copyAngpar1.theAngular[ie1].GetLabel(),
935 copyAngpar1.theAngular[ie1Prev].GetValue(ip),
936 copyAngpar1.theAngular[ie1].GetValue(ip)) * (maxEner1-minEner1);
939 copyAngpar2.theAngular[ie2Prev].
GetLabel(),
940 copyAngpar2.theAngular[ie2].
GetLabel(),
941 copyAngpar2.theAngular[ie2Prev].
GetValue(ip),
942 copyAngpar2.theAngular[ie2].
GetValue(ip)) * (maxEner2-minEner2);
945 copyAngpar1.theEnergy, copyAngpar2.theEnergy,
947 if (interMaxEner != interMinEner) {
948 value /= (interMaxEner-interMinEner);
949 }
else if (value != 0) {
951 "G4ParticleHPContAngularPar::PrepareTableInterpolation interMaxEner == interMinEner and value != 0.");
957 for (itv = vAngular.cbegin(); itv != vAngular.cend(); ++itv)
delete (*itv);
964 G4cout << theEnergy <<
" " << nEnergies <<
" " << nDiscreteEnergies
965 <<
" " << nAngularParameters <<
G4endl;
967 for (
G4int ii = 0; ii < nEnergies; ii++) theAngular[ii].
Dump();
G4GLOB_DLL std::ostream G4cout
static G4Deuteron * Deuteron()
static G4Electron * Electron()
void Init(G4int aScheme, G4int aRange)
G4InterpolationScheme GetScheme(G4int index) const
G4InterpolationScheme GetInverseScheme(G4int index)
static G4IonTable * GetIonTable()
static G4Neutron * Neutron()
static G4double GetNuclearMass(const G4double A, const G4double Z)
G4double GetPDGMass() const
G4double GetPDGCharge() const
G4ReactionProduct * Sample(G4double anEnergy, G4double massCode, G4double mass, G4int angularRep, G4int interpol)
void PrepareTableInterpolation()
G4int GetNEnergies() const
void Init(std::istream &aDataFile, G4ParticleDefinition *projectile)
std::map< G4double, G4int > GetDiscreteEnergiesOwn() const
G4int GetNDiscreteEnergies() const
G4double GetEnergy() const
G4double GetMinEner() const
G4ParticleHPContAngularPar()
void BuildByInterpolation(G4double anEnergy, G4InterpolationScheme aScheme, G4ParticleHPContAngularPar &store1, G4ParticleHPContAngularPar &store2)
G4double GetMaxEner() const
G4double Interpolate(G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double GetWeightedBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
G4double Interpolate2(G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double GetBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
G4double Sample(G4double anEnergy)
void SetCoeff(G4int i, G4int l, G4double coeff)
void Init(G4int i, G4double e, G4int n)
G4double SampleMax(G4double energy)
void SetManager(G4InterpolationManager &aManager)
void SetLabel(G4double aLabel)
void SetValue(G4int i, G4double y)
void Init(std::istream &aDataFile, G4int nPar, G4double unit=1.)
G4double GetValue(G4int i)
static G4ParticleHPManager * GetInstance()
void SetY(G4int i, G4double x)
void SetX(G4int i, G4double e)
void SetInterpolationManager(const G4InterpolationManager &aManager)
G4double GetY(G4double x)
G4double GetX(G4int i) const
G4int GetVectorLength() const
static G4Positron * Positron()
static G4Proton * Proton()
void SetMomentum(const G4double x, const G4double y, const G4double z)
G4double GetTotalMomentum() const
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
void SetKineticEnergy(const G4double en)
static G4Triton * Triton()