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"),
88 m_outputFile(nullptr),
89 m_currentTree(nullptr),
111 m_x_pixel_smeared(0),
112 m_y_pixel_smeared(0),
145 return StatusCode::FAILURE;
150 return StatusCode::FAILURE;
156 return StatusCode::FAILURE;
169 return StatusCode::FAILURE;
179 return StatusCode::FAILURE;
185 if (service(
"THistSvc",
m_thistSvc).isFailure()) {
187 return StatusCode::FAILURE;
191 m_outputFile =
new TFile(
"CheckSmearing_Pixel.root",
"RECREATE");
192 m_currentTree =
new TTree(
"PixelTree",
"Check smearing Pixel");
211 return StatusCode::FAILURE;
217 m_outputFile =
new TFile(
"CheckSmearing_SCT.root",
"RECREATE");
234 return StatusCode::FAILURE;
243 return StatusCode::SUCCESS;
254 ATH_MSG_DEBUG (
"SiSmearedDigitizationTool : Writing Tree" );
261 return StatusCode::SUCCESS;
268 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel prepareEvent() ---" );
273 return StatusCode::SUCCESS;
281 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel processBunchXing() ---" );
288 TimedHitCollList hitCollList;
291 bSubEvents, eSubEvents).isSuccess()) &&
292 hitCollList.empty()) {
294 return StatusCode::FAILURE;
303 for( ; iColl != endColl; ++iColl) {
309 <<
" index: " << timeIndex.
index()
310 <<
" type: " << timeIndex.
type());
314 return StatusCode::SUCCESS;
320 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel processAllSubEvents() ---" );
328 ATH_MSG_FATAL(
"[ --- ] Could not create PixelClusterContainer");
329 return StatusCode::FAILURE;
338 ATH_MSG_FATAL(
"[ hitproc ] Error while registering PixelCluster container");
339 return StatusCode::FAILURE;
347 ATH_MSG_FATAL(
"[ --- ] PixelClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
348 return StatusCode::FAILURE;
350 ATH_MSG_INFO(
"[ hitproc ] PixelClusterContainer symlinked to SiClusterContainer in StoreGate" );
357 ATH_MSG_FATAL(
"[ --- ] Could not create SCT_ClusterContainer");
358 return StatusCode::FAILURE;
365 ATH_MSG_FATAL(
"[ hitproc ] Error while registering SCT_Cluster container");
366 return StatusCode::FAILURE;
372 ATH_MSG_FATAL(
"[ --- ] SCT_ClusterContainer could not be symlinked to SiClusterContainter in StoreGate !" );
373 return StatusCode::FAILURE;
375 ATH_MSG_DEBUG(
"[ hitproc ] SCT_ClusterContainer symlinked to SiClusterContainer in StoreGate" );
382 return StatusCode::FAILURE;
391 TimedHitCollList hitCollList;
392 unsigned int numberOfSimHits(0);
395 return StatusCode::FAILURE;
409 while ( iColl != endColl ) {
414 thpcsi.
insert(iColl->first, p_collection);
415 ATH_MSG_DEBUG (
"SiHitCollection found with " << p_collection->
size() <<
" hits" );
420 if(this->
digitize(ctx, thpcsi).isFailure()) {
422 return StatusCode::FAILURE;
428 return StatusCode::FAILURE;
433 return StatusCode::FAILURE;
439 return StatusCode::SUCCESS;
453 return StatusCode::FAILURE;
458 return StatusCode::FAILURE;
467 return StatusCode::FAILURE;
472 return StatusCode::FAILURE;
478 return StatusCode::SUCCESS;
482 template<
typename CLUSTER>
485 ATH_MSG_DEBUG(
"Truth map filling with cluster " << *cluster <<
" and link = " << hit->particleLink());
486 if (hit->particleLink().isValid()){
488 map->insert(std::make_pair(cluster->identify(), hit->particleLink()));
489 ATH_MSG_DEBUG(
"Truth map filled with cluster " << *cluster <<
" and link = " << hit->particleLink());
492 ATH_MSG_DEBUG(
"Particle link NOT valid!! Truth map NOT filled with cluster" << cluster <<
" and link = " << hit->particleLink());
495 return StatusCode::SUCCESS;
506 template<
typename CLUSTER>
515 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_a = " << intersection_a);
516 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: intersection_b = " << intersection_b);
518 double distX = intersection_a.x() - intersection_b.x();
519 double distY = intersection_a.y() - intersection_b.y();
521 return sqrt(distX*distX + distY*distY);
524 template<
typename CLUSTER>
527 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
530 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
541 template<
typename CLUSTER>
545 const Amg::MatrixX& clusterErr_a = clusterA->localCovariance();
549 const Amg::MatrixX& clusterErr_b = clusterB->localCovariance();
557 double interX = 0.5*(intersection_a.x()+intersection_b.x());
558 double interY = 0.5*(intersection_a.y()+intersection_b.y());
567 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_a = " << siWidth_a);
568 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth_b = " << siWidth_b);
575 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: siWidth = " << siWidth);
578 covariance.setIdentity();
592 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using PixelClusters --- ");
597 for (;
i !=
e;
i = cluster_map->upper_bound(
i->first)){
598 IdentifierHash current_id =
i->first;
601 bool NewMerge =
true;
605 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator>
range = cluster_map->equal_range(current_id);
615 std::vector<Identifier> rdoList;
625 rdoList.push_back(intersectionId);
629 if ( !currentCellId.
isValid() ) {
638 std::move(clusterErr));
641 cluster_map->erase(iter);
651 return StatusCode::SUCCESS;
659 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in mergeClusters() using SCT_Clusters --- ");
664 for (;
i !=
e;
i = cluster_map->upper_bound(
i->first)){
665 IdentifierHash current_id =
i->first;
667 bool NewMerge =
true;
672 std::pair <SCT_detElement_RIO_map::iterator, SCT_detElement_RIO_map::iterator>
range = cluster_map->equal_range(current_id);
682 std::vector<Identifier> rdoList;
692 rdoList.push_back(intersectionId);
696 if ( !currentCellId.
isValid() ) {
702 std::vector<Identifier>(rdoList),
706 ((*inner_iter).second) = sctCluster;
708 cluster_map->erase(iter);
718 return StatusCode::SUCCESS;
727 rngWrapper->
setSeed( rngName, ctx );
728 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
730 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SiSmearedDigizationTool::digitize() ---" );
736 elementsPixel = pixelDetEle.
retrieve();
737 if (elementsPixel==
nullptr) {
739 return StatusCode::FAILURE;
747 if (elementsSCT==
nullptr) {
749 return StatusCode::FAILURE;
767 int barrelEC = hit->getBarrelEndcap();
768 int layerDisk = hit->getLayerDisk();
770 int etaModule = hit->getEtaModule();
779 ATH_MSG_DEBUG(
"Pixel SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " <<
phiModule <<
", eta_module " << etaModule );
780 hitSiDetElement = hitSiDetElement_temp;
782 side = hit->getSide();
786 ATH_MSG_DEBUG(
"SCT SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " <<
phiModule <<
", eta_module " << etaModule <<
", side " <<
side);
787 hitSiDetElement = hitSiDetElement_temp;
795 if (not hitSiDetElement) {
796 ATH_MSG_FATAL(
"hitSiDetElement is null in SiSmearedDigitizationTool:"<<__LINE__);
797 throw std::runtime_error(std::string(
"hitSiDetElement is null in SiSmearedDigitizationTool::digitize() "));
800 if (
m_SmearPixel && !(hitSiDetElement->isPixel()))
continue;
801 if (!
m_SmearPixel && !(hitSiDetElement->isSCT()))
continue;
803 IdentifierHash waferID;
811 HepGeom::Point3D<double> pix_localStartPosition = hit->localStartPosition();
812 HepGeom::Point3D<double> pix_localEndPosition = hit->localEndPosition();
814 pix_localStartPosition = hitSiDetElement->hitLocalToLocal3D(pix_localStartPosition);
815 pix_localEndPosition = hitSiDetElement->hitLocalToLocal3D(pix_localEndPosition);
817 double localEntryX = pix_localStartPosition.x();
818 double localEntryY = pix_localStartPosition.y();
819 double localEntryZ = pix_localStartPosition.z();
820 double localExitX = pix_localEndPosition.x();
821 double localExitY = pix_localEndPosition.y();
822 double localExitZ = pix_localEndPosition.z();
824 double thickness = 0.0;
825 thickness = hitSiDetElement->thickness();
829 HepGeom::Point3D<double> sct_localStartPosition = hit->localStartPosition();
830 HepGeom::Point3D<double> sct_localEndPosition = hit->localEndPosition();
832 sct_localStartPosition = hitSiDetElement->hitLocalToLocal3D(sct_localStartPosition);
833 sct_localEndPosition = hitSiDetElement->hitLocalToLocal3D(sct_localEndPosition);
835 localEntryX = sct_localStartPosition.x();
836 localEntryY = sct_localStartPosition.y();
837 localEntryZ = sct_localStartPosition.z();
838 localExitX = sct_localEndPosition.x();
839 localExitY = sct_localEndPosition.y();
840 localExitZ = sct_localEndPosition.z();
843 double distX = std::abs(std::abs(localExitX)-std::abs(localEntryX));
844 double distY = std::abs(std::abs(localExitY)-std::abs(localEntryY));
847 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
848 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
856 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
857 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
870 std::vector<Identifier> rdoList;
872 Amg::Vector3D localDirection(localExitX-localEntryX, localExitY-localEntryY, localExitZ-localEntryZ);
878 Identifier entryId = hitSiDetElement->identifierOfPosition(localEntry);
879 Identifier exitId = hitSiDetElement->identifierOfPosition(localExit);
882 entryCellId = hitSiDetElement->cellIdFromIdentifier(entryId);
883 exitCellId = hitSiDetElement->cellIdFromIdentifier(exitId);
885 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryId " << entryId <<
" --- exitId " << exitId );
886 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryCellId " << entryCellId <<
" --- exitCellId " << exitCellId );
888 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: surface " << hitSiDetElement->surface());
891 bool entryValid = entryCellId.
isValid();
892 bool exitValid = exitCellId.
isValid();
894 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryValid? " << entryValid <<
" --- exitValid? " << exitValid );
896 if (!entryValid && !exitValid)
continue;
899 double interX = 0.5*(localEntryX+localExitX);
900 double interY = 0.5*(localEntryY+localExitY);
911 double newdistX = distX - (timesX*
m_pitch_X);
912 double newdistY = distY - (timesY*
m_pitch_Y);
914 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times X --- " << timesX );
915 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: times Y --- " << timesY );
916 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist X --- " << newdistX );
917 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: new dist Y --- " << newdistY );
918 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: thickness --- " << thickness );
922 double ProbY = 2*newdistY/(
m_pitch_Y+newdistY);
923 double ProbX = 2*newdistX/(
m_pitch_X+newdistX);
925 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbX --- " << ProbX );
926 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbY --- " << ProbY );
935 int elementX = timesX+1;
936 int elementY = timesY+1;
939 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbY) {
945 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbX) {
956 double temp_X = interX;
957 double temp_Y = interY;
963 Identifier intersectionId;
964 intersectionId = hitSiDetElement->identifierOfPosition(
intersection);
966 rdoList.push_back(intersectionId);
967 InDetDD::SiCellId currentCellId = hitSiDetElement->cellIdFromIdentifier(intersectionId);
969 if (!currentCellId.
isValid())
continue;
971 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: Intersection Id = " << intersectionId <<
" --- currentCellId = " << currentCellId );
979 ATH_MSG_WARNING(
"--- SiSmearedDigitizationTool: pitchX and/or pitchY are 0. Cluster length is forced to be 1. mm");
986 covariance.setIdentity();
993 std::vector<Identifier>(rdoList),
1001 return StatusCode::FAILURE;
1046 double clusterWidth = rdoList.size()*hitSiDetElement->phiPitch(
intersection);
1047 const std::pair<InDetDD::SiLocalPosition, InDetDD::SiLocalPosition> ends(design_sct->
endsOfStrip(
intersection));
1048 double stripLength = std::abs(ends.first.xEta()-ends.second.xEta());
1067 if(colRow.x() == 1) {
1070 else if(colRow.x() == 2) {
1078 double sn = hitSiDetElement->sinStereoLocal(
intersection);
1080 double cs2 = 1.-sn2;
1081 double w = hitSiDetElement->phiPitch(
intersection)/hitSiDetElement->phiPitch();
1092 std::vector<Identifier>(rdoList),
1097 m_sctClusterMap->insert(std::pair<IdentifierHash, InDet::SCT_Cluster* >(waferID, sctCluster));
1101 return StatusCode::FAILURE;
1106 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT_Cluster --> " << *sctCluster);
1112 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: BEFORE SMEARING LocalPosition --> X = " <<
m_x_SCT );
1125 return StatusCode::SUCCESS;
1135 elementsPixel = pixelDetEle.
retrieve();
1136 if (elementsPixel==
nullptr) {
1138 return StatusCode::FAILURE;
1145 elementsSCT = sctDetEle.
retrieve();
1146 if (elementsSCT==
nullptr) {
1148 return StatusCode::FAILURE;
1154 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in pixel createAndStoreRIOs() ---" );
1161 std::pair <Pixel_detElement_RIO_map::iterator, Pixel_detElement_RIO_map::iterator>
range;
1165 firstDetElem =
range.first;
1167 IdentifierHash waferID;
1168 waferID = firstDetElem->first;
1173 clusterCollection->setIdentifier(detElement->
identify());
1178 pixelCluster->setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1183 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1192 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SCT createAndStoreRIOs() ---" );
1198 std::pair <SCT_detElement_RIO_map::iterator, SCT_detElement_RIO_map::iterator>
range;
1202 firstDetElem =
range.first;
1204 IdentifierHash waferID;
1205 waferID = firstDetElem->first;
1209 clusterCollection->setIdentifier(detElement->
identify());
1214 sctCluster->
setHashAndIndex(clusterCollection->identifyHash(),clusterCollection->size());
1215 clusterCollection->push_back(sctCluster);
1218 if (
m_sctClusterContainer->addCollection( clusterCollection, clusterCollection->identifyHash() ).isFailure() ) {
1219 ATH_MSG_WARNING(
"Could not add collection to Identifyable container !" );
1227 return StatusCode::SUCCESS;