45 #include <tpia_target.h>
46 #include <tpia_misc.h>
50 #if defined __cplusplus
61 static const struct ZSymbol ZSymbols[] = { { 0,
"n" }, { 1,
"H" }, { 2,
"He" }, { 3,
"Li" }, { 4,
"Be" }, { 5,
"B" }, { 6,
"C" },
62 { 7,
"N" }, { 8,
"O" }, { 9,
"F" }, { 10,
"Ne" }, { 11,
"Na" }, { 12,
"Mg" }, { 13,
"Al" }, { 14,
"Si" }, { 15,
"P" },
63 { 16,
"S" }, { 17,
"Cl" }, { 18,
"Ar" }, { 19,
"K" }, { 20,
"Ca" }, { 21,
"Sc" }, { 22,
"Ti" }, { 23,
"V" }, { 24,
"Cr" },
64 { 25,
"Mn" }, { 26,
"Fe" }, { 27,
"Co" }, { 28,
"Ni" }, { 29,
"Cu" }, { 30,
"Zn" }, { 31,
"Ga" }, { 32,
"Ge" }, { 33,
"As" },
65 { 34,
"Se" }, { 35,
"Br" }, { 36,
"Kr" }, { 37,
"Rb" }, { 38,
"Sr" }, { 39,
"Y" }, { 40,
"Zr" }, { 41,
"Nb" }, { 42,
"Mo" },
66 { 43,
"Tc" }, { 44,
"Ru" }, { 45,
"Rh" }, { 46,
"Pd" }, { 47,
"Ag" }, { 48,
"Cd" }, { 49,
"In" }, { 50,
"Sn" }, { 51,
"Sb" },
67 { 52,
"Te" }, { 53,
"I" }, { 54,
"Xe" }, { 55,
"Cs" }, { 56,
"Ba" }, { 57,
"La" }, { 58,
"Ce" }, { 59,
"Pr" }, { 60,
"Nd" },
68 { 61,
"Pm" }, { 62,
"Sm" }, { 63,
"Eu" }, { 64,
"Gd" }, { 65,
"Tb" }, { 66,
"Dy" }, { 67,
"Ho" }, { 68,
"Er" }, { 69,
"Tm" },
69 { 70,
"Yb" }, { 71,
"Lu" }, { 72,
"Hf" }, { 73,
"Ta" }, { 74,
"W" }, { 75,
"Re" }, { 76,
"Os" }, { 77,
"Ir" }, { 78,
"Pt" },
70 { 79,
"Au" }, { 80,
"Hg" }, { 81,
"Tl" }, { 82,
"Pb" }, { 83,
"Bi" }, { 84,
"Po" }, { 85,
"At" }, { 86,
"Rn" }, { 87,
"Fr" },
71 { 88,
"Ra" }, { 89,
"Ac" }, { 90,
"Th" }, { 91,
"Pa" }, { 92,
"U" }, { 93,
"Np" }, { 94,
"Pu" }, { 95,
"Am" }, { 96,
"Cm" },
72 { 97,
"Bk" }, { 98,
"Cf" }, { 99,
"Es" }, { 100,
"Fm" }, { 101,
"Md" }, { 102,
"No" }, { 103,
"Lr" }, { 104,
"Rf" }, { 105,
"Db" },
73 { 106,
"Sg" }, { 107,
"Bh" }, { 108,
"Hs" }, { 109,
"Mt" } };
80 return(
sizeof( ZSymbols ) /
sizeof(
struct ZSymbol ) );
89 return( ZSymbols[iZ].
symbol.c_str() );
98 for( i = 0; i <
n; i++ ) {
100 if( !strcmp( Z, ZSymbols[i].
symbol.c_str() ) )
return( ZSymbols[i].Z );
111 char s[1024] =
"", *q, *e;
116 if( !strncmp(
"FissionProduct", name, 14 ) ) {
121 if( !strcmp(
"gamma", name ) )
return( 0 );
122 for( p = name, q = s, i = 0; ( *p !=
'_' ) && ( i != n ); p++, q++, i++ ) *q = *p;
124 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Failed to find first '_' in particle name %s", name ); }
128 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Particle %s's symbol = '%s' not found", name, s ); }
130 for( p++, q = s; ( *p !=
'_' ) && ( *p != 0 ) && ( i !=
n ); p++, q++, i++ ) *q = *p;
132 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Failed to find second '_' in particle name %s", name ); }
135 if( strcmp( s,
"natural" ) == 0 ) {
139 *A = (int) strtol( s, &e, 10 );
142 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Failed to convert A to integer in particle name %s", name ); }
148 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Particle name %s missing meta-stable label 'm'", name ); }
151 *m = (int) strtol( p, &e, 10 );
152 if( *e != 0 )
smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Failed to convert m to integer in particle name %s", name );
166 xData_attributionList *attributes,
const char *
name,
const char *file,
int line ) {
170 if( !
smr_isOk( smr ) )
return( NULL );
173 if( element != NULL ) {
176 smr_setMessageError( smr, NULL, file, line, 1,
"element does not have attribute named %s for file = %d", name, path );
186 const char *fmt, ... ) {
192 va_start( args, fmt );
197 va_start( args, fmt );
201 status =
smr_setMessageError( smr, userInterface, file, line, code,
"%s for element %s at line %d column %d", msg, element->fullName,
202 (
int) element->docInfo.line, (
int) element->docInfo.column );
212 xData_Int imin = 0, imid,
imax = n - 1;
214 if( d < ds[0] )
return( -2 );
215 if( d > ds[n-1] )
return( -1 );
217 imid = ( imin +
imax ) >> 1;
218 if( imid == imin )
break;
232 xData_element *xDataElement;
242 *length = (xData_Int) length_;
252 xData_element *xDataElement;
260 if( start != NULL ) *start = xDataElement->xDataTypeInfo.start;
261 if( end != NULL ) *end = xDataElement->xDataTypeInfo.end;
273 xData_element *xDataElement;
281 if( start != NULL ) *start = xDataElement->xDataTypeInfo.start;
282 if( end != NULL ) *end = xDataElement->xDataTypeInfo.end;
283 if( length != NULL ) *length = xDataElement->xDataTypeInfo.length;
302 double xsec = 0.0,
e1,
e2;
304 if( ( index >= crossSection->start ) && ( index < crossSection->end ) ) {
305 e1 = energyGrid[index];
306 e2 = energyGrid[index + 1];
307 index -= crossSection->start;
309 xsec = 0.5 * ( crossSection->data[index] + crossSection->data[index + 1] ); }
311 xsec = ( crossSection->data[index] * ( e2 - e_in ) + crossSection->data[index + 1] * ( e_in -
e1 ) ) / ( e2 -
e1 );
321 xData_element *element;
340 xData_Int index, size;
341 xData_elementList *list;
342 xData_element *element, *xData;
344 tpia_EqualProbableBinSpectrum *epbs = NULL, *epb;
352 size = list->n * (
sizeof( tpia_EqualProbableBinSpectrum ) + ( nBins + 1 ) *
sizeof( double ) );
354 if( ( epbs = (tpia_EqualProbableBinSpectrum*) xData_malloc2( smr, size, 0,
"energies" ) ) != NULL ) {
355 d = (
double *) &(epbs[list->n]);
356 for( i = 0, epb = epbs; i < list->n; i++, epb++ ) {
357 element = list->items[i].element;
362 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
368 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
378 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
383 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
392 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
410 r = rng( rngState ); }
413 r = CLHEP::HepRandom::getTheEngine()->flat();
423 tpia_EqualProbableBinSpectra *binned,
double *value_ ) {
425 int i, j, index1, index2, method = 0;
426 double fE = 1., r, value1, value2, value3,
P12,
P23, value = -2.;
428 if( e_in <= binned->energies[0].value ) {
431 else if( e_in >= binned->energies[binned->numberOfEs-1].value ) {
432 index1 = binned->numberOfEs - 1;
433 index2 = binned->numberOfEs - 1; }
435 for( i = 0; i < binned->numberOfEs - 1; i++ ) {
436 if( e_in <= binned->energies[i].value )
break;
441 if( e_in != binned->energies[i].value ) {
443 fE = ( e_in - binned->energies[i].value ) / ( binned->energies[i+1].value - binned->energies[i].value );
446 r =
tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
447 j = (int) (r * nBins);
448 if( j >= nBins ) j = nBins - 1;
450 r =
tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
451 if( tpia_samplingMethods_isLinear( decaySamplingInfo->samplingMethods->angular_equalProbableBinMethod ) ) {
453 if( ( ( j == 0 ) && ( r <= 0.5 ) ) || ( j == ( nBins - 1 ) && r > 0.5 ) ) method = 0;
456 value1 = ( 1. - fE ) * binned->energies[index1].bins[j] + fE * binned->energies[index2].bins[j];
457 value2 = ( 1. - fE ) * binned->energies[index1].bins[j+1] + fE * binned->energies[index2].bins[j+1];
458 value = ( 1. - r ) * value1 + r * value2; }
461 value1 = ( 1. - fE ) * binned->energies[index1].bins[j] + fE * binned->energies[index2].bins[j];
462 value2 = ( 1. - fE ) * binned->energies[index1].bins[j+1] + fE * binned->energies[index2].bins[j+1];
463 value3 = ( 1. - fE ) * binned->energies[index1].bins[j+2] + fE * binned->energies[index2].bins[j+2];
466 if ( value1 == value2 && value2 == value3 ) {
470 if ( value2 != value1 )
471 P12 = 1. / ( value2 - value1 );
475 if ( value3 != value2 )
476 P23 = 1. / ( value3 - value2 );
480 r =
tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
481 if( 0.25 * ( 1.0 + 2.0 * ( value2 - value1 ) / ( value3 - value1 ) ) > r ) {
482 P23 = 2. / ( value3 - value1 );
485 P12 = 2. / ( value3 - value1 );
488 r =
tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
489 if( P23 != P12 ) r = ( -P12 + std::sqrt( P12 * P12 * ( 1. - r ) + r * P23 * P23 ) ) / ( P23 - P12 );
490 value = 0.5 * ( value1 + value2 + r * ( value3 - value1 ) );
498 #if defined __cplusplus
xData_Int xData_convertAttributeTo_xData_Int(statusMessageReporting *smr, xData_element *element, const char *name, xData_Int *n)
xData_element * xData_getOneElementByTagName(statusMessageReporting *smr, xData_element *element, char *name, int required)
int xData_addToAccessed(statusMessageReporting *, xData_element *element, int increment)
char * tpia_misc_pointerToAttributeIfAllOk(statusMessageReporting *smr, xData_element *element, const char *path, int required, xData_attributionList *attributes, const char *name, const char *file, int line)
int tpia_misc_get2d_xShared_yHistogram_data_Grouped(statusMessageReporting *smr, xData_element *element, tpia_1dData *group)
int tpia_misc_NumberOfZSymbols(void)
xData_element * xData_getElements_xDataElement(statusMessageReporting *smr, xData_element *element)
double * xData_2d_xShared_yHistogram_copyData(statusMessageReporting *, xData_element *element, xData_Int *n)
int xData_is_2d_xy(statusMessageReporting *smr, xDataType *xDT, int setMsg)
tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBin(statusMessageReporting *smr, xData_element *parent, xData_Int *n, xData_Int *nBins)
int tpia_misc_setMessageError_Element(statusMessageReporting *smr, void *userInterface, xData_element *element, const char *file, int line, int code, const char *fmt,...)
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
char * xData_getAttributesValue(xData_attributionList *attributes, const char *name)
static const G4double P12[nE]
double tpia_misc_drng(double(*rng)(void *), void *rngState)
double * tpia_misc_get2d_xShared_yHistogram_data(statusMessageReporting *smr, xData_element *element, xData_Int *start, xData_Int *end, xData_Int *length)
int tpia_misc_symbolToZ(const char *Z)
double * xData_2d_xy_allocateCopyData(statusMessageReporting *smr, xData_element *element, xData_Int *length)
xData_elementList * xData_getElementsByTagNameAndSort(statusMessageReporting *smr, xData_element *element, const char *tagName, const char *sortAttributeName, xData_sortElementFunc sortFunction)
double * xData_2d_xindex_y_toFilledYs(statusMessageReporting *smr, xData_element *element, double *Xs)
int smr_isOk(statusMessageReporting *smr)
int tpia_miscNameToZAm(statusMessageReporting *smr, const char *name, int *Z, int *A, int *m)
tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBins(statusMessageReporting *smr, xData_element *parent, const char *name, xData_Int nBins, xData_Int *n)
xData_Int tpia_misc_binarySearch(xData_Int n, double *ds, double d)
static const G4double A[nN]
static const G4double P23[nE]
int xData_1d_x_copyData(statusMessageReporting *smr, xData_element *element, xData_Int nAllocatedBytes, double *d)
const char * tpia_misc_ZToSymbol(int iZ)
void * xData_free(statusMessageReporting *, void *p)
int tpia_misc_sampleEqualProbableBin(statusMessageReporting *, tpia_decaySamplingInfo *decaySamplingInfo, double e_in, int nBins, tpia_EqualProbableBinSpectra *binned, double *value_)
double * tpia_misc_get2dxindex_y_data(statusMessageReporting *smr, xData_element *element, xData_Int *start, xData_Int *end, double *xValues)
double tpia_misc_getPointwiseCrossSectionAtE(statusMessageReporting *, tpia_1dData *crossSection, double *energyGrid, xData_Int index, double e_in)
int xData_convertAttributeToDouble(statusMessageReporting *smr, xData_element *element, const char *name, double *d)
double * tpia_misc_get2dx_y_data(statusMessageReporting *smr, xData_element *element, xData_Int *length)
int xData_is_2d_xindex_y(statusMessageReporting *smr, xDataType *xDT, int setMsg)
static const struct ZSymbol ZSymbols[]
int smr_vsetMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt, va_list *args)
char * smr_vallocateFormatMessage(const char *fmt, va_list *args)
void xData_freeElementList(statusMessageReporting *smr, xData_elementList *list)