15#include "Acts/Definitions/Units.hpp"
16#include "Acts/Definitions/Common.hpp"
17#include "Acts/Definitions/Algebra.hpp"
18#include "Acts/Surfaces/Surface.hpp"
19#include "Acts/Surfaces/AnnulusBounds.hpp"
20#include "Acts/Surfaces/SurfaceBounds.hpp"
21#include "Acts/Surfaces/DiscSurface.hpp"
22#include "Acts/EventData/TransformationHelpers.hpp"
23#include "Acts/Utilities/detail/OstreamStateGuard.hpp"
37using Acts::detail::OstreamStateGuard;
48 static constexpr std::array<std::tuple<bool, Acts::TrackStateFlag, char>, 6> trackStateNames{{
49 {
false, Acts::TrackStateFlag::HasParameters,
'-'},
50 {
true, Acts::TrackStateFlag::HasMeasurement,
'M'},
51 {
true, Acts::TrackStateFlag::IsOutlier,
'O'},
52 {
true, Acts::TrackStateFlag::IsHole,
'H'},
53 {
true, Acts::TrackStateFlag::HasMaterial,
'm'},
54 {
true, Acts::TrackStateFlag::IsSharedHit,
'S'},
57 for (
const auto &[b, f, c] : trackStateNames)
59 if (trackStateType.test(f) == b)
68 const auto type = std::min(surface.type(), Acts::Surface::SurfaceType::Other);
69 std::string name{Acts::Surface::s_surfaceTypeNames[
type]};
70 static const std::map<Acts::SurfaceBounds::BoundsType, const char *> boundsNames{{
71 {Acts::SurfaceBounds::BoundsType::eCone,
"Cone"},
72 {Acts::SurfaceBounds::BoundsType::eCylinder,
"Cylinder"},
73 {Acts::SurfaceBounds::BoundsType::eDiamond,
"Diamond"},
74 {Acts::SurfaceBounds::BoundsType::eDisc,
"Disc"},
75 {Acts::SurfaceBounds::BoundsType::eEllipse,
"Ellipse"},
76 {Acts::SurfaceBounds::BoundsType::eLine,
"Line"},
77 {Acts::SurfaceBounds::BoundsType::eRectangle,
"Rectangle"},
78 {Acts::SurfaceBounds::BoundsType::eTrapezoid,
"Trapezoid"},
79 {Acts::SurfaceBounds::BoundsType::eTriangle,
"Triangle"},
80 {Acts::SurfaceBounds::BoundsType::eDiscTrapezoid,
"DiscTrapezoid"},
81 {Acts::SurfaceBounds::BoundsType::eConvexPolygon,
"ConvexPolygon"},
82 {Acts::SurfaceBounds::BoundsType::eAnnulus,
"Annulus"},
83 {Acts::SurfaceBounds::BoundsType::eBoundless,
"Boundless"},
84 {Acts::SurfaceBounds::BoundsType::eOther,
"Other"},
86 if (
auto it = boundsNames.find(surface.bounds().type());
87 it != boundsNames.end() && it->second != name)
98 if (measurement_surface) {
100 if (acts_detector_element) {
105 auto name = idHelper->show_to_string(detElem->
identify());
106 if (name.size() >= 2 && name[0] ==
'[' && name[name.size() - 1] ==
']')
108 return name.substr(1, name.size() - 2);
123 OstreamStateGuard s(std::cout);
124 std::cout << std::left
125 << std::setw(5) <<
"Index" <<
' '
126 << std::setw(4) <<
"Type" <<
' '
127 << std::setw(21) <<
"SurfaceBounds" <<
' ';
130 std::cout << std::setw(22) <<
"GeometryId" <<
' '
131 << std::setw(20) <<
"ATLAS ID" <<
' '
133 << std::setw(10) <<
"loc0" <<
' '
134 << std::setw(10) <<
"loc1"
136 << std::setw(9) <<
"R" <<
' '
137 << std::setw(9) <<
"Pos Z" <<
' '
138 << std::setw(9) <<
"phid" <<
' '
139 << std::setw(9) <<
"eta";
143 << std::setw(10) <<
"Trk loc0" <<
' '
144 << std::setw(10) <<
"loc1"
146 << std::setw(9) <<
"Trk R" <<
' '
147 << std::setw(9) <<
"phid" <<
' '
148 << std::setw(9) <<
"eta" <<
' '
149 << std::setw(10) <<
"g2l loc0" <<
' '
150 << std::setw(10) <<
"loc1";
153 static std::atomic<int> kilroy = 0;
156 std::cout <<
"R (mm) and phi (degrees). Estimated local coordinate indicated by \"*\" (from SP), \"o\" (from module center), or \"#\" (globalToLocal(center) failure).";
158 std::cout <<
" Athena/ACTS comparison only shown if different.";
164 std::cout << std::setw(22) <<
"GeometryId/meas/stats" <<
' '
166 << std::setw(10) <<
"loc0" <<
' '
167 << std::setw(10) <<
"loc1" <<
' '
168 << std::setw(9) <<
"Pos R" <<
' '
169 << std::setw(9) <<
"Pos Z" <<
' '
170 << std::setw(9) <<
"phid" <<
' '
171 << std::setw(9) <<
"eta" <<
' '
172 << std::setw(9) <<
"q*pT" <<
' '
173 << std::setw(9) <<
"phid" <<
' '
174 << std::setw(9) <<
"eta" <<
' '
175 << std::setw(6) <<
"TrkLen" <<
' '
176 << std::setw(7) <<
"chi2" <<
' '
177 << std::setw(6) <<
"Flags" <<
'\n';
184 OstreamStateGuard s(std::cout);
185 std::cout << std::fixed <<
' '
186 << std::setw(9) << std::setprecision(3) << p.head<2>().norm() <<
' '
187 << std::setw(9) << std::setprecision(3) << p[2] <<
' '
188 << std::setw(9) << std::setprecision(3) << std::atan2(p[1], p[0]) / Acts::UnitConstants::degree <<
' '
189 << std::setw(9) << std::setprecision(5) << std::atanh(p[2] / p.norm());
194 printVec3(
const Acts::Vector3 &p,
const Acts::Vector3 &cmp,
int precision = 3)
196 if (((p - cmp).array().abs() >= 0.5 * std::pow(10.0, -precision)).any())
202 std::cout << std::setw(30) <<
"";
207 printVec2(
const Acts::Vector2 &p,
const char *estimated =
nullptr)
209 OstreamStateGuard s(std::cout);
210 const char e0 = estimated ? estimated[0] :
' ';
211 const char *e1 = estimated ? estimated + 1 :
"";
212 std::cout << std::fixed <<
' '
213 << std::setw(10) << std::setprecision(4) << p[0] << e0
214 << std::setw(10) << std::setprecision(4) << p[1] << e1;
219 printVec2(
const Acts::Vector2 &p,
const Acts::Vector2 &cmp,
const char *estimated =
nullptr,
int precision = 4)
221 if (((p - cmp).array().abs() >= 0.5 * std::pow(10.0, -precision)).any())
227 std::cout << std::setw(22 + (estimated ? 1 : 0)) <<
"";
233 const Acts::Surface *surface,
234 const std::tuple<Acts::Vector2, Amg::Vector2D, int, int> &locData,
235 bool compareMeasurementTransforms =
false)
237 OstreamStateGuard s(std::cout);
238 auto &[loc, locTrk, measInd, est] = locData;
239 int flag = est < 0 ? est : 2 * est + measInd;
240 int flagTrk = est < 0 ? est : 2 * est;
242 static const std::map<int, const char *> estimated_flags{{-1,
" "},
249 printVec2(loc, estimated_flags.at(flag));
254 auto glob = surface->localToGlobal(tgContext, loc, Acts::Vector3::Zero());
257 if (compareMeasurementTransforms) {
259 if (acts_detector_element) {
264 printVec2(locTrk, (measInd == 1 ? loc.reverse() : loc), estimated_flags.at(flagTrk));
271 auto res = surface->globalToLocal(tgContext, globTrk, Acts::Vector3::Zero());
274 std::cout <<
" ** " <<
res.error() <<
" **";
287 static std::tuple<Acts::Vector2, Amg::Vector2D, int, int>
290 const Acts::Surface *surface,
293 auto *disc =
dynamic_cast<const Acts::DiscSurface *
>(surface);
294 Acts::Vector2 loc{Acts::Vector2::Zero()};
300 auto res = surface->globalToLocal(tgContext,
sp->globalPosition().cast<
double>(), Acts::Vector3::Zero());
310 if (
auto *annulus =
dynamic_cast<const Acts::AnnulusBounds *
>(&surface->bounds()))
312 loc[0] = 0.5 * (annulus->rMin() + annulus->rMax());
317 auto res = surface->globalToLocal(tgContext, surface->center(tgContext), Acts::Vector3::Zero());
327 const int measInd = disc ? 1 : 0;
331 Amg::Vector2D locTrk{disc->localPolarToCartesian(loc).reverse()};
332 locTrk[0] = -locTrk[0];
333 return {loc, locTrk, measInd, est};
337 return {loc, loc, measInd, est};
345 size_t offset)
const {
349 std::cout << std::setw(5) << (measurement->index() + offset) <<
' '
352 const Acts::Surface *surface_ptr =
m_surfAcc.get(measurement);
355 std::cout << std::setw(20 + 22 + 20 + 2) <<
"** no surface for measurement **";
359 std::cout << std::left;
361 << std::setw(22) <<
to_string(surface_ptr->geometryId()) <<
' ';
363 std::cout << std::right;
368 const auto loc = measurement->
localPosition<2>().cast<double>();
373 if (measurement->index() >= measToSp.size() || measToSp.at(measurement->index()).empty()) {
380 ATH_MSG_DEBUG(
"No SpacePoints for strip measurement " << measurement->index() <<
" (" << measToSp.size() <<
" associated SPs)");
383 for (
auto *
sp : measToSp.at(measurement->index()))
389 << std::setw(76) <<
to_string(
"** Spacepoint ", isp,
" **")
399 const auto loc3D = measurement->
localPosition<3>().cast<double>();
400 const std::tuple<Acts::Vector2, Amg::Vector2D, int, int> locTup = {Acts::Vector2{loc3D.head<2>()},
Amg::Vector2D{loc3D.head<2>()}, -1, -1};
407 const Acts::GeometryContext &tgContext,
408 const Acts::BoundVector &bound)
410 OstreamStateGuard s(std::cout);
411 auto p = Acts::transformBoundToFreeParameters(surface, tgContext, bound);
412 std::cout << std::fixed
413 << std::setw(10) << std::setprecision(4) << bound[Acts::eBoundLoc0] <<
' '
414 << std::setw(10) << std::setprecision(4) << bound[Acts::eBoundLoc1] <<
' '
415 << std::setw(9) << std::setprecision(3) << p.segment<2>(Acts::eFreePos0).norm() <<
' '
416 << std::setw(9) << std::setprecision(3) << p[Acts::eFreePos2] <<
' '
417 << std::setw(9) << std::setprecision(3) << std::atan2(p[Acts::eFreePos1], p[Acts::eFreePos0]) / Acts::UnitConstants::degree <<
' '
418 << std::setw(9) << std::setprecision(5) << std::atanh(p[Acts::eFreePos2] / p.segment<3>(Acts::eFreePos0).norm()) <<
' '
419 << std::setw(9) << std::setprecision(3) << p.segment<2>(Acts::eFreeDir0).norm() / p[Acts::eFreeQOverP] <<
' '
420 << std::setw(9) << std::setprecision(3) << std::atan2(p[Acts::eFreeDir1], p[Acts::eFreeDir0]) / Acts::UnitConstants::degree <<
' '
421 << std::setw(9) << std::setprecision(5) << std::atanh(p[Acts::eFreeDir2]);
439 return StatusCode::SUCCESS;
445 const Acts::BoundTrackParameters &initialParameters,
453 std::ostringstream os;
455 for (
const auto *
sp : seed.sp())
458 for (
const auto *el :
sp->measurements())
466 os << measurementIndexer.
index(*el);
470 std::cout << std::setw(5) << iseed <<
' '
472 << std::setw(4) << (!isKF ?
"seed" :
"KF") <<
' '
473 << std::setw(21) <<
actsSurfaceName(initialParameters.referenceSurface()) <<
' '
474 << std::setw(22) <<
to_string(os.str()) <<
' '
476 printParameters(initialParameters.referenceSurface(), tgContext, initialParameters.parameters());
483 const std::vector<const xAOD::UncalibratedMeasurementContainer *> &clusterContainers,
484 const std::vector<size_t> &offsets)
const {
486 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
493 for (std::size_t icontainer = 0; icontainer < clusterContainers.size(); ++icontainer)
495 for (
const auto *measurement : *clusterContainers[icontainer])
498 measToSp[icontainer], offsets[icontainer]);
501 std::cout << std::flush;
504 std::vector<std::vector<TrackStatePrinterTool::small_vector<const xAOD::SpacePoint *>>>
506 const std::vector<const xAOD::UncalibratedMeasurementContainer *> &clusterContainers,
507 const std::vector<size_t> &offsets)
const
509 std::vector<std::vector<TrackStatePrinterTool::small_vector<const xAOD::SpacePoint *>>> measToSp{clusterContainers.size()};
510 for (std::size_t icontainer = 0; icontainer < clusterContainers.size(); ++icontainer)
512 measToSp[icontainer].resize(clusterContainers[icontainer]->
size());
517 ATH_MSG_DEBUG(
"Retrieving from input SpacePoint collection '" << spacePointKey.key() <<
"' ...");
519 if (!handle.isValid())
521 ATH_MSG_ERROR(
"Error retrieving from input SpacePoint collection '" << spacePointKey.key() <<
"'");
525 for (
const auto *
sp : *handle)
531 for (std::size_t icontainer = 0; icontainer < clusterContainers.size(); ++icontainer)
534 if (!(meas && meas->index() < clusterContainers[icontainer]->size() && meas == clusterContainers[icontainer]->at(meas->index())))
540 << (meas->index() + offsets[icontainer])
541 <<
" used by SpacePoints at ("
542 <<
sp->globalPosition()[0] <<
',' <<
sp->globalPosition()[1] <<
',' <<
sp->globalPosition()[2]
544 << measSp[0]->globalPosition()[0] <<
',' << measSp[0]->globalPosition()[1] <<
',' << measSp[0]->globalPosition()[2]
547 measSp.push_back(
sp);
const ActsDetectorElement * getActsDetectorElement(const Acts::Surface &surf)
Attempts to retrieve the ActsDetectorElement associated to the passed ActsSurface.
#define ATH_CHECK
Evaluate an expression and check for errors.
std::pair< std::vector< unsigned int >, bool > res
size_t size() const
Number of registered mappings.
std::size_t index(const xAOD::UncalibratedMeasurement &hit) const
Helper class to access the Acts::surface associated with an Uncalibrated xAOD measurement.
Class to hold geometrical description of a silicon detector element.
virtual Identifier identify() const override final
identifier of this detector element (inline)
const AtlasDetectorID * getIdHelper() const
Returns the id helper (inline).
Trk::Surface & surface()
Element Surface.
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const =0
Specified by each surface type: LocalToGlobal method without dynamic memory allocation.
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
virtual unsigned int numDimensions() const =0
Returns the number of dimensions of the measurement.
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
static std::string atlasSurfaceName(const Acts::Surface *measurement_surface)
static void printVec3(const Acts::Vector3 &p)
static void printMeasurement(const Acts::GeometryContext &tgContext, const Acts::Surface *surface, const std::tuple< Acts::Vector2, Amg::Vector2D, int, int > &locData, bool compareMeasurementTransforms=false)
static std::tuple< Acts::Vector2, Amg::Vector2D, int, int > localPositionStrip2D(const Acts::GeometryContext &tgContext, const xAOD::UncalibratedMeasurement &measurement, const Acts::Surface *surface, const xAOD::SpacePoint *sp)
static void printHeader(int type, bool extra=false)
static void printVec2(const Acts::Vector2 &p, const char *estimated=nullptr)
Eigen::Matrix< double, 2, 1 > Vector2D
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.