ATLAS Offline Software
SiSpacePointRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "StoreGate/DataHandle.h"
7 #include "JiveXML/DataType.h"
8 
10 #include "StoreGate/ReadHandle.h"
11 
13 #include "InDetIdentifier/SCT_ID.h"
18 
19 #include "CLHEP/Units/SystemOfUnits.h"
20 
21 namespace JiveXML
22 {
23 
30  SiSpacePointRetriever::SiSpacePointRetriever(const std::string& type,const std::string& name,const IInterface* 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
45  namespace SiSpacePointRetrieverHelpers {
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 
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 
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 
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
238  dataMap["x"] = x;
239  dataMap["y"] = y;
240  dataMap["z"] = z;
241  dataMap["clusters multiple=\"2\""] = clusters;
242  dataMap["phiModule"] = phiModule;
243  dataMap["etaModule"] = 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] = barcodes;
252  }
253 
254  ATH_MSG_DEBUG( dataTypeName() << ": "<< x.size() );
255 
256  //forward data to formating tool and return
257  return FormatTool->AddToEvent(dataTypeName(), "", &dataMap);
258  }
259 
261  // Read Handle Key
268 
269  return m_geo.retrieve();
270  }
271 
272 } //namespace
273 
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
DataType.h
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
JiveXML::SiSpacePointRetriever::m_SCTPRDTruthName
SG::ReadHandleKey< PRD_MultiTruthCollection > m_SCTPRDTruthName
Definition: SiSpacePointRetriever.h:70
JiveXML::SiSpacePointRetriever::initialize
virtual StatusCode initialize()
Only retrieve geo tool in initialize.
Definition: SiSpacePointRetriever.cxx:260
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
JiveXML::SiSpacePointRetriever::SiSpacePointRetriever
SiSpacePointRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: SiSpacePointRetriever.cxx:30
SG::ReadHandle< SpacePointContainer >
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PRD_MultiTruthCollection
A PRD is mapped onto all contributing particles.
Definition: PRD_MultiTruthCollection.h:24
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
x
#define x
DataHandle.h
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
PrepRawData.h
SpacePoint
Definition: Trigger/TrigAccel/TrigCudaFitter/src/SpacePoint.h:6
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
JiveXML::SiSpacePointRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: SiSpacePointRetriever.cxx:109
JiveXML::SiSpacePointRetrieverHelpers::getTruthBarcodes
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,...
Definition: SiSpacePointRetriever.cxx:55
SpacePointCollection.h
python.Dumpers.barcodes
def barcodes(beg, end, sz)
Definition: Dumpers.py:2800
z
#define z
JiveXML::DataType
Templated class to convert any object that is streamable in a ostringstream in a string.
Definition: DataType.h:21
LArHistMerge_trf.dataMap
dataMap
Definition: LArHistMerge_trf.py:218
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SpacePoint.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SpacePointCLASS_DEF.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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
JiveXML::SiSpacePointRetriever::m_useSCTTruthMap
bool m_useSCTTruthMap
StoreGate key for SCT PRD_MultiTruth.
Definition: SiSpacePointRetriever.h:69
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:21
JiveXML::SiSpacePointRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: SiSpacePointRetriever.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
JiveXML::SiSpacePointRetriever::m_geo
const ToolHandle< IInDetGeoModelTool > m_geo
A tool handle to the geo model tool.
Definition: SiSpacePointRetriever.h:56
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
JiveXML::SiSpacePointRetriever::m_PixelSPContainerName
SG::ReadHandleKey< SpacePointContainer > m_PixelSPContainerName
StoreGate key for Pixel space points.
Definition: SiSpacePointRetriever.h:59
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
y
#define y
TRT::Hit::phiModule
@ phiModule
Definition: HitInfo.h:80
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
Trk::PrepRawDataType::SCT_Cluster
@ SCT_Cluster
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
JiveXML::SiSpacePointRetriever::m_PixelPRDTruthName
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PixelPRDTruthName
Definition: SiSpacePointRetriever.h:66
ReadHandle.h
Handle class for reading from StoreGate.
AthAlgTool
Definition: AthAlgTool.h:26
set_intersection
Set * set_intersection(Set *set1, Set *set2)
Perform an intersection of two sets.
SiSpacePointRetriever.h
JiveXML::SiSpacePointRetriever::m_SCTSPContainerName
SG::ReadHandleKey< SpacePointContainer > m_SCTSPContainerName
StoreGate key for SCT space points.
Definition: SiSpacePointRetriever.h:62
JiveXML::SiSpacePointRetriever::m_usePixelTruthMap
bool m_usePixelTruthMap
StoreGate key for pixel PRD_MultiTruth.
Definition: SiSpacePointRetriever.h:65