9#define M_PI 3.141592653589793238463
17#if defined __cplusplus
32static nfu_status MCGIDI_energy_parseMadlandNixFromTOM_callback(
double x,
double *y,
void *argList );
33static double MCGIDI_energy_parseMadlandNixFromTOM_callback_g(
double Ep,
double EFL,
double T_M,
nfu_status *status );
42static nfu_status MCGIDI_energy_NBodyPhaseSpacePDF_callback(
double x,
double *y,
void *argList );
79 if( energy->theta ) energy->theta =
ptwXY_free( energy->theta );
80 if( energy->Watt_a ) energy->Watt_a =
ptwXY_free( energy->Watt_a );
81 if( energy->Watt_b ) energy->Watt_b =
ptwXY_free( energy->Watt_b );
85 for( i = 0; i < energy->weightedFunctionals.numberOfWeights; i++ ) {
86 ptwXY_free( energy->weightedFunctionals.weightedFunctional[i].weight );
101 xDataTOM_element *energyElement, *linearElement, *functional, *frameElement;
102 char const *nativeData;
103 double projectileMass_MeV, targetMass_MeV;
109 energy->e_inCOMFactor = targetMass_MeV / ( projectileMass_MeV + targetMass_MeV );
112 energy->type = energyType;
113 energy->gammaEnergy_MeV = gammaEnergy_MeV;
121 if( linearElement == NULL ) {
123 if( MCGIDI_energy_parseGeneralEvaporationFromTOM( smr, functional, energy ) )
goto err; }
125 if( MCGIDI_energy_parseSimpleMaxwellianFissionFromTOM( smr, functional, energy ) )
goto err; }
127 if( MCGIDI_energy_parseEvaporationFromTOM( smr, functional, energy ) )
goto err; }
129 if( MCGIDI_energy_parseWattFromTOM( smr, functional, energy ) )
goto err; }
131 if( MCGIDI_energy_parseMadlandNixFromTOM( smr, functional, energy ) )
goto err; }
133 if( MCGIDI_energy_parseNBodyPhaseSpaceFromTOM( smr, functional, energy, distribution ) )
goto err; }
135 if( MCGIDI_energy_parseWeightedFunctionalsFromTOM( smr, functional, energy ) )
goto err; }
140 frameElement = functional; }
142 char const *toUnits[3] = {
"MeV",
"MeV",
"1/MeV" };
144 frameElement = linearElement;
150 distribution->
energy = energy;
167 if( strcmp( child->name,
"weighted" ) )
goto err;
168 if( MCGIDI_energy_parseWeightFromTOM( smr, child, &(
energy->weightedFunctionals.weightedFunctional[i]) ) )
goto err;
169 energy->weightedFunctionals.numberOfWeights++;
185 char const *toUnits[2] = {
"MeV",
"" };
189 if( strcmp( child->
name,
"weight" ) == 0 ) {
191 else if( strcmp( child->
name,
"evaporation" ) == 0 ) {
192 if( MCGIDI_energy_parseEvaporationFromTOM( smr, child, energy ) )
goto err; }
198 weightedFunctional->
weight = weight;
215 char const *toUnits[2] = {
"MeV",
"MeV" };
227 if( std::fabs( 1. - norm ) > 0.001 ) printf(
"bad norm = %e\n", norm );
243 char const *U, *toUnits[2] = {
"MeV",
"MeV" };
264 char const *U, *toUnits[2] = {
"MeV",
"MeV" };
285 char const *U, *toUnits[2] = {
"MeV",
"MeV" };
297 toUnits[1] =
"1/MeV";
312 int iE, length, nXs, i1,
n;
313 double E=0., T_M=0., EFL=0., EFH=0., argList[3] = { 0., 0., 0. },
314 xs[] = { 1e-5, 1e-3, 1e-1, 1e1, 1e3, 1e5, 3e7 }, norm;
323 char const *EF, *TMUnits[2] = {
"MeV",
"MeV" };
325 nXs =
sizeof( xs ) /
sizeof( xs[0] );
348 if( ( dists->
Ws = (
double *)
smr_malloc2( smr, length *
sizeof(
double ), 1,
"dists->Ws" ) ) == NULL )
goto err;
351 for( iE = 0; iE < length; iE++ ) {
354 dist = &(dists->
dist[iE]);
358 (
void *) argList, 1e-3, 0, 12, &status ) ) == NULL )
goto err;
367 if( ( dist->
Xs = (
double *)
smr_malloc2( smr, 3 * n *
sizeof(
double ), 0,
"dist->Xs" ) ) == NULL )
goto err;
369 dist->
pdf = &(dist->
Xs[
n]);
372 for( i1 = 0; i1 <
n; i1++ ) {
374 dist->
Xs[i1] = point->
x;
375 dist->
pdf[i1] = point->
y;
385 for( i1 = 0; i1 <
n; i1++ ) dist->
pdf[i1] /= norm;
396 if( ptwXY_TM != NULL )
ptwXY_free( ptwXY_TM );
398 if( cdfX != NULL ) cdfX =
ptwX_free( cdfX );
405static nfu_status MCGIDI_energy_parseMadlandNixFromTOM_callback(
double Ep,
double *y,
void *argList ) {
407 double *parameters = (
double *) argList, EFL, EFH, T_M;
413 *y = MCGIDI_energy_parseMadlandNixFromTOM_callback_g( Ep, EFL, T_M, &status );
414 if( status ==
nfu_Okay ) *y += MCGIDI_energy_parseMadlandNixFromTOM_callback_g( Ep, EFH, T_M, &status );
421static double MCGIDI_energy_parseMadlandNixFromTOM_callback_g(
double Ep,
double E_F,
double T_M,
nfu_status *status ) {
423 double u1, u2, E1, E2 = 0., gamma1 = 0., gamma2 = 0., signG = 1;
425 u1 = std::sqrt( Ep ) - std::sqrt( E_F );
427 u2 = std::sqrt( Ep ) + std::sqrt( E_F );
432 if( *status !=
nfu_Okay )
return( 0. );
441 if( *status !=
nfu_Okay )
return( 0. );
442 return( ( u2 * std::sqrt( u2 ) * E2 - u1 * std::sqrt( u1 ) * E1 + signG * ( gamma2 - gamma1 ) ) / ( 3 * std::sqrt( E_F * T_M ) ) );
451 double xs[2] = { 0.0, 1.0 }, productMass_MeV, norm;
462 argList[0] =
energy->NBodyPhaseSpace.numberOfProducts;
463 if( ( pdf =
ptwXY_createFromFunction( 2, xs, MCGIDI_energy_NBodyPhaseSpacePDF_callback, (
void *) argList, 1e-3, 0, 16, &status ) ) == NULL ) {
487static nfu_status MCGIDI_energy_NBodyPhaseSpacePDF_callback(
double x,
double *y,
void *argList ) {
489 int numberOfProducts = *((
int *) argList);
490 double e = 0.5 * ( 3 * numberOfProducts - 8 );
506 decaySamplingInfo->
frame = energy->frame;
507 switch( energy->type ) {
509 decaySamplingInfo->
Ep = energy->gammaEnergy_MeV + e_in * energy->primaryGammaMassFactor;
512 decaySamplingInfo->
Ep = energy->gammaEnergy_MeV;
515 randomEp = decaySamplingInfo->
rng( decaySamplingInfo->
rngState );
519 decaySamplingInfo->
Ep = sampled.
x;
525 decaySamplingInfo->
Ep = theta * sampled.
x;
529 MCGIDI_energy_sampleSimpleMaxwellianFission( smr, ( e_in - energy->U ) / theta, decaySamplingInfo );
530 decaySamplingInfo->
Ep *= theta;
534 MCGIDI_energy_sampleEvaporation( smr, ( e_in - energy->U ) / theta, decaySamplingInfo );
535 decaySamplingInfo->
Ep *= theta;
540 MCGIDI_energy_sampleWatt( smr, e_in - energy->U, Watt_a, Watt_b, decaySamplingInfo );
544 decaySamplingInfo->
Ep = sampled.
x;
548 decaySamplingInfo->
Ep = ( energy->e_inCOMFactor * e_in + energy->NBodyPhaseSpace.Q_MeV ) * energy->NBodyPhaseSpace.massFactor * sampled.
x;
551 MCGIDI_energy_sampleWeightedFunctional( smr, energy, modes, decaySamplingInfo );
565 double a = e_in_U_theta, b, c, x, norm_a, xMin = 0., xMax = a, sqrt_x, sqrt_pi_2 = std::sqrt(
M_PI ) / 2.;
567 sqrt_x = std::sqrt( a );
568 norm_a = sqrt_pi_2 * erf( sqrt_x ) - sqrt_x *
G4Exp( -a );
569 b = norm_a * decaySamplingInfo->
rng( decaySamplingInfo->
rngState );
570 for( i1 = 0; i1 < 16; i1++ ) {
571 x = 0.5 * ( xMin + xMax );
572 sqrt_x = std::sqrt( x );
573 c = sqrt_pi_2 * erf( sqrt_x ) - sqrt_x *
G4Exp( -x );
581 decaySamplingInfo->
Ep = x;
591 double a = e_in_U_theta, b, c, x, norm_a, xMin = 0., xMax = a;
593 norm_a = 1 - ( 1 + a ) *
G4Exp( -a );
594 b = 1. - norm_a * decaySamplingInfo->
rng( decaySamplingInfo->
rngState );
595 for( i1 = 0; i1 < 16; i1++ ) {
596 x = 0.5 * ( xMin + xMax );
597 c = ( 1 + x ) *
G4Exp( -x );
605 decaySamplingInfo->
Ep = x;
616 double WattMin = 0., WattMax = e_in_U, x, y, z, energyOut = 0., rand1, rand2;
618 x = 1. + ( Watt_b / ( 8. * Watt_a ) );
619 y = ( x + std::sqrt( x * x - 1. ) ) / Watt_a;
622 G4int icounter_max=1024;
626 if ( icounter > icounter_max ) {
627 G4cout <<
"Loop-counter exceeded the threshold value at " << __LINE__ <<
"th line of " << __FILE__ <<
"." <<
G4endl;
632 energyOut = y * rand1;
634 while( ( ( rand2 - z * ( rand1 + 1. ) ) * ( rand2 - z * ( rand1 + 1. ) ) > Watt_b * y * rand1 ) || ( energyOut < WattMin ) || ( energyOut > WattMax ) );
635 decaySamplingInfo->
Ep = energyOut;
648 double rW = decaySamplingInfo->
rng( decaySamplingInfo->
rngState ), cumulativeW = 0., weight;
651 for( iW = 0; iW <
energy->weightedFunctionals.numberOfWeights; iW++ ) {
652 weightedFunctional = &(
energy->weightedFunctionals.weightedFunctional[iW]);
654 cumulativeW += weight;
655 if( cumulativeW >= rW )
break;
660#if defined __cplusplus
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
G4double G4Log(G4double x)
G4GLOB_DLL std::ostream G4cout
double MCGIDI_sampling_ptwXY_getValueAtX(ptwXYPoints *ptwXY, double x1)
int MCGIDI_sampling_pdfsOfXGivenW_release(statusMessageReporting *smr, MCGIDI_pdfsOfXGivenW *dists)
MCGIDI_energy * MCGIDI_energy_free(statusMessageReporting *smr, MCGIDI_energy *energy)
int MCGIDI_energy_sampleEnergy(statusMessageReporting *smr, MCGIDI_energy *energy, MCGIDI_quantitiesLookupModes &modes, MCGIDI_decaySamplingInfo *decaySamplingInfo)
int MCGIDI_energy_initialize(statusMessageReporting *smr, MCGIDI_energy *energy)
int MCGIDI_sampling_pdfsOfX_release(statusMessageReporting *smr, MCGIDI_pdfOfX *dist)
double MCGIDI_outputChannel_getQ_MeV(statusMessageReporting *smr, MCGIDI_outputChannel *outputChannel, double e_in)
MCGIDI_energy * MCGIDI_energy_new(statusMessageReporting *smr)
int MCGIDI_energy_parseFromTOM(statusMessageReporting *smr, xDataTOM_element *element, MCGIDI_distribution *distribution, ptwXYPoints *norms, enum MCGIDI_energyType energyType, double gammaEnergy_MeV)
int MCGIDI_misc_PQUStringToDouble(statusMessageReporting *smr, char const *str, char const *unit, double conversion, double *value)
int MCGIDI_sampling_sampleX_from_pdfOfX(MCGIDI_pdfOfX *dist, MCGIDI_pdfsOfXGivenW_sampled *sampled, double r)
double MCGIDI_product_getMass_MeV(statusMessageReporting *smr, MCGIDI_product *product)
int MCGIDI_sampling_sampleX_from_pdfsOfXGivenW(MCGIDI_pdfsOfXGivenW *dists, MCGIDI_pdfsOfXGivenW_sampled *sampled, double r)
int MCGIDI_misc_PQUStringToDoubleInUnitOf(statusMessageReporting *smr, char const *str, char const *toUnit, double *value)
double MCGIDI_product_getTargetMass_MeV(statusMessageReporting *smr, MCGIDI_product *product)
double MCGIDI_product_getProjectileMass_MeV(statusMessageReporting *smr, MCGIDI_product *product)
int MCGIDI_energy_release(statusMessageReporting *smr, MCGIDI_energy *energy)
@ MCGIDI_energyType_NBodyPhaseSpace
@ MCGIDI_energyType_primaryGamma
@ MCGIDI_energyType_weightedFunctional
@ MCGIDI_energyType_simpleMaxwellianFission
@ MCGIDI_energyType_discreteGamma
@ MCGIDI_energyType_generalEvaporation
@ MCGIDI_energyType_MadlandNix
@ MCGIDI_energyType_evaporation
@ MCGIDI_energyType_linear
int MCGIDI_fromTOM_pdfsOfXGivenW(statusMessageReporting *smr, xDataTOM_element *element, MCGIDI_pdfsOfXGivenW *dists, ptwXYPoints *norms, char const *toUnits[3])
int MCGIDI_fromTOM_pdfOfX(statusMessageReporting *smr, ptwXYPoints *pdfXY, MCGIDI_pdfOfX *dist, double *norm)
ptwXYPoints * MCGIDI_misc_dataFromXYs2ptwXYPointsInUnitsOf(statusMessageReporting *smr, xDataTOM_XYs *XYs, ptwXY_interpolation interpolation, char const *units[2])
ptwXYPoints * MCGIDI_misc_dataFromElement2ptwXYPointsInUnitsOf(statusMessageReporting *smr, xDataTOM_element *linear, char const *toUnits[2])
enum xDataTOM_frame MCGIDI_misc_getProductFrame(statusMessageReporting *smr, xDataTOM_element *frameElement)
static G4Pow * GetInstance()
G4double powA(G4double A, G4double y) const
double getProjectileEnergy(void) const
G4double energy(const ThreeVector &p, const G4double m)
double nf_incompleteGammaFunctionComplementary(double a, double x, nfu_status *status)
double nf_incompleteGammaFunction(double a, double x, nfu_status *status)
double nf_exponentialIntegral(int n, double x, nfu_status *status)
enum nfu_status_e nfu_status
const char * nfu_statusMessage(nfu_status status)
ptwXY_interpolation ptwXY_getInterpolation(ptwXYPoints *ptwXY)
nfu_status ptwXY_simpleCoalescePoints(ptwXYPoints *ptwXY)
ptwXYPoint * ptwXY_getPointAtIndex_Unsafely(ptwXYPoints *ptwXY, int64_t index)
@ ptwXY_interpolationLinLin
int64_t ptwXY_length(ptwXYPoints *ptwXY)
ptwXYPoints * ptwXY_createFromFunction(int n, double *xs, ptwXY_createFromFunction_callback func, void *argList, double accuracy, int checkForRoots, int biSectionMax, nfu_status *status)
ptwXPoints * ptwXY_runningIntegral(ptwXYPoints *ptwXY, nfu_status *status)
nfu_status ptwXY_normalize(ptwXYPoints *ptwXY1)
nfu_status ptwXY_getXYPairAtIndex(ptwXYPoints *ptwXY, int64_t index, double *x, double *y)
ptwXYPoints * ptwXY_free(ptwXYPoints *ptwXY)
nfu_status(* ptwXY_createFromFunction_callback)(double x, double *y, void *argList)
double ptwX_getPointAtIndex_Unsafely(ptwXPoints *ptwX, int64_t index)
ptwXPoints * ptwX_free(ptwXPoints *ptwX)
#define smr_setReportError2(smr, libraryID, code, fmt,...)
void * smr_freeMemory(void **p)
int smr_isOk(statusMessageReporting *smr)
#define smr_malloc2(smr, size, zero, forItem)
enum xDataTOM_frame frame
ptwXY_interpolation interpolationXY
ptwXY_interpolation interpolationWY
ptwXY_interpolation interpolationXY
statusMessageReporting * smr
MCGIDI_outputChannel * outputChannel
xDataTOM_element * xDataTOME_getOneElementByName(statusMessageReporting *smr, xDataTOM_element *element, char const *name, int required)
xDataTOM_element * xDataTOME_getNextElement(xDataTOM_element *element)
char const * xDataTOM_getAttributesValueInElement(xDataTOM_element *element, char const *name)
int xDataTOME_convertAttributeToInteger(statusMessageReporting *smr, xDataTOM_element *element, char const *name, int *n)
xDataTOM_element * xDataTOME_getFirstElement(xDataTOM_element *element)
void * xDataTOME_getXDataIfID(statusMessageReporting *smr, xDataTOM_element *TE, char const *ID)