ATLAS Offline Software
SegmentFitParDecorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
5 
7 #include "StoreGate/ReadHandle.h"
13 namespace MuonR4 {
14  using namespace SegmentFit;
18  using PrdLinkVec = std::vector<PrdLink_t>;
20 
21 
22  template <class ContainerType>
25  const ContainerType*& contToPush) const {
26  contToPush = nullptr;
27  if (key.empty()) {
28  ATH_MSG_VERBOSE("No key has been parsed for object "<< typeid(ContainerType).name());
29  return StatusCode::SUCCESS;
30  }
31  SG::ReadHandle readHandle{key, ctx};
32  ATH_CHECK(readHandle.isPresent());
33  contToPush = readHandle.cptr();
34  return StatusCode::SUCCESS;
35  }
36 
38  ATH_CHECK(m_idHelperSvc.retrieve());
39  ATH_CHECK(m_geoCtxKey.initialize());
40  ATH_CHECK(detStore()->retrieve(m_detMgr));
41  ATH_CHECK(m_segmentKey.initialize());
42  ATH_CHECK(m_locParKey.initialize());
43  ATH_CHECK(m_prdLinkKey.initialize());
44  ATH_CHECK(m_keyTgc.initialize(!m_keyTgc.empty()));
45  ATH_CHECK(m_keyRpc.initialize(!m_keyRpc.empty()));
46  ATH_CHECK(m_keyMdt.initialize(!m_keyMdt.empty()));
47  ATH_CHECK(m_keysTgc.initialize(!m_keysTgc.empty()));
48  ATH_CHECK(m_keyMM.initialize(!m_keyMM.empty()));
49  return StatusCode::SUCCESS;
50  }
52  const MeasKey_t& key,
53  const Identifier& measId,
54  const xAOD::UncalibratedMeasurement*& meas) const {
55  const PrdCont_t* cont{nullptr};
56  ATH_CHECK(retrieveContainer(ctx,key, cont));
57  if (!cont) {
58  ATH_MSG_VERBOSE("No container key given");
59  return StatusCode::SUCCESS;
60  }
61  for (const xAOD::UncalibratedMeasurement* inCont : *cont) {
62  if (xAOD::identify(inCont) == measId) {
63  meas = inCont;
64  break;
65  }
66  }
67  if (!meas) {
68  ATH_MSG_WARNING("Failed to find the hit "<<m_idHelperSvc->toString(measId));
69  }
70  return StatusCode::SUCCESS;
71  }
72 
73  StatusCode SegmentFitParDecorAlg::execute(const EventContext& ctx) const {
74  const xAOD::MuonSegmentContainer* segmentContainer{nullptr};
75  ATH_CHECK(retrieveContainer(ctx, m_segmentKey, segmentContainer));
76  const ActsGeometryContext* gctx{nullptr};
77  ATH_CHECK(retrieveContainer(ctx, m_geoCtxKey, gctx));
80  for (const xAOD::MuonSegment* seg : *segmentContainer) {
81  PrdLinkVec& prdLinks{prdLinkDecor(*seg)};
82  const Trk::Segment* trkSeg{*seg->muonSegment()};
83  Identifier rotId{};
84 
85  auto addLink = [&, this](const Trk::RIO_OnTrack* rot) ->StatusCode{
86  if (!rot) {
87  return StatusCode::SUCCESS;;
88  }
89  if (!rotId.is_valid()) {
90  rotId = rot->identify();
91  }
92  const xAOD::UncalibratedMeasurement* prd{nullptr};
93  switch(m_idHelperSvc->technologyIndex(rot->identify())){
94  case TechIdx_t::MDT:
95  ATH_CHECK(fetchMeasurement(ctx, m_keyMdt, rot->identify(), prd));
96  break;
97  case TechIdx_t::RPC:
98  ATH_CHECK(fetchMeasurement(ctx, m_keyRpc, rot->identify(), prd));
99  break;
100  case TechIdx_t::TGC:
101  ATH_CHECK(fetchMeasurement(ctx, m_keyTgc, rot->identify(), prd));
102  break;
103  case TechIdx_t::MM:
104  ATH_CHECK(fetchMeasurement(ctx, m_keyMM, rot->identify(), prd));
105  break;
106  case TechIdx_t::STGC:
107  ATH_CHECK(fetchMeasurement(ctx, m_keysTgc, rot->identify(), prd));
108  break;
109  default:
110  break;
111  };
112  if (!prd) {
113  return StatusCode::SUCCESS;
114  }
115  ATH_MSG_VERBOSE("Link new measurement "<<m_idHelperSvc->toString(rot->identify()));
116  PrdLink_t link{*static_cast<const PrdCont_t*>(prd->container()),
117  prd->index()};
118  prdLinks.push_back(std::move(link));
119  return StatusCode::SUCCESS;
120  };
121 
122  for (const Trk::MeasurementBase* meas : trkSeg->containedMeasurements()) {
123  const auto* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas);
124  if (rot) {
125  ATH_CHECK(addLink(rot));
126  continue;
127  }
128  const auto* cRot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(meas);
129  if (cRot) {
130  for (unsigned int r = 0 ; r < cRot->numberOfContainedROTs(); ++r){
131  ATH_CHECK(addLink(&cRot->rioOnTrack(r)));
132  }
133  }
134  }
135  const MuonGMR4::SpectrometerSector* chamber = m_detMgr->getSectorEnvelope(rotId);
136  const Amg::Transform3D globToLoc{chamber->globalToLocalTrans(*gctx)};
137 
138  SegPars& locPars{parDecor(*seg)};
139 
140  const Amg::Vector3D locDir = globToLoc.linear() * seg->direction();
141  const Amg::Vector3D locPos = globToLoc * seg->position();
142 
143  const double travDist = Amg::intersect<3>(locPos, locDir, Amg::Vector3D::UnitZ(), 0).value_or(0);
144  const Amg::Vector3D atCentre = locPos + travDist * locDir;
145 
146  locPars[toInt(ParamDefs::x0)] = atCentre[toInt(AxisDefs::phi)];
147  locPars[toInt(ParamDefs::y0)] = atCentre[toInt(AxisDefs::eta)];
148  locPars[toInt(ParamDefs::theta)] = locDir.theta();
149  locPars[toInt(ParamDefs::phi)] = locDir.phi();
150  ATH_MSG_VERBOSE("Segment "<<m_idHelperSvc->toStringChamber(rotId)<<" at chamber centre "
151  <<Amg::toString(atCentre)<<" + x *"<<Amg::toString(locDir));
152  }
153  return StatusCode::SUCCESS;
154  }
155 
156 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TGC
@ TGC
Definition: RegSelEnums.h:33
beamspotman.r
def r
Definition: beamspotman.py:676
STGC
@ STGC
Definition: RegSelEnums.h:39
UtilFunctions.h
MuonGMR4::SpectrometerSector
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
Definition: SpectrometerSector.h:39
CompetingRIOsOnTrack.h
calibdata.chamber
chamber
Definition: calibdata.py:32
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SegmentFitParDecorAlg.h
MM
@ MM
Definition: RegSelEnums.h:38
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
xAOD::identify
Identifier identify(const UncalibratedMeasurement *meas)
Returns the associated identifier.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< ContainerType >
SpectrometerSector.h
MuonR4::SegmentFit::ParamDefs::phi
@ phi
MuonR4::SegmentFitParDecorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: SegmentFitParDecorAlg.cxx:73
MuonR4::SegmentFit::AxisDefs::phi
@ phi
DeMoGenerateWWW.addLink
def addLink(l)
When https is found in a character line, add a link in html If none, simply return the line unchanged...
Definition: DeMoGenerateWWW.py:68
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonR4::SegPars
xAOD::MeasVector< toInt(ParamDefs::nPars)> SegPars
Definition: SegmentFitParDecorAlg.cxx:15
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Trk::Segment
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:56
WriteDecorHandle.h
Handle class for adding a decoration to an object.
Trk::CompetingRIOsOnTrack
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
Definition: CompetingRIOsOnTrack.h:64
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonR4::SegmentFit::ParamDefs::x0
@ x0
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
MuonR4::SegmentFit::AxisDefs::eta
@ eta
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
xAOD::MeasVector
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
Definition: MeasurementDefs.h:52
MuonR4::SegmentFitParDecorAlg::retrieveContainer
StatusCode retrieveContainer(const EventContext &ctx, const SG::ReadHandleKey< ContType > &key, const ContType *&contPtr) const
Loads a container from the StoreGate and returns whether the retrieval is successful.
MuonR4::SegmentFitParDecorAlg::initialize
virtual StatusCode initialize() override final
Definition: SegmentFitParDecorAlg.cxx:37
Trk::MeasurementBase
Definition: MeasurementBase.h:58
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
MuonR4::SegmentFit::ParamDefs::y0
@ y0
RPC
@ RPC
Definition: RegSelEnums.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuonR4::SegmentFit::toInt
constexpr int toInt(const ParamDefs p)
Definition: MuonHoughDefs.h:42
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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
python.copyTCTOutput.locDir
locDir
Definition: copyTCTOutput.py:113
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
SegmentFitterEventData.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonSegment.h
MuonR4::PrdLinkVec
std::vector< PrdLink_t > PrdLinkVec
Definition: SegmentFitParDecorAlg.cxx:18
MuonR4::SegmentFitParDecorAlg::fetchMeasurement
StatusCode fetchMeasurement(const EventContext &ctx, const MeasKey_t &key, const Identifier &measId, const xAOD::UncalibratedMeasurement *&meas) const
Definition: SegmentFitParDecorAlg.cxx:51
ReadHandle.h
Handle class for reading from StoreGate.
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
MuonR4::SegmentFit::ParamDefs::nPars
@ nPars
MuonR4::SegmentFit::ParamDefs::theta
@ theta
MDT
@ MDT
Definition: RegSelEnums.h:31
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Identifier
Definition: IdentifierFieldParser.cxx:14