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_protoTrackCollectionKey.initialize(SG::AllowEmpty));
17  ATH_CHECK(m_PixelClusters.initialize());
18  ATH_CHECK(m_StripClusters.initialize());
19  ATH_CHECK(m_tracksBackendHandlesHelper.initialize(ActsTrk::prefixFromTrackContainerName(m_trackContainerKey.key())));
20  ATH_CHECK(m_actsFitter.retrieve());
21  ATH_CHECK(m_patternBuilder.retrieve());
22  ATH_CHECK(m_detectorElementToGeometryIdMapKey.initialize());
23  ATH_CHECK(m_trackingGeometryTool.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  auto myProtoTracks = std::make_unique<ActsTrk::ProtoTrackCollection>();
51  ATH_CHECK(m_patternBuilder->findProtoTracks(ctx,
52  *thePixelClusters,
53  *theStripClusters,
54  *myProtoTracks ));
55  ATH_MSG_INFO("I received " << myProtoTracks->size() << " proto-tracks");
56 
66 
68  detectorElementToGeometryIdMap{m_detectorElementToGeometryIdMapKey, ctx};
69  ATH_CHECK(detectorElementToGeometryIdMap.isValid());
70 
71  Acts::GeometryContext tgContext = m_trackingGeometryTool->getGeometryContext(ctx).context();
72  Acts::MagneticFieldContext mfContext = m_extrapolationTool->getMagneticFieldContext(ctx);
73  // CalibrationContext converter not implemented yet.
74  Acts::CalibrationContext calContext = Acts::CalibrationContext();
75 
78  ActsTrk::MutableTrackContainer trackContainer;
79 
80  // now we fit each of the proto tracks
81  for (auto & proto : *myProtoTracks){
82  auto res = m_actsFitter->fit(ctx, proto.measurements,*proto.parameters,
83  m_trackingGeometryTool->getGeometryContext(ctx).context(),
84  m_extrapolationTool->getMagneticFieldContext(ctx),
85  Acts::CalibrationContext(),
86  **detectorElementToGeometryIdMap);
87 
88  if(!res) continue;
89  if (res->size() == 0 ) continue;
90  if(not proto.measurements.size()) continue;
91  ATH_MSG_DEBUG(".......Done track with size "<< proto.measurements.size());
92  const auto trackProxy = res->getTrack(0);
93  if (not trackProxy.hasReferenceSurface()) {
94  ATH_MSG_INFO("There is not reference surface for this track");
95  continue;
96  }
97  auto destProxy = trackContainer.getTrack(trackContainer.addTrack());
98  destProxy.copyFrom(trackProxy, true); // make sure we copy track states!
99  if ( m_copyParametersFromFit ) {
100  ATH_MSG_VERBOSE("original " << proto.parameters->parameters());
101  proto.parameters =
102  std::make_unique<Acts::BoundTrackParameters>( trackProxy.referenceSurface().getSharedPtr(),
103  trackProxy.parameters(),
104  trackProxy.covariance(),
105  trackProxy.particleHypothesis());
106  ATH_MSG_VERBOSE("corrected" << proto.parameters->parameters());
107  }
108 
109  }
110  std::unique_ptr<ActsTrk::TrackContainer> constTracksContainer = m_tracksBackendHandlesHelper.moveToConst(std::move(trackContainer),
111  m_trackingGeometryTool->getGeometryContext(ctx).context(), ctx);
112  ATH_CHECK(trackContainerHandle.record(std::move(constTracksContainer)));
113 
114  if (not m_protoTrackCollectionKey.empty()) {
115  auto handle = SG::makeHandle(m_protoTrackCollectionKey, ctx);
116  ATH_CHECK(handle.record(std::move(myProtoTracks)));
117  }
118 
119  return StatusCode::SUCCESS;
120 }
121 
122 
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
ActsTrk::ProtoTrackCreationAndFitAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: ProtoTrackCreationAndFitAlg.cxx:29
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
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
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:270
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:14
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:228
EventInfo.h
ActsTrk::MutableTrackContainer
Definition: TrackContainer.h:122
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.