ATLAS Offline Software
xAODSegmentCnvAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "xAODSegmentCnvAlg.h"
5 
7 
13 
14 
15 
16 namespace MuonR4{
17  using namespace SegmentFit;
21  using PrdLinkVec_t = std::vector<PrdLink_t>;
22 
24 
25 
27 
28  constexpr TechIdx_t toTechIdx(const xAOD::UncalibMeasType aodType){
29  switch (aodType){
31  return TechIdx_t::MDT;
33  return TechIdx_t::RPC;
35  return TechIdx_t::TGC;
37  return TechIdx_t::MM;
39  return TechIdx_t::STGC;
40  default:
41  return TechIdx_t::TechnologyUnknown;
42  }
43  }
44 
46  ATH_CHECK(m_idHelperSvc.retrieve());
47  ATH_CHECK(m_readKey.initialize());
48  ATH_CHECK(m_geoCtxKey.initialize());
49 
50  ATH_CHECK(m_writeKey.initialize());
51  ATH_CHECK(m_prdLinkKey.initialize());
52  ATH_CHECK(m_localSegParKey.initialize());
53  ATH_CHECK(m_parentSegKey.initialize());
54  return StatusCode::SUCCESS;
55  }
56  StatusCode xAODSegmentCnvAlg::execute(const EventContext& ctx) const {
57 
58  SG::WriteHandle outContainer{m_writeKey, ctx};
59  ATH_CHECK(outContainer.record(std::make_unique<xAOD::MuonSegmentContainer>(),
60  std::make_unique<xAOD::MuonSegmentAuxContainer>()));
61 
62 
63  SG::WriteDecorHandle<xAOD::MuonSegmentContainer, SegLink_t> dec_parentLink{m_parentSegKey, ctx};
64  SG::WriteDecorHandle<xAOD::MuonSegmentContainer, SegPars_t> dec_locPars{m_localSegParKey, ctx};
66  const SegmentContainer* segmentContainer{nullptr};
67  const ActsGeometryContext* gctx{nullptr};
68  ATH_CHECK(SG::get(segmentContainer, m_readKey, ctx));
69  ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
70 
71  for (const Segment* inSegment : *segmentContainer) {
72  const MuonGMR4::SpectrometerSector* sector = inSegment->msSector();
73 
74  xAOD::MuonSegment* convertedSeg = outContainer->push_back(std::make_unique<xAOD::MuonSegment>());
75  dec_parentLink(*convertedSeg) = SegLink_t{segmentContainer, outContainer->size() -1};
76 
77  const Amg::Vector3D& pos{inSegment->position()};
78  const Amg::Vector3D& dir{inSegment->direction()};
79  const Amg::Transform3D globToLoc{sector->globalToLocalTrans(*gctx)};
80  convertedSeg->setPosition(pos.x(), pos.y(), pos.z());
81  convertedSeg->setDirection(dir.x(), dir.y(), dir.z());
82 
83 
84  convertedSeg->setIdentifier(sector->sector(), sector->chamberIndex(), sector->side(),
85  toTechIdx(inSegment->summary().tech));
86  convertedSeg->setFitQuality(inSegment->chi2(), inSegment->nDoF());
87  convertedSeg->setNHits(inSegment->summary().nPrecHits, inSegment->summary().nPhiHits,
88  inSegment->summary().nEtaTrigHits);
89 
90  convertedSeg->setT0Error(inSegment->segementT0(),
91  Amg::error(inSegment->covariance(), toInt(ParamDefs::time)));
92 
94  SegPars_t& localPars{dec_locPars(*convertedSeg)};
95  const Amg::Vector3D locPos{globToLoc * pos};
96  const Amg::Vector3D locDir{globToLoc.linear() * dir};
97 
98  localPars[toInt(ParamDefs::x0)] = locPos.x();
99  localPars[toInt(ParamDefs::y0)] = locPos.y();
100  localPars[toInt(ParamDefs::theta)] = locDir.theta();
101  localPars[toInt(ParamDefs::phi)] = locDir.phi();
102  localPars[toInt(ParamDefs::time)] = inSegment->segementT0();
103 
105  PrdLinkVec_t& prdLinks{dec_prdLinks(*convertedSeg)};
106  auto appendLink = [&prdLinks](const xAOD::UncalibratedMeasurement* meas) {
107  if (!meas) {
108  return;
109  }
110  prdLinks.emplace_back(static_cast<const xAOD::UncalibratedMeasurementContainer*>(meas->container()),
111  meas->index());
112 
113  };
114  for (const auto& meas : inSegment->measurements()) {
115  if (!meas->spacePoint()) {
116  continue;
117  }
118  appendLink(meas->spacePoint()->primaryMeasurement());
119  if (meas->spacePoint()->primaryMeasurement() !=
120  meas->spacePoint()->secondaryMeasurement()){
121  appendLink(meas->spacePoint()->secondaryMeasurement());
122  }
123  }
124  }
125  return StatusCode::SUCCESS;
126  }
127 }
MuonGMR4::SpectrometerSector::sector
int sector() const
Returns the sector of the MS-sector.
Definition: SpectrometerSector.cxx:64
MuonGMR4::SpectrometerSector::side
int8_t side() const
Returns the side of the MS-sector 1 -> A side ; -1 -> C side.
Definition: SpectrometerSector.cxx:57
MuonGMR4::SpectrometerSector
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
Definition: SpectrometerSector.h:40
xAOD::MuonSegment_v1::setPosition
void setPosition(float x, float y, float z)
Sets the global position.
Definition: MuonSegment_v1.cxx:26
Muon::MuonStationIndex::TechnologyIndex::RPC
@ RPC
MuonSegmentAuxContainer.h
EventPrimitivesHelpers.h
MuonR4::Segment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:19
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
xAOD::UncalibMeasType::MMClusterType
@ MMClusterType
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
MuonR4::SegPars_t
xAOD::MeasVector< toInt(ParamDefs::nPars)> SegPars_t
Definition: xAODSegmentCnvAlg.cxx:23
MuonR4::xAODSegmentCnvAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: xAODSegmentCnvAlg.cxx:56
xAOD::UncalibMeasType::sTgcStripType
@ sTgcStripType
Muon::MuonStationIndex::TechnologyIndex::MDT
@ MDT
xAOD::MuonSegment_v1::setT0Error
void setT0Error(float t0, float t0Error)
Sets the time error.
Definition: MuonSegment_v1.cxx:51
MuonR4::SegmentFit::ParamDefs::phi
@ phi
xAOD::UncalibMeasType::TgcStripType
@ TgcStripType
xAOD::MuonSegment_v1::setNHits
void setNHits(int nPrecisionHits, int nPhiLayers, int nTrigEtaLayers)
Set the number of hits/layers.
Definition: MuonSegment_v1.cxx:88
xAODSegmentCnvAlg.h
MuonGMR4::SpectrometerSector::chamberIndex
Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index scheme.
Definition: SpectrometerSector.cxx:62
WriteHandle.h
Handle class for recording to StoreGate.
Muon::MuonStationIndex::TechnologyIndex::MM
@ MM
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
MuonR4::toTechIdx
constexpr TechIdx_t toTechIdx(const xAOD::UncalibMeasType aodType)
Definition: xAODSegmentCnvAlg.cxx:28
Muon::MuonStationIndex::TechnologyIndex::TGC
@ TGC
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
MuonGMR4::SpectrometerSector::globalToLocalTrans
Amg::Transform3D globalToLocalTrans(const ActsGeometryContext &gctx) const
Returns the global -> local transformation from the ATLAS global.
Definition: SpectrometerSector.cxx:78
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonPatternContainer.h
UncalibratedMeasurementContainer.h
MuonR4::PrdLinkVec_t
std::vector< PrdLink_t > PrdLinkVec_t
Definition: xAODSegmentCnvAlg.cxx:21
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonR4::SegmentFit::ParamDefs::x0
@ x0
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
MuonR4::SegmentFit::ParamDefs::time
@ time
beamspotman.dir
string dir
Definition: beamspotman.py:621
xAOD::MeasVector
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
Definition: MeasurementDefs.h:53
MuonR4::SegmentFit::ParamDefs::y0
@ y0
Amg::error
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Definition: EventPrimitivesHelpers.h:40
MuonR4::SegmentFit::toInt
constexpr int toInt(const ParamDefs p)
Definition: MuonHoughDefs.h:42
xAOD::UncalibratedMeasurementContainer
UncalibratedMeasurementContainer_v1 UncalibratedMeasurementContainer
Define the version of the uncalibrated measurement container.
Definition: UncalibratedMeasurementContainer.h:14
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4::xAODSegmentCnvAlg::initialize
virtual StatusCode initialize() override final
Definition: xAODSegmentCnvAlg.cxx:45
python.copyTCTOutput.locDir
locDir
Definition: copyTCTOutput.py:112
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
xAOD::MuonSegment_v1::setIdentifier
void setIdentifier(int sector, ::Muon::MuonStationIndex::ChIndex chamberIndex, int etaIndex, ::Muon::MuonStationIndex::TechnologyIndex technology)
Set the identifier.
Definition: MuonSegment_v1.cxx:73
Muon::MuonStationIndex::TechnologyIndex::STGC
@ STGC
xAOD::UncalibMeasType
UncalibMeasType
Define the type of the uncalibrated measurement.
Definition: MeasurementDefs.h:25
xAOD::MuonSegment_v1::setDirection
void setDirection(float px, float py, float pz)
Sets the direction.
Definition: MuonSegment_v1.cxx:39
xAOD::MuonSegment_v1::setFitQuality
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
Definition: MuonSegment_v1.cxx:61
MuonR4::SegmentFit::ParamDefs::nPars
@ nPars
xAOD::UncalibMeasType::RpcStripType
@ RpcStripType
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
MuonR4::SegmentFit::ParamDefs::theta
@ theta