File indexing completed on 2023-01-13 23:39:42
0001 #include "TH2Poly.h"
0002 #include "TGraph.h"
0003 #include "TH1.h"
0004 #include "TH2.h"
0005 #include "TStyle.h"
0006 #include "TCanvas.h"
0007
0008 #include <fmt/printf.h>
0009 #include <fstream>
0010 #include <boost/tokenizer.hpp>
0011 #include <boost/range/adaptor/indexed.hpp>
0012
0013 #include "FWCore/ParameterSet/interface/FileInPath.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0016 #include "DQM/TrackerRemapper/interface/Phase1PixelMaps.h"
0017
0018
0019
0020 void Phase1PixelMaps::resetOption(const char* option) {
0021 if (m_option != nullptr && !m_option[0]) {
0022 m_option = option;
0023 } else {
0024 edm::LogError("Phase1PixelMaps") << "Option has already been set to " << m_option
0025 << ". It's not possible to reset it.";
0026 }
0027 }
0028
0029
0030 void Phase1PixelMaps::bookBarrelHistograms(const std::string& currentHistoName, const char* what, const char* zaxis) {
0031 std::string histName;
0032 std::shared_ptr<TH2Poly> th2p;
0033
0034
0035 if (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) == m_knownNames.end()) {
0036 m_knownNames.emplace_back(currentHistoName);
0037 }
0038
0039 for (unsigned i = 0; i < 4; ++i) {
0040 histName = "barrel_layer_";
0041
0042 th2p = std::make_shared<TH2Poly>(
0043 (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);
0044
0045 th2p->SetFloat();
0046
0047 th2p->GetXaxis()->SetTitle("z [cm]");
0048 th2p->GetYaxis()->SetTitle("ladder");
0049 th2p->GetZaxis()->SetTitle(zaxis);
0050 th2p->GetZaxis()->CenterTitle();
0051 th2p->SetStats(false);
0052 th2p->SetOption(m_option);
0053 pxbTh2PolyBarrel[currentHistoName].push_back(th2p);
0054 }
0055
0056 th2p = std::make_shared<TH2Poly>("barrel_summary", Form("Barrel Pixel Map of %s", what), -5.0, 5.0, 0.0, 15.0);
0057 th2p->SetFloat();
0058
0059 th2p->GetXaxis()->SetTitle("");
0060 th2p->GetYaxis()->SetTitle("");
0061 th2p->GetZaxis()->SetTitle(zaxis);
0062 th2p->GetZaxis()->CenterTitle();
0063 th2p->SetStats(false);
0064 th2p->SetOption(m_option);
0065 pxbTh2PolyBarrelSummary[currentHistoName] = th2p;
0066
0067
0068 bookBarrelBins(currentHistoName);
0069
0070
0071 m_isBooked.first = true;
0072 }
0073
0074
0075 void Phase1PixelMaps::bookForwardHistograms(const std::string& currentHistoName, const char* what, const char* zaxis) {
0076 std::string histName;
0077 std::shared_ptr<TH2Poly> th2p;
0078
0079
0080 if (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) == m_knownNames.end()) {
0081 m_knownNames.emplace_back(currentHistoName);
0082 }
0083
0084 for (unsigned side = 1; side <= 2; ++side) {
0085 for (unsigned disk = 1; disk <= 3; ++disk) {
0086 histName = "forward_disk_";
0087
0088 th2p = std::make_shared<TH2Poly>((histName + std::to_string((side == 1 ? -(int(disk)) : (int)disk))).c_str(),
0089 Form("PXFMap of %s - Side %i Disk %i", what, side, disk),
0090 -15.0,
0091 15.0,
0092 -15.0,
0093 15.0);
0094 th2p->SetFloat();
0095 th2p->GetXaxis()->SetTitle("x [cm]");
0096 th2p->GetYaxis()->SetTitle("y [cm]");
0097 th2p->GetZaxis()->SetTitle(zaxis);
0098 th2p->GetZaxis()->CenterTitle();
0099 th2p->SetStats(false);
0100 th2p->SetOption(m_option);
0101 pxfTh2PolyForward[currentHistoName].push_back(th2p);
0102 }
0103 }
0104
0105 th2p = std::make_shared<TH2Poly>("forward_summary", Form("Forward Pixel Map of %s", what), -40.0, 40.0, -20.0, 90.0);
0106 th2p->SetFloat();
0107
0108 th2p->GetXaxis()->SetTitle("");
0109 th2p->GetYaxis()->SetTitle("");
0110 th2p->GetZaxis()->SetTitle(zaxis);
0111 th2p->GetZaxis()->CenterTitle();
0112 th2p->SetStats(false);
0113 th2p->SetOption(m_option);
0114 pxfTh2PolyForwardSummary[currentHistoName] = th2p;
0115
0116
0117 bookForwardBins(currentHistoName);
0118
0119 m_isBooked.second = true;
0120 }
0121
0122
0123 void Phase1PixelMaps::bookBarrelBins(const std::string& currentHistoName) {
0124 auto theIndexedCorners = this->retrieveCorners(m_cornersBPIX, 4);
0125
0126 for (const auto& entry : theIndexedCorners) {
0127 auto id = entry.first;
0128 auto detid = DetId(id);
0129 if (detid.subdetId() != PixelSubdetector::PixelBarrel)
0130 continue;
0131
0132 int layer = m_trackerTopo.pxbLayer(detid);
0133 int ladder = m_trackerTopo.pxbLadder(detid);
0134
0135 auto theVectX = entry.second.first;
0136 auto theVectY = entry.second.second;
0137
0138 float vertX[] = {theVectX[0], theVectX[1], theVectX[2], theVectX[3], theVectX[4]};
0139 float vertY[] = {(ladder - 1.0f), (ladder - 1.0f), (float)ladder, (float)ladder, (ladder - 1.0f)};
0140
0141 bins[id] = std::make_shared<TGraph>(5, vertX, vertY);
0142 bins[id]->SetName(TString::Format("%u", id));
0143
0144
0145 for (unsigned k = 0; k < 5; ++k) {
0146 vertX[k] += ((layer == 2 || layer == 3) ? 0.0f : -60.0f);
0147 vertY[k] += ((layer > 2) ? 30.0f : 0.0f);
0148 }
0149
0150 binsSummary[id] = std::make_shared<TGraph>(5, vertX, vertY);
0151 binsSummary[id]->SetName(TString::Format("%u", id));
0152
0153 if (pxbTh2PolyBarrel.find(currentHistoName) != pxbTh2PolyBarrel.end()) {
0154 pxbTh2PolyBarrel[currentHistoName][layer - 1]->AddBin(bins[id]->Clone());
0155 } else {
0156 throw cms::Exception("LogicError") << currentHistoName << " is not found in the Barrel map! Aborting.";
0157 }
0158
0159 if (pxbTh2PolyBarrelSummary.find(currentHistoName) != pxbTh2PolyBarrelSummary.end()) {
0160 pxbTh2PolyBarrelSummary[currentHistoName]->AddBin(binsSummary[id]->Clone());
0161 } else {
0162 throw cms::Exception("LocalError") << currentHistoName << " is not found in the Barrel Summary map! Aborting.";
0163 }
0164 }
0165 }
0166
0167
0168 void Phase1PixelMaps::bookForwardBins(const std::string& currentHistoName) {
0169 auto theIndexedCorners = this->retrieveCorners(m_cornersFPIX, 3);
0170
0171 for (const auto& entry : theIndexedCorners) {
0172 auto id = entry.first;
0173 auto detid = DetId(id);
0174 if (detid.subdetId() != PixelSubdetector::PixelEndcap)
0175 continue;
0176
0177 int disk = m_trackerTopo.pxfDisk(detid);
0178 int side = m_trackerTopo.pxfSide(detid);
0179
0180 unsigned mapIdx = disk + (side - 1) * 3 - 1;
0181
0182 auto theVectX = entry.second.first;
0183 auto theVectY = entry.second.second;
0184
0185 float vertX[] = {theVectX[0], theVectX[1], theVectX[2], theVectX[3]};
0186 float vertY[] = {theVectY[0], theVectY[1], theVectY[2], theVectY[3]};
0187
0188 bins[id] = std::make_shared<TGraph>(4, vertX, vertY);
0189 bins[id]->SetName(TString::Format("%u", id));
0190
0191
0192 for (unsigned k = 0; k < 4; ++k) {
0193 vertX[k] += (float(side) - 1.5f) * 40.0f;
0194 vertY[k] += (disk - 1) * 35.0f;
0195 }
0196
0197 binsSummary[id] = std::make_shared<TGraph>(4, vertX, vertY);
0198 binsSummary[id]->SetName(TString::Format("%u", id));
0199
0200 if (pxfTh2PolyForward.find(currentHistoName) != pxfTh2PolyForward.end()) {
0201 pxfTh2PolyForward[currentHistoName][mapIdx]->AddBin(bins[id]->Clone());
0202 } else {
0203 throw cms::Exception("LogicError") << currentHistoName << " is not found in the Forward map! Aborting.";
0204 }
0205
0206 if (pxfTh2PolyForwardSummary.find(currentHistoName) != pxfTh2PolyForwardSummary.end()) {
0207 pxfTh2PolyForwardSummary[currentHistoName]->AddBin(binsSummary[id]->Clone());
0208 } else {
0209 throw cms::Exception("LogicError") << currentHistoName << " is not found in the Forward Summary map! Aborting.";
0210 }
0211 }
0212 }
0213
0214
0215 void Phase1PixelMaps::book(const std::string& currentHistoName, const char* what, const char* zaxis) {
0216 bookBarrelHistograms(currentHistoName, what, zaxis);
0217 bookForwardHistograms(currentHistoName, what, zaxis);
0218 m_isBooked = std::make_pair(true, true);
0219 }
0220
0221
0222 void Phase1PixelMaps::fill(const std::string& currentHistoName, unsigned int id, double value) {
0223 auto detid = DetId(id);
0224 if (detid.subdetId() == PixelSubdetector::PixelBarrel) {
0225 int layer = m_trackerTopo.pxbLayer(id);
0226 if (!m_isBooked.first) {
0227 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to fill a histogram not booked";
0228 return;
0229 }
0230
0231 LogDebug("Phase1PixelMaps") << __func__ << " filling barrel with value: " << value << std::endl;
0232
0233 pxbTh2PolyBarrel[currentHistoName][layer - 1]->Fill(TString::Format("%u", id), value);
0234 pxbTh2PolyBarrelSummary[currentHistoName]->Fill(TString::Format("%u", id), value);
0235 } else if (detid.subdetId() == PixelSubdetector::PixelEndcap) {
0236 int disk = m_trackerTopo.pxfDisk(id);
0237 int side = m_trackerTopo.pxfSide(id);
0238 unsigned mapIdx = disk + (side - 1) * 3 - 1;
0239 if (!m_isBooked.second) {
0240 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to fill a histogram not booked";
0241 return;
0242 }
0243
0244 LogDebug("Phase1PixelMaps") << __func__ << " filling endcaps with value: " << value << std::endl;
0245
0246 pxfTh2PolyForward[currentHistoName][mapIdx]->Fill(TString::Format("%u", id), value);
0247 pxfTh2PolyForwardSummary[currentHistoName]->Fill(TString::Format("%u", id), value);
0248 }
0249 }
0250
0251
0252 void Phase1PixelMaps::fillBarrelBin(const std::string& currentHistoName, unsigned int id, double value) {
0253 auto detid = DetId(id);
0254 if (detid.subdetId() != PixelSubdetector::PixelBarrel) {
0255 edm::LogError("Phase1PixelMaps") << "fillBarrelBin() The following detid " << id << " is not Pixel Barrel!"
0256 << std::endl;
0257 return;
0258 }
0259 if (!m_isBooked.first) {
0260 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to fill a histogram not booked";
0261 return;
0262 }
0263 int layer = m_trackerTopo.pxbLayer(id);
0264 pxbTh2PolyBarrel[currentHistoName][layer - 1]->Fill(TString::Format("%u", id), value);
0265 pxbTh2PolyBarrelSummary[currentHistoName]->Fill(TString::Format("%u", id), value);
0266 }
0267
0268
0269 void Phase1PixelMaps::fillForwardBin(const std::string& currentHistoName, unsigned int id, double value) {
0270 auto detid = DetId(id);
0271 if (detid.subdetId() != PixelSubdetector::PixelEndcap) {
0272 edm::LogError("Phase1PixelMaps") << "fillForwardBin() The following detid " << id << " is not Pixel Forward!"
0273 << std::endl;
0274 return;
0275 }
0276 if (!m_isBooked.second) {
0277 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to fill a histogram not booked";
0278 return;
0279 }
0280 int disk = m_trackerTopo.pxfDisk(id);
0281 int side = m_trackerTopo.pxfSide(id);
0282 unsigned mapIdx = disk + (side - 1) * 3 - 1;
0283 pxfTh2PolyForward[currentHistoName][mapIdx]->Fill(TString::Format("%u", id), value);
0284 pxfTh2PolyForwardSummary[currentHistoName]->Fill(TString::Format("%u", id), value);
0285 }
0286
0287
0288 void Phase1PixelMaps::beautifyAllHistograms() {
0289 if (!m_isBooked.first && !m_isBooked.second) {
0290 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to beautify a histogram not booked";
0291 return;
0292 }
0293
0294
0295 if (m_isBooked.first) {
0296 for (const auto& vec : pxbTh2PolyBarrel) {
0297 for (const auto& plot : vec.second) {
0298 this->makeNicePlotStyle(plot.get());
0299 plot->GetXaxis()->SetTitleOffset(0.9);
0300 plot->GetYaxis()->SetTitleOffset(0.9);
0301 plot->GetZaxis()->SetTitleOffset(1.2);
0302 plot->GetZaxis()->SetTitleSize(0.05);
0303 }
0304 }
0305 }
0306
0307
0308 if (m_isBooked.second) {
0309 for (const auto& vec : pxfTh2PolyForward) {
0310 for (const auto& plot : vec.second) {
0311 this->makeNicePlotStyle(plot.get());
0312 plot->GetXaxis()->SetTitleOffset(0.9);
0313 plot->GetYaxis()->SetTitleOffset(0.9);
0314 plot->GetZaxis()->SetTitleOffset(1.2);
0315 plot->GetZaxis()->SetTitleSize(0.05);
0316 }
0317 }
0318 }
0319 }
0320
0321
0322 void Phase1PixelMaps::setBarrelScale(const std::string& currentHistoName, std::pair<float, float> extrema) {
0323 for (auto& histo : pxbTh2PolyBarrel[currentHistoName]) {
0324 histo->GetZaxis()->SetRangeUser(extrema.first, extrema.second);
0325 }
0326 }
0327
0328
0329 void Phase1PixelMaps::setForwardScale(const std::string& currentHistoName, std::pair<float, float> extrema) {
0330 for (auto& histo : pxfTh2PolyForward[currentHistoName]) {
0331 histo->GetZaxis()->SetRangeUser(extrema.first, extrema.second);
0332 }
0333 }
0334
0335
0336 void Phase1PixelMaps::drawBarrelMaps(const std::string& currentHistoName, TCanvas& canvas, const char* drawOption) {
0337 canvas.Divide(2, 2);
0338 auto found = (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) != m_knownNames.end());
0339
0340 if (!m_isBooked.first || !found) {
0341 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to draw a histogram not booked";
0342 return;
0343 }
0344
0345 for (int i = 1; i <= 4; i++) {
0346 canvas.cd(i);
0347 if (strcmp(m_option, "text") == 0) {
0348 canvas.cd(i)->SetRightMargin(0.02);
0349 pxbTh2PolyBarrel[currentHistoName].at(i - 1)->SetMarkerColor(kRed);
0350 } else {
0351 if (m_autorescale)
0352 rescaleAllBarrel(currentHistoName);
0353 adjustCanvasMargins(canvas.cd(i), 0.07, 0.12, 0.10, 0.18);
0354 }
0355 if (drawOption) {
0356 pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw("L");
0357 pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str());
0358 } else {
0359 pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw("L");
0360 pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw(fmt::sprintf("%ssame", m_option).c_str());
0361 }
0362 }
0363 }
0364
0365
0366 void Phase1PixelMaps::drawForwardMaps(const std::string& currentHistoName, TCanvas& canvas, const char* drawOption) {
0367 canvas.Divide(3, 2);
0368 auto found = (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) != m_knownNames.end());
0369
0370 if (!m_isBooked.second || !found) {
0371 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to draw a histogram not booked";
0372 return;
0373 }
0374
0375 for (int i = 1; i <= 6; i++) {
0376 canvas.cd(i);
0377 if (strcmp(m_option, "text") == 0) {
0378 canvas.cd(i)->SetRightMargin(0.02);
0379 pxfTh2PolyForward[currentHistoName].at(i - 1)->SetMarkerColor(kRed);
0380 } else {
0381 if (m_autorescale)
0382 rescaleAllForward(currentHistoName);
0383 adjustCanvasMargins(canvas.cd(i), 0.07, 0.12, 0.10, 0.18);
0384 }
0385 if (drawOption) {
0386 pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw("L");
0387 pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str());
0388 } else {
0389 pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw("L");
0390 pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw(fmt::sprintf("%ssame", m_option).c_str());
0391 }
0392 }
0393 }
0394
0395
0396 void Phase1PixelMaps::drawSummaryMaps(const std::string& currentHistoName, TCanvas& canvas, const char* drawOption) {
0397 auto found = (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) != m_knownNames.end());
0398
0399 if (!m_isBooked.second || !m_isBooked.first || !found) {
0400 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to draw a histogram not booked";
0401 return;
0402 }
0403
0404 canvas.Divide(2, 1);
0405 canvas.cd(1);
0406 std::string temp(m_option);
0407 auto isText = (temp.find("text") != std::string::npos);
0408 adjustCanvasMargins(canvas.cd(1), 0.07, 0.02, 0.01, isText ? 0.05 : 0.15);
0409 if (isText) {
0410 pxbTh2PolyBarrelSummary[currentHistoName]->SetMarkerColor(kRed);
0411 pxbTh2PolyBarrelSummary[currentHistoName]->SetMarkerSize(0.5);
0412 }
0413 pxbTh2PolyBarrelSummary[currentHistoName]->GetZaxis()->SetTitleOffset(1.4);
0414 pxbTh2PolyBarrelSummary[currentHistoName]->Draw("AL");
0415 pxbTh2PolyBarrelSummary[currentHistoName]->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str());
0416
0417 canvas.cd(2);
0418 adjustCanvasMargins(canvas.cd(2), 0.07, 0.02, 0.01, isText ? 0.05 : 0.15);
0419 if (isText) {
0420 pxfTh2PolyForwardSummary[currentHistoName]->SetMarkerColor(kRed);
0421 pxfTh2PolyForwardSummary[currentHistoName]->SetMarkerSize(0.5);
0422 }
0423 pxfTh2PolyForwardSummary[currentHistoName]->GetZaxis()->SetTitleOffset(1.4);
0424 pxfTh2PolyForwardSummary[currentHistoName]->Draw("AL");
0425 pxfTh2PolyForwardSummary[currentHistoName]->Draw(fmt::sprintf("%s%ssame", m_option, drawOption).c_str());
0426 }
0427
0428
0429 const indexedCorners Phase1PixelMaps::retrieveCorners(const std::vector<edm::FileInPath>& cornerFiles,
0430 const unsigned int reads) {
0431 indexedCorners theOutMap;
0432
0433 for (const auto& file : cornerFiles) {
0434 auto cornerFileName = file.fullPath();
0435 std::ifstream cornerFile(cornerFileName.c_str());
0436 if (!cornerFile.good()) {
0437 throw cms::Exception("FileError") << "Problem opening corner file: " << cornerFileName;
0438 }
0439 std::string line;
0440 while (std::getline(cornerFile, line)) {
0441 if (!line.empty()) {
0442 std::istringstream iss(line);
0443 unsigned int id;
0444 std::string name;
0445 std::vector<std::string> corners(reads, "");
0446 std::vector<float> xP, yP;
0447
0448 iss >> id >> name;
0449 for (unsigned int i = 0; i < reads; ++i) {
0450 iss >> corners.at(i);
0451 }
0452
0453 LOGDEBUG("Phase1PixelMaps") << id << " : ";
0454 for (unsigned int i = 0; i < reads; i++) {
0455
0456 (corners[i]).erase(std::remove(corners[i].begin(), corners[i].end(), '"'), corners[i].end());
0457 LOGDEBUG("Phase1PixelMaps") << corners.at(i) << " ";
0458 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
0459 boost::char_separator<char> sep{","};
0460 tokenizer tok{corners.at(i), sep};
0461 for (const auto& t : tok | boost::adaptors::indexed(0)) {
0462 if (t.index() == 0) {
0463 xP.push_back(atof((t.value()).c_str()));
0464 } else if (t.index() == 1) {
0465 yP.push_back(atof((t.value()).c_str()));
0466 } else {
0467 edm::LogError("LogicError") << "There should not be any token with index " << t.index() << std::endl;
0468 }
0469 }
0470 }
0471 LOGDEBUG("Phase1PixelMaps") << std::endl;
0472
0473 xP.push_back(xP.front());
0474 yP.push_back(yP.front());
0475
0476 for (unsigned int i = 0; i < xP.size(); i++) {
0477 LOGDEBUG("Phase1PixelMaps") << "x[" << i << "]=" << xP[i] << " y[" << i << "]" << yP[i] << std::endl;
0478 }
0479
0480 theOutMap[id] = std::make_pair(xP, yP);
0481
0482 }
0483 }
0484 }
0485 return theOutMap;
0486 }
0487
0488
0489 void Phase1PixelMaps::makeNicePlotStyle(TH1* hist) {
0490 hist->SetStats(kFALSE);
0491 hist->SetLineWidth(2);
0492 hist->GetXaxis()->CenterTitle(true);
0493 hist->GetYaxis()->CenterTitle(true);
0494 hist->GetXaxis()->SetTitleFont(42);
0495 hist->GetYaxis()->SetTitleFont(42);
0496 hist->GetXaxis()->SetTitleSize(0.05);
0497 hist->GetYaxis()->SetTitleSize(0.05);
0498 hist->GetXaxis()->SetTitleOffset(1.1);
0499 hist->GetYaxis()->SetTitleOffset(1.3);
0500 hist->GetXaxis()->SetLabelFont(42);
0501 hist->GetYaxis()->SetLabelFont(42);
0502 hist->GetYaxis()->SetLabelSize(.05);
0503 hist->GetXaxis()->SetLabelSize(.05);
0504
0505 if (hist->InheritsFrom(TH2::Class())) {
0506 hist->GetZaxis()->SetLabelFont(42);
0507 hist->GetZaxis()->SetLabelFont(42);
0508 hist->GetZaxis()->SetLabelSize(.05);
0509 hist->GetZaxis()->SetLabelSize(.05);
0510 }
0511 }
0512
0513
0514 void Phase1PixelMaps::adjustCanvasMargins(TVirtualPad* pad, float top, float bottom, float left, float right) {
0515 if (top > 0)
0516 pad->SetTopMargin(top);
0517 if (bottom > 0)
0518 pad->SetBottomMargin(bottom);
0519 if (left > 0)
0520 pad->SetLeftMargin(left);
0521 if (right > 0)
0522 pad->SetRightMargin(right);
0523 }
0524
0525
0526 void Phase1PixelMaps::rescaleAllBarrel(const std::string& currentHistoName) {
0527 if (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) == m_knownNames.end()) {
0528 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to manipulate a histogram not booked";
0529 return;
0530 }
0531
0532 std::vector<float> maxima;
0533 std::transform(pxbTh2PolyBarrel[currentHistoName].begin(),
0534 pxbTh2PolyBarrel[currentHistoName].end(),
0535 std::back_inserter(maxima),
0536 [](std::shared_ptr<TH2Poly> thp) -> float { return thp->GetMaximum(); });
0537 std::vector<float> minima;
0538 std::transform(pxbTh2PolyBarrel[currentHistoName].begin(),
0539 pxbTh2PolyBarrel[currentHistoName].end(),
0540 std::back_inserter(minima),
0541 [](std::shared_ptr<TH2Poly> thp) -> float { return thp->GetMinimum(); });
0542
0543 auto globalMax = *std::max_element(maxima.begin(), maxima.end());
0544 auto globalMin = *std::min_element(minima.begin(), minima.end());
0545
0546
0547 if (globalMax == globalMin)
0548 return;
0549
0550 for (auto& histo : pxbTh2PolyBarrel[currentHistoName]) {
0551 histo->GetZaxis()->SetRangeUser(globalMin, globalMax);
0552 }
0553 }
0554
0555
0556 void Phase1PixelMaps::rescaleAllForward(const std::string& currentHistoName) {
0557 if (std::find(m_knownNames.begin(), m_knownNames.end(), currentHistoName) == m_knownNames.end()) {
0558 edm::LogError("Phase1PixelMaps") << __func__ << ": trying to manipulate a histogram not booked";
0559 return;
0560 }
0561
0562 std::vector<float> maxima;
0563 std::transform(pxfTh2PolyForward[currentHistoName].begin(),
0564 pxfTh2PolyForward[currentHistoName].end(),
0565 std::back_inserter(maxima),
0566 [](std::shared_ptr<TH2Poly> thp) -> float { return thp->GetMaximum(); });
0567 std::vector<float> minima;
0568 std::transform(pxfTh2PolyForward[currentHistoName].begin(),
0569 pxfTh2PolyForward[currentHistoName].end(),
0570 std::back_inserter(minima),
0571 [](std::shared_ptr<TH2Poly> thp) -> float { return thp->GetMinimum(); });
0572
0573 auto globalMax = *std::max_element(maxima.begin(), maxima.end());
0574 auto globalMin = *std::min_element(minima.begin(), minima.end());
0575
0576
0577 if (globalMax == globalMin)
0578 return;
0579
0580 for (auto& histo : pxfTh2PolyForward[currentHistoName]) {
0581 histo->GetZaxis()->SetRangeUser(globalMin, globalMax);
0582 }
0583 }