19#include "Acts/Utilities/Helpers.hpp"
31 constexpr int truthColor = kOrange +2;
32 constexpr int parLineColor = kRed;
33 using SpacePointSet = std::unordered_set<const MuonR4::SpacePoint*>;
38 using namespace MuonR4;
56 ATH_MSG_INFO(
"Hits linked to the following segment decorations are considered as truth");
59 if (decorName.empty()) {
61 return StatusCode::FAILURE;
74 return StatusCode::SUCCESS;
83 return !decor(hit).empty();
88 std::vector<const xAOD::UncalibratedMeasurement*> measurements{};
89 measurements.reserve(2* hits.size());
91 measurements.push_back(hit->primaryMeasurement());
92 if(hit->secondaryMeasurement()) {
93 measurements.push_back(hit->secondaryMeasurement());
102 for (
const SegLink_t& link : decor(*hit)) {
103 truthSegs.insert(*link);
131 const Acts::HoughTransformUtils::HoughAxisRanges& axisRanges,
132 const MaximumVec& maxima,
133 const std::string& extraLabel)
const {
139 const Acts::HoughTransformUtils::HoughAxisRanges& axisRanges,
140 const MaximumVec& maxima,
141 const std::string& extraLabel,
148 if (accumulator.getNonEmptyBins().empty()) {
153 auto accHisto = std::make_unique<TH2F>(
"AccumulatorHisto",
"histo",
154 accumulator.nBinsX(), axisRanges.xMin, axisRanges.xMax,
155 accumulator.nBinsY(), axisRanges.yMin, axisRanges.yMax);
156 accHisto->SetDirectory(
nullptr);
158 std::vector<const SpacePoint*> spacePointsInAcc{};
159 for (
const std::size_t
bin : accumulator.getNonEmptyBins()) {
160 const auto [xBin, yBin] = accumulator.axisBins(
bin);
161 auto hitIds = accumulator.hitIds(xBin, yBin);
162 spacePointsInAcc.insert(spacePointsInAcc.end(),hitIds.begin(), hitIds.end());
163 accHisto->SetBinContent(xBin+1, yBin+1, accumulator.nHits(
bin));
175 canvas->expandPad(axisRanges.xMin, axisRanges.yMin);
176 canvas->expandPad(axisRanges.xMax, axisRanges.yMax);
177 canvas->setAxisTitles(std::format(
"tan#{}",
m_accumlIsEta ?
"beta" :
"#alpha"),
179 canvas->add(std::move(accHisto),
"HIST SAME");
185 auto truthMarker = std::make_unique<TMarker>(tan, icept, kFullCrossX);
186 truthMarker->SetMarkerColor(truthColor);
187 truthMarker->SetMarkerSize(8);
188 canvas->add(std::move(truthMarker));
189 canvas->add(
drawLabel(std::format(
"true parameters: {:}",
192 for (
const auto& maximum : maxima) {
193 auto maxMarker = std::make_unique<TMarker>(maximum.x, maximum.y, kFullTriangleUp);
194 maxMarker->SetMarkerColor(parLineColor);
195 maxMarker->SetMarkerSize(8);
196 canvas->add(std::move(maxMarker));
198 canvas->add(std::move(primitives));
203 const int view)
const {
215 re->measurementHash(simHit->identify()) :
216 re->layerHash(simHit->identify());
218 re->localToGlobalTrans(*geoCtx, hash);
219 const Amg::Vector3D locPos = trf * xAOD::toEigen(simHit->localPosition());
220 const Amg::Vector3D locDir = trf.linear() * xAOD::toEigen(simHit->localDirection());
221 canvas.add(
drawArrow(locPos, locDir, truthColor, kDashed, view));
226 const std::string& extraLabel)
const {
232 const std::string& extraLabel,
249 canvas->add(std::move(primitives));
257 canvas->setAxisTitles(std::format(
"{:} [mm]", view ==
objViewEta ?
'y' :
'x'),
"z [mm]");
259 if (!
drawHits(*seed.parentBucket(), seed.getHitsInMax(), *canvas, view)) {
264 canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
265 truthColor, kDotted, view));
268 canvas->add(
drawLine(seed.parameters(), canvas->corner(Edges::yLow),
269 canvas->corner(Edges::yHigh), parLineColor, kDashed, view));
271 writeChi2(seed.parameters(), seed.getHitsInMax(), *canvas);
273 std::string legendLabel = std::format(
"Event: {:}, chamber : {:}, #{:}-view ({:})",
274 ctx.eventID().event_number(),
275 m_idHelperSvc->toStringChamber(seed.getHitsInMax().front()->identify()),
278 canvas->add(
drawLabel(legendLabel, 0.1, 0.96));
285 const std::string& extraLabel)
const {
291 const std::string& extraLabel,
307 canvas->add(std::move(primitives));
314 canvas->setAxisTitles(std::format(
"{:} [mm]", view ==
objViewEta ?
'y' :
'x'),
"z [mm]");
316 if (!
drawHits(bucket, bucket, *canvas, view)) {
319 bool drawnTrueLabel{
false};
322 canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
323 truthColor, kDotted, view));
324 if (!drawnTrueLabel) {
326 drawnTrueLabel =
true;
331 std::string legendLabel = std::format(
"Event: {:}, chamber : {:}, #{:}-view ({:})",
332 ctx.eventID().event_number(),
336 canvas->add(
drawLabel(legendLabel, 0.15, 0.96));
342 const std::string& extraLabel)
const {
349 const std::string& extraLabel,
369 canvas->add(std::move(primitives));
379 canvas->setAxisTitles(std::format(
"{:} [mm]", view ==
objViewEta ?
'y' :
'x'),
"z [mm]");
386 truthColor, kDotted, view));
391 canvas->add(
drawLine(segPars, canvas->corner(Edges::yLow), canvas->corner(Edges::yHigh),
392 parLineColor, kDashed, view));
395 std::string legendLabel=std::format(
"Event: {:}, chamber: {:}, #chi^{{2}} / nDoF: {:.2f} ({:d}), #{:}-view (:)",
396 ctx.eventID().event_number(),
m_idHelperSvc->toStringChamber(canvasId),
397 segment.
chi2() /std::max(1u, segment.
nDoF()), segment.
nDoF(),
398 view ==
objViewEta ?
"eta" :
"phi", extraLabel);
400 canvas->add(
drawLabel(legendLabel, 0.2, 0.96));
405 template<
class SpacePo
intType>
408 const unsigned int view,
409 unsigned int fillStyle)
const {
417 canvas.expandPad(hit.localPosition()[view] - hit.driftRadius(),
418 hit.localPosition().z() - hit.driftRadius());
419 canvas.expandPad(hit.localPosition()[view] + hit.driftRadius(),
420 hit.localPosition().z() + hit.driftRadius());
425 constexpr int invalidCalibFill = 3305;
426 if constexpr (std::is_same_v<SpacePointType, SpacePoint>) {
430 if (dc->status() != Muon::MdtDriftCircleStatus::MdtStatusDriftTime) {
431 fillStyle = invalidCalibFill;
434 }
else if constexpr(std::is_same_v<SpacePointType, CalibratedSpacePoint>) {
435 underlyingSp = hit.spacePoint();
436 if (hit.fitState() == CalibratedSpacePoint::State::Valid) {
438 }
else if (hit.fitState() == CalibratedSpacePoint::State::FailedCalib) {
439 fillStyle = invalidCalibFill;
447 canvas.add(
drawDriftCircle(hit.localPosition(), dc->readoutElement()->innerTubeRadius(),
450 const int circColor =
isLabeled(*dc) ? truthColor : kBlue;
451 canvas.add(
drawDriftCircle(hit.localPosition(), hit.driftRadius(), circColor, fillStyle));
455 const int boxColor =
isLabeled(*meas) ? truthColor : kGreen +2;
456 const double boxWidth = 0.5*std::sqrt(12)*std::sqrt(underlyingSp->
covariance()[view]);
457 canvas.add(
drawBox(hit.localPosition(), boxWidth, 0.5*meas->readoutElement()->gasGapPitch(),
458 boxColor, fillStyle));
462 const int boxColor =
isLabeled(*meas) ? truthColor : kCyan + 2;
463 const double boxWidth = 0.5*std::sqrt(12)*std::sqrt(underlyingSp->
covariance()[view]);
464 canvas.add(
drawBox(hit.localPosition(), boxWidth, 0.5*meas->readoutElement()->gasGapPitch(),
465 boxColor, fillStyle));
469 const double boxWidth = 5*Gaudi::Units::mm;
470 canvas.add(
drawBox(hit.localPosition(), boxWidth, 10.*Gaudi::Units::mm, boxColor, fillStyle));
476 const double boxWidth = 5*Gaudi::Units::mm;
477 canvas.add(
drawBox(hit.localPosition(), boxWidth, 10.*Gaudi::Units::mm, boxColor, fillStyle));
480 ATH_MSG_WARNING(
"Please implement proper drawings of the new small wheel.. "<<__FILE__<<
":"<<__LINE__);
487 template<
class SpacePo
intType>
489 const std::vector<SpacePointType>& hitsToDraw,
491 unsigned int view)
const {
493 SpacePointSet drawnPoints{};
494 for (
const SpacePointType& hit : hitsToDraw) {
498 for (
const SpacePointBucket::value_type& hit : bucket) {
500 if (drawnPoints.count(hit.get())) {
506 return drawnPoints.size() - drawnPoints.count(
nullptr) > 1;
508 template<
class SpacePo
intType>
510 const std::vector<SpacePointType>& hits,
512 const double legX,
double startLegY,
513 const double endLegY)
const {
514 const auto [pos, dir] =
makeLine(pars);
516 for (
const SpacePointType& hit : hits) {
518 bool displayChi2{
true};
519 if constexpr(std::is_same_v<SpacePointType, Segment::MeasType>) {
520 underlyingSp = hit->spacePoint();
521 displayChi2 = (hit->fitState() == CalibratedSpacePoint::State::Valid);
526 std::string legendstream{};
527 switch(hit->type()) {
529 const int driftSign{SeedingAux::strawSign(pos, dir, *hit)};
531 legendstream = std::format(
"ML: {:1d}, TL: {:1d}, T: {:3d}, {:}",
533 idHelper.
tube(hitId), driftSign == -1 ?
"L" :
"R");
537 legendstream= std::format(
"DR: {:1d}, DZ: {:1d}, GAP: {:1d}, #eta/#phi: {:}/{:}",
539 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
543 legendstream = std::format(
"ST: {:}, GAP: {:1d}, #eta/#phi: {:}/{:}",
545 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
550 const MuonGMR4::StripDesign& design = clus->readoutElement()->stripLayer(clus->layerHash()).design();
551 legendstream = std::format(
"ML: {:1d}, GAP: {:1d}, {:}", idHelper.
multilayer(hitId), idHelper.
gasGap(hitId),
556 legendstream = std::format(
"ML: {:1d}, GAP: {:1d}, #eta/#phi: {:}/{:}",
558 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
561 legendstream =
"Ext. constaint";
567 const double chi2 = SeedingAux::chi2Term(pos, dir,*hit);
568 legendstream+=std::format(
", #chi^{{2}}: {:.2f}",
chi2);
570 legendstream+=
", #chi^{2}: ---";
572 canvas.add(
drawLabel(legendstream, legX, startLegY, 14));
574 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
The MuonReadoutElement is an abstract class representing the geometry representing the 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< 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< TLatex > drawLabel(const std::string &text, const double xPos, const double yPos, const unsigned int fontSize=18)
Create a TLatex label,.
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.