TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcabss
abss.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <math.h>
10
#include <time.h>
11
#include <string.h>
12
/*****************************************************************************/
13
#include "
tpcextensions.h
"
14
/*****************************************************************************/
15
#include "
tpcabss.h
"
16
/*****************************************************************************/
17
18
/*****************************************************************************/
23
int
abssAboveZero
(
25
TAC
*abss,
28
int
*n1,
31
int
*n2,
34
int
*n
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
&&
42
abss->
format
!=
TAC_FORMAT_ABSS_ALLOGG_OLD
&&
43
abss->
format
!=
TAC_FORMAT_ABSS_GEMS
&&
44
abss->
format
!=
TAC_FORMAT_ABSS_SCANDITRONICS
)
45
{
46
return
(2);
47
}
48
49
/* Set the data columns */
50
int
c1, c2;
51
if
(abss->
format
==
TAC_FORMAT_ABSS_ALLOGG
||
52
abss->
format
==
TAC_FORMAT_ABSS_ALLOGG
)
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
}
74
/*****************************************************************************/
75
76
/*****************************************************************************/
82
int
abssHigherCounts
(
84
TAC
*abss,
87
int
*n1,
90
int
*n2
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
&&
97
abss->
format
!=
TAC_FORMAT_ABSS_ALLOGG_OLD
&&
98
abss->
format
!=
TAC_FORMAT_ABSS_GEMS
&&
99
abss->
format
!=
TAC_FORMAT_ABSS_SCANDITRONICS
)
100
{
101
return
(2);
102
}
103
104
/* Set the data columns */
105
int
c1, c2;
106
if
(abss->
format
==
TAC_FORMAT_ABSS_ALLOGG
||
107
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
}
127
/*****************************************************************************/
128
129
/*****************************************************************************/
134
int
abssCalculateRatio
(
136
TAC
*abss,
138
double
*ratio,
141
int
*n
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
&&
148
abss->
format
!=
TAC_FORMAT_ABSS_ALLOGG_OLD
&&
149
abss->
format
!=
TAC_FORMAT_ABSS_GEMS
&&
150
abss->
format
!=
TAC_FORMAT_ABSS_SCANDITRONICS
)
151
{
152
return
(2);
153
}
154
155
/* Set the data columns */
156
int
c1, c2;
157
if
(abss->
format
==
TAC_FORMAT_ABSS_ALLOGG
||
158
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
}
185
/*****************************************************************************/
186
187
/*****************************************************************************/
192
int
abssFixChannel
(
194
TAC
*abss,
196
int
channel,
198
double
ratio
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
&&
203
abss->
format
!=
TAC_FORMAT_ABSS_ALLOGG_OLD
&&
204
abss->
format
!=
TAC_FORMAT_ABSS_GEMS
&&
205
abss->
format
!=
TAC_FORMAT_ABSS_SCANDITRONICS
)
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
||
215
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
}
237
/*****************************************************************************/
238
239
/*****************************************************************************/
244
int
abssCalculateCps
(
246
TAC
*abss
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
&&
251
abss->
format
!=
TAC_FORMAT_ABSS_ALLOGG_OLD
&&
252
abss->
format
!=
TAC_FORMAT_ABSS_GEMS
&&
253
abss->
format
!=
TAC_FORMAT_ABSS_SCANDITRONICS
)
254
{
255
return
(2);
256
}
257
258
/* Set the data columns */
259
int
c1, c2;
260
if
(abss->
format
==
TAC_FORMAT_ABSS_ALLOGG
||
261
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
}
279
/*****************************************************************************/
280
281
/*****************************************************************************/
292
int
abssChannelMean
(
294
TAC
*abss,
296
double
*mean
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
&&
301
abss->
format
!=
TAC_FORMAT_ABSS_ALLOGG_OLD
&&
302
abss->
format
!=
TAC_FORMAT_ABSS_GEMS
&&
303
abss->
format
!=
TAC_FORMAT_ABSS_SCANDITRONICS
)
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
||
312
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
||
322
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
}
335
/*****************************************************************************/
336
337
/*****************************************************************************/
abssAboveZero
int abssAboveZero(TAC *abss, int *n1, int *n2, int *n)
Definition
abss.c:23
abssHigherCounts
int abssHigherCounts(TAC *abss, int *n1, int *n2)
Definition
abss.c:82
abssFixChannel
int abssFixChannel(TAC *abss, int channel, double ratio)
Definition
abss.c:192
abssCalculateRatio
int abssCalculateRatio(TAC *abss, double *ratio, int *n)
Definition
abss.c:134
abssChannelMean
int abssChannelMean(TAC *abss, double *mean)
Definition
abss.c:292
abssCalculateCps
int abssCalculateCps(TAC *abss)
Definition
abss.c:244
TACC::y
double * y
Definition
tpctac.h:75
TAC
Definition
tpctac.h:87
TAC::format
tacformat format
Definition
tpctac.h:93
TAC::sampleNr
int sampleNr
Definition
tpctac.h:89
TAC::c
TACC * c
Definition
tpctac.h:117
TAC::x2
double * x2
Definition
tpctac.h:101
TAC::x1
double * x1
Definition
tpctac.h:99
TAC::tacNr
int tacNr
Definition
tpctac.h:91
tpcabss.h
Header file for libtpcabss.
tpcextensions.h
Header file for library libtpcextensions.
TAC_FORMAT_ABSS_ALLOGG
@ TAC_FORMAT_ABSS_ALLOGG
ALLOGG ABSS data; reading supported.
Definition
tpctac.h:56
TAC_FORMAT_ABSS_GEMS
@ TAC_FORMAT_ABSS_GEMS
GEMS ABSS data; reading supported.
Definition
tpctac.h:54
TAC_FORMAT_ABSS_ALLOGG_OLD
@ TAC_FORMAT_ABSS_ALLOGG_OLD
ALLOGG ABSS data (old format); reading supported.
Definition
tpctac.h:55
TAC_FORMAT_ABSS_SCANDITRONICS
@ TAC_FORMAT_ABSS_SCANDITRONICS
Scanditronics ABSS data; reading supported.
Definition
tpctac.h:53
Generated on
for TPCCLIB by
1.17.0