00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <string.h>
00037 #include <math.h>
00038 #ifdef WIN32
00039 #include <float.h>
00040 #endif
00041
00042 #include <tpia_target.h>
00043 #include <tpia_misc.h>
00044
00045 #if defined __cplusplus
00046 namespace GIDI {
00047 using namespace GIDI;
00048 #endif
00049
00050 static int _tpia_Legendre_getOrder( statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *Legendre, tpia_EqualProbableBinSpectra *l );
00051
00052
00053
00054 int tpia_Legendre_initialize( statusMessageReporting *smr, tpia_Legendre *Legendre ) {
00055
00056 memset( Legendre, 0, sizeof( tpia_Legendre ) );
00057 if( tpia_frame_setFromString( smr, "", "", 0, &(Legendre->frame) ) ) return( 1 );
00058 Legendre->binned.numberOfLs = 0;
00059 Legendre->binned.ls = NULL;
00060 return( 0 );
00061 }
00062
00063
00064
00065 int tpia_Legendre_release( statusMessageReporting *smr, tpia_Legendre *Legendre ) {
00066
00067 int i;
00068
00069 for( i = 0; i < Legendre->binned.numberOfLs; i++ ) xData_free( smr, Legendre->binned.ls[i].energies );
00070
00071 Legendre->binned.ls = (tpia_EqualProbableBinSpectra*) xData_free( smr, Legendre->binned.ls );
00072 tpia_Legendre_initialize( smr, Legendre );
00073 return( 0 );
00074 }
00075
00076
00077
00078 int tpia_Legendre_getFromElement( statusMessageReporting *smr, xData_element *LegendreElement, tpia_Legendre *Legendre ) {
00079
00080 int i, status = 0;
00081 xData_elementList *list;
00082
00083 xData_addToAccessed( smr, LegendreElement, 1 );
00084 if( ( tpia_frame_setFromElement( smr, LegendreElement, 4, &(Legendre->frame) ) ) != 0 ) return( 1 );
00085 list = xData_getElementsByTagNameAndSort( smr, LegendreElement, "l", NULL, NULL );
00086 if( list->n == 0 ) {
00087 status = 1;
00088 tpia_misc_setMessageError_Element( smr, NULL, LegendreElement, __FILE__, __LINE__, 1, "Legendre element does not contain any l elements" ); }
00089 else {
00090
00091 if( ( Legendre->binned.ls = (tpia_EqualProbableBinSpectra*) xData_malloc2( smr, list->n * sizeof( tpia_EqualProbableBinSpectra ), 1, "ls" ) ) != NULL ) {
00092 Legendre->binned.numberOfLs = 0;
00093 for( i = 0; i < list->n; i++ ) {
00094 if( ( status = _tpia_Legendre_getOrder( smr, list->items[i].element, Legendre, &(Legendre->binned.ls[i]) ) ) != 0 ) break;
00095 Legendre->binned.numberOfLs++;
00096 }
00097 }
00098 }
00099 xData_freeElementList( smr, list );
00100 return( status );
00101 }
00102
00103
00104
00105
00106 static int _tpia_Legendre_getOrder( statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *, tpia_EqualProbableBinSpectra *l ) {
00107
00108 int status = 1;
00109 xData_Int n, nBins, lOrder;
00110
00111 if( xData_convertAttributeTo_xData_Int( smr, LegendreOrder, "value", &lOrder ) != 0 ) {
00112 tpia_misc_setMessageError_Element( smr, NULL, LegendreOrder, __FILE__, __LINE__, 1, "missing or invalid nBins attribute for angular bins" ); }
00113 else {
00114 l->iValue = lOrder;
00115 l->dValue = 0.;
00116 if( ( l->energies = tpia_misc_getEqualProbableBin( smr, LegendreOrder, &n, &nBins ) ) != NULL ) {
00117 status = 0;
00118 l->nBins = (int) nBins;
00119 l->numberOfEs = (int) n;
00120 }
00121 }
00122 return( status );
00123 }
00124
00125
00126
00127 int tpia_Legendre_SampleEp( statusMessageReporting *smr, tpia_Legendre *Legendre, int sampleMu, tpia_decaySamplingInfo *decaySamplingInfo ) {
00128
00129 tpia_EqualProbableBinSpectra *binned_l0 = Legendre->binned.ls;
00130 double Ep;
00131
00132
00133
00134
00135
00136 if( Legendre->binned.numberOfLs > 0 ) {
00137 if( sampleMu ) decaySamplingInfo->mu = 2. * tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState ) - 1.;
00138 #ifndef WIN32
00139 if( decaySamplingInfo->mu <= -1 ) decaySamplingInfo->mu = nextafter( -1., 0. );
00140 #endif
00141 #ifdef WIN32
00142 if( decaySamplingInfo->mu <= -1 ) decaySamplingInfo->mu = _nextafter( -1., 0. );
00143 #endif
00144
00145 tpia_misc_sampleEqualProbableBin( smr, decaySamplingInfo, decaySamplingInfo->e_in, binned_l0->nBins, binned_l0, &Ep );
00146
00147 decaySamplingInfo->Ep = Ep; }
00148 else {
00149 return( 1 );
00150 }
00151
00152 return( 0 );
00153 }
00154
00155 #if defined __cplusplus
00156 }
00157 #endif