Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:58:54

0001 // CMSSW includes
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 // ROOT includes
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 // STL includes
0022 #include <array>
0023 #include <fstream>
0024 #include <iostream>
0025 #include <map>
0026 #include <string>
0027 #include <vector>
0028 
0029 // boost includes
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   // set the titles
0041   m_zAxisTitle = zAxisTitle;
0042   m_mapTitle = mapTitle;
0043 
0044   TGaxis::SetMaxDigits(2);
0045 
0046   // margin of the box
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   for (const auto& pair : m_bins) {
0060     m_trackerMap->AddBin(pair.second->Clone());
0061   }
0062 }
0063 
0064 //============================================================================
0065 void SiStripTkMaps::fill(long rawid, double val) {
0066   m_trackerMap->Fill(TString::Format("%ld", rawid), val);
0067   m_values.push_back(val);
0068 }
0069 
0070 //============================================================================
0071 void SiStripTkMaps::drawMap(TCanvas& canvas, std::string option) {
0072   // margins
0073   static constexpr float tmargin_ = 0.08;
0074   static constexpr float bmargin_ = 0.02;
0075   static constexpr float lmargin_ = 0.02;
0076   static constexpr float rmargin_ = 0.08;
0077 
0078   // window size
0079   static constexpr int wH_ = 3000;
0080   static constexpr int hH_ = 850;
0081 
0082   canvas.cd();
0083   adjustCanvasMargins(canvas.cd(), tmargin_, bmargin_, lmargin_, rmargin_);
0084   canvas.Update();
0085 
0086   m_trackerMap->SetTitle("");
0087   if (!option.empty()) {
0088     m_trackerMap->Draw(option.c_str());
0089   } else {
0090     m_trackerMap->Draw();
0091   }
0092 
0093   canvas.SetFrameLineColor(0);
0094   gPad->Update();
0095   TPaletteAxis* palette = (TPaletteAxis*)m_trackerMap->GetListOfFunctions()->FindObject("palette");
0096   if (palette != nullptr) {
0097     palette->SetLabelSize(0.02);
0098     palette->SetX1NDC(1 - rmargin_);
0099     palette->SetX2NDC(1 - rmargin_ + lmargin_);
0100   }
0101 
0102   // if not right size, and not drawn in same mode
0103   if (canvas.GetWindowHeight() != hH_ && canvas.GetWindowWidth() != wH_ && option.find("same") == std::string::npos) {
0104     canvas.SetWindowSize(wH_, hH_);
0105   }
0106 
0107   // call the map dressing
0108   dressMap(canvas);
0109 }
0110 
0111 //============================================================================
0112 void SiStripTkMaps::dressMap(TCanvas& canv) {
0113   std::array<std::string, 12> barrelNames = {
0114       {"TIB L2", "TIB L1", "TIB L4", "TIB L3", "TOB L2", "TOB L1", "TOB L4", " TOB L3", "TOB L6", "TOB L5"}};
0115   std::array<std::string, 4> endcapNames = {{"TID", "TEC", "TID", "TEC"}};
0116   std::array<std::string, 24> disknumbering = {{"+1", "+2", "+3", "+1", "+2", "+3", "+4", "+5",
0117                                                 "+6", "+7", "+8", "+9", "-1", "-2", "-3", "-1",
0118                                                 "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"}};
0119 
0120   static constexpr std::array<float, 12> b_coordx = {
0121       {0.1, 0.1, 0.26, 0.26, 0.41, 0.41, 0.56, 0.56, 0.725, 0.725, 0.05, 0.17}};
0122   static constexpr std::array<float, 12> b_coordy = {
0123       {0.70, 0.45, 0.70, 0.45, 0.70, 0.46, 0.70, 0.46, 0.70, 0.46, 0.85, 0.85}};
0124 
0125   static constexpr std::array<float, 4> e_coordx = {{0.01, 0.21, 0.01, 0.21}};
0126   static constexpr std::array<float, 4> e_coordy = {{0.89, 0.89, 0.17, 0.17}};
0127 
0128   static constexpr std::array<float, 24> n_coordx = {{0.01,  0.087, 0.165, 0.227, 0.305, 0.383, 0.461, 0.539,
0129                                                       0.616, 0.694, 0.772, 0.850, 0.01,  0.087, 0.165, 0.227,
0130                                                       0.305, 0.383, 0.461, 0.539, 0.617, 0.695, 0.773, 0.851}};
0131 
0132   static constexpr std::array<float, 24> n_coordy = {{0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85,
0133                                                       0.85, 0.85, 0.85, 0.85, 0.13, 0.13, 0.13, 0.13,
0134                                                       0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13}};
0135 
0136   canv.cd();
0137   for (const auto& name : barrelNames | boost::adaptors::indexed(0)) {
0138     auto ltx = TLatex();
0139     ltx.SetTextFont(62);
0140     ltx.SetTextSize(0.035);
0141     ltx.SetTextAlign(11);
0142     ltx.DrawLatexNDC(b_coordx[name.index()], b_coordy[name.index()], name.value().c_str());
0143   }
0144 
0145   for (const auto& name : endcapNames | boost::adaptors::indexed(0)) {
0146     auto ltx = TLatex();
0147     ltx.SetTextFont(62);
0148     ltx.SetTextSize(0.05);
0149     ltx.SetTextAlign(11);
0150     ltx.DrawLatexNDC(e_coordx[name.index()], e_coordy[name.index()], name.value().c_str());
0151   }
0152 
0153   for (const auto& name : disknumbering | boost::adaptors::indexed(0)) {
0154     auto ltx = TLatex();
0155     ltx.SetTextFont(62);
0156     ltx.SetTextSize(0.035);
0157     ltx.SetTextAlign(11);
0158     ltx.DrawLatexNDC(n_coordx[name.index()], n_coordy[name.index()], name.value().c_str());
0159   }
0160 
0161   auto ltx = TLatex();
0162   ltx.SetTextFont(62);
0163   ltx.SetTextSize(0.045);
0164   ltx.SetTextAlign(11);
0165   ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.03, m_mapTitle.c_str());
0166 
0167   // barrel axes
0168   drawArrows(0.09, 0.23, 0.24, 0.45, "#phi", "z");
0169   // endcap axes
0170   drawArrows(0.85, 0.89, 0.83, 0.95, "x", "y");
0171 
0172   canv.Modified();
0173   canv.Update();  // make sure it's really (re)drawn
0174 }
0175 
0176 //============================================================================
0177 void SiStripTkMaps::drawArrows(
0178     const float x_X1, const float x_X2, const float x_Y1, const float y_Y2, const char* x_label, const char* y_label) {
0179   auto arrow_X = TArrow();
0180   arrow_X.SetLineColor(kBlue);
0181   arrow_X.SetLineWidth(2);
0182   arrow_X.SetOption("|>");
0183   arrow_X.SetArrowSize(10);
0184   arrow_X.DrawLineNDC(x_X1, x_Y1, x_X2, x_Y1);
0185 
0186   auto arrow_Y = TArrow();
0187   arrow_Y.SetLineColor(kBlue);
0188   arrow_Y.SetLineWidth(2);
0189   arrow_Y.SetOption("|>");
0190   arrow_Y.SetArrowSize(10);
0191   arrow_Y.DrawLineNDC(x_X2, x_Y1, x_X2, y_Y2);
0192 
0193   auto text_X = TLatex();
0194   text_X.SetTextSize(0.04);
0195   text_X.SetTextAlign(11);
0196   text_X.SetTextColor(kBlue);
0197   text_X.DrawLatexNDC(x_X1, x_Y1 - 0.03, x_label);
0198 
0199   auto text_Y = TLatex();
0200   text_Y.SetTextSize(0.04);
0201   text_Y.SetTextAlign(11);
0202   text_Y.SetTextColor(kBlue);
0203   text_Y.DrawLatexNDC(x_X2 + 0.005, y_Y2 - 0.01, y_label);
0204 }
0205 
0206 //============================================================================
0207 void SiStripTkMaps::adjustCanvasMargins(
0208     TVirtualPad* pad, const float top, const float bottom, const float left, const float right) {
0209   if (top > 0) {
0210     pad->SetTopMargin(top);
0211   }
0212   if (bottom > 0) {
0213     pad->SetBottomMargin(bottom);
0214   }
0215   if (left > 0) {
0216     pad->SetLeftMargin(left);
0217   }
0218   if (right > 0) {
0219     pad->SetRightMargin(right);
0220   }
0221 }
0222 
0223 //============================================================================
0224 void SiStripTkMaps::readVertices(double& minx, double& maxx, double& miny, double& maxy) {
0225   std::ifstream in;
0226 
0227   // TPolyline vertices stored at https://github.com/cms-data/DQM-SiStripMonitorClient
0228   in.open(edm::FileInPath("DQM/SiStripMonitorClient/data/Geometry/tracker_map_bare").fullPath().c_str());
0229 
0230   if (!in.good()) {
0231     throw cms::Exception("FileError") << "SiStripTkMaps: problem opening vertices file!!" << std::endl;
0232     return;
0233   }
0234 
0235   while (in.good()) {
0236     long detid = 0;
0237     double x[5], y[5];
0238 
0239     std::string line;
0240     std::getline(in, line);
0241     typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
0242     boost::char_separator<char> sep{" "};
0243     tokenizer tok{line, sep};
0244 
0245     int ix{0}, iy{0};
0246     bool isPixel{false};
0247     for (const auto& t : tok | boost::adaptors::indexed(0)) {
0248       int i = t.index();
0249       if (i == 0) {
0250         detid = atoll((t.value()).c_str());
0251 
0252         // Drop Pixel Data
0253         DetId detId(detid);
0254         if (detId.subdetId() == PixelSubdetector::PixelBarrel || detId.subdetId() == PixelSubdetector::PixelEndcap) {
0255           isPixel = true;
0256           break;
0257         }
0258       } else {
0259         if (i % 2 == 0) {
0260           x[ix] = atof((t.value()).c_str());
0261           if (x[ix] < minx) {
0262             minx = x[ix];
0263           }
0264           if (x[ix] > maxx) {
0265             maxx = x[ix];
0266           }
0267           ++ix;
0268         } else {
0269           y[iy] = atof((t.value()).c_str());
0270           if (y[iy] < miny) {
0271             miny = y[iy];
0272           }
0273           if (y[iy] > maxy) {
0274             maxy = y[iy];
0275           }
0276           ++iy;
0277         }  // else
0278       }    // else
0279     }      // loop on entries
0280 
0281     if (isPixel) {
0282       continue;
0283     }
0284 
0285     m_bins[detid] = std::make_shared<TGraph>(ix, x, y);
0286     m_bins[detid]->SetName(TString::Format("%ld", detid));
0287     m_bins[detid]->SetTitle(TString::Format("Module ID=%ld", detid));
0288     m_detIdVector.push_back(detid);
0289   }
0290 }