File indexing completed on 2024-09-13 22:52:26
0001
0002 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0003 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
0004 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
0005 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0006 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/FileInPath.h"
0009
0010
0011 #include "TArrow.h"
0012 #include "TPaletteAxis.h"
0013 #include "TGaxis.h"
0014 #include "TCanvas.h"
0015 #include "TColor.h"
0016 #include "TGraph.h"
0017 #include "TLatex.h"
0018 #include "TH2Poly.h"
0019 #include "TStyle.h"
0020
0021
0022 #include <array>
0023 #include <fstream>
0024 #include <iostream>
0025 #include <map>
0026 #include <string>
0027 #include <vector>
0028
0029
0030 #include <boost/tokenizer.hpp>
0031 #include <boost/range/adaptor/indexed.hpp>
0032
0033 #include "DQM/TrackerRemapper/interface/SiStripTkMaps.h"
0034
0035
0036 void SiStripTkMaps::bookMap(const std::string mapTitle, const std::string zAxisTitle) {
0037 double minx = 0xFFFFFF, maxx = -0xFFFFFF, miny = 0xFFFFFF, maxy = -0xFFFFFFF;
0038 readVertices(minx, maxx, miny, maxy);
0039
0040
0041 m_zAxisTitle = zAxisTitle;
0042 m_mapTitle = mapTitle;
0043
0044 TGaxis::SetMaxDigits(2);
0045
0046
0047 static constexpr int margin = 5;
0048 m_trackerMap =
0049 new TH2Poly("Tracker Map", m_mapTitle.c_str(), minx - margin, maxx + margin, miny - margin, maxy + margin);
0050 m_trackerMap->SetFloat();
0051 m_trackerMap->SetOption(m_option);
0052 m_trackerMap->SetStats(false);
0053 m_trackerMap->GetZaxis()->SetLabelSize(0.03);
0054 m_trackerMap->GetZaxis()->SetTitleOffset(0.5);
0055 m_trackerMap->GetZaxis()->SetTitleSize(0.05);
0056 m_trackerMap->GetZaxis()->SetTitle(m_zAxisTitle.c_str());
0057 m_trackerMap->GetZaxis()->CenterTitle();
0058
0059
0060 for (const auto& pair : m_bins) {
0061 m_trackerMap->AddBin(pair.second->Clone());
0062 }
0063
0064
0065 for (const auto& pair : m_bins) {
0066 m_trackerMap->Fill(pair.first, 0.0);
0067 }
0068 }
0069
0070
0071 void SiStripTkMaps::fill(long rawid, double val) {
0072 m_trackerMap->Fill(TString::Format("%ld", rawid), val);
0073 m_values.push_back(val);
0074 }
0075
0076
0077 void SiStripTkMaps::drawMap(TCanvas& canvas, std::string option) {
0078
0079 static constexpr float tmargin_ = 0.08;
0080 static constexpr float bmargin_ = 0.02;
0081 static constexpr float lmargin_ = 0.02;
0082 static constexpr float rmargin_ = 0.08;
0083
0084
0085 static constexpr int wH_ = 3000;
0086 static constexpr int hH_ = 700;
0087
0088
0089 static constexpr double emptyBinValue = -9999;
0090
0091
0092 for (int i = 1; i <= m_trackerMap->GetNumberOfBins(); ++i) {
0093 if (m_trackerMap->GetBinContent(i) == 0) {
0094 m_trackerMap->SetBinContent(i, emptyBinValue);
0095 }
0096 }
0097
0098
0099 if (!m_values.empty()) {
0100 double minValue = *std::min_element(m_values.begin(), m_values.end());
0101 double maxValue = *std::max_element(m_values.begin(), m_values.end());
0102
0103
0104 m_trackerMap->SetMinimum(minValue);
0105 m_trackerMap->SetMaximum(maxValue);
0106 }
0107
0108 canvas.cd();
0109 adjustCanvasMargins(canvas.cd(), tmargin_, bmargin_, lmargin_, rmargin_);
0110 canvas.Update();
0111
0112 m_trackerMap->SetTitle("");
0113 if (!option.empty()) {
0114 m_trackerMap->Draw(option.c_str());
0115 } else {
0116 m_trackerMap->Draw();
0117 }
0118
0119
0120 for (int i = 1; i <= m_trackerMap->GetNumberOfBins(); ++i) {
0121 if (m_trackerMap->GetBinContent(i) == emptyBinValue) {
0122 m_trackerMap->SetBinContent(i, emptyBinValue);
0123 m_trackerMap->SetMarkerColor(kWhite);
0124 }
0125 }
0126
0127 canvas.SetFrameLineColor(0);
0128 gPad->Update();
0129 TPaletteAxis* palette = (TPaletteAxis*)m_trackerMap->GetListOfFunctions()->FindObject("palette");
0130 if (palette != nullptr) {
0131 palette->SetLabelSize(0.02);
0132 palette->SetX1NDC(1 - rmargin_);
0133 palette->SetX2NDC(1 - rmargin_ + lmargin_);
0134 }
0135
0136
0137 if (canvas.GetWindowHeight() != hH_ && canvas.GetWindowWidth() != wH_ && option.find("same") == std::string::npos) {
0138 canvas.SetWindowSize(wH_, hH_);
0139 }
0140
0141
0142 dressMap(canvas);
0143 }
0144
0145
0146 void SiStripTkMaps::dressMap(TCanvas& canv) {
0147 std::array<std::string, 12> barrelNames = {
0148 {"TIB L2", "TIB L1", "TIB L4", "TIB L3", "TOB L2", "TOB L1", "TOB L4", " TOB L3", "TOB L6", "TOB L5"}};
0149 std::array<std::string, 4> endcapNames = {{"TID", "TEC", "TID", "TEC"}};
0150 std::array<std::string, 24> disknumbering = {{"+1", "+2", "+3", "+1", "+2", "+3", "+4", "+5",
0151 "+6", "+7", "+8", "+9", "-1", "-2", "-3", "-1",
0152 "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}};
0153
0154 static constexpr std::array<float, 12> b_coordx = {
0155 {0.1, 0.1, 0.26, 0.26, 0.41, 0.41, 0.56, 0.56, 0.725, 0.725, 0.05, 0.17}};
0156 static constexpr std::array<float, 12> b_coordy = {
0157 {0.70, 0.45, 0.70, 0.45, 0.70, 0.46, 0.70, 0.46, 0.70, 0.46, 0.85, 0.85}};
0158
0159 static constexpr std::array<float, 4> e_coordx = {{0.01, 0.21, 0.01, 0.21}};
0160 static constexpr std::array<float, 4> e_coordy = {{0.89, 0.89, 0.17, 0.17}};
0161
0162 static constexpr std::array<float, 24> n_coordx = {{0.01, 0.087, 0.165, 0.227, 0.305, 0.383, 0.461, 0.539,
0163 0.616, 0.694, 0.772, 0.850, 0.01, 0.087, 0.165, 0.227,
0164 0.305, 0.383, 0.461, 0.539, 0.617, 0.695, 0.773, 0.851}};
0165
0166 static constexpr std::array<float, 24> n_coordy = {{0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85,
0167 0.85, 0.85, 0.85, 0.85, 0.13, 0.13, 0.13, 0.13,
0168 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13}};
0169
0170 canv.cd();
0171 for (const auto& name : barrelNames | boost::adaptors::indexed(0)) {
0172 auto ltx = TLatex();
0173 ltx.SetTextFont(62);
0174 ltx.SetTextSize(0.035);
0175 ltx.SetTextAlign(11);
0176 ltx.DrawLatexNDC(b_coordx[name.index()], b_coordy[name.index()], name.value().c_str());
0177 }
0178
0179 for (const auto& name : endcapNames | boost::adaptors::indexed(0)) {
0180 auto ltx = TLatex();
0181 ltx.SetTextFont(62);
0182 ltx.SetTextSize(0.05);
0183 ltx.SetTextAlign(11);
0184 ltx.DrawLatexNDC(e_coordx[name.index()], e_coordy[name.index()], name.value().c_str());
0185 }
0186
0187 for (const auto& name : disknumbering | boost::adaptors::indexed(0)) {
0188 auto ltx = TLatex();
0189 ltx.SetTextFont(62);
0190 ltx.SetTextSize(0.035);
0191 ltx.SetTextAlign(11);
0192 ltx.DrawLatexNDC(n_coordx[name.index()], n_coordy[name.index()], name.value().c_str());
0193 }
0194
0195 auto ltx = TLatex();
0196 ltx.SetTextFont(62);
0197 ltx.SetTextSize(0.045);
0198 ltx.SetTextAlign(11);
0199 ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.03, m_mapTitle.c_str());
0200
0201
0202 drawArrows(0.09, 0.23, 0.24, 0.45, "#phi", "z");
0203
0204 drawArrows(0.85, 0.89, 0.83, 0.95, "x", "y");
0205
0206 canv.Modified();
0207 canv.Update();
0208 }
0209
0210
0211 void SiStripTkMaps::drawArrows(
0212 const float x_X1, const float x_X2, const float x_Y1, const float y_Y2, const char* x_label, const char* y_label) {
0213 auto arrow_X = TArrow();
0214 arrow_X.SetLineColor(kBlue);
0215 arrow_X.SetLineWidth(2);
0216 arrow_X.SetOption("|>");
0217 arrow_X.SetArrowSize(10);
0218 arrow_X.DrawLineNDC(x_X1, x_Y1, x_X2, x_Y1);
0219
0220 auto arrow_Y = TArrow();
0221 arrow_Y.SetLineColor(kBlue);
0222 arrow_Y.SetLineWidth(2);
0223 arrow_Y.SetOption("|>");
0224 arrow_Y.SetArrowSize(10);
0225 arrow_Y.DrawLineNDC(x_X2, x_Y1, x_X2, y_Y2);
0226
0227 auto text_X = TLatex();
0228 text_X.SetTextSize(0.04);
0229 text_X.SetTextAlign(11);
0230 text_X.SetTextColor(kBlue);
0231 text_X.DrawLatexNDC(x_X1, x_Y1 - 0.03, x_label);
0232
0233 auto text_Y = TLatex();
0234 text_Y.SetTextSize(0.04);
0235 text_Y.SetTextAlign(11);
0236 text_Y.SetTextColor(kBlue);
0237 text_Y.DrawLatexNDC(x_X2 + 0.005, y_Y2 - 0.01, y_label);
0238 }
0239
0240
0241 void SiStripTkMaps::adjustCanvasMargins(
0242 TVirtualPad* pad, const float top, const float bottom, const float left, const float right) {
0243 if (top > 0) {
0244 pad->SetTopMargin(top);
0245 }
0246 if (bottom > 0) {
0247 pad->SetBottomMargin(bottom);
0248 }
0249 if (left > 0) {
0250 pad->SetLeftMargin(left);
0251 }
0252 if (right > 0) {
0253 pad->SetRightMargin(right);
0254 }
0255 }
0256
0257
0258 void SiStripTkMaps::readVertices(double& minx, double& maxx, double& miny, double& maxy) {
0259 std::ifstream in;
0260
0261
0262 in.open(edm::FileInPath("DQM/SiStripMonitorClient/data/Geometry/tracker_map_bare").fullPath().c_str());
0263
0264 if (!in.good()) {
0265 throw cms::Exception("FileError") << "SiStripTkMaps: problem opening vertices file!!" << std::endl;
0266 return;
0267 }
0268
0269 while (in.good()) {
0270 long detid = 0;
0271 double x[5], y[5];
0272
0273 std::string line;
0274 std::getline(in, line);
0275 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
0276 boost::char_separator<char> sep{" "};
0277 tokenizer tok{line, sep};
0278
0279 int ix{0}, iy{0};
0280 bool isPixel{false};
0281 for (const auto& t : tok | boost::adaptors::indexed(0)) {
0282 int i = t.index();
0283 if (i == 0) {
0284 detid = atoll((t.value()).c_str());
0285
0286
0287 DetId detId(detid);
0288 if (detId.subdetId() == PixelSubdetector::PixelBarrel || detId.subdetId() == PixelSubdetector::PixelEndcap) {
0289 isPixel = true;
0290 break;
0291 }
0292 } else {
0293 if (i % 2 == 0) {
0294 x[ix] = atof((t.value()).c_str());
0295 if (x[ix] < minx) {
0296 minx = x[ix];
0297 }
0298 if (x[ix] > maxx) {
0299 maxx = x[ix];
0300 }
0301 ++ix;
0302 } else {
0303 y[iy] = atof((t.value()).c_str());
0304 if (y[iy] < miny) {
0305 miny = y[iy];
0306 }
0307 if (y[iy] > maxy) {
0308 maxy = y[iy];
0309 }
0310 ++iy;
0311 }
0312 }
0313 }
0314
0315 if (isPixel) {
0316 continue;
0317 }
0318
0319 m_bins[detid] = std::make_shared<TGraph>(ix, x, y);
0320 m_bins[detid]->SetName(TString::Format("%ld", detid));
0321 m_bins[detid]->SetTitle(TString::Format("Module ID=%ld", detid));
0322 m_detIdVector.push_back(detid);
0323 }
0324 }