5#include "tpcclibConfig.h"
28 if(tac==NULL)
return(0);
30 if(tac->
weighting<WEIGHTING_LAST)
return(1);
55 for(
int i=i1; i<=i2; i++) {
56 tac2->
w[i]=tac1->
w[i];
83 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
84 if(verbose>0) printf(
"%s()\n", __func__);
95 for(
int i=0; i<tac->
tacNr; i++) {
96 if(strncasecmp(tac->
c[i].
name,
"WEIGHT", 6)!=0)
continue;
116 for(
int i=0; i<tac->
sampleNr; i++) tac->
w[i]=tac->
c[wc].
y[i];
120 statusSet(status, __func__, __FILE__, __LINE__, ret);
145 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
146 if(verbose>0) printf(
"%s(%s)\n", __func__,
isotopeName(isot));
158 for(
int i=0; i<tac->
sampleNr; i++) {
159 tac->
w[i]=tac->
x2[i]-tac->
x1[i];
170 for(i1=i; i1>=0; i1--) {t1=tac->
x[i1];
if(t1<t)
break;}
172 for(i2=i; i2<tac->
sampleNr; i2++) {t2=tac->
x[i2];
if(t2>t)
break;}
175 if(t1<t) f+=t-t1;
else f+=t2-t;
176 if(t2>t) f+=t2-t;
else f+=t-t1;
177 f*=0.5;
if(f<=0.0) f=1.0;
199 for(
int i=0; i<tac->
sampleNr; i++)
if(isfinite(tac->
w[i])) sumw+=tac->
w[i];
205 for(
int i=0; i<tac->
sampleNr; i++) tac->
w[i]/=sumw;
223 if(tac==NULL || tac->
tacNr<1 || tac->
sampleNr<1)
return((
unsigned int)0);
226 for(
int i=0; i<tac->
sampleNr; i++)
if(tac->
w[i]>0.0) n++;
243 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
244 if(verbose>0) printf(
"%s()\n", __func__);
254 double wSum=0.0;
int wNr=0;
256 if(isfinite(tac->
w[i]) && tac->
w[i]>0.0) {wSum+=tac->
w[i]; wNr++;}
257 if(wNr==0 || !(wSum>0.0)) {
261 double wMean=wSum/(double)wNr;
263 if(isfinite(tac->
w[i]) && tac->
w[i]>0.0) tac->
w[i]/=wMean;
284 const double minprop,
292 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
293 if(verbose>0) printf(
"%s(%g, %d, %d)\n", __func__, minprop, doZeroes, doNaNs);
298 if(!isfinite(minprop) || minprop>=1.0) {
308 for(
int i=0; i<tac->
sampleNr; i++)
if(isfinite(tac->
w[i])) {
309 if(!isfinite(wMax)) {wMax=tac->
w[i];
continue;}
310 if(tac->
w[i]>wMax) wMax=tac->
w[i];
312 if(verbose>2) {printf(
"weight_maximum := %g\n", wMax); fflush(stdout);}
313 if(!isfinite(wMax) || wMax<=0.0) {
318 double wLimit=minprop*wMax;
319 if(verbose>2) {printf(
"weight_limit := %g\n", wLimit); fflush(stdout);}
323 for(
int i=0; i<tac->
sampleNr; i++) {
325 if(doZeroes) {tac->
w[i]=wLimit; n++;}
328 if(isnan(tac->
w[i])) {
329 if(doNaNs) {tac->
w[i]=wLimit; n++;}
332 if(tac->
w[i]<wLimit) {tac->
w[i]=wLimit; n++;}
335 if(verbose>1 && minprop>0.0) {printf(
" %d weight(s) set to %g.\n", n, wLimit); fflush(stdout);}
378 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
379 if(verbose>0) printf(
"%s(%s)\n", __func__,
isotopeName(isot));
381 if(sif!=NULL && verbose>2) {
382 printf(
" sif.tacNr := %d\n sif.sampleNr := %d\n", sif->
tacNr, sif->
sampleNr);
394 if(
tacXRange(sif, &xmin, &xmax) || !(xmax>xmin)) {
401 for(
int i=0; i<sif->
sampleNr; i++) trues[i]=sif->
c[0].
y[i]-sif->
c[1].
y[i];
403 printf(
"\nTrues:\n");
404 for(
int i=0; i<sif->
sampleNr; i++) printf(
"\t%g\n", trues[i]);
412 printf(
"\nTrues after decay correction:\n");
413 for(
int i=0; i<sif->
sampleNr; i++) printf(
"\t%g\n", trues[i]);
419 for(
int i=0; i<sif->
sampleNr; i++) {
420 double fdur=sif->
x2[i]-sif->
x1[i];
if(fdur<0.0) {
425 sif->
w[i]=fdur*fdur/trues[i];
426 if(sif->
w[i]>wMax) wMax=sif->
w[i];
435 if(verbose>1) {printf(
"\twMax := %g\n", wMax); fflush(stdout);}
437 for(
int i=0; i<sif->
sampleNr; i++)
if(!(trues[i]>0.0) && isnan(sif->
w[i])) sif->
w[i]=wMax;
439 printf(
"\nWeights before normalization:\n");
440 for(
int i=0; i<sif->
sampleNr; i++) printf(
"\t%g\n", sif->
w[i]);
475 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
476 if(verbose>0) {printf(
"%s(tac, %d, %d)\n", __func__, weightMethod, weightNr); fflush(stdout);}
488 if(verbose>3) {printf(
" isotope := %s\n",
isotopeName(fisot)); fflush(stdout);}
503 printf(
" Note: data did not contain weights.\n"); fflush(stdout);}
505 for(
int i=0; i<tac->
sampleNr; i++) tac->
w[i]=0.0;
506 for(
int i=0; i<weightNr; i++) tac->
w[i]=1.0;
507 if(verbose>1) {printf(
" weights removed.\n"); fflush(stdout);}
511 if(verbose>0) {fprintf(stderr,
"Error: cannot apply general weighting.\n"); fflush(stderr);}
512 for(
int i=0; i<tac->
sampleNr; i++) tac->
w[i]=0.0;
518 for(
int i=weightNr; i<tac->
sampleNr; i++) tac->
w[i]=0.0;
521 if(verbose>2) {printf(
" Note: data does not contain weights.\n"); fflush(stdout);}
522 for(
int i=0; i<weightNr; i++) tac->
w[i]=1.0;
524 if(verbose>2) {printf(
" Note: data contains weights.\n"); fflush(stdout);}
534 printf(
" Note: data already contained weights.\n"); fflush(stdout);}
536 for(
int i=0; i<tac->
sampleNr; i++) tac->
w[i]=0.0;
546 if(verbose>1) {printf(
" weights added.\n"); fflush(stdout);}
550 double weight_moderate=100.0;
577 double sum=0.0, wsum=0.0;
578 for(
int i=0; i<tac->
tacNr; i++) {
579 if(!isfinite(tac->
c[i].
y[j]))
continue;
580 double w=tac->
c[i].
size;
if(!(w>0.0)) w=1.0;
581 sum+=w*tac->
c[i].
y[j]; wsum+=w;
583 if(wsum>0.0) sif.
c[0].
y[j]=sum/wsum;
else sif.
c[0].
y[j]=0.0;
591 for(
int i=0; i<sif.
sampleNr; i++) sif.
c[0].
y[i]*=1000.;
596 for(
int i=0; i<sif.
sampleNr; i++) sif.
c[0].
y[i]*=(sif.
x2[i]-sif.
x1[i]);
600 sif.
c[2].
y[i]=sif.
c[0].
y[i];
608 double prop=0.0;
if(weight_moderate>1.0) prop=1.0/weight_moderate;
615 for(j=0; j<sif.
sampleNr; j++) tac->
w[j]=sif.
w[j];
616 for( ; j<tac->
sampleNr; j++) tac->
w[j]=0.0;
620 if(verbose>1) {printf(
" weights added.\n"); fflush(stdout);}
627 printf(
" Note: data already contained weights.\n"); fflush(stdout);}
629 for(
int i=0; i<tac->
sampleNr; i++) tac->
w[i]=0.0;
635 if(verbose>1) {printf(
" weights added.\n"); fflush(stdout);}
640 printf(
" Note: data already contained weights.\n"); fflush(stdout);}
642 for(
int i=0; i<tac->
sampleNr; i++) tac->
w[i]=0.0;
648 if(verbose>1) {printf(
" weights added.\n"); fflush(stdout);}
651 if(verbose>0) {fprintf(stderr,
"Error: invalid weighting scheme.\n"); fflush(stderr);}
double decayCorrectionFactorFromIsotope(int isotope, double starttime, double duration)
double lambdaFromIsotope(int isotope)
double decayCorrectionFactorFromLambda(double lambda, double starttime, double duration)
char * isotopeName(int isotope_code)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
char name[MAX_TACNAME_LEN+1]
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
int tacGetIsotope(TAC *tac)
int tacDecayCorrection(TAC *tac, int isotope, int mode, TPCSTATUS *status)
void tacSetIsotope(TAC *tac, int isotope)
int tacDeleteTACC(TAC *d, int i)
int tacYUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
int tacXUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
int tacSetWeights(TAC *tac, weights weightMethod, int weightNr, TPCSTATUS *status)
int tacWMove(TAC *tac, int ow, TPCSTATUS *status)
int sifWeight(TAC *sif, isotope isot, TPCSTATUS *status)
int tacIsWeighted(TAC *tac)
int tacWeightModerate(TAC *tac, const double minprop, const int doZeroes, const int doNaNs, TPCSTATUS *status)
int tacWeightNorm(TAC *tac, TPCSTATUS *status)
unsigned int tacWSampleNr(TAC *tac)
int tacWCopy(TAC *tac1, TAC *tac2, int i1, int i2)
int tacWByFreq(TAC *tac, isotope isot, TPCSTATUS *status)
int tacXCopy(TAC *tac1, TAC *tac2, int i1, int i2)
int tacIsX(TAC *d)
Verify if TAC structure contains reasonable x values (times).
int tacXRange(TAC *d, double *xmin, double *xmax)
Get the range of x values (times) in TAC structure.
weights
Is data weighted, or are weight factors available with data?
@ WEIGHTING_OFF
Not weighted or weights not available (weights for all included samples are 1.0).
@ WEIGHTING_ON_FD
Weights based on decay and sample frequency or frame length (Thiele et al, 2008).
@ WEIGHTING_UNKNOWN
Not known; usually assumed that not weighted.
@ WEIGHTING_ON_GENERAL
Weighted or weights are available, but not specified.
@ WEIGHTING_ON_F
Weights based on sample frequency or frame length.
@ WEIGHTING_ON_COUNTS
Weights based on counts (Mazoyer et al, 1986).
@ TPCERROR_DUPLICATE_DATA
File contains duplicate data.
@ TPCERROR_INVALID_XRANGE
Invalid sample time range.
@ TPCERROR_INVALID_VALUE
Invalid value.
@ TPCERROR_FAIL
General error.
@ TPCERROR_INVALID_X
Invalid sample time.
@ TPCERROR_UNSUPPORTED
Unsupported file type.
@ TPCERROR_NO_WEIGHTS
File contains no weights.
@ TPCERROR_INCOMPATIBLE_UNIT
Incompatible units.
@ TPCERROR_UNKNOWN_ISOTOPE
Unknown isotope.
@ TPCERROR_NO_DATA
File contains no data.
@ TPCERROR_INCOMPATIBLE_DATA
Incompatible data.
int unitIsRadioactivity(int u)
Header file for library libtpcift.
@ ISOTOPE_UNKNOWN
Unknown.
Header file for library libtpctac.
@ TAC_FORMAT_SIF
Scan information file.