TPCCLIB
Loading...
Searching...
No Matches
dftdecayc.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "libtpccurveio.h"
7/*****************************************************************************/
8
9/*****************************************************************************/
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) {
115 if(status!=NULL) strcpy(status, "decay corrected");
116 } else {
118 if(status!=NULL) strcpy(status, "decay correction removed");
119 }
120 return(0);
121}
122/*****************************************************************************/
123
124/*****************************************************************************/
int dftDecayCorrection(DFT *dft, double hl, int mode, int y, int y2, int y3, char *status, int verbose)
Definition dftdecayc.c:16
double hl2lambda(double halflife)
Definition halflife.c:84
char * hlIsotopeCode(int isotope)
Definition halflife.c:36
double hlLambda2factor(double lambda, double frametime, double framedur)
Definition halflife.c:98
double hlFromIsotope(char *isocode)
Definition halflife.c:55
int hlIsotopeFromHalflife(double halflife)
Definition halflife.c:195
Header file for libtpccurveio.
#define DFT_DECAY_NOTCORRECTED
#define DFT_DECAY_CORRECTED
#define DFT_TIME_STARTEND
char decayCorrected
int timetype
Voi * voi
int timeunit
double * x1
int voiNr
double * x2
int frameNr
char isotope[8]
double * x
double * y2
double * y
double * y3