ATLAS Offline Software
Loading...
Searching...
No Matches
SiSpacePointRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "JiveXML/DataType.h"
8
11
18
19#include "CLHEP/Units/SystemOfUnits.h"
20
21namespace JiveXML
22{
23
30 SiSpacePointRetriever::SiSpacePointRetriever(const std::string& type,const std::string& name,const IInterface* parent):
31 AthAlgTool(type,name,parent)
32 {
33
34 //Declare the interface
35 declareInterface<IDataRetriever>(this);
36
37 //And the properties
38 declareProperty("PixelSpacePoints" , m_PixelSPContainerName = std::string("PixelSpacePoints"));
39 declareProperty("SCTSpacePoints" , m_SCTSPContainerName = std::string("SCT_SpacePoints"));
40 declareProperty("PRD_TruthPixel" , m_PixelPRDTruthName = std::string("PRD_MultiTruthPixel"));
41 declareProperty("PRD_TruthSCT" , m_SCTPRDTruthName = std::string("PRD_MultiTruthSCT"));
42 }
43
44 //Namespace for the helper functions
46
55 unsigned int getTruthBarcodes( const Identifier idFirst, const Identifier idSecond, const PRD_MultiTruthCollection* truthColl, DataVect& barcodes) {
56
57 //Make life easier
58 using PRDTruthIter = PRD_MultiTruthCollection::const_iterator;
59
60
66
67 //Sets of barcodes associated with first, second and both cluster
68 std::set<int> barcodesFirst;
69 std::set<int> barcodesSecond;
70 std::set<int> barcodesCommon;
71
72 //Get the set of particle barcodes associated with the first cluster identifier
73 std::pair<PRDTruthIter,PRDTruthIter> equalRangeFirst = truthColl->equal_range(idFirst);
74 for(PRDTruthIter TruthCollItr=equalRangeFirst.first; TruthCollItr!= equalRangeFirst.second; ++TruthCollItr)
75 barcodesFirst.insert(TruthCollItr->second.barcode());
76
77 //Check if we have only have one valid cluster identifier
78 if (! idSecond.is_valid()){
79
80 //Make this our list of barcodes (swap is O(1))
81 barcodesCommon.swap(barcodesFirst);
82
83 //otherwise only store barcodes associated with both identifiers
84 } else {
85
86 //Get the set of particle barcodes associated with the second cluster identifier
87 std::pair<PRDTruthIter,PRDTruthIter> equalRangeSecond = truthColl->equal_range(idSecond);
88 for(PRDTruthIter TruthCollItr=equalRangeSecond.first; TruthCollItr!= equalRangeSecond.second; ++TruthCollItr)
89 barcodesSecond.insert(TruthCollItr->second.barcode());
90
91 //Copy the list of particle barcodes that are associated with both clusters
92 std::set_intersection(barcodesFirst.begin(), barcodesFirst.end(), barcodesSecond.begin(), barcodesSecond.end(),
93 std::insert_iterator< std::set<int> >(barcodesCommon,barcodesCommon.begin()) );
94 }
95
96 //Finally add the list of barcodes to our DataVect
97 for (const auto barcodeCommon : barcodesCommon) barcodes.push_back(DataType(barcodeCommon));
98
99 //return the number of added barcodes
100 return barcodesCommon.size();
101 }
102
103 }//helpers namespace
104
109 StatusCode SiSpacePointRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
110
111 //be verbose
112 ATH_MSG_DEBUG( "Retrieving " << dataTypeName() );
113
117
119 if ( not PixelSPContainer.isValid() )
120 ATH_MSG_WARNING( "Unable to retrieve SpacePoint container with name " << m_PixelSPContainerName.key() );
121
123 if (m_usePixelTruthMap) {
124 PixelPRDTruthColl = SG::makeHandle(m_PixelPRDTruthName);
125 if ( not PixelPRDTruthColl.isValid() )
126 ATH_MSG_WARNING( "Unable to retrieve PRD_MultiTruth collection with name " << m_PixelPRDTruthName.key() );
127 }
128
130 if ( not SCTSPContainer.isValid() )
131 ATH_MSG_WARNING( "Unable to retrieve SpacePoint container with name " << m_SCTSPContainerName.key() );
132
134 if (m_useSCTTruthMap) {
135 SCTPRDTruthColl = SG::makeHandle(m_SCTPRDTruthName);
136 if ( not SCTPRDTruthColl.isValid() )
137 ATH_MSG_WARNING( "Unable to retrieve PRD_MultiTruth collection with name " << m_SCTPRDTruthName.key() );
138 }
139
143 using SpacePointTruthPair = std::pair<const SpacePointContainer *, const PRD_MultiTruthCollection *>;
144 std::vector<SpacePointTruthPair> SpacePointTruthPairList;
145
146 //Add Pixel if there is a collection
147 if (PixelSPContainer.isValid())
148 SpacePointTruthPairList.emplace_back(PixelSPContainer.cptr(), m_usePixelTruthMap ? PixelPRDTruthColl.cptr() : nullptr);
149
150 //Add SCT if there is a collection
151 if (SCTSPContainer.isValid())
152 SpacePointTruthPairList.emplace_back(SCTSPContainer.cptr(), m_useSCTTruthMap ? SCTPRDTruthColl.cptr() : nullptr);
153
157 int NSpacePoints = 0;
158 //Loop over all SpacePoint - PRDTruth pairs
159 for (const auto &SPTruthPair : SpacePointTruthPairList) {
160
161 //Add up the size of the SpacePoint collections in the container
162 for (const auto SpacePoint : *(SPTruthPair.first))
163 NSpacePoints += SpacePoint->size();
164 }
165
166 ATH_MSG_DEBUG( "Counted " << NSpacePoints << " in total" );
167
171 DataVect x; x.reserve(NSpacePoints);
172 DataVect y; y.reserve(NSpacePoints);
173 DataVect z; z.reserve(NSpacePoints);
174 DataVect clusters; clusters.reserve(NSpacePoints*2);
175 DataVect phiModule; phiModule.reserve(NSpacePoints);
176 DataVect etaModule; etaModule.reserve(NSpacePoints);
177 DataVect numBarcodes; numBarcodes.reserve(NSpacePoints);
178 DataVect barcodes; barcodes.reserve(NSpacePoints); // Usually less then one per space point
179
183
184 //Loop over all SpacePoint - PRDTruth pairs
185 for (const auto &SPTruthPair : SpacePointTruthPairList) {
186
187 // Loop over SpacePoint Collections in the SpacePoint container
188 for (const auto SpacePointColl : *(SPTruthPair.first)){
189
190 //Loop over SpacePoints themselves
191 for (const auto SpacePoint : *SpacePointColl) {
192
193 //Get the position of the space point
194 Amg::Vector3D point = SpacePoint->globalPosition();
195
196 //Store position in units of centimeters
197 x.push_back(DataType(point.x() * CLHEP::mm/CLHEP::cm));
198 y.push_back(DataType(point.y() * CLHEP::mm/CLHEP::cm));
199 z.push_back(DataType(point.z() * CLHEP::mm/CLHEP::cm));
200
201 //Get the cluster list for the Space point (first and second)
202 const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*> clusterList = SpacePoint->clusterList();
203
204 //Get the identifiers of the first and second cluster
205 Identifier idFirst = clusterList.first->identify();
206 Identifier idSecond = (clusterList.second != NULL) ? clusterList.second->identify() : Identifier();
207
208 //Get phi and eta of the module in detector coordinates of the first cluster
209 if (clusterList.first->type(Trk::PrepRawDataType::SCT_Cluster)) {
210 phiModule.push_back(DataType(m_geo->SCTIDHelper()->phi_module(idFirst)));
211 etaModule.push_back(DataType(m_geo->SCTIDHelper()->eta_module(idFirst)));
212 }
213 else {
214 phiModule.push_back(DataType(m_geo->PixelIDHelper()->phi_module(idFirst)));
215 etaModule.push_back(DataType(m_geo->PixelIDHelper()->eta_module(idFirst)));
216 }
217
218 // Store the cluster(s) identifier (pair)
219 clusters.push_back(DataType(idFirst.get_compact()));
220 clusters.push_back((idSecond.is_valid()) ? DataType(idSecond.get_compact()) : DataType(-1));
221
222 //Stop here if there is no truth
223 const PRD_MultiTruthCollection* PRDTruthColl = SPTruthPair.second;
224 if ( PRDTruthColl == nullptr ) continue ;
225
226 // Finally get barcodes of associated truth particles
227 numBarcodes.push_back(SiSpacePointRetrieverHelpers::getTruthBarcodes(idFirst, idSecond, PRDTruthColl, barcodes));
228
229 ATH_MSG_VERBOSE( "Found " << numBarcodes.back() << " common barcodes, now "
230 << barcodes.size() << " in total" );
231
232 } // loop over SpacePoint collection
233 } // loop over SpacePoint container
234 } //loop over SpacePoint - TruthMap collection pairs
235
236 //Now put together the DataMap
237 DataMap dataMap;
238 const auto sz = x.size();
239 dataMap["x"] = std::move(x);
240 dataMap["y"] = std::move(y);
241 dataMap["z"] = std::move(z);
242 dataMap["clusters multiple=\"2\""] = std::move(clusters);
243 dataMap["phiModule"] = std::move(phiModule);
244 dataMap["etaModule"] = std::move(etaModule);
245
246 //Only store truth associations if we retrieved them
247 if ( numBarcodes.size() > 0 ){
248 //Add barcodes counter
249 dataMap["numBarcodes"] = numBarcodes;
250 // Compute the "multiple" and put the barcodes vector in the map.
251 std::string bctag = "barcodes multiple=\""+DataType(barcodes.size()/double(numBarcodes.size())).toString()+"\"";
252 dataMap[bctag] = std::move(barcodes);
253 }
254
255 ATH_MSG_DEBUG( dataTypeName() << ": "<< sz );
256
257 //forward data to formating tool and return
258 return FormatTool->AddToEvent(dataTypeName(), "", &dataMap);
259 }
260
262 // Read Handle Key
263 ATH_CHECK(m_PixelSPContainerName.initialize());
264 ATH_CHECK(m_SCTSPContainerName.initialize());
267 m_useSCTTruthMap = !m_SCTPRDTruthName.key().empty();
269
270 return m_geo.retrieve();
271 }
272
273} //namespace
274
#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
defines an "iterator" over instances of a given type in StoreGateSvc
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.
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())