84 {
85
86
88
89 if (writeHandle.isValid()) {
91 "CondHandle "
92 << writeHandle.fullKey() << " is already valid.");
93 return StatusCode::SUCCESS;
94 }
95
96
97
98 const LArOnlineID_Base *larOnlineID = nullptr;
100 const LArOnline_SuperCellID *scidhelper;
102 larOnlineID = scidhelper;
103 } else {
104 const LArOnlineID *idhelper;
106 larOnlineID = idhelper;
107 }
108
109
110 const LArOnOffIdMapping *larOnOffIdMapping = nullptr;
111 SG::ReadCondHandle<LArOnOffIdMapping> larOnOffIdMappingHdl{
113 };
114 larOnOffIdMapping = *larOnOffIdMappingHdl;
115 if (larOnOffIdMapping == nullptr) {
116 ATH_MSG_ERROR(
"Failed to retrieve LArOnOffIdMapping object");
117 return StatusCode::FAILURE;
118 }
119 writeHandle.addDependency(larOnOffIdMappingHdl);
120
121
122
124
125
126
127 const ILArShape *larShape{ *ShapeHdl };
128 if (larShape == nullptr) {
130 return StatusCode::FAILURE;
131 }
132 writeHandle.addDependency(ShapeHdl);
133
135 const LArAutoCorrTotal *larAutoCorrTotal = nullptr;
136 larAutoCorrTotal= *AutoCorrTotalHdl;
137 if (larAutoCorrTotal == nullptr) {
139 return StatusCode::FAILURE;
140 }
141 writeHandle.addDependency(AutoCorrTotalHdl);
142
143
144 const ILArNoise *larNoise = nullptr;
145 const ILArPedestal *larPedestal = nullptr;
146
149 larNoise = *NoiseHdl;
150 if (larNoise == nullptr) {
152 return StatusCode::FAILURE;
153 }
154 writeHandle.addDependency(NoiseHdl);
155 } else {
157 larPedestal = *PedestalHdl;
158 if (larPedestal == nullptr) {
160 return StatusCode::FAILURE;
161 }
162 writeHandle.addDependency(PedestalHdl);
163 }
164
165 ATH_MSG_INFO(
"IOV found from intersection for LArOFCCondObj object: "
166 << writeHandle.getRange());
167
168
169
170
171 std::unique_ptr<LArOFC> larOFC =
172 std::make_unique<LArOFC>(larOnlineID, larOnOffIdMapping,
m_nGains);
173
174 std::vector<float> OFCa_tmp, OFCb_tmp;
175
176 for (
const HWIdentifier chid : larOnlineID->
channel_range()) {
177 const IdentifierHash hid = larOnlineID->
channel_Hash(chid);
178
179
182
183
184
185
186
188 unsigned int nsamples_shape = Shape.size();
190
191
192
193 int igain_autocorr = 0;
194
197
198 const std::vector<double>
AutoCorr =
200
201 unsigned int nsamples_AC_OFC = (1+((
int)(sqrt(1+8*
AutoCorr.size()))))/2;
202
203 const std::vector<double>& rmsSampl =
205 unsigned int nsamples2 = rmsSampl.size();
206 if (nsamples2 != nsamples_AC_OFC) {
208
209 }
210
211
212
213
216 firstSample=1;
217 }
218 unsigned int iBeginOfNSamples = firstSample;
219 if(nsamples_AC_OFC + iBeginOfNSamples > nsamples_shape)
220 iBeginOfNSamples=0;
221
222
224 }
225 else
226 {
227 float RMSpedestal = larPedestal->
pedestalRMS(chid,igain);
229 ;
230 else
231 {
233 <<chid<<" at gain "<<igain );
234 }
235 }
236
237
238
239 if(Shape.size()==0 || ShapeDer.size()==0 ||
AutoCorr.empty())
240 {
242 <<chid<<" at gain "<<igain );
243
244
245 }
246 if (Shape.size()!=ShapeDer.size()) {
247 ATH_MSG_ERROR(
"Got invalid shape object: Size=" << Shape.size() <<
", DerSize=" << ShapeDer.size());
248 return StatusCode::SUCCESS;
249 }
250
252
253
254
255
256
257
258 Eigen::MatrixXf
AC = Eigen::MatrixXf::Zero(nsamples_AC_OFC,nsamples_AC_OFC);
259 Eigen::MatrixXf ACinv = Eigen::MatrixXf::Zero(nsamples_AC_OFC,nsamples_AC_OFC);
260 for(l=0;
l<nsamples_AC_OFC;++
l) {
261 for(c=0;
c<nsamples_AC_OFC;++
c) {
262 if (l==c) {
264 }
265 else {
266 int i1=std::min(l,c);
267 int i2=std::max(l,c);
268 int index = i1*nsamples_AC_OFC - i1*(i1+1)/2 -(i1+1) + i2;
270 }
271 AC(l,c) =
AC(l,c)*rmsSampl[
l]*rmsSampl[
c];
272 }
273 }
275
276
277
278 float ACinv_PS[32];
279 float ACinv_PSD[32];
280
281 float Q1=0.;
282 float Q2=0.;
283 float Q3=0.;
284
285 for(l=0;
l<nsamples_AC_OFC;++
l)
286 {
287 ACinv_PS[
l]=0.; ACinv_PSD[
l]=0.;
288 for(c=0;
c<nsamples_AC_OFC;++
c){
289 ACinv_PS[
l]+=ACinv(l,c)*Shape[
c+iBeginOfNSamples];
290 ACinv_PSD[
l]+=ACinv(l,c)*ShapeDer[
c+iBeginOfNSamples];
291 }
292 Q1+=Shape[
l+iBeginOfNSamples]*ACinv_PS[
l];
293 Q2+=ShapeDer[
l+iBeginOfNSamples]*ACinv_PSD[
l];
294 Q3+=ShapeDer[
l+iBeginOfNSamples]*ACinv_PS[
l];
295 }
296 float DELTA=Q1*Q2-Q3*Q3;
297
298
299 OFCa_tmp.resize(nsamples_AC_OFC);
300 for(i=0;
i<nsamples_AC_OFC;++
i)
301 OFCa_tmp[i]=(ACinv_PS[i]*Q2-ACinv_PSD[i]*Q3)/
DELTA;
302
303 OFCb_tmp.resize(nsamples_AC_OFC);
304 for(i=0;
i<nsamples_AC_OFC;++
i)
305 OFCb_tmp[i]=(ACinv_PS[i]*Q3-ACinv_PSD[i]*Q1)/
DELTA;
306
307
309 {
310 std::cout<<larOnlineID
313 std::cout<<"Shape: ";
314 for(c=0;
c<nsamples_shape;++
c)
315 std::cout<<Shape[c]<<" ";
316 std::cout<<std::endl;
317 std::cout<<"ShapeDer: ";
318 for(c=0;
c<nsamples_shape;++
c)
319 std::cout<<ShapeDer[c]<<" ";
320 std::cout<<std::endl;
321 for(c=0;
c<nsamples_AC_OFC;++
c)
322 std::cout<<Shape[c+iBeginOfNSamples]<<" ";
323 std::cout<<" <- "<<iBeginOfNSamples<<std::endl;
324 for(i=0;
i<nsamples_AC_OFC;++
i) std::cout<<ACinv_PS[i]<<
" ";
325 std::cout<<std::endl;
326 for(i=0;
i<nsamples_AC_OFC;++
i) std::cout<<ACinv_PSD[i]<<
" ";
327 std::cout<<std::endl;
328 std::cout<<" Q1="<<Q1<<" Q2="<<Q2<<" Q3="<<Q3
329 <<
" DELTA="<<
DELTA<<std::endl;
330 std::cout << " OFCa: ";
331 for(i=0;
i<nsamples_AC_OFC;++
i)
332 std::cout<<(ACinv_PS[i]*Q2-ACinv_PSD[i]*Q3)/
DELTA<<
" ";
333 std::cout<<std::endl;
334 }
335 bool stat = larOFC->setOFC(hid, igain, std::make_pair(OFCa_tmp, OFCb_tmp));
336 if (!stat) {
337 msg(MSG::ERROR) <<
"LArOFC::setOFC fails for gain " <<
igain <<
", hash " << hid <<
endmsg;
338 }
339 }
340 } else {
342 std::vector<float>
empty;
343 bool stat = larOFC->setOFC(hid,igain, std::make_pair(
empty,
empty));
344 if (!stat) {
345 msg(MSG::ERROR) <<
"LArOFC::setOFC fails for gain " <<
igain <<
", hash " << hid <<
endmsg;
346 }
347 }
348 }
349
350 }
351
352
353 ATH_CHECK(writeHandle.record(std::move(larOFC)));
355 return StatusCode::SUCCESS;
356}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
static const double DELTA
static const Attributes_t empty
const ServiceHandle< StoreGateSvc > & detStore() const
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
virtual float pedestalRMS(const HWIdentifier &id, int gain) const =0
access to RMS of Pedestal index by Identifier, and gain setting
LArVectorProxy ShapeRef_t
This class defines the interface for accessing Shape (Nsample variable, Dt = 25 ns fixed) @stereotype...
virtual ShapeRef_t Shape(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
virtual ShapeRef_t ShapeDer(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
const std::vector< double > autoCorrTotal(const IdentifierHash &hid, int gain, float Nminbias) const
const std::vector< double > samplRMS(const IdentifierHash &hid, int gain, float Nminbias) const
Identifier cnvToIdentifier(const HWIdentifier &sid) const
create an Identifier from a HWIdentifier (inline)
bool isOnlineConnected(const HWIdentifier &sid) const
Test whether a HWIdentifier is connected of not (inline)
id_range channel_range() const
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
bool isFCALchannel(const HWIdentifier id) const
virtual bool isHECchannel(const HWIdentifier id) const =0
l
Printing final latex table to .tex output file.
retrieve(aClass, aKey=None)