ATLAS Offline Software
LArNoisyROAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "LArNoisyROAlg.h"
7 
9 #include "CaloEvent/CaloCell.h"
10 #include "Identifier/Identifier.h"
17 
18 #include <cmath>
19 
20 LArNoisyROAlg::LArNoisyROAlg(const std::string &name,ISvcLocator *pSvcLocator):
21  AthReentrantAlgorithm (name, pSvcLocator),
22  m_noisyROTool("LArNoisyROTool",this)
23 {
25 }
26 
28  ATH_CHECK(m_noisyROTool.retrieve());
33  ATH_CHECK(m_knownBadFEBsVecKey.initialize(!m_isMC) );
34  ATH_CHECK(m_knownMNBFEBsVecKey.initialize(!m_isMC) );
38 
39  return StatusCode::SUCCESS;
40 }
41 
42 StatusCode LArNoisyROAlg::execute (const EventContext& ctx) const
43 {
45  if (!cellContainer.isValid()) {
46  ATH_MSG_WARNING( " Can not retrieve CaloCellContainer: " << m_CaloCellContainerName.key());
47  ATH_MSG_WARNING( " Empty object recorded !");
48 
49  const std::set<unsigned int> knownBadFEBs;
50  const std::vector<HWIdentifier> knownMNBFEBs;
52  ATH_CHECK(noisyRO.record(m_noisyROTool->process(ctx,nullptr, &knownBadFEBs, &knownMNBFEBs, nullptr, nullptr, nullptr)));
53 
54  return StatusCode::SUCCESS;
55  }
56 
57  const EventIDBase& EIHandle = ctx.eventID();
58  long int thisTimeStamp = (EIHandle).time_stamp();
59  long int thisTimeStampns = (EIHandle).time_stamp_ns_offset();
60  uint32_t thisLB = (EIHandle).lumi_block();
61  unsigned long long thisEv = (EIHandle).event_number();
62  ATH_MSG_DEBUG ( name() << " processing EN : " << thisEv << " in LB : " << thisLB << " TS : " << thisTimeStamp << " TSNS : " << thisTimeStampns );
63 
64  std::set<unsigned int> bf;
65  std::vector<HWIdentifier> MNBfeb;
66  const LArHVNMap* hvmap=nullptr;
67  const CaloDetDescrManager* cddm=nullptr;
68  const LArHVIdMapping* hvid=nullptr;
69  if (! m_isMC) {
71  const LArBadFebCont* badCont=*badHdl;
72  if(badCont) {
73  for(LArBadFebCont::BadChanVec::const_iterator i = badCont->begin(); i!=badCont->end(); ++i) {
74  bf.insert(i->first);
75  }
76  }
77 
79  const LArBadFebCont* MNBCont=*MNBHdl;
80  if(MNBCont) {
81  for(LArBadFebCont::BadChanVec::const_iterator i = MNBCont->begin(); i!=MNBCont->end(); ++i) {
82  MNBfeb.emplace_back(i->first);
83  }
84  }
85 
86  if(!m_hvMapKey.empty()) {
88  if(!hvMapHdl.isValid()) {
89  ATH_MSG_WARNING( " Can not retrieve HVline nCells: " << m_hvMapKey.key());
90  ATH_MSG_WARNING( " Will not flag HV lines noise !");
91  } else {
92  hvmap = *hvMapHdl;
93  }
94  }
95 
97  if(!cddmHdl.isValid()) {
98  ATH_MSG_WARNING( " Can not retrieve CaloDetDesrManager: " << m_caloDetDescrMgrKey.key());
99  ATH_MSG_WARNING( " Will not flag HV lines noise !");
100  } else {
101  cddm = *cddmHdl;
102  }
103 
104  if(!m_hvCablingKey.empty()){
106  if(!hvidHdl.isValid()) {
107  ATH_MSG_WARNING( " Can not retrieve LArHVIdMapping: " << m_hvCablingKey.key());
108  ATH_MSG_WARNING( " Will not flag HV lines noise !");
109  } else {
110  hvid = *hvidHdl;
111  }
112  }
113  }
114 
115  ATH_MSG_DEBUG("Number of known Bad FEBs: "<<bf.size());
116  ATH_MSG_DEBUG("Number of known MNB FEBs: "<<MNBfeb.size());
117 
118 
119 
121  ATH_CHECK(noisyRO.record(m_noisyROTool->process(ctx,cellContainer.cptr(), &bf, &MNBfeb, hvmap, cddm, hvid)));
122  ATH_MSG_DEBUG("Recorded LArNoisyROSummary with key: "<<m_outputKey.key());
123 
124 
125  bool badFEBFlag=noisyRO->BadFEBFlaggedPartitions();
126  bool badFEBFlag_W=noisyRO->BadFEB_WFlaggedPartitions();
127  bool badSaturatedTightCut=noisyRO->SatTightFlaggedPartitions();
128  bool MNBLooseCut=noisyRO->MNBLooseFlaggedPartitions();
129  bool MNBTightCut=noisyRO->MNBTightFlaggedPartitions();
130  bool MNBTight_PsVetoCut=noisyRO->MNBTight_PsVetoFlaggedPartitions();
131  bool badHVlinesFlag=noisyRO->HVlineFlaggedPartitions();
132 
134  if ( badFEBFlag || badFEBFlag_W || badSaturatedTightCut || MNBLooseCut || MNBTightCut || MNBTight_PsVetoCut || badHVlinesFlag )
135  {
136  // retrieve EventInfo
137  bool failSetWARN=false;
138  bool failSetWARNREASON=false;
139  // set warning flag except if the error flag has been already set
140  if ( eventInfo->errorState(xAOD::EventInfo::LAr) != xAOD::EventInfo::Error) {
141  if ( badFEBFlag ) {
142  failSetWARN |= (!eventInfo->updateErrorState(xAOD::EventInfo::LAr,xAOD::EventInfo::Warning));
143  failSetWARNREASON |= (!eventInfo->updateEventFlagBit(xAOD::EventInfo::LAr,LArEventBitInfo::BADFEBS));
144  }//endif badFEBFlag
145 
146  if ( badFEBFlag_W ) {
147  //Set WARNING Flag
148  failSetWARN |=(!eventInfo->updateErrorState(xAOD::EventInfo::LAr,xAOD::EventInfo::Warning));
149  // Set reason why event was flagged
150  failSetWARNREASON |=(!eventInfo->updateEventFlagBit(xAOD::EventInfo::LAr,LArEventBitInfo::BADFEBS_W));
151  }// end if badFEBFlag_W
152 
153  if ( badSaturatedTightCut ){
154  failSetWARNREASON |= (!eventInfo->updateEventFlagBit(xAOD::EventInfo::LAr,LArEventBitInfo::TIGHTSATURATEDQ));
155  }
156  }
157 
158  if ( MNBTightCut ) {
159  failSetWARN |=(!eventInfo->updateErrorState(xAOD::EventInfo::LAr,xAOD::EventInfo::Warning));
160  // Set reason why event was flagged
161  failSetWARNREASON |=(!eventInfo->updateEventFlagBit(xAOD::EventInfo::LAr,LArEventBitInfo::MININOISEBURSTTIGHT));
162  }
163 
164  if ( MNBTight_PsVetoCut ) {
165  failSetWARN |=(!eventInfo->updateErrorState(xAOD::EventInfo::LAr,xAOD::EventInfo::Warning));
166  // Set reason why event was flagged
167  failSetWARNREASON |=(!eventInfo->updateEventFlagBit(xAOD::EventInfo::LAr,LArEventBitInfo::MININOISEBURSTTIGHT_PSVETO));
168  }
169 
170  if ( MNBLooseCut ) { //FIXME Tight cut actually implies loose cut too
171  failSetWARNREASON |=(!eventInfo->updateEventFlagBit(xAOD::EventInfo::LAr,LArEventBitInfo::MININOISEBURSTLOOSE));
172  }
173 
174  if ( badHVlinesFlag ) {
175  failSetWARN |= (!eventInfo->updateErrorState(xAOD::EventInfo::LAr,xAOD::EventInfo::Warning));
176  failSetWARNREASON |= (!eventInfo->updateEventFlagBit(xAOD::EventInfo::LAr,LArEventBitInfo::BADHVLINES));
177  }//endif badFEBFlag
178 
179  if (failSetWARN) ATH_MSG_WARNING( "Failure during EventInfo::setEventErrorState(EventInfo::LAR,EventInfo::WARNING)" );
180  if (failSetWARNREASON) ATH_MSG_WARNING( "Failure during setEventFlagBit(EventInfo::LAr,...)" );
181 
182  }
183  return StatusCode::SUCCESS;
184 }
185 
187 {
188  return StatusCode::SUCCESS;
189 }
190 
LArNoisyROSummary::MNBTight_PsVetoFlaggedPartitions
uint8_t MNBTight_PsVetoFlaggedPartitions() const
Definition: LArNoisyROSummary.h:138
LArNoisyROAlg::m_CaloCellContainerName
SG::ReadHandleKey< CaloCellContainer > m_CaloCellContainerName
Definition: LArNoisyROAlg.h:55
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
LArHVNMap
Definition: LArHVNMap.h:14
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
LArNoisyROAlg::m_caloDetDescrMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloDetDescrMgrKey
Definition: LArNoisyROAlg.h:60
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LArNoisyROAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: LArNoisyROAlg.cxx:42
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArEventBitInfo::MININOISEBURSTTIGHT
@ MININOISEBURSTTIGHT
Definition: LArEventBitInfo.h:18
LArBadXCont
Conditions-Data class holding LAr Bad Channel or Bad Feb information.
Definition: LArBadChannelCont.h:28
LArEventBitInfo::BADHVLINES
@ BADHVLINES
Definition: LArEventBitInfo.h:20
LArNoisyROSummary::SatTightFlaggedPartitions
uint8_t SatTightFlaggedPartitions() const
Definition: LArNoisyROSummary.h:129
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:210
CaloCell.h
LArEventBitInfo::BADFEBS
@ BADFEBS
Definition: LArEventBitInfo.h:10
LArNoisyROAlg::initialize
virtual StatusCode initialize() override
Definition: LArNoisyROAlg.cxx:27
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
xAOD::EventInfo_v1::LAr
@ LAr
The LAr calorimeter.
Definition: EventInfo_v1.h:335
LArEventBitInfo.h
CaloCell_ID.h
xAOD::EventInfo_v1::Error
@ Error
The sub-detector issued an error.
Definition: EventInfo_v1.h:349
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
LArNoisyROAlg::m_outputKey
SG::WriteHandleKey< LArNoisyROSummary > m_outputKey
Definition: LArNoisyROAlg.h:56
LArNoisyROAlg.h
LArEventBitInfo::TIGHTSATURATEDQ
@ TIGHTSATURATEDQ
Definition: LArEventBitInfo.h:12
LArNoisyROSummary::MNBTightFlaggedPartitions
uint8_t MNBTightFlaggedPartitions() const
Definition: LArNoisyROSummary.h:135
LArEventBitInfo::MININOISEBURSTTIGHT_PSVETO
@ MININOISEBURSTTIGHT_PSVETO
Definition: LArEventBitInfo.h:19
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LArNoisyROAlg::m_hvMapKey
SG::ReadCondHandleKey< LArHVNMap > m_hvMapKey
Definition: LArNoisyROAlg.h:59
WriteDecorHandle.h
Handle class for adding a decoration to an object.
LArEventBitInfo::BADFEBS_W
@ BADFEBS_W
Definition: LArEventBitInfo.h:16
LArNoisyROSummary::MNBLooseFlaggedPartitions
uint8_t MNBLooseFlaggedPartitions() const
Definition: LArNoisyROSummary.h:132
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArBadXCont::const_iterator
BadChanVec::const_iterator const_iterator
Definition: LArBadChannelCont.h:33
LArNoisyROAlg::m_knownMNBFEBsVecKey
SG::ReadCondHandleKey< LArBadFebCont > m_knownMNBFEBsVecKey
Definition: LArNoisyROAlg.h:58
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LArNoisyROAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: LArNoisyROAlg.h:53
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LArNoisyROAlg::m_noisyROTool
ToolHandle< ILArNoisyROTool > m_noisyROTool
Definition: LArNoisyROAlg.h:50
LArEventBitInfo::MININOISEBURSTLOOSE
@ MININOISEBURSTLOOSE
Definition: LArEventBitInfo.h:17
LArNoisyROAlg::m_isMC
Gaudi::Property< bool > m_isMC
Definition: LArNoisyROAlg.h:52
LArNoisyROAlg::LArNoisyROAlg
LArNoisyROAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArNoisyROAlg.cxx:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LArNoisyROAlg::m_hvCablingKey
SG::ReadCondHandleKey< LArHVIdMapping > m_hvCablingKey
Definition: LArNoisyROAlg.h:61
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCellContainer.h
EventInfo.h
LArNoisyROAlg::m_knownBadFEBsVecKey
SG::ReadCondHandleKey< LArBadFebCont > m_knownBadFEBsVecKey
Definition: LArNoisyROAlg.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
xAOD::EventInfo_v1::Warning
@ Warning
The sub-detector issued a warning.
Definition: EventInfo_v1.h:348
LArHVIdMapping
Definition: LArHVIdMapping.h:21
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArNoisyROSummary::BadFEB_WFlaggedPartitions
uint8_t BadFEB_WFlaggedPartitions() const
Definition: LArNoisyROSummary.h:123
LArNoisyROAlg::m_eventInfoDecorKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_eventInfoDecorKey
Definition: LArNoisyROAlg.h:54
LArNoisyROSummary::HVlineFlaggedPartitions
uint8_t HVlineFlaggedPartitions() const
Definition: LArNoisyROSummary.h:141
LArNoisyROAlg::finalize
virtual StatusCode finalize() override
Definition: LArNoisyROAlg.cxx:186
CaloIdManager.h
LArBadXCont::begin
const_iterator begin() const
Access to the begin iterator of the underlying vector.
Definition: LArBadChannelCont.h:73
LArNoisyROSummary::BadFEBFlaggedPartitions
uint8_t BadFEBFlaggedPartitions() const
Definition: LArNoisyROSummary.h:120
LArBadXCont::end
const_iterator end() const
Access to the end iterator of the underlying vector.
Definition: LArBadChannelCont.h:76
LArOnlineID.h