8 #include <fmt/printf.h> 11 #include <boost/tokenizer.hpp> 12 #include <boost/range/adaptor/indexed.hpp> 26 <<
". It's not possible to reset it.";
33 std::shared_ptr<TH2Poly> th2p;
40 for (
unsigned i = 0;
i < 4; ++
i) {
41 histName =
"barrel_layer_";
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);
48 th2p->GetXaxis()->SetTitle(
"z [cm]");
49 th2p->GetYaxis()->SetTitle(
"ladder");
50 th2p->GetZaxis()->SetTitle(
zaxis);
51 th2p->GetZaxis()->CenterTitle();
52 th2p->SetStats(
false);
57 th2p = std::make_shared<TH2Poly>(
"barrel_summary", Form(
"Barrel Pixel Map of %s", what), -5.0, 5.0, 0.0, 15.0);
60 th2p->GetXaxis()->SetTitle(
"");
61 th2p->GetYaxis()->SetTitle(
"");
62 th2p->GetZaxis()->SetTitle(
zaxis);
63 th2p->GetZaxis()->CenterTitle();
64 th2p->SetStats(
false);
78 std::shared_ptr<TH2Poly> th2p;
86 for (
unsigned disk = 1; disk <= 3; ++disk) {
87 histName =
"forward_disk_";
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),
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);
106 th2p = std::make_shared<TH2Poly>(
"forward_summary", Form(
"Forward Pixel Map of %s", what), -40.0, 40.0, -20.0, 90.0);
109 th2p->GetXaxis()->SetTitle(
"");
110 th2p->GetYaxis()->SetTitle(
"");
111 th2p->GetZaxis()->SetTitle(
zaxis);
112 th2p->GetZaxis()->CenterTitle();
113 th2p->SetStats(
false);
127 for (
const auto&
entry : theIndexedCorners) {
128 auto id =
entry.first;
129 auto detid =
DetId(
id);
136 auto theVectX =
entry.second.first;
137 auto theVectY =
entry.second.second;
139 float vertX[] = {theVectX[0], theVectX[1], theVectX[2], theVectX[3], theVectX[4]};
142 bins[
id] = std::make_shared<TGraph>(5, vertX, vertY);
143 bins[
id]->SetName(TString::Format(
"%u",
id));
146 for (
unsigned k = 0;
k < 5; ++
k) {
148 vertY[
k] += ((
layer > 2) ? 30.0
f : 0.0
f);
157 throw cms::Exception(
"LogicError") << currentHistoName <<
" is not found in the Barrel map! Aborting.";
163 throw cms::Exception(
"LocalError") << currentHistoName <<
" is not found in the Barrel Summary map! Aborting.";
172 for (
const auto&
entry : theIndexedCorners) {
173 auto id =
entry.first;
174 auto detid =
DetId(
id);
181 unsigned mapIdx = disk + (
side - 1) * 3 - 1;
183 auto theVectX =
entry.second.first;
184 auto theVectY =
entry.second.second;
186 float vertX[] = {theVectX[0], theVectX[1], theVectX[2], theVectX[3]};
187 float vertY[] = {theVectY[0], theVectY[1], theVectY[2], theVectY[3]};
189 bins[
id] = std::make_shared<TGraph>(4, vertX, vertY);
190 bins[
id]->SetName(TString::Format(
"%u",
id));
193 for (
unsigned k = 0;
k < 4; ++
k) {
195 vertY[
k] += (disk - 1) * 35.0
f;
204 throw cms::Exception(
"LogicError") << currentHistoName <<
" is not found in the Forward map! Aborting.";
210 throw cms::Exception(
"LogicError") << currentHistoName <<
" is not found in the Forward Summary map! Aborting.";
224 auto detid =
DetId(
id);
228 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to fill a histogram not booked";
232 LogDebug(
"Phase1PixelMaps") << __func__ <<
" filling barrel with value: " <<
value << std::endl;
239 unsigned mapIdx = disk + (
side - 1) * 3 - 1;
241 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to fill a histogram not booked";
245 LogDebug(
"Phase1PixelMaps") << __func__ <<
" filling endcaps with value: " <<
value << std::endl;
254 auto detid =
DetId(
id);
256 edm::LogError(
"Phase1PixelMaps") <<
"fillBarrelBin() The following detid " <<
id <<
" is not Pixel Barrel!" 261 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to fill a histogram not booked";
271 auto detid =
DetId(
id);
273 edm::LogError(
"Phase1PixelMaps") <<
"fillForwardBin() The following detid " <<
id <<
" is not Pixel Forward!" 278 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to fill a histogram not booked";
283 unsigned mapIdx = disk + (
side - 1) * 3 - 1;
291 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to beautify a histogram not booked";
298 for (
const auto&
plot : vec.second) {
300 plot->GetXaxis()->SetTitleOffset(0.9);
301 plot->GetYaxis()->SetTitleOffset(0.9);
302 plot->GetZaxis()->SetTitleOffset(1.2);
303 plot->GetZaxis()->SetTitleSize(0.05);
311 for (
const auto&
plot : vec.second) {
313 plot->GetXaxis()->SetTitleOffset(0.9);
314 plot->GetYaxis()->SetTitleOffset(0.9);
315 plot->GetZaxis()->SetTitleOffset(1.2);
316 plot->GetZaxis()->SetTitleSize(0.05);
325 histo->GetZaxis()->SetRangeUser(extrema.first, extrema.second);
332 histo->GetZaxis()->SetRangeUser(extrema.first, extrema.second);
341 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to draw a histogram not booked";
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);
350 for (
int i = 1;
i <= 4;
i++) {
352 if (strcmp(
m_option,
"text") == 0) {
353 pad1->cd(
i)->SetRightMargin(0.02);
375 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to draw a histogram not booked";
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);
385 for (
int i = 1;
i <= 6;
i++) {
387 if (strcmp(
m_option,
"text") == 0) {
388 pad1->cd(
i)->SetRightMargin(0.02);
410 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to draw a histogram not booked";
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);
422 auto isText = (
temp.find(
"text") != std::string::npos);
445 const unsigned int reads) {
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;
455 while (std::getline(cornerFile,
line)) {
457 std::istringstream iss(
line);
460 std::vector<std::string> corners(reads,
"");
461 std::vector<float> xP, yP;
464 for (
unsigned int i = 0;
i < reads; ++
i) {
465 iss >> corners.at(
i);
468 LOGDEBUG(
"Phase1PixelMaps") <<
id <<
" : ";
469 for (
unsigned int i = 0;
i < reads;
i++) {
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()));
482 edm::LogError(
"LogicError") <<
"There should not be any token with index " <<
t.index() << std::endl;
486 LOGDEBUG(
"Phase1PixelMaps") << std::endl;
488 xP.push_back(xP.front());
489 yP.push_back(yP.front());
491 for (
unsigned int i = 0;
i < xP.size();
i++) {
492 LOGDEBUG(
"Phase1PixelMaps") <<
"x[" <<
i <<
"]=" << xP[
i] <<
" y[" <<
i <<
"]" << yP[
i] << std::endl;
495 theOutMap[
id] = std::make_pair(xP, yP);
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);
521 hist->GetZaxis()->SetLabelFont(42);
522 hist->GetZaxis()->SetLabelFont(42);
523 hist->GetZaxis()->SetLabelSize(.05);
524 hist->GetZaxis()->SetLabelSize(.05);
531 pad->SetTopMargin(top);
533 pad->SetBottomMargin(bottom);
535 pad->SetLeftMargin(left);
537 pad->SetRightMargin(right);
543 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to manipulate a histogram not booked";
547 std::vector<float> maxima;
550 std::back_inserter(maxima),
551 [](std::shared_ptr<TH2Poly> thp) ->
float {
return thp->GetMaximum(); });
552 std::vector<float> minima;
555 std::back_inserter(minima),
556 [](std::shared_ptr<TH2Poly> thp) ->
float {
return thp->GetMinimum(); });
558 auto globalMax = *std::max_element(maxima.begin(), maxima.end());
559 auto globalMin = *std::min_element(minima.begin(), minima.end());
562 if (globalMax == globalMin)
566 histo->GetZaxis()->SetRangeUser(globalMin, globalMax);
573 edm::LogError(
"Phase1PixelMaps") << __func__ <<
": trying to manipulate a histogram not booked";
577 std::vector<float> maxima;
580 std::back_inserter(maxima),
581 [](std::shared_ptr<TH2Poly> thp) ->
float {
return thp->GetMaximum(); });
582 std::vector<float> minima;
585 std::back_inserter(minima),
586 [](std::shared_ptr<TH2Poly> thp) ->
float {
return thp->GetMinimum(); });
588 auto globalMax = *std::max_element(maxima.begin(), maxima.end());
589 auto globalMin = *std::min_element(minima.begin(), minima.end());
592 if (globalMax == globalMin)
596 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)
ALPAKA_FN_ACC int side(int ieta, int iphi)
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)
static std::string to_string(const XMLCh *ch)
std::map< std::string, std::vector< std::shared_ptr< TH2Poly > > > pxfTh2PolyForward
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)