ATLAS Offline Software
Loading...
Searching...
No Matches
LArSCvsRawChannelMonAlg.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
8#include "CaloDetDescr/CaloDetDescrElement.h"
10
12
13 ATH_CHECK(m_SCKey.initialize());
14 ATH_CHECK(m_RCKey.initialize());
15 ATH_CHECK(m_cablingKey.initialize());
16 ATH_CHECK(m_cablingSCKey.initialize());
17 ATH_CHECK(m_badChanKey.initialize());
18 ATH_CHECK(m_badSCKey.initialize());
19 ATH_CHECK(m_caloSuperCellMgrKey.initialize());
20 ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
21 ATH_CHECK(detStore()->retrieve(m_calo_id, "CaloCell_ID"));
22 ATH_CHECK(m_scidtool.retrieve());
23 ATH_CHECK(m_bcMask.buildBitMask(m_problemsToMask, msg()));
25
26 ATH_MSG_INFO("Building tool map");
28
30}
31
32struct MonValues {
33 float raw_eta;
34 float raw_phi;
35 float scEne;
36 float eneSum;
37 float eneFrac;
38};
39
40
41StatusCode LArSCvsRawChannelMonAlg::fillHistograms(const EventContext& ctx) const {
42
44 if (!cablingHdl.isValid()) {
45 ATH_MSG_ERROR("Do not have Onl-Ofl cabling map !!!!");
46 return StatusCode::FAILURE;
47 }
48
50 if (!cablingSCHdl.isValid()) {
51 ATH_MSG_ERROR("Do not have Onl-Ofl cabling map for SuperCells !!!!");
52 return StatusCode::FAILURE;
53 }
54
56 if (!scDetMgr.isValid()) {
57 ATH_MSG_ERROR("Do not have CaloSuperCellDetDescrManager !!!!");
58 return StatusCode::FAILURE;
59 }
60
62 if (!bcHdl.isValid()) {
63 ATH_MSG_ERROR("Do not have BadChannelContainer !!!!");
64 return StatusCode::FAILURE;
65 }
66 const LArBadChannelCont* bcCont = *bcHdl;
67
69 if (!bcSCHdl.isValid()) {
70 ATH_MSG_ERROR("Do not have BadSCContainer !!!!");
71 return StatusCode::FAILURE;
72 }
73 const LArBadChannelCont* bcSCCont = *bcSCHdl;
74
75 // get SuperCellContainer
77 if (!scHdl.isValid()) {
78 ATH_MSG_WARNING("Do not have LArRawSCContainer container with key" << m_SCKey.key());
79 return StatusCode::SUCCESS;
80 } else {
81 ATH_MSG_DEBUG("Reading SuperCell container with key " << m_SCKey.key() << ", size=" << scHdl->size());
82 }
83
84 // get regular LArRawChannel container
86 if (!scHdl.isValid()) {
87 ATH_MSG_WARNING("Do not have LArRawChannel container with key" << m_RCKey.key());
88 return StatusCode::SUCCESS;
89 } else {
90 ATH_MSG_DEBUG("Reading LArRawChannel container with key " << m_RCKey.key() << ", size=" << rcHdl->size());
91 }
92
93 const CaloBCIDAverage* bcidavgshift = nullptr;
94 if (!(m_caloBCIDAvg.key().empty())) {
96 bcidavgshift = bcidavgshiftHdl.cptr();
97 }
98
99 const unsigned int bcid = ctx.eventID().bunch_crossing_id();
100
101 std::vector<std::pair<Monitored::Scalar<float>, Monitored::Scalar<float> > > monVars;
102 for (int p = 0; p < MAXPARTITIONS; ++p) {
103 monVars.emplace_back(Monitored::Scalar<float>("scEne_" + m_partitionNames.value()[p], 0.0),
104 Monitored::Scalar<float>("eneSum_" + m_partitionNames.value()[p], 0.0));
105 }
106
107 std::vector<std::vector<MonValues>> MonValueVec(m_layerNames.size());
108
109 for (const LArRawSC* rawSC : *scHdl) {
110 const std::vector<unsigned short>& bcids = rawSC->bcids();
111 const std::vector<int>& energies = rawSC->energies();
112 const std::vector<bool>& satur = rawSC->satur();
113
114 // Look for bcid:
115 float scEne = 0;
116
117 const size_t nBCIDs = bcids.size();
118 size_t i = 0;
119 for (i = 0; i < nBCIDs && bcids[i] != bcid; i++)
120 ;
121 if (satur[i])
122 continue;
123
124 if (!bcSCCont->status(rawSC->hardwareID()).good())
125 continue;
126
127 scEne = energies[i];
128 if (scEne < m_scEneCut)
129 continue;
130 Identifier off_id = cablingSCHdl->cnvToIdentifier(rawSC->hardwareID());
131
132
133 const int iPart = getPartition(off_id);
134 if (iPart < 0) {
135 ATH_MSG_ERROR("Got unkonwn partition number " << iPart);
136 return StatusCode::FAILURE;
137 }
138 const std::vector<Identifier>& regularIDs = m_scidtool->superCellToOfflineID(off_id);
139 std::set<HWIdentifier> hwids;
140 for (const Identifier& id : regularIDs) {
141 hwids.insert(cablingHdl->createSignalChannelID(id));
142 }
143 // Loop over regular RawChannelContainer to find the relevant cells:
144 float eneSum = 0;
145 const size_t nChans = rcHdl->size();
146 bool hasBadChan = false;
147 for (size_t i = 0; i < nChans && !hwids.empty(); ++i) {
148 const LArRawChannel& rc = rcHdl->at(i);
149 if (hwids.contains(rc.hardwareID())) {
150 if (m_bcMask.cellShouldBeMasked(bcCont, rc.hardwareID())) {
151 hasBadChan = true;
152 break;
153 }
154
155 eneSum += rc.energy();
156 if (bcidavgshift)
157 eneSum -= bcidavgshift->average(rc.hardwareID());
158 hwids.erase(rc.hardwareID());
159 }
160 } // end loop over regular raw channels
161
162 if (hasBadChan) {
163 ATH_MSG_DEBUG("SuperCell with id 0x" << std::hex << off_id.get_identifier32().get_compact() << std::dec << " E[" << i << "]=" << scEne
164 << " is connected to at least one bad channel. Ignoring SC.");
165 continue;
166 }
167 if (!hwids.empty()) {
168 ATH_MSG_ERROR("SuperCell with id 0x" << std::hex << off_id.get_identifier32().get_compact() << std::dec << ": " << hwids.size()
169 << " attached regular RawChannels not found");
170 continue; // Ignore this supercell
171 }
172 const CaloDetDescrElement* scDDE = scDetMgr->get_element(off_id);
173 scEne *= 12.5 / scDDE->sinTh();
174 ATH_MSG_VERBOSE("SuperCell with id 0x" << std::hex << off_id.get_identifier32().get_compact() << std::dec << ", eta=" << scDDE->eta() << " E[" << i
175 << "]=" << scEne << " Sum of RC energies=" << eneSum << ", Ratio=" << (eneSum != 0 ? scEne / eneSum : 0.0));
176
177 if (m_warnOffenders && scEne > 15000 && eneSum < 5000) {
178 ATH_MSG_WARNING("SuperCell with id 0x" << std::hex << off_id.get_identifier32().get_compact() << std::dec << ", eta=" << scDDE->eta() << " E[" << i
179 << "]=" << scEne << " Sum of RC energies=" << eneSum);
180 }
181
182 float eneFrac = 0;
183 if ( eneSum != 0 and scEne != 0 ){
184 eneFrac = scEne / eneSum;
185 }
186
187
188 const float eta = scDDE->eta_raw();
189 const float phi = scDDE->phi_raw();
190 const int calosample=scDDE->getSampling();
191 const unsigned iLyrNS=m_caloSamplingToLyrNS[calosample];
192 const int side = m_onlineID->pos_neg(rawSC->hardwareID());
193 const unsigned iLyr=iLyrNS*2+side;
194
195 auto& lvaluemap = MonValueVec[iLyr];
196
197 ATH_MSG_DEBUG("Chan "<<rawSC->hardwareID()<<" "<<rawSC->SourceId()<<" "<<m_onlineID->channel_name(rawSC->hardwareID())<<" iPart "<<iPart<<" iLyrNS "<<iLyrNS<<" side "<<side<<" iLyr "<<iLyr<<" "<<m_layerNames[iLyr]<<" MAXP "<<MAXPARTITIONS<<" MAXL "<<MAXLYRNS);
198
199
200 auto& monPair = monVars[iPart];
201 monPair.first = scEne;
202 monPair.second = eneSum;
203
204
205 lvaluemap.emplace_back(eta, phi, scEne, eneSum, eneFrac);
206
207
208 fill(m_MonGroupName, monPair.first, monPair.second); //, monPairLyr.first, monPairLyr.second);
209 }
210
211
212 for (size_t ilayer = 0; ilayer < MonValueVec.size(); ++ilayer) {
213 const auto& tool = MonValueVec[ilayer];
214 auto part_eta = Monitored::Collection("part_eta",tool,[](const auto& v){return v.raw_eta;});
215 auto part_phi = Monitored::Collection("part_phi",tool,[](const auto& v){return v.raw_phi;});
216 auto part_scEne = Monitored::Collection("part_scEne",tool,[](const auto& v){return v.scEne;});
217 auto part_eneSum = Monitored::Collection("part_eneSum",tool,[](const auto& v){return v.eneSum;});
218 auto part_eneFrac = Monitored::Collection("part_eneFrac",tool,[](const auto& v){return v.eneFrac;});
219
221 part_eta, part_phi, part_scEne, part_eneSum, part_eneFrac);
222
223 }
224
225
226 return StatusCode::SUCCESS;
227}
228
230 const int s = m_calo_id->calo_sample(id);
231
232 // PreSamplerB=0, EMB1, EMB2, EMB3, PreSamplerE, EME1, EME2, EME3, HEC0, HEC1,
233 // HEC2, HEC3, TileBar0, TileBar1, TileBar2,TileGap1, TileGap2, TileGap3,
234 // TileExt0, TileExt1, TileExt2, FCAL0, FCAL1, FCAL2, MINIFCAL0, MINIFCAL1,
235 // MINIFCAL2, MINIFCAL3,
236 constexpr std::array<int, CaloSampling::getNumberOfSamplings()> samplingToPartitonMap{
237 0, 0, 0, 0, // Barrel BS to EMB3
238 2, 2, 2, 2, // EMEC PS to EME3
239 4, 4, 4, 4, // HEC0 to HEC3
240 -1, -1, -1, // TileBar0 - 2 (ignored)
241 -1, -1, -1, // Tile Gap 0 -2 (ignored)
242 -1, -1, -1, // TIleExt0 0-2 (ignored)
243 6, 6, 6, // FCAL 0-2
244 -1, -1, -1, -1 // MiniFCAL0-3 (ignored)
245 };
246
247 const int pNoSide = samplingToPartitonMap[s];
248 if (ATH_UNLIKELY(pNoSide < 0)) {
249 return MAXPARTITIONS;
250 }
251
252 return (m_calo_id->pos_neg(id) < 0) ? pNoSide + 1 : pNoSide;
253}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#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_UNLIKELY(x)
LArBadXCont< LArBadChannel > LArBadChannelCont
static Double_t rc
const ServiceHandle< StoreGateSvc > & detStore() const
virtual StatusCode initialize() override
initialize
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
float average(const Identifier &id) const
This class groups all DetDescr information related to a CaloCell.
float sinTh() const
for algorithm working in transverse Energy
CaloCell_ID::CaloSample getSampling() const
cell sampling
static constexpr unsigned int getNumberOfSamplings()
Get number of available samplings.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
bool good() const
Returns true if no problems at all (all bits at zero)
LArBC_t status(const HWIdentifier channel) const
Query the status of a particular channel or FEB This is the main client access method.
Liquid Argon ROD output object base class.
Liquid Argon SuperCell raw data.
Definition LArRawSC.h:19
SG::ReadHandleKey< LArRawChannelContainer > m_RCKey
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
StringArrayProperty m_partitionNames
Gaudi::Property< bool > m_warnOffenders
int getPartition(const Identifier &scid) const
SG::ReadHandleKey< CaloBCIDAverage > m_caloBCIDAvg
std::map< std::string, int > m_toolmapPerLayer
SG::ReadCondHandleKey< LArBadChannelCont > m_badChanKey
const std::array< unsigned, CaloSampling::Unknown > m_caloSamplingToLyrNS
virtual StatusCode initialize() override final
initialize
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingSCKey
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSuperCellMgrKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Gaudi::Property< int > m_scEneCut
SG::ReadCondHandleKey< LArBadChannelCont > m_badSCKey
SG::ReadHandleKey< LArRawSCContainer > m_SCKey
Gaudi::Property< std::vector< std::string > > m_problemsToMask
Gaudi::Property< std::string > m_MonGroupName
ToolHandle< ICaloSuperCellIDTool > m_scidtool
Declare a monitored scalar variable.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case)
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
void fill(H5::Group &out_file, size_t iterations)