ATLAS Offline Software
ProtoTrackCreationAndFitAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include <stdlib.h>
9 
10 
11 ActsTrk::ProtoTrackCreationAndFitAlg::ProtoTrackCreationAndFitAlg (const std::string& name, ISvcLocator* pSvcLocator ) : AthReentrantAlgorithm( name, pSvcLocator ){
12 }
13 
15  ATH_CHECK(m_trackContainerKey.initialize());
16  ATH_CHECK(m_PixelClusters.initialize());
17  ATH_CHECK(m_StripClusters.initialize());
18  ATH_CHECK(m_tracksBackendHandlesHelper.initialize(ActsTrk::prefixFromTrackContainerName(m_trackContainerKey.key())));
19  ATH_CHECK(m_actsFitter.retrieve());
20  ATH_CHECK(m_patternBuilder.retrieve());
21  ATH_CHECK(m_detEleCollKeys.initialize());
22  ATH_CHECK(m_trackingGeometryTool.retrieve());
23  ATH_CHECK(m_ATLASConverterTool.retrieve());
24  ATH_CHECK(m_extrapolationTool.retrieve());
25 
26  return StatusCode::SUCCESS;
27 }
28 
30 
31  // Read the pixel and strip cluster list
32  SG::ReadHandle<xAOD::PixelClusterContainer> thePixelClusters(m_PixelClusters,ctx);
33  SG::ReadHandle<xAOD::StripClusterContainer> theStripClusters(m_StripClusters,ctx);
34  if (!thePixelClusters.isValid()){
35  ATH_MSG_FATAL("no Pixel clusters");
36  return StatusCode::FAILURE;
37  }
38  ATH_MSG_DEBUG("I found " <<thePixelClusters->size()<<" pix clusters");
39 
40  if (!theStripClusters.isValid()){
41  ATH_MSG_FATAL("no strip clusters");
42  return StatusCode::FAILURE;
43  }
44  ATH_MSG_DEBUG("I found " <<theStripClusters->size()<<" strip clusters");
45 
46  // book the output tracks
47  auto trackContainerHandle = SG::makeHandle(m_trackContainerKey, ctx);
48 
49  // call the user-provided track finder
50  std::vector<ActsTrk::ProtoTrack> myProtoTracks;
51  ATH_CHECK(m_patternBuilder->findProtoTracks(ctx,
52  *thePixelClusters,
53  *theStripClusters,
54  myProtoTracks ));
55  ATH_MSG_INFO("I received " <<myProtoTracks.size()<<" proto-tracks");
56 
57 
67 
68  std::vector<const InDetDD::SiDetectorElementCollection *> detEleColl;
69  detEleColl.reserve(m_detEleCollKeys.size());
70  for (const auto &detEleCollKey : m_detEleCollKeys)
71  {
72  ATH_MSG_DEBUG("Reading input condition data with key " << detEleCollKey.key());
73  SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> detEleCollHandle(detEleCollKey, ctx);
74  ATH_CHECK(detEleCollHandle.isValid());
75  detEleColl.push_back(detEleCollHandle.retrieve());
76  if (detEleColl.back() == nullptr)
77  {
78  ATH_MSG_FATAL(detEleCollKey.fullKey() << " is not available.");
79  return StatusCode::FAILURE;
80  }
81  ATH_MSG_DEBUG("Retrieved " << detEleColl.back()->size() << " input condition elements from key " << detEleCollKey.key());
82  }
83 
84  TrackingSurfaceHelper trackingSurfaceHelper;
85  for (auto & coll : detEleColl)
86  {
87  for (const auto *det_el : *coll){
88  const Acts::Surface &surface =
89  m_ATLASConverterTool->trkSurfaceToActsSurface(det_el->surface());
91  if (det_el->isPixel()) type = xAOD::UncalibMeasType::PixelClusterType;
92  else if (det_el->isSCT()) type = xAOD::UncalibMeasType::StripClusterType;
93  trackingSurfaceHelper.actsSurfaces(type).push_back(&surface);
94  }
95  }
96  for (const auto & coll : detEleColl)
97  {
99  if (coll->front()->isPixel()) measType = xAOD::UncalibMeasType::PixelClusterType;
101  trackingSurfaceHelper.setSiDetectorElements(measType, coll);
102  }
103  Acts::GeometryContext tgContext = m_trackingGeometryTool->getGeometryContext(ctx).context();
104  Acts::MagneticFieldContext mfContext = m_extrapolationTool->getMagneticFieldContext(ctx);
105  // CalibrationContext converter not implemented yet.
106  Acts::CalibrationContext calContext = Acts::CalibrationContext();
107 
110  ActsTrk::MutableTrackContainer trackContainer;
111 
112  // now we fit each of the proto tracks
113  for (auto & proto : myProtoTracks){
114  auto res = m_actsFitter->fit(ctx, proto.measurements,*proto.parameters,
115  m_trackingGeometryTool->getGeometryContext(ctx).context(),
116  m_extrapolationTool->getMagneticFieldContext(ctx),
117  Acts::CalibrationContext(),
118  trackingSurfaceHelper);
119 
120  if(!res) continue;
121  if (res->size() == 0 ) continue;
122  if(not proto.measurements.size()) continue;
123  ATH_MSG_DEBUG(".......Done track with size "<< proto.measurements.size());
124  const auto trackProxy = res->getTrack(0);
125  if (not trackProxy.hasReferenceSurface()) {
126  ATH_MSG_INFO("There is not reference surface for this track");
127  continue;
128  }
129  auto destProxy = trackContainer.getTrack(trackContainer.addTrack());
130  destProxy.copyFrom(trackProxy, true); // make sure we copy track states!
131  }
132  std::unique_ptr<ActsTrk::TrackContainer> constTracksContainer = m_tracksBackendHandlesHelper.moveToConst(std::move(trackContainer),
133  m_trackingGeometryTool->getGeometryContext(ctx).context(), ctx);
134  ATH_CHECK(trackContainerHandle.record(std::move(constTracksContainer)));
135 
136 
137  return StatusCode::SUCCESS;
138 }
139 
140 
TrackingSurfaceHelper
Simple helper class which allows to access the tracking surface associated to a certain (Si-)measurem...
Definition: TrackingSurfaceHelper.h:17
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
ActsTrk::ProtoTrackCreationAndFitAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: ProtoTrackCreationAndFitAlg.cxx:29
TrackingSurfaceHelper::setSiDetectorElements
void setSiDetectorElements(xAOD::UncalibMeasType type, const InDetDD::SiDetectorElementCollection *det_element_collection)
Definition: TrackingSurfaceHelper.h:29
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:205
ActsTrk::prefixFromTrackContainerName
std::string prefixFromTrackContainerName(const std::string &tracks)
Parse TrackContainer name to get the prefix for backends The name has to contain XYZTracks,...
Definition: TrackContainerHandlesHelper.cxx:18
ProtoTrackCreationAndFitAlg.h
TrackingSurfaceHelper::actsSurfaces
std::vector< const Acts::Surface * > & actsSurfaces(xAOD::UncalibMeasType type)
Definition: TrackingSurfaceHelper.h:25
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
ActsTrk::ProtoTrackCreationAndFitAlg::initialize
virtual StatusCode initialize() override final
uncomment and implement methods as required
Definition: ProtoTrackCreationAndFitAlg.cxx:14
SG::ReadCondHandle::retrieve
const_pointer_type retrieve()
Definition: ReadCondHandle.h:161
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
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
xAOD::Other
@ Other
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsTrk::ProtoTrackCreationAndFitAlg::ProtoTrackCreationAndFitAlg
ProtoTrackCreationAndFitAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ProtoTrackCreationAndFitAlg.cxx:11
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
EventInfo.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::UncalibMeasType
UncalibMeasType
Define the type of the uncalibrated measurement.
Definition: MeasurementDefs.h:24
ActsTrk::MutableTrackContainer
Definition: TrackContainer.h:122
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::UncalibMeasType::PixelClusterType
@ PixelClusterType