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

Factors for correcting or simulating physical decay. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcisotope.h"

Go to the source code of this file.

Functions

char * decayDescr (decaycorrection d)
 
double lambdaFromHalflife (double halflife)
 
double lambdaFromIsotope (int isotope)
 
double decayCorrectionFactorFromLambda (double lambda, double starttime, double duration)
 
double decayCorrectionFactorFromIsotope (int isotope, double starttime, double duration)
 

Detailed Description

Factors for correcting or simulating physical decay.

Definition in file decay.c.

Function Documentation

◆ decayCorrectionFactorFromIsotope()

double decayCorrectionFactorFromIsotope ( int isotope,
double starttime,
double duration )

Calculate the correction factor for physical decay from measurement time to time zero.

Returns
Factor for decay correction (>1), or NaN if input is invalid.
See also
lambdaFromIsotope, isotopeIdentify, decayCorrectionFactorFromLambda, isotopeName
Author
Vesa Oikonen
Parameters
isotopeisotope_code as enum or the index of isotope in isotope table.
starttimeRadioactivity measurement start time, or middle time, if measurement duration is not known. Unit must be min.
durationRadioactivity measurement duration; if not known, then set to zero, and put measurement middle time for starttime. Unit must be min.

Definition at line 107 of file decay.c.

116 {
117 double lambda=lambdaFromIsotope(isotope); if(isnan(lambda)) return nan("");
118 return decayCorrectionFactorFromLambda(lambda, starttime, duration);
119}
double lambdaFromIsotope(int isotope)
Definition decay.c:63
double decayCorrectionFactorFromLambda(double lambda, double starttime, double duration)
Definition decay.c:79
isotope
Definition tpcisotope.h:50

Referenced by noiseSD4Frame(), and sifWeight().

◆ decayCorrectionFactorFromLambda()

double decayCorrectionFactorFromLambda ( double lambda,
double starttime,
double duration )

Calculate the correction factor for physical decay from measurement time to time zero.

Returns
Factor for decay correction (>1 when lambda>0) or for simulating decay (<1 when lambda<0), or NaN if input is invalid.
See also
lambdaFromIsotope, isotopeIdentify, decayCorrectionFactorFromIsotope
Author
Vesa Oikonen
Parameters
lambdaPositive or negative lambda for the isotope. Note that time unit must be 1/timeunit of the starttime and duration.
starttimeRadioactivity measurement start time, or middle time, if measurement duration is not known.
durationRadioactivity measurement duration; if not known, then set to zero, and put measurement middle time for starttime.

Definition at line 79 of file decay.c.

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}

Referenced by decayCorrectionFactorFromIsotope(), tacDecayCorrection(), and tacWByFreq().

◆ decayDescr()

char * decayDescr ( decaycorrection d)

Return pointer to string describing the status of decay correction.

See also
isotopeName
Returns
pointer to the name string.
Parameters
dEnum decaycorrection.

Definition at line 32 of file decay.c.

35 {
36 if(d>4) return(decay_correction[0]);
37 return(decay_correction[d]);
38}

Referenced by dcmImgIsotope(), and imgReadDICOM().

◆ lambdaFromHalflife()

double lambdaFromHalflife ( double halflife)

Calculate lambda based on specified halflife.

Returns
Lambda (=ln(2)/halflife), or NaN if halflife is NaN or <=0.
See also
isotopeIdentifyHalflife, isotopeName, lambdaFromIsotope
Author
Vesa Oikonen
Parameters
halflifeHalflife of the isotope; if halflife is in minutes, then the unit of lambda will be 1/min, if seconds, then lambda will be in units 1/sec, etc.

Definition at line 47 of file decay.c.

51 {
52 if(halflife>0.0) return(M_LN2/halflife); // M_LN2=log(2.0)
53 else return nan("");
54}
#define M_LN2
Defined ln(2) for faster computations.
Definition tpcisotope.h:37

Referenced by tacDecayCorrection().

◆ lambdaFromIsotope()

double lambdaFromIsotope ( int isotope)

Calculate lambda for specified isotope.

Returns
Lambda (=ln(2)/halflife) in units 1/min, or NaN if isotope is not identified.
See also
decayCorrectionFactorFromLambda, isotopeName, isotopeIdentify, decayCorrectionFactorFromIsotope
Author
Vesa Oikonen
Parameters
isotopeisotope_code as enum or the index of isotope in isotope table.

Definition at line 63 of file decay.c.

66 {
67 double hl=isotopeHalflife(isotope); if(isnan(hl) || hl<=0.0) return nan("");
68 return(M_LN2/hl);
69}
double isotopeHalflife(int isotope_code)
Definition isotope.c:62

Referenced by decayCorrectionFactorFromIsotope(), and tacWByFreq().