6#define _USE_MATH_DEFINES
15#if defined __cplusplus
30static nfu_status MCGIDI_energy_parseMadlandNixFromTOM_callback(
double x,
double *y,
void *argList );
31static double MCGIDI_energy_parseMadlandNixFromTOM_callback_g(
double Ep,
double EFL,
double T_M,
nfu_status *status );
40static nfu_status MCGIDI_energy_NBodyPhaseSpacePDF_callback(
double x,
double *y,
void *argList );
77 if( energy->theta ) energy->theta =
ptwXY_free( energy->theta );
78 if( energy->Watt_a ) energy->Watt_a =
ptwXY_free( energy->Watt_a );
79 if( energy->Watt_b ) energy->Watt_b =
ptwXY_free( energy->Watt_b );
83 for( i = 0; i < energy->weightedFunctionals.numberOfWeights; i++ ) {
84 ptwXY_free( energy->weightedFunctionals.weightedFunctional[i].weight );
100 char const *nativeData;
101 double projectileMass_MeV, targetMass_MeV;
107 energy->e_inCOMFactor = targetMass_MeV / ( projectileMass_MeV + targetMass_MeV );
110 energy->type = energyType;
111 energy->gammaEnergy_MeV = gammaEnergy_MeV;
119 if( linearElement == NULL ) {
121 if( MCGIDI_energy_parseGeneralEvaporationFromTOM( smr, functional, energy ) )
goto err; }
123 if( MCGIDI_energy_parseSimpleMaxwellianFissionFromTOM( smr, functional, energy ) )
goto err; }
125 if( MCGIDI_energy_parseEvaporationFromTOM( smr, functional, energy ) )
goto err; }
127 if( MCGIDI_energy_parseWattFromTOM( smr, functional, energy ) )
goto err; }
129 if( MCGIDI_energy_parseMadlandNixFromTOM( smr, functional, energy ) )
goto err; }
131 if( MCGIDI_energy_parseNBodyPhaseSpaceFromTOM( smr, functional, energy, distribution ) )
goto err; }
133 if( MCGIDI_energy_parseWeightedFunctionalsFromTOM( smr, functional, energy ) )
goto err; }
138 frameElement = functional; }
140 char const *toUnits[3] = {
"MeV",
"MeV",
"1/MeV" };
142 frameElement = linearElement;
148 distribution->
energy = energy;
165 if( strcmp( child->name,
"weighted" ) )
goto err;
166 if( MCGIDI_energy_parseWeightFromTOM( smr, child, &(
energy->weightedFunctionals.weightedFunctional[i]) ) )
goto err;
167 energy->weightedFunctionals.numberOfWeights++;
183 char const *toUnits[2] = {
"MeV",
"" };
187 if( strcmp( child->
name,
"weight" ) == 0 ) {
189 else if( strcmp( child->
name,
"evaporation" ) == 0 ) {
190 if( MCGIDI_energy_parseEvaporationFromTOM( smr, child, energy ) )
goto err; }
196 weightedFunctional->
weight = weight;
213 char const *toUnits[2] = {
"MeV",
"MeV" };
225 if( std::fabs( 1. - norm ) > 0.001 ) printf(
"bad norm = %e\n", norm );
241 char const *U, *toUnits[2] = {
"MeV",
"MeV" };
262 char const *U, *toUnits[2] = {
"MeV",
"MeV" };
283 char const *U, *toUnits[2] = {
"MeV",
"MeV" };
295 toUnits[1] =
"1/MeV";
310 int iE, length, nXs, i1,
n;
311 double E=0., T_M=0., EFL=0., EFH=0., argList[3] = { 0., 0., 0. },
312 xs[] = { 1e-5, 1e-3, 1e-1, 1e1, 1e3, 1e5, 3e7 }, norm;
321 char const *EF, *TMUnits[2] = {
"MeV",
"MeV" };
323 nXs =
sizeof( xs ) /
sizeof( xs[0] );
346 if( ( dists->
Ws = (
double *)
smr_malloc2( smr, length *
sizeof(
double ), 1,
"dists->Ws" ) ) == NULL )
goto err;
349 for( iE = 0; iE < length; iE++ ) {
352 dist = &(dists->
dist[iE]);
356 (
void *) argList, 1e-3, 0, 12, &status ) ) == NULL )
goto err;
365 if( ( dist->
Xs = (
double *)
smr_malloc2( smr, 3 * n *
sizeof(
double ), 0,
"dist->Xs" ) ) == NULL )
goto err;
367 dist->
pdf = &(dist->
Xs[
n]);
370 for( i1 = 0; i1 <
n; i1++ ) {
372 dist->
Xs[i1] = point->
x;
373 dist->
pdf[i1] = point->
y;
383 for( i1 = 0; i1 <
n; i1++ ) dist->
pdf[i1] /= norm;
394 if( ptwXY_TM != NULL )
ptwXY_free( ptwXY_TM );
396 if( cdfX != NULL ) cdfX =
ptwX_free( cdfX );
403static nfu_status MCGIDI_energy_parseMadlandNixFromTOM_callback(
double Ep,
double *y,
void *argList ) {
405 double *parameters = (
double *) argList, EFL, EFH, T_M;
411 *y = MCGIDI_energy_parseMadlandNixFromTOM_callback_g( Ep, EFL, T_M, &status );
412 if( status ==
nfu_Okay ) *y += MCGIDI_energy_parseMadlandNixFromTOM_callback_g( Ep, EFH, T_M, &status );
419static double MCGIDI_energy_parseMadlandNixFromTOM_callback_g(
double Ep,
double E_F,
double T_M,
nfu_status *status ) {
421 double u1, u2, E1, E2 = 0., gamma1 = 0., gamma2 = 0., signG = 1;
423 u1 = std::sqrt( Ep ) - std::sqrt( E_F );
425 u2 = std::sqrt( Ep ) + std::sqrt( E_F );
430 if( *status !=
nfu_Okay )
return( 0. );
439 if( *status !=
nfu_Okay )
return( 0. );
440 return( ( u2 * std::sqrt( u2 ) * E2 - u1 * std::sqrt( u1 ) * E1 + signG * ( gamma2 - gamma1 ) ) / ( 3 * std::sqrt( E_F * T_M ) ) );
449 double xs[2] = { 0.0, 1.0 }, productMass_MeV, norm;
460 argList[0] =
energy->NBodyPhaseSpace.numberOfProducts;
461 if( ( pdf =
ptwXY_createFromFunction( 2, xs, MCGIDI_energy_NBodyPhaseSpacePDF_callback, (
void *) argList, 1e-3, 0, 16, &status ) ) == NULL ) {
485static nfu_status MCGIDI_energy_NBodyPhaseSpacePDF_callback(
double x,
double *y,
void *argList ) {
487 int numberOfProducts = *((
int *) argList);
488 double e = 0.5 * ( 3 * numberOfProducts - 8 );
504 decaySamplingInfo->
frame = energy->frame;
505 switch( energy->type ) {
507 decaySamplingInfo->
Ep = energy->gammaEnergy_MeV + e_in * energy->primaryGammaMassFactor;
510 decaySamplingInfo->
Ep = energy->gammaEnergy_MeV;
513 randomEp = decaySamplingInfo->
rng( decaySamplingInfo->
rngState );
517 decaySamplingInfo->
Ep = sampled.
x;
523 decaySamplingInfo->
Ep = theta * sampled.
x;
527 MCGIDI_energy_sampleSimpleMaxwellianFission( smr, ( e_in - energy->U ) / theta, decaySamplingInfo );
528 decaySamplingInfo->
Ep *= theta;
532 MCGIDI_energy_sampleEvaporation( smr, ( e_in - energy->U ) / theta, decaySamplingInfo );
533 decaySamplingInfo->
Ep *= theta;
538 MCGIDI_energy_sampleWatt( smr, e_in - energy->U, Watt_a, Watt_b, decaySamplingInfo );
542 decaySamplingInfo->
Ep = sampled.
x;
546 decaySamplingInfo->
Ep = ( energy->e_inCOMFactor * e_in + energy->NBodyPhaseSpace.Q_MeV ) * energy->NBodyPhaseSpace.massFactor * sampled.
x;
549 MCGIDI_energy_sampleWeightedFunctional( smr, energy, modes, decaySamplingInfo );
563 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.;
565 sqrt_x = std::sqrt( a );
566 norm_a = sqrt_pi_2 * erf( sqrt_x ) - sqrt_x *
G4Exp( -a );
567 b = norm_a * decaySamplingInfo->
rng( decaySamplingInfo->
rngState );
568 for( i1 = 0; i1 < 16; i1++ ) {
569 x = 0.5 * ( xMin + xMax );
570 sqrt_x = std::sqrt( x );
571 c = sqrt_pi_2 * erf( sqrt_x ) - sqrt_x *
G4Exp( -x );
579 decaySamplingInfo->
Ep = x;
589 double a = e_in_U_theta, b, c, x, norm_a, xMin = 0., xMax = a;
591 norm_a = 1 - ( 1 + a ) *
G4Exp( -a );
592 b = 1. - norm_a * decaySamplingInfo->
rng( decaySamplingInfo->
rngState );
593 for( i1 = 0; i1 < 16; i1++ ) {
594 x = 0.5 * ( xMin + xMax );
595 c = ( 1 + x ) *
G4Exp( -x );
603 decaySamplingInfo->
Ep = x;
614 double WattMin = 0., WattMax = e_in_U, x, y, z, energyOut = 0., rand1, rand2;
616 x = 1. + ( Watt_b / ( 8. * Watt_a ) );
617 y = ( x + std::sqrt( x * x - 1. ) ) / Watt_a;
620 G4int icounter_max=1024;
624 if ( icounter > icounter_max ) {
625 G4cout <<
"Loop-counter exceeded the threshold value at " << __LINE__ <<
"th line of " << __FILE__ <<
"." <<
G4endl;
630 energyOut = y * rand1;
632 while( ( ( rand2 - z * ( rand1 + 1. ) ) * ( rand2 - z * ( rand1 + 1. ) ) > Watt_b * y * rand1 ) || ( energyOut < WattMin ) || ( energyOut > WattMax ) );
633 decaySamplingInfo->
Ep = energyOut;
646 double rW = decaySamplingInfo->
rng( decaySamplingInfo->
rngState ), cumulativeW = 0., weight;
649 for( iW = 0; iW <
energy->weightedFunctionals.numberOfWeights; iW++ ) {
650 weightedFunctional = &(
energy->weightedFunctionals.weightedFunctional[iW]);
652 cumulativeW += weight;
653 if( cumulativeW >= rW )
break;
658#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)