#include <string.h>
#include <tpia_target.h>
#include <tpia_misc.h>
Go to the source code of this file.
Functions | |
int | tpia_angularEnergy_initialize (statusMessageReporting *smr, tpia_angularEnergy *angularEnergy) |
int | tpia_angularEnergy_release (statusMessageReporting *smr, tpia_angularEnergy *angularEnergy) |
int | tpia_angularEnergy_getFromElement (statusMessageReporting *smr, xData_element *angularEnergyElement, tpia_angularEnergy *angularEnergy) |
int | tpia_angularEnergy_SampleEp (statusMessageReporting *smr, tpia_angularEnergy *angularEnergy, tpia_decaySamplingInfo *decaySamplingInfo) |
int tpia_angularEnergy_getFromElement | ( | statusMessageReporting * | smr, | |
xData_element * | angularEnergyElement, | |||
tpia_angularEnergy * | angularEnergy | |||
) |
Definition at line 73 of file tpia_angularEnergy.cc.
References CLHEP::detail::n, tpia_frame_setFromElement(), tpia_misc_getEqualProbableBins(), tpia_misc_setMessageError_Element(), xData_addToAccessed(), xData_convertAttributeTo_xData_Int(), xData_convertAttributeToDouble(), xData_freeElementList(), xData_getElementsByTagNameAndSort(), and xData_getOneElementByTagName().
00073 { 00074 00075 int i, j, status = 1; 00076 xData_Int nBins, size, n, index; 00077 xData_element *epbElement, *element; 00078 xData_elementList *list; 00079 tpia_EqualProbableBinSpectra *mus; 00080 00081 xData_addToAccessed( smr, angularEnergyElement, 1 ); 00082 if( ( tpia_frame_setFromElement( smr, angularEnergyElement, 4, &(angularEnergy->frame) ) ) != 0 ) return( 1 ); 00083 //if( ( epbElement = xData_getOneElementByTagName( smr, angularEnergyElement, "equalProbableBins", 0 ) ) == NULL ) return( 1 ); 00084 if( ( epbElement = xData_getOneElementByTagName( smr, angularEnergyElement, (char*)"equalProbableBins", 0 ) ) == NULL ) return( 1 ); 00085 xData_addToAccessed( smr, epbElement, 1 ); 00086 if( xData_convertAttributeTo_xData_Int( smr, epbElement, "nBins", &nBins ) != 0 ) { 00087 tpia_misc_setMessageError_Element( smr, NULL, epbElement, __FILE__, __LINE__, 1, "missing or invalid nBins attribute" ); 00088 return( 1 ); 00089 } 00090 list = xData_getElementsByTagNameAndSort( smr, epbElement, "energy", NULL, NULL ); 00091 if( list->n == 0 ) { 00092 tpia_misc_setMessageError_Element( smr, NULL, epbElement, __FILE__, __LINE__, 1, "bins does not contain any energy elements" ); } 00093 else { 00094 size = list->n * sizeof( tpia_EqualProbableBinSpectra ); 00095 angularEnergy->binned.nBins = (int) nBins; 00096 //if( ( angularEnergy->binned.energies = xData_malloc2( smr, size, 1, "energies" ) ) != NULL ) { 00097 if( ( angularEnergy->binned.energies = (tpia_EqualProbableBinSpectra*) xData_malloc2( smr, size, 1, "energies" ) ) != NULL ) { 00098 status = 0; 00099 for( i = 0, mus = angularEnergy->binned.energies; i < list->n; i++, mus++ ) { 00100 mus->iValue = 0; 00101 element = list->items[i].element; 00102 if( xData_convertAttributeTo_xData_Int( smr, element, "index", &index ) != 0 ) { 00103 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "missing or invalid index attribute" ); 00104 status = 1; 00105 break; 00106 } 00107 if( index != i ) { 00108 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "index = %lld is not incremental", index ); 00109 status = 1; 00110 break; 00111 } 00112 if( ( j = xData_convertAttributeToDouble( smr, element, "value", &(mus->dValue) ) ) != 0 ) { 00113 if( j == 1 ) { 00114 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "element does not have value attribute" ); } 00115 else { 00116 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "failed to convert value attribute to double" ); 00117 } 00118 status = 1; 00119 break; 00120 } 00121 if( ( mus->energies = tpia_misc_getEqualProbableBins( smr, element, "mu", nBins, &n ) ) == NULL ) { 00122 status = 1; 00123 break; } 00124 else { 00125 mus->numberOfEs = n; 00126 } 00127 angularEnergy->binned.numberOfEs++; 00128 } 00129 } 00130 } 00131 xData_freeElementList( smr, list ); 00132 return( status ); 00133 }
int tpia_angularEnergy_initialize | ( | statusMessageReporting * | smr, | |
tpia_angularEnergy * | angularEnergy | |||
) |
Definition at line 49 of file tpia_angularEnergy.cc.
References tpia_frame_setFromString().
Referenced by tpia_angularEnergy_release().
00049 { 00050 00051 memset( angularEnergy, 0, sizeof( tpia_angularEnergy ) ); 00052 if( tpia_frame_setFromString( smr, "", "", 0, &(angularEnergy->frame) ) ) return( 1 ); 00053 angularEnergy->binned.numberOfEs = 0; 00054 angularEnergy->binned.energies = NULL; 00055 return( 0 ); 00056 }
int tpia_angularEnergy_release | ( | statusMessageReporting * | smr, | |
tpia_angularEnergy * | angularEnergy | |||
) |
Definition at line 60 of file tpia_angularEnergy.cc.
References tpia_angularEnergy_initialize(), and xData_free().
Referenced by tpia_product_release().
00060 { 00061 00062 int i; 00063 00064 for( i = 0; i < angularEnergy->binned.numberOfEs; i++ ) xData_free( smr, angularEnergy->binned.energies[i].energies ); 00065 //angularEnergy->binned.energies = xData_free( smr, angularEnergy->binned.energies ); 00066 angularEnergy->binned.energies = (tpia_EqualProbableBinSpectra*) xData_free( smr, angularEnergy->binned.energies ); 00067 tpia_angularEnergy_initialize( smr, angularEnergy ); 00068 return( 0 ); 00069 }
int tpia_angularEnergy_SampleEp | ( | statusMessageReporting * | smr, | |
tpia_angularEnergy * | angularEnergy, | |||
tpia_decaySamplingInfo * | decaySamplingInfo | |||
) |
Definition at line 137 of file tpia_angularEnergy.cc.
References smr_isOk().
Referenced by tpia_decayChannel_sampleProductsAtE().
00137 { 00138 00139 int iE1, iE2; 00140 tpia_EqualProbableBinSpectra *energies = angularEnergy->binned.energies; 00141 double Ep, Ep1, Ep2, f, e_in = decaySamplingInfo->e_in; 00142 /* 00143 Currently, only equal probable binning is supported. 00144 Need to return frame info for Ep also. 00145 */ 00146 00147 if( !smr_isOk( smr ) ) return( 1 ); 00148 if( angularEnergy->binned.numberOfEs == 0 ) return( 1 ); 00149 for( iE2 = 0; iE2 < angularEnergy->binned.numberOfEs; iE2++ ) if( energies[iE2].dValue >= e_in ) break; 00150 if( iE2 == 0 ) { 00151 iE1 = iE2; } 00152 else if( iE2 == angularEnergy->binned.numberOfEs ) { 00153 iE1 = iE2 = angularEnergy->binned.numberOfEs - 1; } 00154 else { 00155 iE1 = iE2 - 1; 00156 } 00157 tpia_misc_sampleEqualProbableBin( smr, decaySamplingInfo, decaySamplingInfo->mu, angularEnergy->binned.nBins, &(energies[iE1]), &Ep1 ); 00158 if( iE1 == iE2 ) { 00159 Ep = Ep1; } 00160 else { 00161 tpia_misc_sampleEqualProbableBin( smr, decaySamplingInfo, decaySamplingInfo->mu, angularEnergy->binned.nBins, &(energies[iE2]), &Ep2 ); 00162 f = ( energies[iE2].dValue - e_in ) / ( energies[iE2].dValue - energies[iE1].dValue ); 00163 Ep = f * Ep1 + ( 1 - f ) * Ep2; 00164 } 00165 decaySamplingInfo->Ep = Ep; 00166 00167 return( 0 ); 00168 }