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"
38 constexpr int truthColor = kOrange +2;
39 constexpr int parLineColor = kRed;
40 using SpacePointSet = std::unordered_set<const MuonR4::SpacePoint*>;
45 using namespace MuonR4;
63 ATH_MSG_INFO(
"Hits linked to the following segment decorations are considered as truth");
66 if (decorName.empty()) {
68 return StatusCode::FAILURE;
81 return StatusCode::SUCCESS;
90 return !decor(hit).empty();
95 std::vector<const xAOD::UncalibratedMeasurement*> measurements{};
96 measurements.reserve(2* hits.size());
98 measurements.push_back(hit->primaryMeasurement());
99 if(hit->secondaryMeasurement()) {
100 measurements.push_back(hit->secondaryMeasurement());
109 for (
const SegLink_t& link : decor(*hit)) {
110 truthSegs.insert(*link);
118 const Acts::HoughTransformUtils::HoughAxisRanges& axisRanges,
119 const MaximumVec& maxima,
120 const std::string& extraLabel)
const {
126 const Acts::HoughTransformUtils::HoughAxisRanges& axisRanges,
127 const MaximumVec& maxima,
128 const std::string& extraLabel,
135 if (accumulator.getNonEmptyBins().empty()) {
140 auto accHisto = std::make_unique<TH2F>(
"AccumulatorHisto",
"histo",
141 accumulator.nBinsX(), axisRanges.xMin, axisRanges.xMax,
142 accumulator.nBinsY(), axisRanges.yMin, axisRanges.yMax);
143 accHisto->SetDirectory(
nullptr);
145 std::vector<const SpacePoint*> spacePointsInAcc{};
146 for (
const std::size_t
bin : accumulator.getNonEmptyBins()) {
147 const auto [xBin, yBin] = accumulator.axisBins(
bin);
148 auto hitIds = accumulator.hitIds(xBin, yBin);
149 spacePointsInAcc.insert(spacePointsInAcc.end(),hitIds.begin(), hitIds.end());
150 accHisto->SetBinContent(xBin+1, yBin+1, accumulator.nHits(
bin));
162 canvas->expandPad(axisRanges.xMin, axisRanges.yMin);
163 canvas->expandPad(axisRanges.xMax, axisRanges.yMax);
164 canvas->setAxisTitles(std::format(
"tan#{}",
m_accumlIsEta ?
"beta" :
"#alpha"),
166 canvas->add(std::move(accHisto),
"HIST SAME");
172 auto truthMarker = std::make_unique<TMarker>(tan, icept, kFullCrossX);
173 truthMarker->SetMarkerColor(truthColor);
174 truthMarker->SetMarkerSize(8);
175 canvas->add(std::move(truthMarker));
176 canvas->add(
drawLabel(std::format(
"true parameters: {:}",
179 for (
const auto& maximum : maxima) {
180 auto maxMarker = std::make_unique<TMarker>(maximum.x, maximum.y, kFullTriangleUp);
181 maxMarker->SetMarkerColor(parLineColor);
182 maxMarker->SetMarkerSize(8);
183 canvas->add(std::move(maxMarker));
185 canvas->add(std::move(primitives));
190 const int view)
const {
202 re->measurementHash(simHit->identify()) :
203 re->layerHash(simHit->identify());
205 re->localToGlobalTransform(*geoCtx, hash);
206 const Amg::Vector3D locPos = trf * xAOD::toEigen(simHit->localPosition());
207 const Amg::Vector3D locDir = trf.linear() * xAOD::toEigen(simHit->localDirection());
208 canvas.add(
drawArrow(locPos, locDir, truthColor, kDashed, view));
213 const std::string& extraLabel)
const {
219 const std::string& extraLabel,
236 canvas->add(std::move(primitives));
244 canvas->setAxisTitles(std::format(
"{:} [mm]", view ==
objViewEta ?
'y' :
'x'),
"z [mm]");
246 if (!
drawHits(*seed.parentBucket(), seed.getHitsInMax(), *canvas, view)) {
251 canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
252 truthColor, kDotted, view));
255 canvas->add(
drawLine(seed.parameters(), canvas->corner(Edges::yLow),
256 canvas->corner(Edges::yHigh), parLineColor, kDashed, view));
258 writeChi2(seed.parameters(), seed.getHitsInMax(), *canvas);
260 std::string legendLabel = std::format(
"Event: {:}, chamber : {:}, #{:}-view ({:})",
261 ctx.eventID().event_number(),
262 m_idHelperSvc->toStringChamber(seed.getHitsInMax().front()->identify()),
265 canvas->add(
drawLabel(legendLabel, 0.1, 0.96));
272 const std::string& extraLabel)
const {
278 const std::string& extraLabel,
294 canvas->add(std::move(primitives));
301 canvas->setAxisTitles(std::format(
"{:} [mm]", view ==
objViewEta ?
'y' :
'x'),
"z [mm]");
303 if (!
drawHits(bucket, bucket, *canvas, view)) {
306 bool drawnTrueLabel{
false};
309 canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
310 truthColor, kDotted, view));
311 if (!drawnTrueLabel) {
313 drawnTrueLabel =
true;
318 std::string legendLabel = std::format(
"Event: {:}, chamber : {:}, #{:}-view ({:})",
319 ctx.eventID().event_number(),
323 canvas->add(
drawLabel(legendLabel, 0.15, 0.96));
329 const std::string& extraLabel)
const {
336 const std::string& extraLabel,
356 canvas->add(std::move(primitives));
366 canvas->setAxisTitles(std::format(
"{:} [mm]", view ==
objViewEta ?
'y' :
'x'),
"z [mm]");
373 truthColor, kDotted, view));
378 canvas->add(
drawLine(segPars, canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
379 parLineColor, kDashed, view));
382 std::string legendLabel=std::format(
"Event: {:}, chamber: {:}, #chi^{{2}} / nDoF: {:.2f} ({:d}), #{:}-view (:)",
383 ctx.eventID().event_number(),
m_idHelperSvc->toStringChamber(canvasId),
384 segment.
chi2() /std::max(1u, segment.
nDoF()), segment.
nDoF(),
385 view ==
objViewEta ?
"eta" :
"phi", extraLabel);
387 canvas->add(
drawLabel(legendLabel, 0.2, 0.96));
392 template<
class SpacePo
intType>
395 const unsigned int view,
396 unsigned int fillStyle)
const {
404 canvas.expandPad(hit.localPosition()[view] - hit.driftRadius(),
405 hit.localPosition().z() - hit.driftRadius());
406 canvas.expandPad(hit.localPosition()[view] + hit.driftRadius(),
407 hit.localPosition().z() + hit.driftRadius());
412 constexpr int invalidCalibFill = 3305;
413 if constexpr (std::is_same_v<SpacePointType, SpacePoint>) {
417 if (dc->status() != Muon::MdtDriftCircleStatus::MdtStatusDriftTime) {
418 fillStyle = invalidCalibFill;
421 }
else if constexpr(std::is_same_v<SpacePointType, CalibratedSpacePoint>) {
422 underlyingSp = hit.spacePoint();
423 if (hit.fitState() == CalibratedSpacePoint::State::Valid) {
425 }
else if (hit.fitState() == CalibratedSpacePoint::State::FailedCalib) {
426 fillStyle = invalidCalibFill;
434 canvas.add(
drawDriftCircle(hit.localPosition(), dc->readoutElement()->innerTubeRadius(),
437 const int circColor =
isLabeled(*dc) ? truthColor : kBlue;
438 canvas.add(
drawDriftCircle(hit.localPosition(), hit.driftRadius(), circColor, fillStyle));
442 const int boxColor =
isLabeled(*meas) ? truthColor : kGreen +2;
443 const double boxWidth = 0.5*std::sqrt(12)*std::sqrt(underlyingSp->
covariance()[view]);
444 canvas.add(
drawBox(hit.localPosition(), boxWidth, 0.5*meas->readoutElement()->gasGapPitch(),
445 boxColor, fillStyle));
449 const int boxColor =
isLabeled(*meas) ? truthColor : kCyan + 2;
450 const double boxWidth = 0.5*std::sqrt(12)*std::sqrt(underlyingSp->
covariance()[view]);
451 canvas.add(
drawBox(hit.localPosition(), boxWidth, 0.5*meas->readoutElement()->gasGapPitch(),
452 boxColor, fillStyle));
456 const double boxWidth = 5*Gaudi::Units::mm;
457 canvas.add(
drawBox(hit.localPosition(), boxWidth, 10.*Gaudi::Units::mm, boxColor, fillStyle));
463 const double boxWidth = 5*Gaudi::Units::mm;
464 canvas.add(
drawBox(hit.localPosition(), boxWidth, 10.*Gaudi::Units::mm, boxColor, fillStyle));
467 ATH_MSG_WARNING(
"Please implement proper drawings of the new small wheel.. "<<__FILE__<<
":"<<__LINE__);
474 template<
class SpacePo
intType>
476 const std::vector<SpacePointType>& hitsToDraw,
478 unsigned int view)
const {
480 SpacePointSet drawnPoints{};
481 for (
const SpacePointType& hit : hitsToDraw) {
485 for (
const SpacePointBucket::value_type& hit : bucket) {
487 if (drawnPoints.count(hit.get())) {
493 return drawnPoints.size() - drawnPoints.count(
nullptr) > 1;
495 template<
class SpacePo
intType>
497 const std::vector<SpacePointType>& hits,
499 const double legX,
double startLegY,
500 const double endLegY)
const {
501 const auto [pos, dir] =
makeLine(pars);
503 for (
const SpacePointType& hit : hits) {
505 bool displayChi2{
true};
506 if constexpr(std::is_same_v<SpacePointType, Segment::MeasType>) {
507 underlyingSp = hit->spacePoint();
508 displayChi2 = (hit->fitState() == CalibratedSpacePoint::State::Valid);
513 std::string legendstream{};
514 switch(hit->type()) {
516 const int driftSign{SeedingAux::strawSign(pos, dir, *hit)};
518 legendstream = std::format(
"ML: {:1d}, TL: {:1d}, T: {:3d}, {:}",
520 idHelper.
tube(hitId), driftSign == -1 ?
"L" :
"R");
524 legendstream= std::format(
"DR: {:1d}, DZ: {:1d}, GAP: {:1d}, #eta/#phi: {:}/{:}",
526 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
530 legendstream = std::format(
"ST: {:}, GAP: {:1d}, #eta/#phi: {:}/{:}",
532 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
537 const MuonGMR4::StripDesign& design = clus->readoutElement()->stripLayer(clus->layerHash()).design();
538 legendstream = std::format(
"ML: {:1d}, GAP: {:1d}, {:}", idHelper.
multilayer(hitId), idHelper.
gasGap(hitId),
543 legendstream = std::format(
"ML: {:1d}, GAP: {:1d}, #eta/#phi: {:}/{:}",
545 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
548 legendstream =
"Ext. constaint";
554 const double chi2 = SeedingAux::chi2Term(pos, dir,*hit);
555 legendstream+=std::format(
", #chi^{{2}}: {:.2f}",
chi2);
557 legendstream+=
", #chi^{2}: ---";
559 canvas.add(
drawLabel(legendstream, legX, startLegY, 14));
561 if (startLegY<= endLegY) {
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
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.
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.
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.
double chi2() const
Returns the chi2 of the segment fit.
: 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
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)
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< TLatex > drawLabel(const std::string &text, const double xPos, const double yPos, const double textSize=18, const bool useNDC=true, const int color=kBlack)
Create a TLatex label,.
std::unique_ptr< TEllipse > drawDriftCircle(const Amg::Vector3D ¢er, const double radius, const int color=kViolet, const int fillStyle=hollowFilling)
Create a TEllipse for drawing a drift circle.
constexpr int fullFilling
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.
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
MdtDriftCircle_v1 MdtDriftCircle
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
RpcMeasurement_v1 RpcMeasurement
MuonSegment_v1 MuonSegment
Reference the current persistent version:
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.