14#include "Acts/Definitions/Units.hpp"
15#include "Acts/Definitions/Common.hpp"
16#include "Acts/Definitions/Algebra.hpp"
17#include "Acts/Surfaces/Surface.hpp"
18#include "Acts/Surfaces/AnnulusBounds.hpp"
19#include "Acts/Surfaces/SurfaceBounds.hpp"
20#include "Acts/Surfaces/DiscSurface.hpp"
21#include "Acts/EventData/TransformationHelpers.hpp"
44 static constexpr std::array<std::tuple<bool, Acts::TrackStateFlag, char>, 6> trackStateNames{{
45 {
false, Acts::TrackStateFlag::ParameterFlag,
'-'},
46 {
true, Acts::TrackStateFlag::MeasurementFlag,
'M'},
47 {
true, Acts::TrackStateFlag::OutlierFlag,
'O'},
48 {
true, Acts::TrackStateFlag::HoleFlag,
'H'},
49 {
true, Acts::TrackStateFlag::MaterialFlag,
'm'},
50 {
true, Acts::TrackStateFlag::SharedHitFlag,
'S'},
53 for (
const auto &[b, f, c] : trackStateNames)
55 if (trackStateType.test(f) == b)
64 const auto type = std::min(surface.type(), Acts::Surface::SurfaceType::Other);
65 std::string name{Acts::Surface::s_surfaceTypeNames[
type]};
66 static const std::map<Acts::SurfaceBounds::BoundsType, const char *> boundsNames{{
67 {Acts::SurfaceBounds::BoundsType::eCone,
"Cone"},
68 {Acts::SurfaceBounds::BoundsType::eCylinder,
"Cylinder"},
69 {Acts::SurfaceBounds::BoundsType::eDiamond,
"Diamond"},
70 {Acts::SurfaceBounds::BoundsType::eDisc,
"Disc"},
71 {Acts::SurfaceBounds::BoundsType::eEllipse,
"Ellipse"},
72 {Acts::SurfaceBounds::BoundsType::eLine,
"Line"},
73 {Acts::SurfaceBounds::BoundsType::eRectangle,
"Rectangle"},
74 {Acts::SurfaceBounds::BoundsType::eTrapezoid,
"Trapezoid"},
75 {Acts::SurfaceBounds::BoundsType::eTriangle,
"Triangle"},
76 {Acts::SurfaceBounds::BoundsType::eDiscTrapezoid,
"DiscTrapezoid"},
77 {Acts::SurfaceBounds::BoundsType::eConvexPolygon,
"ConvexPolygon"},
78 {Acts::SurfaceBounds::BoundsType::eAnnulus,
"Annulus"},
79 {Acts::SurfaceBounds::BoundsType::eBoundless,
"Boundless"},
80 {Acts::SurfaceBounds::BoundsType::eOther,
"Other"},
82 if (
auto it = boundsNames.find(surface.bounds().type());
83 it != boundsNames.end() && it->second != name)
92 atlasSurfaceName(
const Acts::Surface *measurement_surface)
94 if (measurement_surface) {
96 acts_detector_element =
dynamic_cast<const ActsDetectorElement *
>(measurement_surface->associatedDetectorElement());
97 if (acts_detector_element) {
102 auto name = idHelper->show_to_string(detElem->
identify());
103 if (name.size() >= 2 && name[0] ==
'[' && name[name.size() - 1] ==
']')
105 return name.substr(1, name.size() - 2);
118 static void printHeader(
int type,
bool extra =
false)
120 std::cout << std::left
121 << std::setw(5) <<
"Index" <<
' '
122 << std::setw(4) <<
"Type" <<
' '
123 << std::setw(21) <<
"SurfaceBounds" <<
' ';
126 std::cout << std::setw(22) <<
"GeometryId" <<
' '
127 << std::setw(20) <<
"ATLAS ID" <<
' '
129 << std::setw(10) <<
"loc0" <<
' '
130 << std::setw(10) <<
"loc1"
132 << std::setw(9) <<
"R" <<
' '
133 << std::setw(9) <<
"Pos Z" <<
' '
134 << std::setw(9) <<
"phid" <<
' '
135 << std::setw(9) <<
"eta";
139 << std::setw(10) <<
"Trk loc0" <<
' '
140 << std::setw(10) <<
"loc1"
142 << std::setw(9) <<
"Trk R" <<
' '
143 << std::setw(9) <<
"phid" <<
' '
144 << std::setw(9) <<
"eta" <<
' '
145 << std::setw(10) <<
"g2l loc0" <<
' '
146 << std::setw(10) <<
"loc1";
149 static std::atomic<int> kilroy = 0;
152 std::cout <<
"R (mm) and phi (degrees). Estimated local coordinate indicated by \"*\" (from SP), \"o\" (from module center), or \"#\" (globalToLocal(center) failure).";
154 std::cout <<
" Athena/ACTS comparison only shown if different.";
160 std::cout << std::setw(22) <<
"GeometryId/meas/stats" <<
' '
162 << std::setw(10) <<
"loc0" <<
' '
163 << std::setw(10) <<
"loc1" <<
' '
164 << std::setw(9) <<
"Pos R" <<
' '
165 << std::setw(9) <<
"Pos Z" <<
' '
166 << std::setw(9) <<
"phid" <<
' '
167 << std::setw(9) <<
"eta" <<
' '
168 << std::setw(9) <<
"q*pT" <<
' '
169 << std::setw(9) <<
"phid" <<
' '
170 << std::setw(9) <<
"eta" <<
' '
171 << std::setw(6) <<
"TrkLen" <<
' '
172 << std::setw(7) <<
"chi2" <<
' '
173 << std::setw(6) <<
"Flags" <<
'\n';
178 printVec3(
const Acts::Vector3 &p)
180 std::cout << std::fixed <<
' '
181 << std::setw(9) << std::setprecision(3) <<
p.head<2>().
norm() <<
' '
182 << std::setw(9) << std::setprecision(3) <<
p[2] <<
' '
183 << std::setw(9) << std::setprecision(3) << std::atan2(p[1], p[0]) / Acts::UnitConstants::degree <<
' '
184 << std::setw(9) << std::setprecision(5) << std::atanh(p[2] /
p.norm())
185 << std::defaultfloat << std::setprecision(-1);
189 printVec3(
const Acts::Vector3 &p,
const Acts::Vector3 &cmp,
int precision = 3)
191 if (((p - cmp).
array().abs() >= 0.5 * std::pow(10.0, -precision)).any())
197 std::cout << std::setw(30) <<
"";
202 printVec2(
const Acts::Vector2 &p,
const char *estimated =
nullptr)
204 const char e0 = estimated ? estimated[0] :
' ';
205 const char *
e1 = estimated ? estimated + 1 :
"";
206 std::cout << std::fixed <<
' '
207 << std::setw(10) << std::setprecision(4) <<
p[0] <<
e0
208 << std::setw(10) << std::setprecision(4) <<
p[1] <<
e1
209 << std::defaultfloat << std::setprecision(-1);
213 printVec2(
const Acts::Vector2 &p,
const Acts::Vector2 &cmp,
const char *estimated =
nullptr,
int precision = 4)
215 if (((p - cmp).
array().abs() >= 0.5 * std::pow(10.0, -precision)).any())
217 printVec2(p, estimated);
221 std::cout << std::setw(22 + (estimated ? 1 : 0)) <<
"";
226 printMeasurement(
const Acts::GeometryContext &tgContext,
227 const Acts::Surface *surface,
228 const std::tuple<Acts::Vector2, Amg::Vector2D, int, int> &locData,
229 bool compareMeasurementTransforms =
false)
231 auto &[loc, locTrk, measInd, est] = locData;
232 int flag = est < 0 ? est : 2 * est + measInd;
233 int flagTrk = est < 0 ? est : 2 * est;
235 static const std::map<int, const char *> estimated_flags{{-1,
" "},
242 printVec2(loc, estimated_flags.at(flag));
247 auto glob = surface->localToGlobal(tgContext, loc, Acts::Vector3::Zero());
250 if (compareMeasurementTransforms)
252 const ActsDetectorElement *
253 acts_detector_element =
dynamic_cast<const ActsDetectorElement *
>(surface->associatedDetectorElement());
254 if (acts_detector_element) {
255 const InDetDD::SiDetectorElement *detElem =
dynamic_cast< const InDetDD::SiDetectorElement *
>(acts_detector_element->
upstreamDetectorElement());
259 printVec2(locTrk, (measInd == 1 ? loc.reverse() : loc), estimated_flags.at(flagTrk));
264 printVec3(globTrk, glob);
266 auto res = surface->globalToLocal(tgContext, globTrk, Acts::Vector3::Zero());
269 std::cout <<
" ** " <<
res.error() <<
" **";
273 printVec2(
res.value(), loc);
280 std::cout << std::defaultfloat << std::setprecision(-1);
283 static std::tuple<Acts::Vector2, Amg::Vector2D, int, int>
284 localPositionStrip2D(
const Acts::GeometryContext &tgContext,
286 const Acts::Surface *surface,
289 auto *disc =
dynamic_cast<const Acts::DiscSurface *
>(surface);
290 Acts::Vector2 loc{Acts::Vector2::Zero()};
296 auto res = surface->globalToLocal(tgContext, sp->
globalPosition().cast<
double>(), Acts::Vector3::Zero());
306 if (
auto *annulus =
dynamic_cast<const Acts::AnnulusBounds *
>(&surface->bounds()))
308 loc[0] = 0.5 * (annulus->rMin() + annulus->rMax());
313 auto res = surface->globalToLocal(tgContext, surface->center(tgContext), Acts::Vector3::Zero());
323 const int measInd = disc ? 1 : 0;
327 Amg::Vector2D locTrk{disc->localPolarToCartesian(loc).reverse()};
328 locTrk[0] = -locTrk[0];
329 return {loc, locTrk, measInd, est};
333 return {loc, loc, measInd, est};
341 size_t offset)
const {
345 std::cout << std::setw(5) << (measurement->
index() + offset) <<
' '
348 const Acts::Surface *surface_ptr =
m_surfAcc.get(measurement);
351 std::cout << std::setw(20 + 22 + 20 + 2) <<
"** no surface for measurement **";
355 std::cout << std::left;
357 << std::setw(22) <<
to_string(surface_ptr->geometryId()) <<
' ';
358 std::cout << std::setw(20) << atlasSurfaceName(surface_ptr);
359 std::cout << std::right;
364 const auto loc = measurement->
localPosition<2>().cast<double>();
372 printMeasurement(tgContext, surface_ptr,
373 localPositionStrip2D(tgContext, *measurement, surface_ptr,
nullptr),
379 for (
auto *sp : spvec)
385 << std::setw(76) <<
to_string(
"** Spacepoint ", isp,
" **")
388 printMeasurement(tgContext, surface_ptr,
389 localPositionStrip2D(tgContext, *measurement, surface_ptr, sp),
395 const auto loc3D = measurement->
localPosition<3>().cast<double>();
396 const std::tuple<Acts::Vector2, Amg::Vector2D, int, int> locTup = {Acts::Vector2{loc3D.head<2>()},
Amg::Vector2D{loc3D.head<2>()}, -1, -1};
403 const Acts::GeometryContext &tgContext,
404 const Acts::BoundVector &bound)
406 auto p = Acts::transformBoundToFreeParameters(surface, tgContext, bound);
407 std::cout << std::fixed
408 << std::setw(10) << std::setprecision(4) << bound[Acts::eBoundLoc0] <<
' '
409 << std::setw(10) << std::setprecision(4) << bound[Acts::eBoundLoc1] <<
' '
410 << std::setw(9) << std::setprecision(3) << p.segment<2>(Acts::eFreePos0).norm() <<
' '
411 << std::setw(9) << std::setprecision(3) << p[Acts::eFreePos2] <<
' '
412 << std::setw(9) << std::setprecision(3) << std::atan2(p[Acts::eFreePos1], p[Acts::eFreePos0]) / Acts::UnitConstants::degree <<
' '
413 << std::setw(9) << std::setprecision(5) << std::atanh(p[Acts::eFreePos2] / p.segment<3>(Acts::eFreePos0).norm()) <<
' '
414 << std::setw(9) << std::setprecision(3) << p.segment<2>(Acts::eFreeDir0).norm() / p[Acts::eFreeQOverP] <<
' '
415 << std::setw(9) << std::setprecision(3) << std::atan2(p[Acts::eFreeDir1], p[Acts::eFreeDir0]) / Acts::UnitConstants::degree <<
' '
416 << std::setw(9) << std::setprecision(5) << std::atanh(p[Acts::eFreeDir2])
417 << std::defaultfloat << std::setprecision(-1);
434 return StatusCode::SUCCESS;
440 const Acts::BoundTrackParameters &initialParameters,
448 std::ostringstream os;
450 for (
const auto *sp : seed.sp())
453 for (
const auto *el : sp->measurements())
461 os << measurementIndexer.
index(*el);
465 std::cout << std::setw(5) << iseed <<
' '
467 << std::setw(4) << (!isKF ?
"seed" :
"KF") <<
' '
468 << std::setw(21) <<
actsSurfaceName(initialParameters.referenceSurface()) <<
' '
469 << std::setw(22) <<
to_string(os.str()) <<
' '
471 printParameters(initialParameters.referenceSurface(), tgContext, initialParameters.parameters());
478 const std::vector<const xAOD::UncalibratedMeasurementContainer *> &clusterContainers,
479 const std::vector<size_t> &offsets)
const {
488 for (std::size_t icontainer = 0; icontainer < clusterContainers.size(); ++icontainer)
490 for (
const auto *measurement : *clusterContainers[icontainer])
493 measToSp[icontainer], offsets[icontainer]);
496 std::cout << std::flush;
499 std::vector<std::vector<TrackStatePrinterTool::small_vector<const xAOD::SpacePoint *>>>
501 const std::vector<const xAOD::UncalibratedMeasurementContainer *> &clusterContainers,
502 const std::vector<size_t> &offsets)
const
504 std::vector<std::vector<TrackStatePrinterTool::small_vector<const xAOD::SpacePoint *>>> measToSp{clusterContainers.size()};
505 for (std::size_t icontainer = 0; icontainer < clusterContainers.size(); ++icontainer)
507 measToSp[icontainer].resize(clusterContainers[icontainer]->size());
512 ATH_MSG_DEBUG(
"Retrieving from input SpacePoint collection '" << spacePointKey.key() <<
"' ...");
516 ATH_MSG_ERROR(
"Error retrieving from input SpacePoint collection '" << spacePointKey.key() <<
"'");
520 for (
const auto *sp : *handle)
526 for (std::size_t icontainer = 0; icontainer < clusterContainers.size(); ++icontainer)
529 if (!(meas && meas->index() < clusterContainers[icontainer]->size() && meas == clusterContainers[icontainer]->at(meas->index())))
535 << (meas->index() + offsets[icontainer])
536 <<
" used by SpacePoints at ("
537 << sp->globalPosition()[0] <<
',' << sp->globalPosition()[1] <<
',' << sp->globalPosition()[2]
539 << measSp[0]->globalPosition()[0] <<
',' << measSp[0]->globalPosition()[1] <<
',' << measSp[0]->globalPosition()[2]
542 measSp.push_back(sp);
#define ATH_CHECK
Evaluate an expression and check for errors.
std::pair< std::vector< unsigned int >, bool > res
const GeoVDetectorElement * upstreamDetectorElement() const
Returns the underllying GeoModel detectorelement that this one is based on.
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.
size_t index() const
Return the index of this element within its container.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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 globalPosition() const
Returns the global position of the pixel cluster.
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...
std::string to_string(const DetectorType &type)
Eigen::Matrix< double, 2, 1 > Vector2D
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
double e0(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in pre-sampler
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.