Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:19

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 #include <memory>
0031 #include <sstream>
0032 #include <iostream>
0033 
0034 // include ROOT
0035 #include "TGaxis.h"
0036 #include "TH2F.h"
0037 #include "TLegend.h"
0038 #include "TCanvas.h"
0039 #include "TLine.h"
0040 #include "TStyle.h"
0041 #include "TLatex.h"
0042 #include "TPave.h"
0043 #include "TPaveStats.h"
0044 
0045 namespace {
0046 
0047   using namespace cond::payloadInspector;
0048 
0049   class TrackerSurfaceDeformationsTest : public Histogram1D<AlignmentSurfaceDeformations, SINGLE_IOV> {
0050   public:
0051     TrackerSurfaceDeformationsTest()
0052         : Histogram1D<AlignmentSurfaceDeformations, SINGLE_IOV>(
0053               "TrackerSurfaceDeformationsTest", "TrackerSurfaceDeformationsTest", 2, 0.0, 2.0) {}
0054 
0055     bool fill() override {
0056       auto tag = PlotBase::getTag<0>();
0057       for (auto const &iov : tag.iovs) {
0058         std::shared_ptr<AlignmentSurfaceDeformations> payload = Base::fetchPayload(std::get<1>(iov));
0059         if (payload.get()) {
0060           int i = 0;
0061           auto listOfItems = payload->items();
0062           COUT << "items size:" << listOfItems.size() << std::endl;
0063 
0064           for (const auto &item : listOfItems) {
0065             COUT << i << " " << item.m_rawId << " Det: " << DetId(item.m_rawId).subdetId() << " " << item.m_index
0066                  << std::endl;
0067             const auto beginEndPair = payload->parameters(i);
0068             std::vector<align::Scalar> params(beginEndPair.first, beginEndPair.second);
0069             COUT << "params.size()" << params.size() << std::endl;
0070             for (const auto &par : params) {
0071               COUT << par << std::endl;
0072             }
0073             i++;
0074           }
0075 
0076         }  // payload
0077       }    // iovs
0078       return true;
0079     }  // fill
0080   };
0081 
0082   //*******************************************************
0083   // Summary of the parameters for each partition for 1 IOV
0084   //*******************************************************
0085 
0086   template <AlignmentPI::partitions q>
0087   class TrackerAlignmentSurfaceDeformationsSummary : public PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV> {
0088   public:
0089     TrackerAlignmentSurfaceDeformationsSummary()
0090         : PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV>("Details for " + AlignmentPI::getStringFromPart(q)) {}
0091 
0092     bool fill() override {
0093       auto tag = PlotBase::getTag<0>();
0094       auto iov = tag.iovs.front();
0095       std::shared_ptr<AlignmentSurfaceDeformations> payload = fetchPayload(std::get<1>(iov));
0096       auto listOfItems = payload->items();
0097 
0098       int canvas_w = (q <= 4) ? 1200 : 1800;
0099       std::pair<int, int> divisions = (q <= 4) ? std::make_pair(3, 1) : std::make_pair(7, 2);
0100 
0101       TCanvas canvas("Summary", "Summary", canvas_w, 600);
0102       canvas.Divide(divisions.first, divisions.second);
0103 
0104       std::array<std::unique_ptr<TH1F>, 14> summaries;
0105       for (int nPar = 0; nPar < 14; nPar++) {
0106         summaries[nPar] =
0107             std::make_unique<TH1F>(Form("h_summary_%i", nPar),
0108                                    Form("Surface Deformation parameter %i;parameter %i size;# modules", nPar, nPar),
0109                                    100,
0110                                    -0.1,
0111                                    0.1);
0112       }
0113 
0114       int i = 0;
0115       for (const auto &item : listOfItems) {
0116         int subid = DetId(item.m_rawId).subdetId();
0117         auto thePart = static_cast<AlignmentPI::partitions>(subid);
0118 
0119         const auto beginEndPair = payload->parameters(i);
0120         std::vector<align::Scalar> params(beginEndPair.first, beginEndPair.second);
0121 
0122         // increase the counter before continuing if partition doesn't match,
0123         // otherwise the cound of the parameter count gets altered
0124         i++;
0125 
0126         // return if not the right partition
0127         if (thePart != q)
0128           continue;
0129         int nPar = 0;
0130 
0131         for (const auto &par : params) {
0132           summaries[nPar]->Fill(par);
0133           nPar++;
0134         }  // ends loop on the parameters
0135       }    // ends loop on the item vector
0136 
0137       TLatex t1;
0138 
0139       for (int c = 1; c <= (divisions.first * divisions.second); c++) {
0140         canvas.cd(c)->SetLogy();
0141         canvas.cd(c)->SetTopMargin(0.02);
0142         canvas.cd(c)->SetBottomMargin(0.15);
0143         canvas.cd(c)->SetLeftMargin(0.14);
0144         canvas.cd(c)->SetRightMargin(0.03);
0145 
0146         summaries[c - 1]->SetLineWidth(2);
0147         AlignmentPI::makeNicePlotStyle(summaries[c - 1].get(), kBlack);
0148         summaries[c - 1]->Draw("same");
0149         summaries[c - 1]->SetTitle("");
0150 
0151         AlignmentPI::makeNiceStats(summaries[c - 1].get(), q, kBlack);
0152 
0153         canvas.cd(c);
0154 
0155         t1.SetTextAlign(21);
0156         t1.SetTextSize(0.06);
0157         t1.SetTextColor(kBlue);
0158         t1.DrawLatexNDC(0.32, 0.95, Form("IOV: %s ", std::to_string(std::get<0>(iov)).c_str()));
0159       }
0160 
0161       std::string fileName(m_imageFileName);
0162       canvas.SaveAs(fileName.c_str());
0163 
0164       return true;
0165     }
0166   };
0167 
0168   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::BPix> BPixSurfaceDeformationsSummary;
0169   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::FPix> FPixSurfaceDeformationsSummary;
0170   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::TIB> TIBSurfaceDeformationsSummary;
0171   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::TID> TIDSurfaceDeformationsSummary;
0172   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::TOB> TOBSurfaceDeformationsSummary;
0173   typedef TrackerAlignmentSurfaceDeformationsSummary<AlignmentPI::TEC> TECSurfaceDeformationsSummary;
0174 
0175   //*******************************************************
0176   // Comparison of the parameters for each partition for 1 IOV
0177   //*******************************************************
0178 
0179   template <AlignmentPI::partitions q>
0180   class TrackerAlignmentSurfaceDeformationsComparison : public PlotImage<AlignmentSurfaceDeformations, MULTI_IOV> {
0181   public:
0182     TrackerAlignmentSurfaceDeformationsComparison()
0183         : PlotImage<AlignmentSurfaceDeformations, MULTI_IOV>("Details for " + AlignmentPI::getStringFromPart(q)) {}
0184 
0185     bool fill() override {
0186       auto tag = PlotBase::getTag<0>();
0187       auto sorted_iovs = tag.iovs;
0188 
0189       // make absolute sure the IOVs are sortd by since
0190       std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
0191         return std::get<0>(t1) < std::get<0>(t2);
0192       });
0193 
0194       auto firstiov = sorted_iovs.front();
0195       auto lastiov = sorted_iovs.back();
0196 
0197       std::shared_ptr<AlignmentSurfaceDeformations> last_payload = fetchPayload(std::get<1>(lastiov));
0198       std::shared_ptr<AlignmentSurfaceDeformations> first_payload = fetchPayload(std::get<1>(firstiov));
0199 
0200       std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
0201       std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
0202 
0203       auto first_listOfItems = first_payload->items();
0204       auto last_listOfItems = last_payload->items();
0205 
0206       int canvas_w = (q <= 4) ? 1600 : 1800;
0207       std::pair<int, int> divisions = (q <= 4) ? std::make_pair(3, 1) : std::make_pair(7, 2);
0208 
0209       TCanvas canvas("Comparison", "Comparison", canvas_w, 600);
0210       canvas.Divide(divisions.first, divisions.second);
0211 
0212       std::array<std::unique_ptr<TH1F>, 14> deltas;
0213       for (int nPar = 0; nPar < 14; nPar++) {
0214         deltas[nPar] =
0215             std::make_unique<TH1F>(Form("h_summary_%i", nPar),
0216                                    Form("Surface Deformation #Delta parameter %i;#Deltapar_{%i};# modules", nPar, nPar),
0217                                    100,
0218                                    -0.05,
0219                                    0.05);
0220       }
0221 
0222       //assert(first_listOfItems.size() == last_listOfItems.size());
0223 
0224       for (unsigned int i = 0; i < first_listOfItems.size(); i++) {
0225         auto first_id = first_listOfItems[i].m_rawId;
0226         int subid = DetId(first_listOfItems[i].m_rawId).subdetId();
0227         auto thePart = static_cast<AlignmentPI::partitions>(subid);
0228         if (thePart != q)
0229           continue;
0230 
0231         const auto f_beginEndPair = first_payload->parameters(i);
0232         std::vector<align::Scalar> first_params(f_beginEndPair.first, f_beginEndPair.second);
0233 
0234         for (unsigned int j = 0; j < last_listOfItems.size(); j++) {
0235           auto last_id = last_listOfItems[j].m_rawId;
0236           if (first_id == last_id) {
0237             const auto l_beginEndPair = last_payload->parameters(j);
0238             std::vector<align::Scalar> last_params(l_beginEndPair.first, l_beginEndPair.second);
0239 
0240             assert(first_params.size() == last_params.size());
0241 
0242             for (unsigned int nPar = 0; nPar < first_params.size(); nPar++) {
0243               deltas[nPar]->Fill(last_params[nPar] - first_params[nPar]);
0244             }
0245             break;
0246           }
0247         }
0248 
0249       }  // ends loop on the item vector
0250 
0251       TLatex t1;
0252 
0253       for (int c = 1; c <= (divisions.first * divisions.second); c++) {
0254         canvas.cd(c)->SetLogy();
0255         canvas.cd(c)->SetTopMargin(0.015);
0256         canvas.cd(c)->SetBottomMargin(0.13);
0257         canvas.cd(c)->SetLeftMargin(0.14);
0258         canvas.cd(c)->SetRightMargin(0.03);
0259 
0260         deltas[c - 1]->SetLineWidth(2);
0261         AlignmentPI::makeNicePlotStyle(deltas[c - 1].get(), kBlack);
0262         deltas[c - 1]->Draw("same");
0263         deltas[c - 1]->SetTitle("");
0264 
0265         AlignmentPI::makeNiceStats(deltas[c - 1].get(), q, kBlack);
0266 
0267         canvas.cd(c);
0268         t1.SetTextAlign(21);
0269         t1.SetTextSize(0.045);
0270         t1.SetTextColor(kBlue);
0271         t1.DrawLatexNDC(0.4, 0.95, Form("#DeltaIOV: %s - %s ", lastIOVsince.c_str(), firstIOVsince.c_str()));
0272 
0273         if (deltas[c - 1]->GetEntries() == 0) {
0274           TLatex t2;
0275           t2.SetTextAlign(21);
0276           t2.SetTextSize(0.1);
0277           t2.SetTextAngle(45);
0278           t2.SetTextColor(kRed);
0279           t2.DrawLatexNDC(0.6, 0.50, "NO COMMON DETIDS");
0280         }
0281       }
0282 
0283       std::string fileName(m_imageFileName);
0284       canvas.SaveAs(fileName.c_str());
0285 
0286       return true;
0287     }
0288   };
0289 
0290   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::BPix> BPixSurfaceDeformationsComparison;
0291   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::FPix> FPixSurfaceDeformationsComparison;
0292   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::TIB> TIBSurfaceDeformationsComparison;
0293   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::TID> TIDSurfaceDeformationsComparison;
0294   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::TOB> TOBSurfaceDeformationsComparison;
0295   typedef TrackerAlignmentSurfaceDeformationsComparison<AlignmentPI::TEC> TECSurfaceDeformationsComparison;
0296 
0297   // /************************************************
0298   //   TrackerMap of single parameter
0299   // *************************************************/
0300   template <unsigned int par>
0301   class SurfaceDeformationTrackerMap : public PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV> {
0302   public:
0303     SurfaceDeformationTrackerMap()
0304         : PlotImage<AlignmentSurfaceDeformations, SINGLE_IOV>(
0305               "Tracker Map of Tracker Surface deformations - parameter: " + std::to_string(par)) {}
0306 
0307     bool fill() override {
0308       auto tag = PlotBase::getTag<0>();
0309       auto iov = tag.iovs.front();
0310 
0311       std::shared_ptr<AlignmentSurfaceDeformations> payload = fetchPayload(std::get<1>(iov));
0312       auto listOfItems = payload->items();
0313 
0314       std::string titleMap =
0315           "Surface deformation parameter " + std::to_string(par) + " value (payload : " + std::get<1>(iov) + ")";
0316 
0317       std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("Surface Deformations");
0318       tmap->setTitle(titleMap);
0319       tmap->setPalette(1);
0320 
0321       std::map<unsigned int, float> surfDefMap;
0322 
0323       bool isPhase0(false);
0324       if (listOfItems.size() == AlignmentPI::phase0size)
0325         isPhase0 = true;
0326 
0327       int iDet = 0;
0328       for (const auto &item : listOfItems) {
0329         // fill the tracker map
0330         int subid = DetId(item.m_rawId).subdetId();
0331 
0332         if (DetId(item.m_rawId).det() != DetId::Tracker) {
0333           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0334               << "Encountered invalid Tracker DetId:" << item.m_rawId << " - terminating ";
0335           return false;
0336         }
0337 
0338         const auto beginEndPair = payload->parameters(iDet);
0339         std::vector<align::Scalar> params(beginEndPair.first, beginEndPair.second);
0340 
0341         iDet++;
0342         // protect against exceeding the vector of parameter size
0343         if (par >= params.size())
0344           continue;
0345 
0346         if (isPhase0) {
0347           tmap->addPixel(true);
0348           tmap->fill(item.m_rawId, params.at(par));
0349           surfDefMap[item.m_rawId] = params.at(par);
0350         } else {
0351           if (subid != 1 && subid != 2) {
0352             tmap->fill(item.m_rawId, params.at(par));
0353             surfDefMap[item.m_rawId] = params.at(par);
0354           }
0355         }
0356       }  // loop over detIds
0357 
0358       //=========================
0359 
0360       // saturate at 1.5sigma
0361       auto autoRange = AlignmentPI::getTheRange(surfDefMap, 1.5);  //tmap->getAutomaticRange();
0362 
0363       std::string fileName(m_imageFileName);
0364       // protect against uniform values (Surface deformations are defined positive)
0365       if (autoRange.first != autoRange.second) {
0366         tmap->save(true, autoRange.first, autoRange.second, fileName);
0367       } else {
0368         if (autoRange.first == 0.) {
0369           tmap->save(true, 0., 1., fileName);
0370         } else {
0371           tmap->save(true, autoRange.first, autoRange.second, fileName);
0372         }
0373       }
0374 
0375       return true;
0376     }
0377   };
0378 
0379   typedef SurfaceDeformationTrackerMap<0> SurfaceDeformationParameter0TrackerMap;
0380   typedef SurfaceDeformationTrackerMap<1> SurfaceDeformationParameter1TrackerMap;
0381   typedef SurfaceDeformationTrackerMap<2> SurfaceDeformationParameter2TrackerMap;
0382   typedef SurfaceDeformationTrackerMap<3> SurfaceDeformationParameter3TrackerMap;
0383   typedef SurfaceDeformationTrackerMap<4> SurfaceDeformationParameter4TrackerMap;
0384   typedef SurfaceDeformationTrackerMap<5> SurfaceDeformationParameter5TrackerMap;
0385   typedef SurfaceDeformationTrackerMap<6> SurfaceDeformationParameter6TrackerMap;
0386   typedef SurfaceDeformationTrackerMap<7> SurfaceDeformationParameter7TrackerMap;
0387   typedef SurfaceDeformationTrackerMap<8> SurfaceDeformationParameter8TrackerMap;
0388   typedef SurfaceDeformationTrackerMap<9> SurfaceDeformationParameter9TrackerMap;
0389   typedef SurfaceDeformationTrackerMap<10> SurfaceDeformationParameter10TrackerMap;
0390   typedef SurfaceDeformationTrackerMap<11> SurfaceDeformationParameter11TrackerMap;
0391   typedef SurfaceDeformationTrackerMap<12> SurfaceDeformationParameter12TrackerMap;
0392 
0393   // /************************************************
0394   //   TrackerMap of single parameter
0395   // *************************************************/
0396   template <unsigned int m_par>
0397   class SurfaceDeformationsTkMapDelta : public PlotImage<AlignmentSurfaceDeformations, MULTI_IOV> {
0398   public:
0399     SurfaceDeformationsTkMapDelta()
0400         : PlotImage<AlignmentSurfaceDeformations, MULTI_IOV>(
0401               "Tracker Map of Tracker Surface deformations differences - parameter: " + std::to_string(m_par)) {}
0402 
0403     bool fill() override {
0404       auto tag = PlotBase::getTag<0>();
0405       auto sorted_iovs = tag.iovs;
0406 
0407       // make absolute sure the IOVs are sortd by since
0408       std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
0409         return std::get<0>(t1) < std::get<0>(t2);
0410       });
0411 
0412       auto firstiov = sorted_iovs.front();
0413       auto lastiov = sorted_iovs.back();
0414 
0415       std::shared_ptr<AlignmentSurfaceDeformations> last_payload = fetchPayload(std::get<1>(lastiov));
0416       std::shared_ptr<AlignmentSurfaceDeformations> first_payload = fetchPayload(std::get<1>(firstiov));
0417 
0418       std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
0419       std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
0420 
0421       auto first_listOfItems = first_payload->items();
0422       auto last_listOfItems = last_payload->items();
0423 
0424       std::string titleMap = "#Delta Surface deformation parameter " + std::to_string(m_par) +
0425                              " (IOV : " + std::to_string(std::get<0>(lastiov)) + "- " +
0426                              std::to_string(std::get<0>(firstiov)) + ")";
0427 
0428       std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("Surface Deformations #Delta");
0429       tmap->setTitle(titleMap);
0430       tmap->setPalette(1);
0431 
0432       std::map<unsigned int, float> f_paramsMap;
0433       std::map<unsigned int, float> l_paramsMap;
0434       std::map<unsigned int, float> surfDefMap;
0435 
0436       // check the payload sizes are matched
0437       if (first_listOfItems.size() != last_listOfItems.size()) {
0438         edm::LogInfo("TrackerSurfaceDeformations_PayloadInspector")
0439             << "(" << firstIOVsince << ") has " << first_listOfItems.size() << " DetIds - (" << lastIOVsince << ") has "
0440             << last_listOfItems.size() << " DetIds" << std::endl;
0441       };
0442 
0443       bool isPhase0(false);
0444       if (first_listOfItems.size() <= AlignmentPI::phase0size)
0445         isPhase0 = true;
0446       if (isPhase0)
0447         tmap->addPixel(true);
0448 
0449       // loop on the first payload
0450       int iDet = 0;
0451       for (const auto &f_item : first_listOfItems) {
0452         auto first_id = f_item.m_rawId;
0453 
0454         if (DetId(first_id).det() != DetId::Tracker) {
0455           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0456               << "Encountered invalid Tracker DetId:" << first_id << " - terminating ";
0457           return false;
0458         }
0459 
0460         const auto f_beginEndPair = first_payload->parameters(iDet);
0461         std::vector<align::Scalar> first_params(f_beginEndPair.first, f_beginEndPair.second);
0462 
0463         iDet++;
0464         // protect against exceeding the vector of parameter size
0465         if (m_par >= first_params.size())
0466           continue;
0467 
0468         f_paramsMap[first_id] = first_params.at(m_par);
0469       }
0470 
0471       // loop on the second payload
0472       int jDet = 0;
0473       for (const auto &l_item : last_listOfItems) {
0474         auto last_id = l_item.m_rawId;
0475 
0476         if (DetId(last_id).det() != DetId::Tracker) {
0477           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0478               << "Encountered invalid Tracker DetId:" << last_id << " - terminating ";
0479           return false;
0480         }
0481 
0482         const auto l_beginEndPair = last_payload->parameters(jDet);
0483         std::vector<align::Scalar> last_params(l_beginEndPair.first, l_beginEndPair.second);
0484 
0485         jDet++;
0486         // protect against exceeding the vector of parameter size
0487         if (m_par >= last_params.size())
0488           continue;
0489 
0490         l_paramsMap[last_id] = last_params.at(m_par);
0491       }
0492 
0493       // fill the tk map
0494       for (const auto &f_entry : f_paramsMap) {
0495         for (const auto &l_entry : l_paramsMap) {
0496           if (f_entry.first != l_entry.first)
0497             continue;
0498 
0499           int subid = DetId(f_entry.first).subdetId();
0500 
0501           float delta = (l_entry.second - f_entry.second);
0502 
0503           //COUT<<" match! subid:" << subid << " rawId:" << f_entry.first << " delta:"<< delta << std::endl;
0504 
0505           if (isPhase0) {
0506             tmap->addPixel(true);
0507             tmap->fill(f_entry.first, delta);
0508             surfDefMap[f_entry.first] = delta;
0509           } else {
0510             // fill pixel map only for phase-0 (in lack of a dedicate phase-I map)
0511             if (subid != 1 && subid != 2) {
0512               tmap->fill(f_entry.first, delta);
0513               surfDefMap[f_entry.first] = delta;
0514             }
0515           }  // if not phase-0
0516         }    // loop on the last payload map
0517       }      // loop on the first payload map
0518 
0519       //=========================
0520 
0521       if (surfDefMap.empty()) {
0522         edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector") << "No common DetIds have been found!!! ";
0523         tmap->fillc_all_blank();
0524         tmap->setTitle("NO COMMON DETIDS (IOV : " + std::to_string(std::get<0>(lastiov)) + "- " +
0525                        std::to_string(std::get<0>(firstiov)) + ")");
0526       }
0527 
0528       // saturate at 1.5sigma
0529       auto autoRange = AlignmentPI::getTheRange(surfDefMap, 1.5);  //tmap->getAutomaticRange();
0530 
0531       std::string fileName(m_imageFileName);
0532       // protect against uniform values (Surface deformations are defined positive)
0533       if (autoRange.first != autoRange.second) {
0534         tmap->save(true, autoRange.first, autoRange.second, fileName);
0535       } else {
0536         if (autoRange.first == 0.) {
0537           tmap->save(true, 0., 1., fileName);
0538         } else {
0539           tmap->save(true, autoRange.first, autoRange.second, fileName);
0540         }
0541       }
0542 
0543       return true;
0544     }
0545   };
0546 
0547   typedef SurfaceDeformationsTkMapDelta<0> SurfaceDeformationParameter0TkMapDelta;
0548   typedef SurfaceDeformationsTkMapDelta<1> SurfaceDeformationParameter1TkMapDelta;
0549   typedef SurfaceDeformationsTkMapDelta<2> SurfaceDeformationParameter2TkMapDelta;
0550   typedef SurfaceDeformationsTkMapDelta<3> SurfaceDeformationParameter3TkMapDelta;
0551   typedef SurfaceDeformationsTkMapDelta<4> SurfaceDeformationParameter4TkMapDelta;
0552   typedef SurfaceDeformationsTkMapDelta<5> SurfaceDeformationParameter5TkMapDelta;
0553   typedef SurfaceDeformationsTkMapDelta<6> SurfaceDeformationParameter6TkMapDelta;
0554   typedef SurfaceDeformationsTkMapDelta<7> SurfaceDeformationParameter7TkMapDelta;
0555   typedef SurfaceDeformationsTkMapDelta<8> SurfaceDeformationParameter8TkMapDelta;
0556   typedef SurfaceDeformationsTkMapDelta<9> SurfaceDeformationParameter9TkMapDelta;
0557   typedef SurfaceDeformationsTkMapDelta<10> SurfaceDeformationParameter10TkMapDelta;
0558   typedef SurfaceDeformationsTkMapDelta<11> SurfaceDeformationParameter11TkMapDelta;
0559   typedef SurfaceDeformationsTkMapDelta<12> SurfaceDeformationParameter12TkMapDelta;
0560 
0561   // /************************************************
0562   //  Tracker Surface Deformations grand summary comparison of 2 IOVs
0563   // *************************************************/
0564 
0565   template <unsigned int m_par>
0566   class TrackerSurfaceDeformationsComparator : public PlotImage<AlignmentSurfaceDeformations, MULTI_IOV> {
0567   public:
0568     TrackerSurfaceDeformationsComparator()
0569         : PlotImage<AlignmentSurfaceDeformations, MULTI_IOV>("Summary per Tracker region of parameter " +
0570                                                              std::to_string(m_par) + " of Surface Deformations") {}
0571 
0572     bool fill() override {
0573       auto tag = PlotBase::getTag<0>();
0574       auto sorted_iovs = tag.iovs;
0575 
0576       TGaxis::SetMaxDigits(3);
0577       gStyle->SetPaintTextFormat(".1f");
0578 
0579       // make absolute sure the IOVs are sortd by since
0580       std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
0581         return std::get<0>(t1) < std::get<0>(t2);
0582       });
0583 
0584       auto firstiov = sorted_iovs.front();
0585       auto lastiov = sorted_iovs.back();
0586 
0587       std::shared_ptr<AlignmentSurfaceDeformations> last_payload = fetchPayload(std::get<1>(lastiov));
0588       std::shared_ptr<AlignmentSurfaceDeformations> first_payload = fetchPayload(std::get<1>(firstiov));
0589 
0590       std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
0591       std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
0592 
0593       auto first_listOfItems = first_payload->items();
0594       auto last_listOfItems = last_payload->items();
0595 
0596       TCanvas canvas("Comparison", "Comparison", 1600, 800);
0597 
0598       std::map<AlignmentPI::regions, std::shared_ptr<TH1F> > FirstSurfDef_spectraByRegion;
0599       std::map<AlignmentPI::regions, std::shared_ptr<TH1F> > LastSurfDef_spectraByRegion;
0600       std::shared_ptr<TH1F> summaryFirst;
0601       std::shared_ptr<TH1F> summaryLast;
0602 
0603       // book the intermediate histograms
0604       for (int r = AlignmentPI::BPixL1o; r != AlignmentPI::StripDoubleSide; r++) {
0605         AlignmentPI::regions part = static_cast<AlignmentPI::regions>(r);
0606         std::string s_part = AlignmentPI::getStringFromRegionEnum(part);
0607 
0608         FirstSurfDef_spectraByRegion[part] =
0609             std::make_shared<TH1F>(Form("hfirstSurfDef_%i_%s", m_par, s_part.c_str()),
0610                                    Form(";%s SurfDef parameter %i;n. of modules", s_part.c_str(), m_par),
0611                                    10000,
0612                                    -1,
0613                                    1.);
0614         LastSurfDef_spectraByRegion[part] =
0615             std::make_shared<TH1F>(Form("hlastSurfDef_%i_%s", m_par, s_part.c_str()),
0616                                    Form(";%s SurfDef parameter %i;n. of modules", s_part.c_str(), m_par),
0617                                    10000,
0618                                    -1.,
0619                                    1.);
0620       }
0621 
0622       summaryFirst = std::make_shared<TH1F>(
0623           Form("first Summary_%i", m_par),
0624           Form("Summary for parameter %i Surface Deformation;;Surface Deformation paramter %i", m_par, m_par),
0625           FirstSurfDef_spectraByRegion.size(),
0626           0,
0627           FirstSurfDef_spectraByRegion.size());
0628       summaryLast = std::make_shared<TH1F>(
0629           Form("last Summary_%i", m_par),
0630           Form("Summary for parameter %i Surface Deformation;;Surface Deformation paramter %i", m_par, m_par),
0631           LastSurfDef_spectraByRegion.size(),
0632           0,
0633           LastSurfDef_spectraByRegion.size());
0634 
0635       // N.B. <= and not == because the list of surface deformations might not include all tracker modules
0636       const char *path_toTopologyXML = (first_listOfItems.size() <= AlignmentPI::phase0size)
0637                                            ? "Geometry/TrackerCommonData/data/trackerParameters.xml"
0638                                            : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
0639       const char *alternative_path_toTopologyXML = (first_listOfItems.size() <= AlignmentPI::phase0size)
0640                                                        ? "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"
0641                                                        : "Geometry/TrackerCommonData/data/trackerParameters.xml";
0642       TrackerTopology f_tTopo =
0643           StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath());
0644       TrackerTopology af_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0645           edm::FileInPath(alternative_path_toTopologyXML).fullPath());
0646 
0647       bool isPhase0(false);
0648       if (first_listOfItems.size() <= AlignmentPI::phase0size)
0649         isPhase0 = true;
0650 
0651       // -------------------------------------------------------------------
0652       // loop on the first vector of errors
0653       // -------------------------------------------------------------------
0654       int iDet = 0;
0655       for (const auto &it : first_listOfItems) {
0656         if (DetId(it.m_rawId).det() != DetId::Tracker) {
0657           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0658               << "Encountered invalid Tracker DetId:" << it.m_rawId << " - terminating ";
0659           return false;
0660         }
0661 
0662         AlignmentPI::topolInfo t_info_fromXML;
0663         t_info_fromXML.init();
0664         DetId detid(it.m_rawId);
0665         t_info_fromXML.fillGeometryInfo(detid, f_tTopo, isPhase0);
0666 
0667         //COUT<<"sanityCheck: "<< t_info_fromXML.sanityCheck() << std::endl;
0668 
0669         if (!t_info_fromXML.sanityCheck()) {
0670           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0671               << "Wrong choice of Tracker Topology encountered for DetId:" << it.m_rawId << " ---> changing";
0672           t_info_fromXML.init();
0673           t_info_fromXML.fillGeometryInfo(detid, af_tTopo, !isPhase0);
0674         }
0675 
0676         //t_info_fromXML.printAll();
0677 
0678         AlignmentPI::regions thePart = t_info_fromXML.filterThePartition();
0679 
0680         // skip the glued detector detIds
0681         if (thePart == AlignmentPI::StripDoubleSide)
0682           continue;
0683 
0684         const auto f_beginEndPair = first_payload->parameters(iDet);
0685         std::vector<align::Scalar> first_params(f_beginEndPair.first, f_beginEndPair.second);
0686 
0687         iDet++;
0688         // protect against exceeding the vector of parameter size
0689         if (m_par >= first_params.size())
0690           continue;
0691 
0692         FirstSurfDef_spectraByRegion[thePart]->Fill(first_params.at(m_par));
0693         //COUT<<  getStringFromRegionEnum(thePart) << " first payload: "<< first_params.at(m_par) << std::endl;
0694 
0695       }  // ends loop on the vector of error transforms
0696 
0697       // N.B. <= and not == because the list of surface deformations might not include all tracker modules
0698       path_toTopologyXML = (last_listOfItems.size() <= AlignmentPI::phase0size)
0699                                ? "Geometry/TrackerCommonData/data/trackerParameters.xml"
0700                                : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
0701       alternative_path_toTopologyXML = (first_listOfItems.size() <= AlignmentPI::phase0size)
0702                                            ? "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"
0703                                            : "Geometry/TrackerCommonData/data/trackerParameters.xml";
0704       TrackerTopology l_tTopo =
0705           StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath());
0706       TrackerTopology al_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0707           edm::FileInPath(alternative_path_toTopologyXML).fullPath());
0708 
0709       if (last_listOfItems.size() <= AlignmentPI::phase0size)
0710         isPhase0 = true;
0711 
0712       // -------------------------------------------------------------------
0713       // loop on the second vector of errors
0714       // -------------------------------------------------------------------
0715       int jDet = 0;
0716       for (const auto &it : last_listOfItems) {
0717         if (DetId(it.m_rawId).det() != DetId::Tracker) {
0718           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0719               << "Encountered invalid Tracker DetId:" << it.m_rawId << " - terminating ";
0720           return false;
0721         }
0722 
0723         AlignmentPI::topolInfo t_info_fromXML;
0724         t_info_fromXML.init();
0725         DetId detid(it.m_rawId);
0726         t_info_fromXML.fillGeometryInfo(detid, l_tTopo, isPhase0);
0727 
0728         //COUT<<"sanityCheck: "<< t_info_fromXML.sanityCheck() << std::endl;
0729 
0730         if (!t_info_fromXML.sanityCheck()) {
0731           edm::LogWarning("TrackerSurfaceDeformations_PayloadInspector")
0732               << "Wrong choice of Tracker Topology encountered for DetId:" << it.m_rawId << " ---> changing";
0733           t_info_fromXML.init();
0734           isPhase0 = !isPhase0;
0735           t_info_fromXML.fillGeometryInfo(detid, al_tTopo, !isPhase0);
0736         }
0737 
0738         //t_info_fromXML.printAll();
0739 
0740         AlignmentPI::regions thePart = t_info_fromXML.filterThePartition();
0741 
0742         // skip the glued detector detIds
0743         if (thePart == AlignmentPI::StripDoubleSide)
0744           continue;
0745 
0746         const auto l_beginEndPair = last_payload->parameters(jDet);
0747         std::vector<align::Scalar> last_params(l_beginEndPair.first, l_beginEndPair.second);
0748 
0749         jDet++;
0750         // protect against exceeding the vector of parameter size
0751         if (m_par >= last_params.size())
0752           continue;
0753 
0754         LastSurfDef_spectraByRegion[thePart]->Fill(last_params.at(m_par));
0755         //COUT<< getStringFromRegionEnum(thePart) <<  " last payload: "<< last_params.at(m_par) << std::endl;
0756 
0757       }  // ends loop on the vector of error transforms
0758 
0759       // fill the summary plots
0760       int bin = 1;
0761       for (int r = AlignmentPI::BPixL1o; r != AlignmentPI::StripDoubleSide; r++) {
0762         AlignmentPI::regions part = static_cast<AlignmentPI::regions>(r);
0763 
0764         summaryFirst->GetXaxis()->SetBinLabel(bin, AlignmentPI::getStringFromRegionEnum(part).c_str());
0765         // avoid filling the histogram with numerical noise
0766         float f_mean = FirstSurfDef_spectraByRegion[part]->GetMean();
0767         summaryFirst->SetBinContent(bin, f_mean);
0768         //summaryFirst->SetBinError(bin, FirstSurfDef_spectraByRegion[part]->GetRMS());
0769 
0770         summaryLast->GetXaxis()->SetBinLabel(bin, AlignmentPI::getStringFromRegionEnum(part).c_str());
0771         // avoid filling the histogram with numerical noise
0772         float l_mean = LastSurfDef_spectraByRegion[part]->GetMean();
0773         summaryLast->SetBinContent(bin, l_mean);
0774         //summaryLast->SetBinError(bin,LastSurfDef_spectraByRegion[part]->GetRMS());
0775         bin++;
0776       }
0777 
0778       AlignmentPI::makeNicePlotStyle(summaryFirst.get(), kBlue);
0779       summaryFirst->SetMarkerColor(kBlue);
0780       summaryFirst->GetXaxis()->LabelsOption("v");
0781       summaryFirst->GetXaxis()->SetLabelSize(0.05);
0782       summaryFirst->GetYaxis()->SetTitleOffset(0.9);
0783 
0784       AlignmentPI::makeNicePlotStyle(summaryLast.get(), kRed);
0785       summaryLast->SetMarkerColor(kRed);
0786       summaryLast->GetYaxis()->SetTitleOffset(0.9);
0787       summaryLast->GetXaxis()->LabelsOption("v");
0788       summaryLast->GetXaxis()->SetLabelSize(0.05);
0789 
0790       canvas.cd()->SetGridy();
0791 
0792       canvas.SetBottomMargin(0.18);
0793       canvas.SetLeftMargin(0.11);
0794       canvas.SetRightMargin(0.02);
0795       canvas.Modified();
0796 
0797       summaryFirst->SetFillColor(kBlue);
0798       summaryLast->SetFillColor(kRed);
0799 
0800       summaryFirst->SetBarWidth(0.45);
0801       summaryFirst->SetBarOffset(0.1);
0802 
0803       summaryLast->SetBarWidth(0.4);
0804       summaryLast->SetBarOffset(0.55);
0805 
0806       float max = (summaryFirst->GetMaximum() > summaryLast->GetMaximum()) ? summaryFirst->GetMaximum()
0807                                                                            : summaryLast->GetMaximum();
0808       float min = (summaryFirst->GetMinimum() < summaryLast->GetMinimum()) ? summaryFirst->GetMinimum()
0809                                                                            : summaryLast->GetMinimum();
0810 
0811       summaryFirst->GetYaxis()->SetRangeUser(min * 1.20, max * 1.40);
0812       summaryFirst->Draw("b");
0813       //summaryFirst->Draw("text90same");
0814       summaryLast->Draw("b,same");
0815       //summaryLast->Draw("text180same");
0816 
0817       TLegend legend = TLegend(0.52, 0.82, 0.98, 0.9);
0818       legend.SetHeader(("Surface Deformation par " + std::to_string(m_par) + " comparison").c_str(),
0819                        "C");  // option "C" allows to center the header
0820       legend.AddEntry(
0821           summaryLast.get(),
0822           ("IOV:  #scale[1.2]{" + std::to_string(std::get<0>(lastiov)) + "} | #color[2]{" + std::get<1>(lastiov) + "}")
0823               .c_str(),
0824           "F");
0825       legend.AddEntry(summaryFirst.get(),
0826                       ("IOV:  #scale[1.2]{" + std::to_string(std::get<0>(firstiov)) + "} | #color[4]{" +
0827                        std::get<1>(firstiov) + "}")
0828                           .c_str(),
0829                       "F");
0830       legend.SetTextSize(0.025);
0831       legend.Draw("same");
0832 
0833       std::string fileName(m_imageFileName);
0834       canvas.SaveAs(fileName.c_str());
0835 
0836       return true;
0837 
0838     }  // ends fill method
0839   };
0840 
0841   typedef TrackerSurfaceDeformationsComparator<0> TrackerSurfaceDeformationsPar0Comparator;
0842   typedef TrackerSurfaceDeformationsComparator<1> TrackerSurfaceDeformationsPar1Comparator;
0843   typedef TrackerSurfaceDeformationsComparator<2> TrackerSurfaceDeformationsPar2Comparator;
0844   typedef TrackerSurfaceDeformationsComparator<3> TrackerSurfaceDeformationsPar3Comparator;
0845   typedef TrackerSurfaceDeformationsComparator<4> TrackerSurfaceDeformationsPar4Comparator;
0846   typedef TrackerSurfaceDeformationsComparator<5> TrackerSurfaceDeformationsPar5Comparator;
0847   typedef TrackerSurfaceDeformationsComparator<6> TrackerSurfaceDeformationsPar6Comparator;
0848   typedef TrackerSurfaceDeformationsComparator<7> TrackerSurfaceDeformationsPar7Comparator;
0849   typedef TrackerSurfaceDeformationsComparator<8> TrackerSurfaceDeformationsPar8Comparator;
0850   typedef TrackerSurfaceDeformationsComparator<9> TrackerSurfaceDeformationsPar9Comparator;
0851   typedef TrackerSurfaceDeformationsComparator<10> TrackerSurfaceDeformationsPar10Comparator;
0852   typedef TrackerSurfaceDeformationsComparator<11> TrackerSurfaceDeformationsPar11Comparator;
0853   typedef TrackerSurfaceDeformationsComparator<12> TrackerSurfaceDeformationsPar12Comparator;
0854 
0855 }  // namespace
0856 
0857 PAYLOAD_INSPECTOR_MODULE(TrackerSurfaceDeformations) {
0858   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsTest);
0859   PAYLOAD_INSPECTOR_CLASS(BPixSurfaceDeformationsSummary);
0860   PAYLOAD_INSPECTOR_CLASS(FPixSurfaceDeformationsSummary);
0861   PAYLOAD_INSPECTOR_CLASS(TIBSurfaceDeformationsSummary);
0862   PAYLOAD_INSPECTOR_CLASS(TIDSurfaceDeformationsSummary);
0863   PAYLOAD_INSPECTOR_CLASS(TOBSurfaceDeformationsSummary);
0864   PAYLOAD_INSPECTOR_CLASS(TECSurfaceDeformationsSummary);
0865   PAYLOAD_INSPECTOR_CLASS(BPixSurfaceDeformationsComparison);
0866   PAYLOAD_INSPECTOR_CLASS(FPixSurfaceDeformationsComparison);
0867   PAYLOAD_INSPECTOR_CLASS(TIBSurfaceDeformationsComparison);
0868   PAYLOAD_INSPECTOR_CLASS(TIDSurfaceDeformationsComparison);
0869   PAYLOAD_INSPECTOR_CLASS(TOBSurfaceDeformationsComparison);
0870   PAYLOAD_INSPECTOR_CLASS(TECSurfaceDeformationsComparison);
0871   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter0TrackerMap);
0872   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter1TrackerMap);
0873   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter2TrackerMap);
0874   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter3TrackerMap);
0875   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter4TrackerMap);
0876   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter5TrackerMap);
0877   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter6TrackerMap);
0878   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter7TrackerMap);
0879   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter8TrackerMap);
0880   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter9TrackerMap);
0881   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter10TrackerMap);
0882   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter11TrackerMap);
0883   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter12TrackerMap);
0884   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter0TkMapDelta);
0885   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter1TkMapDelta);
0886   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter2TkMapDelta);
0887   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter3TkMapDelta);
0888   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter4TkMapDelta);
0889   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter5TkMapDelta);
0890   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter6TkMapDelta);
0891   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter7TkMapDelta);
0892   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter8TkMapDelta);
0893   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter9TkMapDelta);
0894   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter10TkMapDelta);
0895   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter11TkMapDelta);
0896   PAYLOAD_INSPECTOR_CLASS(SurfaceDeformationParameter12TkMapDelta);
0897   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar0Comparator);
0898   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar1Comparator);
0899   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar2Comparator);
0900   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar3Comparator);
0901   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar4Comparator);
0902   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar5Comparator);
0903   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar6Comparator);
0904   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar7Comparator);
0905   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar8Comparator);
0906   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar9Comparator);
0907   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar10Comparator);
0908   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar11Comparator);
0909   PAYLOAD_INSPECTOR_CLASS(TrackerSurfaceDeformationsPar12Comparator);
0910 }