5 #include "CLHEP/Vector/RotationInterfaces.h"
45 #include "CLHEP/Vector/ThreeVector.h"
61 : referenceTracker(nullptr),
62 dummyTracker(nullptr),
63 currentTracker(nullptr),
65 theSurveyValues(nullptr),
66 theSurveyErrors(nullptr),
67 _levelStrings(
cfg.getUntrackedParameter<
std::vector<
std::
string> >(
"levels")),
68 _writeToDB(
cfg.getUntrackedParameter<
bool>(
"writeToDB")),
69 _commonTrackerLevel(
align::invalid),
70 _moduleListFile(nullptr),
72 _inputRootFile1(nullptr),
73 _inputRootFile2(nullptr),
74 _inputTree01(nullptr),
75 _inputTree02(nullptr),
76 _inputTree11(nullptr),
77 _inputTree12(nullptr),
106 while (!
fin.eof() &&
fin.good()) {
116 std::ifstream inFile;
119 while (!inFile.eof()) {
123 inFile.ignore(256,
'\n');
173 for (std::vector<TrackerMap>::iterator it =
m_vtkmap.begin(); it !=
m_vtkmap.end(); ++it) {
182 for (
int ii = 0;
ii < 13; ++
ii) {
183 std::stringstream histname0;
184 histname0 <<
"SurfDeform_Par_" <<
ii;
185 m_h1[histname0.str()] =
188 std::stringstream histname1;
189 histname1 <<
"SurfDeform_PixelBarrel_Par_" <<
ii;
190 m_h1[histname1.str()] =
193 std::stringstream histname2;
194 histname2 <<
"SurfDeform_PixelEndcap_Par_" <<
ii;
195 m_h1[histname2.str()] =
204 for (std::vector<TrackerMap>::iterator it =
m_vtkmap.begin(); it !=
m_vtkmap.end(); ++it) {
205 std::stringstream mapname;
206 mapname <<
"TkMap_SurfDeform" << iname <<
".png";
207 it->save(
true, 0, 0, mapname.str());
210 mapname <<
"TkMap_SurfDeform" << iname <<
".pdf";
211 it->save(
true, 0, 0, mapname.str());
260 throw cms::Exception(
"NotAvailable") <<
"PoolDBOutputService not available";
264 &(*myAlignmentErrorsExtended), poolDbService->
beginOfTime(),
"TrackerAlignmentErrorExtendedRcd");
272 int inputRawId1, inputRawId2;
273 double inputX1, inputY1, inputZ1, inputX2, inputY2, inputZ2;
274 double inputAlpha1, inputBeta1, inputGamma1, inputAlpha2, inputBeta2, inputGamma2;
290 edm::LogInfo(
"TrackerGeometryCompare") <<
"Error: Module list not found! Please verify that given list exists!";
309 for (
int i = 0;
i < nEntries1; ++
i) {
311 CLHEP::Hep3Vector translation1(inputX1, inputY1, inputZ1);
312 CLHEP::HepEulerAngles eulerangles1(inputAlpha1, inputBeta1, inputGamma1);
313 uint32_t detid1 = inputRawId1;
315 alignments1->
m_align.push_back(transform1);
318 CLHEP::HepSymMatrix clhepSymMatrix(3, 0);
320 alignmentErrors1->
m_alignError.push_back(transformError);
324 std::sort(alignments1->
m_align.begin(), alignments1->
m_align.end());
343 for (
int i = 0;
i < nEntries2; ++
i) {
345 CLHEP::Hep3Vector translation2(inputX2, inputY2, inputZ2);
346 CLHEP::HepEulerAngles eulerangles2(inputAlpha2, inputBeta2, inputGamma2);
347 uint32_t detid2 = inputRawId2;
349 alignments2->
m_align.push_back(transform2);
352 CLHEP::HepSymMatrix clhepSymMatrix(3, 0);
354 alignmentErrors2->
m_alignError.push_back(transformError);
358 std::sort(alignments2->
m_align.begin(), alignments2->
m_align.end());
376 &(*theRefTracker), &(*alignments1), &(*alignmentErrors1),
AlignTransform());
383 int inputDtype1, inputDtype2;
384 std::vector<double> inputDpar1;
385 std::vector<double> inputDpar2;
386 std::vector<double>* p_inputDpar1 = &inputDpar1;
387 std::vector<double>* p_inputDpar2 = &inputDpar2;
399 edm::LogInfo(
"TrackerGeometryCompare") <<
" nentries11 = " << nEntries11;
400 for (
unsigned int iEntry = 0; iEntry < nEntries11; ++iEntry) {
405 if (
int(comp1[iEntry]->
id()) == inputRawid1) {
406 comp1[iEntry]->setSurfaceDeformation(surfDef1,
true);
416 &(*theCurTracker), &(*alignments2), &(*alignmentErrors2),
AlignTransform());
430 edm::LogInfo(
"TrackerGeometryCompare") <<
" nentries12 = " << nEntries12;
431 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
436 if (
int(comp2[iEntry]->
id()) == inputRawid2) {
437 comp2[iEntry]->setSurfaceDeformation(surfDef2,
true);
443 delete alignmentErrors1;
445 delete alignmentErrors2;
452 int inputSubdetid1, inputSubdetid2;
453 int inputDtype1, inputDtype2;
454 std::vector<double> inputDpar1;
455 std::vector<double> inputDpar2;
456 std::vector<double>* p_inputDpar1 = &inputDpar1;
457 std::vector<double>* p_inputDpar2 = &inputDpar2;
460 refTree->SetBranchAddress(
"irawid", &inputRawid1);
461 refTree->SetBranchAddress(
"subdetid", &inputSubdetid1);
462 refTree->SetBranchAddress(
"dtype", &inputDtype1);
463 refTree->SetBranchAddress(
"dpar", &p_inputDpar1);
466 curTree->SetBranchAddress(
"irawid", &inputRawid2);
467 curTree->SetBranchAddress(
"subdetid", &inputSubdetid2);
468 curTree->SetBranchAddress(
"dtype", &inputDtype2);
469 curTree->SetBranchAddress(
"dpar", &p_inputDpar2);
471 unsigned int nEntries11 = refTree->GetEntries();
472 unsigned int nEntries12 = curTree->GetEntries();
474 if (nEntries11 != nEntries12) {
475 edm::LogError(
"TrackerGeometryCompare") <<
" Surface deformation parameters in two geometries differ!\n";
479 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
480 refTree->GetEntry(iEntry);
481 curTree->GetEntry(iEntry);
482 for (
int ii = 0;
ii < 13; ++
ii) {
485 for (
int npar = 0; npar <
int(inputDpar2.size()); ++npar) {
486 if (inputRawid1 == inputRawid2) {
487 _surfDeform[npar] = inputDpar2.at(npar) - inputDpar1.at(npar);
488 std::stringstream histname0;
489 histname0 <<
"SurfDeform_Par_" << npar;
492 if (inputSubdetid1 == 1 && inputSubdetid2 == 1) {
493 std::stringstream histname1;
494 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
498 if (inputSubdetid1 == 2 && inputSubdetid2 == 2) {
499 std::stringstream histname2;
500 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
513 std::vector<double> inputDpar2;
514 std::vector<double>* p_inputDpar2 = &inputDpar2;
517 curTree->SetBranchAddress(
"irawid", &inputRawid2);
518 curTree->SetBranchAddress(
"subdetid", &inputSubdetid2);
519 curTree->SetBranchAddress(
"dtype", &inputDtype2);
520 curTree->SetBranchAddress(
"dpar", &p_inputDpar2);
522 unsigned int nEntries12 = curTree->GetEntries();
524 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
525 curTree->GetEntry(iEntry);
526 for (
int ii = 0;
ii < 12; ++
ii) {
529 for (
int npar = 0; npar <
int(inputDpar2.size()); ++npar) {
531 std::stringstream histname0;
532 histname0 <<
"SurfDeform_Par_" << npar;
535 if (inputSubdetid2 == 1) {
536 std::stringstream histname1;
537 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
541 if (inputSubdetid2 == 2) {
542 std::stringstream histname2;
543 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
555 std::vector<double> inputDpar1;
556 std::vector<double>* p_inputDpar1 = &inputDpar1;
559 refTree->SetBranchAddress(
"irawid", &inputRawid1);
560 refTree->SetBranchAddress(
"subdetid", &inputSubdetid1);
561 refTree->SetBranchAddress(
"dtype", &inputDtype1);
562 refTree->SetBranchAddress(
"dpar", &p_inputDpar1);
564 unsigned int nEntries11 = refTree->GetEntries();
566 for (
unsigned int iEntry = 0; iEntry < nEntries11; ++iEntry) {
567 refTree->GetEntry(iEntry);
568 for (
int ii = 0;
ii < 12; ++
ii) {
571 for (
int npar = 0; npar <
int(inputDpar1.size()); ++npar) {
573 std::stringstream histname0;
574 histname0 <<
"SurfDeform_Par_" << npar;
577 if (inputSubdetid1 == 1) {
578 std::stringstream histname1;
579 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
583 if (inputSubdetid1 == 2) {
584 std::stringstream histname2;
585 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
594 edm::LogInfo(
"TrackerGeometryCompare") <<
">>>> Comparing IDEAL with IDEAL: nothing to do! <<<<\n";
604 using namespace align;
609 unsigned int nComp = refComp.size();
611 bool useLevel =
false;
624 CLHEP::Hep3Vector Rtotal, Wtotal, lRtotal, lWtotal;
625 Rtotal.set(0., 0., 0.);
626 Wtotal.set(0., 0., 0.);
627 lRtotal.set(0., 0., 0.);
628 lWtotal.set(0., 0., 0.);
630 bool converged =
false;
634 for (
int i = 0;
i < 100;
i++) {
645 CLHEP::Hep3Vector dRLocal(-
diff[6], -
diff[7], -
diff[8]);
653 CLHEP::HepRotation
rot(Wtotal.unit(), Wtotal.mag());
654 CLHEP::HepRotation drot(dW.unit(), dW.mag());
656 Wtotal.set(
rot.axis().x() *
rot.delta(),
rot.axis().y() *
rot.delta(),
rot.axis().z() *
rot.delta());
658 CLHEP::HepRotation rotLocal(lWtotal.unit(), lWtotal.mag());
659 CLHEP::HepRotation drotLocal(dWLocal.unit(), dWLocal.mag());
660 rotLocal *= drotLocal;
661 lWtotal.set(rotLocal.axis().x() * rotLocal.delta(),
662 rotLocal.axis().y() * rotLocal.delta(),
663 rotLocal.axis().z() * rotLocal.delta());
685 throw cms::Exception(
"Tolerance in TrackerGeometryCompare exceeded");
690 TRtot(1) = Rtotal.x();
691 TRtot(2) = Rtotal.y();
692 TRtot(3) = Rtotal.z();
693 TRtot(4) = Wtotal.x();
694 TRtot(5) = Wtotal.y();
695 TRtot(6) = Wtotal.z();
697 TRtot(7) = lRtotal.x();
698 TRtot(8) = lRtotal.y();
699 TRtot(9) = lRtotal.z();
700 TRtot(10) = lWtotal.x();
701 TRtot(11) = lWtotal.y();
702 TRtot(12) = lWtotal.z();
704 fillTree(refAli, TRtot, tTopo, iSetup);
708 for (
unsigned int i = 0;
i < nComp; ++
i)
713 edm::LogInfo(
"TrackerGeometryCompare") <<
"Setting Common Tracker System....";
728 edm::LogInfo(
"TrackerGeometryCompare") <<
"what we get from overlaying the pixels..." << theR <<
", " <<
rot;
744 TrackerCommonTR(1) = theRprime.x();
745 TrackerCommonTR(2) = theRprime.y();
746 TrackerCommonTR(3) = theRprime.z();
751 edm::LogInfo(
"TrackerGeometryCompare") <<
"and after the transformation: " << TrackerCommonTR;
760 unsigned int nComp = refComp.size();
762 bool useLevel =
false;
768 CLHEP::Hep3Vector Rtotal, Wtotal;
769 Rtotal.set(0., 0., 0.);
770 Wtotal.set(0., 0., 0.);
776 CLHEP::HepRotation
rot(Wtotal.unit(), Wtotal.mag());
777 CLHEP::HepRotation drot(dW.unit(), dW.mag());
779 Wtotal.set(
rot.axis().x() *
rot.delta(),
rot.axis().y() *
rot.delta(),
rot.axis().z() *
rot.delta());
808 for (
unsigned int i = 0;
i < nComp; ++
i)
939 std::copy(detPB.begin(), detPB.end(), std::back_inserter(allGeomDets));
940 std::copy(detPEC.begin(), detPEC.end(), std::back_inserter(allGeomDets));
941 std::copy(detTIB.begin(), detTIB.end(), std::back_inserter(allGeomDets));
942 std::copy(detTID.begin(), detTID.end(), std::back_inserter(allGeomDets));
943 std::copy(detTOB.begin(), detTOB.end(), std::back_inserter(allGeomDets));
944 std::copy(detTEC.begin(), detTEC.end(), std::back_inserter(allGeomDets));
947 for (
const auto&
i : allGeomDets) {
948 if (
i->components().size() == 1) {
949 rcdAlis.push_back(
i);
950 }
else if (
i->components().size() > 1) {
951 rcdAlis.push_back(
i);
952 const auto&
comp =
i->components();
953 for (
const auto&
j :
comp)
954 rcdAlis.push_back(
j);
959 for (
const auto&
k : rcdAlis) {
963 CLHEP::Hep3Vector clhepVector(
pos.x(),
pos.y(),
pos.z());
964 CLHEP::HepRotation clhepRotation(
980 unsigned int nComp =
comp.size();
982 for (
unsigned int i = 0;
i < nComp; ++
i)
988 throw cms::Exception(
"DatabaseError") <<
"Error reading survey info from DB. Mismatched id!";
1010 for (
int i = 0;
i < nEntries;
i++) {
1019 switch (subdetlevel) {
1075 edm::LogInfo(
"TrackerGeometryCompare") <<
"Error: bad subdetid!!";