ATLAS Offline Software
LArCelldeadOTXTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "LArCelldeadOTXTool.h"
6 
7 #include "CaloEvent/CaloCell.h"
10 
12 
15 
16  if (m_testMode) {
18  "Test mode activated with additional debug output. Makes only sense if we try to patch a FEB that is actually there, so we have a reference");
19  }
20 
21  return StatusCode::SUCCESS;
22 }
23 
24 StatusCode LArCelldeadOTXTool::process(CaloCellContainer* cellCollection, const EventContext& ctx) const {
25 
26  ATH_MSG_VERBOSE(" in process...");
27  if (!cellCollection) {
28  ATH_MSG_ERROR("Cell Correction tool receives invalid cell Collection");
29  return StatusCode::FAILURE;
30  }
31 
32  if (!(cellCollection->hasCalo(CaloCell_ID::LAREM) ||
33  cellCollection->hasCalo(CaloCell_ID::LARHEC) ||
34  cellCollection->hasCalo(CaloCell_ID::LARFCAL))) {
35  ATH_MSG_VERBOSE("No LAr cell in CellContainer. Do nothing");
36  return StatusCode::SUCCESS;
37  }
38 
40  const LArDeadOTXCorrFactors::payload_t& scToDead=scToDeadHdl->get();
41  if (scToDead.empty()) {
42  return StatusCode::SUCCESS; // No dead FEBs, do nothing
43  }
44 
45  // get SuperCellContainer
47  if (!scHdl.isValid()) {
48  if (msgLvl(MSG::WARNING) && m_nWarnings < 5) {
49  ATH_MSG_WARNING("Do not have SuperCell container no patching !!!!");
50  ++m_nWarnings;
51  }
52  return StatusCode::SUCCESS;
53  }
54 
55  const unsigned int bcid = ctx.eventID().bunch_crossing_id();
56 
57  // get the SC, container is unordered, so have to loop
58  const LArRawSCContainer* scells = scHdl.cptr();
59  for (const auto* sc : *scells) {
60  if (!sc)
61  continue;
62  const HWIdentifier scHwid = sc->hardwareID();
63  auto itr = scToDead.find(scHwid);
64  if (itr == scToDead.end())
65  continue; // This SC is not connected to any deadFEB cell
66 
67  const std::vector<unsigned short>& bcids = sc->bcids();
68  const std::vector<int>& energies = sc->energies();
69  const std::vector<bool>& satur = sc->satur();
70 
71  // Look for bcid:
72  float scEne = 0;
73  const size_t nBCIDs = bcids.size();
74  size_t i = 0;
75  for (i = 0; i < nBCIDs && bcids[i] != bcid; i++)
76  ;
77 
78  if (ATH_LIKELY(!satur[i]))
79  scEne = energies[i];
80  if (scEne < m_scCut) {
81  ATH_MSG_VERBOSE("SuperCell value " << scEne << " below threshold, ignoring");
82  continue;
83  }
84  float cellESum = 0;
85  float patchEneSum = 0;
86  for (const auto& [h, convFactor] : itr->second) { // Loop over all deadFEB cells connected to this SC
87  CaloCell* cell = cellCollection->findCell(h);
88  if (cell) {
89  const float patchEne = scEne * convFactor; // Convert ET (coming from LATOMEs) into Energy
90  if (m_testMode) {
91  cellESum += cell->energy();
92  patchEneSum += patchEne;
93  }
94  ATH_MSG_DEBUG("Cell id 0x" << std::hex << cell->ID().get_identifier32().get_compact() << " Replacing energy " << cell->energy() << " " << patchEne
95  << ", SCene=" << scEne);
96  cell->setEnergy(patchEne);
97  cell->setProvenance(cell->provenance() | LArProv::PATCHED);
98  } // end if cell obj found
99  } // end loop over all deadFEB cells connected to this SC
100  if (m_testMode) {
101  const float ratio = patchEneSum != 0 ? cellESum / patchEneSum : 0;
102  ATH_MSG_DEBUG("ESums=" << cellESum << "/" << patchEneSum << "=" << ratio);
103  std::scoped_lock l(m_mtx);
104  auto& entry = m_testMap[scEne];
105  entry.first += ratio;
106  entry.second++;
107  } // end if testMode
108  } // End loop over SuperCell container
109 
110  return StatusCode::SUCCESS;
111 }
112 
113 
115  if (m_testMode) {
116  ATH_MSG_INFO("Test mode for cell-patching:");
117  std::vector<std::pair<float, float> > avgList;
118  for (auto& [scEne, entry] : m_testMap) {
119  avgList.emplace_back(scEne, entry.first / entry.second);
120  }
121  auto ordering = [](const std::pair<float, float>& a, std::pair<float, float>& b) { return (a.first < b.first); };
122  std::sort(avgList.begin(), avgList.end(), ordering);
123  for (auto& p : avgList) {
124  ATH_MSG_INFO("SCEne=" << p.first << "Avg patching ratio=" << p.second);
125  }
126  }
127  return StatusCode::SUCCESS;
128 }
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:43
LArCelldeadOTXTool::m_scCut
Gaudi::Property< int > m_scCut
Definition: LArCelldeadOTXTool.h:32
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
LArRawSCContainer
Container class for LArRawSC.
Definition: LArRawSCContainer.h:17
CaloCell.h
CaloCell_Base_ID::LARHEC
@ LARHEC
Definition: CaloCell_Base_ID.h:43
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
LArCelldeadOTXTool::process
virtual StatusCode process(CaloCellContainer *cellCollection, const EventContext &ctx) const override final
Definition: LArCelldeadOTXTool.cxx:24
LArCelldeadOTXTool::finalize
virtual StatusCode finalize() override final
Definition: LArCelldeadOTXTool.cxx:114
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
HWIdentifier
Definition: HWIdentifier.h:13
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LArCelldeadOTXTool::m_SCKey
SG::ReadHandleKey< LArRawSCContainer > m_SCKey
Definition: LArCelldeadOTXTool.h:30
LArDeadOTXCorrFactors::payload_t
std::map< HWIdentifier, std::vector< std::pair< IdentifierHash, float > > > payload_t
Definition: LArDeadOTXCorrFactors.h:19
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
LArCelldeadOTXTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArProv::PATCHED
@ PATCHED
Definition: LArProvenance.h:21
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
LArCelldeadOTXTool::m_testMode
Gaudi::Property< bool > m_testMode
Definition: LArCelldeadOTXTool.h:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LArCelldeadOTXTool::m_nWarnings
std::atomic< int > m_nWarnings
Definition: LArCelldeadOTXTool.h:38
CaloCellContainer::findCell
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
Definition: CaloCellContainer.cxx:345
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
ATH_LIKELY
#define ATH_LIKELY(x)
Definition: AthUnlikelyMacros.h:16
LArCelldeadOTXTool::m_mtx
std::mutex m_mtx
Definition: LArCelldeadOTXTool.h:36
a
TList * a
Definition: liststreamerinfos.cxx:10
h
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:294
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArProvenance.h
LArCelldeadOTXTool::m_factors
SG::ReadCondHandleKey< LArDeadOTXCorrFactors > m_factors
Definition: LArCelldeadOTXTool.h:31
CaloCellContainer::hasCalo
bool hasCalo(const CaloCell_ID::SUBCALO caloNum) const
tell wether it has been filled with cells (maybe none) of a given calo
Definition: CaloCellContainer.cxx:209
CaloCell_Base_ID::LAREM
@ LAREM
Definition: CaloCell_Base_ID.h:43
hist_file_dump.ordering
ordering
Definition: hist_file_dump.py:85
LArCelldeadOTXTool::initialize
virtual StatusCode initialize() override final
Definition: LArCelldeadOTXTool.cxx:11