TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcisotope
decay.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <math.h>
10
#include <time.h>
11
#include <string.h>
12
/*****************************************************************************/
13
#include "
tpcisotope.h
"
14
/*****************************************************************************/
15
16
/*****************************************************************************/
18
static
char
*decay_correction[] = {
19
"unknown"
,
20
"not corrected"
,
21
"corrected"
,
22
"corrected to scan start time"
,
23
"corrected to administration time"
,
24
0};
25
/*****************************************************************************/
26
27
/*****************************************************************************/
32
char
*
decayDescr
(
34
decaycorrection
d
35
) {
36
if
(d>4)
return
(decay_correction[0]);
37
return
(decay_correction[d]);
38
}
39
/*****************************************************************************/
40
41
/*****************************************************************************/
47
double
lambdaFromHalflife
(
50
double
halflife
51
) {
52
if
(halflife>0.0)
return
(
M_LN2
/halflife);
// M_LN2=log(2.0)
53
else
return
nan(
""
);
54
}
55
/*****************************************************************************/
56
57
/*****************************************************************************/
63
double
lambdaFromIsotope
(
65
int
isotope
66
) {
67
double
hl=
isotopeHalflife
(
isotope
);
if
(isnan(hl) || hl<=0.0)
return
nan(
""
);
68
return
(
M_LN2
/hl);
69
}
70
/*****************************************************************************/
71
72
/*****************************************************************************/
79
double
decayCorrectionFactorFromLambda
(
82
double
lambda,
84
double
starttime,
87
double
duration
88
) {
89
if
(starttime<0.0)
return
nan(
""
);
90
if
(duration<0.0) duration=0.0;
91
if
(fabs(lambda)<1.0E-100)
return
nan(
""
);
92
double
cf=exp(lambda*starttime);
93
if
(duration>1.0E-10) {
94
double
ff=fabs(lambda)*duration/(1.0-exp(-fabs(lambda)*duration));
95
if
(lambda<0.0) cf/=ff;
else
cf*=ff;
96
}
97
return
(cf);
98
}
99
/*****************************************************************************/
100
101
/*****************************************************************************/
107
double
decayCorrectionFactorFromIsotope
(
109
int
isotope
,
112
double
starttime,
115
double
duration
116
) {
117
double
lambda=
lambdaFromIsotope
(
isotope
);
if
(isnan(lambda))
return
nan(
""
);
118
return
decayCorrectionFactorFromLambda
(lambda, starttime, duration);
119
}
120
/*****************************************************************************/
121
122
/*****************************************************************************/
decayDescr
char * decayDescr(decaycorrection d)
Definition
decay.c:32
lambdaFromHalflife
double lambdaFromHalflife(double halflife)
Definition
decay.c:47
decayCorrectionFactorFromIsotope
double decayCorrectionFactorFromIsotope(int isotope, double starttime, double duration)
Definition
decay.c:107
lambdaFromIsotope
double lambdaFromIsotope(int isotope)
Definition
decay.c:63
decayCorrectionFactorFromLambda
double decayCorrectionFactorFromLambda(double lambda, double starttime, double duration)
Definition
decay.c:79
isotopeHalflife
double isotopeHalflife(int isotope_code)
Definition
isotope.c:62
tpcisotope.h
Header file for library libtpcisotope.
decaycorrection
decaycorrection
Definition
tpcisotope.h:78
M_LN2
#define M_LN2
Defined ln(2) for faster computations.
Definition
tpcisotope.h:37
isotope
isotope
Definition
tpcisotope.h:50
Generated on
for TPCCLIB by
1.17.0