9 #include "GaudiKernel/MsgStream.h"
10 #include "GaudiKernel/SmartDataPtr.h"
17 #include "Identifier/Identifier.h"
27 #include "GaudiKernel/IRndmGenSvc.h"
28 #include "GaudiKernel/RndmGenerators.h"
34 constexpr
long double operator"" _degree (
long double deg ){
37 static constexpr
double const& phiModEnd = 26.25;
43 const std::string&
name,
const IInterface*
parent)
49 m_current_IDAlignDBTool(
nullptr),
50 m_survey_IDAlignDBTool(
nullptr),
55 m_SurveyWeightPhiX(1.0),
56 m_SurveyWeightPhiY(1.0),
57 m_SurveyWeightPhiZ(1.0),
71 m_TransXRandPixB(0.01),
72 m_TransYRandPixB(0.01),
73 m_TransZRandPixB(0.1),
74 m_RotXRandPixB(0.001),
75 m_RotYRandPixB(0.001),
76 m_RotZRandPixB(0.00024),
77 m_TransXRandSCTEC(0.03),
78 m_TransYRandSCTEC(0.03),
79 m_TransZRandSCTEC(0.03),
80 m_RotXRandSCTEC(0.001),
81 m_RotYRandSCTEC(0.001),
82 m_RotZRandSCTEC(0.0003),
83 m_TransXRandSCTB(0.1),
84 m_TransYRandSCTB(0.1),
85 m_TransZRandSCTB(0.1),
86 m_RotXRandSCTB(0.001),
87 m_RotYRandSCTB(0.001),
88 m_RotZRandSCTB(0.001),
90 m_TransXRandSect(0.0),
91 m_TransYRandSect(0.0),
92 m_TransZRandSect(0.0),
101 m_proximity(999999.),
102 m_aligndbtoolinst(
"InDetCurrentDBTool"),
103 m_surveydbtoolinst(
"InDetSurveyDBTool"),
108 declareInterface<ISurveyConstraint>(
this);
176 msg(MSG::INFO) <<
"SurveyConstraint initialize()" <<
endmsg;
180 if (
sc.isFailure()) {
184 msg(MSG::INFO) <<
"got ToolSvc" <<
endmsg;
188 if (
sc.isFailure()) {
192 msg(MSG::INFO) <<
"got current_IDAlignDBTool" <<
endmsg;
197 if (
sc.isFailure()) {
201 msg(MSG::INFO) <<
"got survey_IDAlignDBTool" <<
endmsg;
205 if (
sc.isFailure()) {
206 msg(MSG::WARNING) <<
"Could not get AtlasDetectorID !" <<
endmsg;
207 return StatusCode::SUCCESS;
216 return StatusCode::FAILURE;
218 msg(MSG::INFO) <<
"got ID helpers from detector store (relying on GeoModel to put them)" <<
endmsg;
225 if (StatusCode::SUCCESS!=service(
"RndmGenSvc",
m_randsvc,
true))
226 msg(MSG::ERROR) <<
"Cannot find RndmGenSvc" <<
endmsg;
256 msg(MSG::INFO) <<
"now entering SurveyConstraint::setup_SurveyConstraintModules()" <<
endmsg;
259 return StatusCode::SUCCESS;
267 msg(MSG::INFO) <<
"finalize()" <<
endmsg;
269 std::map<Identifier, SurveyConstraintModule*, std::less<Identifier> >
::iterator it;
275 return StatusCode::SUCCESS;
303 bool isPixEC =
false, isPixB =
false, isSCTEC =
false, isSCTB =
false;
318 std::vector< SurveyConstraintPoint > Stavepoints;
320 if (
msgLvl(
MSG::DEBUG))
msg() <<
"SurveyConstraint().computeConstraint: Stavepoints.size() " << Stavepoints.size() <<
endmsg;
325 for (
unsigned int iPoint(0); iPoint < Stavepoints.size(); ++iPoint ) {
327 if (
msgLvl(
MSG::DEBUG))
msg() <<
"Survey Stavepoints before: " << survey.x() <<
"," << survey.y() <<
"," << survey.z() <<
endmsg;
330 survey = Stavepoints[iPoint].survey();
335 double stavemin = minimizer.
findMinimum(Stavepoints,staveangles,stavetrans);
340 stavetrans[2] = (stavetrans.z()/
m_scaleZ);
342 stavetrans.x() <<
"," << stavetrans.y() <<
"," << stavetrans.z() <<
"," <<
343 staveangles.x()/
m_scaleZ <<
"," << staveangles.y()/
m_scaleZ <<
"," << staveangles.z() <<
")" <<
349 return StatusCode::FAILURE;
354 Amg::Transform3D staveTransform = amgstavetrans * Amg::RotationMatrix3D::Identity();
362 std::vector< SurveyConstraintPoint > Modulepoints;
370 for(
unsigned ipoint=0;ipoint<Modulepoints.size();ipoint++){
372 survey = staveTransform * survey;
382 return StatusCode::FAILURE;
386 for(
unsigned ipar=0;ipar<3;ipar++)
387 dparams[ipar] = modtrans[ipar];
388 dparams[3] = modangles[0];
389 dparams[4] = modangles[1];
390 dparams[5] = modangles[2];
409 return StatusCode::FAILURE;
420 msg(MSG::ERROR) <<
"Chech that the size of the matrix is a 1,1: " << temp.rows() <<
", " << temp.cols() <<
endmsg;
421 deltachisq = temp(0,0);
427 DOCA_Vector = 2.0*
weight*dparams;
430 return StatusCode::SUCCESS;
452 m_survey_IDAlignDBTool->
dispGroup(-1, -1, -1, -1, -1,
m_TransLayerRand,
m_TransLayerRand,
m_TransLayerRand, 2, 2, 0);
455 m_survey_IDAlignDBTool->
dispGroup(1, 2, 0, -1, -1,
m_TransLayerRand, 0, 0, 1, 2, 0);
458 m_survey_IDAlignDBTool->
dispGroup(1, 2, 2, -1, -1,
m_TransLayerRand, 0, 0, 1, 2, 0);
461 int nSCT(0), nPixel(0);
462 std::vector< Amg::Vector3D > localSurveyCoords;
464 SurveyTransRand.setIdentity();
465 SurveyTransRandSect.setIdentity();
467 unsigned int nSCTMod = 0,nSCTModInMap = 0,nSCTModEC = 0,nSCTModPointsEC = 0;
471 if (not sctDetEleHandle.
isValid() or sctElements==
nullptr) {
476 const Identifier SCT_ModuleID = element->identify();
516 Misalign_Vector[0]=
m1;Misalign_Vector[1]=
m2;Misalign_Vector[2]=
m3;Misalign_Vector[3]=m4;Misalign_Vector[4]=m5;Misalign_Vector[5]=m6;
533 Misalign_Vector[0]=
m1;Misalign_Vector[1]=
m2;Misalign_Vector[2]=
m3;Misalign_Vector[3]=m4;Misalign_Vector[4]=m5;Misalign_Vector[5]=m6;
540 for (
unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
543 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) * localSurveyCoords[iCorn];
548 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint );
549 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint);
557 bool first =
true, NewDisk =
true, NewSector =
true, firstB =
true;
558 unsigned int nPixMod = 0,nPixModInMap = 0,nPixModEC = 0,nPixModPointsEC = 0;
559 int previous_disk = -1, previous_sector = -1;
563 if (not pixelDetEleHandle.
isValid() or pixelElements==
nullptr) {
568 const Identifier Pixel_ModuleID = element->identify();
623 Misalign_Vector[0]=
m1;Misalign_Vector[1]=
m2;Misalign_Vector[2]=
m3;Misalign_Vector[3]=m4;Misalign_Vector[4]=m5;Misalign_Vector[5]=m6;
644 for (
unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
648 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) * localSurveyCoords[iCorn];
654 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint);
655 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint );
671 msg(MSG::INFO) <<
"Local Coordinates = (" << localSurveyCoords[iCorn][0] <<
","
672 << localSurveyCoords[iCorn][1] <<
"," << localSurveyCoords[iCorn][2] <<
")" <<
endmsg;
673 msg(MSG::INFO) <<
"Survey Local Coordinates = (" << surveyPoint[0] <<
","
674 << surveyPoint[1] <<
"," << surveyPoint[2] <<
")" <<
endmsg;
675 msg(MSG::INFO) <<
"Current Local Coordinates = (" << currentPoint[0] <<
","
676 << currentPoint[1] <<
"," << currentPoint[2] <<
")" <<
endmsg;
677 msg(MSG::INFO) <<
"Survey Global Coordinates = (" << globalSurveyPoint[0] <<
","
678 << globalSurveyPoint[1] <<
"," << globalSurveyPoint[2] <<
")" <<
endmsg;
679 msg(MSG::INFO) <<
"Current Global Coordinates = (" << globalCurrentPoint[0] <<
","
680 << globalCurrentPoint[1] <<
"," << globalCurrentPoint[2] <<
")" <<
endmsg;
681 msg(MSG::INFO) <<
"SurveyConstraint().setup_SurveyConstraintModules: nModulePoints " <<
m_ModuleMap[Pixel_ModuleID]->nModulePoints() <<
endmsg;
714 Misalign_Vector[0]=
m1;Misalign_Vector[1]=
m2;Misalign_Vector[2]=
m3;Misalign_Vector[3]=m4;Misalign_Vector[4]=m5;Misalign_Vector[5]=m6;
720 for (
unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
723 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) *localSurveyCoords[iCorn] ;
728 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint );
729 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint );
737 msg(MSG::INFO) <<
"nSCTMod " << nSCTMod
738 <<
", nSCTModInMap " << nSCTModInMap
739 <<
", nSCTModEC " << nSCTModEC
740 <<
", nSCTModPointsEC " << nSCTModPointsEC
741 <<
", nPixMod " << nPixMod
742 <<
", nPixModInMap " << nPixModInMap
743 <<
", nPixModEC " << nPixModEC
744 <<
", nPixModPointsEC " << nPixModPointsEC
753 std::vector< SurveyConstraintPoint > Stavepoints;
755 unsigned int nPixModEC2 = 0,nPixModPixModEC = 0,nPixModECPixModEC = 0,nSameLayer = 0,nNotIdentical = 0;
762 const Identifier Pixel_ModuleID2 = *wafer_it2;
771 if(Pixel_ModuleID != Pixel_ModuleID2){
774 (
m_ModuleMap[Pixel_ModuleID])->addStaveConstraintPoint(Stavepoints);
779 std::vector< SurveyConstraintPoint > Testpoints;
781 msg(MSG::INFO) <<
"SurveyConstraint().setup_SurveyConstraintModules: Stavepoints.size() (from map) " << Testpoints.size() <<
endmsg;
793 msg(MSG::INFO) <<
"Loop 2, filling stave-points, nPixModEC2 " << nPixModEC2
794 <<
", nPixModPixModEC " << nPixModPixModEC
795 <<
", nPixModECPixModEC " << nPixModECPixModEC
796 <<
", nSameLayer " << nSameLayer
797 <<
", nNotIdentical " << nNotIdentical
801 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
808 const Identifier Pixel_ModuleID2 = *wafer_it2;
815 if(Pixel_ModuleID == Pixel_ModuleID2)
continue;
818 (
m_ModuleMap[Pixel_ModuleID])->addStaveConstraintPoint(Stavepoints);
821 msg(MSG::INFO) <<
"Loop 2, filling stave-points, nPixModB2 " << nPixModEC2
822 <<
", nPixModPixModB " << nPixModPixModEC
823 <<
", nPixModBPixModB " << nPixModECPixModEC
824 <<
", nSameLayer " << nSameLayer
825 <<
", nNotIdentical " << nNotIdentical
829 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
845 if(SCT_ModuleID == SCT_ModuleID2)
continue;
848 (
m_ModuleMap[SCT_ModuleID])->addStaveConstraintPoint(Stavepoints);
859 std::vector< SurveyConstraintPoint > Testpoints;
861 msg(MSG::INFO) <<
"SurveyConstraint().setup_SurveyConstraintModules: Stavepoints.size() (from map) " << Testpoints.size() <<
endmsg;
867 msg(MSG::INFO) <<
"Loop 2, filling stave-points, nSCTModEC2 " << nPixModEC2
868 <<
", nSCTModSCTModEC " << nPixModPixModEC
869 <<
", nSCTModECSCTModEC " << nPixModECPixModEC
870 <<
", nSameLayer " << nSameLayer
871 <<
", nNotIdentical " << nNotIdentical
875 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
891 if(SCT_ModuleID == SCT_ModuleID2)
continue;
894 (
m_ModuleMap[SCT_ModuleID])->addStaveConstraintPoint(Stavepoints);
897 msg(MSG::INFO) <<
"Loop 2, filling stave-points, nSCTModB2 " << nPixModEC2
898 <<
", nSCTModSCTModB " << nPixModPixModEC
899 <<
", nSCTModBSCTModB " << nPixModECPixModEC
900 <<
", nSameLayer " << nSameLayer
901 <<
", nNotIdentical " << nNotIdentical
910 msg(MSG::ERROR) <<
"Write of AlignableTransforms fails" <<
endmsg;
989 std::vector< Amg::Vector3D > & coords) {
991 const double SurveyTargetX = 17.8/2.0;
992 const double SurveyTargetY = 59.8/2.0;
994 coords.emplace_back(-SurveyTargetX,-SurveyTargetY,0.0);
995 coords.emplace_back(-SurveyTargetX, SurveyTargetY,0.0);
996 coords.emplace_back( SurveyTargetX,-SurveyTargetY,0.0);
997 coords.emplace_back( SurveyTargetX, SurveyTargetY,0.0);
1002 std::vector< Amg::Vector3D > & coords) {
1004 const double SurveyTargetX = 17.8/2.0;
1005 const double SurveyTargetY = 59.8/2.0;
1007 coords.emplace_back(-SurveyTargetX,-SurveyTargetY,0.0);
1008 coords.emplace_back(-SurveyTargetX, SurveyTargetY,0.0);
1009 coords.emplace_back( SurveyTargetX,-SurveyTargetY,0.0);
1010 coords.emplace_back( SurveyTargetX, SurveyTargetY,0.0);
1015 std::vector< Amg::Vector3D > & coords) {
1017 const double SurveyTargetX = 63.6/2.0;
1018 const double SurveyTargetY = 128.2/2.0;
1020 coords.emplace_back(-SurveyTargetX,-SurveyTargetY,0.0);
1021 coords.emplace_back(-SurveyTargetX, SurveyTargetY,0.0);
1022 coords.emplace_back( SurveyTargetX,-SurveyTargetY,0.0);
1023 coords.emplace_back( SurveyTargetX, SurveyTargetY,0.0);
1028 std::vector< Amg::Vector3D > & coords) {
1030 const double SurveyTargetX = 63.6/2.0;
1031 const double SurveyTargetY = 128.2/2.0;
1033 coords.emplace_back(-SurveyTargetX,-SurveyTargetY,0.0);
1034 coords.emplace_back(-SurveyTargetX, SurveyTargetY,0.0);
1035 coords.emplace_back( SurveyTargetX,-SurveyTargetY,0.0);
1036 coords.emplace_back( SurveyTargetX, SurveyTargetY,0.0);
1041 std::vector<SurveyConstraintPoint>& points) {
1045 for(
unsigned ipoint=0;ipoint<points.size();ipoint++){
1048 survey =globaltolocal *survey;
1078 if(phi_module >= 0 && phi_module <= 5)
return 0;
1079 if(phi_module >= 6 && phi_module <= 11)
return 1;
1080 if(phi_module >= 12 && phi_module <= 17)
return 2;
1081 if(phi_module >= 18 && phi_module <= 23)
return 3;
1082 if(phi_module >= 24 && phi_module <= 29)
return 4;
1083 if(phi_module >= 30 && phi_module <= 35)
return 5;
1084 if(phi_module >= 36 && phi_module <= 41)
return 6;
1085 if(phi_module >= 42 && phi_module <= 47)
return 7;
1091 int phiMod6 = phi_module%6;
1092 if(phiMod6 == 0)
return ( 7.5 - phiModEnd) * 1.0_degree;
1093 else if(phiMod6 == 1)
return (15 - phiModEnd) * 1.0_degree;
1094 else if(phiMod6 == 2)
return (22.5 - phiModEnd) * 1.0_degree;
1095 else if(phiMod6 == 3)
return (30 - phiModEnd) * 1.0_degree;
1096 else if(phiMod6 == 4)
return (37.5 - phiModEnd) * 1.0_degree;
1097 else if(phiMod6 == 5)
return (45 - phiModEnd) * 1.0_degree;