ATLAS Offline Software
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 
11 #include "StoreGate/WriteHandle.h"
12 #include "StoreGate/ReadHandle.h"
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 
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  }
52  m_nsegmentsTotal = 0;
53  return StatusCode::SUCCESS;
54 }
55 
57 // Execute
59 
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  }
82  MagField::AtlasFieldCache fieldCache;
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 
154 MsgStream& 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 
179 MsgStream& 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 
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
InDet::TRT_TrackSegmentsFinder::dumptools
MsgStream & dumptools(MsgStream &out) const
Definition: TRT_TrackSegmentsFinder.cxx:154
AtlasFieldCacheCondObj
Definition: AtlasFieldCacheCondObj.h:19
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
InDet::TRT_TrackSegmentsFinder::m_fieldCondObjInputKey
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
Definition: TRT_TrackSegmentsFinder.h:64
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet::TRT_TrackSegmentsFinder::m_caloClusterROIKey
SG::ReadHandleKey< ROIPhiRZContainer > m_caloClusterROIKey
Definition: TRT_TrackSegmentsFinder.h:53
hist_file_dump.d
d
Definition: hist_file_dump.py:137
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
M_PI
#define M_PI
Definition: ActiveFraction.h:11
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
InDet::TRT_TrackSegmentsFinder::m_minNumberDCs
Gaudi::Property< int > m_minNumberDCs
Definition: TRT_TrackSegmentsFinder.h:50
Trk::alongMomentum
@ alongMomentum
Definition: PropDirection.h:20
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
InDet::TRT_TrackSegmentsFinder::m_roadtool
ToolHandle< ITRT_DetElementsRoadMaker > m_roadtool
Definition: TRT_TrackSegmentsFinder.h:62
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
WriteHandle.h
Handle class for recording to StoreGate.
Ringer::PS
@ PS
Definition: CaloRingsDefs.h:46
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::Segment
Definition: TrkEvent/TrkSegment/TrkSegment/Segment.h:56
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?
InDet::TRT_TrackSegmentsFinder::dumpevent
MsgStream & dumpevent(MsgStream &out, int nsegments) const
Definition: TRT_TrackSegmentsFinder.cxx:179
TRT_BaseElement.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
InDet::TRT_TrackSegmentsFinder::execute
StatusCode execute(const EventContext &ctx) const
Definition: TRT_TrackSegmentsFinder.cxx:60
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
InDet::TRT_TrackSegmentsFinder::m_segmentsMakerTool
ToolHandle< ITRT_TrackSegmentsMaker > m_segmentsMakerTool
Definition: TRT_TrackSegmentsFinder.h:59
InDet::TRT_TrackSegmentsFinder::TRT_TrackSegmentsFinder
TRT_TrackSegmentsFinder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRT_TrackSegmentsFinder.cxx:21
InDet::TRT_TrackSegmentsFinder::initialize
StatusCode initialize()
Definition: TRT_TrackSegmentsFinder.cxx:30
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TRT_TrackSegmentsFinder.h
DEBUG
#define DEBUG
Definition: page_access.h:11
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
MagField::AtlasFieldCache
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h)
Definition: AtlasFieldCache.h:43
InDet::TRT_TrackSegmentsFinder::m_useCaloSeeds
Gaudi::Property< bool > m_useCaloSeeds
Definition: TRT_TrackSegmentsFinder.h:47
InDet::TRT_TrackSegmentsFinder::finalize
StatusCode finalize()
Definition: TRT_TrackSegmentsFinder.cxx:139
ReadHandle.h
Handle class for reading from StoreGate.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDet::TRT_TrackSegmentsFinder::m_nsegmentsTotal
std::atomic< int > m_nsegmentsTotal
Definition: TRT_TrackSegmentsFinder.h:66
ROIPhiRZ
Definition: ROIPhiRZContainer.h:19
InDet::TRT_TrackSegmentsFinder::m_foundSegmentsKey
SG::WriteHandleKey< Trk::SegmentCollection > m_foundSegmentsKey
Definition: TRT_TrackSegmentsFinder.h:56
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5