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"
67 const IInterface* parent):
119 declareProperty(
"InputObjectName",
m_inputObjectName=
"PixelHits",
"Input Object name" );
122 declareProperty(
"MergeClusters",
m_merge);
123 declareProperty(
"Nsigma",
m_nSigma);
124 declareProperty(
"SmearPixel",
m_SmearPixel,
"Enable Pixel or SCT Smearing");
144 return StatusCode::FAILURE;
147 if (detStore()->retrieve(
m_pixel_ID,
"PixelID").isFailure()) {
149 return StatusCode::FAILURE;
153 if (detStore()->retrieve(
m_sct_ID,
"SCT_ID").isFailure()) {
155 return StatusCode::FAILURE;
168 return StatusCode::FAILURE;
178 return StatusCode::FAILURE;
187 m_outputFile =
new TFile(
"CheckSmearing_Pixel.root",
"RECREATE");
188 m_currentTree =
new TTree(
"PixelTree",
"Check smearing Pixel");
207 return StatusCode::FAILURE;
213 m_outputFile =
new TFile(
"CheckSmearing_SCT.root",
"RECREATE");
230 return StatusCode::FAILURE;
239 return StatusCode::SUCCESS;
250 ATH_MSG_DEBUG (
"SiSmearedDigitizationTool : Writing Tree" );
257 return StatusCode::SUCCESS;
264 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel prepareEvent() ---" );
269 return StatusCode::SUCCESS;
277 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel processBunchXing() ---" );
284 TimedHitCollList hitCollList;
287 bSubEvents, eSubEvents).isSuccess()) &&
288 hitCollList.empty()) {
290 return StatusCode::FAILURE;
296 TimedHitCollList::iterator iColl(hitCollList.begin());
297 TimedHitCollList::iterator endColl(hitCollList.end());
299 for( ; iColl != endColl; ++iColl) {
305 <<
" index: " << timeIndex.
index()
306 <<
" type: " << timeIndex.
type());
310 return StatusCode::SUCCESS;
316 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel processAllSubEvents() ---" );
318 InDet::SiClusterContainer* symSiContainer=
nullptr;
324 ATH_MSG_FATAL(
"[ --- ] Could not create PixelClusterContainer");
325 return StatusCode::FAILURE;
334 ATH_MSG_FATAL(
"[ hitproc ] Error while registering PixelCluster container");
335 return StatusCode::FAILURE;
343 ATH_MSG_FATAL(
"[ --- ] PixelClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
344 return StatusCode::FAILURE;
346 ATH_MSG_INFO(
"[ hitproc ] PixelClusterContainer symlinked to SiClusterContainer in StoreGate" );
353 ATH_MSG_FATAL(
"[ --- ] Could not create SCT_ClusterContainer");
354 return StatusCode::FAILURE;
361 ATH_MSG_FATAL(
"[ hitproc ] Error while registering SCT_Cluster container");
362 return StatusCode::FAILURE;
368 ATH_MSG_FATAL(
"[ --- ] SCT_ClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
369 return StatusCode::FAILURE;
371 ATH_MSG_DEBUG(
"[ hitproc ] SCT_ClusterContainer symlinked to SiClusterContainer in StoreGate" );
378 return StatusCode::FAILURE;
387 TimedHitCollList hitCollList;
388 unsigned int numberOfSimHits(0);
391 return StatusCode::FAILURE;
400 TimedHitCollList::iterator iColl(hitCollList.begin());
401 TimedHitCollList::iterator endColl(hitCollList.end() );
405 while ( iColl != endColl ) {
410 thpcsi.
insert(iColl->first, p_collection);
411 ATH_MSG_DEBUG (
"SiHitCollection found with " << p_collection->
size() <<
" hits" );
416 if(this->
digitize(ctx, thpcsi).isFailure()) {
418 return StatusCode::FAILURE;
424 return StatusCode::FAILURE;
429 return StatusCode::FAILURE;
435 return StatusCode::SUCCESS;
449 return StatusCode::FAILURE;
454 return StatusCode::FAILURE;
463 return StatusCode::FAILURE;
468 return StatusCode::FAILURE;
474 return StatusCode::SUCCESS;
478template<
typename CLUSTER>
481 ATH_MSG_DEBUG(
"Truth map filling with cluster " << *cluster <<
" and link = " << hit->particleLink());
482 if (hit->particleLink().isValid()){
484 map->insert(std::make_pair(cluster->identify(), hit->particleLink()));
485 ATH_MSG_DEBUG(
"Truth map filled with cluster " << *cluster <<
" and link = " << hit->particleLink());
488 ATH_MSG_DEBUG(
"Particle link NOT valid!! Truth map NOT filled with cluster" << cluster <<
" and link = " << hit->particleLink());
491 return StatusCode::SUCCESS;
502template<
typename CLUSTER>
511 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_a = " << intersection_a);
512 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_b = " << intersection_b);
514 double distX = intersection_a.x() - intersection_b.x();
515 double distY = intersection_a.y() - intersection_b.y();
517 return sqrt(distX*distX + distY*distY);
520template<
typename CLUSTER>
523 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
526 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
534 return sqrt(sigmaX*sigmaX + sigmaY*sigmaY);
537template<
typename CLUSTER>
541 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
545 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
553 double interX = 0.5*(intersection_a.x()+intersection_b.x());
554 double interY = 0.5*(intersection_a.y()+intersection_b.y());
563 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_a = " << siWidth_a);
564 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_b = " << siWidth_b);
571 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth = " << siWidth);
574 covariance.setIdentity();
588 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using PixelClusters --- ");
590 Pixel_detElement_RIO_map::iterator i = cluster_map->begin();
591 Pixel_detElement_RIO_map::iterator e = cluster_map->end();
593 for (; i != e; i = cluster_map->upper_bound(i->first)){
597 bool NewMerge =
true;
601 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range = cluster_map->equal_range(current_id);
603 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter){
604 for (Pixel_detElement_RIO_map::iterator inner_iter = std::next(iter); inner_iter != range.second; ++inner_iter){
607 double sigma =
calculateSigma((*iter).second,(*inner_iter).second);
611 std::vector<Identifier> rdoList;
621 rdoList.push_back(intersectionId);
625 if ( !currentCellId.
isValid() ) {
634 std::move(clusterErr));
635 ((*inner_iter).second) = pixelCluster;
637 cluster_map->erase(iter);
647 return StatusCode::SUCCESS;
655 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using SCT_Clusters --- ");
657 SCT_detElement_RIO_map::iterator i = cluster_map->begin();
658 SCT_detElement_RIO_map::iterator e = cluster_map->end();
660 for (; i != e; i = cluster_map->upper_bound(i->first)){
663 bool NewMerge =
true;
668 std::pair <SCT_detElement_RIO_map::iterator, SCT_detElement_RIO_map::iterator> range = cluster_map->equal_range(current_id);
669 for ( SCT_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter){
670 for ( SCT_detElement_RIO_map::iterator inner_iter = std::next(iter); inner_iter != range.second; ++inner_iter){
674 double sigma =
calculateSigma((*iter).second,(*inner_iter).second);
678 std::vector<Identifier> rdoList;
688 rdoList.push_back(intersectionId);
692 if ( !currentCellId.
isValid() ) {
698 std::vector<Identifier>(rdoList),
702 ((*inner_iter).second) = sctCluster;
704 cluster_map->erase(iter);
714 return StatusCode::SUCCESS;
723 rngWrapper->
setSeed( rngName, ctx );
724 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
726 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SiSmearedDigizationTool::digitize() ---" );
732 elementsPixel = pixelDetEle.
retrieve();
733 if (elementsPixel==
nullptr) {
735 return StatusCode::FAILURE;
743 if (elementsSCT==
nullptr) {
745 return StatusCode::FAILURE;
763 int barrelEC = hit->getBarrelEndcap();
764 int layerDisk = hit->getLayerDisk();
765 int phiModule = hit->getPhiModule();
766 int etaModule = hit->getEtaModule();
775 ATH_MSG_DEBUG(
"Pixel SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule );
776 hitSiDetElement = hitSiDetElement_temp;
778 side = hit->getSide();
782 ATH_MSG_DEBUG(
"SCT SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule <<
", side " << side);
783 hitSiDetElement = hitSiDetElement_temp;
791 if (not hitSiDetElement) {
792 ATH_MSG_FATAL(
"hitSiDetElement is null in SiSmearedDigitizationTool:"<<__LINE__);
793 throw std::runtime_error(std::string(
"hitSiDetElement is null in SiSmearedDigitizationTool::digitize() "));
807 HepGeom::Point3D<double> pix_localStartPosition = hit->localStartPosition();
808 HepGeom::Point3D<double> pix_localEndPosition = hit->localEndPosition();
810 pix_localStartPosition = hitSiDetElement->
hitLocalToLocal3D(pix_localStartPosition);
813 double localEntryX = pix_localStartPosition.x();
814 double localEntryY = pix_localStartPosition.y();
815 double localEntryZ = pix_localStartPosition.z();
816 double localExitX = pix_localEndPosition.x();
817 double localExitY = pix_localEndPosition.y();
818 double localExitZ = pix_localEndPosition.z();
820 double thickness = 0.0;
821 thickness = hitSiDetElement->
thickness();
825 HepGeom::Point3D<double> sct_localStartPosition = hit->localStartPosition();
826 HepGeom::Point3D<double> sct_localEndPosition = hit->localEndPosition();
828 sct_localStartPosition = hitSiDetElement->
hitLocalToLocal3D(sct_localStartPosition);
831 localEntryX = sct_localStartPosition.x();
832 localEntryY = sct_localStartPosition.y();
833 localEntryZ = sct_localStartPosition.z();
834 localExitX = sct_localEndPosition.x();
835 localExitY = sct_localEndPosition.y();
836 localExitZ = sct_localEndPosition.z();
839 double distX = std::abs(std::abs(localExitX)-std::abs(localEntryX));
840 double distY = std::abs(std::abs(localExitY)-std::abs(localEntryY));
843 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
844 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
852 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
853 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
866 std::vector<Identifier> rdoList;
868 Amg::Vector3D localDirection(localExitX-localEntryX, localExitY-localEntryY, localExitZ-localEntryZ);
881 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryId " << entryId <<
" --- exitId " << exitId );
882 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryCellId " << entryCellId <<
" --- exitCellId " << exitCellId );
887 bool entryValid = entryCellId.
isValid();
888 bool exitValid = exitCellId.
isValid();
890 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryValid? " << entryValid <<
" --- exitValid? " << exitValid );
892 if (!entryValid && !exitValid)
continue;
895 double interX = 0.5*(localEntryX+localExitX);
896 double interY = 0.5*(localEntryY+localExitY);
907 double newdistX = distX - (timesX*
m_pitch_X);
908 double newdistY = distY - (timesY*
m_pitch_Y);
910 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times X --- " << timesX );
911 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times Y --- " << timesY );
912 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist X --- " << newdistX );
913 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist Y --- " << newdistY );
914 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: thickness --- " << thickness );
918 double ProbY = 2*newdistY/(
m_pitch_Y+newdistY);
919 double ProbX = 2*newdistX/(
m_pitch_X+newdistX);
921 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbX --- " << ProbX );
922 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbY --- " << ProbY );
931 int elementX = timesX+1;
932 int elementY = timesY+1;
935 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbY) {
936 sigmaY = (double)(timesY+2)*
m_pitch_Y/sqrt(12.);
939 sigmaY = (double)(timesY+1)*
m_pitch_Y/sqrt(12.);
941 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbX) {
942 sigmaX = (double)(timesX+2)*
m_pitch_X/sqrt(12.);
945 sigmaX = (double)(timesX+1)*
m_pitch_X/sqrt(12.);
952 double temp_X = interX;
953 double temp_Y = interY;
962 rdoList.push_back(intersectionId);
965 if (!currentCellId.
isValid())
continue;
967 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: Intersection Id = " << intersectionId <<
" --- currentCellId = " << currentCellId );
975 ATH_MSG_WARNING(
"--- SiSmearedDigitizationTool: pitchX and/or pitchY are 0. Cluster length is forced to be 1. mm");
982 covariance.setIdentity();
989 std::vector<Identifier>(rdoList),
993 m_pixelClusterMap->insert(std::pair<IdentifierHash, InDet::PixelCluster* >(waferID, pixelCluster));
997 return StatusCode::FAILURE;
1002 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixelCluster --> " << *pixelCluster);
1013 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: GlobalPosition --> X = " << (pixelCluster->globalPosition()).x() <<
" Y = " << (pixelCluster->globalPosition()).y());
1043 const std::pair<InDetDD::SiLocalPosition, InDetDD::SiLocalPosition> ends(design_sct->
endsOfStrip(
intersection));
1044 double stripLength = std::abs(ends.first.xEta()-ends.second.xEta());
1063 if(colRow.x() == 1) {
1066 else if(colRow.x() == 2) {
1076 double cs2 = 1.-sn2;
1088 std::vector<Identifier>(rdoList),
1093 m_sctClusterMap->insert(std::pair<IdentifierHash, InDet::SCT_Cluster* >(waferID, sctCluster));
1097 return StatusCode::FAILURE;
1102 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT_Cluster --> " << *sctCluster);
1108 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: BEFORE SMEARING LocalPosition --> X = " <<
m_x_SCT );
1121 return StatusCode::SUCCESS;
1131 elementsPixel = pixelDetEle.
retrieve();
1132 if (elementsPixel==
nullptr) {
1134 return StatusCode::FAILURE;
1141 elementsSCT = sctDetEle.
retrieve();
1142 if (elementsSCT==
nullptr) {
1144 return StatusCode::FAILURE;
1150 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel createAndStoreRIOs() ---" );
1157 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range;
1160 Pixel_detElement_RIO_map::iterator firstDetElem;
1161 firstDetElem = range.first;
1164 waferID = firstDetElem->first;
1168 InDet::PixelClusterCollection *clusterCollection =
new InDet::PixelClusterCollection(waferID);
1169 clusterCollection->setIdentifier(detElement->
identify());
1171 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter ) {
1174 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1175 clusterCollection->push_back(pixelCluster);
1179 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1188 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SCT createAndStoreRIOs() ---" );
1194 std::pair <SCT_detElement_RIO_map::iterator, SCT_detElement_RIO_map::iterator> range;
1197 SCT_detElement_RIO_map::iterator firstDetElem;
1198 firstDetElem = range.first;
1201 waferID = firstDetElem->first;
1204 InDet::SCT_ClusterCollection *clusterCollection =
new InDet::SCT_ClusterCollection(waferID);
1205 clusterCollection->setIdentifier(detElement->
identify());
1208 for ( SCT_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter ) {
1210 sctCluster->
setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1211 clusterCollection->push_back(sctCluster);
1214 if (
m_sctClusterContainer->addCollection( clusterCollection, clusterCollection->identifyHash() ).isFailure() ) {
1215 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1223 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
defines an "iterator" over instances of a given type in StoreGateSvc
#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
constexpr int pow(int base, int exp) noexcept
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