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;
205 unsigned int nwafer =
m_pixel_ID->wafer_hash_max();
207 ATH_CHECK( wh.record (std::make_unique<InDet::PixelClusterContainer>(nwafer)) );
222 return StatusCode::FAILURE;
227 return StatusCode::FAILURE;
239 TimedHitCollList hitCollList;
240 unsigned int numberOfSimHits(0);
241 if ( !(
m_mergeSvc->retrieveSubEvtsData(
m_inputObjectName.value(), hitCollList, numberOfSimHits).isSuccess()) && hitCollList.empty() ) {
243 return StatusCode::FAILURE;
252 TimedHitCollList::iterator iColl(hitCollList.begin());
253 TimedHitCollList::iterator endColl(hitCollList.end() );
257 while ( iColl != endColl ) {
263 thpcsi.
insert(iColl->first, p_collection);
264 ATH_MSG_DEBUG (
"SiHitCollection found with " << p_collection->
size() <<
" hits" );
269 if(this->
digitize(ctx, thpcsi).isFailure()) {
271 return StatusCode::FAILURE;
276 return StatusCode::FAILURE;
284 ATH_MSG_ERROR(
"[ ---- ] Could not set Pixel ROT container ");
289 ATH_MSG_FATAL (
"PixelClusterAmbiguitiesMap could not be recorded in StoreGate !" );
290 return StatusCode::FAILURE;
292 ATH_MSG_DEBUG (
"PixelClusterAmbiguitiesMap recorded in StoreGate" );
298 return StatusCode::SUCCESS;
309 unsigned int nwafer =
m_pixel_ID->wafer_hash_max();
311 ATH_CHECK( wh.record (std::make_unique<InDet::PixelClusterContainer>(nwafer)) );
325 return StatusCode::FAILURE;
330 return StatusCode::FAILURE;
339 return StatusCode::FAILURE;
350 return StatusCode::FAILURE;
357 ATH_MSG_ERROR(
"[ ---- ] Could not set Pixel ROT container ");
362 ATH_MSG_FATAL (
"PixelClusterAmbiguitiesMap could not be recorded in StoreGate !" );
363 return StatusCode::FAILURE;
365 ATH_MSG_DEBUG (
"PixelClusterAmbiguitiesMap recorded in StoreGate" );
370 return StatusCode::SUCCESS;
380 rngWrapper->
setSeed( rngName, ctx );
381 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
385 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
387 return StatusCode::FAILURE;
398 std::vector<int> truthIdList;
399 std::vector<Identifier> detEl;
414 const int barrelEC =
hit->getBarrelEndcap();
415 const int layerDisk =
hit->getLayerDisk();
416 const int phiModule =
hit->getPhiModule();
417 const int etaModule =
hit->getEtaModule();
422 if (!hitSiDetElement) {
ATH_MSG_ERROR(
" could not get detector element ");
continue;}
424 if (!(hitSiDetElement->
isPixel())) {
continue;}
428 std::vector<HepMcParticleLink> hit_vector;
430 const int truthID = (currentLink.
barcode() !=0 && currentLink.
id() == 0) ? 3 : currentLink.
id();
438 for (
int j : truthIdList) {
439 for (
auto & k : detEl) {
440 if ((truthID > 0) && (truthID == j) && (hitId == k)) {isRep =
true;
break;}
447 truthIdList.push_back(truthID);
448 detEl.push_back(hitId);
450 HepGeom::Point3D<double> localStartPosition =
hit->localStartPosition();
451 HepGeom::Point3D<double> localEndPosition =
hit->localEndPosition();
456 int isEndcap = (barrelEC==0) ? 0:1;
464 Diffuse(localStartPosition, localEndPosition, shiftX, shiftY);
466 const Amg::Vector3D localDirection(localEndPosition.x()-localStartPosition.x(), localEndPosition.y()-localStartPosition.y(), localEndPosition.z()-localStartPosition.z());
468 Amg::Vector3D entryPoint(localStartPosition.x(),localStartPosition.y(),localStartPosition.z());
469 Amg::Vector3D exitPoint(localEndPosition.x(),localEndPosition.y(),localEndPosition.z());
473 ATH_MSG_FATAL(
"Failed to cast the hitSiDetElement::design pointer to a PixelModuleDesign*; aborting due to null pointer");
474 return StatusCode::FAILURE;
476 const Amg::Vector2D localEntry(localStartPosition.x(),localStartPosition.y());
477 const Amg::Vector2D localExit(localEndPosition.x(),localEndPosition.y());
485 double halfthickness = hitSiDetElement->
thickness()*0.5;
487 bool EntryValid(entryCellId.
isValid());
488 bool ExitValid(exitCellId.
isValid());
503 pixMinimalPathCut=th0;
505 if (!EntryValid || !ExitValid)
509 if ( !EntryValid && !ExitValid)
continue;
517 ATH_MSG_WARNING(
"ATTENTION THE INTERSECTION COORDINATE IS OUT OF THE MODULE");
521 const Amg::Vector2D Intersection_2d(Intersection.x(),Intersection.y());
527 if(!Intersection_2dCellId.
isValid())
continue;
530 exitPoint = Intersection;
532 entryPoint = Intersection;
540 if(!digitizationModule){
542 return StatusCode::FAILURE;
546 std::vector<Trk::DigitizationStep> digitizationSteps =
m_digitizationStepper->cellSteps(*digitizationModule,entryPoint,exitPoint);
551 std::unique_ptr<InDet::PixelCluster> pixelCluster =
nullptr;
554 std::vector<Identifier> rdoList;
555 std::vector<int> totList;
557 const bool isGanged =
false;
560 double accumulatedPathLength=0.;
563 int phiIndexMax = -999999;
564 int phiIndexMin = 1000000;
565 int etaIndexMax = -999999;
566 int etaIndexMin = 1000000;
569 for (
auto& dStep : digitizationSteps){
571 double pathlength = dStep.stepLength;
578 pathlength *= (1.+sPar);
582 if (pathlength < pixMinimalPathCut)
continue;
596 clusterPosition += pathlength * chargeCenterPosition;
598 int currentEtaIndex = diode.
etaIndex();
599 int currentPhiIndex = diode.
phiIndex();
600 if(currentEtaIndex > etaIndexMax) etaIndexMax = currentEtaIndex;
601 if(currentEtaIndex < etaIndexMin) etaIndexMin = currentEtaIndex;
602 if(currentPhiIndex > phiIndexMax) phiIndexMax = currentPhiIndex;
603 if(currentPhiIndex < phiIndexMin) phiIndexMin = currentPhiIndex;
607 accumulatedPathLength += pathlength;
609 rdoList.push_back(rdoId);
614 delete digitizationModule;
617 int siDeltaPhiCut = phiIndexMax-phiIndexMin+1;
618 int siDeltaEtaCut = etaIndexMax-etaIndexMin+1;
620 int totalToT=std::accumulate(totList.begin(), totList.end(), 0);;
623 if (rdoList.empty() || accumulatedPathLength < pixMinimalPathCut || totalToT == 0) {
624 if (totalToT == 0 && !rdoList.empty() )
ATH_MSG_WARNING(
"The total ToT of the cluster is 0, this should never happen");
631 clusterPosition *= 1./accumulatedPathLength;
640 for(Pixel_detElement_RIO_map::iterator currentClusIter = PixelDetElClusterMap.begin(); currentClusIter != PixelDetElClusterMap.end();) {
642 Pixel_detElement_RIO_map::iterator clusIter = currentClusIter++;
644 const std::vector<Identifier> ¤tRdoList = currentCluster->
rdoList();
646 for (
auto rdoIter : rdoList) {
648 if (areNb) {
break; }
651 const std::vector<int> ¤tTotList = currentCluster->
totList();
652 rdoList.insert(rdoList.end(), currentRdoList.begin(), currentRdoList.end() );
653 totList.insert(totList.end(), currentTotList.begin(), currentTotList.end() );
655 float c1 = (float)currentRdoList.size();
656 float c2 = (float)rdoList.size();
657 clusterPosition = (clusterPosition*c2 + currentClusterPosition*c1)/((c1 + c2));
660 PixelDetElClusterMap.erase(clusIter);
663 std::pair<PRD_MultiTruthCollection::iterator,PRD_MultiTruthCollection::iterator> saved_hit =
m_pixPrdTruth->equal_range(currentCluster->
identify());
664 for (PRD_MultiTruthCollection::iterator this_hit = saved_hit.first; this_hit != saved_hit.second; ++this_hit)
666 hit_vector.push_back(this_hit->second);
670 delete currentCluster;
676 bool not_valid =
false;
677 for (
auto & entry : rdoList) {
678 if (!(entry.is_valid())) { not_valid =
true;
break;}
681 if (not_valid)
continue;
685 for (
auto rdoIter : rdoList) {
688 int chargePhiIndex = chargeCellId.
phiIndex();
689 int chargeEtaIndex = chargeCellId.
etaIndex();
691 phiIndexMin = chargePhiIndex < phiIndexMin ? chargePhiIndex : phiIndexMin;
692 phiIndexMax = chargePhiIndex > phiIndexMax ? chargePhiIndex : phiIndexMax;
693 etaIndexMin = chargeEtaIndex < etaIndexMin ? chargeEtaIndex : etaIndexMin;
694 etaIndexMax = chargeEtaIndex > etaIndexMax ? chargeEtaIndex : etaIndexMax;
696 siDeltaPhiCut = (phiIndexMax-phiIndexMin)+1;
697 siDeltaEtaCut = (etaIndexMax-etaIndexMin)+1;
712 const auto* pixModDesign =
714 &hitSiDetElement->
design());
716 return StatusCode::FAILURE;
722 pixModDesign->widthFromRowRange(phiIndexMin, phiIndexMax);
730 clusterId, clusterPosition, std::move(rdoList),
731 lvl1a, std::move(totList), siWidth,
733 false, 0.0, 0.0, calibData, *offlineCalibData, ctx));
735 pixelCluster->setGangedPixel(isGanged);
739 "[ cluster - pix ] No pixels errors provided, but configured to "
742 " -> No pixels cluster will be created.");
746 if (!(pixelCluster->identify().is_valid())) {
747 pixelCluster.reset();
751 if (!(
m_pixel_ID->is_pixel(pixelCluster->identify()))) {
752 pixelCluster.reset();
757 PixelDetElClusterMap.insert(Pixel_detElement_RIO_map::value_type(
758 waferHash, pixelCluster.release()));
764 std::make_pair(insertedCluster->
identify(), currentLink));
767 <<
" and link = " << currentLink);
771 "Particle link NOT valid!! Truth map NOT filled with cluster"
772 << insertedCluster <<
" and link = " << currentLink);
785 (void)
m_pixelClusterMap->insert(PixelDetElClusterMap.begin(), PixelDetElClusterMap.end());
791 return StatusCode::SUCCESS;
798 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
800 return StatusCode::FAILURE;
810 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range;
812 Pixel_detElement_RIO_map::iterator firstDetElem;
813 firstDetElem = range.first;
814 waferHash = firstDetElem->first;
816 auto clusterCollection = std::make_unique<InDet::PixelClusterCollection>(waferHash);
817 clusterCollection->setIdentifier(detElement->
identify());
818 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter){
820 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
821 clusterCollection->push_back(pixelCluster);
823 if (!clusterCollection->empty()) {
828 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
835 return StatusCode::SUCCESS;
839(
const std::vector<Identifier>& group,
849 std::vector<Identifier>::const_iterator groupBegin = group.begin();
850 std::vector<Identifier>::const_iterator groupEnd = group.end();
857 while (groupBegin!=groupEnd)
862 if(row1 > rowmax) rowmax = row1;
863 int deltarow = abs(row2-row1);
864 int deltacol = abs(col2-col1);
867 if(deltacol+deltarow < 2)
match =
true;
869 if(deltacol == 1 && deltarow == 1)
match =
true;
888 const double halfThickness = hitSiDetElement->
thickness() * 0.5;
889 const double halfWidth = design->
width() * 0.5;
890 const double halfLength = design->
length() * 0.5;
892 int binsX = design->
rows();
900 ATH_MSG_VERBOSE(
"Retrieving infos: halfThickness = " << halfThickness <<
" --- halfWidth = " << halfWidth <<
" --- halfLength = " << halfLength );
901 ATH_MSG_VERBOSE(
"Retrieving infos: binsX = " << binsX <<
" --- binsY = " << binsY <<
" --- numberOfChip = " << numberOfChip);
905 const bool useLorentzAngle{
true};
921 auto rectangleBounds = std::make_shared<const Trk::RectangleBounds>(halfWidth,halfLength);
924 std::shared_ptr<const Trk::Segmentation> rectangleSegmentation(
new Trk::RectangularSegmentation(std::move(rectangleBounds),(
size_t)binsX,LongPitch,(
size_t)binsY, numberOfChip));
931 ATH_MSG_VERBOSE(
"Building Rectangle Segmentation with dimensions (halfX, halfY) = (" << halfWidth <<
", " << halfLength <<
")");
934 return digitizationModule;
943 std::vector<double> parameters;
944 parameters.push_back((PlaneBorder.x() -
Point.x())/Direction.x());
945 parameters.push_back((-PlaneBorder.x() -
Point.x())/Direction.x());
946 parameters.push_back((PlaneBorder.y() -
Point.y())/Direction.y());
947 parameters.push_back((-PlaneBorder.y() -
Point.y())/Direction.y());
949 for(
double parameter: parameters)
951 double z =
Point.
z() + Direction.z() * parameter;
952 if( std::abs(
z) > halfthickness )
956 double x =
Point.x() + Direction.x() * parameter;
957 double y =
Point.y() + Direction.y() * parameter;
959 if(std::abs(
x) > PlaneBorder.x() || std::abs(
y) > PlaneBorder.y())
973 double localEntryX = localEntry.x();
974 double localEntryY = localEntry.y();
975 double localExitX = localExit.x();
976 double localExitY = localExit.y();
978 double signX = localExitX>localEntryX ? 1:-1 ;
979 double signY = localExitY>localEntryY ? 1:-1 ;
981 localEntryX += shiftX*signX*(-1);
982 localExitX += shiftX*signX;
983 localEntryY += shiftY*signY*(-1);
984 localExitY += shiftY*signY;
986 localEntry.setX(localEntryX);
987 localEntry.setY(localEntryY);
988 localExit.setX(localExitX);
989 localExit.setY(localExitY);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_FATAL(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
Property holding a SG store/key/clid from which a WriteHandle is made.
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.
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