ATLAS Offline Software
Loading...
Searching...
No Matches
SegmentRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10
11#include "JiveXML/DataType.h"
12
13namespace JiveXML {
14
21 SegmentRetriever::SegmentRetriever(const std::string& type,const std::string& name,const IInterface* parent):
22 AthAlgTool(type,name,parent){}
23
24
26 ATH_CHECK(m_keys.initialize());
27 return StatusCode::SUCCESS;
28 }
29
30
38 StatusCode SegmentRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
39
40 ATH_MSG_DEBUG("Retrieving " << dataTypeName());
41
42 for( const auto& key : m_keys ) {
44 if (cont.isValid()) {
45
46 //Get number of segments in this collection
47 Trk::SegmentCollection::size_type NSegs=cont.cptr()->size();
48
49 //Define the data vectors we want to fill and create space
50 DataVect x; x.reserve(NSegs);
51 DataVect y; y.reserve(NSegs);
52 DataVect z; z.reserve(NSegs);
53 DataVect phi; phi.reserve(NSegs);
54 DataVect theta; theta.reserve(NSegs);
55 DataVect numHits; numHits.reserve(NSegs);
56 DataVect hits;
57
58 //Loop over the segments
60 //reserve once to avoid reallocation
61 std::size_t nMeasurements{};
62 for (const Trk::Segment * segment : *cont.cptr()){
63 nMeasurements+= segment->containedMeasurements().size();
64 }
65 hits.reserve(nMeasurements);
66 for (SegmentItr=cont.cptr()->begin(); SegmentItr!=cont.cptr()->end(); ++SegmentItr) {
67
68 //Retrieve primitive variables
69 x.emplace_back((*SegmentItr)->globalPosition().x()/10.);
70 y.emplace_back((*SegmentItr)->globalPosition().y()/10.);
71 z.emplace_back((*SegmentItr)->globalPosition().z()/10.);
72 phi.emplace_back((*SegmentItr)->localParameters()[Trk::phi]);
73 theta.emplace_back((*SegmentItr)->localParameters()[Trk::theta]);
74
75 //Count number of valid (non-null) RIO_OnTracks
76 int NRoTs = 0;
77 //Loop over segment measurments
78 std::vector< const Trk::MeasurementBase * >::const_iterator measItr, measEnd;
79 measItr=(*SegmentItr)->containedMeasurements().begin();
80 measEnd=(*SegmentItr)->containedMeasurements().end();
81
82 //Now loop over measurements
83 for (; measItr!=measEnd; ++measItr) {
84
85 //dynamic_cast to RIO_OnTrack - will return NULL if not a RIO_OnTrack object
86 const Trk::RIO_OnTrack *RoT = dynamic_cast<const Trk::RIO_OnTrack*>(*measItr);
87
88 //Ignore failed dynamic_casts
89 if (!RoT) continue ;
90
91 //Add the hit
92 hits.emplace_back(RoT->identify().get_compact() );
93 //count as valid
94 NRoTs++;
95 }
96
97 //Store number of hits for this segement
98 numHits.emplace_back(NRoTs);
99 }
100
101 //Add data to our map
103 DataMap["x"] = std::move(x);
104 DataMap["y"] = std::move(y);
105 DataMap["z"] = std::move(z);
106 DataMap["phi"] = std::move(phi);
107 DataMap["theta"] = std::move(theta);
108 std::size_t n = numHits.size();
109 DataMap["numHits"] = std::move(numHits);
110
111 //Hits are stored as multiple with average size given in XML header
112 if (NSegs > 0) {
113 std::string multiple = "hits multiple=\"" + DataType( hits.size()*1./n).toString() + "\"";
114 DataMap[multiple] = std::move(hits);
115 }
116
117 //forward data to formating tool
118 if ( FormatTool->AddToEvent(dataTypeName(), key.key(), &DataMap).isFailure())
119 return StatusCode::RECOVERABLE;
120
121 ATH_MSG_DEBUG(dataTypeName() << " collection " << key << " retrieved with " << NSegs << " entries");
122
123 }
124 else{
125 ATH_MSG_WARNING("Collection " << key << " not found in SG ");
126 }
127 }
128
129 //All collections retrieved - done
130 return StatusCode::SUCCESS;
131
132 } // retrieve
133} //namespace
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
#define y
#define x
#define z
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
typename DataVectorBase< Trk::Segment >::Base::size_type size_type
Definition DataVector.h:814
value_type get_compact() const
Get the compact id.
SegmentRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
SG::ReadHandleKeyArray< Trk::SegmentCollection > m_keys
virtual StatusCode initialize()
virtual std::string dataTypeName() const
Return the name of the data type.
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
Identifier identify() const
return the identifier -extends MeasurementBase
Base class for all TrackSegment implementations, extends the common MeasurementBase.
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition DataType.h:58
@ theta
Definition ParamDefs.h:66
@ phi
Definition ParamDefs.h:75