TPCCLIB
Loading...
Searching...
No Matches
halflife.c File Reference

Functions for processing isotope half-life and decay correction. More...

#include "libtpcmisc.h"

Go to the source code of this file.

Functions

char * hlIsotopeCode (int isotope)
 
double hlFromIsotope (char *isocode)
 
double hl2lambda (double halflife)
 
double hlLambda2factor (double lambda, double frametime, double framedur)
 
float hlLambda2factor_float (float lambda, float frametime, float framedur)
 
char * hlCorrectIsotopeCode (char *isocode)
 
int hlIsotopeFromHalflife (double halflife)
 

Detailed Description

Functions for processing isotope half-life and decay correction.

Author
Vesa Oikonen, Kaisa Liukko
See also
branch.c

Definition in file halflife.c.

Function Documentation

◆ hl2lambda()

double hl2lambda ( double halflife)

Calculates the isotope lambda from specified halflife.

Parameters
halflifehalflife time value
Returns
A negative value is returned in case of error.

Definition at line 84 of file halflife.c.

84 {
85 if(halflife>0.0) return(M_LN2/halflife); else return(-1.0); // M_LN2=log(2.0)
86}
#define M_LN2
Definition libtpcmisc.h:90

Referenced by atnMake(), dftDecayCorrection(), img2sif(), imgDecayCorrection(), imgSetDecayCorrFactors(), and noiseSD4Simulation().

◆ hlCorrectIsotopeCode()

char * hlCorrectIsotopeCode ( char * isocode)

Check that isotope code, e.g. F-18, is in valid format, containing '-' and in this order. Returns the correct isotope code.

Parameters
isocodePointer to string "C-11", "11c" etc; contents of this string is not changed, and this is not returned in any case
Returns
pointer to correct isotope code, and NULL if it was not valid and could not be corrected.

Definition at line 141 of file halflife.c.

141 {
142 int i, ok=0, n, mass_nr=0, ic_mass_nr=0;
143 char *cptr, atom[3], ic_atom[3];
144
145 /* Check, if isocode can be found in the list */
146 i=ok=0;
147 while(isotope_code[i]!=0) {
148 if(strcasecmp(isotope_code[i], isocode)==0) {
149 ok=1;
150 break;
151 }
152 i++;
153 }
154 if(ok==1) return(isotope_code[i]);
155
156 /* Try to figure out what it is */
157 /* Separate the atom name and mass number */
158 n=strcspn(isocode, "-1234567890");
159 if(n>2) { /* cannot be */
160 return(NULL);
161 } else if(n>0) { /* start with atom name */
162 strncpy(atom, isocode, n); atom[n]=(char)0;
163 mass_nr=atoi(isocode+n); if(mass_nr<0) mass_nr=-mass_nr;
164 } else { /* starts with mass number */
165 mass_nr=atoi(isocode);
166 cptr=isocode; while(isdigit((int)cptr[0])) cptr++;
167 if(strlen(cptr)>2) return(NULL);
168 strcpy(atom, cptr);
169 }
170 /* Check if it matches any of the listed isotopes */
171 i=ok=0;
172 while(isotope_code[i]!=0) {
173 /* Separate the atom name and mass number from the listed isotope */
174 n=strcspn(isotope_code[i], "-1234567890");
175 strncpy(ic_atom, isotope_code[i], n); ic_atom[n]=(char)0;
176 ic_mass_nr=atoi(isotope_code[i]+n+1);
177 /* Check the atom name */
178 if(strcasecmp(ic_atom, atom)!=0) {i++; continue;}
179 /* Check the mass number, if given */
180 if(mass_nr>0 && ic_mass_nr!=mass_nr) {i++; continue;}
181 /* Match was found! */
182 ok=1; break;
183 }
184 if(ok==1) return(isotope_code[i]); else return(NULL);
185}

Referenced by hlFromIsotope(), and sif2dft().

◆ hlFromIsotope()

double hlFromIsotope ( char * isocode)

Identify the isotope from the specified isotope code string and return the halflife (min). This function checks the validity of the isotope string using hlCorrectIsotopeCode(), but does not change it in any way.

Returns
A negative value is returned in case of error.
Parameters
isocodePointer to string "C-11", "18f" etc. This argument is not changed.

Definition at line 55 of file halflife.c.

58 {
59 char *corrected_isocode;
60 int i = 0;
61 int ok = 0;
62
63 /* Validate the isotope string */
64 corrected_isocode=hlCorrectIsotopeCode(isocode);
65 if(corrected_isocode==NULL) return(-1.0);
66
67 /* Determine the isotope and return the half-life */
68 while(isotope_code[i]!=0) {
69 if(strcmp(isotope_code[i], corrected_isocode)==0) {ok=1; break;}
70 i++;
71 }
72 if(ok==1) return(isotope_halflife[i]);
73 else return(-2.0);
74}
char * hlCorrectIsotopeCode(char *isocode)
Definition halflife.c:141

Referenced by dftDecayCorrection(), imgReadAnalyzeHeader(), imgReadModelingData(), imgReadNiftiHeader(), noiseSD4SimulationFromDFT(), and sif2img().

◆ hlIsotopeCode()

char * hlIsotopeCode ( int isotope)

Isotope code as a string, based on isotope list number.

Parameters
isotopeindex of PET isotope in the list in halflife.c
Returns
pointer to static string or "unknown".

Definition at line 36 of file halflife.c.

36 {
37 static char unknown_isotope[]="unknown";
38 int n=0;
39
40 while(isotope_code[n]!=0) n++;
41 if(isotope<0 || isotope>n-1) return(unknown_isotope);
42 else return(isotope_code[isotope]);
43}

Referenced by dftDecayCorrection(), and imgIsotope().

◆ hlIsotopeFromHalflife()

int hlIsotopeFromHalflife ( double halflife)

Identify the isotope based on its halflife (in minutes).

Parameters
halflifeHalf-life in minutes
Returns
the isotope list number, or negative value if not identified.

Definition at line 195 of file halflife.c.

195 {
196 int i=0, ok=0;
197 if(halflife<=0.01) return(-1);
198 while(isotope_halflife[i]>0.0) {
199 if( fabs(halflife/isotope_halflife[i]-1.0)<0.05 ) {ok=1; break;}
200 i++;
201 }
202 if(ok==1) return(i);
203 else return(-2.0);
204}

Referenced by dftDecayCorrection(), imgBranchingCorrection(), and imgIsotope().

◆ hlLambda2factor()

double hlLambda2factor ( double lambda,
double frametime,
double framedur )

Calculate the decay correction factor for specified isotope lambda.

Parameters
lambdaNegative lambda removes decay correction
frametimeFrame start time, or mid time if framedur<=0
framedurIf unknown, set <0 and give mid time for frametime
Returns
A negative value is returned in case of error.

Definition at line 98 of file halflife.c.

98 {
99 double cf, ff;
100
101 if(frametime<0) return(-1.0);
102 cf=exp(lambda*frametime);
103 if(framedur>1.0E-5) {
104 ff=fabs(lambda)*framedur/(1.0-exp(-fabs(lambda)*framedur));
105 if(lambda<0.0) cf/=ff; else cf*=ff;
106 }
107 return(cf);
108}

Referenced by atnMake(), dftDecayCorrection(), img2sif(), and noiseSD4Simulation().

◆ hlLambda2factor_float()

float hlLambda2factor_float ( float lambda,
float frametime,
float framedur )

Calculate the decay correction factor for specified isotope lambda. Version for floats (mainly image data).

Parameters
lambdaNegative lambda removes decay correction
frametimeFrame start time, or mid time if framedur<=0
framedurIf unknown, set <0 and give mid time for frametime
Returns
A negative value is returned in case of error.

Definition at line 118 of file halflife.c.

118 {
119 float cf, ff;
120
121 if(frametime<0) return(-1.0);
122 cf=exp(lambda*frametime);
123 if(framedur>1.0E-5) {
124 ff=fabs(lambda)*framedur/(1.0-exp(-fabs(lambda)*framedur));
125 if(lambda<0.0) cf/=ff; else cf*=ff;
126 }
127 return(cf);
128}

Referenced by imgDecayCorrection(), and imgSetDecayCorrFactors().