21 #include "CLHEP/Vector/RotationInterfaces.h" 33 #include <boost/range/adaptor/indexed.hpp> 49 #include "TPaveStats.h" 64 const std::map<AlignmentPI::coordinate, float> hardcodeGPR = {
72 template <
int ntags, IOVMultiplicity nIOVs,
bool doOnlyPixel>
73 class TrackerAlignmentCompareAll :
public PlotImage<Alignments, nIOVs, ntags> {
75 TrackerAlignmentCompareAll()
76 :
PlotImage<
Alignments, nIOVs, ntags>(
"comparison of all coordinates between two geometries") {}
78 bool fill()
override {
79 TGaxis::SetExponentOffset(-0.12, 0.01,
"y");
82 auto theIOVs = PlotBase::getTag<0>().iovs;
83 auto tagname1 = PlotBase::getTag<0>().
name;
85 auto firstiov = theIOVs.front();
86 std::tuple<cond::Time_t, cond::Hash> lastiov;
89 assert(this->m_plotAnnotations.ntags < 3);
91 if (this->m_plotAnnotations.ntags == 2) {
92 auto tag2iovs = PlotBase::getTag<1>().iovs;
93 tagname2 = PlotBase::getTag<1>().
name;
94 lastiov = tag2iovs.front();
96 lastiov = theIOVs.back();
99 std::shared_ptr<Alignments> last_payload = this->fetchPayload(std::get<1>(lastiov));
100 std::shared_ptr<Alignments> first_payload = this->fetchPayload(std::get<1>(firstiov));
105 std::vector<AlignTransform> ref_ali = first_payload->m_align;
106 std::vector<AlignTransform> target_ali = last_payload->m_align;
110 ref_ali.erase(std::remove_if(ref_ali.begin(),
118 target_ali.erase(std::remove_if(target_ali.begin(),
126 TCanvas
canvas(
"Alignment Comparison",
"Alignment Comparison", 2000, 1200);
129 if (ref_ali.size() != target_ali.size()) {
131 <<
"the size of the reference alignment (" << ref_ali.size()
132 <<
") is different from the one of the target (" << target_ali.size()
133 <<
")! You are probably trying to compare different underlying geometries. Exiting";
140 const char *path_toTopologyXML =
nullptr;
142 path_toTopologyXML =
"Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
145 ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" 146 :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
152 for (
const auto &ali : ref_ali) {
153 auto mydetid = ali.rawId();
156 <<
"Encountered invalid Tracker DetId:" <<
DetId(mydetid).
rawId() <<
" (" <<
DetId(mydetid).
det()
158 <<
"); subdetId " <<
DetId(mydetid).
subdetId() <<
" - terminating ";
170 std::unordered_map<AlignmentPI::coordinate, std::unique_ptr<TH1F> > diffs;
173 for (
const auto &coord : coords) {
178 diffs[coord] = std::make_unique<TH1F>(Form(
"comparison_%s", s_coord.c_str()),
179 Form(
";Detector Id index; #Delta%s %s", s_coord.c_str(),
unit.c_str()),
182 ref_ali.size() - 0.5);
186 std::map<int, AlignmentPI::partitions> boundaries;
190 unsigned int subpad{1};
191 TLegend
legend = TLegend(0.17, 0.84, 0.95, 0.94);
192 legend.SetTextSize(0.023);
193 for (
const auto &coord : coords) {
195 canvas.cd(subpad)->SetTopMargin(0.06);
196 canvas.cd(subpad)->SetLeftMargin(0.17);
197 canvas.cd(subpad)->SetRightMargin(0.05);
198 canvas.cd(subpad)->SetBottomMargin(0.15);
200 auto max = diffs[coord]->GetMaximum();
201 auto min = diffs[coord]->GetMinimum();
207 diffs[coord]->GetYaxis()->SetRangeUser(-
range * 1.5,
range * 1.5);
208 diffs[coord]->GetYaxis()->SetTitleOffset(1.5);
209 diffs[coord]->SetMarkerStyle(20);
210 diffs[coord]->SetMarkerSize(0.5);
211 diffs[coord]->Draw(
"P");
214 if (this->m_plotAnnotations.ntags == 2) {
215 legend.SetHeader(
"#bf{Two Tags Comparison}",
"C");
218 (
"#splitline{" + tagname1 +
" : " + firstIOVsince +
"}{" + tagname2 +
" : " + lastIOVsince +
"}")
222 legend.SetHeader((
"tag: #bf{" + tagname1 +
"}").c_str(),
"C");
223 legend.AddEntry(diffs[coord].
get(),
224 (
"#splitline{IOV since: " + firstIOVsince +
"}{IOV since: " + lastIOVsince +
"}").c_str(),
235 TLine
l[6][boundaries.size()];
237 for (
unsigned int i = 0;
i < 6;
i++) {
238 tSubdet[
i].SetTextColor(kRed);
240 tSubdet[
i].SetTextAlign(21);
241 tSubdet[
i].SetTextSize(doOnlyPixel ? 0.05 : 0.03);
242 tSubdet[
i].SetTextAngle(90);
246 for (
const auto &coord : coords) {
249 for (
const auto &
line : boundaries | boost::adaptors::indexed(0)) {
252 l[subpad][
index] = TLine(diffs[coord]->GetBinLowEdge(
value.first),
253 canvas.cd(subpad + 1)->GetUymin(),
254 diffs[coord]->GetBinLowEdge(
value.first),
255 canvas.cd(subpad + 1)->GetUymax() * 0.84);
256 l[subpad][
index].SetLineWidth(1);
257 l[subpad][
index].SetLineStyle(9);
258 l[subpad][
index].SetLineColor(2);
259 l[subpad][
index].Draw(
"same");
262 for (
const auto &elem : boundaries | boost::adaptors::indexed(0)) {
263 const auto &lm =
canvas.cd(subpad + 1)->GetLeftMargin();
264 const auto &
rm = 1 -
canvas.cd(subpad + 1)->GetRightMargin();
265 const auto &
frac =
float(elem.value().first) / ref_ali.size();
267 LogDebug(
"TrackerAlignmentCompareAll")
268 << __PRETTY_FUNCTION__ <<
" left margin: " << lm <<
" right margin: " <<
rm <<
" fraction: " <<
frac;
270 float theX_ = lm + (
rm - lm) *
frac + ((elem.index() > 0 || doOnlyPixel) ? 0.025 : 0.01);
272 tSubdet[subpad].DrawLatex(
278 ltx.SetTextSize(0.042);
279 ltx.SetTextAlign(11);
280 ltx.DrawLatexNDC(
canvas.cd(subpad + 1)->GetLeftMargin(),
281 1 -
canvas.cd(subpad + 1)->GetTopMargin() + 0.01,
282 (
"Tracker Alignment Compare : #color[4]{" + s_coord +
"}").c_str());
295 typedef TrackerAlignmentCompareAll<1, MULTI_IOV, false> TrackerAlignmentComparatorSingleTag;
296 typedef TrackerAlignmentCompareAll<2, SINGLE_IOV, false> TrackerAlignmentComparatorTwoTags;
298 typedef TrackerAlignmentCompareAll<1, MULTI_IOV, true> PixelAlignmentComparatorSingleTag;
299 typedef TrackerAlignmentCompareAll<2, SINGLE_IOV, true> PixelAlignmentComparatorTwoTags;
306 template <AlignmentPI::coordinate coord,
int ntags, IOVMultiplicity nIOVs>
307 class TrackerAlignmentComparatorBase :
public PlotImage<Alignments, nIOVs, ntags> {
309 TrackerAlignmentComparatorBase()
311 " coordinate between two geometries") {}
313 bool fill()
override {
314 TGaxis::SetExponentOffset(-0.12, 0.01,
"y");
317 auto theIOVs = PlotBase::getTag<0>().iovs;
318 auto tagname1 = PlotBase::getTag<0>().
name;
320 auto firstiov = theIOVs.front();
321 std::tuple<cond::Time_t, cond::Hash> lastiov;
324 assert(this->m_plotAnnotations.ntags < 3);
326 if (this->m_plotAnnotations.ntags == 2) {
327 auto tag2iovs = PlotBase::getTag<1>().iovs;
328 tagname2 = PlotBase::getTag<1>().
name;
329 lastiov = tag2iovs.front();
331 lastiov = theIOVs.back();
334 std::shared_ptr<Alignments> last_payload = this->fetchPayload(std::get<1>(lastiov));
335 std::shared_ptr<Alignments> first_payload = this->fetchPayload(std::get<1>(firstiov));
340 std::vector<AlignTransform> ref_ali = first_payload->m_align;
341 std::vector<AlignTransform> target_ali = last_payload->m_align;
343 TCanvas
canvas(
"Alignment Comparison",
"Alignment Comparison", 1200, 1200);
345 if (ref_ali.size() != target_ali.size()) {
347 <<
"the size of the reference alignment (" << ref_ali.size()
348 <<
") is different from the one of the target (" << target_ali.size()
349 <<
")! You are probably trying to compare different underlying geometries. Exiting";
355 ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" 356 :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
360 for (
const auto &ali : ref_ali) {
361 auto mydetid = ali.rawId();
364 <<
"Encountered invalid Tracker DetId:" <<
DetId(mydetid).
rawId() <<
" (" <<
DetId(mydetid).
det()
366 <<
"); subdetId " <<
DetId(mydetid).
subdetId() <<
" - terminating ";
376 std::unique_ptr<TH1F>
compare =
377 std::make_unique<TH1F>(
"comparison",
378 Form(
";Detector Id index; #Delta%s %s", s_coord.c_str(),
unit.c_str()),
381 ref_ali.size() - 0.5);
384 std::map<int, AlignmentPI::partitions> boundaries;
390 canvas.SetTopMargin(0.06);
391 canvas.SetLeftMargin(0.17);
392 canvas.SetRightMargin(0.05);
393 canvas.SetBottomMargin(0.15);
403 compare->GetYaxis()->SetTitleOffset(1.5);
411 TLine
l[boundaries.size()];
412 for (
const auto &
line : boundaries | boost::adaptors::indexed(0)) {
427 tSubdet.SetTextAlign(21);
428 tSubdet.SetTextSize(0.027);
429 tSubdet.SetTextAngle(90);
431 for (
const auto &elem : boundaries) {
432 tSubdet.SetTextColor(kRed);
434 float theX_ = elem.first != 0 ? myPair.first + 0.025 : myPair.first + 0.01;
439 TLegend
legend = TLegend(0.17, 0.86, 0.95, 0.94);
440 if (this->m_plotAnnotations.ntags == 2) {
441 legend.SetHeader(
"#bf{Two Tags Comparison}",
"C");
444 (
"#splitline{" + tagname1 +
" : " + firstIOVsince +
"}{" + tagname2 +
" : " + lastIOVsince +
"}").c_str(),
447 legend.SetHeader((
"tag: #bf{" + tagname1 +
"}").c_str(),
"C");
449 (
"#splitline{IOV since: " + firstIOVsince +
"}{IOV since: " + lastIOVsince +
"}").c_str(),
452 legend.SetTextSize(0.020);
457 ltx.SetTextSize(0.042);
458 ltx.SetTextAlign(11);
459 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
460 1 - gPad->GetTopMargin() + 0.01,
461 (
"Tracker Alignment Compare :#color[4]{" + s_coord +
"}").c_str());
470 template <AlignmentPI::coordinate coord>
471 using TrackerAlignmentCompare = TrackerAlignmentComparatorBase<coord, 1, MULTI_IOV>;
473 template <AlignmentPI::coordinate coord>
474 using TrackerAlignmentCompareTwoTags = TrackerAlignmentComparatorBase<coord, 2, SINGLE_IOV>;
476 typedef TrackerAlignmentCompare<AlignmentPI::t_x> TrackerAlignmentCompareX;
477 typedef TrackerAlignmentCompare<AlignmentPI::t_y> TrackerAlignmentCompareY;
478 typedef TrackerAlignmentCompare<AlignmentPI::t_z> TrackerAlignmentCompareZ;
480 typedef TrackerAlignmentCompare<AlignmentPI::rot_alpha> TrackerAlignmentCompareAlpha;
481 typedef TrackerAlignmentCompare<AlignmentPI::rot_beta> TrackerAlignmentCompareBeta;
482 typedef TrackerAlignmentCompare<AlignmentPI::rot_gamma> TrackerAlignmentCompareGamma;
484 typedef TrackerAlignmentCompareTwoTags<AlignmentPI::t_x> TrackerAlignmentCompareXTwoTags;
485 typedef TrackerAlignmentCompareTwoTags<AlignmentPI::t_y> TrackerAlignmentCompareYTwoTags;
486 typedef TrackerAlignmentCompareTwoTags<AlignmentPI::t_z> TrackerAlignmentCompareZTwoTags;
488 typedef TrackerAlignmentCompareTwoTags<AlignmentPI::rot_alpha> TrackerAlignmentCompareAlphaTwoTags;
489 typedef TrackerAlignmentCompareTwoTags<AlignmentPI::rot_beta> TrackerAlignmentCompareBetaTwoTags;
490 typedef TrackerAlignmentCompareTwoTags<AlignmentPI::rot_gamma> TrackerAlignmentCompareGammaTwoTags;
496 template <
int ntags, IOVMultiplicity nIOVs, AlignmentPI::partitions q>
497 class TrackerAlignmentSummaryBase :
public PlotImage<Alignments, nIOVs, ntags> {
499 TrackerAlignmentSummaryBase()
500 :
PlotImage<
Alignments, nIOVs, ntags>(
"Comparison of all coordinates between two geometries for " +
503 bool fill()
override {
505 auto theIOVs = PlotBase::getTag<0>().iovs;
506 auto tagname1 = PlotBase::getTag<0>().
name;
508 auto firstiov = theIOVs.front();
509 std::tuple<cond::Time_t, cond::Hash> lastiov;
512 assert(this->m_plotAnnotations.ntags < 3);
514 if (this->m_plotAnnotations.ntags == 2) {
515 auto tag2iovs = PlotBase::getTag<1>().iovs;
516 tagname2 = PlotBase::getTag<1>().
name;
517 lastiov = tag2iovs.front();
519 lastiov = theIOVs.back();
522 std::shared_ptr<Alignments> last_payload = this->fetchPayload(std::get<1>(lastiov));
523 std::shared_ptr<Alignments> first_payload = this->fetchPayload(std::get<1>(firstiov));
528 std::vector<AlignTransform> ref_ali = first_payload->m_align;
529 std::vector<AlignTransform> target_ali = last_payload->m_align;
531 if (ref_ali.size() != target_ali.size()) {
533 <<
"the size of the reference alignment (" << ref_ali.size()
534 <<
") is different from the one of the target (" << target_ali.size()
535 <<
")! You are probably trying to compare different underlying geometries. Exiting";
541 ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" 542 :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
546 for (
const auto &ali : ref_ali) {
547 auto mydetid = ali.rawId();
550 <<
"Encountered invalid Tracker DetId:" <<
DetId(mydetid).
rawId() <<
" (" <<
DetId(mydetid).
det()
552 <<
"); subdetId " <<
DetId(mydetid).
subdetId() <<
" - terminating ";
557 TCanvas
canvas(
"Alignment Comparison",
"Alignment Comparison", 1800, 1200);
560 std::unordered_map<AlignmentPI::coordinate, std::unique_ptr<TH1F> > diffs;
568 for (
const auto &coord : coords) {
573 diffs[coord] = std::make_unique<TH1F>(Form(
"hDiff_%s", s_coord.c_str()),
574 Form(
";#Delta%s %s;n. of modules", s_coord.c_str(),
unit.c_str()),
581 std::map<int, AlignmentPI::partitions> boundaries;
587 auto legend = std::make_unique<TLegend>(0.14, 0.88, 0.96, 0.99);
588 if (this->m_plotAnnotations.ntags == 2) {
589 legend->SetHeader(
"#bf{Two Tags Comparison}",
"C");
592 (
"#splitline{" + tagname1 +
" : " + firstIOVsince +
"}{" + tagname2 +
" : " + lastIOVsince +
"}").c_str(),
595 legend->SetHeader((
"tag: #bf{" + tagname1 +
"}").c_str(),
"C");
597 (
"#splitline{IOV since: " + firstIOVsince +
"}{IOV since: " + lastIOVsince +
"}").c_str(),
600 legend->SetTextSize(0.025);
602 for (
const auto &coord : coords) {
603 canvas.cd(c_index)->SetLogy();
604 canvas.cd(c_index)->SetTopMargin(0.01);
605 canvas.cd(c_index)->SetBottomMargin(0.15);
606 canvas.cd(c_index)->SetLeftMargin(0.14);
607 canvas.cd(c_index)->SetRightMargin(0.04);
608 diffs[coord]->SetLineWidth(2);
616 int i_max = diffs[coord]->FindLastBinAbove(0.);
617 int i_min = diffs[coord]->FindFirstBinAbove(0.);
618 diffs[coord]->GetXaxis()->SetRange(
std::max(1, i_min - 10),
std::min(i_max + 10, diffs[coord]->GetNbinsX()));
619 diffs[coord]->SetMaximum(diffs[coord]->GetMaximum() * 5);
620 diffs[coord]->Draw(
"HIST");
635 typedef TrackerAlignmentSummaryBase<1, MULTI_IOV, AlignmentPI::BPix> TrackerAlignmentSummaryBPix;
636 typedef TrackerAlignmentSummaryBase<1, MULTI_IOV, AlignmentPI::FPix> TrackerAlignmentSummaryFPix;
637 typedef TrackerAlignmentSummaryBase<1, MULTI_IOV, AlignmentPI::TIB> TrackerAlignmentSummaryTIB;
639 typedef TrackerAlignmentSummaryBase<1, MULTI_IOV, AlignmentPI::TID> TrackerAlignmentSummaryTID;
640 typedef TrackerAlignmentSummaryBase<1, MULTI_IOV, AlignmentPI::TOB> TrackerAlignmentSummaryTOB;
641 typedef TrackerAlignmentSummaryBase<1, MULTI_IOV, AlignmentPI::TEC> TrackerAlignmentSummaryTEC;
643 typedef TrackerAlignmentSummaryBase<2, SINGLE_IOV, AlignmentPI::BPix> TrackerAlignmentSummaryBPixTwoTags;
644 typedef TrackerAlignmentSummaryBase<2, SINGLE_IOV, AlignmentPI::FPix> TrackerAlignmentSummaryFPixTwoTags;
645 typedef TrackerAlignmentSummaryBase<2, SINGLE_IOV, AlignmentPI::TIB> TrackerAlignmentSummaryTIBTwoTags;
647 typedef TrackerAlignmentSummaryBase<2, SINGLE_IOV, AlignmentPI::TID> TrackerAlignmentSummaryTIDTwoTags;
648 typedef TrackerAlignmentSummaryBase<2, SINGLE_IOV, AlignmentPI::TOB> TrackerAlignmentSummaryTOBTwoTags;
649 typedef TrackerAlignmentSummaryBase<2, SINGLE_IOV, AlignmentPI::TEC> TrackerAlignmentSummaryTECTwoTags;
654 template <AlignmentPI::coordinate coord,
int ntags, IOVMultiplicity nIOVs>
655 class PixelAlignmentComparisonMapBase :
public PlotImage<Alignments, nIOVs, ntags> {
657 PixelAlignmentComparisonMapBase()
661 payloadString =
"Tracker Alignment";
664 bool fill()
override {
665 gStyle->SetPalette(1);
668 auto theIOVs = PlotBase::getTag<0>().iovs;
669 auto tagname1 = PlotBase::getTag<0>().
name;
671 auto firstiov = theIOVs.front();
672 std::tuple<cond::Time_t, cond::Hash> lastiov;
675 assert(this->m_plotAnnotations.ntags < 3);
677 if (this->m_plotAnnotations.ntags == 2) {
678 auto tag2iovs = PlotBase::getTag<1>().iovs;
679 tagname2 = PlotBase::getTag<1>().
name;
680 lastiov = tag2iovs.front();
682 lastiov = theIOVs.back();
685 std::shared_ptr<Alignments> last_payload = this->fetchPayload(std::get<1>(lastiov));
686 std::shared_ptr<Alignments> first_payload = this->fetchPayload(std::get<1>(firstiov));
691 const std::vector<AlignTransform> &ref_ali = first_payload->m_align;
692 const std::vector<AlignTransform> &target_ali = last_payload->m_align;
694 if (last_payload.get() && first_payload.get()) {
700 fullMap.createTrackerBaseMap();
702 if (this->isPhase0(ref_ali) || this->isPhase0(target_ali)) {
703 edm::LogError(label_) <<
"Pixel Tracker Alignment maps are not supported for non-Phase1 Pixel geometries !";
704 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
712 std::map<uint32_t, double> diffPerDetid;
713 this->fillPerDetIdDiff(coord, ref_ali, target_ali, diffPerDetid);
716 for (
const auto &elem : diffPerDetid) {
722 fullMap.fillTrackerMap(elem.first, elem.second);
728 TCanvas
canvas(
"Canv",
"Canv", 3000, 2000);
729 fullMap.printTrackerMap(
canvas);
733 ltx.SetTextSize(0.025);
734 ltx.SetTextAlign(11);
736 ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
737 gPad->GetBottomMargin() + 0.01,
738 (
"#color[4]{" + tagname1 +
"}, IOV: #color[4]{" + firstIOVsince +
"} vs #color[4]{" +
739 tagname2 +
"}, IOV: #color[4]{" + lastIOVsince +
"}")
754 bool isPhase0(std::vector<AlignTransform> theAlis) {
757 const auto &p0detIds =
reader.getAllDetIds();
759 std::vector<uint32_t> ownDetIds;
764 for (
const auto &det : ownDetIds) {
766 if (
std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
775 const std::vector<AlignTransform> &ref_ali,
776 const std::vector<AlignTransform> &target_ali,
777 std::map<uint32_t, double> &
diff)
780 for (
unsigned int i = 0;
i < ref_ali.size();
i++) {
781 uint32_t detid = ref_ali[
i].rawId();
783 CLHEP::HepRotation target_rot(target_ali[
i].
rotation());
784 CLHEP::HepRotation ref_rot(ref_ali[
i].
rotation());
806 const std::vector<double> deltaRot = {
811 const auto &deltaTrans = target_ali[
i].translation() - ref_ali[
i].translation();
833 edm::LogError(
"TrackerAlignment_PayloadInspector") <<
"Unrecognized coordinate " << myCoord << std::endl;
841 template <AlignmentPI::coordinate coord>
842 using PixelAlignmentCompareMap = PixelAlignmentComparisonMapBase<coord, 1, MULTI_IOV>;
844 template <AlignmentPI::coordinate coord>
845 using PixelAlignmentCompareMapTwoTags = PixelAlignmentComparisonMapBase<coord, 2, SINGLE_IOV>;
847 typedef PixelAlignmentCompareMap<AlignmentPI::t_x> PixelAlignmentCompareMapX;
848 typedef PixelAlignmentCompareMap<AlignmentPI::t_y> PixelAlignmentCompareMapY;
849 typedef PixelAlignmentCompareMap<AlignmentPI::t_z> PixelAlignmentCompareMapZ;
851 typedef PixelAlignmentCompareMap<AlignmentPI::rot_alpha> PixelAlignmentCompareMapAlpha;
852 typedef PixelAlignmentCompareMap<AlignmentPI::rot_beta> PixelAlignmentCompareMapBeta;
853 typedef PixelAlignmentCompareMap<AlignmentPI::rot_gamma> PixelAlignmentCompareMapGamma;
855 typedef PixelAlignmentCompareMapTwoTags<AlignmentPI::t_x> PixelAlignmentCompareMapXTwoTags;
856 typedef PixelAlignmentCompareMapTwoTags<AlignmentPI::t_y> PixelAlignmentCompareMapYTwoTags;
857 typedef PixelAlignmentCompareMapTwoTags<AlignmentPI::t_z> PixelAlignmentCompareMapZTwoTags;
859 typedef PixelAlignmentCompareMapTwoTags<AlignmentPI::rot_alpha> PixelAlignmentCompareMapAlphaTwoTags;
860 typedef PixelAlignmentCompareMapTwoTags<AlignmentPI::rot_beta> PixelAlignmentCompareMapBetaTwoTags;
861 typedef PixelAlignmentCompareMapTwoTags<AlignmentPI::rot_gamma> PixelAlignmentCompareMapGammaTwoTags;
867 template <AlignmentPI::coordinate coord>
868 class BPixBarycenterHistory :
public HistoryPlot<Alignments, float> {
870 BPixBarycenterHistory()
874 ~BPixBarycenterHistory()
override =
default;
877 std::vector<AlignTransform> alignments =
payload.m_align;
879 float barycenter = 0.;
881 for (
const auto &ali : alignments) {
884 <<
"Encountered invalid Tracker DetId:" << ali.rawId() <<
" " <<
DetId(ali.rawId()).det()
889 int subid =
DetId(ali.rawId()).subdetId();
896 barycenter += (ali.translation().x());
899 barycenter += (ali.translation().y());
902 barycenter += (ali.translation().z());
905 edm::LogError(
"TrackerAlignment_PayloadInspector") <<
"Unrecognized coordinate " << coord << std::endl;
910 edm::LogInfo(
"TrackerAlignment_PayloadInspector") <<
"barycenter (" << barycenter <<
")/n. modules (" << nmodules
911 <<
") = " << barycenter / nmodules << std::endl;
914 barycenter /= nmodules;
917 barycenter += hardcodeGPR.at(coord);
924 typedef BPixBarycenterHistory<AlignmentPI::t_x> X_BPixBarycenterHistory;
925 typedef BPixBarycenterHistory<AlignmentPI::t_y> Y_BPixBarycenterHistory;
926 typedef BPixBarycenterHistory<AlignmentPI::t_z> Z_BPixBarycenterHistory;
931 class TrackerAlignmentBarycenters :
public PlotImage<Alignments, SINGLE_IOV> {
935 bool fill()
override {
936 auto tag = PlotBase::getTag<0>();
937 auto iov =
tag.iovs.front();
939 std::shared_ptr<Alignments>
payload = fetchPayload(std::get<1>(iov));
940 unsigned int run = std::get<0>(iov);
942 TCanvas
canvas(
"Tracker Alignment Barycenter Summary",
"Tracker Alignment Barycenter summary", 1600, 1000);
945 canvas.SetTopMargin(0.07);
946 canvas.SetBottomMargin(0.06);
947 canvas.SetLeftMargin(0.15);
948 canvas.SetRightMargin(0.03);
952 auto h2_BarycenterParameters =
953 std::make_unique<TH2F>(
"Parameters",
"SubDetector Barycenter summary", 6, 0.0, 6.0, 6, 0, 6.);
955 auto h2_uncBarycenterParameters =
956 std::make_unique<TH2F>(
"Parameters2",
"SubDetector Barycenter summary", 6, 0.0, 6.0, 6, 0, 6.);
958 h2_BarycenterParameters->SetStats(
false);
959 h2_BarycenterParameters->SetTitle(
nullptr);
960 h2_uncBarycenterParameters->SetStats(
false);
961 h2_uncBarycenterParameters->SetTitle(
nullptr);
963 std::vector<AlignTransform> alignments =
payload->m_align;
968 const char *path_toTopologyXML = isPhase0 ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" 969 :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
979 auto Xbarycenters = barycenters.
getX();
980 auto Ybarycenters = barycenters.
getY();
981 auto Zbarycenters = barycenters.
getZ();
986 auto c_Xbarycenters = barycenters.
getX();
987 auto c_Ybarycenters = barycenters.
getY();
988 auto c_Zbarycenters = barycenters.
getZ();
990 h2_BarycenterParameters->GetXaxis()->SetBinLabel(1,
"X [cm]");
991 h2_BarycenterParameters->GetXaxis()->SetBinLabel(2,
"Y [cm]");
992 h2_BarycenterParameters->GetXaxis()->SetBinLabel(3,
"Z [cm]");
993 h2_BarycenterParameters->GetXaxis()->SetBinLabel(4,
"X_{no GPR} [cm]");
994 h2_BarycenterParameters->GetXaxis()->SetBinLabel(5,
"Y_{no GPR} [cm]");
995 h2_BarycenterParameters->GetXaxis()->SetBinLabel(6,
"Z_{no GPR} [cm]");
997 bool isLikelyMC(
false);
999 std::count_if(Xbarycenters.begin(), Xbarycenters.begin() + 2, [](
float a) {
return (
std::abs(
a) >= 1.e-4); });
1001 std::count_if(Ybarycenters.begin(), Ybarycenters.begin() + 2, [](
float a) {
return (
std::abs(
a) >= 1.e-4); });
1003 std::count_if(Zbarycenters.begin(), Zbarycenters.begin() + 2, [](
float a) {
return (
std::abs(
a) >= 1.e-4); });
1007 if ((checkX + checkY + checkZ) == 0 &&
run == 1)
1010 unsigned int yBin = 6;
1011 for (
unsigned int i = 0;
i < 6;
i++) {
1014 h2_BarycenterParameters->GetYaxis()->SetBinLabel(
yBin, theLabel.c_str());
1016 h2_BarycenterParameters->SetBinContent(1,
yBin, c_Xbarycenters[
i]);
1017 h2_BarycenterParameters->SetBinContent(2,
yBin, c_Ybarycenters[
i]);
1018 h2_BarycenterParameters->SetBinContent(3,
yBin, c_Zbarycenters[
i]);
1021 h2_uncBarycenterParameters->SetBinContent(4,
yBin, Xbarycenters[
i]);
1022 h2_uncBarycenterParameters->SetBinContent(5,
yBin, Ybarycenters[
i]);
1023 h2_uncBarycenterParameters->SetBinContent(6,
yBin, Zbarycenters[
i]);
1027 h2_BarycenterParameters->GetXaxis()->LabelsOption(
"h");
1028 h2_BarycenterParameters->GetYaxis()->SetLabelSize(0.05);
1029 h2_BarycenterParameters->GetXaxis()->SetLabelSize(0.05);
1030 h2_BarycenterParameters->SetMarkerSize(1.5);
1031 h2_BarycenterParameters->Draw(
"TEXT");
1033 h2_uncBarycenterParameters->SetMarkerSize(1.5);
1034 h2_uncBarycenterParameters->SetMarkerColor(kRed);
1035 h2_uncBarycenterParameters->Draw(
"TEXTsame");
1039 t1.SetTextAlign(26);
1040 t1.SetTextSize(0.045);
1041 t1.DrawLatex(0.5, 0.96, Form(
"TkAl Barycenters, Tag: #color[4]{%s}, IOV #color[4]{%i}",
tagname.c_str(),
run));
1042 t1.SetTextSize(0.025);
1057 template <
int ntags, IOVMultiplicity nIOVs>
1058 class TrackerAlignmentBarycentersComparatorBase :
public PlotImage<Alignments, nIOVs, ntags> {
1060 TrackerAlignmentBarycentersComparatorBase()
1063 bool fill()
override {
1065 auto theIOVs = PlotBase::getTag<0>().iovs;
1066 auto tagname1 = PlotBase::getTag<0>().
name;
1068 auto firstiov = theIOVs.front();
1069 std::tuple<cond::Time_t, cond::Hash> lastiov;
1072 assert(this->m_plotAnnotations.ntags < 3);
1074 if (this->m_plotAnnotations.ntags == 2) {
1075 auto tag2iovs = PlotBase::getTag<1>().iovs;
1076 tagname2 = PlotBase::getTag<1>().
name;
1077 lastiov = tag2iovs.front();
1079 lastiov = theIOVs.back();
1082 unsigned int first_run = std::get<0>(firstiov);
1083 unsigned int last_run = std::get<0>(lastiov);
1085 std::shared_ptr<Alignments> last_payload = this->fetchPayload(std::get<1>(lastiov));
1086 std::vector<AlignTransform> last_alignments = last_payload->m_align;
1088 std::shared_ptr<Alignments> first_payload = this->fetchPayload(std::get<1>(firstiov));
1089 std::vector<AlignTransform> first_alignments = first_payload->m_align;
1095 const char *path_toTopologyXML = isInitialPhase0 ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" 1096 :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
1101 path_toTopologyXML = isFinalPhase0 ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" 1102 :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
1107 TCanvas
canvas(
"Tracker Alignment Barycenter Summary",
"Tracker Alignment Barycenter summary", 1200, 800);
1110 canvas.SetTopMargin(0.07);
1111 canvas.SetBottomMargin(0.06);
1112 canvas.SetLeftMargin(0.15);
1113 canvas.SetRightMargin(0.03);
1117 auto h2_BarycenterDiff =
1118 std::make_unique<TH2F>(
"Parameters diff",
"SubDetector Barycenter Difference", 3, 0.0, 3.0, 6, 0, 6.);
1120 h2_BarycenterDiff->SetStats(
false);
1121 h2_BarycenterDiff->SetTitle(
nullptr);
1122 h2_BarycenterDiff->GetXaxis()->SetBinLabel(1,
"X [#mum]");
1123 h2_BarycenterDiff->GetXaxis()->SetBinLabel(2,
"Y [#mum]");
1124 h2_BarycenterDiff->GetXaxis()->SetBinLabel(3,
"Z [#mum]");
1132 unsigned int yBin = 6;
1133 for (
unsigned int i = 0;
i < 6;
i++) {
1136 h2_BarycenterDiff->GetYaxis()->SetBinLabel(
yBin, theLabel.c_str());
1137 h2_BarycenterDiff->SetBinContent(
1139 h2_BarycenterDiff->SetBinContent(
1141 h2_BarycenterDiff->SetBinContent(
1146 h2_BarycenterDiff->GetXaxis()->LabelsOption(
"h");
1147 h2_BarycenterDiff->GetYaxis()->SetLabelSize(0.05);
1148 h2_BarycenterDiff->GetXaxis()->SetLabelSize(0.05);
1149 h2_BarycenterDiff->SetMarkerSize(1.5);
1150 h2_BarycenterDiff->SetMarkerColor(kRed);
1151 h2_BarycenterDiff->Draw(
"TEXT");
1155 t1.SetTextAlign(26);
1156 t1.SetTextSize(0.05);
1157 t1.DrawLatex(0.5, 0.96, Form(
"Tracker Alignment Barycenters Diff, IOV %i - IOV %i",
last_run,
first_run));
1158 t1.SetTextSize(0.025);
1167 bool isInitialPhase0;
1171 using TrackerAlignmentBarycentersCompare = TrackerAlignmentBarycentersComparatorBase<1, MULTI_IOV>;
1172 using TrackerAlignmentBarycentersCompareTwoTags = TrackerAlignmentBarycentersComparatorBase<2, SINGLE_IOV>;
1177 template <
int ntags, IOVMultiplicity nIOVs>
1178 class PixelBarycentersComparatorBase :
public PlotImage<Alignments, nIOVs, ntags> {
1180 PixelBarycentersComparatorBase() :
PlotImage<
Alignments, nIOVs, ntags>(
"Comparison of Pixel Barycenters") {}
1182 bool fill()
override {
1184 auto theIOVs = PlotBase::getTag<0>().iovs;
1185 auto tagname1 = PlotBase::getTag<0>().
name;
1187 auto firstiov = theIOVs.front();
1188 std::tuple<cond::Time_t, cond::Hash> lastiov;
1191 assert(this->m_plotAnnotations.ntags < 3);
1193 if (this->m_plotAnnotations.ntags == 2) {
1194 auto tag2iovs = PlotBase::getTag<1>().iovs;
1195 tagname2 = PlotBase::getTag<1>().
name;
1196 lastiov = tag2iovs.front();
1198 lastiov = theIOVs.back();
1201 unsigned int first_run = std::get<0>(firstiov);
1202 unsigned int last_run = std::get<0>(lastiov);
1204 std::shared_ptr<Alignments> last_payload = this->fetchPayload(std::get<1>(lastiov));
1205 std::vector<AlignTransform> last_alignments = last_payload->m_align;
1207 std::shared_ptr<Alignments> first_payload = this->fetchPayload(std::get<1>(firstiov));
1208 std::vector<AlignTransform> first_alignments = first_payload->m_align;
1210 TCanvas
canvas(
"Pixel Barycenter Summary",
"Pixel Barycenter summary", 1200, 1200);
1216 t1.SetTextAlign(26);
1217 t1.SetTextSize(0.03);
1223 t1.SetTextSize(0.025);
1225 for (
unsigned int c = 1;
c <= 4;
c++) {
1226 canvas.cd(
c)->SetTopMargin(0.07);
1227 canvas.cd(
c)->SetBottomMargin(0.12);
1228 canvas.cd(
c)->SetLeftMargin(0.15);
1229 canvas.cd(
c)->SetRightMargin(0.03);
1234 std::array<std::string, 3> structures = {{
"FPIX-",
"BPIX",
"FPIX+"}};
1235 std::array<std::unique_ptr<TH2F>, 3>
histos;
1241 const char *path_toTopologyXML = isInitialPhase0 ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" 1242 :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
1252 path_toTopologyXML = isFinalPhase0 ?
"Geometry/TrackerCommonData/data/trackerParameters.xml" 1253 :
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
1263 if (isFinalPhase0 != isInitialPhase0) {
1265 <<
"the size of the reference alignment (" << first_alignments.size()
1266 <<
") is different from the one of the target (" << last_alignments.size()
1267 <<
")! You are probably trying to compare different underlying geometries.";
1270 unsigned int index(0);
1271 for (
const auto &piece : structures) {
1272 const char *
name = piece.c_str();
1275 Form(
"%s x-y Barycenter Difference;x_{%s}-x_{TOB} [mm];y_{%s}-y_{TOB} [mm]",
name,
name,
name),
1295 auto h2_ZBarycenterDiff = std::make_unique<TH2F>(
1296 "Pixel_z_diff",
"Pixel z-Barycenter Difference;; z_{Pixel-Ideal} -z_{TOB} [mm]", 3, -0.5, 2.5, 100, -10., 10.);
1297 h2_ZBarycenterDiff->SetStats(
false);
1298 h2_ZBarycenterDiff->SetTitle(
nullptr);
1299 h2_ZBarycenterDiff->GetXaxis()->SetBinLabel(1,
"FPIX -");
1300 h2_ZBarycenterDiff->GetXaxis()->SetBinLabel(2,
"BPIX");
1301 h2_ZBarycenterDiff->GetXaxis()->SetBinLabel(3,
"FPIX +");
1302 h2_ZBarycenterDiff->GetYaxis()->SetLabelSize(0.05);
1303 h2_ZBarycenterDiff->GetXaxis()->SetLabelSize(0.07);
1304 h2_ZBarycenterDiff->GetYaxis()->SetTitleSize(0.06);
1305 h2_ZBarycenterDiff->GetXaxis()->SetTitleSize(0.06);
1306 h2_ZBarycenterDiff->GetYaxis()->CenterTitle();
1307 h2_ZBarycenterDiff->GetXaxis()->CenterTitle();
1308 h2_ZBarycenterDiff->GetYaxis()->SetTitleOffset(1.1);
1310 std::function<GlobalPoint(int)> cutFunctorInitial = [&myInitialBarycenters](
int index) {
1323 std::function<GlobalPoint(int)> cutFunctorFinal = [&myFinalBarycenters](
int index) {
1336 float x0i, x0f, y0i, y0f;
1339 t1.SetTextSize(0.047);
1340 for (
unsigned int c = 1;
c <= 3;
c++) {
1341 x0i = cutFunctorInitial(
c).x() * 10;
1342 x0f = cutFunctorFinal(
c).x() * 10;
1343 y0i = cutFunctorInitial(
c).y() * 10;
1344 y0f = cutFunctorFinal(
c).y() * 10;
1349 COUT <<
"initial x,y " << std::left << std::setw(7) << structures[
c - 1] <<
" (" << x0i <<
"," << y0i <<
") mm" 1351 COUT <<
"final x,y " << std::left << std::setw(7) << structures[
c - 1] <<
" (" << x0f <<
"," << y0f <<
") mm" 1354 TMarker *initial =
new TMarker(x0i, y0i, 21);
1355 TMarker *
final =
new TMarker(x0f, y0f, 20);
1357 initial->SetMarkerColor(kRed);
1358 final->SetMarkerColor(kBlue);
1359 initial->SetMarkerSize(2.5);
1360 final->SetMarkerSize(2.5);
1361 t1.SetTextColor(kRed);
1363 t1.DrawLatex(x0i, y0i + (y0i > y0f ? 0.3 : -0.5), Form(
"(%.2f,%.2f)", x0i, y0i));
1364 final->Draw(
"same");
1365 t1.SetTextColor(kBlue);
1366 t1.DrawLatex(x0f, y0f + (y0i > y0f ? -0.5 : 0.3), Form(
"(%.2f,%.2f)", x0f, y0f));
1371 h2_ZBarycenterDiff->Draw();
1376 std::array<double, 3> hardcodeIdealZPhase0 = {{-41.94909, 0., 41.94909}};
1377 std::array<double, 3> hardcodeIdealZPhase1 = {{-39.82911, 0., 39.82911}};
1379 for (
unsigned int c = 1;
c <= 3;
c++) {
1383 (cutFunctorInitial(
c).z() - (isInitialPhase0 ? hardcodeIdealZPhase0[
c - 1] : hardcodeIdealZPhase1[
c - 1])) *
1386 (cutFunctorFinal(
c).z() - (isFinalPhase0 ? hardcodeIdealZPhase0[
c - 1] : hardcodeIdealZPhase1[
c - 1])) * 10;
1388 TMarker *initial =
new TMarker(
c - 1, z0i, 21);
1389 TMarker *
final =
new TMarker(
c - 1, z0f, 20);
1391 COUT <<
"initial z " << std::left << std::setw(7) << structures[
c - 1] <<
" " << z0i <<
" mm" << std::endl;
1392 COUT <<
"final z " << std::left << std::setw(7) << structures[
c - 1] <<
" " << z0f <<
" mm" << std::endl;
1394 initial->SetMarkerColor(kRed);
1395 final->SetMarkerColor(kBlue);
1396 initial->SetMarkerSize(2.5);
1397 final->SetMarkerSize(2.5);
1399 t1.SetTextColor(kRed);
1400 t1.DrawLatex(
c - 1, z0i + (z0i > z0f ? 1. : -1.5), Form(
"(%.2f)", z0i));
1401 final->Draw(
"same");
1402 t1.SetTextColor(kBlue);
1403 t1.DrawLatex(
c - 1, z0f + (z0i > z0f ? -1.5 : 1), Form(
"(%.2f)", z0f));
1413 bool isInitialPhase0;
1417 using PixelBarycentersCompare = PixelBarycentersComparatorBase<1, MULTI_IOV>;
1418 using PixelBarycentersCompareTwoTags = PixelBarycentersComparatorBase<2, SINGLE_IOV>;
const std::array< double, 6 > getY()
bool tidIsDoubleSide(const DetId &id) const
void makeNicePlotStyle(TH1 *hist, int color)
void computeBarycenters(const std::vector< AlignTransform > &input, const TrackerTopology &tTopo, const std::map< AlignmentPI::coordinate, float > &GPR)
Global3DPoint GlobalPoint
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
constexpr Detector det() const
get the detector field from this detid
static std::string to_string(const XMLCh *ch)
static const float cmToUm
void makeNiceStats(TH1F *hist, AlignmentPI::partitions part, int color)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
const std::array< double, 6 > getX()
static const unsigned int phase0size
static const float tomRad
Abs< T >::type abs(const T &t)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
static const unsigned int phase1size
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Basic3DVector unit() const
Log< level::Info, false > LogInfo
void fillComparisonHistograms(std::map< int, AlignmentPI::partitions > &boundaries, const std::vector< AlignTransform > &ref_ali, const std::vector< AlignTransform > &target_ali, std::unordered_map< AlignmentPI::coordinate, std::unique_ptr< TH1F > > &compare, bool diff=false, AlignmentPI::partitions checkPart=AlignmentPI::INVALID)
GlobalPoint getPartitionAvg(AlignmentPI::PARTITION p)
constexpr uint32_t rawId() const
get the raw id
std::string getStringFromCoordinate(AlignmentPI::coordinate coord)
std::pair< double, double > calculatePosition(TVirtualPad *myPad, int boundary)
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
static constexpr char const *const kPh0DefaultFile
void displayNotSupported(TCanvas &canv, const unsigned int size)
void fillComparisonHistogram(const AlignmentPI::coordinate &coord, std::map< int, AlignmentPI::partitions > &boundaries, const std::vector< AlignTransform > &ref_ali, const std::vector< AlignTransform > &target_ali, std::unique_ptr< TH1F > &compare)
Log< level::Warning, false > LogWarning
const std::array< double, 6 > getZ()
std::string getStringFromPart(AlignmentPI::partitions i, bool isPhase2=false)