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

Processing ABSS data stored in TAC struct. More...

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

Go to the source code of this file.

Functions

int abssAboveZero (TAC *abss, int *n1, int *n2, int *n)
int abssHigherCounts (TAC *abss, int *n1, int *n2)
int abssCalculateRatio (TAC *abss, double *ratio, int *n)
int abssFixChannel (TAC *abss, int channel, double ratio)
int abssCalculateCps (TAC *abss)
int abssChannelMean (TAC *abss, double *mean)

Detailed Description

Processing ABSS data stored in TAC struct.

Definition in file abss.c.

Function Documentation

◆ abssAboveZero()

int abssAboveZero ( TAC * abss,
int * n1,
int * n2,
int * n )

Calculate the number of ABSS samples with positive counts.

See also
tacRead, abssWrite, abssHigherCounts, abssCalculateRatio, abssFixChannel
Returns
Returns <>0 in case of an error.
Parameters
abssPointer to TAC struct containing raw ABSS data.
n1Number of positive samples in channel 1 is written in here; enter NULL if not needed.
n2Number of positive samples in channel 2 is written in here; enter NULL if not needed.
nNumber of samples with positive counts in either of channels; enter NULL if not needed.

Definition at line 23 of file abss.c.

35 {
36 if(n1!=NULL) *n1=0;
37 if(n2!=NULL) *n2=0;
38 if(n!=NULL) *n=0;
39 /* Check the data */
40 if(abss==NULL || abss->tacNr<1 || abss->sampleNr<1) return(1);
41 if(abss->format!=TAC_FORMAT_ABSS_ALLOGG &&
45 {
46 return(2);
47 }
48
49 /* Set the data columns */
50 int c1, c2;
53 {
54 c1=0; c2=1;
55 } else {
56 c1=0; c2=3;
57 }
58 if(c2>=abss->tacNr) {return(3);}
59
60 /* Count the samples with positive counts */
61 int m1, m2, m;
62 m1=m2=m=0;
63 for(int i=0; i<abss->sampleNr; i++) {
64 if(abss->c[c1].y[i]>0.0) m1++;
65 if(abss->c[c2].y[i]>0.0) m2++;
66 if(abss->c[c1].y[i]>0.0 || abss->c[c2].y[i]>0.0) m++;
67 }
68 if(n1!=NULL) *n1=m1;
69 if(n2!=NULL) *n2=m2;
70 if(n!=NULL) *n=m;
71
72 return(0);
73}
double * y
Definition tpctac.h:75
tacformat format
Definition tpctac.h:93
int sampleNr
Definition tpctac.h:89
TACC * c
Definition tpctac.h:117
int tacNr
Definition tpctac.h:91
@ TAC_FORMAT_ABSS_ALLOGG
ALLOGG ABSS data; reading supported.
Definition tpctac.h:56
@ TAC_FORMAT_ABSS_GEMS
GEMS ABSS data; reading supported.
Definition tpctac.h:54
@ TAC_FORMAT_ABSS_ALLOGG_OLD
ALLOGG ABSS data (old format); reading supported.
Definition tpctac.h:55
@ TAC_FORMAT_ABSS_SCANDITRONICS
Scanditronics ABSS data; reading supported.
Definition tpctac.h:53

◆ abssCalculateCps()

int abssCalculateCps ( TAC * abss)

Divide the ABSS coincident counts by frame duration.

See also
tacRead, abssWrite, abssCalculateRatio, abssFixChannel
Returns
Returns <>0 in case of an error.
Parameters
abssPointer to TAC struct containing raw ABSS data.

Definition at line 244 of file abss.c.

247 {
248 /* Check the data */
249 if(abss==NULL || abss->tacNr<1 || abss->sampleNr<1) return(1);
250 if(abss->format!=TAC_FORMAT_ABSS_ALLOGG &&
254 {
255 return(2);
256 }
257
258 /* Set the data columns */
259 int c1, c2;
260 if(abss->format==TAC_FORMAT_ABSS_ALLOGG ||
262 {
263 c1=0; c2=1;
264 } else {
265 c1=0; c2=3;
266 }
267 if(c2>=abss->tacNr) {return(3);}
268
269 /* Count the cps for both channels */
270 double fdur;
271 for(int i=0; i<abss->sampleNr; i++) {
272 fdur=abss->x2[i]-abss->x1[i]; if(!(fdur>0.0)) continue;
273 abss->c[c1].y[i]/=fdur;
274 abss->c[c2].y[i]/=fdur;
275 }
276
277 return(0);
278}
double * x2
Definition tpctac.h:101
double * x1
Definition tpctac.h:99

◆ abssCalculateRatio()

int abssCalculateRatio ( TAC * abss,
double * ratio,
int * n )

Calculate the number of ABSS samples with positive counts.

See also
tacRead, abssWrite, abssFixChannel
Returns
Returns <>0 in case of an error.
Parameters
abssPointer to TAC struct containing raw ABSS data.
ratioChannel1-to-channel2 is written in here.
nNumber of samples which could be used in calculation of the ratio; enter NULL if not needed.

Definition at line 134 of file abss.c.

142 {
143 if(ratio!=NULL) *ratio=nan("");
144 if(n!=NULL) *n=0;
145 /* Check the data */
146 if(abss==NULL || abss->tacNr<1 || abss->sampleNr<1) return(1);
147 if(abss->format!=TAC_FORMAT_ABSS_ALLOGG &&
151 {
152 return(2);
153 }
154
155 /* Set the data columns */
156 int c1, c2;
157 if(abss->format==TAC_FORMAT_ABSS_ALLOGG ||
159 {
160 c1=0; c2=1;
161 } else {
162 c1=0; c2=3;
163 }
164 if(c2>=abss->tacNr) {return(3);}
165
166 /* Count the cps sum for both channels */
167 double s1, s2, v1, v2, fdur, r;
168 s1=s2=0.0;
169 int m=0;
170 for(int i=0; i<abss->sampleNr; i++) {
171 fdur=abss->x2[i]-abss->x1[i]; if(!(fdur>0.0)) continue;
172 v1=abss->c[c1].y[i]/fdur; v2=abss->c[c2].y[i]/fdur;
173 if(!isfinite(v1) || !isfinite(v2)) continue;
174 s1+=v1; s2+=v2; m++;
175 }
176 if(m<1) {return(4);}
177
178 /* Calculate the ratio of sums */
179 r=s1/s2; if(!isfinite(r)) {return(5);}
180 if(ratio!=NULL) *ratio=r;
181 if(n!=NULL) *n=m;
182
183 return(0);
184}

◆ abssChannelMean()

int abssChannelMean ( TAC * abss,
double * mean )

Compute the mean of the two channels in Scanditronics or GEMS ABSS data stored in TAC struct.

If data is collected with Allogg, then column two is copied to 'mean' as such. Data is not divided by frame duration in this function.

See also
tacRead, abssCalculateCps, abssCalculateRatio
Returns
Returns <>0 in case of an error.
Parameters
abssPointer to TAC struct containing raw ABSS data.
meanPointer to double array, at least of length abss->sampleNr.

Definition at line 292 of file abss.c.

297 {
298 /* Check the data */
299 if(abss==NULL || abss->tacNr<1 || abss->sampleNr<1) return(1);
300 if(abss->format!=TAC_FORMAT_ABSS_ALLOGG &&
304 {
305 return(2);
306 }
307 if(mean==NULL) return(3);
308
309 /* Set the data columns */
310 int c1, c2;
311 if(abss->format==TAC_FORMAT_ABSS_ALLOGG ||
313 {
314 c1=0; c2=1;
315 } else {
316 c1=0; c2=3;
317 }
318 if(c2>=abss->tacNr) {return(3);}
319
320 /* If Allogg, the just copy, and then return */
321 if(abss->format==TAC_FORMAT_ABSS_ALLOGG ||
323 {
324 for(int i=0; i<abss->sampleNr; i++) mean[i]=abss->c[c2].y[i];
325 return(0);
326 }
327
328 /* Otherwise, compute the average for each sample frame */
329 for(int i=0; i<abss->sampleNr; i++) {
330 mean[i]=0.5*(abss->c[c1].y[i]+abss->c[c2].y[i]);
331 }
332
333 return(0);
334}

◆ abssFixChannel()

int abssFixChannel ( TAC * abss,
int channel,
double ratio )

Calculate the number of ABSS samples with positive counts.

See also
abssAboveZero, abssCalculateRatio, tacRead, abssWrite, abssCalculateRatio
Returns
Returns <>0 in case of an error.
Parameters
abssPointer to TAC struct containing raw ABSS data.
channelChannel to fix; either 1 or 2.
ratioCorrect channel1-to-channel2 ratio.

Definition at line 192 of file abss.c.

199 {
200 /* Check the data */
201 if(abss==NULL || abss->tacNr<1 || abss->sampleNr<1) return(1);
202 if(abss->format!=TAC_FORMAT_ABSS_ALLOGG &&
206 {
207 return(2);
208 }
209 if(channel!=1 && channel!=2) return(3);
210 if(!isfinite(ratio) || ratio<=0.0) return(4);
211
212 /* Set the data columns */
213 int c1, c2;
214 if(abss->format==TAC_FORMAT_ABSS_ALLOGG ||
216 {
217 c1=0; c2=1;
218 } else {
219 c1=0; c2=3;
220 }
221 if(c2>=abss->tacNr) {return(5);}
222
223 /* Fix the samples */
224 double f;
225 if(channel==1) {
226 f=ratio;
227 for(int i=0; i<abss->sampleNr; i++)
228 abss->c[c1].y[i]=f*abss->c[c2].y[i];
229 } else {
230 f=1.0/ratio;
231 for(int i=0; i<abss->sampleNr; i++)
232 abss->c[c2].y[i]=f*abss->c[c1].y[i];
233 }
234
235 return(0);
236}

◆ abssHigherCounts()

int abssHigherCounts ( TAC * abss,
int * n1,
int * n2 )

Calculate the number of ABSS samples which are positive and higher than the counts from the other channel.

See also
abssAboveZero, abssCalculateRatio, tacRead, abssWrite
Returns
Returns <>0 in case of an error.
Parameters
abssPointer to TAC struct containing raw ABSS data.
n1Number of samples in channel 1 that are positive and higher than counts from channel 2.
n2Number of samples in channel 2 that are positive and higher than counts from channel 1.

Definition at line 82 of file abss.c.

91 {
92 if(n1!=NULL) *n1=0;
93 if(n2!=NULL) *n2=0;
94 /* Check the data */
95 if(abss==NULL || abss->tacNr<1 || abss->sampleNr<1) return(1);
96 if(abss->format!=TAC_FORMAT_ABSS_ALLOGG &&
100 {
101 return(2);
102 }
103
104 /* Set the data columns */
105 int c1, c2;
106 if(abss->format==TAC_FORMAT_ABSS_ALLOGG ||
108 {
109 c1=0; c2=1;
110 } else {
111 c1=0; c2=3;
112 }
113 if(c2>=abss->tacNr) {return(3);}
114
115 /* Count the samples */
116 int m1, m2, m;
117 m1=m2=m=0;
118 for(int i=0; i<abss->sampleNr; i++) {
119 if(abss->c[c1].y[i]>abss->c[c2].y[i] && abss->c[c1].y[i]>0.0) m1++;
120 if(abss->c[c2].y[i]>abss->c[c1].y[i] && abss->c[c2].y[i]>0.0) m2++;
121 }
122 if(n1!=NULL) *n1=m1;
123 if(n2!=NULL) *n2=m2;
124
125 return(0);
126}