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 
23  using SegPars_t = xAOD::MeasVector<Acts::toUnderlying(ParamDefs::nPars)>;
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_readKeys.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 ActsGeometryContext* gctx{nullptr};
67 
68  ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
69  for (const SG::ReadHandleKey<SegmentContainer>& key : m_readKeys) {
70  const SegmentContainer* segmentContainer{nullptr};
71  ATH_CHECK(SG::get(segmentContainer, key, ctx));
72 
74  unsigned recoSegIdx{0};
75  for (const Segment* inSegment : *segmentContainer) {
76  const MuonGMR4::SpectrometerSector* sector = inSegment->msSector();
77 
78  xAOD::MuonSegment* convertedSeg = outContainer->push_back(std::make_unique<xAOD::MuonSegment>());
79  dec_parentLink(*convertedSeg) = SegLink_t{segmentContainer, recoSegIdx};
80  ++recoSegIdx;
81 
82  const Amg::Vector3D& pos{inSegment->position()};
83  const Amg::Vector3D& dir{inSegment->direction()};
84  convertedSeg->setPosition(pos.x(), pos.y(), pos.z());
85  convertedSeg->setDirection(dir.x(), dir.y(), dir.z());
86 
87 
88  convertedSeg->setIdentifier(sector->sector(), sector->chamberIndex(), sector->side(),
89  toTechIdx(inSegment->summary().tech));
90  convertedSeg->setFitQuality(inSegment->chi2(), inSegment->nDoF());
91  convertedSeg->setNHits(inSegment->summary().nPrecHits, inSegment->summary().nPhiHits,
92  inSegment->summary().nEtaTrigHits);
93 
94  using enum ParamDefs;
95  convertedSeg->setT0Error(inSegment->segementT0(),
96  Amg::error(inSegment->covariance(), Acts::toUnderlying(t0)));
97 
98  SegPars_t& localPars{dec_locPars(*convertedSeg)};
99  const Amg::Transform3D globToLoc{sector->globalToLocalTrans(*gctx)};
100  const Amg::Vector3D locPos{globToLoc * pos};
101  const Amg::Vector3D locDir{globToLoc.linear() * dir};
102 
103  localPars[Acts::toUnderlying(x0)] = locPos.x();
104  localPars[Acts::toUnderlying(y0)] = locPos.y();
105  localPars[Acts::toUnderlying(theta)] = locDir.theta();
106  localPars[Acts::toUnderlying(phi)] = locDir.phi();
107  localPars[Acts::toUnderlying(t0)] = inSegment->segementT0();
108 
110  PrdLinkVec_t& prdLinks{dec_prdLinks(*convertedSeg)};
111  auto appendLink = [&prdLinks](const xAOD::UncalibratedMeasurement* meas) {
112  if (!meas) {
113  return;
114  }
115  const auto* mCont = static_cast<const xAOD::UncalibratedMeasurementContainer*>(meas->container());
116  prdLinks.emplace_back(mCont, meas->index());
117  };
118  for (const auto& meas : inSegment->measurements()) {
119  if (!meas->spacePoint()) {
120  continue;
121  }
122  appendLink(meas->spacePoint()->primaryMeasurement());
123  if (meas->spacePoint()->primaryMeasurement() !=
124  meas->spacePoint()->secondaryMeasurement()){
125  appendLink(meas->spacePoint()->secondaryMeasurement());
126  }
127  }
128  }
129  }
130  return StatusCode::SUCCESS;
131  }
132 }
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
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
DataVector::emplace_back
value_type emplace_back(value_type pElem)
Add an element to the end of the collection.
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
MuonR4::SegPars_t
xAOD::MeasVector< Acts::toUnderlying(ParamDefs::nPars)> SegPars_t
Definition: xAODSegmentCnvAlg.cxx:23
MuonSegmentAuxContainer.h
EventPrimitivesHelpers.h
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
MuonR4::Segment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:19
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
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::SegmentFit::ParamDefs
SeedingAux::FitParIndex ParamDefs
Use the same parameter indices as used by the CompSpacePointAuxiliaries.
Definition: MuonHoughDefs.h:37
MuonR4::xAODSegmentCnvAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: xAODSegmentCnvAlg.cxx:56
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
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
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
beamspotman.dir
string dir
Definition: beamspotman.py:619
xAOD::MeasVector
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
Definition: MeasurementDefs.h:53
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
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:110
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
xAOD::UncalibMeasType::RpcStripType
@ RpcStripType
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37