CMS 3D CMS Logo

Phase1PixelMaps.cc
Go to the documentation of this file.
1 #include "TH2Poly.h"
2 #include "TGraph.h"
3 #include "TH1.h"
4 #include "TH2.h"
5 #include "TStyle.h"
6 #include "TCanvas.h"
7 
8 #include <fmt/printf.h>
9 #include <fstream>
10 #include <iostream>
11 #include <boost/tokenizer.hpp>
12 #include <boost/range/adaptor/indexed.hpp>
13 
18 
19 // set option, but only if not already set
20 //============================================================================
22  if (m_option != nullptr && !m_option[0]) {
23  m_option = option;
24  } else {
25  edm::LogError("Phase1PixelMaps") << "Option has already been set to " << m_option
26  << ". It's not possible to reset it.";
27  }
28 }
29 
30 //============================================================================
31 void Phase1PixelMaps::bookBarrelHistograms(const std::string& currentHistoName, const char* what, const char* zaxis) {
32  std::string histName;
33  std::shared_ptr<TH2Poly> th2p;
34 
35  // check if the passed histogram name already exists, if not store it
36  if (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) == m_knownNames.end()) {
37  m_knownNames.emplace_back(currentHistoName);
38  }
39 
40  for (unsigned i = 0; i < 4; ++i) {
41  histName = "barrel_layer_";
42 
43  th2p = std::make_shared<TH2Poly>(
44  (histName + std::to_string(i + 1)).c_str(), Form("PXBMap of %s - Layer %i", what, i + 1), -15.0, 15.0, 0.0, 5.0);
45 
46  th2p->SetFloat();
47 
48  th2p->GetXaxis()->SetTitle("z [cm]");
49  th2p->GetYaxis()->SetTitle("ladder");
50  th2p->GetZaxis()->SetTitle(zaxis);
51  th2p->GetZaxis()->CenterTitle();
52  th2p->SetStats(false);
53  th2p->SetOption(m_option);
54  pxbTh2PolyBarrel[currentHistoName].push_back(th2p);
55  }
56 
57  th2p = std::make_shared<TH2Poly>("barrel_summary", Form("Barrel Pixel Map of %s", what), -5.0, 5.0, 0.0, 15.0);
58  th2p->SetFloat();
59 
60  th2p->GetXaxis()->SetTitle("");
61  th2p->GetYaxis()->SetTitle("");
62  th2p->GetZaxis()->SetTitle(zaxis);
63  th2p->GetZaxis()->CenterTitle();
64  th2p->SetStats(false);
65  th2p->SetOption(m_option);
66  pxbTh2PolyBarrelSummary[currentHistoName] = th2p;
67 
68  // book the bins
69  bookBarrelBins(currentHistoName);
70 
71  // set the isBooked bit to true;
72  m_isBooked.first = true;
73 }
74 
75 //============================================================================
76 void Phase1PixelMaps::bookForwardHistograms(const std::string& currentHistoName, const char* what, const char* zaxis) {
77  std::string histName;
78  std::shared_ptr<TH2Poly> th2p;
79 
80  // check if the passed histogram name already exists, if not store it
81  if (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) == m_knownNames.end()) {
82  m_knownNames.emplace_back(currentHistoName);
83  }
84 
85  for (unsigned side = 1; side <= 2; ++side) {
86  for (unsigned disk = 1; disk <= 3; ++disk) {
87  histName = "forward_disk_";
88 
89  th2p = std::make_shared<TH2Poly>((histName + std::to_string((side == 1 ? -(int(disk)) : (int)disk))).c_str(),
90  Form("PXFMap of %s - Side %i Disk %i", what, side, disk),
91  -15.0,
92  15.0,
93  -15.0,
94  15.0);
95  th2p->SetFloat();
96  th2p->GetXaxis()->SetTitle("x [cm]");
97  th2p->GetYaxis()->SetTitle("y [cm]");
98  th2p->GetZaxis()->SetTitle(zaxis);
99  th2p->GetZaxis()->CenterTitle();
100  th2p->SetStats(false);
101  th2p->SetOption(m_option);
102  pxfTh2PolyForward[currentHistoName].push_back(th2p);
103  }
104  }
105 
106  th2p = std::make_shared<TH2Poly>("forward_summary", Form("Forward Pixel Map of %s", what), -40.0, 40.0, -20.0, 90.0);
107  th2p->SetFloat();
108 
109  th2p->GetXaxis()->SetTitle("");
110  th2p->GetYaxis()->SetTitle("");
111  th2p->GetZaxis()->SetTitle(zaxis);
112  th2p->GetZaxis()->CenterTitle();
113  th2p->SetStats(false);
114  th2p->SetOption(m_option);
115  pxfTh2PolyForwardSummary[currentHistoName] = th2p;
116 
117  // book the bins
118  bookForwardBins(currentHistoName);
119 
120  m_isBooked.second = true;
121 }
122 
123 //============================================================================
124 void Phase1PixelMaps::bookBarrelBins(const std::string& currentHistoName) {
125  auto theIndexedCorners = this->retrieveCorners(m_cornersBPIX, 4);
126 
127  for (const auto& entry : theIndexedCorners) {
128  auto id = entry.first;
129  auto detid = DetId(id);
130  if (detid.subdetId() != PixelSubdetector::PixelBarrel)
131  continue;
132 
133  int layer = m_trackerTopo.pxbLayer(detid);
134  int ladder = m_trackerTopo.pxbLadder(detid);
135 
136  auto theVectX = entry.second.first;
137  auto theVectY = entry.second.second;
138 
139  float vertX[] = {theVectX[0], theVectX[1], theVectX[2], theVectX[3], theVectX[4]};
140  float vertY[] = {(ladder - 1.0f), (ladder - 1.0f), (float)ladder, (float)ladder, (ladder - 1.0f)};
141 
142  bins[id] = std::make_shared<TGraph>(5, vertX, vertY);
143  bins[id]->SetName(TString::Format("%u", id));
144 
145  // Summary plot
146  for (unsigned k = 0; k < 5; ++k) {
147  vertX[k] += ((layer == 2 || layer == 3) ? 0.0f : -60.0f);
148  vertY[k] += ((layer > 2) ? 30.0f : 0.0f);
149  }
150 
151  binsSummary[id] = std::make_shared<TGraph>(5, vertX, vertY);
152  binsSummary[id]->SetName(TString::Format("%u", id));
153 
154  if (pxbTh2PolyBarrel.find(currentHistoName) != pxbTh2PolyBarrel.end()) {
155  pxbTh2PolyBarrel[currentHistoName][layer - 1]->AddBin(bins[id]->Clone());
156  } else {
157  throw cms::Exception("LogicError") << currentHistoName << " is not found in the Barrel map! Aborting.";
158  }
159 
160  if (pxbTh2PolyBarrelSummary.find(currentHistoName) != pxbTh2PolyBarrelSummary.end()) {
161  pxbTh2PolyBarrelSummary[currentHistoName]->AddBin(binsSummary[id]->Clone());
162  } else {
163  throw cms::Exception("LocalError") << currentHistoName << " is not found in the Barrel Summary map! Aborting.";
164  }
165  }
166 }
167 
168 //============================================================================
169 void Phase1PixelMaps::bookForwardBins(const std::string& currentHistoName) {
170  auto theIndexedCorners = this->retrieveCorners(m_cornersFPIX, 3);
171 
172  for (const auto& entry : theIndexedCorners) {
173  auto id = entry.first;
174  auto detid = DetId(id);
175  if (detid.subdetId() != PixelSubdetector::PixelEndcap)
176  continue;
177 
178  int disk = m_trackerTopo.pxfDisk(detid);
179  int side = m_trackerTopo.pxfSide(detid);
180 
181  unsigned mapIdx = disk + (side - 1) * 3 - 1;
182 
183  auto theVectX = entry.second.first;
184  auto theVectY = entry.second.second;
185 
186  float vertX[] = {theVectX[0], theVectX[1], theVectX[2], theVectX[3]};
187  float vertY[] = {theVectY[0], theVectY[1], theVectY[2], theVectY[3]};
188 
189  bins[id] = std::make_shared<TGraph>(4, vertX, vertY);
190  bins[id]->SetName(TString::Format("%u", id));
191 
192  // Summary plot
193  for (unsigned k = 0; k < 4; ++k) {
194  vertX[k] += (float(side) - 1.5f) * 40.0f;
195  vertY[k] += (disk - 1) * 35.0f;
196  }
197 
198  binsSummary[id] = std::make_shared<TGraph>(4, vertX, vertY);
199  binsSummary[id]->SetName(TString::Format("%u", id));
200 
201  if (pxfTh2PolyForward.find(currentHistoName) != pxfTh2PolyForward.end()) {
202  pxfTh2PolyForward[currentHistoName][mapIdx]->AddBin(bins[id]->Clone());
203  } else {
204  throw cms::Exception("LogicError") << currentHistoName << " is not found in the Forward map! Aborting.";
205  }
206 
207  if (pxfTh2PolyForwardSummary.find(currentHistoName) != pxfTh2PolyForwardSummary.end()) {
208  pxfTh2PolyForwardSummary[currentHistoName]->AddBin(binsSummary[id]->Clone());
209  } else {
210  throw cms::Exception("LogicError") << currentHistoName << " is not found in the Forward Summary map! Aborting.";
211  }
212  }
213 }
214 
215 //============================================================================
216 void Phase1PixelMaps::book(const std::string& currentHistoName, const char* what, const char* zaxis) {
217  bookBarrelHistograms(currentHistoName, what, zaxis);
218  bookForwardHistograms(currentHistoName, what, zaxis);
219  m_isBooked = std::make_pair(true, true);
220 }
221 
222 //============================================================================
223 void Phase1PixelMaps::fill(const std::string& currentHistoName, unsigned int id, double value) {
224  auto detid = DetId(id);
225  if (detid.subdetId() == PixelSubdetector::PixelBarrel) {
226  int layer = m_trackerTopo.pxbLayer(id);
227  if (!m_isBooked.first) {
228  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to fill a histogram not booked";
229  return;
230  }
231 
232  LogDebug("Phase1PixelMaps") << __func__ << " filling barrel with value: " << value << std::endl;
233 
234  pxbTh2PolyBarrel[currentHistoName][layer - 1]->Fill(TString::Format("%u", id), value);
235  pxbTh2PolyBarrelSummary[currentHistoName]->Fill(TString::Format("%u", id), value);
236  } else if (detid.subdetId() == PixelSubdetector::PixelEndcap) {
237  int disk = m_trackerTopo.pxfDisk(id);
238  int side = m_trackerTopo.pxfSide(id);
239  unsigned mapIdx = disk + (side - 1) * 3 - 1;
240  if (!m_isBooked.second) {
241  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to fill a histogram not booked";
242  return;
243  }
244 
245  LogDebug("Phase1PixelMaps") << __func__ << " filling endcaps with value: " << value << std::endl;
246 
247  pxfTh2PolyForward[currentHistoName][mapIdx]->Fill(TString::Format("%u", id), value);
248  pxfTh2PolyForwardSummary[currentHistoName]->Fill(TString::Format("%u", id), value);
249  }
250 }
251 
252 //============================================================================
253 void Phase1PixelMaps::fillBarrelBin(const std::string& currentHistoName, unsigned int id, double value) {
254  auto detid = DetId(id);
255  if (detid.subdetId() != PixelSubdetector::PixelBarrel) {
256  edm::LogError("Phase1PixelMaps") << "fillBarrelBin() The following detid " << id << " is not Pixel Barrel!"
257  << std::endl;
258  return;
259  }
260  if (!m_isBooked.first) {
261  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to fill a histogram not booked";
262  return;
263  }
264  int layer = m_trackerTopo.pxbLayer(id);
265  pxbTh2PolyBarrel[currentHistoName][layer - 1]->Fill(TString::Format("%u", id), value);
266  pxbTh2PolyBarrelSummary[currentHistoName]->Fill(TString::Format("%u", id), value);
267 }
268 
269 //============================================================================
270 void Phase1PixelMaps::fillForwardBin(const std::string& currentHistoName, unsigned int id, double value) {
271  auto detid = DetId(id);
272  if (detid.subdetId() != PixelSubdetector::PixelEndcap) {
273  edm::LogError("Phase1PixelMaps") << "fillForwardBin() The following detid " << id << " is not Pixel Forward!"
274  << std::endl;
275  return;
276  }
277  if (!m_isBooked.second) {
278  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to fill a histogram not booked";
279  return;
280  }
281  int disk = m_trackerTopo.pxfDisk(id);
282  int side = m_trackerTopo.pxfSide(id);
283  unsigned mapIdx = disk + (side - 1) * 3 - 1;
284  pxfTh2PolyForward[currentHistoName][mapIdx]->Fill(TString::Format("%u", id), value);
285  pxfTh2PolyForwardSummary[currentHistoName]->Fill(TString::Format("%u", id), value);
286 }
287 
288 //============================================================================
290  if (!m_isBooked.first && !m_isBooked.second) {
291  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to beautify a histogram not booked";
292  return;
293  }
294 
295  // only if the barrel is booked
296  if (m_isBooked.first) {
297  for (const auto& vec : pxbTh2PolyBarrel) {
298  for (const auto& plot : vec.second) {
299  this->makeNicePlotStyle(plot.get());
300  plot->GetXaxis()->SetTitleOffset(0.9);
301  plot->GetYaxis()->SetTitleOffset(0.9);
302  plot->GetZaxis()->SetTitleOffset(1.2);
303  plot->GetZaxis()->SetTitleSize(0.05);
304  }
305  }
306  }
307 
308  // only if the forwards are booked
309  if (m_isBooked.second) {
310  for (const auto& vec : pxfTh2PolyForward) {
311  for (const auto& plot : vec.second) {
312  this->makeNicePlotStyle(plot.get());
313  plot->GetXaxis()->SetTitleOffset(0.9);
314  plot->GetYaxis()->SetTitleOffset(0.9);
315  plot->GetZaxis()->SetTitleOffset(1.2);
316  plot->GetZaxis()->SetTitleSize(0.05);
317  }
318  }
319  }
320 }
321 
322 //============================================================================
323 void Phase1PixelMaps::setBarrelScale(const std::string& currentHistoName, std::pair<float, float> extrema) {
324  for (auto& histo : pxbTh2PolyBarrel[currentHistoName]) {
325  histo->GetZaxis()->SetRangeUser(extrema.first, extrema.second);
326  }
327 }
328 
329 //============================================================================
330 void Phase1PixelMaps::setForwardScale(const std::string& currentHistoName, std::pair<float, float> extrema) {
331  for (auto& histo : pxfTh2PolyForward[currentHistoName]) {
332  histo->GetZaxis()->SetRangeUser(extrema.first, extrema.second);
333  }
334 }
335 
336 //============================================================================
337 void Phase1PixelMaps::drawBarrelMaps(const std::string& currentHistoName, TCanvas& canvas, const char* drawOption) {
338  auto found = (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) != m_knownNames.end());
339 
340  if (!m_isBooked.first || !found) {
341  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to draw a histogram not booked";
342  return;
343  }
344 
345  TPad* pad1 = new TPad("pad1", "pad1", 0.0, 0.025, 1.0, 1.0);
346  TPad* pad2 = new TPad("pad2", "pad2", 0.0, 0.00, 1.0, 0.025);
347  pad1->Divide(2, 2);
348  pad1->Draw();
349  pad2->Draw();
350  for (int i = 1; i <= 4; i++) {
351  pad1->cd(i);
352  if (strcmp(m_option, "text") == 0) {
353  pad1->cd(i)->SetRightMargin(0.02);
354  pxbTh2PolyBarrel[currentHistoName].at(i - 1)->SetMarkerColor(kRed);
355  } else {
356  if (m_autorescale)
357  rescaleAllBarrel(currentHistoName);
358  adjustCanvasMargins(pad1->cd(i), 0.07, 0.12, 0.10, 0.18);
359  }
360  if (drawOption) {
361  pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw("L");
362  pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str());
363  } else {
364  pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw("L");
365  pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw(fmt::sprintf("%ssame", m_option).c_str());
366  }
367  }
368 }
369 
370 //============================================================================
371 void Phase1PixelMaps::drawForwardMaps(const std::string& currentHistoName, TCanvas& canvas, const char* drawOption) {
372  auto found = (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) != m_knownNames.end());
373 
374  if (!m_isBooked.second || !found) {
375  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to draw a histogram not booked";
376  return;
377  }
378 
379  TPad* pad1 = new TPad("pad1", "pad1", 0.0, 0.025, 1.0, 1.0);
380  TPad* pad2 = new TPad("pad2", "pad2", 0.0, 0.00, 1.0, 0.025);
381  pad1->Divide(3, 2);
382  pad1->Draw();
383  pad2->Draw();
384 
385  for (int i = 1; i <= 6; i++) {
386  pad1->cd(i);
387  if (strcmp(m_option, "text") == 0) {
388  pad1->cd(i)->SetRightMargin(0.02);
389  pxfTh2PolyForward[currentHistoName].at(i - 1)->SetMarkerColor(kRed);
390  } else {
391  if (m_autorescale)
392  rescaleAllForward(currentHistoName);
393  adjustCanvasMargins(pad1->cd(i), 0.07, 0.12, 0.10, 0.18);
394  }
395  if (drawOption) {
396  pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw("L");
397  pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str());
398  } else {
399  pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw("L");
400  pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw(fmt::sprintf("%ssame", m_option).c_str());
401  }
402  }
403 }
404 
405 //============================================================================
406 void Phase1PixelMaps::drawSummaryMaps(const std::string& currentHistoName, TCanvas& canvas, const char* drawOption) {
407  auto found = (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) != m_knownNames.end());
408 
409  if (!m_isBooked.second || !m_isBooked.first || !found) {
410  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to draw a histogram not booked";
411  return;
412  }
413 
414  TPad* pad1 = new TPad("pad1", "pad1", 0.0, 0.025, 1.0, 1.0);
415  TPad* pad2 = new TPad("pad2", "pad2", 0.0, 0.00, 1.0, 0.025);
416  pad1->Divide(2, 1);
417  pad1->Draw();
418  pad2->Draw();
419 
420  pad1->cd(1);
421  std::string temp(m_option); // create a std string
422  auto isText = (temp.find("text") != std::string::npos);
423  adjustCanvasMargins(pad1->cd(1), 0.07, 0.02, 0.01, isText ? 0.05 : 0.15);
424  if (isText) {
425  pxbTh2PolyBarrelSummary[currentHistoName]->SetMarkerColor(kRed);
426  pxbTh2PolyBarrelSummary[currentHistoName]->SetMarkerSize(0.5);
427  }
428  pxbTh2PolyBarrelSummary[currentHistoName]->GetZaxis()->SetTitleOffset(1.4);
429  pxbTh2PolyBarrelSummary[currentHistoName]->Draw("AL");
430  pxbTh2PolyBarrelSummary[currentHistoName]->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str());
431 
432  pad1->cd(2);
433  adjustCanvasMargins(pad1->cd(2), 0.07, 0.02, 0.01, isText ? 0.05 : 0.15);
434  if (isText) {
435  pxfTh2PolyForwardSummary[currentHistoName]->SetMarkerColor(kRed);
436  pxfTh2PolyForwardSummary[currentHistoName]->SetMarkerSize(0.5);
437  }
438  pxfTh2PolyForwardSummary[currentHistoName]->GetZaxis()->SetTitleOffset(1.4);
439  pxfTh2PolyForwardSummary[currentHistoName]->Draw("AL");
440  pxfTh2PolyForwardSummary[currentHistoName]->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str());
441 }
442 
443 //============================================================================
444 const indexedCorners Phase1PixelMaps::retrieveCorners(const std::vector<edm::FileInPath>& cornerFiles,
445  const unsigned int reads) {
446  indexedCorners theOutMap;
447 
448  for (const auto& file : cornerFiles) {
449  auto cornerFileName = file.fullPath();
450  std::ifstream cornerFile(cornerFileName.c_str());
451  if (!cornerFile.good()) {
452  throw cms::Exception("FileError") << "Problem opening corner file: " << cornerFileName;
453  }
455  while (std::getline(cornerFile, line)) {
456  if (!line.empty()) {
457  std::istringstream iss(line);
458  unsigned int id;
460  std::vector<std::string> corners(reads, "");
461  std::vector<float> xP, yP;
462 
463  iss >> id >> name;
464  for (unsigned int i = 0; i < reads; ++i) {
465  iss >> corners.at(i);
466  }
467 
468  LOGDEBUG("Phase1PixelMaps") << id << " : ";
469  for (unsigned int i = 0; i < reads; i++) {
470  // remove the leading and trailing " signs in the corners list
471  (corners[i]).erase(std::remove(corners[i].begin(), corners[i].end(), '"'), corners[i].end());
472  LOGDEBUG("Phase1PixelMaps") << corners.at(i) << " ";
473  typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
474  boost::char_separator<char> sep{","};
475  tokenizer tok{corners.at(i), sep};
476  for (const auto& t : tok | boost::adaptors::indexed(0)) {
477  if (t.index() == 0) {
478  xP.push_back(atof((t.value()).c_str()));
479  } else if (t.index() == 1) {
480  yP.push_back(atof((t.value()).c_str()));
481  } else {
482  edm::LogError("LogicError") << "There should not be any token with index " << t.index() << std::endl;
483  }
484  }
485  }
486  LOGDEBUG("Phase1PixelMaps") << std::endl;
487 
488  xP.push_back(xP.front());
489  yP.push_back(yP.front());
490 
491  for (unsigned int i = 0; i < xP.size(); i++) {
492  LOGDEBUG("Phase1PixelMaps") << "x[" << i << "]=" << xP[i] << " y[" << i << "]" << yP[i] << std::endl;
493  }
494 
495  theOutMap[id] = std::make_pair(xP, yP);
496 
497  } // if line is empty
498  } // loop on lines
499  } // loop on files
500  return theOutMap;
501 }
502 
503 //============================================================================
505  hist->SetStats(kFALSE);
506  hist->SetLineWidth(2);
507  hist->GetXaxis()->CenterTitle(true);
508  hist->GetYaxis()->CenterTitle(true);
509  hist->GetXaxis()->SetTitleFont(42);
510  hist->GetYaxis()->SetTitleFont(42);
511  hist->GetXaxis()->SetTitleSize(0.05);
512  hist->GetYaxis()->SetTitleSize(0.05);
513  hist->GetXaxis()->SetTitleOffset(1.1);
514  hist->GetYaxis()->SetTitleOffset(1.3);
515  hist->GetXaxis()->SetLabelFont(42);
516  hist->GetYaxis()->SetLabelFont(42);
517  hist->GetYaxis()->SetLabelSize(.05);
518  hist->GetXaxis()->SetLabelSize(.05);
519 
520  if (hist->InheritsFrom(TH2::Class())) {
521  hist->GetZaxis()->SetLabelFont(42);
522  hist->GetZaxis()->SetLabelFont(42);
523  hist->GetZaxis()->SetLabelSize(.05);
524  hist->GetZaxis()->SetLabelSize(.05);
525  }
526 }
527 
528 //============================================================================
529 void Phase1PixelMaps::adjustCanvasMargins(TVirtualPad* pad, float top, float bottom, float left, float right) {
530  if (top > 0)
531  pad->SetTopMargin(top);
532  if (bottom > 0)
533  pad->SetBottomMargin(bottom);
534  if (left > 0)
535  pad->SetLeftMargin(left);
536  if (right > 0)
537  pad->SetRightMargin(right);
538 }
539 
540 //============================================================================
541 void Phase1PixelMaps::rescaleAllBarrel(const std::string& currentHistoName) {
542  if (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) == m_knownNames.end()) {
543  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to manipulate a histogram not booked";
544  return;
545  }
546 
547  std::vector<float> maxima;
548  std::transform(pxbTh2PolyBarrel[currentHistoName].begin(),
549  pxbTh2PolyBarrel[currentHistoName].end(),
550  std::back_inserter(maxima),
551  [](std::shared_ptr<TH2Poly> thp) -> float { return thp->GetMaximum(); });
552  std::vector<float> minima;
553  std::transform(pxbTh2PolyBarrel[currentHistoName].begin(),
554  pxbTh2PolyBarrel[currentHistoName].end(),
555  std::back_inserter(minima),
556  [](std::shared_ptr<TH2Poly> thp) -> float { return thp->GetMinimum(); });
557 
558  auto globalMax = *std::max_element(maxima.begin(), maxima.end());
559  auto globalMin = *std::min_element(minima.begin(), minima.end());
560 
561  // in case the two coincide do not rescale
562  if (globalMax == globalMin)
563  return;
564 
565  for (auto& histo : pxbTh2PolyBarrel[currentHistoName]) {
566  histo->GetZaxis()->SetRangeUser(globalMin, globalMax);
567  }
568 }
569 
570 //============================================================================
571 void Phase1PixelMaps::rescaleAllForward(const std::string& currentHistoName) {
572  if (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) == m_knownNames.end()) {
573  edm::LogError("Phase1PixelMaps") << __func__ << ": trying to manipulate a histogram not booked";
574  return;
575  }
576 
577  std::vector<float> maxima;
578  std::transform(pxfTh2PolyForward[currentHistoName].begin(),
579  pxfTh2PolyForward[currentHistoName].end(),
580  std::back_inserter(maxima),
581  [](std::shared_ptr<TH2Poly> thp) -> float { return thp->GetMaximum(); });
582  std::vector<float> minima;
583  std::transform(pxfTh2PolyForward[currentHistoName].begin(),
584  pxfTh2PolyForward[currentHistoName].end(),
585  std::back_inserter(minima),
586  [](std::shared_ptr<TH2Poly> thp) -> float { return thp->GetMinimum(); });
587 
588  auto globalMax = *std::max_element(maxima.begin(), maxima.end());
589  auto globalMin = *std::min_element(minima.begin(), minima.end());
590 
591  // in case the two coincide do not rescale
592  if (globalMax == globalMin)
593  return;
594 
595  for (auto& histo : pxfTh2PolyForward[currentHistoName]) {
596  histo->GetZaxis()->SetRangeUser(globalMin, globalMax);
597  }
598 }
void drawForwardMaps(const std::string &currentHistoName, TCanvas &canvas, const char *drawOption=nullptr)
unsigned int pxbLayer(const DetId &id) const
std::vector< edm::FileInPath > m_cornersFPIX
void setBarrelScale(const std::string &currentHistoName, std::pair< float, float > extrema)
void adjustCanvasMargins(TVirtualPad *pad, float top, float bottom, float left, float right)
void makeNicePlotStyle(TH1 *hist)
Option_t * m_option
void rescaleAllForward(const std::string &currentHistoName)
unsigned int pxbLadder(const DetId &id) const
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void drawSummaryMaps(const std::string &currentHistoName, TCanvas &canvas, const char *drawOption=nullptr)
static std::string to_string(const XMLCh *ch)
std::map< std::string, std::vector< std::shared_ptr< TH2Poly > > > pxfTh2PolyForward
void fillForwardBin(const std::string &currentHistoName, unsigned int id, double value)
#define LOGDEBUG(x)
std::map< uint32_t, std::shared_ptr< TGraph > > binsSummary
std::vector< edm::FileInPath > m_cornersBPIX
void drawBarrelMaps(const std::string &currentHistoName, TCanvas &canvas, const char *drawOption=nullptr)
std::map< uint32_t, std::shared_ptr< TGraph > > bins
const indexedCorners retrieveCorners(const std::vector< edm::FileInPath > &cornerFiles, const unsigned int reads)
void resetOption(const char *option)
void bookBarrelBins(const std::string &currentHistoName)
TrackerTopology m_trackerTopo
void rescaleAllBarrel(const std::string &currentHistoName)
unsigned int pxfDisk(const DetId &id) const
std::map< unsigned int, std::pair< std::vector< float >, std::vector< float > >> indexedCorners
std::map< std::string, std::vector< std::shared_ptr< TH2Poly > > > pxbTh2PolyBarrel
std::map< std::string, std::shared_ptr< TH2Poly > > pxbTh2PolyBarrelSummary
double f[11][100]
Definition: value.py:1
void bookForwardBins(const std::string &currentHistoName)
void beautifyAllHistograms()
std::pair< bool, bool > m_isBooked
std::map< std::string, std::shared_ptr< TH2Poly > > pxfTh2PolyForwardSummary
Definition: DetId.h:17
std::vector< std::string > m_knownNames
unsigned int pxfSide(const DetId &id) const
void bookBarrelHistograms(const std::string &currentHistoName, const char *what, const char *zaxis)
void book(const std::string &currentHistoName, const char *what, const char *zaxis)
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:233
void bookForwardHistograms(const std::string &currentHistoName, const char *what, const char *zaxis)
void fillBarrelBin(const std::string &currentHistoName, unsigned int id, double value)
def canvas(sub, attr)
Definition: svgfig.py:482
void setForwardScale(const std::string &currentHistoName, std::pair< float, float > extrema)
void fill(const std::string &currentHistoName, unsigned int id, double value)
#define LogDebug(id)
unsigned transform(const HcalDetId &id, unsigned transformCode)