ATLAS Offline Software
LArCellMaskingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /********************************************************************
6 
7 NAME: CaloCellMaskingTool
8 PACKAGE: offline/Calorimeter/CaloRec
9 
10 ********************************************************************/
11 
12 #include "LArCellMaskingTool.h"
15 
16 
18 // CONSTRUCTOR:
20 
22  const std::string& type,
23  const std::string& name,
24  const IInterface* parent)
25  : base_class (type, name, parent),
26  m_onlineID(nullptr),
27  m_offlineID(nullptr),
28  m_mapInitialized (false)
29 {
30  //List of strings to determine detector parts to be masked.
31  //Syntax: barrel_endcap pos_neg Feedthrough slot channel (integers separated by white space)
32  //Feedthrough, slot, and channel can be left out. In this case all channels belonging to this
33  //Subdetector, Feedthrough or FEB will be masked.
34  declareProperty ("RejectLArChannels",m_rejLArChannels);
35 }
36 
37 
38 
39 
41 // INITIALIZE:
42 // The initialize method will create all the required algorithm objects
44 
46 {
50 
51  // Get hash ranges
53  ATH_MSG_DEBUG ("CaloCell Hash Max: " << m_offlinehashMax);
54 
55 // m_onlinehashMax=m_onlineID->hash_max();
56 // (*m_log) << MSG::DEBUG << "CaloCell Hash Max: " << m_offlinehashMax << endmsg;
57 
58  //Fill the bit map
59  m_includedCellsMap.set(); // By default include all cells
60 
61  ATH_MSG_INFO (" Will exclude " << m_includedCellsMap.size() - m_includedCellsMap.count() << " cells from CaloCellContainer");
62 
63 
64  return StatusCode::SUCCESS;
65 
66 }
67 
69 {
70  for (const std::string& s : m_rejLArChannels) {
71  std::stringstream is;
72  is << s;
73  bool haveFT=false, haveSlot=false, haveChannel=false;
74  int bec=0, pn=0, FT=0, slot=1,channel=0;
75  //Want at least subdetector (=pn & bec)
76  is >> bec >> pn;
77  if (is.bad()) {
78  ATH_MSG_ERROR ("jO problem: Malformed string [" << s << "]");
79  return StatusCode::FAILURE;
80  }
81 
82  int FTmax;
83  if (bec==0)
84  FTmax=32; //Barrel
85  else
86  FTmax=24; //Endcap
87 
88 
89 
90  if (!is.eof()) {//have FT
91  is >> FT;
92  haveFT=true;
93  //check good?
94  }
95  if (!is.eof()) {//have slot
96  is >> slot;
97  haveSlot=true;
98  }
99  if (!is.eof()) {//have channel
100  is >> channel;
101  haveChannel=true;
102  }
103 
104  msg() << MSG::DEBUG << "Will exclude: bec="<< bec << " pn=" << pn;
105  if (haveFT) msg() << " FT=" << FT;
106  if (haveSlot) msg() << " slot=" << slot;
107  if (haveChannel) msg() << " channel=" << channel;
108  msg() << endmsg;
109 
110  unsigned nChannels=0;
111  unsigned nDisconnected=0;
112  HWIdentifier chanId;
113  do { //loop over FTs (only once if FT is set
114  //Number of channels for this FT
115  int slotMax=15;
116  do {
117  int channelMax=128;
118  do { //loop over channels in slot
119  nChannels++;
120  try {
121  chanId=m_onlineID->channel_Id(bec,pn,FT,slot,channel);
122  if (cabling->isOnlineConnected(chanId)) {
123  const Identifier cellId=cabling->cnvToIdentifier(chanId);
124  const IdentifierHash cellhash=m_offlineID->calo_cell_hash(cellId);
125  m_includedCellsMap.reset(cellhash);
126  //std::cout << "Block channel: bec="<< bec << " pn=" << pn
127  // << " FT=" << FT <<":" << haveFT << " slot=" << slot << ":" << haveSlot << " channel=" << channel <<":" << haveChannel<< std::endl;
128  }
129  else
130  nDisconnected++;
131  }
132  catch (const LArOnlID_Exception&) {
133  }
134  catch(const LArID_Exception&) {
135  }
136  if (!haveChannel) channel++;
137  }while (!haveChannel && channel<channelMax);
138  if (!haveChannel) channel=0;
139  if (!haveSlot) slot++;
140  }while (!haveSlot && slot<slotMax);
141  if (!haveSlot) slot=0;
142  if (!haveFT) FT++;
143  } while (!haveFT && FT<FTmax);
144  ATH_MSG_DEBUG ("Channels selected for exclusion: "<< nChannels << ". Disconnected: " << nDisconnected);
145  }// end loop over strings
146  return StatusCode::SUCCESS;
147 }
148 
149 
150 
152  const EventContext& ctx) const
153 {
154  if (! m_mapInitialized) {
155  // FIXME: Can we do this in start()?
156  std::lock_guard<std::mutex> lock (m_mutex);
157  // cppcheck-suppress identicalInnerCondition
158  if (!m_mapInitialized) {
160  const LArOnOffIdMapping* cabling=*cablingHdl;
162  m_mapInitialized=true;
163  }
164  }
165 
166  //Build bitmap to keep track which cells have been added to reducedCellContainer;
167  unsigned cnt=0;
169  while(it!=theCont->end()) {
170  const IdentifierHash cellHash=(*it)->caloDDE()->calo_hash();
171  if (!m_includedCellsMap.test(cellHash)) {
172  //Possible optimization: check how many consecutive cells to be deleted and erase a range
173  it=theCont->erase(it);
174  cnt++;
175  }
176  else
177  ++it;
178  }
179  ATH_MSG_DEBUG ("Removed " << cnt << " Cells from container");
180  return StatusCode::SUCCESS ;
181 }
182 
183 
185  return StatusCode::SUCCESS;
186 }
187 
188 
189 
190 
191 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArCellMaskingTool::initialize
virtual StatusCode initialize() override
Definition: LArCellMaskingTool.cxx:45
RPDUtils::nChannels
unsigned constexpr int nChannels
Definition: RPDUtils.h:23
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArCellMaskingTool::m_mutex
std::mutex m_mutex
Definition: LArCellMaskingTool.h:53
python.ZdcOnlineRecMonitorConfig.pn
pn
Definition: ZdcOnlineRecMonitorConfig.py:341
LArCellMaskingTool::m_offlinehashMax
IdentifierHash m_offlinehashMax
Definition: LArCellMaskingTool.h:51
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
LArOnlID_Exception.h
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
skel.it
it
Definition: skel.GENtoEVGEN.py:407
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
HWIdentifier
Definition: HWIdentifier.h:13
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
LArCellMaskingTool::finalize
virtual StatusCode finalize() override
Definition: LArCellMaskingTool.cxx:184
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max() const
cell 'global' hash table max size
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
LArCellMaskingTool::LArCellMaskingTool
LArCellMaskingTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: LArCellMaskingTool.cxx:21
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
LArOnlID_Exception
Exception class for LAr online Identifiers.
Definition: LArOnlID_Exception.h:16
LArCellMaskingTool::fillIncludedCellsMap
StatusCode fillIncludedCellsMap(const LArOnOffIdMapping *cabling) const
Definition: LArCellMaskingTool.cxx:68
LArOnlineID_Base::channel_Id
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
Definition: LArOnlineID_Base.cxx:1569
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
WriteCellNoiseToCool.cellHash
cellHash
Definition: WriteCellNoiseToCool.py:433
LArDigits2NtupleDumper.FT
FT
Definition: LArDigits2NtupleDumper.py:77
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
LArCellMaskingTool.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArCellMaskingTool::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArCellMaskingTool.h:44
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
DEBUG
#define DEBUG
Definition: page_access.h:11
LArCellMaskingTool::m_rejLArChannels
std::vector< std::string > m_rejLArChannels
Definition: LArCellMaskingTool.h:47
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
LArCellMaskingTool::process
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
Definition: LArCellMaskingTool.cxx:151
LArCellMaskingTool::m_offlineID
const CaloCell_ID * m_offlineID
Definition: LArCellMaskingTool.h:43
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
DataVector::erase
iterator erase(iterator position)
Remove element at a given position.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
LArID_Exception
Exception class for LAr Identifiers.
Definition: LArID_Exception.h:20
LArCellMaskingTool::m_mapInitialized
std::atomic< bool > m_mapInitialized
Definition: LArCellMaskingTool.h:50
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LArCellMaskingTool::m_onlineID
const LArOnlineID * m_onlineID
Definition: LArCellMaskingTool.h:42
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
Identifier
Definition: IdentifierFieldParser.cxx:14