Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI_LLNLAngular_angularEnergy.cc
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# <<END-copyright>>
4*/
5#include <string.h>
6
7#include "MCGIDI.h"
8#include "MCGIDI_fromTOM.h"
9#include "MCGIDI_misc.h"
10#include "MCGIDI_private.h"
11
12#if defined __cplusplus
13namespace GIDI {
14using namespace GIDI;
15#endif
16
17static int MCGIDI_LLNL_angularEnergy_parseFromTOM( statusMessageReporting *smr, xDataTOM_element *element, MCGIDI_distribution *distribution );
18static int MCGIDI_LLNL_angularEnergy_parsePointwiseFromTOM( statusMessageReporting *smr, xDataTOM_element *pointwise, MCGIDI_distribution *distribution );
19/*
20************************************************************
21*/
23
24 xDataTOM_element *angularEnergyElement;
25
26 if( ( angularEnergyElement = xDataTOME_getOneElementByName( smr, element, "LLNLAngular_angularEnergy", 1 ) ) == NULL ) return( 1 );
27
28 if( MCGIDI_angular_parseFromTOM( smr, angularEnergyElement, distribution, NULL ) ) goto err;
29 if( MCGIDI_LLNL_angularEnergy_parseFromTOM( smr, angularEnergyElement, distribution ) ) goto err;
30
31 return( 0 );
32
33err:
34 if( distribution->angular ) distribution->angular = MCGIDI_angular_free( smr, distribution->angular );
35 return( 1 );
36}
37/*
38************************************************************
39*/
40static int MCGIDI_LLNL_angularEnergy_parseFromTOM( statusMessageReporting *smr, xDataTOM_element *element, MCGIDI_distribution *distribution ) {
41
42 xDataTOM_element *angularEnergyElement, *pointwise = NULL;
43 char const *nativeData;
44
45 if( ( angularEnergyElement = xDataTOME_getOneElementByName( smr, element, "LLNLAngularEnergy", 1 ) ) == NULL ) goto err;
46
47 if( ( nativeData = xDataTOM_getAttributesValueInElement( angularEnergyElement, "nativeData" ) ) == NULL ) goto err;
48 if( strcmp( nativeData, "pointwise" ) == 0 ) {
49 if( ( pointwise = xDataTOME_getOneElementByName( smr, angularEnergyElement, "pointwise", 1 ) ) == NULL ) goto err; }
50 else if( strcmp( nativeData, "linear" ) == 0 ) {
51 if( ( pointwise = xDataTOME_getOneElementByName( smr, angularEnergyElement, "linear", 1 ) ) == NULL ) goto err; }
52 else {
53 smr_setReportError2( smr, smr_unknownID, 1, "angularEnergy nativeData = '%s' not supported", nativeData );
54 goto err;
55 }
56 if( pointwise != NULL ) return( MCGIDI_LLNL_angularEnergy_parsePointwiseFromTOM( smr, pointwise, distribution ) );
57
58 return( 0 );
59
60err:
61 return( 1 );
62}
63/*
64************************************************************
65*/
66static int MCGIDI_LLNL_angularEnergy_parsePointwiseFromTOM( statusMessageReporting *smr, xDataTOM_element *pointwise, MCGIDI_distribution *distribution ) {
67
68 int iV = 0, iW;
69 double y1, norm/*, energyInFactor*/;
70 char const /*energyUnit,*/ *energyOutProbabilityUnits[2] = { "MeV", "1/MeV" };
71 MCGIDI_angularEnergy *angularEnergy = NULL;
72 ptwXY_interpolation interpolationXY, interpolationWY, interpolationVY;
73 xDataTOM_XYs *XYs;
74 xDataTOM_W_XYs *W_XYs;
75 xDataTOM_V_W_XYs *V_W_XYs;
76 MCGIDI_pdfsOfXGivenW *pdfOfEpGivenEAndMu = NULL, *pdfOfEpGivenEAndMu2 = NULL;
77 ptwXYPoints *pdfXY1 = NULL;
78 nfu_status status;
79 enum xDataTOM_frame frame;
80
81 if( ( frame = MCGIDI_misc_getProductFrame( smr, pointwise ) ) == xDataTOM_frame_invalid ) goto err;
82 if( MCGIDI_fromTOM_interpolation( smr, pointwise, 0, &interpolationVY ) ) goto err;
83 if( MCGIDI_fromTOM_interpolation( smr, pointwise, 1, &interpolationWY ) ) goto err;
84 if( MCGIDI_fromTOM_interpolation( smr, pointwise, 2, &interpolationXY ) ) goto err;
85
86 if( ( V_W_XYs = (xDataTOM_V_W_XYs *) xDataTOME_getXDataIfID( smr, pointwise, "V_W_XYs" ) ) == NULL ) goto err;
87 /*energyUnit = xDataTOM_subAxes_getUnit( smr, &(V_W_XYs->subAxes), 0 );*/
88 if( !smr_isOk( smr ) ) goto err;
89 /*energyInFactor = MCGIDI_misc_getUnitConversionFactor( smr, energyUnit, "MeV" );*/
90 if( !smr_isOk( smr ) ) goto err;
91
92 if( ( pdfOfEpGivenEAndMu = (MCGIDI_pdfsOfXGivenW *) smr_malloc2( smr, V_W_XYs->length * sizeof( MCGIDI_pdfsOfXGivenW ), 1, "pdfOfEpGivenEAndMu" ) ) == NULL ) goto err;
93 for( iV = 0; iV < V_W_XYs->length; iV++ ) {
94 W_XYs = &(V_W_XYs->W_XYs[iV]);
95 pdfOfEpGivenEAndMu2 = &(pdfOfEpGivenEAndMu[iV]);
96 pdfOfEpGivenEAndMu2->Ws = NULL;
97 pdfOfEpGivenEAndMu2->dist = NULL;
98
99 pdfOfEpGivenEAndMu2->interpolationWY = interpolationWY;
100 pdfOfEpGivenEAndMu2->interpolationXY = interpolationXY;
101 if( ( pdfOfEpGivenEAndMu2->Ws = (double *) smr_malloc2( smr, W_XYs->length * sizeof( double ), 1, "pdfOfEpGivenEAndMu2->Ws" ) ) == NULL ) goto err;
102 if( ( pdfOfEpGivenEAndMu2->dist = (MCGIDI_pdfOfX *) smr_malloc2( smr, W_XYs->length * sizeof( MCGIDI_pdfOfX ), 0, "pdfOfEpGivenEAndMu2->dist" ) ) == NULL ) goto err;
103
104 for( iW = 0; iW < W_XYs->length; iW++ ) {
105 XYs = &(W_XYs->XYs[iW]);
106 if( ( pdfXY1 = MCGIDI_misc_dataFromXYs2ptwXYPointsInUnitsOf( smr, XYs, interpolationXY, energyOutProbabilityUnits ) ) == NULL ) goto err;
107 y1 = ptwXY_integrateDomain( pdfXY1, &status );
108 if( status != nfu_Okay ) goto errA;
109
110 if( y1 == 0 ) {
111 if( ( status = ptwXY_add_double( pdfXY1, 0.5 ) ) != nfu_Okay ) goto errA;
112 }
113 pdfOfEpGivenEAndMu2->Ws[iW] = XYs->value;
114 if( MCGIDI_fromTOM_pdfOfX( smr, pdfXY1, &(pdfOfEpGivenEAndMu2->dist[iW]), &norm ) ) goto err;
115 pdfOfEpGivenEAndMu2->numberOfWs++;
116
117 pdfXY1 = ptwXY_free( pdfXY1 );
118 }
119 pdfOfEpGivenEAndMu2 = NULL;
120 }
121
122 if( ( angularEnergy = MCGIDI_angularEnergy_new( smr ) ) == NULL ) goto err;
123 angularEnergy->frame = frame;
124
125 angularEnergy->pdfOfMuGivenE.numberOfWs = distribution->angular->dists.numberOfWs;
126 angularEnergy->pdfOfMuGivenE.interpolationWY = distribution->angular->dists.interpolationWY;
127 angularEnergy->pdfOfMuGivenE.interpolationXY = distribution->angular->dists.interpolationXY;
128 angularEnergy->pdfOfMuGivenE.Ws = distribution->angular->dists.Ws;
129 angularEnergy->pdfOfMuGivenE.dist = distribution->angular->dists.dist;
130 smr_freeMemory( (void **) &(distribution->angular) );
131 distribution->angular = NULL;
132
133 angularEnergy->pdfOfEpGivenEAndMu = pdfOfEpGivenEAndMu;
134 distribution->angularEnergy = angularEnergy;
136
137 return( 0 );
138
139errA:
140 smr_setReportError2( smr, smr_unknownID, 1, "ptwXY_integrateDomain err = %d: %s\n", status, nfu_statusMessage( status ) );
141err:
142 if( pdfXY1 != NULL ) ptwXY_free( pdfXY1 );
143 if( pdfOfEpGivenEAndMu2 != NULL ) MCGIDI_sampling_pdfsOfXGivenW_release( smr, pdfOfEpGivenEAndMu2 );
144 if( pdfOfEpGivenEAndMu != NULL ) {
145 for( ; iV > 0; iV-- ) MCGIDI_sampling_pdfsOfXGivenW_release( smr, &(pdfOfEpGivenEAndMu[iV]) );
146 smr_freeMemory( (void **) &pdfOfEpGivenEAndMu );
147 }
148 return( 1 );
149}
150
151#if defined __cplusplus
152}
153#endif
int MCGIDI_LLNLAngular_angularEnergy_parseFromTOM(statusMessageReporting *smr, xDataTOM_element *element, MCGIDI_distribution *distribution)
int MCGIDI_sampling_pdfsOfXGivenW_release(statusMessageReporting *smr, MCGIDI_pdfsOfXGivenW *dists)
@ MCGIDI_distributionType_angularEnergy_e
Definition: MCGIDI.h:210
MCGIDI_angular * MCGIDI_angular_free(statusMessageReporting *smr, MCGIDI_angular *angular)
int MCGIDI_angular_parseFromTOM(statusMessageReporting *smr, xDataTOM_element *element, MCGIDI_distribution *distribution, ptwXYPoints *norms)
MCGIDI_angularEnergy * MCGIDI_angularEnergy_new(statusMessageReporting *smr)
int MCGIDI_fromTOM_interpolation(statusMessageReporting *smr, xDataTOM_element *element, int index, enum ptwXY_interpolation_e *interpolation)
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])
Definition: MCGIDI_misc.cc:405
enum xDataTOM_frame MCGIDI_misc_getProductFrame(statusMessageReporting *smr, xDataTOM_element *frameElement)
Definition: MCGIDI_misc.cc:315
@ 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
enum ptwXY_interpolation_e ptwXY_interpolation
nfu_status ptwXY_add_double(ptwXYPoints *ptwXY, double value)
ptwXYPoints * ptwXY_free(ptwXYPoints *ptwXY)
Definition: ptwXY_core.cc:574
double ptwXY_integrateDomain(ptwXYPoints *ptwXY, nfu_status *status)
#define smr_setReportError2(smr, libraryID, code, fmt,...)
void * smr_freeMemory(void **p)
int smr_isOk(statusMessageReporting *smr)
#define smr_malloc2(smr, size, zero, forItem)
#define smr_unknownID
MCGIDI_pdfsOfXGivenW * pdfOfEpGivenEAndMu
Definition: MCGIDI.h:365
enum xDataTOM_frame frame
Definition: MCGIDI.h:363
MCGIDI_pdfsOfXGivenW pdfOfMuGivenE
Definition: MCGIDI.h:364
MCGIDI_pdfsOfXGivenW dists
Definition: MCGIDI.h:322
MCGIDI_angularEnergy * angularEnergy
Definition: MCGIDI.h:386
MCGIDI_angular * angular
Definition: MCGIDI.h:383
enum MCGIDI_distributionType type
Definition: MCGIDI.h:382
ptwXY_interpolation interpolationXY
Definition: MCGIDI.h:306
MCGIDI_pdfOfX * dist
Definition: MCGIDI.h:308
ptwXY_interpolation interpolationWY
Definition: MCGIDI.h:306
xDataTOM_W_XYs * W_XYs
Definition: xDataTOM.h:103
xDataTOM_XYs * XYs
Definition: xDataTOM.h:97
double value
Definition: xDataTOM.h:82
xDataTOM_element * xDataTOME_getOneElementByName(statusMessageReporting *smr, xDataTOM_element *element, char const *name, int required)
Definition: xDataTOM.cc:246
char const * xDataTOM_getAttributesValueInElement(xDataTOM_element *element, char const *name)
Definition: xDataTOM.cc:286
xDataTOM_frame
Definition: xDataTOM.h:23
@ xDataTOM_frame_invalid
Definition: xDataTOM.h:23
void * xDataTOME_getXDataIfID(statusMessageReporting *smr, xDataTOM_element *TE, char const *ID)
Definition: xDataTOM.cc:512