ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCGIDI_LLNLAngular_angularEnergy.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MCGIDI_LLNLAngular_angularEnergy.cc
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
13 namespace GIDI {
14 using namespace GIDI;
15 #endif
16 
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 
33 err:
34  if( distribution->angular ) distribution->angular = MCGIDI_angular_free( smr, distribution->angular );
35  return( 1 );
36 }
37 /*
38 ************************************************************
39 */
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 
60 err:
61  return( 1 );
62 }
63 /*
64 ************************************************************
65 */
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 
139 errA:
140  smr_setReportError2( smr, smr_unknownID, 1, "ptwXY_integrateDomain err = %d: %s\n", status, nfu_statusMessage( status ) );
141 err:
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