ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellMaskingTool.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// Gaudi includes
6#include "GaudiKernel/Service.h"
7#include "Gaudi/Property.h"
8
9// Atlas includes
11
12// Calo includes
15
16// Tile includes
20#include "TileEvent/TileCell.h"
21
22#include <CLHEP/Units/SystemOfUnits.h>
23
24using CLHEP::MeV;
25
27 , const std::string& name, const IInterface* parent)
28 : AthAlgTool(type, name, parent)
29 , m_tileID(0)
30 , m_tileHWID(0)
31{
32 declareInterface<ICaloCellMakerTool>( this );
33
34 declareProperty("RejectedTileDrawer", m_rejectedTileDrawer) ;
35 declareProperty("RejectedTileMB", m_rejectedTileMB) ;
36 declareProperty("RejectedTileDigitizer", m_rejectedTileDigitizer) ;
37 declareProperty("RejectedTileDMU", m_rejectedTileDMU) ;
38 declareProperty("RejectedTileChannels", m_rejectedTileChannels) ;
39
40 declareProperty("BadChannelZeroEnergy",m_zeroEnergy = 0.5 * MeV); // half a MeV in both PMTs i.e. one MeV in a cell
41}
42
44
46
47 ATH_MSG_DEBUG( " TileCellMaskingTool called " );
48
49 CHECK( detStore() -> retrieve(m_tileID, "TileID") );
50 CHECK( detStore() -> retrieve(m_tileHWID, "TileHWID") );
51
53 ATH_MSG_DEBUG( " Will exclude "
54 << m_includedCellsMap.size() - m_includedCellsMap.count()
55 << " channels " );
56
57 return StatusCode::SUCCESS;
58}
59
61
63
65
66 int ros = 0, drw = 0, index = -1;
67
68 for (const std::string& dr : m_rejectedTileDrawer) {
69 std::stringstream dris;
70 dris << dr;
71 dris >> ros >> drw;
72 killer("drawer", ros, drw, index);
73 }
74
75 for (const std::string& mb : m_rejectedTileMB) {
76 std::stringstream dris;
77 dris << mb;
78 dris >> ros >> drw >> index;
79 killer("mb", ros, drw, index);
80 }
81
82 for (const std::string& dig : m_rejectedTileDigitizer) {
83 std::stringstream dris;
84 dris << dig;
85 dris >> ros >> drw >> index;
86 killer("dig", ros, drw, index);
87 }
88
89 for (const std::string& dmu : m_rejectedTileDMU) {
90 std::stringstream dris;
91 dris << dmu;
92 dris >> ros >> drw >> index;
93 killer("dmu", ros, drw, index);
94 }
95
96 for (const std::string& chan : m_rejectedTileChannels) {
97 std::stringstream dris;
98 dris << chan;
99 dris >> ros >> drw >> index;
100 killer("channel", ros, drw, index);
101 }
102
103 return StatusCode::SUCCESS;
104}
105
107
108void TileCellMaskingTool::killer(std::string_view component, int ros, int drw, int index) {
109
110 int begin = 0, end = 0;
111
112 if (component == "drawer") {
113 begin = 0;
114 end = 48;
115 } else if (component == "mb") {
116 begin = (4 - index) * 12;
117 end = begin + 12;
118 } else if (component == "dig") {
119 begin = (8 - index) * 6;
120 end = begin + 6;
121 } else if (component == "dmu") {
122 begin = index * 3;
123 end = begin + 3;
124 } else {
125 begin = index;
126 end = begin + 1;
127 }
128
129 if (ros < 1 || ros > 4) {
130 ATH_MSG_WARNING( " wrong selection of ros = " << ros << " in TileCellMaskingTool::killer ");
131 } else if (drw < 0 || drw > 63) {
132 ATH_MSG_WARNING( " wrong selection of drawer = " << drw << " in TileCellMaskingTool::killer ");
133 } else if (begin < 0 || end > 48) {
134 ATH_MSG_WARNING( " wrong selection of "<< component
135 << " = " << index << " in TileCellMaskingTool::killer ");
136 } else {
137 msg(MSG::INFO) << " killing ros " << ros << " drawer " << drw;
138 if (component != "drawer") {
139 msg(MSG::INFO) << component << " " << index << endmsg;
140 } else {
141 msg(MSG::INFO) << endmsg;
142 }
143
144 for (int channel = begin; channel < end; ++channel) {
145 HWIdentifier chid = m_tileHWID->channel_id(ros, drw, channel);
146 IdentifierHash hash = m_tileHWID->get_channel_hash(chid);
147 m_includedCellsMap.reset(hash);
148 ATH_MSG_DEBUG( "deleting channel " << m_tileHWID->to_string(chid,-1)
149 << " hash " << hash );
150 }
151 }
152}
153
155
157 const EventContext& /*ctx*/) const
158{
159 int n_cells = 0, n_masked_1 = 0, n_masked_2 = 0, n_masked_12 = 0;
160 double ene_before = 0.0, ene_after = 0.0;
161
162 size_t firstCell = theCont->indexFirstCellCalo(CaloCell_ID::TILE);
163 size_t lastCell = theCont->indexLastCellCalo(CaloCell_ID::TILE);
164
165 for (size_t iCell = firstCell; iCell <= lastCell; ++iCell) {
166
167 CaloCell* aCell = (*theCont)[iCell];
168 const CaloDetDescrElement * caloDDE = aCell->caloDDE();
169
170 if (caloDDE->is_tile()) { // check if cell belongs to TileCalorimeter
171
172 if (msgLvl(MSG::DEBUG)) {
173 ++n_cells;
174 ene_before += aCell->energy();
175 }
176
177 IdentifierHash hash1 = caloDDE->onl1();
178 IdentifierHash hash2 = caloDDE->onl2();
179
180 bool bit1 = m_includedCellsMap.test(hash1); // true - good channel
181 bool bit2 = m_includedCellsMap.test(hash2); // false - channel should be masked
182
183 TileCell* pCell = static_cast<TileCell*>(aCell);
184 int gain1 = pCell->gain1();
185 int gain2 = pCell->gain2();
186
187 if (bit1) { // first is good
188
189 if (!bit2) { // second is bad
190
191 if (msgLvl(MSG::DEBUG)) {
192 ++n_masked_12;
193 if (msgLvl(MSG::VERBOSE)) {
194 msg(MSG::VERBOSE) << " second channel is OFF"
195 << ", hash2: " << hash2
196 << " before " << pCell->ene1()
197 << " + " << pCell->ene2()
198 << " = " << pCell->energy();
199 }
200 }
201
202 float ene1 = pCell->ene1();
203 pCell->setEnergy(ene1, ene1, gain1, gain1); // use energy/gain from first pmt for both pmts
204 pCell->setTime(pCell->time1()); // use time from first pmt as cell time
205 pCell->setQuality(pCell->qual1(), (pCell->qbit1() | TileCell::MASK_BADCH), 1); // change quality flag for second pmt
206
207 if (msgLvl(MSG::VERBOSE)) {
208 msg(MSG::VERBOSE) << " after " << pCell -> ene1()
209 << " + " << pCell -> ene2()
210 << " = " << pCell -> energy() << endmsg;
211 }
212 }
213 } else { // first is bad
214
215 if (hash2 == TileHWID::NOT_VALID_HASH) { // cells wih single PMT
216
217 if (msgLvl(MSG::DEBUG)) {
218 ++n_masked_1;
219 if (msgLvl(MSG::VERBOSE)) {
220 msg(MSG::VERBOSE) << " channel in GAP is OFF"
221 << ", hash1: " << hash1
222 << " before " << pCell->ene1()
223 << " + " << pCell->ene2()
224 << " = " << pCell->energy();
225 }
226 }
227
228 if (gain1 == CaloGain::INVALIDGAIN) {
229 pCell->setEnergy(m_zeroEnergy, 0.0, TileID::LOWGAIN, CaloGain::INVALIDGAIN); // reset energy completely, indicate problem putting low gain
230 } else {
231 pCell->setEnergy(m_zeroEnergy, 0.0); // reset energy completely without changing gain
232 }
233 pCell->setTime(0.0); // reset time completely
234 pCell->setQuality(255, TileCell::MASK_BADCH, 0); // reset quality flag for first pmt
235 pCell->setQuality(0, TileCell::MASK_BADCH, 1); // reset quality flag for second pmt
236
237 if (msgLvl(MSG::VERBOSE)) {
238 msg(MSG::VERBOSE) << " after " << pCell->ene1()
239 << " + " << pCell->ene2()
240 << " = " << pCell->energy() << endmsg;
241 }
242
243 } else if (bit2) { // second is good
244
245 if (msgLvl(MSG::DEBUG)) {
246 ++n_masked_12;
247 if (msgLvl(MSG::VERBOSE)) {
248 msg(MSG::VERBOSE) << " first channel is OFF"
249 << ", hash1: " << hash1
250 << " before " << pCell->ene1()
251 << " + " << pCell->ene2()
252 << " = " << pCell->energy();
253 }
254 }
255
256 float ene2 = pCell->ene2();
257 pCell->setEnergy(ene2, ene2, gain2, gain2); // use energy/gain from second pmt for both pmts
258 pCell->setTime(pCell->time2()); // use time from second pmt as cell time
259 pCell->setQuality(pCell->qual2(), (pCell->qbit2() | TileCell::MASK_BADCH), 0); // change quality flag for first pmt
260
261 if (msgLvl(MSG::VERBOSE))
262 msg(MSG::VERBOSE) << " after " << pCell->ene1()
263 << " + " << pCell->ene2()
264 << " = " << pCell->energy() << endmsg;
265
266 } else { // second is bad
267
268 if (msgLvl(MSG::DEBUG)) {
269 ++n_masked_2;
270 if (msgLvl(MSG::VERBOSE)) {
271 msg(MSG::VERBOSE) << " both channels are OFF"
272 << ", hash1: " << hash1
273 << ", hash2: " << hash2
274 << " before " << pCell->ene1()
275 << " + " << pCell->ene2()
276 << " = " << pCell->energy();
277 }
278 }
279
280 if (gain1 == CaloGain::INVALIDGAIN || gain2 == CaloGain::INVALIDGAIN) {
281 if (gain1 == CaloGain::INVALIDGAIN) gain1 = 0; // this is TileID::LOWGAIN; - commented out to make Coverity happy
282 if (gain2 == CaloGain::INVALIDGAIN) gain2 = 0; // this is TileID::LOWGAIN; - commented out to make Coverity happy
283 pCell->setEnergy(m_zeroEnergy, m_zeroEnergy, gain1, gain2); // reset energy completely, indicate problem putting low gain
284 } else {
285 pCell->setEnergy(m_zeroEnergy, m_zeroEnergy); // reset energy completely without changing gain
286 }
287 pCell->setTime(0.0); // reset time completely
288 pCell->setQuality(255, TileCell::MASK_BADCH, 0); // reset quality flag for first pmt
289 pCell->setQuality(255, TileCell::MASK_BADCH, 1); // reset quality flag for second pmt
290
291 if (msgLvl(MSG::VERBOSE)) {
292 msg(MSG::VERBOSE) << " after " << pCell->ene1()
293 << " + " << pCell->ene2()
294 << " = " << pCell->energy() << endmsg;
295 }
296 }
297 }
298 ene_after += aCell->energy();
299 }
300 }
301
302 ATH_MSG_DEBUG( " Ncells: " << n_cells
303 << " N masked gap/normal/half-masked: " << n_masked_1 << " " << n_masked_2 << " " << n_masked_12
304 << " Ene before/after/delta: " << ene_before << " " << ene_after << " " << ene_after-ene_before );
305
306 return StatusCode::SUCCESS;
307}
308
310
312
313 return StatusCode::SUCCESS;
314}
315
317
319
320 IdentifierHash ChHash = m_tileHWID->get_channel_hash(m_tileHWID->channel_id(hwid));
321
322 return m_includedCellsMap.test(ChHash);
323}
#define endmsg
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
static const double MeV
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
Container class for CaloCell.
int indexFirstCellCalo(const CaloCell_ID::SUBCALO caloNum) const
index of first cell of given calorimeter (-1 if none).
int indexLastCellCalo(const CaloCell_ID::SUBCALO caloNum) const
index of last cell of given calorimeter (-2 if none) Note that it is normally more efficient to use i...
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
double energy() const
get energy (data member)
Definition CaloCell.h:327
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
This class groups all DetDescr information related to a CaloCell.
IdentifierHash onl2() const
cell online identifier 2
IdentifierHash onl1() const
cell online identifier 1
This is a "hash" representation of an Identifier.
std::vector< std::string > m_rejectedTileChannels
std::vector< std::string > m_rejectedTileDigitizer
virtual bool channel_is_good(HWIdentifier &hwid)
std::vector< std::string > m_rejectedTileMB
void killer(std::string_view component, int ros, int drw, int index)
std::bitset< 65536 > m_includedCellsMap
std::vector< std::string > m_rejectedTileDrawer
TileCellMaskingTool(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode finalize() override
const TileHWID * m_tileHWID
std::vector< std::string > m_rejectedTileDMU
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
virtual StatusCode initialize() override
uint8_t qual1(void) const
get quality of first PMT (data member)
Definition TileCell.h:197
float time1(void) const
get time of first PMT
Definition TileCell.h:192
virtual void setEnergy(float ene) override final
set total energy, reset eneDiff to zero (final override of CaloCell method)
Definition TileCell.cxx:123
int gain2(void) const
get gain of second PMT
Definition TileCell.cxx:175
uint8_t qbit2(void) const
get quality bits of second PMT (data member)
Definition TileCell.h:206
int gain1(void) const
get gain of first PMT
Definition TileCell.cxx:168
uint8_t qual2(void) const
get quality of second PMT (data member)
Definition TileCell.h:200
void setQuality(unsigned char qual, unsigned char qbit, int pmt)
set quality value and quality bits for one PMT (TileCell specific overloads)
Definition TileCell.h:280
float ene1(void) const
get energy of first PMT
Definition TileCell.h:187
virtual void setTime(float t) override final
set cell time, reset timeDiff
Definition TileCell.h:251
float time2(void) const
get time of second PMT
Definition TileCell.h:194
@ MASK_BADCH
Definition TileCell.h:63
uint8_t qbit1(void) const
get quality bits of first PMT (data member)
Definition TileCell.h:203
float ene2(void) const
get energy of second PMT
Definition TileCell.h:189
@ NOT_VALID_HASH
Definition TileHWID.h:314
@ INVALIDGAIN
Definition CaloGain.h:18
Definition index.py:1