8 #include "GaudiKernel/MsgStream.h"
12 #include <CLHEP/Matrix/Matrix.h>
13 #include <CLHEP/Matrix/Vector.h>
39 ShiftE=HepGeom::Vector3D<double>();
40 ShiftS=HepGeom::Vector3D<double>();
126 static constexpr std::array<double,10> ALFA_stagger{0.0, 0.283, -0.141, 0.141, -0.283, 0.354, -0.071, 0.212, -0.212, 0.071};
127 static constexpr std::array<double,3> OD_stagger{0.0, -0.167, -0.334};
128 static constexpr
double fSCY=-126.3765+0.0045;
130 static constexpr
double fSCY_ODFiberU=-106.333;
131 static constexpr
double fSCY_ODFiberV=-113.833;
133 static constexpr
double fSCX_ODFiber00=-23.00;
134 static constexpr
double fSCX_ODFiber01=+23.00;
138 MsgStream LogStream(
Athena::getMessageSvc(),
"ALFA_GeometryReader::TransformFiberPositionsFCSCladding");
145 LogStream<<MSG::ERROR<<
"(EFT_VFIBER): Wrong PlateID "<<pFiberParams->
nPlateID<<
" (RP no."<<eRPName<<
")"<<
endmsg;
155 if(
const auto i = pFiberParams->
nPlateID; (
i<1) || (
i>3)){
156 LogStream<<MSG::ERROR<<
"(EFT_ODFIBERV1): Wrong ODPlateID "<<
i<<
" (RP no."<<eRPName<<
")"<<
endmsg;
262 MsgStream LogStream(
Athena::getMessageSvc(),
"ALFA_GeometryReader::TransformFiberPositionsFCSAtlas");
263 static constexpr std::array<double,10> MD_stagger{0.0, 0.283, -0.141, 0.141, -0.283, 0.354, -0.071, 0.212, -0.212, 0.071};
264 static constexpr std::array<double,3> OD_stagger{0.0, -0.167, -0.334};
265 static constexpr
double fSCY=-126.3765+0.0045;
267 static constexpr
double fSCY_ODFiberU=-106.333;
268 static constexpr
double fSCY_ODFiberV=-113.833;
270 double fCentrePos=0.0, fZOffset=0.0;
282 pFiberParams->
fOffset=-1.414213562*fCentrePos+fSCY-fStagger;
286 pFiberParams->
fOffset=+1.414213562*fCentrePos+fSCY+fStagger;
296 if(
const auto i = pFiberParams->
nPlateID; (
i<1) || (
i>3)){
297 LogStream<<MSG::ERROR<<
"(EFT_ODFIBERV1): Wrong ODPlateID "<<
i<<
" (RP no."<<eRPName<<
")"<<
endmsg;
307 pFiberParams->
fOffset=fCentrePos+fSCY_ODFiberV+fStagger;
311 pFiberParams->
fOffset=fCentrePos+fSCY_ODFiberV+fStagger;
320 if(
const auto i = pFiberParams->
nPlateID; (
i<1) || (
i>3)){
321 LogStream<<MSG::ERROR<<
"(EFT_ODFIBERU1): Wrong ODPlateID "<<
i<<
" (RP no."<<eRPName<<
")"<<
endmsg;
330 pFiberParams->
fOffset=fCentrePos+fSCY_ODFiberU+fStagger;
334 pFiberParams->
fOffset=fCentrePos+fSCY_ODFiberU+fStagger;
346 HepGeom::Point3D<double> DetFiberPoint1, DetFiberPoint2, DetPin1Point;
347 HepGeom::Point3D<double> AtlFiberPoint1, AtlFiberPoint2, AtlDetPin1Point;
348 HepGeom::Point3D<double> AtlProjFiberPoint1, AtlProjFiberPoint2;
350 DetPin1Point=HepGeom::Point3D<double>(0.0,0.0,0.0);
351 DetFiberPoint1=HepGeom::Point3D<double>(0.0,pFiberParams->
fOffset,(RPPosParams.
bIsLow)? -fZOffset:+fZOffset);
352 DetFiberPoint2=HepGeom::Point3D<double>(-pFiberParams->
fOffset/pFiberParams->
fSlope,0.0,(RPPosParams.
bIsLow)? -fZOffset:+fZOffset);
358 AtlProjFiberPoint1=HepGeom::Point3D<double>(AtlFiberPoint1[0],AtlFiberPoint1[1],AtlDetPin1Point[2]+fZOffset);
359 AtlProjFiberPoint2=HepGeom::Point3D<double>(AtlFiberPoint2[0],AtlFiberPoint2[1],AtlDetPin1Point[2]+fZOffset);
361 double fx2=AtlProjFiberPoint1[0]+AtlProjFiberPoint1[1]*(AtlProjFiberPoint2[0]-AtlProjFiberPoint1[0])/(AtlProjFiberPoint1[1]-AtlProjFiberPoint2[1]);
362 double fy1=AtlProjFiberPoint1[1]+AtlProjFiberPoint1[0]*(AtlProjFiberPoint2[1]-AtlProjFiberPoint1[1])/(AtlProjFiberPoint1[0]-AtlProjFiberPoint2[0]);
369 HepGeom::Vector3D<double> DirVector=AtlFiberPoint2-AtlFiberPoint1;
396 strcpy(ASPosParams.
szLabel,
"B7L1");
402 strcpy(ASPosParams.
szLabel,
"A7L1");
408 strcpy(ASPosParams.
szLabel,
"A7R1");
414 strcpy(ASPosParams.
szLabel,
"B7R1");
422 strcpy(RPPosParams.
szLabel,
"B7L1U");
447 strcpy(RPPosParams.
szLabel,
"B7L1L");
472 strcpy(RPPosParams.
szLabel,
"A7L1U");
497 strcpy(RPPosParams.
szLabel,
"A7L1L");
522 strcpy(RPPosParams.
szLabel,
"A7R1U");
547 strcpy(RPPosParams.
szLabel,
"A7R1L");
572 strcpy(RPPosParams.
szLabel,
"B7R1U");
597 strcpy(RPPosParams.
szLabel,
"B7R1L");
655 LogStream<<MSG::INFO<<
"Metrology data loaded from file "<<
FilePath<<
endmsg;
669 throw GaudiException(
" Unknown metrology type ",
"ALFA_GeometryReader::Initialize", StatusCode::FAILURE);
706 HepGeom::Vector3D<double> MeanShift;
712 m_ASPosParams[eASName].ASTransformInMainPoint=HepGeom::Translate3D(MeanShift);
718 m_ASPosParams[eASName].ASTransformInMainPoint=HepGeom::Translate3D(MeanShift);
724 m_ASPosParams[eASName].ASTransformInMainPoint=HepGeom::Translate3D(MeanShift);
730 m_ASPosParams[eASName].ASTransformInMainPoint=HepGeom::Translate3D(MeanShift);
737 HepGeom::Scale3D AuxScale;
762 HepGeom::Vector3D<double> NominalDetNormal=HepGeom::Vector3D<double>(0.0,0.0,1.0);
768 HepGeom::Point3D<double> RPPin1,MainPoint;
775 std::vector<HepGeom::Point3D<double> > VecIdealDetRefPoints(nCnt);
776 std::vector<HepGeom::Point3D<double> > VecRealDetRefPoints(nCnt);
779 VecIdealDetRefPoints[
i]=
m_RPPosParams[eRPName].VecIdealDetRefPoints[
i];
792 CLHEP::HepRotation RotationInMainPoint=Params.
DetSWTransform.getRotation();
805 HepGeom::Scale3D&
Scale,
bool bForceUseSVD)
808 const int N=nPointCnt;
809 CLHEP::HepVector vecAux1,vecAux2;
810 CLHEP::HepVector xmean,ymean,
t;
811 CLHEP::HepMatrix
C,U,V,
R,
W;
813 HepGeom::Rotate3D AuxRot;
814 HepGeom::Translate3D AuxTranslation;
817 if(nPointCnt==3 && !bForceUseSVD)
820 VecRealRefPoints[0],VecRealRefPoints[1],VecRealRefPoints[2]);
821 AuxTrans.getDecomposition(
Scale,AuxRot,AuxTranslation);
828 std::vector<CLHEP::HepVector> pX (
N);
829 std::vector<CLHEP::HepVector> pY (
N);
830 std::vector<CLHEP::HepVector> pXs (
N);
831 std::vector<CLHEP::HepVector> pYs(
N);
834 pX[
i]=CLHEP::Hep3Vector(VecIdealRefPoints[
i].
x(),VecIdealRefPoints[
i].
y(),VecIdealRefPoints[
i].
z());
835 pY[
i]=CLHEP::Hep3Vector(VecRealRefPoints[
i].
x(),VecRealRefPoints[
i].
y(),VecRealRefPoints[
i].
z());
839 vecAux1=CLHEP::Hep3Vector();
840 vecAux2=CLHEP::Hep3Vector();
846 xmean=vecAux1/(1.0*
N);
847 ymean=vecAux2/(1.0*
N);
849 C=CLHEP::HepMatrix(3,3);
853 C+=pYs[
i]*pXs[
i].T();
857 std::vector<double*> ppfA(3);
858 std::vector<double*> ppfV(3);
860 ppfA[
i]=
new double[3];
863 ppfV[
i]=
new double[3];
867 std::vector<double> pfW (3);
871 for(j=0;j<3;j++) ppfA[
i][j]=(
double)
C[
i][j];
874 dsvd(ppfA.data(),3,3,pfW.data(),ppfV.data());
876 U=CLHEP::HepMatrix(3,3); V=CLHEP::HepMatrix(3,3);
878 for(j=0;j<3;j++) U[
i][j]=(
double)ppfA[
i][j];
879 for(j=0;j<3;j++) V[
i][j]=(
double)ppfV[
i][j];
882 W=CLHEP::HepMatrix(3,3);
883 W[0][0]=1;
W[1][1]=1;
884 W[2][2]=(U*V).determinant();
890 CLHEP::HepRep3x3 matAux;
891 matAux.xx_=
R[0][0]; matAux.xy_=
R[0][1]; matAux.xz_=
R[0][2];
892 matAux.yx_=
R[1][0]; matAux.yy_=
R[1][1]; matAux.yz_=
R[1][2];
893 matAux.zx_=
R[2][0]; matAux.zy_=
R[2][1]; matAux.zz_=
R[2][2];
894 CLHEP::HepRotation TransM=CLHEP::HepRotation(matAux);
895 CLHEP::Hep3Vector TransT=CLHEP::Hep3Vector(
t[0],
t[1],
t[2]);
911 std::list<eRPotName>::const_iterator iterRPName;
919 nRPCfgIndex=((
int)(*iterRPName))-1;
939 std::string strDetType,
FilePath, GeomFile;
948 LogStream<<MSG::INFO<<
"The IDEAL "<<strDetType<<
" fiber geometry will be loaded for RP "<<
GetRPotLabel(eRPName)<<
endmsg;
953 GeomFile=std::string(
"geom_")+strDetType+std::string(
"_")+std::string(
GetRPotLabel(eRPName))+std::string(
".dat");
955 else FilePath=std::string(szDataSource);
957 LogStream<<MSG::INFO<<
"The "<<strDetType<<
" fiber geometry will be loaded from FILE "<<
FilePath.c_str()<<
" for RP "<<
GetRPotLabel(eRPName)<<
endmsg;
961 LogStream<<MSG::INFO<<
"The "<<strDetType<<
" fiber geometry will be loaded from DATABASE for RP "<<
GetRPotLabel(eRPName)<<
endmsg;
972 m_MapRPot[eRPName].MapPlates.insert(std::pair<int,PLATEPARAMS>(
i,PlateParams));
976 m_MapRPot[eRPName].MapODPlates.insert(std::pair<int,PLATEPARAMS>(
i,PlateParams));
986 throw GaudiException(
" Could not load geometry ",
"ALFA_GeometryReader::ReadSource", StatusCode::FAILURE);
1012 m_MapRPot.insert(std::pair<eRPotName,ROMAPOT>(eRPName,RomaPot));
1052 m_MapRPot[eRPName].ListODFibersV0.push_back(FiberParams);
1057 m_MapRPot[eRPName].ListODFibersV1.push_back(FiberParams);
1063 m_MapRPot[eRPName].ListODFibersU0.push_back(FiberParams);
1068 m_MapRPot[eRPName].ListODFibersU1.push_back(FiberParams);
1082 int i,nLine,nLength;
1100 m_MapRPot.insert(std::pair<eRPotName,ROMAPOT>(eRPName,RomaPot));
1106 if((pFile=fopen(szFilename,
"r"))==
nullptr){
1107 LogStream<<MSG::ERROR<<
"Could not open the file "<<szFilename<<
endmsg;
1112 while(!feof(pFile)){
1113 if(fgets(szLine,
sizeof(szLine),pFile)!=
nullptr){
1118 if(nLine<6)
continue;
1120 nLength=strlen(szLine);
1123 for(
i=0;
i<nLength;
i++) {
if(*(szLine+
i)==
' ')
continue;
else break; }
1125 pch2=strchr(pch1,
' ');
1132 LogStream<<MSG::ERROR<<
"Error at line "<<nLine<<
" while reading the data file "<<szFilename<<
endmsg;
1139 for(
i=0;
i<nLength;
i++) {
if(*(pch2+
i)==
' ')
continue;
else break;}
1141 pch2=strchr(pch1,
' ');
1147 LogStream<<MSG::ERROR<<
"Error at line "<<nLine<<
" while reading the data file "<<szFilename<<
endmsg;
1154 for(
i=0;
i<nLength;
i++) {
if(*(pch2+
i)==
' ')
continue;
else break; }
1156 pch2=strchr(pch1,
' ');
1162 LogStream<<MSG::ERROR<<
"Error at line "<<nLine<<
" while reading the data file "<<szFilename<<
endmsg;
1169 for(
i=0;
i<nLength;
i++) {
if(*(pch2+
i)==
' ')
continue;
else break; }
1171 pch2=strchr(pch1,
' ');
1177 LogStream<<MSG::ERROR<<
"Error at line "<<nLine<<
" while reading the data file "<<szFilename<<
endmsg;
1184 for(
i=0;
i<nLength;
i++) {
if(*(pch2+
i)==
' ')
continue;
else break; }
1217 if(pFile) fclose(pFile);
1231 std::vector<std::string> strDBElements;
1235 memset(szSource,0,
sizeof(szSource));
1236 if(szDataSource) strncpy(szSource, szDataSource,
sizeof(szSource)-1);
1237 char* strtok_ptr =
nullptr;
1238 pch = strtok_r(szSource,
":",&strtok_ptr);
1239 while (pch !=
nullptr)
1241 strDBElements.emplace_back(pch);
1242 pch = strtok_r(
nullptr,
":",&strtok_ptr);
1248 bRes = p_DBAccess->
ReadGeometry(eRPName, eFType, strDBElements[2], strDBElements[1], strDBElements[0]);
1259 m_MapRPot.insert(std::pair<eRPotName,ROMAPOT>(eRPName,RomaPot));
1265 std::list<FIBERDATA>::const_iterator iter;
1268 if (eRPName == (*iter).nPotID)
1272 FiberParams.
nLayerID = (*iter).nLayerID;
1273 FiberParams.
nFiberID = (*iter).nFiberID;
1274 FiberParams.
fSlope = (*iter).fSlope;
1275 FiberParams.
fOffset = (*iter).fOffset;
1276 FiberParams.
fZPos = (*iter).fZPos;
1314 std::list<FIBERPARAMS>::const_iterator iter;
1315 std::map<eRPotName, ROMAPOT>::const_iterator rpiter;
1320 for(iter=(*rpiter).second.ListUFibers.begin();iter!=(*rpiter).second.ListUFibers.end();++iter){
1321 if(((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
1324 if(iter==(*rpiter).second.ListUFibers.end()){
1325 LogStream<<MSG::ERROR<<
"Cannot find fiber PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
1328 *pFiberParams = *iter;
1333 LogStream<<MSG::ERROR<<
"Unknown Roman pot PotID="<<eRPName<<
endmsg;
1342 std::list<FIBERPARAMS>::const_iterator iter;
1343 std::map<eRPotName, ROMAPOT>::const_iterator rpiter;
1348 for(iter=(*rpiter).second.ListVFibers.begin();iter!=(*rpiter).second.ListVFibers.end();++iter){
1349 if(((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
1352 if(iter==(*rpiter).second.ListVFibers.end()) {
1353 LogStream<<MSG::ERROR<<
"Cannot find fiber PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
1357 *pFiberParams = *iter;
1362 LogStream<<MSG::ERROR<<
"Unknown Roman pot PotID="<<eRPName<<
endmsg;
1376 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1394 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1412 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1430 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1447 MsgStream LogStream(
Athena::getMessageSvc(),
"ALFA_GeometryReader::SetUFiberPositionToMainReference");
1450 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1455 for(iter=(*rpiter).second.ListUFibers.begin();iter!=(*rpiter).second.ListUFibers.end();++iter){
1456 if(((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
1459 if(iter==(*rpiter).second.ListUFibers.end()) {
1460 LogStream<<MSG::ERROR<<
"Cannot find fiber PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
1464 (*iter).MainRefPointPos=TransPoint;
1465 (*iter).fMainRefPointSlope=fTransSlope;
1469 LogStream<<MSG::ERROR<<
"Unknown Roman pot PotID="<<eRPName<<
endmsg;
1479 MsgStream LogStream(
Athena::getMessageSvc(),
"ALFA_GeometryReader::SetVFiberPositionToMainReference");
1482 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1487 for(iter=(*rpiter).second.ListVFibers.begin();iter!=(*rpiter).second.ListVFibers.end();++iter){
1488 if(((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
1491 if(iter==(*rpiter).second.ListVFibers.end()){
1492 LogStream<<MSG::ERROR<<
"Cannot find fiber PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
1496 (*iter).MainRefPointPos=TransPoint;
1497 (*iter).fMainRefPointSlope=fTransSlope;
1501 LogStream<<MSG::ERROR<<
"Unknown Roman pot PotID="<<eRPName<<
endmsg;
1514 if((pliter=(*rpiter).second.MapPlates.find(nPlateID))!=(*rpiter).second.MapPlates.end()){
1515 *pPlateParams=(*pliter).second;
1519 LogStream<<MSG::ERROR<<
"Unknown Ti plate ID "<<nPlateID<<
endmsg;
1523 LogStream<<MSG::ERROR<<
"Unknown Roman pot PotID="<<eRPName<<
endmsg;
1540 std::list<FIBERPARAMS>::const_iterator iter;
1541 std::map<eRPotName, ROMAPOT>::const_iterator rpiter;
1547 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1552 OutStream<<std::endl<<
"Geometry of U-fibers in Roma Pot "<<(*rpiter).first<<std::endl;
1556 for(iter=(*rpiter).second.ListUFibers.begin();iter!=(*rpiter).second.ListUFibers.end();++iter){
1557 OutStream<<(*rpiter).first<<
"\t\t\t\t"<<(*iter).nPlateID<<
"\t\t\t\t"<<(*iter).nFiberID<<
"\t\t\t\t"<<(*iter).nLayerID<<
"\t\t\t\t";
1562 OutStream<<std::endl<<
"Geometry of V-fibers in Roma Pot "<<(*rpiter).first<<std::endl;
1566 for(iter=(*rpiter).second.ListVFibers.begin();iter!=(*rpiter).second.ListVFibers.end();++iter){
1567 OutStream<<(*rpiter).first<<
"\t\t\t\t"<<(*iter).nPlateID<<
"\t\t\t\t"<<(*iter).nFiberID<<
"\t\t\t\t"<<(*iter).nLayerID<<
"\t\t\t\t";
1572 OutStream<<std::endl<<
"Geometry of V0-ODFibers in Roma Pot "<<(*rpiter).first<<std::endl;
1576 for(iter=(*rpiter).second.ListODFibersV0.begin();iter!=(*rpiter).second.ListODFibersV0.end();++iter){
1577 OutStream<<(*rpiter).first<<
"\t\t\t\t"<<(*iter).nPlateID<<
"\t\t\t\t"<<(*iter).nFiberID<<
"\t\t\t\t"<<(*iter).nLayerID<<
"\t\t\t\t";
1582 OutStream<<std::endl<<
"Geometry of U0-ODFibers in Roma Pot "<<(*rpiter).first<<std::endl;
1586 for(iter=(*rpiter).second.ListODFibersU0.begin();iter!=(*rpiter).second.ListODFibersU0.end();++iter){
1587 OutStream<<(*rpiter).first<<
"\t\t\t\t"<<(*iter).nPlateID<<
"\t\t\t\t"<<(*iter).nFiberID<<
"\t\t\t\t"<<(*iter).nLayerID<<
"\t\t\t\t";
1592 OutStream<<std::endl<<
"Geometry of U1-ODFibers in Roma Pot "<<(*rpiter).first<<std::endl;
1596 for(iter=(*rpiter).second.ListODFibersU1.begin();iter!=(*rpiter).second.ListODFibersU1.end();++iter){
1597 OutStream<<(*rpiter).first<<
"\t\t\t\t"<<(*iter).nPlateID<<
"\t\t\t\t"<<(*iter).nFiberID<<
"\t\t\t\t"<<(*iter).nLayerID<<
"\t\t\t\t";
1602 OutStream<<std::endl<<
"Geometry of V1-ODFibers in Roma Pot "<<(*rpiter).first<<std::endl;
1606 for(iter=(*rpiter).second.ListODFibersV1.begin();iter!=(*rpiter).second.ListODFibersV1.end();++iter){
1607 OutStream<<(*rpiter).first<<
"\t\t\t\t"<<(*iter).nPlateID<<
"\t\t\t\t"<<(*iter).nFiberID<<
"\t\t\t\t"<<(*iter).nLayerID<<
"\t\t\t\t";
1617 double fParamB, fY, fX, fZ, fSlope;
1624 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1628 pFile = fopen(szDataDestination,
"w");
1629 if(pFile==
nullptr)
return false;
1631 fprintf(pFile,
"xxxxxxxxxxxxxxxxxxx\n");
1636 fprintf(pFile,
"20\n");
1648 fParamB=fY-fSlope*fX;
1656 fprintf(pFile,
" %2d %2d %7.5f %7.4f %7.3f\n", (
i*2-1), j, fSlope, fParamB, fZ);
1669 fParamB=fY-fSlope*fX;
1677 fprintf(pFile,
" %2d %2d %7.5f %7.4f %7.3f\n", (
i*2), j, fSlope, fParamB, fZ);
1684 fprintf(pFile,
"6\n");
1698 fParamB=fY-fSlope*fX;
1706 fprintf(pFile,
" %2d %2d %7.5f %7.4f %7.3f\n", (
i*2-1), j, fSlope, fParamB, fZ);
1720 fParamB=fY-fSlope*fX;
1728 fprintf(pFile,
" %2d %2d %7.5f %7.4f %7.3f\n", (
i*2-1), j, fSlope, fParamB, fZ);
1742 fParamB=fY-fSlope*fX;
1749 fprintf(pFile,
" %2d %2d %7.5f %7.4f %7.3f\n", (
i*2), j, fSlope, fParamB, fZ);
1764 fParamB=fY-fSlope*fX;
1771 fprintf(pFile,
" %2d %2d %7.5f %7.4f %7.3f\n", (
i*2), j, fSlope, fParamB, fZ);
1787 std::list<FIBERPARAMS>::const_iterator iter;
1805 std::string strLabel;
1806 std::map<eRPotName,ROMAPOT>::const_iterator rpiter;
1808 if(pMapRPotName!=
nullptr){
1809 pMapRPotName->clear();
1813 pMapRPotName->insert(std::pair<eRPotName,std::string>((*rpiter).first,strLabel));
1830 pRPPosParams->
clear();
1832 *pRPPosParams=(*iter).second;
1836 LogStream<<MSG::ERROR<<
"Unknown Roma pot ID="<<eRPName<<
endmsg;
1849 pASPosParams->
clear();
1851 *pASPosParams=(*iter).second;
1855 LogStream<<MSG::ERROR<<
"Unknown ALFA Station ID="<<eASName<<
endmsg;
1871 LogStream<<MSG::ERROR<<
"Unknown Roman pot ID="<<eRPName<<
endmsg;
1884 if(pFiberParams==
nullptr)
1886 LogStream<<MSG::ERROR<<
"pFiberParams points to NULL"<<
endmsg;
1890 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
1901 LogStream<<MSG::ERROR<<
"Invalid fiber type"<<
endmsg;
1913 std::list<FIBERPARAMS>::const_iterator iter;
1914 std::map<eRPotName, ROMAPOT>::const_iterator rpiter;
1924 for(iter=(*rpiter).second.ListODFibersU0.begin();iter!=(*rpiter).second.ListODFibersU0.end();++iter)
1926 if (((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
1929 if (iter==(*rpiter).second.ListODFibersU0.end())
1931 LogStream<<MSG::ERROR<<
"Cannot find ODFiberU0 PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
1935 *pFiberParams = *iter;
1943 for(iter=(*rpiter).second.ListODFibersV0.begin();iter!=(*rpiter).second.ListODFibersV0.end();++iter)
1945 if (((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
1948 if (iter==(*rpiter).second.ListODFibersV0.end())
1950 LogStream<<MSG::ERROR<<
"Cannot find ODFiberV0 PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
1954 *pFiberParams = *iter;
1962 for(iter=(*rpiter).second.ListODFibersU1.begin();iter!=(*rpiter).second.ListODFibersU1.end();++iter)
1964 if (((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
1967 if (iter==(*rpiter).second.ListODFibersU1.end())
1969 LogStream<<MSG::ERROR<<
"Cannot find ODFiberU1 PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
1973 *pFiberParams = *iter;
1981 for(iter=(*rpiter).second.ListODFibersV1.begin();iter!=(*rpiter).second.ListODFibersV1.end();++iter)
1983 if (((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
1986 if (iter==(*rpiter).second.ListODFibersV1.end())
1988 LogStream<<MSG::ERROR<<
"Cannot find ODFiberV1 PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
1992 *pFiberParams = *iter;
2000 LogStream<<MSG::ERROR<<
"Unknown ODFiber eFType="<<eFType<<
endmsg;
2007 LogStream<<MSG::ERROR<<
"Unknown Roma pot PotID="<<eRPName<<
endmsg;
2018 MsgStream LogStream(
Athena::getMessageSvc(),
"ALFA_GeometryReader::SetODFiberPositionToMainReference");
2021 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2031 for(iter=(*rpiter).second.ListODFibersU0.begin();iter!=(*rpiter).second.ListODFibersU0.end();++iter)
2033 if (((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
2036 if (iter==(*rpiter).second.ListODFibersU0.end())
2038 LogStream<<MSG::ERROR<<
"Cannot find ODFiberU0 PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
2043 (*iter).MainRefPointPos=TransPoint;
2044 (*iter).fMainRefPointSlope=fTransSlope;
2051 for(iter=(*rpiter).second.ListODFibersV0.begin();iter!=(*rpiter).second.ListODFibersV0.end();++iter)
2053 if (((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
2056 if (iter==(*rpiter).second.ListODFibersV0.end())
2058 LogStream<<MSG::ERROR<<
"Cannot find ODFiberV0 PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
2062 (*iter).MainRefPointPos=TransPoint;
2063 (*iter).fMainRefPointSlope=fTransSlope;
2070 for(iter=(*rpiter).second.ListODFibersU1.begin();iter!=(*rpiter).second.ListODFibersU1.end();++iter)
2072 if (((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
2075 if (iter==(*rpiter).second.ListODFibersU1.end())
2077 LogStream<<MSG::ERROR<<
"Cannot find ODFiberU1 PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
2081 (*iter).MainRefPointPos=TransPoint;
2082 (*iter).fMainRefPointSlope=fTransSlope;
2089 for(iter=(*rpiter).second.ListODFibersV1.begin();iter!=(*rpiter).second.ListODFibersV1.end();++iter)
2091 if (((*iter).nPlateID==nPlateID) && ((*iter).nFiberID==nFiberID))
break;
2094 if (iter==(*rpiter).second.ListODFibersV1.end())
2096 LogStream<<MSG::ERROR<<
"Cannot find ODFiberV1 PotID="<<eRPName<<
", PlateID="<<nPlateID<<
" and FiberID="<<nFiberID<<
endmsg;
2100 (*iter).MainRefPointPos=TransPoint;
2101 (*iter).fMainRefPointSlope=fTransSlope;
2108 LogStream<<MSG::ERROR<<
"Unknown ODFiber eFType="<<eFType<<
endmsg;
2115 LogStream<<MSG::ERROR<<
"Unknown Roman pot PotID="<<eRPName<<
endmsg;
2127 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2146 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2166 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2182 LogStream<<MSG::ERROR<<
"Invalid fiber type"<<
endmsg;
2197 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2213 LogStream<<MSG::ERROR<<
"Invalid fiber type"<<
endmsg;
2228 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2244 LogStream<<MSG::ERROR<<
"Invalid fiber type"<<
endmsg;
2258 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2277 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2296 LogStream<<MSG::ERROR<<
"Invalid coordinate system"<<
endmsg;
2319 if(CfgParams.
Init(szDataSource,
"[B7L1]")==0)
return false;
2322 if(CfgParams.
Init(szDataSource,
"[A7L1]")==0)
return false;
2325 if(CfgParams.
Init(szDataSource,
"[A7R1]")==0)
return false;
2328 if(CfgParams.
Init(szDataSource,
"[B7R1]")==0)
return false;
2333 if(CfgParams.
Init(szDataSource,
"[B7L1U]")==0)
return false;
2338 if(CfgParams.
Init(szDataSource,
"[B7L1L]")==0)
return false;
2343 if(CfgParams.
Init(szDataSource,
"[A7L1U]")==0)
return false;
2348 if(CfgParams.
Init(szDataSource,
"[A7L1L]")==0)
return false;
2353 if(CfgParams.
Init(szDataSource,
"[A7R1U]")==0)
return false;
2358 if(CfgParams.
Init(szDataSource,
"[A7R1L]")==0)
return false;
2363 if(CfgParams.
Init(szDataSource,
"[B7R1U]")==0)
return false;
2368 if(CfgParams.
Init(szDataSource,
"[B7R1L]")==0)
return false;
2376 LogStream<<MSG::ERROR<<
"The file source is supported only."<<
endmsg;
2386 std::vector<HepGeom::Point3D<double> > vecRefPoints;
2403 double fx{},fy{},fz{},faux{};
2404 char *ppos1,*ppos2,*ppos3,*ppos4,*pstop;
2406 HepGeom::Point3D<double> RefPoint;
2409 if (strlen(szvalue) <513){
2410 strcpy(szbuff,szvalue);
2412 LogStream<<MSG::ERROR<<
"String too long for buffer."<<
endmsg;
2417 while((ppos1=strchr(ppos2,
'['))!=
nullptr){
2418 if(!(ppos2=strchr(ppos1+1,
']')))
return false;
2423 if(nCnt==0)
return false;
2424 vecRefPoints.resize(nCnt);
2428 while((ppos1=strchr(ppos2,
'['))!=
nullptr){
2429 if(!(ppos2=strchr(ppos1,
']')))
return false;
2433 if(!(ppos4=strchr(ppos3+1,
',')))
return false;
2435 faux=strtod(ppos3,&pstop);
2436 if(pstop!=ppos4 && *pstop!=
' ')
return false;
2441 if(!(ppos4=strchr(ppos3+1,
',')))
return false;
2443 faux=strtod(ppos3,&pstop);
2444 if(pstop!=ppos4 && *pstop!=
' ')
return false;
2449 if(!(ppos4=strchr(ppos3+1,
']')))
return false;
2451 faux=strtod(ppos3,&pstop);
2452 if(pstop!=ppos4 && *pstop!=
' ')
return false;
2457 RefPoint[0]=fx; RefPoint[1]=fy; RefPoint[2]=fz;
2460 RefPoint[0]=fx; RefPoint[1]=fz; RefPoint[2]=-fy;
2463 RefPoint[0]=fx; RefPoint[1]=-fz; RefPoint[2]=fy;
2466 RefPoint[0]=fx; RefPoint[1]=fy; RefPoint[2]=fz;
2468 else throw new GaudiException(
"Invalid type of metrology coordinate system",
"ALFA_GeometryReader::ParseRefPoints", StatusCode::FAILURE);
2470 vecRefPoints[
i++]=RefPoint;
2482 char *ppos1,*ppos2,*pstop;
2486 memset(szbuff,0,
sizeof(szbuff));
2487 if(szvalue) strncpy(szbuff,szvalue,
sizeof(szbuff)-1);
2490 ppos2=strchr(ppos1,
',');
2492 while(ppos2!=
nullptr){
2495 faux=strtod(ppos1,&pstop);
2496 if(pstop==ppos2) vecValues.push_back(faux);
2503 ppos2=strchr(ppos1,
',');
2507 faux=strtod(ppos1,&pstop);
2508 if(*pstop==0) vecValues.push_back(faux);
2512 if(!bRes) vecValues.clear();
2526 double xr1,yr1,xr2,yr2;
2527 HepGeom::Point3D<double> PointIdealD3, PointRealD3;
2528 HepGeom::Point3D<double> PointIdealD4, PointRealD4;
2529 HepGeom::Point3D<double> PointIdealD5, PointRealD5;
2531 std::vector<double> vecDetEdges;
2532 std::vector<HepGeom::Point3D<double> > vecNominalDetPoints;
2533 std::vector<HepGeom::Point3D<double> > vecRealDetPoints;
2536 if(!CfgParams.
IsKey(
"idealrefdetpoints"))
return false;
2538 if(!CfgParams.
IsKey(
"realrefdetpoints"))
return false;
2541 if(!CfgParams.
IsKey(
"realdetedgeypos"))
return false;
2544 fZc=0.5*(vecDetEdges[0]+vecDetEdges[1]);
2545 PointIdealD3=HepGeom::Point3D<double>(10.0,0.0,0.0);
2546 PointIdealD4=HepGeom::Point3D<double>(0.0,10.0,0.0);
2547 PointIdealD5=HepGeom::Point3D<double>(0.0,0.0,10.0);
2550 xp1=vecNominalDetPoints[0].x();
2551 yp1=vecNominalDetPoints[0].y();
2554 xr1=vecRealDetPoints[0].x();
2555 yr1=vecRealDetPoints[0].y();
2556 xr2=vecRealDetPoints[1].x();
2557 yr2=vecRealDetPoints[1].y();
2560 double alpha=-
atan((xr2-xr1)/(yr2-yr1));
2570 CorrectionInDetPin1=HepGeom::Translate3D(a3,a4,fZc-113.0*
CLHEP::mm)*HepGeom::RotateZ3D(
alpha);
2577 HepGeom::Vector3D<double> OriginShift=RPPin1+DetPin1-MainPoint;
2579 CLHEP::Hep3Vector TranslationInMainPoint=CorrectionInDetPin1.getTranslation()-CorrectionInDetPin1*OriginShift+OriginShift;
2581 CLHEP::HepRotation RotationInMainPoint=CorrectionInDetPin1.getRotation();
2584 PointRealD3=CorrectionInMainPoint*PointIdealD3;
2585 PointRealD4=CorrectionInMainPoint*PointIdealD4;
2586 PointRealD5=CorrectionInMainPoint*PointIdealD5;
2591 m_RPPosParams[eRPName].VecIdealDetRefPoints[0]=std::move(PointIdealD5);
2592 m_RPPosParams[eRPName].VecRealDetRefPoints[0]=std::move(PointRealD5);
2594 m_RPPosParams[eRPName].VecIdealDetRefPoints[1]=std::move(PointIdealD4);
2595 m_RPPosParams[eRPName].VecRealDetRefPoints[1]=std::move(PointRealD4);
2597 m_RPPosParams[eRPName].VecIdealDetRefPoints[2]=std::move(PointIdealD3);
2598 m_RPPosParams[eRPName].VecRealDetRefPoints[2]=std::move(PointRealD3);
2609 double fCurrentLVDTmm;
2610 HepGeom::Point3D<double> PSinStation, RPPinNominal;
2611 double fCurrentLVDT=0.0;
2612 std::vector<double> vecPolyFitParams;
2613 std::vector<HepGeom::Point3D<double> > vecPSinRPCS;
2614 std::vector<HepGeom::Point3D<double> > vecNominalPSinStationCS;
2615 std::vector<HepGeom::Point3D<double> > vecRealPSinStationCS;
2626 vecNominalPSinStationCS.resize(nCnt);
2627 vecRealPSinStationCS.resize(nCnt);
2630 if(!CfgParams.
IsKey(
"psinrpss"))
return false;
2634 for(
i=0;
i<nCnt;
i++){
2635 vecNominalPSinStationCS[
i]=RPPinNominal+HepGeom::RotateX3D(RPPosParams.
bIsLow? 180*
CLHEP::deg:0.0)*vecPSinRPCS[
i];
2652 PSinStation.set(fx,fy,fz);
2653 vecRealPSinStationCS[0]=PSinStation;
2661 PSinStation.set(fx,fy,fz);
2662 vecRealPSinStationCS[1]=PSinStation;
2670 PSinStation.set(fx,fy,fz);
2671 vecRealPSinStationCS[2]=std::move(PSinStation);
2674 m_RPPosParams[eRPName].VecIdealRPRefPoints=std::move(vecNominalPSinStationCS);
2675 m_RPPosParams[eRPName].VecRealRPRefPoints=std::move(vecRealPSinStationCS);
2684 std::vector<HepGeom::Point3D<double> > vecShiftPoints;
2687 if(!CfgParams.
IsKey(
"shifte"))
return false;
2692 if(!CfgParams.
IsKey(
"shifts"))
return false;
2702 double fOutputValue=0.0;
2704 n=vecPolyFitParams.size();
2708 fOutputValue+=vecPolyFitParams[
i]*
pow(fInputValue,
n-1-
i);
2711 return fOutputValue;
2722 HepGeom::Point3D<double> PointInAtlasCS, PointInRPotCS;
2727 HepGeom::Vector3D<double>
Shift=RPPin1-MainPoint;
2728 HepGeom::Point3D<double> PointInMainPoint=
Shift+AlfaRefPoint+PointInDetCS;
2731 PointInAtlasCS=TotTransform*PointInRPotCS;
2734 throw new GaudiException(
" The GetDetPointInAtlas() can be used only with EFCS_ATLAS or EFCS_CLADDING flag ",
"ALFA_GeometryReader::GetDetPointInAtlas", StatusCode::FAILURE);
2737 return PointInAtlasCS;
2746 HepGeom::Point3D<double> PointInRPotCS;
2751 HepGeom::Vector3D<double>
Shift=RPPin1-MainPoint;
2752 HepGeom::Point3D<double> PointInMainPoint=
Shift+AlfaRefPoint+PointInDetCS;
2756 throw new GaudiException(
" The GetDetPointInAtlas() can be used only with EFCS_ATLAS or EFCS_CLADDING flag ",
"ALFA_GeometryReader::GetDetPointInAtlas", StatusCode::FAILURE);
2759 return PointInRPotCS;
2766 double fRotX,fRotY,fRotZ;
2768 FILE *
pfile=fopen(szDataDestination,
"w");
2771 fprintf(
pfile,
"Romain pot geometry info: ----------------------------------------\r\n");
2775 fprintf(
pfile,
"Transformation matrix of RP in station MainPoint:\r\n");
2783 fprintf(
pfile,
"RotX=%.5f rad, RotY=%.5f rad, RotZ=%.5f rad\r\n",fRotX,fRotY,fRotZ);
2786 fprintf(
pfile,
"\r\nDetector geometry info: ------------------------------------------\r\n");
2787 fprintf(
pfile,
"Transformation matrix of detector in RP MainPoint:\r\n");
2795 fprintf(
pfile,
"RotX=%.5f rad, RotY=%.5f rad, RotZ=%.5f rad\r\n",fRotX,fRotY,fRotZ);
2797 fprintf(
pfile,
"\r\nReference pins and Track point info: ------------------------------------------\r\n");
2798 fprintf(
pfile,
"RPPin1: nominal=[%.3f,%.3f,%.3f], real=[%.3f,%.3f,%.3f] (Station CS)\r\n",
m_RPPosParams[eRPName].RefPins.IdealRPPin1.x(),
m_RPPosParams[eRPName].RefPins.IdealRPPin1.y(),
m_RPPosParams[eRPName].RefPins.IdealRPPin1.z(),
2800 fprintf(
pfile,
"RPPin2: nominal=[%.3f,%.3f,%.3f], real=[%.3f,%.3f,%.3f] (Station CS)\r\n",
m_RPPosParams[eRPName].RefPins.IdealRPPin2.x(),
m_RPPosParams[eRPName].RefPins.IdealRPPin2.y(),
m_RPPosParams[eRPName].RefPins.IdealRPPin2.z(),
2802 fprintf(
pfile,
"RPPin3: nominal=[%.3f,%.3f,%.3f], real=[%.3f,%.3f,%.3f] (Station CS)\r\n",
m_RPPosParams[eRPName].RefPins.IdealRPPin3.x(),
m_RPPosParams[eRPName].RefPins.IdealRPPin3.y(),
m_RPPosParams[eRPName].RefPins.IdealRPPin3.z(),
2804 fprintf(
pfile,
"Detector TrackPoint: [%.3f,%.3f,%.3f] (ALFA CS), [%.3f,%.3f,%.3f] (RPot CS), [%.3f,%.3f,%.3f] (ATLAS CS)\r\n",
m_RPPosParams[eRPName].RefPins.DTPInAlfaCS.x(),
m_RPPosParams[eRPName].RefPins.DTPInAlfaCS.y(),
m_RPPosParams[eRPName].RefPins.DTPInAlfaCS.z(),
2807 fprintf(
pfile,
"Detector CentrePoint: [%.3f,%.3f,%.3f] (ALFA CS), [%.3f,%.3f,%.3f] (RPot CS), [%.3f,%.3f,%.3f] (ATLAS CS)\r\n",
m_RPPosParams[eRPName].RefPins.DCPInAlfaCS.x(),
m_RPPosParams[eRPName].RefPins.DCPInAlfaCS.y(),
m_RPPosParams[eRPName].RefPins.DCPInAlfaCS.z(),
2833 HepGeom::Vector3D<double> Shift1=RPPin1-MainPoint;
2834 HepGeom::Vector3D<double> Shift2=RPPin1-MainPoint+AlfaRefPoint;
2835 HepGeom::Vector3D<double> Shift3=0.5*(AParams.
ShiftE+AParams.
ShiftS);
2849 TransMatrix=HepGeom::Translate3D(-Shift1);
2852 TransMatrix=HepGeom::Translate3D(Shift2);
2855 TransMatrix=HepGeom::Translate3D(-Shift3);
2858 throw GaudiException(
" Invalid matrix identificator ",
"ALFA_GeometryReader::GetTransformMatrix", StatusCode::FAILURE);
2891 nSign=(
i%2==0)? +1:-1;