ATLAS Offline Software
TileCellMaskingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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
13 #include "CaloIdentifier/TileID.h"
15 
16 // Tile includes
19 #include "TileEvent/TileCell.h"
20 
21 #include <CLHEP/Units/SystemOfUnits.h>
22 
23 using CLHEP::MeV;
24 
26  , const std::string& name, const IInterface* 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 
63  m_includedCellsMap.set();
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 
107 void 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) {
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 = (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 
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 
320 
321  return m_includedCellsMap.test(ChHash);
322 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileCell
Definition: TileCell.h:57
CaloDetDescrElement::onl2
IdentifierHash onl2() const
cell online identifier 2
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:408
TileCell::time1
float time1(void) const
get time of first PMT
Definition: TileCell.h:198
CaloCellContainer::indexLastCellCalo
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...
Definition: CaloCellContainer.cxx:141
TileCell::setTime
virtual void setTime(float t) override final
set cell time, reset timeDiff
Definition: TileCell.h:257
TileCellMaskingTool::killer
void killer(const std::string &component, int ros, int drw, int index)
Definition: TileCellMaskingTool.cxx:107
TileCellMaskingTool::m_zeroEnergy
float m_zeroEnergy
Definition: TileCellMaskingTool.h:48
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
TileCellMaskingTool::process
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
Definition: TileCellMaskingTool.cxx:155
TileCell::time2
float time2(void) const
get time of second PMT
Definition: TileCell.h:200
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileCell::ene1
float ene1(void) const
get energy of first PMT
Definition: TileCell.h:193
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
CaloTime_fillDB.gain2
gain2
Definition: CaloTime_fillDB.py:357
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TileCellMaskingTool::m_includedCellsMap
std::bitset< 65536 > m_includedCellsMap
Definition: TileCellMaskingTool.h:53
TileCellMaskingTool::finalize
virtual StatusCode finalize() override
Definition: TileCellMaskingTool.cxx:310
TileCellMaskingTool.h
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TileCellMaskingTool::m_rejectedTileDigitizer
std::vector< std::string > m_rejectedTileDigitizer
Definition: TileCellMaskingTool.h:45
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
HWIdentifier
Definition: HWIdentifier.h:13
TileCell::MASK_BADCH
@ MASK_BADCH
Definition: TileCell.h:63
TileCellMaskingTool::TileCellMaskingTool
TileCellMaskingTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TileCellMaskingTool.cxx:25
TileID.h
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TileCellMaskingTool::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileCellMaskingTool.h:51
CaloCell::energy
double energy() const
get energy (data member)
Definition: CaloCell.h:311
CaloDetDescrElement::onl1
IdentifierHash onl1() const
cell online identifier 1
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:404
CaloGain::INVALIDGAIN
@ INVALIDGAIN
Definition: CaloGain.h:18
TileCell::qual2
uint8_t qual2(void) const
get quality of second PMT (data member)
Definition: TileCell.h:206
CaloCellContainer::indexFirstCellCalo
int indexFirstCellCalo(const CaloCell_ID::SUBCALO caloNum) const
index of first cell of given calorimeter (-1 if none).
Definition: CaloCellContainer.cxx:137
TileCellMaskingTool::m_rejectedTileMB
std::vector< std::string > m_rejectedTileMB
Definition: TileCellMaskingTool.h:44
TileHWID.h
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
TileCell.h
TileHWID::get_channel_hash
virtual IdentifierHash get_channel_hash(const HWIdentifier &id) const
create hash id from compact Channel id
Definition: TileHWID.cxx:589
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Tile_Base_ID::LOWGAIN
@ LOWGAIN
Definition: Tile_Base_ID.h:57
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
TileCell::qbit1
uint8_t qbit1(void) const
get quality bits of first PMT (data member)
Definition: TileCell.h:209
maskDeadModules.ros
ros
Definition: maskDeadModules.py:35
TileCellMaskingTool::channel_is_good
virtual bool channel_is_good(HWIdentifier &hwid)
Definition: TileCellMaskingTool.cxx:317
TileCellMaskingTool::fillIncludedCellsMap
StatusCode fillIncludedCellsMap()
Definition: TileCellMaskingTool.cxx:61
TileCell::gain1
int gain1(void) const
get gain of first PMT
Definition: TileCell.cxx:182
CaloDetDescrElement::is_tile
bool is_tile() const
cell belongs to Tile
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:442
CaloTime_fillDB.gain1
gain1
Definition: CaloTime_fillDB.py:356
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TileCell::setQuality
void setQuality(unsigned char qual, unsigned char qbit, int pmt)
set quality value and quality bits for one PMT
Definition: TileCell.h:286
TileHWID::channel_id
HWIdentifier channel_id(int ros, int drawer, int channel) const
channel HWIdentifer
Definition: TileHWID.cxx:198
TileCellMaskingTool::m_tileID
const TileID * m_tileID
Definition: TileCellMaskingTool.h:50
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileCellMaskingTool::m_rejectedTileDMU
std::vector< std::string > m_rejectedTileDMU
Definition: TileCellMaskingTool.h:46
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
TileCell::setEnergy
virtual void setEnergy(float ene) override final
set total energy, reset eneDiff to zero
Definition: TileCell.cxx:123
TileCell::qbit2
uint8_t qbit2(void) const
get quality bits of second PMT (data member)
Definition: TileCell.h:212
TileCell::gain2
int gain2(void) const
get gain of second PMT
Definition: TileCell.cxx:189
TileCell::ene2
float ene2(void) const
get energy of second PMT
Definition: TileCell.h:195
DeMoScan.index
string index
Definition: DeMoScan.py:362
TileHWID::NOT_VALID_HASH
@ NOT_VALID_HASH
Definition: TileHWID.h:314
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TRT_PAI_physicsConstants::mb
const double mb
1mb to cm2
Definition: TRT_PAI_physicsConstants.h:15
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TileCellMaskingTool::initialize
virtual StatusCode initialize() override
Definition: TileCellMaskingTool.cxx:44
TileCell::qual1
uint8_t qual1(void) const
get quality of first PMT (data member)
Definition: TileCell.h:203
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
TileHWID::to_string
std::string to_string(const HWIdentifier &id, int level=0) const
extract all fields from HW identifier HWIdentifier get_all_fields ( const HWIdentifier & id,...
Definition: TileHWID.cxx:49
AthAlgTool
Definition: AthAlgTool.h:26
IdentifierHash
Definition: IdentifierHash.h:38
TileCellMaskingTool::m_rejectedTileDrawer
std::vector< std::string > m_rejectedTileDrawer
Definition: TileCellMaskingTool.h:43
TileCellMaskingTool::m_rejectedTileChannels
std::vector< std::string > m_rejectedTileChannels
Definition: TileCellMaskingTool.h:47