ATLAS Offline Software
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 
22 #include "StoreGate/StoreGateSvc.h"
27 #include "GaudiKernel/ServiceHandle.h"
30 
31 using namespace LVL2_MUON_CALIBRATION;
32 
33 // function to sort the Mdt hits according to the LVL2 identifier
34 bool CompareIds(const MdtCalibData data1, const MdtCalibData data2) { return data1.id() > data2.id(); }
35 
36 
37 MdtCalibRawDataProvider::MdtCalibRawDataProvider(const std::string& name, ISvcLocator* pSvcLocator) :
38  AthReentrantAlgorithm(name, pSvcLocator) {}
39 
41  ATH_MSG_INFO("MdtCalibRawDataProvider::initialize");
42 
44  ATH_CHECK(m_muonIdHelper.retrieve());
45  ATH_CHECK(m_dataProvider.retrieve());
46  ATH_CHECK(m_mdtPrepDataContainerKey.initialize());
47 
48  return StatusCode::SUCCESS;
49 }
50 
51 // --------------------------------------------------------------------
52 // Execute
53 StatusCode 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 
83 StatusCode 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);
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 }
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
MuonCalibStreamAddress.h
MdtReadoutElement.h
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
MdtCalibRawDataProvider::m_adcCut
Gaudi::Property< int > m_adcCut
Definition: MdtCalibRawDataProvider.h:69
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
AthCheckMacros.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthMsgStreamMacros.h
LVL2_MUON_CALIBRATION
Definition: MuCalStreamerTool.h:37
IdentifiableContainerMT::getWriteHandle
IDC_WriteHandle getWriteHandle(IdentifierHash hash)
Definition: IdentifiableContainerMT.h:248
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Muon::MdtDriftCircleStatus
MdtDriftCircleStatus
Enum to represent the 'status' of Mdt measurements e.g.
Definition: MdtDriftCircleStatus.h:25
Muon::MdtPrepData::adc
int adc() const
Returns the ADC (typically range is 0 to 250)
Definition: MdtPrepData.h:146
Muon::MuonPrepDataCollection::setIdentifier
virtual void setIdentifier(Identifier id)
Muon::MdtStatusDriftTime
@ MdtStatusDriftTime
The tube produced a vaild measurement.
Definition: MdtDriftCircleStatus.h:34
Muon::TubeLayer
HedgehogBoard::TubeLayer TubeLayer
Definition: HedgehogBoard.cxx:27
ReadCondHandle.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MdtPrepDataCollection.h
RTTAlgmain.data2
data2
Definition: RTTAlgmain.py:54
MuonGM::MuonDetectorManager::getMdtReadoutElement
const MdtReadoutElement * getMdtReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:204
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:51
MuonPrepDataCollection.h
MdtCalibRawDataProvider::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execute.
Definition: MdtCalibRawDataProvider.cxx:53
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
Trk::driftRadius
@ driftRadius
trt, straws
Definition: ParamDefs.h:53
WriteCondHandle.h
MdtCalibRawDataProvider::m_dataProvider
ServiceHandle< IMuonCalibStreamDataProviderSvc > m_dataProvider
Definition: MdtCalibRawDataProvider.h:61
MdtCalibRawDataProvider::MdtCalibRawDataProvider
MdtCalibRawDataProvider(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: MdtCalibRawDataProvider.cxx:37
IdentifiableContainerMT::IDC_WriteHandle
Definition: IdentifiableContainerMT.h:34
MdtIdHelper
Definition: MdtIdHelper.h:61
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MdtCalibRawDataProvider.h
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
ReadCondHandleKey.h
MdtCalibHit.h
WriteHandleKey.h
Property holding a SG store/key/clid from which a WriteHandle is made.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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)
MdtCalibRawDataProvider::m_mdtPrepDataContainerKey
SG::WriteHandleKey< Muon::MdtPrepDataContainer > m_mdtPrepDataContainerKey
Definition: MdtCalibRawDataProvider.h:63
MdtCalibRawDataProvider::m_detectorManagerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_detectorManagerKey
Definition: MdtCalibRawDataProvider.h:65
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
IdentifiableContainerMT::IDC_WriteHandle::addOrDelete
StatusCode addOrDelete(std::unique_ptr< T > ptr)
Definition: IdentifiableContainerMT.h:53
RTTAlgmain.data1
data1
Definition: RTTAlgmain.py:54
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CompareIds
bool CompareIds(const MdtCalibData data1, const MdtCalibData data2)
Definition: MdtCalibRawDataProvider.cxx:34
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:50
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MdtCalibRawDataProvider::decodeImpl
StatusCode decodeImpl(Muon::MdtPrepDataContainer *mdtPrepDataContainer, const CalibEvent *event, const MuonGM::MuonDetectorManager *muDetMgr) const
Definition: MdtCalibRawDataProvider.cxx:83
MdtCalibRawDataProvider::initialize
virtual StatusCode initialize() override
Initialize.
Definition: MdtCalibRawDataProvider.cxx:40
MdtCalibRawDataProvider::m_muonIdHelper
ServiceHandle< Muon::IMuonIdHelperSvc > m_muonIdHelper
Definition: MdtCalibRawDataProvider.h:67
StoreGateSvc.h
Identifier
Definition: IdentifierFieldParser.cxx:14