15 #include "Identifier/Identifier.h"
25 #include "CLHEP/Random/RandGaussZiggurat.h"
26 #include "CLHEP/Random/RandFlat.h"
27 #include "CLHEP/Random/RandLandau.h"
66 using namespace InDet;
97 return StatusCode::FAILURE;
102 return StatusCode::FAILURE;
108 return StatusCode::FAILURE;
134 return StatusCode::FAILURE;
141 return StatusCode::FAILURE;
148 return StatusCode::SUCCESS;
159 return StatusCode::SUCCESS;
173 TimedHitCollList hitCollList;
176 bSubEvents, eSubEvents).isSuccess()) &&
177 hitCollList.empty()) {
179 return StatusCode::FAILURE;
188 for( ; iColl != endColl; ++iColl) {
194 <<
" index: " << timeIndex.
index()
195 <<
" type: " << timeIndex.
type());
200 return StatusCode::SUCCESS;
209 ATH_MSG_FATAL(
"[ --- ] Could not create PixelClusterContainer");
210 return StatusCode::FAILURE;
219 ATH_MSG_FATAL(
"[ hitproc ] Error while registering PixelCluster container");
220 return StatusCode::FAILURE;
225 ATH_MSG_FATAL(
"[ --- ] PixelClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
226 return StatusCode::FAILURE;
228 ATH_MSG_DEBUG(
"[ hitproc ] PixelClusterContainer symlinked to SiClusterContainer in StoreGate" );
238 return StatusCode::FAILURE;
243 return StatusCode::FAILURE;
255 TimedHitCollList hitCollList;
256 unsigned int numberOfSimHits(0);
257 if ( !(
m_mergeSvc->retrieveSubEvtsData(
m_inputObjectName.value(), hitCollList, numberOfSimHits).isSuccess()) && hitCollList.empty() ) {
259 return StatusCode::FAILURE;
273 while ( iColl != endColl ) {
279 thpcsi.
insert(iColl->first, p_collection);
280 ATH_MSG_DEBUG (
"SiHitCollection found with " << p_collection->
size() <<
" hits" );
285 if(this->
digitize(ctx, thpcsi).isFailure()) {
287 return StatusCode::FAILURE;
292 return StatusCode::FAILURE;
300 ATH_MSG_ERROR(
"[ ---- ] Could not set Pixel ROT container ");
305 ATH_MSG_FATAL (
"PixelClusterAmbiguitiesMap could not be recorded in StoreGate !" );
306 return StatusCode::FAILURE;
308 ATH_MSG_DEBUG (
"PixelClusterAmbiguitiesMap recorded in StoreGate" );
314 return StatusCode::SUCCESS;
326 ATH_MSG_FATAL(
"[ --- ] Could not create PixelClusterContainer");
327 return StatusCode::FAILURE;
336 ATH_MSG_FATAL(
"[ hitproc ] Error while registering PixelCluster container");
337 return StatusCode::FAILURE;
342 ATH_MSG_FATAL(
"[ --- ] PixelClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
343 return StatusCode::FAILURE;
345 ATH_MSG_DEBUG(
"[ hitproc ] PixelClusterContainer symlinked to SiClusterContainer in StoreGate" );
354 return StatusCode::FAILURE;
359 return StatusCode::FAILURE;
368 return StatusCode::FAILURE;
379 return StatusCode::FAILURE;
386 ATH_MSG_ERROR(
"[ ---- ] Could not set Pixel ROT container ");
391 ATH_MSG_FATAL (
"PixelClusterAmbiguitiesMap could not be recorded in StoreGate !" );
392 return StatusCode::FAILURE;
394 ATH_MSG_DEBUG (
"PixelClusterAmbiguitiesMap recorded in StoreGate" );
399 return StatusCode::SUCCESS;
409 rngWrapper->
setSeed( rngName, ctx );
410 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
414 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
416 return StatusCode::FAILURE;
427 std::vector<int> truthIdList;
428 std::vector<Identifier> detEl;
443 const int barrelEC = hit->getBarrelEndcap();
444 const int layerDisk = hit->getLayerDisk();
445 const int phiModule = hit->getPhiModule();
446 const int etaModule = hit->getEtaModule();
451 if (!hitSiDetElement) {
ATH_MSG_ERROR(
" could not get detector element ");
continue;}
453 if (!(hitSiDetElement->
isPixel())) {
continue;}
457 std::vector<HepMcParticleLink> hit_vector;
459 const int truthID = (currentLink.
barcode() !=0 && currentLink.
id() == 0) ? 3 : currentLink.
id();
467 for (
int j : truthIdList) {
468 for (
auto &
k : detEl) {
469 if ((truthID > 0) && (truthID == j) && (hitId ==
k)) {isRep =
true;
break;}
476 truthIdList.push_back(truthID);
477 detEl.push_back(hitId);
479 HepGeom::Point3D<double> localStartPosition = hit->localStartPosition();
480 HepGeom::Point3D<double> localEndPosition = hit->localEndPosition();
485 int isEndcap = (barrelEC==0) ? 0:1;
493 Diffuse(localStartPosition, localEndPosition, shiftX, shiftY);
495 const Amg::Vector3D localDirection(localEndPosition.x()-localStartPosition.x(), localEndPosition.y()-localStartPosition.y(), localEndPosition.z()-localStartPosition.z());
497 Amg::Vector3D entryPoint(localStartPosition.x(),localStartPosition.y(),localStartPosition.z());
498 Amg::Vector3D exitPoint(localEndPosition.x(),localEndPosition.y(),localEndPosition.z());
502 ATH_MSG_FATAL(
"Failed to cast the hitSiDetElement::design pointer to a PixelModuleDesign*; aborting due to null pointer");
503 return StatusCode::FAILURE;
505 const Amg::Vector2D localEntry(localStartPosition.x(),localStartPosition.y());
506 const Amg::Vector2D localExit(localEndPosition.x(),localEndPosition.y());
514 double halfthickness = hitSiDetElement->
thickness()*0.5;
516 bool EntryValid(entryCellId.
isValid());
517 bool ExitValid(exitCellId.
isValid());
532 pixMinimalPathCut=th0;
534 if (!EntryValid || !ExitValid)
538 if ( !EntryValid && !ExitValid)
continue;
546 ATH_MSG_WARNING(
"ATTENTION THE INTERSECTION COORDINATE IS OUT OF THE MODULE");
550 const Amg::Vector2D Intersection_2d(Intersection.x(),Intersection.y());
556 if(!Intersection_2dCellId.
isValid())
continue;
559 exitPoint = Intersection;
561 entryPoint = Intersection;
569 if(!digitizationModule){
571 return StatusCode::FAILURE;
575 std::vector<Trk::DigitizationStep> digitizationSteps =
m_digitizationStepper->cellSteps(*digitizationModule,entryPoint,exitPoint);
580 std::unique_ptr<InDet::PixelCluster>
pixelCluster =
nullptr;
583 std::vector<Identifier> rdoList;
584 std::vector<int> totList;
586 const bool isGanged =
false;
589 double accumulatedPathLength=0.;
592 int phiIndexMax = -999999;
593 int phiIndexMin = 1000000;
594 int etaIndexMax = -999999;
595 int etaIndexMin = 1000000;
598 for (
auto& dStep : digitizationSteps){
600 double pathlength = dStep.stepLength;
607 pathlength *= (1.+sPar);
611 if (pathlength < pixMinimalPathCut)
continue;
625 clusterPosition += pathlength * chargeCenterPosition;
627 int currentEtaIndex = diode.
etaIndex();
628 int currentPhiIndex = diode.
phiIndex();
629 if(currentEtaIndex > etaIndexMax) etaIndexMax = currentEtaIndex;
630 if(currentEtaIndex < etaIndexMin) etaIndexMin = currentEtaIndex;
631 if(currentPhiIndex > phiIndexMax) phiIndexMax = currentPhiIndex;
632 if(currentPhiIndex < phiIndexMin) phiIndexMin = currentPhiIndex;
636 accumulatedPathLength += pathlength;
638 rdoList.push_back(rdoId);
643 delete digitizationModule;
646 int siDeltaPhiCut = phiIndexMax-phiIndexMin+1;
647 int siDeltaEtaCut = etaIndexMax-etaIndexMin+1;
652 if (rdoList.empty() || accumulatedPathLength < pixMinimalPathCut || totalToT == 0) {
653 if (totalToT == 0 && !rdoList.empty() )
ATH_MSG_WARNING(
"The total ToT of the cluster is 0, this should never happen");
658 clusterPosition *= 1./accumulatedPathLength;
671 const std::vector<Identifier> ¤tRdoList = currentCluster->
rdoList();
673 for (
auto rdoIter : rdoList) {
675 if (areNb) {
break; }
678 const std::vector<int> ¤tTotList = currentCluster->
totList();
679 rdoList.insert(rdoList.end(), currentRdoList.begin(), currentRdoList.end() );
680 totList.insert(totList.end(), currentTotList.begin(), currentTotList.end() );
682 float c1 = (
float)currentRdoList.size();
683 float c2 = (
float)rdoList.size();
684 clusterPosition = (clusterPosition*
c2 + currentClusterPosition*
c1)/((
c1 +
c2));
687 PixelDetElClusterMap.erase(clusIter);
690 std::pair<PRD_MultiTruthCollection::iterator,PRD_MultiTruthCollection::iterator> saved_hit =
m_pixPrdTruth->equal_range(currentCluster->
identify());
693 hit_vector.push_back(this_hit->second);
697 delete currentCluster;
703 bool not_valid =
false;
704 for (
auto &
entry : rdoList) {
705 if (!(
entry.is_valid())) { not_valid =
true;
break;}
708 if (not_valid)
continue;
712 for (
auto rdoIter : rdoList) {
715 int chargePhiIndex = chargeCellId.
phiIndex();
716 int chargeEtaIndex = chargeCellId.
etaIndex();
718 phiIndexMin = chargePhiIndex < phiIndexMin ? chargePhiIndex : phiIndexMin;
719 phiIndexMax = chargePhiIndex > phiIndexMax ? chargePhiIndex : phiIndexMax;
720 etaIndexMin = chargeEtaIndex < etaIndexMin ? chargeEtaIndex : etaIndexMin;
721 etaIndexMax = chargeEtaIndex > etaIndexMax ? chargeEtaIndex : etaIndexMax;
723 siDeltaPhiCut = (phiIndexMax-phiIndexMin)+1;
724 siDeltaEtaCut = (etaIndexMax-etaIndexMin)+1;
739 const auto* pixModDesign =
741 &hitSiDetElement->
design());
743 return StatusCode::FAILURE;
749 pixModDesign->widthFromRowRange(phiIndexMin, phiIndexMax);
757 clusterId, clusterPosition, std::vector<Identifier>(rdoList),
758 lvl1a, std::vector<int>(totList), siWidth,
760 false, 0.0, 0.0, calibData, *offlineCalibData, ctx));
766 "[ cluster - pix ] No pixels errors provided, but configured to "
769 " -> No pixels cluster will be created.");
784 PixelDetElClusterMap.insert(Pixel_detElement_RIO_map::value_type(
791 std::make_pair(insertedCluster->
identify(), currentLink));
794 <<
" and link = " << currentLink);
798 "Particle link NOT valid!! Truth map NOT filled with cluster"
799 << insertedCluster <<
" and link = " << currentLink);
812 (void)
m_pixelClusterMap->insert(PixelDetElClusterMap.begin(), PixelDetElClusterMap.end());
818 return StatusCode::SUCCESS;
825 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
827 return StatusCode::FAILURE;
834 IdentifierHash waferHash;
838 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator>
range;
842 firstDetElem =
range.first;
844 waferHash = firstDetElem->first;
849 clusterCollection->setIdentifier(detElement->
identify());
855 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
861 if (clusterCollection) {
862 if (!clusterCollection->empty()) {
867 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
870 else {
delete clusterCollection;}
878 return StatusCode::SUCCESS;
882 (
const std::vector<Identifier>&
group,
892 std::vector<Identifier>::const_iterator groupBegin =
group.begin();
893 std::vector<Identifier>::const_iterator groupEnd =
group.end();
900 while (groupBegin!=groupEnd)
905 if(row1 > rowmax) rowmax = row1;
906 int deltarow = abs(row2-row1);
907 int deltacol = abs(col2-col1);
910 if(deltacol+deltarow < 2)
match =
true;
912 if(deltacol == 1 && deltarow == 1)
match =
true;
931 const double halfThickness = hitSiDetElement->
thickness() * 0.5;
932 const double halfWidth = design->
width() * 0.5;
933 const double halfLength = design->
length() * 0.5;
943 ATH_MSG_VERBOSE(
"Retrieving infos: halfThickness = " << halfThickness <<
" --- halfWidth = " << halfWidth <<
" --- halfLength = " << halfLength );
944 ATH_MSG_VERBOSE(
"Retrieving infos: binsX = " <<
binsX <<
" --- binsY = " <<
binsY <<
" --- numberOfChip = " << numberOfChip);
948 const bool useLorentzAngle{
true};
949 const IdentifierHash detElHash = hitSiDetElement->
identifyHash();
964 auto rectangleBounds = std::make_shared<const Trk::RectangleBounds>(halfWidth,halfLength);
974 ATH_MSG_VERBOSE(
"Building Rectangle Segmentation with dimensions (halfX, halfY) = (" << halfWidth <<
", " << halfLength <<
")");
977 return digitizationModule;
994 double z =
Point.
z() + Direction.z() * parameter;
995 if( std::abs(
z) > halfthickness )
999 double x =
Point.x() + Direction.x() * parameter;
1000 double y =
Point.y() + Direction.y() * parameter;
1002 if(std::abs(
x) > PlaneBorder.x() || std::abs(
y) > PlaneBorder.y())
1011 return Intersection;
1016 double localEntryX = localEntry.x();
1017 double localEntryY = localEntry.y();
1018 double localExitX = localExit.x();
1019 double localExitY = localExit.y();
1021 double signX = localExitX>localEntryX ? 1:-1 ;
1022 double signY = localExitY>localEntryY ? 1:-1 ;
1024 localEntryX += shiftX*signX*(-1);
1025 localExitX += shiftX*signX;
1026 localEntryY += shiftY*signY*(-1);
1027 localExitY += shiftY*signY;
1029 localEntry.setX(localEntryX);
1030 localEntry.setY(localEntryY);
1031 localExit.setX(localExitX);
1032 localExit.setY(localExitY);