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 
15 
16 namespace InDet
17 {
18 
19  PixelRDOTool::PixelRDOTool(const std::string &type,
20  const std::string &name,
21  const IInterface *parent) :
23  {
24  }
25 
27  {
29 
30  bool disable_smry =
31  !m_useModuleMap ||
33 
34  ATH_CHECK(m_summaryTool.retrieve(DisableTool{disable_smry}));
35 
37  if (!m_pixelDetElStatus.empty()) {
38  ATH_CHECK( m_pixelReadout.retrieve() );
39  }
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 
59 
61  const IdentifierHash& moduleHash,
62  const Identifier& rdoID, const EventContext& ctx,
63  const IInDetConditionsTool::IDCCacheEntry* cacheEntry) const
64  {
66  m_useModuleMap && pixelDetElStatus,
67  pixelDetElStatus->isChipGood(moduleHash,m_pixelReadout->getFE(rdoID, m_pixelId->wafer_id(rdoID))),
68  m_summaryTool->isGood(moduleHash, rdoID, ctx, cacheEntry));
69 
70  return !m_useModuleMap ||
71  (pixelDetElStatus ?
72  pixelDetElStatus->isChipGood(moduleHash, m_pixelReadout->getFE(rdoID, m_pixelId->wafer_id(rdoID)))
73  : m_summaryTool->isGood(moduleHash, rdoID, ctx, cacheEntry));
74  }
75 
76 
78  const Identifier& rdoID,
79  const int lvl1,
80  std::vector<UnpackedPixelRDO>& collectionID) const
81  {
83  return false;
84 
85  auto isDuplicate = [&pixelID,rdoID](const UnpackedPixelRDO& rc) -> bool {
86  return (pixelID.phi_index(rdoID) == pixelID.phi_index(rc.ID)) &&
87  (pixelID.eta_index(rdoID) == pixelID.eta_index(rc.ID));
88  };
89 
90  const auto pDuplicate = std::find_if(collectionID.begin(), collectionID.end(),isDuplicate);
91  const bool foundDuplicate {pDuplicate != collectionID.end()};
92  if (foundDuplicate)
93  pDuplicate->LVL1 = std::max(pDuplicate->LVL1, lvl1);
94 
95  return foundDuplicate;
96  }
97 
98 
100  {
102  if (!m_pixelDetElStatus.empty()) {
104  if (!pixelDetElStatus.isValid()) {
105  std::stringstream msg;
106  msg << "Failed to get " << m_pixelDetElStatus.key() << " from StoreGate in " << name();
107  throw std::runtime_error(msg.str());
108  }
109  return pixelDetElStatus.cptr();
110  }
111  return nullptr;
112  }
113 
114 
115 
117  PixelRDOTool::checkCollection(const InDetRawDataCollection<PixelRDORawData> &collection, const EventContext& ctx) const
118  {
119  const unsigned int RDO_size = collection.size();
120  if ( RDO_size==0) {
121  ATH_MSG_DEBUG("Empty RDO collection");
122  return nullptr;
123  }
124 
125  IdentifierHash idHash = collection.identifyHash();
126 
127  const InDet::SiDetectorElementStatus *pixelDetElStatus = getPixelDetElStatus(ctx);
128  if (pixelDetElStatus){
129  // If module is bad, do not create a cluster collection
132  pixelDetElStatus->isGood(idHash),
133  m_summaryTool->isGood(idHash,ctx)
134  );
135  }
136  //
137  if (m_useModuleMap && (pixelDetElStatus ? !pixelDetElStatus->isGood(idHash): !(m_summaryTool->isGood(idHash, ctx)))) {
138  return nullptr;
139  }
140 
142  const InDetDD::SiDetectorElementCollection* pixelDetEle(*pixelDetEleHandle);
143  if (not pixelDetEleHandle.isValid() or pixelDetEle == nullptr) {
144  ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
145  return nullptr;
146  }
147 
148  const InDetDD::SiDetectorElement* element = pixelDetEle->getDetectorElement(idHash);
149  const Trk::RectangleBounds *mybounds =
150  dynamic_cast<const Trk::RectangleBounds *>(&element->surface().bounds());
151  if (not mybounds) {
152  ATH_MSG_ERROR("Dynamic cast failed at "<<__LINE__<<" of PixelRDOTool.cxx.");
153  return nullptr;
154  }
155 
156  return element;
157  }
158 
159  std::vector<UnpackedPixelRDO>
161  const PixelID& pixelID,
162  const InDetDD::SiDetectorElement* element,
163  const EventContext& ctx,
164  int defaultLabel) const
165  {
166  std::vector<UnpackedPixelRDO> unpacked;
167  unpacked.reserve(collection.size());
168  std::unordered_set<Identifier> idset;
169  const IdentifierHash idHash = collection.identifyHash();
170 
171  const InDet::SiDetectorElementStatus *pixelDetElStatus = getPixelDetElStatus(ctx);
172 
173  IInDetConditionsTool::IDCCacheEntry* cacheEntry = (pixelDetElStatus ? nullptr : m_summaryTool->getCacheEntryOut(ctx));
174  for(const auto *const rdo : collection) {
175  const Identifier rdoID = rdo->identify();
176 
177  if (!isGoodRDO(pixelDetElStatus, idHash, rdoID, ctx, cacheEntry))
178  continue;
179 
180  if (not idset.insert(rdoID).second) {
181  if (m_printDuplicate) ATH_MSG_WARNING("Discarded a duplicated RDO");
182  continue;
183  }
184 
185  const int lvl1 = rdo->getLVL1A();
186  if (checkDuplication(pixelID, rdoID, lvl1, unpacked))
187  continue;
188 
189  const int tot = rdo->getToT();
190 
191  unpacked.emplace_back(
192  defaultLabel,
193  pixelID.phi_index(rdoID),
194  pixelID.eta_index(rdoID),
195  tot,
196  lvl1,
197  rdoID
198 
199  );
200 
201  if (m_checkGanged) {
202  std::optional<Identifier> gangedID = isGanged(rdoID, element);
203  if (gangedID.has_value()) {
204  unpacked.emplace_back(
205  defaultLabel,
206  pixelID.phi_index(*gangedID),
207  pixelID.eta_index(*gangedID),
208  tot,
209  lvl1,
210  *gangedID
211 
212  );
213  }
214  }
215  }
216  return unpacked;
217  }
218 
219 
220 
221 }
InDet::PixelRDOTool::getPixelDetElStatus
const InDet::SiDetectorElementStatus * getPixelDetElStatus(const EventContext &ctx) const
Definition: PixelRDOTool.cxx:99
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:26
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:658
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:142
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:112
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
RectangleBounds.h
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
InDet::SiDetectorElementStatus::isChipGood
bool isChipGood(IdentifierHash hash, unsigned int chip) const
Definition: SiDetectorElementStatus.h:100
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::PixelRDOTool::isGoodRDO
bool isGoodRDO(const InDet::SiDetectorElementStatus *pixelDetElStatus, const IdentifierHash &moduleHash, const Identifier &rdoID, const EventContext &ctx, const IInDetConditionsTool::IDCCacheEntry *cacheEntry) const
Definition: PixelRDOTool.cxx:60
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:150
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
InDet::PixelRDOTool::checkCollection
const InDetDD::SiDetectorElement * checkCollection(const InDetRawDataCollection< PixelRDORawData > &collection, const EventContext &ctx) const
Definition: PixelRDOTool.cxx:117
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:364
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::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:160
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:664
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDet::PixelRDOTool::m_checkDuplicatedRDO
BooleanProperty m_checkDuplicatedRDO
Definition: PixelRDOTool.h:128
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:19
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InDet::PixelRDOTool::m_pixelReadout
ServiceHandle< InDetDD::IPixelReadoutManager > m_pixelReadout
Definition: PixelRDOTool.h:119
InDet::SiDetectorElementStatus::isGood
bool isGood(IdentifierHash hash) const
Definition: SiDetectorElementStatus.h:97
Trk::Surface::bounds
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
InDet::PixelRDOTool::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: PixelRDOTool.h:157
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
PixelID
Definition: PixelID.h:67
InDet::PixelRDOTool::checkDuplication
bool checkDuplication(const PixelID &pixelID, const Identifier &rdoID, const int lvl1, std::vector< UnpackedPixelRDO > &collectionID) const
Definition: PixelRDOTool.cxx:77
InDet::PixelRDOTool::m_printDuplicate
BooleanProperty m_printDuplicate
Definition: PixelRDOTool.h:135
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:100
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:15
IInDetConditionsTool::IDCCacheEntry
Definition: IInDetConditionsTool.h:33
InDet::PixelRDOTool::m_pixelId
const PixelID * m_pixelId
Definition: PixelRDOTool.h:126
PixelRDOTool.h
Identifier
Definition: IdentifierFieldParser.cxx:14