tpia_angularEnergy.cc

Go to the documentation of this file.
00001 /*
00002 # <<BEGIN-copyright>>
00003 # Copyright (c) 2010, Lawrence Livermore National Security, LLC. 
00004 # Produced at the Lawrence Livermore National Laboratory 
00005 # Written by Bret R. Beck, beck6@llnl.gov. 
00006 # CODE-461393
00007 # All rights reserved. 
00008 #  
00009 # This file is part of GIDI. For details, see nuclear.llnl.gov. 
00010 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov. 
00011 # 
00012 # Redistribution and use in source and binary forms, with or without modification, 
00013 # are permitted provided that the following conditions are met: 
00014 #
00015 #      1) Redistributions of source code must retain the above copyright notice, 
00016 #         this list of conditions and the disclaimer below.
00017 #      2) Redistributions in binary form must reproduce the above copyright notice, 
00018 #         this list of conditions and the disclaimer (as noted below) in the 
00019 #          documentation and/or other materials provided with the distribution.
00020 #      3) Neither the name of the LLNS/LLNL nor the names of its contributors may be 
00021 #         used to endorse or promote products derived from this software without 
00022 #         specific prior written permission. 
00023 #
00024 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
00025 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00026 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT 
00027 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR 
00028 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00029 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
00030 # OR SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00031 # AND ON  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00032 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00033 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00034 # <<END-copyright>>
00035 */
00036 #include <string.h>
00037 
00038 #include <tpia_target.h>
00039 #include <tpia_misc.h>
00040 
00041 #if defined __cplusplus
00042 namespace GIDI {
00043 using namespace GIDI;
00044 #endif
00045 
00046 /*
00047 ************************************************************
00048 */
00049 int tpia_angularEnergy_initialize( statusMessageReporting *smr, tpia_angularEnergy *angularEnergy ) {
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 }
00057 /*
00058 ************************************************************
00059 */
00060 int tpia_angularEnergy_release( statusMessageReporting *smr, tpia_angularEnergy *angularEnergy ) {
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 }
00070 /*
00071 ************************************************************
00072 */
00073 int tpia_angularEnergy_getFromElement( statusMessageReporting *smr, xData_element *angularEnergyElement, tpia_angularEnergy *angularEnergy ) {
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 }
00134 /*
00135 ************************************************************
00136 */
00137 int tpia_angularEnergy_SampleEp( statusMessageReporting *smr, tpia_angularEnergy *angularEnergy, tpia_decaySamplingInfo *decaySamplingInfo ) {
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 }
00169 
00170 #if defined __cplusplus
00171 }
00172 #endif

Generated on Mon May 27 17:50:35 2013 for Geant4 by  doxygen 1.4.7