12 #include "Identifier/Identifier.h"
22 #include "CLHEP/Geometry/Point3D.h"
26 #define AUXDATA(OBJ, TYP, NAME) \
27 static const SG::AuxElement::Accessor<TYP> acc_##NAME (#NAME); acc_##NAME(*(OBJ))
65 return StatusCode::SUCCESS;
76 std::map<Identifier, const SCT_RDORawData*> idToRAWDataMap;
79 if (rdoContainer.isValid()) {
81 for (
const auto collection: *rdoContainer) {
83 for (
const auto rdo : *collection) {
89 idToRAWDataMap.insert(std::pair<Identifier, const SCT_RDORawData*>{rdoId, rdo});
96 ATH_MSG_DEBUG(
"Size of RDO map is " << idToRAWDataMap.size());
102 if (prdmtCollHandle.isValid()) {
103 prdmtColl = &*prdmtCollHandle;
107 if (truthParticleLinksHandle.isValid()) {
108 truth_particle_links = truthParticleLinksHandle.cptr();
116 if (sdoCollectionHandle.isValid()) {
117 sdoCollection = &*sdoCollectionHandle;
124 if (sihitCollection.isValid()) {
125 for (
const SiHit& siHit: *sihitCollection) {
127 if (not siHit.isSCT())
continue;
130 siHit.getLayerDisk(),
131 siHit.getPhiModule(),
132 siHit.getEtaModule(),
135 siHits[wafer_hash].push_back(&siHit);
142 if (not sctClusterContainer.isValid()) {
144 return StatusCode::FAILURE;
149 ATH_CHECK(xaod.record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),
150 std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>()));
155 unsigned int have_truth_link=0
u;
156 unsigned int missing_truth_particle=0
u;
157 unsigned int missing_parent_particle=0
u;
160 for (
const auto clusterCollection: *sctClusterContainer) {
162 (*offsets)[clusterCollection->identifyHash()] =
counter;
165 if (clusterCollection->empty())
continue;
167 xaod->resize(
counter + clusterCollection->size());
171 if (not clusterId.is_valid()) {
181 xprd->setIdentifier(clusterId.get_compact());
185 xprd->setGlobalPosition(gpos.x(), gpos.y(), gpos.z());
190 float locX{
static_cast<float>(locpos.x())};
191 if ((not std::isinf(locpos.y()) or std::isnan(locpos.y()))) {
192 if (locpos.y()>=1
e-07)
locY = locpos.y();
201 if (localCov.size() == 1) {
202 xprd->setLocalPositionError(localCov(0, 0), 0., 0.);
203 }
else if (localCov.size() == 4) {
204 xprd->setLocalPositionError(localCov(0, 0), localCov(1, 1), localCov(0, 1));
206 xprd->setLocalPositionError(0., 0., 0.);
210 std::vector<uint64_t> rdoIdentifierList;
211 rdoIdentifierList.reserve(prd->rdoList().size());
212 for (
const auto& hitIdentifier: prd->rdoList()) {
213 rdoIdentifierList.push_back(hitIdentifier.get_compact());
215 xprd->setRdoIdentifierList(rdoIdentifierList);
219 AUXDATA(xprd,
int, SiWidth) =
static_cast<int>(cw.colRow()[0]);
220 AUXDATA(xprd,
int, hitsInThirdTimeBin) =
static_cast<int>(prd->hitsInThirdTimeBin());
233 if (detId.is_valid()) {
234 detElementId = detId.get_compact();
247 auto range{prdmtColl->equal_range(clusterId)};
248 if (truth_particle_links) {
249 std::vector<unsigned int> tp_indices;
252 if (a_truth_particle_link) {
254 if (truth_particle) {
256 tp_indices.push_back(
static_cast<int>(truth_particle->
index()));
259 ++missing_parent_particle;
264 ++missing_truth_particle;
268 AUXDATA(xprd, std::vector<unsigned int>, truth_index) = tp_indices;
294 ATH_MSG_DEBUG(
" recorded SCT_PrepData objects: size " << xaod->size());
301 return StatusCode::SUCCESS;
308 std::vector<int> sdo_word;
309 std::vector<std::vector<int>> sdo_depositsBarcode;
310 std::vector<std::vector<float>> sdo_depositsEnergy;
312 for (
const auto& hitIdentifier: prd->
rdoList()) {
313 auto pos{sdoCollection->find(hitIdentifier)};
314 if (
pos == sdoCollection->end())
continue;
315 sdo_word.push_back(
pos->second.word());
316 std::vector<int> sdoDepBC(
pos->second.getdeposits().size(), -1);
317 std::vector<float> sdoDepEnergy(
pos->second.getdeposits().size());
318 unsigned int nDepos{0};
319 for (
auto& deposit:
pos->second.getdeposits()) {
320 if (deposit.first) sdoDepBC[nDepos] =
HepMC::barcode(deposit.first);
322 sdoDepEnergy[nDepos] = deposit.second;
325 sdo_depositsBarcode.push_back(sdoDepBC);
326 sdo_depositsEnergy.push_back(sdoDepEnergy);
328 AUXDATA(xprd, std::vector<int>, sdo_words) = sdo_word;
329 AUXDATA(xprd, std::vector<std::vector<int>>, sdo_depositsBarcode) = sdo_depositsBarcode;
330 AUXDATA(xprd, std::vector<std::vector<float>>, sdo_depositsEnergy) = sdo_depositsEnergy;
336 const std::vector<const SiHit*>* siHits)
const
338 std::vector<SiHit> matchingHits;
341 long unsigned int numHits{matchingHits.size()};
343 std::vector<float> sihit_energyDeposit(numHits, 0.);
344 std::vector<float> sihit_meanTime(numHits, 0.);
345 std::vector<int> sihit_barcode(numHits, 0);
347 std::vector<float> sihit_startPosX(numHits, 0.);
348 std::vector<float> sihit_startPosY(numHits, 0.);
349 std::vector<float> sihit_startPosZ(numHits, 0.);
351 std::vector<float> sihit_endPosX(numHits, 0);
352 std::vector<float> sihit_endPosY(numHits, 0);
353 std::vector<float> sihit_endPosZ(numHits, 0);
358 for (
const SiHit& sihit : matchingHits) {
359 sihit_energyDeposit[hitNumber] = sihit.energyLoss();
360 sihit_meanTime[hitNumber] = sihit.meanTime();
364 const HepGeom::Point3D<double>& startPos{sihit.localStartPosition()};
367 sihit_startPosX[hitNumber] =
pos[0];
368 sihit_startPosY[hitNumber] =
pos[1];
369 sihit_startPosZ[hitNumber] = startPos.x();
371 const HepGeom::Point3D<double>& endPos{sihit.localEndPosition()};
372 pos= de->hitLocalToLocal(endPos.z(), endPos.y());
373 sihit_endPosX[hitNumber] =
pos[0];
374 sihit_endPosY[hitNumber] =
pos[1];
375 sihit_endPosZ[hitNumber] = endPos.x();
380 AUXDATA(xprd, std::vector<float>, sihit_energyDeposit) = sihit_energyDeposit;
381 AUXDATA(xprd, std::vector<float>, sihit_meanTime) = sihit_meanTime;
382 AUXDATA(xprd, std::vector<int>, sihit_barcode) = sihit_barcode;
384 AUXDATA(xprd, std::vector<float>, sihit_startPosX) = sihit_startPosX;
385 AUXDATA(xprd, std::vector<float>, sihit_startPosY) = sihit_startPosY;
386 AUXDATA(xprd, std::vector<float>, sihit_startPosZ) = sihit_startPosZ;
388 AUXDATA(xprd, std::vector<float>, sihit_endPosX) = sihit_endPosX;
389 AUXDATA(xprd, std::vector<float>, sihit_endPosY) = sihit_endPosY;
390 AUXDATA(xprd, std::vector<float>, sihit_endPosZ) = sihit_endPosZ;
394 const std::vector<const SiHit*>* siHits,
395 std::vector<SiHit>& matchingHits)
const
397 ATH_MSG_VERBOSE(
"Got " << siHits->size() <<
" SiHits to look through");
401 if (de==
nullptr)
return;
403 std::vector<const SiHit*> multiMatchingHits;
405 for (
const SiHit* siHit: *siHits) {
409 HepGeom::Point3D<double> averagePosition{siHit->localStartPosition() + siHit->localEndPosition()};
410 averagePosition *= 0.5;
411 Amg::Vector2D pos{de->hitLocalToLocal(averagePosition.z(), averagePosition.y())};
414 for (
const auto& hitIdentifier: prd->
rdoList()) {
417 if (std::abs(
static_cast<int>(diode.phiIndex()) -
m_SCTHelper->
strip(hitIdentifier))<=1) {
418 multiMatchingHits.push_back(siHit);
424 matchingHits.reserve(multiMatchingHits.size());
428 ATH_MSG_DEBUG(
"Found " << multiMatchingHits.size() <<
" SiHit ");
429 for (; siHitIter != multiMatchingHits.end(); ++siHitIter) {
430 const SiHit* lowestXPos{*siHitIter};
431 const SiHit* highestXPos{*siHitIter};
434 std::vector<const SiHit*> ajoiningHits;
435 ajoiningHits.push_back(*siHitIter);
437 siHitIter2 = siHitIter+1;
439 while (siHitIter2 != multiMatchingHits.end()) {
446 constexpr
double maxDiff = 0.00005;
448 if (std::abs((highestXPos->localEndPosition().x()-(*siHitIter2)->localStartPosition().x()))<maxDiff and
449 std::abs((highestXPos->localEndPosition().y()-(*siHitIter2)->localStartPosition().y()))<maxDiff and
450 std::abs((highestXPos->localEndPosition().z()-(*siHitIter2)->localStartPosition().z()))<maxDiff) {
451 highestXPos = *siHitIter2;
452 ajoiningHits.push_back(*siHitIter2);
454 siHitIter2 = multiMatchingHits.erase(siHitIter2);
455 }
else if (std::abs((lowestXPos->localStartPosition().x()-(*siHitIter2)->localEndPosition().x()))<maxDiff and
456 std::abs((lowestXPos->localStartPosition().y()-(*siHitIter2)->localEndPosition().y()))<maxDiff and
457 std::abs((lowestXPos->localStartPosition().z()-(*siHitIter2)->localEndPosition().z()))<maxDiff) {
458 lowestXPos = *siHitIter2;
459 ajoiningHits.push_back(*siHitIter2);
461 siHitIter2 = multiMatchingHits.erase(siHitIter2);
467 if (ajoiningHits.size()==0) {
470 }
else if (ajoiningHits.size()==1) {
472 matchingHits.emplace_back(*ajoiningHits[0]);
476 ATH_MSG_DEBUG(
"Merging " << ajoiningHits.size() <<
" SiHits together.");
479 for (
auto& siHit: ajoiningHits) {
480 energyDep += siHit->energyLoss();
481 time += siHit->meanTime();
483 time /=
static_cast<float>(ajoiningHits.size());
484 matchingHits.emplace_back(lowestXPos->localStartPosition(),
485 highestXPos->localEndPosition(),
490 (*siHitIter)->getBarrelEndcap(),
491 (*siHitIter)->getLayerDisk(),
492 (*siHitIter)->getEtaModule(),
493 (*siHitIter)->getPhiModule(),
494 (*siHitIter)->getSide());
501 const std::map<Identifier, const SCT_RDORawData*>& idToRAWDataMap)
const {
503 std::vector<int> timebin(prd->
rdoList().size(), -1);
504 std::vector<int> groupsize(prd->
rdoList().size(), -1);
506 unsigned int nRDOs{0};
507 for (
const auto& hitIdentifier: prd->
rdoList()) {
508 auto result{idToRAWDataMap.find(hitIdentifier)};
509 if (
result != idToRAWDataMap.end()) {
514 timebin[nRDOs] = rdo3->getTimeBin();
515 groupsize[nRDOs] = rdo3->getGroupSize();
522 AUXDATA(xprd, std::vector<int>, rdo_timebin) = timebin;
523 AUXDATA(xprd, std::vector<int>, rdo_groupsize) = groupsize;
537 return StatusCode::SUCCESS;