ATLAS Offline Software
MdtDigitToMdtRDO.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MdtDigitToMdtRDO.h"
6 
7 #include <algorithm>
8 #include <atomic>
9 #include <cmath>
10 
15 #include "MuonRDO/MdtCsm.h"
17 #include "MuonRDO/MdtCsmIdHash.h"
18 
21 namespace {
25  std::atomic<bool> bmgWarningPrinted = false;
26 
27 } // namespace
28 
29 MdtDigitToMdtRDO::MdtDigitToMdtRDO(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
32 
34  ATH_MSG_DEBUG(" in initialize()");
36  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_csmContainerKey);
38  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_digitContainerKey);
39  ATH_CHECK(m_idHelperSvc.retrieve());
42 
43  if (fillTagInfo().isFailure()) { ATH_MSG_WARNING("Could not fill the tagInfo for MDT cabling"); }
44 
45  m_BMG_station_name = m_idHelperSvc->mdtIdHelper().stationNameIndex("BMG");
47  if (m_BMGpresent) { ATH_MSG_INFO("Processing configuration for layouts with BME chambers (stationID: " << m_BMG_station_name << ")."); }
48  m_BIS_station_name = m_idHelperSvc->mdtIdHelper().stationNameIndex("BIS");
49  return StatusCode::SUCCESS;
50 }
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
54 
55 StatusCode MdtDigitToMdtRDO::execute(const EventContext& ctx) const {
56  ATH_MSG_DEBUG("in execute() : fill_MDTdata");
57  // create an empty pad container and record it
59  ATH_CHECK(csmContainer.record(std::make_unique<MdtCsmContainer>()));
60  ATH_MSG_DEBUG("Recorded MdtCsmContainer called " << csmContainer.name() << " in store " << csmContainer.store());
61 
63  if (!container.isValid()) {
64  ATH_MSG_ERROR("Could not find MdtDigitContainer called " << container.name() << " in store " << container.store());
65  return StatusCode::SUCCESS;
66  }
67  ATH_MSG_DEBUG("Found MdtDigitContainer called " << container.name() << " in store " << container.store());
68 
70  const MuonMDT_CablingMap* cabling_ptr{*readHandle_Cabling};
71  if (!cabling_ptr) {
72  ATH_MSG_ERROR("Null pointer to the read conditions object");
73  return StatusCode::FAILURE;
74  }
75 
76  SG::ReadCondHandle<MdtCondDbData> readHandle_Conditions{m_condKey, ctx};
77  const MdtCondDbData* condtionsPtr{*readHandle_Conditions};
78  if (!condtionsPtr) {
79  ATH_MSG_ERROR("Null pointer to the read conditions object");
80  return StatusCode::FAILURE;
81  }
82  const MdtIdHelper& id_helper = m_idHelperSvc->mdtIdHelper();
83  auto& msg = msgStream();
84 
86  using csmMap = std::map<IdentifierHash, std::unique_ptr<MdtCsm>>;
87  csmMap csm_cache{};
88  // Iterate on the collections
89  for (const MdtDigitCollection* mdtCollection : *container) {
90  const Identifier chid1 = mdtCollection->identify();
92  if (!condtionsPtr->isGood(chid1)) continue;
93 
95  if (!cabling_ptr->convert(chid1, cabling_data)) {
96  ATH_MSG_FATAL("Found a non mdt identifier " << m_idHelperSvc->toString(chid1));
97  return StatusCode::FAILURE;
98  }
99 
101  for (const MdtDigit* mdtDigit : *mdtCollection) {
102  const Identifier channelId = mdtDigit->identify();
103 
104  if (!id_helper.valid(channelId) || !cabling_ptr->convert(channelId, cabling_data)) {
105  ATH_MSG_DEBUG("Found invalid mdt identifier " << channelId);
106  continue;
107  }
108 
110  bool cabling = cabling_ptr->getOnlineId(cabling_data, msg);
111 
112  if (!cabling) {
113  if (cabling_data.stationIndex == m_BMG_station_name) {
114  if (!bmgWarningPrinted) {
115  ATH_MSG_WARNING("Apparently BMG chambers are disconnected to the cabling. "
116  << "This has been checked to only appear in mc16a-like setups as the chambers were installed in "
117  "the end-of-the-year shutdown 2016. "
118  << "In any other case, be despaired in facing the villian and check what has gone wrong");
119  bmgWarningPrinted = true;
120  }
121  continue;
122  }
124  if (m_isPhaseII && id_helper.stationName(channelId) == m_BIS_station_name && m_idHelperSvc->issMdt(channelId)) {
125  ATH_MSG_DEBUG("Found BIS sMDT which cannot be mapped " << cabling_data
126  << ". This should only happen in the Phase-II geometry.");
127  continue;
128  }
129  ATH_MSG_ERROR("MDTcabling can't return an online ID for the channel : " << cabling_data);
130  return StatusCode::FAILURE;
131  }
132 
133  // Create the new AMT hit
134  std::unique_ptr<MdtAmtHit> amtHit =
135  std::make_unique<MdtAmtHit>(cabling_data.tdcId, cabling_data.channelId, mdtDigit->is_masked());
136  // Get coarse time and fine time
137  int tdc_counts = mdtDigit->tdc();
138 
139  uint16_t coarse = (tdc_counts >> 5) & 0xfff;
140  uint16_t fine = tdc_counts & 0x1f;
141  uint16_t width = mdtDigit->adc();
142 
143  amtHit->setValues(coarse, fine, width);
144 
145  ATH_MSG_DEBUG("Adding a new AmtHit -- " << cabling_data);
146  ATH_MSG_DEBUG(" Coarse time : " << coarse << " Fine time : " << fine << " Width : " << width);
147 
149  IdentifierHash csm_hash{0};
150  Identifier csmId{0};
152  if (!cabling_ptr->getMultiLayerCode(cabling_data, csmId, csm_hash, msg)) {
153  ATH_MSG_ERROR("Hash generation failed for " << cabling_data);
154  return StatusCode::FAILURE;
155  }
156 
158  csmMap::iterator csm_itr = csm_cache.find(csm_hash);
159  if (csm_itr == csm_cache.end()) {
160  ATH_MSG_DEBUG("Insert new CSM module using " << cabling_data << " " << m_idHelperSvc->toString(csmId));
161  std::unique_ptr<MdtCsm> csm =
162  std::make_unique<MdtCsm>(csmId, csm_hash, cabling_data.subdetectorId, cabling_data.mrod, cabling_data.csm);
163  csm_itr = csm_cache.insert(std::make_pair(csm_hash, std::move(csm))).first;
164  }
165  std::unique_ptr<MdtCsm>& mdtCsm = csm_itr->second;
166  // Check that the CSM is correct
167  if (cabling_data.csm != mdtCsm->CsmId() || cabling_data.subdetectorId != mdtCsm->SubDetId() ||
168  cabling_data.mrod != mdtCsm->MrodId()) {
169  ATH_MSG_FATAL("Cannot create AmtHit " << cabling_data);
170  return StatusCode::FAILURE;
171  }
172  // Add the digit to the CSM
173  mdtCsm->push_back(std::move(amtHit));
174  }
175  }
177  for (auto& csm_coll : csm_cache) {
178  ATH_MSG_DEBUG("Add CSM container " << csm_coll.first << " " << csm_coll.first);
179  ATH_CHECK(csmContainer->addCollection(csm_coll.second.release(), csm_coll.first));
180  }
181  return StatusCode::SUCCESS;
182 }
183 
184 // NOTE: although this function has no clients in release 22, currently the Run2 trigger simulation is still run in
185 // release 21 on RDOs produced in release 22. Since release 21 accesses the TagInfo, it needs to be written to the
186 // RDOs produced in release 22. The fillTagInfo() function thus needs to stay in release 22 until the workflow changes
188  ServiceHandle<ITagInfoMgr> tagInfoMgr("TagInfoMgr", name());
189  if (tagInfoMgr.retrieve().isFailure()) { return StatusCode::FAILURE; }
190 
191  std::string cablingType = "NewMDT_Cabling"; // everything starting from Run2 should be 'New'
192  StatusCode sc = tagInfoMgr->addTag("MDT_CablingType", cablingType);
193 
194  if (sc.isFailure()) {
195  ATH_MSG_WARNING("MDT_CablingType " << cablingType << " not added to TagInfo ");
196  return sc;
197  } else {
198  ATH_MSG_DEBUG("MDT_CablingType " << cablingType << " is Added TagInfo ");
199  }
200 
201  return StatusCode::SUCCESS;
202 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
MdtAmtHit::setValues
void setValues(uint16_t coarse, uint16_t fine, uint16_t width)
Definition: MdtAmtHit.cxx:26
MdtCsm::CsmId
uint16_t CsmId() const
Returns the CSM online id (online identifier inside a MROD)
Definition: MdtCsm.h:61
MdtDigitToMdtRDO::m_BMG_station_name
int m_BMG_station_name
Definition: MdtDigitToMdtRDO.h:34
MdtDigitCollection.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MdtDigitToMdtRDO::m_csmContainerKey
SG::WriteHandleKey< MdtCsmContainer > m_csmContainerKey
Definition: MdtDigitToMdtRDO.h:37
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
IdentifiableContainerMT::addCollection
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
Definition: IdentifiableContainerMT.h:300
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MdtDigit
Definition: MdtDigit.h:19
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
MdtDigitToMdtRDO::m_BIS_station_name
int m_BIS_station_name
Definition: MdtDigitToMdtRDO.h:35
MdtDigitToMdtRDO.h
ITagInfoMgr.h
MdtDigitToMdtRDO::m_cablingKey
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_cablingKey
Definition: MdtDigitToMdtRDO.h:40
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
MdtDigitToMdtRDO::MdtDigitToMdtRDO
MdtDigitToMdtRDO(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MdtDigitToMdtRDO.cxx:29
MdtCsm::SubDetId
uint16_t SubDetId() const
Returns the sub-detector Id.
Definition: MdtCsm.h:57
createCablingJSON.cabling_data
dictionary cabling_data
Definition: createCablingJSON.py:18
MdtDigit.h
MdtCondDbData
Definition: MdtCondDbData.h:21
MuonIdHelper::stationName
int stationName(const Identifier &id) const
Definition: MuonIdHelper.cxx:804
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MdtCsmContainer.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MdtCsmIdHash.h
MdtCsm::MrodId
uint16_t MrodId() const
Returns the MROD id from the CSM header.
Definition: MdtCsm.h:59
MuonMDT_CablingMap
Definition: MuonMDT_CablingMap.h:28
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MdtDigitToMdtRDO::fillTagInfo
StatusCode fillTagInfo() const
Definition: MdtDigitToMdtRDO.cxx:187
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
MdtDigitToMdtRDO::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: MdtDigitToMdtRDO.cxx:55
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
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:379
MdtIdHelper
Definition: MdtIdHelper.h:61
MdtDigitToMdtRDO::m_condKey
SG::ReadCondHandleKey< MdtCondDbData > m_condKey
Definition: MdtDigitToMdtRDO.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MdtCablingData
Definition: MdtCablingData.h:82
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
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
MdtDigitToMdtRDO::m_isPhaseII
Gaudi::Property< bool > m_isPhaseII
Definition: MdtDigitToMdtRDO.h:43
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MdtDigitCollection
Definition: MdtDigitCollection.h:18
MdtCsm.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
MdtDigitToMdtRDO::initialize
virtual StatusCode initialize() override final
Definition: MdtDigitToMdtRDO.cxx:33
MdtDigitToMdtRDO::m_BMGpresent
bool m_BMGpresent
Definition: MdtDigitToMdtRDO.h:33
MdtIdHelper::valid
bool valid(const Identifier &id) const
Public validation of levels.
Definition: MdtIdHelper.cxx:531
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
MdtDigitContainer.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MdtDigitToMdtRDO::m_digitContainerKey
SG::ReadHandleKey< MdtDigitContainer > m_digitContainerKey
Definition: MdtDigitToMdtRDO.h:38
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
IdentifierHash
Definition: IdentifierHash.h:38
MdtDigitToMdtRDO::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MdtDigitToMdtRDO.h:36
ServiceHandle< ITagInfoMgr >