66 if ( fCache.
Get() == 0 ) cacheInit();
67 fCache.
Get()->currentMeanEnergy = -2;
68 fCache.
Get()->fresh =
true;
74 theProjectile = projectile;
78 nDiscreteEnergies = 0;
79 nAngularParameters = 0;
87 theProjectile = projectile;
89 aDataFile >> theEnergy >> nEnergies >> nDiscreteEnergies >> nAngularParameters;
93 for(
G4int i=0; i<nEnergies; i++)
99 theAngular[i].
Init(aDataFile, nAngularParameters, 1.);
100 theMinEner = std::min(theMinEner,sEnergy);
101 theMaxEner = std::max(theMaxEner,sEnergy);
109 if( std::getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample " << anEnergy <<
" " << massCode <<
" " << angularRep <<
G4endl;
110 if ( fCache.
Get() == 0 ) cacheInit();
140 if(Z!=2)
throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar: Unknown ion case 1");
151 if( angularRep == 1 )
157 if ( nDiscreteEnergies != 0 )
162 if ( fCache.
Get()->fresh ==
true )
166 fCache.
Get()->remaining_energy = std::max ( theAngular[0].GetLabel() , theAngular[nEnergies-1].GetLabel() );
167 fCache.
Get()->fresh =
false;
172 if ( nDiscreteEnergies == nEnergies )
174 fCache.
Get()->remaining_energy = std::max ( fCache.
Get()->remaining_energy , theAngular[nDiscreteEnergies-1].
GetLabel() );
181 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
183 cont_min = theAngular[j].
GetLabel();
184 if ( theAngular[j].GetValue(0) != 0.0 )
break;
186 fCache.
Get()->remaining_energy = std::max ( fCache.
Get()->remaining_energy , std::min ( theAngular[nDiscreteEnergies-1].
GetLabel() , cont_min ) );
194 for (
G4int j = 0 ; j < nDiscreteEnergies ; j++ )
197 if ( theAngular[j].GetLabel() <= fCache.
Get()->remaining_energy ) delta = theAngular[i].
GetValue(0);
198 running[j+1] = running[j] + delta;
200 G4double tot_prob_DIS = running[ nDiscreteEnergies ];
202 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
207 if ( theAngular[j].GetLabel() <= fCache.
Get()->remaining_energy ) delta = theAngular[j].
GetValue(0);
214 if ( theAngular[j].GetLabel() != 0 )
216 if ( j == nDiscreteEnergies ) {
219 e_low = theAngular[j-1].
GetLabel()/eV;
221 e_high = theAngular[j].
GetLabel()/eV;
225 if ( theAngular[j].GetLabel() == 0.0 ) {
226 e_low = theAngular[j].
GetLabel()/eV;
227 if ( j != nEnergies-1 ) {
228 e_high = theAngular[j+1].
GetLabel()/eV;
230 e_high = theAngular[j].
GetLabel()/eV;
231 if ( theAngular[j].GetValue(0) != 0.0 ) {
232 throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar: Unexpected non zero value of theAngular[nEnergies-1].GetValue(0)");
237 running[j+1] = running[j] + ( ( e_high - e_low ) * delta );
239 G4double tot_prob_CON = running[ nEnergies ] - running[ nDiscreteEnergies ];
253 random *= (tot_prob_DIS + tot_prob_CON);
255 if ( random <= ( tot_prob_DIS / ( tot_prob_DIS + tot_prob_CON ) ) || nDiscreteEnergies == nEnergies )
258 for (
G4int j = 0 ; j < nDiscreteEnergies ; j++ )
261 if ( random < running[ j+1 ] )
267 fsEnergy = theAngular[ it ].
GetLabel();
270 theStore.
Init(0,fsEnergy,nAngularParameters);
271 for (
G4int j=0;j<nAngularParameters;j++)
273 theStore.
SetCoeff(0,j,theAngular[it].GetValue(j));
282 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
285 if ( random < running[ j ] )
296 if ( it != nDiscreteEnergies )
304 theStore.
Init(0,y1,nAngularParameters);
305 theStore.
Init(1,y2,nAngularParameters);
307 for (
G4int j=0;j<nAngularParameters;j++)
310 if ( it == nDiscreteEnergies ) itt = it+1;
317 theStore.
SetCoeff(0,j,theAngular[itt-1].GetValue(j));
318 theStore.
SetCoeff(1,j,theAngular[itt].GetValue(j));
327 if( adjustResult ) fCache.
Get()->remaining_energy -= fsEnergy;
339 if ( fCache.
Get()->fresh ==
true )
341 fCache.
Get()->remaining_energy = theAngular[ nEnergies-1 ].
GetLabel();
342 fCache.
Get()->fresh =
false;
349 for(i=1; i<nEnergies; i++)
364 running[i]=running[i-1];
365 if ( fCache.
Get()->remaining_energy >= theAngular[i].
GetLabel() )
377 if ( nEnergies == 1 || running[nEnergies-1] == 0 )
378 fCache.
Get()->currentMeanEnergy = 0.0;
381 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
385 if ( nEnergies == 1 ) it = 0;
388 if ( running[nEnergies-1] != 0 )
390 for ( i = 1 ; i < nEnergies ; i++ )
393 if ( random < running [ i ] / running [ nEnergies-1 ] )
break;
398 if ( running [ nEnergies-1 ] == 0 ) it = 0;
401 if (it<nDiscreteEnergies||it==0)
405 fsEnergy = theAngular[it].
GetLabel();
407 theStore.
Init(0,fsEnergy,nAngularParameters);
408 for(i=0;i<nAngularParameters;i++)
410 theStore.
SetCoeff(0,i,theAngular[it].GetValue(i));
422 running[it-1]/running[nEnergies-1],
423 running[it]/running[nEnergies-1],
427 theStore.
Init(0,e1,nAngularParameters);
428 theStore.
Init(1,e2,nAngularParameters);
429 for(i=0;i<nAngularParameters;i++)
431 theStore.
SetCoeff(0,i,theAngular[it-1].GetValue(i));
432 theStore.
SetCoeff(1,i,theAngular[it].GetValue(i));
441 G4double x1 = running[it-1]/running[nEnergies-1];
442 G4double x2 = running[it]/running[nEnergies-1];
448 theStore.
Init(0,y1,nAngularParameters);
449 theStore.
Init(1,y2,nAngularParameters);
451 for(i=0;i<nAngularParameters;i++)
453 theStore.
SetCoeff(0,i,theAngular[it-1].GetValue(i));
454 theStore.
SetCoeff(1,i,theAngular[it].GetValue(i));
462 if( adjustResult ) fCache.
Get()->remaining_energy -= fsEnergy;
466 else if(angularRep==2)
473 if( std::getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample nEnergies " << nEnergies <<
G4endl;
474 for(j=1; j<nEnergies; j++)
476 if(j!=0) running[j]=running[j-1];
483 if( std::getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample " << j <<
" running " << running[j]
489 if ( nEnergies == 1 )
490 fCache.
Get()->currentMeanEnergy = 0.0;
492 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
498 for(j=1; j<nEnergies; j++)
501 if(randkal<running[j]/running[nEnergies-1])
break;
507 x = randkal*running[nEnergies-1];
516 if( std::getenv(
"G4PHPTEST") )
G4cout << itt <<
" G4particleHPContAngularPar fsEnergy " << fsEnergy <<
" " << theManager.
GetInverseScheme(itt-1) <<
" x " << x <<
" " << x1 <<
" " << x2 <<
" y " << y1 <<
" " << y2 <<
G4endl;
521 fsEnergy, y1, y2, cLow,cHigh);
523 if ( compoundFraction > 1.0 ) compoundFraction = 1.0;
525 if( std::getenv(
"G4PHPTEST") )
G4cout << itt <<
" G4particleHPContAngularPar compoundFraction " << compoundFraction <<
" E " << fsEnergy <<
" " << theManager.
GetScheme(itt) <<
" ener " << fsEnergy <<
" y " << y1 <<
" " << y2 <<
" cLH " << cLow <<
" " << cHigh <<
G4endl;
534 G4int targetA =
G4int(fCache.
Get()->theTargetCode-1000*targetZ);
537 targetA =
G4int ( fCache.
Get()->theTarget->GetMass()/amu_c2 + 0.5 );
538 G4double targetMass = fCache.
Get()->theTarget->GetMass();
539 G4int incidentA=
G4int(incidentMass/amu_c2 + 0.5 );
541 G4int residualA = targetA+incidentA-
A;
542 G4int residualZ = targetZ+incidentZ-Z;
545 incidentEnergy, incidentMass,
546 productEnergy, productMass,
547 residualMass, residualA, residualZ,
548 targetMass, targetA, targetZ,
549 incidentA,incidentZ,
A,Z);
550 cosTh = theKallbach.
Sample(anEnergy);
551 if( std::getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPKallbachMannSyst::Sample resulttest " << cosTh <<
G4endl;
553 else if(angularRep>10&&angularRep<16)
559 for(i=1; i<nEnergies; i++)
561 if(i!=0) running[i]=running[i-1];
571 if ( nEnergies == 1 )
572 fCache.
Get()->currentMeanEnergy = 0.0;
574 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
577 if ( nEnergies == 1 ) it = 0;
579 for(i=1; i<nEnergies; i++)
582 if(random<running[i]/running[nEnergies-1])
break;
584 if(it<nDiscreteEnergies||it==0)
588 fsEnergy = theAngular[0].
GetLabel();
591 for(
G4int j=1; j<nAngularParameters; j+=2)
593 theStore.
SetX(aCounter, theAngular[0].GetValue(j));
594 theStore.
SetY(aCounter, theAngular[0].GetValue(j+1));
598 aMan.
Init(angularRep-10, nAngularParameters-1);
600 cosTh = theStore.
Sample();
604 fsEnergy = theAngular[it].
GetLabel();
607 aMan.
Init(angularRep-10, nAngularParameters-1);
611 for(
G4int j=1; j<nAngularParameters; j+=2)
613 theStore.
SetX(aCounter, theAngular[it].GetValue(j));
616 running[it-1]/running[nEnergies-1],
617 running[it]/running[nEnergies-1],
622 cosTh = theStore.
Sample();
627 G4double x1 = running[it-1]/running[nEnergies-1];
628 G4double x2 = running[it]/running[nEnergies-1];
636 aMan.
Init(angularRep-10, nAngularParameters-1);
650 for(i=0,j=1; i<nAngularParameters; i++,j+=2)
652 theBuff1.
SetX(i, theAngular[it-1].GetValue(j));
653 theBuff1.
SetY(i, theAngular[it-1].GetValue(j+1));
654 theBuff2.
SetX(i, theAngular[it].GetValue(j));
655 theBuff2.
SetY(i, theAngular[it].GetValue(j+1));
666 x = theBuff1.
GetX(i);
667 y1 = theBuff1.
GetY(i);
668 y2 = theBuff2.
GetY(i);
670 fsEnergy, theAngular[it-1].
GetLabel(),
675 cosTh = theStore.
Sample();
681 throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar::Sample: Unknown angular representation");
688 G4ThreeVector tempVector(mtot*sinth*std::cos(phi), mtot*sinth*std::sin(phi), mtot*std::cos(theta) );
702 for(ie=0; ie<nDiscreteEnergies; ie++) {
703 theDiscreteEnergiesOwn[theAngular[ie].
GetLabel()] = ie;
705 if( !angParPrev )
return;
708 for(ie=0; ie<nDiscreteEnergies; ie++) {
709 theDiscreteEnergies.insert(theAngular[ie].GetLabel());
712 for(ie=0; ie<nDiscreteEnergiesPrev; ie++) {
713 theDiscreteEnergies.insert(angParPrev->theAngular[ie].
GetLabel());
717 for(ie=nDiscreteEnergies; ie<nEnergies; ie++) {
719 G4double enerT = (ener-theMinEner)/(theMaxEner-theMinEner);
720 theEnergiesTransformed.insert(enerT);
726 for(ie=nDiscreteEnergiesPrev; ie<nEnergiesPrev; ie++) {
728 G4double enerT = (ener-minEnerPrev)/(maxEnerPrev-minEnerPrev);
729 theEnergiesTransformed.insert(enerT);
733 theEnergiesTransformed.insert(1.);
741 G4int ie,ie1,ie2, ie1Prev, ie2Prev;
742 nAngularParameters = angpar1.nAngularParameters;
743 theManager = angpar1.theManager;
744 theEnergy = anEnergy;
746 nDiscreteEnergies = theDiscreteEnergies.size();
747 std::set<G4double>::const_iterator itede;
750 std::map<G4double,G4int>::const_iterator itedeo;
752 for( itede = theDiscreteEnergies.begin(); itede != theDiscreteEnergies.end(); itede++, ie++ ) {
754 itedeo = discEnerOwn1.find(discEner);
755 if( itedeo == discEnerOwn1.end() ) {
760 itedeo = discEnerOwn2.find(discEner);
761 if( itedeo == discEnerOwn2.end() ) {
769 for(
G4int ip=0; ip<nAngularParameters; ip++) {
771 val1 = angpar1.theAngular[ie1].
GetValue(ip);
776 val2 = angpar2.theAngular[ie2].
GetValue(ip);
782 angpar1.theEnergy, angpar2.theEnergy,
785 if( std::getenv(
"G4PHPTEST2") )
G4cout << ie <<
" " << ip <<
" G4ParticleHPContAngularPar::Merge DiscreteEnergies val1 " << val1 <<
" val2 " << val2 <<
" value " << value <<
G4endl;
791 if(theAngular != 0)
delete [] theAngular;
799 if( std::getenv(
"G4PHPTEST2") )
G4cout <<
" G4ParticleHPContAngularPar::Merge E " << anEnergy <<
" minmax " << theMinEner <<
" " << theMaxEner <<
G4endl;
803 std::set<G4double>::const_iterator iteet = energiesTransformed.begin();
812 for(ie=nDiscreteEnergies; ie<nEnergies; ie++,iteet++) {
816 G4double e1 = (maxEner1-minEner1) * eT + minEner1;
818 for(ie1=nDiscreteEnergies1; ie1<nEnergies1; ie1++) {
819 if( (angpar1.theAngular[ie1].
GetLabel() - e1) > 1.E-10*e1 )
break;
822 if( ie1 == 0 ) ie1Prev++;
823 if( ie1 == nEnergies1 ) {
828 G4double e2 = (maxEner2-minEner2) * eT + minEner2;
830 for(ie2=nDiscreteEnergies2; ie2<nEnergies2; ie2++) {
832 if( (angpar2.theAngular[ie2].
GetLabel() - e2) > 1.E-10*e2 )
break;
835 if( ie2 == 0 ) ie2Prev++;
836 if( ie2 == nEnergies2 ) {
842 G4double eN = (theMaxEner-theMinEner) * eT + theMinEner;
843 if( std::getenv(
"G4PHPTEST2") )
G4cout << ie <<
" " << ie1 <<
" " << ie2 <<
" G4ParticleHPContAngularPar::loop eT " << eT <<
" -> eN " << eN <<
" e1 " << e1 <<
" e2 " << e2 <<
G4endl;
847 for(
G4int ip=0; ip<nAngularParameters; ip++) {
850 angpar1.theAngular[ie1Prev].
GetLabel(),
852 angpar1.theAngular[ie1Prev].
GetValue(ip),
853 angpar1.theAngular[ie1].
GetValue(ip)) * (maxEner1-minEner1);
856 angpar2.theAngular[ie2Prev].
GetLabel(),
858 angpar2.theAngular[ie2Prev].
GetValue(ip),
859 angpar2.theAngular[ie2].
GetValue(ip)) * (maxEner2-minEner2);
862 angpar1.theEnergy, angpar2.theEnergy,
866 if ( theMaxEner != theMinEner ) {
867 value /= (theMaxEner-theMinEner);
868 }
else if ( value != 0 ) {
869 throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar::PrepareTableInterpolation theMaxEner == theMinEner and value != 0.");
871 if( std::getenv(
"G4PHPTEST2") )
G4cout << ie <<
" " << ip <<
" G4ParticleHPContAngularPar::Merge val1 " << val1 <<
" val2 " << val2 <<
" value " << value <<
G4endl;
880 if( std::getenv(
"G4PHPTEST2") ) {
881 G4cout <<
" G4ParticleHPContAngularPar::Merge ANGPAR1 " <<
G4endl;
883 G4cout <<
" G4ParticleHPContAngularPar::Merge ANGPAR2 " <<
G4endl;
885 G4cout <<
" G4ParticleHPContAngularPar::Merge ANGPARNEW " <<
G4endl;
892 G4cout << theEnergy <<
" " << nEnergies <<
" " << nDiscreteEnergies <<
" " << nAngularParameters <<
G4endl;
894 for(
G4int ii=0; ii<nEnergies; ii++) {
895 theAngular[ii].
Dump();
double A(double temperature)
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(const G4ParticleHPContAngularPar *angularPrev)
G4int GetNEnergies() const
void Init(std::istream &aDataFile, G4ParticleDefinition *projectile)
std::map< G4double, G4int > GetDiscreteEnergiesOwn() const
G4int GetNDiscreteEnergies() const
std::set< G4double > GetEnergiesTransformed() const
G4double GetMinEner() const
G4ParticleHPContAngularPar()
void BuildByInterpolation(G4double anEnergy, G4InterpolationScheme aScheme, G4ParticleHPContAngularPar &store1, G4ParticleHPContAngularPar &store2)
G4double GetMaxEner() const
G4int GetNEnergiesTransformed() 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()