Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:24

0001 /*!
0002   \file TrackerSurfaceDeformations_PayloadInspector
0003   \Payload Inspector Plugin for Tracker Surface Deformations
0004   \author M. Musich
0005   \version $Revision: 1.0 $
0006   \date $Date: 2018/02/01 15:57:24 $
0007 */
0008 
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0012 #include "CondCore/Utilities/interface/PayloadInspector.h"
0013 #include "CondCore/CondDB/interface/Time.h"
0014 
0015 // the data format of the condition to be inspected
0016 #include "CondFormats/Alignment/interface/AlignmentSurfaceDeformations.h"
0017 #include "DataFormats/DetId/interface/DetId.h"
0018 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0019 #include "DataFormats/DetId/interface/DetId.h"
0020 
0021 #include "CondFormats/Alignment/interface/Definitions.h"
0022 
0023 // needed for the tracker map
0024 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0025 
0026 // needed for mapping
0027 #include "CondCore/AlignmentPlugins/interface/AlignmentPayloadInspectorHelper.h"
0028 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0029 
0030 // for the pixel map
0031 #include "DQM/TrackerRemapper/interface/Phase1PixelSummaryMap.h"
0032 
0033 #include <memory>
0034 #include <sstream>
0035 #include <iostream>
0036 
0037 // include ROOT
0038 #include "TGaxis.h"
0039 #include "TH2F.h"
0040 #include "TLegend.h"
0041 #include "TCanvas.h"
0042 #include "TLine.h"
0043 #include "TStyle.h"
0044 #include "TLatex.h"
0045 #include "TPave.h"
0046 #include "TPaveStats.h"
0047 
0048 namespace {
0049 
0050   using namespace cond::payloadInspector;
0051 
0052   class TrackerSurfaceDeformationsTest : public Histogram1D<AlignmentSurfaceDeformations, SINGLE_IOV> {
0053   public:
0054     TrackerSurfaceDeformationsTest()
0055         : Histogram1D<AlignmentSurfaceDeformations, SINGLE_IOV>(
0056               "TrackerSurfaceDeformationsTest", "TrackerSurfaceDeformationsTest", 2, 0.0, 2.0) {}
0057 
0058     bool fill() override {
0059       auto tag = PlotBase::getTag<0>();
0060       for (auto const &iov : tag.iovs) {
0061         std::shared_ptr<AlignmentSurfaceDeformations> payload = Base::fetchPayload(std::get<1>(iov));
0062         if (payload.get()) {
0063           int i = 0;
0064           auto listOfItems = payload->items();
0065           COUT << "items size:" << listOfItems.size() << std::endl;
0066 
0067           for (const auto &item : listOfItems) {
0068             COUT << i << " " << item.m_rawId << " Det: " << DetId(item.m_rawId).subdetId() << " " << item.m_index
0069                  << std::endl;
0070             const auto beginEndPair = payload->parameters(i);
0071             std::vector<align::Scalar> params(beginEndPair.first, beginEndPair.second);
0072             COUT << "params.size()" << params.size() << std::endl;
0073             for (const auto &par : params) {
0074               COUT << par << std::endl;
0075             }
0076             i++;
0077           }
0078 
0079         }  // payload
0080       }  // iovs
0081       return true;
0082     }  // fill
0083   };
0084 
0085   //*******************************************************
0086   // Summary of the parameters for each partition for 1 IOV
0087   //*******************************************************
0088 
0089   template <AlignmentPI::partitions q>
0090   class TrackerAlignmentSurfaceDeformationsSummary : public PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV> {
0091   public:
0092     TrackerAlignmentSurfaceDeformationsSummary()
0093         : PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV>("Details for " + AlignmentPI::getStringFromPart(q)) {}
0094 
0095     bool fill() override {
0096       auto tag = PlotBase::getTag<0>();
0097       auto iov = tag.iovs.front();
0098       std::shared_ptr<AlignmentSurfaceDeformations> payload = fetchPayload(std::get<1>(iov));
0099       auto listOfItems = payload->items();
0100 
0101       int canvas_w = (q <= 4) ? 1200 : 1800;
0102       std::pair<int, int> divisions = (q <= 4) ? std::make_pair(3, 1) : std::make_pair(7, 2);
0103 
0104       TCanvas canvas("Summary", "Summary", canvas_w, 600);
0105       canvas.Divide(divisions.first, divisions.second);
0106 
0107       std::array<std::unique_ptr<TH1F>, 14> summaries;
0108       for (int nPar = 0; nPar < 14; nPar++) {
0109         summaries[nPar] =
0110             std::make_unique<TH1F>(Form("h_summary_%i", nPar),
0111                                    Form("Surface Deformation parameter %i;parameter %i size;# modules", nPar, nPar),
0112                                    100,
0113                                    -0.1,
0114                                    0.1);
0115       }
0116 
0117       int i = 0;
0118       for (const auto &item : listOfItems) {
0119         int subid = DetId(item.m_rawId).subdetId();
0120         auto thePart = static_cast<AlignmentPI::partitions>(subid);
0121 
0122         const auto beginEndPair = payload->parameters(i);
0123         std::vector<align::Scalar> params(beginEndPair.first, beginEndPair.second);
0124 
0125         // increase the counter before continuing if partition doesn't match,
0126         // otherwise the cound of the parameter count gets altered
0127         i++;
0128 
0129         // return if not the right partition
0130         if (thePart != q)
0131           continue;
0132         int nPar = 0;
0133 
0134         for (const auto &par : params) {
0135           summaries[nPar]->Fill(par);
0136           nPar++;
0137         }  // ends loop on the parameters
0138       }  // ends loop on the item vector
0139 
0140       TLatex t1;
0141 
0142       for (int c = 1; c <= (divisions.first * divisions.second); c++) {
0143         canvas.cd(c)->SetLogy();
0144         canvas.cd(c)->SetTopMargin(0.02);
0145         canvas.cd(c)->SetBottomMargin(0.15);
0146         canvas.cd(c)->SetLeftMargin(0.14);
0147         canvas.cd(c)->SetRightMargin(0.03);
0148 
0149         summaries[c - 1]->SetLineWidth(2);
0150         AlignmentPI::makeNicePlotStyle(summaries[c - 1].get(), kBlack);
0151         summaries[c - 1]->Draw("same");
0152         summaries[c - 1]->SetTitle("");
0153 
0154         AlignmentPI::makeNiceStats(summaries[c - 1].get(), q, kBlack);
0155 
0156         canvas.cd(c);
0157 
0158         t1.SetTextAlign(21);
0159         t1.SetTextSize(0.06);
0160         t1.SetTextColor(kBlue);
0161         t1.DrawLatexNDC(0.32, 0.95, Form("IOV: %s ", std::to_string(std::get<0>(iov)).c_str()));
0162       }
0163 
0164       std::string fileName(m_imageFileName);
0165       canvas.SaveAs(fileName.c_str());
0166 
0167       return true;
0168     }
0169   };
0170 
0171   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::BPix> BPixSurfaceDeformationsSummary;
0172   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::FPix> FPixSurfaceDeformationsSummary;
0173   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::TIB> TIBSurfaceDeformationsSummary;
0174   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::TID> TIDSurfaceDeformationsSummary;
0175   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::TOB> TOBSurfaceDeformationsSummary;
0176   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::TEC> TECSurfaceDeformationsSummary;
0177 
0178   //*******************************************************
0179   // Comparison of the parameters for each partition for 1 IOV
0180   //*******************************************************
0181 
0182   template <AlignmentPI::partitions q>
0183   class TrackerAlignmentSurfaceDeformationsComparison : public PlotImage<AlignmentSurfaceDeformations, MULTI_IOV> {
0184   public:
0185     TrackerAlignmentSurfaceDeformationsComparison()
0186         : PlotImage<AlignmentSurfaceDeformations, MULTI_IOV>("Details for " + AlignmentPI::getStringFromPart(q)) {}
0187 
0188     bool fill() override {
0189       auto tag = PlotBase::getTag<0>();
0190       auto sorted_iovs = tag.iovs;
0191 
0192       // make absolute sure the IOVs are sortd by since
0193       std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
0194         return std::get<0>(t1) < std::get<0>(t2);
0195       });
0196 
0197       auto firstiov = sorted_iovs.front();
0198       auto lastiov = sorted_iovs.back();
0199 
0200       std::shared_ptr<AlignmentSurfaceDeformations> last_payload = fetchPayload(std::get<1>(lastiov));
0201       std::shared_ptr<AlignmentSurfaceDeformations> first_payload = fetchPayload(std::get<1>(firstiov));
0202 
0203       std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
0204       std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
0205 
0206       auto first_listOfItems = first_payload->items();
0207       auto last_listOfItems = last_payload->items();
0208 
0209       int canvas_w = (q <= 4) ? 1600 : 1800;
0210       std::pair<int, int> divisions = (q <= 4) ? std::make_pair(3, 1) : std::make_pair(7, 2);
0211 
0212       TCanvas canvas("Comparison", "Comparison", canvas_w, 600);
0213       canvas.Divide(divisions.first, divisions.second);
0214 
0215       std::array<std::unique_ptr<TH1F>, 14> deltas;
0216       for (int nPar = 0; nPar < 14; nPar++) {
0217         deltas[nPar] =
0218             std::make_unique<TH1F>(Form("h_summary_%i", nPar),
0219                                    Form("Surface Deformation #Delta parameter %i;#Deltapar_{%i};# modules", nPar, nPar),
0220                                    100,
0221                                    -0.05,
0222                                    0.05);
0223       }
0224 
0225       //assert(first_listOfItems.size() == last_listOfItems.size());
0226 
0227       for (unsigned int i = 0; i < first_listOfItems.size(); i++) {
0228         auto first_id = first_listOfItems[i].m_rawId;
0229         int subid = DetId(first_listOfItems[i].m_rawId).subdetId();
0230         auto thePart = static_cast<AlignmentPI::partitions>(subid);
0231         if (thePart != q)
0232           continue;
0233 
0234         const auto f_beginEndPair = first_payload->parameters(i);
0235         std::vector<align::Scalar> first_params(f_beginEndPair.first, f_beginEndPair.second);
0236 
0237         for (unsigned int j = 0; j < last_listOfItems.size(); j++) {
0238           auto last_id = last_listOfItems[j].m_rawId;
0239           if (first_id == last_id) {
0240             const auto l_beginEndPair = last_payload->parameters(j);
0241             std::vector<align::Scalar> last_params(l_beginEndPair.first, l_beginEndPair.second);
0242 
0243             assert(first_params.size() == last_params.size());
0244 
0245             for (unsigned int nPar = 0; nPar < first_params.size(); nPar++) {
0246               deltas[nPar]->Fill(last_params[nPar] - first_params[nPar]);
0247             }
0248             break;
0249           }
0250         }
0251 
0252       }  // ends loop on the item vector
0253 
0254       TLatex t1;
0255 
0256       for (int c = 1; c <= (divisions.first * divisions.second); c++) {
0257         canvas.cd(c)->SetLogy();
0258         canvas.cd(c)->SetTopMargin(0.015);
0259         canvas.cd(c)->SetBottomMargin(0.13);
0260         canvas.cd(c)->SetLeftMargin(0.14);
0261         canvas.cd(c)->SetRightMargin(0.03);
0262 
0263         deltas[c - 1]->SetLineWidth(2);
0264         AlignmentPI::makeNicePlotStyle(deltas[c - 1].get(), kBlack);
0265         deltas[c - 1]->Draw("same");
0266         deltas[c - 1]->SetTitle("");
0267 
0268         AlignmentPI::makeNiceStats(deltas[c - 1].get(), q, kBlack);
0269 
0270         canvas.cd(c);
0271         t1.SetTextAlign(21);
0272         t1.SetTextSize(0.045);
0273         t1.SetTextColor(kBlue);
0274         t1.DrawLatexNDC(0.4, 0.95, Form("#DeltaIOV: %s - %s ", lastIOVsince.c_str(), firstIOVsince.c_str()));
0275 
0276         if (deltas[c - 1]->GetEntries() == 0) {
0277           TLatex t2;
0278           t2.SetTextAlign(21);
0279           t2.SetTextSize(0.1);
0280           t2.SetTextAngle(45);
0281           t2.SetTextColor(kRed);
0282           t2.DrawLatexNDC(0.6, 0.50, "NO COMMON DETIDS");
0283         }
0284       }
0285 
0286       std::string fileName(m_imageFileName);
0287       canvas.SaveAs(fileName.c_str());
0288 
0289       return true;
0290     }
0291   };
0292 
0293   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::BPix> BPixSurfaceDeformationsComparison;
0294   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::FPix> FPixSurfaceDeformationsComparison;
0295   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::TIB> TIBSurfaceDeformationsComparison;
0296   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::TID> TIDSurfaceDeformationsComparison;
0297   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::TOB> TOBSurfaceDeformationsComparison;
0298   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::TEC> TECSurfaceDeformationsComparison;
0299 
0300   // /************************************************
0301   //   TrackerMap of single parameter
0302   // *************************************************/
0303   template <unsigned int par>
0304   class SurfaceDeformationTrackerMap : public PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV> {
0305   public:
0306     SurfaceDeformationTrackerMap()
0307         : PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV>(
0308               "Tracker Map of Tracker Surface deformations - parameter: " + std::to_string(par)) {}
0309 
0310     bool fill() override {
0311       auto tag = PlotBase::getTag<0>();
0312       auto iov = tag.iovs.front();
0313 
0314       std::shared_ptr<AlignmentSurfaceDeformations> payload = fetchPayload(std::get<1>(iov));
0315       auto listOfItems = payload->items();
0316 
0317       std::string titleMap =
0318           "Surface deformation parameter " + std::to_string(par) + " value (payload : " + std::get<1>(iov) + ")";
0319 
0320       std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("Surface Deformations");
0321       tmap->setTitle(titleMap);
0322       tmap->setPalette(1);
0323 
0324       std::map<unsigned int, float> surfDefMap;
0325 
0326       bool isPhase0(false);
0327       if (listOfItems.size() == AlignmentPI::phase0size)
0328         isPhase0 = true;
0329 
0330       int iDet = 0;
0331       for (const auto &item : listOfItems) {
0332         // fill the tracker map
0333         int subid = DetId(item.m_rawId).subdetId();
0334 
0335         if (DetId(item.m_rawId).det() != DetId::Tracker) {
0336           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0337               << "Encountered invalid Tracker DetId:" << item.m_rawId << " - terminating ";
0338           return false;
0339         }
0340 
0341         const auto beginEndPair = payload->parameters(iDet);
0342         std::vector<align::Scalar> params(beginEndPair.first, beginEndPair.second);
0343 
0344         iDet++;
0345         // protect against exceeding the vector of parameter size
0346         if (par >= params.size())
0347           continue;
0348 
0349         if (isPhase0) {
0350           tmap->addPixel(true);
0351           tmap->fill(item.m_rawId, params.at(par));
0352           surfDefMap[item.m_rawId] = params.at(par);
0353         } else {
0354           if (subid != 1 && subid != 2) {
0355             tmap->fill(item.m_rawId, params.at(par));
0356             surfDefMap[item.m_rawId] = params.at(par);
0357           }
0358         }
0359       }  // loop over detIds
0360 
0361       //=========================
0362 
0363       // saturate at 1.5sigma
0364       auto autoRange = AlignmentPI::getTheRange(surfDefMap, 1.5);  //tmap->getAutomaticRange();
0365 
0366       std::string fileName(m_imageFileName);
0367       // protect against uniform values (Surface deformations are defined positive)
0368       if (autoRange.first != autoRange.second) {
0369         tmap->save(true, autoRange.first, autoRange.second, fileName);
0370       } else {
0371         if (autoRange.first == 0.) {
0372           tmap->save(true, 0., 1., fileName);
0373         } else {
0374           tmap->save(true, autoRange.first, autoRange.second, fileName);
0375         }
0376       }
0377 
0378       return true;
0379     }
0380   };
0381 
0382   typedef SurfaceDeformationTrackerMap<0> SurfaceDeformationParameter0TrackerMap;
0383   typedef SurfaceDeformationTrackerMap<1> SurfaceDeformationParameter1TrackerMap;
0384   typedef SurfaceDeformationTrackerMap<2> SurfaceDeformationParameter2TrackerMap;
0385   typedef SurfaceDeformationTrackerMap<3> SurfaceDeformationParameter3TrackerMap;
0386   typedef SurfaceDeformationTrackerMap<4> SurfaceDeformationParameter4TrackerMap;
0387   typedef SurfaceDeformationTrackerMap<5> SurfaceDeformationParameter5TrackerMap;
0388   typedef SurfaceDeformationTrackerMap<6> SurfaceDeformationParameter6TrackerMap;
0389   typedef SurfaceDeformationTrackerMap<7> SurfaceDeformationParameter7TrackerMap;
0390   typedef SurfaceDeformationTrackerMap<8> SurfaceDeformationParameter8TrackerMap;
0391   typedef SurfaceDeformationTrackerMap<9> SurfaceDeformationParameter9TrackerMap;
0392   typedef SurfaceDeformationTrackerMap<10> SurfaceDeformationParameter10TrackerMap;
0393   typedef SurfaceDeformationTrackerMap<11> SurfaceDeformationParameter11TrackerMap;
0394   typedef SurfaceDeformationTrackerMap<12> SurfaceDeformationParameter12TrackerMap;
0395 
0396   // /************************************************
0397   //   TrackerMap of single parameter
0398   // *************************************************/
0399   template <unsigned int par>
0400   class SurfaceDeformationPixelMap : public PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV> {
0401   public:
0402     SurfaceDeformationPixelMap()
0403         : PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV>(
0404               "Tracker Map of Tracker Surface deformations - parameter: " + std::to_string(par)) {}
0405 
0406     bool fill() override {
0407       auto tag = PlotBase::getTag<0>();
0408       auto iov = tag.iovs.front();
0409 
0410       std::shared_ptr<AlignmentSurfaceDeformations> payload = fetchPayload(std::get<1>(iov));
0411       auto listOfItems = payload->items();
0412 
0413       TCanvas canvas("Canv", "Canv", 1400, 1000);
0414       Phase1PixelSummaryMap fullMap("", "Surface deformation parameter " + std::to_string(par), "");
0415       fullMap.createTrackerBaseMap();
0416 
0417       std::map<unsigned int, float> surfDefMap;
0418 
0419       bool isPhase0(false);
0420       if (listOfItems.size() == AlignmentPI::phase0size) {
0421         isPhase0 = true;
0422       }
0423 
0424       int iDet = 0;
0425       for (const auto &item : listOfItems) {
0426         // fill the tracker map
0427         int subid = DetId(item.m_rawId).subdetId();
0428 
0429         if (DetId(item.m_rawId).det() != DetId::Tracker) {
0430           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0431               << "Encountered invalid Tracker DetId:" << item.m_rawId << " - terminating ";
0432           return false;
0433         }
0434 
0435         const auto beginEndPair = payload->parameters(iDet);
0436         std::vector<align::Scalar> params(beginEndPair.first, beginEndPair.second);
0437 
0438         iDet++;
0439         // protect against exceeding the vector of parameter size
0440         if (par >= params.size())
0441           continue;
0442 
0443         if (isPhase0) {
0444           surfDefMap[item.m_rawId] = params.at(par);
0445         } else {
0446           if (subid == 1 || subid == 2) {
0447             fullMap.fillTrackerMap(item.m_rawId, params.at(par));
0448             surfDefMap[item.m_rawId] = params.at(par);
0449           }
0450         }
0451       }  // loop over detIds
0452 
0453       //=========================
0454 
0455       if (surfDefMap.empty()) {
0456         edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector") << "No common DetIds have been found!!! ";
0457       }
0458 
0459       // protect against uniform values (Surface deformations are defined positive)
0460       fullMap.printTrackerMap(canvas);
0461 
0462       std::string fileName(this->m_imageFileName);
0463       canvas.SaveAs(fileName.c_str());
0464 
0465       return true;
0466     }
0467   };
0468 
0469   typedef SurfaceDeformationPixelMap<0> SurfaceDeformationParameter0PixelMap;
0470   typedef SurfaceDeformationPixelMap<1> SurfaceDeformationParameter1PixelMap;
0471   typedef SurfaceDeformationPixelMap<2> SurfaceDeformationParameter2PixelMap;
0472   typedef SurfaceDeformationPixelMap<3> SurfaceDeformationParameter3PixelMap;
0473   typedef SurfaceDeformationPixelMap<4> SurfaceDeformationParameter4PixelMap;
0474   typedef SurfaceDeformationPixelMap<5> SurfaceDeformationParameter5PixelMap;
0475   typedef SurfaceDeformationPixelMap<6> SurfaceDeformationParameter6PixelMap;
0476   typedef SurfaceDeformationPixelMap<7> SurfaceDeformationParameter7PixelMap;
0477   typedef SurfaceDeformationPixelMap<8> SurfaceDeformationParameter8PixelMap;
0478   typedef SurfaceDeformationPixelMap<9> SurfaceDeformationParameter9PixelMap;
0479   typedef SurfaceDeformationPixelMap<10> SurfaceDeformationParameter10PixelMap;
0480   typedef SurfaceDeformationPixelMap<11> SurfaceDeformationParameter11PixelMap;
0481   typedef SurfaceDeformationPixelMap<12> SurfaceDeformationParameter12PixelMap;
0482 
0483   // /************************************************
0484   //   TrackerMap of delta for a single parameter
0485   // *************************************************/
0486   template <unsigned int m_par>
0487   class SurfaceDeformationsTkMapDelta : public PlotImage<AlignmentSurfaceDeformations, MULTI_IOV> {
0488   public:
0489     SurfaceDeformationsTkMapDelta()
0490         : PlotImage<AlignmentSurfaceDeformations, MULTI_IOV>(
0491               "Tracker Map of Tracker Surface deformations differences - parameter: " + std::to_string(m_par)) {}
0492 
0493     bool fill() override {
0494       auto tag = PlotBase::getTag<0>();
0495       auto sorted_iovs = tag.iovs;
0496 
0497       // make absolute sure the IOVs are sortd by since
0498       std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
0499         return std::get<0>(t1) < std::get<0>(t2);
0500       });
0501 
0502       auto firstiov = sorted_iovs.front();
0503       auto lastiov = sorted_iovs.back();
0504 
0505       std::shared_ptr<AlignmentSurfaceDeformations> last_payload = fetchPayload(std::get<1>(lastiov));
0506       std::shared_ptr<AlignmentSurfaceDeformations> first_payload = fetchPayload(std::get<1>(firstiov));
0507 
0508       std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
0509       std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
0510 
0511       auto first_listOfItems = first_payload->items();
0512       auto last_listOfItems = last_payload->items();
0513 
0514       std::string titleMap = "#Delta Surface deformation parameter " + std::to_string(m_par) +
0515                              " (IOV : " + std::to_string(std::get<0>(lastiov)) + "- " +
0516                              std::to_string(std::get<0>(firstiov)) + ")";
0517 
0518       std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("Surface Deformations #Delta");
0519       tmap->setTitle(titleMap);
0520       tmap->setPalette(1);
0521 
0522       std::map<unsigned int, float> f_paramsMap;
0523       std::map<unsigned int, float> l_paramsMap;
0524       std::map<unsigned int, float> surfDefMap;
0525 
0526       // check the payload sizes are matched
0527       if (first_listOfItems.size() != last_listOfItems.size()) {
0528         edm::LogInfo("TrackerSurfaceDeformations_PayloadInspector")
0529             << "(" << firstIOVsince << ") has " << first_listOfItems.size() << " DetIds - (" << lastIOVsince << ") has "
0530             << last_listOfItems.size() << " DetIds" << std::endl;
0531       };
0532 
0533       bool isPhase0(false);
0534       if (first_listOfItems.size() <= AlignmentPI::phase0size)
0535         isPhase0 = true;
0536       if (isPhase0)
0537         tmap->addPixel(true);
0538 
0539       // loop on the first payload
0540       int iDet = 0;
0541       for (const auto &f_item : first_listOfItems) {
0542         auto first_id = f_item.m_rawId;
0543 
0544         if (DetId(first_id).det() != DetId::Tracker) {
0545           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0546               << "Encountered invalid Tracker DetId:" << first_id << " - terminating ";
0547           return false;
0548         }
0549 
0550         const auto f_beginEndPair = first_payload->parameters(iDet);
0551         std::vector<align::Scalar> first_params(f_beginEndPair.first, f_beginEndPair.second);
0552 
0553         iDet++;
0554         // protect against exceeding the vector of parameter size
0555         if (m_par >= first_params.size())
0556           continue;
0557 
0558         f_paramsMap[first_id] = first_params.at(m_par);
0559       }
0560 
0561       // loop on the second payload
0562       int jDet = 0;
0563       for (const auto &l_item : last_listOfItems) {
0564         auto last_id = l_item.m_rawId;
0565 
0566         if (DetId(last_id).det() != DetId::Tracker) {
0567           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0568               << "Encountered invalid Tracker DetId:" << last_id << " - terminating ";
0569           return false;
0570         }
0571 
0572         const auto l_beginEndPair = last_payload->parameters(jDet);
0573         std::vector<align::Scalar> last_params(l_beginEndPair.first, l_beginEndPair.second);
0574 
0575         jDet++;
0576         // protect against exceeding the vector of parameter size
0577         if (m_par >= last_params.size())
0578           continue;
0579 
0580         l_paramsMap[last_id] = last_params.at(m_par);
0581       }
0582 
0583       // fill the tk map
0584       for (const auto &f_entry : f_paramsMap) {
0585         for (const auto &l_entry : l_paramsMap) {
0586           if (f_entry.first != l_entry.first)
0587             continue;
0588 
0589           int subid = DetId(f_entry.first).subdetId();
0590 
0591           float delta = (l_entry.second - f_entry.second);
0592 
0593           //COUT<<" match! subid:" << subid << " rawId:" << f_entry.first << " delta:"<< delta << std::endl;
0594 
0595           if (isPhase0) {
0596             tmap->addPixel(true);
0597             tmap->fill(f_entry.first, delta);
0598             surfDefMap[f_entry.first] = delta;
0599           } else {
0600             // fill pixel map only for phase-0 (in lack of a dedicate phase-I map)
0601             if (subid != 1 && subid != 2) {
0602               tmap->fill(f_entry.first, delta);
0603               surfDefMap[f_entry.first] = delta;
0604             }
0605           }  // if not phase-0
0606         }  // loop on the last payload map
0607       }  // loop on the first payload map
0608 
0609       //=========================
0610 
0611       if (surfDefMap.empty()) {
0612         edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector") << "No common DetIds have been found!!! ";
0613         tmap->fillc_all_blank();
0614         tmap->setTitle("NO COMMON DETIDS (IOV : " + std::to_string(std::get<0>(lastiov)) + "- " +
0615                        std::to_string(std::get<0>(firstiov)) + ")");
0616       }
0617 
0618       // saturate at 1.5sigma
0619       auto autoRange = AlignmentPI::getTheRange(surfDefMap, 1.5);  //tmap->getAutomaticRange();
0620 
0621       std::string fileName(m_imageFileName);
0622       // protect against uniform values (Surface deformations are defined positive)
0623       if (autoRange.first != autoRange.second) {
0624         tmap->save(true, autoRange.first, autoRange.second, fileName);
0625       } else {
0626         if (autoRange.first == 0.) {
0627           tmap->save(true, 0., 1., fileName);
0628         } else {
0629           tmap->save(true, autoRange.first, autoRange.second, fileName);
0630         }
0631       }
0632 
0633       return true;
0634     }
0635   };
0636 
0637   typedef SurfaceDeformationsTkMapDelta<0> SurfaceDeformationParameter0TkMapDelta;
0638   typedef SurfaceDeformationsTkMapDelta<1> SurfaceDeformationParameter1TkMapDelta;
0639   typedef SurfaceDeformationsTkMapDelta<2> SurfaceDeformationParameter2TkMapDelta;
0640   typedef SurfaceDeformationsTkMapDelta<3> SurfaceDeformationParameter3TkMapDelta;
0641   typedef SurfaceDeformationsTkMapDelta<4> SurfaceDeformationParameter4TkMapDelta;
0642   typedef SurfaceDeformationsTkMapDelta<5> SurfaceDeformationParameter5TkMapDelta;
0643   typedef SurfaceDeformationsTkMapDelta<6> SurfaceDeformationParameter6TkMapDelta;
0644   typedef SurfaceDeformationsTkMapDelta<7> SurfaceDeformationParameter7TkMapDelta;
0645   typedef SurfaceDeformationsTkMapDelta<8> SurfaceDeformationParameter8TkMapDelta;
0646   typedef SurfaceDeformationsTkMapDelta<9> SurfaceDeformationParameter9TkMapDelta;
0647   typedef SurfaceDeformationsTkMapDelta<10> SurfaceDeformationParameter10TkMapDelta;
0648   typedef SurfaceDeformationsTkMapDelta<11> SurfaceDeformationParameter11TkMapDelta;
0649   typedef SurfaceDeformationsTkMapDelta<12> SurfaceDeformationParameter12TkMapDelta;
0650 
0651   // /************************************************
0652   //   TrackerMap of delta for a single parameter
0653   // *************************************************/
0654   template <unsigned int m_par>
0655   class SurfaceDeformationsPXMapDelta : public PlotImage<AlignmentSurfaceDeformations, MULTI_IOV> {
0656   public:
0657     SurfaceDeformationsPXMapDelta()
0658         : PlotImage<AlignmentSurfaceDeformations, MULTI_IOV>(
0659               "Tracker Map of Tracker Surface deformations differences - parameter: " + std::to_string(m_par)) {}
0660 
0661     bool fill() override {
0662       auto tag = PlotBase::getTag<0>();
0663       auto sorted_iovs = tag.iovs;
0664 
0665       // make absolute sure the IOVs are sortd by since
0666       std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
0667         return std::get<0>(t1) < std::get<0>(t2);
0668       });
0669 
0670       auto firstiov = sorted_iovs.front();
0671       auto lastiov = sorted_iovs.back();
0672 
0673       std::shared_ptr<AlignmentSurfaceDeformations> last_payload = fetchPayload(std::get<1>(lastiov));
0674       std::shared_ptr<AlignmentSurfaceDeformations> first_payload = fetchPayload(std::get<1>(firstiov));
0675 
0676       std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
0677       std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
0678 
0679       auto first_listOfItems = first_payload->items();
0680       auto last_listOfItems = last_payload->items();
0681 
0682       std::string titleMap = "#Delta Surface deformation parameter " + std::to_string(m_par) +
0683                              " (IOV : " + std::to_string(std::get<0>(lastiov)) + "- " +
0684                              std::to_string(std::get<0>(firstiov)) + ")";
0685 
0686       TCanvas canvas("Canv", "Canv", 1400, 1000);
0687       Phase1PixelSummaryMap fullMap("", "#Delta Surface deformation parameter " + std::to_string(m_par), "");
0688       fullMap.createTrackerBaseMap();
0689 
0690       std::map<unsigned int, float> f_paramsMap;
0691       std::map<unsigned int, float> l_paramsMap;
0692       std::map<unsigned int, float> surfDefMap;
0693 
0694       // check the payload sizes are matched
0695       if (first_listOfItems.size() != last_listOfItems.size()) {
0696         edm::LogInfo("TrackerSurfaceDeformations_PayloadInspector")
0697             << "(" << firstIOVsince << ") has " << first_listOfItems.size() << " DetIds - (" << lastIOVsince << ") has "
0698             << last_listOfItems.size() << " DetIds" << std::endl;
0699       };
0700 
0701       bool isPhase0(false);
0702       if (first_listOfItems.size() <= AlignmentPI::phase0size) {
0703         isPhase0 = true;
0704       }
0705 
0706       // loop on the first payload
0707       int iDet = 0;
0708       for (const auto &f_item : first_listOfItems) {
0709         auto first_id = f_item.m_rawId;
0710 
0711         if (DetId(first_id).det() != DetId::Tracker) {
0712           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0713               << "Encountered invalid Tracker DetId:" << first_id << " - terminating ";
0714           return false;
0715         }
0716 
0717         const auto f_beginEndPair = first_payload->parameters(iDet);
0718         std::vector<align::Scalar> first_params(f_beginEndPair.first, f_beginEndPair.second);
0719 
0720         iDet++;
0721         // protect against exceeding the vector of parameter size
0722         if (m_par >= first_params.size())
0723           continue;
0724 
0725         f_paramsMap[first_id] = first_params.at(m_par);
0726       }
0727 
0728       // loop on the second payload
0729       int jDet = 0;
0730       for (const auto &l_item : last_listOfItems) {
0731         auto last_id = l_item.m_rawId;
0732 
0733         if (DetId(last_id).det() != DetId::Tracker) {
0734           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0735               << "Encountered invalid Tracker DetId:" << last_id << " - terminating ";
0736           return false;
0737         }
0738 
0739         const auto l_beginEndPair = last_payload->parameters(jDet);
0740         std::vector<align::Scalar> last_params(l_beginEndPair.first, l_beginEndPair.second);
0741 
0742         jDet++;
0743         // protect against exceeding the vector of parameter size
0744         if (m_par >= last_params.size())
0745           continue;
0746 
0747         l_paramsMap[last_id] = last_params.at(m_par);
0748       }
0749 
0750       if (f_paramsMap.empty() || l_paramsMap.empty()) {
0751         edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0752             << " One or more of the paylods is null \n"
0753             << " Cannot perform the comparison." << std::endl;
0754         return false;
0755       }
0756 
0757       // fill the tk map
0758       for (const auto &f_entry : f_paramsMap) {
0759         for (const auto &l_entry : l_paramsMap) {
0760           if (f_entry.first != l_entry.first)
0761             continue;
0762 
0763           int subid = DetId(f_entry.first).subdetId();
0764           float delta = (l_entry.second - f_entry.second);
0765 
0766           if (isPhase0) {
0767             surfDefMap[f_entry.first] = delta;
0768           } else {
0769             // fill pixel map only for phase-0 (in lack of a dedicate phase-I map)
0770             if (subid == 1 || subid == 2) {
0771               fullMap.fillTrackerMap(f_entry.first, delta);
0772               surfDefMap[f_entry.first] = delta;
0773             }
0774           }  // if not phase-0
0775         }  // loop on the last payload map
0776       }  // loop on the first payload map
0777 
0778       //=========================
0779 
0780       if (surfDefMap.empty()) {
0781         edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector") << "No common DetIds have been found!!! ";
0782       }
0783 
0784       fullMap.printTrackerMap(canvas);
0785 
0786       std::string fileName(this->m_imageFileName);
0787       canvas.SaveAs(fileName.c_str());
0788 
0789       return true;
0790     }
0791   };
0792 
0793   typedef SurfaceDeformationsPXMapDelta<0> SurfaceDeformationParameter0PXMapDelta;
0794   typedef SurfaceDeformationsPXMapDelta<1> SurfaceDeformationParameter1PXMapDelta;
0795   typedef SurfaceDeformationsPXMapDelta<2> SurfaceDeformationParameter2PXMapDelta;
0796   typedef SurfaceDeformationsPXMapDelta<3> SurfaceDeformationParameter3PXMapDelta;
0797   typedef SurfaceDeformationsPXMapDelta<4> SurfaceDeformationParameter4PXMapDelta;
0798   typedef SurfaceDeformationsPXMapDelta<5> SurfaceDeformationParameter5PXMapDelta;
0799   typedef SurfaceDeformationsPXMapDelta<6> SurfaceDeformationParameter6PXMapDelta;
0800   typedef SurfaceDeformationsPXMapDelta<7> SurfaceDeformationParameter7PXMapDelta;
0801   typedef SurfaceDeformationsPXMapDelta<8> SurfaceDeformationParameter8PXMapDelta;
0802   typedef SurfaceDeformationsPXMapDelta<9> SurfaceDeformationParameter9PXMapDelta;
0803   typedef SurfaceDeformationsPXMapDelta<10> SurfaceDeformationParameter10PXMapDelta;
0804   typedef SurfaceDeformationsPXMapDelta<11> SurfaceDeformationParameter11PXMapDelta;
0805   typedef SurfaceDeformationsPXMapDelta<12> SurfaceDeformationParameter12PXMapDelta;
0806 
0807   // /************************************************
0808   //  Tracker Surface Deformations grand summary comparison of 2 IOVs
0809   // *************************************************/
0810 
0811   template <unsigned int m_par>
0812   class TrackerSurfaceDeformationsComparator : public PlotImage<AlignmentSurfaceDeformations, MULTI_IOV> {
0813   public:
0814     TrackerSurfaceDeformationsComparator()
0815         : PlotImage<AlignmentSurfaceDeformations, MULTI_IOV>("Summary per Tracker region of parameter " +
0816                                                              std::to_string(m_par) + " of Surface Deformations") {}
0817 
0818     bool fill() override {
0819       auto tag = PlotBase::getTag<0>();
0820       auto sorted_iovs = tag.iovs;
0821 
0822       TGaxis::SetMaxDigits(3);
0823       gStyle->SetPaintTextFormat(".1f");
0824 
0825       // make absolute sure the IOVs are sortd by since
0826       std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
0827         return std::get<0>(t1) < std::get<0>(t2);
0828       });
0829 
0830       auto firstiov = sorted_iovs.front();
0831       auto lastiov = sorted_iovs.back();
0832 
0833       std::shared_ptr<AlignmentSurfaceDeformations> last_payload = fetchPayload(std::get<1>(lastiov));
0834       std::shared_ptr<AlignmentSurfaceDeformations> first_payload = fetchPayload(std::get<1>(firstiov));
0835 
0836       std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
0837       std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
0838 
0839       auto first_listOfItems = first_payload->items();
0840       auto last_listOfItems = last_payload->items();
0841 
0842       TCanvas canvas("Comparison", "Comparison", 1600, 800);
0843 
0844       std::map<AlignmentPI::regions, std::shared_ptr<TH1F> > FirstSurfDef_spectraByRegion;
0845       std::map<AlignmentPI::regions, std::shared_ptr<TH1F> > LastSurfDef_spectraByRegion;
0846       std::shared_ptr<TH1F> summaryFirst;
0847       std::shared_ptr<TH1F> summaryLast;
0848 
0849       // book the intermediate histograms
0850       for (int r = AlignmentPI::BPixL1o; r != AlignmentPI::StripDoubleSide; r++) {
0851         AlignmentPI::regions part = static_cast<AlignmentPI::regions>(r);
0852         std::string s_part = AlignmentPI::getStringFromRegionEnum(part);
0853 
0854         FirstSurfDef_spectraByRegion[part] =
0855             std::make_shared<TH1F>(Form("hfirstSurfDef_%i_%s", m_par, s_part.c_str()),
0856                                    Form(";%s SurfDef parameter %i;n. of modules", s_part.c_str(), m_par),
0857                                    10000,
0858                                    -1,
0859                                    1.);
0860         LastSurfDef_spectraByRegion[part] =
0861             std::make_shared<TH1F>(Form("hlastSurfDef_%i_%s", m_par, s_part.c_str()),
0862                                    Form(";%s SurfDef parameter %i;n. of modules", s_part.c_str(), m_par),
0863                                    10000,
0864                                    -1.,
0865                                    1.);
0866       }
0867 
0868       summaryFirst = std::make_shared<TH1F>(
0869           Form("first Summary_%i", m_par),
0870           Form("Summary for parameter %i Surface Deformation;;Surface Deformation paramter %i", m_par, m_par),
0871           FirstSurfDef_spectraByRegion.size(),
0872           0,
0873           FirstSurfDef_spectraByRegion.size());
0874       summaryLast = std::make_shared<TH1F>(
0875           Form("last Summary_%i", m_par),
0876           Form("Summary for parameter %i Surface Deformation;;Surface Deformation paramter %i", m_par, m_par),
0877           LastSurfDef_spectraByRegion.size(),
0878           0,
0879           LastSurfDef_spectraByRegion.size());
0880 
0881       // N.B. <= and not == because the list of surface deformations might not include all tracker modules
0882       const char *path_toTopologyXML = (first_listOfItems.size() <= AlignmentPI::phase0size)
0883                                            ? "Geometry/TrackerCommonData/data/trackerParameters.xml"
0884                                            : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
0885       const char *alternative_path_toTopologyXML = (first_listOfItems.size() <= AlignmentPI::phase0size)
0886                                                        ? "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"
0887                                                        : "Geometry/TrackerCommonData/data/trackerParameters.xml";
0888       TrackerTopology f_tTopo =
0889           StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath());
0890       TrackerTopology af_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0891           edm::FileInPath(alternative_path_toTopologyXML).fullPath());
0892 
0893       bool isPhase0(false);
0894       if (first_listOfItems.size() <= AlignmentPI::phase0size)
0895         isPhase0 = true;
0896 
0897       // -------------------------------------------------------------------
0898       // loop on the first vector of errors
0899       // -------------------------------------------------------------------
0900       int iDet = 0;
0901       for (const auto &it : first_listOfItems) {
0902         if (DetId(it.m_rawId).det() != DetId::Tracker) {
0903           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0904               << "Encountered invalid Tracker DetId:" << it.m_rawId << " - terminating ";
0905           return false;
0906         }
0907 
0908         AlignmentPI::topolInfo t_info_fromXML;
0909         t_info_fromXML.init();
0910         DetId detid(it.m_rawId);
0911         t_info_fromXML.fillGeometryInfo(detid, f_tTopo, isPhase0);
0912 
0913         //COUT<<"sanityCheck: "<< t_info_fromXML.sanityCheck() << std::endl;
0914 
0915         if (!t_info_fromXML.sanityCheck()) {
0916           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0917               << "Wrong choice of Tracker Topology encountered for DetId:" << it.m_rawId << " ---> changing";
0918           t_info_fromXML.init();
0919           t_info_fromXML.fillGeometryInfo(detid, af_tTopo, !isPhase0);
0920         }
0921 
0922         //t_info_fromXML.printAll();
0923 
0924         AlignmentPI::regions thePart = t_info_fromXML.filterThePartition();
0925 
0926         // skip the glued detector detIds
0927         if (thePart == AlignmentPI::StripDoubleSide)
0928           continue;
0929 
0930         const auto f_beginEndPair = first_payload->parameters(iDet);
0931         std::vector<align::Scalar> first_params(f_beginEndPair.first, f_beginEndPair.second);
0932 
0933         iDet++;
0934         // protect against exceeding the vector of parameter size
0935         if (m_par >= first_params.size())
0936           continue;
0937 
0938         FirstSurfDef_spectraByRegion[thePart]->Fill(first_params.at(m_par));
0939         //COUT<<  getStringFromRegionEnum(thePart) << " first payload: "<< first_params.at(m_par) << std::endl;
0940 
0941       }  // ends loop on the vector of error transforms
0942 
0943       // N.B. <= and not == because the list of surface deformations might not include all tracker modules
0944       path_toTopologyXML = (last_listOfItems.size() <= AlignmentPI::phase0size)
0945                                ? "Geometry/TrackerCommonData/data/trackerParameters.xml"
0946                                : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
0947       alternative_path_toTopologyXML = (first_listOfItems.size() <= AlignmentPI::phase0size)
0948                                            ? "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"
0949                                            : "Geometry/TrackerCommonData/data/trackerParameters.xml";
0950       TrackerTopology l_tTopo =
0951           StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath());
0952       TrackerTopology al_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0953           edm::FileInPath(alternative_path_toTopologyXML).fullPath());
0954 
0955       if (last_listOfItems.size() <= AlignmentPI::phase0size)
0956         isPhase0 = true;
0957 
0958       // -------------------------------------------------------------------
0959       // loop on the second vector of errors
0960       // -------------------------------------------------------------------
0961       int jDet = 0;
0962       for (const auto &it : last_listOfItems) {
0963         if (DetId(it.m_rawId).det() != DetId::Tracker) {
0964           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0965               << "Encountered invalid Tracker DetId:" << it.m_rawId << " - terminating ";
0966           return false;
0967         }
0968 
0969         AlignmentPI::topolInfo t_info_fromXML;
0970         t_info_fromXML.init();
0971         DetId detid(it.m_rawId);
0972         t_info_fromXML.fillGeometryInfo(detid, l_tTopo, isPhase0);
0973 
0974         //COUT<<"sanityCheck: "<< t_info_fromXML.sanityCheck() << std::endl;
0975 
0976         if (!t_info_fromXML.sanityCheck()) {
0977           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0978               << "Wrong choice of Tracker Topology encountered for DetId:" << it.m_rawId << " ---> changing";
0979           t_info_fromXML.init();
0980           isPhase0 = !isPhase0;
0981           t_info_fromXML.fillGeometryInfo(detid, al_tTopo, !isPhase0);
0982         }
0983 
0984         //t_info_fromXML.printAll();
0985 
0986         AlignmentPI::regions thePart = t_info_fromXML.filterThePartition();
0987 
0988         // skip the glued detector detIds
0989         if (thePart == AlignmentPI::StripDoubleSide)
0990           continue;
0991 
0992         const auto l_beginEndPair = last_payload->parameters(jDet);
0993         std::vector<align::Scalar> last_params(l_beginEndPair.first, l_beginEndPair.second);
0994 
0995         jDet++;
0996         // protect against exceeding the vector of parameter size
0997         if (m_par >= last_params.size())
0998           continue;
0999 
1000         LastSurfDef_spectraByRegion[thePart]->Fill(last_params.at(m_par));
1001         //COUT<< getStringFromRegionEnum(thePart) <<  " last payload: "<< last_params.at(m_par) << std::endl;
1002 
1003       }  // ends loop on the vector of error transforms
1004 
1005       // fill the summary plots
1006       int bin = 1;
1007       for (int r = AlignmentPI::BPixL1o; r != AlignmentPI::StripDoubleSide; r++) {
1008         AlignmentPI::regions part = static_cast<AlignmentPI::regions>(r);
1009 
1010         summaryFirst->GetXaxis()->SetBinLabel(bin, AlignmentPI::getStringFromRegionEnum(part).c_str());
1011         // avoid filling the histogram with numerical noise
1012         float f_mean = FirstSurfDef_spectraByRegion[part]->GetMean();
1013         summaryFirst->SetBinContent(bin, f_mean);
1014         //summaryFirst->SetBinError(bin, FirstSurfDef_spectraByRegion[part]->GetRMS());
1015 
1016         summaryLast->GetXaxis()->SetBinLabel(bin, AlignmentPI::getStringFromRegionEnum(part).c_str());
1017         // avoid filling the histogram with numerical noise
1018         float l_mean = LastSurfDef_spectraByRegion[part]->GetMean();
1019         summaryLast->SetBinContent(bin, l_mean);
1020         //summaryLast->SetBinError(bin,LastSurfDef_spectraByRegion[part]->GetRMS());
1021         bin++;
1022       }
1023 
1024       AlignmentPI::makeNicePlotStyle(summaryFirst.get(), kBlue);
1025       summaryFirst->SetMarkerColor(kBlue);
1026       summaryFirst->GetXaxis()->LabelsOption("v");
1027       summaryFirst->GetXaxis()->SetLabelSize(0.05);
1028       summaryFirst->GetYaxis()->SetTitleOffset(0.9);
1029 
1030       AlignmentPI::makeNicePlotStyle(summaryLast.get(), kRed);
1031       summaryLast->SetMarkerColor(kRed);
1032       summaryLast->GetYaxis()->SetTitleOffset(0.9);
1033       summaryLast->GetXaxis()->LabelsOption("v");
1034       summaryLast->GetXaxis()->SetLabelSize(0.05);
1035 
1036       canvas.cd()->SetGridy();
1037 
1038       canvas.SetBottomMargin(0.18);
1039       canvas.SetLeftMargin(0.11);
1040       canvas.SetRightMargin(0.02);
1041       canvas.Modified();
1042 
1043       summaryFirst->SetFillColor(kBlue);
1044       summaryLast->SetFillColor(kRed);
1045 
1046       summaryFirst->SetBarWidth(0.45);
1047       summaryFirst->SetBarOffset(0.1);
1048 
1049       summaryLast->SetBarWidth(0.4);
1050       summaryLast->SetBarOffset(0.55);
1051 
1052       float max = (summaryFirst->GetMaximum() > summaryLast->GetMaximum()) ? summaryFirst->GetMaximum()
1053                                                                            : summaryLast->GetMaximum();
1054       float min = (summaryFirst->GetMinimum() < summaryLast->GetMinimum()) ? summaryFirst->GetMinimum()
1055                                                                            : summaryLast->GetMinimum();
1056 
1057       summaryFirst->GetYaxis()->SetRangeUser(min * 1.20, max * 1.40);
1058       summaryFirst->Draw("b");
1059       //summaryFirst->Draw("text90same");
1060       summaryLast->Draw("b,same");
1061       //summaryLast->Draw("text180same");
1062 
1063       TLegend legend = TLegend(0.52, 0.82, 0.98, 0.9);
1064       legend.SetHeader(("Surface Deformation par " + std::to_string(m_par) + " comparison").c_str(),
1065                        "C");  // option "C" allows to center the header
1066       legend.AddEntry(
1067           summaryLast.get(),
1068           ("IOV:  #scale[1.2]{" + std::to_string(std::get<0>(lastiov)) + "} | #color[2]{" + std::get<1>(lastiov) + "}")
1069               .c_str(),
1070           "F");
1071       legend.AddEntry(summaryFirst.get(),
1072                       ("IOV:  #scale[1.2]{" + std::to_string(std::get<0>(firstiov)) + "} | #color[4]{" +
1073                        std::get<1>(firstiov) + "}")
1074                           .c_str(),
1075                       "F");
1076       legend.SetTextSize(0.025);
1077       legend.Draw("same");
1078 
1079       std::string fileName(m_imageFileName);
1080       canvas.SaveAs(fileName.c_str());
1081 
1082       return true;
1083 
1084     }  // ends fill method
1085   };
1086 
1087   typedef TrackerSurfaceDeformationsComparator<0> TrackerSurfaceDeformationsPar0Comparator;
1088   typedef TrackerSurfaceDeformationsComparator<1> TrackerSurfaceDeformationsPar1Comparator;
1089   typedef TrackerSurfaceDeformationsComparator<2> TrackerSurfaceDeformationsPar2Comparator;
1090   typedef TrackerSurfaceDeformationsComparator<3> TrackerSurfaceDeformationsPar3Comparator;
1091   typedef TrackerSurfaceDeformationsComparator<4> TrackerSurfaceDeformationsPar4Comparator;
1092   typedef TrackerSurfaceDeformationsComparator<5> TrackerSurfaceDeformationsPar5Comparator;
1093   typedef TrackerSurfaceDeformationsComparator<6> TrackerSurfaceDeformationsPar6Comparator;
1094   typedef TrackerSurfaceDeformationsComparator<7> TrackerSurfaceDeformationsPar7Comparator;
1095   typedef TrackerSurfaceDeformationsComparator<8> TrackerSurfaceDeformationsPar8Comparator;
1096   typedef TrackerSurfaceDeformationsComparator<9> TrackerSurfaceDeformationsPar9Comparator;
1097   typedef TrackerSurfaceDeformationsComparator<10> TrackerSurfaceDeformationsPar10Comparator;
1098   typedef TrackerSurfaceDeformationsComparator<11> TrackerSurfaceDeformationsPar11Comparator;
1099   typedef TrackerSurfaceDeformationsComparator<12> TrackerSurfaceDeformationsPar12Comparator;
1100 
1101 }  // namespace
1102 
1103 PAYLOAD_INSPECTOR_MODULE(TrackerSurfaceDeformations) {
1104   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsTest);
1105   PAYLOAD_INSPECTOR_CLASS(BPixSurfaceDeformationsSummary);
1106   PAYLOAD_INSPECTOR_CLASS(FPixSurfaceDeformationsSummary);
1107   PAYLOAD_INSPECTOR_CLASS(TIBSurfaceDeformationsSummary);
1108   PAYLOAD_INSPECTOR_CLASS(TIDSurfaceDeformationsSummary);
1109   PAYLOAD_INSPECTOR_CLASS(TOBSurfaceDeformationsSummary);
1110   PAYLOAD_INSPECTOR_CLASS(TECSurfaceDeformationsSummary);
1111   PAYLOAD_INSPECTOR_CLASS(BPixSurfaceDeformationsComparison);
1112   PAYLOAD_INSPECTOR_CLASS(FPixSurfaceDeformationsComparison);
1113   PAYLOAD_INSPECTOR_CLASS(TIBSurfaceDeformationsComparison);
1114   PAYLOAD_INSPECTOR_CLASS(TIDSurfaceDeformationsComparison);
1115   PAYLOAD_INSPECTOR_CLASS(TOBSurfaceDeformationsComparison);
1116   PAYLOAD_INSPECTOR_CLASS(TECSurfaceDeformationsComparison);
1117   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter0TrackerMap);
1118   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter1TrackerMap);
1119   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter2TrackerMap);
1120   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter3TrackerMap);
1121   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter4TrackerMap);
1122   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter5TrackerMap);
1123   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter6TrackerMap);
1124   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter7TrackerMap);
1125   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter8TrackerMap);
1126   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter9TrackerMap);
1127   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter10TrackerMap);
1128   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter11TrackerMap);
1129   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter12TrackerMap);
1130   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter0PixelMap);
1131   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter1PixelMap);
1132   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter2PixelMap);
1133   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter3PixelMap);
1134   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter4PixelMap);
1135   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter5PixelMap);
1136   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter6PixelMap);
1137   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter7PixelMap);
1138   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter8PixelMap);
1139   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter9PixelMap);
1140   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter10PixelMap);
1141   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter11PixelMap);
1142   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter12PixelMap);
1143   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter0TkMapDelta);
1144   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter1TkMapDelta);
1145   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter2TkMapDelta);
1146   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter3TkMapDelta);
1147   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter4TkMapDelta);
1148   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter5TkMapDelta);
1149   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter6TkMapDelta);
1150   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter7TkMapDelta);
1151   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter8TkMapDelta);
1152   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter9TkMapDelta);
1153   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter10TkMapDelta);
1154   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter11TkMapDelta);
1155   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter12TkMapDelta);
1156   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter0PXMapDelta);
1157   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter1PXMapDelta);
1158   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter2PXMapDelta);
1159   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter3PXMapDelta);
1160   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter4PXMapDelta);
1161   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter5PXMapDelta);
1162   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter6PXMapDelta);
1163   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter7PXMapDelta);
1164   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter8PXMapDelta);
1165   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter9PXMapDelta);
1166   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter10PXMapDelta);
1167   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter11PXMapDelta);
1168   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter12PXMapDelta);
1169   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar0Comparator);
1170   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar1Comparator);
1171   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar2Comparator);
1172   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar3Comparator);
1173   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar4Comparator);
1174   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar5Comparator);
1175   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar6Comparator);
1176   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar7Comparator);
1177   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar8Comparator);
1178   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar9Comparator);
1179   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar10Comparator);
1180   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar11Comparator);
1181   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar12Comparator);
1182 }