Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
tpia_misc.cc File Reference
#include "Randomize.hh"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <tpia_target.h>
#include <tpia_misc.h>
#include <string>

Go to the source code of this file.

Classes

struct  ZSymbol
 

Functions

int tpia_misc_NumberOfZSymbols (void)
 
const char * tpia_misc_ZToSymbol (int iZ)
 
int tpia_misc_symbolToZ (const char *Z)
 
int tpia_miscNameToZAm (statusMessageReporting *smr, const char *name, int *Z, int *A, int *m)
 
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_setMessageError_Element (statusMessageReporting *smr, void *userInterface, xData_element *element, const char *file, int line, int code, const char *fmt,...)
 
xData_Int tpia_misc_binarySearch (xData_Int n, double *ds, double d)
 
double * tpia_misc_get2dx_y_data (statusMessageReporting *smr, xData_element *element, xData_Int *length)
 
double * tpia_misc_get2dxindex_y_data (statusMessageReporting *smr, xData_element *element, xData_Int *start, xData_Int *end, double *xValues)
 
double * tpia_misc_get2d_xShared_yHistogram_data (statusMessageReporting *smr, xData_element *element, xData_Int *start, xData_Int *end, xData_Int *length)
 
int tpia_misc_get2d_xShared_yHistogram_data_Grouped (statusMessageReporting *smr, xData_element *element, tpia_1dData *group)
 
double tpia_misc_getPointwiseCrossSectionAtE (statusMessageReporting *, tpia_1dData *crossSection, double *energyGrid, xData_Int index, double e_in)
 
tpia_EqualProbableBinSpectrumtpia_misc_getEqualProbableBin (statusMessageReporting *smr, xData_element *parent, xData_Int *n, xData_Int *nBins)
 
tpia_EqualProbableBinSpectrumtpia_misc_getEqualProbableBins (statusMessageReporting *smr, xData_element *parent, const char *name, xData_Int nBins, xData_Int *n)
 
double tpia_misc_drng (double(*rng)(void *), void *rngState)
 
int tpia_misc_sampleEqualProbableBin (statusMessageReporting *, tpia_decaySamplingInfo *decaySamplingInfo, double e_in, int nBins, tpia_EqualProbableBinSpectra *binned, double *value_)
 

Function Documentation

◆ tpia_misc_binarySearch()

xData_Int tpia_misc_binarySearch ( xData_Int  n,
double *  ds,
double  d 
)

Definition at line 208 of file tpia_misc.cc.

208 {
209
210 xData_Int imin = 0, imid, imax = n - 1;
211
212 if( d < ds[0] ) return( -2 );
213 if( d > ds[n-1] ) return( -1 );
214 while( 1 ) {
215 imid = ( imin + imax ) >> 1;
216 if( imid == imin ) break;
217 if( d < ds[imid] ) {
218 imax = imid; }
219 else {
220 imin = imid;
221 }
222 }
223 return( imin );
224}
int xData_Int
Definition: xData.h:50

Referenced by tpia_target_heated_getEIndex().

◆ tpia_misc_drng()

double tpia_misc_drng ( double(*)(void *)  rng,
void *  rngState 
)

Definition at line 403 of file tpia_misc.cc.

403 {
404
405 double r;
406
407 if( rng != NULL ) {
408 r = rng( rngState ); }
409 else {
410 //r = drand48( );
412
413 }
414 return( r );
415}
virtual double flat()=0
static HepRandomEngine * getTheEngine()
Definition: Random.cc:165

Referenced by G4GIDI_target::sampleChannelCrossSectionAtE(), tpia_decayChannel_sampleProductsAtE(), tpia_Legendre_SampleEp(), and tpia_misc_sampleEqualProbableBin().

◆ tpia_misc_get2d_xShared_yHistogram_data()

double * tpia_misc_get2d_xShared_yHistogram_data ( statusMessageReporting smr,
xData_element element,
xData_Int start,
xData_Int end,
xData_Int length 
)

Definition at line 268 of file tpia_misc.cc.

268 {
269
270 xData_Int i;
271 xData_element *xDataElement;
272 double *d = NULL;
273
274 xData_addToAccessed( smr, element, 1 );
275 //if( ( xDataElement = xData_getOneElementByTagName( smr, element, "xData", 1 ) ) != NULL ) {
276 if( ( xDataElement = xData_getOneElementByTagName( smr, element, (char*) "xData", 1 ) ) != NULL ) {
277 xData_addToAccessed( smr, xDataElement, 1 );
278 if( ( d = xData_2d_xShared_yHistogram_copyData( smr, xDataElement, &i ) ) != NULL ) {
279 if( start != NULL ) *start = xDataElement->xDataTypeInfo.start;
280 if( end != NULL ) *end = xDataElement->xDataTypeInfo.end;
281 if( length != NULL ) *length = xDataElement->xDataTypeInfo.length;
282 }
283 }
284 return( d );
285}
xData_Int length
Definition: xData.h:162
xData_Int end
Definition: xData.h:162
xData_Int start
Definition: xData.h:162
xDataType xDataTypeInfo
Definition: xData.h:187
xData_element * xData_getOneElementByTagName(statusMessageReporting *smr, xData_element *element, char *name, int required)
Definition: xData.cc:810
int xData_addToAccessed(statusMessageReporting *smr, xData_element *element, int increment)
Definition: xData.cc:1078
double * xData_2d_xShared_yHistogram_copyData(statusMessageReporting *smr, xData_element *element, xData_Int *n)

Referenced by tpia_misc_get2d_xShared_yHistogram_data_Grouped().

◆ tpia_misc_get2d_xShared_yHistogram_data_Grouped()

int tpia_misc_get2d_xShared_yHistogram_data_Grouped ( statusMessageReporting smr,
xData_element element,
tpia_1dData group 
)

Definition at line 289 of file tpia_misc.cc.

289 {
290
291 if( ( group->data = tpia_misc_get2d_xShared_yHistogram_data( smr, element, &(group->start), &(group->end), &(group->length) ) ) == NULL ) return( 1 );
292 return( 0 );
293}
xData_Int start
Definition: tpia_target.h:144
double * data
Definition: tpia_target.h:145
xData_Int end
Definition: tpia_target.h:144
xData_Int length
Definition: tpia_target.h:144
double * tpia_misc_get2d_xShared_yHistogram_data(statusMessageReporting *smr, xData_element *element, xData_Int *start, xData_Int *end, xData_Int *length)
Definition: tpia_misc.cc:268

Referenced by tpia_channel_getFromElement(), and tpia_multiplicity_getFromElement().

◆ tpia_misc_get2dx_y_data()

double * tpia_misc_get2dx_y_data ( statusMessageReporting smr,
xData_element element,
xData_Int length 
)

Definition at line 228 of file tpia_misc.cc.

228 {
229
230 xData_element *xDataElement;
231 double *d = NULL;
232 xData_Int length_;
233
234 xData_addToAccessed( smr, element, 1 );
235 //if( ( xDataElement = xData_getOneElementByTagName( smr, element, "xData", 1 ) ) != NULL ) {
236 if( ( xDataElement = xData_getOneElementByTagName( smr, element, (char*)"xData", 1 ) ) != NULL ) {
237 xData_addToAccessed( smr, xDataElement, 1 );
238 if( xData_is_2d_xy( smr, &(xDataElement->xDataTypeInfo), 1 ) ) {
239 d = xData_2d_xy_allocateCopyData( smr, xDataElement, &length_ );
240 *length = (xData_Int) length_;
241 }
242 }
243 return( d );
244}
int xData_is_2d_xy(statusMessageReporting *smr, xDataType *xDT, int setMsg)
Definition: xData_2d_xy.cc:70
double * xData_2d_xy_allocateCopyData(statusMessageReporting *smr, xData_element *element, xData_Int *length)
Definition: xData_2d_xy.cc:84

Referenced by tpia_multiplicity_getFromElement().

◆ tpia_misc_get2dxindex_y_data()

double * tpia_misc_get2dxindex_y_data ( statusMessageReporting smr,
xData_element element,
xData_Int start,
xData_Int end,
double *  xValues 
)

Definition at line 248 of file tpia_misc.cc.

248 {
249
250 xData_element *xDataElement;
251 double *d = NULL;
252
253 xData_addToAccessed( smr, element, 1 );
254 //if( ( xDataElement = xData_getOneElementByTagName( smr, element, "xData", 1 ) ) != NULL ) {
255 if( ( xDataElement = xData_getOneElementByTagName( smr, element, (char*) "xData", 1 ) ) != NULL ) {
256 xData_addToAccessed( smr, xDataElement, 1 );
257 if( xData_is_2d_xindex_y( smr, &(xDataElement->xDataTypeInfo), 1 ) ) {
258 if( start != NULL ) *start = xDataElement->xDataTypeInfo.start;
259 if( end != NULL ) *end = xDataElement->xDataTypeInfo.end;
260 d = xData_2d_xindex_y_toFilledYs( smr, xDataElement, xValues );
261 }
262 }
263 return( d );
264}
int xData_is_2d_xindex_y(statusMessageReporting *smr, xDataType *xDT, int setMsg)
double * xData_2d_xindex_y_toFilledYs(statusMessageReporting *smr, xData_element *element, double *Xs)

Referenced by tpia_channel_getFromElement().

◆ tpia_misc_getEqualProbableBin()

tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBin ( statusMessageReporting smr,
xData_element parent,
xData_Int n,
xData_Int nBins 
)

Definition at line 317 of file tpia_misc.cc.

317 {
318
319 xData_element *element;
320
321 xData_addToAccessed( smr, parent, 1 );
322 //if( ( element = xData_getOneElementByTagName( smr, parent, "equalProbableBins", 0 ) ) == NULL ) return( NULL );
323 if( ( element = xData_getOneElementByTagName( smr, parent, (char*) "equalProbableBins", 0 ) ) == NULL ) return( NULL );
324 if( xData_convertAttributeTo_xData_Int( smr, element, "nBins", nBins ) != 0 ) {
325 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "missing or invalid nBins attribute" );
326 return( NULL );
327 }
328 return( tpia_misc_getEqualProbableBins( smr, element, "energy", *nBins, n ) );
329}
int tpia_misc_setMessageError_Element(statusMessageReporting *smr, void *userInterface, xData_element *element, const char *file, int line, int code, const char *fmt,...)
Definition: tpia_misc.cc:183
tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBins(statusMessageReporting *smr, xData_element *parent, const char *name, xData_Int nBins, xData_Int *n)
Definition: tpia_misc.cc:333
xData_Int xData_convertAttributeTo_xData_Int(statusMessageReporting *smr, xData_element *element, const char *name, xData_Int *n)
Definition: xData.cc:710

Referenced by tpia_angular_getFromElement().

◆ tpia_misc_getEqualProbableBins()

tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBins ( statusMessageReporting smr,
xData_element parent,
const char *  name,
xData_Int  nBins,
xData_Int n 
)

Definition at line 333 of file tpia_misc.cc.

334 {
335
336
337 int i, j;
338 xData_Int index, size;
339 xData_elementList *list;
340 xData_element *element, *xData;
341 double *d;
342 tpia_EqualProbableBinSpectrum *epbs = NULL, *epb;
343
344 xData_addToAccessed( smr, parent, 1 );
345 list = xData_getElementsByTagNameAndSort( smr, parent, name, NULL, NULL );
346 if( list->n == 0 ) {
347 tpia_misc_setMessageError_Element( smr, NULL, parent, __FILE__, __LINE__, 1, "bins does not contain any %s elements", name ); }
348 else {
349 *n = list->n;
350 size = list->n * ( sizeof( tpia_EqualProbableBinSpectrum ) + ( nBins + 1 ) * sizeof( double ) );
351 //if( ( epbs = xData_malloc2( smr, size, 0, "energies" ) ) != NULL ) {
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++ ) { /* Loop to test nBins and index are proper. */
355 element = list->items[i].element;
356 xData_addToAccessed( smr, element, 1 );
357 if( xData_convertAttributeTo_xData_Int( smr, element, "index", &index ) != 0 ) {
358 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "missing or invalid index attribute" );
359 //epbs = xData_free( smr, epbs );
360 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
361 break;
362 }
363 if( index != i ) {
364 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "index = %lld is not incremental", index );
365 //epbs = xData_free( smr, epbs );
366 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
367 break;
368 }
369 if( ( j = xData_convertAttributeToDouble( smr, element, "value", &(epb->value) ) ) != 0 ) {
370 if( j == 1 ) {
371 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "element does not have value attribute" ); }
372 else {
373 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "failed to convert value attribute to double" );
374 }
375 //epbs = xData_free( smr, epbs );
376 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
377 break;
378 }
379 if( ( xData = xData_getElements_xDataElement( smr, element ) ) == NULL ) {
380 //epbs = xData_free( smr, epbs );
381 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
382 break;
383 }
384 xData_addToAccessed( smr, xData, 1 );
385 epb->index = index;
386 epb->nBins = nBins;
387 epb->bins = d;
388 if( xData_1d_x_copyData( smr, xData, ( nBins + 1 ) * sizeof( double ), d ) != 0 ) {
389 //epbs = xData_free( smr, epbs );
390 epbs = (tpia_EqualProbableBinSpectrum*) xData_free( smr, epbs );
391 break;
392 }
393 d += nBins + 1;
394 }
395 }
396 }
397 xData_freeElementList( smr, list );
398 return( epbs );
399}
xData_element * element
Definition: xData.h:145
xData_elementListItem * items
Definition: xData.h:151
struct tpia_EqualProbableBinSpectrum_s tpia_EqualProbableBinSpectrum
Definition: tpia_target.h:62
int xData_convertAttributeToDouble(statusMessageReporting *smr, xData_element *element, const char *name, double *d)
Definition: xData.cc:730
void * xData_free(statusMessageReporting *smr, void *p)
Definition: xDataMisc.cc:89
void xData_freeElementList(statusMessageReporting *smr, xData_elementList *list)
Definition: xData.cc:832
xData_elementList * xData_getElementsByTagNameAndSort(statusMessageReporting *smr, xData_element *element, const char *tagName, const char *sortAttributeName, xData_sortElementFunc sortFunction)
Definition: xData.cc:788
int xData_1d_x_copyData(statusMessageReporting *smr, xData_element *element, xData_Int nAllocatedBytes, double *d)
Definition: xData_1d_x.cc:84
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313
xData_element * xData_getElements_xDataElement(statusMessageReporting *smr, xData_element *element)
Definition: xData.cc:622

Referenced by tpia_angularEnergy_getFromElement(), and tpia_misc_getEqualProbableBin().

◆ tpia_misc_getPointwiseCrossSectionAtE()

double tpia_misc_getPointwiseCrossSectionAtE ( statusMessageReporting smr,
tpia_1dData crossSection,
double *  energyGrid,
xData_Int  index,
double  e_in 
)

Definition at line 298 of file tpia_misc.cc.

298 {
299
300 double xsec = 0.0, e1, e2;
301
302 if( ( index >= crossSection->start ) && ( index < crossSection->end ) ) {
303 e1 = energyGrid[index];
304 e2 = energyGrid[index + 1];
305 index -= crossSection->start;
306 if( e1 == e2 ) { /* Allow for future where step function may be allowed. */
307 xsec = 0.5 * ( crossSection->data[index] + crossSection->data[index + 1] ); }
308 else {
309 xsec = ( crossSection->data[index] * ( e2 - e_in ) + crossSection->data[index + 1] * ( e_in - e1 ) ) / ( e2 - e1 );
310 }
311 }
312 return( xsec );
313}

Referenced by tpia_channel_getCrossSectionAtE(), and tpia_target_heated_getTotalCrossSectionAtE().

◆ tpia_misc_NumberOfZSymbols()

int tpia_misc_NumberOfZSymbols ( void  )

Definition at line 76 of file tpia_misc.cc.

76 {
77
78 return( sizeof( ZSymbols ) / sizeof( struct ZSymbol ) );
79}

Referenced by tpia_misc_symbolToZ(), and tpia_misc_ZToSymbol().

◆ tpia_misc_pointerToAttributeIfAllOk()

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 
)

Definition at line 163 of file tpia_misc.cc.

164 {
165
166 char *value;
167
168 if( !smr_isOk( smr ) ) return( NULL );
169 if( ( value = xData_getAttributesValue( attributes, name ) ) == NULL ) {
170 if( required ) {
171 if( element != NULL ) {
172 tpia_misc_setMessageError_Element( smr, NULL, element, file, line, 1, "element does not have attribute named %s", name ); }
173 else {
174 smr_setMessageError( smr, NULL, file, line, 1, "element does not have attribute named %s for file = %d", name, path );
175 }
176 }
177 }
178 return( value );
179}
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int smr_isOk(statusMessageReporting *smr)
char * xData_getAttributesValue(xData_attributionList *attributes, const char *name)
Definition: xData.cc:530

◆ tpia_misc_sampleEqualProbableBin()

int tpia_misc_sampleEqualProbableBin ( statusMessageReporting smr,
tpia_decaySamplingInfo decaySamplingInfo,
double  e_in,
int  nBins,
tpia_EqualProbableBinSpectra binned,
double *  value_ 
)

Definition at line 420 of file tpia_misc.cc.

421 {
422
423 int i, j, index1, index2, method = 0;
424 double fE = 1., r, value1, value2, value3, P12, P23, value = -2.;
425
426 if( e_in <= binned->energies[0].value ) {
427 index1 = 0;
428 index2 = 0; }
429 else if( e_in >= binned->energies[binned->numberOfEs-1].value ) {
430 index1 = binned->numberOfEs - 1;
431 index2 = binned->numberOfEs - 1; }
432 else {
433 for( i = 0; i < binned->numberOfEs - 1; i++ ) {
434 if( e_in <= binned->energies[i].value ) break;
435 }
436 i--;
437 index1 = i;
438 index2 = i;
439 if( e_in != binned->energies[i].value ) {
440 index2++;
441 fE = ( e_in - binned->energies[i].value ) / ( binned->energies[i+1].value - binned->energies[i].value );
442 }
443 }
444 r = tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState );
445 j = (int) (r * nBins);
446 if( j >= nBins ) j = nBins - 1;
447 if( j < 0 ) j = 0;
448 r = tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState ); // Do not change r until after Point1 below.
450 method = 1;
451 if( ( ( j == 0 ) && ( r <= 0.5 ) ) || ( j == ( nBins - 1 ) && r > 0.5 ) ) method = 0;
452 }
453 if( method == 0 ) { /* Constant interpolaton. */
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; }
457 else { /* Linear interpolation. */
458 if( r <= 0.5 ) j--; /* Point1: Above test insures that j is not 0 (nBins-1) if r <= 0.5 (> 0.5); */
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 );
467 value3 = value2; }
468 else {
469 P12 = 2. / ( value3 - value1 );
470 value1 = value2;
471 }
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 ) );
475 }
476 *value_ = value;
477 return( 0 );
478}
tpia_EqualProbableBinSpectrum * energies
Definition: tpia_target.h:196
tpia_samplingMethods * samplingMethods
Definition: tpia_target.h:150
double(* rng)(void *)
Definition: tpia_target.h:153
const char * angular_equalProbableBinMethod
Definition: tpia_target.h:136
double tpia_misc_drng(double(*rng)(void *), void *rngState)
Definition: tpia_misc.cc:403
#define tpia_samplingMethods_isLinear(method)
Definition: tpia_target.h:121

Referenced by tpia_angular_SampleMu(), tpia_angularEnergy_SampleEp(), and tpia_Legendre_SampleEp().

◆ tpia_misc_setMessageError_Element()

int tpia_misc_setMessageError_Element ( statusMessageReporting smr,
void *  userInterface,
xData_element element,
const char *  file,
int  line,
int  code,
const char *  fmt,
  ... 
)

Definition at line 183 of file tpia_misc.cc.

184 {
185
186 int status = 0;
187 va_list args;
188 char *msg;
189
190 va_start( args, fmt );
191 msg = smr_vallocateFormatMessage( fmt, &args );
192 va_end( args );
193 if( msg == NULL ) {
194 status = 1;
195 va_start( args, fmt );
196 smr_vsetMessageError( smr, userInterface, file, line, code, fmt, &args );
197 va_end( args ); }
198 else {
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 );
201 free( msg );
202 }
203 return( status );
204}
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)
size_t line
Definition: xData.h:117
size_t column
Definition: xData.h:118
xData_docInfo docInfo
Definition: xData.h:177
char * fullName
Definition: xData.h:185

Referenced by tpia_angularEnergy_getFromElement(), tpia_frame_setFromElement(), tpia_Legendre_getFromElement(), tpia_misc_getEqualProbableBin(), tpia_misc_getEqualProbableBins(), tpia_misc_pointerToAttributeIfAllOk(), tpia_multiplicity_getFromElement(), tpia_multiplicity_getTimeScaleFromElement(), tpia_product_getFromElement(), tpia_target_heated_read(), and tpia_target_read().

◆ tpia_misc_symbolToZ()

int tpia_misc_symbolToZ ( const char *  Z)

Definition at line 92 of file tpia_misc.cc.

92 {
93
94 int i, n = tpia_misc_NumberOfZSymbols( );
95
96 for( i = 0; i < n; i++ ) {
97 //if( !strcmp( Z, ZSymbols[i].symbol ) ) return( ZSymbols[i].Z );
98 if( !strcmp( Z, ZSymbols[i].symbol.c_str() ) ) return( ZSymbols[i].Z );
99 }
100 return( -1 );
101}
int tpia_misc_NumberOfZSymbols(void)
Definition: tpia_misc.cc:76

Referenced by tpia_miscNameToZAm().

◆ tpia_misc_ZToSymbol()

const char * tpia_misc_ZToSymbol ( int  iZ)

Definition at line 83 of file tpia_misc.cc.

83 {
84
85 if( ( iZ < 0 ) || ( iZ >= tpia_misc_NumberOfZSymbols( ) ) ) return( NULL );
86 //return( ZSymbols[iZ].symbol );
87 return( ZSymbols[iZ].symbol.c_str() );
88}

Referenced by G4GIDI_Misc_Z_A_m_ToName().

◆ tpia_miscNameToZAm()

int tpia_miscNameToZAm ( statusMessageReporting smr,
const char *  name,
int *  Z,
int *  A,
int *  m 
)

Definition at line 105 of file tpia_misc.cc.

105 {
106
107 int i, n;
108 const char *p;
109 char s[1024] = "", *q, *e; /* Note 1) routine will fail when parts of a particle name can be longer than 1024. */
110
111 n = sizeof( s ) - 1;
112
113 *Z = *A = *m = 0;
114 if( !strncmp( "FissionProduct", name, 14 ) ) {
115 *Z = 99;
116 *A = 120;
117 return( 0 );
118 }
119 if( !strcmp( "gamma", name ) ) return( 0 );
120 for( p = name, q = s, i = 0; ( *p != '_' ) && ( i != n ); p++, q++, i++ ) *q = *p;
121 if( i == n ) { /* See note 1 above. */
122 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "Failed to find first '_' in particle name %s", name ); }
123 else {
124 *q = 0;
125 if( ( *Z = tpia_misc_symbolToZ( s ) ) < 0 ) {
126 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "Particle %s's symbol = '%s' not found", name, s ); }
127 else { /* Getting here implies that *p == '_'. */
128 for( p++, q = s; ( *p != '_' ) && ( *p != 0 ) && ( i != n ); p++, q++, i++ ) *q = *p;
129 if( i == n ) { /* See note 1 above. */
130 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "Failed to find second '_' in particle name %s", name ); }
131 else {
132 *q = 0;
133 if( strcmp( s, "natural" ) == 0 ) {
134 e = s;
135 while( *e ) e++; }
136 else {
137 *A = (int) strtol( s, &e, 10 );
138 }
139 if( *e != 0 ) {
140 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "Failed to convert A to integer in particle name %s", name ); }
141 else { /* Getting here implies that *p == '_' or 0. */
142 *m = 0;
143 if( *p == '_' ) {
144 p++;
145 if( *p != 'm' ) {
146 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "Particle name %s missing meta-stable label 'm'", name ); }
147 else {
148 p++;
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 );
151 }
152 }
153 }
154 }
155 }
156 }
157
158 return( !smr_isOk( smr ) );
159}
int tpia_misc_symbolToZ(const char *Z)
Definition: tpia_misc.cc:92

Referenced by G4GIDI_Misc_channelCompound(), and tpia_particle_getInternalID().