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"
71 m_randomEngineName(
"SiSmearedDigitization"),
76 m_useDiscSurface(false),
77 m_pixelClusterContainer(nullptr),
78 m_sctClusterContainer(nullptr),
79 m_mergeSvc(
"PileUpMergeSvc",
name),
80 m_HardScatterSplittingMode(0),
81 m_HardScatterSplittingSkipper(false),
82 m_prdTruthNamePixel(
"PRD_MultiTruthPixel"),
83 m_prdTruthNameSCT(
"PRD_MultiTruthSCT"),
87 m_outputFile(nullptr),
88 m_currentTree(nullptr),
110 m_x_pixel_smeared(0),
111 m_y_pixel_smeared(0),
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;
149 return StatusCode::FAILURE;
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;
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() ---" );
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;
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;
478 template<
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;
502 template<
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);
520 template<
typename CLUSTER>
523 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
526 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
537 template<
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 --- ");
593 for (;
i !=
e;
i = cluster_map->upper_bound(
i->first)){
594 IdentifierHash current_id =
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);
611 std::vector<Identifier> rdoList;
621 rdoList.push_back(intersectionId);
625 if ( !currentCellId.
isValid() ) {
634 std::move(clusterErr));
637 cluster_map->erase(iter);
647 return StatusCode::SUCCESS;
655 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using SCT_Clusters --- ");
660 for (;
i !=
e;
i = cluster_map->upper_bound(
i->first)){
661 IdentifierHash current_id =
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);
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();
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() "));
796 if (
m_SmearPixel && !(hitSiDetElement->isPixel()))
continue;
797 if (!
m_SmearPixel && !(hitSiDetElement->isSCT()))
continue;
799 IdentifierHash waferID;
807 HepGeom::Point3D<double> pix_localStartPosition = hit->localStartPosition();
808 HepGeom::Point3D<double> pix_localEndPosition = hit->localEndPosition();
810 pix_localStartPosition = hitSiDetElement->hitLocalToLocal3D(pix_localStartPosition);
811 pix_localEndPosition = hitSiDetElement->hitLocalToLocal3D(pix_localEndPosition);
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);
829 sct_localEndPosition = hitSiDetElement->hitLocalToLocal3D(sct_localEndPosition);
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);
874 Identifier entryId = hitSiDetElement->identifierOfPosition(localEntry);
875 Identifier exitId = hitSiDetElement->identifierOfPosition(localExit);
878 entryCellId = hitSiDetElement->cellIdFromIdentifier(entryId);
879 exitCellId = hitSiDetElement->cellIdFromIdentifier(exitId);
881 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryId " << entryId <<
" --- exitId " << exitId );
882 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryCellId " << entryCellId <<
" --- exitCellId " << exitCellId );
884 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: surface " << hitSiDetElement->surface());
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) {
941 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbX) {
952 double temp_X = interX;
953 double temp_Y = interY;
960 intersectionId = hitSiDetElement->identifierOfPosition(
intersection);
962 rdoList.push_back(intersectionId);
963 InDetDD::SiCellId currentCellId = hitSiDetElement->cellIdFromIdentifier(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),
997 return StatusCode::FAILURE;
1042 double clusterWidth = rdoList.size()*hitSiDetElement->phiPitch(
intersection);
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) {
1074 double sn = hitSiDetElement->sinStereoLocal(
intersection);
1076 double cs2 = 1.-sn2;
1077 double w = hitSiDetElement->phiPitch(
intersection)/hitSiDetElement->phiPitch();
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;
1161 firstDetElem =
range.first;
1163 IdentifierHash waferID;
1164 waferID = firstDetElem->first;
1169 clusterCollection->setIdentifier(detElement->
identify());
1174 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
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;
1198 firstDetElem =
range.first;
1200 IdentifierHash waferID;
1201 waferID = firstDetElem->first;
1205 clusterCollection->setIdentifier(detElement->
identify());
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;