ATLAS Offline Software
Loading...
Searching...
No Matches
ObjVisualizationHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
7
15
17
20
21#include "Acts/Surfaces/detail/PlanarHelper.hpp"
22#include "Acts/Visualization/GeometryView3D.hpp"
23#include "Acts/Surfaces/StrawSurface.hpp"
24#include "Acts/Surfaces/LineBounds.hpp"
25#include "Acts/Surfaces/RectangleBounds.hpp"
26#include "Acts/Surfaces/TrapezoidBounds.hpp"
27#include "Acts/Surfaces/PlaneSurface.hpp"
28#include "Acts/Definitions/Units.hpp"
29
30
31using namespace Acts::PlanarHelper;
32using namespace MuonR4;
33using namespace Acts::UnitLiterals;
34
35namespace{
36 using CovIdx = MuonR4::SpacePoint::CovIdx;
37}
38
39namespace MuonValR4 {
40 void drawPropagation(const std::vector<Acts::detail::Step>& steps,
41 Acts::ObjVisualization3D& visualHelper,
42 const Acts::ViewConfig& viewConfig){
43
44 if (steps.empty()) {
45 return;
46 }
47 Amg::Vector3D start = steps.front().position;
48 for (std::size_t s = 1; s < steps.size(); ++s) {
49 Amg::Vector3D end = steps[s].position;
50 if ( (end - start).mag() > Acts::s_epsilon){
51 Acts::GeometryView3D::drawSegment(visualHelper, start, end, viewConfig);
52 start = std::move(end);
53 }
54
55 }
56 }
57 void drawSegmentLine(const Acts::GeometryContext& tgContext,
58 const MuonR4::Segment& segment,
59 Acts::ObjVisualization3D& visualHelper,
60 const Acts::ViewConfig& viewConfig) {
62 const Amg::Transform3D& locToGlob = segment.msSector()->localToGlobalTransform(tgContext);
63 const Amg::Vector3D firstSurfPos = locToGlob*segment.measurements().front()->localPosition();
64 const Amg::Vector3D lastSurfPos = locToGlob*segment.measurements().back()->localPosition();
65 const Amg::Vector3D planeNorm = locToGlob.linear().col(2);
67 const auto firstPlaneIsect = intersectPlane(segment.position(), segment.direction(),
68 planeNorm, firstSurfPos);
69 const auto lastPlaneIsect = intersectPlane(segment.position(), segment.direction(),
70 planeNorm, lastSurfPos);
71
72 Acts::GeometryView3D::drawSegment(visualHelper,
73 segment.position() + firstPlaneIsect.pathLength() * segment.direction(),
74 segment.position() + lastPlaneIsect.pathLength() * segment.direction(),
75 viewConfig);
76 }
77 void drawSegmentLine(const Acts::GeometryContext& tgContext,
78 const xAOD::MuonSegment& segment,
79 Acts::ObjVisualization3D& visualHelper,
80 const Acts::ViewConfig& viewConfig ,
81 const double standardLength){
82
83 std::vector<const xAOD::UncalibratedMeasurement*> assocMeas = collectMeasurements(segment, false);
84 if (assocMeas.empty()){
85 Acts::GeometryView3D::drawSegment(visualHelper,
86 segment.position() - 0.5 * standardLength * segment.direction(),
87 segment.position() + 0.5 * standardLength * segment.direction(),
88 viewConfig);
89 return;
90 }
91 const xAOD::UncalibratedMeasurement* firstMeas = assocMeas.front()->type() != xAOD::UncalibMeasType::Other ?
92 assocMeas.front() : assocMeas[1];
93 const xAOD::UncalibratedMeasurement* lastMeas = assocMeas.back();
94
95 const Amg::Vector3D firstSurfPos = xAOD::muonSurface(firstMeas).center(tgContext);
96 const Amg::Vector3D lastSurfPos = xAOD::muonSurface(lastMeas).center(tgContext);
97
98 const Segment* detSeg = detailedSegment(segment);
100 const Amg::Vector3D planeNorm = detSeg->msSector()->localToGlobalTransform(tgContext).linear().col(2);
102 const auto firstPlaneIsect = intersectPlane(segment.position(), segment.direction(),
103 planeNorm, firstSurfPos);
104 const auto lastPlaneIsect = intersectPlane(segment.position(), segment.direction(),
105 planeNorm, lastSurfPos);
106
107 Acts::GeometryView3D::drawSegment(visualHelper,
108 segment.position() + firstPlaneIsect.pathLength() * segment.direction(),
109 segment.position() + lastPlaneIsect.pathLength() * segment.direction(),
110 viewConfig);
111 }
112 void drawSegmentMeasurements(const Acts::GeometryContext& tgContext,
113 const xAOD::MuonSegment& segment,
114 Acts::ObjVisualization3D& visualHelper,
115 const Acts::ViewConfig& viewConfig) {
116 std::vector<const xAOD::UncalibratedMeasurement*> assocMeas = collectMeasurements(segment, false);
117 for (const xAOD::UncalibratedMeasurement* meas : assocMeas){
118 drawMeasurement(tgContext, meas, visualHelper, viewConfig);
119 }
120 }
121 void drawSegmentMeasurements(const Acts::GeometryContext& tgContext,
122 const MuonR4::Segment& segment,
123 Acts::ObjVisualization3D& visualHelper,
124 const Acts::ViewConfig& viewConfig) {
125 for (const auto& meas : segment.measurements()) {
126 drawSpacePoint(tgContext, *meas, segment.msSector(), visualHelper, viewConfig);
127 }
128 }
129 void drawMeasurement(const Acts::GeometryContext& tgContext,
131 Acts::ObjVisualization3D& visualHelper,
132 const Acts::ViewConfig& viewConfig) {
133
135 const Acts::Surface& surf{*surfAcc.get(meas)};
136 const auto& bounds = surf.bounds();
138 const auto& lBounds = static_cast<const Acts::LineBounds&>(bounds);
139 const auto* driftCirc = static_cast<const xAOD::MdtDriftCircle*>(meas);
140 const double dR = driftCirc->driftRadius();
141 const double hZ = driftCirc->numDimensions() == 1 ?
142 lBounds.get(Acts::LineBounds::eHalfLengthZ) :
143 std::sqrt(meas->localCovariance<2>()(1,1));
144 auto newBounds = std::make_unique<Acts::LineBounds>(dR, hZ);
145 auto dummySurface = Acts::Surface::makeShared<Acts::StrawSurface>(surf.localToGlobalTransform(tgContext)*
146 Amg::getTranslate3D(driftCirc->localMeasurementPos()),
147 std::move(newBounds));
148 Acts::GeometryView3D::drawSurface(visualHelper, *dummySurface, tgContext,
149 Amg::Transform3D::Identity(), viewConfig);
150 return;
151 }
152 double dX{0.}, dY{0.};
153 Amg::Vector3D locPos{Amg::Vector3D::Zero()};
154 switch (meas->numDimensions()) {
156 case 0:{
157 const auto* cmbMeas = static_cast<const xAOD::CombinedMuonStrip*>(meas);
158 dX = std::sqrt(cmbMeas->localCovariance<2>()(0,0));
159 dY = std::sqrt(cmbMeas->localCovariance<2>()(1,1));
160 locPos.block<2,1>(0,0) = xAOD::toEigen(cmbMeas->localPosition<2>());
161 break;
162 } case 1:{
165 const auto* rpcClus = static_cast<const xAOD::RpcMeasurement*>(meas);
166 locPos = rpcClus->localMeasurementPos();
167 dX = rpcClus->measuresPhi() ? 0.5* rpcClus->readoutElement()->stripPhiLength()
168 : std::sqrt(rpcClus->localCovariance<1>()(0,0));
169 dY = rpcClus->measuresPhi() ? std::sqrt(rpcClus->localCovariance<1>()(0,0))
170 : 0.5* rpcClus->readoutElement()->stripEtaLength();
171 } else if (meas->type() == xAOD::UncalibMeasType::TgcStripType) {
172 const auto* tgcClus = static_cast<const xAOD::TgcStrip*>(meas);
173 const MuonGMR4::TgcReadoutElement* re = tgcClus->readoutElement();
174 const auto& stripLay = re->sensorLayout(tgcClus->measurementHash());
175 locPos = tgcClus->localMeasurementPos();
176 dX = tgcClus->measuresPhi() ? 0.5* stripLay->design(true).stripLength(tgcClus->channelNumber())
177 : std::sqrt(tgcClus->localCovariance<1>()(0,0));
178 dY = tgcClus->measuresPhi() ? std::sqrt(tgcClus->localCovariance<1>()(0,0))
179 : 0.5* stripLay->design(false).stripLength(tgcClus->channelNumber());
180 } else if (meas->type() == xAOD::UncalibMeasType::MMClusterType) {
181 const auto* mmClust = static_cast<const xAOD::MMCluster*>(meas);
182 locPos = mmClust->localMeasurementPos();
183 dX = std::sqrt(mmClust->localCovariance<1>()(0,0));
184 dY = 0.5* mmClust->readoutElement()->stripLength(mmClust->measurementHash());
185 } else if(meas->type() == xAOD::UncalibMeasType::sTgcStripType) {
186 const auto* sTgcClus = static_cast<const xAOD::sTgcMeasurement*>(meas);
187 locPos = sTgcClus->localMeasurementPos();
188 if (sTgcClus->channelType() == sTgcIdHelper::sTgcChannelTypes::Strip){
189 dX = std::sqrt(sTgcClus->localCovariance<1>()(0,0));
190 dY = 0.5* sTgcClus->readoutElement()->stripDesign(sTgcClus->measurementHash()).stripLength(sTgcClus->channelNumber());
191 } else if (sTgcClus->channelType() == sTgcIdHelper::sTgcChannelTypes::Wire) {
192 dY = std::sqrt(sTgcClus->localCovariance<1>()(0,0));
193 dX = 0.5*sTgcClus->readoutElement()->wireDesign(sTgcClus->measurementHash()).stripLength(sTgcClus->channelNumber());
194 }
195 } else if (meas->type() == xAOD::UncalibMeasType::Other) {
196 const auto* pseudo = static_cast<const xAOD::AuxiliaryMeasurement*>(meas);
197 using ProjectorType = xAOD::AuxiliaryMeasurement::ProjectorType;
198 constexpr double measLength = 1._m;
199 if (pseudo->calibProjector() == ProjectorType::e1DimNoTime) {
200 dX = std::sqrt(meas->localCovariance<1>()(0,0));
201 dY = measLength;
202 } else if (pseudo->calibProjector() == ProjectorType::e1DimRotNoTime) {
203 dY = std::sqrt(meas->localCovariance<1>()(0,0));
204 dX = measLength;
205 }
206 }
207 break;
208 }
210 case 2:{
211 locPos.block<2,1>(0, 0) = xAOD::toEigen(meas->localPosition<2>());
212 dX = std::sqrt(meas->localCovariance<2>()(0,0));
213 dY = std::sqrt(meas->localCovariance<2>()(1,1));
214 break;
215 }
216 }
217
218 std::shared_ptr<Acts::Surface> dummySurf{};
219
220 if (surf.type() == Acts::Surface::SurfaceType::Straw) {
221 auto newBounds = std::make_unique<Acts::LineBounds>(dX, dY);
222 dummySurf = Acts::Surface::makeShared<Acts::StrawSurface>(surf.localToGlobalTransform(tgContext)*
223 Amg::getTranslate3D(locPos),
224 std::move(newBounds));
225
226 } else {
227 auto newBounds = std::make_unique<Acts::RectangleBounds>(dX, dY);
228 dummySurf = Acts::Surface::makeShared<Acts::PlaneSurface>(surf.localToGlobalTransform(tgContext)*
229 Amg::getTranslate3D(locPos),
230 std::move(newBounds));
231
232 }
233 Acts::GeometryView3D::drawSurface(visualHelper, *dummySurf, tgContext,
234 Amg::Transform3D::Identity(), viewConfig);
235 }
236 void drawBoundParameters(const Acts::GeometryContext& tgContext,
237 const Acts::BoundTrackParameters& pars,
238 Acts::ObjVisualization3D& visualHelper,
239 const Acts::ViewConfig& viewConfig,
240 const double standardLength){
241 const Amg::Vector3D globPos = pars.position(tgContext);
242 const Amg::Vector3D start = globPos - 0.5 * standardLength * pars.direction();
243 const Amg::Vector3D end = globPos + 0.5 * standardLength * pars.direction();
244 Acts::GeometryView3D::drawSegment(visualHelper, start, end, viewConfig);
245 }
246 void drawSpacePoint(const Acts::GeometryContext& tgContext,
247 const MuonR4::SpacePoint& spacePoint,
248 Acts::ObjVisualization3D& visualHelper,
249 const Acts::ViewConfig& viewConfig) {
250 if (spacePoint.dimension() == 2 && !spacePoint.isStraw() &&
251 spacePoint.primaryMeasurement() != spacePoint.secondaryMeasurement()) {
252 const Amg::Transform3D& locToGlob = spacePoint.msSector()->localToGlobalTransform(tgContext);
253 const double dX = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
254 const double dY = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::etaCov)]);
255 auto bounds = std::make_unique<Acts::RectangleBounds>(dX, dY);
256 const Acts::Transform3 trf = locToGlob * Amg::getTranslate3D(spacePoint.localPosition());
257 auto surf = Acts::Surface::makeShared<Acts::PlaneSurface>(trf, std::move(bounds));
258 Acts::GeometryView3D::drawSurface(visualHelper, *surf, tgContext);
259 } else {
260 drawMeasurement(tgContext, spacePoint.primaryMeasurement(),
261 visualHelper, viewConfig);
262 }
263 }
264 void drawSpacePoint(const Acts::GeometryContext& tgContext,
265 const MuonR4::CalibratedSpacePoint& spacePoint,
266 const MuonGMR4::SpectrometerSector* msSector,
267 Acts::ObjVisualization3D& visualHelper,
268 const Acts::ViewConfig& viewConfig) {
269 if (spacePoint.type() != xAOD::UncalibMeasType::Other) {
270 drawSpacePoint(tgContext, *spacePoint.spacePoint(), visualHelper, viewConfig);
271 return;
272 }
273 const Amg::Transform3D& locToGlob = msSector->localToGlobalTransform(tgContext);
274 if (spacePoint.isStraw()) {
275 const double dR = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::etaCov)]);
276 const double hZ = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
277 auto bounds = std::make_unique<Acts::LineBounds>(dR, hZ);
278 const Amg::Transform3D trf = locToGlob * Amg::getTranslate3D(spacePoint.localPosition());
279 auto surface = Acts::Surface::makeShared<Acts::StrawSurface>(trf, std::move(bounds));
280 Acts::GeometryView3D::drawSurface(visualHelper, *surface, tgContext);
281 } else {
282 const double dX = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
283 const double dY = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::etaCov)]);
284 auto bounds = std::make_unique<Acts::RectangleBounds>(dX, dY);
285 const Acts::Transform3 trf = locToGlob * Amg::getTranslate3D(spacePoint.localPosition());
286 auto surf = Acts::Surface::makeShared<Acts::PlaneSurface>(trf, std::move(bounds));
287 Acts::GeometryView3D::drawSurface(visualHelper, *surf, tgContext);
288 }
289 }
290
291
292} // namespace MuonValR4
const std::regex re(r_e)
Scalar mag() const
mag method
Helper class to access the Acts::surface associated with an Uncalibrated xAOD measurement.
const Acts::Surface * get(const xAOD::UncalibratedMeasurement *meas) const
Operator.
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &gctx) const
Returns the local -> global tarnsformation from the sector.
The calibrated Space point is created during the calibration process.
const Amg::Vector3D & localPosition() const
bool isStraw() const
Returns whether the measurement is a Mdt.
const SpacePoint * spacePoint() const
The pointer to the space point out of which this space point has been built.
xAOD::UncalibMeasType type() const
Returns the space point type.
const Cov_t & covariance() const
Returns the covariance array.
Placeholder for what will later be the muon segment EDM representation.
const MuonGMR4::SpectrometerSector * msSector() const
Returns the associated MS sector.
const MeasVec & measurements() const
Returns the associated measurements.
const Amg::Vector3D & position() const
Returns the global segment position.
const Amg::Vector3D & direction() const
Returns the global segment direction.
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
const Cov_t & covariance() const
Returns the covariance array.
unsigned dimension() const
Is the space point a 1D or combined 2D measurement.
bool isStraw() const
Returns whether the measurement is a Mdt.
ActsTrk::detail::MeasurementCalibratorBase::ProjectorType ProjectorType
Use the calibration projector.
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
ConstMatrixMap< N > localCovariance() const
Returns the local covariance of the measurement.
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
virtual unsigned int numDimensions() const =0
Returns the number of dimensions of the measurement.
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
Amg::Transform3D getTranslate3D(const double X, const double Y, const double Z)
: Returns a shift transformation along an arbitrary axis
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
This header ties the generic definitions in this package.
std::vector< const xAOD::UncalibratedMeasurement * > collectMeasurements(const xAOD::MuonSegment &segment, bool skipOutlier=true)
Helper function to extract the measurements from the segment.
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
void drawSegmentMeasurements(const Acts::GeometryContext &tgContext, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw all uncalibrated measurements associated to the segment.
void drawBoundParameters(const Acts::GeometryContext &tgContext, const Acts::BoundTrackParameters &pars, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine, const double standardLength=3.*Gaudi::Units::cm)
Draw a line representing the bound track parameters.
void drawPropagation(const std::vector< Acts::detail::Step > &steps, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine)
Draws the recorded propagation steps as a polygon line.
void drawSegmentLine(const Acts::GeometryContext &tgContext, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine, const double standardLength=1.*Gaudi::Units::m)
Draw a segment line inside the obj file.
void drawSpacePoint(const Acts::GeometryContext &tgContext, const MuonR4::SpacePoint &spacePoint, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw an uncalibrated space point inside the obj file.
void drawMeasurement(const Acts::GeometryContext &tgContext, const xAOD::UncalibratedMeasurement *meas, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw an uncalibrated measurement inside the obj file.
AuxiliaryMeasurement_v1 AuxiliaryMeasurement
MdtDriftCircle_v1 MdtDriftCircle
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
TgcStrip_v1 TgcStrip
Definition TgcStripFwd.h:9
RpcMeasurement_v1 RpcMeasurement
MMCluster_v1 MMCluster
sTgcMeasurement_v1 sTgcMeasurement
MuonSegment_v1 MuonSegment
Reference the current persistent version:
const Acts::Surface & muonSurface(const UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.
CombinedMuonStrip_v1 CombinedMuonStrip