63 if ( fCache.
Get() == NULL ) cacheInit();
64 fCache.
Get()->currentMeanEnergy = -2;
65 fCache.
Get()->fresh =
true;
67 if ( getenv(
"G4PHP_DO_NOT_ADJUST_FINAL_STATE" ) ) adjustResult =
false;
71 theProjectile = projectile;
75 nDiscreteEnergies = 0;
76 nAngularParameters = 0;
82 if ( getenv(
"G4PHP_DO_NOT_ADJUST_FINAL_STATE" ) ) adjustResult =
false;
84 theProjectile = projectile;
86 aDataFile >> theEnergy >> nEnergies >> nDiscreteEnergies >> nAngularParameters;
90 for(
G4int i=0; i<nEnergies; i++)
96 theAngular[i].
Init(aDataFile, nAngularParameters, 1.);
97 theMinEner =
std::min(theMinEner,sEnergy);
98 theMaxEner =
std::max(theMaxEner,sEnergy);
106 if( getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample " << anEnergy <<
" " << massCode <<
" " << angularRep <<
G4endl;
107 if ( fCache.
Get() == NULL ) cacheInit();
137 if(Z!=2)
throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar: Unknown ion case 1");
148 if( angularRep == 1 )
154 if ( nDiscreteEnergies != 0 )
159 if ( fCache.
Get()->fresh == true )
163 fCache.
Get()->remaining_energy =
std::max ( theAngular[0].GetLabel() , theAngular[nEnergies-1].GetLabel() );
164 fCache.
Get()->fresh =
false;
169 if ( nDiscreteEnergies == nEnergies )
171 fCache.
Get()->remaining_energy =
std::max ( fCache.
Get()->remaining_energy , theAngular[nDiscreteEnergies-1].
GetLabel() );
178 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
180 cont_min = theAngular[j].
GetLabel();
181 if ( theAngular[j].GetValue(0) != 0.0 )
break;
183 fCache.
Get()->remaining_energy =
std::max ( fCache.
Get()->remaining_energy ,
std::min ( theAngular[nDiscreteEnergies-1].GetLabel() , cont_min ) );
191 for (
G4int j = 0 ; j < nDiscreteEnergies ; j++ )
194 if ( theAngular[j].GetLabel() <= fCache.
Get()->remaining_energy ) delta = theAngular[i].GetValue(0);
195 running[j+1] = running[j] + delta;
197 G4double tot_prob_DIS = running[ nDiscreteEnergies ];
199 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
204 if ( theAngular[j].GetLabel() <= fCache.
Get()->remaining_energy ) delta = theAngular[j].GetValue(0);
211 if ( theAngular[j].GetLabel() != 0 )
213 if ( j == nDiscreteEnergies ) {
222 if ( theAngular[j].GetLabel() == 0.0 ) {
224 if ( j != nEnergies-1 ) {
228 if ( theAngular[j].GetValue(0) != 0.0 ) {
229 throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar: Unexpected non zero value of theAngular[nEnergies-1].GetValue(0)");
234 running[j+1] = running[j] + ( ( e_high - e_low ) * delta );
236 G4double tot_prob_CON = running[ nEnergies ] - running[ nDiscreteEnergies ];
250 random *= (tot_prob_DIS + tot_prob_CON);
252 if ( random <= ( tot_prob_DIS / ( tot_prob_DIS + tot_prob_CON ) ) || nDiscreteEnergies == nEnergies )
255 for (
G4int j = 0 ; j < nDiscreteEnergies ; j++ )
258 if ( random < running[ j+1 ] )
264 fsEnergy = theAngular[ it ].
GetLabel();
267 theStore.
Init(0,fsEnergy,nAngularParameters);
268 for (
G4int j=0;j<nAngularParameters;j++)
270 theStore.
SetCoeff(0,j,theAngular[it].GetValue(j));
279 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
282 if ( random < running[ j ] )
293 if ( it != nDiscreteEnergies )
301 theStore.
Init(0,y1,nAngularParameters);
302 theStore.
Init(1,y2,nAngularParameters);
304 for (
G4int j=0;j<nAngularParameters;j++)
307 if ( it == nDiscreteEnergies ) itt = it+1;
314 theStore.
SetCoeff(0,j,theAngular[itt-1].GetValue(j));
315 theStore.
SetCoeff(1,j,theAngular[itt].GetValue(j));
324 if( adjustResult ) fCache.
Get()->remaining_energy -= fsEnergy;
336 if ( fCache.
Get()->fresh == true )
338 fCache.
Get()->remaining_energy = theAngular[ nEnergies-1 ].
GetLabel();
339 fCache.
Get()->fresh =
false;
346 for(i=1; i<nEnergies; i++)
361 running[i]=running[i-1];
362 if ( fCache.
Get()->remaining_energy >= theAngular[i].
GetLabel() )
374 if ( nEnergies == 1 || running[nEnergies-1] == 0 )
375 fCache.
Get()->currentMeanEnergy = 0.0;
378 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
382 if ( nEnergies == 1 ) it = 0;
385 if ( running[nEnergies-1] != 0 )
387 for ( i = 1 ; i < nEnergies ; i++ )
390 if ( random < running [ i ] / running [ nEnergies-1 ] )
break;
395 if ( running [ nEnergies-1 ] == 0 ) it = 0;
398 if (it<nDiscreteEnergies||it==0)
402 fsEnergy = theAngular[it].
GetLabel();
404 theStore.
Init(0,fsEnergy,nAngularParameters);
405 for(i=0;i<nAngularParameters;i++)
407 theStore.
SetCoeff(0,i,theAngular[it].GetValue(i));
419 running[it-1]/running[nEnergies-1],
420 running[it]/running[nEnergies-1],
424 theStore.
Init(0,e1,nAngularParameters);
425 theStore.
Init(1,e2,nAngularParameters);
426 for(i=0;i<nAngularParameters;i++)
428 theStore.
SetCoeff(0,i,theAngular[it-1].GetValue(i));
429 theStore.
SetCoeff(1,i,theAngular[it].GetValue(i));
438 G4double x1 = running[it-1]/running[nEnergies-1];
439 G4double x2 = running[it]/running[nEnergies-1];
445 theStore.
Init(0,y1,nAngularParameters);
446 theStore.
Init(1,y2,nAngularParameters);
448 for(i=0;i<nAngularParameters;i++)
450 theStore.
SetCoeff(0,i,theAngular[it-1].GetValue(i));
451 theStore.
SetCoeff(1,i,theAngular[it].GetValue(i));
459 if( adjustResult ) fCache.
Get()->remaining_energy -= fsEnergy;
463 else if(angularRep==2)
470 if( getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample nEnergies " << nEnergies <<
G4endl;
471 for(j=1; j<nEnergies; j++)
473 if(j!=0) running[j]=running[j-1];
480 if( getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample " << j <<
" running " << running[j]
486 if ( nEnergies == 1 )
487 fCache.
Get()->currentMeanEnergy = 0.0;
489 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
495 for(j=1; j<nEnergies; j++)
498 if(randkal<running[j]/running[nEnergies-1])
break;
504 x = randkal*running[nEnergies-1];
513 if( getenv(
"G4PHPTEST") )
G4cout << itt <<
" G4particleHPContAngularPar fsEnergy " << fsEnergy <<
" " << theManager.
GetInverseScheme(itt-1) <<
" x " << x <<
" " << x1 <<
" " << x2 <<
" y " << y1 <<
" " << y2 <<
G4endl;
518 fsEnergy, y1, y2, cLow,cHigh);
519 if( getenv(
"G4PHPTEST") )
G4cout << itt <<
" G4particleHPContAngularPar compoundFraction " << compoundFraction <<
" E " << fsEnergy <<
" " << theManager.
GetScheme(itt) <<
" ener " << fsEnergy <<
" y " << y1 <<
" " << y2 <<
" cLH " << cLow <<
" " << cHigh <<
G4endl;
528 G4int targetA =
G4int(fCache.
Get()->theTargetCode-1000*targetZ);
531 targetA =
G4int ( fCache.
Get()->theTarget->GetMass()/
amu_c2 + 0.5 );
532 G4double targetMass = fCache.
Get()->theTarget->GetMass();
533 G4int residualA = targetA+1-
A;
534 G4int residualZ = targetZ-
Z;
536 residualMass +=(residualA-residualZ)*theProjectile->
GetPDGMass();
539 incidentEnergy, incidentMass,
540 productEnergy, productMass,
541 residualMass, residualA, residualZ,
542 targetMass, targetA, targetZ);
543 cosTh = theKallbach.
Sample(anEnergy);
544 if( getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPKallbachMannSyst::Sample resulttest " << cosTh <<
G4endl;
546 else if(angularRep>10&&angularRep<16)
552 for(i=1; i<nEnergies; i++)
554 if(i!=0) running[i]=running[i-1];
564 if ( nEnergies == 1 )
565 fCache.
Get()->currentMeanEnergy = 0.0;
567 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
570 if ( nEnergies == 1 ) it = 0;
572 for(i=1; i<nEnergies; i++)
575 if(random<running[i]/running[nEnergies-1])
break;
577 if(it<nDiscreteEnergies||it==0)
581 fsEnergy = theAngular[0].
GetLabel();
584 for(
G4int j=1; j<nAngularParameters; j+=2)
586 theStore.
SetX(aCounter, theAngular[0].GetValue(j));
587 theStore.
SetY(aCounter, theAngular[0].GetValue(j+1));
591 aMan.
Init(angularRep-10, nAngularParameters-1);
593 cosTh = theStore.
Sample();
597 fsEnergy = theAngular[it].
GetLabel();
600 aMan.
Init(angularRep-10, nAngularParameters-1);
604 for(
G4int j=1; j<nAngularParameters; j+=2)
606 theStore.
SetX(aCounter, theAngular[it].GetValue(j));
609 running[it-1]/running[nEnergies-1],
610 running[it]/running[nEnergies-1],
615 cosTh = theStore.
Sample();
620 G4double x1 = running[it-1]/running[nEnergies-1];
621 G4double x2 = running[it]/running[nEnergies-1];
629 aMan.
Init(angularRep-10, nAngularParameters-1);
643 for(i=0,j=1; i<nAngularParameters; i++,j+=2)
645 theBuff1.
SetX(i, theAngular[it-1].GetValue(j));
646 theBuff1.
SetY(i, theAngular[it-1].GetValue(j+1));
647 theBuff2.
SetX(i, theAngular[it].GetValue(j));
648 theBuff2.
SetY(i, theAngular[it].GetValue(j+1));
659 x = theBuff1.
GetX(i);
660 y1 = theBuff1.
GetY(i);
661 y2 = theBuff2.
GetY(i);
663 fsEnergy, theAngular[it-1].
GetLabel(),
668 cosTh = theStore.
Sample();
674 throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar::Sample: Unknown angular representation");
681 G4ThreeVector tempVector(mtot*sinth*std::cos(phi), mtot*sinth*std::sin(phi), mtot*std::cos(theta) );
695 for(ie=0; ie<nDiscreteEnergies; ie++) {
696 theDiscreteEnergiesOwn[theAngular[ie].
GetLabel()] = ie;
698 if( !angParPrev )
return;
701 for(ie=0; ie<nDiscreteEnergies; ie++) {
702 theDiscreteEnergies.insert(theAngular[ie].GetLabel());
705 for(ie=0; ie<nDiscreteEnergiesPrev; ie++) {
706 theDiscreteEnergies.insert(angParPrev->theAngular[ie].
GetLabel());
710 for(ie=nDiscreteEnergies; ie<nEnergies; ie++) {
712 G4double enerT = (ener-theMinEner)/(theMaxEner-theMinEner);
713 theEnergiesTransformed.insert(enerT);
719 for(ie=nDiscreteEnergiesPrev; ie<nEnergiesPrev; ie++) {
721 G4double enerT = (ener-minEnerPrev)/(maxEnerPrev-minEnerPrev);
722 theEnergiesTransformed.insert(enerT);
726 theEnergiesTransformed.insert(1.);
734 G4int ie,ie1,ie2, ie1Prev, ie2Prev;
735 nAngularParameters = angpar1.nAngularParameters;
736 theManager = angpar1.theManager;
737 theEnergy = anEnergy;
739 nDiscreteEnergies = theDiscreteEnergies.size();
740 std::set<G4double>::const_iterator itede;
743 std::map<G4double,G4int>::const_iterator itedeo;
745 for( itede = theDiscreteEnergies.begin(); itede != theDiscreteEnergies.end(); itede++, ie++ ) {
747 itedeo = discEnerOwn1.find(discEner);
748 if( itedeo == discEnerOwn1.end() ) {
753 itedeo = discEnerOwn2.find(discEner);
754 if( itedeo == discEnerOwn2.end() ) {
762 for(
G4int ip=0; ip<nAngularParameters; ip++) {
764 val1 = angpar1.theAngular[ie1].
GetValue(ip);
769 val2 = angpar2.theAngular[ie2].
GetValue(ip);
775 angpar1.theEnergy, angpar2.theEnergy,
778 if( getenv(
"G4PHPTEST2") )
G4cout << ie <<
" " << ip <<
" G4ParticleHPContAngularPar::Merge DiscreteEnergies val1 " << val1 <<
" val2 " << val2 <<
" value " << value <<
G4endl;
784 if(theAngular != 0)
delete [] theAngular;
792 if( getenv(
"G4PHPTEST2") )
G4cout <<
" G4ParticleHPContAngularPar::Merge E " << anEnergy <<
" minmax " << theMinEner <<
" " << theMaxEner <<
G4endl;
796 std::set<G4double>::const_iterator iteet = energiesTransformed.begin();
805 for(ie=nDiscreteEnergies; ie<nEnergies; ie++,iteet++) {
809 G4double e1 = (maxEner1-minEner1) * eT + minEner1;
811 for(ie1=nDiscreteEnergies1; ie1<nEnergies1; ie1++) {
812 if( (angpar1.theAngular[ie1].
GetLabel() - e1) > 1.E-10*e1 )
break;
815 if( ie1 == 0 ) ie1Prev++;
816 if( ie1 == nEnergies1 ) {
821 G4double e2 = (maxEner2-minEner2) * eT + minEner2;
823 for(ie2=nDiscreteEnergies2; ie2<nEnergies2; ie2++) {
825 if( (angpar2.theAngular[ie2].
GetLabel() - e2) > 1.E-10*e2 )
break;
828 if( ie2 == 0 ) ie2Prev++;
829 if( ie2 == nEnergies2 ) {
835 G4double eN = (theMaxEner-theMinEner) * eT + theMinEner;
836 if( getenv(
"G4PHPTEST2") )
G4cout << ie <<
" " << ie1 <<
" " << ie2 <<
" G4ParticleHPContAngularPar::loop eT " << eT <<
" -> eN " << eN <<
" e1 " << e1 <<
" e2 " << e2 <<
G4endl;
840 for(
G4int ip=0; ip<nAngularParameters; ip++) {
843 angpar1.theAngular[ie1Prev].
GetLabel(),
845 angpar1.theAngular[ie1Prev].
GetValue(ip),
846 angpar1.theAngular[ie1].
GetValue(ip)) * (maxEner1-minEner1);
849 angpar2.theAngular[ie2Prev].
GetLabel(),
851 angpar2.theAngular[ie2Prev].
GetValue(ip),
852 angpar2.theAngular[ie2].
GetValue(ip)) * (maxEner2-minEner2);
855 angpar1.theEnergy, angpar2.theEnergy,
859 if ( theMaxEner != theMinEner ) {
860 value /= (theMaxEner-theMinEner);
861 }
else if ( value != 0 ) {
862 throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar::PrepareTableInterpolation theMaxEner == theMinEner and value != 0.");
864 if( getenv(
"G4PHPTEST2") )
G4cout << ie <<
" " << ip <<
" G4ParticleHPContAngularPar::Merge val1 " << val1 <<
" val2 " << val2 <<
" value " << value <<
G4endl;
873 if( getenv(
"G4PHPTEST2") ) {
874 G4cout <<
" G4ParticleHPContAngularPar::Merge ANGPAR1 " <<
G4endl;
876 G4cout <<
" G4ParticleHPContAngularPar::Merge ANGPAR2 " <<
G4endl;
878 G4cout <<
" G4ParticleHPContAngularPar::Merge ANGPARNEW " <<
G4endl;
885 G4cout << theEnergy <<
" " << nEnergies <<
" " << nDiscreteEnergies <<
" " << nAngularParameters <<
G4endl;
887 for(
G4int ii=0; ii<nEnergies; ii++) {
888 theAngular[ii].
Dump();
G4double G4ParticleHPJENDLHEData::G4double result
std::map< G4double, G4int > GetDiscreteEnergiesOwn() const
void Init(G4int i, G4double e, G4int n)
G4int GetVectorLength() const
G4double GetTotalMomentum() const
void Init(std::istream &aDataFile, G4int nPar, G4double unit=1.)
G4ReactionProduct * Sample(G4double anEnergy, G4double massCode, G4double mass, G4int angularRep, G4int interpol)
void BuildByInterpolation(G4double anEnergy, G4InterpolationScheme aScheme, G4ParticleHPContAngularPar &store1, G4ParticleHPContAngularPar &store2)
G4double Interpolate2(G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
void Init(G4int aScheme, G4int aRange)
void SetKineticEnergy(const G4double en)
G4double GetMinEner() const
void SetMomentum(const G4double x, const G4double y, const G4double z)
G4double SampleMax(G4double energy)
void SetInterpolationManager(const G4InterpolationManager &aManager)
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
G4ParticleHPContAngularPar()
static constexpr double twopi
std::set< G4double > GetEnergiesTransformed() const
void SetY(G4int i, G4double x)
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
void Init(std::istream &aDataFile, G4ParticleDefinition *projectile)
const XML_Char int const XML_Char * value
G4int GetNEnergiesTransformed() const
void SetValue(G4int i, G4double y)
G4InterpolationScheme GetScheme(G4int index) const
static G4Triton * Triton()
static G4Proton * Proton()
static constexpr double eV
static constexpr double amu_c2
G4double GetX(G4int i) const
static G4Neutron * Neutron()
G4double GetY(G4double x)
G4double GetMaxEner() const
G4double GetWeightedBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
static G4Deuteron * Deuteron()
G4double Interpolate(G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
void SetLabel(G4double aLabel)
static G4IonTable * GetIonTable()
void SetManager(G4InterpolationManager &aManager)
static G4Positron * Positron()
G4int GetNDiscreteEnergies() const
G4double GetPDGMass() const
static G4double GetBindingEnergy(const G4int A, const G4int Z)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
void SetCoeff(G4int i, G4int l, G4double coeff)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4InterpolationScheme GetInverseScheme(G4int index)
static G4Electron * Electron()
G4double GetValue(G4int i)
G4double GetBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
void PrepareTableInterpolation(const G4ParticleHPContAngularPar *angularPrev)
void SetX(G4int i, G4double e)
G4double Sample(G4double anEnergy)
G4int GetNEnergies() const