ATLAS Offline Software
Loading...
Searching...
No Matches
SiSpacePointRetriever.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#include "JiveXML/DataType.h"
7
10
17
18#include "CLHEP/Units/SystemOfUnits.h"
19
20namespace JiveXML
21{
22
29 SiSpacePointRetriever::SiSpacePointRetriever(const std::string& type,const std::string& name,const IInterface* parent):
30 AthAlgTool(type,name,parent)
31 {
32
33 //Declare the interface
34 declareInterface<IDataRetriever>(this);
35
36 //And the properties
37 declareProperty("PixelSpacePoints" , m_PixelSPContainerName = std::string("PixelSpacePoints"));
38 declareProperty("SCTSpacePoints" , m_SCTSPContainerName = std::string("SCT_SpacePoints"));
39 declareProperty("PRD_TruthPixel" , m_PixelPRDTruthName = std::string("PRD_MultiTruthPixel"));
40 declareProperty("PRD_TruthSCT" , m_SCTPRDTruthName = std::string("PRD_MultiTruthSCT"));
41 }
42
43 //Namespace for the helper functions
45
54 unsigned int getTruthBarcodes( const Identifier idFirst, const Identifier idSecond, const PRD_MultiTruthCollection* truthColl, DataVect& barcodes) {
55
56 //Make life easier
57 using PRDTruthIter = PRD_MultiTruthCollection::const_iterator;
58
59
65
66 //Sets of barcodes associated with first, second and both cluster
67 std::set<int> barcodesFirst;
68 std::set<int> barcodesSecond;
69 std::set<int> barcodesCommon;
70
71 //Get the set of particle barcodes associated with the first cluster identifier
72 std::pair<PRDTruthIter,PRDTruthIter> equalRangeFirst = truthColl->equal_range(idFirst);
73 for(PRDTruthIter TruthCollItr=equalRangeFirst.first; TruthCollItr!= equalRangeFirst.second; ++TruthCollItr)
74 barcodesFirst.insert(TruthCollItr->second.barcode());
75
76 //Check if we have only have one valid cluster identifier
77 if (! idSecond.is_valid()){
78
79 //Make this our list of barcodes (swap is O(1))
80 barcodesCommon.swap(barcodesFirst);
81
82 //otherwise only store barcodes associated with both identifiers
83 } else {
84
85 //Get the set of particle barcodes associated with the second cluster identifier
86 std::pair<PRDTruthIter,PRDTruthIter> equalRangeSecond = truthColl->equal_range(idSecond);
87 for(PRDTruthIter TruthCollItr=equalRangeSecond.first; TruthCollItr!= equalRangeSecond.second; ++TruthCollItr)
88 barcodesSecond.insert(TruthCollItr->second.barcode());
89
90 //Copy the list of particle barcodes that are associated with both clusters
91 std::set_intersection(barcodesFirst.begin(), barcodesFirst.end(), barcodesSecond.begin(), barcodesSecond.end(),
92 std::insert_iterator< std::set<int> >(barcodesCommon,barcodesCommon.begin()) );
93 }
94
95 //Finally add the list of barcodes to our DataVect
96 for (const auto barcodeCommon : barcodesCommon) barcodes.push_back(DataType(barcodeCommon));
97
98 //return the number of added barcodes
99 return barcodesCommon.size();
100 }
101
102 }//helpers namespace
103
108 StatusCode SiSpacePointRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
109
110 //be verbose
111 ATH_MSG_DEBUG( "Retrieving " << dataTypeName() );
112
116
118 if ( not PixelSPContainer.isValid() )
119 ATH_MSG_WARNING( "Unable to retrieve SpacePoint container with name " << m_PixelSPContainerName.key() );
120
122 if (m_usePixelTruthMap) {
123 PixelPRDTruthColl = SG::makeHandle(m_PixelPRDTruthName);
124 if ( not PixelPRDTruthColl.isValid() )
125 ATH_MSG_WARNING( "Unable to retrieve PRD_MultiTruth collection with name " << m_PixelPRDTruthName.key() );
126 }
127
129 if ( not SCTSPContainer.isValid() )
130 ATH_MSG_WARNING( "Unable to retrieve SpacePoint container with name " << m_SCTSPContainerName.key() );
131
133 if (m_useSCTTruthMap) {
134 SCTPRDTruthColl = SG::makeHandle(m_SCTPRDTruthName);
135 if ( not SCTPRDTruthColl.isValid() )
136 ATH_MSG_WARNING( "Unable to retrieve PRD_MultiTruth collection with name " << m_SCTPRDTruthName.key() );
137 }
138
142 using SpacePointTruthPair = std::pair<const SpacePointContainer *, const PRD_MultiTruthCollection *>;
143 std::vector<SpacePointTruthPair> SpacePointTruthPairList;
144
145 //Add Pixel if there is a collection
146 if (PixelSPContainer.isValid())
147 SpacePointTruthPairList.emplace_back(PixelSPContainer.cptr(), m_usePixelTruthMap ? PixelPRDTruthColl.cptr() : nullptr);
148
149 //Add SCT if there is a collection
150 if (SCTSPContainer.isValid())
151 SpacePointTruthPairList.emplace_back(SCTSPContainer.cptr(), m_useSCTTruthMap ? SCTPRDTruthColl.cptr() : nullptr);
152
156 int NSpacePoints = 0;
157 //Loop over all SpacePoint - PRDTruth pairs
158 for (const auto &SPTruthPair : SpacePointTruthPairList) {
159
160 //Add up the size of the SpacePoint collections in the container
161 for (const auto SpacePoint : *(SPTruthPair.first))
162 NSpacePoints += SpacePoint->size();
163 }
164
165 ATH_MSG_DEBUG( "Counted " << NSpacePoints << " in total" );
166
170 DataVect x; x.reserve(NSpacePoints);
171 DataVect y; y.reserve(NSpacePoints);
172 DataVect z; z.reserve(NSpacePoints);
173 DataVect clusters; clusters.reserve(NSpacePoints*2);
174 DataVect phiModule; phiModule.reserve(NSpacePoints);
175 DataVect etaModule; etaModule.reserve(NSpacePoints);
176 DataVect numBarcodes; numBarcodes.reserve(NSpacePoints);
177 DataVect barcodes; barcodes.reserve(NSpacePoints); // Usually less then one per space point
178
182
183 //Loop over all SpacePoint - PRDTruth pairs
184 for (const auto &SPTruthPair : SpacePointTruthPairList) {
185
186 // Loop over SpacePoint Collections in the SpacePoint container
187 for (const auto SpacePointColl : *(SPTruthPair.first)){
188
189 //Loop over SpacePoints themselves
190 for (const auto SpacePoint : *SpacePointColl) {
191
192 //Get the position of the space point
193 Amg::Vector3D point = SpacePoint->globalPosition();
194
195 //Store position in units of centimeters
196 x.push_back(DataType(point.x() * CLHEP::mm/CLHEP::cm));
197 y.push_back(DataType(point.y() * CLHEP::mm/CLHEP::cm));
198 z.push_back(DataType(point.z() * CLHEP::mm/CLHEP::cm));
199
200 //Get the cluster list for the Space point (first and second)
201 const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*> clusterList = SpacePoint->clusterList();
202
203 //Get the identifiers of the first and second cluster
204 Identifier idFirst = clusterList.first->identify();
205 Identifier idSecond = (clusterList.second != NULL) ? clusterList.second->identify() : Identifier();
206
207 //Get phi and eta of the module in detector coordinates of the first cluster
208 if (clusterList.first->type(Trk::PrepRawDataType::SCT_Cluster)) {
209 phiModule.push_back(DataType(m_geo->SCTIDHelper()->phi_module(idFirst)));
210 etaModule.push_back(DataType(m_geo->SCTIDHelper()->eta_module(idFirst)));
211 }
212 else {
213 phiModule.push_back(DataType(m_geo->PixelIDHelper()->phi_module(idFirst)));
214 etaModule.push_back(DataType(m_geo->PixelIDHelper()->eta_module(idFirst)));
215 }
216
217 // Store the cluster(s) identifier (pair)
218 clusters.push_back(DataType(idFirst.get_compact()));
219 clusters.push_back((idSecond.is_valid()) ? DataType(idSecond.get_compact()) : DataType(-1));
220
221 //Stop here if there is no truth
222 const PRD_MultiTruthCollection* PRDTruthColl = SPTruthPair.second;
223 if ( PRDTruthColl == nullptr ) continue ;
224
225 // Finally get barcodes of associated truth particles
226 numBarcodes.push_back(SiSpacePointRetrieverHelpers::getTruthBarcodes(idFirst, idSecond, PRDTruthColl, barcodes));
227
228 ATH_MSG_VERBOSE( "Found " << numBarcodes.back() << " common barcodes, now "
229 << barcodes.size() << " in total" );
230
231 } // loop over SpacePoint collection
232 } // loop over SpacePoint container
233 } //loop over SpacePoint - TruthMap collection pairs
234
235 //Now put together the DataMap
236 DataMap dataMap;
237 const auto sz = x.size();
238 dataMap["x"] = std::move(x);
239 dataMap["y"] = std::move(y);
240 dataMap["z"] = std::move(z);
241 dataMap["clusters multiple=\"2\""] = std::move(clusters);
242 dataMap["phiModule"] = std::move(phiModule);
243 dataMap["etaModule"] = std::move(etaModule);
244
245 //Only store truth associations if we retrieved them
246 if ( numBarcodes.size() > 0 ){
247 //Add barcodes counter
248 dataMap["numBarcodes"] = numBarcodes;
249 // Compute the "multiple" and put the barcodes vector in the map.
250 std::string bctag = "barcodes multiple=\""+DataType(barcodes.size()/double(numBarcodes.size())).toString()+"\"";
251 dataMap[bctag] = std::move(barcodes);
252 }
253
254 ATH_MSG_DEBUG( dataTypeName() << ": "<< sz );
255
256 //forward data to formating tool and return
257 return FormatTool->AddToEvent(dataTypeName(), "", &dataMap);
258 }
259
261 // Read Handle Key
262 ATH_CHECK(m_PixelSPContainerName.initialize());
263 ATH_CHECK(m_SCTSPContainerName.initialize());
266 m_useSCTTruthMap = !m_SCTPRDTruthName.key().empty();
268
269 return m_geo.retrieve();
270 }
271
272} //namespace
273
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
An STL vector of pointers that by default owns its pointed-to elements.
static Double_t sz
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
Handle class for reading from StoreGate.
#define y
#define x
#define z
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool is_valid() const
Check if id is in a valid state.
value_type get_compact() const
Get the compact id.
Templated class to convert any object that is streamable in a ostringstream in a string.
Definition DataType.h:21
SG::ReadHandleKey< SpacePointContainer > m_PixelSPContainerName
StoreGate key for Pixel space points.
SG::ReadHandleKey< SpacePointContainer > m_SCTSPContainerName
StoreGate key for SCT space points.
SiSpacePointRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
virtual std::string dataTypeName() const
Return the name of the data type.
bool m_usePixelTruthMap
StoreGate key for pixel PRD_MultiTruth.
virtual StatusCode initialize()
Only retrieve geo tool in initialize.
SG::ReadHandleKey< PRD_MultiTruthCollection > m_SCTPRDTruthName
bool m_useSCTTruthMap
StoreGate key for SCT PRD_MultiTruth.
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PixelPRDTruthName
const ToolHandle< IInDetGeoModelTool > m_geo
A tool handle to the geo model tool.
A PRD is mapped onto all contributing particles.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
ConstVectorMap globalPosition() const
Returns the global position of the pixel cluster.
Eigen::Matrix< double, 3, 1 > Vector3D
unsigned int getTruthBarcodes(const Identifier idFirst, const Identifier idSecond, const PRD_MultiTruthCollection *truthColl, DataVect &barcodes)
Get the barcodes of associated truth particles for a SpacePoint ( we require both clusters,...
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
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())