CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Phase1PixelSummaryMap.cc
Go to the documentation of this file.
1 #include "TArrow.h"
2 #include "TCanvas.h"
3 #include "TGraph.h"
4 #include "TH1.h"
5 #include "TH2.h"
6 #include "TH2Poly.h"
7 #include "TLatex.h"
8 #include "TStyle.h"
9 
10 #include <fmt/printf.h>
11 #include <fstream>
12 #include <memory>
13 #include <boost/tokenizer.hpp>
14 #include <boost/range/adaptor/indexed.hpp>
15 
20 
21 // set option, but only if not already set
22 //============================================================================
23 void Phase1PixelSummaryMap::resetOption(const char* option) {
24  if (m_option != nullptr && !m_option[0]) {
25  m_option = option;
26  } else {
27  edm::LogError("Phase1PixelSummaryMap")
28  << "Option has already been set to " << m_option << ". It's not possible to reset it.";
29  }
30 }
31 
32 //============================================================================
34  m_BaseTrackerMap = std::make_shared<TH2Poly>("Summary", "", -10, 160, -70, 70);
35  m_BaseTrackerMap->SetFloat(true);
36  m_BaseTrackerMap->GetXaxis()->SetTitle("");
37  m_BaseTrackerMap->GetYaxis()->SetTitle("");
38  m_BaseTrackerMap->GetZaxis()->SetTitle(m_zAxisTitle.c_str());
39  m_BaseTrackerMap->GetZaxis()->CenterTitle();
40  m_BaseTrackerMap->GetZaxis()->SetTitleOffset(1.2);
41  m_BaseTrackerMap->SetOption("COLZ L");
42  m_BaseTrackerMap->SetStats(false);
43 
44  //BARREL FIRST
45  for (unsigned int i = 0; i < maxPxBarrel; i++) {
46  LOGINFO("Phase1PixelSummaryMap") << "barrel, shift: " << i << " corner: " << i << std::endl;
47  LOGINFO("Phase1PixelSummaryMap") << "translate x: " << 0 << std::endl;
48  LOGINFO("Phase1PixelSummaryMap") << "translate y: " << barrelLadderShift[i] << std::endl;
49 
50  int currBarrelTranslateX = 0;
51  int currBarrelTranslateY = barrelLadderShift[i];
52  addNamedBins(m_cornersBPIX[i], currBarrelTranslateX, currBarrelTranslateY, 1, 1, true);
53  }
54 
55  //MINUS FORWARD
56  for (int j : {-3, -2, -1}) {
57  LOGINFO("Phase1PixelSummaryMap") << "negative fwd, shift: " << -j - 1 << " corner: " << maxPxForward + j
58  << std::endl;
59  LOGINFO("Phase1PixelSummaryMap") << "translate x: " << forwardDiskXShift[-j - 1] << std::endl;
60  LOGINFO("Phase1PixelSummaryMap") << "translate y: " << -forwardDiskYShift << std::endl;
61 
62  int currForwardTranslateX = forwardDiskXShift[-j - 1];
63  int currForwardTranslateY = -forwardDiskYShift;
64  addNamedBins(m_cornersFPIX[maxPxForward + j], currForwardTranslateX, currForwardTranslateY, 1, 1);
65  }
66 
67  //PLUS FORWARD
68  for (int k : {1, 2, 3}) {
69  LOGINFO("Phase1PixelSummaryMap") << "positive fwd, shift: " << k << " corner: " << maxPxForward + k - 1
70  << std::endl;
71  LOGINFO("Phase1PixelSummaryMap") << "translate x: " << forwardDiskXShift[k - 1] << std::endl;
72  LOGINFO("Phase1PixelSummaryMap") << "translate y: " << forwardDiskYShift << std::endl;
73 
74  int currForwardTranslateX = forwardDiskXShift[k - 1];
75  int currForwardTranslateY = forwardDiskYShift;
76  addNamedBins(m_cornersFPIX[maxPxForward + k - 1], currForwardTranslateX, currForwardTranslateY, 1, 1);
77  }
78 
79  edm::LogPrint("Phase1PixelSummaryMap") << "Base Tracker Map: constructed" << std::endl;
80  return;
81 }
82 
83 //============================================================================
84 void Phase1PixelSummaryMap::printTrackerMap(TCanvas& canvas, const float topMargin) {
85  //canvas = TCanvas("c1","c1",plotWidth,plotHeight);
86  canvas.cd();
87  canvas.SetTopMargin(topMargin);
88  canvas.SetBottomMargin(0.02);
89  canvas.SetLeftMargin(0.02);
90  canvas.SetRightMargin(0.14);
91  m_BaseTrackerMap->Draw("AL");
92  m_BaseTrackerMap->Draw("AC COLZ0 L SAME");
93 
94  //### z arrow
95  arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02, "|>");
96  arrow.SetLineWidth(4);
97  arrow.Draw();
98  arrow.SetAngle(30);
99  //### phi arrow
100  phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02, "|>");
101  phiArrow.SetLineWidth(4);
102  phiArrow.Draw();
103  phiArrow.SetAngle(30);
104  //### x arrow
105  xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02, "|>");
106  xArrow.SetLineWidth(4);
107  xArrow.Draw();
108  xArrow.SetAngle(30);
109  //### y arrow
110  yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02, "|>");
111  yArrow.SetLineWidth(4);
112  yArrow.Draw();
113  yArrow.SetAngle(30);
114 
115  //###################################################
116  //# add some captions
117  auto txt = TLatex();
118  txt.SetNDC();
119  txt.SetTextFont(1);
120  txt.SetTextColor(1);
121  txt.SetTextAlign(22);
122  txt.SetTextAngle(0);
123 
124  //# draw new-style title
125  txt.SetTextSize((topMargin == 0.02) ? 0.05 : 0.03);
126  txt.DrawLatex(0.5, 0.95, (fmt::sprintf("Pixel Tracker Map: %s", m_title)).c_str());
127  txt.SetTextSize(0.03);
128 
129  txt.DrawLatex(0.55, 0.125, "-DISK");
130  txt.DrawLatex(0.55, 0.875, "+DISK");
131 
132  txt.DrawLatex(0.08, 0.28, "+z");
133  txt.DrawLatex(0.25, 0.70, "+phi");
134  txt.DrawLatex(0.31, 0.78, "+x");
135  txt.DrawLatex(0.21, 0.96, "+y");
136 
137  txt.SetTextAngle(90);
138  txt.DrawLatex(0.04, 0.5, "BARREL");
139 
140  edm::LogPrint("Phase1PixelSummaryMap") << "Base Tracker Map: printed" << std::endl;
141 }
142 
143 //============================================================================
144 bool Phase1PixelSummaryMap::fillTrackerMap(unsigned int id, double value) {
145  auto detid = DetId(id);
146  if (detid.subdetId() != PixelSubdetector::PixelBarrel && detid.subdetId() != PixelSubdetector::PixelEndcap) {
147  edm::LogError("Phase1PixelSummaryMap")
148  << __func__ << " The following detid " << id << " is not Pixel!" << std::endl;
149  return false;
150  } else {
151  m_BaseTrackerMap->Fill(TString::Format("%u", id), value);
152  return true;
153  }
154 }
155 
156 //============================================================================
158  edm::FileInPath geoFile, int tX, int tY, int sX, int sY, bool applyModuleRotation) {
159  auto cornerFileName = geoFile.fullPath();
160  std::ifstream cornerFile(cornerFileName.c_str());
161  if (!cornerFile.good()) {
162  throw cms::Exception("FileError") << "Problem opening corner file: " << cornerFileName;
163  }
165  while (std::getline(cornerFile, line)) {
166  if (!line.empty()) {
167  std::istringstream iss(line);
168 
169  auto tokens = Ph1PMapSummaryHelper::tokenize(line, '"');
170  // Printing the token vector
171  for (unsigned int i = 0; i < tokens.size(); i++)
172  LOGDEBUG("Phase1PixelSummaryMap") << tokens[i] << '\n';
173 
174  auto detInfo = Ph1PMapSummaryHelper::tokenize(tokens[0], ' ');
175  unsigned int detId = stoi(detInfo[0]);
176  std::string detIdName = detInfo[1];
177  auto xy = Ph1PMapSummaryHelper::tokenize(tokens[1], ' ');
178  unsigned int verNum = 1;
179  std::vector<float> xP, yP;
180  for (const auto& coord : xy) {
181  auto coordSpl = Ph1PMapSummaryHelper::tokenize(coord, ',');
182  if (applyModuleRotation) {
183  xP.push_back(-(std::stof(coordSpl[0]) * sX + tX));
184  yP.push_back(((std::stof(coordSpl[1]) * sY + tY)));
185  } else {
186  xP.push_back(std::stof(coordSpl[0]) * sX + tX);
187  yP.push_back(std::stof(coordSpl[1]) * sY + tY);
188  }
189  verNum++;
190  }
191  //close the polygon
192  xP.push_back(xP[0]);
193  yP.push_back(yP[0]);
194 
195  LOGDEBUG("Phase1PixelSummaryMap") << detId << "[";
196  for (const auto& p : xP) {
197  LOGDEBUG("Phase1PixelSummaryMap") << p << ",";
198  }
199  LOGDEBUG("Phase1PixelSummaryMap") << "] [ ";
200  for (const auto& q : yP) {
201  LOGDEBUG("Phase1PixelSummaryMap") << q << ",";
202  }
203  LOGDEBUG("Phase1PixelSummaryMap") << "]" << std::endl;
204 
205  const unsigned int N = verNum;
206  if (applyModuleRotation) {
207  bins[detId] = std::make_shared<TGraph>(N, &yP[0], &xP[0]);
208  } else {
209  bins[detId] = std::make_shared<TGraph>(N, &xP[0], &yP[0]);
210  //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)
211  }
212 
213  bins[detId]->SetName(detInfo[0].c_str());
214  m_BaseTrackerMap->AddBin(bins[detId]->Clone());
215  }
216  }
217  return;
218 }
const std::string m_zAxisTitle
void resetOption(const char *option)
static const unsigned int maxPxBarrel
const std::array< int, maxPxBarrel > barrelLadderShift
std::map< uint32_t, std::shared_ptr< TGraph > > bins
const std::array< int, maxPxForward > forwardDiskXShift
#define LOGINFO(x)
std::vector< std::string > tokenize(std::string line, char delimiter)
static const unsigned int maxPxForward
void printTrackerMap(TCanvas &canvas, const float topMargin=0.02)
Log< level::Error, false > LogError
def canvas
Definition: svgfig.py:482
std::shared_ptr< TH2Poly > m_BaseTrackerMap
std::vector< edm::FileInPath > m_cornersBPIX
#define LOGDEBUG(x)
Log< level::Warning, true > LogPrint
Basic2DVector< T > xy() const
Definition: DetId.h:17
#define N
Definition: blowfish.cc:9
void addNamedBins(edm::FileInPath geoFile, int tX, int tY, int sX, int sY, bool applyModuleRotation=false)
std::vector< edm::FileInPath > m_cornersFPIX
bool fillTrackerMap(unsigned int id, double value)
std::string fullPath() const
Definition: FileInPath.cc:161