Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
ptwXY_functions.cc File Reference
#include <cmath>
#include "ptwXY.h"

Go to the source code of this file.

Functions

nfu_status ptwXY_pow (ptwXYPoints *ptwXY, double v)
 
nfu_status ptwXY_exp (ptwXYPoints *ptwXY, double a)
 
ptwXYPointsptwXY_convolution (ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status, int mode)
 

Function Documentation

◆ ptwXY_convolution()

ptwXYPoints * ptwXY_convolution ( ptwXYPoints * ptwXY1,
ptwXYPoints * ptwXY2,
nfu_status * status,
int mode )

Definition at line 96 of file ptwXY_functions.cc.

96 {
97/*
98* Currently, only supports linear-linear interpolation.
99*
100* This function calculates c(y) = integral dx f1(x) * f2(y-x)
101*
102*/
103 int64_t i1, i2, n1, n2, n;
104 ptwXYPoints *f1 = ptwXY1, *f2 = ptwXY2, *convolute;
105 double accuracy = ptwXY1->accuracy, yMin, yMax, c, y, dy;
106
107 if( ( *status = ptwXY_simpleCoalescePoints( ptwXY1 ) ) != nfu_Okay ) return( NULL );
108 if( ( *status = ptwXY_simpleCoalescePoints( ptwXY2 ) ) != nfu_Okay ) return( NULL );
109
111 if( ( ptwXY1->interpolation != ptwXY_interpolationLinLin ) || ( ptwXY2->interpolation != ptwXY_interpolationLinLin ) ) return( NULL );
112 *status = nfu_Okay;
113
114 n1 = f1->length;
115 n2 = f2->length;
116
117 if( ( n1 == 0 ) || ( n2 == 0 ) ) {
118 convolute = ptwXY_new( ptwXY_interpolationLinLin, NULL, 1., accuracy, 0, 0, status, 0 );
119 return( convolute );
120 }
121
122 if( ( n1 == 1 ) || ( n2 == 1 ) ) {
123 *status = nfu_tooFewPoints;
124 return( NULL );
125 }
126
127 if( accuracy < ptwXY2->accuracy ) accuracy = ptwXY2->accuracy;
128 n = n1 * n2;
129 if( mode == 0 ) {
130 mode = 1;
131 if( n > 1000 ) mode = -1;
132 }
133 if( n > 100000 ) mode = -1;
134 if( ( convolute = ptwXY_new( ptwXY_interpolationLinLin, NULL, 1., accuracy, 400, 40, status, 0 ) ) == NULL ) return( NULL );
135
136 yMin = f1->points[0].x + f2->points[0].x;
137 yMax = f1->points[n1 - 1].x + f2->points[n2 - 1].x;
138
139 if( ( *status = ptwXY_setValueAtX( convolute, yMin, 0. ) ) != nfu_Okay ) goto Err;
140
141 if( mode < 0 ) {
142 dy = ( yMax - yMin ) / 400;
143 for( y = yMin + dy; y < yMax; y += dy ) {
144 if( ( *status = ptwXY_convolution2( f1, f2, y, yMin, &c ) ) != nfu_Okay ) goto Err;
145 if( ( *status = ptwXY_setValueAtX( convolute, y, c ) ) != nfu_Okay ) goto Err;
146 } }
147 else {
148 for( i1 = 0; i1 < n1; i1++ ) {
149 for( i2 = 0; i2 < n2; i2++ ) {
150 y = yMin + ( f1->points[i1].x - f1->points[0].x ) + ( f2->points[i2].x - f2->points[0].x );
151 if( y <= yMin ) continue;
152 if( y >= yMax ) continue;
153 if( ( *status = ptwXY_convolution2( f1, f2, y, yMin, &c ) ) != nfu_Okay ) goto Err;
154 if( ( *status = ptwXY_setValueAtX( convolute, y, c ) ) != nfu_Okay ) goto Err;
155 }
156 }
157 }
158 if( ( *status = ptwXY_setValueAtX( convolute, yMax, 0. ) ) != nfu_Okay ) goto Err;
159 if( ( *status = ptwXY_simpleCoalescePoints( convolute ) ) != nfu_Okay ) goto Err;
160 for( i1 = convolute->length - 1; i1 > 0; i1-- ) {
161 if( ( *status = ptwXY_convolution3( convolute, f1, f2, convolute->points[i1 - 1].x, convolute->points[i1 - 1].y,
162 convolute->points[i1].x, convolute->points[i1].y, yMin ) ) != nfu_Okay ) goto Err;
163 }
164
165 return( convolute );
166
167Err:
168 ptwXY_free( convolute );
169 return( NULL );
170}
@ nfu_unsupportedInterpolation
@ nfu_Okay
@ nfu_tooFewPoints
nfu_status ptwXY_setValueAtX(ptwXYPoints *ptwXY, double x, double y)
nfu_status ptwXY_simpleCoalescePoints(ptwXYPoints *ptwXY)
ptwXYPoints * ptwXY_new(ptwXY_interpolation interpolation, ptwXY_interpolationOtherInfo const *interpolationOtherInfo, double biSectionMax, double accuracy, int64_t primarySize, int64_t secondarySize, nfu_status *status, int userFlag)
Definition ptwXY_core.cc:29
@ ptwXY_interpolationLinLin
Definition ptwXY.h:35
ptwXYPoints * ptwXY_free(ptwXYPoints *ptwXY)
double x
Definition ptwXY.h:62
ptwXYPoint * points
Definition ptwXY.h:99
ptwXY_interpolation interpolation
Definition ptwXY.h:87
double accuracy
Definition ptwXY.h:91
int64_t length
Definition ptwXY.h:93

◆ ptwXY_exp()

nfu_status ptwXY_exp ( ptwXYPoints * ptwXY,
double a )

Definition at line 43 of file ptwXY_functions.cc.

43 {
44
45 int64_t i, length;
46 nfu_status status;
47 double x1, y1, z1, x2, y2, z2;
48
49 length = ptwXY->length;
50 if( length < 1 ) return( ptwXY->status );
53
54 if( ( status = ptwXY_simpleCoalescePoints( ptwXY ) ) != nfu_Okay ) return( status );
55 x2 = ptwXY->points[length-1].x;
56 y2 = a * ptwXY->points[length-1].y;
57 z2 = ptwXY->points[length-1].y = G4Exp( y2 );
58 for( i = length - 2; i >= 0; i-- ) {
59 x1 = ptwXY->points[i].x;
60 y1 = a * ptwXY->points[i].y;
61 z1 = ptwXY->points[i].y = G4Exp( y1 );
62 if( ( status = ptwXY_exp_s( ptwXY, x1, y1, z1, x2, y2, z2, 0 ) ) != nfu_Okay ) return( status );
63 x2 = x1;
64 y2 = y1;
65 }
66 return( status );
67}
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition G4Exp.hh:180
@ nfu_invalidInterpolation
@ nfu_otherInterpolation
enum nfu_status_e nfu_status
@ ptwXY_interpolationFlat
Definition ptwXY.h:36
@ ptwXY_interpolationOther
Definition ptwXY.h:36
double y
Definition ptwXY.h:62
nfu_status status
Definition ptwXY.h:85

◆ ptwXY_pow()

nfu_status ptwXY_pow ( ptwXYPoints * ptwXY,
double v )

Definition at line 24 of file ptwXY_functions.cc.

24 {
25
26 return( ptwXY_applyFunction( ptwXY, ptwXY_pow_callback, (void *) &v, 0 ) );
27}
nfu_status ptwXY_applyFunction(ptwXYPoints *ptwXY1, ptwXY_applyFunction_callback func, void *argList, int checkForRoots)