CMS 3D CMS Logo

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 //============================================================================
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 //============================================================================
85  //canvas = TCanvas("c1","c1",plotWidth,plotHeight);
86  canvas.cd();
87  canvas.SetTopMargin(0.02);
88  canvas.SetBottomMargin(0.02);
89  canvas.SetLeftMargin(0.02);
90  canvas.SetRightMargin(0.14);
91  m_BaseTrackerMap->Draw("AC COLZ L");
92 
93  //### z arrow
94  arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02, "|>");
95  arrow.SetLineWidth(4);
96  arrow.Draw();
97  arrow.SetAngle(30);
98  //### phi arrow
99  phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02, "|>");
100  phiArrow.SetLineWidth(4);
101  phiArrow.Draw();
102  phiArrow.SetAngle(30);
103  //### x arrow
104  xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02, "|>");
105  xArrow.SetLineWidth(4);
106  xArrow.Draw();
107  xArrow.SetAngle(30);
108  //### y arrow
109  yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02, "|>");
110  yArrow.SetLineWidth(4);
111  yArrow.Draw();
112  yArrow.SetAngle(30);
113 
114  //###################################################
115  //# add some captions
116  auto txt = TLatex();
117  txt.SetNDC();
118  txt.SetTextFont(1);
119  txt.SetTextColor(1);
120  txt.SetTextAlign(22);
121  txt.SetTextAngle(0);
122 
123  //# draw new-style title
124  txt.SetTextSize(0.05);
125  txt.DrawLatex(0.5, 0.95, (fmt::sprintf("Pixel Tracker Map: %s", m_title)).c_str());
126  txt.SetTextSize(0.03);
127 
128  txt.DrawLatex(0.55, 0.125, "-DISK");
129  txt.DrawLatex(0.55, 0.875, "+DISK");
130 
131  txt.DrawLatex(0.08, 0.28, "+z");
132  txt.DrawLatex(0.25, 0.70, "+phi");
133  txt.DrawLatex(0.31, 0.78, "+x");
134  txt.DrawLatex(0.21, 0.96, "+y");
135 
136  txt.SetTextAngle(90);
137  txt.DrawLatex(0.04, 0.5, "BARREL");
138 
139  edm::LogPrint("Phase1PixelSummaryMap") << "Base Tracker Map: printed" << std::endl;
140 }
141 
142 //============================================================================
143 bool Phase1PixelSummaryMap::fillTrackerMap(unsigned int id, double value) {
144  auto detid = DetId(id);
145  if (detid.subdetId() != PixelSubdetector::PixelBarrel && detid.subdetId() != PixelSubdetector::PixelEndcap) {
146  edm::LogError("Phase1PixelSummaryMap")
147  << __func__ << " The following detid " << id << " is not Pixel!" << std::endl;
148  return false;
149  } else {
150  m_BaseTrackerMap->Fill(TString::Format("%u", id), value);
151  return true;
152  }
153 }
154 
155 //============================================================================
157  edm::FileInPath geoFile, int tX, int tY, int sX, int sY, bool applyModuleRotation) {
158  auto cornerFileName = geoFile.fullPath();
159  std::ifstream cornerFile(cornerFileName.c_str());
160  if (!cornerFile.good()) {
161  throw cms::Exception("FileError") << "Problem opening corner file: " << cornerFileName;
162  }
164  while (std::getline(cornerFile, line)) {
165  if (!line.empty()) {
166  std::istringstream iss(line);
167 
168  auto tokens = Ph1PMapSummaryHelper::tokenize(line, '"');
169  // Printing the token vector
170  for (unsigned int i = 0; i < tokens.size(); i++)
171  LOGDEBUG("Phase1PixelSummaryMap") << tokens[i] << '\n';
172 
173  auto detInfo = Ph1PMapSummaryHelper::tokenize(tokens[0], ' ');
174  unsigned int detId = stoi(detInfo[0]);
175  std::string detIdName = detInfo[1];
176  auto xy = Ph1PMapSummaryHelper::tokenize(tokens[1], ' ');
177  unsigned int verNum = 1;
178  std::vector<float> xP, yP;
179  for (const auto& coord : xy) {
180  auto coordSpl = Ph1PMapSummaryHelper::tokenize(coord, ',');
181  if (applyModuleRotation) {
182  xP.push_back(-(std::stof(coordSpl[0]) * sX + tX));
183  yP.push_back(((std::stof(coordSpl[1]) * sY + tY)));
184  } else {
185  xP.push_back(std::stof(coordSpl[0]) * sX + tX);
186  yP.push_back(std::stof(coordSpl[1]) * sY + tY);
187  }
188  verNum++;
189  }
190  //close the polygon
191  xP.push_back(xP[0]);
192  yP.push_back(yP[0]);
193 
194  LOGDEBUG("Phase1PixelSummaryMap") << detId << "[";
195  for (const auto& p : xP) {
196  LOGDEBUG("Phase1PixelSummaryMap") << p << ",";
197  }
198  LOGDEBUG("Phase1PixelSummaryMap") << "] [ ";
199  for (const auto& q : yP) {
200  LOGDEBUG("Phase1PixelSummaryMap") << q << ",";
201  }
202  LOGDEBUG("Phase1PixelSummaryMap") << "]" << std::endl;
203 
204  const unsigned int N = verNum;
205  if (applyModuleRotation) {
206  bins[detId] = std::make_shared<TGraph>(N, &yP[0], &xP[0]);
207  } else {
208  bins[detId] = std::make_shared<TGraph>(N, &xP[0], &yP[0]);
209  //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)
210  }
211 
212  bins[detId]->SetName(detInfo[0].c_str());
213  m_BaseTrackerMap->AddBin(bins[detId]->Clone());
214  }
215  }
216  return;
217 }
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
Phase1PixelSummaryMap::addNamedBins
void addNamedBins(edm::FileInPath geoFile, int tX, int tY, int sX, int sY, bool applyModuleRotation=false)
Definition: Phase1PixelSummaryMap.cc:156
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Phase1PixelSummaryMap::arrow
TArrow arrow
Definition: Phase1PixelSummaryMap.h:107
Phase1PixelSummaryMap::bins
std::map< uint32_t, std::shared_ptr< TGraph > > bins
Definition: Phase1PixelSummaryMap.h:92
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
Phase1PixelSummaryMap::xArrow
TArrow xArrow
Definition: Phase1PixelSummaryMap.h:107
Phase1PixelSummaryMap::maxPxBarrel
static const unsigned int maxPxBarrel
Definition: Phase1PixelSummaryMap.h:97
Phase1PixelSummaryMap.h
LOGDEBUG
#define LOGDEBUG(x)
Definition: Phase1PixelMaps.h:21
fileinputsource_cfi.option
option
Definition: fileinputsource_cfi.py:94
FileInPath.h
Phase1PixelSummaryMap::m_title
const std::string m_title
Definition: Phase1PixelSummaryMap.h:87
Phase1PixelSummaryMap::m_cornersBPIX
std::vector< edm::FileInPath > m_cornersBPIX
Definition: Phase1PixelSummaryMap.h:94
DetId
Definition: DetId.h:17
edm::FileInPath
Definition: FileInPath.h:64
Phase1PixelSummaryMap::m_zAxisTitle
const std::string m_zAxisTitle
Definition: Phase1PixelSummaryMap.h:88
StandaloneTrackerTopology.h
Phase1PixelSummaryMap::barrelLadderShift
const std::array< int, maxPxBarrel > barrelLadderShift
Definition: Phase1PixelSummaryMap.h:99
LOGINFO
#define LOGINFO(x)
Definition: SiPixelGenError.cc:37
N
#define N
Definition: blowfish.cc:9
Phase1PixelSummaryMap::resetOption
void resetOption(const char *option)
Definition: Phase1PixelSummaryMap.cc:23
dqmdumpme.k
k
Definition: dqmdumpme.py:60
Phase1PixelSummaryMap::forwardDiskYShift
const int forwardDiskYShift
Definition: Phase1PixelSummaryMap.h:102
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
Phase1PixelSummaryMap::m_cornersFPIX
std::vector< edm::FileInPath > m_cornersFPIX
Definition: Phase1PixelSummaryMap.h:95
Phase1PixelSummaryMap::m_BaseTrackerMap
std::shared_ptr< TH2Poly > m_BaseTrackerMap
Definition: Phase1PixelSummaryMap.h:91
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Phase1PixelSummaryMap::forwardDiskXShift
const std::array< int, maxPxForward > forwardDiskXShift
Definition: Phase1PixelSummaryMap.h:100
Phase1PixelSummaryMap::m_option
Option_t * m_option
Definition: Phase1PixelSummaryMap.h:86
Phase1PixelSummaryMap::maxPxForward
static const unsigned int maxPxForward
Definition: Phase1PixelSummaryMap.h:98
value
Definition: value.py:1
Phase1PixelSummaryMap::phiArrow
TArrow phiArrow
Definition: Phase1PixelSummaryMap.h:107
submitPVResolutionJobs.q
q
Definition: submitPVResolutionJobs.py:84
Phase1PixelSummaryMap::yArrow
TArrow yArrow
Definition: Phase1PixelSummaryMap.h:107
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
Exception
Definition: hltDiff.cc:245
Ph1PMapSummaryHelper::tokenize
std::vector< std::string > tokenize(std::string line, char delimiter)
Definition: Phase1PixelSummaryMap.h:39
Phase1PixelSummaryMap::fillTrackerMap
bool fillTrackerMap(unsigned int id, double value)
Definition: Phase1PixelSummaryMap.cc:143
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
Phase1PixelSummaryMap::printTrackerMap
void printTrackerMap(TCanvas &canvas)
Definition: Phase1PixelSummaryMap.cc:84
mps_splice.line
line
Definition: mps_splice.py:76
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
Phase1PixelSummaryMap::createTrackerBaseMap
void createTrackerBaseMap()
Definition: Phase1PixelSummaryMap.cc:33