43 #include <tpia_target.h>
44 #include <tpia_misc.h>
48 #if defined __cplusplus
59 static const struct ZSymbol ZSymbols[] = { { 0,
"n" }, { 1,
"H" }, { 2,
"He" }, { 3,
"Li" }, { 4,
"Be" }, { 5,
"B" }, { 6,
"C" },
60 { 7,
"N" }, { 8,
"O" }, { 9,
"F" }, { 10,
"Ne" }, { 11,
"Na" }, { 12,
"Mg" }, { 13,
"Al" }, { 14,
"Si" }, { 15,
"P" },
61 { 16,
"S" }, { 17,
"Cl" }, { 18,
"Ar" }, { 19,
"K" }, { 20,
"Ca" }, { 21,
"Sc" }, { 22,
"Ti" }, { 23,
"V" }, { 24,
"Cr" },
62 { 25,
"Mn" }, { 26,
"Fe" }, { 27,
"Co" }, { 28,
"Ni" }, { 29,
"Cu" }, { 30,
"Zn" }, { 31,
"Ga" }, { 32,
"Ge" }, { 33,
"As" },
63 { 34,
"Se" }, { 35,
"Br" }, { 36,
"Kr" }, { 37,
"Rb" }, { 38,
"Sr" }, { 39,
"Y" }, { 40,
"Zr" }, { 41,
"Nb" }, { 42,
"Mo" },
64 { 43,
"Tc" }, { 44,
"Ru" }, { 45,
"Rh" }, { 46,
"Pd" }, { 47,
"Ag" }, { 48,
"Cd" }, { 49,
"In" }, { 50,
"Sn" }, { 51,
"Sb" },
65 { 52,
"Te" }, { 53,
"I" }, { 54,
"Xe" }, { 55,
"Cs" }, { 56,
"Ba" }, { 57,
"La" }, { 58,
"Ce" }, { 59,
"Pr" }, { 60,
"Nd" },
66 { 61,
"Pm" }, { 62,
"Sm" }, { 63,
"Eu" }, { 64,
"Gd" }, { 65,
"Tb" }, { 66,
"Dy" }, { 67,
"Ho" }, { 68,
"Er" }, { 69,
"Tm" },
67 { 70,
"Yb" }, { 71,
"Lu" }, { 72,
"Hf" }, { 73,
"Ta" }, { 74,
"W" }, { 75,
"Re" }, { 76,
"Os" }, { 77,
"Ir" }, { 78,
"Pt" },
68 { 79,
"Au" }, { 80,
"Hg" }, { 81,
"Tl" }, { 82,
"Pb" }, { 83,
"Bi" }, { 84,
"Po" }, { 85,
"At" }, { 86,
"Rn" }, { 87,
"Fr" },
69 { 88,
"Ra" }, { 89,
"Ac" }, { 90,
"Th" }, { 91,
"Pa" }, { 92,
"U" }, { 93,
"Np" }, { 94,
"Pu" }, { 95,
"Am" }, { 96,
"Cm" },
70 { 97,
"Bk" }, { 98,
"Cf" }, { 99,
"Es" }, { 100,
"Fm" }, { 101,
"Md" }, { 102,
"No" }, { 103,
"Lr" }, { 104,
"Rf" }, { 105,
"Db" },
71 { 106,
"Sg" }, { 107,
"Bh" }, { 108,
"Hs" }, { 109,
"Mt" } };
78 return(
sizeof( ZSymbols ) /
sizeof(
struct ZSymbol ) );
87 return( ZSymbols[iZ].
symbol.c_str() );
96 for( i = 0; i <
n; i++ ) {
98 if( !strcmp( Z, ZSymbols[i].
symbol.c_str() ) )
return( ZSymbols[i].Z );
109 char s[1024] =
"", *q, *e;
114 if( !strncmp(
"FissionProduct", name, 14 ) ) {
119 if( !strcmp(
"gamma", name ) )
return( 0 );
120 for( p = name, q = s, i = 0; ( *p !=
'_' ) && ( i != n ); p++, q++, i++ ) *q = *p;
122 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Failed to find first '_' in particle name %s", name ); }
126 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Particle %s's symbol = '%s' not found", name, s ); }
128 for( p++, q = s; ( *p !=
'_' ) && ( *p != 0 ) && ( i !=
n ); p++, q++, i++ ) *q = *p;
130 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Failed to find second '_' in particle name %s", name ); }
133 if( strcmp( s,
"natural" ) == 0 ) {
137 *A = (int) strtol( s, &e, 10 );
140 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Failed to convert A to integer in particle name %s", name ); }
146 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Particle name %s missing meta-stable label 'm'", name ); }
149 *m = (int) strtol( p, &e, 10 );
150 if( *e != 0 )
smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Failed to convert m to integer in particle name %s", name );
164 xData_attributionList *attributes,
const char *
name,
const char *file,
int line ) {
168 if( !
smr_isOk( smr ) )
return( NULL );
171 if( element != NULL ) {
174 smr_setMessageError( smr, NULL, file, line, 1,
"element does not have attribute named %s for file = %d", name, path );
184 const char *fmt, ... ) {
190 va_start( args, fmt );
195 va_start( args, fmt );
199 status =
smr_setMessageError( smr, userInterface, file, line, code,
"%s for element %s at line %d column %d", msg, element->fullName,
200 (
int) element->docInfo.line, (
int) element->docInfo.column );
210 xData_Int imin = 0, imid,
imax = n - 1;
212 if( d < ds[0] )
return( -2 );
213 if( d > ds[n-1] )
return( -1 );
215 imid = ( imin +
imax ) >> 1;
216 if( imid == imin )
break;
230 xData_element *xDataElement;
240 *length = (xData_Int) length_;
250 xData_element *xDataElement;
258 if( start != NULL ) *start = xDataElement->xDataTypeInfo.start;
259 if( end != NULL ) *end = xDataElement->xDataTypeInfo.end;
271 xData_element *xDataElement;
279 if( start != NULL ) *start = xDataElement->xDataTypeInfo.start;
280 if( end != NULL ) *end = xDataElement->xDataTypeInfo.end;
281 if( length != NULL ) *length = xDataElement->xDataTypeInfo.length;
300 double xsec = 0.0,
e1,
e2;
302 if( ( index >= crossSection->start ) && ( index < crossSection->end ) ) {
303 e1 = energyGrid[index];
304 e2 = energyGrid[index + 1];
305 index -= crossSection->start;
307 xsec = 0.5 * ( crossSection->data[index] + crossSection->data[index + 1] ); }
309 xsec = ( crossSection->data[index] * ( e2 - e_in ) + crossSection->data[index + 1] * ( e_in -
e1 ) ) / ( e2 -
e1 );
319 xData_element *element;
338 xData_Int index, size;
339 xData_elementList *list;
340 xData_element *element, *xData;
342 tpia_EqualProbableBinSpectrum *epbs = NULL, *epb;
350 size = list->n * (
sizeof( tpia_EqualProbableBinSpectrum ) + ( nBins + 1 ) *
sizeof( double ) );
352 if( ( epbs = (tpia_EqualProbableBinSpectrum*) xData_malloc2( smr, size, 0,
"energies" ) ) != NULL ) {
353 d = (
double *) &(epbs[list->n]);
354 for( i = 0, epb = epbs; i < list->n; i++, epb++ ) {
355 element = list->items[i].element;
360 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
366 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
376 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
381 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
390 epbs = (tpia_EqualProbableBinSpectrum*)
xData_free( smr, epbs );
408 r = rng( rngState ); }
411 r = CLHEP::HepRandom::getTheEngine()->flat();
421 tpia_EqualProbableBinSpectra *binned,
double *value_ ) {
423 int i, j, index1, index2, method = 0;
424 double fE = 1., r, value1, value2, value3,
P12,
P23, value = -2.;
426 if( e_in <= binned->energies[0].value ) {
429 else if( e_in >= binned->energies[binned->numberOfEs-1].value ) {
430 index1 = binned->numberOfEs - 1;
431 index2 = binned->numberOfEs - 1; }
433 for( i = 0; i < binned->numberOfEs - 1; i++ ) {
434 if( e_in <= binned->energies[i].value )
break;
439 if( e_in != binned->energies[i].value ) {
441 fE = ( e_in - binned->energies[i].value ) / ( binned->energies[i+1].value - binned->energies[i].value );
444 r =
tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
445 j = (int) (r * nBins);
446 if( j >= nBins ) j = nBins - 1;
448 r =
tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
449 if( tpia_samplingMethods_isLinear( decaySamplingInfo->samplingMethods->angular_equalProbableBinMethod ) ) {
451 if( ( ( j == 0 ) && ( r <= 0.5 ) ) || ( j == ( nBins - 1 ) && r > 0.5 ) ) method = 0;
454 value1 = ( 1. - fE ) * binned->energies[index1].bins[j] + fE * binned->energies[index2].bins[j];
455 value2 = ( 1. - fE ) * binned->energies[index1].bins[j+1] + fE * binned->energies[index2].bins[j+1];
456 value = ( 1. - r ) * value1 + r * value2; }
459 value1 = ( 1. - fE ) * binned->energies[index1].bins[j] + fE * binned->energies[index2].bins[j];
460 value2 = ( 1. - fE ) * binned->energies[index1].bins[j+1] + fE * binned->energies[index2].bins[j+1];
461 value3 = ( 1. - fE ) * binned->energies[index1].bins[j+2] + fE * binned->energies[index2].bins[j+2];
462 P12 = 1. / ( value2 - value1 );
463 P23 = 1. / ( value3 - value2 );
464 r =
tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
465 if( 0.25 * ( 1.0 + 2.0 * ( value2 - value1 ) / ( value3 - value1 ) ) > r ) {
466 P23 = 2. / ( value3 - value1 );
469 P12 = 2. / ( value3 - value1 );
472 r =
tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
473 if( P23 != P12 ) r = ( -P12 + std::sqrt( P12 * P12 * ( 1. - r ) + r * P23 * P23 ) ) / ( P23 - P12 );
474 value = 0.5 * ( value1 + value2 + r * ( value3 - value1 ) );
480 #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)