TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcimgio
imgdecayc.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
#include "
libtpcimgio.h
"
7
/*****************************************************************************/
8
9
/*****************************************************************************/
16
int
imgDecayCorrection
(
18
IMG
*image,
20
int
mode
21
) {
22
float
lambda;
23
float
cf, dur;
24
25
/* Check for arguments */
26
if
(image->
status
!=
IMG_STATUS_OCCUPIED
)
return
(1);
27
if
(image->
isotopeHalflife
<=0.0)
return
(1);
28
/* Existing/nonexisting decay correction is an error */
29
if
(mode==1 && image->
decayCorrection
!=
IMG_DC_NONCORRECTED
)
return
(2);
30
if
(mode==0 && image->
decayCorrection
!=
IMG_DC_CORRECTED
)
return
(2);
31
32
/* All time frames */
33
for
(
int
fi=0; fi<image->
dimt
; fi++) {
34
dur=image->
end
[fi]-image->
start
[fi];
35
if
(image->
end
[fi]>0.0) {
36
if
(mode==0 && image->
decayCorrFactor
[fi]>1.000001) {
37
/* if decay correction is to be removed, and factor is known,
38
then use it */
39
cf=1.0/image->
decayCorrFactor
[fi];
40
}
else
{
41
lambda=
hl2lambda
(image->
isotopeHalflife
);
if
(lambda<0.0)
return
(1);
42
/* remove decay correction by giving negative lambda */
43
if
(mode==0) lambda=-lambda;
44
if
(fi==image->
dimt
-1 && image->
end
[fi]<=0.0)
return
(3);
45
cf=
hlLambda2factor_float
(lambda, image->
start
[fi], dur);
46
}
47
if
(
IMG_TEST
) printf(
"applied_dc_factor[%d] := %g\n"
, fi+1, cf);
48
/* Set decay correction factor inside IMG for future */
49
if
(mode==0) {
50
image->
decayCorrFactor
[fi]=1.0;
51
}
else
{
52
image->
decayCorrFactor
[fi]=cf;
53
}
54
/* All planes, all matrices */
55
for
(
int
pi=0; pi<image->
dimz
; pi++)
56
for
(
int
i=0; i<image->
dimy
; i++)
57
for
(
int
j=0; j<image->
dimx
; j++)
58
image->
m
[pi][i][j][fi]*=cf;
59
if
(mode==0) image->
decayCorrection
=
IMG_DC_NONCORRECTED
;
60
else
image->
decayCorrection
=
IMG_DC_CORRECTED
;
61
/* in some cases left unchanged! */
62
}
63
}
/* next frame */
64
return
(0);
65
}
66
/*****************************************************************************/
67
68
/*****************************************************************************/
76
char
*
imgIsotope
(
IMG
*img) {
77
return
(
hlIsotopeCode
(
hlIsotopeFromHalflife
(img->
isotopeHalflife
/60.0)));
78
}
79
/*****************************************************************************/
80
81
/*****************************************************************************/
87
int
imgSetDecayCorrFactors
(
89
IMG
*image,
91
int
mode
92
) {
93
float
lambda, cf, dur;
94
95
/* Check for arguments */
96
if
(image->
status
!=
IMG_STATUS_OCCUPIED
)
return
(1);
97
if
(image->
isotopeHalflife
<=0.0)
return
(1);
98
99
/* Check that image contains frame times */
100
if
(mode!=0 && image->
end
[image->
dimt
-1]<=0.0)
return
(3);
101
102
/* All time frames */
103
for
(
int
fi=0; fi<image->
dimt
; fi++) {
104
if
(mode==0) {
105
image->
decayCorrFactor
[fi]=1.0;
106
}
else
{
107
dur=image->
end
[fi]-image->
start
[fi];
108
if
(image->
end
[fi]>0.0) {
109
lambda=
hl2lambda
(image->
isotopeHalflife
);
if
(lambda<0.0)
return
(2);
110
cf=
hlLambda2factor_float
(lambda, image->
start
[fi], dur);
111
image->
decayCorrFactor
[fi]=cf;
112
}
113
}
114
}
/* next frame */
115
if
(mode==0) image->
decayCorrection
=
IMG_DC_NONCORRECTED
;
116
else
image->
decayCorrection
=
IMG_DC_CORRECTED
;
117
return
(0);
118
}
119
/*****************************************************************************/
120
121
/*****************************************************************************/
132
int
imgBranchingCorrection
(
134
IMG
*image,
136
int
mode,
138
int
verbose,
140
char
*status
141
) {
142
int
isotope;
143
float
bf;
144
float
cf;
145
146
if
(verbose>0) printf(
"imgBranchingCorrection(*img, %d, %d, *status)\n"
,
147
mode, verbose);
148
/* Check for arguments */
149
if
(status!=NULL) strcpy(status,
"invalid input"
);
150
if
(image->
status
!=
IMG_STATUS_OCCUPIED
)
return
(1);
151
if
(image->
isotopeHalflife
<=0.0) {
152
if
(verbose>0) printf(
"Error: unknown isotope.\n"
);
153
if
(status!=NULL) strcpy(status,
"unknown isotope"
);
154
return
(2);
155
}
156
157
/* If branching factor not found in IMG, then get it based on half-life */
158
bf=image->
branchingFraction
;
159
if
(bf<=0.0 || bf>=1.0) {
160
isotope=
hlIsotopeFromHalflife
(image->
isotopeHalflife
/60.0);
161
if
(verbose>2) printf(
"isotope := %d\n"
, isotope);
162
bf=
branchingFraction
(isotope);
163
}
164
if
(bf<=0.0 || bf>=1.0) {
165
if
(verbose>0) printf(
"Error: branching fraction unknown for the isotope.\n"
);
166
if
(status!=NULL) strcpy(status,
"branching fraction unknown for the isotope"
);
167
return
(3);
168
}
169
170
/* Multiply with BF to remove correction, and divide to correct */
171
if
(mode==0) cf=bf;
else
cf=1.0/bf;
172
/* Process pixel values */
173
if
(verbose>1) printf(
"multiplying data by %g\n"
, cf);
174
for
(
int
fi=0; fi<image->
dimt
; fi++) {
175
for
(
int
pi=0; pi<image->
dimz
; pi++)
176
for
(
int
i=0; i<image->
dimy
; i++)
177
for
(
int
j=0; j<image->
dimx
; j++)
178
image->
m
[pi][i][j][fi]*=cf;
179
}
180
181
/* Fix header contents, too */
182
if
(image->
calibrationFactor
>0.0) image->
calibrationFactor
*=cf;
183
if
(mode==0) image->
branchingFraction
=0.0;
184
else
image->
branchingFraction
=bf;
185
186
if
(status!=NULL) strcpy(status,
"ok"
);
187
return
(0);
188
}
189
/*****************************************************************************/
190
191
/*****************************************************************************/
192
branchingFraction
float branchingFraction(int isotope)
Definition
branch.c:14
hl2lambda
double hl2lambda(double halflife)
Definition
halflife.c:84
hlIsotopeCode
char * hlIsotopeCode(int isotope)
Definition
halflife.c:36
hlLambda2factor_float
float hlLambda2factor_float(float lambda, float frametime, float framedur)
Definition
halflife.c:118
hlIsotopeFromHalflife
int hlIsotopeFromHalflife(double halflife)
Definition
halflife.c:195
IMG_TEST
int IMG_TEST
Definition
img.c:6
imgIsotope
char * imgIsotope(IMG *img)
Definition
imgdecayc.c:76
imgBranchingCorrection
int imgBranchingCorrection(IMG *image, int mode, int verbose, char *status)
Definition
imgdecayc.c:132
imgSetDecayCorrFactors
int imgSetDecayCorrFactors(IMG *image, int mode)
Definition
imgdecayc.c:87
imgDecayCorrection
int imgDecayCorrection(IMG *image, int mode)
Definition
imgdecayc.c:16
libtpcimgio.h
Header file for libtpcimgio.
IMG_STATUS_OCCUPIED
#define IMG_STATUS_OCCUPIED
Definition
libtpcimgio.h:1479
IMG_DC_CORRECTED
#define IMG_DC_CORRECTED
Definition
libtpcimgio.h:1531
IMG_DC_NONCORRECTED
#define IMG_DC_NONCORRECTED
Definition
libtpcimgio.h:1533
IMG
Definition
libtpcimgio.h:1657
IMG::dimx
unsigned short int dimx
Definition
libtpcimgio.h:1780
IMG::branchingFraction
float branchingFraction
Definition
libtpcimgio.h:1690
IMG::m
float **** m
Definition
libtpcimgio.h:1799
IMG::decayCorrection
char decayCorrection
Definition
libtpcimgio.h:1688
IMG::status
char status
Definition
libtpcimgio.h:1665
IMG::dimt
unsigned short int dimt
Definition
libtpcimgio.h:1778
IMG::start
float * start
Definition
libtpcimgio.h:1815
IMG::dimz
unsigned short int dimz
Definition
libtpcimgio.h:1784
IMG::dimy
unsigned short int dimy
Definition
libtpcimgio.h:1782
IMG::end
float * end
Definition
libtpcimgio.h:1817
IMG::calibrationFactor
float calibrationFactor
Definition
libtpcimgio.h:1675
IMG::decayCorrFactor
float * decayCorrFactor
Definition
libtpcimgio.h:1839
IMG::isotopeHalflife
float isotopeHalflife
Definition
libtpcimgio.h:1685
Generated on
for TPCCLIB by
1.17.0