ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
10
12
13 ATH_CHECK(m_SCKey.initialize());
14 ATH_CHECK(m_factors.initialize());
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
24StatusCode 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 !!!!");
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define ATH_LIKELY(x)
static Double_t a
static Double_t sc
Header file for AthHistogramAlgorithm.
Container class for CaloCell.
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
bool hasCalo(const CaloCell_ID::SUBCALO caloNum) const
tell wether it has been filled with cells (maybe none) of a given calo
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
SG::ReadHandleKey< LArRawSCContainer > m_SCKey
Gaudi::Property< bool > m_testMode
virtual StatusCode finalize() override final
virtual StatusCode process(CaloCellContainer *cellCollection, const EventContext &ctx) const override final
virtual StatusCode initialize() override final
std::atomic< int > m_nWarnings
Gaudi::Property< int > m_scCut
SG::ReadCondHandleKey< LArDeadOTXCorrFactors > m_factors
std::map< HWIdentifier, std::vector< std::pair< IdentifierHash, float > > > payload_t
Container class for LArRawSC.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.