File indexing completed on 2024-04-06 12:09:04
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
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
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
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
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, int index) {
0085
0086 if (index != 0)
0087 canvas.cd(index);
0088 else
0089 canvas.cd();
0090
0091 if (index == 0) {
0092 canvas.SetTopMargin(topMargin);
0093 canvas.SetBottomMargin(0.02);
0094 canvas.SetLeftMargin(0.02);
0095 canvas.SetRightMargin(0.14);
0096 } else {
0097 m_BaseTrackerMap->GetZaxis()->SetTitleOffset(1.5);
0098 canvas.cd(index)->SetTopMargin(topMargin);
0099 canvas.cd(index)->SetBottomMargin(0.02);
0100 canvas.cd(index)->SetLeftMargin(0.02);
0101 canvas.cd(index)->SetRightMargin(0.14);
0102 }
0103
0104 m_BaseTrackerMap->Draw("AL");
0105 m_BaseTrackerMap->Draw("AC COLZ0 L SAME");
0106
0107
0108 arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02, "|>");
0109 arrow.SetLineWidth(4);
0110 arrow.Draw();
0111 arrow.SetAngle(30);
0112
0113 phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02, "|>");
0114 phiArrow.SetLineWidth(4);
0115 phiArrow.Draw();
0116 phiArrow.SetAngle(30);
0117
0118 xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02, "|>");
0119 xArrow.SetLineWidth(4);
0120 xArrow.Draw();
0121 xArrow.SetAngle(30);
0122
0123 yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02, "|>");
0124 yArrow.SetLineWidth(4);
0125 yArrow.Draw();
0126 yArrow.SetAngle(30);
0127
0128
0129
0130 auto txt = TLatex();
0131 txt.SetNDC();
0132 txt.SetTextFont(1);
0133 txt.SetTextColor(1);
0134 txt.SetTextAlign(22);
0135 txt.SetTextAngle(0);
0136
0137
0138 txt.SetTextSize(0.03);
0139 txt.DrawLatex(0.5, ((index == 0) ? 0.95 : 0.93), (fmt::sprintf("Pixel Tracker Map: %s", m_title)).c_str());
0140 txt.SetTextSize(0.03);
0141
0142 txt.DrawLatex(0.55, 0.125, "-DISK");
0143 txt.DrawLatex(0.55, 0.875, "+DISK");
0144
0145 txt.DrawLatex(0.08, 0.28, "+z");
0146 txt.DrawLatex(0.25, 0.70, "+phi");
0147 txt.DrawLatex((index == 0) ? 0.31 : 0.33, 0.78, "+x");
0148 txt.DrawLatex((index == 0) ? 0.21 : 0.22, ((index == 0) ? 0.96 : 0.94), "+y");
0149
0150 txt.SetTextAngle(90);
0151 txt.DrawLatex(0.04, 0.5, "BARREL");
0152
0153 edm::LogPrint("Phase1PixelSummaryMap") << "Base Tracker Map: printed" << std::endl;
0154 }
0155
0156
0157 bool Phase1PixelSummaryMap::fillTrackerMap(unsigned int id, double value) {
0158 auto detid = DetId(id);
0159 if (detid.subdetId() != PixelSubdetector::PixelBarrel && detid.subdetId() != PixelSubdetector::PixelEndcap) {
0160 edm::LogError("Phase1PixelSummaryMap")
0161 << __func__ << " The following detid " << id << " is not Pixel!" << std::endl;
0162 return false;
0163 } else {
0164 m_BaseTrackerMap->Fill(TString::Format("%u", id), value);
0165 return true;
0166 }
0167 }
0168
0169
0170 const std::pair<float, float> Phase1PixelSummaryMap::getZAxisRange() const {
0171 return std::make_pair(m_BaseTrackerMap->GetMinimum(), m_BaseTrackerMap->GetMaximum());
0172 }
0173
0174
0175 void Phase1PixelSummaryMap::setZAxisRange(const double min, const double max) {
0176 m_BaseTrackerMap->GetZaxis()->SetRangeUser(min, max);
0177 }
0178
0179
0180 void Phase1PixelSummaryMap::addNamedBins(
0181 edm::FileInPath geoFile, int tX, int tY, int sX, int sY, bool applyModuleRotation) {
0182 auto cornerFileName = geoFile.fullPath();
0183 std::ifstream cornerFile(cornerFileName.c_str());
0184 if (!cornerFile.good()) {
0185 throw cms::Exception("FileError") << "Problem opening corner file: " << cornerFileName;
0186 }
0187 std::string line;
0188 while (std::getline(cornerFile, line)) {
0189 if (!line.empty()) {
0190 std::istringstream iss(line);
0191
0192 auto tokens = Ph1PMapSummaryHelper::tokenize(line, '"');
0193
0194 for (unsigned int i = 0; i < tokens.size(); i++)
0195 LOGDEBUG("Phase1PixelSummaryMap") << tokens[i] << '\n';
0196
0197 auto detInfo = Ph1PMapSummaryHelper::tokenize(tokens[0], ' ');
0198 unsigned int detId = stoi(detInfo[0]);
0199 std::string detIdName = detInfo[1];
0200 auto xy = Ph1PMapSummaryHelper::tokenize(tokens[1], ' ');
0201 unsigned int verNum = 1;
0202 std::vector<float> xP, yP;
0203 for (const auto& coord : xy) {
0204 auto coordSpl = Ph1PMapSummaryHelper::tokenize(coord, ',');
0205 if (applyModuleRotation) {
0206 xP.push_back(-(std::stof(coordSpl[0]) * sX + tX));
0207 yP.push_back(((std::stof(coordSpl[1]) * sY + tY)));
0208 } else {
0209 xP.push_back(std::stof(coordSpl[0]) * sX + tX);
0210 yP.push_back(std::stof(coordSpl[1]) * sY + tY);
0211 }
0212 verNum++;
0213 }
0214
0215 xP.push_back(xP[0]);
0216 yP.push_back(yP[0]);
0217
0218 LOGDEBUG("Phase1PixelSummaryMap") << detId << "[";
0219 for (const auto& p : xP) {
0220 LOGDEBUG("Phase1PixelSummaryMap") << p << ",";
0221 }
0222 LOGDEBUG("Phase1PixelSummaryMap") << "] [ ";
0223 for (const auto& q : yP) {
0224 LOGDEBUG("Phase1PixelSummaryMap") << q << ",";
0225 }
0226 LOGDEBUG("Phase1PixelSummaryMap") << "]" << std::endl;
0227
0228 const unsigned int N = verNum;
0229 if (applyModuleRotation) {
0230 bins[detId] = std::make_shared<TGraph>(N, &yP[0], &xP[0]);
0231 } else {
0232 bins[detId] = std::make_shared<TGraph>(N, &xP[0], &yP[0]);
0233
0234 }
0235
0236 bins[detId]->SetName(detInfo[0].c_str());
0237 m_BaseTrackerMap->AddBin(bins[detId]->Clone());
0238 }
0239 }
0240 return;
0241 }