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() ---" );
319 unsigned int nwafer =
m_pixel_ID->wafer_hash_max();
321 ATH_CHECK( wh.record (std::make_unique<InDet::PixelClusterContainer>(nwafer)) );
332 unsigned int nwafer =
m_sct_ID->wafer_hash_max();
334 ATH_CHECK( wh.record (std::make_unique<InDet::SCT_ClusterContainer>(nwafer)) );
345 return StatusCode::FAILURE;
354 TimedHitCollList hitCollList;
355 unsigned int numberOfSimHits(0);
358 return StatusCode::FAILURE;
367 TimedHitCollList::iterator iColl(hitCollList.begin());
368 TimedHitCollList::iterator endColl(hitCollList.end() );
372 while ( iColl != endColl ) {
377 thpcsi.
insert(iColl->first, p_collection);
378 ATH_MSG_DEBUG (
"SiHitCollection found with " << p_collection->
size() <<
" hits" );
383 if(this->
digitize(ctx, thpcsi).isFailure()) {
385 return StatusCode::FAILURE;
391 return StatusCode::FAILURE;
396 return StatusCode::FAILURE;
402 return StatusCode::SUCCESS;
416 return StatusCode::FAILURE;
421 return StatusCode::FAILURE;
430 return StatusCode::FAILURE;
435 return StatusCode::FAILURE;
441 return StatusCode::SUCCESS;
445template<
typename CLUSTER>
448 ATH_MSG_DEBUG(
"Truth map filling with cluster " << *cluster <<
" and link = " <<
hit->particleLink());
449 if (
hit->particleLink().isValid()){
451 map->insert(std::make_pair(cluster->identify(),
hit->particleLink()));
452 ATH_MSG_DEBUG(
"Truth map filled with cluster " << *cluster <<
" and link = " <<
hit->particleLink());
455 ATH_MSG_DEBUG(
"Particle link NOT valid!! Truth map NOT filled with cluster" << cluster <<
" and link = " <<
hit->particleLink());
458 return StatusCode::SUCCESS;
469template<
typename CLUSTER>
478 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_a = " << intersection_a);
479 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_b = " << intersection_b);
481 double distX = intersection_a.x() - intersection_b.x();
482 double distY = intersection_a.y() - intersection_b.y();
484 return sqrt(distX*distX + distY*distY);
487template<
typename CLUSTER>
490 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
493 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
501 return sqrt(sigmaX*sigmaX + sigmaY*sigmaY);
504template<
typename CLUSTER>
508 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
512 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
520 double interX = 0.5*(intersection_a.x()+intersection_b.x());
521 double interY = 0.5*(intersection_a.y()+intersection_b.y());
530 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_a = " << siWidth_a);
531 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_b = " << siWidth_b);
538 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth = " << siWidth);
541 covariance.setIdentity();
555 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using PixelClusters --- ");
557 Pixel_detElement_RIO_map::iterator i = cluster_map->begin();
558 Pixel_detElement_RIO_map::iterator e = cluster_map->end();
560 for (; i != e; i = cluster_map->upper_bound(i->first)){
564 bool NewMerge =
true;
568 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range = cluster_map->equal_range(current_id);
570 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter){
571 for (Pixel_detElement_RIO_map::iterator inner_iter = std::next(iter); inner_iter != range.second; ++inner_iter){
574 double sigma =
calculateSigma((*iter).second,(*inner_iter).second);
578 std::vector<Identifier> rdoList;
588 rdoList.push_back(intersectionId);
592 if ( !currentCellId.
isValid() ) {
601 std::move(clusterErr));
602 ((*inner_iter).second) = pixelCluster;
604 cluster_map->erase(iter);
614 return StatusCode::SUCCESS;
621 "--- SiSmearedDigitizationTool: in mergeClusters() using SCT_Clusters ---");
624 ATH_MSG_FATAL(
"Null SCT cluster map passed to mergeClusters()");
625 return StatusCode::FAILURE;
628 auto i = cluster_map->begin();
630 while (i != cluster_map->end()) {
635 mergedThisPass =
false;
636 const auto range = cluster_map->equal_range(current_id);
638 auto iter = range.first;
641 while (iter != range.second && !mergedThisPass) {
642 auto inner_iter = std::next(iter);
644 while (inner_iter != range.second) {
663 inner_iter->second->detectorElement();
671 if (!currentCellId.
isValid()) {
676 std::vector<Identifier> rdoList{intersectionId};
678 auto sctCluster = std::make_unique<InDet::SCT_Cluster>(
684 std::move(clusterErr));
686 auto*
const oldIterCluster = iter->second;
687 auto*
const oldInnerCluster = inner_iter->second;
689 inner_iter->second = sctCluster.release();
691 delete oldIterCluster;
692 delete oldInnerCluster;
694 cluster_map->erase(iter);
696 mergedThisPass =
true;
700 if (!mergedThisPass) {
704 }
while (mergedThisPass);
706 i = cluster_map->upper_bound(current_id);
709 return StatusCode::SUCCESS;
717 rngWrapper->
setSeed( rngName, ctx );
718 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
720 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SiSmearedDigizationTool::digitize() ---" );
726 elementsPixel = pixelDetEle.
retrieve();
727 if (elementsPixel==
nullptr) {
729 return StatusCode::FAILURE;
737 if (elementsSCT==
nullptr) {
739 return StatusCode::FAILURE;
757 int barrelEC =
hit->getBarrelEndcap();
758 int layerDisk =
hit->getLayerDisk();
759 int phiModule =
hit->getPhiModule();
760 int etaModule =
hit->getEtaModule();
769 ATH_MSG_DEBUG(
"Pixel SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule );
770 hitSiDetElement = hitSiDetElement_temp;
772 side =
hit->getSide();
776 ATH_MSG_DEBUG(
"SCT SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule <<
", side " << side);
777 hitSiDetElement = hitSiDetElement_temp;
785 if (not hitSiDetElement) {
786 ATH_MSG_FATAL(
"hitSiDetElement is null in SiSmearedDigitizationTool:"<<__LINE__);
787 throw std::runtime_error(std::string(
"hitSiDetElement is null in SiSmearedDigitizationTool::digitize() "));
801 HepGeom::Point3D<double> pix_localStartPosition =
hit->localStartPosition();
802 HepGeom::Point3D<double> pix_localEndPosition =
hit->localEndPosition();
804 pix_localStartPosition = hitSiDetElement->
hitLocalToLocal3D(pix_localStartPosition);
807 double localEntryX = pix_localStartPosition.x();
808 double localEntryY = pix_localStartPosition.y();
809 double localEntryZ = pix_localStartPosition.z();
810 double localExitX = pix_localEndPosition.x();
811 double localExitY = pix_localEndPosition.y();
812 double localExitZ = pix_localEndPosition.z();
814 double thickness = 0.0;
815 thickness = hitSiDetElement->
thickness();
819 HepGeom::Point3D<double> sct_localStartPosition =
hit->localStartPosition();
820 HepGeom::Point3D<double> sct_localEndPosition =
hit->localEndPosition();
822 sct_localStartPosition = hitSiDetElement->
hitLocalToLocal3D(sct_localStartPosition);
825 localEntryX = sct_localStartPosition.x();
826 localEntryY = sct_localStartPosition.y();
827 localEntryZ = sct_localStartPosition.z();
828 localExitX = sct_localEndPosition.x();
829 localExitY = sct_localEndPosition.y();
830 localExitZ = sct_localEndPosition.z();
833 double distX = std::abs(std::abs(localExitX)-std::abs(localEntryX));
834 double distY = std::abs(std::abs(localExitY)-std::abs(localEntryY));
837 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
838 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
846 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
847 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
860 std::vector<Identifier> rdoList;
862 Amg::Vector3D localDirection(localExitX-localEntryX, localExitY-localEntryY, localExitZ-localEntryZ);
875 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryId " << entryId <<
" --- exitId " << exitId );
876 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryCellId " << entryCellId <<
" --- exitCellId " << exitCellId );
881 bool entryValid = entryCellId.
isValid();
882 bool exitValid = exitCellId.
isValid();
884 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryValid? " << entryValid <<
" --- exitValid? " << exitValid );
886 if (!entryValid && !exitValid)
continue;
889 double interX = 0.5*(localEntryX+localExitX);
890 double interY = 0.5*(localEntryY+localExitY);
901 double newdistX = distX - (timesX*
m_pitch_X);
902 double newdistY = distY - (timesY*
m_pitch_Y);
904 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times X --- " << timesX );
905 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times Y --- " << timesY );
906 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist X --- " << newdistX );
907 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist Y --- " << newdistY );
908 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: thickness --- " << thickness );
912 double ProbY = 2*newdistY/(
m_pitch_Y+newdistY);
913 double ProbX = 2*newdistX/(
m_pitch_X+newdistX);
915 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbX --- " << ProbX );
916 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbY --- " << ProbY );
925 int elementX = timesX+1;
926 int elementY = timesY+1;
929 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbY) {
930 sigmaY = (double)(timesY+2)*
m_pitch_Y/sqrt(12.);
933 sigmaY = (double)(timesY+1)*
m_pitch_Y/sqrt(12.);
935 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbX) {
936 sigmaX = (double)(timesX+2)*
m_pitch_X/sqrt(12.);
939 sigmaX = (double)(timesX+1)*
m_pitch_X/sqrt(12.);
946 double temp_X = interX;
947 double temp_Y = interY;
956 rdoList.push_back(intersectionId);
959 if (!currentCellId.
isValid())
continue;
961 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: Intersection Id = " << intersectionId <<
" --- currentCellId = " << currentCellId );
969 ATH_MSG_WARNING(
"--- SiSmearedDigitizationTool: pitchX and/or pitchY are 0. Cluster length is forced to be 1. mm");
976 covariance.setIdentity();
987 m_pixelClusterMap->insert(std::pair<IdentifierHash, InDet::PixelCluster* >(waferID, pixelCluster));
991 return StatusCode::FAILURE;
996 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixelCluster --> " << *pixelCluster);
1007 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: GlobalPosition --> X = " << (pixelCluster->globalPosition()).x() <<
" Y = " << (pixelCluster->globalPosition()).y());
1037 const std::pair<InDetDD::SiLocalPosition, InDetDD::SiLocalPosition> ends(design_sct->
endsOfStrip(
intersection));
1038 double stripLength = std::abs(ends.first.xEta()-ends.second.xEta());
1057 if(colRow.x() == 1) {
1060 else if(colRow.x() == 2) {
1070 double cs2 = 1.-sn2;
1087 m_sctClusterMap->insert(std::pair<IdentifierHash, InDet::SCT_Cluster* >(waferID, sctCluster));
1091 return StatusCode::FAILURE;
1096 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT_Cluster --> " << *sctCluster);
1102 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: BEFORE SMEARING LocalPosition --> X = " <<
m_x_SCT );
1115 return StatusCode::SUCCESS;
1125 elementsPixel = pixelDetEle.
retrieve();
1126 if (elementsPixel==
nullptr) {
1128 return StatusCode::FAILURE;
1135 elementsSCT = sctDetEle.
retrieve();
1136 if (elementsSCT==
nullptr) {
1138 return StatusCode::FAILURE;
1144 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel createAndStoreRIOs() ---" );
1151 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator> range;
1154 Pixel_detElement_RIO_map::iterator firstDetElem;
1155 firstDetElem = range.first;
1158 waferID = firstDetElem->first;
1162 InDet::PixelClusterCollection *clusterCollection =
new InDet::PixelClusterCollection(waferID);
1163 clusterCollection->setIdentifier(detElement->
identify());
1165 for ( Pixel_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter ) {
1168 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1169 clusterCollection->push_back(pixelCluster);
1173 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1182 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SCT createAndStoreRIOs() ---" );
1188 std::pair <SCT_detElement_RIO_map::iterator, SCT_detElement_RIO_map::iterator> range;
1191 SCT_detElement_RIO_map::iterator firstDetElem;
1192 firstDetElem = range.first;
1195 waferID = firstDetElem->first;
1198 InDet::SCT_ClusterCollection *clusterCollection =
new InDet::SCT_ClusterCollection(waferID);
1199 clusterCollection->setIdentifier(detElement->
identify());
1202 for ( SCT_detElement_RIO_map::iterator iter = range.first; iter != range.second; ++iter ) {
1204 sctCluster->
setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1205 clusterCollection->push_back(sctCluster);
1208 if (
m_sctClusterContainer->addCollection( clusterCollection, clusterCollection->identifyHash() ).isFailure() ) {
1209 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1217 return StatusCode::SUCCESS;
#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_INFO(x,...)
#define ATH_MSG_FATAL(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()
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.
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