TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcimgio
weight.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
#include "
libtpcimgio.h
"
7
/*****************************************************************************/
8
9
/*****************************************************************************/
28
void
sifWeight
(
30
SIF
*data,
35
double
halflife
36
) {
37
int
i;
38
double
f, d;
39
40
if
(
SIF_TEST
) printf(
"sifWeight(*sif, %g)\n"
, halflife);
41
/* Calculate weights */
42
for
(i=0; i<data->
frameNr
; i++) {
43
if
(data->
trues
[i]<1.0) data->
trues
[i]=1.0;
44
f=data->
x2
[i]-data->
x1
[i];
if
(f<=0.0) f=1.0;
45
if
(halflife<=1.0E-8)
46
d=1.0;
47
else
48
d=exp( ((data->
x1
[i]+data->
x2
[i])/2.0)*0.693147/halflife );
49
data->
weights
[i]=(f*f)/(d*data->
trues
[i]);
50
/*printf("%3d %g %g\n", i, data->trues[i], data->weights[i]);*/
51
}
52
53
/* Scale weights so that average weight is 1.0 */
54
sifWeightNorm
(data);
55
56
return
;
57
}
58
/*****************************************************************************/
59
60
/*****************************************************************************/
72
void
sifWeightByFrames
(
74
SIF
*data,
77
double
halflife
78
) {
79
int
i;
80
double
f, d;
81
82
if
(
SIF_TEST
) printf(
"sifWeightByFrames(*sif, %g)\n"
, halflife);
83
/* Calculate weights */
84
for
(i=0; i<data->
frameNr
; i++) {
85
f=data->
x2
[i]-data->
x1
[i];
if
(f<=0.0) f=1.0;
86
if
(halflife<=1.0E-8)
87
d=1.0;
88
else
89
d=exp( -((data->
x1
[i]+data->
x2
[i])/2.0)*0.693147/halflife );
90
data->
weights
[i]=f*d;
91
}
92
93
/* Scale weights so that average weight is 1.0 */
94
sifWeightNorm
(data);
95
96
return
;
97
}
98
/*****************************************************************************/
99
100
/*****************************************************************************/
105
void
sifWeightNorm
(
107
SIF
*d
108
) {
109
if
(
SIF_TEST
) printf(
"sifWeightNorm(*sif)\n"
);
110
int
i;
111
double
f=0.0;
112
for
(i=0; i<d->
frameNr
; i++) f+=d->
weights
[i];
113
f/=(double)d->
frameNr
;
114
for
(i=0; i<d->
frameNr
; i++) d->
weights
[i]/=f;
115
return
;
116
}
117
/*****************************************************************************/
118
119
/*****************************************************************************/
131
void
sifModerateTrues
(
133
SIF
*sif,
135
double
limit
136
) {
137
if
(
SIF_TEST
) printf(
"sifModerateTrues(*sif, %g)\n"
, limit);
138
139
if
(sif==NULL || sif->
frameNr
<2)
return
;
140
if
(limit<=1.0)
return
;
141
142
int
fi;
143
double
w, f;
144
for
(w=f=sif->
trues
[0], fi=1; fi<sif->frameNr; fi++) {
145
if
(sif->
trues
[fi]>w) w=sif->
trues
[fi];
146
else
if
(sif->
trues
[fi]<f) f=sif->
trues
[fi];
147
}
148
if
(f*limit<w) {
149
for
(w/=limit, fi=0; fi<sif->
frameNr
; fi++)
150
if
(sif->
trues
[fi]>0.0) sif->
trues
[fi]+=w;
else
sif->
trues
[fi]=w;
151
}
else
{
152
for
(fi=0; fi<sif->
frameNr
; fi++)
153
if
(sif->
trues
[fi]<0.0) sif->
trues
[fi]=0.0;
154
}
155
}
156
/*****************************************************************************/
157
158
/*****************************************************************************/
167
void
sifModerateWeights
(
169
SIF
*sif,
171
double
limit
172
) {
173
if
(
SIF_TEST
) printf(
"sifModerateWeights(*sif, %g)\n"
, limit);
174
175
if
(sif==NULL || sif->
frameNr
<2)
return
;
176
if
(limit<=1.0)
return
;
177
178
int
fi;
179
double
w, f;
180
w=f=nan(
""
);
181
for
(fi=0; fi<sif->
frameNr
; fi++) {
182
if
(isnan(sif->
weights
[fi]))
continue
;
183
if
(sif->
weights
[fi]<=0.0) {sif->
weights
[fi]=0.0;
continue
;}
184
if
(isnan(w)) w=sif->
weights
[fi];
185
if
(isnan(f)) f=sif->
weights
[fi];
186
if
(sif->
weights
[fi]>w) w=sif->
weights
[fi];
187
if
(sif->
weights
[fi]<f) f=sif->
weights
[fi];
188
}
189
if
(isnan(w) || isnan(f))
return
;
190
191
if
(f*limit<w) {
192
for
(w/=limit, fi=0; fi<sif->
frameNr
; fi++)
193
if
(sif->
weights
[fi]>0.0) sif->
weights
[fi]+=w;
194
}
195
}
196
/*****************************************************************************/
197
198
/*****************************************************************************/
207
int
sifExistentCounts
(
209
SIF
*sif
210
) {
211
int
fi, p=0, r=0;
212
double
v1, v2;
213
if
(sif==NULL || sif->
frameNr
<1)
return
0;
214
/* If just one frame, then value > 0 is fine */
215
if
(sif->
frameNr
==1) {
216
if
(sif->
prompts
[0]>0.00000001) p=1;
217
if
(sif->
randoms
[0]>0.00000001) r=2;
218
return
(p+r);
219
}
220
/* Otherwise, check also that frames have different count level */
221
for
(fi=1; fi<sif->
frameNr
; fi++) {
222
v1=sif->
prompts
[fi]-sif->
prompts
[fi-1];
if
(fabs(v1)>0.001) p=1;
223
v2=sif->
randoms
[fi]-sif->
randoms
[fi-1];
if
(fabs(v2)>0.001) r=2;
224
if
((p+r)>2)
break
;
225
}
226
return
(p+r);
227
}
228
/*****************************************************************************/
229
230
/*****************************************************************************/
libtpcimgio.h
Header file for libtpcimgio.
SIF_TEST
int SIF_TEST
Definition
sif.c:6
SIF
Definition
libtpcimgio.h:1443
SIF::x1
double * x1
Definition
libtpcimgio.h:1457
SIF::prompts
double * prompts
Definition
libtpcimgio.h:1461
SIF::frameNr
int frameNr
Definition
libtpcimgio.h:1447
SIF::x2
double * x2
Definition
libtpcimgio.h:1459
SIF::weights
double * weights
Definition
libtpcimgio.h:1467
SIF::randoms
double * randoms
Definition
libtpcimgio.h:1463
SIF::trues
double * trues
Definition
libtpcimgio.h:1465
sifModerateTrues
void sifModerateTrues(SIF *sif, double limit)
Definition
weight.c:131
sifModerateWeights
void sifModerateWeights(SIF *sif, double limit)
Definition
weight.c:167
sifWeightByFrames
void sifWeightByFrames(SIF *data, double halflife)
Calculate weights for frames in SIF data based on frame lengths. Weights are normalized to have an av...
Definition
weight.c:72
sifExistentCounts
int sifExistentCounts(SIF *sif)
Definition
weight.c:207
sifWeight
void sifWeight(SIF *data, double halflife)
Calculate weights for frames in SIF data based on true counts. Weights are normalized to have an aver...
Definition
weight.c:28
sifWeightNorm
void sifWeightNorm(SIF *d)
Definition
weight.c:105
Generated on
for TPCCLIB by
1.17.0