35 ATH_MSG_DEBUG(
"Null Acts::TrackingGeometry from tracking geometry service");
36 return StatusCode::FAILURE;
41 ATH_MSG_DEBUG(
"Null detector element to Acts geometry ID map from "
42 "tracking geometry service");
43 return StatusCode::FAILURE;
69 return StatusCode::SUCCESS;
76 auto cell_start = std::chrono::high_resolution_clock::now();
82 traccc::edm::silicon_cell_collection::const_device cells{*cells_handle};
84 std::vector<uint8_t> cells_buffer;
87 auto cell_end = std::chrono::high_resolution_clock::now();
88 std::chrono::duration<double, std::milli> cell_time = cell_end - cell_start;
89 ATH_MSG_INFO(
"Cell reading time: " << cell_time.count() <<
" ms");
91 std::unordered_map<int64_t, int> cluster_map;
98 std::vector<TracccTrackParameters> TracccTrackParams;
99 std::vector<LocalMeasurementInfoInTracks> TracccMeasurementsInfoInTracks;
102 auto traccc_start = std::chrono::high_resolution_clock::now();
104 auto traccc_end = std::chrono::high_resolution_clock::now();
105 std::chrono::duration<double, std::milli> traccc_time = traccc_end - traccc_start;
106 ATH_MSG_INFO(
"Traccc total inference time: " << traccc_time.count() <<
" ms");
109 unsigned int nb_output_tracks = 0;
110 auto convert_start = std::chrono::high_resolution_clock::now();
112 cluster_map, nb_output_tracks));
113 auto convert_end = std::chrono::high_resolution_clock::now();
114 std::chrono::duration<double, std::milli> convert_time = convert_end - convert_start;
115 ATH_MSG_INFO(
"Traccc total conversion time: " << convert_time.count() <<
" ms");
117 return StatusCode::SUCCESS;
121inline void appendBytes(std::vector<uint8_t>& out,
const uint64_t& value)
123 const auto* p =
reinterpret_cast<const uint8_t*
>(&value);
124 out.insert(out.end(), p, p +
sizeof(value));
126inline void appendBytes(std::vector<uint8_t>& out,
const uint32_t& value)
128 const auto* p =
reinterpret_cast<const uint8_t*
>(&value);
129 out.insert(out.end(), p, p +
sizeof(value));
131inline void appendBytes(std::vector<uint8_t>& out,
const float& value)
133 const auto* p =
reinterpret_cast<const uint8_t*
>(&value);
134 out.insert(out.end(), p, p +
sizeof(value));
138 const traccc::edm::silicon_cell_collection::const_device& cells,
139 std::vector<uint8_t>& out)
const
141 const uint64_t nCells = cells.size();
145 out.reserve(
sizeof(uint64_t) + nCells * (3 *
sizeof(uint32_t) + 2 *
sizeof(
float)));
151 for (uint64_t i = 0; i < nCells; ++i) {
152 appendBytes(out,
static_cast<uint32_t
>(cells.channel0()[i]));
154 for (uint64_t i = 0; i < nCells; ++i) {
155 appendBytes(out,
static_cast<uint32_t
>(cells.channel1()[i]));
157 for (uint64_t i = 0; i < nCells; ++i) {
158 appendBytes(out,
static_cast<float>(cells.activation()[i]));
160 for (uint64_t i = 0; i < nCells; ++i) {
161 appendBytes(out,
static_cast<float>(cells.time()[i]));
163 for (uint64_t i = 0; i < nCells; ++i) {
164 appendBytes(out,
static_cast<uint32_t
>(cells.module_index()[i]));
167 ATH_MSG_DEBUG(
"Serialized " << nCells <<
" traccc cells into "
168 << out.size() <<
" bytes");
170 return StatusCode::SUCCESS;
174 const EventContext& eventContext)
const
178 std::unordered_map<int64_t, int> traccc_to_xaod_cluster_map;
182 xAODPixelContainerFromInDetClusters(
184 if ((xAODPixelContainerFromInDetClusters.
record(
185 std::make_unique<xAOD::PixelClusterContainer>(),
186 std::make_unique<xAOD::PixelClusterAuxContainer>()))
189 "Could not record xAOD Pixel container from InDet Clusters");
190 throw std::runtime_error(
191 "creation of xAOD Pixel container from InDet Clusters failed");
195 xAODStripContainerFromInDetClusters(
197 if ((xAODStripContainerFromInDetClusters.
record(
198 std::make_unique<xAOD::StripClusterContainer>(),
199 std::make_unique<xAOD::StripClusterAuxContainer>()))
202 "Could not record xAOD Strip container from InDet Clusters");
203 throw std::runtime_error(
204 "creation of xAOD Strip container from InDet Clusters failed");
212 pixElements ==
nullptr) {
214 std::ostringstream errMsg;
216 throw std::runtime_error(errMsg.str());
223 if (not stripDetEleHandle.
isValid() or stripElements ==
nullptr) {
225 std::ostringstream errMsg;
227 throw std::runtime_error(errMsg.str());
231 xAODSpacepointContainerFromInDetClusters(
233 if (xAODSpacepointContainerFromInDetClusters
234 .record(std::make_unique<xAOD::SpacePointContainer>(),
235 std::make_unique<xAOD::SpacePointAuxContainer>())
237 throw std::runtime_error(
238 "creation of InDet spacepoint containers failed");
243 const InDet::PixelClusterContainer* inputPixelClusterContainer{};
247 inputPixelClusterContainer ==
nullptr) {
249 <<
" is not available.");
250 std::ostringstream errMsg;
252 <<
" is not available.";
253 throw std::runtime_error(errMsg.str());
256 for (
const auto*
const clusterCollection : *inputPixelClusterContainer) {
257 if (!clusterCollection)
259 for (
const auto*
const theCluster : *clusterCollection) {
262 theCluster->detectorElement();
265 auto pixelCl = xAODPixelContainerFromInDetClusters->push_back(
266 std::make_unique<xAOD::PixelCluster>());
269 ATH_MSG_FATAL(
"Could not convert InDet pixel cluster to xAOD");
270 throw std::runtime_error(
271 "conversion of InDet pixel cluster to xAOD failed");
274 auto xaod_sp = xAODSpacepointContainerFromInDetClusters->push_back(
275 std::make_unique<xAOD::SpacePoint>());
282 xaod_sp->setSpacePoint(Pixel_ModuleHash, globalPosition,
283 globalVariance(0, 0), globalVariance(1, 0),
286 size_t index = xAODPixelContainerFromInDetClusters->size() - 1;
294 const InDet::SCT_ClusterContainer* inputStripClusterContainer{};
298 inputStripClusterContainer ==
nullptr) {
300 <<
" is not available.");
301 std::ostringstream errMsg;
303 <<
" is not available.";
304 throw std::runtime_error(errMsg.str());
307 for (
const auto*
const clusterCollection : *inputStripClusterContainer) {
308 if (!clusterCollection)
310 for (
const auto*
const theCluster : *clusterCollection) {
313 theCluster->detectorElement();
317 xAODStripContainerFromInDetClusters->push_back(stripCl);
320 ATH_MSG_FATAL(
"Could not convert InDet strip cluster to xAOD");
321 throw std::runtime_error(
322 "conversion of InDet strip cluster to xAOD failed");
324 size_t index = xAODStripContainerFromInDetClusters->size() - 1;
333 return traccc_to_xaod_cluster_map;
348 localCovariance.setZero();
349 localCovariance(0, 0) = localCov(0, 0);
350 localCovariance(1, 1) = localCov(1, 1);
353 Eigen::Matrix<float, 3, 1> globalPosition(globalPos.x(), globalPos.y(),
356 const auto& RDOs = indetCluster.
rdoList();
357 const auto& ToTs = indetCluster.
totList();
358 const auto& charges = indetCluster.
chargeList();
361 xaodCluster.
setMeasurement<2>(idHash, localPosition, localCovariance);
371 return StatusCode::SUCCESS;
385 localCovariance.setZero();
388 localPosition(0, 0) = localPos.x();
389 localCovariance(0, 0) =
396 if (design ==
nullptr) {
397 return StatusCode::FAILURE;
401 localPosition(0, 0) = localInPolar.
xPhi();
402 localCovariance(0, 0) =
407 Eigen::Matrix<float, 3, 1> globalPosition(globalPos.x(), globalPos.y(),
410 const auto& RDOs = indetCluster.
rdoList();
413 xaodCluster.
setMeasurement<1>(idHash, localPosition, localCovariance);
419 return StatusCode::SUCCESS;
425 const bool isPixel =
m_pixelID->is_pixel(atlasID);
432 measType,
static_cast<unsigned int>(hash));
441 ATH_MSG_DEBUG(
"No Acts surface corresponding to this ATLAS id: " << atlasID);
449 Acts::BoundMatrix cov = Acts::BoundMatrix::Zero();
450 for (
unsigned int i = 0; i < 5; i++) {
451 for (
unsigned int j = 0; j < 5; j++) {
452 size_t index = i * 5 + j;
459 constexpr double kUnconstrainedTimeVariance = 1e6;
460 cov(Acts::eBoundTime, Acts::eBoundTime) = kUnconstrainedTimeVariance;
465std::optional<Acts::BoundTrackParameters>
469 using namespace Acts::UnitLiterals;
470 std::shared_ptr<const Acts::Surface> actsSurface;
471 Acts::BoundVector params{};
480 actsSurface = surface->getSharedPtr();
489 Acts::ParticleHypothesis hypothesis{Acts::ParticleHypothesis::pion()};
491 return Acts::BoundTrackParameters(actsSurface, params, cov, hypothesis);
495 EventContext
const& eventContext,
496 std::vector<TracccTrackParameters>& trackParams,
497 std::vector<LocalMeasurementInfoInTracks>& measInfo,
498 const std::unordered_map<int64_t, int>& cluster_map,
499 unsigned& nb_output_tracks)
const
501 nb_output_tracks = 0;
503 Acts::VectorTrackContainer track_backend;
504 Acts::VectorMultiTrajectory track_state_backend;
506 std::move(track_backend), std::move(track_state_backend));
511 Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(eventContext);
521 float chi2_min = std::numeric_limits<float>::max();
522 float chi2_max = std::numeric_limits<float>::min();
524 float ndf_min = std::numeric_limits<float>::max();
525 float ndf_max = std::numeric_limits<float>::min();
527 unsigned meas_min = std::numeric_limits<unsigned>::max();
528 unsigned meas_max = std::numeric_limits<unsigned>::min();
530 int excluded_ndf = 0;
531 int excluded_no_sp = 0;
532 int excluded_weird_state = 0;
534 for (std::size_t i = 0; i < trackParams.size(); i++) {
535 auto fit_res = trackParams.at(i);
536 auto& states = measInfo.at(i);
537 if (states.local_x.size() < 1) {
545 static_cast<float>(std::numeric_limits<unsigned int>::max()) ||
547 static_cast<float>(std::numeric_limits<unsigned int>::min())) {
553 auto actsTrack = track_container.makeTrack();
558 actsTrack.chi2() = fit_res.chi2;
559 actsTrack.nDoF() = fit_res.ndf;
561 Acts::TrackStatePropMask
const mask =
562 Acts::TrackStatePropMask::Smoothed;
564 bool first_state =
true;
565 for (
size_t j = 0; j < states.local_x.size(); ++j) {
566 auto actsTSOS = actsTrack.appendTrackState(mask);
570 singleState.
local_x = {states.local_x[j]};
571 singleState.
local_y = {states.local_y[j]};
572 singleState.
phi = {states.phi[j]};
573 singleState.
theta = {states.theta[j]};
574 singleState.
qop = {states.qop[j]};
575 singleState.
time = {states.time[j]};
577 for (
size_t k = 0; k < 25; ++k) {
578 singleState.
covariances.push_back(states.covariances[j * 25 + k]);
580 singleState.
athena_id = {states.athena_id[j]};
582 std::optional<Acts::BoundTrackParameters> params_opt =
584 if (!params_opt.has_value()) {
587 "convertToActsParameters failed: track state is weird");
588 track_validity = INVALID_STATE;
593 Acts::BoundTrackParameters
const& parameters = params_opt.value();
594 ATH_MSG_DEBUG(
"Track parameters: " << parameters.parameters());
601 pixelClustersHandle.
cptr();
607 stripClustersHandle.
cptr();
611 if (
auto it = cluster_map.find(states.athena_id[j]);
612 it != cluster_map.end()) {
613 cl_index = it->second;
615 return StatusCode::FAILURE;
619 Identifier id(
static_cast<Identifier::value_type
>(states.athena_id[j]));
624 umeas = inputPixelClusters->
at(cl_index);
626 umeas = inputStripClusters->
at(cl_index);
629 actsTSOS.setUncalibratedSourceLink(
644 std::optional<Acts::BoundTrackParameters> params_gl =
647 if (!params_gl.has_value()) {
650 "convertToActsParameters failed: track state is weird");
651 track_validity = INVALID_GLOBAL;
655 Acts::BoundTrackParameters
const& parameters_gl =
659 actsTrack.parameters() = parameters_gl.parameters();
660 actsTrack.covariance() = *parameters_gl.covariance();
661 actsTrack.setReferenceSurface(
662 parameters_gl.referenceSurface().getSharedPtr());
667 actsTSOS.setReferenceSurface(
668 parameters.referenceSurface().getSharedPtr());
669 actsTSOS.smoothed() = parameters.parameters();
670 actsTSOS.smoothedCovariance() = *parameters.covariance();
672 actsTSOS.typeFlags().setIsMeasurement();
673 if (!(actsTSOS.hasSmoothed() &&
674 actsTSOS.hasReferenceSurface())) {
676 "TrackState does not have smoothed state ["
677 << actsTSOS.hasSmoothed()
678 <<
"] or reference surface ["
679 << actsTSOS.hasReferenceSurface() <<
"].");
682 "TrackState has smoothed state and reference "
688 if (track_validity == INVALID_STATE) {
689 ATH_MSG_INFO(
"excluding track " << i <<
" for weird state");
690 excluded_weird_state += 1;
691 track_container.removeTrack(actsTrack.index());
692 }
else if (track_validity == INVALID_GLOBAL) {
694 <<
" for weird global params");
695 track_container.removeTrack(actsTrack.index());
700 chi2_min = std::min(fit_res.chi2, chi2_min);
701 chi2_max = std::max(fit_res.chi2, chi2_max);
702 ndf_min = std::min(fit_res.ndf, ndf_min);
703 ndf_max = std::max(fit_res.ndf, ndf_max);
704 meas_min = std::min<unsigned>(states.local_x.size(), meas_min);
705 meas_max = std::max<unsigned>(states.local_x.size(), meas_max);
708 nb_output_tracks = track_container.size();
709 ATH_MSG_DEBUG(
"Wrote out "<< nb_output_tracks <<
" tracks from " << trackParams.size() <<
" candidates"
711 <<
" no sp: " << excluded_no_sp
712 <<
", weird sp: " << excluded_weird_state
713 <<
", ndf: " << excluded_ndf
716 Acts::ConstVectorTrackContainer ctrack_backend(
717 std::move(track_container.container()));
718 Acts::ConstVectorMultiTrajectory ctrack_state_backend(
719 std::move(track_container.trackStateContainer()));
720 std::unique_ptr<ActsTrk::TrackContainer> ctrack_container =
721 std::make_unique<ActsTrk::TrackContainer>(
722 std::move(ctrack_backend), std::move(ctrack_state_backend));
726 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
static constexpr double one_over_twelve
void appendBytes(std::vector< uint8_t > &out, const uint64_t &value)
static Acts::SourceLink pack(const Ptr_t &measurement)
Pack the measurement type pointer to an Acts::SourceLink including the intermediate conversion into a...
const ServiceHandle< StoreGateSvc > & detStore() const
const T * at(size_type n) const
Access an element, as an rvalue.
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
Identifier for the strip or pixel cell.
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
double phiPitch() const
Pitch (inline methods).
Class to represent a position in the natural frame of a silicon sensor, for Pixel and SCT For Pixel: ...
double xPhi() const
position along phi direction:
SiCellId cellIdOfPosition(const Amg::Vector2D &localPos) const
As in previous method but returns SiCellId.
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
virtual Identifier identify() const override final
identifier of this detector element (inline)
double phiPitchPhi(const SiLocalPosition &localPosition) const
SiLocalPosition localPositionOfCellPC(const SiCellId &cellId) const
This is for debugging only.
const std::vector< int > & totList() const
const std::vector< float > & chargeList() const
const Amg::Vector3D & globalPosition() const
return global position reference
const InDet::SiWidth & width() const
return width class reference
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::ReadHandleKey< InDet::SCT_ClusterContainer > m_inputStripClusterContainerKey
const Acts::Surface * actsSurfaceFromAtlasId(const Identifier &atlasID) const
StatusCode serializeCells(const traccc::edm::silicon_cell_collection::const_device &cells, std::vector< uint8_t > &out) const
Acts::BoundMatrix buildBoundCovariance(const LocalMeasurementInfoInTracks &state) const
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
std::shared_ptr< const Acts::TrackingGeometry > m_trackingGeometry
StatusCode convertInDetToXaodCluster(const InDet::PixelCluster &indetCluster, const InDetDD::SiDetectorElement &element, xAOD::PixelCluster &xaodCluster) const
StringProperty m_featureNames
ActsTrk::MutableTrackContainerHandlesHelper m_tracksBackendHandlesHelper
std::unordered_map< int64_t, int > readAndConvertClusters(const EventContext &eventContext) const
StatusCode convertTracks(EventContext const &eventContext, std::vector< TracccTrackParameters > &trackParams, std::vector< LocalMeasurementInfoInTracks > &measInfo, const std::unordered_map< int64_t, int > &cluster_map, unsigned &nb_output_tracks) const
SG::WriteHandleKey< xAOD::SpacePointContainer > m_xAODSpacepointFromInDetClusterKey
SG::WriteHandleKey< ActsTrk::TrackContainer > m_ActsTracccTrackContainerKey
SG::ReadHandleKey< InDet::PixelClusterContainer > m_inputPixelClusterContainerKey
ActsTrk::ContextUtility m_ctxProvider
Utility to fetch the geometry, magnetic field and calibration context in the event.
SG::ReadHandleKey< ActsTrk::MeasurementToTruthParticleAssociation > m_stripClustersToTruth
const ActsTrk::DetectorElementToActsGeometryIdMap * m_detEleToGeoIdMap
virtual StatusCode execute(const EventContext &ctx) const override
const PixelID * m_pixelID
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_xAODPixelClusterFromInDetClusterKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_stripDetEleCollKey
std::optional< Acts::BoundTrackParameters > convertToActsParameters(const LocalMeasurementInfoInTracks &state) const
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Gaudi::Property< bool > m_doTruth
Truth association for plotting and debugging.
SG::ReadHandleKey< traccc::edm::silicon_cell_collection::const_view > m_tracccCellsKey
virtual StatusCode initialize() override
std::vector< std::string > m_featureNamesVec
SG::ReadHandleKey< ActsTrk::MeasurementToTruthParticleAssociation > m_pixelClustersToTruth
SG::WriteHandleKey< xAOD::StripClusterContainer > m_xAODStripClusterFromInDetClusterKey
ToolHandle< ITracccTritonTool > m_tracccTrackingTool
const Amg::Vector2D & localPosition() const
return the local position reference
Identifier identify() const
return the identifier
const Amg::MatrixX & localCovariance() const
return const ref to the error matrix
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
void setChannelsInPhiEta(int channelsInPhi, int channelsInEta)
Sets the dimensions of the cluster in numbers of channels in phi (x) and eta (y) directions.
ConstVectorMap< 3 > globalPosition() const
Returns the global position of the pixel cluster.
void setChargelist(const std::vector< float > &charges)
Sets the list of charges of the channels building the cluster.
void setToTlist(const std::vector< int > &tots)
Sets the list of ToT of the channels building the cluster.
void setLVL1A(int lvl1a)
Sets the LVL1 accept.
void setRDOlist(const std::vector< Identifier > &rdolist)
Sets the list of identifiers of the channels building the cluster.
void setWidthInEta(float widthInEta)
Sets the width of the cluster in eta (y) direction.
ConstVectorMap< 3 > globalPosition() const
Returns the global position of the strip cluster.
void setRDOlist(const std::vector< Identifier > &rdolist)
Sets the list of identifiers of the channels building the cluster.
void setChannelsInPhi(int channelsInPhi)
Sets the dimensions of the cluster in numbers of channels in phi (x).
void setMeasurement(const DetectorIDHashType idHash, MeasVector< N > locPos, MeasMatrix< N > locCov)
Sets IdentifierHash, local position and local covariance of the measurement.
void setIdentifier(const DetectorIdentType measId)
Sets the full Identifier of the measurement.
std::string prefixFromTrackContainerName(const std::string &tracks)
Parse TrackContainer name to get the prefix for backends The name has to contain XYZTracks,...
Acts::TrackContainer< MutableTrackBackend, MutableTrackStateBackend, Acts::detail::ValueHolder > MutableTrackContainer
DetectorElementKey makeDetectorElementKey(xAOD::UncalibMeasType meas_type, unsigned int identifier_hash)
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
PixelClusterContainer_v1 PixelClusterContainer
Define the version of the pixel cluster container.
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
Eigen::Matrix< float, N, N > MeasMatrix
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
StripClusterContainer_v1 StripClusterContainer
Define the version of the strip cluster container.
MeasVector< N > toStorage(const AmgVector(N)&amgVec)
Converts the double precision of the AmgVector into the floating point storage precision of the MeasV...
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
static const Acts::GeometryIdentifier & getValue(const value_type &element)
std::vector< int64_t > athena_id
std::vector< float > covariances
std::vector< float > time
std::vector< float > local_x
std::vector< float > theta
std::vector< float > local_y