713{
714
717 rngWrapper->
setSeed( rngName, ctx );
718 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
719
720 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SiSmearedDigizationTool::digitize() ---" );
721
722
723 const InDetDD::SiDetectorElementCollection* elementsPixel = nullptr;
725 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> pixelDetEle(
m_pixelDetEleCollKey, ctx);
726 elementsPixel = pixelDetEle.retrieve();
727 if (elementsPixel==nullptr) {
729 return StatusCode::FAILURE;
730 }
731 }
732
733 const InDetDD::SiDetectorElementCollection* elementsSCT = nullptr;
735 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle(
m_SCTDetEleCollKey, ctx);
736 elementsSCT = sctDetEle.retrieve();
737 if (elementsSCT==nullptr) {
739 return StatusCode::FAILURE;
740 }
741 }
742
744
747 } else {
749 }
750
752
753 while (i != e) {
755
756 const TimedHitPtr<SiHit>&
hit(*i++);
757 int barrelEC =
hit->getBarrelEndcap();
758 int layerDisk =
hit->getLayerDisk();
760 int etaModule =
hit->getEtaModule();
762
763 const InDetDD::SiDetectorElement* hitSiDetElement = nullptr;
764
766 Identifier wafer_id =
m_pixel_ID->wafer_id(barrelEC,layerDisk,phiModule,etaModule);
767 IdentifierHash wafer_hash =
m_pixel_ID->wafer_hash(wafer_id);
768 const InDetDD::SiDetectorElement* hitSiDetElement_temp = elementsPixel->
getDetectorElement(wafer_hash);
769 ATH_MSG_DEBUG(
"Pixel SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule );
770 hitSiDetElement = hitSiDetElement_temp;
771 } else {
773 Identifier idwafer =
m_sct_ID->wafer_id(barrelEC,layerDisk,phiModule,etaModule,side);
775 const InDetDD::SiDetectorElement* hitSiDetElement_temp = elementsSCT->
getDetectorElement(idhash);
776 ATH_MSG_DEBUG(
"SCT SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule <<
", side " << side);
777 hitSiDetElement = hitSiDetElement_temp;
778 }
779
780
781
782
783
784
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() "));
788 }
789
790 if (
m_SmearPixel && !(hitSiDetElement->isPixel()))
continue;
791 if (!
m_SmearPixel && !(hitSiDetElement->isSCT()))
continue;
792
793 IdentifierHash waferID;
794
796 waferID =
m_pixel_ID->wafer_hash(hitSiDetElement->identify());
797 } else {
798 waferID =
m_sct_ID->wafer_hash(hitSiDetElement->identify());
799 }
800
801 HepGeom::Point3D<double> pix_localStartPosition =
hit->localStartPosition();
802 HepGeom::Point3D<double> pix_localEndPosition =
hit->localEndPosition();
803
804 pix_localStartPosition = hitSiDetElement->hitLocalToLocal3D(pix_localStartPosition);
805 pix_localEndPosition = hitSiDetElement->hitLocalToLocal3D(pix_localEndPosition);
806
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();
813
814 double thickness = 0.0;
815 thickness = hitSiDetElement->thickness();
816
817
819 HepGeom::Point3D<double> sct_localStartPosition =
hit->localStartPosition();
820 HepGeom::Point3D<double> sct_localEndPosition =
hit->localEndPosition();
821
822 sct_localStartPosition = hitSiDetElement->hitLocalToLocal3D(sct_localStartPosition);
823 sct_localEndPosition = hitSiDetElement->hitLocalToLocal3D(sct_localEndPosition);
824
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();
831 }
832
833 double distX = std::abs(std::abs(localExitX)-std::abs(localEntryX));
834 double distY = std::abs(std::abs(localExitY)-std::abs(localEntryY));
835
837 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
838 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
845 } else {
846 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
847 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
854 }
855
858
859
860 std::vector<Identifier> rdoList;
861
862 Amg::Vector3D localDirection(localExitX-localEntryX, localExitY-localEntryY, localExitZ-localEntryZ);
863
864 InDetDD::SiCellId entryCellId;
865 InDetDD::SiCellId exitCellId;
866
867
868 Identifier entryId = hitSiDetElement->identifierOfPosition(localEntry);
869 Identifier exitId = hitSiDetElement->identifierOfPosition(localExit);
870
871
872 entryCellId = hitSiDetElement->cellIdFromIdentifier(entryId);
873 exitCellId = hitSiDetElement->cellIdFromIdentifier(exitId);
874
875 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryId " << entryId <<
" --- exitId " << exitId );
876 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryCellId " << entryCellId <<
" --- exitCellId " << exitCellId );
877
878 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: surface " << hitSiDetElement->surface());
879
880
881 bool entryValid = entryCellId.
isValid();
882 bool exitValid = exitCellId.
isValid();
883
884 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryValid? " << entryValid <<
" --- exitValid? " << exitValid );
885
886 if (!entryValid && !exitValid) continue;
887
888
889 double interX = 0.5*(localEntryX+localExitX);
890 double interY = 0.5*(localEntryY+localExitY);
891
896
897
900
901 double newdistX = distX - (timesX*
m_pitch_X);
902 double newdistY = distY - (timesY*
m_pitch_Y);
903
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 );
909
910
911
912 double ProbY = 2*newdistY/(
m_pitch_Y+newdistY);
913 double ProbX = 2*newdistX/(
m_pitch_X+newdistX);
914
915 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbX --- " << ProbX );
916 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbY --- " << ProbY );
917
918
921
924
925 int elementX = timesX+1;
926 int elementY = timesY+1;
927
929 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbY) {
931 elementY++;
932 } else
934
935 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbX) {
937 elementX++;
938 } else
940 }
941
944
945
946 double temp_X = interX;
947 double temp_Y = interY;
948
950
952
953 Identifier intersectionId;
954 intersectionId = hitSiDetElement->identifierOfPosition(
intersection);
955
956 rdoList.push_back(intersectionId);
957 InDetDD::SiCellId currentCellId = hitSiDetElement->cellIdFromIdentifier(intersectionId);
958
959 if (!currentCellId.
isValid())
continue;
960
961 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: Intersection Id = " << intersectionId <<
" --- currentCellId = " << currentCellId );
962
964
967
969 ATH_MSG_WARNING(
"--- SiSmearedDigitizationTool: pitchX and/or pitchY are 0. Cluster length is forced to be 1. mm");
970
972
974
976 covariance.setIdentity();
977 covariance(Trk::locX,Trk::locX) = sigmaX*sigmaX;
978 covariance(Trk::locY,Trk::locY) = sigmaY*sigmaY;
979
980
981 pixelCluster = new InDet::PixelCluster(intersectionId,
983 std::move(rdoList),
984 siWidth,
985 hitSiDetElement,
986 Amg::MatrixX(covariance));
987 m_pixelClusterMap->insert(std::pair<IdentifierHash, InDet::PixelCluster* >(waferID, pixelCluster));
988
991 return StatusCode::FAILURE;
992 }
993
995
996 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixelCluster --> " << *pixelCluster);
997
1000
1003
1006
1011
1014
1016
1018 }
1019
1020 } else {
1021
1022
1023 InDet::SCT_Cluster * sctCluster = nullptr;
1024
1025
1026 const InDetDD::SCT_ModuleSideDesign* design_sct;
1027
1028 design_sct = dynamic_cast<const InDetDD::SCT_ModuleSideDesign*>(&hitSiDetElement->design());
1029
1030 if (!design_sct) {
1032 continue;
1033 }
1034
1035
1036 double clusterWidth = rdoList.size()*hitSiDetElement->phiPitch(
intersection);
1037 const std::pair<InDetDD::SiLocalPosition, InDetDD::SiLocalPosition> ends(design_sct->
endsOfStrip(
intersection));
1038 double stripLength = std::abs(ends.first.xEta()-ends.second.xEta());
1039
1040 InDet::SiWidth siWidth(
Amg::Vector2D(
int(rdoList.size()),1),
1042
1044
1046 mat.setIdentity();
1047 mat(Trk::locX,Trk::locX) = sigmaX*sigmaX;
1048 mat(Trk::locY,Trk::locY) = hitSiDetElement->
length()*hitSiDetElement->
length()/12.;
1049
1050
1051
1052
1053 InDetDD::
DetectorShape elShape = hitSiDetElement->design().shape();
1055 {
1056
1057 if(colRow.x() == 1) {
1058 mat(Trk::locX,Trk::locX) = pow(siWidth.phiR(),2)/12;
1059 }
1060 else if(colRow.x() == 2) {
1061 mat(Trk::locX,Trk::locX) = pow(0.27*siWidth.phiR(),2)/12;
1062 }
1063 else {
1064 mat(Trk::locX,Trk::locX) = pow(siWidth.phiR(),2)/12;
1065 }
1066
1068 double sn = hitSiDetElement->sinStereoLocal(
intersection);
1069 double sn2 = sn*sn;
1070 double cs2 = 1.-sn2;
1071 double w = hitSiDetElement->phiPitch(
intersection)/hitSiDetElement->phiPitch();
1077 }
1078
1079
1080 sctCluster = new InDet::SCT_Cluster(intersectionId,
1082 std::move(rdoList),
1083 siWidth,
1084 hitSiDetElement,
1086
1087 m_sctClusterMap->insert(std::pair<IdentifierHash, InDet::SCT_Cluster* >(waferID, sctCluster));
1088
1091 return StatusCode::FAILURE;
1092 }
1093
1095
1096 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT_Cluster --> " << *sctCluster);
1097
1098
1101
1102 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: BEFORE SMEARING LocalPosition --> X = " <<
m_x_SCT );
1104
1109
1111 }
1112 }
1113 }
1114 }
1115 return StatusCode::SUCCESS;
1116}
#define ATH_MSG_INFO(x,...)
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.
virtual std::pair< SiLocalPosition, SiLocalPosition > endsOfStrip(const SiLocalPosition &position) const override=0
give the ends of strips
bool isValid() const
Test if its in a valid state.
const Amg::Vector3D & globalPosition() const
return global position reference
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
const Amg::Vector2D & localPosition() const
return the local position reference
Eigen::Matrix< double, 3, 1 > Vector3D