ATLAS Offline Software
Loading...
Searching...
No Matches
LArShapeDumper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "GaudiKernel/INTupleSvc.h"
12
16
18#include "CaloDetDescr/CaloDetDescrElement.h"
23#include "LArCafJobs/CellInfo.h"
24#include "LArCafJobs/RunData.h"
28#include "TFile.h"
29#include "TMath.h"
30
31#include <regex>
32
33
34#include <vector>
35#include <iostream>
36using std::cout;
37using std::endl;
38
39using namespace LArSamples;
40
41
42LArShapeDumper::LArShapeDumper(const std::string & name, ISvcLocator * pSvcLocator) :
43 AthAlgorithm(name, pSvcLocator),
44 m_count(0),
47 m_nLArError(0),
48 m_nNoDigits(0),
50 m_onlineHelper(nullptr),
51 m_onlineHelperSC(nullptr),
52 m_doEM(false),
53 m_doHEC(false),
54 m_doFCAL(false),
55 m_doSC(false),
56 m_samples(nullptr)
57{
58 declareProperty("FileName", m_fileName = "samples.root");
59 declareProperty("MaxChannels", m_maxChannels = 200000);
60 declareProperty("Prescale", m_prescale = 1);
61 declareProperty("CaloType", m_caloType = "EMHECFCALSC");
62 declareProperty("EnergyCut", m_energyCut = -1);
63 declareProperty("EnergyCutSC", m_energyCutSC = -1);
64 declareProperty("NoiseSignifCut", m_noiseSignifCut = 3);
65 declareProperty("MinADCMax", m_minADCMax = -1);
66 declareProperty("MinADCMaxSC", m_minADCMaxSC = -1);
67 declareProperty("Gains", m_gainSpec = "HIGH,MEDIUM,LOW");
68 declareProperty("DumpDisconnected", m_dumpDisc = false);
69 declareProperty("DoStream", m_doStream = false);
70 declareProperty("DoTrigger", m_doTrigger = true);
71 declareProperty("DoOFCIter", m_doOFCIter = true);
72 declareProperty("DoAllEvents", m_doAllEvents = true);
73 declareProperty("DumpChannelInfos", m_dumpChannelInfos = false);
74 declareProperty("DoRoIs", m_doRoIs = true);
75 declareProperty("TriggerNames", m_triggerNames);
76 declareProperty("DoAllLvl1", m_doAllLvl1 = true);
77 declareProperty("onlyEmptyBC",m_onlyEmptyBC=false);
78
79 m_bcMaskSC.setSC();
80}
81
82
86
87
89{
90 ATH_MSG_DEBUG ("in initialize()");
91
92 m_samples = new DataStore();
93
94 std::transform(m_caloType.begin(), m_caloType.end(), m_caloType.begin(), toupper);
95 m_doEM = (m_caloType.find("EM") != std::string::npos);
96 m_doHEC = (m_caloType.find("HEC") != std::string::npos);
97 m_doFCAL = (m_caloType.find("FCAL") != std::string::npos);
98 m_doSC = (m_caloType.find("SC") != std::string::npos);
99
100 ATH_CHECK( m_cablingKey.initialize() );
101 ATH_CHECK( m_BCKey.initialize() );
102 ATH_CHECK( m_BCKeySC.initialize(m_doSC) );
103 ATH_CHECK( m_noiseCDOKey.initialize() );
104 ATH_CHECK( m_adc2mevKey.initialize() );
105 ATH_CHECK( m_pedestalKey.initialize() );
106 ATH_CHECK( m_bcDataKey.initialize() );
107
108 ATH_CHECK( m_digitsKey.initialize() );
109 ATH_CHECK( m_channelsKey.initialize() );
110
111 ATH_CHECK( m_digitsKeySC.initialize(m_doSC) );
112 ATH_CHECK( m_rawscKey.initialize(m_doSC) );
114 ATH_CHECK( m_cablingKeySC.initialize(m_doSC) );
115 ATH_CHECK( m_pedestalKeySC.initialize(m_doSC) );
116
117 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
118 ATH_CHECK(m_caloMgrKey.initialize());
120 if(m_doSC) ATH_CHECK( detStore()->retrieve(m_onlineHelperSC, "LArOnline_SuperCellID") );
121
123 ATH_CHECK(m_bcMask.buildBitMask(m_problemsToMask,msg()));
124 if(m_doSC) ATH_CHECK(m_bcMaskSC.buildBitMask(m_problemsToMaskSC,msg()));
125
126
127 if (m_doTrigger) {
128 CHECK( m_trigDec.retrieve() );
129 }
130
131 ATH_CHECK( m_dumperTool.retrieve() );
132
133 ATH_CHECK(m_acorrKey.initialize(m_dumperTool->doShape()) );
134
135 std::transform(m_gainSpec.begin(), m_gainSpec.end(), m_gainSpec.begin(), toupper);
136 m_gains[CaloGain::LARHIGHGAIN] = (m_gainSpec.find("HIGH") != std::string::npos);
137 m_gains[CaloGain::LARMEDIUMGAIN] = (m_gainSpec.find("MEDIUM") != std::string::npos);
138 m_gains[CaloGain::LARLOWGAIN] = (m_gainSpec.find("LOW") != std::string::npos);
139
140 //if (m_onlyEmptyBC)
141 //ATH_CHECK(m_bcidTool.retrieve());
142
143 return StatusCode::SUCCESS;
144}
145
146
148{
149 m_runData = std::make_unique<RunData>(0);
150
151 if (m_doTrigger) {
152 std::vector<std::regex> regexs;
153 regexs.reserve(m_triggerNames.size());
154for (const std::string& name : m_triggerNames) {
155 regexs.push_back(std::regex(name));
156 }
157
158 std::vector<std::string> chains = m_trigDec->getListOfTriggers();
159 std::vector<std::string> myChains;
160 std::cmatch match;
161
162 for (const std::string& chain : chains) {
163 ATH_MSG_INFO ( "Configured chain : " << chain );
164 for (const std::regex& regex : regexs) {
165 if (std::regex_match(chain.c_str(), match, regex)) myChains.push_back(chain);
166 }
167 }
168 for (const std::string& group : m_trigDec->getListOfGroups())
169 ATH_MSG_INFO ( "Configured group : " << group );
170 const Trig::ChainGroup* calibStreamGroup = m_trigDec->getChainGroup("Calibration");
171 if (calibStreamGroup) {
172 std::vector<std::string> chains = calibStreamGroup->getListOfTriggers();
173 ATH_MSG_INFO ( "Chains for Calibration group:" );
174 for (const std::string& chain : chains)
175 ATH_MSG_INFO ( "Calib chain : " << chain );
176 }
177
178 unsigned int idx = 0;
179
180 if (m_doAllLvl1) {
181 const Trig::ChainGroup* group = m_trigDec->getChainGroup("L1_.*");
182 for (const std::string& l1Item : group->getListOfTriggers()) {
183 const TrigConf::TriggerItem* confItem = m_trigDec->ExperimentalAndExpertMethods().getItemConfigurationDetails(l1Item);
184 if (!confItem) {
185 ATH_MSG_WARNING ( "LVL1 item " << l1Item << ", obtained from TrigConfig, cannot be retrieved!" );
186 continue;
187 }
188 int pos = confItem->ctpId();
189 if (pos < 0 || pos >= 256) {
190 ATH_MSG_WARNING ( "LVL1 item " << l1Item << "has out-of-range ctpId " << pos );
191 continue;
192 }
193 m_runData->addBit(l1Item.c_str(), pos);
194 ATH_MSG_INFO ( "Adding LVL1 trigger bit for " << l1Item << " at position " << pos );
195 }
196 idx = 256;
197 }
198
199 for (const std::string& name : myChains) {
200 if (m_trigDec->getListOfTriggers(name).empty()) {
201 ATH_MSG_WARNING ( "Requested trigger name " << name << " is not configured in this run" );
202 continue;
203 }
204 const Trig::ChainGroup* group = m_trigDec->getChainGroup(name);
205 if (!group) {
206 ATH_MSG_WARNING ( "Could not retrieve chain group for trigger " << name );
207 continue;
208 }
209 m_runData->addBit(name.c_str(), idx++);
210 m_triggerGroups.push_back(group);
211 ATH_MSG_INFO ( "Adding trigger bit for " << name << " at position " << idx-1 );
212 }
213 }
214 return StatusCode::SUCCESS;
215}
216
217
218StatusCode LArShapeDumper::execute(const EventContext& ctx)
219{
220 m_count++;
221 if ((m_prescale > 1 && m_random.Rndm() > 1.0/m_prescale) || m_prescale <= 0) {
222 ATH_MSG_VERBOSE ( "======== prescaling event "<< m_count << " ========" );
224 return StatusCode::SUCCESS;
225 }
226
227 ATH_MSG_VERBOSE ( "======== executing event "<< m_count << " ========" );
228
229 const xAOD::EventInfo* eventInfo = nullptr;
230 ATH_CHECK( evtStore()->retrieve(eventInfo) );
231
232 int event = eventInfo->eventNumber();
233 int run = eventInfo->runNumber();
234 int lumiBlock = eventInfo->lumiBlock();
235 int bunchId = eventInfo->bcid();
236
237
239 ATH_MSG_DEBUG("Ignoring Event b/c of LAr ERROR");
240 m_nLArError++;
241 return StatusCode::SUCCESS;
242 }
243
244
246 const BunchCrossingCondData* bunchCrossing=*bccd;
247 if (!bunchCrossing) {
248 ATH_MSG_ERROR("Failed to retrieve Bunch Crossing obj");
249 return StatusCode::FAILURE;
250 }
251
253 ATH_CHECK(caloMgrHandle.isValid());
254 const CaloDetDescrManager* caloMgr = *caloMgrHandle;
255
256 if (m_onlyEmptyBC) {
257 if (!bccd->isFilled(bunchId)) {
258 ATH_MSG_DEBUG("Ignoring Event with bunch crossing type ");
260 return StatusCode::SUCCESS;
261 }
262 }
263
264
265 EventData* eventData = nullptr;
266 int eventIndex = -1;
267 if (m_doAllEvents) {
268 eventIndex = makeEvent(eventData, run, event, lumiBlock, bunchId);
269 if (eventIndex < 0) return StatusCode::FAILURE;
270 }
271
273 if(!hdlDigit.isValid()) {
274 ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key " << m_digitsKey << " from DetectorStore. " );
275 return StatusCode::SUCCESS;
276 } else
277 ATH_MSG_DEBUG( "Got LArDigitContainer with key " << m_digitsKey.key() );
278 const LArDigitContainer* larDigitContainer = &(*hdlDigit);
279
280 if (larDigitContainer->empty()) {
281 ATH_MSG_WARNING ( "LArDigitContainer with key=" << m_digitsKey.key() << " is empty!" );
282 m_nNoDigits++;
283 return StatusCode::SUCCESS;
284 }
285
287 if(!hdlRaw.isValid()) {
288 ATH_MSG_WARNING( "Unable to retrieve LArRawChannelsContainer with key " << m_channelsKey.key() << " from DetectorStore. " );
289 return StatusCode::SUCCESS;
290 } else
291 ATH_MSG_DEBUG( "Got LArRawChannelsContainer with key " << m_channelsKey.key() );
292 const LArRawChannelContainer* rawChannelContainer = &(*hdlRaw);;
293
294 if (rawChannelContainer->empty()) {
295 ATH_MSG_WARNING ( "LArRawChannelContainer with key=" << m_channelsKey << " is empty!" );
296 m_nNoDigits++;
297 return StatusCode::SUCCESS;
298 }
299
300
301
303 const LArOnOffIdMapping* cabling=*cablingHdl;
304 if(!cabling) {
305 ATH_MSG_ERROR( "Do not have cabling object LArOnOffIdMapping" );
306 return StatusCode::FAILURE;
307 }
308
310 const LArADC2MeV* adc2MeV=*adc2mevHdl;
311 if(!adc2MeV) {
312 ATH_MSG_ERROR( "Failed to retreive ADC2MeV cond obj" );
313 return StatusCode::FAILURE;
314 }
315
317 const ILArPedestal* pedestals=*pedHdl;
318 if (!pedestals) {
319 ATH_MSG_ERROR("Failed to retrieve pedestal cond obj");
320 return StatusCode::FAILURE;
321 }
322
323 const ILArAutoCorr* aCorr=nullptr;
324 if(m_dumperTool->doShape()) {
326 aCorr=*acorrHdl;
327 if (!aCorr) {
328 ATH_MSG_ERROR("Failed to retrieve AutoCorr cond obj");
329 return StatusCode::FAILURE;
330 }
331 }
332
334 const LArBadChannelCont *bcCont {*readHandle};
335 if(!bcCont) {
336 ATH_MSG_ERROR( "Do not have Bad chan container " << m_BCKey.key() );
337 return StatusCode::FAILURE;
338 }
339
340 const LArOFIterResultsContainer* ofIterResult = nullptr;
341 if (m_doOFCIter) {
342 if (evtStore()->contains<LArOFIterResultsContainer> ("LArOFIterResult")) {
343 ATH_CHECK( evtStore()->retrieve(ofIterResult, "LArOFIterResult") );
344 } else {
345 ATH_MSG_WARNING("Do not have LArOFIterResult in this event");
346 }
347 }
348
349 const LArFebErrorSummary* larFebErrorSummary = nullptr;
350 ATH_CHECK( evtStore()->retrieve(larFebErrorSummary, "LArFebErrorSummary") );
351 const std::map<unsigned int,uint16_t>& febErrorMap = larFebErrorSummary->get_all_febs();
352 std::map<unsigned int, const LArRawChannel*> channelsToKeep;
353
354 for (LArRawChannelContainer::const_iterator channel = rawChannelContainer->begin();
355 channel != rawChannelContainer->end(); ++channel)
356 {
357 if (m_energyCut > 0 && TMath::Abs(channel->energy()) < m_energyCut) continue;
358 if (m_bcMask.cellShouldBeMasked(bcCont,channel->channelID())) continue;
359
360 IdentifierHash hash = m_onlineHelper->channel_Hash(channel->channelID());
361
362 if (!hash.is_valid()) {
363 ATH_MSG_FATAL ( "Found a LArRawChannel whose HWIdentifier (" << channel->channelID()
364 << ") does not correspond to a valid hash -- returning StatusCode::FAILURE." );
365 return StatusCode::FAILURE;
366 }
367 channelsToKeep[hash] = &*channel;
368 if (m_dumpChannelInfos) {
369 HistoryContainer* histCont = m_samples->hist_cont(hash);
370 CellInfo* info = nullptr;
371 if (!histCont) {
372 HWIdentifier channelID = channel->hardwareID();
373 const Identifier id = cabling->cnvToIdentifier(channelID);
374 const CaloDetDescrElement* caloDetElement = caloMgr->get_element(id);
375 info = m_dumperTool->makeCellInfo(channelID, id, caloDetElement);
376 if (!info) continue;
377 m_samples->makeNewHistory(hash, info);
378 }
379 }
380 }
381
382 std::map<HWIdentifier, LArOFIterResultsContainer::const_iterator> ofcResultPosition;
383 if (m_doOFCIter && ofIterResult) {
384 for (LArOFIterResultsContainer::const_iterator ofResult = ofIterResult->begin();
385 ofResult != ofIterResult->end(); ++ofResult)
386 ofcResultPosition[ofResult->getChannelID()] = ofResult;
387
388 ATH_MSG_DEBUG ( "njpbSizes : " << larDigitContainer->size()
389 << " " << (ofIterResult ? ofIterResult->size() : 0) << " "
390 << rawChannelContainer->size() << " " << channelsToKeep.size() );
391 }
393 const CaloNoise* noiseCDO=*noiseHdl;
394
395 for (LArDigitContainer::const_iterator digit = larDigitContainer->begin();
396 digit != larDigitContainer->end(); ++digit)
397 {
398 //Check Energy selection
399 IdentifierHash hash = m_onlineHelper->channel_Hash((*digit)->channelID());
400
401 std::map<unsigned int, const LArRawChannel*>::const_iterator findChannel = channelsToKeep.find(hash);
402 if (findChannel == channelsToKeep.end()) continue;
403 const LArRawChannel* rawChannel = findChannel->second;
404
405 //Check detector part
406 HWIdentifier channelID = (*digit)->hardwareID();
407 if ((m_onlineHelper->isEMBchannel(channelID) || m_onlineHelper->isEMECchannel(channelID)) && !m_doEM) continue;
408 if (m_onlineHelper->isHECchannel(channelID) && !m_doHEC) continue;
409 if (m_onlineHelper->isFCALchannel(channelID) && !m_doFCAL) continue;
410
411 //Check gain
412 CaloGain::CaloGain gain=(*digit)->gain();
413 if (gain >= CaloGain::LARNGAIN || m_gains[gain] == false) continue;
414
415 //Check if connected
416 const bool connected = cabling->isOnlineConnected(channelID);
417 if (!connected && !m_dumpDisc) continue;
418
419 // Check ADCMax selection
420 float pedestal = pedestals->pedestal(channelID, gain);
421 float pedestalRMS = pedestals->pedestalRMS(channelID, gain);
422 if (m_minADCMax > 0 || m_noiseSignifCut > 0) {
423 const std::vector<short>& samples = (*digit)->samples();
424 double maxValue = -1;
425 for (short sample : samples)
426 if (sample - pedestal > maxValue) maxValue = sample - pedestal;
427 if (m_minADCMax > 0 && fabs(maxValue) < m_minADCMax) continue;
428 if (m_noiseSignifCut > 0 && fabs(maxValue) < pedestalRMS*m_noiseSignifCut) continue;
429 }
430
431 const Identifier id = cabling->cnvToIdentifier(channelID);
432 const CaloDetDescrElement* caloDetElement = nullptr;
433
434 HistoryContainer* histCont = m_samples->hist_cont(hash);
435 CellInfo* info = nullptr;
436 if (!histCont) {
437 if (!caloDetElement) caloDetElement = caloMgr->get_element(id);
438 info = m_dumperTool->makeCellInfo(channelID, id, caloDetElement);
439 if (!info) continue;
440 histCont = m_samples->makeNewHistory(hash, info);
441 }
442 else
443 info = histCont->cell_info();
444
445 float noise = -1;
446 unsigned int status = 0xFFFFFFFF;
447 if (connected) {
448 if (!caloDetElement) caloDetElement = caloMgr->get_element(id);
449 noise = noiseCDO->getNoise(id,gain);
450 status = bcCont->status(channelID).packedData();
451 HWIdentifier febId = m_onlineHelper->feb_Id(m_onlineHelper->feedthrough_Id(channelID), m_onlineHelper->slot(channelID));
452 std::map<unsigned int,uint16_t>::const_iterator findError = febErrorMap.find(febId.get_identifier32().get_compact());
453 if (findError != febErrorMap.end()) {
454 unsigned int febErrWord = findError->second;
455 status = status & (febErrWord >> 17);
456 }
457 }
458
459 //std::vector<float> autoCorr;
461 if (m_dumperTool->doShape()) {
462 const LArAutoCorrComplete* autoCorrObj = dynamic_cast<const LArAutoCorrComplete*>(aCorr);
463 if (!autoCorrObj)
464 ATH_MSG_WARNING ( "AutoCorr object is not of type LArAutoCorrComplete!" );
465 else
466 autoCorr = autoCorrObj->autoCorr(channelID, gain);
467 }
468
469 if (!info->shape((*digit)->gain())) // this happens if doAllShapes is off
470 info->setShape((*digit)->gain(), m_dumperTool->retrieveShape(channelID, gain));
471
472 if (!eventData) {
473 eventIndex = makeEvent(eventData, run, event, lumiBlock, bunchId); // this happens if doAllEvents is off
474 if (eventIndex < 0) return StatusCode::FAILURE;
475 }
476
477 DataContainer* data =
478 new DataContainer((*digit)->gain(), (*digit)->samples(),
479 rawChannel->energy(),
480 rawChannel->time()/double(1000),
481 rawChannel->quality(),
482 eventIndex,
483 autoCorr,
484 noise, pedestal, pedestalRMS, status);
485
486 // std::map<HWIdentifier, LArOFIterResultsContainer::const_iterator>::const_iterator findResult = ofcResultPosition.find(channelID);
487// if (findResult != ofcResultPosition.end()) {
488// LArOFIterResultsContainer::const_iterator ofResult = findResult->second;
489// if (ofResult->getValid() && ofResult->getConverged())
490// data->setADCMax(ofResult->getAmplitude());
491// }
492// else
493// msg() << MSG::INFO << "OFResult for channel 0x" << MSG::hex << channelID << MSG::dec
494// << " not found. (size was " << ofcResultPosition.size() << ")" << endmsg;
495
496
497 const auto ramp=adc2MeV->ADC2MEV(channelID,gain); //dudu
498 data->setADCMax(rawChannel->energy()/ramp[1]); //pow(ADCPeak,i); //dudu
499
500
501 histCont->add(data);
502 }
503
504 if(m_doSC) {
505 std::map<unsigned int, const LArRawSC*> scToKeep;
506
508 if(!hdlSC.isValid()) {
509 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key " << m_rawscKey << " from EventStore. " );
510 return StatusCode::SUCCESS;
511 } else
512 ATH_MSG_DEBUG( "Got LArRawSCContainer with key " << m_rawscKey.key() );
513
514 if (hdlSC->empty()) {
515 ATH_MSG_WARNING ( "LArRawSCContainer with key=" << m_rawscKey.key() << " is empty!" );
516 return StatusCode::SUCCESS;
517 }
518
520 if(!hdlrecoSC.isValid()) {
521 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key " << m_rawRecomputedscKey << " from EventStore. " );
522 return StatusCode::SUCCESS;
523 } else
524 ATH_MSG_DEBUG( "Got LArRawSCContainer with key " << m_rawRecomputedscKey.key() );
525
526 if (hdlrecoSC->empty()) {
527 ATH_MSG_WARNING ( "LArRawSCContainer with key=" << m_rawRecomputedscKey.key() << " is empty!" );
528 return StatusCode::SUCCESS;
529 }
530
532 const LArOnOffIdMapping* cablingSC=*cablingHdl;
533 if(!cablingSC) {
534 ATH_MSG_ERROR( "Do not have cabling object LArOnOffIdMapping" );
535 return StatusCode::FAILURE;
536 }
537
539 ATH_CHECK(caloMgrHandle.isValid());
540 const CaloSuperCellDetDescrManager* caloMgrSC = *caloMgrHandle;
541
543 const ILArPedestal* pedestalsSC=*pedHdl;
544 if (!pedestals) {
545 ATH_MSG_ERROR("Failed to retrieve pedestal cond obj for SC");
546 return StatusCode::FAILURE;
547 }
548
549 std::map<unsigned int, std::pair<float, std::pair<float,float> > > channelsToKeepSC;
550
551 for (const LArRawSC* rawSC : *hdlSC) { // from bytestream
552
553 // is SC masked ?
554 if (m_bcMaskSC.cellShouldBeMasked(bcCont,rawSC->hardwareID())) continue;
555
556 const std::vector<unsigned short>& bcids = rawSC->bcids();
557 const std::vector<int>& energies = rawSC->energies();
558 const std::vector<bool>& satur = rawSC->satur();
559
560 // Look for bcid:
561 float scEne = 0;
562 float defValue = -99999999.;
563
564 const size_t nBCIDs = bcids.size();
565 size_t i = 0;
566 for (i = 0; i < nBCIDs && bcids[i] != bunchId; i++)
567 ;
568 if(i==nBCIDs) continue;
569 if (satur[i]) continue;
570
571 scEne = energies[i];
572 if (m_energyCutSC > 0 && TMath::Abs(scEne) < m_energyCutSC) continue;
573 if (m_bcMaskSC.cellShouldBeMasked(bcCont,rawSC->hardwareID())) continue;
574
575 IdentifierHash hash = m_onlineHelperSC->channel_Hash(rawSC->hardwareID());
576
577 if (!hash.is_valid()) {
578 ATH_MSG_FATAL ( "Found a LArRawSC whose HWIdentifier (" << rawSC->hardwareID()
579 << ") does not correspond to a valid hash -- returning StatusCode::FAILURE." );
580 return StatusCode::FAILURE;
581 }
582
583 channelsToKeepSC[hash] = std::make_pair(scEne, std::make_pair(defValue,defValue));
584
585 if (m_dumpChannelInfos) {
586 HistoryContainer* histCont = m_samples->hist_cont_sc(hash);
587 CellInfo* info = nullptr;
588 if (!histCont) {
589 HWIdentifier channelID = rawSC->hardwareID();
590 const Identifier id = cablingSC->cnvToIdentifier(channelID);
591 const CaloDetDescrElement* caloDetElement = caloMgrSC->get_element(id);
592 info = m_dumperToolSC->makeCellInfo(channelID, id, caloDetElement);
593 if (!info) continue;
594 m_samples->makeNewHistorySC(hash, info);
595 }
596 }
597 }
598 ATH_MSG_INFO("SC to keep in this event: "<<channelsToKeepSC.size());
599
600 for (const LArRawSC* rawSC : *hdlrecoSC) { //reconstructed
601
602 if (m_bcMaskSC.cellShouldBeMasked(bcCont,rawSC->hardwareID())) continue;
603 IdentifierHash hash = m_onlineHelperSC->channel_Hash(rawSC->hardwareID());
604 if (!hash.is_valid()) {
605 ATH_MSG_FATAL ( "Found a LArRawSC whose HWIdentifier (" << rawSC->hardwareID()
606 << ") does not correspond to a valid hash -- returning StatusCode::FAILURE." );
607 return StatusCode::FAILURE;
608 }
609
610 // do we keep this SC ?
611 if (channelsToKeepSC.find(hash) == channelsToKeepSC.end()) continue;
612
613 const std::vector<unsigned short>& bcids = rawSC->bcids();
614 const std::vector<int>& energies = rawSC->energies();
615 const std::vector<int>& tauenergies = rawSC->tauEnergies();
616
617 // Look for bcid:
618 float scEne = 0;
619 float scTim = -99999999.;
620
621 const size_t nBCIDs = bcids.size();
622 size_t i = 0;
623 for (i = 0; i < nBCIDs && bcids[i] != bunchId; i++)
624 ;
625 if(i==nBCIDs) continue;
626
627 scEne = energies[i];
628
629 if(tauenergies.size() && scEne != 0) scTim = tauenergies[i] / scEne;
630
631 channelsToKeepSC[hash].second = std::make_pair(scEne, scTim);
632
633 if (m_dumpChannelInfos) {
634 HistoryContainer* histCont = m_samples->hist_cont_sc(hash);
635 CellInfo* info = nullptr;
636 if (!histCont) {
637 HWIdentifier channelID = rawSC->hardwareID();
638 const Identifier id = cablingSC->cnvToIdentifier(channelID);
639 const CaloDetDescrElement* caloDetElement = caloMgrSC->get_element(id);
640 info = m_dumperToolSC->makeCellInfo(channelID, id, caloDetElement);
641 if (!info) continue;
642 m_samples->makeNewHistorySC(hash, info);
643 }
644 }
645 }
646
648 if(!hdlSCDigit.isValid()) {
649 ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key " << m_digitsKeySC << " from DetectorStore. " );
650 return StatusCode::SUCCESS;
651 } else
652 ATH_MSG_DEBUG( "Got LArDigitContainer with key " << m_digitsKeySC.key() );
653 const LArDigitContainer* larSCDigitContainer = &(*hdlSCDigit);
654
655 if (larSCDigitContainer->empty()) {
656 ATH_MSG_WARNING ( "LArDigitContainer with key=" << m_digitsKeySC.key() << " is empty!" );
658 return StatusCode::SUCCESS;
659 }
660
661 for (LArDigitContainer::const_iterator digit = larSCDigitContainer->begin();
662 digit != larSCDigitContainer->end(); ++digit)
663 {
664 //Check Energy selection
665 IdentifierHash hash = m_onlineHelperSC->channel_Hash((*digit)->channelID());
666
667 std::map<unsigned int, std::pair<float, std::pair<float,float> > >::const_iterator findChannel = channelsToKeepSC.find(hash);
668 if (findChannel == channelsToKeepSC.end()) continue;
669
670 // Check ADCMax selection
671 float pedestal = pedestalsSC->pedestal((*digit)->channelID(), 0);
672 if (m_minADCMaxSC > 0 ) {
673 const std::vector<short>& samples = (*digit)->samples();
674 double maxValue = -1;
675 for (short sample : samples)
676 if (sample - pedestal > maxValue) maxValue = sample - pedestal;
677 if (fabs(maxValue) < m_minADCMax) continue;
678 }
679
680 const Identifier id = cablingSC->cnvToIdentifier((*digit)->channelID());
681 const CaloDetDescrElement* caloDetElement = nullptr;
682
683 HistoryContainer* histCont = m_samples->hist_cont_sc(hash);
684 CellInfo* info = nullptr;
685 if (!histCont) {
686 if (!caloDetElement) caloDetElement = caloMgrSC->get_element(id);
687 info = m_dumperToolSC->makeCellInfo((*digit)->channelID(), id, caloDetElement);
688 if (!info) continue;
689 histCont = m_samples->makeNewHistorySC(hash, info);
690 }
691 else
692 info = histCont->cell_info();
693
694 if (!eventData) {
695 eventIndex = makeEvent(eventData, run, event, lumiBlock, bunchId); // this happens if doAllEvents is off
696 if (eventIndex < 0) return StatusCode::FAILURE;
697 }
698
699 DataContainer* data =
700 new DataContainer((*digit)->gain(), (*digit)->samples(),
701 findChannel->second.first,
702 findChannel->second.second.second,
703 findChannel->second.second.first,
704 eventIndex,
706 -1, pedestal, 0, 0);
707
708
709 histCont->add(data);
710 }
711
712 } //m_doSC
713
714 return StatusCode::SUCCESS;
715}
716
717
719{
720 m_samples->addRun(m_runData.release());
721 return StatusCode::SUCCESS;
722}
723
724
726{
727 ATH_MSG_DEBUG ("in finalize() ");
728
729 if (m_prescale>1) ATH_MSG_INFO("Prescale dropped " << m_nPrescaledAway << "/" << m_count << " events");
730 if (m_onlyEmptyBC) ATH_MSG_INFO("Dropped " << m_nWrongBunchGroup << "/" << m_count << " events b/c of wrong bunch group");
731 ATH_MSG_INFO("Dropped " << m_nLArError << "/" << m_count << " Events b/c of LAr Veto (Noise burst or corruption)");
732
733
734 int n = 0;
735 for (unsigned int i = 0; i < m_samples->nChannels(); i++)
736 if (m_samples->historyContainer(i)) {
737 if (m_samples->historyContainer(i)->cellInfo() == nullptr)
738 ATH_MSG_INFO ( "Cell with no cellInfo at index " << i << " !!" );
739 //else if (m_samples->historyContainer(i)->cellInfo()->shape() == 0)
740 //msg() << MSG::INFO << "Cell with no ShapeInfo at index " << i << " !!" << endmsg;
741 //msg() << MSG::INFO << "Non-zero cell at index " << i << " " << m_samples->shape(i)->size() << endmsg;
742 n++;
743 }
744
745 //for (unsigned int i = 0; i < m_samples->nEvents(); i++) {
746 // msg() << MSG::INFO << "Event " << i << " = "
747 // << m_samples->eventData(i)->run() << " " << m_samples->eventData(i)->event()
748 // << "trigger = " << m_samples->eventData(i)->triggers() << ", nRoIs = " << m_samples->eventData(i)->nRoIs() << endmsg;
749 // }
750 ATH_MSG_INFO ( "Non-zero cells = " << n << ", footprint = " << m_samples->footprint() );
751 ATH_MSG_INFO ( "Writing..." );
752
753 if (!m_doStream) {
754 m_samples->writeTrees(m_fileName.c_str());
755/* TFile* f = TFile::Open(m_fileName.c_str(), "RECREATE");
756 msg() << MSG::INFO << "Writing (2)..." << endmsg;
757 f->WriteObjectAny(m_samples, "Container", "LArSamples");
758 msg() << MSG::INFO << "Closing..." << endmsg;
759 f->Close();
760 msg() << MSG::INFO << "Deleting..." << endmsg;
761 delete m_samples;*/
762 msg() << MSG::INFO << "Done!" << endmsg;
763 }
764
765 return StatusCode::SUCCESS;
766}
767
768
770 int run, int event,
771 int lumiBlock, int bunchXing) const
772{
773 std::vector<unsigned int> triggerWords;
774 if (m_doTrigger) {
775 const ROIB::RoIBResult* l1Result = nullptr;
776 if (evtStore()->retrieve(l1Result).isFailure() || !l1Result) {
777 ATH_MSG_FATAL ( "Could not retrieve RoIBResult!" );
778 return -1;
779 }
780 const std::vector<ROIB::CTPRoI> tav = l1Result->cTPResult().TAV();
781 for (const ROIB::CTPRoI& word : tav)
782 triggerWords.push_back(word.roIWord());
783
784 for (const std::pair<const TString, unsigned int>& p : m_runData->triggerConfig()) {
785 while (triggerWords.size() <= p.second/32) triggerWords.push_back(0);
786 if (m_trigDec->isPassed(p.first.Data())) {
787 triggerWords[p.second/32] |= (0x1 << (p.second % 32));
788 //msg() << MSG::INFO << "Trigger line " << p.first.Data() << " passed" << endmsg;
789 }
790 }
791 //msg() << MSG::INFO << "Trigger words : ";
792 //for (unsigned int i = 0; i < triggerWords.size(); i++) msg() << MSG::INFO << triggerWords[i] << " ";
793 //msg() << MSG::INFO << endmsg;
794 }
795
796 eventData = new EventData(event, 0, lumiBlock, bunchXing);
797 if (m_runData->run() == 0) m_runData->setRun(run);
798 eventData->setRunData(m_runData.get());
799 eventData->setTriggerData(triggerWords);
800 if (m_doRoIs) {
801 //msg() << MSG::INFO << "Filling RoI list" << endmsg;
802 for (const Trig::ChainGroup* group : m_triggerGroups) {
803 std::vector<Trig::Feature<TrigRoiDescriptor> > roIs = group->features().get<TrigRoiDescriptor>();
804 for (const Trig::Feature<TrigRoiDescriptor>& roI : roIs) {
805 //msg() << MSG::INFO << "Found an roi for chain ";
806 //for (unsigned int i = 0; i < group->getListOfTriggers().size(); i++) cout << group->getListOfTriggers()[i] << " ";
807 //cout << "@ " << roI.cptr()->eta() << ", " << roI.cptr()->phi() << ", TE = "
808 // << roI.te()->getId() << " " << Trig::getTEName(*roI.te()) << " with label " << roI.label() << endmsg;
809 eventData->addRoI(roI.cptr()->eta(), roI.cptr()->phi(), group->getListOfTriggers()[0].c_str(), roI.label().c_str());
810 //msg() << MSG::INFO << "nRoIs so far = " << eventData->nRoIs() << endmsg;
811 }
812 }
813 }
814 return m_samples->addEvent(eventData);
815}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescriptor.
#define maxValue(current, test)
#define CHECK(...)
Evaluate an expression and check for errors.
LArBadXCont< LArBadChannel > LArBadChannelCont
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
This class groups all DetDescr information related to a CaloCell.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition CaloNoise.h:35
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.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
This class defines the interface for accessing AutoCorrelation parameters for each channel @stereotyp...
LArVectorProxy AutoCorrRef_t
virtual float pedestal(const HWIdentifier &id, int gain) const =0
virtual float pedestalRMS(const HWIdentifier &id, int gain) const =0
access to RMS of Pedestal index by Identifier, and gain setting
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
const LArVectorProxy ADC2MEV(const HWIdentifier &id, int gain) const
Definition LArADC2MeV.h:32
This class implements the ILArAutoCorr interface.
virtual AutoCorrRef_t autoCorr(const HWIdentifier &CellID, int gain) const
BitWord packedData() const
LArBC_t status(const HWIdentifier channel) const
Query the status of a particular channel or FEB This is the main client access method.
Container class for LArDigit.
Holds information from the FEB Error Summary.
const std::map< unsigned int, uint16_t > & get_all_febs() const
get all febs with error
Identifier cnvToIdentifier(const HWIdentifier &sid) const
create an Identifier from a HWIdentifier (inline)
Container for LArRawChannel (IDC using LArRawChannelCollection).
Liquid Argon ROD output object base class.
int time() const
uint16_t quality() const
int energy() const
Liquid Argon SuperCell raw data.
Definition LArRawSC.h:19
storage of the time histories of all the cells
void setRunData(const RunData *runData)
Definition EventData.h:75
void setTriggerData(const std::vector< unsigned int > &words)
Definition EventData.cxx:75
void addRoI(float eta, float phi, const char *name="", const char *label="")
Definition EventData.h:73
void add(const DataContainer *data)
append data (takes ownership)
virtual StatusCode stop() override
std::string m_gainSpec
SG::ReadCondHandleKey< LArADC2MeV > m_adc2mevKey
unsigned m_maxChannels
Gaudi::Property< std::vector< std::string > > m_problemsToMask
SG::ReadCondHandleKey< LArBadChannelCont > m_BCKeySC
virtual StatusCode start() override
SG::ReadCondHandleKey< ILArPedestal > m_pedestalKeySC
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
std::vector< std::string > m_triggerNames
unsigned m_nPrescaledAway
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
SG::ReadHandleKey< LArRawSCContainer > m_rawscKey
Gaudi::Property< std::vector< std::string > > m_problemsToMaskSC
ToolHandle< ILArShapeDumperTool > m_dumperToolSC
unsigned m_nLArError
std::string m_caloType
virtual StatusCode finalize() override
SG::ReadHandleKey< LArRawSCContainer > m_rawRecomputedscKey
virtual StatusCode initialize() override
SG::ReadCondHandleKey< LArBadChannelCont > m_BCKey
int makeEvent(LArSamples::EventData *&eventData, int run, int event, int lumiBlock, int bunchXing) const
double m_noiseSignifCut
LArSamples::DataStore * m_samples
ToolHandle< ILArShapeDumperTool > m_dumperTool
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSuperCellMgrKey
const LArOnlineID * m_onlineHelper
PublicToolHandle< Trig::TrigDecisionTool > m_trigDec
unsigned m_nNoDigits
std::vector< const Trig::ChainGroup * > m_triggerGroups
LArBadChannelMask m_bcMask
LArBadChannelMask m_bcMaskSC
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
SG::ReadCondHandleKey< ILArAutoCorr > m_acorrKey
const LArOnline_SuperCellID * m_onlineHelperSC
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
bool m_gains[CaloGain::LARNGAIN]
std::unique_ptr< LArSamples::RunData > m_runData
SG::ReadHandleKey< LArRawChannelContainer > m_channelsKey
SG::ReadCondHandleKey< BunchCrossingCondData > m_bcDataKey
SG::ReadHandleKey< LArDigitContainer > m_digitsKeySC
unsigned m_nWrongBunchGroup
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeySC
SG::ReadCondHandleKey< ILArPedestal > m_pedestalKey
std::string m_fileName
unsigned m_nNoDigitsSC
LArShapeDumper(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< LArDigitContainer > m_digitsKey
Proxy for accessing a range of float values like a vector.
const std::vector< CTPRoI > TAV() const
get trigger result after veto
ROIB::CTPRoI contains a RoI delivered by the CTP.
Definition CTPRoI.h:28
Class holding the LVL1 RoIB result build by the RoIBuilder.
Definition RoIBResult.h:47
const CTPResult & cTPResult() const
Gets the CTP part of the L1 RDO.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
std::vector< std::string > getListOfTriggers() const
is basic vehicle of object access in TDT
Definition Feature.h:112
uint32_t lumiBlock() const
The current event's luminosity block number.
uint32_t bcid() const
The bunch crossing ID of the event.
@ LAr
The LAr calorimeter.
@ Error
The sub-detector issued an error.
uint32_t runNumber() const
The current event's run number.
EventFlagErrorState errorState(EventFlagSubDet subDet) const
Get the error state for a particular sub-detector.
uint64_t eventNumber() const
The current event's event number.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:359
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ LARLOWGAIN
Definition CaloGain.h:18
@ LARNGAIN
Definition CaloGain.h:19
@ LARHIGHGAIN
Definition CaloGain.h:18
EventInfo_v1 EventInfo
Definition of the latest event info version.
int run(int argc, char *argv[])