|
11 | 11 |
|
12 | 12 | #include <string> |
13 | 13 | #include <algorithm> |
| 14 | +#include <fmt/core.h> |
14 | 15 | #include <fmt/format.h> |
15 | 16 | #include <cmath> |
16 | 17 |
|
|
22 | 23 | #include "TH2.h" |
23 | 24 | #include "TH3.h" |
24 | 25 | #include "TH2Poly.h" |
| 26 | +#include "TProfile2D.h" |
25 | 27 | #include "TCanvas.h" |
26 | 28 | #include "TLine.h" |
27 | 29 | #include "TLatex.h" |
@@ -303,16 +305,16 @@ TCanvas* painter::draw(const CalDet<T>& calDet, int nbins1D, float xMin1D, float |
303 | 305 | const int bufferSize = TH1::GetDefaultBufferSize(); |
304 | 306 | TH1::SetDefaultBufferSize(Sector::MAXSECTOR * mapper.getPadsInSector()); |
305 | 307 |
|
306 | | - auto hAside1D = new TH1F(fmt::format("h_Aside_1D_{}", name).data(), fmt::format("{} (A-Side)", title).data(), |
| 308 | + auto hAside1D = new TH1F(fmt::format("h_Aside_1D_{}", name).data(), fmt::format("{0} (A-Side);{0}", title).data(), |
307 | 309 | nbins1D, xMin1D, xMax1D); // TODO: modify ranges |
308 | 310 |
|
309 | | - auto hCside1D = new TH1F(fmt::format("h_Cside_1D_{}", name).data(), fmt::format("{} (C-Side)", title).data(), |
| 311 | + auto hCside1D = new TH1F(fmt::format("h_Cside_1D_{}", name).data(), fmt::format("{0} (C-Side);{0}", title).data(), |
310 | 312 | nbins1D, xMin1D, xMax1D); // TODO: modify ranges |
311 | 313 |
|
312 | | - auto hAside2D = new TH2F(fmt::format("h_Aside_2D_{}", name).data(), fmt::format("{} (A-Side);#it{{x}} (cm);#it{{y}} (cm)", title).data(), |
| 314 | + auto hAside2D = new TH2F(fmt::format("h_Aside_2D_{}", name).data(), fmt::format("{0} (A-Side);#it{{x}} (cm);#it{{y}} (cm);{0}", title).data(), |
313 | 315 | 330, -270, 270, 330, -270, 270); |
314 | 316 |
|
315 | | - auto hCside2D = new TH2F(fmt::format("h_Cside_2D_{}", name).data(), fmt::format("{} (C-Side);#it{{x}} (cm);#it{{y}} (cm)", title).data(), |
| 317 | + auto hCside2D = new TH2F(fmt::format("h_Cside_2D_{}", name).data(), fmt::format("{0} (C-Side);#it{{x}} (cm);#it{{y}} (cm);{0}", title).data(), |
316 | 318 | 330, -270, 270, 330, -270, 270); |
317 | 319 |
|
318 | 320 | for (ROC roc; !roc.looped(); ++roc) { |
@@ -363,13 +365,15 @@ TCanvas* painter::draw(const CalDet<T>& calDet, int nbins1D, float xMin1D, float |
363 | 365 | hAside2D->SetStats(0); |
364 | 366 | hAside2D->SetTitleOffset(1.05, "XY"); |
365 | 367 | hAside2D->SetTitleSize(0.05, "XY"); |
| 368 | + adjustPalette(hAside2D, 0.92); |
366 | 369 | drawSectorsXY(Side::A); |
367 | 370 |
|
368 | 371 | c->cd(2); |
369 | 372 | hCside2D->Draw("colz"); |
370 | 373 | hCside2D->SetStats(0); |
371 | 374 | hCside2D->SetTitleOffset(1.05, "XY"); |
372 | 375 | hCside2D->SetTitleSize(0.05, "XY"); |
| 376 | + adjustPalette(hCside2D, 0.92); |
373 | 377 | drawSectorsXY(Side::C); |
374 | 378 |
|
375 | 379 | c->cd(3); |
@@ -613,6 +617,153 @@ std::vector<TCanvas*> painter::makeSummaryCanvases(const CalDet<T>& calDet, int |
613 | 617 | return vecCanvases; |
614 | 618 | } |
615 | 619 |
|
| 620 | +std::vector<TCanvas*> o2::tpc::painter::makeSummaryCanvases(TTree& tree, const std::string_view draw, std::string_view cut, int nbins1D, float xMin1D, float xMax1D) |
| 621 | +{ |
| 622 | + const Mapper& mapper = Mapper::instance(); |
| 623 | + |
| 624 | + std::vector<TCanvas*> vecCanvases; |
| 625 | + |
| 626 | + // ===| name and title |====================================================== |
| 627 | + std::string title = draw.data(); |
| 628 | + std::string name = title; |
| 629 | + std::replace(name.begin(), name.end(), ' ', '_'); |
| 630 | + std::replace(name.begin(), name.end(), '/', '_'); |
| 631 | + const std::string_view calName = name; |
| 632 | + |
| 633 | + // ===| Per ROC histograms |=== |
| 634 | + if (nbins1D > 0) { |
| 635 | + const size_t nROCs = 72; |
| 636 | + auto cROCs1D = new TCanvas(fmt::format("c_ROCs_{}_1D", calName).data(), fmt::format("{} values for each ROC", calName).data(), 1400, 1000); |
| 637 | + auto cROCs2D = new TCanvas(fmt::format("c_ROCs_{}_2D", calName).data(), fmt::format("{} values for each ROC", calName).data(), 1400, 1000); |
| 638 | + |
| 639 | + cROCs1D->DivideSquare(nROCs); |
| 640 | + cROCs2D->DivideSquare(nROCs); |
| 641 | + |
| 642 | + vecCanvases.emplace_back(cROCs1D); |
| 643 | + vecCanvases.emplace_back(cROCs2D); |
| 644 | + |
| 645 | + // ===| produce plots for each ROC |=== |
| 646 | + size_t pad = 1; |
| 647 | + for (size_t iroc = 0; iroc < nROCs; ++iroc) { |
| 648 | + |
| 649 | + // ===| 1D histogram |=== |
| 650 | + auto h1D = new TH1F(fmt::format("h1_{}_{:02d}", calName, iroc).data(), fmt::format("{} distribution ROC {:02d} ({});{}", calName, iroc, getROCTitle(iroc), draw).data(), nbins1D, xMin1D, xMax1D); |
| 651 | + tree.Draw(fmt::format("{} >> {}", draw, h1D->GetName()).data(), fmt::format("(roc == {}) && ({})", iroc, cut).data(), "goff"); |
| 652 | + |
| 653 | + // ===| 2D histogram |=== |
| 654 | + const int nrows = mapper.getNumberOfPadRows(PadSubset::ROC, iroc); |
| 655 | + const int npads = mapper.getNumberOfPadsInRow(PadSubset::ROC, iroc, nrows - 1) + 6; |
| 656 | + |
| 657 | + // ===| create histogram |==================================================== |
| 658 | + |
| 659 | + const std::string rocTitle = title + fmt::format(" ({})", getROCTitle(iroc)); |
| 660 | + |
| 661 | + auto h2D = new TProfile2D(fmt::format("h_{}_ROC{}", name, iroc).data(), |
| 662 | + fmt::format("{};pad row;pad;{}", rocTitle, draw).data(), |
| 663 | + nrows, 0., nrows, |
| 664 | + npads, -npads / 2., npads / 2.); |
| 665 | + tree.Draw(fmt::format("{} : cpad : row >> {}", draw, h2D->GetName()).data(), fmt::format("(roc == {}) && ({})", iroc, cut).data(), "profcolzgoff"); |
| 666 | + |
| 667 | + h2D->SetStats(0); |
| 668 | + if (xMax1D > xMin1D) { |
| 669 | + h2D->SetMinimum(xMin1D); |
| 670 | + h2D->SetMaximum(xMax1D); |
| 671 | + } |
| 672 | + h2D->SetUniqueID(iroc); |
| 673 | + |
| 674 | + cROCs1D->cd(pad); |
| 675 | + h1D->Draw(); |
| 676 | + |
| 677 | + cROCs2D->cd(pad); |
| 678 | + h2D->Draw("colz"); |
| 679 | + |
| 680 | + ++pad; |
| 681 | + |
| 682 | + // associate histograms to canvas |
| 683 | + h1D->SetBit(TObject::kCanDelete); |
| 684 | + h2D->SetBit(TObject::kCanDelete); |
| 685 | + } |
| 686 | + } |
| 687 | + |
| 688 | + // ===| Side histograms |===================================================== |
| 689 | + |
| 690 | + // ---| define histograms |--------------------------------------------------- |
| 691 | + // TODO: auto scaling of ranges based on mean and variance? |
| 692 | + // for the moment use roots auto scaling |
| 693 | + |
| 694 | + // set buffer size such that autoscaling uses the full range. This is about 2MB per histogram! |
| 695 | + const int bufferSize = TH1::GetDefaultBufferSize(); |
| 696 | + TH1::SetDefaultBufferSize(Sector::MAXSECTOR * mapper.getPadsInSector()); |
| 697 | + |
| 698 | + auto hAside1D = new TH1F(fmt::format("h_Aside_1D_{}", name).data(), fmt::format("{0} (A-Side);{0}", title).data(), |
| 699 | + std::abs(nbins1D), xMin1D, xMax1D); // TODO: modify ranges |
| 700 | + |
| 701 | + auto hCside1D = new TH1F(fmt::format("h_Cside_1D_{}", name).data(), fmt::format("{0} (C-Side);{0}", title).data(), |
| 702 | + std::abs(nbins1D), xMin1D, xMax1D); // TODO: modify ranges |
| 703 | + |
| 704 | + auto hAside2D = new TProfile2D(fmt::format("h_Aside_2D_{}", name).data(), fmt::format("{} (A-Side);#it{{x}} (cm);#it{{y}} (cm);{}", title, draw).data(), |
| 705 | + 330, -270, 270, 330, -270, 270); |
| 706 | + |
| 707 | + auto hCside2D = new TProfile2D(fmt::format("h_Cside_2D_{}", name).data(), fmt::format("{} (C-Side);#it{{x}} (cm);#it{{y}} (cm);{}", title, draw).data(), |
| 708 | + 330, -270, 270, 330, -270, 270); |
| 709 | + |
| 710 | + tree.Draw(fmt::format("{} >> {}", draw, hAside1D->GetName()).data(), fmt::format("(A_Side) && ({})", cut).data(), "goff"); |
| 711 | + tree.Draw(fmt::format("{} >> {}", draw, hCside1D->GetName()).data(), fmt::format("(C_Side) && ({})", cut).data(), "goff"); |
| 712 | + tree.Draw(fmt::format("{} : gy : gx >> {}", draw, hAside2D->GetName()).data(), fmt::format("(A_Side) && ({})", cut).data(), "profcolzgoff"); |
| 713 | + tree.Draw(fmt::format("{} : gy : gx >> {}", draw, hCside2D->GetName()).data(), fmt::format("(C_Side) && ({})", cut).data(), "profcolzgoff"); |
| 714 | + |
| 715 | + if (xMax1D > xMin1D) { |
| 716 | + hAside2D->SetMinimum(xMin1D); |
| 717 | + hAside2D->SetMaximum(xMax1D); |
| 718 | + hCside2D->SetMinimum(xMin1D); |
| 719 | + hCside2D->SetMaximum(xMax1D); |
| 720 | + } |
| 721 | + |
| 722 | + // ===| Draw histograms |===================================================== |
| 723 | + gStyle->SetOptStat("mr"); |
| 724 | + auto cSides = new TCanvas(fmt::format("c_{}", name).data(), title.data(), 1000, 1000); |
| 725 | + vecCanvases.emplace_back(cSides); |
| 726 | + |
| 727 | + gStyle->SetStatX(1. - gPad->GetRightMargin()); |
| 728 | + gStyle->SetStatY(1. - gPad->GetTopMargin()); |
| 729 | + |
| 730 | + cSides->Clear(); |
| 731 | + cSides->Divide(2, 2); |
| 732 | + |
| 733 | + cSides->cd(1); |
| 734 | + hAside2D->Draw("colz"); |
| 735 | + hAside2D->SetStats(0); |
| 736 | + hAside2D->SetTitleOffset(1.05, "XY"); |
| 737 | + hAside2D->SetTitleSize(0.05, "XY"); |
| 738 | + adjustPalette(hAside2D, 0.92); |
| 739 | + drawSectorsXY(Side::A); |
| 740 | + |
| 741 | + cSides->cd(2); |
| 742 | + hCside2D->Draw("colz"); |
| 743 | + hCside2D->SetStats(0); |
| 744 | + hCside2D->SetTitleOffset(1.05, "XY"); |
| 745 | + hCside2D->SetTitleSize(0.05, "XY"); |
| 746 | + adjustPalette(hCside2D, 0.92); |
| 747 | + drawSectorsXY(Side::C); |
| 748 | + |
| 749 | + cSides->cd(3); |
| 750 | + hAside1D->Draw(); |
| 751 | + |
| 752 | + cSides->cd(4); |
| 753 | + hCside1D->Draw(); |
| 754 | + |
| 755 | + // reset the buffer size |
| 756 | + TH1::SetDefaultBufferSize(bufferSize); |
| 757 | + |
| 758 | + // associate histograms to canvas |
| 759 | + hAside1D->SetBit(TObject::kCanDelete); |
| 760 | + hCside1D->SetBit(TObject::kCanDelete); |
| 761 | + hAside2D->SetBit(TObject::kCanDelete); |
| 762 | + hCside2D->SetBit(TObject::kCanDelete); |
| 763 | + |
| 764 | + return vecCanvases; |
| 765 | +} |
| 766 | + |
616 | 767 | //______________________________________________________________________________ |
617 | 768 | std::vector<TCanvas*> painter::makeSummaryCanvases(const std::string_view fileName, const std::string_view calPadNames, int nbins1D, float xMin1D, float xMax1D, bool onlyFilled) |
618 | 769 | { |
|
0 commit comments