ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_TrackSegmentsFinder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
8
10
13
14#include <memory>
15
17// Constructor
19
21(const std::string& name,ISvcLocator* pSvcLocator) :
22 AthReentrantAlgorithm(name, pSvcLocator)
23{
24}
25
27// Initialisation
29
31{
32 // Get tool for drift circles seeds maker
33 //
34 ATH_CHECK( m_segmentsMakerTool.retrieve() );
35 ATH_CHECK( m_roadtool.retrieve( DisableTool{ !m_useCaloSeeds }) );
36
38 ATH_CHECK( m_foundSegmentsKey.initialize() );
39
41 ATH_CHECK( m_fieldCondObjInputKey.initialize());
43
44 // Get output print level
45 //
46 if (msgLvl(MSG::DEBUG)) {
47 MsgStream& out = msg(MSG::DEBUG);
48 out << std::endl;
49 dumptools(out);
50 out << endmsg;
51 }
53 return StatusCode::SUCCESS;
54}
55
57// Execute
59
60StatusCode InDet::TRT_TrackSegmentsFinder::execute(const EventContext &ctx) const
61{
62 std::unique_ptr<Trk::SegmentCollection> found_segments(std::make_unique<Trk::SegmentCollection>());
63 std::unique_ptr<InDet::ITRT_TrackSegmentsMaker::IEventData> event_data_p;
65 if(!m_useCaloSeeds) {
66 event_data_p = m_segmentsMakerTool->newEvent(ctx);
67 m_segmentsMakerTool->find (ctx, *event_data_p, map);
68 // Loop through all segments and reconsrtucted segments collection preparation
69 //
70 Trk::Segment* segment = nullptr;
71 while((segment = m_segmentsMakerTool->next(*event_data_p))) {
72 found_segments->push_back(segment);
73 }
74 } else {
75 Amg::Vector3D PSV(0.,0.,0.); Trk::PerigeeSurface PS(PSV);
76 std::vector<IdentifierHash> vTR;
78 if (!calo_rois.isValid()) {
79 ATH_MSG_FATAL("Failed to get EM Calo cluster collection " << m_caloClusterROIKey );
80 return StatusCode::FAILURE;
81 }
84 const AtlasFieldCacheCondObj* fieldCondObj{*readHandle};
85 if (fieldCondObj == nullptr) {
86 ATH_MSG_ERROR("InDet::TRT_TrackExtensionTool_xk::findSegment: Failed to retrieve AtlasFieldCacheCondObj with key " << m_fieldCondObjInputKey.key());
87 return StatusCode::FAILURE;
88 }
89 fieldCondObj->getInitializedCache (fieldCache);
90 for (const ROIPhiRZ &roi : *calo_rois) {
91 if (std::abs(roi[0])>M_PI) continue; // reject duplicates;
92 std::unique_ptr<Trk::TrackParameters> par = PS.createUniqueTrackParameters(0., 0., roi.phi(), roi.theta(), 0., std::nullopt);
93 // Get AtlasFieldCache
94 // TRT detector elements road builder
95 //
96 const auto & DE = m_roadtool->detElementsRoad(ctx, fieldCache, *par, Trk::alongMomentum, map);
97 if(int(DE.size()) < m_minNumberDCs) continue;
98 vTR.clear();
99 vTR.reserve(DE.size());
100 for (const InDetDD::TRT_BaseElement*d: DE) {
101 vTR.push_back(d->identifyHash());
102 }
103 event_data_p = m_segmentsMakerTool->newRegion(ctx, vTR);
104 m_segmentsMakerTool->find(ctx, *event_data_p,map);
105 // Loop through all segments and reconsrtucted segments collection preparation
106 Trk::Segment* segment = nullptr;
107 while((segment = m_segmentsMakerTool->next(*event_data_p))) {
108 found_segments->push_back(segment);
109 }
110 }//end of loopover *calo
111 }
112 if (event_data_p) {
113 m_segmentsMakerTool->endEvent(*event_data_p);
114 }
115
116 // gather stat before found segments are moved.
117 if (msgLvl(MSG::DEBUG)) {
118 MsgStream& out = msg(MSG::DEBUG);
119 out << std::endl;
120 dumpevent(out,found_segments->size());
121 out << endmsg;
122 }
123 m_nsegmentsTotal+=found_segments->size();
124
125 if (SG::WriteHandle( m_foundSegmentsKey, ctx ).record(std::move(found_segments)).isFailure()) {
126 ATH_MSG_ERROR("Could not save TRT segments " << m_foundSegmentsKey.key() );
127 return StatusCode::FAILURE;
128 }
129
130 // Print common event information
131 //
132 return StatusCode::SUCCESS;
133}
134
136// Finalize
138
140{
141 if (msgLvl(MSG::INFO)) {
142 MsgStream& out = msg(MSG::INFO);
143 out << std::endl;
145 out << endmsg;
146 }
147 return StatusCode::SUCCESS;
148}
149
151// Dumps conditions information into the MsgStream
153
154MsgStream& InDet::TRT_TrackSegmentsFinder::dumptools( MsgStream& out ) const
155{
156 int n = 65-m_segmentsMakerTool.type().size();
157 std::string s1; for(int i=0; i<n; ++i) s1.append(" "); s1.append("|");
158 n = 65-m_foundSegmentsKey.key().size();
159 std::string s2; for(int i=0; i<n; ++i) s2.append(" "); s2.append("|");
160
161 out<<"|----------------------------------------------------------------"
162 <<"----------------------------------------------------|"
163 <<std::endl;
164 out<<"| Tool for TRT track segments finding | "<<m_segmentsMakerTool.type()<<s1
165 <<std::endl;
166 out<<"| Location of output segments | "<<m_foundSegmentsKey.key()<<s2
167 <<std::endl;
168 out<<"|----------------------------------------------------------------"
169 <<"----------------------------------------------------|"
170 <<std::endl;
171
172 return out;
173}
174
176// Dumps event information into the ostream
178
179MsgStream& InDet::TRT_TrackSegmentsFinder::dumpevent( MsgStream& out, int nsegments) const
180{
181 out<<"|-------------------------------------------------------------------";
182 out<<"-----------------------------|"
183 <<std::endl;
184
185 out<< ((m_useCaloSeeds)
186 ? "| TRT track segments found with calo seeds |"
187 : "| TRT track segments found without calo seeds |")
188 <<std::setw(7)<<nsegments
189 <<" |"
190 <<std::endl;
191 out<<"|-------------------------------------------------------------------";
192 out<<"-----------------------------|"
193 <<std::endl;
194 return out;
195}
196
197
198
199
200
201
#define M_PI
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
Virtual base class of TRT readout elements.
TRT_TrackSegmentsFinder(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< ITRT_TrackSegmentsMaker > m_segmentsMakerTool
MsgStream & dumpevent(MsgStream &out, int nsegments) const
SG::WriteHandleKey< Trk::SegmentCollection > m_foundSegmentsKey
ToolHandle< ITRT_DetElementsRoadMaker > m_roadtool
StatusCode execute(const EventContext &ctx) const
MsgStream & dumptools(MsgStream &out) const
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
SG::ReadHandleKey< ROIPhiRZContainer > m_caloClusterROIKey
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Class describing the Line to which the Perigee refers to.
Base class for all TrackSegment implementations, extends the common MeasurementBase.
STL class.
Eigen::Matrix< double, 3, 1 > Vector3D
@ alongMomentum