ATLAS Offline Software
Loading...
Searching...
No Matches
PatternVisualizationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5
10
14
19
20#include "Acts/Utilities/Helpers.hpp"
21#include "Acts/Surfaces/RectangleBounds.hpp"
22#include "Acts/Surfaces/TrapezoidBounds.hpp"
23#include "Acts/Surfaces/PlaneSurface.hpp"
24#include "Acts/Surfaces/StrawSurface.hpp"
25#include "Acts/Visualization/GeometryView3D.hpp"
26
27
28#include <format>
29#include <sstream>
30#include <filesystem>
31
32
33#include "TH1F.h"
34#include "TH2F.h"
35#include "TMarker.h"
36#include "TColor.h"
37namespace {
38 constexpr int truthColor = kOrange +2;
39 constexpr int parLineColor = kRed;
40 using SpacePointSet = std::unordered_set<const MuonR4::SpacePoint*>;
41}
42
43
44namespace MuonValR4 {
45 using namespace MuonR4;
46 using namespace SegmentFit;
48
50 if (m_canvasLimit > 0) {
51 m_clientToken.canvasLimit = m_canvasLimit;
52 m_clientToken.preFixName = m_canvasPrefix;
53 m_clientToken.saveSinglePlots = m_saveSinglePDFs;
54 m_clientToken.saveSummaryPlot = m_saveSummaryPDF;
55 m_clientToken.subDirectory = m_subDir;
56 ATH_CHECK(m_visualSvc.retrieve());
57 ATH_CHECK(m_visualSvc->registerClient(m_clientToken));
58 } else {
59 m_plotsDone = true;
60 }
61 ATH_CHECK(m_prepContainerKeys.initialize(!m_truthSegLinks.empty()));
63 ATH_MSG_INFO("Hits linked to the following segment decorations are considered as truth");
64 for (const std::string& decorName : m_truthSegLinks) {
65 ATH_MSG_INFO(" **** "<<decorName);
66 if (decorName.empty()) {
67 ATH_MSG_FATAL("Decoration must not be empty");
68 return StatusCode::FAILURE;
69 }
71 m_truthLinkDecorKeys.emplace_back(key, decorName);
72 m_truthLinkDecors.push_back(SegLinkDecor_t{decorName});
73 }
74 }
75 ATH_CHECK(m_truthLinkDecorKeys.initialize());
76 m_displayOnlyTruth.value() &= !m_truthLinkDecorKeys.empty();
77
78 ATH_CHECK(m_idHelperSvc.retrieve());
79 ATH_CHECK(m_geoCtxKey.initialize());
80 ATH_CHECK(detStore()->retrieve(m_detMgr));
81 return StatusCode::SUCCESS;
82 }
88 return std::find_if(m_truthLinkDecors.begin(), m_truthLinkDecors.end(),
89 [&hit](const SegLinkDecor_t& decor){
90 return !decor(hit).empty();
91 }) != m_truthLinkDecors.end();
92 }
93
94 LabeledSegmentSet PatternVisualizationTool::getLabeledSegments(const std::vector<const MuonR4::SpacePoint*>& hits) const {
95 std::vector<const xAOD::UncalibratedMeasurement*> measurements{};
96 measurements.reserve(2* hits.size());
97 for (const SpacePoint* hit: hits) {
98 measurements.push_back(hit->primaryMeasurement());
99 if(hit->secondaryMeasurement()) {
100 measurements.push_back(hit->secondaryMeasurement());
101 }
102 }
103 return getLabeledSegments(measurements);
104 }
105 LabeledSegmentSet PatternVisualizationTool::getLabeledSegments(const std::vector<const xAOD::UncalibratedMeasurement*>& hits) const {
106 LabeledSegmentSet truthSegs{};
107 for (const xAOD::UncalibratedMeasurement* hit : hits) {
108 for (const SegLinkDecor_t& decor: m_truthLinkDecors) {
109 for (const SegLink_t& link : decor(*hit)) {
110 truthSegs.insert(*link);
111 }
112 }
113 }
114 return truthSegs;
115 }
116 // void PatternVisualizationTool::drawPrimitives(const TCanvas& can, PrimitiveVec& primitives) const {
117 // const double yLow = can.GetPad(0)->GetUymin();
118 // const double yHigh = can.GetPad(0)->GetUymax();
119 // for (auto& prim : primitives) {
120 // const TObject &primRef = *prim;
121 // if (typeid(primRef) == typeid(TLine)){
122 // TLine* line = static_cast<TLine*>(prim.get());
123 // const Amg::Vector3D linePoint{line->GetX1(), line->GetY1(), 0.};
124 // const Amg::Vector3D lineDir = Amg::Vector3D{(line->GetX2() - line->GetX1()) / (line->GetY2() - line->GetY1()), 1.,0.}.unit();
125
126 // const Amg::Vector3D newHigh = linePoint + Amg::intersect<3>(linePoint, lineDir, Amg::Vector3D::UnitY(), yHigh).value_or(0.) * lineDir;
127 // const Amg::Vector3D newLow = linePoint + Amg::intersect<3>(linePoint, lineDir, Amg::Vector3D::UnitY(), yLow).value_or(0.) * lineDir;
128 // line->SetX1(newLow.x());
129 // line->SetY1(newLow.y());
130 // line->SetX2(newHigh.x());
131 // line->SetY2(newHigh.y());
132 // }
133 // prim->Draw();
134 // }
135 // }
137 const MuonR4::HoughPlane& accumulator,
138 const Acts::HoughTransformUtils::HoughAxisRanges& axisRanges,
139 const MaximumVec& maxima,
140 const std::string& extraLabel) const {
141 PrimitiveVec primitives{};
142 visualizeAccumulator(ctx, accumulator, axisRanges, maxima, extraLabel, std::move(primitives));
143 }
145 const MuonR4::HoughPlane& accumulator,
146 const Acts::HoughTransformUtils::HoughAxisRanges& axisRanges,
147 const MaximumVec& maxima,
148 const std::string& extraLabel,
149 PrimitiveVec&& primitives) const {
150
152 if (m_plotsDone) {
153 return;
154 }
155 if (accumulator.getNonEmptyBins().empty()) {
156 ATH_MSG_WARNING("Hough accumulator is empty");
157 return;
158 }
159
160 auto accHisto = std::make_unique<TH2F>("AccumulatorHisto", "histo",
161 accumulator.nBinsX(), axisRanges.xMin, axisRanges.xMax,
162 accumulator.nBinsY(), axisRanges.yMin, axisRanges.yMax);
163 accHisto->SetDirectory(nullptr);
164
165 std::vector<const SpacePoint*> spacePointsInAcc{};
166 for (const std::size_t bin : accumulator.getNonEmptyBins()) {
167 const auto [xBin, yBin] = accumulator.axisBins(bin);
168 auto hitIds = accumulator.hitIds(xBin, yBin);
169 spacePointsInAcc.insert(spacePointsInAcc.end(),hitIds.begin(), hitIds.end());
170 accHisto->SetBinContent(xBin+1, yBin+1, accumulator.nHits(bin));
171 }
172
173 const LabeledSegmentSet truthSegs{getLabeledSegments(spacePointsInAcc)};
174 if (truthSegs.empty() && m_displayOnlyTruth) {
175 return;
176 }
177 auto canvas = m_visualSvc->prepareCanvas(ctx, m_clientToken, extraLabel);
178 if (!canvas){
179 m_plotsDone = true;
180 return;
181 }
182 canvas->expandPad(axisRanges.xMin, axisRanges.yMin);
183 canvas->expandPad(axisRanges.xMax, axisRanges.yMax);
184 canvas->setAxisTitles(std::format("tan#{}", m_accumlIsEta ? "beta" : "#alpha"),
185 std::format("{:}_{{0}} [mm]", m_accumlIsEta ? "y" : "x"));
186 canvas->add(std::move(accHisto), "HIST SAME");
187
188 for (const xAOD::MuonSegment* segment : truthSegs) {
189 const auto [pos, dir] = makeLine(localSegmentPars(*segment));
190 const double tan = m_accumlIsEta ? houghTanBeta(dir) : houghTanAlpha(dir);
191 const double icept = pos[m_accumlIsEta ? objViewEta : objViewPhi];
192 auto truthMarker = std::make_unique<TMarker>(tan, icept, kFullCrossX);
193 truthMarker->SetMarkerColor(truthColor);
194 truthMarker->SetMarkerSize(8);
195 canvas->add(std::move(truthMarker));
196 canvas->add(drawLabel(std::format("true parameters: {:}",
197 makeLabel(localSegmentPars(*segment))),0.2, 0.9));
198 }
199 for (const auto& maximum : maxima) {
200 auto maxMarker = std::make_unique<TMarker>(maximum.x, maximum.y, kFullTriangleUp);
201 maxMarker->SetMarkerColor(parLineColor);
202 maxMarker->SetMarkerSize(8);
203 canvas->add(std::move(maxMarker));
204 }
205 canvas->add(std::move(primitives));
206 }
207 void PatternVisualizationTool::paintSimHits(const EventContext& ctx,
208 const xAOD::MuonSegment& truthSeg,
209 Canvas_t& canvas,
210 const int view) const {
211 if (!m_paintTruthHits) {
212 return;
213 }
214 auto truthHits = getMatchingSimHits(truthSeg);
215 const ActsTrk::GeometryContext* geoCtx{nullptr};
216 if (!SG::get(geoCtx, m_geoCtxKey, ctx).isSuccess()) {
217 return;
218 }
219 for (const xAOD::MuonSimHit* simHit : truthHits) {
220 const MuonGMR4::MuonReadoutElement* re = m_detMgr->getReadoutElement(simHit->identify());
221 const IdentifierHash hash = re->detectorType() == ActsTrk::DetectorType::Mdt ?
222 re->measurementHash(simHit->identify()) :
223 re->layerHash(simHit->identify());
224 const Amg::Transform3D trf = re->msSector()->globalToLocalTransform(*geoCtx) *
225 re->localToGlobalTransform(*geoCtx, hash);
226 const Amg::Vector3D locPos = trf * xAOD::toEigen(simHit->localPosition());
227 const Amg::Vector3D locDir = trf.linear() * xAOD::toEigen(simHit->localDirection());
228 canvas.add(drawArrow(locPos, locDir, truthColor, kDashed, view));
229 }
230 }
231 void PatternVisualizationTool::visualizeSeed(const EventContext& ctx,
232 const MuonR4::SegmentSeed& seed,
233 const std::string& extraLabel) const {
234 PrimitiveVec primitives{};
235 visualizeSeed(ctx, seed, extraLabel, std::move(primitives));
236 }
237 void PatternVisualizationTool::visualizeSeed(const EventContext& ctx,
238 const MuonR4::SegmentSeed& seed,
239 const std::string& extraLabel,
240 PrimitiveVec&& primitives) const {
241
243 if (m_plotsDone) {
244 return;
245 }
246 const LabeledSegmentSet truthSegs{getLabeledSegments(seed.getHitsInMax())};
247 if (truthSegs.empty() && m_displayOnlyTruth) {
248 return;
249 }
250
251 auto canvas = m_visualSvc->prepareCanvas(ctx, m_clientToken, extraLabel);
252 if (!canvas) {
253 m_plotsDone = true;
254 return;
255 }
256 canvas->add(std::move(primitives));
257
258
259 for (const int view : {objViewEta, objViewPhi}) {
260 if ((view == objViewEta && !m_doEtaBucketViews) ||
261 (view == objViewPhi && !m_doPhiBucketViews)){
262 continue;
263 }
264 canvas->setAxisTitles(std::format("{:} [mm]", view == objViewEta ? 'y' : 'x'), "z [mm]");
265
266 if (!drawHits(*seed.parentBucket(), seed.getHitsInMax(), *canvas, view)) {
267 continue;
268 }
269 for (const xAOD::MuonSegment* segment : truthSegs) {
270 canvas->add(drawLine(localSegmentPars(*segment),
271 canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
272 truthColor, kDotted, view));
273 paintSimHits(ctx,*segment, *canvas, view);
274 }
275 canvas->add(drawLine(seed.parameters(), canvas->corner(Edges::yLow),
276 canvas->corner(Edges::yHigh), parLineColor, kDashed, view));
277
278 writeChi2(seed.parameters(), seed.getHitsInMax(), *canvas);
279
280 std::string legendLabel = std::format("Event: {:}, chamber : {:}, #{:}-view ({:})",
281 ctx.eventID().event_number(),
282 m_idHelperSvc->toStringChamber(seed.getHitsInMax().front()->identify()),
283 view ==objViewEta ? "eta" : "phi",
284 extraLabel);
285 canvas->add(drawLabel(legendLabel, 0.1, 0.96));
286 canvas->add(drawLabel(makeLabel(seed.parameters()),0.25, 0.89));
287 }
288 }
289
290 void PatternVisualizationTool::visualizeBucket(const EventContext& ctx,
291 const MuonR4::SpacePointBucket& bucket,
292 const std::string& extraLabel) const {
293 PrimitiveVec primitives{};
294 visualizeBucket(ctx, bucket, extraLabel, std::move(primitives));
295 }
296 void PatternVisualizationTool::visualizeBucket(const EventContext& ctx,
297 const MuonR4::SpacePointBucket& bucket,
298 const std::string& extraLabel,
299 PrimitiveVec&& primitives) const {
301 if (m_plotsDone) {
302 return;
303 }
304
305 LabeledSegmentSet truthSegs{getLabeledSegments(Acts::unpackConstSmartPointers(bucket))};
306 if (truthSegs.empty() && m_displayOnlyTruth) {
307 return;
308 }
309 auto canvas = m_visualSvc->prepareCanvas(ctx, m_clientToken, extraLabel);
310 if (!canvas){
311 m_plotsDone = true;
312 return;
313 }
314 canvas->add(std::move(primitives));
315
316 for (const int view : {objViewEta, objViewPhi}) {
317 if ((view == objViewEta && !m_doEtaBucketViews) ||
318 (view == objViewPhi && !m_doPhiBucketViews)){
319 continue;
320 }
321 canvas->setAxisTitles(std::format("{:} [mm]", view == objViewEta ? 'y' : 'x'), "z [mm]");
323 if (!drawHits(bucket, bucket, *canvas, view)) {
324 continue;
325 }
326 bool drawnTrueLabel{false};
327 for (const xAOD::MuonSegment* segment : truthSegs) {
328 canvas->add(drawLine(localSegmentPars(*segment),
329 canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
330 truthColor, kDotted, view));
331 if (!drawnTrueLabel) {
332 canvas->add(drawLabel(std::format("true parameters: {:}",makeLabel(localSegmentPars(*segment))),0.2, 0.89));
333 drawnTrueLabel = true;
334 }
335 paintSimHits(ctx,*segment, *canvas, view);
336 }
337
338 std::string legendLabel = std::format("Event: {:}, chamber : {:}, #{:}-view ({:})",
339 ctx.eventID().event_number(),
340 bucket.msSector()->identString(),
341 view ==objViewEta ? "eta" : "phi",
342 extraLabel);
343 canvas->add(drawLabel(legendLabel, 0.15, 0.96));
344 }
345 }
346
347 void PatternVisualizationTool::visualizeSegment(const EventContext& ctx,
348 const MuonR4::Segment& segment,
349 const std::string& extraLabel) const {
350 PrimitiveVec primitives{};
351 visualizeSegment(ctx, segment,extraLabel, std::move(primitives));
352 }
353
354 void PatternVisualizationTool::visualizeSegment(const EventContext& ctx,
355 const MuonR4::Segment& segment,
356 const std::string& extraLabel,
357 PrimitiveVec&& primitives) const {
359 if (m_plotsDone) {
360 return;
361 }
362
363 const LabeledSegmentSet truthSegs{getLabeledSegments(segment.parent()->getHitsInMax())};
364 if (truthSegs.empty() && m_displayOnlyTruth) {
365 return;
366 }
367 const ActsTrk::GeometryContext* geoCtx{nullptr};
368 if (!SG::get(geoCtx, m_geoCtxKey, ctx).isSuccess()) {
369 return;
370 }
371 auto canvas = m_visualSvc->prepareCanvas(ctx, m_clientToken, extraLabel);
372 if (!canvas) {
373 m_plotsDone = true;
374 return;
375 }
376 canvas->add(std::move(primitives));
377
378
379 const Parameters segPars = SegmentFit::localSegmentPars(*geoCtx, segment);
380
381 for (const int view : {objViewEta, objViewPhi}) {
382 if ((view == objViewEta && !m_doEtaBucketViews) ||
383 (view == objViewPhi && !m_doPhiBucketViews)){
384 continue;
385 }
386 canvas->setAxisTitles(std::format("{:} [mm]", view == objViewEta ? 'y' : 'x'), "z [mm]");
387 if (!drawHits(*segment.parent()->parentBucket(), segment.measurements(),
388 *canvas, view)) {
389 continue;
390 }
391 for (const xAOD::MuonSegment* segment : truthSegs) {
392 canvas->add(drawLine(localSegmentPars(*segment), canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
393 truthColor, kDotted, view));
394 paintSimHits(ctx,*segment, *canvas, view);
395 }
396 writeChi2(segPars, segment.measurements(), *canvas);
397
398 canvas->add(drawLine(segPars, canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
399 parLineColor, kDashed, view));
400
401 const Identifier canvasId{segment.parent()->getHitsInMax().front()->identify()};
402 std::string legendLabel=std::format("Event: {:}, chamber: {:}, #chi^{{2}} / nDoF: {:.2f} ({:d}), #{:}-view (:)",
403 ctx.eventID().event_number(), m_idHelperSvc->toStringChamber(canvasId),
404 segment.chi2() /std::max(1u, segment.nDoF()), segment.nDoF(),
405 view ==objViewEta ? "eta" : "phi", extraLabel);
406
407 canvas->add(drawLabel(legendLabel, 0.2, 0.96));
408 canvas->add(drawLabel(makeLabel(segPars),0.25, 0.91));
409 }
410 }
411
413 const MuonR4::Segment& segment,
414 const std::string& extraLabel) const {
415
416 const ActsTrk::GeometryContext* geoCtx{nullptr};
417 if (!SG::get(geoCtx, m_geoCtxKey, ctx).isSuccess()) {
418 return;
419 }
420 Acts::ObjVisualization3D visualHelper{};
421 const MuonR4::Segment::MeasVec& measurements{segment.measurements()};
422 drawObjHits(*geoCtx, measurements, visualHelper);
423 const SpacePoint* sp = measurements.front()->type() != xAOD::UncalibMeasType::Other ? measurements.front()->spacePoint() :
424 measurements[1]->spacePoint();
425 auto chamberId = sp->identify();
426
427 //draw also the segment line in the same obj and in the end write the obj file with the visualHelper
428 double pathLength{1.*Gaudi::Units::m};
429 Acts::GeometryView3D::drawSegment(visualHelper,
430 segment.position() + 0.5* pathLength * segment.direction(),
431 segment.position() - 0.5* pathLength * segment.direction(),
432 Acts::s_viewLine);
433 std::string fileName = std::format("Event_{:}_chamber_{:}_{:}",
434 ctx.eventID().event_number(), m_idHelperSvc->toStringChamber(chamberId), extraLabel);
435 visualHelper.write(fileName + ".obj");
436
437 }
438
440 const MuonR4::Segment::MeasVec& measVec,
441 const std::string& extraLabel) const {
442 const ActsTrk::GeometryContext* geoCtx{nullptr};
443 if (!SG::get(geoCtx, m_geoCtxKey, ctx).isSuccess()) {
444 return;
445 }
446
447 Acts::ObjVisualization3D visualHelper{};
448 drawObjHits(*geoCtx, measVec, visualHelper);
449 const SpacePoint* sp = measVec.front()->type() != xAOD::UncalibMeasType::Other ? measVec.front()->spacePoint() :
450 measVec[1]->spacePoint();
451 auto chamberId = sp->identify();
452 std::string fileName = std::format("Event_{:}_chamber_{:}_{:}",
453 ctx.eventID().event_number(), m_idHelperSvc->toStringChamber(chamberId), extraLabel);
454 visualHelper.write(fileName + ".obj");
455 }
456
458 const MuonR4::Segment::MeasVec& measVec,
459 Acts::ObjVisualization3D& visualHelper) const {
460
461
462 const SpacePoint* sp = measVec.front()->type() != xAOD::UncalibMeasType::Other ? measVec.front()->spacePoint() :
463 measVec[1]->spacePoint();
464
465 const MuonGMR4::SpectrometerSector* msSector = sp->msSector();
466 const Amg::Transform3D& locToGlob = msSector->localToGlobalTransform(geoCtx);
467 using CovIdx = SpacePoint::CovIdx;
468 double dX{0.}, dY{0.};
469
470 for(const auto& meas : measVec){
471
472 //if this is a 2D measurement visualize it as the spacepoint
473
474 if(meas->dimension() == 2){
475 //handle straw surfaces
476 if(meas->isStraw()){
477 const double dR = meas->type() == xAOD::UncalibMeasType::Other ? std::sqrt(meas->covariance()[Acts::toUnderlying(CovIdx::etaCov)]):
478 meas->driftRadius();
479 const double hZ = std::sqrt(meas->covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
480 auto bounds = std::make_unique<Acts::LineBounds>(dR, hZ);
481 Amg::Vector3D globalPos = locToGlob* meas->localPosition();
482 const Acts::Transform3 trf = Acts::Transform3(
483 Acts::Translation3(globalPos) *locToGlob.rotation());
484 auto surface = Acts::Surface::makeShared<Acts::StrawSurface>(trf, std::move(bounds));
485 Acts::GeometryView3D::drawSurface(visualHelper, *surface, geoCtx.context());
486 continue;
487 }
488
489 dX = std::sqrt(meas->covariance()[Acts::toUnderlying(CovIdx::phiCov)]);
490 dY = std::sqrt(meas->covariance()[Acts::toUnderlying(CovIdx::etaCov)]);
491 auto bounds = std::make_unique<Acts::RectangleBounds>(dX, dY);
492 Amg::Vector3D globalPos = locToGlob* meas->localPosition();
493 const Acts::Transform3 trf = Acts::Transform3(
494 Acts::Translation3(globalPos) *locToGlob.rotation());
495
496 auto surf = Acts::Surface::makeShared<Acts::PlaneSurface>(trf,std::move(bounds));
497 Acts::GeometryView3D::drawSurface(visualHelper, *surf, geoCtx.context());
498 }else{
499 if(meas->type() == xAOD::UncalibMeasType::Other){
500 continue;
501 }
502 const SpacePoint* underlyingSp{meas->spacePoint()};
503 MuonValR4::drawMeasurement(geoCtx, underlyingSp->primaryMeasurement(), visualHelper);
504 }
505 }
506 }
507
508
509 template<class SpacePointType>
510 const SpacePoint*
511 PatternVisualizationTool::drawHit(const SpacePointType& hit, Canvas_t& canvas,
512 const unsigned int view,
513 unsigned int fillStyle) const {
514
516 if ((view == objViewEta && !hit.measuresEta()) || (view == objViewPhi && !hit.measuresPhi())) {
517 return nullptr;
518 }
519
520 if (hit.type() != xAOD::UncalibMeasType::Other) {
521 canvas.expandPad(hit.localPosition()[view] - hit.driftRadius(),
522 hit.localPosition().z() - hit.driftRadius());
523 canvas.expandPad(hit.localPosition()[view] + hit.driftRadius(),
524 hit.localPosition().z() + hit.driftRadius());
525 }
526
527 const SpacePoint* underlyingSp{nullptr};
529 constexpr int invalidCalibFill = 3305;
530 if constexpr (std::is_same_v<SpacePointType, SpacePoint>) {
531 underlyingSp = &hit;
533 const auto* dc = static_cast<const xAOD::MdtDriftCircle*>(hit.primaryMeasurement());
534 if (dc->status() != Muon::MdtDriftCircleStatus::MdtStatusDriftTime) {
535 fillStyle = invalidCalibFill;
536 }
537 }
538 } else if constexpr(std::is_same_v<SpacePointType, CalibratedSpacePoint>) {
539 underlyingSp = hit.spacePoint();
540 if (hit.fitState() == CalibratedSpacePoint::State::Valid) {
541 fillStyle = fullFilling;
542 } else if (hit.fitState() == CalibratedSpacePoint::State::FailedCalib) {
543 fillStyle = invalidCalibFill;
544 } else {
545 fillStyle = hatchedFilling;
546 }
547 }
548 switch(hit.type()) {
550 const auto* dc = static_cast<const xAOD::MdtDriftCircle*>(underlyingSp->primaryMeasurement());
551 canvas.add(drawDriftCircle(hit.localPosition(), dc->readoutElement()->innerTubeRadius(),
552 kBlack, hollowFilling));
553
554 const int circColor = isLabeled(*dc) ? truthColor : kBlue;
555 canvas.add(drawDriftCircle(hit.localPosition(), hit.driftRadius(), circColor, fillStyle));
556 break;
558 const auto* meas{static_cast<const xAOD::RpcMeasurement*>(underlyingSp->primaryMeasurement())};
559 const int boxColor = isLabeled(*meas) ? truthColor : kGreen +2;
560 const double boxWidth = 0.5*std::sqrt(12)*std::sqrt(underlyingSp->covariance()[view]);
561 canvas.add(drawBox(hit.localPosition(), boxWidth, 0.5*meas->readoutElement()->gasGapPitch(),
562 boxColor, fillStyle));
563 break;
565 const auto* meas{static_cast<const xAOD::TgcStrip*>(underlyingSp->primaryMeasurement())};
566 const int boxColor = isLabeled(*meas) ? truthColor : kCyan + 2;
567 const double boxWidth = 0.5*std::sqrt(12)*std::sqrt(underlyingSp->covariance()[view]);
568 canvas.add(drawBox(hit.localPosition(), boxWidth, 0.5*meas->readoutElement()->gasGapPitch(),
569 boxColor, fillStyle));
570 break;
572 const int boxColor = isLabeled(*underlyingSp->primaryMeasurement()) ? truthColor : kAquamarine;
573 const double boxWidth = 5*Gaudi::Units::mm;
574 canvas.add(drawBox(hit.localPosition(), boxWidth, 10.*Gaudi::Units::mm, boxColor, fillStyle));
575 break;
577 break;
579 const int boxColor = isLabeled(*underlyingSp->primaryMeasurement()) ? truthColor : kTeal;
580 const double boxWidth = 5*Gaudi::Units::mm;
581 canvas.add(drawBox(hit.localPosition(), boxWidth, 10.*Gaudi::Units::mm, boxColor, fillStyle));
582 break;
583 } default: {
584 ATH_MSG_WARNING("Please implement proper drawings of the new small wheel.. "<<__FILE__<<":"<<__LINE__);
585 break;
586 }
587 }
588 return underlyingSp;
589 }
590
591 template<class SpacePointType>
593 const std::vector<SpacePointType>& hitsToDraw,
594 Canvas_t& canvas,
595 unsigned int view) const {
596
597 SpacePointSet drawnPoints{};
598 for (const SpacePointType& hit : hitsToDraw) {
599 drawnPoints.insert(drawHit(*hit, canvas, view, fullFilling));
600 }
601 if (m_displayBucket) {
602 for (const SpacePointBucket::value_type& hit : bucket) {
603 // Don't redraw the other points
604 if (drawnPoints.count(hit.get())) {
605 continue;
606 }
607 drawHit(*hit, canvas, view, hollowFilling);
608 }
609 }
610 return drawnPoints.size() - drawnPoints.count(nullptr) > 1;
611 }
612 template<class SpacePointType>
614 const std::vector<SpacePointType>& hits,
615 Canvas_t& canvas,
616 const double legX, double startLegY,
617 const double endLegY) const {
618 const auto [pos, dir] = makeLine(pars);
619
620 for (const SpacePointType& hit : hits) {
621 const SpacePoint* underlyingSp{nullptr};
622 bool displayChi2{true};
623 if constexpr(std::is_same_v<SpacePointType, Segment::MeasType>) {
624 underlyingSp = hit->spacePoint();
625 displayChi2 = (hit->fitState() == CalibratedSpacePoint::State::Valid);
626 } else {
627 underlyingSp = hit;
628 }
629 const Identifier hitId = underlyingSp ? underlyingSp->identify(): Identifier{};
630 std::string legendstream{};
631 switch(hit->type()) {
633 const int driftSign{SeedingAux::strawSign(pos, dir, *hit)};
634 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
635 legendstream = std::format("ML: {:1d}, TL: {:1d}, T: {:3d}, {:}",
636 idHelper.multilayer(hitId), idHelper.tubeLayer(hitId),
637 idHelper.tube(hitId), driftSign == -1 ? "L" : "R");
638 break;
640 const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
641 legendstream= std::format("DR: {:1d}, DZ: {:1d}, GAP: {:1d}, #eta/#phi: {:}/{:}",
642 idHelper.doubletR(hitId), idHelper.doubletZ(hitId), idHelper.gasGap(hitId),
643 hit->measuresEta() ? "si" : "nay", hit->measuresPhi() ? "si" : "nay");
644 break;
646 const TgcIdHelper& idHelper{m_idHelperSvc->tgcIdHelper()};
647 legendstream = std::format("ST: {:}, GAP: {:1d}, #eta/#phi: {:}/{:}",
648 m_idHelperSvc->stationNameString(hitId), idHelper.gasGap(hitId),
649 hit->measuresEta() ? "si" : "nay", hit->measuresPhi() ? "si" : "nay");
650 break;
652 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
653 const auto* clus = static_cast<const xAOD::MMCluster*>(underlyingSp->primaryMeasurement());
654 const MuonGMR4::StripDesign& design = clus->readoutElement()->stripLayer(clus->layerHash()).design();
655 legendstream = std::format("ML: {:1d}, GAP: {:1d}, {:}", idHelper.multilayer(hitId), idHelper.gasGap(hitId),
656 !design.hasStereoAngle() ? "X" : design.stereoAngle() > 0 ? "U" :"V");
657 break;
659 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
660 legendstream = std::format("ML: {:1d}, GAP: {:1d}, #eta/#phi: {:}/{:}",
661 idHelper.multilayer(hitId), idHelper.gasGap(hitId),
662 hit->measuresEta() ? "si" : "nay", hit->measuresPhi() ? "si" : "nay");
663 break;
665 legendstream = "Ext. constaint";
666 }
667 default:
668 break;
669 }
670 if (displayChi2) {
671 const double chi2 = SeedingAux::chi2Term(pos, dir,*hit);
672 legendstream+=std::format(", #chi^{{2}}: {:.2f}", chi2);
673 } else {
674 legendstream+=", #chi^{2}: ---";
675 }
676 canvas.add(drawLabel(legendstream, legX, startLegY, 14));
677 startLegY -= 0.05;
678 if (startLegY<= endLegY) {
679 break;
680 }
681 }
682 }
683}
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
static Double_t sp
Acts::GeometryContext context() const
This is a "hash" representation of an Identifier.
int multilayer(const Identifier &id) const
Access to components of the ID.
int tube(const Identifier &id) const
int tubeLayer(const Identifier &id) const
int gasGap(const Identifier &id) const override
get the hashes
int multilayer(const Identifier &id) const
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
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.
std::string identString() const
Returns a string encoding the chamber index & the sector of the MS sector.
double stereoAngle() const
Returns the value of the stereo angle.
bool hasStereoAngle() const
Returns whether a stereo angle is defined.
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition SegmentSeed.h:14
const std::vector< HitType > & getHitsInMax() const
Returns the list of assigned hits.
const SpacePointBucket * parentBucket() const
Returns the bucket out of which the seed was formed.
Placeholder for what will later be the muon segment EDM representation.
unsigned int nDoF() const
Returns the number of degrees of freedom.
const SegmentSeed * parent() const
Returns the seed out of which the segment was built.
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 bucket represents a collection of points that will bre processed together in t...
const MuonGMR4::SpectrometerSector * msSector() const
returns th associated muonChamber
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
const xAOD::UncalibratedMeasurement * secondaryMeasurement() const
const Identifier & identify() const
: Identifier of the primary measurement
const Cov_t & covariance() const
Returns the covariance array.
const xAOD::UncalibratedMeasurement * primaryMeasurement() const
Gaudi::Property< std::string > m_subDir
Define the subdirectory in which the plots shall be saved.
Gaudi::Property< bool > m_doEtaBucketViews
Switch to visualize the eta view of the bucket event.
virtual void visualizeSegmentsMeasurementsObj(const EventContext &ctx, const MuonR4::Segment &segment, const std::string &extraLabel) const override final
virtual StatusCode initialize() override final
Gaudi::Property< bool > m_accumlIsEta
Swtich toggling whether the accumulator view are in the eta or phi plane.
virtual void visualizeAccumulator(const EventContext &ctx, const MuonR4::HoughPlane &accumulator, const Acts::HoughTransformUtils::HoughAxisRanges &axisRanges, const MaximumVec &maxima, const std::string &extraLabel) const override final
virtual void visualizeSegment(const EventContext &ctx, const MuonR4::Segment &segment, const std::string &extraLabel) const override final
Gaudi::Property< unsigned int > m_canvasLimit
Maximum canvases to draw.
Gaudi::Property< bool > m_displayBucket
Display the surrounding hits from the bucket not part of the seed.
Gaudi::Property< std::string > m_canvasPrefix
Prefix of the individual canvas file names <MANDATORY>
virtual void visualizeBucket(const EventContext &ctx, const MuonR4::SpacePointBucket &bucket, const std::string &extraLabel) const override final
Gaudi::Property< bool > m_saveSinglePDFs
If set to true each canvas is saved into a dedicated pdf file.
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
Geometry context key to retrieve the alignment.
std::unordered_set< const xAOD::MuonSegment * > LabeledSegmentSet
virtual void visualizeSeed(const EventContext &ctx, const MuonR4::SegmentSeed &seed, const std::string &extraLabel) const override final
IRootVisualizationService::ClientToken m_clientToken
Token to present to the visualization service such that the display froms this tool are grouped toget...
std::vector< SegLinkDecor_t > m_truthLinkDecors
Gaudi::Property< bool > m_doPhiBucketViews
Switch to visualize the phi view of the bucket event.
SG::ReadDecorHandleKeyArray< xAOD::UncalibratedMeasurementContainer > m_truthLinkDecorKeys
Declaration of the dependency on the decorations.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Service Handle to the IMuonIdHelperSvc.
SG::ReadHandleKeyArray< xAOD::UncalibratedMeasurementContainer > m_prepContainerKeys
Declare dependency on the prep data containers.
bool drawHits(const MuonR4::SpacePointBucket &bucket, const std::vector< SpacePointType > &hitsToDraw, Canvas_t &canvasDim, unsigned int view) const
Translates the Spacepoint information into TObjects that are dawn on the canvas & evaluates the size ...
virtual LabeledSegmentSet getLabeledSegments(const std::vector< const MuonR4::SpacePoint * > &hits) const override final
Returns whether the hit has been used on the labeled segments we refer to (e.g.
IRootVisualizationService::ICanvasObject Canvas_t
void drawObjHits(const ActsTrk::GeometryContext &geoCtx, const MuonR4::Segment::MeasVec &measVec, Acts::ObjVisualization3D &visualHelper) const
Append hits from a segment in an obj file.
Gaudi::Property< std::set< std::string > > m_truthSegLinks
List of truth segment links to fetch.
void paintSimHits(const EventContext &ctx, const xAOD::MuonSegment &truthSeg, Canvas_t &canvas, const int view) const
Paints the truth sim hits associated with the segment.
ElementLink< xAOD::MuonSegmentContainer > SegLink_t
ServiceHandle< IRootVisualizationService > m_visualSvc
Service handle of the visualization service.
virtual bool isLabeled(const MuonR4::SpacePoint &hit) const override final
Fetches all labeled (e.g.
Gaudi::Property< bool > m_saveSummaryPDF
If set to true a summary Canvas is created.
const MuonR4::SpacePoint * drawHit(const SpacePointType &hit, Canvas_t &canvas, const unsigned int view, unsigned int fillStyle) const
Converts a Hit into a particular TBox/ TEllipse for drawing.
void writeChi2(const MuonR4::SegmentFit::Parameters &pars, const std::vector< SpacePointType > &hits, Canvas_t &canvas, const double legX=0.2, double startLegY=0.8, const double endLegY=0.3) const
Writes the chi2 of the hits onto the Canvas.
const MuonGMR4::MuonDetectorManager * m_detMgr
pointer to the Detector manager
Gaudi::Property< bool > m_paintTruthHits
Switch to visualize the truth hits.
std::atomic< bool > m_plotsDone
Flag toggling whether all Canvases have been exhausted.
SG::AuxElement::ConstAccessor< SegLinkVec_t > SegLinkDecor_t
int gasGap(const Identifier &id) const override
get the hashes
int doubletR(const Identifier &id) const
int doubletZ(const Identifier &id) const
Property holding a SG store/key/clid from which a ReadHandle is made.
int gasGap(const Identifier &id) const override
get the hashes
int multilayer(const Identifier &id) const
int gasGap(const Identifier &id) const override
get the hashes
double chi2(TH1 *h0, TH1 *h1)
@ Mdt
MuonSpectrometer.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
std::pair< Amg::Vector3D, Amg::Vector3D > makeLine(const Parameters &pars)
Returns the parsed parameters into an Eigen line parametrization.
Acts::Experimental::CompositeSpacePointLineFitter::ParamVec_t Parameters
std::string makeLabel(const Parameters &pars)
Dumps the parameters into a string in the form of TLatex.
double houghTanBeta(const Amg::Vector3D &v)
Returns the hough tanBeta [y] / [z].
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
MuonValR4::IPatternVisualizationTool::PrimitiveVec PrimitiveVec
Acts::HoughTransformUtils::HoughPlane< HoughHitType > HoughPlane
double houghTanAlpha(const Amg::Vector3D &v)
: Returns the hough tanAlpha [x] / [z]
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
constexpr int objViewEta
ObjectView.
PatternVisualizationTool::LabeledSegmentSet LabeledSegmentSet
constexpr int hollowFilling
Filling codes for hollow / fullFilling / hatched filling.
std::unique_ptr< TLine > drawLine(const MuonR4::SegmentFit::Parameters &pars, const double lowEnd, const double highEnd, const int color=kRed+1, const int lineStyle=kDashed, const int view=objViewEta)
Draws a line from the segment fit parameters.
constexpr int hatchedFilling
std::unique_ptr< TEllipse > drawDriftCircle(const Amg::Vector3D &center, const double radius, const int color=kViolet, const int fillStyle=hollowFilling)
Create a TEllipse for drawing a drift circle.
std::unique_ptr< TLatex > drawLabel(const std::string &text, const double xPos, const double yPos, const unsigned int fontSize=18, const bool useNDC=true)
Create a TLatex label,.
constexpr int fullFilling
constexpr int objViewPhi
std::unique_ptr< TArrow > drawArrow(const Amg::Vector3D &start, const Amg::Vector3D &dir, const int color=kRed+1, const int lineStyle=kDashed, const int view=objViewEta)
Draw an arror between two endpoints in the y-z or the x-z plane.
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.
std::unique_ptr< TBox > drawBox(const Amg::Vector3D &boxCenter, const double boxWidth, const double boxHeight, const int color=kGreen+2, const int fillStyle=hollowFilling, const int view=objViewEta)
Creates a box for drawing, e.g strip measurements.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
std::vector< const SpacePoint * > SpacePointSet
vector of space points
Definition FitterTypes.h:38
MdtDriftCircle_v1 MdtDriftCircle
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
TgcStrip_v1 TgcStrip
Definition TgcStripFwd.h:9
RpcMeasurement_v1 RpcMeasurement
MMCluster_v1 MMCluster
MuonSegment_v1 MuonSegment
Reference the current persistent version:
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.