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*>;
39 using namespace SegmentFit;
43 if (m_canvasLimit > 0) {
44 m_clientToken.canvasLimit = m_canvasLimit;
45 m_clientToken.preFixName = m_canvasPrefix;
46 m_clientToken.saveSinglePlots = m_saveSinglePDFs;
47 m_clientToken.saveSummaryPlot = m_saveSummaryPDF;
48 m_clientToken.subDirectory = m_subDir;
50 ATH_CHECK(m_visualSvc->registerClient(m_clientToken));
54 ATH_CHECK(m_prepContainerKeys.initialize(!m_truthSegLinks.empty()));
55 m_truthLinkDecorKeys.clear();
56 ATH_MSG_INFO(
"Hits linked to the following segment decorations are considered as truth");
57 for (
const std::string& decorName : m_truthSegLinks) {
59 if (decorName.empty()) {
61 return StatusCode::FAILURE;
64 m_truthLinkDecorKeys.emplace_back(
key, decorName);
68 ATH_CHECK(m_truthLinkDecorKeys.initialize());
69 m_displayOnlyTruth.value() &= !m_truthLinkDecorKeys.empty();
74 return StatusCode::SUCCESS;
81 return std::find_if(m_truthLinkDecors.begin(), m_truthLinkDecors.end(),
83 return !decor(hit).empty();
84 }) != m_truthLinkDecors.end();
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());
96 return getLabeledSegments(measurements);
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 {
135 visualizeAccumulator(ctx, accumulator, axisRanges, maxima, extraLabel, std::move(primitives));
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));
167 if (truthSegs.empty() && m_displayOnlyTruth) {
170 auto canvas = m_visualSvc->prepareCanvas(ctx, m_clientToken, extraLabel);
175 canvas->expandPad(axisRanges.xMin, axisRanges.yMin);
176 canvas->expandPad(axisRanges.xMax, axisRanges.yMax);
178 std::format(
"{:}_{{0}} [mm]", m_accumlIsEta ?
"y" :
"x"));
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));
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 {
204 if (!m_paintTruthHits) {
209 if (!
SG::get(geoCtx, m_geoCtxKey, ctx).isSuccess()) {
215 re->measurementHash(simHit->identify()) :
216 re->layerHash(simHit->identify());
218 re->localToGlobalTrans(*geoCtx,
hash);
226 const std::string& extraLabel)
const {
228 visualizeSeed(ctx, seed, extraLabel, std::move(primitives));
232 const std::string& extraLabel,
240 if (truthSegs.empty() && m_displayOnlyTruth) {
244 auto canvas = m_visualSvc->prepareCanvas(ctx, m_clientToken, extraLabel);
249 canvas->add(std::move(primitives));
259 if (!drawHits(*seed.parentBucket(), seed.getHitsInMax(), *
canvas,
view)) {
264 canvas->corner(Edges::yLow),
canvas->corner(Edges::yHigh),
265 truthColor, kDotted,
view));
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()),
285 const std::string& extraLabel)
const {
287 visualizeBucket(ctx, bucket, extraLabel, std::move(primitives));
291 const std::string& extraLabel,
298 LabeledSegmentSet truthSegs{getLabeledSegments(Acts::unpackConstSmartPointers(bucket))};
299 if (truthSegs.empty() && m_displayOnlyTruth) {
302 auto canvas = m_visualSvc->prepareCanvas(ctx, m_clientToken, extraLabel);
307 canvas->add(std::move(primitives));
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(),
342 const std::string& extraLabel)
const {
344 visualizeSegment(ctx, segment,extraLabel, std::move(primitives));
349 const std::string& extraLabel,
357 if (truthSegs.empty() && m_displayOnlyTruth) {
361 if (!
SG::get(geoCtx, m_geoCtxKey, ctx).isSuccess()) {
364 auto canvas = m_visualSvc->prepareCanvas(ctx, m_clientToken, extraLabel);
369 canvas->add(std::move(primitives));
386 truthColor, kDotted,
view));
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),
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>) {
431 fillStyle = invalidCalibFill;
434 }
else if constexpr(std::is_same_v<SpacePointType, CalibratedSpacePoint>) {
435 underlyingSp = hit.spacePoint();
439 fillStyle = invalidCalibFill;
450 const int circColor = isLabeled(*dc) ? truthColor : kBlue;
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));
461 const auto* meas{
static_cast<const xAOD::TgcStrip*
>(underlyingSp->primaryMeasurement())};
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));
468 const int boxColor = isLabeled(*underlyingSp->primaryMeasurement()) ? truthColor : kAquamarine;
475 const int boxColor = isLabeled(*underlyingSp->primaryMeasurement()) ? truthColor : kTeal;
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 {
494 for (
const SpacePointType& hit : hitsToDraw) {
497 if (m_displayBucket) {
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 {
516 for (
const SpacePointType& hit :
hits) {
518 bool displayChi2{
true};
519 if constexpr(std::is_same_v<SpacePointType, Segment::MeasType>) {
520 underlyingSp = hit->spacePoint();
526 std::string legendstream{};
527 switch(hit->type()) {
529 const int driftSign{SeedingAux::strawSign(
pos,
dir, *hit)};
530 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
531 legendstream =
std::format(
"ML: {:1d}, TL: {:1d}, T: {:3d}, {:}",
532 idHelper.multilayer(hitId), idHelper.tubeLayer(hitId),
533 idHelper.tube(hitId), driftSign == -1 ?
"L" :
"R");
536 const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
537 legendstream=
std::format(
"DR: {:1d}, DZ: {:1d}, GAP: {:1d}, #eta/#phi: {:}/{:}",
538 idHelper.doubletR(hitId), idHelper.doubletZ(hitId), idHelper.gasGap(hitId),
539 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
542 const TgcIdHelper& idHelper{m_idHelperSvc->tgcIdHelper()};
543 legendstream =
std::format(
"ST: {:}, GAP: {:1d}, #eta/#phi: {:}/{:}",
544 m_idHelperSvc->stationNameString(hitId), idHelper.gasGap(hitId),
545 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
548 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
549 const auto* clus =
static_cast<const xAOD::MMCluster*
>(underlyingSp->primaryMeasurement());
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),
555 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
556 legendstream =
std::format(
"ML: {:1d}, GAP: {:1d}, #eta/#phi: {:}/{:}",
557 idHelper.multilayer(hitId), idHelper.gasGap(hitId),
558 hit->measuresEta() ?
"si" :
"nay", hit->measuresPhi() ?
"si" :
"nay");
561 legendstream =
"Ext. constaint";
567 const double chi2 = SeedingAux::chi2Term(
pos,
dir,*hit);
570 legendstream+=
", #chi^{2}: ---";
574 if (startLegY<= endLegY) {