5 #include "CLHEP/Vector/RotationInterfaces.h"
41 #include "CLHEP/Vector/ThreeVector.h"
64 referenceTracker(nullptr),
65 dummyTracker(nullptr),
66 currentTracker(nullptr),
68 theSurveyValues(nullptr),
69 theSurveyErrors(nullptr),
71 fromDD4hep_(
cfg.getUntrackedParameter<
bool>(
"fromDD4hep")),
72 writeToDB_(
cfg.getUntrackedParameter<
bool>(
"writeToDB")),
73 commonTrackerLevel_(
align::invalid),
74 moduleListFile_(nullptr),
76 inputRootFile1_(nullptr),
77 inputRootFile2_(nullptr),
78 inputTree01_(nullptr),
79 inputTree02_(nullptr),
80 inputTree11_(nullptr),
81 inputTree12_(nullptr),
110 while (!
fin.eof() &&
fin.good()) {
120 std::ifstream inFile;
123 while (!inFile.eof()) {
127 inFile.ignore(256,
'\n');
177 for (std::vector<TrackerMap>::iterator it =
m_vtkmap_.begin(); it !=
m_vtkmap_.end(); ++it) {
186 for (
int ii = 0;
ii < 13; ++
ii) {
187 std::stringstream histname0;
188 histname0 <<
"SurfDeform_Par_" <<
ii;
189 m_h1_[histname0.str()] = subDir_All.
make<TH1D>(
192 std::stringstream histname1;
193 histname1 <<
"SurfDeform_PixelBarrel_Par_" <<
ii;
194 m_h1_[histname1.str()] = subDir_PXB.
make<TH1D>(
197 std::stringstream histname2;
198 histname2 <<
"SurfDeform_PixelEndcap_Par_" <<
ii;
199 m_h1_[histname2.str()] = subDir_PXF.
make<TH1D>(
208 for (std::vector<TrackerMap>::iterator it =
m_vtkmap_.begin(); it !=
m_vtkmap_.end(); ++it) {
209 std::stringstream mapname;
210 mapname <<
"TkMap_SurfDeform" << iname <<
".png";
211 it->save(
true, 0, 0, mapname.str());
214 mapname <<
"TkMap_SurfDeform" << iname <<
".pdf";
215 it->save(
true, 0, 0, mapname.str());
262 throw cms::Exception(
"NotAvailable") <<
"PoolDBOutputService not available";
266 &(*myAlignmentErrorsExtended), poolDbService->
beginOfTime(),
"TrackerAlignmentErrorExtendedRcd");
274 int inputRawId1, inputRawId2;
275 double inputX1, inputY1, inputZ1, inputX2, inputY2, inputZ2;
276 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);
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);
379 &(*theRefTracker), &(*alignments1), &(*alignmentErrors1),
AlignTransform());
386 int inputDtype1, inputDtype2;
387 std::vector<double> inputDpar1;
388 std::vector<double> inputDpar2;
389 std::vector<double>* p_inputDpar1 = &inputDpar1;
390 std::vector<double>* p_inputDpar2 = &inputDpar2;
402 edm::LogInfo(
"TrackerGeometryCompare") <<
" nentries11 = " << nEntries11;
403 for (
unsigned int iEntry = 0; iEntry < nEntries11; ++iEntry) {
408 if (
int(comp1[iEntry]->
id()) == inputRawid1) {
409 comp1[iEntry]->setSurfaceDeformation(surfDef1,
true);
419 &(*theCurTracker), &(*alignments2), &(*alignmentErrors2),
AlignTransform());
433 edm::LogInfo(
"TrackerGeometryCompare") <<
" nentries12 = " << nEntries12;
434 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
439 if (
int(comp2[iEntry]->
id()) == inputRawid2) {
440 comp2[iEntry]->setSurfaceDeformation(surfDef2,
true);
446 delete alignmentErrors1;
448 delete alignmentErrors2;
455 int inputSubdetid1, inputSubdetid2;
456 int inputDtype1, inputDtype2;
457 std::vector<double> inputDpar1;
458 std::vector<double> inputDpar2;
459 std::vector<double>* p_inputDpar1 = &inputDpar1;
460 std::vector<double>* p_inputDpar2 = &inputDpar2;
463 refTree->SetBranchAddress(
"irawid", &inputRawid1);
464 refTree->SetBranchAddress(
"subdetid", &inputSubdetid1);
465 refTree->SetBranchAddress(
"dtype", &inputDtype1);
466 refTree->SetBranchAddress(
"dpar", &p_inputDpar1);
469 curTree->SetBranchAddress(
"irawid", &inputRawid2);
470 curTree->SetBranchAddress(
"subdetid", &inputSubdetid2);
471 curTree->SetBranchAddress(
"dtype", &inputDtype2);
472 curTree->SetBranchAddress(
"dpar", &p_inputDpar2);
474 unsigned int nEntries11 = refTree->GetEntries();
475 unsigned int nEntries12 = curTree->GetEntries();
477 if (nEntries11 != nEntries12) {
478 edm::LogError(
"TrackerGeometryCompare") <<
" Surface deformation parameters in two geometries differ!\n";
482 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
483 refTree->GetEntry(iEntry);
484 curTree->GetEntry(iEntry);
485 for (
int ii = 0;
ii < 13; ++
ii) {
488 for (
int npar = 0; npar <
int(inputDpar2.size()); ++npar) {
489 if (inputRawid1 == inputRawid2) {
490 surfDeform_[npar] = inputDpar2.at(npar) - inputDpar1.at(npar);
491 std::stringstream histname0;
492 histname0 <<
"SurfDeform_Par_" << npar;
495 if (inputSubdetid1 == 1 && inputSubdetid2 == 1) {
496 std::stringstream histname1;
497 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
501 if (inputSubdetid1 == 2 && inputSubdetid2 == 2) {
502 std::stringstream histname2;
503 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
516 std::vector<double> inputDpar2;
517 std::vector<double>* p_inputDpar2 = &inputDpar2;
520 curTree->SetBranchAddress(
"irawid", &inputRawid2);
521 curTree->SetBranchAddress(
"subdetid", &inputSubdetid2);
522 curTree->SetBranchAddress(
"dtype", &inputDtype2);
523 curTree->SetBranchAddress(
"dpar", &p_inputDpar2);
525 unsigned int nEntries12 = curTree->GetEntries();
527 for (
unsigned int iEntry = 0; iEntry < nEntries12; ++iEntry) {
528 curTree->GetEntry(iEntry);
529 for (
int ii = 0;
ii < 12; ++
ii) {
532 for (
int npar = 0; npar <
int(inputDpar2.size()); ++npar) {
534 std::stringstream histname0;
535 histname0 <<
"SurfDeform_Par_" << npar;
538 if (inputSubdetid2 == 1) {
539 std::stringstream histname1;
540 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
544 if (inputSubdetid2 == 2) {
545 std::stringstream histname2;
546 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
558 std::vector<double> inputDpar1;
559 std::vector<double>* p_inputDpar1 = &inputDpar1;
562 refTree->SetBranchAddress(
"irawid", &inputRawid1);
563 refTree->SetBranchAddress(
"subdetid", &inputSubdetid1);
564 refTree->SetBranchAddress(
"dtype", &inputDtype1);
565 refTree->SetBranchAddress(
"dpar", &p_inputDpar1);
567 unsigned int nEntries11 = refTree->GetEntries();
569 for (
unsigned int iEntry = 0; iEntry < nEntries11; ++iEntry) {
570 refTree->GetEntry(iEntry);
571 for (
int ii = 0;
ii < 12; ++
ii) {
574 for (
int npar = 0; npar <
int(inputDpar1.size()); ++npar) {
576 std::stringstream histname0;
577 histname0 <<
"SurfDeform_Par_" << npar;
580 if (inputSubdetid1 == 1) {
581 std::stringstream histname1;
582 histname1 <<
"SurfDeform_PixelBarrel_Par_" << npar;
586 if (inputSubdetid1 == 2) {
587 std::stringstream histname2;
588 histname2 <<
"SurfDeform_PixelEndcap_Par_" << npar;
597 edm::LogInfo(
"TrackerGeometryCompare") <<
">>>> Comparing IDEAL with IDEAL: nothing to do! <<<<\n";
607 using namespace align;
612 unsigned int nComp = refComp.size();
614 bool useLevel =
false;
627 CLHEP::Hep3Vector Rtotal, Wtotal, lRtotal, lWtotal;
628 Rtotal.set(0., 0., 0.);
629 Wtotal.set(0., 0., 0.);
630 lRtotal.set(0., 0., 0.);
631 lWtotal.set(0., 0., 0.);
633 bool converged =
false;
637 for (
int i = 0;
i < 100;
i++) {
648 CLHEP::Hep3Vector dRLocal(-
diff[6], -
diff[7], -
diff[8]);
656 CLHEP::HepRotation
rot(Wtotal.unit(), Wtotal.mag());
657 CLHEP::HepRotation drot(dW.unit(), dW.mag());
659 Wtotal.set(
rot.axis().x() *
rot.delta(),
rot.axis().y() *
rot.delta(),
rot.axis().z() *
rot.delta());
661 CLHEP::HepRotation rotLocal(lWtotal.unit(), lWtotal.mag());
662 CLHEP::HepRotation drotLocal(dWLocal.unit(), dWLocal.mag());
663 rotLocal *= drotLocal;
664 lWtotal.set(rotLocal.axis().x() * rotLocal.delta(),
665 rotLocal.axis().y() * rotLocal.delta(),
666 rotLocal.axis().z() * rotLocal.delta());
688 throw cms::Exception(
"Tolerance in TrackerGeometryCompare exceeded");
693 TRtot(1) = Rtotal.x();
694 TRtot(2) = Rtotal.y();
695 TRtot(3) = Rtotal.z();
696 TRtot(4) = Wtotal.x();
697 TRtot(5) = Wtotal.y();
698 TRtot(6) = Wtotal.z();
700 TRtot(7) = lRtotal.x();
701 TRtot(8) = lRtotal.y();
702 TRtot(9) = lRtotal.z();
703 TRtot(10) = lWtotal.x();
704 TRtot(11) = lWtotal.y();
705 TRtot(12) = lWtotal.z();
707 fillTree(refAli, TRtot, tTopo, iSetup);
711 for (
unsigned int i = 0;
i < nComp; ++
i)
716 edm::LogInfo(
"TrackerGeometryCompare") <<
"Setting Common Tracker System....";
731 edm::LogInfo(
"TrackerGeometryCompare") <<
"what we get from overlaying the pixels..." << theR <<
", " <<
rot;
747 TrackerCommonTR(1) = theRprime.x();
748 TrackerCommonTR(2) = theRprime.y();
749 TrackerCommonTR(3) = theRprime.z();
754 edm::LogInfo(
"TrackerGeometryCompare") <<
"and after the transformation: " << TrackerCommonTR;
763 unsigned int nComp = refComp.size();
765 bool useLevel =
false;
771 CLHEP::Hep3Vector Rtotal, Wtotal;
772 Rtotal.set(0., 0., 0.);
773 Wtotal.set(0., 0., 0.);
779 CLHEP::HepRotation
rot(Wtotal.unit(), Wtotal.mag());
780 CLHEP::HepRotation drot(dW.unit(), dW.mag());
782 Wtotal.set(
rot.axis().x() *
rot.delta(),
rot.axis().y() *
rot.delta(),
rot.axis().z() *
rot.delta());
789 for (
unsigned int i = 0;
i < nComp; ++
i)
918 std::copy(detPB.begin(), detPB.end(), std::back_inserter(allGeomDets));
919 std::copy(detPEC.begin(), detPEC.end(), std::back_inserter(allGeomDets));
920 std::copy(detTIB.begin(), detTIB.end(), std::back_inserter(allGeomDets));
921 std::copy(detTID.begin(), detTID.end(), std::back_inserter(allGeomDets));
922 std::copy(detTOB.begin(), detTOB.end(), std::back_inserter(allGeomDets));
923 std::copy(detTEC.begin(), detTEC.end(), std::back_inserter(allGeomDets));
926 for (
const auto&
i : allGeomDets) {
927 if (
i->components().size() == 1) {
928 rcdAlis.push_back(
i);
929 }
else if (
i->components().size() > 1) {
930 rcdAlis.push_back(
i);
931 const auto&
comp =
i->components();
932 for (
const auto&
j :
comp)
933 rcdAlis.push_back(
j);
938 for (
const auto&
k : rcdAlis) {
942 CLHEP::Hep3Vector clhepVector(
pos.x(),
pos.y(),
pos.z());
943 CLHEP::HepRotation clhepRotation(
959 unsigned int nComp =
comp.size();
961 for (
unsigned int i = 0;
i < nComp; ++
i)
967 throw cms::Exception(
"DatabaseError") <<
"Error reading survey info from DB. Mismatched id!";
989 for (
int i = 0;
i < nEntries;
i++) {
998 switch (subdetlevel) {
1054 edm::LogInfo(
"TrackerGeometryCompare") <<
"Error: bad subdetid!!";