Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PixelClusterTruthDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
10 namespace ActsTrk {
11 
13  ISvcLocator *pSvcLocator) :
14  AthReentrantAlgorithm(name, pSvcLocator)
15  {}
16 
18  ATH_MSG_DEBUG("Initialize " << name() << " ...");
19 
20  // Read keys
24 
25  // Write keys
26  ATH_CHECK(m_write_xaod_key.initialize());
27 
28  // Decorators
31 
47 
50 
52  ATH_CHECK(m_measurement_waferID.initialize());
53  ATH_CHECK(m_measurement_bec.initialize());
54  ATH_CHECK(m_measurement_layer.initialize());
55  ATH_CHECK(m_measurement_sizePhi.initialize());
56  ATH_CHECK(m_measurement_sizeZ.initialize());
57  ATH_CHECK(m_measurement_SiWidth.initialize());
58  ATH_CHECK(m_measurement_eta_module.initialize());
59  ATH_CHECK(m_measurement_phi_module.initialize());
60  ATH_CHECK(m_measurement_omegax.initialize());
61  ATH_CHECK(m_measurement_omegay.initialize());
65  ATH_CHECK(m_measurement_side.initialize());
66 
67  ATH_CHECK( m_lorentzAngleTool.retrieve() );
68  ATH_CHECK( detStore()->retrieve(m_PixelHelper, "PixelID") );
69 
70  return StatusCode::SUCCESS;
71  }
72 
73  StatusCode PixelClusterTruthDecoratorAlg::execute(const EventContext& ctx) const {
74 
75  //Mandatory. Require if the algorithm is scheduled.
79 
81  ATH_CHECK(pixelDetEleHandle.isValid());
82  const InDetDD::SiDetectorElementCollection* pixelDetEle = pixelDetEleHandle.cptr();
83 
84  // Get the truth association map
85  const MeasurementToTruthParticleAssociation* measToTruth(nullptr);
86  if (m_useTruthInfo) {
88  ATH_CHECK(measToTruthHandle.isValid());
89  measToTruth = measToTruthHandle.cptr();
90  }
91 
92  // Setup outputs
93  // Create the xAOD container and its auxiliary store:
95  ATH_CHECK(xaod.record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),
96  std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>()));
97 
98  // Decorations
114 
115 
116  // Create output collection
117  xAOD::TrackMeasurementValidationContainer *measurements = xaod.ptr();
118  std::vector<xAOD::TrackMeasurementValidation*> toAdd(clusters->size(), nullptr);
119  for (std::size_t i(0); i<toAdd.size(); ++i) {
121  }
122  measurements->insert(measurements->end(), toAdd.begin(), toAdd.end());
123 
124 
125  // loop over collection and convert to xAOD::TrackMeasurementValidation
126  for (std::size_t i(0); i<clusters->size(); ++i) {
127  const xAOD::PixelCluster* cluster = clusters->at(i);
128  xAOD::TrackMeasurementValidation* measurement = measurements->at(i);
129 
130  xAOD::DetectorIdentType clusterId = cluster->identifier();
131  xAOD::DetectorIDHashType hashId = cluster->identifierHash();
132 
133  const InDetDD::SiDetectorElement *element = pixelDetEle->getDetectorElement(hashId);
134  if ( not element ) {
135  ATH_MSG_FATAL( "Invalid pixel detector element for hash " << hashId );
136  return StatusCode::FAILURE;
137  }
138 
139  const std::vector<Identifier> rdoList = cluster->rdoList();
140  std::vector< std::uint64_t > rdoIdentifierList;
141  rdoIdentifierList.reserve(rdoList.size());
142  int rowmin = std::numeric_limits<int>::max();
143  int rowmax = std::numeric_limits<int>::min();
144  int colmin = std::numeric_limits<int>::max();
145  int colmax = std::numeric_limits<int>::min();
146  for( const Identifier& hitIdentifier : rdoList ){
147  rdoIdentifierList.push_back( hitIdentifier.get_compact() );
148  //May want to addinformation about the individual hits here
149  int row = m_PixelHelper->phi_index(hitIdentifier);
150  int col = m_PixelHelper->eta_index(hitIdentifier);
151  rowmin = std::min(rowmin, row);
152  rowmax = std::max(rowmax, row);
153  colmin = std::min(colmin, col);
154  colmax = std::max(colmax, col);
155  }
156 
157  // compute centroid
158  const InDetDD::PixelModuleDesign* design = dynamic_cast<const InDetDD::PixelModuleDesign*>(&element->design());
159  if (not design) {
160  ATH_MSG_ERROR("Cannot retrieve detector design");
161  return StatusCode::FAILURE;
162  }
163  InDetDD::SiLocalPosition pos1 = design->positionFromColumnRow(colmin,rowmin);
164  InDetDD::SiLocalPosition pos2 = design->positionFromColumnRow(colmax,rowmin);
165  InDetDD::SiLocalPosition pos3 = design->positionFromColumnRow(colmin,rowmax);
166  InDetDD::SiLocalPosition pos4 = design->positionFromColumnRow(colmax,rowmax);
167  InDetDD::SiLocalPosition centroid = 0.25 * (pos1 + pos2 + pos3 + pos4);
168 
169  //Set Identifier
170  measurement->setIdentifier( clusterId );
171  measurement->setRdoIdentifierList(std::move(rdoIdentifierList));
172 
173  //Set Global Position
174  auto gpos = cluster->globalPosition();
175  measurement->setGlobalPosition(gpos.x(), gpos.y(), gpos.z());
176 
177  // Set local position and error matrix
178  auto locpos = cluster->localPosition<2>();
179  measurement->setLocalPosition(locpos[0], locpos[1]);
180 
181  auto localCov = cluster->localCovariance<2>();
182  measurement->setLocalPositionError( localCov(0,0), localCov(1,1), localCov(0,1) );
183 
184  const Identifier waferId = m_PixelHelper->wafer_id(hashId);
185  decor_detectorElementID(*measurement) = hashId;
186  decor_waferID(*measurement) = waferId.get_compact();
187  decor_bec(*measurement) = m_PixelHelper->barrel_ec(waferId);
188  decor_layer(*measurement) = m_PixelHelper->layer_disk(waferId);
189  decor_sizePhi(*measurement) = cluster->channelsInPhi();
190  decor_sizeZ(*measurement) = cluster->channelsInEta();
191  decor_SiWidth(*measurement) = cluster->channelsInPhi();
192  decor_eta_module(*measurement) = m_PixelHelper->eta_module(waferId);
193  decor_phi_module(*measurement) = m_PixelHelper->phi_module(waferId);
194  decor_omegax(*measurement) = cluster->omegaX();
195  decor_omegay(*measurement) = cluster->omegaY();
196  decor_LorentzShift(*measurement) = static_cast<float>( m_lorentzAngleTool->getLorentzShift(cluster->identifierHash(), ctx) );
197  decor_centroid_xphi(*measurement) = centroid.xPhi();
198  decor_centroid_xeta(*measurement) = centroid.xEta();
199  decor_side(*measurement) = 0;
200  }
201 
202 
203  // handle the truth
204  if (m_useTruthInfo) {
207 
208  for (std::size_t i(0); i<clusters->size(); ++i) {
209  const xAOD::PixelCluster* cluster = clusters->at(i);
210  xAOD::TrackMeasurementValidation* measurement = measurements->at(i);
211 
212  // Use the MultiTruth Collection
213  // to get a list of all true particle contributing to the cluster
214  if (cluster->index() >= measToTruth->size()) {
215  ATH_MSG_ERROR( "PRD index "<< cluster->index() << " not present in the measurement to truth vector with size " << measToTruth->size() );
216  return StatusCode::FAILURE;
217  }
218 
219  auto tps = measToTruth->at(cluster->index());
220 
221  std::vector<unsigned int> tp_indices;
222  std::vector<unsigned int> tp_barcodes;
223  for (const auto& tp : tps) {
224  tp_indices.push_back(tp->index());
225  tp_barcodes.push_back(HepMC::barcode(tp));
226  }
227 
228  // decorate
229  decor_truth_indices(*measurement) = std::move(tp_indices);
230  decor_truth_barcode(*measurement) = std::move(tp_barcodes);
231 
232  } // loop on clusters/measurements
233  } // if do truth
234 
235  ATH_MSG_DEBUG( " recorded PixelPrepData objects: size " << measurements->size() );
236  return StatusCode::SUCCESS;
237 }
238 
239 }
240 
241 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
query_example.row
row
Definition: query_example.py:24
ActsTrk::PixelClusterTruthDecoratorAlg::m_PixelHelper
const PixelID * m_PixelHelper
Definition: PixelClusterTruthDecoratorAlg.h:76
ActsTrk::PixelClusterTruthDecoratorAlg::PixelClusterTruthDecoratorAlg
PixelClusterTruthDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelClusterTruthDecoratorAlg.cxx:12
xAOD::DetectorIdentType
long unsigned int DetectorIdentType
Definition: MeasurementDefs.h:44
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
PixelID::phi_index
int phi_index(const Identifier &id) const
Definition: PixelID.h:658
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
InDetDD::PixelModuleDesign
Definition: PixelModuleDesign.h:48
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_centroid_xphi
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_centroid_xphi
Definition: PixelClusterTruthDecoratorAlg.h:71
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAOD::TrackMeasurementValidation
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
Definition: TrackMeasurementValidation.h:13
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_centroid_xeta
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_centroid_xeta
Definition: PixelClusterTruthDecoratorAlg.h:72
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_phi_module
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_phi_module
Definition: PixelClusterTruthDecoratorAlg.h:67
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:210
ParticleTest.tp
tp
Definition: ParticleTest.py:25
Identifier::get_compact
value_type get_compact() const
Get the compact id.
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_layer
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_layer
Definition: PixelClusterTruthDecoratorAlg.h:62
ActsTrk::PixelClusterTruthDecoratorAlg::m_clustercontainer_key
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_clustercontainer_key
Definition: PixelClusterTruthDecoratorAlg.h:50
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_bec
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_bec
Definition: PixelClusterTruthDecoratorAlg.h:61
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_LorentzShift
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_LorentzShift
Definition: PixelClusterTruthDecoratorAlg.h:70
xAOD::TrackMeasurementValidation_v1::setRdoIdentifierList
void setRdoIdentifierList(const std::vector< uint64_t > &rdoIdentifierList)
Sets the list of RDO identifiers.
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_sizeZ
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_sizeZ
Definition: PixelClusterTruthDecoratorAlg.h:64
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_eta_module
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_eta_module
Definition: PixelClusterTruthDecoratorAlg.h:66
ActsTrk::MeasurementToTruthParticleAssociation
Definition: MeasurementToTruthParticleAssociation.h:18
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:364
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
InDetDD::SiLocalPosition
Definition: SiLocalPosition.h:31
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
PixelClusterTruthDecoratorAlg.h
xAOD::TrackMeasurementValidation_v1
Class describing a TrackMeasurementValidation.
Definition: TrackMeasurementValidation_v1.h:27
ActsTrk::PixelClusterTruthDecoratorAlg::m_associationMap_key
SG::ReadHandleKey< ActsTrk::MeasurementToTruthParticleAssociation > m_associationMap_key
Definition: PixelClusterTruthDecoratorAlg.h:51
ActsTrk::PixelClusterTruthDecoratorAlg::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: PixelClusterTruthDecoratorAlg.h:52
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_truth_barcodes
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_truth_barcodes
Definition: PixelClusterTruthDecoratorAlg.h:57
xAOD::TrackMeasurementValidation_v1::setLocalPosition
void setLocalPosition(float localX, float localY)
Sets the local position.
lumiFormat.i
int i
Definition: lumiFormat.py:85
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_omegay
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_omegay
Definition: PixelClusterTruthDecoratorAlg.h:69
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_side
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_side
Definition: PixelClusterTruthDecoratorAlg.h:73
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_truth_indices
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_truth_indices
Definition: PixelClusterTruthDecoratorAlg.h:56
PixelID::eta_index
int eta_index(const Identifier &id) const
Definition: PixelID.h:664
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector::insert
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
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
xAOD::TrackMeasurementValidation_v1::setIdentifier
void setIdentifier(uint64_t identifier)
Sets the identifier.
ActsTrk::PixelClusterTruthDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: PixelClusterTruthDecoratorAlg.cxx:73
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_waferID
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_waferID
Definition: PixelClusterTruthDecoratorAlg.h:60
ActsTrk::PixelClusterTruthDecoratorAlg::m_useTruthInfo
Gaudi::Property< bool > m_useTruthInfo
Definition: PixelClusterTruthDecoratorAlg.h:75
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DeMoUpdate.toAdd
bool toAdd
Definition: DeMoUpdate.py:1304
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ActsTrk::PixelClusterTruthDecoratorAlg::m_lorentzAngleTool
ToolHandle< ISiLorentzAngleTool > m_lorentzAngleTool
Definition: PixelClusterTruthDecoratorAlg.h:48
ActsTrk::PixelClusterTruthDecoratorAlg::m_write_xaod_key
SG::WriteHandleKey< xAOD::TrackMeasurementValidationContainer > m_write_xaod_key
Definition: PixelClusterTruthDecoratorAlg.h:53
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
PixelID::eta_module
int eta_module(const Identifier &id) const
Definition: PixelID.h:651
xAOD::TrackMeasurementValidation_v1::setGlobalPosition
void setGlobalPosition(float globalX, float globalY, float globalZ)
Sets the global position.
Definition: TrackMeasurementValidation_v1.cxx:50
xAOD::PixelClusterContainer
PixelClusterContainer_v1 PixelClusterContainer
Define the version of the pixel cluster container.
Definition: Event/xAOD/xAODInDetMeasurement/xAODInDetMeasurement/PixelClusterContainer.h:14
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::DetectorIDHashType
unsigned int DetectorIDHashType
@ detector ID element hash
Definition: MeasurementDefs.h:43
xAOD::TrackMeasurementValidation_v1::setLocalPositionError
void setLocalPositionError(float localXError, float localYError, float localXYCorrelation)
Sets the local position error.
Definition: TrackMeasurementValidation_v1.cxx:37
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
query_example.col
col
Definition: query_example.py:7
SiDetectorElement.h
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_sizePhi
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_sizePhi
Definition: PixelClusterTruthDecoratorAlg.h:63
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_detectorElementID
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_detectorElementID
Definition: PixelClusterTruthDecoratorAlg.h:59
xAOD::PixelCluster_v1
Definition: PixelCluster_v1.h:17
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
PixelModuleDesign.h
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
ActsTrk::PixelClusterTruthDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: PixelClusterTruthDecoratorAlg.cxx:17
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:55
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_omegax
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_omegax
Definition: PixelClusterTruthDecoratorAlg.h:68
PixelID::phi_module
int phi_module(const Identifier &id) const
Definition: PixelID.h:644
ActsTrk::PixelClusterTruthDecoratorAlg::m_measurement_SiWidth
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_SiWidth
Definition: PixelClusterTruthDecoratorAlg.h:65
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:15
NSWL1::centroid
Vertex centroid(const Polygon &p)
Definition: GeoUtils.cxx:59
HepMCHelpers.h
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:71
Identifier
Definition: IdentifierFieldParser.cxx:14