ATLAS Offline Software
Loading...
Searching...
No Matches
LArCaliWaveBuilderXtalk.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "CLHEP/Units/SystemOfUnits.h"
7
8#include "GaudiKernel/ToolHandle.h"
9
11
13
14#include "TString.h"
15
16#include <fstream>
17#include <algorithm>
18
19
20using CLHEP::megahertz;
21using CLHEP::ns;
22
23
24//=========================================================================================================
25LArCaliWaveBuilderXtalk::LArCaliWaveBuilderXtalk(const std::string& name, ISvcLocator* pSvcLocator)
26 : AthAlgorithm(name, pSvcLocator),
27 m_groupingType("ExtendedFeedThrough"), // SubDetector, Single, FeedThrough
28 m_onlineHelper(nullptr),
29 m_posOrNeg(0),
33 m_dt(0)
34//=========================================================================================================
35{
37 declareProperty("KeyOutput", m_keyoutput="LArCaliWave");
38 declareProperty("SamplingPeriod", m_SamplingPeriod=1./(40.08*megahertz));
39 declareProperty("NSteps", m_NStep=24); //Number of DelaySteps. FIXME: Try to get this information for somewhere else
40 declareProperty("ADCsaturation", m_ADCsatur=0);
41 declareProperty("GroupingType", m_groupingType);
42
43 // Description of the required pulsed channel to have the caliwaves reconstructed
44 // PartitionPulsed = "BarrelA", "EndcapA", "BarrelC", "EndcapC"
45 declareProperty("PartitionPulsed", m_partition);
46
47 // For EMEC special crates
48 declareProperty("SpecialCrate", m_isSpecialCrate=false);
49 declareProperty("SpecialRegion", m_emecSpecialRegion="OuterWheel"); // OuterWheel / InnerWheel
50
51 // FeedthroughPul = [1-32] (Barrel) [1-24] (Endcap)
52 // used to detect the right calibration pattern
53 // please ensure that this FT has no bad channels / disconnected FEB
54 declareProperty("FeedthroughPul", m_feedthroughNumber=1);
55
56 // CalibPattern = "StripSinglexx", "MiddleSinglexx", "BackSinglexx",
57 // EMB : xx = [1-4] (Strip) xx = [1-8] (Middle) xx = [1-4] (Back)
58 // EMEC : xx = [1-4] (Strip) xx = [1-4] (Middle) xx = [1-4] (Back)
59 // and xx = [1-4] (Middle) xx = [1-4] (Back) for inner wheel
60 declareProperty("CalibPattern", m_calibPattern="StripSingle1");
61
62 // Allow to cut waves
63 // consider only the N=CutOnSample first samples to reduce needed memory (0 = no cut)
64 declareProperty("CutOnSample", m_cutOnSample=0);
65}
66
67//=========================================================================================================
69//=========================================================================================================
70= default;
71
72//=========================================================================================================
74//=========================================================================================================
75{
76
77 MsgStream log(msgSvc(), name());
78 log << MSG::INFO << "Initialize LArCaliWaveBuilderXtalk" << endmsg;
79
80 // Set barrel_ec and pos_neg from PartitionPulsed
82 if (m_partition == "BarrelC") {m_barrelEndcap = 0; m_posOrNeg = 0;}
83 else if (m_partition == "BarrelA") {m_barrelEndcap = 0; m_posOrNeg = 1;}
84 else if (m_partition == "EndcapC") {m_barrelEndcap = 1; m_posOrNeg = 0;}
85 else if (m_partition == "EndcapA") {m_barrelEndcap = 1; m_posOrNeg = 1;}
86 else {
87 ATH_MSG_ERROR ( "Can't find partition " << m_partition << " ! Use BarrelC instead." );
88 }
89 ATH_MSG_INFO ( "Partition : " << m_partition << " (barrel_ec=" << m_barrelEndcap << " ; pos_neg=" << m_posOrNeg << ")" );
90
91 // Test m_isSpecialCrate, set m_isInnerWheel, and check FT number for EMEC
92 if (m_barrelEndcap==1) {
93
94 // EMEC special crates
96
97 TString emecSpecialRegion_test = TString(m_emecSpecialRegion.c_str());
98 emecSpecialRegion_test.ToLower();
99 if (emecSpecialRegion_test.Contains("inner"))
100 m_isInnerWheel = true;
101 else {
102 m_isInnerWheel = false;
103 if (! emecSpecialRegion_test.Contains("outer"))
104 ATH_MSG_WARNING ( "Can't read EMEC special region (Inner/Outer Wheel) - set SpecialRegion to OuterWheel." );
105 }
106
107 if (!m_isInnerWheel){ // EMEC outer wheel special crates
109 ATH_MSG_WARNING ( "FeedthroughPul=" << m_feedthroughNumber << ". For EMEC outer wheel special crates studies one should use FT = 2, 9, 15 or 21." );
110 ATH_MSG_WARNING ( "Set FeedthroughPul to 2.");
112 }
113 ATH_MSG_INFO ( "Look at EM end-cap outer wheel special crates. Check calibration patterns with FT number " << m_feedthroughNumber );
114 }
115 else { // EMEC inner wheel (special crates)
117 ATH_MSG_WARNING ( "FeedthroughPul=" << m_feedthroughNumber << ". For EMEC inner wheel studies one should use FT = 3, 10, 16 or 22." );
118 ATH_MSG_WARNING ( "Set FeedthroughPul to 3.");
120 }
121 ATH_MSG_INFO ( "Look at EM end-cap inner wheel (special crates). Check calibration patterns with FT number " << m_feedthroughNumber );
122 }
123
124 }
125
126 // EMEC standard crates
127 else {
131 || m_feedthroughNumber>24) {
132 ATH_MSG_WARNING ( "FeedthroughPul=" << m_feedthroughNumber << " : not in EMEC standard crates." );
133 ATH_MSG_WARNING ( "Set FeedthroughPul to 1.");
135 }
136 ATH_MSG_INFO ( "Look at EM end-cap standard crates. Check calibration patterns with FT number " << m_feedthroughNumber );
137 }
138 } else {
139 // EM Barrel
140 ATH_MSG_INFO ( "Look at EM barrel. Check calibration patterns with FT number " << m_feedthroughNumber );
141 }
142
143
144 if (m_keylistproperty.empty()) // Not key list given
145 {
146 m_keylistproperty.emplace_back("HIGH");
147 m_keylistproperty.emplace_back("MEDIUM");
148 m_keylistproperty.emplace_back("LOW");
149 }
151
152 //FIXME probably useless because m_wave isn't written anywhere
153 ATH_CHECK( m_waves.setGroupingType(m_groupingType,msg()) );
154 ATH_CHECK( m_waves.initialize() );
155
157
158 //m_dt=25*ns/m_NStep;
160
161 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
162 ATH_CHECK( m_cablingKey.initialize() );
163 ATH_CHECK( m_CLKey.initialize() );
164
165 return StatusCode::SUCCESS;
166}
167
168//=========================================================================================================
170//=========================================================================================================
171{
172 // bug in LArTools, on-off map doesn't work at initialization stage
173
174 ATH_MSG_INFO ( "Consider only partition " << m_partition );
175
176 // Temporary solution to create onoff map as long as it is not done in calibSlotLine()
177 // WAITING FOR A FIX in LArTools
178 Identifier cellId = cabling->cnvToIdentifier(m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,1,4));
179 ATH_MSG_INFO ( "Dummy ids - TEMPORARY " << m_onlineHelper->show_to_string(cellId) );
180
181
182 // Fill the m_CalibLineHW vector,containing all the calib line HW id
183 // that are required to be pulsed
184 // The m_calibPattern string is given in the job option
185
186
187 //--------------------------------------------------
188 // EM BARREL
189
190 if (m_partition == "BarrelA" || m_partition == "BarrelC") {
191
192 // StripSingle pattern
193 if( m_calibPattern.find("StripSingle",0) != std::string::npos ){
194 HWIdentifier theConsidChannel;
195 int pulsedSlot = 2;
196 if (m_calibPattern.find('1',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,1);
197 if (m_calibPattern.find('2',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,2);
198 if (m_calibPattern.find('3',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,3);
199 if (m_calibPattern.find('4',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,4);
200
201 const std::vector<HWIdentifier>& calibLine = clCont->calibSlotLine(theConsidChannel);
202
203 ATH_MSG_INFO ( "Considered Online Channel " << m_onlineHelper->show_to_string(theConsidChannel) );
204 ATH_MSG_DEBUG ( "Number of associated calib line " << calibLine.size() );
205 if (!calibLine.empty()) {
206 m_CalibLineHW.push_back(calibLine[0]);
207 ATH_MSG_INFO ( "Calib line" << m_onlineHelper->show_to_string(calibLine[0]) );
208 }
209 }
210
211 // MiddleSingle pattern
212 if( m_calibPattern.find("MiddleSingle",0) != std::string::npos ){
213 HWIdentifier theConsidChannel;
214 int pulsedSlot = 11;
215 if (m_calibPattern.find('1',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,3);
216 if (m_calibPattern.find('2',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,2);
217 if (m_calibPattern.find('3',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,7);
218 if (m_calibPattern.find('4',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,6);
219 if (m_calibPattern.find('5',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,67);
220 if (m_calibPattern.find('6',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,66);
221 if (m_calibPattern.find('7',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,71);
222 if (m_calibPattern.find('8',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,70);
223
224 const std::vector<HWIdentifier>& calibLine = clCont->calibSlotLine(theConsidChannel);
225 ATH_MSG_INFO ( "Considered Channel " << m_onlineHelper->show_to_string(theConsidChannel) );
226 if (!calibLine.empty()) {
227 m_CalibLineHW.push_back(calibLine[0]);
228 ATH_MSG_INFO ( "Calib Line " << m_onlineHelper->show_to_string(calibLine[0]) );
229 }
230 }
231
232 // BackSingle pattern
233 if ( m_calibPattern.find("BackSingle",0) != std::string::npos){
234 HWIdentifier theConsidChannel;
235 int pulsedSlot = 9;
236 if (m_calibPattern.find('1',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,3);
237 if (m_calibPattern.find('2',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,2);
238 if (m_calibPattern.find('3',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,7);
239 if (m_calibPattern.find('4',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,6);
240
241 const std::vector<HWIdentifier>& calibLine = clCont->calibSlotLine(theConsidChannel);
242 ATH_MSG_INFO ( "Considered Channel " << m_onlineHelper->show_to_string(theConsidChannel) );
243 if (!calibLine.empty()) {
244 m_CalibLineHW.push_back(calibLine[0]);
245 ATH_MSG_INFO ( "Calib Line " << m_onlineHelper->show_to_string(calibLine[0]) );
246 }
247 }
248
249 } // End of barrel treatment
250
251
252 //--------------------------------------------------
253 // EM ENDCAP
254
255
256 else{
257
258 // StripSingle pattern
259 if (m_isInnerWheel && m_isSpecialCrate && m_calibPattern.find("StripSingle",0) != std::string::npos )
260 ATH_MSG_WARNING ( "There is no StripSingle pattern for EMEC inner wheel. You should try another pattern (MiddleSingle[1-4] or BackSingle[1-4])." );
261 else if( m_calibPattern.find("StripSingle",0) != std::string::npos ){
262 HWIdentifier theConsidChannel;
263
264 int pulsedSlot = 2; // EMEC outer wheel standard crates
265 if (m_isSpecialCrate) pulsedSlot = 5; // EMEC outer wheel special crates
266
267 if (m_calibPattern.find('1',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,1);
268 if (m_calibPattern.find('2',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,2);
269 if (m_calibPattern.find('3',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,3);
270 if (m_calibPattern.find('4',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,4);
271
272 const std::vector<HWIdentifier>& calibLine = clCont->calibSlotLine(theConsidChannel);
273
274 ATH_MSG_INFO ( "Considered Online Channel " << m_onlineHelper->show_to_string(theConsidChannel) );
275 ATH_MSG_DEBUG ( "Number of associated calib line " << calibLine.size() );
276 if (!calibLine.empty()) {
277 m_CalibLineHW.push_back(calibLine[0]);
278 ATH_MSG_INFO ( "Calib line" << m_onlineHelper->show_to_string(calibLine[0]) );
279 }
280 }
281
282 // MiddleSingle pattern
283 if( m_calibPattern.find("MiddleSingle",0) != std::string::npos ){
284 HWIdentifier theConsidChannel;
285
286 int pulsedSlot = 10; // EMEC outer wheel (standard and special crates)
287 int pulsedCell1 = 1;
288 int pulsedCell2 = 2;
289 int pulsedCell3 = 7;
290 int pulsedCell4 = 6;
291 if (m_isInnerWheel && m_isSpecialCrate){ // EMEC inner wheel
292 pulsedSlot = 1;
293 pulsedCell1 = 1;
294 pulsedCell2 = 0;
295 pulsedCell3 = 2;
296 pulsedCell4 = 3;
297 }
298
299 if (m_calibPattern.find('1',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,pulsedCell1);
300 if (m_calibPattern.find('2',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,pulsedCell2);
301 if (m_calibPattern.find('3',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,pulsedCell3);
302 if (m_calibPattern.find('4',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,pulsedCell4);
303
304 const std::vector<HWIdentifier>& calibLine = clCont->calibSlotLine(theConsidChannel);
305
306 ATH_MSG_INFO ( "Considered Channel " << m_onlineHelper->show_to_string(theConsidChannel) );
307 ATH_MSG_DEBUG ( "Number of associated calib line " << calibLine.size() );
308 if (!calibLine.empty()) {
309 m_CalibLineHW.push_back(calibLine[0]);
310 ATH_MSG_INFO ( "Calib Line " << m_onlineHelper->show_to_string(calibLine[0]) );
311 }
312 }// End of MiddleSingle pattern
313
314 // BackSingle pattern
315 if ( m_calibPattern.find("BackSingle",0) != std::string::npos){
316 HWIdentifier theConsidChannel;
317
318 int pulsedSlot = 8; // EMEC standard crates
319 int pulsedCell1 = 1;
320 int pulsedCell2 = 2;
321 int pulsedCell3 = 33;
322 int pulsedCell4 = 34;
323 if (m_isInnerWheel && m_isSpecialCrate){ // EMEC inner wheel
324 pulsedSlot = 2;
325 pulsedCell1 = 1;
326 pulsedCell2 = 0;
327 pulsedCell3 = 2;
328 pulsedCell4 = 3;
329 }
330 else if (m_isSpecialCrate) { // EMEC outer wheel special crates
331 pulsedSlot = 9;
332 pulsedCell1 = 2;
333 pulsedCell2 = 1;
334 pulsedCell3 = 17;
335 pulsedCell4 = 18;
336 }
337
338 if (m_calibPattern.find('1',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,pulsedCell1);
339 if (m_calibPattern.find('2',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,pulsedCell2);
340 if (m_calibPattern.find('3',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,pulsedCell3);
341 if (m_calibPattern.find('4',0) != std::string::npos )theConsidChannel = m_onlineHelper->channel_Id(m_barrelEndcap,m_posOrNeg,m_feedthroughNumber,pulsedSlot,pulsedCell4);
342
343 const std::vector<HWIdentifier>& calibLine = clCont->calibSlotLine(theConsidChannel);
344 ATH_MSG_INFO ( "Considered Channel " << m_onlineHelper->show_to_string(theConsidChannel) );
345 if (!calibLine.empty()) {
346 m_CalibLineHW.push_back(calibLine[0]);
347 ATH_MSG_INFO ( "Calib Line " << m_onlineHelper->show_to_string(calibLine[0]) );
348 }
349 }// End of BackSingle pattern
350
351 };// End of endcap treatment
352
353 return StatusCode::SUCCESS;
354}
355
356//=========================================================================================================
358//=========================================================================================================
359{
361 const LArOnOffIdMapping* cabling{*cablingHdl};
362 if(!cabling) {
363 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
364 return StatusCode::FAILURE;
365 }
366
368 const LArCalibLineMapping *clCont {*clHdl};
369 if(!clCont) {
370 ATH_MSG_ERROR("Do not have calibration mapping object " << m_CLKey.key());
371 return StatusCode::FAILURE;
372 }
373
374 if (m_event_counter==0) {
375 ATH_CHECK ( initializeCabling(cabling, clCont) );
376 }
377
378 // Print progression
379 if ( m_event_counter < 100 || ( m_event_counter < 1000 && m_event_counter%100==0 ) || m_event_counter%1000==0 )
380 ATH_MSG_INFO ( "Processing event " << m_event_counter );
382
383 if (m_keylist.empty()) {
384 ATH_MSG_ERROR ( "Key list is empty! No containers to process!" );
385 return StatusCode::FAILURE;
386 }
387
388 const LArAccumulatedCalibDigitContainer* larAccumulatedCalibDigitContainer = nullptr;
389
390 std::vector<std::string>::const_iterator key_it=m_keylist.begin();
391 std::vector<std::string>::const_iterator key_it_e=m_keylist.end();
392
393 for (;key_it!=key_it_e; ++key_it) { //Loop over all containers that are to be processed (e.g. different gains)
394
395 StatusCode sc = evtStore()->retrieve(larAccumulatedCalibDigitContainer,*key_it);
396 if (sc.isFailure()) {
397 ATH_MSG_WARNING ( "Cannot read LArAccumulatedCalibDigitContainer from StoreGate! key=" << *key_it );
398 continue; // Try next container
399 }
400
401 LArAccumulatedCalibDigitContainer::const_iterator it=larAccumulatedCalibDigitContainer->begin();
402 LArAccumulatedCalibDigitContainer::const_iterator it_end=larAccumulatedCalibDigitContainer->end();
403
404 if (it == it_end) {
405 ATH_MSG_DEBUG ( "LArAccumulatedCalibDigitContainer with key=" << *key_it << " is empty " );
406 continue; // at this event LArAccumulatedCalibDigitContainer is empty, do not even try to loop on it...
407 }
408
409 const float delayScale = larAccumulatedCalibDigitContainer->getDelayScale();
410 const float deltaDelay = 25*ns/(delayScale*m_NStep);
411
412 // Check whether this "event" (LArAccumulatedDigit) is relevant for our studies
413 bool relevantForXtalk = false;
414
415 // for print purpose
416 std::vector<int> nbOfEventSlot; // Number of 'events' per slot
417 nbOfEventSlot.resize(15);
418
419 std::vector<int> nbOfEventPart; // Number of 'events' per Subdetector/layer
420 nbOfEventPart.resize(8);
421 int sideA=0; // Number of 'events' in A side
422 int sideC=0; // Number of 'events' in C side
423
424
425 // Loop over all cells as long as no interesting pulsed cell is found
426 do{
427
428 const std::vector<HWIdentifier>& calibLine = clCont->calibSlotLine((*it)->hardwareID());
429 if (!calibLine.empty()) {
430 std::vector<HWIdentifier>::iterator found=find(m_CalibLineHW.begin(),m_CalibLineHW.end(),calibLine[0]);
431
432 if (((*it)->isPulsed()) && (found != m_CalibLineHW.end()))
433 relevantForXtalk = true;
434
435// if (m_onlineHelper->slot((*it)->hardwareID()) == 2 && m_onlineHelper->channel((*it)->hardwareID())<10)
436// log << MSG::DEBUG << "Relevant ? HW id ->" << m_onlineHelper->show_to_string((*it)->hardwareID()) << "Calib -> " << m_onlineHelper->show_to_string(calibLine[0]) << "Pulsed ?" << (*it)->isPulsed() << endmsg;
437
438 }
439
440 if ((*it)->isPulsed()){
441 int iSlot = m_onlineHelper->slot((*it)->hardwareID());
442 int ibarrel_ec = m_onlineHelper->barrel_ec((*it)->hardwareID());
443 int ipos_neg = m_onlineHelper->pos_neg((*it)->hardwareID());
444
445 nbOfEventSlot[iSlot-1]++;
446
447 if (ipos_neg==1) sideA++;
448 else sideC++;
449
450 if (!m_onlineHelper->isEmEndcapSpecialOnline((*it)->hardwareID())){ // do not count EMEC Special entries
451 if (iSlot==1) nbOfEventPart[4*ibarrel_ec]++; // PS
452 else if (iSlot < 9 - ibarrel_ec) nbOfEventPart[4*ibarrel_ec + 1]++; // Front
453 else if (iSlot > 10 - ibarrel_ec) nbOfEventPart[4*ibarrel_ec + 2]++; // Middle
454 else nbOfEventPart[4*ibarrel_ec + 3]++; // Back
455 }
456 }
457
458 ++it;
459 }
460 while ((!relevantForXtalk) && (it != it_end));// End of loop on cell to determine whether this event is relevant for xtalk study
461
462 // Debug : print number of events per slot
463 /*
464 log << MSG::DEBUG << "[Slot-Nevents]: ";
465 for (int jj=0; jj<15; jj++){
466 log << MSG::DEBUG << "[" << jj << "-" << nbOfEventSlot[jj] << "] ";
467 }
468 log << MSG::DEBUG << " - Shall I keep this? " << relevantForXtalk << endmsg;
469 */
470
471 // Debug : print number of events per detector region
472 msg() << MSG::DEBUG << "Event nb " << m_event_counter - 1<< " - " ;
473 msg() << MSG::DEBUG << "Entries : EMB PS/F/M/B=" << nbOfEventPart[0] << "/" << nbOfEventPart[1] << "/" << nbOfEventPart[2] << "/" << nbOfEventPart[3];
474 msg() << MSG::DEBUG << " - EMEC Std PS/F/M/B=" << nbOfEventPart[4] << "/" << nbOfEventPart[5] << "/" << nbOfEventPart[6] << "/" << nbOfEventPart[7];
475 msg() << MSG::DEBUG << " - A/(A+C)=" << (sideA+sideC==0 ? -1 : float(sideA)/float(sideA+sideC));
476 if (!relevantForXtalk)
477 msg() << MSG::DEBUG << " - don't keep (partition/pattern)" << endmsg;
478 else
479 msg() << MSG::DEBUG << " - KEEP THIS EVENT" << endmsg;
480
481
482 // Process relevant events
483 if (relevantForXtalk){
484 bool hasbeenprinted = false;
485 for (it=larAccumulatedCalibDigitContainer->begin();it!=it_end; ++it) { // Loop over all cells
486
487 HWIdentifier chid=(*it)->hardwareID();
488
489 // FT selection for EMEC
490 if (m_barrelEndcap==1) {
491 int iFT = m_onlineHelper->feedthrough(chid);
493 if (m_isInnerWheel) {if (iFT!=3 && iFT!=10 && iFT!=16 && iFT!=22) continue;}
494 else {if (iFT!=2 && iFT!=9 && iFT!=15 && iFT!=21) continue;}
495 else if (iFT==2 || iFT==9 || iFT==15 || iFT==21 || iFT==3 || iFT==10 || iFT==16 || iFT==22 || iFT==6)
496 continue;
497 }
498
499 // Process only channels that are in the studied partition
500 if ( (m_barrelEndcap == m_onlineHelper->barrel_ec(chid)) && (m_posOrNeg == m_onlineHelper->pos_neg(chid)) ){
501
502 if (!hasbeenprinted){
503 ATH_MSG_DEBUG ( "This event is relevant for the studied partition" );
504 hasbeenprinted = true;
505 }
506
507 CaloGain::CaloGain gain=(*it)->gain();
508
509 if (gain<0 || gain>CaloGain::LARNGAIN) {
510 ATH_MSG_ERROR ( "Found not-matching gain number ("<< (int)gain <<")" );
511 return StatusCode::FAILURE;
512 }
513
514 // transform sampleSum vector from uint32_t to double
515 // Allow to cut waves : consider only first samples to reduce needed memory (0 = no cut)
516 std::vector<double> samplesum;
517 std::vector < uint64_t >::const_iterator samplesum_it=(*it)->sampleSum().begin();
518 std::vector < uint64_t >::const_iterator samplesum_it_e=(*it)->sampleSum().end();
519 int nSample=m_cutOnSample;
520 do {
521 samplesum.push_back((double)(*samplesum_it));
522 ++samplesum_it;
523 --nSample;
524 }
525 while ( (samplesum_it!=samplesum_it_e) && (nSample!=0) );
526
527 // transform sample2Sum vector from uint32_t to double
528 // Allow to cut waves : consider only first samples to reduce needed memory (0 = no cut)
529 std::vector<double> sample2sum;
530 std::vector < uint64_t >::const_iterator sample2sum_it=(*it)->sample2Sum().begin();
531 std::vector < uint64_t >::const_iterator sample2sum_it_e=(*it)->sample2Sum().end();
532 nSample=m_cutOnSample;
533 do {
534 sample2sum.push_back((double)(*sample2sum_it));
535 ++sample2sum_it;
536 --nSample;
537 }
538 while ( (sample2sum_it!=sample2sum_it_e) && (nSample!=0) );
539
540 WaveMap& waveMap = m_waves.get(chid,gain);
541 WaveMap::iterator itm = waveMap.find((*it)->DAC());
542
543 if ( itm == waveMap.end() ) { // A new LArCaliWave is booked
544 LArCaliWave wave(samplesum.size()*m_NStep, m_dt, (*it)->DAC(), 0x1, LArWave::meas ) ;
545
546 // Be careful! Don't call addAccumulatedEvent() twice!!!
547 // cf. LArCaliwaveBuilder ref. 1.38
548 //wave.addAccumulatedEvent((int)roundf((*it)->delay()/deltaDelay), m_NStep,
549 // samplesum, sample2sum, (*it)->nTriggers());
550
551 itm = (waveMap.insert(WaveMap::value_type((*it)->DAC(), wave))).first;
552 }//else { // A LArCaliWave for this channel/DAC is already existing
553
554 (*itm).second.addAccumulatedEvent((int)roundf((*it)->delay()/deltaDelay), m_NStep,
555 samplesum, sample2sum, (*it)->nTriggers());
556 } // End of test on studied partition
557 } //End loop over all cells
558 } // End of relevantForXtalk test
559 } //End loop over all containers
560
561 return StatusCode::SUCCESS;
562}
563
564//=========================================================================================================
566//=========================================================================================================
567{
568 // Create wave container using feedthru grouping and initialize
569 auto caliWaveContainer = std::make_unique<LArCaliWaveContainer>();
570
571 ATH_CHECK( caliWaveContainer->setGroupingType(m_groupingType,msg()) );
572 ATH_MSG_DEBUG ( "Set groupingType for LArCaliWaveContainer object" );
573
574 ATH_CHECK( caliWaveContainer->initialize() );
575 ATH_MSG_DEBUG ( "Initialized LArCaliWaveContainer object" );
576
577 // Note : sometimes a Segmentation fault happen at this stage
578 // not yet solved
579 //
580 // Extract of the thread :
581 // > Caught signal 11(Segmentation fault). Details:
582 // > errno = 0, code = 1 (address not mapped to object)
583 // > #10 <signal handler called>
584 // > #11 cpp_alloc (size=52, nothrow=false) at src/tcmalloc.cc:354
585 // > #12 0xf7fd7a69 in operator new (size=52) at src/tcmalloc.cc:3104
586 // > #13 0xf775a306 in std::vector<unsigned int, std::allocator<unsigned int> >::operator= ()
587 // > #14 0xee8b63d7 in LArCondFEBIdChanMap::addFEBIdVector ()
588 // > #15 0xee8b03c4 in LArConditionsContainerBase::initGrouping ()
589 // > #16 0xee8b2c82 in LArConditionsContainerBase::initializeBase ()
590 // > #17 0xeed5f872 in LArConditionsContainer<LArCaliWaveVec>::initialize ()
591
593 const LArOnOffIdMapping* cabling{*cablingHdl};
594 if(!cabling) {
595 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
596 return StatusCode::FAILURE;
597 }
598
599
600 LArWaveHelper wHelper;
601 int NCaliWave=0;
602
603 // Loop over all gains
604 for (unsigned k=0;k<(int)CaloGain::LARNGAIN;k++) {
605
607
609 WaveContainer::ConditionsMapIterator cell_it = m_waves.begin(gain);
610 WaveContainer::ConditionsMapIterator cell_it_e = m_waves.end(gain);
611
612 HWIdentifier lastId;
613
614 for (; cell_it!=cell_it_e; ++cell_it) {
615
616 // Get id of this cell - use id from first cell in map
617 //
618 // Some accumulations may be empty and we must skip this
619 // cell. WaveContainer has all 128 channels for each FEB
620 // with at least ONE being read out.
621 //
622
623 const HWIdentifier hwId = cell_it.channelId();
624 if (!cabling->isOnlineConnected(hwId)) continue; //Ignore disconnected channels
625
626 const WaveMap& waveMap = (*cell_it);
627 if (waveMap.empty()) {
628 ATH_MSG_INFO ( "Empty accumulated wave. Last id: " << MSG::hex
629 << lastId << MSG::dec );
630 continue;
631 }
632
633 lastId = hwId; // save previous id for debug printout
634
635 // FT selection for EMEC
636 if (m_barrelEndcap==1) {
637 int iFT = m_onlineHelper->feedthrough(hwId);
639 if (m_isInnerWheel) {if (iFT!=3 && iFT!=10 && iFT!=16 && iFT!=22) continue;}
640 else {if (iFT!=2 && iFT!=9 && iFT!=15 && iFT!=21) continue;}
641 else if (iFT==2 || iFT==9 || iFT==15 || iFT==21 || iFT==3 || iFT==10 || iFT==16 || iFT==22 || iFT==6)
642 continue;
643 }
644
645 // Get the vector of waves for this chid,gain
646 LArCaliWaveContainer::LArCaliWaves& dacWaves = caliWaveContainer->get(hwId, gain);
647
648 std::map<int, LArCaliWave>::const_iterator dac_it = cell_it->begin();
649 std::map<int, LArCaliWave>::const_iterator dac_it_e = cell_it->end();
650
651 for (; dac_it != dac_it_e; ++dac_it) {
652
653 const LArCaliWave& thisWave = dac_it->second ;
654 float pedAve = 0.;
655
656 double waveMax = thisWave.getSample( wHelper.getMax(thisWave) ) ;
657 if ( m_ADCsatur>0 && waveMax>m_ADCsatur ) {
658 ATH_MSG_INFO ( "Absolute ADC saturation at DAC = " << thisWave.getDAC() << " ... skip!" );
659 continue ;
660 } else {
661
662 LArCaliWave newWave( ((thisWave)+(-pedAve)).getWave() ,
663 thisWave.getErrors(),
664 thisWave.getTriggers(),
665 thisWave.getDt(),
666 thisWave.getDAC(),
667 thisWave.getIsPulsedInt(),
668 thisWave.getFlag() );
669
670 dacWaves.push_back(newWave);
671 NCaliWave++;
672 }
673 } // end of loop DACs
674
675 // intermediate map cleanup (save memory)
676 cell_it->clear();
677
678 } //end loop cells
679
680 } //end loop over m_keyList
681
682 ATH_MSG_INFO ( "Summary : Number of cells with a CaliWave reconstructed : " << NCaliWave );
683 ATH_MSG_INFO ( "Size of LAr calibration waves container : " << caliWaveContainer->size() );
684
685 // Record in detector store with key (m_keyoutput)
686 ATH_CHECK( detStore()->record(std::move(caliWaveContainer), m_keyoutput) );
687
688 ATH_MSG_INFO ( "LArCaliWaveBuilderXtalk has finished." );
689 return StatusCode::SUCCESS;
690}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Container class for LArAccumulatedCalibDigit.
double getDelayScale() const
get the delay Scale
LArCaliWaveBuilderXtalk(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< std::string > m_keylistproperty
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
std::map< int, LArCaliWave > WaveMap
SG::ReadCondHandleKey< LArCalibLineMapping > m_CLKey
const LArOnlineID * m_onlineHelper
StatusCode initializeCabling(const LArOnOffIdMapping *cabling, const LArCalibLineMapping *clCont)
std::vector< std::string > m_keylist
std::vector< HWIdentifier > m_CalibLineHW
int getIsPulsedInt() const
isPulsed value
int getDAC() const
DAC value.
const std::vector< HWIdentifier > & calibSlotLine(const HWIdentifier id) const
ConditionsMap::iterator ConditionsMapIterator
const std::vector< int > & getTriggers() const
trigger vector
const std::vector< double > & getErrors() const
error vector
unsigned int getMax(const LArWave &theWave) const
return index of maximum sample
const double & getSample(const unsigned int i) const
Amplitude per time bin.
Definition LArWave.h:53
const double & getDt() const
delta time
Definition LArWave.h:50
unsigned getFlag() const
flag: ...
Definition LArWave.h:178
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
@ LARNGAIN
Definition CaloGain.h:19