ATLAS Offline Software
ProtoTrackCreationAndFitAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
10 #include <stdlib.h>
11 
12 
13 
20  ATH_CHECK(m_actsFitter.retrieve());
21  ATH_CHECK(m_patternBuilder.retrieve());
23  ATH_CHECK(m_extrapolationTool.retrieve());
24 
25  return StatusCode::SUCCESS;
26 }
27 
29 
30  // Read the pixel and strip cluster list
31  SG::ReadHandle<xAOD::PixelClusterContainer> thePixelClusters(m_PixelClusters,ctx);
32  SG::ReadHandle<xAOD::StripClusterContainer> theStripClusters(m_StripClusters,ctx);
33  if (!thePixelClusters.isValid()){
34  ATH_MSG_FATAL("no Pixel clusters");
35  return StatusCode::FAILURE;
36  }
37  ATH_MSG_DEBUG("I found " <<thePixelClusters->size()<<" pix clusters");
38 
39  if (!theStripClusters.isValid()){
40  ATH_MSG_FATAL("no strip clusters");
41  return StatusCode::FAILURE;
42  }
43  ATH_MSG_DEBUG("I found " <<theStripClusters->size()<<" strip clusters");
44 
45  // book the output tracks
46  auto trackContainerHandle = SG::makeHandle(m_trackContainerKey, ctx);
47 
48  // call the user-provided track finder
49  auto myProtoTracks = std::make_unique<ActsTrk::ProtoTrackCollection>();
50  ATH_CHECK(m_patternBuilder->findProtoTracks(ctx,
51  *thePixelClusters,
52  *theStripClusters,
53  *myProtoTracks ));
54  ATH_MSG_INFO("I received " << myProtoTracks->size() << " proto-tracks");
55 
65  const Acts::GeometryContext tgContext = m_trackingGeometryTool->getGeometryContext(ctx).context();
66  const Acts::MagneticFieldContext mfContext = m_extrapolationTool->getMagneticFieldContext(ctx);
67  const Acts::CalibrationContext calContext{getCalibrationContext(ctx)};
68 
71  Acts::VectorTrackContainer trackBackend;
72  Acts::VectorMultiTrajectory trackStateBackend;
73  ActsTrk::detail::RecoTrackContainer trackContainer( trackBackend, trackStateBackend );
74 
75  // now we fit each of the proto tracks
76  for (auto & proto : *myProtoTracks){
77  auto res = m_actsFitter->fit(proto.measurements,*proto.parameters,
78  tgContext, mfContext, calContext);
79 
80  if(!res) continue;
81  if (res->size() == 0 ) continue;
82  if(not proto.measurements.size()) continue;
83  ATH_MSG_DEBUG(".......Done track with size "<< proto.measurements.size());
84  const auto trackProxy = res->getTrack(0);
85  if (not trackProxy.hasReferenceSurface()) {
86  ATH_MSG_INFO("There is not reference surface for this track");
87  continue;
88  }
89  auto destProxy = trackContainer.getTrack(trackContainer.addTrack());
90  destProxy.copyFrom(trackProxy, true); // make sure we copy track states!
91  if ( m_copyParametersFromFit ) {
92  ATH_MSG_VERBOSE("original " << proto.parameters->parameters());
93  proto.parameters =
94  std::make_unique<Acts::BoundTrackParameters>( trackProxy.referenceSurface().getSharedPtr(),
95  trackProxy.parameters(),
96  trackProxy.covariance(),
97  trackProxy.particleHypothesis());
98  ATH_MSG_VERBOSE("corrected" << proto.parameters->parameters());
99  }
100 
101  }
102 
103  ActsTrk::TrackBackend constTrackBackend( std::move(trackBackend) );
104  ActsTrk::TrackStateBackend constTrackStateBackend( std::move(trackStateBackend) );
105  std::unique_ptr<ActsTrk::TrackContainer> constTracksContainer = std::make_unique<ActsTrk::TrackContainer>( std::move(constTrackBackend),
106  std::move(constTrackStateBackend) );
107  ATH_CHECK(trackContainerHandle.record(std::move(constTracksContainer)));
108 
109  if (not m_protoTrackCollectionKey.empty()) {
110  auto handle = SG::makeHandle(m_protoTrackCollectionKey, ctx);
111  ATH_CHECK(handle.record(std::move(myProtoTracks)));
112  }
113 
114  return StatusCode::SUCCESS;
115 }
116 
117 
ActsTrk::ProtoTrackCreationAndFitAlg::m_actsFitter
ToolHandle< ActsTrk::IFitterTool > m_actsFitter
Definition: ProtoTrackCreationAndFitAlg.h:45
ActsTrk::getCalibrationContext
Acts::CalibrationContext getCalibrationContext(const EventContext &ctx)
The Acts::Calibration context is piped through the Acts fitters to (re)calibrate the Acts::SourceLink...
Definition: CalibrationContext.h:15
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ActsTrk::ProtoTrackCreationAndFitAlg::m_patternBuilder
ToolHandle< ActsTrk::IProtoTrackCreatorTool > m_patternBuilder
Definition: ProtoTrackCreationAndFitAlg.h:43
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ActsTrk::ProtoTrackCreationAndFitAlg::m_extrapolationTool
ToolHandle< IActsExtrapolationTool > m_extrapolationTool
Definition: ProtoTrackCreationAndFitAlg.h:49
Definitions.h
ActsTrk::ProtoTrackCreationAndFitAlg::m_trackingGeometryTool
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
Definition: ProtoTrackCreationAndFitAlg.h:47
ActsTrk::TrackBackend
Acts::ConstVectorTrackContainer TrackBackend
Definition: TrackContainer.h:14
ActsTrk::ProtoTrackCreationAndFitAlg::m_trackContainerKey
SG::WriteHandleKey< ActsTrk::TrackContainer > m_trackContainerKey
Definition: ProtoTrackCreationAndFitAlg.h:51
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
ActsTrk::ProtoTrackCreationAndFitAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: ProtoTrackCreationAndFitAlg.cxx:28
ActsTrk::ProtoTrackCreationAndFitAlg::m_PixelClusters
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_PixelClusters
Definition: ProtoTrackCreationAndFitAlg.h:39
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:20
ProtoTrackCreationAndFitAlg.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
ActsTrk::detail::RecoTrackContainer
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
Definition: Tracking/Acts/ActsTrackReconstruction/src/detail/Definitions.h:22
ActsTrk::MutableTrackContainerHandlesHelper::initialize
StatusCode initialize(const std::string &prefix)
Sets up the handles.
Definition: TrackContainerHandlesHelper.cxx:47
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
ActsTrk::ProtoTrackCreationAndFitAlg::m_tracksBackendHandlesHelper
ActsTrk::MutableTrackContainerHandlesHelper m_tracksBackendHandlesHelper
Definition: ProtoTrackCreationAndFitAlg.h:57
CalibrationContext.h
ActsTrk::ProtoTrackCreationAndFitAlg::initialize
virtual StatusCode initialize() override final
uncomment and implement methods as required
Definition: ProtoTrackCreationAndFitAlg.cxx:14
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:11
ActsTrk::TrackStateBackend
Acts::ConstVectorMultiTrajectory TrackStateBackend
Definition: TrackContainer.h:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.TrackLeptonConfig.trackContainer
string trackContainer
Definition: TrackLeptonConfig.py:23
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?
ActsTrk::ProtoTrackCreationAndFitAlg::m_StripClusters
SG::ReadHandleKey< xAOD::StripClusterContainer > m_StripClusters
Definition: ProtoTrackCreationAndFitAlg.h:41
ActsTrk::ProtoTrackCreationAndFitAlg::m_protoTrackCollectionKey
SG::WriteHandleKey< ActsTrk::ProtoTrackCollection > m_protoTrackCollectionKey
Definition: ProtoTrackCreationAndFitAlg.h:54
EventInfo.h
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.