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"
14 
15 
17 // CONSTRUCTOR:
19 
21  const std::string& type,
22  const std::string& name,
23  const IInterface* parent)
24  : base_class (type, name, parent),
25  m_onlineID(nullptr),
26  m_offlineID(nullptr),
27  m_mapInitialized (false)
28 {
29  //List of strings to determine detector parts to be masked.
30  //Syntax: barrel_endcap pos_neg Feedthrough slot channel (integers separated by white space)
31  //Feedthrough, slot, and channel can be left out. In this case all channels belonging to this
32  //Subdetector, Feedthrough or FEB will be masked.
33  declareProperty ("RejectLArChannels",m_rejLArChannels);
34 }
35 
36 
37 
38 
40 // INITIALIZE:
41 // The initialize method will create all the required algorithm objects
43 
45 {
49 
50  // Get hash ranges
52  ATH_MSG_DEBUG ("CaloCell Hash Max: " << m_offlinehashMax);
53 
54 // m_onlinehashMax=m_onlineID->hash_max();
55 // (*m_log) << MSG::DEBUG << "CaloCell Hash Max: " << m_offlinehashMax << endmsg;
56 
57  //Fill the bit map
58  m_includedCellsMap.set(); // By default include all cells
59 
60  ATH_MSG_INFO (" Will exclude " << m_includedCellsMap.size() - m_includedCellsMap.count() << " cells from CaloCellContainer");
61 
62 
63  return StatusCode::SUCCESS;
64 
65 }
66 
68 {
69  for (const std::string& s : m_rejLArChannels) {
70  std::stringstream is;
71  is << s;
72  bool haveFT=false, haveSlot=false, haveChannel=false;
73  int bec=0, pn=0, FT=0, slot=1,channel=0;
74  //Want at least subdetector (=pn & bec)
75  is >> bec >> pn;
76  if (is.bad()) {
77  ATH_MSG_ERROR ("jO problem: Malformed string [" << s << "]");
78  return StatusCode::FAILURE;
79  }
80 
81  int FTmax;
82  if (bec==0)
83  FTmax=32; //Barrel
84  else
85  FTmax=24; //Endcap
86 
87 
88 
89  if (!is.eof()) {//have FT
90  is >> FT;
91  haveFT=true;
92  //check good?
93  }
94  if (!is.eof()) {//have slot
95  is >> slot;
96  haveSlot=true;
97  }
98  if (!is.eof()) {//have channel
99  is >> channel;
100  haveChannel=true;
101  }
102 
103  msg() << MSG::DEBUG << "Will exclude: bec="<< bec << " pn=" << pn;
104  if (haveFT) msg() << " FT=" << FT;
105  if (haveSlot) msg() << " slot=" << slot;
106  if (haveChannel) msg() << " channel=" << channel;
107  msg() << endmsg;
108 
109  unsigned nChannels=0;
110  unsigned nDisconnected=0;
111  HWIdentifier chanId;
112  do { //loop over FTs (only once if FT is set
113  //Number of channels for this FT
114  int slotMax=15;
115  do {
116  int channelMax=128;
117  do { //loop over channels in slot
118  nChannels++;
119  try {
120  chanId=m_onlineID->channel_Id(bec,pn,FT,slot,channel);
121  if (cabling->isOnlineConnected(chanId)) {
122  const Identifier cellId=cabling->cnvToIdentifier(chanId);
123  const IdentifierHash cellhash=m_offlineID->calo_cell_hash(cellId);
124  m_includedCellsMap.reset(cellhash);
125  //std::cout << "Block channel: bec="<< bec << " pn=" << pn
126  // << " FT=" << FT <<":" << haveFT << " slot=" << slot << ":" << haveSlot << " channel=" << channel <<":" << haveChannel<< std::endl;
127  }
128  else
129  nDisconnected++;
130  }
131  catch (const LArOnlID_Exception&) {
132  }
133  catch(const LArID_Exception&) {
134  }
135  if (!haveChannel) channel++;
136  }while (!haveChannel && channel<channelMax);
137  if (!haveChannel) channel=0;
138  if (!haveSlot) slot++;
139  }while (!haveSlot && slot<slotMax);
140  if (!haveSlot) slot=0;
141  if (!haveFT) FT++;
142  } while (!haveFT && FT<FTmax);
143  ATH_MSG_DEBUG ("Channels selected for exclusion: "<< nChannels << ". Disconnected: " << nDisconnected);
144  }// end loop over strings
145  return StatusCode::SUCCESS;
146 }
147 
148 
149 
151  const EventContext& ctx) const
152 {
153  if (! m_mapInitialized) {
154  // FIXME: Can we do this in start()?
155  std::lock_guard<std::mutex> lock (m_mutex);
156  // cppcheck-suppress identicalInnerCondition
157  if (!m_mapInitialized) {
159  const LArOnOffIdMapping* cabling=*cablingHdl;
161  m_mapInitialized=true;
162  }
163  }
164 
165  //Build bitmap to keep track which cells have been added to reducedCellContainer;
166  unsigned cnt=0;
168  while(it!=theCont->end()) {
169  const IdentifierHash cellHash=(*it)->caloDDE()->calo_hash();
170  if (!m_includedCellsMap.test(cellHash)) {
171  //Possible optimization: check how many consecutive cells to be deleted and erase a range
172  it=theCont->erase(it);
173  cnt++;
174  }
175  else
176  ++it;
177  }
178  ATH_MSG_DEBUG ("Removed " << cnt << " Cells from container");
179  return StatusCode::SUCCESS ;
180 }
181 
182 
184  return StatusCode::SUCCESS;
185 }
186 
187 
188 
189 
190 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArCellMaskingTool::initialize
virtual StatusCode initialize() override
Definition: LArCellMaskingTool.cxx:44
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
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:28
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
LArCellMaskingTool::m_offlinehashMax
IdentifierHash m_offlinehashMax
Definition: LArCellMaskingTool.h:51
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
skel.it
it
Definition: skel.GENtoEVGEN.py:423
HWIdentifier
Definition: HWIdentifier.h:13
LArCellMaskingTool::finalize
virtual StatusCode finalize() override
Definition: LArCellMaskingTool.cxx:183
python.ZdcRecConfig.pn
pn
Definition: ZdcRecConfig.py:357
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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:20
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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:67
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
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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.
LArNewCalib_Delay_OFC_Cali.FT
FT
Definition: LArNewCalib_Delay_OFC_Cali.py:120
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
LArCellMaskingTool::m_rejLArChannels
std::vector< std::string > m_rejLArChannels
Definition: LArCellMaskingTool.h:47
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
LArCellMaskingTool::process
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
Definition: LArCellMaskingTool.cxx:150
LArCellMaskingTool::m_offlineID
const CaloCell_ID * m_offlineID
Definition: LArCellMaskingTool.h:43
IdentifierHash
Definition: IdentifierHash.h:38
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
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max(void) const
cell 'global' hash table max size
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20