38 {
39 bool hasRawRampContainer=false;
41 NTuple::Item<long> cellIndex;
42 NTuple::Item<long>
gain;
43 NTuple::Item<long> corrUndo;
44 NTuple::Array<float> SampleMax;
46 NTuple::Array<float> DAC;
47 NTuple::Array<float>
ADC;
48 NTuple::Array<long> NTriggers;
49
50
51 NTuple::Array<float> Sample0;
52 NTuple::Array<float> Sample1;
53 NTuple::Array<float> Sample2;
54 NTuple::Array<float> Sample3;
55 NTuple::Array<float> Sample4;
56 NTuple::Array<float> Sample5;
57 NTuple::Array<float> Sample6;
58
59
60 NTuple::Array<float> RMS0;
61 NTuple::Array<float> RMS1;
62 NTuple::Array<float> RMS2;
63 NTuple::Array<float> RMS3;
64 NTuple::Array<float> RMS4;
65 NTuple::Array<float> RMS5;
66 NTuple::Array<float> RMS6;
67
68 NTuple::Item<unsigned long> DACIndex;
69 NTuple::Array<float>
coeffs;
70 NTuple::Item<unsigned long> coeffIndex;
71
72 NTuple::Item<float> RampRMS;
73
75
76 for (
const std::string& key :
m_contKey) {
77 LArRawRampContainer* rawRampContainer=nullptr;
79 if (
sc!=StatusCode::SUCCESS || !rawRampContainer) {
80 ATH_MSG_WARNING(
"Unable to retrieve LArRawRampContainer with key " << key );
81 }
82 else {
84 hasRawRampContainer = true;
85 }
86 }
87 if (!hasRawRampContainer)
ATH_MSG_WARNING(
" No LArRawRampContainer found. Only fitted ramp in ntuple " );
88
89 }
90
91
92
93
94
95 const ILArRamp* ramp =
97 if (!ramp) {
98 SG::ReadCondHandle<ILArRamp> readHandle{
m_rampKey};
99 ramp = *readHandle;
100 }
101
102 LArRampComplete* rampComplete_nc=nullptr;
103
104 if (ramp==nullptr) {
106 }
107
108 if (!ramp && !hasRawRampContainer) {
109 ATH_MSG_ERROR(
"Have neither Raw Ramp nor Fitted Ramp. No Ntuple produced." );
110 return StatusCode::FAILURE;
111 }
112
113 sc=
m_nt->addItem(
"cellIndex",cellIndex,0,2000);
114 if (
sc!=StatusCode::SUCCESS) {
116 return StatusCode::FAILURE;
117 }
118
119 sc=
m_nt->addItem(
"gain",gain,0,3);
120 if (
sc!=StatusCode::SUCCESS) {
122 return StatusCode::FAILURE;
123 }
124
126 sc=
m_nt->addItem(
"corrUndo",corrUndo,0,1);
127 if (
sc!=StatusCode::SUCCESS) {
129 return StatusCode::FAILURE;
130 }
131 }
132
133 if (hasRawRampContainer)
134 {
135 sc=
m_nt->addItem(
"DACIndex",DACIndex,0,800);
136 if (
sc!=StatusCode::SUCCESS) {
138 return StatusCode::FAILURE;
139 }
140
141 sc=
m_nt->addItem(
"SampleMax",DACIndex,SampleMax);
142 if (
sc!=StatusCode::SUCCESS)
144 return StatusCode::FAILURE;
145 }
146
147 sc=
m_nt->addItem(
"TimeMax",DACIndex,TimeMax);
148 if (
sc!=StatusCode::SUCCESS)
150 return StatusCode::FAILURE;
151 }
153 if (
sc!=StatusCode::SUCCESS)
155 return StatusCode::FAILURE;
156 }
157
158 sc=
m_nt->addItem(
"DAC",DACIndex,DAC);
159 if (
sc!=StatusCode::SUCCESS)
161 return StatusCode::FAILURE;
162 }
163
164 sc=
m_nt->addItem(
"NTriggers",DACIndex,NTriggers);
165 if (
sc!=StatusCode::SUCCESS) {
167 return StatusCode::FAILURE;
168 }
169
171 sc=
m_nt->addItem(
"Sample0",DACIndex,Sample0);
172 if (
sc!=StatusCode::SUCCESS)
174 return StatusCode::FAILURE;
175 }
176 sc=
m_nt->addItem(
"Sample1",DACIndex,Sample1);
177 if (
sc!=StatusCode::SUCCESS)
179 return StatusCode::FAILURE;
180 }
181 sc=
m_nt->addItem(
"Sample2",DACIndex,Sample2);
182 if (
sc!=StatusCode::SUCCESS)
184 return StatusCode::FAILURE;
185 }
186 sc=
m_nt->addItem(
"Sample3",DACIndex,Sample3);
187 if (
sc!=StatusCode::SUCCESS)
189 return StatusCode::FAILURE;
190 }
191 sc=
m_nt->addItem(
"Sample4",DACIndex,Sample4);
192 if (
sc!=StatusCode::SUCCESS)
194 return StatusCode::FAILURE;
195 }
196 sc=
m_nt->addItem(
"Sample5",DACIndex,Sample5);
197 if (
sc!=StatusCode::SUCCESS)
199 return StatusCode::FAILURE;
200 }
201 sc=
m_nt->addItem(
"Sample6",DACIndex,Sample6);
202 if (
sc!=StatusCode::SUCCESS)
204 return StatusCode::FAILURE;
205 }
206
207 sc=
m_nt->addItem(
"RMS0",DACIndex,RMS0);
208 if (
sc!=StatusCode::SUCCESS)
210 return StatusCode::FAILURE;
211 }
212 sc=
m_nt->addItem(
"RMS1",DACIndex,RMS1);
213 if (
sc!=StatusCode::SUCCESS)
215 return StatusCode::FAILURE;
216 }
217 sc=
m_nt->addItem(
"RMS2",DACIndex,RMS2);
218 if (
sc!=StatusCode::SUCCESS)
220 return StatusCode::FAILURE;
221 }
222 sc=
m_nt->addItem(
"RMS3",DACIndex,RMS3);
223 if (
sc!=StatusCode::SUCCESS)
225 return StatusCode::FAILURE;
226 }
227 sc=
m_nt->addItem(
"RMS4",DACIndex,RMS4);
228 if (
sc!=StatusCode::SUCCESS)
230 return StatusCode::FAILURE;
231 }
232 sc=
m_nt->addItem(
"RMS5",DACIndex,RMS5);
233 if (
sc!=StatusCode::SUCCESS)
235 return StatusCode::FAILURE;
236 }
237 sc=
m_nt->addItem(
"RMS6",DACIndex,RMS6);
238 if (
sc!=StatusCode::SUCCESS)
240 return StatusCode::FAILURE;
241 }
242 }
243 }
244
245 if (ramp) {
246 sc=
m_nt->addItem(
"Xi",coeffIndex,0,7);
247 if (
sc!=StatusCode::SUCCESS)
249 return StatusCode::FAILURE;
250 }
251
252 sc=
m_nt->addItem(
"X",coeffIndex,coeffs);
253 if (
sc!=StatusCode::SUCCESS)
255 return StatusCode::FAILURE;
256 }
257
258 if (hasRawRampContainer) {
259 sc=
m_nt->addItem(
"RampRMS",RampRMS,-1000,1000);
260 if (
sc!=StatusCode::SUCCESS)
262 return StatusCode::FAILURE;
263 }
264 }
265
267 const LArRampComplete* rampComplete=dynamic_cast<const LArRampComplete*>(ramp);
268 if (!rampComplete) {
269 ATH_MSG_WARNING(
"Failed to dyn-cast to ILArRamp to LArRampComplete. Cannot apply corrections");
271 }
273 rampComplete_nc=const_cast<LArRampComplete*>(rampComplete);
275 if (
sc.isFailure()) {
276 ATH_MSG_ERROR(
"Failed to apply corrections to LArRampComplete!" );
277 }
278 else
279 ATH_MSG_INFO(
"Applied corrections to LArRampComplete" );
280 }
281 else {
283 }
284 }
285 }
286
287 const LArOnOffIdMapping *
cabling=
nullptr;
292 }else{
293 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{
m_cablingKey};
295 }
296
297
298 if(!cabling) {
300 return StatusCode::FAILURE;
301 }
302
303 unsigned cellCounter=0;
304 std::set<std::pair<HWIdentifier,unsigned> > cellDone;
305 if (hasRawRampContainer) {
306
307
308 for (
const std::string& key :
m_contKey) {
309 LArRawRampContainer* rawRampContainer=nullptr;
311 if (
sc!=StatusCode::SUCCESS || !rawRampContainer) {
312 ATH_MSG_WARNING(
"Unable to retrieve LArRawRampContainer with key " << key );
313 continue;
314 }
315 for (const LArRawRamp* rawramp : *rawRampContainer) {
316 const std::vector<LArRawRamp::RAMPPOINT_t>& singleRamp=rawramp->theRamp();
317
318 for (DACIndex=0;DACIndex<singleRamp.size();DACIndex++) {
319 SampleMax[DACIndex] = singleRamp[DACIndex].iMaxSample;
320 TimeMax[DACIndex] = singleRamp[DACIndex].TimeMax;
321 ADC[DACIndex] = singleRamp[DACIndex].ADC;
322 NTriggers[DACIndex] = singleRamp[DACIndex].NTriggers;
323 DAC[DACIndex] = singleRamp[DACIndex].DAC;
324
326
327 if ( singleRamp[DACIndex].Samples.empty() || singleRamp[DACIndex].RMS.empty() ) {
329 } else {
330
331 Sample0[DACIndex]=singleRamp[DACIndex].Samples[0];
332 Sample1[DACIndex]=singleRamp[DACIndex].Samples[1];
333 Sample2[DACIndex]=singleRamp[DACIndex].Samples[2];
334 Sample3[DACIndex]=singleRamp[DACIndex].Samples[3];
335 Sample4[DACIndex]=singleRamp[DACIndex].Samples[4];
336 if(singleRamp[DACIndex].Samples.size()>5) Sample5[DACIndex]=singleRamp[DACIndex].Samples[5];
337 if(singleRamp[DACIndex].Samples.size()>6) Sample6[DACIndex]=singleRamp[DACIndex].Samples[6];
338
339 RMS0[DACIndex]=singleRamp[DACIndex].RMS[0];
340 RMS1[DACIndex]=singleRamp[DACIndex].RMS[1];
341 RMS2[DACIndex]=singleRamp[DACIndex].RMS[2];
342 RMS3[DACIndex]=singleRamp[DACIndex].RMS[3];
343 RMS4[DACIndex]=singleRamp[DACIndex].RMS[4];
344 if(singleRamp[DACIndex].
RMS.size()>5) RMS5[DACIndex]=singleRamp[DACIndex].RMS[5];
345 if(singleRamp[DACIndex].
RMS.size()>6) RMS6[DACIndex]=singleRamp[DACIndex].RMS[6];
346 }
347 }
348
349 }
350
351 HWIdentifier chid=rawramp->channelID();
355 if (ramp &&
cabling->isOnlineConnected(chid)) {
356
357
359 cellDone.insert(std::make_pair(chid, igain));
360
361 unsigned nDAC=0;
362 unsigned nCoeff=0;
364 if (rampcoeff.size()==0) {
366 " channel=" <<
static_cast<long>(
m_channel) <<
" gain=" << igain );
367 }
368 for (coeffIndex=0;coeffIndex<rampcoeff.size();coeffIndex++) coeffs[coeffIndex]=rampcoeff[coeffIndex];
369 nDAC = singleRamp.size();
370 nCoeff = rampcoeff.size();
371
372 if (nDAC>1 && nCoeff>0) {
373
374 double rampDev=0;
375 for (unsigned iDAC=1;iDAC<nDAC;iDAC++) {
376 double fittedResult=0;
377 for (unsigned icoeff=0;icoeff<nCoeff;icoeff++)
378 fittedResult+=coeffs[icoeff]*
pow(
ADC[iDAC],icoeff);
379 rampDev+=(fittedResult-DAC[iDAC])*(fittedResult-DAC[iDAC]);
380 }
381 RampRMS=1./(nDAC-1)*sqrt(rampDev);
382 }
383 else
384 RampRMS=-999;
385
387 if (
sc!=StatusCode::SUCCESS) {
389 return StatusCode::FAILURE;
390 }
391
392 }
393
394 cellCounter++;
395
396 }
397 }
398 }
399
400
401
404 {
405 for (HWIdentifier chid :
m_onlineId->channel_range()) {
406 if (
cabling->isOnlineConnected(chid)) {
408 if ( !cellDone.empty() && cellDone.contains(std::make_pair(chid,gain)) ) continue;
410 if (not ramp) continue;
412 if (rampcoeff.size()==0) continue;
413 cellIndex = cellCounter;
415 for (coeffIndex=0;coeffIndex<rampcoeff.size();coeffIndex++) coeffs[coeffIndex]=rampcoeff[coeffIndex];
416
418
419 if (
sc!=StatusCode::SUCCESS) {
421 return StatusCode::FAILURE;
422 }
423 }
424 cellCounter++;
425 }
426 }
427
428
430
434 itUndo_e = itUndo;
435 const LArRampComplete *rampComplete=dynamic_cast<const LArRampComplete *>(ramp);
436 if(rampComplete) {
439
440 for(;itUndo!=itUndo_e;itUndo++) {
441 const HWIdentifier chid(itUndo->first);
443 corrUndo = 1;
444 const std::vector<float>& rampcoeff=itUndo->second.m_vRamp;
445 if (rampcoeff.empty())
446 continue;
447
448 cellIndex = cellCounter;
450
451 for (coeffIndex=0;coeffIndex<rampcoeff.size();coeffIndex++) coeffs[coeffIndex]=rampcoeff[coeffIndex];
452
454
455 if (
sc!=StatusCode::SUCCESS) {
457 return StatusCode::FAILURE;
458 }
459 }
460 }
461 }
462 }
463
464 if (rampComplete_nc) {
466 ATH_MSG_INFO(
"Reverted corrections of LArRampComplete container");
467 }
468
470 return StatusCode::SUCCESS;
471
472}
constexpr int pow(int base, int exp) noexcept
const ServiceHandle< StoreGateSvc > & detStore() const
virtual RampRef_t ADC2DAC(const HWIdentifier &id, int gain) const =0
LArVectorProxy RampRef_t
This class defines the interface for accessing Ramp @stereotype Interface.
StoreGateSvc * m_detStore
bool fillFromIdentifier(const HWIdentifier &id)
bool correctionsApplied() const
Have corrections been applied?
StatusCode applyCorrections()
apply correction set
StatusCode undoCorrections()
undo corrections that have been already applied
ConstCorrectionIt undoCorrBegin(unsigned int gain) const
get iterator over the Undo-Vector for a certain gain
ConstCorrectionIt undoCorrEnd(unsigned int gain) const
Subset::ConstCorrectionVecIt ConstCorrectionIt
::StatusCode StatusCode
StatusCode definition for legacy code.