19#include "Acts/Utilities/TrackHelpers.hpp"
27 ISvcLocator* pSvcLocator)
41 return StatusCode::SUCCESS;
53 trk_ptkl_container_handle.
cptr();
54 if (not track_particles) {
56 "[TrackTimeDefAndQualityAlg] TrackParticleContainer not found, "
58 return StatusCode::FAILURE;
72 ATH_CHECK(layerClusterTimeHandle.isValid());
76 ATH_CHECK(layerHasExtensionHandle.isValid());
80 ATH_CHECK(layerClusterTruthClassHandle.isValid());
83 for (
const auto* track_ptkl : *track_particles) {
86 const std::vector<float>& times = layerClusterTimeHandle(*track_ptkl);
87 const std::vector<bool>& has_clusters = layerHasExtensionHandle(*track_ptkl);
88 const std::vector<int>& hit_classification = layerClusterTruthClassHandle(*track_ptkl);
102 short prime_pattern = 0x0;
103 for (
short i = 0; i < s_hgtd_layers; i++) {
104 if (
res.m_hits.at(i).m_isprime) {
105 prime_pattern |= (1 << i);
111 time_handle(*track_ptkl) =
res.m_time;
112 timeres_handle(*track_ptkl) =
res.m_resolution;
113 hasValidTime_handle(*track_ptkl) =
res.m_hasValidTime;
114 summary_handle(*track_ptkl) =
res.m_field;
116 return StatusCode::SUCCESS;
124 const std::vector<bool>& has_clusters,
125 const std::vector<int>& hit_classification)
const {
127 std::array<Hit, s_hgtd_layers> valid_hits =
getValidHits(times,
132 result.m_hits = valid_hits;
136 result.m_hasValidTime = 0;
142 short nhits = std::count_if(valid_hits.begin(), valid_hits.end(),
143 [](
const Hit& hit) { return hit.m_isvalid; });
149 result.m_hasValidTime = recoed_pattern ? 1 : 0;
151 }
else if (nhits == 2) {
159 result.m_hasValidTime = 1;
177 nhits = std::count_if(valid_hits.begin(), valid_hits.end(),
178 [](
const Hit& hit) { return hit.m_isvalid; });
191 result.m_hasValidTime = 1;
204 result.m_hasValidTime = 1;
210std::array<TrackTimeDefAndQualityAlg::Hit, s_hgtd_layers>
212 const std::vector<bool>& has_clusters,
213 const std::vector<int>& hit_classification)
const {
214 std::array<Hit, s_hgtd_layers> valid_hits {};
216 for (
size_t i = 0; i < s_hgtd_layers; i++) {
217 Hit& newhit = valid_hits[i];
218 if (has_clusters.at(i)) {
219 newhit.
m_time = times.at(i);
220 newhit.
m_isprime = hit_classification.at(i) == 1;
230 const std::array<TrackTimeDefAndQualityAlg::Hit, s_hgtd_layers>& hits)
233 for (
short i = 0; i < s_hgtd_layers; i++) {
234 if (hits.at(i).m_isvalid) {
242 const std::array<Hit, s_hgtd_layers>& hits)
const {
247 for (
const auto& hit : hits) {
250 (hit.m_resolution * hit.m_resolution);
257 const std::array<TrackTimeDefAndQualityAlg::Hit, s_hgtd_layers>& hits)
260 short n_valid = std::count_if(hits.begin(), hits.end(),
261 [](
const Hit& hit) { return hit.m_isvalid; });
266 std::vector<float> times;
267 std::vector<float>
res;
268 for (
const auto& hit : hits) {
270 times.push_back(hit.
m_time);
275 return std::abs(times.at(0) - times.at(1)) <
280 const std::array<TrackTimeDefAndQualityAlg::Hit, s_hgtd_layers>& hits)
284 for (
const auto& hit : hits) {
294 const std::array<TrackTimeDefAndQualityAlg::Hit, s_hgtd_layers>& hits)
298 for (
const auto& hit : hits) {
300 sum += 1. / (hit.m_resolution * hit.m_resolution);
304 :
static_cast<float>(std::sqrt(1. / sum));
308 std::array<TrackTimeDefAndQualityAlg::Hit, s_hgtd_layers> hits)
const {
309 short remove_layer = -1;
310 float local_min_chi2 = 999999;
311 for (
auto& hit : hits) {
313 bool validbuff = hit.m_isvalid;
314 hit.m_isvalid =
false;
316 hit.m_isvalid = validbuff;
317 if (local_chi2 < local_min_chi2) {
318 local_min_chi2 = local_chi2;
319 remove_layer = hit.m_layer;
326 std::array<TrackTimeDefAndQualityAlg::Hit, s_hgtd_layers>& hits,
328 for (
auto& hit : hits) {
329 if (hit.m_layer == layer) {
330 hit.m_isvalid =
false;
339 track.trackStateOnSurfaces();
346 for (
auto i = tsos->
rbegin(); i != tsos->
rend(); ++i) {
347 const auto* curr_last_tsos = *i;
348 if (not curr_last_tsos) {
353 curr_last_tsos->trackParameters() and
354 curr_last_tsos->measurementOnTrack()) {
355 return curr_last_tsos->trackParameters();
369 if (not track)
throw std::runtime_error(
"Cannot retrieve Trk track from Track Particle");
371 if (not last_hit_param)
throw std::runtime_error(
"Cannot retrieve Trk track parameters from Trk track");
373 radius = std::hypot(last_hit_param->
position().x(),
375 abs_z = std::abs(last_hit_param->
position().z());
379 if (not actsTrackLink.
isAvailable(track_particle))
throw std::runtime_error(
"Track particle does not have link to acts track");
382 if (not link_to_track.
isValid())
throw std::runtime_error(
"Element link to acts track is not valid");
384 std::optional<ActsTrk::TrackContainer::ConstTrackProxy> optional_track = *link_to_track;
385 if (not optional_track.has_value())
throw std::runtime_error(
"Link to acts track has no value");
387 const ActsTrk::TrackContainer::ConstTrackProxy& track = optional_track.value();
388 const auto lastMeasurementState = Acts::findLastMeasurementState(track);
389 const auto state = lastMeasurementState.value();
392 assert( sl !=
nullptr);
396 switch (clusterType) {
400 radius = std::sqrt( glob(0, 0) * glob(0, 0) + glob(1, 0) * glob(1, 0) );
401 abs_z = std::abs( glob(2, 0) );
407 radius = std::sqrt( glob(0, 0) * glob(0, 0) + glob(1, 0) * glob(1, 0) );
408 abs_z = std::abs( glob(2, 0) );
413 return std::make_pair(700, 3000);
415 return std::make_pair(radius, abs_z);
419 return std::make_pair(radius, abs_z);
429 if (radius < 350 and abs_z > 2400) {
433 if (radius > 205 and radius < 350 and abs_z > 2100) {
437 if (radius < 220 and abs_z > 2200) {
441 if (radius < 140 and abs_z > 1890) {
#define ATH_CHECK
Evaluate an expression and check for errors.
std::pair< std::vector< unsigned int >, bool > res
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
const_reverse_iterator rend() const noexcept
Return a const_reverse_iterator pointing at the beginning of the collection.
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
ElementLink implementation for ROOT usage.
bool isValid() const
Test to see if the link can be dereferenced.
const short m_primes_ptrn_sft
Gaudi::Property< bool > m_doActs
float calculateChi2(const std::array< Hit, s_hgtd_layers > &hits) const
Calculates the chi2 of the hit times given their resolution.
const short m_holes_ptrn_sft
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_time_dec_key
FloatProperty m_chi2_threshold
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_layerClusterTruthClassKey
std::array< Hit, s_hgtd_layers > getValidHits(const std::vector< float > ×, const std::vector< bool > &has_clusters, const std::vector< int > &hit_classification) const
CleaningResult runTimeConsistencyCuts(const std::vector< float > ×, const std::vector< bool > &has_clusters, const std::vector< int > &hit_classification) const
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_time_res_dec_key
FloatProperty m_deltat_cut
std::pair< float, float > getRadiusAndZ(const xAOD::TrackParticle &track_particle) const
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticleContainerKey
float meanTime(const std::array< Hit, s_hgtd_layers > &hits) const
Calculates the arithmetic mean of the valid hit times;.
const short m_recoed_ptrn_sft
void setLayerAsInvalid(std::array< Hit, s_hgtd_layers > &hits, short layer) const
Given a layer number, the hit sitting on this layer is flagged as invalid.
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_hasValidTime_dec_key
float trackTimeResolution(const std::array< Hit, s_hgtd_layers > &hits) const
Calculates the combined resolution.
const short m_comp_ptrn_sft
short findLayerWithBadChi2(std::array< Hit, s_hgtd_layers > hits) const
Identifies time outliers by finding the layer within which a hit contributes negatively to the overal...
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_layerClusterTimeKey
bool lastHitIsOnLastSurface(const xAOD::TrackParticle &track_particle) const
Checks if the last hit on track was found on a pre-specified set of Pixel and Strip layers close to t...
bool passesDeltaT(const std::array< Hit, s_hgtd_layers > &hits) const
Checks two hits for time compatibility.
FloatProperty m_default_time_res
virtual StatusCode execute(const EventContext &ctx) const override final
short getValidPattern(const std::array< Hit, s_hgtd_layers > &hits) const
Returns the pattern of valid hits in HGTD as a 4-bit bitfield, where a 1 encodes that a valid hit was...
TrackTimeDefAndQualityAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_summarypattern_dec_key
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_layerHasExtensionKey
const Trk::TrackParameters * getLastHitOnTrack(const Trk::Track &track) const
FloatProperty m_default_time
virtual StatusCode initialize() override final
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Handle class for adding a decoration to an object.
const Amg::Vector3D & position() const
Access method for the position.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
double chi2(TH1 *h0, TH1 *h1)
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
DataVector< const Trk::TrackStateOnSurface > TrackStates
ParametersBase< TrackParametersDim, Charged > TrackParameters
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
UncalibMeasType
Define the type of the uncalibrated measurement.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.