14#include "Acts/Geometry/TrackingGeometry.hpp"
15#include "Acts/Geometry/TrackingVolume.hpp"
16#include "Acts/Visualization/GeometryView3D.hpp"
29 using PrimitivesVec_t = MuonValR4::TrackVisualizationTool::PrimitivesVec_t;
30 constexpr int truthColor = kOrange +2;
32 constexpr int ColorBarrel = kRed;
33 constexpr int ColorEndcapA = kBlue;
34 constexpr int ColorEndcapC = kGreen +2;
35 constexpr double inM = 1./ Gaudi::Units::m;
37 constexpr double extraMargin = 50.*Gaudi::Units::cm * inM;
42 std::unique_ptr<TMarker> drawMarker(
const Amg::Vector2D& pos,
const int mStyle,
const int mColor,
const int mSize = 2) {
43 auto marker = std::make_unique<TMarker>(
pos.x(),
pos.y(), mStyle);
44 marker->SetMarkerColor(mColor);
45 marker->SetMarkerSize(mSize);
50 constexpr double arrowLength = 2.*Gaudi::Units::m;
52 auto arrow = std::make_unique<TArrow>(
start.x(),
start.y(),
end.x(),
end.y(),0.01);
53 arrow->SetLineColor(
color);
54 arrow->SetLineWidth(2);
55 arrow->SetLineStyle(lineStyle);
61 const bool openMarker,
const bool onSeed) {
67 return onSeed ? (openMarker ? kOpenTriangleUp : kFullTriangleUp)
68 : (openMarker ? kOpenTriangleDown : kFullTriangleDown);
70 return onSeed ? (openMarker ? kOpenCrossX : kFullCrossX)
71 : (openMarker ? kOpenCross : kFullCross);
73 return onSeed ? (openMarker ? kOpenFourTrianglesX: kFullFourTrianglesX)
74 : (openMarker ? kOpenThreeTriangles : kFullThreeTriangles);
86 constexpr double phi = 0.6180339887498949;
87 const double h = 360 * std::fmod(0.13 +
phi *
double(iSeed), 1.0);
88 constexpr double s = 0.75;
89 constexpr double v = 0.95;
91 float r=0.f, g=0.f, b=0.f;
92 TColor::HLS2RGB(
h, s, v,
r, g, b);
93 return TColor::GetColor(
r, g, b);
102 colors.insert(std::make_pair(
color, std::move(box)));
109 legend->AddEntry(tMarker.get(),
label.c_str(),
"P");
110 markers.insert(std::make_pair(marker, std::move(tMarker)));
115 canvas.add(std::move(
legend));
116 for (
auto&[i, obj] :
colors){
117 canvas.add(std::move(obj));
120 canvas.add(std::move(obj));
128 return Amg::Vector2D{posOnCylinder[1]*inM, posOnCylinder[0]*inM};
151 return StatusCode::SUCCESS;
159 PrimitivesVec_t && extPrimitives)
const {
178 const EventContext& ctx,
184 std::format(
"SeedSegsGlobalTruth{:}", view ==
DisplayView::XY ?
"XY" :
"RZ"));
193 PrimitivesVec_t primitives{};
208 const auto chIdx = seg->chamberIndex();
209 const int mStyleTruth = stationMarkerSyle(chIdx,
true,
true);
212 const double x = p.x() * inM;
213 const double y = p.y() * inM;
214 const double z = p.z() * inM;
215 const double r = std::hypot(
x,
y);
219 primitives.emplace_back(drawMarker(plotPos, mStyleTruth, truthColor, 3));
222 const double dir_x = seg->direction().x() * inM;
223 const double dir_y = seg->direction().y() * inM;
224 const double dir_z = seg->direction().z() * inM;
228 primitives.emplace_back(drawArrow2D(plotPos, plotDir, truthColor));
235 canvas->expandPad(plotPos.x() - extraMargin, plotPos.y() - extraMargin);
236 canvas->expandPad(plotPos.x() + extraMargin, plotPos.y() + extraMargin);
244 for (std::size_t iSeed = 0; iSeed < seeds.size(); ++iSeed) {
248 std::string seedLabel = std::format(
"s{:d}: ",
static_cast<int>(iSeed));
253 const auto chIdx = seg->chamberIndex();
254 const int mStyle = stationMarkerSyle(chIdx,
false,
true);
257 const double x = p.x() * inM;
258 const double y = p.y() * inM;
259 const double z = p.z() * inM;
260 const double r = std::hypot(
x,
y);
265 primitives.emplace_back(drawMarker(plotPos, mStyle,
color));
268 const double dir_x = seg->direction().x() * inM;
269 const double dir_y = seg->direction().y() * inM;
270 const double dir_z = seg->direction().z() * inM;
274 primitives.emplace_back(drawArrow2D(plotPos, plotDir,
color));
277 seedLabel +=
label +
"_";
286 canvas->expandPad(plotPos.x() - extraMargin, plotPos.y() - extraMargin);
287 canvas->expandPad(plotPos.x() + extraMargin, plotPos.y() + extraMargin);
294 if (!drewAny) { canvas->trash();
return; }
296 for (
auto& p : primitives) canvas->add(std::move(p));
297 legend.fillPrimitives(*canvas);
307 PrimitivesVec_t&& extPrimitives)
const{
325 return std::ranges::any_of(seeds,[segment, loc](
const MsTrackSeed& seed){
326 return seed.location() == loc && std::ranges::find(seed.segments(), segment) != seed.segments().end();
330 const Acts::GeometryContext tgContext =
m_contextProvider.getGeometryContext(ctx);
331 bool drawnPoint{
false};
336 using namespace Muon;
339 const int mColor = msSector->
barrel() ? ColorBarrel : (msSector->
side() > 0 ? ColorEndcapA : ColorEndcapC);
341 for (
const auto secProj : {leftOverlap, center, rightOverlap}) {
353 const bool isGood = onSeed(segment, loc);
354 const int mStyle = stationMarkerSyle(chIdx,
true, isGood);
356 extPrimitives.emplace_back( drawMarker(markerPos, mStyle, mColor));
357 canvas->add( drawMarker(markerPos, mStyle, mColor));
360 const double r = markerPos.mag() + extraMargin;
361 canvas->expandPad(
r,
r);
362 canvas->expandPad(-
r, -
r);
364 canvas->expandPad(markerPos[0] - extraMargin, markerPos[1] - extraMargin);
365 canvas->expandPad(markerPos[0] + extraMargin, markerPos[1] + extraMargin);
368 isGood ?
"" :
" (discarded)"), mColor);
369 legend.addColor(mColor, msSector->
barrel() ?
"Barrel" : msSector->
side() > 0 ?
"Endcap A" :
"Endcap C");
380 kFullDiamond, kBlack));
381 legend.addMarker(kFullDiamond,
"track seed");
384 for (
unsigned int s = 1; s<=16 ; ++s) {
391 const int lStyle = s%2 ? kDashed : kDotted;
392 const double r = canvas->corner(Edges::xHigh);
397 auto theLine = std::make_unique<TLine>(0.,0., e1.x(), e1.y());
398 theLine->SetLineStyle(lStyle);
399 extPrimitives.insert(extPrimitives.begin(), std::move(theLine));
400 theLine = std::make_unique<TLine>(0.,0., e2.x(), e2.y());
401 theLine->SetLineStyle(lStyle);
402 extPrimitives.insert(extPrimitives.begin(), std::move(theLine));
403 theLine = std::make_unique<TLine>(e1.x(), e1.y(), e2.x(), e2.y());
404 theLine->SetLineStyle(lStyle);
405 extPrimitives.insert(extPrimitives.begin(), std::move(theLine));
407 legend.fillPrimitives(*canvas);
420 const Acts::GeometryContext tgContext =
m_contextProvider.getGeometryContext(ctx);
421 bool addedEntry{
false};
423 const auto chIdx = segment->chamberIndex();
424 const int mStyle = stationMarkerSyle(chIdx,
true,
true);
434 canvas.add(drawMarker(
viewVector(sector.
phi(), projected, view), mStyle, truthColor, 3));
440 legend.addColor(truthColor,
"truth");
445 const OptBoundPars_t& parsToExt,
446 const std::string& objName)
const {
450 const Acts::GeometryContext tgContext =
m_contextProvider.getGeometryContext(ctx);
451 Acts::ObjVisualization3D visualHelper{};
452 const std::string subDir = std::format(
"./ObjDisplays/{:}/",
m_subDir.value());
456 std::unordered_set<Acts::GeometryIdentifier> surfaceIds{};
468 if (stepsResult.ok()) {
471 auto [begin, end] = std::ranges::remove_if(stepsResult->first,
472 [vol](
const Acts::detail::Step& step) {
473 return !vol->volumeBounds().inside(step.position);
475 stepsResult->first.erase(begin, end);
476 for (
const Acts::detail::Step& step: stepsResult->first) {
477 if (!step.surface || surfaceIds.count(step.surface->geometryId())) {
480 Acts::GeometryView3D::drawSurface(visualHelper, *step.surface, tgContext,
481 Amg::Transform3D::Identity(), Acts::s_viewPassive);
485 ATH_MSG_WARNING(
"Failed to extrapolate the seed for visualization: " << stepsResult.error().message());
489 unsigned fileVersion{0};
490 std::string finalStr{};
491 while (finalStr.empty() || std::filesystem::exists(finalStr)) {
492 finalStr = std::format(
"{:}/{:}_{:}_{:}_{:}.obj", subDir,
493 m_clientToken.preFixName, ctx.eventID().event_number(), ++fileVersion, segStr);
495 visualHelper.write(finalStr);
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x,...)
bool empty() const noexcept
Returns true if the collection is empty.
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
int8_t side() const
Returns the side of the MS-sector 1 -> A side ; -1 -> C side.
bool barrel() const
Returns whether the sector is placed in the barrel.
double phi() const
Returns the phi angle of the expanded sector.
SectorProjector
Enumeration to select the sector projection of the regular MS sector.
const MuonGMR4::SpectrometerSector * msSector() const
Returns the associated MS sector.
double sectorPhi(int sector) const
returns the centeral phi position of a sector in radians
double sectorWidth(int sector) const
sector width (with overlap) in radians
::Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
std::string label(const std::string &format, int i)
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
This header ties the generic definitions in this package.
std::vector< MsTrackSeed > MsTrackSeedContainer
std::string printID(const xAOD::MuonSegment &seg)
Print the chamber ID of a segment, e.g.
const xAOD::UncalibratedMeasurement * getMeasurement(const xAOD::MuonSegment &segment, const std::size_t n)
Returns the n-th uncalibrated measurement.
std::size_t nMeasurements(const xAOD::MuonSegment &segment)
Returns the number of associated Uncalibrated measurements.
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
void ensureDirectory(const std::string &path)
Ensures that the subdirectory in the path is created.
void drawSegmentMeasurements(const Acts::GeometryContext &tgContext, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw all uncalibrated measurements associated to the segment.
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::vector< std::unique_ptr< TObject > > clone(const std::vector< std::unique_ptr< TObject > > &cloneMe)
int seedColorIdx(std::size_t iSeed)
void drawPropagation(const std::vector< Acts::detail::Step > &steps, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine)
Draws the recorded propagation steps as a polygon line.
void drawSegmentLine(const Acts::GeometryContext &tgContext, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine, const double standardLength=1.*Gaudi::Units::m)
Draw a segment line inside the obj file.
constexpr int fullFilling
std::string removeNonAlphaNum(std::string str)
Removes all non-alpha numerical characters from a string.
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 std::string & layerName(LayerIndex index)
convert LayerIndex into a string
LayerIndex
enum to classify the different layers in the muon spectrometer
LayerIndex toLayerIndex(ChIndex index)
convert ChIndex into LayerIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
MuonSegment_v1 MuonSegment
Reference the current persistent version:
const Acts::Surface & muonSurface(const UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.
Helper to simultaneously calculate sin and cos of the same angle.
#define THROW_EXCEPTION(MESSAGE)