ATLAS Offline Software
DefectsEmulatorAlg.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 // Silicon trackers includes
5 #include "InDetRawData/PixelRDORawData.h"
6 
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"
15 
16 #include "StoreGate/WriteHandle.h"
17 #include <typeinfo>
18 
19 
20 namespace InDet{
21 
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()) );
28 
29  return DefectsEmulatorBase::initialize();
30  }
31 
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)) );
40 
41  unsigned int n_rejected=0u;
42  unsigned int n_new=0;
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() );
49  if (!helper) {
50  ATH_MSG_ERROR( "Not module design for " << idHash);
51  return StatusCode::FAILURE;
52  }
53  unsigned int rejected_per_mod=0u;
54  for(const auto *const rdo : *collection) {
55  const Identifier rdoID = rdo->identify();
56 
57  auto row_idx = m_idHelper->phi_index(rdoID);
58  auto col_idx = m_idHelper->eta_index(rdoID);
59 
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)
62  ).release() );
63  }
64  else {
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);
69  }
70  ++rejected_per_mod;
71  }
72 
73  }
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 );
77  }
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);
82  }
83  rdoOutContainer->addCollection( clone.release(), idHash).ignore();
84  }
85  m_rejectedRDOs += n_rejected;
86  m_totalRDOs += n_new;
87  ATH_MSG_DEBUG("rejected " << m_rejectedRDOs << ", copied " << m_totalRDOs << " RDOs");
88 
89  return StatusCode::SUCCESS;
90  }
91 
92 }