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 }
58 const MuonR4::Segment& segment,
59 Acts::ObjVisualization3D& visualHelper,
60 const Acts::ViewConfig& viewConfig) {
62 const Amg::Transform3D& locToGlob = segment.msSector()->localToGlobalTransform(gctx);
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 }
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(gctx.context());
96 const Amg::Vector3D lastSurfPos = xAOD::muonSurface(lastMeas).center(gctx.context());
97
98 const Segment* detSeg = detailedSegment(segment);
100 const Amg::Vector3D planeNorm = detSeg->msSector()->localToGlobalTransform(gctx).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 }
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(gctx, meas, visualHelper, viewConfig);
119 }
120 }
122 const MuonR4::Segment& segment,
123 Acts::ObjVisualization3D& visualHelper,
124 const Acts::ViewConfig& viewConfig) {
125 for (const auto& meas : segment.measurements()) {
126 drawSpacePoint(gctx, *meas, segment.msSector(), visualHelper, viewConfig);
127 }
128 }
131 Acts::ObjVisualization3D& visualHelper,
132 const Acts::ViewConfig& viewConfig) {
133
135 const Acts::Surface& surf{*surfAcc.get(meas)};
136 const Acts::GeometryContext tgContext = gctx.context();
137 const auto& bounds = surf.bounds();
139 const auto& lBounds = static_cast<const Acts::LineBounds&>(bounds);
140 const auto* driftCirc = static_cast<const xAOD::MdtDriftCircle*>(meas);
141 const double dR = driftCirc->driftRadius();
142 const double hZ = driftCirc->numDimensions() == 1 ?
143 lBounds.get(Acts::LineBounds::eHalfLengthZ) :
144 std::sqrt(meas->localCovariance<2>()(1,1));
145 auto newBounds = std::make_unique<Acts::LineBounds>(dR, hZ);
146 auto dummySurface = Acts::Surface::makeShared<Acts::StrawSurface>(surf.localToGlobalTransform(tgContext)*
147 Amg::getTranslate3D(driftCirc->localMeasurementPos()),
148 std::move(newBounds));
149 Acts::GeometryView3D::drawSurface(visualHelper, *dummySurface, tgContext,
150 Amg::Transform3D::Identity(), viewConfig);
151 return;
152 }
153 double dX{0.}, dY{0.};
154 Amg::Vector3D locPos{Amg::Vector3D::Zero()};
155 switch (meas->numDimensions()) {
157 case 0:{
158 const auto* cmbMeas = static_cast<const xAOD::CombinedMuonStrip*>(meas);
159 const auto [locPos2D, locCov2D] = xAOD::positionAndCovariance(cmbMeas);
160 dX = std::sqrt(locCov2D(0,0));
161 dY = std::sqrt(locCov2D(1,1));
162 locPos.block<2,1>(0,0) = locPos2D;
163 break;
164 } case 1:{
167 const auto* rpcClus = static_cast<const xAOD::RpcMeasurement*>(meas);
168 locPos = rpcClus->localMeasurementPos();
169 dX = rpcClus->measuresPhi() ? 0.5* rpcClus->readoutElement()->stripPhiLength()
170 : std::sqrt(rpcClus->localCovariance<1>()(0,0));
171 dY = rpcClus->measuresPhi() ? std::sqrt(rpcClus->localCovariance<1>()(0,0))
172 : 0.5* rpcClus->readoutElement()->stripEtaLength();
173 } else if (meas->type() == xAOD::UncalibMeasType::TgcStripType) {
174 const auto* tgcClus = static_cast<const xAOD::TgcStrip*>(meas);
175 const MuonGMR4::TgcReadoutElement* re = tgcClus->readoutElement();
176 const auto& stripLay = re->sensorLayout(tgcClus->measurementHash());
177 locPos = tgcClus->localMeasurementPos();
178 dX = tgcClus->measuresPhi() ? 0.5* stripLay->design(true).stripLength(tgcClus->channelNumber())
179 : std::sqrt(tgcClus->localCovariance<1>()(0,0));
180 dY = tgcClus->measuresPhi() ? std::sqrt(tgcClus->localCovariance<1>()(0,0))
181 : 0.5* stripLay->design(false).stripLength(tgcClus->channelNumber());
182 } else if (meas->type() == xAOD::UncalibMeasType::MMClusterType) {
183 const auto* mmClust = static_cast<const xAOD::MMCluster*>(meas);
184 locPos = mmClust->localMeasurementPos();
185 dX = std::sqrt(mmClust->localCovariance<1>()(0,0));
186 dY = 0.5* mmClust->readoutElement()->stripLength(mmClust->measurementHash());
187 } else if(meas->type() == xAOD::UncalibMeasType::sTgcStripType) {
188 const auto* sTgcClus = static_cast<const xAOD::sTgcMeasurement*>(meas);
189 locPos = sTgcClus->localMeasurementPos();
190 if (sTgcClus->channelType() == sTgcIdHelper::sTgcChannelTypes::Strip){
191 dX = std::sqrt(sTgcClus->localCovariance<1>()(0,0));
192 dY = 0.5* sTgcClus->readoutElement()->stripDesign(sTgcClus->measurementHash()).stripLength(sTgcClus->channelNumber());
193 } else if (sTgcClus->channelType() == sTgcIdHelper::sTgcChannelTypes::Wire) {
194 dY = std::sqrt(sTgcClus->localCovariance<1>()(0,0));
195 dX = 0.5*sTgcClus->readoutElement()->wireDesign(sTgcClus->measurementHash()).stripLength(sTgcClus->channelNumber());
196 }
197 } else if (meas->type() == xAOD::UncalibMeasType::Other) {
198 const auto* pseudo = static_cast<const xAOD::AuxiliaryMeasurement*>(meas);
199 using ProjectorType = xAOD::AuxiliaryMeasurement::ProjectorType;
200 constexpr double measLength = 1._m;
201 if (pseudo->calibProjector() == ProjectorType::e1DimNoTime) {
202 dX = std::sqrt(meas->localCovariance<1>()(0,0));
203 dY = measLength;
204 } else if (pseudo->calibProjector() == ProjectorType::e1DimRotNoTime) {
205 dY = std::sqrt(meas->localCovariance<1>()(0,0));
206 dX = measLength;
207 }
208 }
209 break;
210 }
212 case 2:{
213 locPos.block<2,1>(0, 0) = xAOD::toEigen(meas->localPosition<2>());
214 dX = std::sqrt(meas->localCovariance<2>()(0,0));
215 dY = std::sqrt(meas->localCovariance<2>()(1,1));
216 break;
217 }
218 }
219
220 std::shared_ptr<Acts::Surface> dummySurf{};
221
222 if (surf.type() == Acts::Surface::SurfaceType::Straw) {
223 auto newBounds = std::make_unique<Acts::LineBounds>(dX, dY);
224 dummySurf = Acts::Surface::makeShared<Acts::StrawSurface>(surf.localToGlobalTransform(tgContext)*
225 Amg::getTranslate3D(locPos),
226 std::move(newBounds));
227
228 } else {
229 auto newBounds = std::make_unique<Acts::RectangleBounds>(dX, dY);
230 dummySurf = Acts::Surface::makeShared<Acts::PlaneSurface>(surf.localToGlobalTransform(tgContext)*
231 Amg::getTranslate3D(locPos),
232 std::move(newBounds));
233
234 }
235 Acts::GeometryView3D::drawSurface(visualHelper, *dummySurf, tgContext,
236 Amg::Transform3D::Identity(), viewConfig);
237 }
239 const Acts::BoundTrackParameters& pars,
240 Acts::ObjVisualization3D& visualHelper,
241 const Acts::ViewConfig& viewConfig,
242 const double standardLength){
243 const Amg::Vector3D globPos = pars.position(gctx.context());
244 const Amg::Vector3D start = globPos - 0.5 * standardLength * pars.direction();
245 const Amg::Vector3D end = globPos + 0.5 * standardLength * pars.direction();
246 Acts::GeometryView3D::drawSegment(visualHelper, start, end, viewConfig);
247 }
249 const MuonR4::SpacePoint& spacePoint,
250 Acts::ObjVisualization3D& visualHelper,
251 const Acts::ViewConfig& viewConfig) {
252 if (spacePoint.dimension() == 2 && !spacePoint.isStraw() &&
253 spacePoint.primaryMeasurement() != spacePoint.secondaryMeasurement()) {
254 const Amg::Transform3D& locToGlob = spacePoint.msSector()->localToGlobalTransform(gctx);
255 const double dX = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
256 const double dY = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::etaCov)]);
257 auto bounds = std::make_unique<Acts::RectangleBounds>(dX, dY);
258 const Acts::Transform3 trf = locToGlob * Amg::getTranslate3D(spacePoint.localPosition());
259 auto surf = Acts::Surface::makeShared<Acts::PlaneSurface>(trf, std::move(bounds));
260 Acts::GeometryView3D::drawSurface(visualHelper, *surf, gctx.context());
261 } else {
262 drawMeasurement(gctx, spacePoint.primaryMeasurement(),
263 visualHelper, viewConfig);
264 }
265 }
267 const MuonR4::CalibratedSpacePoint& spacePoint,
268 const MuonGMR4::SpectrometerSector* msSector,
269 Acts::ObjVisualization3D& visualHelper,
270 const Acts::ViewConfig& viewConfig) {
271 if (spacePoint.type() != xAOD::UncalibMeasType::Other) {
272 drawSpacePoint(gctx, *spacePoint.spacePoint(), visualHelper, viewConfig);
273 return;
274 }
275 const Amg::Transform3D& locToGlob = msSector->localToGlobalTransform(gctx);
276 if (spacePoint.isStraw()) {
277 const double dR = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::etaCov)]);
278 const double hZ = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
279 auto bounds = std::make_unique<Acts::LineBounds>(dR, hZ);
280 const Amg::Transform3D trf = locToGlob * Amg::getTranslate3D(spacePoint.localPosition());
281 auto surface = Acts::Surface::makeShared<Acts::StrawSurface>(trf, std::move(bounds));
282 Acts::GeometryView3D::drawSurface(visualHelper, *surface, gctx.context());
283 } else {
284 const double dX = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
285 const double dY = std::sqrt(spacePoint.covariance()[Acts::toUnderlying(CovIdx::etaCov)]);
286 auto bounds = std::make_unique<Acts::RectangleBounds>(dX, dY);
287 const Acts::Transform3 trf = locToGlob * Amg::getTranslate3D(spacePoint.localPosition());
288 auto surf = Acts::Surface::makeShared<Acts::PlaneSurface>(trf, std::move(bounds));
289 Acts::GeometryView3D::drawSurface(visualHelper, *surf, gctx.context());
290 }
291 }
292
293
294} // namespace MuonValR4
const boost::regex re(r_e)
Scalar mag() const
mag method
Acts::GeometryContext context() const
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...
unsigned dimension() const
Is the space point a 1D or combined 2D measurement.
bool isStraw() const
Returns whether the measurement is a Mdt.
const xAOD::UncalibratedMeasurement * secondaryMeasurement() const
const Cov_t & covariance() const
Returns the covariance array.
const xAOD::UncalibratedMeasurement * primaryMeasurement() const
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 drawBoundParameters(const ActsTrk::GeometryContext &gctx, 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 drawMeasurement(const ActsTrk::GeometryContext &gctx, const xAOD::UncalibratedMeasurement *meas, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw an uncalibrated measurement inside the obj file.
void drawSpacePoint(const ActsTrk::GeometryContext &gctx, const MuonR4::SpacePoint &spacePoint, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw an uncalibrated space point inside the obj file.
void drawSegmentMeasurements(const ActsTrk::GeometryContext &gctx, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw all uncalibrated measurements associated to the segment.
void drawSegmentLine(const ActsTrk::GeometryContext &gctx, 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.
AuxiliaryMeasurement_v1 AuxiliaryMeasurement
MdtDriftCircle_v1 MdtDriftCircle
TgcStrip_v1 TgcStrip
Definition TgcStripFwd.h:9
std::pair< Amg::Vector2D, AmgSymMatrix(2)> positionAndCovariance(const CombinedMuonStrip *combinedPrd)
Returns the position and covariance from a combined strip measurement.
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
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.