743{
744
747 rngWrapper->
setSeed( rngName, ctx );
748 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
749
750 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: in SiSmearedDigizationTool::digitize() ---" );
751
752
753 const InDetDD::SiDetectorElementCollection* elementsPixel = nullptr;
755 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> pixelDetEle(
m_pixelDetEleCollKey, ctx);
756 elementsPixel = pixelDetEle.retrieve();
757 if (elementsPixel==nullptr) {
759 return StatusCode::FAILURE;
760 }
761 }
762
763 const InDetDD::SiDetectorElementCollection* elementsSCT = nullptr;
765 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle(
m_SCTDetEleCollKey, ctx);
766 elementsSCT = sctDetEle.retrieve();
767 if (elementsSCT==nullptr) {
769 return StatusCode::FAILURE;
770 }
771 }
772
774
777 } else {
779 }
780
782
783 while (i != e) {
785
786 const TimedHitPtr<SiHit>& hit(*i++);
787 int barrelEC = hit->getBarrelEndcap();
788 int layerDisk = hit->getLayerDisk();
790 int etaModule = hit->getEtaModule();
792
793 const InDetDD::SiDetectorElement* hitSiDetElement = nullptr;
794
796 Identifier wafer_id =
m_pixel_ID->wafer_id(barrelEC,layerDisk,phiModule,etaModule);
797 IdentifierHash wafer_hash =
m_pixel_ID->wafer_hash(wafer_id);
798 const InDetDD::SiDetectorElement* hitSiDetElement_temp = elementsPixel->
getDetectorElement(wafer_hash);
799 ATH_MSG_DEBUG(
"Pixel SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule );
800 hitSiDetElement = hitSiDetElement_temp;
801 } else {
802 side = hit->getSide();
803 Identifier idwafer =
m_sct_ID->wafer_id(barrelEC,layerDisk,phiModule,etaModule,side);
805 const InDetDD::SiDetectorElement* hitSiDetElement_temp = elementsSCT->
getDetectorElement(idhash);
806 ATH_MSG_DEBUG(
"SCT SiDetectorElement --> barrel_ec " << barrelEC <<
", layer_disk " << layerDisk <<
", phi_module " << phiModule <<
", eta_module " << etaModule <<
", side " << side);
807 hitSiDetElement = hitSiDetElement_temp;
808 }
809
810
811
812
813
814
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() "));
818 }
819
820 if (
m_SmearPixel && !(hitSiDetElement->isPixel()))
continue;
821 if (!
m_SmearPixel && !(hitSiDetElement->isSCT()))
continue;
822
823 IdentifierHash waferID;
824
826 waferID =
m_pixel_ID->wafer_hash(hitSiDetElement->identify());
827 } else {
828 waferID =
m_sct_ID->wafer_hash(hitSiDetElement->identify());
829 }
830
831 HepGeom::Point3D<double> pix_localStartPosition = hit->localStartPosition();
832 HepGeom::Point3D<double> pix_localEndPosition = hit->localEndPosition();
833
834 pix_localStartPosition = hitSiDetElement->hitLocalToLocal3D(pix_localStartPosition);
835 pix_localEndPosition = hitSiDetElement->hitLocalToLocal3D(pix_localEndPosition);
836
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();
843
844 double thickness = 0.0;
845 thickness = hitSiDetElement->thickness();
846
847
849 HepGeom::Point3D<double> sct_localStartPosition = hit->localStartPosition();
850 HepGeom::Point3D<double> sct_localEndPosition = hit->localEndPosition();
851
852 sct_localStartPosition = hitSiDetElement->hitLocalToLocal3D(sct_localStartPosition);
853 sct_localEndPosition = hitSiDetElement->hitLocalToLocal3D(sct_localEndPosition);
854
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();
861 }
862
863 double distX = std::abs(std::abs(localExitX)-std::abs(localEntryX));
864 double distY = std::abs(std::abs(localExitY)-std::abs(localEntryY));
865
867 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
868 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixel exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
875 } else {
876 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT start position --- " << localEntryX <<
", " << localEntryY <<
", " << localEntryZ );
877 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT exit position --- " << localExitX <<
", " << localExitY <<
", " << localExitZ );
884 }
885
888
889
890 std::vector<Identifier> rdoList;
891
892 Amg::Vector3D localDirection(localExitX-localEntryX, localExitY-localEntryY, localExitZ-localEntryZ);
893
894 InDetDD::SiCellId entryCellId;
895 InDetDD::SiCellId exitCellId;
896
897
898 Identifier entryId = hitSiDetElement->identifierOfPosition(localEntry);
899 Identifier exitId = hitSiDetElement->identifierOfPosition(localExit);
900
901
902 entryCellId = hitSiDetElement->cellIdFromIdentifier(entryId);
903 exitCellId = hitSiDetElement->cellIdFromIdentifier(exitId);
904
905 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryId " << entryId <<
" --- exitId " << exitId );
906 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryCellId " << entryCellId <<
" --- exitCellId " << exitCellId );
907
908 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: surface " << hitSiDetElement->surface());
909
910
911 bool entryValid = entryCellId.
isValid();
912 bool exitValid = exitCellId.
isValid();
913
914 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: entryValid? " << entryValid <<
" --- exitValid? " << exitValid );
915
916 if (!entryValid && !exitValid) continue;
917
918
919 double interX = 0.5*(localEntryX+localExitX);
920 double interY = 0.5*(localEntryY+localExitY);
921
926
927
930
931 double newdistX = distX - (timesX*
m_pitch_X);
932 double newdistY = distY - (timesY*
m_pitch_Y);
933
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 );
939
940
941
942 double ProbY = 2*newdistY/(
m_pitch_Y+newdistY);
943 double ProbX = 2*newdistX/(
m_pitch_X+newdistX);
944
945 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbX --- " << ProbX );
946 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: ProbY --- " << ProbY );
947
948
951
954
955 int elementX = timesX+1;
956 int elementY = timesY+1;
957
959 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbY) {
961 elementY++;
962 } else
964
965 if (CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) < ProbX) {
967 elementX++;
968 } else
970 }
971
974
975
976 double temp_X = interX;
977 double temp_Y = interY;
978
980
982
983 Identifier intersectionId;
984 intersectionId = hitSiDetElement->identifierOfPosition(
intersection);
985
986 rdoList.push_back(intersectionId);
987 InDetDD::SiCellId currentCellId = hitSiDetElement->cellIdFromIdentifier(intersectionId);
988
989 if (!currentCellId.
isValid())
continue;
990
991 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: Intersection Id = " << intersectionId <<
" --- currentCellId = " << currentCellId );
992
994
997
999 ATH_MSG_WARNING(
"--- SiSmearedDigitizationTool: pitchX and/or pitchY are 0. Cluster length is forced to be 1. mm");
1000
1002
1004
1006 covariance.setIdentity();
1007 covariance(Trk::locX,Trk::locX) = sigmaX*sigmaX;
1008 covariance(Trk::locY,Trk::locY) = sigmaY*sigmaY;
1009
1010
1011 pixelCluster = new InDet::PixelCluster(intersectionId,
1013 std::move(rdoList),
1014 siWidth,
1015 hitSiDetElement,
1016 Amg::MatrixX(covariance));
1017 m_pixelClusterMap->insert(std::pair<IdentifierHash, InDet::PixelCluster* >(waferID, pixelCluster));
1018
1021 return StatusCode::FAILURE;
1022 }
1023
1025
1026 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: pixelCluster --> " << *pixelCluster);
1027
1030
1033
1036
1041
1044
1046
1048 }
1049
1050 } else {
1051
1052
1053 InDet::SCT_Cluster * sctCluster = nullptr;
1054
1055
1056 const InDetDD::SCT_ModuleSideDesign* design_sct;
1057
1058 design_sct = dynamic_cast<const InDetDD::SCT_ModuleSideDesign*>(&hitSiDetElement->design());
1059
1060 if (!design_sct) {
1062 continue;
1063 }
1064
1065
1066 double clusterWidth = rdoList.size()*hitSiDetElement->phiPitch(
intersection);
1067 const std::pair<InDetDD::SiLocalPosition, InDetDD::SiLocalPosition> ends(design_sct->
endsOfStrip(
intersection));
1068 double stripLength = std::abs(ends.first.xEta()-ends.second.xEta());
1069
1070 InDet::SiWidth siWidth(
Amg::Vector2D(
int(rdoList.size()),1),
1072
1074
1076 mat.setIdentity();
1077 mat(Trk::locX,Trk::locX) = sigmaX*sigmaX;
1078 mat(Trk::locY,Trk::locY) = hitSiDetElement->
length()*hitSiDetElement->
length()/12.;
1079
1080
1081
1082
1083 InDetDD::
DetectorShape elShape = hitSiDetElement->design().shape();
1085 {
1086
1087 if(colRow.x() == 1) {
1088 mat(Trk::locX,Trk::locX) = pow(siWidth.phiR(),2)/12;
1089 }
1090 else if(colRow.x() == 2) {
1091 mat(Trk::locX,Trk::locX) = pow(0.27*siWidth.phiR(),2)/12;
1092 }
1093 else {
1094 mat(Trk::locX,Trk::locX) = pow(siWidth.phiR(),2)/12;
1095 }
1096
1098 double sn = hitSiDetElement->sinStereoLocal(
intersection);
1099 double sn2 = sn*sn;
1100 double cs2 = 1.-sn2;
1101 double w = hitSiDetElement->phiPitch(
intersection)/hitSiDetElement->phiPitch();
1107 }
1108
1109
1110 sctCluster = new InDet::SCT_Cluster(intersectionId,
1112 std::move(rdoList),
1113 siWidth,
1114 hitSiDetElement,
1116
1117 m_sctClusterMap->insert(std::pair<IdentifierHash, InDet::SCT_Cluster* >(waferID, sctCluster));
1118
1121 return StatusCode::FAILURE;
1122 }
1123
1125
1126 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: SCT_Cluster --> " << *sctCluster);
1127
1128
1131
1132 ATH_MSG_DEBUG(
"--- SiSmearedDigitizationTool: BEFORE SMEARING LocalPosition --> X = " <<
m_x_SCT );
1134
1139
1141 }
1142 }
1143 }
1144 }
1145 return StatusCode::SUCCESS;
1146}
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