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) const
63  {
65  m_useModuleMap && pixelDetElStatus,
66  pixelDetElStatus->isChipGood(moduleHash,m_pixelReadout->getFE(rdoID, m_pixelId->wafer_id(rdoID))),
67  m_summaryTool->isGood(moduleHash, rdoID, ctx));
68 
69  return !m_useModuleMap ||
70  (pixelDetElStatus ?
71  pixelDetElStatus->isChipGood(moduleHash, m_pixelReadout->getFE(rdoID, m_pixelId->wafer_id(rdoID)))
72  : m_summaryTool->isGood(moduleHash, rdoID, ctx));
73  }
74 
75 
77  const Identifier& rdoID,
78  const int lvl1,
79  std::vector<UnpackedPixelRDO>& collectionID) const
80  {
82  return false;
83 
84  auto isDuplicate = [&pixelID,rdoID](const UnpackedPixelRDO& rc) -> bool {
85  return (pixelID.phi_index(rdoID) == pixelID.phi_index(rc.ID)) &&
86  (pixelID.eta_index(rdoID) == pixelID.eta_index(rc.ID));
87  };
88 
89  const auto pDuplicate = std::find_if(collectionID.begin(), collectionID.end(),isDuplicate);
90  const bool foundDuplicate {pDuplicate != collectionID.end()};
91  if (foundDuplicate)
92  pDuplicate->LVL1 = std::max(pDuplicate->LVL1, lvl1);
93 
94  return foundDuplicate;
95  }
96 
97 
99  {
101  if (!m_pixelDetElStatus.empty()) {
103  if (!pixelDetElStatus.isValid()) {
104  std::stringstream msg;
105  msg << "Failed to get " << m_pixelDetElStatus.key() << " from StoreGate in " << name();
106  throw std::runtime_error(msg.str());
107  }
108  return pixelDetElStatus.cptr();
109  }
110  return nullptr;
111  }
112 
113 
114 
116  PixelRDOTool::checkCollection(const InDetRawDataCollection<PixelRDORawData> &collection, const EventContext& ctx) const
117  {
118  const unsigned int RDO_size = collection.size();
119  if ( RDO_size==0) {
120  ATH_MSG_DEBUG("Empty RDO collection");
121  return nullptr;
122  }
123 
124  IdentifierHash idHash = collection.identifyHash();
125 
126  const InDet::SiDetectorElementStatus *pixelDetElStatus = getPixelDetElStatus(ctx);
127  if (pixelDetElStatus){
128  // If module is bad, do not create a cluster collection
131  pixelDetElStatus->isGood(idHash),
132  m_summaryTool->isGood(idHash,ctx)
133  );
134  }
135  //
136  if (m_useModuleMap && (pixelDetElStatus ? !pixelDetElStatus->isGood(idHash): !(m_summaryTool->isGood(idHash, ctx)))) {
137  return nullptr;
138  }
139 
141  const InDetDD::SiDetectorElementCollection* pixelDetEle(*pixelDetEleHandle);
142  if (not pixelDetEleHandle.isValid() or pixelDetEle == nullptr) {
143  ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
144  return nullptr;
145  }
146 
147  const InDetDD::SiDetectorElement* element = pixelDetEle->getDetectorElement(idHash);
148  const Trk::RectangleBounds *mybounds =
149  dynamic_cast<const Trk::RectangleBounds *>(&element->surface().bounds());
150  if (not mybounds) {
151  ATH_MSG_ERROR("Dynamic cast failed at "<<__LINE__<<" of PixelRDOTool.cxx.");
152  return nullptr;
153  }
154 
155  return element;
156  }
157 
158  std::vector<UnpackedPixelRDO>
160  const PixelID& pixelID,
161  const InDetDD::SiDetectorElement* element,
162  const EventContext& ctx,
163  int defaultLabel) const
164  {
165  std::vector<UnpackedPixelRDO> unpacked;
166  std::unordered_set<Identifier> idset;
167  const IdentifierHash idHash = collection.identifyHash();
168 
169  const InDet::SiDetectorElementStatus *pixelDetElStatus = getPixelDetElStatus(ctx);
170 
171  for(const auto *const rdo : collection) {
172  const Identifier rdoID = rdo->identify();
173 
174  if (!isGoodRDO(pixelDetElStatus, idHash, rdoID, ctx))
175  continue;
176 
177  if (not idset.insert(rdoID).second) {
178  if (m_printDuplicate) ATH_MSG_WARNING("Discarded a duplicated RDO");
179  continue;
180  }
181 
182  const int lvl1 = rdo->getLVL1A();
183  if (checkDuplication(pixelID, rdoID, lvl1, unpacked))
184  continue;
185 
186  const int tot = rdo->getToT();
187 
188  unpacked.emplace_back(
189  defaultLabel,
190  pixelID.phi_index(rdoID),
191  pixelID.eta_index(rdoID),
192  tot,
193  lvl1,
194  rdoID
195 
196  );
197 
198  if (m_checkGanged) {
199  std::optional<Identifier> gangedID = isGanged(rdoID, element);
200  if (gangedID.has_value()) {
201  unpacked.emplace_back(
202  defaultLabel,
203  pixelID.phi_index(*gangedID),
204  pixelID.eta_index(*gangedID),
205  tot,
206  lvl1,
207  *gangedID
208 
209  );
210  }
211  }
212  }
213  return unpacked;
214  }
215 
216 
217 
218 }
InDet::PixelRDOTool::getPixelDetElStatus
const InDet::SiDetectorElementStatus * getPixelDetElStatus(const EventContext &ctx) const
Definition: PixelRDOTool.cxx:98
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:141
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:111
max
#define max(a, b)
Definition: cfImp.cxx:41
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
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDetDD::SolidStateDetectorElementBase::surface
Trk::Surface & surface()
Element Surface.
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:205
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:149
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:116
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
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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:159
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:127
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
LB_AnalMapSplitter.tot
tot
Definition: LB_AnalMapSplitter.py:46
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:118
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:192
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:156
AthAlgTool
Definition: AthAlgTool.h:26
IdentifierHash
Definition: IdentifierHash.h:38
InDet::PixelRDOTool::isGoodRDO
bool isGoodRDO(const InDet::SiDetectorElementStatus *pixelDetElStatus, const IdentifierHash &moduleHash, const Identifier &rdoID, const EventContext &ctx) const
Definition: PixelRDOTool.cxx:60
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:76
InDet::PixelRDOTool::m_printDuplicate
BooleanProperty m_printDuplicate
Definition: PixelRDOTool.h:134
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:99
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
InDet::PixelRDOTool::m_pixelId
const PixelID * m_pixelId
Definition: PixelRDOTool.h:125
PixelRDOTool.h