72{
73
74 std::map<Identifier, const SCT_RDORawData*> idToRAWDataMap;
76 SG::ReadHandle<SCT_RDO_Container> rdoContainer{
m_rdoContainer, ctx};
78
79 for (const auto collection: *rdoContainer) {
80
81 for (const auto rdo : *collection) {
82 if (rdo==nullptr) {
84 continue;
85 }
86 Identifier rdoId{rdo->identify()};
87 idToRAWDataMap.insert(std::pair<Identifier, const SCT_RDORawData*>{rdoId, rdo});
88 }
89 }
92 }
93 }
94 ATH_MSG_DEBUG(
"Size of RDO map is " << idToRAWDataMap.size());
95
96 const PRD_MultiTruthCollection* prdmtColl{nullptr};
97 const xAODTruthParticleLinkVector *truth_particle_links{nullptr};
99 SG::ReadHandle<PRD_MultiTruthCollection> prdmtCollHandle{
m_multiTruth, ctx};
100 if (prdmtCollHandle.
isValid()) {
101 prdmtColl = &*prdmtCollHandle;
102 }
104 SG::ReadHandle<xAODTruthParticleLinkVector> truthParticleLinksHandle{
m_truthParticleLinks, ctx};
105 if (truthParticleLinksHandle.
isValid()) {
106 truth_particle_links = truthParticleLinksHandle.
cptr();
107 }
108 }
109 }
110
111 const InDetSimDataCollection* sdoCollection{nullptr};
113 SG::ReadHandle<InDetSimDataCollection> sdoCollectionHandle{
m_SDOcontainer, ctx};
114 if (sdoCollectionHandle.
isValid()) {
115 sdoCollection = &*sdoCollectionHandle;
116 }
117 }
118
119 std::vector<std::vector<const SiHit*>> siHits(
m_SCTHelper->wafer_hash_max());
122
123
124
125
126
127 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEleHandle{
m_SCTDetEleCollKey, ctx};
128 const InDetDD::SiDetectorElementCollection* sctElements =
129 sctDetEleHandle.
isValid() ? sctDetEleHandle.
cptr() :
nullptr;
130 if (sihitCollection.
isValid()) {
131 for (const SiHit& siHit: *sihitCollection) {
132
133 if (not siHit.isSCT()) continue;
134
135 Identifier wafer_id{
m_SCTHelper->wafer_id(siHit.getBarrelEndcap(),
136 siHit.getLayerDisk(),
137 siHit.getPhiModule(),
138 siHit.getEtaModule(),
139 siHit.getSide())};
140 IdentifierHash wafer_hash{
m_SCTHelper->wafer_hash(wafer_id)};
141
142 if (sctElements) {
143 const InDetDD::SiDetectorElement* baseEl = sctElements->
getDetectorElement(wafer_hash);
144 if (baseEl) {
145 const auto* design =
146 dynamic_cast<const InDetDD::SCT_ModuleSideDesign*
>(&baseEl->
design());
147 const InDetDD::SCT_ModuleSideDesign* mother = design ? design->getMother() : nullptr;
148 if (mother) {
149 HepGeom::Point3D<double>
avg{siHit.localStartPosition() + siHit.localEndPosition()};
151
153 const InDetDD::SiLocalPosition slp(
p3.y(),
p3.x());
156 const int rowOffset = mother->
getStripRow(mDiode).second;
157 if (rowOffset != 0) {
158 const Identifier child_id{
m_SCTHelper->wafer_id(siHit.getBarrelEndcap(),
159 siHit.getLayerDisk(),
160 siHit.getPhiModule(),
161 siHit.getEtaModule() + rowOffset,
162 siHit.getSide())};
164 }
165 }
166 }
167 }
168 }
169
170 if (wafer_hash < siHits.size()) {
171 siHits[wafer_hash].push_back(&siHit);
172 } else {
174 << siHit.getEtaModule() << ", hash " << wafer_hash << "), dropped");
175 }
176 }
177 }
178 }
179
180
181 SG::ReadHandle<InDet::SCT_ClusterContainer> sctClusterContainer{
m_clustercontainer, ctx};
182 if (not sctClusterContainer.
isValid()) {
184 return StatusCode::FAILURE;
185 }
186
187
188 SG::WriteHandle<xAOD::TrackMeasurementValidationContainer> xaod{
m_xAodContainer, ctx};
189 ATH_CHECK(xaod.
record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),
190 std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>()));
191
192 SG::WriteHandle<std::vector<unsigned int>> offsets{
m_xAodOffset, ctx};
194
195 unsigned int have_truth_link=0
u;
196 unsigned int missing_truth_particle=0
u;
197 unsigned int missing_parent_particle=0
u;
198
200 for (const auto clusterCollection: *sctClusterContainer) {
201
202 (*offsets)[clusterCollection->identifyHash()] =
counter;
203
204
205 if (clusterCollection->empty()) continue;
206
207 xaod->resize(counter + clusterCollection->size());
208
209 for (const InDet::SCT_Cluster* prd: *clusterCollection) {
210 Identifier clusterId{prd->identify()};
213 }
214
215
217 xaod->at(counter) = xprd;
219
220
222
223
226
227
230 float locX{
static_cast<float>(locpos.x())};
231 if ((not std::isinf(locpos.y()) or std::isnan(locpos.y()))) {
232 if (locpos.y()>=1e-07)
locY = locpos.y();
233 } else {
235 }
236
237
239
241 if (localCov.size() == 1) {
243 } else if (localCov.size() == 4) {
245 } else {
247 }
248
249
250 std::vector<uint64_t> rdoIdentifierList;
251 rdoIdentifierList.reserve(prd->rdoList().size());
252 for (const auto& hitIdentifier: prd->rdoList()) {
253 rdoIdentifierList.push_back(hitIdentifier.get_compact());
254 }
256
257
258 const InDet::SiWidth cw{prd->width()};
259 AUXDATA(xprd,
int, SiWidth) =
static_cast<int>(cw.
colRow()[0]);
260 AUXDATA(xprd,
int, hitsInThirdTimeBin) =
static_cast<int>(prd->hitsInThirdTimeBin());
261
267
268
269 const InDetDD::SiDetectorElement* de{prd->detectorElement()};
270
272 if (de) {
276 }
277 }
278 AUXDATA(xprd, uint64_t, detectorElementID) = detElementId;
279
280
283 }
284
285
287 if (prdmtColl) {
288 auto range{prdmtColl->equal_range(clusterId)};
289 if (truth_particle_links) {
290 std::vector<unsigned int> tp_indices;
292 ElementLink<xAOD::TruthParticleContainer> a_truth_particle_link = truth_particle_links->
find(
i->second);
293 if (a_truth_particle_link) {
295 if (truth_particle) {
296 ++have_truth_link;
297 tp_indices.push_back(static_cast<int>(truth_particle->index()));
298 }
299 else {
300 ++missing_parent_particle;
301 }
302 }
303 else {
304 tp_indices.push_back(std::numeric_limits<unsigned int>::max());
305 ++missing_truth_particle;
306 }
307 }
308 AUXDATA(xprd, std::vector<unsigned int>, truth_index) = std::move(tp_indices);
309 }
310 std::vector<int> uniqueIDs;
313 }
314 AUXDATA(xprd, std::vector<int>, truth_barcode) = std::move(uniqueIDs);
315 }
316 }
317
318
319
320 std::vector<std::vector<int>> sdoTruthUIDs;
322 if (sdoCollection) {
324 }
325 }
326
327
328
330 addSiHitInformation(xprd, prd, &siHits[prd->detectorElement()->identifyHash()], sdoTruthUIDs);
331 }
332 }
333 }
334 ATH_MSG_DEBUG(
" recorded SCT_PrepData objects: size " << xaod->size());
335
340
341 return StatusCode::SUCCESS;
342}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_FATAL(x,...)
bool is_valid() const
Check if id is in a valid state.
value_type get_compact() const
Get the compact id.
virtual SiCellId cellIdOfPosition(const SiLocalPosition &localPos) const =0
position -> id
virtual std::pair< int, int > getStripRow(SiCellId id) const
Get the strip and row number of the cell.
bool isValid() const
Test if its in a valid state.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
virtual Identifier identify() const override final
identifier of this detector element (inline)
const Amg::Vector2D & colRow() const
std::atomic< unsigned int > m_missingParentParticle
SG::ReadHandleKey< SiHitCollection > m_sihitContainer
SG::ReadHandleKey< PRD_MultiTruthCollection > m_multiTruth
SG::ReadHandleKey< SCT_RDO_Container > m_rdoContainer
BooleanProperty m_writeSDOs
SG::ReadHandleKey< InDetSimDataCollection > m_SDOcontainer
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
std::atomic_bool m_firstEventWarnings
BooleanProperty m_writeSiHits
SG::WriteHandleKey< xAOD::TrackMeasurementValidationContainer > m_xAodContainer
std::vector< std::vector< int > > addSDOInformation(xAOD::TrackMeasurementValidation *xprd, const InDet::SCT_Cluster *prd, const InDetSimDataCollection *sdoCollection) const
Decorate the cluster with SDO truth information and return, per RDO, the uniqueIDs of the truth parti...
SG::WriteHandleKey< std::vector< unsigned int > > m_xAodOffset
void addSiHitInformation(xAOD::TrackMeasurementValidation *xprd, const InDet::SCT_Cluster *prd, const std::vector< const SiHit * > *siHits, const std::vector< std::vector< int > > &sdoTruthUIDs) const
BooleanProperty m_writeRDOinformation
SG::ReadHandleKey< xAODTruthParticleLinkVector > m_truthParticleLinks
std::atomic< unsigned int > m_missingTruthParticle
SG::ReadHandleKey< InDet::SCT_ClusterContainer > m_clustercontainer
void addRDOInformation(xAOD::TrackMeasurementValidation *, const InDet::SCT_Cluster *, const std::map< Identifier, const SCT_RDORawData * > &idToRAWDataMap) const
std::atomic< unsigned int > m_haveTruthLink
BooleanProperty m_useTruthInfo
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ElementLink< xAOD::TruthParticleContainer > find(const HepMcParticleLink &hepMCLink) const
void setRdoIdentifierList(const std::vector< uint64_t > &rdoIdentifierList)
Sets the list of RDO identifiers.
void setLocalPositionError(float localXError, float localYError, float localXYCorrelation)
Sets the local position error.
void setLocalPosition(float localX, float localY)
Sets the local position.
void setIdentifier(uint64_t identifier)
Sets the identifier.
void setGlobalPosition(float globalX, float globalY, float globalZ)
Sets the global position.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
@ u
Enums for curvilinear frames.
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.