14#include "Identifier/Identifier.h"
26#include "CLHEP/Random/RandGaussZiggurat.h"
27#include "CLHEP/Random/RandFlat.h"
28#include "CLHEP/Random/RandGauss.h"
29#include "CLHEP/Random/RandLandau.h"
30#include "CLHEP/Vector/ThreeVector.h"
64 const IInterface* parent):
116 declareProperty(
"InputObjectName",
m_inputObjectName=
"PixelHits",
"Input Object name" );
119 declareProperty(
"MergeClusters",
m_merge);
120 declareProperty(
"Nsigma",
m_nSigma);
121 declareProperty(
"SmearPixel",
m_SmearPixel,
"Enable Pixel or SCT Smearing");
141 return StatusCode::FAILURE;
144 if (detStore()->retrieve(
m_pixel_ID,
"PixelID").isFailure()) {
146 return StatusCode::FAILURE;
150 if (detStore()->retrieve(
m_sct_ID,
"SCT_ID").isFailure()) {
152 return StatusCode::FAILURE;
165 return StatusCode::FAILURE;
175 return StatusCode::FAILURE;
184 m_outputFile =
new TFile(
"CheckSmearing_Pixel.root",
"RECREATE");
185 m_currentTree =
new TTree(
"PixelTree",
"Check smearing Pixel");
204 return StatusCode::FAILURE;
210 m_outputFile =
new TFile(
"CheckSmearing_SCT.root",
"RECREATE");
227 return StatusCode::FAILURE;
236 return StatusCode::SUCCESS;
247 ATH_MSG_DEBUG (
"SiSmearedDigitizationTool : Writing Tree" );
254 return StatusCode::SUCCESS;
261 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel prepareEvent() ---" );
266 return StatusCode::SUCCESS;
274 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel processBunchXing() ---" );
281 TimedHitCollList hitCollList;
284 bSubEvents, eSubEvents).isSuccess()) &&
285 hitCollList.empty()) {
287 return StatusCode::FAILURE;
293 TimedHitCollList::iterator iColl(hitCollList.begin());
294 TimedHitCollList::iterator endColl(hitCollList.end());
296 for( ; iColl != endColl; ++iColl) {
302 <<
" index: " << timeIndex.
index()
303 <<
" type: " << timeIndex.
type());
307 return StatusCode::SUCCESS;
313 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel processAllSubEvents() ---" );
315 InDet::SiClusterContainer* symSiContainer=
nullptr;
321 ATH_MSG_FATAL(
"[ --- ] Could not create PixelClusterContainer");
322 return StatusCode::FAILURE;
331 ATH_MSG_FATAL(
"[ hitproc ] Error while registering PixelCluster container");
332 return StatusCode::FAILURE;
340 ATH_MSG_FATAL(
"[ --- ] PixelClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
341 return StatusCode::FAILURE;
343 ATH_MSG_INFO(
"[ hitproc ] PixelClusterContainer symlinked to SiClusterContainer in StoreGate" );
350 ATH_MSG_FATAL(
"[ --- ] Could not create SCT_ClusterContainer");
351 return StatusCode::FAILURE;
358 ATH_MSG_FATAL(
"[ hitproc ] Error while registering SCT_Cluster container");
359 return StatusCode::FAILURE;
365 ATH_MSG_FATAL(
"[ --- ] SCT_ClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
366 return StatusCode::FAILURE;
368 ATH_MSG_DEBUG(
"[ hitproc ] SCT_ClusterContainer symlinked to SiClusterContainer in StoreGate" );
375 return StatusCode::FAILURE;
384 TimedHitCollList hitCollList;
385 unsigned int numberOfSimHits(0);
388 return StatusCode::FAILURE;
397 TimedHitCollList::iterator iColl(hitCollList.begin());
398 TimedHitCollList::iterator endColl(hitCollList.end() );
402 while ( iColl != endColl ) {
407 thpcsi.
insert(iColl->first, p_collection);
408 ATH_MSG_DEBUG (
"SiHitCollection found with " << p_collection->
size() <<
" hits" );
413 if(this->
digitize(ctx, thpcsi).isFailure()) {
415 return StatusCode::FAILURE;
421 return StatusCode::FAILURE;
426 return StatusCode::FAILURE;
432 return StatusCode::SUCCESS;
446 return StatusCode::FAILURE;
451 return StatusCode::FAILURE;
460 return StatusCode::FAILURE;
465 return StatusCode::FAILURE;
471 return StatusCode::SUCCESS;
475template<
typename CLUSTER>
478 ATH_MSG_DEBUG(
"Truth map filling with cluster " << *cluster <<
" and link = " <<
hit->particleLink());
479 if (
hit->particleLink().isValid()){
481 map->insert(std::make_pair(cluster->identify(),
hit->particleLink()));
482 ATH_MSG_DEBUG(
"Truth map filled with cluster " << *cluster <<
" and link = " <<
hit->particleLink());
485 ATH_MSG_DEBUG(
"Particle link NOT valid!! Truth map NOT filled with cluster" << cluster <<
" and link = " <<
hit->particleLink());
488 return StatusCode::SUCCESS;
499template<
typename CLUSTER>
508 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_a = " << intersection_a);
509 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_b = " << intersection_b);
511 double distX = intersection_a.x() - intersection_b.x();
512 double distY = intersection_a.y() - intersection_b.y();
514 return sqrt(distX*distX + distY*distY);
517template<
typename CLUSTER>
520 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
523 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
531 return sqrt(sigmaX*sigmaX + sigmaY*sigmaY);
534template<
typename CLUSTER>
538 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
542 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
550 double interX = 0.5*(intersection_a.x()+intersection_b.x());
551 double interY = 0.5*(intersection_a.y()+intersection_b.y());
560 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_a = " << siWidth_a);
561 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_b = " << siWidth_b);
568 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth = " << siWidth);
571 covariance.setIdentity();
585 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using PixelClusters --- ");
587 Pixel_detElement_RIO_map::iterator i = cluster_map->begin();
588 Pixel_detElement_RIO_map::iterator e = cluster_map->end();
590 for (; i != e; i = cluster_map->upper_bound(i->first)){
594 bool NewMerge =
true;
598 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range = cluster_map->equal_range(current_id);
600 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter){
601 for (Pixel_detElement_RIO_map::iterator inner_iter = std::next(iter); inner_iter != range.second; ++inner_iter){
604 double sigma =
calculateSigma((*iter).second,(*inner_iter).second);
608 std::vector<Identifier> rdoList;
618 rdoList.push_back(intersectionId);
622 if ( !currentCellId.
isValid() ) {
631 std::move(clusterErr));
632 ((*inner_iter).second) = pixelCluster;
634 cluster_map->erase(iter);
644 return StatusCode::SUCCESS;
652 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using SCT_Clusters --- ");
654 SCT_detElement_RIO_map::iterator i = cluster_map->begin();
655 SCT_detElement_RIO_map::iterator e = cluster_map->end();
657 for (; i != e; i = cluster_map->upper_bound(i->first)){
660 bool NewMerge =
true;
665 std::pair <SCT_detElement_RIO_map::iterator, SCT_detElement_RIO_map::iterator> range = cluster_map->equal_range(current_id);
666 for ( SCT_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter){
667 for ( SCT_detElement_RIO_map::iterator inner_iter = std::next(iter); inner_iter != range.second; ++inner_iter){
671 double sigma =
calculateSigma((*iter).second,(*inner_iter).second);
675 std::vector<Identifier> rdoList;
685 rdoList.push_back(intersectionId);
689 if ( !currentCellId.
isValid() ) {
695 std::vector<Identifier>(rdoList),
699 ((*inner_iter).second) = sctCluster;
701 cluster_map->erase(iter);
711 return StatusCode::SUCCESS;
720 rngWrapper->
setSeed( rngName, ctx );
721 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
723 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SiSmearedDigizationTool::digitize() ---" );
729 elementsPixel = pixelDetEle.
retrieve();
730 if (elementsPixel==
nullptr) {
732 return StatusCode::FAILURE;
740 if (elementsSCT==
nullptr) {
742 return StatusCode::FAILURE;
760 int barrelEC =
hit->getBarrelEndcap();
761 int layerDisk =
hit->getLayerDisk();
762 int phiModule =
hit->getPhiModule();
763 int etaModule =
hit->getEtaModule();
772 ATH_MSG_DEBUG(
"Pixel SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule );
773 hitSiDetElement = hitSiDetElement_temp;
775 side =
hit->getSide();
779 ATH_MSG_DEBUG(
"SCT SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule <<
", side " << side);
780 hitSiDetElement = hitSiDetElement_temp;
788 if (not hitSiDetElement) {
789 ATH_MSG_FATAL(
"hitSiDetElement is null in SiSmearedDigitizationTool:"<<__LINE__);
790 throw std::runtime_error(std::string(
"hitSiDetElement is null in SiSmearedDigitizationTool::digitize() "));
804 HepGeom::Point3D<double> pix_localStartPosition =
hit->localStartPosition();
805 HepGeom::Point3D<double> pix_localEndPosition =
hit->localEndPosition();
807 pix_localStartPosition = hitSiDetElement->
hitLocalToLocal3D(pix_localStartPosition);
810 double localEntryX = pix_localStartPosition.x();
811 double localEntryY = pix_localStartPosition.y();
812 double localEntryZ = pix_localStartPosition.z();
813 double localExitX = pix_localEndPosition.x();
814 double localExitY = pix_localEndPosition.y();
815 double localExitZ = pix_localEndPosition.z();
817 double thickness = 0.0;
818 thickness = hitSiDetElement->
thickness();
822 HepGeom::Point3D<double> sct_localStartPosition =
hit->localStartPosition();
823 HepGeom::Point3D<double> sct_localEndPosition =
hit->localEndPosition();
825 sct_localStartPosition = hitSiDetElement->
hitLocalToLocal3D(sct_localStartPosition);
828 localEntryX = sct_localStartPosition.x();
829 localEntryY = sct_localStartPosition.y();
830 localEntryZ = sct_localStartPosition.z();
831 localExitX = sct_localEndPosition.x();
832 localExitY = sct_localEndPosition.y();
833 localExitZ = sct_localEndPosition.z();
836 double distX = std::abs(std::abs(localExitX)-std::abs(localEntryX));
837 double distY = std::abs(std::abs(localExitY)-std::abs(localEntryY));
840 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
841 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
849 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
850 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
863 std::vector<Identifier> rdoList;
865 Amg::Vector3D localDirection(localExitX-localEntryX, localExitY-localEntryY, localExitZ-localEntryZ);
878 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryId " << entryId <<
" --- exitId " << exitId );
879 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryCellId " << entryCellId <<
" --- exitCellId " << exitCellId );
884 bool entryValid = entryCellId.
isValid();
885 bool exitValid = exitCellId.
isValid();
887 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryValid? " << entryValid <<
" --- exitValid? " << exitValid );
889 if (!entryValid && !exitValid)
continue;
892 double interX = 0.5*(localEntryX+localExitX);
893 double interY = 0.5*(localEntryY+localExitY);
904 double newdistX = distX - (timesX*
m_pitch_X);
905 double newdistY = distY - (timesY*
m_pitch_Y);
907 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times X --- " << timesX );
908 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times Y --- " << timesY );
909 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist X --- " << newdistX );
910 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist Y --- " << newdistY );
911 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: thickness --- " << thickness );
915 double ProbY = 2*newdistY/(
m_pitch_Y+newdistY);
916 double ProbX = 2*newdistX/(
m_pitch_X+newdistX);
918 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbX --- " << ProbX );
919 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbY --- " << ProbY );
928 int elementX = timesX+1;
929 int elementY = timesY+1;
932 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbY) {
933 sigmaY = (double)(timesY+2)*
m_pitch_Y/sqrt(12.);
936 sigmaY = (double)(timesY+1)*
m_pitch_Y/sqrt(12.);
938 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbX) {
939 sigmaX = (double)(timesX+2)*
m_pitch_X/sqrt(12.);
942 sigmaX = (double)(timesX+1)*
m_pitch_X/sqrt(12.);
949 double temp_X = interX;
950 double temp_Y = interY;
959 rdoList.push_back(intersectionId);
962 if (!currentCellId.
isValid())
continue;
964 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: Intersection Id = " << intersectionId <<
" --- currentCellId = " << currentCellId );
972 ATH_MSG_WARNING(
"--- SiSmearedDigitizationTool: pitchX and/or pitchY are 0. Cluster length is forced to be 1. mm");
979 covariance.setIdentity();
986 std::vector<Identifier>(rdoList),
990 m_pixelClusterMap->insert(std::pair<IdentifierHash, InDet::PixelCluster* >(waferID, pixelCluster));
994 return StatusCode::FAILURE;
999 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixelCluster --> " << *pixelCluster);
1010 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: GlobalPosition --> X = " << (pixelCluster->globalPosition()).x() <<
" Y = " << (pixelCluster->globalPosition()).y());
1040 const std::pair<InDetDD::SiLocalPosition, InDetDD::SiLocalPosition> ends(design_sct->
endsOfStrip(
intersection));
1041 double stripLength = std::abs(ends.first.xEta()-ends.second.xEta());
1060 if(colRow.x() == 1) {
1063 else if(colRow.x() == 2) {
1073 double cs2 = 1.-sn2;
1085 std::vector<Identifier>(rdoList),
1090 m_sctClusterMap->insert(std::pair<IdentifierHash, InDet::SCT_Cluster* >(waferID, sctCluster));
1094 return StatusCode::FAILURE;
1099 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT_Cluster --> " << *sctCluster);
1105 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: BEFORE SMEARING LocalPosition --> X = " <<
m_x_SCT );
1118 return StatusCode::SUCCESS;
1128 elementsPixel = pixelDetEle.
retrieve();
1129 if (elementsPixel==
nullptr) {
1131 return StatusCode::FAILURE;
1138 elementsSCT = sctDetEle.
retrieve();
1139 if (elementsSCT==
nullptr) {
1141 return StatusCode::FAILURE;
1147 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel createAndStoreRIOs() ---" );
1154 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range;
1157 Pixel_detElement_RIO_map::iterator firstDetElem;
1158 firstDetElem = range.first;
1161 waferID = firstDetElem->first;
1165 InDet::PixelClusterCollection *clusterCollection =
new InDet::PixelClusterCollection(waferID);
1166 clusterCollection->setIdentifier(detElement->
identify());
1168 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter ) {
1171 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1172 clusterCollection->push_back(pixelCluster);
1176 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1185 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SCT createAndStoreRIOs() ---" );
1191 std::pair <SCT_detElement_RIO_map::iterator, SCT_detElement_RIO_map::iterator> range;
1194 SCT_detElement_RIO_map::iterator firstDetElem;
1195 firstDetElem = range.first;
1198 waferID = firstDetElem->first;
1201 InDet::SCT_ClusterCollection *clusterCollection =
new InDet::SCT_ClusterCollection(waferID);
1202 clusterCollection->setIdentifier(detElement->
identify());
1205 for ( SCT_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter ) {
1207 sctCluster->
setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1208 clusterCollection->push_back(sctCluster);
1211 if (
m_sctClusterContainer->addCollection( clusterCollection, clusterCollection->identifyHash() ).isFailure() ) {
1212 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1220 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define AmgSymMatrix(dim)
the preferred mechanism to access information from the different event stores in a pileup job.
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT 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.
This is a "hash" representation of an Identifier.
virtual DetectorShape shape() const
Shape of element.
Base class for the SCT module side design, extended by the Forward and Barrel module design.
virtual std::pair< SiLocalPosition, SiLocalPosition > endsOfStrip(const SiLocalPosition &position) const override=0
give the ends of strips
Identifier for the strip or pixel cell.
bool isValid() const
Test if its in a valid state.
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):
double phiPitch() const
Pitch (inline methods)
double sinStereoLocal(const Amg::Vector2D &localPos) const
Angle of strip in local frame with respect to the etaAxis.
double length() const
Length in eta direction (z - barrel, r - endcap)
HepGeom::Point3D< double > hitLocalToLocal3D(const HepGeom::Point3D< double > &hitPosition) const
Same as previuos method but 3D.
virtual Identifier identify() const override final
identifier of this detector element (inline)
Identifier identifierOfPosition(const Amg::Vector2D &localPos) const
Full identifier of the cell for a given position: assumes a raw local position (no Lorentz shift)
Trk::Surface & surface()
Element Surface.
const Amg::Vector3D & globalPosition() const
return global position reference
const Amg::Vector2D & widthPhiRZ() const
const Amg::Vector2D & colRow() const
A PRD is mapped onto all contributing particles.
const_pointer_type retrieve()
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.
const Amg::Vector2D & localPosition() const
return the local position reference
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
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::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