ATLAS Offline Software
PixelRDOTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // PixelRDOTool.cxx
8 // (c) ATLAS Detector software
10 
17 #include <boost/container/flat_set.hpp>
18 
19 namespace InDet
20 {
21 
22  PixelRDOTool::PixelRDOTool(const std::string &type,
23  const std::string &name,
24  const IInterface *parent) :
26  {
27  }
28 
30  {
32 
33  bool disable_smry =
34  !m_useModuleMap ||
36 
37  ATH_CHECK(m_summaryTool.retrieve(DisableTool{disable_smry}));
38 
40  ATH_CHECK( detStore()->retrieve(m_pixelId, "PixelID") );
41 
42  return StatusCode::SUCCESS;
43  }
44 
45 
46  std::optional<Identifier>
48  const InDetDD::SiDetectorElement* element)
49  {
50  // If the pixel is ganged, returns a new identifier for it
51  InDetDD::SiCellId cellID = element->cellIdFromIdentifier(rdoID);
52  if (element->numberOfConnectedCells(cellID) > 1) {
53  InDetDD::SiCellId gangedCellID = element->connectedCell(cellID,1);
54  return element->identifierFromCellId(gangedCellID);
55  }
56  return {};
57  }
58 
60  const IdentifierHash& moduleHash,
61  const InDetDD::PixelModuleDesign &design,
62  const Identifier& rdoID, const EventContext& ctx,
63  const IInDetConditionsTool::IDCCacheEntry* cacheEntry) const
64  {
65 
66  std::array<InDetDD::PixelDiodeTree::CellIndexType,2> diode_idx
68  m_pixelId->eta_index(rdoID));
70  std::uint32_t feValue = design.getFE(si_param);
71 
73  m_useModuleMap && pixelDetElStatus,
74  pixelDetElStatus ? pixelDetElStatus->isChipGood(moduleHash,feValue) : false,
75  m_summaryTool->isGood(moduleHash, rdoID, ctx, cacheEntry));
76 
77  if (!m_useModuleMap) {
78  return true;
79  }
80 
81  if (pixelDetElStatus) {
82 
83  return pixelDetElStatus->isChipGood(moduleHash, feValue);
84  } else {
85  return m_summaryTool->isGood(moduleHash, rdoID, ctx, cacheEntry);
86  }
87  }
88 
89 
91  const Identifier& rdoID,
92  const int lvl1,
93  std::vector<UnpackedPixelRDO>& collectionID) const
94  {
96  return false;
97 
98  auto isDuplicate = [&pixelID,rdoID](const UnpackedPixelRDO& rc) -> bool {
99  return (pixelID.phi_index(rdoID) == pixelID.phi_index(rc.ID)) &&
100  (pixelID.eta_index(rdoID) == pixelID.eta_index(rc.ID));
101  };
102 
103  const auto pDuplicate = std::find_if(collectionID.begin(), collectionID.end(),isDuplicate);
104  const bool foundDuplicate {pDuplicate != collectionID.end()};
105  if (foundDuplicate)
106  pDuplicate->LVL1 = std::max(pDuplicate->LVL1, lvl1);
107 
108  return foundDuplicate;
109  }
110 
111 
113  {
114  if (m_pixelDetElStatus.empty()) {
115  return nullptr;
116  }
117 
118  SG::ReadHandle<InDet::SiDetectorElementStatus> status = SG::makeHandle<InDet::SiDetectorElementStatus>(m_pixelDetElStatus, ctx);
119  if (!status.isValid()) {
120  std::stringstream msg;
121  msg << "Failed to get " << m_pixelDetElStatus.key() << " from StoreGate in " << name();
122  throw std::runtime_error(msg.str());
123  }
124  return status.cptr();
125  }
126 
127 
128 
130  PixelRDOTool::checkCollection(const InDetRawDataCollection<PixelRDORawData> &collection, const EventContext& ctx) const
131  {
132  const unsigned int RDO_size = collection.size();
133  if ( RDO_size==0) {
134  ATH_MSG_DEBUG("Empty RDO collection");
135  return nullptr;
136  }
137 
138  IdentifierHash idHash = collection.identifyHash();
139 
140  const InDet::SiDetectorElementStatus *pixelDetElStatus = getPixelDetElStatus(ctx);
141  if (pixelDetElStatus){
142  // If module is bad, do not create a cluster collection
145  pixelDetElStatus->isGood(idHash),
146  m_summaryTool->isGood(idHash,ctx)
147  );
148  }
149  //
150  if (m_useModuleMap && (pixelDetElStatus ? !pixelDetElStatus->isGood(idHash): !(m_summaryTool->isGood(idHash, ctx)))) {
151  return nullptr;
152  }
153 
155  const InDetDD::SiDetectorElementCollection* pixelDetEle(*pixelDetEleHandle);
156  if (not pixelDetEleHandle.isValid() or pixelDetEle == nullptr) {
157  ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
158  return nullptr;
159  }
160 
161  const InDetDD::SiDetectorElement* element = pixelDetEle->getDetectorElement(idHash);
162  const Trk::RectangleBounds *mybounds =
163  dynamic_cast<const Trk::RectangleBounds *>(&element->surface().bounds());
164  if (not mybounds) {
165  ATH_MSG_ERROR("Dynamic cast failed at "<<__LINE__<<" of PixelRDOTool.cxx.");
166  return nullptr;
167  }
168 
169  return element;
170  }
171 
172  std::vector<UnpackedPixelRDO>
174  const PixelID& pixelID,
175  const InDetDD::SiDetectorElement* element,
176  const EventContext& ctx,
177  int defaultLabel) const
178  {
179  std::vector<UnpackedPixelRDO> unpacked;
180  unpacked.reserve(collection.size());
181 
182  const IdentifierHash idHash = collection.identifyHash();
183  const InDet::SiDetectorElementStatus *pixelDetElStatus = getPixelDetElStatus(ctx);
184  IInDetConditionsTool::IDCCacheEntry* cacheEntry = (pixelDetElStatus ? nullptr : m_summaryTool->getCacheEntryOut(ctx));
185  const InDetDD::PixelModuleDesign &pixel_design=dynamic_cast<const InDetDD::PixelModuleDesign &>(element->design());
186 
187  // For ttbar200 we have ~70 RDO in average per element, with a max of ~1000.
188  // A flat set brings marginal improvements wrt unordered set for those sizes.
189  //std::unordered_set<Identifier> > idset;
190 
191  // This is not used for ITk, still we are creating it for the moment and could be optimized away in the future
192  boost::container::flat_set<Identifier> idset;
193 
194  for(const auto *const rdo : collection) {
195  const Identifier rdoID = rdo->identify();
196 
197  if (!isGoodRDO(pixelDetElStatus,
198  idHash,
199  pixel_design,
200  rdoID,
201  ctx,
202  cacheEntry))
203  continue;
204 
205  const int lvl1 = rdo->getLVL1A();
206 
207  if (!m_isITk) {
208 
209  if (not idset.insert(rdoID).second) {
210  if (m_printDuplicate) ATH_MSG_WARNING("Discarded a duplicated RDO");
211  continue;
212  }
213 
214  if (m_checkDuplicatedRDO) {
215  if (checkDuplication(pixelID, rdoID, lvl1, unpacked))
216  continue;
217  }
218  }
219 
220  const int tot = rdo->getToT();
221 
222  unpacked.emplace_back(
223  defaultLabel,
224  pixelID.phi_index(rdoID),
225  pixelID.eta_index(rdoID),
226  tot,
227  lvl1,
228  rdoID
229 
230  );
231 
232  if (m_checkGanged) {
233  std::optional<Identifier> gangedID = isGanged(rdoID, element);
234  if (gangedID.has_value()) {
235  unpacked.emplace_back(
236  defaultLabel,
237  pixelID.phi_index(*gangedID),
238  pixelID.eta_index(*gangedID),
239  tot,
240  lvl1,
241  *gangedID
242 
243  );
244  }
245  }
246  }
247  return unpacked;
248  }
249 
250 
251 
252 }
InDet::PixelRDOTool::getPixelDetElStatus
const InDet::SiDetectorElementStatus * getPixelDetElStatus(const EventContext &ctx) const
Definition: PixelRDOTool.cxx:112
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
Trk::RectangleBounds
Definition: RectangleBounds.h:38
InDet::PixelRDOTool::initialize
virtual StatusCode initialize()
Definition: PixelRDOTool.cxx:29
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
PixelID::phi_index
int phi_index(const Identifier &id) const
Definition: PixelID.h:639
InDet::PixelRDOTool::isGoodRDO
bool isGoodRDO(const InDet::SiDetectorElementStatus *pixelDetElStatus, const IdentifierHash &moduleHash, const InDetDD::PixelModuleDesign &pixel_design, const Identifier &rdoID, const EventContext &ctx, const IInDetConditionsTool::IDCCacheEntry *cacheEntry) const
Definition: PixelRDOTool.cxx:59
InDetDD::SolidStateDetectorElementBase::connectedCell
SiCellId connectedCell(const SiCellId cellId, int number) const
Get the cell ids sharing the readout for this cell.
Definition: SolidStateDetectorElementBase.cxx:250
InDet::PixelRDOTool::m_checkGanged
BooleanProperty m_checkGanged
Definition: PixelRDOTool.h:136
InDet::PixelRDOTool::m_pixelDetElStatus
SG::ReadHandleKey< InDet::SiDetectorElementStatus > m_pixelDetElStatus
Optional read handle to get status data to test whether a pixel detector element is good.
Definition: PixelRDOTool.h:113
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:27
SG::ReadCondHandle
Definition: ReadCondHandle.h:40
RectangleBounds.h
InDetDD::PixelModuleDesign
Definition: PixelModuleDesign.h:45
InDet::PixelRDOTool::m_isITk
BooleanProperty m_isITk
Definition: PixelRDOTool.h:151
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
InDet::SiDetectorElementStatus::isChipGood
bool isChipGood(IdentifierHash hash, unsigned int chip) const
Definition: SiDetectorElementStatus.h:100
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDetDD::SolidStateDetectorElementBase::surface
Trk::Surface & surface()
Element Surface.
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
InDet::PixelRDOTool::m_useModuleMap
BooleanProperty m_useModuleMap
Definition: PixelRDOTool.h:144
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
InDetDD::PixelModuleDesign::getFE
static unsigned int getFE(const PixelDiodeTree::DiodeProxy &diode_proxy)
Definition: PixelModuleDesign.h:258
InDetDD::PixelModuleDesign::diodeProxyFromIdxCachePosition
PixelDiodeTree::DiodeProxyWithPosition diodeProxyFromIdxCachePosition(const std::array< PixelDiodeTree::IndexType, 2 > &idx) const
Definition: PixelModuleDesign.h:251
InDet::PixelRDOTool::checkCollection
const InDetDD::SiDetectorElement * checkCollection(const InDetRawDataCollection< PixelRDORawData > &collection, const EventContext &ctx) const
Definition: PixelRDOTool.cxx:130
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
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
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
InDetDD::PixelDiodeTree::DiodeProxyWithPosition
A diode proxy which caches the position of a diode.
Definition: PixelDiodeTree.h:230
InDetDD::SiDetectorElement::cellIdFromIdentifier
virtual SiCellId cellIdFromIdentifier(const Identifier &identifier) const override final
SiCellId from Identifier.
Definition: SiDetectorElement.cxx:120
InDetDD::SolidStateDetectorElementBase::numberOfConnectedCells
int numberOfConnectedCells(const SiCellId cellId) const
Test if readout cell has more than one diode associated with it.
Definition: SolidStateDetectorElementBase.cxx:243
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ClusterMakerTool.h
VALIDATE_STATUS_ARRAY
#define VALIDATE_STATUS_ARRAY(use_info, info_val, summary_val)
Definition: SiDetectorElementStatus.h:51
InDet::SiDetectorElementStatus
Definition: SiDetectorElementStatus.h:62
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
InDetDD::SiDetectorElement::identifierFromCellId
virtual Identifier identifierFromCellId(const SiCellId &cellId) const override final
Identifier <-> SiCellId (ie strip number or pixel eta_index,phi_index) Identifier from SiCellId (ie s...
Definition: SiDetectorElement.cxx:89
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
InDet::PixelRDOTool::getUnpackedPixelRDOs
std::vector< UnpackedPixelRDO > getUnpackedPixelRDOs(const InDetRawDataCollection< PixelRDORawData > &collection, const PixelID &pixelID, const InDetDD::SiDetectorElement *element, const EventContext &ctx, int defaultLabel=-1) const
Definition: PixelRDOTool.cxx:173
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VALIDATE_STATUS_ARRAY_ACTIVATED
#define VALIDATE_STATUS_ARRAY_ACTIVATED
Definition: SiDetectorElementStatus.h:50
PixelID::eta_index
int eta_index(const Identifier &id) const
Definition: PixelID.h:645
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDet::PixelRDOTool::m_checkDuplicatedRDO
BooleanProperty m_checkDuplicatedRDO
Definition: PixelRDOTool.h:122
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
InDet::PixelRDOTool::PixelRDOTool
PixelRDOTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: PixelRDOTool.cxx:22
InDet::SiDetectorElementStatus::isGood
bool isGood(IdentifierHash hash) const
Definition: SiDetectorElementStatus.h:97
PixelCalibrationConfig.tot
tot
Definition: PixelCalibrationConfig.py:28
Trk::Surface::bounds
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDetDD::SiCellId
Definition: SiCellId.h:29
InDet::UnpackedPixelRDO
Definition: PixelRDOTool.h:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PixelModuleDesign.h
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
merge.status
status
Definition: merge.py:16
InDetDD::PixelDiodeTree::makeCellIndex
static constexpr std::array< PixelDiodeTree::CellIndexType, 2 > makeCellIndex(T local_x_idx, T local_y_idx)
Create a 2D cell index from the indices in local-x (phi, row) and local-y (eta, column) direction.
Definition: PixelDiodeTree.h:320
InDet::PixelRDOTool::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: PixelRDOTool.h:158
AthAlgTool
Definition: AthAlgTool.h:26
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
InDetDD::SiDetectorElement::design
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
PixelID
Definition: PixelID.h:67
PixelDiodeTree.h
InDet::PixelRDOTool::checkDuplication
bool checkDuplication(const PixelID &pixelID, const Identifier &rdoID, const int lvl1, std::vector< UnpackedPixelRDO > &collectionID) const
Definition: PixelRDOTool.cxx:90
InDet::PixelRDOTool::m_printDuplicate
BooleanProperty m_printDuplicate
Definition: PixelRDOTool.h:129
DataVector< RawDataT >::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDet::PixelRDOTool::m_summaryTool
ToolHandle< IInDetConditionsTool > m_summaryTool
Definition: PixelRDOTool.h:101
InDet::PixelRDOTool::isGanged
static std::optional< Identifier > isGanged(const Identifier &rdoID, const InDetDD::SiDetectorElement *element)
Definition: PixelRDOTool.cxx:47
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:9
IInDetConditionsTool::IDCCacheEntry
Definition: IInDetConditionsTool.h:32
InDet::PixelRDOTool::m_pixelId
const PixelID * m_pixelId
Definition: PixelRDOTool.h:120
PixelRDOTool.h
Identifier
Definition: IdentifierFieldParser.cxx:14