8 #include <fmt/printf.h> 10 #include <boost/tokenizer.hpp> 11 #include <boost/range/adaptor/indexed.hpp> 25 <<
". It's not possible to reset it.";
32 std::shared_ptr<TH2Poly> th2p;
39 for (
unsigned i = 0;
i < 4; ++
i) {
40 histName =
"barrel_layer_";
42 th2p = std::make_shared<TH2Poly>(
43 (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);
47 th2p->GetXaxis()->SetTitle(
"z [cm]");
48 th2p->GetYaxis()->SetTitle(
"ladder");
49 th2p->GetZaxis()->SetTitle(
zaxis);
50 th2p->GetZaxis()->CenterTitle();
51 th2p->SetStats(
false);
56 th2p = std::make_shared<TH2Poly>(
"barrel_summary", Form(
"Barrel Pixel Map of %s", what), -5.0, 5.0, 0.0, 15.0);
59 th2p->GetXaxis()->SetTitle(
"");
60 th2p->GetYaxis()->SetTitle(
"");
61 th2p->GetZaxis()->SetTitle(
zaxis);
62 th2p->GetZaxis()->CenterTitle();
63 th2p->SetStats(
false);
77 std::shared_ptr<TH2Poly> th2p;
84 for (
unsigned side = 1; side <= 2; ++side) {
85 for (
unsigned disk = 1; disk <= 3; ++disk) {
86 histName =
"forward_disk_";
88 th2p = std::make_shared<TH2Poly>((histName +
std::to_string((side == 1 ? -(
int(disk)) : (
int)disk))).c_str(),
89 Form(
"PXFMap of %s - Side %i Disk %i", what, side, disk),
95 th2p->GetXaxis()->SetTitle(
"x [cm]");
96 th2p->GetYaxis()->SetTitle(
"y [cm]");
97 th2p->GetZaxis()->SetTitle(
zaxis);
98 th2p->GetZaxis()->CenterTitle();
99 th2p->SetStats(
false);
105 th2p = std::make_shared<TH2Poly>(
"forward_summary", Form(
"Forward Pixel Map of %s", what), -40.0, 40.0, -20.0, 90.0);
108 th2p->GetXaxis()->SetTitle(
"");
109 th2p->GetYaxis()->SetTitle(
"");
110 th2p->GetZaxis()->SetTitle(
zaxis);
111 th2p->GetZaxis()->CenterTitle();
112 th2p->SetStats(
false);
126 for (
const auto&
entry : theIndexedCorners) {
127 auto id =
entry.first;
128 auto detid =
DetId(
id);
135 auto theVectX =
entry.second.first;
136 auto theVectY =
entry.second.second;
138 float vertX[] = {theVectX[0], theVectX[1], theVectX[2], theVectX[3], theVectX[4]};
141 bins[
id] = std::make_shared<TGraph>(5, vertX, vertY);
142 bins[
id]->SetName(TString::Format(
"%u",
id));
145 for (
unsigned k = 0;
k < 5; ++
k) {
147 vertY[
k] += ((
layer > 2) ? 30.0
f : 0.0
f);
156 throw cms::Exception(
"LogicError") << currentHistoName <<
" is not found in the Barrel map! Aborting.";
162 throw cms::Exception(
"LocalError") << currentHistoName <<
" is not found in the Barrel Summary map! Aborting.";
171 for (
const auto&
entry : theIndexedCorners) {
172 auto id =
entry.first;
173 auto detid =
DetId(
id);
180 unsigned mapIdx = disk + (side - 1) * 3 - 1;
182 auto theVectX =
entry.second.first;
183 auto theVectY =
entry.second.second;
185 float vertX[] = {theVectX[0], theVectX[1], theVectX[2], theVectX[3]};
186 float vertY[] = {theVectY[0], theVectY[1], theVectY[2], theVectY[3]};
188 bins[
id] = std::make_shared<TGraph>(4, vertX, vertY);
189 bins[
id]->SetName(TString::Format(
"%u",
id));
192 for (
unsigned k = 0;
k < 4; ++
k) {
193 vertX[
k] += (
float(side) - 1.5f) * 40.0
f;
194 vertY[
k] += (disk - 1) * 35.0
f;
203 throw cms::Exception(
"LogicError") << currentHistoName <<
" is not found in the Forward map! Aborting.";
209 throw cms::Exception(
"LogicError") << currentHistoName <<
" is not found in the Forward Summary map! Aborting.";
223 auto detid =
DetId(
id);
227 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to fill a histogram not booked";
231 LogDebug(
"Phase1PixelMaps") << __func__ <<
" filling barrel with value: " <<
value << std::endl;
238 unsigned mapIdx = disk + (side - 1) * 3 - 1;
240 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to fill a histogram not booked";
244 LogDebug(
"Phase1PixelMaps") << __func__ <<
" filling endcaps with value: " <<
value << std::endl;
253 auto detid =
DetId(
id);
255 edm::LogError(
"Phase1PixelMaps") <<
"fillBarrelBin() The following detid " <<
id <<
" is not Pixel Barrel!" 260 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to fill a histogram not booked";
270 auto detid =
DetId(
id);
272 edm::LogError(
"Phase1PixelMaps") <<
"fillForwardBin() The following detid " <<
id <<
" is not Pixel Forward!" 277 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to fill a histogram not booked";
282 unsigned mapIdx = disk + (side - 1) * 3 - 1;
290 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to beautify a histogram not booked";
297 for (
const auto&
plot : vec.second) {
299 plot->GetXaxis()->SetTitleOffset(0.9);
300 plot->GetYaxis()->SetTitleOffset(0.9);
301 plot->GetZaxis()->SetTitleOffset(1.2);
302 plot->GetZaxis()->SetTitleSize(0.05);
310 for (
const auto&
plot : vec.second) {
312 plot->GetXaxis()->SetTitleOffset(0.9);
313 plot->GetYaxis()->SetTitleOffset(0.9);
314 plot->GetZaxis()->SetTitleOffset(1.2);
315 plot->GetZaxis()->SetTitleSize(0.05);
324 histo->GetZaxis()->SetRangeUser(extrema.first, extrema.second);
331 histo->GetZaxis()->SetRangeUser(extrema.first, extrema.second);
341 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to draw a histogram not booked";
345 for (
int i = 1;
i <= 4;
i++) {
347 if (strcmp(
m_option,
"text") == 0) {
348 canvas.cd(
i)->SetRightMargin(0.02);
371 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to draw a histogram not booked";
375 for (
int i = 1;
i <= 6;
i++) {
377 if (strcmp(
m_option,
"text") == 0) {
378 canvas.cd(
i)->SetRightMargin(0.02);
400 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to draw a histogram not booked";
407 auto isText = (
temp.find(
"text") != std::string::npos);
430 const unsigned int reads) {
433 for (
const auto&
file : cornerFiles) {
434 auto cornerFileName =
file.fullPath();
435 std::ifstream cornerFile(cornerFileName.c_str());
436 if (!cornerFile.good()) {
437 throw cms::Exception(
"FileError") <<
"Problem opening corner file: " << cornerFileName;
440 while (std::getline(cornerFile,
line)) {
442 std::istringstream iss(
line);
445 std::vector<std::string> corners(reads,
"");
446 std::vector<float> xP, yP;
449 for (
unsigned int i = 0;
i < reads; ++
i) {
450 iss >> corners.at(
i);
453 LOGDEBUG(
"Phase1PixelMaps") <<
id <<
" : ";
454 for (
unsigned int i = 0;
i < reads;
i++) {
456 (corners[
i]).erase(
std::remove(corners[
i].begin(), corners[
i].
end(),
'"'), corners[
i].end());
457 LOGDEBUG(
"Phase1PixelMaps") << corners.at(
i) <<
" ";
458 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
459 boost::char_separator<char> sep{
","};
460 tokenizer tok{corners.at(
i), sep};
461 for (
const auto&
t : tok | boost::adaptors::indexed(0)) {
462 if (
t.index() == 0) {
463 xP.push_back(atof((
t.value()).c_str()));
464 }
else if (
t.index() == 1) {
465 yP.push_back(atof((
t.value()).c_str()));
467 edm::LogError(
"LogicError") <<
"There should not be any token with index " <<
t.index() << std::endl;
471 LOGDEBUG(
"Phase1PixelMaps") << std::endl;
473 xP.push_back(xP.front());
474 yP.push_back(yP.front());
476 for (
unsigned int i = 0;
i < xP.size();
i++) {
477 LOGDEBUG(
"Phase1PixelMaps") <<
"x[" <<
i <<
"]=" << xP[
i] <<
" y[" <<
i <<
"]" << yP[
i] << std::endl;
480 theOutMap[
id] = std::make_pair(xP, yP);
490 hist->SetStats(kFALSE);
491 hist->SetLineWidth(2);
492 hist->GetXaxis()->CenterTitle(
true);
493 hist->GetYaxis()->CenterTitle(
true);
494 hist->GetXaxis()->SetTitleFont(42);
495 hist->GetYaxis()->SetTitleFont(42);
496 hist->GetXaxis()->SetTitleSize(0.05);
497 hist->GetYaxis()->SetTitleSize(0.05);
498 hist->GetXaxis()->SetTitleOffset(1.1);
499 hist->GetYaxis()->SetTitleOffset(1.3);
500 hist->GetXaxis()->SetLabelFont(42);
501 hist->GetYaxis()->SetLabelFont(42);
502 hist->GetYaxis()->SetLabelSize(.05);
503 hist->GetXaxis()->SetLabelSize(.05);
506 hist->GetZaxis()->SetLabelFont(42);
507 hist->GetZaxis()->SetLabelFont(42);
508 hist->GetZaxis()->SetLabelSize(.05);
509 hist->GetZaxis()->SetLabelSize(.05);
516 pad->SetTopMargin(top);
518 pad->SetBottomMargin(bottom);
520 pad->SetLeftMargin(left);
522 pad->SetRightMargin(right);
528 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to manipulate a histogram not booked";
532 std::vector<float> maxima;
535 std::back_inserter(maxima),
536 [](std::shared_ptr<TH2Poly> thp) ->
float {
return thp->GetMaximum(); });
537 std::vector<float> minima;
540 std::back_inserter(minima),
541 [](std::shared_ptr<TH2Poly> thp) ->
float {
return thp->GetMinimum(); });
543 auto globalMax = *std::max_element(maxima.begin(), maxima.end());
544 auto globalMin = *std::min_element(minima.begin(), minima.end());
547 if (globalMax == globalMin)
551 histo->GetZaxis()->SetRangeUser(globalMin, globalMax);
558 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to manipulate a histogram not booked";
562 std::vector<float> maxima;
565 std::back_inserter(maxima),
566 [](std::shared_ptr<TH2Poly> thp) ->
float {
return thp->GetMaximum(); });
567 std::vector<float> minima;
570 std::back_inserter(minima),
571 [](std::shared_ptr<TH2Poly> thp) ->
float {
return thp->GetMinimum(); });
573 auto globalMax = *std::max_element(maxima.begin(), maxima.end());
574 auto globalMin = *std::min_element(minima.begin(), minima.end());
577 if (globalMax == globalMin)
581 histo->GetZaxis()->SetRangeUser(globalMin, globalMax);
void drawForwardMaps(const std::string ¤tHistoName, TCanvas &canvas, const char *drawOption=nullptr)
unsigned int pxbLayer(const DetId &id) const
std::vector< edm::FileInPath > m_cornersFPIX
void setBarrelScale(const std::string ¤tHistoName, std::pair< float, float > extrema)
void adjustCanvasMargins(TVirtualPad *pad, float top, float bottom, float left, float right)
void makeNicePlotStyle(TH1 *hist)
void rescaleAllForward(const std::string ¤tHistoName)
std::string to_string(const V &value)
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)
void drawSummaryMaps(const std::string ¤tHistoName, TCanvas &canvas, const char *drawOption=nullptr)
std::map< std::string, std::vector< std::shared_ptr< TH2Poly > > > pxfTh2PolyForward
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
void fillForwardBin(const std::string ¤tHistoName, unsigned int id, double value)
std::map< uint32_t, std::shared_ptr< TGraph > > binsSummary
std::vector< edm::FileInPath > m_cornersBPIX
void drawBarrelMaps(const std::string ¤tHistoName, 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 ¤tHistoName)
TrackerTopology m_trackerTopo
void rescaleAllBarrel(const std::string ¤tHistoName)
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
void bookForwardBins(const std::string ¤tHistoName)
void beautifyAllHistograms()
std::pair< bool, bool > m_isBooked
std::map< std::string, std::shared_ptr< TH2Poly > > pxfTh2PolyForwardSummary
std::vector< std::string > m_knownNames
unsigned int pxfSide(const DetId &id) const
void bookBarrelHistograms(const std::string ¤tHistoName, const char *what, const char *zaxis)
void book(const std::string ¤tHistoName, const char *what, const char *zaxis)
def remove(d, key, TELL=False)
void bookForwardHistograms(const std::string ¤tHistoName, const char *what, const char *zaxis)
void fillBarrelBin(const std::string ¤tHistoName, unsigned int id, double value)
void setForwardScale(const std::string ¤tHistoName, std::pair< float, float > extrema)
void fill(const std::string ¤tHistoName, unsigned int id, double value)