74{
75
77
81
82 const LArCalibLineMapping *clcabling = nullptr;
84 clcabling =*clHdl;
85 if(!clcabling) {
87 return StatusCode::FAILURE;
88 }
89
90 const LArCalibLineMapping *clcablingSC = nullptr;
93 clcablingSC =*clHdl;
94 if(!clcablingSC) {
96 return StatusCode::FAILURE;
97 }
98 }
99
100
101 const LArOnOffIdMapping*
cabling(
nullptr);
102 const LArOnOffIdMapping* cablingLeg(nullptr);
106 if(!cabling) {
108 return StatusCode::FAILURE;
109 }
110
111 SG::ReadCondHandle<LArOnOffIdMapping> cablingHdlLeg{
m_cablingKey};
112 cablingLeg = {*cablingHdlLeg};
113 if(!cablingLeg) {
115 return StatusCode::FAILURE;
116 }
117 }
118
119
120
121
122
123
124 const LArCalibDigitContainer* calibDigitContainer=nullptr;
125
126
130
131 const LArCalibParams* calibParams;
132 sc=
detStore()->retrieve(calibParams,
"LArCalibParams");
134 {
ATH_MSG_ERROR(
"Cannot load LArCalibParams from DetStore." );
135 return StatusCode::FAILURE;
136 }
137
139
140
141
142
143 for (
const std::string& key :
m_keylist) {
144
145 sc=
evtStore()->retrieve(calibDigitContainer,key);
147 ATH_MSG_ERROR(
"Can't retrieve LArCalibDigitContainer with key " << key <<
"from StoreGate." );
148 return StatusCode::SUCCESS;
149 }else{
150 ATH_MSG_DEBUG(
"Retrieved LArCalibDigitContainer with key " << key <<
" from StoreGate." );
151 }
152
153 if(calibDigitContainer->
empty()) {
154 ATH_MSG_DEBUG(
"LArCalibDigitContainer with key=" << key <<
" is empty " );
155 }else{
156 ATH_MSG_DEBUG(
"LArCalibDigitContainer with key=" << key <<
" has size = " << calibDigitContainer->
size() );
157 }
158
159
160 std::vector<unsigned int> ntrigger, nTriggerPerStep, nStepTrigger, iStepTrigger;
161
162 ntrigger.resize(calibDigitContainer->
size(),0);
163
167
168
169 LArAccumulatedCalibDigitContainer* larAccuCalibDigitContainer = new LArAccumulatedCalibDigitContainer();
170
171 for (const LArCalibDigit* digit : *calibDigitContainer) {
173
174
175 HWIdentifier chid=
digit->hardwareID();
179
180
181
183
184 std::vector<Identifier> ccellIds(0);
185 unsigned numPulsedLeg = 0;
186 unsigned numCL = 0;
188
190 bool hasInvalid=false;
191 for(
auto s :
digit->samples()){
192 if(s<0){
193 hasInvalid=true;
194 break;
195 }
196 }
197 if(hasInvalid) continue;
198
199 Identifier myofflineID =
cabling->cnvToIdentifier(
digit->hardwareID()) ;
201 for (Identifier id : ccellIds) {
202 HWIdentifier cellLegHWID = cablingLeg->createSignalChannelID(id);
203 const std::vector<HWIdentifier>& calibLineLeg = clcabling->
calibSlotLine(cellLegHWID);
204 numCL += calibLineLeg.size();
205 for (HWIdentifier calibLineHWID : calibLineLeg) {
206 if ( calibParams->
isPulsed(eventNb,calibLineHWID) ){
207 numPulsedLeg += 1;
208 ATH_MSG_DEBUG(
"SC "<< chid <<
" constituent cell "<< cellLegHWID <<
" calib line "<< calibLineHWID<<
" not pulsed");
209 }else{
210 if (
digit->isPulsed() )
ATH_MSG_WARNING(
"SC "<< chid <<
" constituent cell "<< cellLegHWID <<
" calib line "<< calibLineHWID<<
" not pulsed");}
211 }
212 }
213 if (
digit->isPulsed() && numPulsedLeg != numCL ){
214 ATH_MSG_WARNING(
"Number of pulsed legacy cells does not equal number of calibration lines "<<chid<<
"!! LArParams counter = " << numPulsedLeg <<
", SC2CCMappingTool = " << ccellIds.size() <<
", num CLs = "<< numCL);
215
217 ATH_MSG_WARNING(
"Discarding this SC ("<<chid<<
") as it is not fully pulsed");
218 continue;
219 }
220 }
221 ATH_MSG_DEBUG(
"SC "<<chid<<
" pulsed cells "<< numPulsedLeg <<
" or "<< ccellIds.size()<<
", "<<numCL<<
" calibration lines");
222 }
223
225
226
227
229 HWIdentifier calibModuleID;
230 if(!calibLineID.empty()){
232 nTriggerPerStep[febhash] = calibParams->
NTrigger(calibModuleID);
233 ATH_MSG_DEBUG(
"Ntrigger per step = " << nTriggerPerStep[febhash] );
234 if(nTriggerPerStep[febhash] > 1000) nTriggerPerStep[febhash]=100;
235 }else{
236
237 nTriggerPerStep[febhash] = 100;
238 }
239
240
241 bool isPulsed =
digit->isPulsed();
242
243
246 }
247 else{
248
250 ATH_MSG_DEBUG(
"Delay is changing to " <<
digit->delay() <<
" from " <<
m_delay <<
": book a new LArAccumulatedCalibDigitContainer" );
252 }
253 }
254
256
257 std::map<std::string, std::vector<LArAccumulated> >::iterator accIter=
m_Accumulated_map.find(patternName);
260 }
261
264 {
ATH_MSG_ERROR(
"Found not-matching gain number ("<< (
int)gain <<
")" );
265 delete larAccuCalibDigitContainer;
266 return StatusCode::FAILURE;
267 }
268
269
272
273
274 cellAccumulated.m_ntrigger++;
275 ATH_MSG_DEBUG(
"chid = " << chid <<
", trigger = " << cellAccumulated.m_ntrigger <<
", DAC = " <<
digit->DAC()<<
", Delay = "<<
digit->delay()<<
", isPulsed? "<<
digit->isPulsed() );
276
277
278 unsigned int sizeSamples =
digit->samples().size();
279 ATH_MSG_DEBUG(
"sizeSteps = " << sizeSteps <<
", # of samples = " << sizeSamples );
280
281 if(cellAccumulated.m_ntrigger==1){
282 cellAccumulated.m_sum.clear();
283 cellAccumulated.m_sum2.clear();
284 cellAccumulated.m_sum.resize(sizeSamples,0);
285 cellAccumulated.m_sum2.resize(sizeSamples,0);
286 }
287
289 for(unsigned int j=0;j<sizeSamples;j++){
290 int digis;
292 digis=
digit->samples()[sizeSamples-1];
293 cellAccumulated.m_sum[j] += digis;
294 cellAccumulated.m_sum2[j] += digis*digis;
295 }
297 digis=
digit->samples()[0];
298 cellAccumulated.m_sum[j] += digis;
299 cellAccumulated.m_sum2[j] += digis*digis;
300 } else{
302 cellAccumulated.m_sum[j] += digis;
303 cellAccumulated.m_sum2[j] += digis*digis;
304 }
305 }
306
307
308 unsigned int ntrigUsed = nTriggerPerStep[febhash];
311 }
312
313 if(cellAccumulated.m_ntrigger==ntrigUsed){
315 ATH_MSG_DEBUG(
"chid = " << chid <<
", gain = " << gain <<
", DAC = " <<
digit->DAC() <<
", isPulsed = " << isPulsed <<
", delay = " <<
m_delay <<
", trigPerStep = " << nTriggerPerStep[febhash] <<
", istep = " << iStepTrigger[febhash] );
316
317
318 LArAccumulatedCalibDigit* accuCalibDigit;
320 ATH_MSG_DEBUG(
"Channel "<<chid<<
" DAC "<<
digit->DAC()<<
" will multiply by "<<numPulsedLeg<<
" = "<<
digit->DAC()*numPulsedLeg<<
" is pulsed??? "<<isPulsed);
321 accuCalibDigit =
new LArAccumulatedCalibDigit(chid,gain,sizeSamples,(int32_t)(
digit->DAC()*numPulsedLeg),(uint16_t)
m_delay,isPulsed,0,0);
322 }else{
323 accuCalibDigit =
new LArAccumulatedCalibDigit(chid,gain,sizeSamples,(uint16_t)
digit->DAC(),(uint16_t)
m_delay,isPulsed,0,0);
324 }
325
326
327 accuCalibDigit->
setAddSubStep(cellAccumulated.m_sum,cellAccumulated.m_sum2,ntrigUsed);
328 iStepTrigger[febhash]++;
329
330 std::vector<float>
mean = accuCalibDigit->
mean();
331 std::vector<float>
RMS = accuCalibDigit->
RMS();
332
333 for(
unsigned int i=0;
i<
mean.size();
i++){
336 }
337
338 larAccuCalibDigitContainer->
push_back(accuCalibDigit);
339
340 cellAccumulated.m_nused = cellAccumulated.m_ntrigger;
341 cellAccumulated.m_ntrigger = 0;
342 }
343
344 }
345
346
348 sc =
evtStore()->record(larAccuCalibDigitContainer,key);
349 if (
sc!=StatusCode::SUCCESS)
350 {
ATH_MSG_WARNING(
"Unable to record LArAccumulatedCalibDigitContainer with key " << key <<
" from DetectorStore. " );
351 }
352 else
353 ATH_MSG_DEBUG(
"Recorded succesfully LArAccumulatedCalibDigitContainer with key " << key <<
" with size " << larAccuCalibDigitContainer->
size());
354
355 sc =
evtStore()->setConst(larAccuCalibDigitContainer);
356 if (
sc.isFailure()) {
357 ATH_MSG_ERROR(
" Cannot lock LArAccumulatedCalibDigitContainer " );
358 return(StatusCode::FAILURE);
359 }
360
361
362 }
363 return StatusCode::SUCCESS;
364}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
void setDelayScale(const double scale)
set the delay Scale
bool setAddSubStep(const std::vector< uint64_t > &sampleSum, const std::vector< uint64_t > &sample2Sum, const uint32_t nTriggerPerStep)
Sum up with another substep.
std::vector< float > RMS() const
Calculates and returns the RMS value of each ADC sample.
std::vector< float > mean() const
Calculates and returns the Mean value of each ADC sample.
Class of intermediate accumulations.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeySC
static std::string getPatternName(const std::string &gain, bool isPulsed, int delay, int dac)
SG::ReadCondHandleKey< LArCalibLineMapping > m_calibMapSCKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
std::map< std::string, std::vector< LArAccumulated > > m_Accumulated_map
Vector (index=hash ID) of accumulation quantities.
SG::ReadCondHandleKey< LArCalibLineMapping > m_calibMapKey
const std::vector< HWIdentifier > & calibSlotLine(const HWIdentifier id) const
bool isPulsed(const unsigned event, const HWIdentifier calibLineID) const
unsigned NTrigger(const HWIdentifier calibModuleID) const
uint64_t eventNumber() const
The current event's event number.
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
::StatusCode StatusCode
StatusCode definition for legacy code.
retrieve(aClass, aKey=None)
EventInfo_v1 EventInfo
Definition of the latest event info version.