TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpccurveio
dftdecayc.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
#include "
libtpccurveio.h
"
7
/*****************************************************************************/
8
9
/*****************************************************************************/
16
int
dftDecayCorrection
(
20
DFT
*dft,
23
double
hl,
25
int
mode,
27
int
y,
29
int
y2,
31
int
y3,
34
char
*status,
36
int
verbose
37
) {
38
int
ri, fi, isotopeID=-1;
39
double
lambda, dc;
40
41
if
(verbose>0) printf(
"dftDecayCorrection(dft, %g, %d, %d, %d, %d, ...)\n"
,
42
hl, mode, y, y2, y3);
43
44
/* Check the input */
45
if
(status!=NULL) strcpy(status,
"invalid input"
);
46
if
(dft==NULL)
return
(1);
47
if
(dft->
voiNr
<1 || dft->
frameNr
<1)
return
(1);
48
49
/* Check that DFT contains time unit */
50
if
(dft->
timeunit
!=TUNIT_SEC && dft->
timeunit
!=TUNIT_MIN &&
51
dft->
timeunit
!=TUNIT_HOUR)
52
{
53
if
(verbose>0) printf(
"dft->timeunit := %d\n"
, dft->
timeunit
);
54
if
(status!=NULL) strcpy(status,
"sample time unit is not specified"
);
55
return
(2);
56
}
57
58
/* Check and set isotope code and half-life */
59
if
(hl>1.0E-10) {
60
/* Try to identify the isotope from given half-life */
61
isotopeID=
hlIsotopeFromHalflife
(hl);
62
if
(isotopeID>=0) {
63
/* If identified, then set the code in DFT */
64
strcpy(dft->
isotope
,
hlIsotopeCode
(isotopeID));
65
if
(verbose>1) printf(
" isotope := %s\n"
, dft->
isotope
);
66
}
else
{
67
/* If not identified, that may just be because isotope is not yet listed
68
in TPC library, but give a warning */
69
fprintf(stderr,
"Warning: halflife %g min is not identified.\n"
, hl);
70
}
71
}
else
{
72
/* Check that valid isotope code is found in DFT */
73
hl=
hlFromIsotope
(dft->
isotope
);
if
(hl<=0.0) {
74
if
(verbose>0) printf(
"dft->isotope := %s\n"
, dft->
isotope
);
75
if
(status!=NULL) strcpy(status,
"valid isotope is not specified"
);
76
return
(11);
77
}
78
if
(verbose>1) printf(
" half-life := %g min\n"
, hl);
79
}
80
81
/*
82
* Calculate the lambda
83
*/
84
if
(dft->
timeunit
==TUNIT_SEC) hl*=60.0;
85
else
if
(dft->
timeunit
==TUNIT_HOUR) hl/=60.0;
86
lambda=
hl2lambda
(hl);
if
(mode==0) lambda=-lambda;
87
if
(verbose>1) printf(
"lambda := %e\n"
, lambda);
88
89
/*
90
* Decay correction / removal
91
*/
92
if
(verbose>2) {
93
if
(mode!=0) printf(
"decay correction\n"
);
94
else
printf(
"removing decay correction\n"
);
95
}
96
for
(fi=0; fi<dft->
frameNr
; fi++) {
97
/* Calculate decay factor */
98
if
(dft->
timetype
==
DFT_TIME_STARTEND
) {
99
if
(isnan(dft->
x1
[fi]) || isnan(dft->
x2
[fi]))
continue
;
100
dc=
hlLambda2factor
(lambda, dft->
x1
[fi], dft->
x2
[fi]-dft->
x1
[fi]);
101
}
else
{
102
if
(isnan(dft->
x
[fi]))
continue
;
103
dc=
hlLambda2factor
(lambda, dft->
x
[fi], 0.0);
104
}
105
if
(verbose>4) printf(
" %10.4f -> %e\n"
, dft->
x
[fi], dc);
106
/* Correct all regions */
107
for
(ri=0; ri<dft->
voiNr
; ri++) {
108
if
(y!=0 && !isnan(dft->
voi
[ri].
y
[fi])) dft->
voi
[ri].
y
[fi]*=dc;
109
if
(y2!=0 && !isnan(dft->
voi
[ri].
y2
[fi])) dft->
voi
[ri].
y2
[fi]*=dc;
110
if
(y3!=0 && !isnan(dft->
voi
[ri].
y3
[fi])) dft->
voi
[ri].
y3
[fi]*=dc;
111
}
112
}
113
if
(mode!=0) {
114
dft->
decayCorrected
=
DFT_DECAY_CORRECTED
;
115
if
(status!=NULL) strcpy(status,
"decay corrected"
);
116
}
else
{
117
dft->
decayCorrected
=
DFT_DECAY_NOTCORRECTED
;
118
if
(status!=NULL) strcpy(status,
"decay correction removed"
);
119
}
120
return
(0);
121
}
122
/*****************************************************************************/
123
124
/*****************************************************************************/
dftDecayCorrection
int dftDecayCorrection(DFT *dft, double hl, int mode, int y, int y2, int y3, char *status, int verbose)
Definition
dftdecayc.c:16
hl2lambda
double hl2lambda(double halflife)
Definition
halflife.c:84
hlIsotopeCode
char * hlIsotopeCode(int isotope)
Definition
halflife.c:36
hlLambda2factor
double hlLambda2factor(double lambda, double frametime, double framedur)
Definition
halflife.c:98
hlFromIsotope
double hlFromIsotope(char *isocode)
Definition
halflife.c:55
hlIsotopeFromHalflife
int hlIsotopeFromHalflife(double halflife)
Definition
halflife.c:195
libtpccurveio.h
Header file for libtpccurveio.
DFT_DECAY_NOTCORRECTED
#define DFT_DECAY_NOTCORRECTED
Definition
libtpccurveio.h:446
DFT_DECAY_CORRECTED
#define DFT_DECAY_CORRECTED
Definition
libtpccurveio.h:444
DFT_TIME_STARTEND
#define DFT_TIME_STARTEND
Definition
libtpccurveio.h:439
DFT
Definition
libtpccurveio.h:73
DFT::decayCorrected
char decayCorrected
Definition
libtpccurveio.h:92
DFT::timetype
int timetype
Definition
libtpccurveio.h:99
DFT::voi
Voi * voi
Definition
libtpccurveio.h:108
DFT::timeunit
int timeunit
Definition
libtpccurveio.h:85
DFT::x1
double * x1
Definition
libtpccurveio.h:104
DFT::voiNr
int voiNr
Definition
libtpccurveio.h:78
DFT::x2
double * x2
Definition
libtpccurveio.h:106
DFT::frameNr
int frameNr
Definition
libtpccurveio.h:76
DFT::isotope
char isotope[8]
Definition
libtpccurveio.h:90
DFT::x
double * x
Definition
libtpccurveio.h:102
Voi::y2
double * y2
Definition
libtpccurveio.h:61
Voi::y
double * y
Definition
libtpccurveio.h:59
Voi::y3
double * y3
Definition
libtpccurveio.h:63
Generated on
for TPCCLIB by
1.17.0