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
219{
220 m_count++;
221 const EventContext& ctx = Gaudi::Hive::currentContext();
222 if ((m_prescale > 1 && m_random.Rndm() > 1.0/m_prescale) || m_prescale <= 0) {
223 ATH_MSG_VERBOSE ( "======== prescaling event "<< m_count << " ========" );
225 return StatusCode::SUCCESS;
226 }
227
228 ATH_MSG_VERBOSE ( "======== executing event "<< m_count << " ========" );
229
230 const xAOD::EventInfo* eventInfo = nullptr;
231 ATH_CHECK( evtStore()->retrieve(eventInfo) );
232
233 int event = eventInfo->eventNumber();
234 int run = eventInfo->runNumber();
235 int lumiBlock = eventInfo->lumiBlock();
236 int bunchId = eventInfo->bcid();
237
238
240 ATH_MSG_DEBUG("Ignoring Event b/c of LAr ERROR");
241 m_nLArError++;
242 return StatusCode::SUCCESS;
243 }
244
245
247 const BunchCrossingCondData* bunchCrossing=*bccd;
248 if (!bunchCrossing) {
249 ATH_MSG_ERROR("Failed to retrieve Bunch Crossing obj");
250 return StatusCode::FAILURE;
251 }
252
254 ATH_CHECK(caloMgrHandle.isValid());
255 const CaloDetDescrManager* caloMgr = *caloMgrHandle;
256
257 if (m_onlyEmptyBC) {
258 if (!bccd->isFilled(bunchId)) {
259 ATH_MSG_DEBUG("Ignoring Event with bunch crossing type ");
261 return StatusCode::SUCCESS;
262 }
263 }
264
265
266 EventData* eventData = nullptr;
267 int eventIndex = -1;
268 if (m_doAllEvents) {
269 eventIndex = makeEvent(eventData, run, event, lumiBlock, bunchId);
270 if (eventIndex < 0) return StatusCode::FAILURE;
271 }
272
274 if(!hdlDigit.isValid()) {
275 ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key " << m_digitsKey << " from DetectorStore. " );
276 return StatusCode::SUCCESS;
277 } else
278 ATH_MSG_DEBUG( "Got LArDigitContainer with key " << m_digitsKey.key() );
279 const LArDigitContainer* larDigitContainer = &(*hdlDigit);
280
281 if (larDigitContainer->empty()) {
282 ATH_MSG_WARNING ( "LArDigitContainer with key=" << m_digitsKey.key() << " is empty!" );
283 m_nNoDigits++;
284 return StatusCode::SUCCESS;
285 }
286
288 if(!hdlRaw.isValid()) {
289 ATH_MSG_WARNING( "Unable to retrieve LArRawChannelsContainer with key " << m_channelsKey.key() << " from DetectorStore. " );
290 return StatusCode::SUCCESS;
291 } else
292 ATH_MSG_DEBUG( "Got LArRawChannelsContainer with key " << m_channelsKey.key() );
293 const LArRawChannelContainer* rawChannelContainer = &(*hdlRaw);;
294
295 if (rawChannelContainer->empty()) {
296 ATH_MSG_WARNING ( "LArRawChannelContainer with key=" << m_channelsKey << " is empty!" );
297 m_nNoDigits++;
298 return StatusCode::SUCCESS;
299 }
300
301
302
304 const LArOnOffIdMapping* cabling=*cablingHdl;
305 if(!cabling) {
306 ATH_MSG_ERROR( "Do not have cabling object LArOnOffIdMapping" );
307 return StatusCode::FAILURE;
308 }
309
311 const LArADC2MeV* adc2MeV=*adc2mevHdl;
312 if(!adc2MeV) {
313 ATH_MSG_ERROR( "Failed to retreive ADC2MeV cond obj" );
314 return StatusCode::FAILURE;
315 }
316
318 const ILArPedestal* pedestals=*pedHdl;
319 if (!pedestals) {
320 ATH_MSG_ERROR("Failed to retrieve pedestal cond obj");
321 return StatusCode::FAILURE;
322 }
323
324 const ILArAutoCorr* aCorr=nullptr;
325 if(m_dumperTool->doShape()) {
327 aCorr=*acorrHdl;
328 if (!aCorr) {
329 ATH_MSG_ERROR("Failed to retrieve AutoCorr cond obj");
330 return StatusCode::FAILURE;
331 }
332 }
333
335 const LArBadChannelCont *bcCont {*readHandle};
336 if(!bcCont) {
337 ATH_MSG_ERROR( "Do not have Bad chan container " << m_BCKey.key() );
338 return StatusCode::FAILURE;
339 }
340
341 const LArOFIterResultsContainer* ofIterResult = nullptr;
342 if (m_doOFCIter) {
343 if (evtStore()->contains<LArOFIterResultsContainer> ("LArOFIterResult")) {
344 ATH_CHECK( evtStore()->retrieve(ofIterResult, "LArOFIterResult") );
345 } else {
346 ATH_MSG_WARNING("Do not have LArOFIterResult in this event");
347 }
348 }
349
350 const LArFebErrorSummary* larFebErrorSummary = nullptr;
351 ATH_CHECK( evtStore()->retrieve(larFebErrorSummary, "LArFebErrorSummary") );
352 const std::map<unsigned int,uint16_t>& febErrorMap = larFebErrorSummary->get_all_febs();
353 std::map<unsigned int, const LArRawChannel*> channelsToKeep;
354
355 for (LArRawChannelContainer::const_iterator channel = rawChannelContainer->begin();
356 channel != rawChannelContainer->end(); ++channel)
357 {
358 if (m_energyCut > 0 && TMath::Abs(channel->energy()) < m_energyCut) continue;
359 if (m_bcMask.cellShouldBeMasked(bcCont,channel->channelID())) continue;
360
361 IdentifierHash hash = m_onlineHelper->channel_Hash(channel->channelID());
362
363 if (!hash.is_valid()) {
364 ATH_MSG_FATAL ( "Found a LArRawChannel whose HWIdentifier (" << channel->channelID()
365 << ") does not correspond to a valid hash -- returning StatusCode::FAILURE." );
366 return StatusCode::FAILURE;
367 }
368 channelsToKeep[hash] = &*channel;
369 if (m_dumpChannelInfos) {
370 HistoryContainer* histCont = m_samples->hist_cont(hash);
371 CellInfo* info = nullptr;
372 if (!histCont) {
373 HWIdentifier channelID = channel->hardwareID();
374 const Identifier id = cabling->cnvToIdentifier(channelID);
375 const CaloDetDescrElement* caloDetElement = caloMgr->get_element(id);
376 info = m_dumperTool->makeCellInfo(channelID, id, caloDetElement);
377 if (!info) continue;
378 m_samples->makeNewHistory(hash, info);
379 }
380 }
381 }
382
383 std::map<HWIdentifier, LArOFIterResultsContainer::const_iterator> ofcResultPosition;
384 if (m_doOFCIter && ofIterResult) {
385 for (LArOFIterResultsContainer::const_iterator ofResult = ofIterResult->begin();
386 ofResult != ofIterResult->end(); ++ofResult)
387 ofcResultPosition[ofResult->getChannelID()] = ofResult;
388
389 ATH_MSG_DEBUG ( "njpbSizes : " << larDigitContainer->size()
390 << " " << (ofIterResult ? ofIterResult->size() : 0) << " "
391 << rawChannelContainer->size() << " " << channelsToKeep.size() );
392 }
394 const CaloNoise* noiseCDO=*noiseHdl;
395
396 for (LArDigitContainer::const_iterator digit = larDigitContainer->begin();
397 digit != larDigitContainer->end(); ++digit)
398 {
399 //Check Energy selection
400 IdentifierHash hash = m_onlineHelper->channel_Hash((*digit)->channelID());
401
402 std::map<unsigned int, const LArRawChannel*>::const_iterator findChannel = channelsToKeep.find(hash);
403 if (findChannel == channelsToKeep.end()) continue;
404 const LArRawChannel* rawChannel = findChannel->second;
405
406 //Check detector part
407 HWIdentifier channelID = (*digit)->hardwareID();
408 if ((m_onlineHelper->isEMBchannel(channelID) || m_onlineHelper->isEMECchannel(channelID)) && !m_doEM) continue;
409 if (m_onlineHelper->isHECchannel(channelID) && !m_doHEC) continue;
410 if (m_onlineHelper->isFCALchannel(channelID) && !m_doFCAL) continue;
411
412 //Check gain
413 CaloGain::CaloGain gain=(*digit)->gain();
414 if (gain >= CaloGain::LARNGAIN || m_gains[gain] == false) continue;
415
416 //Check if connected
417 const bool connected = cabling->isOnlineConnected(channelID);
418 if (!connected && !m_dumpDisc) continue;
419
420 // Check ADCMax selection
421 float pedestal = pedestals->pedestal(channelID, gain);
422 float pedestalRMS = pedestals->pedestalRMS(channelID, gain);
423 if (m_minADCMax > 0 || m_noiseSignifCut > 0) {
424 const std::vector<short>& samples = (*digit)->samples();
425 double maxValue = -1;
426 for (short sample : samples)
427 if (sample - pedestal > maxValue) maxValue = sample - pedestal;
428 if (m_minADCMax > 0 && fabs(maxValue) < m_minADCMax) continue;
429 if (m_noiseSignifCut > 0 && fabs(maxValue) < pedestalRMS*m_noiseSignifCut) continue;
430 }
431
432 const Identifier id = cabling->cnvToIdentifier(channelID);
433 const CaloDetDescrElement* caloDetElement = nullptr;
434
435 HistoryContainer* histCont = m_samples->hist_cont(hash);
436 CellInfo* info = nullptr;
437 if (!histCont) {
438 if (!caloDetElement) caloDetElement = caloMgr->get_element(id);
439 info = m_dumperTool->makeCellInfo(channelID, id, caloDetElement);
440 if (!info) continue;
441 histCont = m_samples->makeNewHistory(hash, info);
442 }
443 else
444 info = histCont->cell_info();
445
446 float noise = -1;
447 unsigned int status = 0xFFFFFFFF;
448 if (connected) {
449 if (!caloDetElement) caloDetElement = caloMgr->get_element(id);
450 noise = noiseCDO->getNoise(id,gain);
451 status = bcCont->status(channelID).packedData();
452 HWIdentifier febId = m_onlineHelper->feb_Id(m_onlineHelper->feedthrough_Id(channelID), m_onlineHelper->slot(channelID));
453 std::map<unsigned int,uint16_t>::const_iterator findError = febErrorMap.find(febId.get_identifier32().get_compact());
454 if (findError != febErrorMap.end()) {
455 unsigned int febErrWord = findError->second;
456 status = status & (febErrWord >> 17);
457 }
458 }
459
460 //std::vector<float> autoCorr;
462 if (m_dumperTool->doShape()) {
463 const LArAutoCorrComplete* autoCorrObj = dynamic_cast<const LArAutoCorrComplete*>(aCorr);
464 if (!autoCorrObj)
465 ATH_MSG_WARNING ( "AutoCorr object is not of type LArAutoCorrComplete!" );
466 else
467 autoCorr = autoCorrObj->autoCorr(channelID, gain);
468 }
469
470 if (!info->shape((*digit)->gain())) // this happens if doAllShapes is off
471 info->setShape((*digit)->gain(), m_dumperTool->retrieveShape(channelID, gain));
472
473 if (!eventData) {
474 eventIndex = makeEvent(eventData, run, event, lumiBlock, bunchId); // this happens if doAllEvents is off
475 if (eventIndex < 0) return StatusCode::FAILURE;
476 }
477
479 new DataContainer((*digit)->gain(), (*digit)->samples(),
480 rawChannel->energy(),
481 rawChannel->time()/double(1000),
482 rawChannel->quality(),
483 eventIndex,
484 autoCorr,
485 noise, pedestal, pedestalRMS, status);
486
487 // std::map<HWIdentifier, LArOFIterResultsContainer::const_iterator>::const_iterator findResult = ofcResultPosition.find(channelID);
488// if (findResult != ofcResultPosition.end()) {
489// LArOFIterResultsContainer::const_iterator ofResult = findResult->second;
490// if (ofResult->getValid() && ofResult->getConverged())
491// data->setADCMax(ofResult->getAmplitude());
492// }
493// else
494// msg() << MSG::INFO << "OFResult for channel 0x" << MSG::hex << channelID << MSG::dec
495// << " not found. (size was " << ofcResultPosition.size() << ")" << endmsg;
496
497
498 const auto ramp=adc2MeV->ADC2MEV(channelID,gain); //dudu
499 data->setADCMax(rawChannel->energy()/ramp[1]); //pow(ADCPeak,i); //dudu
500
501
502 histCont->add(data);
503 }
504
505 if(m_doSC) {
506 std::map<unsigned int, const LArRawSC*> scToKeep;
507
509 if(!hdlSC.isValid()) {
510 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key " << m_rawscKey << " from EventStore. " );
511 return StatusCode::SUCCESS;
512 } else
513 ATH_MSG_DEBUG( "Got LArRawSCContainer with key " << m_rawscKey.key() );
514
515 if (hdlSC->empty()) {
516 ATH_MSG_WARNING ( "LArRawSCContainer with key=" << m_rawscKey.key() << " is empty!" );
517 return StatusCode::SUCCESS;
518 }
519
521 if(!hdlrecoSC.isValid()) {
522 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key " << m_rawRecomputedscKey << " from EventStore. " );
523 return StatusCode::SUCCESS;
524 } else
525 ATH_MSG_DEBUG( "Got LArRawSCContainer with key " << m_rawRecomputedscKey.key() );
526
527 if (hdlrecoSC->empty()) {
528 ATH_MSG_WARNING ( "LArRawSCContainer with key=" << m_rawRecomputedscKey.key() << " is empty!" );
529 return StatusCode::SUCCESS;
530 }
531
533 const LArOnOffIdMapping* cablingSC=*cablingHdl;
534 if(!cablingSC) {
535 ATH_MSG_ERROR( "Do not have cabling object LArOnOffIdMapping" );
536 return StatusCode::FAILURE;
537 }
538
540 ATH_CHECK(caloMgrHandle.isValid());
541 const CaloSuperCellDetDescrManager* caloMgrSC = *caloMgrHandle;
542
544 const ILArPedestal* pedestalsSC=*pedHdl;
545 if (!pedestals) {
546 ATH_MSG_ERROR("Failed to retrieve pedestal cond obj for SC");
547 return StatusCode::FAILURE;
548 }
549
550 std::map<unsigned int, std::pair<float, std::pair<float,float> > > channelsToKeepSC;
551
552 for (const LArRawSC* rawSC : *hdlSC) { // from bytestream
553
554 // is SC masked ?
555 if (m_bcMaskSC.cellShouldBeMasked(bcCont,rawSC->hardwareID())) continue;
556
557 const std::vector<unsigned short>& bcids = rawSC->bcids();
558 const std::vector<int>& energies = rawSC->energies();
559 const std::vector<bool>& satur = rawSC->satur();
560
561 // Look for bcid:
562 float scEne = 0;
563 float defValue = -99999999.;
564
565 const size_t nBCIDs = bcids.size();
566 size_t i = 0;
567 for (i = 0; i < nBCIDs && bcids[i] != bunchId; i++)
568 ;
569 if(i==nBCIDs) continue;
570 if (satur[i]) continue;
571
572 scEne = energies[i];
573 if (m_energyCutSC > 0 && TMath::Abs(scEne) < m_energyCutSC) continue;
574 if (m_bcMaskSC.cellShouldBeMasked(bcCont,rawSC->hardwareID())) continue;
575
576 IdentifierHash hash = m_onlineHelperSC->channel_Hash(rawSC->hardwareID());
577
578 if (!hash.is_valid()) {
579 ATH_MSG_FATAL ( "Found a LArRawSC whose HWIdentifier (" << rawSC->hardwareID()
580 << ") does not correspond to a valid hash -- returning StatusCode::FAILURE." );
581 return StatusCode::FAILURE;
582 }
583
584 channelsToKeepSC[hash] = std::make_pair(scEne, std::make_pair(defValue,defValue));
585
586 if (m_dumpChannelInfos) {
587 HistoryContainer* histCont = m_samples->hist_cont_sc(hash);
588 CellInfo* info = nullptr;
589 if (!histCont) {
590 HWIdentifier channelID = rawSC->hardwareID();
591 const Identifier id = cablingSC->cnvToIdentifier(channelID);
592 const CaloDetDescrElement* caloDetElement = caloMgrSC->get_element(id);
593 info = m_dumperToolSC->makeCellInfo(channelID, id, caloDetElement);
594 if (!info) continue;
595 m_samples->makeNewHistorySC(hash, info);
596 }
597 }
598 }
599 ATH_MSG_INFO("SC to keep in this event: "<<channelsToKeepSC.size());
600
601 for (const LArRawSC* rawSC : *hdlrecoSC) { //reconstructed
602
603 if (m_bcMaskSC.cellShouldBeMasked(bcCont,rawSC->hardwareID())) continue;
604 IdentifierHash hash = m_onlineHelperSC->channel_Hash(rawSC->hardwareID());
605 if (!hash.is_valid()) {
606 ATH_MSG_FATAL ( "Found a LArRawSC whose HWIdentifier (" << rawSC->hardwareID()
607 << ") does not correspond to a valid hash -- returning StatusCode::FAILURE." );
608 return StatusCode::FAILURE;
609 }
610
611 // do we keep this SC ?
612 if (channelsToKeepSC.find(hash) == channelsToKeepSC.end()) continue;
613
614 const std::vector<unsigned short>& bcids = rawSC->bcids();
615 const std::vector<int>& energies = rawSC->energies();
616 const std::vector<int>& tauenergies = rawSC->tauEnergies();
617
618 // Look for bcid:
619 float scEne = 0;
620 float scTim = -99999999.;
621
622 const size_t nBCIDs = bcids.size();
623 size_t i = 0;
624 for (i = 0; i < nBCIDs && bcids[i] != bunchId; i++)
625 ;
626 if(i==nBCIDs) continue;
627
628 scEne = energies[i];
629
630 if(tauenergies.size() && scEne != 0) scTim = tauenergies[i] / scEne;
631
632 channelsToKeepSC[hash].second = std::make_pair(scEne, scTim);
633
634 if (m_dumpChannelInfos) {
635 HistoryContainer* histCont = m_samples->hist_cont_sc(hash);
636 CellInfo* info = nullptr;
637 if (!histCont) {
638 HWIdentifier channelID = rawSC->hardwareID();
639 const Identifier id = cablingSC->cnvToIdentifier(channelID);
640 const CaloDetDescrElement* caloDetElement = caloMgrSC->get_element(id);
641 info = m_dumperToolSC->makeCellInfo(channelID, id, caloDetElement);
642 if (!info) continue;
643 m_samples->makeNewHistorySC(hash, info);
644 }
645 }
646 }
647
649 if(!hdlSCDigit.isValid()) {
650 ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key " << m_digitsKeySC << " from DetectorStore. " );
651 return StatusCode::SUCCESS;
652 } else
653 ATH_MSG_DEBUG( "Got LArDigitContainer with key " << m_digitsKeySC.key() );
654 const LArDigitContainer* larSCDigitContainer = &(*hdlSCDigit);
655
656 if (larSCDigitContainer->empty()) {
657 ATH_MSG_WARNING ( "LArDigitContainer with key=" << m_digitsKeySC.key() << " is empty!" );
659 return StatusCode::SUCCESS;
660 }
661
662 for (LArDigitContainer::const_iterator digit = larSCDigitContainer->begin();
663 digit != larSCDigitContainer->end(); ++digit)
664 {
665 //Check Energy selection
666 IdentifierHash hash = m_onlineHelperSC->channel_Hash((*digit)->channelID());
667
668 std::map<unsigned int, std::pair<float, std::pair<float,float> > >::const_iterator findChannel = channelsToKeepSC.find(hash);
669 if (findChannel == channelsToKeepSC.end()) continue;
670
671 // Check ADCMax selection
672 float pedestal = pedestalsSC->pedestal((*digit)->channelID(), 0);
673 if (m_minADCMaxSC > 0 ) {
674 const std::vector<short>& samples = (*digit)->samples();
675 double maxValue = -1;
676 for (short sample : samples)
677 if (sample - pedestal > maxValue) maxValue = sample - pedestal;
678 if (fabs(maxValue) < m_minADCMax) continue;
679 }
680
681 const Identifier id = cablingSC->cnvToIdentifier((*digit)->channelID());
682 const CaloDetDescrElement* caloDetElement = nullptr;
683
684 HistoryContainer* histCont = m_samples->hist_cont_sc(hash);
685 CellInfo* info = nullptr;
686 if (!histCont) {
687 if (!caloDetElement) caloDetElement = caloMgrSC->get_element(id);
688 info = m_dumperToolSC->makeCellInfo((*digit)->channelID(), id, caloDetElement);
689 if (!info) continue;
690 histCont = m_samples->makeNewHistorySC(hash, info);
691 }
692 else
693 info = histCont->cell_info();
694
695 if (!eventData) {
696 eventIndex = makeEvent(eventData, run, event, lumiBlock, bunchId); // this happens if doAllEvents is off
697 if (eventIndex < 0) return StatusCode::FAILURE;
698 }
699
701 new DataContainer((*digit)->gain(), (*digit)->samples(),
702 findChannel->second.first,
703 findChannel->second.second.second,
704 findChannel->second.second.first,
705 eventIndex,
707 -1, pedestal, 0, 0);
708
709
710 histCont->add(data);
711 }
712
713 } //m_doSC
714
715 return StatusCode::SUCCESS;
716}
717
718
720{
721 m_samples->addRun(m_runData.release());
722 return StatusCode::SUCCESS;
723}
724
725
727{
728 ATH_MSG_DEBUG ("in finalize() ");
729
730 if (m_prescale>1) ATH_MSG_INFO("Prescale dropped " << m_nPrescaledAway << "/" << m_count << " events");
731 if (m_onlyEmptyBC) ATH_MSG_INFO("Dropped " << m_nWrongBunchGroup << "/" << m_count << " events b/c of wrong bunch group");
732 ATH_MSG_INFO("Dropped " << m_nLArError << "/" << m_count << " Events b/c of LAr Veto (Noise burst or corruption)");
733
734
735 int n = 0;
736 for (unsigned int i = 0; i < m_samples->nChannels(); i++)
737 if (m_samples->historyContainer(i)) {
738 if (m_samples->historyContainer(i)->cellInfo() == nullptr)
739 ATH_MSG_INFO ( "Cell with no cellInfo at index " << i << " !!" );
740 //else if (m_samples->historyContainer(i)->cellInfo()->shape() == 0)
741 //msg() << MSG::INFO << "Cell with no ShapeInfo at index " << i << " !!" << endmsg;
742 //msg() << MSG::INFO << "Non-zero cell at index " << i << " " << m_samples->shape(i)->size() << endmsg;
743 n++;
744 }
745
746 //for (unsigned int i = 0; i < m_samples->nEvents(); i++) {
747 // msg() << MSG::INFO << "Event " << i << " = "
748 // << m_samples->eventData(i)->run() << " " << m_samples->eventData(i)->event()
749 // << "trigger = " << m_samples->eventData(i)->triggers() << ", nRoIs = " << m_samples->eventData(i)->nRoIs() << endmsg;
750 // }
751 ATH_MSG_INFO ( "Non-zero cells = " << n << ", footprint = " << m_samples->footprint() );
752 ATH_MSG_INFO ( "Writing..." );
753
754 if (!m_doStream) {
755 m_samples->writeTrees(m_fileName.c_str());
756/* TFile* f = TFile::Open(m_fileName.c_str(), "RECREATE");
757 msg() << MSG::INFO << "Writing (2)..." << endmsg;
758 f->WriteObjectAny(m_samples, "Container", "LArSamples");
759 msg() << MSG::INFO << "Closing..." << endmsg;
760 f->Close();
761 msg() << MSG::INFO << "Deleting..." << endmsg;
762 delete m_samples;*/
763 msg() << MSG::INFO << "Done!" << endmsg;
764 }
765
766 return StatusCode::SUCCESS;
767}
768
769
771 int run, int event,
772 int lumiBlock, int bunchXing) const
773{
774 std::vector<unsigned int> triggerWords;
775 if (m_doTrigger) {
776 const ROIB::RoIBResult* l1Result = nullptr;
777 if (evtStore()->retrieve(l1Result).isFailure() || !l1Result) {
778 ATH_MSG_FATAL ( "Could not retrieve RoIBResult!" );
779 return -1;
780 }
781 const std::vector<ROIB::CTPRoI> tav = l1Result->cTPResult().TAV();
782 for (const ROIB::CTPRoI& word : tav)
783 triggerWords.push_back(word.roIWord());
784
785 for (const std::pair<const TString, unsigned int>& p : m_runData->triggerConfig()) {
786 while (triggerWords.size() <= p.second/32) triggerWords.push_back(0);
787 if (m_trigDec->isPassed(p.first.Data())) {
788 triggerWords[p.second/32] |= (0x1 << (p.second % 32));
789 //msg() << MSG::INFO << "Trigger line " << p.first.Data() << " passed" << endmsg;
790 }
791 }
792 //msg() << MSG::INFO << "Trigger words : ";
793 //for (unsigned int i = 0; i < triggerWords.size(); i++) msg() << MSG::INFO << triggerWords[i] << " ";
794 //msg() << MSG::INFO << endmsg;
795 }
796
797 eventData = new EventData(event, 0, lumiBlock, bunchXing);
798 if (m_runData->run() == 0) m_runData->setRun(run);
799 eventData->setRunData(m_runData.get());
800 eventData->setTriggerData(triggerWords);
801 if (m_doRoIs) {
802 //msg() << MSG::INFO << "Filling RoI list" << endmsg;
803 for (const Trig::ChainGroup* group : m_triggerGroups) {
804 std::vector<Trig::Feature<TrigRoiDescriptor> > roIs = group->features().get<TrigRoiDescriptor>();
805 for (const Trig::Feature<TrigRoiDescriptor>& roI : roIs) {
806 //msg() << MSG::INFO << "Found an roi for chain ";
807 //for (unsigned int i = 0; i < group->getListOfTriggers().size(); i++) cout << group->getListOfTriggers()[i] << " ";
808 //cout << "@ " << roI.cptr()->eta() << ", " << roI.cptr()->phi() << ", TE = "
809 // << roI.te()->getId() << " " << Trig::getTEName(*roI.te()) << " with label " << roI.label() << endmsg;
810 eventData->addRoI(roI.cptr()->eta(), roI.cptr()->phi(), group->getListOfTriggers()[0].c_str(), roI.label().c_str());
811 //msg() << MSG::INFO << "nRoIs so far = " << eventData->nRoIs() << endmsg;
812 }
813 }
814 }
815 return m_samples->addEvent(eventData);
816}
#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.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
LArBadXCont< LArBadChannel > LArBadChannelCont
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
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:34
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 setTriggerData(const std::vector< unsigned int > &words)
Definition EventData.cxx:75
void addRoI(float eta, float phi, const char *name="", const char *label="")
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
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
virtual StatusCode execute() override
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:114
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ LARLOWGAIN
Definition CaloGain.h:18
@ LARNGAIN
Definition CaloGain.h:19
@ LARHIGHGAIN
Definition CaloGain.h:18
Definition run.py:1
EventInfo_v1 EventInfo
Definition of the latest event info version.