TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpctac
tacdc.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include "
tpcift.h
"
8
/*****************************************************************************/
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <math.h>
12
#include <time.h>
13
#include <string.h>
14
/*****************************************************************************/
15
#include "
tpcisotope.h
"
16
#include "
tpctac.h
"
17
/*****************************************************************************/
18
19
/*****************************************************************************/
25
int
tacGetIsotope
(
27
TAC
*tac
28
) {
29
if
(tac==NULL)
return
(
ISOTOPE_UNKNOWN
);
30
char
buf[
MAX_ISOTOPE_LEN
+1];
31
if
(
tacGetHeaderIsotope
(&tac->
h
, buf, NULL)!=
TPCERROR_OK
)
return
(
ISOTOPE_UNKNOWN
);
32
return
(
isotopeIdentify
(buf));
33
}
34
/*****************************************************************************/
35
36
/*****************************************************************************/
41
void
tacSetIsotope
(
43
TAC
*tac,
45
int
isotope
46
) {
47
if
(tac!=NULL)
tacSetHeaderIsotope
(&tac->
h
,
isotopeName
(
isotope
));
48
}
49
/*****************************************************************************/
50
51
/*****************************************************************************/
59
int
tacDecayCorrection
(
62
TAC
*tac,
64
int
isotope
,
66
int
mode,
68
TPCSTATUS
*status
69
) {
70
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
71
if
(verbose>0) printf(
"%s()\n"
, __func__);
72
/* check that data exists */
73
if
(tac==NULL || tac->
sampleNr
<1 || tac->
tacNr
<1) {
74
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
75
return
TPCERROR_NO_DATA
;
76
}
77
/* check time unit */
78
if
(!
unitIsTime
(tac->
tunit
)) {
79
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_UNKNOWN_UNIT
);
80
return
TPCERROR_UNKNOWN_UNIT
;
81
}
82
/* check isotope and get halflife */
83
double
f, lambda, halflife=
isotopeHalflife
(
isotope
);
// halflife in min
84
if
(
isotope
==
ISOTOPE_UNKNOWN
|| isnan(halflife)) {
85
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_UNKNOWN_ISOTOPE
);
86
return
TPCERROR_UNKNOWN_ISOTOPE
;
87
}
88
/* convert halflife to the same unit that the TAC data has */
89
f=
unitConversionFactor
(
UNIT_MIN
, tac->
tunit
);
90
if
(!isnan(f)) halflife*=f;
91
/* calculate the lambda */
92
lambda=
lambdaFromHalflife
(halflife);
93
if
(mode==0) lambda=-lambda;
94
if
(verbose>2) {
95
printf(
"halflife := %g\n"
, halflife);
96
printf(
"lambda := %g\n"
, lambda);
97
}
98
99
100
/*
101
* Decay correction / removal
102
*/
103
if
(verbose>2) {
104
if
(mode!=0) printf(
"decay correction\n"
);
else
printf(
"removing decay correction\n"
);
105
fflush(stdout);
106
}
107
for
(
int
i=0; i<tac->
sampleNr
; i++) {
108
/* Calculate decay correction factor */
109
if
(tac->
isframe
) {
110
if
(isnan(tac->
x1
[i]) || isnan(tac->
x2
[i]))
continue
;
111
f=
decayCorrectionFactorFromLambda
(lambda, tac->
x1
[i], tac->
x2
[i]-tac->
x1
[i]);
112
}
else
{
113
if
(isnan(tac->
x
[i]))
continue
;
114
f=
decayCorrectionFactorFromLambda
(lambda, tac->
x
[i], 0.0);
115
}
116
if
(verbose>6) printf(
" %10.4f -> %e\n"
, tac->
x
[i], f);
117
/* Correct all TACs */
118
for
(
int
j=0; j<tac->
tacNr
; j++) tac->
c
[j].
y
[i]*=f;
119
/* Opposite correction for weights, if available */
120
if
(tac->
weighting
==
WEIGHTING_ON_GENERAL
|| tac->
weighting
==
WEIGHTING_ON_COUNTS
||
121
tac->
weighting
==
WEIGHTING_ON_FD
)
122
tac->
w
[i]/=f;
123
}
124
if
(
tacIsWeighted
(tac))
tacWeightNorm
(tac, NULL);
125
if
(mode==0)
tacSetHeaderDecayCorrection
(&tac->
h
,
DECAY_NOTCORRECTED
);
126
else
tacSetHeaderDecayCorrection
(&tac->
h
,
DECAY_CORRECTED
);
127
128
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
129
return
(
TPCERROR_OK
);
130
}
131
/*****************************************************************************/
132
133
/*****************************************************************************/
lambdaFromHalflife
double lambdaFromHalflife(double halflife)
Definition
decay.c:47
decayCorrectionFactorFromLambda
double decayCorrectionFactorFromLambda(double lambda, double starttime, double duration)
Definition
decay.c:79
isotopeName
char * isotopeName(int isotope_code)
Definition
isotope.c:101
isotopeHalflife
double isotopeHalflife(int isotope_code)
Definition
isotope.c:62
isotopeIdentify
int isotopeIdentify(const char *isotope)
Definition
isotope.c:145
statusSet
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition
statusmsg.c:142
TACC::y
double * y
Definition
tpctac.h:75
TAC
Definition
tpctac.h:87
TAC::x
double * x
Definition
tpctac.h:97
TAC::sampleNr
int sampleNr
Definition
tpctac.h:89
TAC::h
IFT h
Optional (but often useful) header information.
Definition
tpctac.h:141
TAC::w
double * w
Definition
tpctac.h:111
TAC::isframe
int isframe
Definition
tpctac.h:95
TAC::c
TACC * c
Definition
tpctac.h:117
TAC::weighting
weights weighting
Definition
tpctac.h:115
TAC::x2
double * x2
Definition
tpctac.h:101
TAC::tunit
unit tunit
Definition
tpctac.h:109
TAC::x1
double * x1
Definition
tpctac.h:99
TAC::tacNr
int tacNr
Definition
tpctac.h:91
TPCSTATUS
Definition
tpcextensions.h:241
TPCSTATUS::verbose
int verbose
Verbose level, used by statusPrint() etc.
Definition
tpcextensions.h:242
tacGetIsotope
int tacGetIsotope(TAC *tac)
Definition
tacdc.c:25
tacDecayCorrection
int tacDecayCorrection(TAC *tac, int isotope, int mode, TPCSTATUS *status)
Definition
tacdc.c:59
tacSetIsotope
void tacSetIsotope(TAC *tac, int isotope)
Definition
tacdc.c:41
tacSetHeaderDecayCorrection
int tacSetHeaderDecayCorrection(IFT *h, decaycorrection dc)
Definition
tacift.c:578
tacSetHeaderIsotope
int tacSetHeaderIsotope(IFT *h, const char *s)
Definition
tacift.c:341
tacGetHeaderIsotope
int tacGetHeaderIsotope(IFT *h, char *s, TPCSTATUS *status)
Definition
tacift.c:290
tacIsWeighted
int tacIsWeighted(TAC *tac)
Definition
tacw.c:24
tacWeightNorm
int tacWeightNorm(TAC *tac, TPCSTATUS *status)
Definition
tacw.c:237
WEIGHTING_ON_FD
@ WEIGHTING_ON_FD
Weights based on decay and sample frequency or frame length (Thiele et al, 2008).
Definition
tpcextensions.h:58
WEIGHTING_ON_GENERAL
@ WEIGHTING_ON_GENERAL
Weighted or weights are available, but not specified.
Definition
tpcextensions.h:55
WEIGHTING_ON_COUNTS
@ WEIGHTING_ON_COUNTS
Weights based on counts (Mazoyer et al, 1986).
Definition
tpcextensions.h:56
UNIT_MIN
@ UNIT_MIN
minutes
Definition
tpcextensions.h:90
TPCERROR_UNKNOWN_UNIT
@ TPCERROR_UNKNOWN_UNIT
Unknown data unit.
Definition
tpcextensions.h:226
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
TPCERROR_UNKNOWN_ISOTOPE
@ TPCERROR_UNKNOWN_ISOTOPE
Unknown isotope.
Definition
tpcextensions.h:225
TPCERROR_NO_DATA
@ TPCERROR_NO_DATA
File contains no data.
Definition
tpcextensions.h:203
unitConversionFactor
double unitConversionFactor(const int u1, const int u2)
Definition
units.c:487
unitIsTime
int unitIsTime(int u)
Definition
units.c:359
tpcift.h
Header file for library libtpcift.
tpcisotope.h
Header file for library libtpcisotope.
MAX_ISOTOPE_LEN
#define MAX_ISOTOPE_LEN
Max string length for PET isotope.
Definition
tpcisotope.h:41
DECAY_NOTCORRECTED
@ DECAY_NOTCORRECTED
Data is not corrected for physical decay.
Definition
tpcisotope.h:80
DECAY_CORRECTED
@ DECAY_CORRECTED
Data is corrected for physical decay.
Definition
tpcisotope.h:81
isotope
isotope
Definition
tpcisotope.h:50
ISOTOPE_UNKNOWN
@ ISOTOPE_UNKNOWN
Unknown.
Definition
tpcisotope.h:51
tpctac.h
Header file for library libtpctac.
Generated on
for TPCCLIB by
1.17.0