ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArRawEvent
src
LArAccumulatedDigit.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
LArRawEvent/LArAccumulatedDigit.h
"
6
#include <cmath>
7
#include <iostream>
8
10
LArAccumulatedDigit::LArAccumulatedDigit
() :
11
m_gain
(
CaloGain
::UNKNOWNGAIN),
m_nTrigger
(0)
12
{}
13
14
LArAccumulatedDigit::LArAccumulatedDigit
(
HWIdentifier
& channel_value,
15
CaloGain::CaloGain
gain_value,
16
const
std::vector<uint64_t>& sampleSum_value,
17
const
std::vector< uint64_t >& sampleSquare_value,
18
uint32_t nTrigger_value) :
19
m_hardwareID
(channel_value),
m_gain
(gain_value),
m_nTrigger
(nTrigger_value) {
20
21
const
size_t
nS=sampleSum_value.size();
22
m_sampleSum
.resize(nS);
23
for
(
size_t
i=0;i<nS;++i)
24
m_sampleSum
[i]=(uint64_t)sampleSum_value[i];
25
26
27
const
size_t
nSS=sampleSquare_value.size();
28
m_sampleSquare
.resize(nSS);
29
for
(
size_t
i=0;i<nSS;++i)
30
m_sampleSquare
[i]=(uint64_t)sampleSquare_value[i];
31
}
32
34
LArAccumulatedDigit::LArAccumulatedDigit
(
HWIdentifier
& channel_value)
35
:
m_hardwareID
(channel_value),
36
m_gain
((
CaloGain
::
CaloGain
) 0),
37
m_nTrigger
(0)
38
{
39
}
40
41
float
LArAccumulatedDigit::mean
(
int
n_min,
int
n_max)
const
{
42
//float mean;
43
unsigned
imin=0;
44
const
size_t
nS=
m_sampleSum
.size();
45
if
(nS==0)
return
0.;
46
if
(n_min>0 && (
unsigned
)n_min<nS) imin=n_min;
47
unsigned
imax
=nS-1;
48
if
(n_max>0 && n_max>n_min && (
unsigned
)n_max<nS)
imax
=n_max;
49
50
const
double
n = (
imax
-imin+1)*
m_nTrigger
;
51
if
(n<=0)
return
0;
52
uint64_t
x
=0;
53
for
(
size_t
i=imin;i<=
imax
;i++) {
54
//std::cout << "Computing mean: " << x << " += " << m_sampleSum[i] << " [" << i << "] ";
55
x
+=
m_sampleSum
[i];
56
//std::cout << " = " << x << std::endl;
57
}
58
//std::cout << x << " /= " << n << std::endl;
59
//mean = x/n;
60
//std::cout << " = " << mean << std::endl;
61
return
x
/n;
62
}
63
64
float
LArAccumulatedDigit::RMS
(
int
n_min,
int
n_max)
const
65
{
66
unsigned
imin=0;
67
const
size_t
nS=
m_sampleSum
.size();
68
if
(nS==0)
return
0.;
69
if
(n_min>0 && (
unsigned
)n_min<nS) imin=n_min;
70
unsigned
imax
=nS-1;
71
if
(n_max>0 && n_max>n_min && (
unsigned
)n_max<nS)
imax
=n_max;
72
73
const
double
n = (
imax
-imin+1)*
m_nTrigger
;
74
if
(n<=0)
return
0;
75
if
(
m_sampleSquare
.empty())
return
0;
76
77
uint64_t
x
=0;
78
for
(
size_t
i=imin;i<=
imax
;i++)
79
x
+=
m_sampleSum
[i];
80
const
double
inv_n = 1. / n;
81
double
mean2 =
x
* inv_n;
82
mean2=mean2*mean2;
83
const
double
rms2=
m_sampleSquare
[0]*inv_n - mean2;
84
if
(rms2<0.0) {
//W.L 2010-12-07 protect against FPE due to rounding error
85
//std::cout << "ERROR negative squareroot:" << rms2 << std::endl;
86
return
0.0;
87
}
88
float
rms = sqrt(rms2);
89
return
rms;
90
}
91
92
bool
LArAccumulatedDigit::setAddDigit
(
const
std::vector<short>& digit) {
93
const
size_t
nS=digit.size();
94
if
(nS!=
m_sampleSum
.size() || nS!=
m_sampleSquare
.size()) {
95
if
(!
m_nTrigger
)
96
return
false
;
97
m_sampleSquare
.resize(nS,0);
98
m_sampleSum
.resize(nS,0);
99
}
// end if object empty
100
101
102
for
(
size_t
i=0;i<nS;++i) {
103
m_sampleSum
[i]+=digit[i];
104
for
(
size_t
j=i;j<nS;++j)
105
m_sampleSquare
[j]+=digit[i]*digit[j];
106
}
107
++
m_nTrigger
;
108
return
true
;
109
}
110
111
112
113
bool
LArAccumulatedDigit::setAddSubStep
(
const
CaloGain::CaloGain
gain_value,
114
const
HWIdentifier
chid,
115
const
std::vector<uint64_t>&
sampleSum
,
116
const
std::vector <uint64_t>&
sampleSquare
,
117
const
unsigned
nTrigger
)
118
{
119
size_t
i;
120
121
if
(gain_value!=
m_gain
|| chid!=
m_hardwareID
) {
122
if
(
m_nTrigger
!=0)
123
return
false
;
124
m_gain
=gain_value;
125
m_hardwareID
=chid;
126
}
127
128
129
const
size_t
n =
sampleSquare
.size();
130
if
(n!=
sampleSum
.size())
131
return
false
;
// Can not accumulate if nsamples differs
132
if
(n!=
m_sampleSum
.size() || n!=
m_sampleSquare
.size()) {
133
if
(
m_nTrigger
!=0)
134
return
false
;
// Can not accumulate if nsamples differs
135
m_sampleSquare
.resize(n,0);
136
m_sampleSum
.resize(n,0);
137
}
138
for
(i=0;i<n;++i)
139
m_sampleSum
[i] +=
sampleSum
[i];
140
141
for
(i=0;i<n;i++)
142
m_sampleSquare
[i] +=
sampleSquare
[i];
143
144
m_nTrigger
+=
nTrigger
;
145
return
true
;
146
}
147
148
149
void
LArAccumulatedDigit::setAddSubStep
(
CaloGain::CaloGain
gain_value,
const
std::vector<uint64_t>&
sampleSum
,
150
const
std::vector <uint64_t>&
sampleSquare
,
unsigned
nTrigger
)
151
{
152
std::vector<uint64_t> tmpSum;
153
std::vector<uint64_t> tmpSquare;
154
unsigned
i,n;
155
const
size_t
nS=
m_sampleSum
.size();
156
if
(gain_value!=
m_gain
) {
157
if
(
m_nTrigger
!=0)
158
return
;
159
m_gain
=gain_value;
160
}
161
n =
sampleSquare
.size();
162
if
(n!=
sampleSum
.size())
163
return
;
// Can not accumulate if nsamples differs
164
if
(n!=nS) {
165
if
(
m_nTrigger
!=0)
166
return
;
// Can not accumulate if nsamples differs
167
m_sampleSquare
.resize(n,0);
168
m_sampleSum
.resize(n,0);
169
}
170
171
tmpSum.resize(n,0);
172
for
(i=0;i<n;i++) {
173
tmpSum[i] =
sampleSum
[i];
174
m_sampleSum
[i] +=
sampleSum
[i];
175
}
176
177
tmpSquare.resize(n,0);
178
for
(i=0;i<n;i++) {
179
tmpSquare[i] =
sampleSquare
[i];
180
m_sampleSquare
[i] +=
sampleSquare
[i];
181
}
182
183
m_nTrigger
+=
nTrigger
;
184
tmpSum.clear();
185
tmpSquare.clear();
186
}
187
188
void
LArAccumulatedDigit::setAddSubStep
(
CaloGain::CaloGain
gain_value,
const
std::vector<int64_t>&
sampleSum
,
189
const
std::vector <int64_t>&
sampleSquare
,
unsigned
nTrigger
,
190
int32_t
base
)
191
{
192
int64_t tmpBase;
193
std::vector<uint64_t> tmpSum;
194
std::vector<uint64_t> tmpSquare;
195
unsigned
i,n;
196
const
size_t
nS=
m_sampleSum
.size();
197
if
(gain_value!=
m_gain
) {
198
if
(
m_nTrigger
!=0)
199
return
;
200
m_gain
=gain_value;
201
}
202
n =
sampleSquare
.size();
203
if
(n!=
sampleSum
.size())
204
return
;
// Can not accumulate if nsamples differs
205
if
(n!=nS) {
206
if
(
m_nTrigger
!=0)
207
return
;
// Can not accumulate if nsamples differs
208
m_sampleSquare
.resize(n,0);
209
m_sampleSum
.resize(n,0);
210
}
211
tmpBase =
base
;
212
tmpSum.resize(n,0);
213
for
(i=0;i<n;i++) {
214
tmpSum[i] = (uint64_t) (
sampleSum
[i]+tmpBase);
215
m_sampleSum
[i] += tmpSum[i];
216
}
217
218
tmpBase =
static_cast<
int64_t
>
(
base
)*
base
;
219
tmpSquare.resize(n,0);
220
for
(i=0;i<n;i++) {
221
tmpSquare[i] = (uint64_t) (
sampleSquare
[i]+tmpBase);
222
m_sampleSquare
[i] += tmpSquare[i];
223
}
224
225
m_nTrigger
+=
nTrigger
;
226
227
tmpSum.clear();
228
tmpSquare.clear();
229
}
230
231
232
void
LArAccumulatedDigit::getCov
(std::vector<float>& cov,
int
normalize
)
const
233
{
234
cov.clear();
235
const
double
n =
m_nTrigger
;
236
const
size_t
nS=
m_sampleSum
.size();
237
if
(n<=0)
return
;
238
if
(
m_sampleSquare
.size()!=nS)
return
;
239
240
std::vector<double> mean2;
241
mean2.resize(nS);
242
for
(
size_t
i=1;i<nS;i++) {
243
for
(
size_t
j=i;j<nS;j++) {
244
mean2[i] +=
m_sampleSum
[j-i]*
m_sampleSum
[j];
245
}
246
mean2[i]/=n*n*(nS-i);
247
}
248
uint64_t temp_mean = 0;
249
double
mean
;
250
for
(uint32_t i=0;i<nS;i++)
251
temp_mean +=
m_sampleSum
[i];
252
mean
= temp_mean/((double) n*nS);
253
254
if
(
normalize
!=1) {
// No mormalization send as is
255
for
(
size_t
i=1;i<nS;i++)
256
cov.push_back(
m_sampleSquare
[i]/(n*(nS-i)) - mean2[i] );
257
mean2.clear();
258
return
;
259
}
260
261
//Normalize covariance elements if required
262
const
double
norm =
m_sampleSquare
[0]/(n*nS)-
mean
*
mean
;
263
//norm = sqrt(norm*norm);
264
if
(norm==0.0)
265
cov.assign(nS-1,0.0);
266
else
{
267
const
double
inv_norm = 1. / norm;
268
for
(uint32_t i=1;i<nS;i++) {
269
cov.push_back((
m_sampleSquare
[i]/(n*(nS-i)) - mean2[i])*inv_norm);
270
}
271
}
272
273
mean2.clear();
274
}
275
LArAccumulatedDigit.h
normalize
Double_t normalize(TF1 *func, Double_t *rampl=NULL, Double_t from=0., Double_t to=0., Double_t step=1.)
Definition
LArPhysWaveHECTool.cxx:825
imax
int imax(int i, int j)
Definition
TileLaserTimingTool.cxx:33
x
#define x
HWIdentifier
Definition
HWIdentifier.h:13
LArAccumulatedDigit::m_gain
CaloGain::CaloGain m_gain
gain
Definition
LArAccumulatedDigit.h:40
LArAccumulatedDigit::sampleSum
const std::vector< uint64_t > & sampleSum() const
return the sample-sums
Definition
LArAccumulatedDigit.h:82
LArAccumulatedDigit::sampleSquare
const std::vector< uint64_t > & sampleSquare() const
return a reference to a stl vector containing the sum of the squares of the sample
Definition
LArAccumulatedDigit.h:85
LArAccumulatedDigit::RMS
float RMS(int n_min=-1, int n_max=-1) const
Calculates and returns the RMS value of ADC samples.
Definition
LArAccumulatedDigit.cxx:64
LArAccumulatedDigit::m_sampleSquare
std::vector< uint64_t > m_sampleSquare
vector(index: j from s_i*s_{i+j})
Definition
LArAccumulatedDigit.h:46
LArAccumulatedDigit::m_hardwareID
HWIdentifier m_hardwareID
Online Identifier.
Definition
LArAccumulatedDigit.h:37
LArAccumulatedDigit::mean
float mean(int n_min=-1, int n_max=-1) const
Calculates and returns the Mean value of ADC samples.
Definition
LArAccumulatedDigit.cxx:41
LArAccumulatedDigit::LArAccumulatedDigit
LArAccumulatedDigit()
default constructor for persistency
Definition
LArAccumulatedDigit.cxx:10
LArAccumulatedDigit::setAddDigit
bool setAddDigit(const std::vector< short > &digit)
Accumulate single digit.
Definition
LArAccumulatedDigit.cxx:92
LArAccumulatedDigit::m_nTrigger
uint32_t m_nTrigger
number of total triggers
Definition
LArAccumulatedDigit.h:49
LArAccumulatedDigit::nTrigger
unsigned nTrigger() const
return the number of triggers
Definition
LArAccumulatedDigit.h:88
LArAccumulatedDigit::m_sampleSum
std::vector< uint64_t > m_sampleSum
sampleSum over ntrigger*nsamples
Definition
LArAccumulatedDigit.h:43
LArAccumulatedDigit::getCov
void getCov(std::vector< float > &cov, int normalize) const
Compute the autocorrelation elements.
Definition
LArAccumulatedDigit.cxx:232
LArAccumulatedDigit::setAddSubStep
bool setAddSubStep(const CaloGain::CaloGain gain_value, const HWIdentifier chid, const std::vector< uint64_t > &sampleSum, const std::vector< uint64_t > &sampleSquare, const unsigned nTrigger)
Accumulate new values.
Definition
LArAccumulatedDigit.cxx:113
base
std::string base
Definition
hcg.cxx:83
CaloGain
Definition
CaloGain.h:10
CaloGain::CaloGain
CaloGain
Definition
CaloGain.h:11
Generated on
for ATLAS Offline Software by
1.17.0