ATLAS Offline Software
Loading...
Searching...
No Matches
SurveyConstraint.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "SurveyConstraint.h"
7
8// Gaudi & StoreGate
9#include "GaudiKernel/MsgStream.h"
10#include "GaudiKernel/SmartDataPtr.h"
12
14
15
16// Geometry Stuff
17#include "Identifier/Identifier.h"
24
25// Alignment DB StuffStuff
27#include "GaudiKernel/IRndmGenSvc.h"
28#include "GaudiKernel/RndmGenerators.h"
29
30#include <cmath>
31
32// use anonymous namespace to be only valid inside this .cxx file
33namespace {
34 constexpr long double operator"" _degree ( long double deg ){
35 return deg * M_PI / 180;
36 }
37 static constexpr double const& phiModEnd = 26.25;
38}
39
41
43 const std::string& name, const IInterface* parent)
44 : base_class(type,name,parent),
45 m_idHelper{},
46 m_pixid(nullptr),
47 m_sctid(nullptr),
50 m_SurveyWeightX(1.0),
51 m_SurveyWeightY(1.0),
52 m_SurveyWeightZ(1.0),
56 m_TransX(0.0),
57 m_TransY(0.0),
58 m_TransZ(0.0),
59 m_RotX(0.0),
60 m_RotX2(0.0),
61 m_RotY(0.0),
62 m_RotZ(0.0),
63 m_TransXRand(0.0046),
64 m_TransYRand(0.0047),
65 m_TransZRand(0.0127),
66 m_RotXRand(0.0003),
67 m_RotYRand(0.0007),
68 m_RotZRand(0.00012),
69 m_TransXRandPixB(0.01),
70 m_TransYRandPixB(0.01),
72 m_RotXRandPixB(0.001),
73 m_RotYRandPixB(0.001),
74 m_RotZRandPixB(0.00024),
78 m_RotXRandSCTEC(0.001),
79 m_RotYRandSCTEC(0.001),
80 m_RotZRandSCTEC(0.0003),
84 m_RotXRandSCTB(0.001),
85 m_RotYRandSCTB(0.001),
86 m_RotZRandSCTB(0.001),
87 m_gaus(false),
91 m_RotXRandSect(0.0),
92 m_RotYRandSect(0.0),
93 m_RotZRandSect(0.0),
96 m_gausSect(false),
97 m_FullDisk(false),
98 m_scaleZ(1.0),
99 m_proximity(999999.),
100 m_aligndbtoolinst("InDetCurrentDBTool"),
101 m_surveydbtoolinst("InDetSurveyDBTool"),
102 m_surveywfile(""),
103 m_surveyrfile(""),
104 m_ntuple(false)
105 {
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);
161}
162
163// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
164
166
167 // Part 1: Get the messaging service, print where you are
168 ATH_MSG_INFO("SurveyConstraint initialize()");
169
170 // Get The ToolSvc
171 SmartIF<IToolSvc> toolSvc{Gaudi::svcLocator()->service("ToolSvc")};
172 ATH_CHECK(toolSvc.isValid());
173 ATH_MSG_INFO("got ToolSvc");
174
175 // Get current InDetAlignDataBaseTool from ToolService
176 ATH_CHECK(toolSvc->retrieveTool("InDetAlignDBTool",m_aligndbtoolinst,m_current_IDAlignDBTool));
177 ATH_MSG_INFO("got current_IDAlignDBTool");
178 ATH_MSG_INFO("current_IDAlignDBTool name = " << m_current_IDAlignDBTool->name());
179
180 // Get survey InDetAlignDataBaseTool from ToolService
181 ATH_CHECK(toolSvc->retrieveTool("InDetAlignDBTool",m_surveydbtoolinst,m_survey_IDAlignDBTool));
182 ATH_MSG_INFO("got survey_IDAlignDBTool");
183
184 //ID Helper
185 ATH_CHECK(detStore()->retrieve(m_idHelper, "AtlasID" ));
186 ATH_MSG_DEBUG("Found AtlasDetectorID");
187
188 // get ID helpers from detector store (relying on GeoModel to put them)
189 ATH_CHECK(detStore()->retrieve(m_pixid));
190 ATH_CHECK(detStore()->retrieve(m_sctid));
191 ATH_MSG_INFO("got ID helpers from detector store (relying on GeoModel to put them)");
192
193 // ReadCondHandleKeys
194 ATH_CHECK(m_pixelDetEleCollKey.initialize());
195 ATH_CHECK(m_SCTDetEleCollKey.initialize());
196
197 // Protection against singular weight matrix
198 if (m_surveywfile==""){
199 if(m_TransXRand<1.E-7) m_TransXRand=1.E-7;
200 if(m_TransYRand<1.E-7) m_TransYRand=1.E-7;
201 if(m_TransZRand<1.E-7) m_TransZRand=1.E-7;
202 if(m_RotXRand<1.E-7) m_RotXRand=1.E-7;
203 if(m_RotYRand<1.E-7) m_RotYRand=1.E-7;
204 if(m_RotZRand<1.E-7) m_RotZRand=1.E-7;
205 if(m_TransXRandPixB<1.E-7) m_TransXRandPixB=1.E-7;
206 if(m_TransYRandPixB<1.E-7) m_TransYRandPixB=1.E-7;
207 if(m_TransZRandPixB<1.E-7) m_TransZRandPixB=1.E-7;
208 if(m_RotXRandPixB<1.E-7) m_RotXRandPixB=1.E-7;
209 if(m_RotYRandPixB<1.E-7) m_RotYRandPixB=1.E-7;
210 if(m_RotZRandPixB<1.E-7) m_RotZRandPixB=1.E-7;
211 //
212 if(m_TransXRandSCTEC<1.E-7) m_TransXRandSCTEC=1.E-7;
213 if(m_TransYRandSCTEC<1.E-7) m_TransYRandSCTEC=1.E-7;
214 if(m_TransZRandSCTEC<1.E-7) m_TransZRandSCTEC=1.E-7;
215 if(m_RotXRandSCTEC<1.E-7) m_RotXRandSCTEC=1.E-7;
216 if(m_RotYRandSCTEC<1.E-7) m_RotYRandSCTEC=1.E-7;
217 if(m_RotZRandSCTEC<1.E-7) m_RotZRandSCTEC=1.E-7;
218 if(m_TransXRandSCTB<1.E-7) m_TransXRandSCTB=1.E-7;
219 if(m_TransYRandSCTB<1.E-7) m_TransYRandSCTB=1.E-7;
220 if(m_TransZRandSCTB<1.E-7) m_TransZRandSCTB=1.E-7;
221 if(m_RotXRandSCTB<1.E-7) m_RotXRandSCTB=1.E-7;
222 if(m_RotYRandSCTB<1.E-7) m_RotYRandSCTB=1.E-7;
223 if(m_RotZRandSCTB<1.E-7) m_RotZRandSCTB=1.E-7;
224 }
225 ATH_MSG_INFO("now entering SurveyConstraint::setup_SurveyConstraintModules()");
227 //if (m_surveywfile!="")
228 return StatusCode::SUCCESS;
229 }
230
231// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
232
234
235 // Part 1: Get the messaging service, print where you are
236 ATH_MSG_INFO("finalize()");
237
238 std::map<Identifier, SurveyConstraintModule*, std::less<Identifier> >::iterator it;
239 for (it = m_ModuleMap.begin(); it != m_ModuleMap.end(); ++it) {
240 delete it->second;
241 }
242 m_ModuleMap.clear();
243
244 return StatusCode::SUCCESS;
245}
246
247
248 void SurveyConstraint::MMap(std::map<Identifier, SurveyConstraintModule*, std::less<Identifier> >& ModuleMap) {
249 ModuleMap = m_ModuleMap;
250 }
251
252
254 Amg::VectorX& dparams, // alignment parameters
255 double& deltachisq,
256 Amg::VectorX& DOCA_Vector,
257 Amg::MatrixX& DOCA_Matrix) {
258 AmgVector(6) weightfactor;
259 weightfactor[0] = m_SurveyWeightX;
260 weightfactor[1] = m_SurveyWeightY;
261 weightfactor[2] = m_SurveyWeightZ;
262 weightfactor[3] = m_SurveyWeightPhiX;
263 weightfactor[4] = m_SurveyWeightPhiY;
264 weightfactor[5] = m_SurveyWeightPhiZ;
265
266
267 //get the SurveyConstraintModule from the ModuleMap, it knows about the global
268 //Module-SurveyConstraintPoints, and the global Stave-SurveyConstraintPoints
269 SurveyConstraintModule* mut = m_ModuleMap[ModuleID];
270
271 // which subdetector?
272 bool isPixEC = false, isPixB = false, isSCTEC = false, isSCTB = false;
273 if(mut->isPixel()){
274 if(abs(m_pixid->barrel_ec(ModuleID)) == 2) isPixEC = true;
275 else if(m_pixid->barrel_ec(ModuleID) == 0) isPixB = true;
276 } else {
277 if(abs(m_sctid->barrel_ec(ModuleID)) == 2) isSCTEC = true;
278 else if(m_sctid->barrel_ec(ModuleID) == 0) isSCTB = true;
279 }
280
281 //Define the transform which minimizes the distance between the set of
282 //point pairs: this effectively defines the transform between the survey
283 //and current alignment of the SOW.
285 Amg::Vector3D stavetrans;
286 Amg::Vector3D staveangles;
287 std::vector< SurveyConstraintPoint > Stavepoints;
289 ATH_MSG_DEBUG("SurveyConstraint().computeConstraint: Stavepoints.size() " << Stavepoints.size());
290 // transform GlobalToLocal
291 GlobalToLocal(mut,Stavepoints);
292
293 // scale z coordinate
294 for (unsigned int iPoint(0); iPoint < Stavepoints.size(); ++iPoint ) {
295 Amg::Vector3D survey = Stavepoints[iPoint].survey();
296 ATH_MSG_DEBUG("Survey Stavepoints before: " << survey.x() << "," << survey.y() << "," << survey.z());
297 SurveyConstraintPoint& Stavepoint = Stavepoints[iPoint];
298 Stavepoint.scaleZ(m_scaleZ);
299 survey = Stavepoints[iPoint].survey();
300 ATH_MSG_DEBUG(" and after: " << survey.x() << "," << survey.y() << "," << survey.z());
301 }
302
303 ATH_MSG_DEBUG("SurveyConstraint().computeConstraint: Now fitting the 2 Staves");
304 double stavemin = minimizer.findMinimum(Stavepoints,staveangles,stavetrans);
305
306
307
308
309 stavetrans[2] = (stavetrans.z()/m_scaleZ);
310 ATH_MSG_DEBUG("Stavepoints translation and rotations: ("
311 << stavetrans.x() << "," << stavetrans.y() << "," << stavetrans.z() << ","
312 << staveangles.x()/m_scaleZ << "," << staveangles.y()/m_scaleZ << "," << staveangles.z() << ")");
313
314
315 if(stavemin < 0.0){
316 ATH_MSG_FATAL("insufficient Points for Stave Fitting");
317 return StatusCode::FAILURE;
318 }
319
320 //(***) create the transform from survey to current with these parameters
321 Amg::Translation3D amgstavetrans(stavetrans);
322 Amg::Transform3D staveTransform = amgstavetrans * Amg::RotationMatrix3D::Identity();
323 staveTransform *= Amg::AngleAxis3D(staveangles[2], Amg::Vector3D(0.,0.,1.));
324 staveTransform *= Amg::AngleAxis3D(staveangles[1]/m_scaleZ, Amg::Vector3D(0.,1.,0.));
325 staveTransform *= Amg::AngleAxis3D(staveangles[0]/m_scaleZ, Amg::Vector3D(1.,0.,0.));
326
327
328 //now, get the points on the MUT, and move to the MUTs frame
329 //we must get the points from the wafer itself
330 std::vector< SurveyConstraintPoint > Modulepoints;
331 mut->getPoints(Modulepoints,SurveyConstraintModule::Module);
332
333 // transform GlobalToLocal
334 GlobalToLocal(mut,Modulepoints);
335
336
337 //transform ONLY the survey points(survey,-) according to the transform from survey to current from the SOW (***)
338 for(unsigned ipoint=0;ipoint<Modulepoints.size();ipoint++){
339 Amg::Vector3D& survey = Modulepoints[ipoint].survey();
340 survey = staveTransform * survey;
341 }
342
343 //now compute the final parameters: build the 3D residuals between the two sets of MUT points
344 Amg::Vector3D modtrans;
345 Amg::Vector3D modangles;
346 ATH_MSG_DEBUG("SurveyConstraint().computeConstraint: Now fitting the 2 Modules");
347 double modmin = minimizer.findMinimum(Modulepoints,modangles,modtrans);
348 if(modmin < 0.0){
349 ATH_MSG_FATAL("insufficient Points for Module Fitting");
350 return StatusCode::FAILURE;
351 }
352
353 // fill the dparams vector
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];
359
360 // for this get the errors (weight) on the points (actually independent of MUTid)
361 Amg::MatrixX weight;
362 bool ierr=-1;
363 if(isPixEC) ierr = getWeightPixEC(//ModuleID,
364 weight);
365 else if(isPixB) ierr = getWeightPixB(//ModuleID,
366 weight);
367 else if(isSCTEC) ierr = getWeightSCTEC(//ModuleID,
368 weight);
369 else if(isSCTB) ierr = getWeightSCTB(//ModuleID,
370 weight);
371 if(ierr != 0){
372 ATH_MSG_FATAL("matrixInvertFail");
373 if(isPixEC) ATH_MSG_FATAL("for PixEC");
374 else if(isPixB) ATH_MSG_FATAL("for PixB");
375 else if(isSCTEC) ATH_MSG_FATAL("for SCTEC");
376 else if(isSCTB) ATH_MSG_FATAL("for SCTB");
377 return StatusCode::FAILURE;
378 }
379
380 // and asign additional weightfactor to simulate systematic uncertainties (bowing etc.)
381 // Don't need this: Put systematics already in weight matrix!!!
382// for(unsigned icol=1;icol<=6;icol++)
383// for(unsigned irow=1;irow<=icol;irow++)
384// weight.fast(icol,irow) *= weightfactor(icol)*weightfactor(irow);
385
386 // now get the chi2, add to the vector and the matrix.
387 Amg::MatrixX temp = dparams.transpose() * weight * dparams;
388 ATH_MSG_ERROR("Chech that the size of the matrix is a 1,1: " << temp.rows() << ", " << temp.cols());
389 deltachisq = temp(0,0);
390
391
392 // the derivatives are trivial, since we're already in the wafers local
393 // coordinate system. The factor of 2 comes from the dfn of chisquared, the
394 // sign from the convention that we measure dparams as current-survey
395 DOCA_Vector = 2.0*weight*dparams; // dchisqdparams
396 DOCA_Matrix = 2.0*weight; // d2chisqdpdp
397
398 return StatusCode::SUCCESS;
399}
400
401
403{
404 SmartIF<IRndmGenSvc> randsvc{Gaudi::svcLocator()->service("RndmGenSvc")};
405 Rndm::Numbers gauss(randsvc,Rndm::Gauss(0.,1.));
406
407 // read in or write an alignment file for the survey alignment,
408 // either a text file (SurveyText.txt) or an ntuple (reading in and writing out
409 // an ntuple does not work at the moment). For this create a DB
410 // an set DBRoot to "/Indet/SiSurvey"
411 if (m_surveyrfile!="" || m_surveywfile!="") m_survey_IDAlignDBTool->createDB();
412 if (m_surveyrfile!=""){
414 else m_survey_IDAlignDBTool->readTextFile(m_surveyrfile);
415 }
416
417 // create some displacements at level 1/2/3, using only one parameter m_TransLayerRand
418 if(m_TransLayerRand > 0){
419 // displace all layers randomly
420 if(m_misaligncase == 0)
421 m_survey_IDAlignDBTool->dispGroup(-1, -1, -1, -1, -1, m_TransLayerRand, m_TransLayerRand, m_TransLayerRand, 2, 2, 0);
422 // displace pixel EC layer 0 in x
423 else if(m_misaligncase == 1)
424 m_survey_IDAlignDBTool->dispGroup(1, 2, 0, -1, -1, m_TransLayerRand, 0, 0, 1, 2, 0);
425 // displace pixel EC layer 2 in x
426 else if(m_misaligncase == 2)
427 m_survey_IDAlignDBTool->dispGroup(1, 2, 2, -1, -1, m_TransLayerRand, 0, 0, 1, 2, 0);
428 }
429
430 int nSCT(0), nPixel(0);
431 std::vector< Amg::Vector3D > localSurveyCoords;
432 Amg::Transform3D SurveyTransRand, SurveyTransRandSect;
433 SurveyTransRand.setIdentity();
434 SurveyTransRandSect.setIdentity();
435
436 unsigned int nSCTMod = 0,nSCTModInMap = 0,nSCTModEC = 0,nSCTModPointsEC = 0;
437 // Get SiDetectorElementCollection from ConditionStore for SCT
439 const InDetDD::SiDetectorElementCollection* sctElements(*sctDetEleHandle);
440 if (not sctDetEleHandle.isValid() or sctElements==nullptr) {
441 ATH_MSG_FATAL(m_SCTDetEleCollKey.fullKey() << " is not available.");
442 return;
443 }
444 for (const InDetDD::SiDetectorElement* element: *sctElements) {
445 const Identifier SCT_ModuleID = element->identify();
446 if(m_sctid->side(SCT_ModuleID) != 0) continue;
447 ++nSCTMod;
448
449 if (m_ModuleMap.find(SCT_ModuleID) == m_ModuleMap.end()) {
450 ++nSCTModInMap;
451 SurveyConstraintModule* newSCT_Module = new SurveyConstraintModule(SCT_ModuleID,false);
452 Amg::Transform3D globaltolocal = element->transform().inverse();
453 newSCT_Module->set_globaltolocal(globaltolocal);
454 m_ModuleMap[SCT_ModuleID] = newSCT_Module;
455 ++nSCT;
456 ATH_MSG_DEBUG("new SCT Module " << nSCT);
457
458
459
460 // Get the nominal local coordinates (which are the same for all wafers, and for survey and current)
461 // add SCT EC SurveyCoords to SurveyConstraintModule
462 if(abs(m_sctid->barrel_ec(SCT_ModuleID)) == 2) getSurveyCoordsSCTEC(//SCT_ModuleID,
463 localSurveyCoords);
464 // add SCT Barrel SurveyCoords to SurveyConstraintModule
465 else if(m_sctid->barrel_ec(SCT_ModuleID) == 0) getSurveyCoordsSCTB(//SCT_ModuleID,
466 localSurveyCoords);
467 // get the survey, current transformations from nominal
468 Amg::Transform3D SurveyTrans = m_survey_IDAlignDBTool->getTrans(SCT_ModuleID,3);
469 Amg::Transform3D CurrentTrans = m_current_IDAlignDBTool->getTrans(SCT_ModuleID,3);
470
471 if(m_gaus){
472 if(abs(m_sctid->barrel_ec(SCT_ModuleID)) == 2){
473 double m1 = m_TransXRandSCTEC*gauss();
474 double m2 = m_TransYRandSCTEC*gauss();
475 double m3 = m_TransZRandSCTEC*gauss();
476 double m4 = m_RotXRandSCTEC*gauss();
477 double m5 = m_RotYRandSCTEC*gauss();
478 double m6 = m_RotZRandSCTEC*gauss();
479 SurveyTransRand = Amg::Translation3D(m1,m2,m3) * Amg::RotationMatrix3D::Identity()
480 * Amg::AngleAxis3D(m6, Amg::Vector3D(0.,0.,1.))
481 * Amg::AngleAxis3D(m5, Amg::Vector3D(0.,1.,0.))
482 * Amg::AngleAxis3D(m4, Amg::Vector3D(1.,0.,0.));
483 if (m_surveywfile!=""){
484 Amg::VectorX Misalign_Vector(6);
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;
486 newSCT_Module->set_DOCA_Vector(Misalign_Vector);
487 }
488 }
489 else if(m_sctid->barrel_ec(SCT_ModuleID) == 0) {
490 double m1 = m_TransXRandSCTB*gauss();
491 double m2 = m_TransYRandSCTB*gauss();
492 double m3 = m_TransZRandSCTB*gauss();
493 double m4 = m_RotXRandSCTB*gauss();
494 double m5 = m_RotYRandSCTB*gauss();
495 double m6 = m_RotZRandSCTB*gauss();
496 SurveyTransRand = Amg::Translation3D(m1,m2,m3) * Amg::RotationMatrix3D::Identity()
497 * Amg::AngleAxis3D(m6, Amg::Vector3D(0.,0.,1.))
498 * Amg::AngleAxis3D(m5, Amg::Vector3D(0.,1.,0.))
499 * Amg::AngleAxis3D(m4, Amg::Vector3D(1.,0.,0.));
500 if (m_surveywfile!=""){
501 Amg::VectorX Misalign_Vector(6);
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;
503 newSCT_Module->set_DOCA_Vector(Misalign_Vector);
504 }
505 }
506 }
507
508 // add constraint points to "SurveyConstraintModule newSCT_Module" in global coords
509 for ( unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
510 Amg::Vector3D temp = localSurveyCoords[iCorn];
511 // Transform the local points into the MUT's (survey and current) local coordinate system
512 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) * localSurveyCoords[iCorn];
513 if(m_TransLayerRand <= 0) m_survey_IDAlignDBTool->setTrans(SCT_ModuleID,3,SurveyTrans*SurveyTransRand);
514 //m_survey_IDAlignDBTool->tweakTrans(SCT_ModuleID,3,SurveyTransRand);
515 Amg::Vector3D currentPoint = CurrentTrans * temp;
516 // Transform the local (survey and current) constraint points into the global coordinate system
517 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint );
518 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint);
519
520 SurveyConstraintPoint newCPoint( globalSurveyPoint, globalCurrentPoint );
521 newSCT_Module->addModuleConstraintPoint(newCPoint);
522 }
523 }
524 }
525
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;
529 // Get SiDetectorElementCollection from ConditionStore for Pixel
531 const InDetDD::SiDetectorElementCollection* pixelElements(*pixelDetEleHandle);
532 if (not pixelDetEleHandle.isValid() or pixelElements==nullptr) {
533 ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
534 return;
535 }
536 for (const InDetDD::SiDetectorElement* element: *pixelElements) {
537 const Identifier Pixel_ModuleID = element->identify();
538 ++nPixMod;
539
540 if (m_ModuleMap.find(Pixel_ModuleID) == m_ModuleMap.end()) {
541 ++nPixModInMap;
542 SurveyConstraintModule* newPixel_Module = new SurveyConstraintModule(Pixel_ModuleID,true);
543 Amg::Transform3D globaltolocal = element->transform().inverse();
544 newPixel_Module->set_globaltolocal(globaltolocal);
545 m_ModuleMap[Pixel_ModuleID] = newPixel_Module;
546 ++nPixel;
547 ATH_MSG_DEBUG("new Pixel Module " << nPixel);
548
549 // add Pixel EC SurveyCoords
550 if(abs(m_pixid->barrel_ec(Pixel_ModuleID)) == 2){
551 ++nPixModEC;
552 // Get the nominal local coordinates (which are the same for all wafers, and for survey and current)
553 getSurveyCoordsPixEC(//Pixel_ModuleID,
554 localSurveyCoords);
555 // get the survey, current transformations from nominal
556 Amg::Transform3D SurveyTrans = m_survey_IDAlignDBTool->getTrans(Pixel_ModuleID,3);
557 Amg::Transform3D CurrentTrans = m_current_IDAlignDBTool->getTrans(Pixel_ModuleID,3);
558
559
560 // ********************************************
561 // Do some tests for first Pixel EC module
562 if(previous_disk == m_pixid->layer_disk(Pixel_ModuleID) && previous_sector == SectorNumber(m_pixid->phi_module(Pixel_ModuleID)))
563 NewSector=false;
564 else NewSector=true;
565 if(previous_disk == m_pixid->layer_disk(Pixel_ModuleID))
566 NewDisk=false;
567 else NewDisk=true;
568 if (NewSector && (!m_gausSect || NewDisk)){
569 CurrentTrans = CurrentTrans * Amg::Translation3D(m_TransX,m_TransY,m_TransZ)
574
575 }
576
577 if (m_gaus){
578 double m1 = m_TransXRand*gauss();
579 double m2 = m_TransYRand*gauss();
580 double m3 = m_TransZRand*gauss();
581 double m4 = m_RotXRand*gauss();
582 double m5 = m_RotYRand*gauss();
583 double m6 = m_RotZRand*gauss();
584 SurveyTransRand = Amg::Translation3D(m1,m2,m3) * Amg::RotationMatrix3D::Identity()
585 * Amg::AngleAxis3D(m6, Amg::Vector3D(0.,0.,1.))
586 * Amg::AngleAxis3D(m5, Amg::Vector3D(0.,1.,0.))
587 * Amg::AngleAxis3D(m4, Amg::Vector3D(1.,0.,0.));
588
589
590 if (m_surveywfile!=""){
591 Amg::VectorX Misalign_Vector(6);
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;
593 newPixel_Module->set_DOCA_Vector(Misalign_Vector);
594 }
595 }
596 if(m_gausSect && NewSector){
597 double m1 = m_TransXRandSect*gauss();
598 double m2 = m_TransYRandSect*gauss();
599 double m3 = m_TransZRandSect*gauss();
600 double m4 = m_RotXRandSect*gauss();
601 double m5 = m_RotYRandSect*gauss();
602 double m6 = m_RotZRandSect*gauss();
603 SurveyTransRandSect = Amg::Translation3D(m1,m2,m3) * Amg::RotationMatrix3D::Identity()
604 * Amg::AngleAxis3D(m6, Amg::Vector3D(0.,0.,1.))
605 * Amg::AngleAxis3D(m5, Amg::Vector3D(0.,1.,0.))
606 * Amg::AngleAxis3D(m4, Amg::Vector3D(1.,0.,0.));
607
608 }
609 // ********************************************
610
611
612 // add constraint points to "SurveyConstraintModule newPixel_Module" in global coords
613 for ( unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
614 ++nPixModPointsEC;
615 Amg::Vector3D temp = localSurveyCoords[iCorn];
616 // Transform the local points into the MUT's (survey and current) local coordinate system
617 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) * localSurveyCoords[iCorn];
618 if(m_TransLayerRand <= 0) m_survey_IDAlignDBTool->setTrans(Pixel_ModuleID,3,SurveyTrans*SurveyTransRand);
619 //m_survey_IDAlignDBTool->tweakTrans(Pixel_ModuleID,3,SurveyTransRand);
620 Amg::Vector3D currentPoint = CurrentTrans *temp;
621 //Amg::Vector3D currentPoint = temp.transform(CurrentTrans);
622 // Transform the local (survey and current) constraint points into the global coordinate system
623 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint);
624 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint );
625
626
627
628 // transform globalCurrentPoint according to Sector Transformation SurveyTransRandSect
629 //TransformSector(Pixel_ModuleID,newPixel_Module,globalCurrentPoint,SurveyTransRandSect);
630
631 SurveyConstraintPoint newCPoint( globalSurveyPoint, globalCurrentPoint );
632 newPixel_Module->addModuleConstraintPoint(newCPoint);
633
634 // ********************************************
635 // Do some tests for first Pixel EC module
636 if (first){
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());
648 first = false;
649 }
650 // ********************************************
651
652 }
653 previous_disk = m_pixid->layer_disk(Pixel_ModuleID);
654 previous_sector = SectorNumber(m_pixid->phi_module(Pixel_ModuleID));
655 }
656
657 // add Pixel Barrel SurveyCoords to SurveyConstraintModule
658 if(m_pixid->barrel_ec(Pixel_ModuleID) == 0){
659 // Get the nominal local coordinates (which are the same for all wafers, and for survey and current)
660 getSurveyCoordsPixB(//Pixel_ModuleID,
661 localSurveyCoords);
662 // get the survey, current transformations from nominal
663 Amg::Transform3D SurveyTrans = m_survey_IDAlignDBTool->getTrans(Pixel_ModuleID,3);
664 Amg::Transform3D CurrentTrans = m_current_IDAlignDBTool->getTrans(Pixel_ModuleID,3);
665
666 if(m_gaus){
667 double m1 = m_TransXRandPixB*gauss();
668 double m2 = m_TransYRandPixB*gauss();
669 double m3 = m_TransZRandPixB*gauss();
670 double m4 = m_RotXRandPixB*gauss();
671 double m5 = m_RotYRandPixB*gauss();
672 double m6 = m_RotZRandPixB*gauss();
673 SurveyTransRand = Amg::Translation3D(m1,m2,m3) * Amg::RotationMatrix3D::Identity()
674 * Amg::AngleAxis3D(m6, Amg::Vector3D(0.,0.,1.))
675 * Amg::AngleAxis3D(m5, Amg::Vector3D(0.,1.,0.))
676 * Amg::AngleAxis3D(m4, Amg::Vector3D(1.,0.,0.));
677
678 if (m_surveywfile!=""){
679 Amg::VectorX Misalign_Vector(6);
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;
681 newPixel_Module->set_DOCA_Vector(Misalign_Vector);
682 }
683 }
684
685 // add constraint points to "SurveyConstraintModule newPixel_Module" in global coords
686 for ( unsigned int iCorn(0); iCorn < localSurveyCoords.size(); ++iCorn ) {
687 Amg::Vector3D temp = localSurveyCoords[iCorn];
688 // Transform the local points into the MUT's (survey and current) local coordinate system
689 Amg::Vector3D surveyPoint = (SurveyTrans*SurveyTransRand) *localSurveyCoords[iCorn] ;
690 if(m_TransLayerRand <= 0) m_survey_IDAlignDBTool->setTrans(Pixel_ModuleID,3,SurveyTrans*SurveyTransRand);
691 //m_survey_IDAlignDBTool->tweakTrans(Pixel_ModuleID,3,SurveyTransRand);
692 Amg::Vector3D currentPoint = CurrentTrans *temp;
693 // Transform the local (survey and current) constraint points into the global coordinate system
694 Amg::VectorX globalSurveyPoint = element->globalPosition( surveyPoint );
695 Amg::VectorX globalCurrentPoint = element->globalPosition( currentPoint );
696
697 SurveyConstraintPoint newCPoint( globalSurveyPoint, globalCurrentPoint );
698 newPixel_Module->addModuleConstraintPoint(newCPoint);
699 }
700 }
701 }
702 }
703 ATH_MSG_INFO( "nSCTMod " << nSCTMod
704 << ", nSCTModInMap " << nSCTModInMap
705 << ", nSCTModEC " << nSCTModEC
706 << ", nSCTModPointsEC " << nSCTModPointsEC
707 << ", nPixMod " << nPixMod
708 << ", nPixModInMap " << nPixModInMap
709 << ", nPixModEC " << nPixModEC
710 << ", nPixModPointsEC " << nPixModPointsEC);
711
712
713
714
715 // find the set of modules (=stave=modules used to constrain the MUT) associated with this module ID
716 // add the SurveyCoords from this Stave to the MUT (SurveyConstraintModule newPixel_Module),
717 // exclude the points which lie actually on the MUT, to get an unbiased alignment of the two Staves (survey and current)
718 std::vector< SurveyConstraintPoint > Stavepoints;
719 // Pix EC
720 unsigned int nPixModEC2 = 0,nPixModPixModEC = 0,nPixModECPixModEC = 0,nSameLayer = 0,nNotIdentical = 0;
721 for (PixelID::const_id_iterator wafer_it=m_pixid->wafer_begin(); wafer_it!=m_pixid->wafer_end(); ++wafer_it) {
722 const Identifier Pixel_ModuleID = *wafer_it;
723 if(abs(m_pixid->barrel_ec(Pixel_ModuleID)) == 2){
724 ++nPixModEC2;
725 for (PixelID::const_id_iterator wafer_it2=m_pixid->wafer_begin(); wafer_it!=m_pixid->wafer_end(); ++wafer_it) {
726 ++nPixModPixModEC;
727 const Identifier Pixel_ModuleID2 = *wafer_it2;
728 if(m_pixid->barrel_ec(Pixel_ModuleID2) == m_pixid->barrel_ec(Pixel_ModuleID)){
729 ++nPixModECPixModEC;
730 if(m_pixid->layer_disk(Pixel_ModuleID2) == m_pixid->layer_disk(Pixel_ModuleID)){
731 ++nSameLayer;
732 // require Pixel_ModuleID2 and Pixel_ModuleID from same sector OR
733 // m_FullDisk=true which means use all modules from one disk
734 if(m_FullDisk || SectorNumber(m_pixid->phi_module(Pixel_ModuleID2)) == SectorNumber(m_pixid->phi_module(Pixel_ModuleID))){
735 //if(SectorNumber(m_pixid->phi_module(Pixel_ModuleID2)) == SectorNumber(m_pixid->phi_module(Pixel_ModuleID))){
736 if(Pixel_ModuleID != Pixel_ModuleID2){
737 ++nNotIdentical;
738 (m_ModuleMap[Pixel_ModuleID2])->getPoints(Stavepoints,SurveyConstraintModule::Module);
739 (m_ModuleMap[Pixel_ModuleID])->addStaveConstraintPoint(Stavepoints);
740
741 // ********************************************
742 // Do some tests for first Pixel EC module
743 if (firstB){
744 std::vector< SurveyConstraintPoint > Testpoints;
745 m_ModuleMap[Pixel_ModuleID]->getPoints(Testpoints,SurveyConstraintModule::Stave);
746 ATH_MSG_INFO("SurveyConstraint().setup_SurveyConstraintModules: Stavepoints.size() (from map) " << Testpoints.size());
747 firstB = false;
748 }
749 // ********************************************
750
751 }
752 }
753 }
754 }
755 }
756 }
757 }
758 ATH_MSG_INFO("Loop 2, filling stave-points, nPixModEC2 " << nPixModEC2
759 << ", nPixModPixModEC " << nPixModPixModEC
760 << ", nPixModECPixModEC " << nPixModECPixModEC
761 << ", nSameLayer " << nSameLayer
762 << ", nNotIdentical " << nNotIdentical);
763
764 // Pix B
765 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
766 for (PixelID::const_id_iterator wafer_it=m_pixid->wafer_begin(); wafer_it!=m_pixid->wafer_end(); ++wafer_it) {
767 const Identifier Pixel_ModuleID = *wafer_it;
768 if(m_pixid->barrel_ec(Pixel_ModuleID) != 0) continue;
769 ++nPixModEC2;
770 for (PixelID::const_id_iterator wafer_it2=m_pixid->wafer_begin(); wafer_it!=m_pixid->wafer_end(); ++wafer_it) {
771 ++nPixModPixModEC;
772 const Identifier Pixel_ModuleID2 = *wafer_it2;
773 if(m_pixid->barrel_ec(Pixel_ModuleID2) != m_pixid->barrel_ec(Pixel_ModuleID))continue;
774 ++nPixModECPixModEC;
775 if(m_pixid->layer_disk(Pixel_ModuleID2) != m_pixid->layer_disk(Pixel_ModuleID))continue;
776 ++nSameLayer;
777 // require Pixel_ModuleID2 and Pixel_ModuleID from same stave:
778 if(m_pixid->phi_module(Pixel_ModuleID2) != m_pixid->phi_module(Pixel_ModuleID))continue;
779 if(Pixel_ModuleID == Pixel_ModuleID2)continue;
780 ++nNotIdentical;
781 (m_ModuleMap[Pixel_ModuleID2])->getPoints(Stavepoints,SurveyConstraintModule::Module);
782 (m_ModuleMap[Pixel_ModuleID])->addStaveConstraintPoint(Stavepoints);
783 }
784 }
785 ATH_MSG_INFO("Loop 2, filling stave-points, nPixModB2 " << nPixModEC2
786 << ", nPixModPixModB " << nPixModPixModEC
787 << ", nPixModBPixModB " << nPixModECPixModEC
788 << ", nSameLayer " << nSameLayer
789 << ", nNotIdentical " << nNotIdentical);
790
791 // SCT EC
792 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
793 for (SCT_ID::const_id_iterator wafer_it=m_sctid->wafer_begin(); wafer_it!=m_sctid->wafer_end(); ++wafer_it) {
794 const Identifier SCT_ModuleID = *wafer_it;
795 if(m_sctid->side(SCT_ModuleID) != 0) continue;
796 if(abs(m_sctid->barrel_ec(SCT_ModuleID)) != 2) continue;
797 ++nPixModEC2;
798 for (SCT_ID::const_id_iterator wafer_it2=m_sctid->wafer_begin(); wafer_it2!=m_sctid->wafer_end(); ++wafer_it2) {
799 ++nPixModPixModEC;
800 const Identifier SCT_ModuleID2 = *wafer_it2;
801 if(m_sctid->side(SCT_ModuleID2) != 0)continue;
802 if(m_sctid->barrel_ec(SCT_ModuleID2) != m_sctid->barrel_ec(SCT_ModuleID))continue;
803 ++nPixModECPixModEC;
804 if(m_sctid->layer_disk(SCT_ModuleID2) != m_sctid->layer_disk(SCT_ModuleID))continue;
805 ++nSameLayer;
806 //if(m_sctid->eta_module(SCT_ModuleID2) != m_sctid->eta_module(SCT_ModuleID))continue;
807 //if(SectorNumber(m_sctid->phi_module(SCT_ModuleID2)) != SectorNumber(m_sctid->phi_module(SCT_ModuleID)))continue;
808 if(SCT_ModuleID == SCT_ModuleID2)continue;
809 ++nNotIdentical;
810 (m_ModuleMap[SCT_ModuleID2])->getPoints(Stavepoints,SurveyConstraintModule::Module);
811 (m_ModuleMap[SCT_ModuleID])->addStaveConstraintPoint(Stavepoints);
812 }
813
814 // ********************************************
815 // Do some tests for SCT EC module
816 if (m_sctid->barrel_ec(SCT_ModuleID)==2 &&
817 m_sctid->layer_disk(SCT_ModuleID)==0 &&
818 m_sctid->eta_module(SCT_ModuleID)==0 &&
819 m_sctid->side(SCT_ModuleID) == 0 &&
820 SectorNumber(m_sctid->phi_module(SCT_ModuleID)) == 0
821 ){
822 std::vector< SurveyConstraintPoint > Testpoints;
823 m_ModuleMap[SCT_ModuleID]->getPoints(Testpoints,SurveyConstraintModule::Stave);
824 ATH_MSG_INFO("SurveyConstraint().setup_SurveyConstraintModules: Stavepoints.size() (from map) " << Testpoints.size());
825 }
826 // ********************************************
827
828
829 }
830 ATH_MSG_INFO("Loop 2, filling stave-points, nSCTModEC2 " << nPixModEC2
831 << ", nSCTModSCTModEC " << nPixModPixModEC
832 << ", nSCTModECSCTModEC " << nPixModECPixModEC
833 << ", nSameLayer " << nSameLayer
834 << ", nNotIdentical " << nNotIdentical);
835
836 // SCT B
837 nPixModEC2 = 0;nPixModPixModEC = 0;nPixModECPixModEC = 0;nSameLayer = 0;nNotIdentical = 0;
838 for (SCT_ID::const_id_iterator wafer_it=m_sctid->wafer_begin(); wafer_it!=m_sctid->wafer_end(); ++wafer_it) {
839 const Identifier SCT_ModuleID = *wafer_it;
840 if(m_sctid->side(SCT_ModuleID) != 0) continue;
841 if(m_sctid->barrel_ec(SCT_ModuleID) != 0) continue;
842 ++nPixModEC2;
843 for (SCT_ID::const_id_iterator wafer_it2=m_sctid->wafer_begin(); wafer_it2!=m_sctid->wafer_end(); ++wafer_it2) {
844 ++nPixModPixModEC;
845 const Identifier SCT_ModuleID2 = *wafer_it2;
846 if(m_sctid->side(SCT_ModuleID2) != 0)continue;
847 if(m_sctid->barrel_ec(SCT_ModuleID2) != m_sctid->barrel_ec(SCT_ModuleID))continue;
848 ++nPixModECPixModEC;
849 if(m_sctid->layer_disk(SCT_ModuleID2) != m_sctid->layer_disk(SCT_ModuleID))continue;
850 ++nSameLayer;
851 // require SCT_ModuleID2 and SCT_ModuleID from same stave:
852 if(m_sctid->phi_module(SCT_ModuleID2) != m_sctid->phi_module(SCT_ModuleID))continue;
853 if(SCT_ModuleID == SCT_ModuleID2)continue;
854 ++nNotIdentical;
855 (m_ModuleMap[SCT_ModuleID2])->getPoints(Stavepoints,SurveyConstraintModule::Module);
856 (m_ModuleMap[SCT_ModuleID])->addStaveConstraintPoint(Stavepoints);
857 }
858 }
859 ATH_MSG_INFO("Loop 2, filling stave-points, nSCTModB2 " << nPixModEC2
860 << ", nSCTModSCTModB " << nPixModPixModEC
861 << ", nSCTModBSCTModB " << nPixModECPixModEC
862 << ", nSameLayer " << nSameLayer
863 << ", nNotIdentical " << nNotIdentical);
864
865 // write out to Condstream1 and write out ntuple or textfile
866 if (m_surveywfile!=""){
867 if(m_ntuple) m_survey_IDAlignDBTool->writeFile(true,m_surveywfile);
868 else m_survey_IDAlignDBTool->writeFile(false,m_surveywfile);
869 if (StatusCode::SUCCESS!=m_survey_IDAlignDBTool->outputObjs())
870 ATH_MSG_ERROR("Write of AlignableTransforms fails");
871 }
872}
873
874//dumb implementation of weight calculation for PixEC
875//for now which doesn't care about wafer id
876int SurveyConstraint::getWeightPixEC(//const Identifier& ModuleID,
877 Amg::MatrixX& weight) {
878
879 AmgSymMatrix(6) covar;
880 // in local coords, set errors to be diagonal, with values provided by Gil and Ron
881 covar(0,0) = m_TransXRand*m_TransXRand;
882 covar(1,1) = m_TransYRand*m_TransYRand;
883 covar(2,2) = m_TransZRand*m_TransZRand;
884 covar(3,3) = m_RotXRand*m_RotXRand;
885 covar(4,4) = m_RotYRand*m_RotYRand;
886 covar(5,5) = m_RotZRand*m_RotZRand;
887 // invert
888 weight = covar.inverse();
889 return 0;
890}
891
892//dumb implementation of weight calculation for PixB
893//for now which doesn't care about wafer id
894int SurveyConstraint::getWeightPixB(//const Identifier& ModuleID,
895 Amg::MatrixX& weight) {
896
897 AmgSymMatrix(6) covar;
898 // in local coords, set errors to be diagonal, with values to be provided by Vadim
902 covar(3,3) = m_RotXRandPixB*m_RotXRandPixB;
903 covar(4,4) = m_RotYRandPixB*m_RotYRandPixB;
904 covar(5,5) = m_RotZRandPixB*m_RotZRandPixB;
905 // invert
906 weight = covar.inverse();
907 return 0;
908}
909
910//dumb implementation of weight calculation for SCTEC
911//for now which doesn't care about wafer id
912int SurveyConstraint::getWeightSCTEC(//const Identifier& ModuleID,
913 Amg::MatrixX& weight) {
914
915 AmgSymMatrix(6) covar;
916 // in local coords, set errors to be diagonal, with values to be provided by Steve Snow
920 covar(3,3) = m_RotXRandSCTEC*m_RotXRandSCTEC;
921 covar(4,4) = m_RotYRandSCTEC*m_RotYRandSCTEC;
922 covar(5,5) = m_RotZRandSCTEC*m_RotZRandSCTEC;
923 // invert
924 weight = covar.inverse();
925 return 0;
926}
927
928//dumb implementation of weight calculation for SCTB
929//for now which doesn't care about wafer id
930int SurveyConstraint::getWeightSCTB(//const Identifier& ModuleID,
931 Amg::MatrixX& weight) {
932
933 AmgSymMatrix(6) covar;
934
935 // in local coords, set errors to be diagonal, with values to be provided by Stephen Gibson
939 covar(3,3) = m_RotXRandSCTB*m_RotXRandSCTB;
940 covar(4,4) = m_RotYRandSCTB*m_RotYRandSCTB;
941 covar(5,5) = m_RotZRandSCTB*m_RotZRandSCTB;
942 // invert
943 weight = covar.inverse();
944 return 0;
945}
946
947//stupid implementation of Pixel EC survey coordinates
948void SurveyConstraint::getSurveyCoordsPixEC(//const Identifier& ModuleID,
949 std::vector< Amg::Vector3D > & coords) {
950 coords.clear();
951 const double SurveyTargetX = 17.8/2.0;
952 const double SurveyTargetY = 59.8/2.0;
953 // 4 points
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);
958}
959
960//stupid implementation of Pixel barrel survey coordinates
961void SurveyConstraint::getSurveyCoordsPixB(//const Identifier& ModuleID,
962 std::vector< Amg::Vector3D > & coords) {
963 coords.clear();
964 const double SurveyTargetX = 17.8/2.0;
965 const double SurveyTargetY = 59.8/2.0;
966 // 4 points
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);
971}
972
973//stupid implementation of SCT EC survey coordinates
974void SurveyConstraint::getSurveyCoordsSCTEC(//const Identifier& ModuleID,
975 std::vector< Amg::Vector3D > & coords) {
976 coords.clear();
977 const double SurveyTargetX = 63.6/2.0;
978 const double SurveyTargetY = 128.2/2.0;
979 // 4 points
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);
984}
985
986//stupid implementation of SCT barrel survey coordinates
987void SurveyConstraint::getSurveyCoordsSCTB(//const Identifier& ModuleID,
988 std::vector< Amg::Vector3D > & coords) {
989 coords.clear();
990 const double SurveyTargetX = 63.6/2.0;
991 const double SurveyTargetY = 128.2/2.0;
992 // 4 points
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);
997}
998
999
1001 std::vector<SurveyConstraintPoint>& points) {
1002 // get global to wut's local transformation
1003 Amg::Transform3D globaltolocal = mut->get_globaltolocal();
1004 // Transform the points into the wut's coordinate system
1005 for(unsigned ipoint=0;ipoint<points.size();ipoint++){
1006 Amg::Vector3D& survey = points[ipoint].survey();
1007 Amg::Vector3D& current = points[ipoint].current();
1008 survey =globaltolocal *survey;
1009 current=globaltolocal * current;
1010 }
1011}
1012
1013
1016 Amg::Vector3D& current,
1017 Amg::Transform3D SurveyTransRandSect) {
1018 // get rotation angle phi (in global coordinates) to go from module to sector
1019 // coordinate frame
1020 double phi = PhiModuleToSector(m_pixid->phi_module(Pixel_ModuleID));
1021 // transform current point from module to sector coordinate frame
1022 current = Amg::AngleAxis3D(phi, Amg::Vector3D(0.,0.,1.)) * current;
1023 // get global to module's (which is now sector's) local transformation
1024 Amg::Transform3D globaltolocal = mut->get_globaltolocal();
1025 // Transform the points into the sector's local coordinate system
1026 current = globaltolocal * current;
1027 // do the actual sector transformation
1028 current = SurveyTransRandSect * current ;
1029 // go back to global
1030 Amg::Transform3D localtoglobal = globaltolocal.inverse();
1031 current = localtoglobal * current ;
1032 // transform current point back from sector to module coordinate frame
1033 current = Amg::AngleAxis3D(-phi, Amg::Vector3D(0.,0.,1.)) * current ;
1034}
1035
1036
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;
1046 return -1;
1047}
1048
1049
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;
1058 else return -1;
1059}
1060
1061 //__________________________________________________________________________
1063
#define M_PI
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
#define AmgSymMatrix(dim)
#define AmgVector(rows)
Interface to an output stream tool.
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
#define deg
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
std::vector< Identifier >::const_iterator const_id_iterator
Definition PixelID.h:72
std::vector< Identifier >::const_iterator const_id_iterator
Definition SCT_ID.h:73
double findMinimum(const std::vector< SurveyConstraintPoint > &points, Amg::Vector3D &aRotat, Amg::Vector3D &translate)
void addModuleConstraintPoint(const SurveyConstraintPoint &cPoint)
void set_DOCA_Vector(Amg::VectorX &DOCA_Vector)
void getPoints(std::vector< SurveyConstraintPoint > &, ModuleStatus mstat) const
Amg::Transform3D get_globaltolocal()
void set_globaltolocal(Amg::Transform3D &globaltolocal)
bool m_FullDisk
use Full Disk
double m_RotZRandSect
rand Rotation in Z of current PixEC sectors
virtual StatusCode computeConstraint(const Identifier &ModuleID, Amg::VectorX &dparams, double &deltachisq, Amg::VectorX &dchisqdparams, Amg::MatrixX &d2chisqdpdp) override
double m_RotYRand
Weight & rand Rotation in Y of current PixEC modules.
IInDetAlignDBTool * m_survey_IDAlignDBTool
virtual void TransformSector(Identifier Pixel_ModuleID, SurveyConstraintModule *mut, Amg::Vector3D &current, Amg::Transform3D CurrentTransRandSect) override
double m_RotZRandSCTEC
Weight & rand Rotation in Z of current SCTEC modules.
double m_TransXRandSCTB
Weight & rand Translation in X of current SCTB modules.
double m_RotZRand
Weight & rand Rotation in Z of current PixEC modules.
IInDetAlignDBTool * m_current_IDAlignDBTool
double m_TransZ
Translation in Z of the first current PixEC module.
double m_RotXRandSCTEC
Weight & rand Rotation in X of current SCTEC modules.
int m_misaligncase
misaligncase
double m_RotYRandPixB
Weight & rand Rotation in Y of current PixB modules.
double m_SurveyWeightPhiX
""
double m_TransX
Translation in X of the first current PixEC module.
virtual StatusCode initialize() override
virtual int getWeightPixEC(Amg::MatrixX &weight) override
double m_TransXRandPixB
Weight & rand Translation in X of current PixB modules.
virtual void GlobalToLocal(SurveyConstraintModule *mut, std::vector< SurveyConstraintPoint > &points) override
double m_TransYRandSect
rand Translation in Y of current PixEC sectors
virtual void getSurveyCoordsSCTB(std::vector< Amg::Vector3D > &coords) override
double m_RotXRandSCTB
Weight & rand Rotation in X of current SCTB modules.
std::string m_aligndbtoolinst
double m_TransLayerRand
rand Translation in X,Y,Z of all Pixel/SCT EC/B layers
double m_scaleZ
scale Z coordinate to match sensitivity
double m_TransYRandPixB
Weight & rand Translation in Y of current PixB modules.
double m_RotXRand
Weight & rand Rotation in X of current PixEC modules.
double m_TransXRandSect
rand Translation in X of current PixEC sectors
virtual void MMap(std::map< Identifier, SurveyConstraintModule *, std::less< Identifier > > &ModuleMap) override
SurveyConstraint(const std::string &type, const std::string &name, const IInterface *parent)
virtual int getWeightPixB(Amg::MatrixX &weight) override
virtual int getWeightSCTEC(Amg::MatrixX &weight) override
virtual void setup_SurveyConstraintModules() override
double m_TransYRandSCTB
Weight & rand Translation in Y of current SCTB modules.
double m_TransZRandSect
rand Translation in Z of current PixEC sectors
double m_RotXRandPixB
Weight & rand Rotation in X of current PixB modules.
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
const SCT_ID * m_sctid
double m_TransZRand
Weight & rand Translation in Z of current PixEC modules.
std::string m_surveywfile
virtual void getSurveyCoordsPixEC(std::vector< Amg::Vector3D > &coords) override
double m_RotZRandPixB
Weight & rand Rotation in Z of current PixB modules.
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
virtual int getWeightSCTB(Amg::MatrixX &weight) override
double m_TransYRandSCTEC
Weight & rand Translation in Y of current SCTEC modules.
std::string m_surveyrfile
double m_TransYRand
Weight & rand Translation in Y of current PixEC modules.
double m_RotYRandSCTEC
Weight & rand Rotation in Y of current SCTEC modules.
double m_TransZRandSCTB
Weight & rand Translation in Z of current SCTB modules.
std::map< Identifier, SurveyConstraintModule *, std::less< Identifier > > m_ModuleMap
Map of Wafer objects.
bool m_gausSect
use random (Gaus) rotations and translations for sectors
double m_RotZRandSCTB
Weight & rand Rotation in Z of current SCTB modules.
const AtlasDetectorID * m_idHelper
virtual double PhiModuleToSector(int phi_module) override
double m_SurveyWeightPhiZ
""
double m_SurveyWeightPhiY
""
double m_RotX2
Rotation in X (after Y & Z) of the first current PixEC module.
std::string m_surveydbtoolinst
double m_SurveyWeightX
Multiplicative weight, representing systematic unc.
virtual StatusCode finalize() override
virtual int SectorNumber(int phi_module) override
double m_RotZ
Rotation in Z of the first current PixEC module.
double m_TransXRand
Weight & rand Translation in X of current PixEC modules.
virtual void getSurveyCoordsPixB(std::vector< Amg::Vector3D > &coords) override
const PixelID * m_pixid
double m_TransZRandSCTEC
Weight & rand Translation in Z of current SCTEC modules.
double m_RotY
Rotation in Y of the first current PixEC module.
double m_RotYRandSCTB
Weight & rand Rotation in Y of current SCTB modules.
double m_RotYRandSect
rand Rotation in Y of current PixEC sectors
double m_TransY
Translation in Y of the first current PixEC module.
bool m_gaus
use random (Gaus) rotations and translations
virtual void getSurveyCoordsSCTEC(std::vector< Amg::Vector3D > &coords) override
double m_RotX
Rotation in X of the first current PixEC module.
double m_TransXRandSCTEC
Weight & rand Translation in X of current SCTEC modules.
double m_proximity
Proximity of Survey points used for alignment of SOW.
double m_RotXRandSect
rand Rotation in X of current PixEC sectors
double m_TransZRandPixB
Weight & rand Translation in Z of current PixB modules.
Eigen::AngleAxisd AngleAxis3D
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.