Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI_fromTOM.h File Reference
#include <xDataTOM_importXML_private.h>
#include "MCGIDI.h"

Go to the source code of this file.

Functions

ptwXYPointsMCGIDI_fromTOM_XYs_to_ptwXYPoints_linear (statusMessageReporting *smr, xDataTOM_XYs *XYs, enum ptwXY_interpolation_e interpolation)
 
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)
 
int MCGIDI_fromTOM_interpolation (statusMessageReporting *smr, xDataTOM_element *element, int index, enum ptwXY_interpolation_e *interpolation)
 

Function Documentation

◆ MCGIDI_fromTOM_interpolation()

◆ MCGIDI_fromTOM_pdfOfX()

int MCGIDI_fromTOM_pdfOfX ( statusMessageReporting smr,
ptwXYPoints pdfXY,
MCGIDI_pdfOfX dist,
double *  norm 
)

Definition at line 90 of file MCGIDI_fromTOM.cc.

90 {
91
92 int j1, n1 = (int) ptwXY_length( pdfXY );
93 nfu_status status;
94 ptwXPoints *cdfX = NULL;
95 ptwXYPoint *point;
96
97 dist->numberOfXs = 0;
98 dist->Xs = NULL;
99 if( ptwXY_simpleCoalescePoints( pdfXY ) != nfu_Okay ) goto err;
100
101 if( ( dist->Xs = (double *) smr_malloc2( smr, 3 * n1 * sizeof( double ), 0, "dist->Xs" ) ) == NULL ) goto err;
102 dist->pdf = &(dist->Xs[n1]);
103 dist->cdf = &(dist->pdf[n1]);
104
105 for( j1 = 0; j1 < n1; j1++ ) {
106 point = ptwXY_getPointAtIndex_Unsafely( pdfXY, j1 );
107 dist->Xs[j1] = point->x;
108 dist->pdf[j1] = point->y;
109 }
110
111 if( ( cdfX = ptwXY_runningIntegral( pdfXY, &status ) ) == NULL ) {
112 smr_setReportError2( smr, smr_unknownID, 1, "ptwXY_runningIntegral err = %d: %s\n", status, nfu_statusMessage( status ) );
113 goto err;
114 }
115 *norm = ptwX_getPointAtIndex_Unsafely( cdfX, n1 - 1 );
116 if( *norm == 0. ) { /* Should only happend for gammas. */
117 double inv_norm, sum = 0;
118
119 inv_norm = 1.0 / ( dist->Xs[n1-1] - dist->Xs[0] );
120 for( j1 = 0; j1 < n1; ++j1 ) {
121 if( j1 > 0 ) sum += dist->Xs[j1] - dist->Xs[j1-1];
122 dist->pdf[j1] = 1;
123 dist->cdf[j1] = sum * inv_norm;
124 }
125 dist->cdf[n1-1] = 1.; }
126 else {
127 for( j1 = 0; j1 < n1; j1++ ) dist->cdf[j1] = ptwX_getPointAtIndex_Unsafely( cdfX, j1 ) / *norm;
128 for( j1 = 0; j1 < n1; j1++ ) dist->pdf[j1] /= *norm;
129 }
130 ptwX_free( cdfX );
131
132 dist->numberOfXs = n1;
133 return( 0 );
134
135err:
136 if( dist->Xs != NULL ) smr_freeMemory( (void **) &(dist->Xs) );
137 if( cdfX != NULL ) ptwX_free( cdfX );
138 return( 1 );
139}
@ nfu_Okay
Definition: nf_utilities.h:25
enum nfu_status_e nfu_status
const char * nfu_statusMessage(nfu_status status)
Definition: nf_utilities.cc:76
nfu_status ptwXY_simpleCoalescePoints(ptwXYPoints *ptwXY)
Definition: ptwXY_core.cc:529
ptwXYPoint * ptwXY_getPointAtIndex_Unsafely(ptwXYPoints *ptwXY, int64_t index)
Definition: ptwXY_core.cc:684
int64_t ptwXY_length(ptwXYPoints *ptwXY)
Definition: ptwXY_core.cc:583
ptwXPoints * ptwXY_runningIntegral(ptwXYPoints *ptwXY, nfu_status *status)
double ptwX_getPointAtIndex_Unsafely(ptwXPoints *ptwX, int64_t index)
Definition: ptwX_core.cc:215
ptwXPoints * ptwX_free(ptwXPoints *ptwX)
Definition: ptwX_core.cc:158
#define smr_setReportError2(smr, libraryID, code, fmt,...)
void * smr_freeMemory(void **p)
#define smr_malloc2(smr, size, zero, forItem)
#define smr_unknownID
double * Xs
Definition: MCGIDI.h:299
double * pdf
Definition: MCGIDI.h:300
int numberOfXs
Definition: MCGIDI.h:298
double * cdf
Definition: MCGIDI.h:301
double y
Definition: ptwXY.h:62
double x
Definition: ptwXY.h:62

◆ MCGIDI_fromTOM_pdfsOfXGivenW()

int MCGIDI_fromTOM_pdfsOfXGivenW ( statusMessageReporting smr,
xDataTOM_element element,
MCGIDI_pdfsOfXGivenW dists,
ptwXYPoints norms,
char const *  toUnits[3] 
)

Definition at line 26 of file MCGIDI_fromTOM.cc.

27 {
28
29 int i;
30 double norm, wUnitFactor;
31 char const *wFromUnit, *toUnitsXY[2] = { toUnits[1], toUnits[2] };
32 xDataTOM_XYs *XYs;
33 xDataTOM_W_XYs *W_XYs;
34 ptwXYPoints *pdfXY = NULL;
35 ptwXY_interpolation interpolationXY, interpolationWY;
36
37 wFromUnit = xDataTOM_axes_getUnit( smr, &(element->xDataInfo.axes), 0 );
38 if( !smr_isOk( smr ) ) goto err;
39 wUnitFactor = MCGIDI_misc_getUnitConversionFactor( smr, wFromUnit, toUnits[0] );
40 if( !smr_isOk( smr ) ) goto err;
41
42 if( MCGIDI_fromTOM_interpolation( smr, element, 0, &interpolationWY ) ) goto err;
43 if( MCGIDI_fromTOM_interpolation( smr, element, 1, &interpolationXY ) ) goto err;
44 dists->interpolationWY = interpolationWY;
45 dists->interpolationXY = interpolationXY;
46 if( norms != NULL ) {
47 if( interpolationWY == ptwXY_interpolationOther ) {
48 smr_setReportError2p( smr, smr_unknownID, 1, "interpolationWY ptwXY_interpolationOther not supported" );
49 goto err;
50 }
51 }
52
53 W_XYs = (xDataTOM_W_XYs *) xDataTOME_getXDataIfID( smr, element, "W_XYs" );
54 if( ( dists->Ws = (double *) smr_malloc2( smr, W_XYs->length * sizeof( double ), 1, "dists->Ws" ) ) == NULL ) goto err;
55 if( ( dists->dist = (MCGIDI_pdfOfX *) smr_malloc2( smr, W_XYs->length * sizeof( MCGIDI_pdfOfX ), 0, "dists->dist" ) ) == NULL ) goto err;
56
57 for( i = 0; i < W_XYs->length; i++ ) {
58 XYs = &(W_XYs->XYs[i]);
59 dists->Ws[i] = wUnitFactor * XYs->value;
60 if( ( pdfXY = MCGIDI_misc_dataFromXYs2ptwXYPointsInUnitsOf( smr, XYs, interpolationXY, toUnitsXY ) ) == NULL ) goto err;
61 if( MCGIDI_fromTOM_pdfOfXGivenW( smr, pdfXY, dists, i, &norm ) ) goto err;
62 if( norms != NULL ) {
63 ptwXY_setValueAtX( norms, XYs->value, norm ); }
64 else if( std::fabs( 1. - norm ) > 0.99 ) {
65 smr_setReportError2( smr, smr_unknownID, 1, "bad norm = %e for data", norm );
66 goto err;
67 }
68 ptwXY_free( pdfXY );
69 pdfXY = NULL;
70 }
71
72 return( 0 );
73
74err:
75 if( pdfXY != NULL ) ptwXY_free( pdfXY );
76 return( 1 );
77}
int MCGIDI_fromTOM_interpolation(statusMessageReporting *smr, xDataTOM_element *element, int index, ptwXY_interpolation *interpolation)
ptwXYPoints * MCGIDI_misc_dataFromXYs2ptwXYPointsInUnitsOf(statusMessageReporting *smr, xDataTOM_XYs *XYs, ptwXY_interpolation interpolation, char const *units[2])
Definition: MCGIDI_misc.cc:405
double MCGIDI_misc_getUnitConversionFactor(statusMessageReporting *smr, char const *fromUnit, char const *toUnit)
Definition: MCGIDI_misc.cc:381
nfu_status ptwXY_setValueAtX(ptwXYPoints *ptwXY, double x, double y)
Definition: ptwXY_core.cc:876
enum ptwXY_interpolation_e ptwXY_interpolation
@ ptwXY_interpolationOther
Definition: ptwXY.h:36
ptwXYPoints * ptwXY_free(ptwXYPoints *ptwXY)
Definition: ptwXY_core.cc:574
#define smr_setReportError2p(smr, libraryID, code, fmt)
int smr_isOk(statusMessageReporting *smr)
ptwXY_interpolation interpolationXY
Definition: MCGIDI.h:306
MCGIDI_pdfOfX * dist
Definition: MCGIDI.h:308
ptwXY_interpolation interpolationWY
Definition: MCGIDI.h:306
xDataTOM_XYs * XYs
Definition: xDataTOM.h:97
double value
Definition: xDataTOM.h:82
xDataTOM_xDataInfo xDataInfo
Definition: xDataTOM.h:187
xDataTOM_axes axes
Definition: xDataTOM.h:153
char const * xDataTOM_axes_getUnit(statusMessageReporting *smr, xDataTOM_axes *axes, int index)
void * xDataTOME_getXDataIfID(statusMessageReporting *smr, xDataTOM_element *TE, char const *ID)
Definition: xDataTOM.cc:512

Referenced by MCGIDI_energy_parseFromTOM().

◆ MCGIDI_fromTOM_XYs_to_ptwXYPoints_linear()

ptwXYPoints * MCGIDI_fromTOM_XYs_to_ptwXYPoints_linear ( statusMessageReporting smr,
xDataTOM_XYs XYs,
enum ptwXY_interpolation_e  interpolation 
)