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)
48 m_current_IDAlignDBTool(
nullptr),
49 m_survey_IDAlignDBTool(
nullptr),
53 m_SurveyWeightPhiX(1.0),
54 m_SurveyWeightPhiY(1.0),
55 m_SurveyWeightPhiZ(1.0),
69 m_TransXRandPixB(0.01),
70 m_TransYRandPixB(0.01),
71 m_TransZRandPixB(0.1),
72 m_RotXRandPixB(0.001),
73 m_RotYRandPixB(0.001),
74 m_RotZRandPixB(0.00024),
75 m_TransXRandSCTEC(0.03),
76 m_TransYRandSCTEC(0.03),
77 m_TransZRandSCTEC(0.03),
78 m_RotXRandSCTEC(0.001),
79 m_RotYRandSCTEC(0.001),
80 m_RotZRandSCTEC(0.0003),
81 m_TransXRandSCTB(0.1),
82 m_TransYRandSCTB(0.1),
83 m_TransZRandSCTB(0.1),
84 m_RotXRandSCTB(0.001),
85 m_RotYRandSCTB(0.001),
86 m_RotZRandSCTB(0.001),
88 m_TransXRandSect(0.0),
89 m_TransYRandSect(0.0),
90 m_TransZRandSect(0.0),
100 m_aligndbtoolinst(
"InDetCurrentDBTool"),
101 m_surveydbtoolinst(
"InDetSurveyDBTool"),
106 declareProperty(
"SurveyWeightX" , m_SurveyWeightX);
107 declareProperty(
"SurveyWeightY" , m_SurveyWeightY);
108 declareProperty(
"SurveyWeightZ" , m_SurveyWeightZ);
109 declareProperty(
"SurveyWeightPhiX" , m_SurveyWeightPhiX);
110 declareProperty(
"SurveyWeightPhiY" , m_SurveyWeightPhiY);
111 declareProperty(
"SurveyWeightPhiZ" , m_SurveyWeightPhiZ);
112 declareProperty(
"TransX" , m_TransX);
113 declareProperty(
"TransY" , m_TransY);
114 declareProperty(
"TransZ" , m_TransZ);
115 declareProperty(
"RotX" , m_RotX);
116 declareProperty(
"RotX2" , m_RotX2);
117 declareProperty(
"RotY" , m_RotY);
118 declareProperty(
"RotZ" , m_RotZ);
119 declareProperty(
"TransXRand" , m_TransXRand);
120 declareProperty(
"TransYRand" , m_TransYRand);
121 declareProperty(
"TransZRand" , m_TransZRand);
122 declareProperty(
"RotXRand" , m_RotXRand);
123 declareProperty(
"RotYRand" , m_RotYRand);
124 declareProperty(
"RotZRand" , m_RotZRand);
125 declareProperty(
"TransXRandPixB" , m_TransXRandPixB);
126 declareProperty(
"TransYRandPixB" , m_TransYRandPixB);
127 declareProperty(
"TransZRandPixB" , m_TransZRandPixB);
128 declareProperty(
"RotXRandPixB" , m_RotXRandPixB);
129 declareProperty(
"RotYRandPixB" , m_RotYRandPixB);
130 declareProperty(
"RotZRandPixB" , m_RotZRandPixB);
131 declareProperty(
"TransXRandSCTEC" , m_TransXRandSCTEC);
132 declareProperty(
"TransYRandSCTEC" , m_TransYRandSCTEC);
133 declareProperty(
"TransZRandSCTEC" , m_TransZRandSCTEC);
134 declareProperty(
"RotXRandSCTEC" , m_RotXRandSCTEC);
135 declareProperty(
"RotYRandSCTEC" , m_RotYRandSCTEC);
136 declareProperty(
"RotZRandSCTEC" , m_RotZRandSCTEC);
137 declareProperty(
"TransXRandSCTB" , m_TransXRandSCTB);
138 declareProperty(
"TransYRandSCTB" , m_TransYRandSCTB);
139 declareProperty(
"TransZRandSCTB" , m_TransZRandSCTB);
140 declareProperty(
"RotXRandSCTB" , m_RotXRandSCTB);
141 declareProperty(
"RotYRandSCTB" , m_RotYRandSCTB);
142 declareProperty(
"RotZRandSCTB" , m_RotZRandSCTB);
143 declareProperty(
"Gaus" , m_gaus);
144 declareProperty(
"TransXRandSect" , m_TransXRandSect);
145 declareProperty(
"TransYRandSect" , m_TransYRandSect);
146 declareProperty(
"TransZRandSect" , m_TransZRandSect);
147 declareProperty(
"RotXRandSect" , m_RotXRandSect);
148 declareProperty(
"RotYRandSect" , m_RotYRandSect);
149 declareProperty(
"RotZRandSect" , m_RotZRandSect);
150 declareProperty(
"TransLayerRand" , m_TransLayerRand);
151 declareProperty(
"Misaligncase" , m_misaligncase);
152 declareProperty(
"GausSect" , m_gausSect);
153 declareProperty(
"FullDisk" , m_FullDisk);
154 declareProperty(
"ScaleZ" , m_scaleZ);
155 declareProperty(
"Proximity" , m_proximity);
156 declareProperty(
"CurrentDBToolInst" , m_aligndbtoolinst);
157 declareProperty(
"SurveyDBToolInst" , m_surveydbtoolinst);
158 declareProperty(
"SurveyWfile" , m_surveywfile);
159 declareProperty(
"SurveyRFile" , m_surveyrfile);
160 declareProperty(
"Ntuple" , m_ntuple);
171 SmartIF<IToolSvc> toolSvc{Gaudi::svcLocator()->service(
"ToolSvc")};
191 ATH_MSG_INFO(
"got ID helpers from detector store (relying on GeoModel to put them)");
225 ATH_MSG_INFO(
"now entering SurveyConstraint::setup_SurveyConstraintModules()");
228 return StatusCode::SUCCESS;
238 std::map<Identifier, SurveyConstraintModule*, std::less<Identifier> >
::iterator it;
244 return StatusCode::SUCCESS;
272 bool isPixEC =
false, isPixB =
false, isSCTEC =
false, isSCTB =
false;
287 std::vector< SurveyConstraintPoint > Stavepoints;
289 ATH_MSG_DEBUG(
"SurveyConstraint().computeConstraint: Stavepoints.size() " << Stavepoints.size());
294 for (
unsigned int iPoint(0); iPoint < Stavepoints.size(); ++iPoint ) {
296 ATH_MSG_DEBUG(
"Survey Stavepoints before: " << survey.x() <<
"," << survey.y() <<
"," << survey.z());
299 survey = Stavepoints[iPoint].survey();
300 ATH_MSG_DEBUG(
" and after: " << survey.x() <<
"," << survey.y() <<
"," << survey.z());
303 ATH_MSG_DEBUG(
"SurveyConstraint().computeConstraint: Now fitting the 2 Staves");
304 double stavemin = minimizer.
findMinimum(Stavepoints,staveangles,stavetrans);
309 stavetrans[2] = (stavetrans.z()/
m_scaleZ);
311 << stavetrans.x() <<
"," << stavetrans.y() <<
"," << stavetrans.z() <<
","
312 << staveangles.x()/
m_scaleZ <<
"," << staveangles.y()/
m_scaleZ <<
"," << staveangles.z() <<
")");
317 return StatusCode::FAILURE;
322 Amg::Transform3D staveTransform = amgstavetrans * Amg::RotationMatrix3D::Identity();
330 std::vector< SurveyConstraintPoint > Modulepoints;
338 for(
unsigned ipoint=0;ipoint<Modulepoints.size();ipoint++){
340 survey = staveTransform * survey;
346 ATH_MSG_DEBUG(
"SurveyConstraint().computeConstraint: Now fitting the 2 Modules");
350 return StatusCode::FAILURE;
354 for(
unsigned ipar=0;ipar<3;ipar++)
355 dparams[ipar] = modtrans[ipar];
356 dparams[3] = modangles[0];
357 dparams[4] = modangles[1];
358 dparams[5] = modangles[2];
377 return StatusCode::FAILURE;
388 ATH_MSG_ERROR(
"Chech that the size of the matrix is a 1,1: " << temp.rows() <<
", " << temp.cols());
389 deltachisq = temp(0,0);
395 DOCA_Vector = 2.0*
weight*dparams;
398 return StatusCode::SUCCESS;
404 SmartIF<IRndmGenSvc> randsvc{Gaudi::svcLocator()->service(
"RndmGenSvc")};
405 Rndm::Numbers
gauss(randsvc,Rndm::Gauss(0.,1.));
421 m_survey_IDAlignDBTool->
dispGroup(-1, -1, -1, -1, -1,
m_TransLayerRand,
m_TransLayerRand,
m_TransLayerRand, 2, 2, 0);
424 m_survey_IDAlignDBTool->
dispGroup(1, 2, 0, -1, -1,
m_TransLayerRand, 0, 0, 1, 2, 0);
427 m_survey_IDAlignDBTool->
dispGroup(1, 2, 2, -1, -1,
m_TransLayerRand, 0, 0, 1, 2, 0);
430 int nSCT(0), nPixel(0);
431 std::vector< Amg::Vector3D > localSurveyCoords;
433 SurveyTransRand.setIdentity();
434 SurveyTransRandSect.setIdentity();
436 unsigned int nSCTMod = 0,nSCTModInMap = 0,nSCTModEC = 0,nSCTModPointsEC = 0;
440 if (not sctDetEleHandle.
isValid() or sctElements==
nullptr) {
445 const Identifier SCT_ModuleID = element->identify();
485 Misalign_Vector[0]=
m1;Misalign_Vector[1]=
m2;Misalign_Vector[2]=
m3;Misalign_Vector[3]=m4;Misalign_Vector[4]=m5;Misalign_Vector[5]=m6;
502 Misalign_Vector[0]=
m1;Misalign_Vector[1]=
m2;Misalign_Vector[2]=
m3;Misalign_Vector[3]=m4;Misalign_Vector[4]=m5;Misalign_Vector[5]=m6;
509 for (
unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
512 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) * localSurveyCoords[iCorn];
517 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint );
518 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint);
526 bool first =
true, NewDisk =
true, NewSector =
true, firstB =
true;
527 unsigned int nPixMod = 0,nPixModInMap = 0,nPixModEC = 0,nPixModPointsEC = 0;
528 int previous_disk = -1, previous_sector = -1;
532 if (not pixelDetEleHandle.
isValid() or pixelElements==
nullptr) {
537 const Identifier Pixel_ModuleID = element->identify();
592 Misalign_Vector[0]=
m1;Misalign_Vector[1]=
m2;Misalign_Vector[2]=
m3;Misalign_Vector[3]=m4;Misalign_Vector[4]=m5;Misalign_Vector[5]=m6;
613 for (
unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
617 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) * localSurveyCoords[iCorn];
623 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint);
624 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint );
637 ATH_MSG_INFO(
"Local Coordinates = (" << localSurveyCoords[iCorn][0] <<
","
638 << localSurveyCoords[iCorn][1] <<
"," << localSurveyCoords[iCorn][2] <<
")");
639 ATH_MSG_INFO(
"Survey Local Coordinates = (" << surveyPoint[0] <<
","
640 << surveyPoint[1] <<
"," << surveyPoint[2] <<
")");
641 ATH_MSG_INFO(
"Current Local Coordinates = (" << currentPoint[0] <<
","
642 << currentPoint[1] <<
"," << currentPoint[2] <<
")");
643 ATH_MSG_INFO(
"Survey Global Coordinates = (" << globalSurveyPoint[0] <<
","
644 << globalSurveyPoint[1] <<
"," << globalSurveyPoint[2] <<
")");
645 ATH_MSG_INFO(
"Current Global Coordinates = (" << globalCurrentPoint[0] <<
","
646 << globalCurrentPoint[1] <<
"," << globalCurrentPoint[2] <<
")");
647 ATH_MSG_INFO(
"SurveyConstraint().setup_SurveyConstraintModules: nModulePoints " <<
m_ModuleMap[Pixel_ModuleID]->nModulePoints());
680 Misalign_Vector[0]=
m1;Misalign_Vector[1]=
m2;Misalign_Vector[2]=
m3;Misalign_Vector[3]=m4;Misalign_Vector[4]=m5;Misalign_Vector[5]=m6;
686 for (
unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
689 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) *localSurveyCoords[iCorn] ;
694 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint );
695 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint );
704 <<
", nSCTModInMap " << nSCTModInMap
705 <<
", nSCTModEC " << nSCTModEC
706 <<
", nSCTModPointsEC " << nSCTModPointsEC
707 <<
", nPixMod " << nPixMod
708 <<
", nPixModInMap " << nPixModInMap
709 <<
", nPixModEC " << nPixModEC
710 <<
", nPixModPointsEC " << nPixModPointsEC);
718 std::vector< SurveyConstraintPoint > Stavepoints;
720 unsigned int nPixModEC2 = 0,nPixModPixModEC = 0,nPixModECPixModEC = 0,nSameLayer = 0,nNotIdentical = 0;
727 const Identifier Pixel_ModuleID2 = *wafer_it2;
736 if(Pixel_ModuleID != Pixel_ModuleID2){
739 (
m_ModuleMap[Pixel_ModuleID])->addStaveConstraintPoint(Stavepoints);
744 std::vector< SurveyConstraintPoint > Testpoints;
746 ATH_MSG_INFO(
"SurveyConstraint().setup_SurveyConstraintModules: Stavepoints.size() (from map) " << Testpoints.size());
758 ATH_MSG_INFO(
"Loop 2, filling stave-points, nPixModEC2 " << nPixModEC2
759 <<
", nPixModPixModEC " << nPixModPixModEC
760 <<
", nPixModECPixModEC " << nPixModECPixModEC
761 <<
", nSameLayer " << nSameLayer
762 <<
", nNotIdentical " << nNotIdentical);
765 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
772 const Identifier Pixel_ModuleID2 = *wafer_it2;
779 if(Pixel_ModuleID == Pixel_ModuleID2)
continue;
782 (
m_ModuleMap[Pixel_ModuleID])->addStaveConstraintPoint(Stavepoints);
785 ATH_MSG_INFO(
"Loop 2, filling stave-points, nPixModB2 " << nPixModEC2
786 <<
", nPixModPixModB " << nPixModPixModEC
787 <<
", nPixModBPixModB " << nPixModECPixModEC
788 <<
", nSameLayer " << nSameLayer
789 <<
", nNotIdentical " << nNotIdentical);
792 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
808 if(SCT_ModuleID == SCT_ModuleID2)
continue;
811 (
m_ModuleMap[SCT_ModuleID])->addStaveConstraintPoint(Stavepoints);
822 std::vector< SurveyConstraintPoint > Testpoints;
824 ATH_MSG_INFO(
"SurveyConstraint().setup_SurveyConstraintModules: Stavepoints.size() (from map) " << Testpoints.size());
830 ATH_MSG_INFO(
"Loop 2, filling stave-points, nSCTModEC2 " << nPixModEC2
831 <<
", nSCTModSCTModEC " << nPixModPixModEC
832 <<
", nSCTModECSCTModEC " << nPixModECPixModEC
833 <<
", nSameLayer " << nSameLayer
834 <<
", nNotIdentical " << nNotIdentical);
837 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
853 if(SCT_ModuleID == SCT_ModuleID2)
continue;
856 (
m_ModuleMap[SCT_ModuleID])->addStaveConstraintPoint(Stavepoints);
859 ATH_MSG_INFO(
"Loop 2, filling stave-points, nSCTModB2 " << nPixModEC2
860 <<
", nSCTModSCTModB " << nPixModPixModEC
861 <<
", nSCTModBSCTModB " << nPixModECPixModEC
862 <<
", nSameLayer " << nSameLayer
863 <<
", nNotIdentical " << nNotIdentical);
949 std::vector< Amg::Vector3D > & coords) {
951 const double SurveyTargetX = 17.8/2.0;
952 const double SurveyTargetY = 59.8/2.0;
954 coords.emplace_back(-SurveyTargetX,-SurveyTargetY,0.0);
955 coords.emplace_back(-SurveyTargetX, SurveyTargetY,0.0);
956 coords.emplace_back( SurveyTargetX,-SurveyTargetY,0.0);
957 coords.emplace_back( SurveyTargetX, SurveyTargetY,0.0);
962 std::vector< Amg::Vector3D > & coords) {
964 const double SurveyTargetX = 17.8/2.0;
965 const double SurveyTargetY = 59.8/2.0;
967 coords.emplace_back(-SurveyTargetX,-SurveyTargetY,0.0);
968 coords.emplace_back(-SurveyTargetX, SurveyTargetY,0.0);
969 coords.emplace_back( SurveyTargetX,-SurveyTargetY,0.0);
970 coords.emplace_back( SurveyTargetX, SurveyTargetY,0.0);
975 std::vector< Amg::Vector3D > & coords) {
977 const double SurveyTargetX = 63.6/2.0;
978 const double SurveyTargetY = 128.2/2.0;
980 coords.emplace_back(-SurveyTargetX,-SurveyTargetY,0.0);
981 coords.emplace_back(-SurveyTargetX, SurveyTargetY,0.0);
982 coords.emplace_back( SurveyTargetX,-SurveyTargetY,0.0);
983 coords.emplace_back( SurveyTargetX, SurveyTargetY,0.0);
988 std::vector< Amg::Vector3D > & coords) {
990 const double SurveyTargetX = 63.6/2.0;
991 const double SurveyTargetY = 128.2/2.0;
993 coords.emplace_back(-SurveyTargetX,-SurveyTargetY,0.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);
1001 std::vector<SurveyConstraintPoint>&
points) {
1005 for(
unsigned ipoint=0;ipoint<
points.size();ipoint++){
1008 survey =globaltolocal *survey;
1038 if(phi_module >= 0 && phi_module <= 5)
return 0;
1039 if(phi_module >= 6 && phi_module <= 11)
return 1;
1040 if(phi_module >= 12 && phi_module <= 17)
return 2;
1041 if(phi_module >= 18 && phi_module <= 23)
return 3;
1042 if(phi_module >= 24 && phi_module <= 29)
return 4;
1043 if(phi_module >= 30 && phi_module <= 35)
return 5;
1044 if(phi_module >= 36 && phi_module <= 41)
return 6;
1045 if(phi_module >= 42 && phi_module <= 47)
return 7;
1051 int phiMod6 = phi_module%6;
1052 if(phiMod6 == 0)
return ( 7.5 - phiModEnd) * 1.0_degree;
1053 else if(phiMod6 == 1)
return (15 - phiModEnd) * 1.0_degree;
1054 else if(phiMod6 == 2)
return (22.5 - phiModEnd) * 1.0_degree;
1055 else if(phiMod6 == 3)
return (30 - phiModEnd) * 1.0_degree;
1056 else if(phiMod6 == 4)
return (37.5 - phiModEnd) * 1.0_degree;
1057 else if(phiMod6 == 5)
return (45 - phiModEnd) * 1.0_degree;