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