ATLAS Offline Software
Loading...
Searching...
No Matches
MdtCalibRawDataProvider.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
6#include "GaudiKernel/DataObject.h"
7#include "GaudiKernel/IRegistry.h"
8#include "MuCalDecode/CalibData.h"
9#include "MuCalDecode/CalibEvent.h"
10#include "MuCalDecode/CalibUti.h"
16
17#include <iostream>
18#include <algorithm>
19#include <list>
20#include <map>
21
27#include "GaudiKernel/ServiceHandle.h"
30
31using namespace LVL2_MUON_CALIBRATION;
32
33// function to sort the Mdt hits according to the LVL2 identifier
34bool CompareIds(const MdtCalibData data1, const MdtCalibData data2) { return data1.id() > data2.id(); }
35
36
37MdtCalibRawDataProvider::MdtCalibRawDataProvider(const std::string& name, ISvcLocator* pSvcLocator) :
38 AthReentrantAlgorithm(name, pSvcLocator) {}
39
41 ATH_MSG_INFO("MdtCalibRawDataProvider::initialize");
42
43 ATH_CHECK(m_detectorManagerKey.initialize());
44 ATH_CHECK(m_muonIdHelper.retrieve());
45 ATH_CHECK(m_dataProvider.retrieve());
47
48 return StatusCode::SUCCESS;
49}
50
51// --------------------------------------------------------------------
52// Execute
53StatusCode MdtCalibRawDataProvider::execute(const EventContext& ctx) const {
54
55 ATH_MSG_INFO("MdtCalibRawDataProvider::execute");
56
57 const CalibEvent *event = m_dataProvider->getEvent();
58
59 ATH_MSG_DEBUG("Event Pt : "<<event->pt());
60
61 // // setup output write handle for MdtPrepDataContainer
63
64 ATH_CHECK(handle.record(std::make_unique<Muon::MdtPrepDataContainer>(m_muonIdHelper->mdtIdHelper().module_hash_max())));
65 ATH_MSG_DEBUG("Created container " << m_mdtPrepDataContainerKey.key());
66 // Pass the container from the handle
67 Muon::MdtPrepDataContainer *mdtContainer = handle.ptr();
68
70 if (!muDetMgr.isValid()) {
71 ATH_MSG_FATAL("Failed to retrieve the Muon detector manager " << m_detectorManagerKey.fullKey());
72 return StatusCode::FAILURE;
73 }
74
75 ATH_CHECK(decodeImpl(mdtContainer, event, *muDetMgr));
76
77 ATH_MSG_DEBUG("MDT core decode processed in MT decode (calibration stream event)");
78
79 return StatusCode::SUCCESS;
80
81 } // end of execute
82
83StatusCode MdtCalibRawDataProvider::decodeImpl(Muon::MdtPrepDataContainer *mdtPrepDataContainer, const CalibEvent *event, const MuonGM::MuonDetectorManager* muDetMgr) const {
84
85 // decoding process from https://gitlab.cern.ch/atlas-mcp/MdtCalib/mdtcalibframework/-/blob/master/MuonCalibStream/MuonCalibStreamCnv/src/RpcRDOContCalibStreamCnv.cxx
86 // to be verified with run3 data
87
88 // Skip events with no MDT hits (otherwise crash below)
89 if (!event->mdt()) {
90 ATH_MSG_WARNING(" NO MDT hits in event!");
91 return StatusCode::SUCCESS;
92 }
93
94 // extract the list of MDT hit tubes
95 std::list<MdtCalibData> tubes = (event->mdt())->data();
96 // sort the list using CompareIds function
97 tubes.sort(CompareIds);
98
99 std::vector<std::unique_ptr<Muon::MdtPrepDataCollection>> mdtCollections{};
100
101 int mdt_hits(0), mdt_chambers(0);
102 int StationName{0}, StationEta{0}, StationPhi{0}, MultiLayer{0}, TubeLayer{0}, Tube{0};
103 // loop over MDT hit tubes
104 // assumes only leading tdc_counts is present on the data
105 const MdtIdHelper& idHelper{m_muonIdHelper->mdtIdHelper()};
106 for (const MdtCalibData& tubeData : tubes) {
107 uint16_t coarse = tubeData.leadingCoarse();
108 uint16_t fine = tubeData.leadingFine();
109 int tdc_counts = fine | (coarse << 5);
110 int adc_counts = tubeData.width();
111 WordIntoMdtId(tubeData.id(), StationName, StationEta, StationPhi, MultiLayer, TubeLayer, Tube);
112
113 // convert the tube hit info to an MdtPrepData object
115 Identifier channelId = idHelper.channelID(StationName, StationEta, StationPhi, MultiLayer, TubeLayer, Tube);
116
117 // give a fix radius and err here since the precise radius will be calculated later when MdtDriftCircleOnTrack is created
118 const MuonGM::MdtReadoutElement *detEl = muDetMgr->getMdtReadoutElement(channelId);
120 constexpr double radius(7.5), errRadius(4.2);
121 Amg::Vector2D driftRadius(radius, 0);
122 Amg::MatrixX errorMatrix{1, 1};
123 errorMatrix(0, 0) = (errRadius * errRadius);
124
125 IdentifierHash mdtHashId = m_muonIdHelper->moduleHash(channelId);
126
127 const unsigned int mdtHashIdx = static_cast<unsigned int>(mdtHashId);
128 if (mdtHashIdx >= mdtCollections.size()) mdtCollections.resize(mdtHashIdx + 1);
129 std::unique_ptr<Muon::MdtPrepDataCollection>& mdtCollection = mdtCollections[mdtHashIdx];
130 if (!mdtCollection) {
131 mdtCollection = std::make_unique<Muon::MdtPrepDataCollection>(mdtHashId);
132 mdtCollection->setIdentifier(idHelper.elementID(channelId));
133 }
134
135 std::unique_ptr<Muon::MdtPrepData> newPrepData = std::make_unique<Muon::MdtPrepData>(channelId, driftRadius, std::move(errorMatrix), detEl, tdc_counts, adc_counts, digitStatus);
136
137 ATH_MSG_DEBUG(" "<<m_muonIdHelper->toString(channelId)<<" ADC="<<adc_counts<<" TDC="<<tdc_counts<<" mdtHashId : "<<mdtHashId );
138 if (newPrepData->adc() < m_adcCut) {
139 continue;
140 }
141 // add the MdtPrepData to the collection
142 mdtCollection->push_back(std::move(newPrepData));
143
144 } // end loop over tubes
145
146 for (std::unique_ptr<Muon::MdtPrepDataCollection>& coll : mdtCollections) {
147 if (!coll) continue;
148 Muon::MdtPrepDataContainer::IDC_WriteHandle lock = mdtPrepDataContainer->getWriteHandle(coll->identifyHash());
149 ATH_CHECK(lock.addOrDelete(std::move(coll)));
150 }
151 ATH_MSG_DEBUG("Wrote " << mdt_hits << " MDT PRD hits for " << mdt_chambers << " chambers");
152
153 return StatusCode::SUCCESS;
154
155}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
bool CompareIds(const MdtCalibData data1, const MdtCalibData data2)
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
An algorithm that can be simultaneously executed in multiple threads.
StatusCode addOrDelete(std::unique_ptr< T > ptr)
IDC_WriteHandle getWriteHandle(IdentifierHash hash)
This is a "hash" representation of an Identifier.
virtual StatusCode execute(const EventContext &ctx) const override
Execute.
MdtCalibRawDataProvider(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ServiceHandle< Muon::IMuonIdHelperSvc > m_muonIdHelper
Gaudi::Property< int > m_adcCut
SG::WriteHandleKey< Muon::MdtPrepDataContainer > m_mdtPrepDataContainerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_detectorManagerKey
MuonDetectorManager from the conditions store.
StatusCode decodeImpl(Muon::MdtPrepDataContainer *mdtPrepDataContainer, const LVL2_MUON_CALIBRATION::CalibEvent *event, const MuonGM::MuonDetectorManager *muDetMgr) const
ServiceHandle< IMuonCalibStreamDataProviderSvc > m_dataProvider
virtual StatusCode initialize() override
Initialize.
Identifier elementID(int stationName, int stationEta, int stationPhi) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
const MdtReadoutElement * getMdtReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D
MuonPrepDataContainerT< MdtPrepData > MdtPrepDataContainer
MdtDriftCircleStatus
Enum to represent the 'status' of Mdt measurements e.g.
@ MdtStatusDriftTime
The tube produced a vaild measurement.