ATLAS Offline Software
TrackAnalysisAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
7 
8 #include "TrackAnalysisAlg.h"
9 
10 template <>
11 struct Monitored::detail::get_value_type<ActsTrk::TrackContainer> { typedef typename ActsTrk::TrackContainer::TrackProxy value_type; };
12 
13 
14 namespace ActsTrk {
15 
16  TrackAnalysisAlg::TrackAnalysisAlg(const std::string& name, ISvcLocator* pSvcLocator)
17  : AthMonitorAlgorithm(name, pSvcLocator)
18  {}
19 
21  ATH_MSG_INFO("Initializing " << name() << " ...");
22 
23  ATH_MSG_DEBUG("Properties:");
25 
27 
28  ATH_MSG_DEBUG("Monitoring settings ...");
30 
32  }
33 
34  namespace {
35  std::array<uint8_t,static_cast<unsigned int>(xAOD::UncalibMeasType::nTypes)> countHits(
36  const ActsTrk::TrackContainer &tracksContainer,
37  const typename ActsTrk::TrackContainer::ConstTrackProxy& track) {
38  std::array<uint8_t,static_cast<unsigned int>(xAOD::UncalibMeasType::nTypes)> hit_counts_out{};
39  tracksContainer.trackStateContainer().visitBackwards(
40  track.tipIndex(),
41  [
42  &hit_counts_out
43  ](const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state) -> void
44  {
45  if (state.hasUncalibratedSourceLink()) {
46  try {
47  const xAOD::UncalibratedMeasurement *
48  measurement = &(ActsTrk::getUncalibratedMeasurement(state.getUncalibratedSourceLink().get<ATLASUncalibSourceLink>()));
49  assert( static_cast<unsigned int >(measurement->type() < xAOD::UncalibMeasType::nTypes));
50  ++hit_counts_out[static_cast<unsigned int >(measurement->type())];
51  }
52  catch (std::bad_any_cast &) {
53  }
54  }
55  });
56  return hit_counts_out;
57  }
58  }
59 
60  StatusCode TrackAnalysisAlg::fillHistograms(const EventContext& ctx) const {
61  ATH_MSG_DEBUG( "Filling Histograms for " << name() << " ... " );
62 
63  // Retrieve the tracks
64  SG::ReadHandle<ActsTrk::TrackContainer> trackHandle = SG::makeHandle(m_tracksKey, ctx);
65  ATH_CHECK(trackHandle.isValid());
66  const ActsTrk::TrackContainer *tracks = trackHandle.cptr();
67  using ConstTrackProxy = ActsTrk::TrackContainer::ConstTrackProxy;
68 
69  // TODO this copy will be eliminated once the TrackContainer has [] operator
70  std::vector<ConstTrackProxy> proxies;
71  for (auto proxy: *tracks ) {
72  proxies.push_back(proxy);
73  }
74  auto monitor_ntracks = Monitored::Scalar<int>("Ntracks", tracks->size());
75  auto monitor_theta = Monitored::Collection("theta", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.theta()); } );
76  auto monitor_qoverp = Monitored::Collection("qoverp", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.qOverP()); } );
77  auto monitor_phi = Monitored::Collection("phi", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.phi()); } );
78  auto monitor_chi2 = Monitored::Collection("chi2", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.chi2()); } );
79  auto monitor_chi2OverNdof = Monitored::Collection("chi2OverNdof", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.chi2()/tp.nDoF()); } );
80  auto monitor_ndof = Monitored::Collection("ndof", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.nDoF()); } );
81  auto monitor_nstates = Monitored::Collection("nStates", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.nTrackStates()); } );
82  // @TODO not particular efficient to count the hits twice ...
83  auto monitor_nPixelHits = Monitored::Collection("nPixelHits", proxies, [&tracks](const ConstTrackProxy& tp){
84  return countHits(*tracks,tp)[static_cast<unsigned int>(xAOD::UncalibMeasType::PixelClusterType)]; } );
85  auto monitor_nStripHits = Monitored::Collection("nStripHits", proxies, [&tracks](const ConstTrackProxy& tp){
86  return countHits(*tracks,tp)[static_cast<unsigned int>(xAOD::UncalibMeasType::StripClusterType)]; } );
87  auto monitor_nmeas = Monitored::Collection("nMeasurements", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.nMeasurements()); } );
88  auto monitor_surftype = Monitored::Collection("surfaceType", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.referenceSurface().type()); } );
89 
90 
91  fill(m_monGroupName.value(), monitor_ntracks, monitor_theta, monitor_phi,
92  monitor_qoverp, monitor_nstates, monitor_phi, monitor_chi2, monitor_chi2OverNdof,
93  monitor_ndof, monitor_nstates, monitor_nmeas, monitor_surftype,
94  monitor_nPixelHits, monitor_nStripHits);
95 
96  return StatusCode::SUCCESS;
97  }
98 
99 }
ActsTrk::TrackContainer
Definition: TrackContainer.h:31
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
Monitored::detail::get_value_type< ActsTrk::TrackContainer >::value_type
ActsTrk::TrackContainer::TrackProxy value_type
Definition: TrackAnalysisAlg.cxx:11
ActsTrk::TrackAnalysisAlg::m_tracksKey
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksKey
Definition: TrackAnalysisAlg.h:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
ParticleTest.tp
tp
Definition: ParticleTest.py:25
ActsTrk::TrackAnalysisAlg::initialize
virtual StatusCode initialize() override
initialize
Definition: TrackAnalysisAlg.cxx:20
Monitored::detail::get_value_type
Get element type for containers.
Definition: MonitoredCollection.h:162
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
MonitoredCollection.h
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
TrackAnalysisAlg.h
UncalibratedMeasurementContainer.h
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
xAOD::UncalibMeasType::nTypes
@ nTypes
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
ActsTrk::TrackAnalysisAlg::TrackAnalysisAlg
TrackAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackAnalysisAlg.cxx:16
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
ActsTrk::TrackAnalysisAlg::m_monGroupName
Gaudi::Property< std::string > m_monGroupName
Definition: TrackAnalysisAlg.h:28
xAOD::UncalibMeasType::PixelClusterType
@ PixelClusterType