15#include "Identifier/Identifier.h"
25#include "CLHEP/Random/RandGaussZiggurat.h"
26#include "CLHEP/Random/RandFlat.h"
27#include "CLHEP/Random/RandLandau.h"
67 const IInterface* parent):
94 return StatusCode::FAILURE;
97 if (detStore()->retrieve(
m_pixel_ID,
"PixelID").isFailure()) {
99 return StatusCode::FAILURE;
105 return StatusCode::FAILURE;
131 return StatusCode::FAILURE;
138 return StatusCode::FAILURE;
145 return StatusCode::SUCCESS;
156 return StatusCode::SUCCESS;
170 TimedHitCollList hitCollList;
173 bSubEvents, eSubEvents).isSuccess()) &&
174 hitCollList.empty()) {
176 return StatusCode::FAILURE;
182 TimedHitCollList::iterator iColl(hitCollList.begin());
183 TimedHitCollList::iterator endColl(hitCollList.end());
185 for( ; iColl != endColl; ++iColl) {
191 <<
" index: " << timeIndex.
index()
192 <<
" type: " << timeIndex.
type());
193 m_thpcsi->insert(timeIndex, siHitColl);
197 return StatusCode::SUCCESS;
206 ATH_MSG_FATAL(
"[ --- ] Could not create PixelClusterContainer");
207 return StatusCode::FAILURE;
210 InDet::SiClusterContainer* symSiContainer=
nullptr;
216 ATH_MSG_FATAL(
"[ hitproc ] Error while registering PixelCluster container");
217 return StatusCode::FAILURE;
222 ATH_MSG_FATAL(
"[ --- ] PixelClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
223 return StatusCode::FAILURE;
225 ATH_MSG_DEBUG(
"[ hitproc ] PixelClusterContainer symlinked to SiClusterContainer in StoreGate" );
235 return StatusCode::FAILURE;
240 return StatusCode::FAILURE;
252 TimedHitCollList hitCollList;
253 unsigned int numberOfSimHits(0);
254 if ( !(
m_mergeSvc->retrieveSubEvtsData(
m_inputObjectName.value(), hitCollList, numberOfSimHits).isSuccess()) && hitCollList.empty() ) {
256 return StatusCode::FAILURE;
265 TimedHitCollList::iterator iColl(hitCollList.begin());
266 TimedHitCollList::iterator endColl(hitCollList.end() );
270 while ( iColl != endColl ) {
276 thpcsi.
insert(iColl->first, p_collection);
277 ATH_MSG_DEBUG (
"SiHitCollection found with " << p_collection->
size() <<
" hits" );
282 if(this->
digitize(ctx, thpcsi).isFailure()) {
284 return StatusCode::FAILURE;
289 return StatusCode::FAILURE;
297 ATH_MSG_ERROR(
"[ ---- ] Could not set Pixel ROT container ");
302 ATH_MSG_FATAL (
"PixelClusterAmbiguitiesMap could not be recorded in StoreGate !" );
303 return StatusCode::FAILURE;
305 ATH_MSG_DEBUG (
"PixelClusterAmbiguitiesMap recorded in StoreGate" );
311 return StatusCode::SUCCESS;
323 ATH_MSG_FATAL(
"[ --- ] Could not create PixelClusterContainer");
324 return StatusCode::FAILURE;
327 InDet::SiClusterContainer* symSiContainer=
nullptr;
333 ATH_MSG_FATAL(
"[ hitproc ] Error while registering PixelCluster container");
334 return StatusCode::FAILURE;
339 ATH_MSG_FATAL(
"[ --- ] PixelClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
340 return StatusCode::FAILURE;
342 ATH_MSG_DEBUG(
"[ hitproc ] PixelClusterContainer symlinked to SiClusterContainer in StoreGate" );
351 return StatusCode::FAILURE;
356 return StatusCode::FAILURE;
365 return StatusCode::FAILURE;
376 return StatusCode::FAILURE;
383 ATH_MSG_ERROR(
"[ ---- ] Could not set Pixel ROT container ");
388 ATH_MSG_FATAL (
"PixelClusterAmbiguitiesMap could not be recorded in StoreGate !" );
389 return StatusCode::FAILURE;
391 ATH_MSG_DEBUG (
"PixelClusterAmbiguitiesMap recorded in StoreGate" );
396 return StatusCode::SUCCESS;
406 rngWrapper->
setSeed( rngName, ctx );
407 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
411 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
413 return StatusCode::FAILURE;
424 std::vector<int> truthIdList;
425 std::vector<Identifier> detEl;
440 const int barrelEC = hit->getBarrelEndcap();
441 const int layerDisk = hit->getLayerDisk();
442 const int phiModule = hit->getPhiModule();
443 const int etaModule = hit->getEtaModule();
448 if (!hitSiDetElement) {
ATH_MSG_ERROR(
" could not get detector element ");
continue;}
450 if (!(hitSiDetElement->
isPixel())) {
continue;}
454 std::vector<HepMcParticleLink> hit_vector;
456 const int truthID = (currentLink.
barcode() !=0 && currentLink.
id() == 0) ? 3 : currentLink.
id();
464 for (
int j : truthIdList) {
465 for (
auto & k : detEl) {
466 if ((truthID > 0) && (truthID == j) && (hitId == k)) {isRep =
true;
break;}
473 truthIdList.push_back(truthID);
474 detEl.push_back(hitId);
476 HepGeom::Point3D<double> localStartPosition = hit->localStartPosition();
477 HepGeom::Point3D<double> localEndPosition = hit->localEndPosition();
482 int isEndcap = (barrelEC==0) ? 0:1;
490 Diffuse(localStartPosition, localEndPosition, shiftX, shiftY);
492 const Amg::Vector3D localDirection(localEndPosition.x()-localStartPosition.x(), localEndPosition.y()-localStartPosition.y(), localEndPosition.z()-localStartPosition.z());
494 Amg::Vector3D entryPoint(localStartPosition.x(),localStartPosition.y(),localStartPosition.z());
495 Amg::Vector3D exitPoint(localEndPosition.x(),localEndPosition.y(),localEndPosition.z());
499 ATH_MSG_FATAL(
"Failed to cast the hitSiDetElement::design pointer to a PixelModuleDesign*; aborting due to null pointer");
500 return StatusCode::FAILURE;
502 const Amg::Vector2D localEntry(localStartPosition.x(),localStartPosition.y());
503 const Amg::Vector2D localExit(localEndPosition.x(),localEndPosition.y());
511 double halfthickness = hitSiDetElement->
thickness()*0.5;
513 bool EntryValid(entryCellId.
isValid());
514 bool ExitValid(exitCellId.
isValid());
529 pixMinimalPathCut=th0;
531 if (!EntryValid || !ExitValid)
535 if ( !EntryValid && !ExitValid)
continue;
543 ATH_MSG_WARNING(
"ATTENTION THE INTERSECTION COORDINATE IS OUT OF THE MODULE");
547 const Amg::Vector2D Intersection_2d(Intersection.x(),Intersection.y());
553 if(!Intersection_2dCellId.
isValid())
continue;
556 exitPoint = Intersection;
558 entryPoint = Intersection;
566 if(!digitizationModule){
568 return StatusCode::FAILURE;
572 std::vector<Trk::DigitizationStep> digitizationSteps =
m_digitizationStepper->cellSteps(*digitizationModule,entryPoint,exitPoint);
577 std::unique_ptr<InDet::PixelCluster> pixelCluster =
nullptr;
580 std::vector<Identifier> rdoList;
581 std::vector<int> totList;
583 const bool isGanged =
false;
586 double accumulatedPathLength=0.;
589 int phiIndexMax = -999999;
590 int phiIndexMin = 1000000;
591 int etaIndexMax = -999999;
592 int etaIndexMin = 1000000;
595 for (
auto& dStep : digitizationSteps){
597 double pathlength = dStep.stepLength;
604 pathlength *= (1.+sPar);
608 if (pathlength < pixMinimalPathCut)
continue;
622 clusterPosition += pathlength * chargeCenterPosition;
624 int currentEtaIndex = diode.
etaIndex();
625 int currentPhiIndex = diode.
phiIndex();
626 if(currentEtaIndex > etaIndexMax) etaIndexMax = currentEtaIndex;
627 if(currentEtaIndex < etaIndexMin) etaIndexMin = currentEtaIndex;
628 if(currentPhiIndex > phiIndexMax) phiIndexMax = currentPhiIndex;
629 if(currentPhiIndex < phiIndexMin) phiIndexMin = currentPhiIndex;
633 accumulatedPathLength += pathlength;
635 rdoList.push_back(rdoId);
640 delete digitizationModule;
643 int siDeltaPhiCut = phiIndexMax-phiIndexMin+1;
644 int siDeltaEtaCut = etaIndexMax-etaIndexMin+1;
646 int totalToT=std::accumulate(totList.begin(), totList.end(), 0);;
649 if (rdoList.empty() || accumulatedPathLength < pixMinimalPathCut || totalToT == 0) {
650 if (totalToT == 0 && !rdoList.empty() )
ATH_MSG_WARNING(
"The total ToT of the cluster is 0, this should never happen");
655 clusterPosition *= 1./accumulatedPathLength;
664 for(Pixel_detElement_RIO_map::iterator currentClusIter = PixelDetElClusterMap.begin(); currentClusIter != PixelDetElClusterMap.end();) {
666 Pixel_detElement_RIO_map::iterator clusIter = currentClusIter++;
668 const std::vector<Identifier> ¤tRdoList = currentCluster->
rdoList();
670 for (
auto rdoIter : rdoList) {
672 if (areNb) {
break; }
675 const std::vector<int> ¤tTotList = currentCluster->
totList();
676 rdoList.insert(rdoList.end(), currentRdoList.begin(), currentRdoList.end() );
677 totList.insert(totList.end(), currentTotList.begin(), currentTotList.end() );
679 float c1 = (float)currentRdoList.size();
680 float c2 = (float)rdoList.size();
681 clusterPosition = (clusterPosition*c2 + currentClusterPosition*c1)/((c1 + c2));
684 PixelDetElClusterMap.erase(clusIter);
687 std::pair<PRD_MultiTruthCollection::iterator,PRD_MultiTruthCollection::iterator> saved_hit =
m_pixPrdTruth->equal_range(currentCluster->
identify());
688 for (PRD_MultiTruthCollection::iterator this_hit = saved_hit.first; this_hit != saved_hit.second; ++this_hit)
690 hit_vector.push_back(this_hit->second);
694 delete currentCluster;
700 bool not_valid =
false;
701 for (
auto & entry : rdoList) {
702 if (!(entry.is_valid())) { not_valid =
true;
break;}
705 if (not_valid)
continue;
709 for (
auto rdoIter : rdoList) {
712 int chargePhiIndex = chargeCellId.
phiIndex();
713 int chargeEtaIndex = chargeCellId.
etaIndex();
715 phiIndexMin = chargePhiIndex < phiIndexMin ? chargePhiIndex : phiIndexMin;
716 phiIndexMax = chargePhiIndex > phiIndexMax ? chargePhiIndex : phiIndexMax;
717 etaIndexMin = chargeEtaIndex < etaIndexMin ? chargeEtaIndex : etaIndexMin;
718 etaIndexMax = chargeEtaIndex > etaIndexMax ? chargeEtaIndex : etaIndexMax;
720 siDeltaPhiCut = (phiIndexMax-phiIndexMin)+1;
721 siDeltaEtaCut = (etaIndexMax-etaIndexMin)+1;
736 const auto* pixModDesign =
738 &hitSiDetElement->
design());
740 return StatusCode::FAILURE;
746 pixModDesign->widthFromRowRange(phiIndexMin, phiIndexMax);
754 clusterId, clusterPosition, std::vector<Identifier>(rdoList),
755 lvl1a, std::vector<int>(totList), siWidth,
757 false, 0.0, 0.0, calibData, *offlineCalibData, ctx));
759 pixelCluster->setGangedPixel(isGanged);
763 "[ cluster - pix ] No pixels errors provided, but configured to "
766 " -> No pixels cluster will be created.");
770 if (!(pixelCluster->identify().is_valid())) {
771 pixelCluster.reset();
775 if (!(
m_pixel_ID->is_pixel(pixelCluster->identify()))) {
776 pixelCluster.reset();
781 PixelDetElClusterMap.insert(Pixel_detElement_RIO_map::value_type(
782 waferHash, pixelCluster.release()));
788 std::make_pair(insertedCluster->
identify(), currentLink));
791 <<
" and link = " << currentLink);
795 "Particle link NOT valid!! Truth map NOT filled with cluster"
796 << insertedCluster <<
" and link = " << currentLink);
809 (void)
m_pixelClusterMap->insert(PixelDetElClusterMap.begin(), PixelDetElClusterMap.end());
815 return StatusCode::SUCCESS;
822 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
824 return StatusCode::FAILURE;
830 InDet::PixelClusterCollection* clusterCollection =
nullptr;
835 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range;
838 Pixel_detElement_RIO_map::iterator firstDetElem;
839 firstDetElem = range.first;
841 waferHash = firstDetElem->first;
845 clusterCollection =
new InDet::PixelClusterCollection(waferHash);
846 clusterCollection->setIdentifier(detElement->
identify());
849 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter){
852 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
853 clusterCollection->push_back(pixelCluster);
858 if (clusterCollection) {
859 if (!clusterCollection->empty()) {
864 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
867 else {
delete clusterCollection;}
875 return StatusCode::SUCCESS;
879(
const std::vector<Identifier>& group,
889 std::vector<Identifier>::const_iterator groupBegin = group.begin();
890 std::vector<Identifier>::const_iterator groupEnd = group.end();
897 while (groupBegin!=groupEnd)
902 if(row1 > rowmax) rowmax = row1;
903 int deltarow = abs(row2-row1);
904 int deltacol = abs(col2-col1);
907 if(deltacol+deltarow < 2)
match =
true;
909 if(deltacol == 1 && deltarow == 1)
match =
true;
928 const double halfThickness = hitSiDetElement->
thickness() * 0.5;
929 const double halfWidth = design->
width() * 0.5;
930 const double halfLength = design->
length() * 0.5;
932 int binsX = design->
rows();
940 ATH_MSG_VERBOSE(
"Retrieving infos: halfThickness = " << halfThickness <<
" --- halfWidth = " << halfWidth <<
" --- halfLength = " << halfLength );
941 ATH_MSG_VERBOSE(
"Retrieving infos: binsX = " << binsX <<
" --- binsY = " << binsY <<
" --- numberOfChip = " << numberOfChip);
945 const bool useLorentzAngle{
true};
961 auto rectangleBounds = std::make_shared<const Trk::RectangleBounds>(halfWidth,halfLength);
964 std::shared_ptr<const Trk::Segmentation> rectangleSegmentation(
new Trk::RectangularSegmentation(std::move(rectangleBounds),(
size_t)binsX,LongPitch,(
size_t)binsY, numberOfChip));
971 ATH_MSG_VERBOSE(
"Building Rectangle Segmentation with dimensions (halfX, halfY) = (" << halfWidth <<
", " << halfLength <<
")");
974 return digitizationModule;
983 std::vector<double> parameters;
984 parameters.push_back((PlaneBorder.x() -
Point.x())/Direction.x());
985 parameters.push_back((-PlaneBorder.x() -
Point.x())/Direction.x());
986 parameters.push_back((PlaneBorder.y() -
Point.y())/Direction.y());
987 parameters.push_back((-PlaneBorder.y() -
Point.y())/Direction.y());
989 for(
double parameter: parameters)
991 double z =
Point.
z() + Direction.z() * parameter;
992 if( std::abs(
z) > halfthickness )
996 double x =
Point.x() + Direction.x() * parameter;
997 double y =
Point.y() + Direction.y() * parameter;
999 if(std::abs(
x) > PlaneBorder.x() || std::abs(
y) > PlaneBorder.y())
1008 return Intersection;
1013 double localEntryX = localEntry.x();
1014 double localEntryY = localEntry.y();
1015 double localExitX = localExit.x();
1016 double localExitY = localExit.y();
1018 double signX = localExitX>localEntryX ? 1:-1 ;
1019 double signY = localExitY>localEntryY ? 1:-1 ;
1021 localEntryX += shiftX*signX*(-1);
1022 localExitX += shiftX*signX;
1023 localEntryY += shiftY*signY*(-1);
1024 localExitY += shiftY*signY;
1026 localEntry.setX(localEntryX);
1027 localEntry.setY(localEntryY);
1028 localExit.setX(localExitX);
1029 localExit.setY(localExitY);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Structs for holding charge calibration parameterisation and data.
This is an Identifier helper class for the Pixel subdetector.
AtlasHitsVector< SiHit > SiHitCollection
A wrapper class for event-slot-local random engines.
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
a link optimized in size for a GenParticle in a McEventCollection
int id() const
Return the id of the target particle.
bool isValid() const
Validity check.
static HepMcParticleLink getRedirectedLink(const HepMcParticleLink &particleLink, uint32_t eventIndex, const EventContext &ctx)
Return a HepMcParticleLink pointing at the same particle, but in a different GenEvent.
int barcode() const
Return the barcode of the target particle.
This is a "hash" representation of an Identifier.
int readoutSide() const
ReadoutSide.
Class used to describe the design of a module (diode segmentation and readout scheme)
virtual SiDiodesParameters parameters(const SiCellId &cellId) const
readout or diode id -> position, size
int columns() const
Number of cell columns per module:
virtual double length() const
Method to calculate length of a module.
int rows() const
Number of cell rows per module:
double widthFromColumnRange(const int colMin, const int colMax) const
Method to calculate eta width from a column range.
int numberOfCircuits() const
Total number of circuits:
virtual double width() const
Method to calculate average width of a module.
Identifier for the strip or pixel cell.
int phiIndex() const
Get phi index. Equivalent to strip().
bool isValid() const
Test if its in a valid state.
int etaIndex() const
Get eta index.
Class to hold the SiDetectorElement objects to be put in the detector store.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Class to hold geometrical description of a silicon detector element.
virtual SiCellId cellIdFromIdentifier(const Identifier &identifier) const override final
SiCellId from Identifier.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
const SiLocalPosition & width() const
width of the diodes:
double xEta() const
position along eta direction:
HepGeom::Point3D< double > hitLocalToLocal3D(const HepGeom::Point3D< double > &hitPosition) const
Same as previuos method but 3D.
SiCellId cellIdOfPosition(const Amg::Vector2D &localPos) const
As in previous method but returns SiCellId.
double hitPhiDirection() const
See previous method.
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
virtual Identifier identify() const override final
identifier of this detector element (inline)
double hitDepthDirection() const
Directions of hit depth,phi,eta axes relative to reconstruction local position axes (LocalPosition).
Identifier identifierOfPosition(const Amg::Vector2D &localPos) const
Full identifier of the cell for a given position: assumes a raw local position (no Lorentz shift)
Amg::Vector2D rawLocalPositionOfCell(const SiCellId &cellId) const
Returns position (center) of cell.
const std::vector< int > & totList() const
A PRD is mapped onto all contributing particles.
PixelChargeCalib::Thresholds getThresholds(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const
This is an Identifier helper class for the Pixel subdetector.
int eta_index(const Identifier &id) const
int phi_index(const Identifier &id) const
bool nextDetectorElement(const_iterator &b, const_iterator &e)
sets an iterator range with the hits of current detector element returns a bool when done
TimedVector::const_iterator const_iterator
void insert(const PileUpTimeEventIndex &timeEventIndex, const AtlasHitsVector< HIT > *inputCollection)
a smart pointer to a hit that also provides access to the extended timing info of the host event.
unsigned short eventId() const
the index of the component event in PileUpEventInfo.
Class that holds the surfaces for a planar digitization detector module.
const Segmentation & segmentation() const
return the segmenation
const Amg::Vector2D & localPosition() const
return the local position reference
Identifier identify() const
return the identifier
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
virtual const Amg::Vector2D cellPosition(const DigitizationCell &dCell) const =0
calculate the cell Position from the Id
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.
std::pair< size_t, size_t > DigitizationCell
std::list< value_t > type
type of the collection of timed data object
a struct encapsulating the identifier of a pile-up event
index_type index() const
the index of the component event in PileUpEventInfo
PileUpType type() const
the pileup type - minbias, cavern, beam halo, signal?
time_type time() const
bunch xing time in ns