5 #include "CLHEP/Vector/RotationInterfaces.h"
41 #include "CLHEP/Vector/ThreeVector.h"
56 : cpvTokenDDD_(esConsumes()),
57 cpvTokenDD4Hep_(esConsumes()),
58 topoToken_(esConsumes()),
59 geomDetToken_(esConsumes()),
60 ptpToken_(esConsumes()),
61 pixQualityToken_(esConsumes()),
62 stripQualityToken_(esConsumes()),
63 referenceTracker(nullptr),
64 dummyTracker(nullptr),
65 currentTracker(nullptr),
67 theSurveyValues(nullptr),
68 theSurveyErrors(nullptr),
70 fromDD4hep_(
cfg.getUntrackedParameter<
bool>(
"fromDD4hep")),
71 writeToDB_(
cfg.getUntrackedParameter<
bool>(
"writeToDB")),
72 commonTrackerLevel_(
align::invalid),
73 moduleListFile_(nullptr),
75 inputRootFile1_(nullptr),
76 inputRootFile2_(nullptr),
77 inputTree01_(nullptr),
78 inputTree02_(nullptr),
79 inputTree11_(nullptr),
80 inputTree12_(nullptr),
109 while (!
fin.eof() &&
fin.good()) {
119 std::ifstream inFile;
122 while (!inFile.eof()) {
126 inFile.ignore(256,
'\n');
176 for (std::vector<TrackerMap>::iterator it =
m_vtkmap_.begin(); it !=
m_vtkmap_.end(); ++it) {
185 for (
int ii = 0;
ii < 13; ++
ii) {
186 std::stringstream histname0;
187 histname0 <<
"SurfDeform_Par_" <<
ii;
188 m_h1_[histname0.str()] = subDir_All.
make<TH1D>(
191 std::stringstream histname1;
192 histname1 <<
"SurfDeform_PixelBarrel_Par_" <<
ii;
193 m_h1_[histname1.str()] = subDir_PXB.
make<TH1D>(
196 std::stringstream histname2;
197 histname2 <<
"SurfDeform_PixelEndcap_Par_" <<
ii;
198 m_h1_[histname2.str()] = subDir_PXF.
make<TH1D>(
207 for (std::vector<TrackerMap>::iterator it =
m_vtkmap_.begin(); it !=
m_vtkmap_.end(); ++it) {
208 std::stringstream mapname;
209 mapname <<
"TkMap_SurfDeform" << iname <<
".png";
210 it->save(
true, 0, 0, mapname.str());
213 mapname <<
"TkMap_SurfDeform" << iname <<
".pdf";
214 it->save(
true, 0, 0, mapname.str());
261 throw cms::Exception(
"NotAvailable") <<
"PoolDBOutputService not available";
265 &(*myAlignmentErrorsExtended), poolDbService->
beginOfTime(),
"TrackerAlignmentErrorExtendedRcd");
273 int inputRawId1, inputRawId2;
274 double inputX1, inputY1, inputZ1, inputX2, inputY2, inputZ2;
275 double inputAlpha1, inputBeta1, inputGamma1, inputAlpha2, inputBeta2, inputGamma2;
289 edm::LogInfo(
"TrackerGeometryCompare") <<
"Error: Module list not found! Please verify that given list exists!";
308 for (
int i = 0;
i < nEntries1; ++
i) {
310 CLHEP::Hep3Vector translation1(inputX1, inputY1, inputZ1);
311 CLHEP::HepEulerAngles eulerangles1(inputAlpha1, inputBeta1, inputGamma1);
312 uint32_t detid1 = inputRawId1;
314 alignments1->
m_align.push_back(transform1);
317 CLHEP::HepSymMatrix clhepSymMatrix(3, 0);
319 alignmentErrors1->
m_alignError.push_back(transformError);
323 std::sort(alignments1->
m_align.begin(), alignments1->
m_align.end());
342 for (
int i = 0;
i < nEntries2; ++
i) {
344 CLHEP::Hep3Vector translation2(inputX2, inputY2, inputZ2);
345 CLHEP::HepEulerAngles eulerangles2(inputAlpha2, inputBeta2, inputGamma2);
346 uint32_t detid2 = inputRawId2;
348 alignments2->
m_align.push_back(transform2);
351 CLHEP::HepSymMatrix clhepSymMatrix(3, 0);
353 alignmentErrors2->
m_alignError.push_back(transformError);
357 std::sort(alignments2->
m_align.begin(), alignments2->
m_align.end());
377 &(*theRefTracker), &(*alignments1), &(*alignmentErrors1),
AlignTransform());
384 int inputDtype1, inputDtype2;
385 std::vector<double> inputDpar1;
386 std::vector<double> inputDpar2;
387 std::vector<double>* p_inputDpar1 = &inputDpar1;
388 std::vector<double>* p_inputDpar2 = &inputDpar2;
400 edm::LogInfo(
"TrackerGeometryCompare") <<
" nentries11 = " << nEntries11;
401 for (
unsigned int iEntry = 0; iEntry < nEntries11; ++iEntry) {
406 if (
int(comp1[iEntry]->
id()) == inputRawid1) {
407 comp1[iEntry]->setSurfaceDeformation(surfDef1,
true);
417 &(*theCurTracker), &(*alignments2), &(*alignmentErrors2),
AlignTransform());
431 edm::LogInfo(
"TrackerGeometryCompare") <<
" nentries12 = " << nEntries12;
432 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
437 if (
int(comp2[iEntry]->
id()) == inputRawid2) {
438 comp2[iEntry]->setSurfaceDeformation(surfDef2,
true);
444 delete alignmentErrors1;
446 delete alignmentErrors2;
453 int inputSubdetid1, inputSubdetid2;
454 int inputDtype1, inputDtype2;
455 std::vector<double> inputDpar1;
456 std::vector<double> inputDpar2;
457 std::vector<double>* p_inputDpar1 = &inputDpar1;
458 std::vector<double>* p_inputDpar2 = &inputDpar2;
461 refTree->SetBranchAddress(
"irawid", &inputRawid1);
462 refTree->SetBranchAddress(
"subdetid", &inputSubdetid1);
463 refTree->SetBranchAddress(
"dtype", &inputDtype1);
464 refTree->SetBranchAddress(
"dpar", &p_inputDpar1);
467 curTree->SetBranchAddress(
"irawid", &inputRawid2);
468 curTree->SetBranchAddress(
"subdetid", &inputSubdetid2);
469 curTree->SetBranchAddress(
"dtype", &inputDtype2);
470 curTree->SetBranchAddress(
"dpar", &p_inputDpar2);
472 unsigned int nEntries11 = refTree->GetEntries();
473 unsigned int nEntries12 = curTree->GetEntries();
475 if (nEntries11 != nEntries12) {
476 edm::LogError(
"TrackerGeometryCompare") <<
" Surface deformation parameters in two geometries differ!\n";
480 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
481 refTree->GetEntry(iEntry);
482 curTree->GetEntry(iEntry);
483 for (
int ii = 0;
ii < 13; ++
ii) {
486 for (
int npar = 0; npar <
int(inputDpar2.size()); ++npar) {
487 if (inputRawid1 == inputRawid2) {
488 surfDeform_[npar] = inputDpar2.at(npar) - inputDpar1.at(npar);
489 std::stringstream histname0;
490 histname0 <<
"SurfDeform_Par_" << npar;
493 if (inputSubdetid1 == 1 && inputSubdetid2 == 1) {
494 std::stringstream histname1;
495 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
499 if (inputSubdetid1 == 2 && inputSubdetid2 == 2) {
500 std::stringstream histname2;
501 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
514 std::vector<double> inputDpar2;
515 std::vector<double>* p_inputDpar2 = &inputDpar2;
518 curTree->SetBranchAddress(
"irawid", &inputRawid2);
519 curTree->SetBranchAddress(
"subdetid", &inputSubdetid2);
520 curTree->SetBranchAddress(
"dtype", &inputDtype2);
521 curTree->SetBranchAddress(
"dpar", &p_inputDpar2);
523 unsigned int nEntries12 = curTree->GetEntries();
525 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
526 curTree->GetEntry(iEntry);
527 for (
int ii = 0;
ii < 12; ++
ii) {
530 for (
int npar = 0; npar <
int(inputDpar2.size()); ++npar) {
532 std::stringstream histname0;
533 histname0 <<
"SurfDeform_Par_" << npar;
536 if (inputSubdetid2 == 1) {
537 std::stringstream histname1;
538 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
542 if (inputSubdetid2 == 2) {
543 std::stringstream histname2;
544 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
556 std::vector<double> inputDpar1;
557 std::vector<double>* p_inputDpar1 = &inputDpar1;
560 refTree->SetBranchAddress(
"irawid", &inputRawid1);
561 refTree->SetBranchAddress(
"subdetid", &inputSubdetid1);
562 refTree->SetBranchAddress(
"dtype", &inputDtype1);
563 refTree->SetBranchAddress(
"dpar", &p_inputDpar1);
565 unsigned int nEntries11 = refTree->GetEntries();
567 for (
unsigned int iEntry = 0; iEntry < nEntries11; ++iEntry) {
568 refTree->GetEntry(iEntry);
569 for (
int ii = 0;
ii < 12; ++
ii) {
572 for (
int npar = 0; npar <
int(inputDpar1.size()); ++npar) {
574 std::stringstream histname0;
575 histname0 <<
"SurfDeform_Par_" << npar;
578 if (inputSubdetid1 == 1) {
579 std::stringstream histname1;
580 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
584 if (inputSubdetid1 == 2) {
585 std::stringstream histname2;
586 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
595 edm::LogInfo(
"TrackerGeometryCompare") <<
">>>> Comparing IDEAL with IDEAL: nothing to do! <<<<\n";
605 using namespace align;
610 unsigned int nComp = refComp.size();
612 bool useLevel =
false;
625 CLHEP::Hep3Vector Rtotal, Wtotal, lRtotal, lWtotal;
626 Rtotal.set(0., 0., 0.);
627 Wtotal.set(0., 0., 0.);
628 lRtotal.set(0., 0., 0.);
629 lWtotal.set(0., 0., 0.);
631 bool converged =
false;
635 for (
int i = 0;
i < 100;
i++) {
646 CLHEP::Hep3Vector dRLocal(-
diff[6], -
diff[7], -
diff[8]);
654 CLHEP::HepRotation
rot(Wtotal.unit(), Wtotal.mag());
655 CLHEP::HepRotation drot(dW.unit(), dW.mag());
657 Wtotal.set(
rot.axis().x() *
rot.delta(),
rot.axis().y() *
rot.delta(),
rot.axis().z() *
rot.delta());
659 CLHEP::HepRotation rotLocal(lWtotal.unit(), lWtotal.mag());
660 CLHEP::HepRotation drotLocal(dWLocal.unit(), dWLocal.mag());
661 rotLocal *= drotLocal;
662 lWtotal.set(rotLocal.axis().x() * rotLocal.delta(),
663 rotLocal.axis().y() * rotLocal.delta(),
664 rotLocal.axis().z() * rotLocal.delta());
686 throw cms::Exception(
"Tolerance in TrackerGeometryCompare exceeded");
691 TRtot(1) = Rtotal.x();
692 TRtot(2) = Rtotal.y();
693 TRtot(3) = Rtotal.z();
694 TRtot(4) = Wtotal.x();
695 TRtot(5) = Wtotal.y();
696 TRtot(6) = Wtotal.z();
698 TRtot(7) = lRtotal.x();
699 TRtot(8) = lRtotal.y();
700 TRtot(9) = lRtotal.z();
701 TRtot(10) = lWtotal.x();
702 TRtot(11) = lWtotal.y();
703 TRtot(12) = lWtotal.z();
705 fillTree(refAli, TRtot, tTopo, iSetup);
709 for (
unsigned int i = 0;
i < nComp; ++
i)
714 edm::LogInfo(
"TrackerGeometryCompare") <<
"Setting Common Tracker System....";
729 edm::LogInfo(
"TrackerGeometryCompare") <<
"what we get from overlaying the pixels..." << theR <<
", " <<
rot;
745 TrackerCommonTR(1) = theRprime.x();
746 TrackerCommonTR(2) = theRprime.y();
747 TrackerCommonTR(3) = theRprime.z();
752 edm::LogInfo(
"TrackerGeometryCompare") <<
"and after the transformation: " << TrackerCommonTR;
761 unsigned int nComp = refComp.size();
763 bool useLevel =
false;
769 CLHEP::Hep3Vector Rtotal, Wtotal;
770 Rtotal.set(0., 0., 0.);
771 Wtotal.set(0., 0., 0.);
777 CLHEP::HepRotation
rot(Wtotal.unit(), Wtotal.mag());
778 CLHEP::HepRotation drot(dW.unit(), dW.mag());
780 Wtotal.set(
rot.axis().x() *
rot.delta(),
rot.axis().y() *
rot.delta(),
rot.axis().z() *
rot.delta());
787 for (
unsigned int i = 0;
i < nComp; ++
i)
916 std::copy(detPB.begin(), detPB.end(), std::back_inserter(allGeomDets));
917 std::copy(detPEC.begin(), detPEC.end(), std::back_inserter(allGeomDets));
918 std::copy(detTIB.begin(), detTIB.end(), std::back_inserter(allGeomDets));
919 std::copy(detTID.begin(), detTID.end(), std::back_inserter(allGeomDets));
920 std::copy(detTOB.begin(), detTOB.end(), std::back_inserter(allGeomDets));
921 std::copy(detTEC.begin(), detTEC.end(), std::back_inserter(allGeomDets));
924 for (
const auto&
i : allGeomDets) {
925 if (
i->components().size() == 1) {
926 rcdAlis.push_back(
i);
927 }
else if (
i->components().size() > 1) {
928 rcdAlis.push_back(
i);
929 const auto&
comp =
i->components();
930 for (
const auto&
j :
comp)
931 rcdAlis.push_back(
j);
936 for (
const auto&
k : rcdAlis) {
940 CLHEP::Hep3Vector clhepVector(
pos.x(),
pos.y(),
pos.z());
941 CLHEP::HepRotation clhepRotation(
957 unsigned int nComp =
comp.size();
959 for (
unsigned int i = 0;
i < nComp; ++
i)
965 throw cms::Exception(
"DatabaseError") <<
"Error reading survey info from DB. Mismatched id!";
987 for (
int i = 0;
i < nEntries;
i++) {
996 switch (subdetlevel) {
1052 edm::LogInfo(
"TrackerGeometryCompare") <<
"Error: bad subdetid!!";