Geant4  10.00.p01
tpia_Legendre.cc
Go to the documentation of this file.
1 /*
2 # <<BEGIN-copyright>>
3 # Copyright (c) 2010, Lawrence Livermore National Security, LLC.
4 # Produced at the Lawrence Livermore National Laboratory
5 # Written by Bret R. Beck, beck6@llnl.gov.
6 # CODE-461393
7 # All rights reserved.
8 #
9 # This file is part of GIDI. For details, see nuclear.llnl.gov.
10 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov.
11 #
12 # Redistribution and use in source and binary forms, with or without modification,
13 # are permitted provided that the following conditions are met:
14 #
15 # 1) Redistributions of source code must retain the above copyright notice,
16 # this list of conditions and the disclaimer below.
17 # 2) Redistributions in binary form must reproduce the above copyright notice,
18 # this list of conditions and the disclaimer (as noted below) in the
19 # documentation and/or other materials provided with the distribution.
20 # 3) Neither the name of the LLNS/LLNL nor the names of its contributors may be
21 # used to endorse or promote products derived from this software without
22 # specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
25 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
28 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # <<END-copyright>>
35 */
36 #include <string.h>
37 #include <math.h>
38 #ifdef WIN32
39  #include <float.h>
40 #endif
41 
42 #include <tpia_target.h>
43 #include <tpia_misc.h>
44 
45 #if defined __cplusplus
46 namespace GIDI {
47 using namespace GIDI;
48 #endif
49 
50 static int _tpia_Legendre_getOrder( statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *Legendre, tpia_EqualProbableBinSpectra *l );
51 /*
52 ************************************************************
53 */
54 int tpia_Legendre_initialize( statusMessageReporting *smr, tpia_Legendre *Legendre ) {
55 
56  memset( Legendre, 0, sizeof( tpia_Legendre ) );
57  if( tpia_frame_setFromString( smr, "", "", 0, &(Legendre->frame) ) ) return( 1 );
58  Legendre->binned.numberOfLs = 0;
59  Legendre->binned.ls = NULL;
60  return( 0 );
61 }
62 /*
63 ************************************************************
64 */
65 int tpia_Legendre_release( statusMessageReporting *smr, tpia_Legendre *Legendre ) {
66 
67  int i;
68 
69  for( i = 0; i < Legendre->binned.numberOfLs; i++ ) xData_free( smr, Legendre->binned.ls[i].energies );
70  //Legendre->binned.ls = xData_free( smr, Legendre->binned.ls );
71  Legendre->binned.ls = (tpia_EqualProbableBinSpectra*) xData_free( smr, Legendre->binned.ls );
72  tpia_Legendre_initialize( smr, Legendre );
73  return( 0 );
74 }
75 /*
76 ************************************************************
77 */
78 int tpia_Legendre_getFromElement( statusMessageReporting *smr, xData_element *LegendreElement, tpia_Legendre *Legendre ) {
79 
80  int i, status = 0;
81  xData_elementList *list;
82 
83  xData_addToAccessed( smr, LegendreElement, 1 );
84  if( ( tpia_frame_setFromElement( smr, LegendreElement, 4, &(Legendre->frame) ) ) != 0 ) return( 1 );
85  list = xData_getElementsByTagNameAndSort( smr, LegendreElement, "l", NULL, NULL );
86  if( list->n == 0 ) {
87  status = 1;
88  tpia_misc_setMessageError_Element( smr, NULL, LegendreElement, __FILE__, __LINE__, 1, "Legendre element does not contain any l elements" ); }
89  else {
90  //if( ( Legendre->binned.ls = xData_malloc2( smr, list->n * sizeof( tpia_EqualProbableBinSpectra ), 1, "ls" ) ) != NULL ) {
91  if( ( Legendre->binned.ls = (tpia_EqualProbableBinSpectra*) xData_malloc2( smr, list->n * sizeof( tpia_EqualProbableBinSpectra ), 1, "ls" ) ) != NULL ) {
92  Legendre->binned.numberOfLs = 0;
93  for( i = 0; i < list->n; i++ ) {
94  if( ( status = _tpia_Legendre_getOrder( smr, list->items[i].element, Legendre, &(Legendre->binned.ls[i]) ) ) != 0 ) break;
95  Legendre->binned.numberOfLs++;
96  }
97  }
98  }
99  xData_freeElementList( smr, list );
100  return( status );
101 }
102 /*
103 ************************************************************
104 */
105 //static int _tpia_Legendre_getOrder( statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *Legendre, tpia_EqualProbableBinSpectra *l ) {
106 static int _tpia_Legendre_getOrder( statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *, tpia_EqualProbableBinSpectra *l ) {
107 
108  int status = 1;
109  xData_Int n, nBins, lOrder;
110 
111  if( xData_convertAttributeTo_xData_Int( smr, LegendreOrder, "value", &lOrder ) != 0 ) {
112  tpia_misc_setMessageError_Element( smr, NULL, LegendreOrder, __FILE__, __LINE__, 1, "missing or invalid nBins attribute for angular bins" ); }
113  else {
114  l->iValue = lOrder;
115  l->dValue = 0.;
116  if( ( l->energies = tpia_misc_getEqualProbableBin( smr, LegendreOrder, &n, &nBins ) ) != NULL ) {
117  status = 0;
118  l->nBins = (int) nBins;
119  l->numberOfEs = (int) n;
120  }
121  }
122  return( status );
123 }
124 /*
125 ************************************************************
126 */
127 int tpia_Legendre_SampleEp( statusMessageReporting *smr, tpia_Legendre *Legendre, int sampleMu, tpia_decaySamplingInfo *decaySamplingInfo ) {
128 
129  tpia_EqualProbableBinSpectra *binned_l0 = Legendre->binned.ls;
130  double Ep;
131 
132 /*
133 Currently, only l = 0, equal probable binning is supported.
134 Need to return frame info for Ep, mu, also.
135 */
136  if( Legendre->binned.numberOfLs > 0 ) {
137  if( sampleMu ) decaySamplingInfo->mu = 2. * tpia_misc_drng( decaySamplingInfo->rng, decaySamplingInfo->rngState ) - 1.;
138 #ifndef WIN32
139  if( decaySamplingInfo->mu <= -1 ) decaySamplingInfo->mu = nextafter( -1., 0. );
140 #endif
141 #ifdef WIN32
142  if( decaySamplingInfo->mu <= -1 ) decaySamplingInfo->mu = _nextafter( -1., 0. );
143 #endif
144 
145  tpia_misc_sampleEqualProbableBin( smr, decaySamplingInfo, decaySamplingInfo->e_in, binned_l0->nBins, binned_l0, &Ep );
146  /* ??? Need to check that e_in > E_Threshold */
147  decaySamplingInfo->Ep = Ep; }
148  else {
149  return( 1 );
150  }
151 
152  return( 0 );
153 }
154 
155 #if defined __cplusplus
156 }
157 #endif
xData_Int xData_convertAttributeTo_xData_Int(statusMessageReporting *smr, xData_element *element, const char *name, xData_Int *n)
Definition: xData.cc:710
int xData_addToAccessed(statusMessageReporting *, xData_element *element, int increment)
Definition: xData.cc:1078
int tpia_Legendre_getFromElement(statusMessageReporting *smr, xData_element *LegendreElement, tpia_Legendre *Legendre)
int tpia_Legendre_SampleEp(statusMessageReporting *smr, tpia_Legendre *Legendre, int sampleMu, tpia_decaySamplingInfo *decaySamplingInfo)
tpia_EqualProbableBinSpectrum * tpia_misc_getEqualProbableBin(statusMessageReporting *smr, xData_element *parent, xData_Int *n, xData_Int *nBins)
Definition: tpia_misc.cc:317
int tpia_misc_setMessageError_Element(statusMessageReporting *smr, void *userInterface, xData_element *element, const char *file, int line, int code, const char *fmt,...)
Definition: tpia_misc.cc:183
int tpia_Legendre_initialize(statusMessageReporting *smr, tpia_Legendre *Legendre)
double tpia_misc_drng(double(*rng)(void *), void *rngState)
Definition: tpia_misc.cc:403
int tpia_frame_setFromString(statusMessageReporting *smr, const char *forItem, const char *value, int dimension, tpia_data_frame *frame)
Definition: tpia_frame.cc:75
xData_elementList * xData_getElementsByTagNameAndSort(statusMessageReporting *smr, xData_element *element, const char *tagName, const char *sortAttributeName, xData_sortElementFunc sortFunction)
Definition: xData.cc:788
const G4int n
int tpia_frame_setFromElement(statusMessageReporting *smr, xData_element *element, int dimension, tpia_data_frame *frame)
Definition: tpia_frame.cc:62
void * xData_free(statusMessageReporting *, void *p)
Definition: xDataMisc.cc:89
int tpia_misc_sampleEqualProbableBin(statusMessageReporting *, tpia_decaySamplingInfo *decaySamplingInfo, double e_in, int nBins, tpia_EqualProbableBinSpectra *binned, double *value_)
Definition: tpia_misc.cc:420
static int _tpia_Legendre_getOrder(statusMessageReporting *smr, xData_element *LegendreOrder, tpia_Legendre *Legendre, tpia_EqualProbableBinSpectra *l)
int tpia_Legendre_release(statusMessageReporting *smr, tpia_Legendre *Legendre)
void xData_freeElementList(statusMessageReporting *smr, xData_elementList *list)
Definition: xData.cc:832