ATLAS Offline Software
Loading...
Searching...
No Matches
RpcCondDbAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "RpcCondDbAlg.h"
6
8
9namespace Muon{
10// Initialize
12 ATH_MSG_DEBUG("initializing " << name());
13 ATH_CHECK(m_idHelperSvc.retrieve());
14 ATH_CHECK(m_writeKey.initialize());
16 return StatusCode::SUCCESS;
17}
18
19template <class WriteCont>
20 StatusCode RpcCondDbAlg::addCondDependency(const EventContext& ctx,
22 SG::WriteCondHandle<WriteCont>& writeHandle) const {
23 if (key.empty()) {
24 return StatusCode::SUCCESS;
25 }
26 SG::ReadCondHandle<CondAttrListCollection> readCondHandle{key, ctx};
27 ATH_CHECK(readCondHandle.isValid());
28 writeHandle.addDependency(readCondHandle);
29 return StatusCode::SUCCESS;
30 }
31
32// execute
33StatusCode RpcCondDbAlg::execute(const EventContext& ctx) const {
34 ATH_MSG_DEBUG("execute " << name());
35
36 // launching Write Cond Handle
38 if (writeHandle.isValid()) {
39 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
40 << " In theory this should not be called, but may happen"
41 << " if multiple concurrent events are being processed out of order.");
42 return StatusCode::SUCCESS;
43 }
46
47 std::unique_ptr<RpcCondDbData> writeCdo{std::make_unique<RpcCondDbData>()};
48 // data and MC
49 ATH_CHECK(loadMcElementStatus(ctx, *writeCdo));
50
51 ATH_CHECK(writeHandle.record(std::move(writeCdo)));
52 ATH_MSG_DEBUG("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
53
54 return StatusCode::SUCCESS;
55}
56// loadMcElementStatus
57StatusCode RpcCondDbAlg::loadMcElementStatus(const EventContext& ctx, RpcCondDbData& writeCdo) const {
59 ATH_CHECK(readCdo.isValid());
60
61 ATH_MSG_DEBUG("Size of CondAttrListCollection " << readCdo.fullKey() << " readCdo->size()= " << readCdo->size());
62
64 unsigned int chan_index = 0;
65 unsigned int iFracDeadStrip = 0;
66 for (itr = readCdo->begin(); itr != readCdo->end(); ++itr) {
67 const coral::AttributeList& atr = itr->second;
68 CondAttrListCollection::ChanNum channum = itr->first;
69 Identifier chamberId = Identifier(channum);
70
71 std::string eff_panel, striplist, eff;
72
73 eff_panel = *(static_cast<const std::string*>((atr["PanelRes"]).addressOfData()));
74 striplist = *(static_cast<const std::string*>((atr["StripStatus"]).addressOfData()));
75
76 ATH_MSG_DEBUG("-----------------------------entry #" << chan_index);
77 ATH_MSG_DEBUG("channel ID = Panel ID " << channum << " as identif. = " << m_idHelperSvc->toString(chamberId));
78 ATH_MSG_DEBUG("eff_panel load is " << eff_panel);
79 ATH_MSG_DEBUG("striplist load is " << striplist << " " << striplist.size());
80
81 // Efficiencies and Cluster Sizes
82 constexpr std::string_view delimiter{" "};
83 const auto info_panel = CxxUtils::tokenize(eff_panel, delimiter);
84
85 int DBversion = CxxUtils::atoi(info_panel[0]);
86
87 int npanelstrip = CxxUtils::atoi(info_panel[2]);
88
89 double ProjectedTracks = CxxUtils::atof(info_panel[1]);
90 writeCdo.setProjectedTrack(chamberId, ProjectedTracks);
91
92 double Efficiency = CxxUtils::atof(info_panel[3]);
93 writeCdo.setEfficiency(chamberId, Efficiency);
94
95
96 double GapEfficiency = CxxUtils::atof(info_panel[5]);
97 writeCdo.setGapEfficiency(chamberId, GapEfficiency);
98
99 double MeanClusterSize = CxxUtils::atof(info_panel[17]);
100 writeCdo.setMeanClusterSize(chamberId, MeanClusterSize);
101
102 if (DBversion > 2) {
103 double FracClusterSize1 = CxxUtils::atof(info_panel[19]) + CxxUtils::atof(info_panel[20]) * 10000;
104 writeCdo.setFracClusterSize1(chamberId, FracClusterSize1);
105
106 double FracClusterSize2 = CxxUtils::atof(info_panel[21]) + CxxUtils::atof(info_panel[22]) * 10000;
107 writeCdo.setFracClusterSize2(chamberId, FracClusterSize2);
108 } else {
109 if (info_panel.size() > 20) {
110 double FracClusterSize1 = CxxUtils::atof(info_panel[19]);
111 writeCdo.setFracClusterSize1(chamberId, FracClusterSize1);
112
113 double FracClusterSize2 = CxxUtils::atof(info_panel[20]);
114 writeCdo.setFracClusterSize2(chamberId, FracClusterSize2);
115 } else {
116 writeCdo.setFracClusterSize1(chamberId, 0.6);
117 writeCdo.setFracClusterSize2(chamberId, 0.2);
118 ATH_MSG_DEBUG("Panel with incomplete info in the DB, size = " << info_panel.size() << " instead of required >20");
119 ATH_MSG_DEBUG("PanelId = " << channum << " = " << m_idHelperSvc->toString(chamberId));
120 ATH_MSG_DEBUG("Cluster Size 1 and 2 fractions are set to 0.6 and 0.2 for this chamber.");
121 }
122 }
123
124 // strip status
125 // n chars = #strips (status between 0--9)
126 int countdeadstrip = 0;
127 int countdeadstripinfidarea = 0;
128 int countpanelstrip = 0;
129
130 // update for the timing and error on timing
131 // new info strip |status time error_on_time|
132 constexpr std::string_view delimiter_strip{"|"};
133
134
135 const auto info_strip= CxxUtils::tokenize(striplist, delimiter_strip);
136 if (info_strip.size() > 1) {
137 for (unsigned int i = 0; i < info_strip.size(); ++i) {
138 const std::string &ch_strip2 = info_strip[i];
139
140 constexpr std::string_view delimiter_strip2{" "};
141
142 auto info_strip2 = CxxUtils::tokenize(ch_strip2, delimiter_strip2);
143
144 double Time = CxxUtils::atof(info_strip2[1]);
145 double SigmaTime = CxxUtils::atof(info_strip2[2]);
146 const auto &strip_status = info_strip2[0];
147
148
149 Identifier strip_id;
151 stripnum = channum + i * 4;
152 strip_id = channum + i * 4;
153
154 ATH_MSG_DEBUG("strip " << strip_id << " has time " << Time << " and " << SigmaTime);
155
156 writeCdo.setStripTime(strip_id, std::vector<double>{Time, SigmaTime});
157
158 ATH_MSG_VERBOSE("strip #" << i + 1 << " strip_id " << stripnum << " expanded "
159 << m_idHelperSvc->toString(strip_id));
160
161 ++countpanelstrip;
162
163 if (strip_status[0] == '0') {
164 ++countdeadstrip;
165 if (i > 1 && i < info_strip.size() - 2) {
166 // strip in the fiducial area for the efficiency measurement
167 ++countdeadstripinfidarea;
168 }
169 }
170 }
171 } else {
172 ATH_MSG_DEBUG("no timing info");
173
174 for (unsigned int i = 0; i < striplist.size(); i++) {
175 char part_strip = striplist[i];
176
177 char ch_panel = part_strip;
178
179
180 CondAttrListCollection::ChanNum stripnum = channum + i * 4;
181 Identifier strip_id{channum + i * 4};
182
183 ATH_MSG_VERBOSE("strip #" << i + 1 << " info_strip " << part_strip << " strip_id " << stripnum << " expanded "
184 << m_idHelperSvc->toString(strip_id) << " panel = " << ch_panel);
185
186 ++countpanelstrip;
187
188 if (part_strip == '0') {
189 ++countdeadstrip;
190 if (i > 1 && i < striplist.size() - 2) {
191 // strip in the fiducial area for the efficiency measurement
192 ++countdeadstripinfidarea;
193 }
194 }
195 }
196 }
197
198 if (countpanelstrip != npanelstrip)
200 "WARNING (no side effects for this, just a reminder for a proper fix of the DB content) no matching strip number!!! "
201 << countpanelstrip << " != " << npanelstrip << " Identifier: " << channum);
202
203 float FracDeadStripMap = 0;
204 if (countpanelstrip - 4 > 0) FracDeadStripMap = float(countdeadstripinfidarea) / float(countpanelstrip - 4);
205
206 // store in the suitabel maps
207 writeCdo.setFracDeadStrip(chamberId, FracDeadStripMap);
208 ++iFracDeadStrip;
209
210 std::stringstream ss;
211 if (msgLvl(MSG::DEBUG)) {
212 ss << "Size of RPC_PanelFracDeadStripMap " << iFracDeadStrip << "; in panel ";
213 ss << channum << " FracDeadStri(in fid.area) " << FracDeadStripMap << " (incl. borders) ";
214 if (countpanelstrip == 0)
215 ss << "DIVISION BY ZERO IMPOSSIBLE";
216 else
217 ss << float(countdeadstrip) / float(countpanelstrip);
218 ss << " nDeadStrips,InFidArea/nStrips " << countdeadstrip << ",";
219 ss << countdeadstripinfidarea << "/" << countpanelstrip;
220 ATH_MSG_DEBUG(ss.str());
221 }
222
223 ATH_MSG_DEBUG("Efficiency is " << Efficiency << " and fraction is " << FracDeadStripMap << " and thus "
224 << Efficiency - (0.99 - FracDeadStripMap));
225
226 if (msgLvl(MSG::DEBUG) && Efficiency - (0.99 - FracDeadStripMap) > 0. &&
227 (Efficiency < 0.995 || FracDeadStripMap > 0.01) && (Efficiency > 0.005 || FracDeadStripMap < 0.99)) {
228 std::stringstream msg;
229 msg << "WARNING: Inconsistent panel eff.=" << Efficiency << " and 0.99-dead_frac=" << 0.99 - FracDeadStripMap
230 << " nDeadStrips,InFidArea/nStrips " << countdeadstrip << "," << countdeadstripinfidarea << "/" << countpanelstrip
231 << " for panelId=" << m_idHelperSvc->toString(chamberId);
232 if (Efficiency - (0.99 - FracDeadStripMap) > 0.2)
233 msg << " difference >0.2";
234 else if (Efficiency - (0.99 - FracDeadStripMap) > 0.1)
235 msg << " difference >0.1";
236 else if (Efficiency - (0.99 - FracDeadStripMap) > 0.05)
237 msg << " difference >0.05";
238 else if (Efficiency - (0.99 - FracDeadStripMap) > 0.025)
239 msg << " difference >0.025";
240 else if (Efficiency - (0.99 - FracDeadStripMap) > 0.01)
241 msg << " difference >0.01";
242 else
243 msg << " difference >0 but <=0.01";
244 ATH_MSG_DEBUG(msg.str());
245 }
246
247 }
248 return StatusCode::SUCCESS;
249}
250}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t ss
bool msgLvl(const MSG::Level lvl) const
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
StatusCode addCondDependency(const EventContext &ctx, const SG::ReadCondHandleKey< CondAttrListCollection > &key, SG::WriteCondHandle< WriteCont > &writeHandle) const
StatusCode loadMcElementStatus(const EventContext &ctx, RpcCondDbData &condData) const
SG::WriteCondHandleKey< RpcCondDbData > m_writeKey
virtual StatusCode execute(const EventContext &) const override
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_folder_mc_deadElements
virtual StatusCode initialize() override
void setEfficiency(Identifier, double)
void setFracDeadStrip(Identifier, double)
void setFracClusterSize1(Identifier, double)
void setProjectedTrack(Identifier, int)
void setGapEfficiency(Identifier, double)
void setMeanClusterSize(Identifier, double)
void setFracClusterSize2(Identifier, double)
void setStripTime(Identifier, const std::vector< double > &)
const DataObjID & fullKey() const
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
std::string eff_panel[4][6]
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
double atof(std::string_view str)
Converts a string into a double / float.
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
a structure to hold an efficiency together with a variable number of uncertainties