Back to home page

Project CMSSW displayed by LXR

 
 

    


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