2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 // Silicon trackers includes
5 #include "InDetRawData/PixelRDORawData.h"
7 #include "Identifier/Identifier.h"
8 #include "AtlasDetDescr/AtlasDetectorID.h"
9 #include "EventContainers/IdentifiableContainerBase.h"
10 #include "InDetIdentifier/PixelID.h"
11 #include "InDetRawData/InDetRawDataCollection.h"
12 #include "InDetReadoutGeometry/SiDetectorElement.h"
13 #include "PixelReadoutGeometry/PixelModuleDesign.h"
14 #include "InDetRawData/PixelRDORawData.h"
16 #include "StoreGate/WriteHandle.h"
22 template <class T_RDO_Container>
23 StatusCode DefectsEmulatorAlg<T_RDO_Container>::initialize(){
24 ATH_CHECK( m_emulatedDefects.initialize() );
25 ATH_CHECK( m_rdoOutContainerKey.initialize() );
26 ATH_CHECK( m_origRdoContainerKey.initialize() );
27 ATH_CHECK( detStore()->retrieve(m_idHelper, m_idHelperName.value()) );
29 return DefectsEmulatorBase::initialize();
32 template <class T_RDO_Container>
33 StatusCode DefectsEmulatorAlg<T_RDO_Container>::execute(const EventContext& ctx) const {
34 SG::ReadCondHandle<T_DefectsData> emulatedDefects(m_emulatedDefects,ctx);
35 ATH_CHECK(emulatedDefects.isValid());
36 SG::ReadHandle<T_RDO_Container> origRdoContainer(m_origRdoContainerKey, ctx);
37 ATH_CHECK(origRdoContainer.isValid());
38 SG::WriteHandle<T_RDO_Container> rdoOutContainer(m_rdoOutContainerKey, ctx);
39 ATH_CHECK( rdoOutContainer.record (std::make_unique<T_RDO_Container>(origRdoContainer->size(), EventContainers::Mode::OfflineFast)) );
41 unsigned int n_rejected=0u;
43 for(const InDetRawDataCollection<T_RDORawData>* collection : *origRdoContainer ) {
44 const IdentifierHash idHash = collection->identifyHash();
45 std::unique_ptr<InDetRawDataCollection<T_RDORawData> >
46 clone = std::make_unique<InDetRawDataCollection<T_RDORawData> >(idHash);
47 clone->setIdentifier(collection->identify());
48 T_ModuleHelper helper( emulatedDefects->m_detectorElements->at(idHash)->design() );
50 ATH_MSG_ERROR( "Not module design for " << idHash);
51 return StatusCode::FAILURE;
53 unsigned int rejected_per_mod=0u;
54 for(const auto *const rdo : *collection) {
55 const Identifier rdoID = rdo->identify();
57 auto row_idx = m_idHelper->phi_index(rdoID);
58 auto col_idx = m_idHelper->eta_index(rdoID);
60 if (!emulatedDefects->isDefect( helper, idHash, row_idx, col_idx)) {
61 clone->push_back(std::make_unique<T_RDORawDataConcreteType>(dynamic_cast<const T_RDORawDataConcreteType &>(*rdo)
65 if (m_histogrammingEnabled) {
66 std::lock_guard<std::mutex> lock(m_histMutex);
67 TH2 *h2=findHist(helper.nRows(), helper.nColumns());
68 h2->Fill(col_idx, row_idx);
74 if (m_histogrammingEnabled) {
75 std::lock_guard<std::mutex> lock(m_histMutex);
76 m_moduleHist->SetBinContent(m_moduleHist->GetBin( idHash%100+1, idHash/100+1), rejected_per_mod );
78 n_rejected += rejected_per_mod;
79 n_new += clone->size();
80 if (idHash>=emulatedDefects->m_detectorElements->size()) {
81 ATH_MSG_ERROR("Invalid ID hash " << idHash);
83 rdoOutContainer->addCollection( clone.release(), idHash).ignore();
85 m_rejectedRDOs += n_rejected;
87 ATH_MSG_DEBUG("rejected " << m_rejectedRDOs << ", copied " << m_totalRDOs << " RDOs");
89 return StatusCode::SUCCESS;