Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-02 23:43:20

0001 #include "TArrow.h"
0002 #include "TCanvas.h"
0003 #include "TGraph.h"
0004 #include "TH1.h"
0005 #include "TH2.h"
0006 #include "TH2Poly.h"
0007 #include "TLatex.h"
0008 #include "TStyle.h"
0009 
0010 #include <fmt/printf.h>
0011 #include <fstream>
0012 #include <memory>
0013 #include <boost/tokenizer.hpp>
0014 #include <boost/range/adaptor/indexed.hpp>
0015 
0016 #include "FWCore/ParameterSet/interface/FileInPath.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0019 #include "DQM/TrackerRemapper/interface/Phase1PixelSummaryMap.h"
0020 
0021 // set option, but only if not already set
0022 //============================================================================
0023 void Phase1PixelSummaryMap::resetOption(const char* option) {
0024   if (m_option != nullptr && !m_option[0]) {
0025     m_option = option;
0026   } else {
0027     edm::LogError("Phase1PixelSummaryMap")
0028         << "Option has already been set to " << m_option << ". It's not possible to reset it.";
0029   }
0030 }
0031 
0032 //============================================================================
0033 void Phase1PixelSummaryMap::createTrackerBaseMap() {
0034   m_BaseTrackerMap = std::make_shared<TH2Poly>("Summary", "", -10, 160, -70, 70);
0035   m_BaseTrackerMap->SetFloat(true);
0036   m_BaseTrackerMap->GetXaxis()->SetTitle("");
0037   m_BaseTrackerMap->GetYaxis()->SetTitle("");
0038   m_BaseTrackerMap->GetZaxis()->SetTitle(m_zAxisTitle.c_str());
0039   m_BaseTrackerMap->GetZaxis()->CenterTitle();
0040   m_BaseTrackerMap->GetZaxis()->SetTitleOffset(1.2);
0041   m_BaseTrackerMap->SetOption("COLZ L");
0042   m_BaseTrackerMap->SetStats(false);
0043 
0044   //BARREL FIRST
0045   for (unsigned int i = 0; i < maxPxBarrel; i++) {
0046     LOGINFO("Phase1PixelSummaryMap") << "barrel, shift: " << i << " corner: " << i << std::endl;
0047     LOGINFO("Phase1PixelSummaryMap") << "translate x: " << 0 << std::endl;
0048     LOGINFO("Phase1PixelSummaryMap") << "translate y: " << barrelLadderShift[i] << std::endl;
0049 
0050     int currBarrelTranslateX = 0;
0051     int currBarrelTranslateY = barrelLadderShift[i];
0052     addNamedBins(m_cornersBPIX[i], currBarrelTranslateX, currBarrelTranslateY, 1, 1, true);
0053   }
0054 
0055   //MINUS FORWARD
0056   for (int j : {-3, -2, -1}) {
0057     LOGINFO("Phase1PixelSummaryMap") << "negative fwd, shift: " << -j - 1 << " corner: " << maxPxForward + j
0058                                      << std::endl;
0059     LOGINFO("Phase1PixelSummaryMap") << "translate x: " << forwardDiskXShift[-j - 1] << std::endl;
0060     LOGINFO("Phase1PixelSummaryMap") << "translate y: " << -forwardDiskYShift << std::endl;
0061 
0062     int currForwardTranslateX = forwardDiskXShift[-j - 1];
0063     int currForwardTranslateY = -forwardDiskYShift;
0064     addNamedBins(m_cornersFPIX[maxPxForward + j], currForwardTranslateX, currForwardTranslateY, 1, 1);
0065   }
0066 
0067   //PLUS FORWARD
0068   for (int k : {1, 2, 3}) {
0069     LOGINFO("Phase1PixelSummaryMap") << "positive fwd, shift: " << k << " corner: " << maxPxForward + k - 1
0070                                      << std::endl;
0071     LOGINFO("Phase1PixelSummaryMap") << "translate x: " << forwardDiskXShift[k - 1] << std::endl;
0072     LOGINFO("Phase1PixelSummaryMap") << "translate y: " << forwardDiskYShift << std::endl;
0073 
0074     int currForwardTranslateX = forwardDiskXShift[k - 1];
0075     int currForwardTranslateY = forwardDiskYShift;
0076     addNamedBins(m_cornersFPIX[maxPxForward + k - 1], currForwardTranslateX, currForwardTranslateY, 1, 1);
0077   }
0078 
0079   edm::LogPrint("Phase1PixelSummaryMap") << "Base Tracker Map: constructed" << std::endl;
0080   return;
0081 }
0082 
0083 //============================================================================
0084 void Phase1PixelSummaryMap::printTrackerMap(TCanvas& canvas, const float topMargin) {
0085   //canvas = TCanvas("c1","c1",plotWidth,plotHeight);
0086   canvas.cd();
0087   canvas.SetTopMargin(topMargin);
0088   canvas.SetBottomMargin(0.02);
0089   canvas.SetLeftMargin(0.02);
0090   canvas.SetRightMargin(0.14);
0091   m_BaseTrackerMap->Draw("AL");
0092   m_BaseTrackerMap->Draw("AC COLZ0 L SAME");
0093 
0094   //### z arrow
0095   arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02, "|>");
0096   arrow.SetLineWidth(4);
0097   arrow.Draw();
0098   arrow.SetAngle(30);
0099   //### phi arrow
0100   phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02, "|>");
0101   phiArrow.SetLineWidth(4);
0102   phiArrow.Draw();
0103   phiArrow.SetAngle(30);
0104   //### x arrow
0105   xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02, "|>");
0106   xArrow.SetLineWidth(4);
0107   xArrow.Draw();
0108   xArrow.SetAngle(30);
0109   //### y arrow
0110   yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02, "|>");
0111   yArrow.SetLineWidth(4);
0112   yArrow.Draw();
0113   yArrow.SetAngle(30);
0114 
0115   //###################################################
0116   //# add some captions
0117   auto txt = TLatex();
0118   txt.SetNDC();
0119   txt.SetTextFont(1);
0120   txt.SetTextColor(1);
0121   txt.SetTextAlign(22);
0122   txt.SetTextAngle(0);
0123 
0124   //# draw new-style title
0125   txt.SetTextSize((topMargin == 0.02) ? 0.05 : 0.03);
0126   txt.DrawLatex(0.5, 0.95, (fmt::sprintf("Pixel Tracker Map: %s", m_title)).c_str());
0127   txt.SetTextSize(0.03);
0128 
0129   txt.DrawLatex(0.55, 0.125, "-DISK");
0130   txt.DrawLatex(0.55, 0.875, "+DISK");
0131 
0132   txt.DrawLatex(0.08, 0.28, "+z");
0133   txt.DrawLatex(0.25, 0.70, "+phi");
0134   txt.DrawLatex(0.31, 0.78, "+x");
0135   txt.DrawLatex(0.21, 0.96, "+y");
0136 
0137   txt.SetTextAngle(90);
0138   txt.DrawLatex(0.04, 0.5, "BARREL");
0139 
0140   edm::LogPrint("Phase1PixelSummaryMap") << "Base Tracker Map: printed" << std::endl;
0141 }
0142 
0143 //============================================================================
0144 bool Phase1PixelSummaryMap::fillTrackerMap(unsigned int id, double value) {
0145   auto detid = DetId(id);
0146   if (detid.subdetId() != PixelSubdetector::PixelBarrel && detid.subdetId() != PixelSubdetector::PixelEndcap) {
0147     edm::LogError("Phase1PixelSummaryMap")
0148         << __func__ << " The following detid " << id << " is not Pixel!" << std::endl;
0149     return false;
0150   } else {
0151     m_BaseTrackerMap->Fill(TString::Format("%u", id), value);
0152     return true;
0153   }
0154 }
0155 
0156 //============================================================================
0157 void Phase1PixelSummaryMap::addNamedBins(
0158     edm::FileInPath geoFile, int tX, int tY, int sX, int sY, bool applyModuleRotation) {
0159   auto cornerFileName = geoFile.fullPath();
0160   std::ifstream cornerFile(cornerFileName.c_str());
0161   if (!cornerFile.good()) {
0162     throw cms::Exception("FileError") << "Problem opening corner file: " << cornerFileName;
0163   }
0164   std::string line;
0165   while (std::getline(cornerFile, line)) {
0166     if (!line.empty()) {
0167       std::istringstream iss(line);
0168 
0169       auto tokens = Ph1PMapSummaryHelper::tokenize(line, '"');
0170       // Printing the token vector
0171       for (unsigned int i = 0; i < tokens.size(); i++)
0172         LOGDEBUG("Phase1PixelSummaryMap") << tokens[i] << '\n';
0173 
0174       auto detInfo = Ph1PMapSummaryHelper::tokenize(tokens[0], ' ');
0175       unsigned int detId = stoi(detInfo[0]);
0176       std::string detIdName = detInfo[1];
0177       auto xy = Ph1PMapSummaryHelper::tokenize(tokens[1], ' ');
0178       unsigned int verNum = 1;
0179       std::vector<float> xP, yP;
0180       for (const auto& coord : xy) {
0181         auto coordSpl = Ph1PMapSummaryHelper::tokenize(coord, ',');
0182         if (applyModuleRotation) {
0183           xP.push_back(-(std::stof(coordSpl[0]) * sX + tX));
0184           yP.push_back(((std::stof(coordSpl[1]) * sY + tY)));
0185         } else {
0186           xP.push_back(std::stof(coordSpl[0]) * sX + tX);
0187           yP.push_back(std::stof(coordSpl[1]) * sY + tY);
0188         }
0189         verNum++;
0190       }
0191       //close the polygon
0192       xP.push_back(xP[0]);
0193       yP.push_back(yP[0]);
0194 
0195       LOGDEBUG("Phase1PixelSummaryMap") << detId << "[";
0196       for (const auto& p : xP) {
0197         LOGDEBUG("Phase1PixelSummaryMap") << p << ",";
0198       }
0199       LOGDEBUG("Phase1PixelSummaryMap") << "] [ ";
0200       for (const auto& q : yP) {
0201         LOGDEBUG("Phase1PixelSummaryMap") << q << ",";
0202       }
0203       LOGDEBUG("Phase1PixelSummaryMap") << "]" << std::endl;
0204 
0205       const unsigned int N = verNum;
0206       if (applyModuleRotation) {
0207         bins[detId] = std::make_shared<TGraph>(N, &yP[0], &xP[0]);
0208       } else {
0209         bins[detId] = std::make_shared<TGraph>(N, &xP[0], &yP[0]);
0210         //bins[detId] = std::make_shared<TGraph>(N, &yP[0], &xP[0]); // rotation by 90 deg (so that it had the same layout as for the strips)
0211       }
0212 
0213       bins[detId]->SetName(detInfo[0].c_str());
0214       m_BaseTrackerMap->AddBin(bins[detId]->Clone());
0215     }
0216   }
0217   return;
0218 }