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"
65 const IInterface* parent):
117 declareProperty(
"InputObjectName",
m_inputObjectName=
"PixelHits",
"Input Object name" );
120 declareProperty(
"MergeClusters",
m_merge);
121 declareProperty(
"Nsigma",
m_nSigma);
122 declareProperty(
"SmearPixel",
m_SmearPixel,
"Enable Pixel or SCT Smearing");
142 return StatusCode::FAILURE;
145 if (detStore()->retrieve(
m_pixel_ID,
"PixelID").isFailure()) {
147 return StatusCode::FAILURE;
151 if (detStore()->retrieve(
m_sct_ID,
"SCT_ID").isFailure()) {
153 return StatusCode::FAILURE;
166 return StatusCode::FAILURE;
176 return StatusCode::FAILURE;
185 m_outputFile =
new TFile(
"CheckSmearing_Pixel.root",
"RECREATE");
186 m_currentTree =
new TTree(
"PixelTree",
"Check smearing Pixel");
205 return StatusCode::FAILURE;
211 m_outputFile =
new TFile(
"CheckSmearing_SCT.root",
"RECREATE");
228 return StatusCode::FAILURE;
237 return StatusCode::SUCCESS;
248 ATH_MSG_DEBUG (
"SiSmearedDigitizationTool : Writing Tree" );
255 return StatusCode::SUCCESS;
262 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel prepareEvent() ---" );
267 return StatusCode::SUCCESS;
275 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel processBunchXing() ---" );
282 TimedHitCollList hitCollList;
285 bSubEvents, eSubEvents).isSuccess()) &&
286 hitCollList.empty()) {
288 return StatusCode::FAILURE;
294 TimedHitCollList::iterator iColl(hitCollList.begin());
295 TimedHitCollList::iterator endColl(hitCollList.end());
297 for( ; iColl != endColl; ++iColl) {
303 <<
" index: " << timeIndex.
index()
304 <<
" type: " << timeIndex.
type());
308 return StatusCode::SUCCESS;
314 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel processAllSubEvents() ---" );
316 InDet::SiClusterContainer* symSiContainer=
nullptr;
322 ATH_MSG_FATAL(
"[ --- ] Could not create PixelClusterContainer");
323 return StatusCode::FAILURE;
332 ATH_MSG_FATAL(
"[ hitproc ] Error while registering PixelCluster container");
333 return StatusCode::FAILURE;
341 ATH_MSG_FATAL(
"[ --- ] PixelClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
342 return StatusCode::FAILURE;
344 ATH_MSG_INFO(
"[ hitproc ] PixelClusterContainer symlinked to SiClusterContainer in StoreGate" );
351 ATH_MSG_FATAL(
"[ --- ] Could not create SCT_ClusterContainer");
352 return StatusCode::FAILURE;
359 ATH_MSG_FATAL(
"[ hitproc ] Error while registering SCT_Cluster container");
360 return StatusCode::FAILURE;
366 ATH_MSG_FATAL(
"[ --- ] SCT_ClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
367 return StatusCode::FAILURE;
369 ATH_MSG_DEBUG(
"[ hitproc ] SCT_ClusterContainer symlinked to SiClusterContainer in StoreGate" );
376 return StatusCode::FAILURE;
385 TimedHitCollList hitCollList;
386 unsigned int numberOfSimHits(0);
389 return StatusCode::FAILURE;
398 TimedHitCollList::iterator iColl(hitCollList.begin());
399 TimedHitCollList::iterator endColl(hitCollList.end() );
403 while ( iColl != endColl ) {
408 thpcsi.
insert(iColl->first, p_collection);
409 ATH_MSG_DEBUG (
"SiHitCollection found with " << p_collection->
size() <<
" hits" );
414 if(this->
digitize(ctx, thpcsi).isFailure()) {
416 return StatusCode::FAILURE;
422 return StatusCode::FAILURE;
427 return StatusCode::FAILURE;
433 return StatusCode::SUCCESS;
447 return StatusCode::FAILURE;
452 return StatusCode::FAILURE;
461 return StatusCode::FAILURE;
466 return StatusCode::FAILURE;
472 return StatusCode::SUCCESS;
476template<
typename CLUSTER>
479 ATH_MSG_DEBUG(
"Truth map filling with cluster " << *cluster <<
" and link = " << hit->particleLink());
480 if (hit->particleLink().isValid()){
482 map->insert(std::make_pair(cluster->identify(), hit->particleLink()));
483 ATH_MSG_DEBUG(
"Truth map filled with cluster " << *cluster <<
" and link = " << hit->particleLink());
486 ATH_MSG_DEBUG(
"Particle link NOT valid!! Truth map NOT filled with cluster" << cluster <<
" and link = " << hit->particleLink());
489 return StatusCode::SUCCESS;
500template<
typename CLUSTER>
509 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_a = " << intersection_a);
510 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_b = " << intersection_b);
512 double distX = intersection_a.x() - intersection_b.x();
513 double distY = intersection_a.y() - intersection_b.y();
515 return sqrt(distX*distX + distY*distY);
518template<
typename CLUSTER>
521 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
524 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
532 return sqrt(sigmaX*sigmaX + sigmaY*sigmaY);
535template<
typename CLUSTER>
539 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
543 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
551 double interX = 0.5*(intersection_a.x()+intersection_b.x());
552 double interY = 0.5*(intersection_a.y()+intersection_b.y());
561 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_a = " << siWidth_a);
562 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_b = " << siWidth_b);
569 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth = " << siWidth);
572 covariance.setIdentity();
586 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using PixelClusters --- ");
588 Pixel_detElement_RIO_map::iterator i = cluster_map->begin();
589 Pixel_detElement_RIO_map::iterator e = cluster_map->end();
591 for (; i != e; i = cluster_map->upper_bound(i->first)){
595 bool NewMerge =
true;
599 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range = cluster_map->equal_range(current_id);
601 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter){
602 for (Pixel_detElement_RIO_map::iterator inner_iter = std::next(iter); inner_iter != range.second; ++inner_iter){
605 double sigma =
calculateSigma((*iter).second,(*inner_iter).second);
609 std::vector<Identifier> rdoList;
619 rdoList.push_back(intersectionId);
623 if ( !currentCellId.
isValid() ) {
632 std::move(clusterErr));
633 ((*inner_iter).second) = pixelCluster;
635 cluster_map->erase(iter);
645 return StatusCode::SUCCESS;
652 "--- SiSmearedDigitizationTool: in mergeClusters() using SCT_Clusters ---");
655 ATH_MSG_FATAL(
"Null SCT cluster map passed to mergeClusters()");
656 return StatusCode::FAILURE;
659 auto i = cluster_map->begin();
661 while (i != cluster_map->end()) {
666 mergedThisPass =
false;
667 const auto range = cluster_map->equal_range(current_id);
669 auto iter = range.first;
671 while (iter != range.second && !mergedThisPass) {
672 auto inner_iter = std::next(iter);
674 while (inner_iter != range.second) {
693 inner_iter->second->detectorElement();
701 if (!currentCellId.
isValid()) {
706 std::vector<Identifier> rdoList{intersectionId};
708 auto sctCluster = std::make_unique<InDet::SCT_Cluster>(
714 std::move(clusterErr));
716 auto*
const oldIterCluster = iter->second;
717 auto*
const oldInnerCluster = inner_iter->second;
719 inner_iter->second = sctCluster.release();
721 delete oldIterCluster;
722 delete oldInnerCluster;
724 cluster_map->erase(iter);
726 mergedThisPass =
true;
730 if (!mergedThisPass) {
734 }
while (mergedThisPass);
736 i = cluster_map->upper_bound(current_id);
739 return StatusCode::SUCCESS;
747 rngWrapper->
setSeed( rngName, ctx );
748 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
750 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SiSmearedDigizationTool::digitize() ---" );
756 elementsPixel = pixelDetEle.
retrieve();
757 if (elementsPixel==
nullptr) {
759 return StatusCode::FAILURE;
767 if (elementsSCT==
nullptr) {
769 return StatusCode::FAILURE;
787 int barrelEC = hit->getBarrelEndcap();
788 int layerDisk = hit->getLayerDisk();
789 int phiModule = hit->getPhiModule();
790 int etaModule = hit->getEtaModule();
799 ATH_MSG_DEBUG(
"Pixel SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule );
800 hitSiDetElement = hitSiDetElement_temp;
802 side = hit->getSide();
806 ATH_MSG_DEBUG(
"SCT SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule <<
", side " << side);
807 hitSiDetElement = hitSiDetElement_temp;
815 if (not hitSiDetElement) {
816 ATH_MSG_FATAL(
"hitSiDetElement is null in SiSmearedDigitizationTool:"<<__LINE__);
817 throw std::runtime_error(std::string(
"hitSiDetElement is null in SiSmearedDigitizationTool::digitize() "));
831 HepGeom::Point3D<double> pix_localStartPosition = hit->localStartPosition();
832 HepGeom::Point3D<double> pix_localEndPosition = hit->localEndPosition();
834 pix_localStartPosition = hitSiDetElement->
hitLocalToLocal3D(pix_localStartPosition);
837 double localEntryX = pix_localStartPosition.x();
838 double localEntryY = pix_localStartPosition.y();
839 double localEntryZ = pix_localStartPosition.z();
840 double localExitX = pix_localEndPosition.x();
841 double localExitY = pix_localEndPosition.y();
842 double localExitZ = pix_localEndPosition.z();
844 double thickness = 0.0;
845 thickness = hitSiDetElement->
thickness();
849 HepGeom::Point3D<double> sct_localStartPosition = hit->localStartPosition();
850 HepGeom::Point3D<double> sct_localEndPosition = hit->localEndPosition();
852 sct_localStartPosition = hitSiDetElement->
hitLocalToLocal3D(sct_localStartPosition);
855 localEntryX = sct_localStartPosition.x();
856 localEntryY = sct_localStartPosition.y();
857 localEntryZ = sct_localStartPosition.z();
858 localExitX = sct_localEndPosition.x();
859 localExitY = sct_localEndPosition.y();
860 localExitZ = sct_localEndPosition.z();
863 double distX = std::abs(std::abs(localExitX)-std::abs(localEntryX));
864 double distY = std::abs(std::abs(localExitY)-std::abs(localEntryY));
867 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
868 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
876 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
877 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
890 std::vector<Identifier> rdoList;
892 Amg::Vector3D localDirection(localExitX-localEntryX, localExitY-localEntryY, localExitZ-localEntryZ);
905 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryId " << entryId <<
" --- exitId " << exitId );
906 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryCellId " << entryCellId <<
" --- exitCellId " << exitCellId );
911 bool entryValid = entryCellId.
isValid();
912 bool exitValid = exitCellId.
isValid();
914 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryValid? " << entryValid <<
" --- exitValid? " << exitValid );
916 if (!entryValid && !exitValid)
continue;
919 double interX = 0.5*(localEntryX+localExitX);
920 double interY = 0.5*(localEntryY+localExitY);
931 double newdistX = distX - (timesX*
m_pitch_X);
932 double newdistY = distY - (timesY*
m_pitch_Y);
934 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times X --- " << timesX );
935 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times Y --- " << timesY );
936 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist X --- " << newdistX );
937 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist Y --- " << newdistY );
938 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: thickness --- " << thickness );
942 double ProbY = 2*newdistY/(
m_pitch_Y+newdistY);
943 double ProbX = 2*newdistX/(
m_pitch_X+newdistX);
945 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbX --- " << ProbX );
946 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbY --- " << ProbY );
955 int elementX = timesX+1;
956 int elementY = timesY+1;
959 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbY) {
960 sigmaY = (double)(timesY+2)*
m_pitch_Y/sqrt(12.);
963 sigmaY = (double)(timesY+1)*
m_pitch_Y/sqrt(12.);
965 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbX) {
966 sigmaX = (double)(timesX+2)*
m_pitch_X/sqrt(12.);
969 sigmaX = (double)(timesX+1)*
m_pitch_X/sqrt(12.);
976 double temp_X = interX;
977 double temp_Y = interY;
986 rdoList.push_back(intersectionId);
989 if (!currentCellId.
isValid())
continue;
991 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: Intersection Id = " << intersectionId <<
" --- currentCellId = " << currentCellId );
999 ATH_MSG_WARNING(
"--- SiSmearedDigitizationTool: pitchX and/or pitchY are 0. Cluster length is forced to be 1. mm");
1006 covariance.setIdentity();
1017 m_pixelClusterMap->insert(std::pair<IdentifierHash, InDet::PixelCluster* >(waferID, pixelCluster));
1021 return StatusCode::FAILURE;
1026 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixelCluster --> " << *pixelCluster);
1037 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: GlobalPosition --> X = " << (pixelCluster->globalPosition()).x() <<
" Y = " << (pixelCluster->globalPosition()).y());
1067 const std::pair<InDetDD::SiLocalPosition, InDetDD::SiLocalPosition> ends(design_sct->
endsOfStrip(
intersection));
1068 double stripLength = std::abs(ends.first.xEta()-ends.second.xEta());
1087 if(colRow.x() == 1) {
1090 else if(colRow.x() == 2) {
1100 double cs2 = 1.-sn2;
1117 m_sctClusterMap->insert(std::pair<IdentifierHash, InDet::SCT_Cluster* >(waferID, sctCluster));
1121 return StatusCode::FAILURE;
1126 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT_Cluster --> " << *sctCluster);
1132 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: BEFORE SMEARING LocalPosition --> X = " <<
m_x_SCT );
1145 return StatusCode::SUCCESS;
1155 elementsPixel = pixelDetEle.
retrieve();
1156 if (elementsPixel==
nullptr) {
1158 return StatusCode::FAILURE;
1165 elementsSCT = sctDetEle.
retrieve();
1166 if (elementsSCT==
nullptr) {
1168 return StatusCode::FAILURE;
1174 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel createAndStoreRIOs() ---" );
1181 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range;
1184 Pixel_detElement_RIO_map::iterator firstDetElem;
1185 firstDetElem = range.first;
1188 waferID = firstDetElem->first;
1192 InDet::PixelClusterCollection *clusterCollection =
new InDet::PixelClusterCollection(waferID);
1193 clusterCollection->setIdentifier(detElement->
identify());
1195 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter ) {
1198 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1199 clusterCollection->push_back(pixelCluster);
1203 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1212 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SCT createAndStoreRIOs() ---" );
1218 std::pair <SCT_detElement_RIO_map::iterator, SCT_detElement_RIO_map::iterator> range;
1221 SCT_detElement_RIO_map::iterator firstDetElem;
1222 firstDetElem = range.first;
1225 waferID = firstDetElem->first;
1228 InDet::SCT_ClusterCollection *clusterCollection =
new InDet::SCT_ClusterCollection(waferID);
1229 clusterCollection->setIdentifier(detElement->
identify());
1232 for ( SCT_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter ) {
1234 sctCluster->
setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1235 clusterCollection->push_back(sctCluster);
1238 if (
m_sctClusterContainer->addCollection( clusterCollection, clusterCollection->identifyHash() ).isFailure() ) {
1239 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1247 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