ATLAS Offline Software
TrackTimeExtensionAlg.cxx
Go to the documentation of this file.
1 
11 #include "TrackTimeExtensionAlg.h"
12 
16 
17 namespace {
18 static constexpr unsigned short n_hgtd_layers = 4;
19 }
20 
21 namespace HGTD {
22 
24  ISvcLocator* pSvcLocator)
25  : AthReentrantAlgorithm(name, pSvcLocator) {}
26 
28 
29  ATH_CHECK(m_extension_tool.retrieve());
30 
31  ATH_CHECK(m_truth_tool.retrieve());
32 
33  ATH_CHECK(m_clustercont_rh_key.initialize());
47 
48 
49  return StatusCode::SUCCESS;
50 }
51 
54 StatusCode TrackTimeExtensionAlg::execute(const EventContext& ctx) const {
55 
56  ATH_MSG_DEBUG("Start event");
57 
58  SG::ReadHandle<HGTD_ClusterContainer> cluster_container_handle(
60  const HGTD_ClusterContainer* cluster_container =
61  cluster_container_handle.cptr();
62  if (not cluster_container) {
63  ATH_MSG_ERROR("[TrackTimeExtensionAlg] HGTD_ClusterContainer not found, "
64  "aborting execute!");
65  return StatusCode::FAILURE;
66  }
67 
68  SG::ReadHandle<InDetSimDataCollection> sdo_collection_handle(
69  m_sdo_coll_rh_key, ctx);
70  const InDetSimDataCollection* sdo_collection = sdo_collection_handle.cptr();
71  if (not sdo_collection) {
72  ATH_MSG_WARNING("[TrackTimeExtensionAlg] SDO Collection not found, no "
73  "truth info available!");
74  }
75 
76  SG::ReadHandle<McEventCollection> mc_collection_handle(m_mc_coll_rh_key, ctx);
77  const McEventCollection* mc_coll = mc_collection_handle.cptr();
78  if (not mc_coll) {
79  ATH_MSG_ERROR("[TrackTimeExtensionAlg] McEventCollection not found, "
80  "aborting execute!");
81  return StatusCode::FAILURE;
82  }
83 
84  const HepMC::GenEvent* hs_event = nullptr;
85  if (mc_coll->size() > 0) {
86  hs_event = mc_coll->at(0);
87  } else {
88  hs_event = nullptr;
89  }
90 
91  // for each track, run the extension if the track is in HGTD acceptance
92  SG::ReadHandle<xAOD::TrackParticleContainer> trk_ptkl_container_handle(
93  m_trk_ptkl_rh_key, ctx);
94  const xAOD::TrackParticleContainer* track_particles =
95  trk_ptkl_container_handle.cptr();
96  if (not track_particles) {
97  ATH_MSG_ERROR("[TrackTimeExtensionAlg] TrackParticleContainer not found, "
98  "aborting execute!");
99  return StatusCode::FAILURE;
100  }
101 
102  DecorHandles dh (*this, ctx);
103 
104  for (const auto* track_ptkl : *track_particles) {
105 
106  ATH_MSG_DEBUG("Track eta: " << track_ptkl->eta()
107  << " pt: " << track_ptkl->pt());
108 
109  HGTD::ExtensionObject extension;
110 
111  if (std::abs(track_ptkl->eta()) < m_eta_cut) {
112  ATH_MSG_DEBUG("Track out of acceptance");
113  // decorate all track particle objects to avoid issues with the
114  // decorations
115  ATH_CHECK(decorateTrackParticle(dh, track_ptkl, extension, sdo_collection,
116  hs_event, true));
117  continue;
118  }
119 
120  // this should not happen?
121  if (track_ptkl->track() == nullptr) {
122  ATH_MSG_DEBUG("There is no Trk::Track");
123  ATH_CHECK(decorateTrackParticle(dh, track_ptkl, extension, sdo_collection,
124  hs_event, true));
125  continue;
126  }
127 
128  // return 4 track states on surface objects as a result of the extension
129  extension = m_extension_tool->extendTrackToHGTD(ctx,
130  *track_ptkl,
131  cluster_container,
132  hs_event,
133  sdo_collection);
134 
135  // TODO here:
136  // retrieve truth info for associated and non-associated HGTD hits, merging
137  // or shadowing info
138 
139  // decorate the track
140  ATH_CHECK(decorateTrackParticle(dh, track_ptkl, extension, sdo_collection,
141  hs_event, false));
142 
143  } // END LOOP over tracks
144 
145  return StatusCode::SUCCESS;
146 }
147 
150 
152  (const TrackTimeExtensionAlg& tool, const EventContext& ctx)
153  : layerHasExtensionHandle (tool.m_layerHasExtensionKey, ctx),
154  layerExtensionChi2Handle (tool.m_layerExtensionChi2Key, ctx),
155  layerClusterRawTimeHandle (tool.m_layerClusterRawTimeKey, ctx),
156  layerClusterTimeHandle (tool.m_layerClusterTimeKey, ctx),
157  layerClusterTruthClassHandle (tool.m_layerClusterTruthClassKey, ctx),
158  layerClusterShadowedHandle (tool.m_layerClusterShadowedKey, ctx),
159  layerClusterMergedHandle (tool.m_layerClusterMergedKey, ctx),
160  layerPrimaryExpectedHandle (tool.m_layerPrimaryExpectedKey, ctx),
161  extrapXHandle (tool.m_extrapXKey, ctx),
162  extrapYHandle (tool.m_extrapYKey, ctx)
163 {
164 }
165 
167  DecorHandles& dh,
168  const xAOD::TrackParticle* track_ptkl, const HGTD::ExtensionObject& extension,
169  const InDetSimDataCollection* sdo_collection,
170  const HepMC::GenEvent* hs_event, bool skip_deco) const {
171 
172  std::vector<bool> has_cluster_vec;
173  has_cluster_vec.reserve(n_hgtd_layers);
174  std::vector<float> chi2_vec;
175  chi2_vec.reserve(n_hgtd_layers);
176  std::vector<float> raw_time_vec;
177  raw_time_vec.reserve(n_hgtd_layers);
178  std::vector<float> time_vec;
179  time_vec.reserve(n_hgtd_layers);
180  std::vector<int> truth_vec;
181  truth_vec.reserve(n_hgtd_layers);
182  std::vector<bool> is_shadowed_vec;
183  is_shadowed_vec.reserve(n_hgtd_layers);
184  std::vector<bool> is_merged_vec;
185  is_merged_vec.reserve(n_hgtd_layers);
186  std::vector<bool> primary_exists_vec;
187  primary_exists_vec.reserve(n_hgtd_layers);
188 
189  for (unsigned short i = 0; i < n_hgtd_layers; i++) {
190 
191  const std::unique_ptr<const Trk::TrackStateOnSurface>& trk_state =
192  extension.m_hits.at(i);
193  const HGTD_Cluster* primary_cluster = extension.m_truth_primary_hits.at(i);
194 
195  primary_exists_vec.push_back(primary_cluster != nullptr);
196 
197  if (trk_state) {
198  ATH_MSG_DEBUG("[decorateTrackParticle] extension found");
199  has_cluster_vec.emplace_back(true);
200 
201  chi2_vec.emplace_back(
202  trk_state->fitQualityOnSurface().chiSquared() /
203  trk_state->fitQualityOnSurface().doubleNumberDoF());
204 
205  const HGTD_ClusterOnTrack* cot =
206  dynamic_cast<const HGTD_ClusterOnTrack*>(trk_state->measurementOnTrack());
207 
208  time_vec.emplace_back(cot->time());
209 
210  // get the cluster
211  const HGTD_Cluster* cluster = cot->prepRawData();
212 
213  raw_time_vec.emplace_back(cluster->time());
214 
215  // get the truth particle
217  acc_tpl("truthParticleLink");
218  const xAOD::TruthParticle* truth_particle = nullptr;
219  if (acc_tpl.isAvailable(*track_ptkl)) {
220  const auto& truth_match_link = acc_tpl(*track_ptkl);
221  if (truth_match_link.isValid()) {
222  truth_particle = *truth_match_link;
223  }
224  }
225 
227  bool is_shadowed = false;
228  bool is_merged = false;
229 
230  if (truth_particle) {
231  auto truth_info = m_truth_tool->classifyCluster(
232  cluster, truth_particle, sdo_collection, hs_event);
233  truth_origin = truth_info.origin;
234  is_shadowed = truth_info.is_shadowed;
235  is_merged = truth_info.is_merged;
236  }
237 
238  ATH_MSG_DEBUG("Truth origin: " << (int)truth_origin);
239 
240  truth_vec.emplace_back((int)truth_origin);
241  is_shadowed_vec.emplace_back(is_shadowed);
242  is_merged_vec.emplace_back(is_merged);
243  } else {
244  ATH_MSG_DEBUG("[decorateTrackParticle] NO extension found");
245  has_cluster_vec.emplace_back(false);
246  if (not skip_deco) {
247  chi2_vec.emplace_back(-1.);
248  raw_time_vec.emplace_back(-1.);
249  time_vec.emplace_back(-1.);
250  truth_vec.emplace_back(-1);
251  is_shadowed_vec.emplace_back(false);
252  is_merged_vec.emplace_back(false);
253  }
254  }
255 
256  } // END LOOP over TrackStateOnSurface
257 
258  dh.layerHasExtensionHandle(*track_ptkl) = has_cluster_vec;
259  dh.layerExtensionChi2Handle(*track_ptkl) = chi2_vec;
260  dh.layerClusterRawTimeHandle(*track_ptkl) = raw_time_vec;
261  dh.layerClusterTimeHandle(*track_ptkl) = time_vec;
262  dh.layerClusterTruthClassHandle(*track_ptkl) = truth_vec;
263  dh.layerClusterShadowedHandle(*track_ptkl) = is_shadowed_vec;
264  dh.layerClusterMergedHandle(*track_ptkl) = is_merged_vec;
265  dh.layerPrimaryExpectedHandle(*track_ptkl) = primary_exists_vec;
266  dh.extrapXHandle(*track_ptkl) = extension.m_extrap_x;
267  dh.extrapYHandle(*track_ptkl) = extension.m_extrap_y;
268 
269  return StatusCode::SUCCESS;
270 }
271 
272 } // namespace HGTD
HGTD::TrackTimeExtensionAlg::decorateTrackParticle
StatusCode decorateTrackParticle(DecorHandles &dh, const xAOD::TrackParticle *track_ptkl, const HGTD::ExtensionObject &extension, const InDetSimDataCollection *sdo_collection, const HepMC::GenEvent *hs_event, bool skip_deco=false) const
Definition: TrackTimeExtensionAlg.cxx:166
HGTD::ExtensionObject
Definition: IHGTD_TrackTimeExtensionTool.h:32
HGTD::TrackTimeExtensionAlg::m_layerClusterShadowedKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_layerClusterShadowedKey
Definition: TrackTimeExtensionAlg.h:91
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
HGTD::ClusterTruthOrigin
ClusterTruthOrigin
Definition: IHGTD_ClusterTruthTool.h:27
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
HGTD::TrackTimeExtensionAlg::m_extrapXKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_extrapXKey
Definition: TrackTimeExtensionAlg.h:94
TruthParticleContainer.h
Trk::TrackStateOnSurface::measurementOnTrack
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
HGTD_ClusterOnTrack::time
virtual float time() const
Definition: HGTD_ClusterOnTrack.h:161
InDetSimDataCollection
Definition: InDetSimDataCollection.h:25
HGTD::ExtensionObject::m_truth_primary_hits
std::array< const HGTD_Cluster *, 4 > m_truth_primary_hits
Definition: IHGTD_TrackTimeExtensionTool.h:37
HGTD::TrackTimeExtensionAlg::TrackTimeExtensionAlg
TrackTimeExtensionAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackTimeExtensionAlg.cxx:23
Trk::FitQualityOnSurface::doubleNumberDoF
double doubleNumberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as double
Definition: FitQuality.h:68
HGTD::TrackTimeExtensionAlg::m_layerClusterRawTimeKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_layerClusterRawTimeKey
Definition: TrackTimeExtensionAlg.h:88
PyPoolBrowser.dh
dh
Definition: PyPoolBrowser.py:102
Trk::TrackStateOnSurface::fitQualityOnSurface
const FitQualityOnSurface & fitQualityOnSurface() const
return FitQuality On Surface const overload
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
HGTD_Cluster
Definition: HGTD_Cluster.h:35
HGTD::TrackTimeExtensionAlg::m_trk_ptkl_rh_key
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trk_ptkl_rh_key
Definition: TrackTimeExtensionAlg.h:78
HGTD::TrackTimeExtensionAlg
Definition: TrackTimeExtensionAlg.h:41
HGTD::TrackTimeExtensionAlg::m_extrapYKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_extrapYKey
Definition: TrackTimeExtensionAlg.h:95
HGTD::TrackTimeExtensionAlg::m_extension_tool
ToolHandle< IHGTD_TrackTimeExtensionTool > m_extension_tool
Definition: TrackTimeExtensionAlg.h:73
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HGTD
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
Definition: Clustering.h:28
HGTD::TrackTimeExtensionAlg::m_sdo_coll_rh_key
SG::ReadHandleKey< InDetSimDataCollection > m_sdo_coll_rh_key
Definition: TrackTimeExtensionAlg.h:76
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HGTD::TrackTimeExtensionAlg::m_mc_coll_rh_key
SG::ReadHandleKey< McEventCollection > m_mc_coll_rh_key
Definition: TrackTimeExtensionAlg.h:77
HGTD::TrackTimeExtensionAlg::m_layerClusterTimeKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_layerClusterTimeKey
Definition: TrackTimeExtensionAlg.h:89
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
HGTD::ClusterTruthOrigin::UNIDENTIFIED
@ UNIDENTIFIED
TrackTimeExtensionAlg.h
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
DataVector< xAOD::TrackParticle_v1 >
HGTD::TrackTimeExtensionAlg::m_layerClusterTruthClassKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_layerClusterTruthClassKey
Definition: TrackTimeExtensionAlg.h:90
HGTD::ExtensionObject::m_extrap_x
float m_extrap_x
Definition: IHGTD_TrackTimeExtensionTool.h:40
HGTD::TrackTimeExtensionAlg::m_eta_cut
FloatProperty m_eta_cut
Definition: TrackTimeExtensionAlg.h:82
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
HGTD_ClusterOnTrack
Definition: HGTD_ClusterOnTrack.h:27
HGTD::TrackTimeExtensionAlg::initialize
virtual StatusCode initialize() override final
Definition: TrackTimeExtensionAlg.cxx:27
HGTD::ExtensionObject::m_hits
std::array< std::unique_ptr< const Trk::TrackStateOnSurface >, 4 > m_hits
Definition: IHGTD_TrackTimeExtensionTool.h:34
HGTD::TrackTimeExtensionAlg::DecorHandles
Definition: TrackTimeExtensionAlg.h:51
HGTD::TrackTimeExtensionAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: TrackTimeExtensionAlg.cxx:54
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::PrepRawDataContainer
Definition: PrepRawDataContainer.h:26
HGTD::TrackTimeExtensionAlg::m_clustercont_rh_key
SG::ReadHandleKey< HGTD_ClusterContainer > m_clustercont_rh_key
Definition: TrackTimeExtensionAlg.h:75
HGTD::TrackTimeExtensionAlg::m_layerPrimaryExpectedKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_layerPrimaryExpectedKey
Definition: TrackTimeExtensionAlg.h:93
HGTD::TrackTimeExtensionAlg::m_truth_tool
ToolHandle< IHGTD_ClusterTruthTool > m_truth_tool
Definition: TrackTimeExtensionAlg.h:84
HGTD_ClusterOnTrack::prepRawData
virtual const HGTD_Cluster * prepRawData() const override final
returns the PrepRawData - is a SiCluster in this scope
Definition: HGTD_ClusterOnTrack.h:149
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
HGTD::TrackTimeExtensionAlg::m_layerHasExtensionKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_layerHasExtensionKey
Definition: TrackTimeExtensionAlg.h:86
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
HGTD::ExtensionObject::m_extrap_y
float m_extrap_y
Definition: IHGTD_TrackTimeExtensionTool.h:41
HGTD::TrackTimeExtensionAlg::m_layerExtensionChi2Key
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_layerExtensionChi2Key
Definition: TrackTimeExtensionAlg.h:87
HGTD_Cluster::time
virtual float time() const
Definition: HGTD_Cluster.h:115
Trk::FitQualityOnSurface::chiSquared
double chiSquared() const
returns the of the overall track fit
Definition: FitQuality.h:56
HGTD_ClusterOnTrack.h
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
HGTD::TrackTimeExtensionAlg::m_layerClusterMergedKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_layerClusterMergedKey
Definition: TrackTimeExtensionAlg.h:92
HGTD::TrackTimeExtensionAlg::DecorHandles::DecorHandles
DecorHandles(const TrackTimeExtensionAlg &tool, const EventContext &ctx)
Definition: TrackTimeExtensionAlg.cxx:152