ATLAS Offline Software
Loading...
Searching...
No Matches
PatternVisualizationTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef MUONR4_MUONPATTERNRECOGNITIONTEST_PATTERNVISUALIZATIONTOOL_H
5#define MUONR4_MUONPATTERNRECOGNITIONTEST_PATTERNVISUALIZATIONTOOL_H
6
10
13
19
21
22
23#include "TLegend.h"
24#include "TLegendEntry.h"
25
26#include <bitset>
27
28
29namespace MuonR4 {
30 class SpacePoint;
31}
32
33namespace MuonValR4 {
34
35
36enum class LegendItem : std::size_t {
40
41 // general hits in the bucket (hollow filling)
49
50 // hits on the objects (seeds, segments, etc) (full filling)
57
58 //True matched hits
61
64
66};
67using LegendMask = std::bitset<static_cast<std::size_t>(LegendItem::NumItems)>;
68
70public:
72 : m_legend{
73 std::make_unique<TLegend>(
74 0.68, 0.56, 0.94, 0.90)} {
75
76 m_legend->SetBorderSize(0);
77 m_legend->SetFillStyle(0);
78 m_legend->SetTextFont(43);
79 m_legend->SetTextSize(10);
80 }
81
82 DynamicLegend( double xmin, double ymin, double xmax, double ymax,
83 int textfont = 43, double textSize = 10)
84 : m_legend{
85 std::make_unique<TLegend>(
86 xmin, ymin, xmax, ymax)} {
87
88 m_legend->SetBorderSize(0);
89 m_legend->SetFillStyle(0);
90 m_legend->SetTextFont(textfont);
91 m_legend->SetTextSize(textSize);
92 }
93
94 TLegendEntry* addOnce(
95 const LegendItem item,
96 TObject* object,
97 const char* label,
98 const char* option) {
99
100 const std::size_t index =
101 static_cast<std::size_t>(item);
102
103 if (m_entries.test(index)) {
104 return nullptr;
105 }
106
107 TLegendEntry* entry =
108 m_legend->AddEntry(
109 object, label, option);
110
111 if (entry) {
112 m_entries.set(index);
113 }
114
115 return entry;
116 }
117
118 bool empty() const {
119 return m_legend->GetNRows() == 0;
120 }
121
122 std::unique_ptr<TLegend> release() {
123 return std::move(m_legend);
124 }
125
126private:
128 std::unique_ptr<TLegend> m_legend;
129};
130
131
132
133 class PatternVisualizationTool : public extends<AthAlgTool, IPatternVisualizationTool> {
134 public:
135
136 using base_class::base_class;
137
138 virtual StatusCode initialize() override final;
139
140 virtual void visualizeBucket(const EventContext& ctx,
141 const MuonR4::SpacePointBucket& bucket,
142 const std::string& extraLabel) const override final;
143 virtual void visualizeBucket(const EventContext& ctx,
144 const MuonR4::SpacePointBucket& bucket,
145 const std::string& extraLabel,
146 PrimitiveVec&& extraPaints) const override final;
147
148 virtual void visualizeSeed(const EventContext& ctx,
149 const MuonR4::SegmentSeed& seed,
150 const std::string& extraLabel) const override final;
151
152
153 virtual void visualizeSeed(const EventContext& ctx,
154 const MuonR4::SegmentSeed& seed,
155 const std::string& extraLabel,
156 PrimitiveVec&& extraPaints) const override final;
157
158
159 virtual void visualizeAccumulator(const EventContext& ctx,
160 const MuonR4::HoughPlane& accumulator,
161 const Acts::HoughTransformUtils::HoughAxisRanges& axisRanges,
162 const MaximumVec& maxima,
163 const std::string& extraLabel) const override final;
164
165 virtual void visualizeAccumulator(const EventContext& ctx,
166 const MuonR4::HoughPlane& accumulator,
167 const Acts::HoughTransformUtils::HoughAxisRanges& axisRanges,
168 const MaximumVec& maxima,
169 const std::string& extraLabel,
170 PrimitiveVec&& extraPaints) const override final;
171
172 virtual void visualizeSegment(const EventContext& ctx,
173 const MuonR4::Segment& segment,
174 const std::string& extraLabel) const override final;
175
176 virtual void visualizeSegment(const EventContext& ctx,
177 const MuonR4::Segment& segment,
178 const std::string& extraLabel,
179 PrimitiveVec&& extraPaints) const override final;
180
181 using LabeledSegmentSet = std::unordered_set<const xAOD::MuonSegment*>;
182
185 virtual LabeledSegmentSet getLabeledSegments(const std::vector<const MuonR4::SpacePoint*>& hits) const override final;
186 virtual LabeledSegmentSet getLabeledSegments(const std::vector<const xAOD::UncalibratedMeasurement*>& hits) const override final;
187
190 virtual bool isLabeled(const MuonR4::SpacePoint& hit) const override final;
191 virtual bool isLabeled(const xAOD::UncalibratedMeasurement& hit) const override final;
192 private:
204 template<class SpacePointType>
205 bool drawHits(const MuonR4::SpacePointBucket& bucket,
206 const std::vector<SpacePointType>& hitsToDraw,
207 Canvas_t& canvasDim, DynamicLegend& legend,
208 unsigned int view) const;
209
218 template<class SpacePointType>
219 const MuonR4::SpacePoint* drawHit(const SpacePointType& hit,
220 Canvas_t& canvas, DynamicLegend& legend,
221 const unsigned int view,
222 unsigned int fillStyle) const;
232 template<class SpacePointType>
234 const std::vector<SpacePointType>& hits,
235 Canvas_t& canvas,
236 const double legX = 0.2, double startLegY = 0.8,
237 const double endLegY = 0.3) const;
238
246 void paintSimHits(const EventContext& ctx,
247 const xAOD::MuonSegment& truthSeg,
248 Canvas_t& canvas,
249 const int view) const;
250
252 ServiceHandle<IRootVisualizationService> m_visualSvc{this, "VisualSvc", "MuonValR4::RootVisualizationService"};
257 Gaudi::Property<unsigned int> m_canvasLimit{this, "CanvasLimits", 5000};
259 Gaudi::Property<bool> m_saveSinglePDFs{this, "saveSinglePDFs", false};
261 Gaudi::Property<bool> m_saveSummaryPDF{this, "saveSummaryPDF", false};
263 Gaudi::Property<std::string> m_canvasPrefix{this, "CanvasPreFix", ""};
265 Gaudi::Property<std::string> m_subDir{this, "outSubDir", ""};
267 Gaudi::Property<bool> m_displayBucket{this, "displayBucket", true};
270 Gaudi::Property<bool> m_accumlIsEta{this, "AccumulatorsInEtaPlane", true};
272 Gaudi::Property<bool> m_doEtaBucketViews{this,"doEtaBucketViews", true};
274 Gaudi::Property<bool> m_doPhiBucketViews{this,"doPhiBucketViews", false};
276 Gaudi::Property<bool> m_paintTruthHits{this, "paintTruthHits", false};
280 Gaudi::Property<std::set<std::string>> m_truthSegLinks{this, "TruthSegDecors", {}};
284 using SegLinkVec_t = std::vector<SegLink_t>;
285 using SegLinkDecor_t = SG::AuxElement::ConstAccessor<SegLinkVec_t>;
286 std::vector<SegLinkDecor_t> m_truthLinkDecors{};
287
288 Gaudi::Property<bool> m_displayOnlyTruth{this, "displayTruthOnly", false};
289
293 ActsTrk::GeoContextReadKey_t m_geoCtxKey{this, "AlignmentKey", "ActsAlignment", "cond handle key"};
295 ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
297 mutable std::atomic<bool> m_plotsDone{false};
298
299 };
300
301
302
303}
304
305#endif
bool hit(const Container &ids, int pdgId)
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition SegmentSeed.h:14
Placeholder for what will later be the muon segment EDM representation.
: The muon space point bucket represents a collection of points that will bre processed together in t...
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
TLegendEntry * addOnce(const LegendItem item, TObject *object, const char *label, const char *option)
std::unique_ptr< TLegend > m_legend
DynamicLegend(double xmin, double ymin, double xmax, double ymax, int textfont=43, double textSize=10)
std::unique_ptr< TLegend > release()
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.
ActsTrk::GeoContextReadKey_t m_geoCtxKey
Geometry context key to retrieve the alignment.
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>.
bool drawHits(const MuonR4::SpacePointBucket &bucket, const std::vector< SpacePointType > &hitsToDraw, Canvas_t &canvasDim, DynamicLegend &legend, unsigned int view) const
Translates the Spacepoint information into TObjects that are dawn on the canvas & evaluates the size ...
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.
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.
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
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.
const MuonR4::SpacePoint * drawHit(const SpacePointType &hit, Canvas_t &canvas, DynamicLegend &legend, const unsigned int view, unsigned int fillStyle) const
Converts a Hit into a particular TBox/ TEllipse for drawing.
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.
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
std::string label(const std::string &format, int i)
Definition label.h:19
double xmax
Definition listroot.cxx:61
double ymin
Definition listroot.cxx:63
double xmin
Definition listroot.cxx:60
double ymax
Definition listroot.cxx:64
SG::ReadHandleKey< GeometryContext > GeoContextReadKey_t
Abrivate the ReadHandleKey to declare the data dependency on the Geometry context.
Acts::Experimental::CompositeSpacePointLineFitter::ParamVec_t Parameters
This header ties the generic definitions in this package.
MuonValR4::IPatternVisualizationTool::PrimitiveVec PrimitiveVec
Acts::HoughTransformUtils::HoughPlane< HoughHitType > HoughPlane
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
std::bitset< static_cast< std::size_t >(LegendItem::NumItems)> LegendMask
DecorHandleKeyArray< ReadDecorHandle< T, S >, ReadDecorHandleKey< T >, Gaudi::DataHandle::Reader > ReadDecorHandleKeyArray
HandleKeyArray< ReadHandle< T >, ReadHandleKey< T >, Gaudi::DataHandle::Reader > ReadHandleKeyArray
Definition index.py:1
STL namespace.
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
Token class to identify a particular visualization client.
Interface to the container class to temporarily cache the ROOT objects to be drawn on a TCanvas and t...
AxisRanges
Enum to select the corner coordinates shown by the plot.