Skip to content

Commit f6927c9

Browse files
committed
Add summary canvases from pad tree dump, cosmetic fixes
1 parent f6e2c2a commit f6927c9

File tree

2 files changed

+169
-4
lines changed

2 files changed

+169
-4
lines changed

Detectors/TPC/base/include/TPCBase/Painter.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ struct painter {
184184
/// \return TCanvas containing CalDet content
185185
static std::vector<TCanvas*> makeSummaryCanvases(const std::string_view fileName, const std::string_view calPadNames, int nbins1D = 300, float xMin1D = 0, float xMax1D = 0, bool onlyFilled = true);
186186

187+
/// Create summary canvases from pad calibration tree dumped via CalibTreeDump
188+
///
189+
/// 1 Canvas with 2D and 1D distributions for each side
190+
/// 1 Canvas with 2D distributions for all ROCs
191+
/// 1 Canvas with 1D distributions for all ROCs
192+
/// \param tree input calibTree
193+
/// \param draw draw string to use for the variable (1D)
194+
/// \param cut cut string to use (default 1 = no cut)
195+
/// \param nbins1D number of bins used for the 1D projections, if negative, exclude per ROC histograms
196+
/// \param xMin1D minimum value for 1D distribution (xMin = 0 and xMax = 0 for auto scaling)
197+
/// \param xMax1D maximum value for 1D distribution (xMin = 0 and xMax = 0 for auto scaling)
198+
/// \return TCanvas containing CalDet content
199+
static std::vector<TCanvas*> makeSummaryCanvases(TTree& tree, const std::string_view draw, std::string_view cut = "1", int nbins1D = 300, float xMin1D = 0, float xMax1D = 0);
200+
187201
/// draw sector boundaris, side name and sector numbers
188202
static void drawSectorsXY(Side side, int sectorLineColor = 920, int sectorTextColor = 1);
189203

Detectors/TPC/base/src/Painter.cxx

Lines changed: 155 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <string>
1313
#include <algorithm>
14+
#include <fmt/core.h>
1415
#include <fmt/format.h>
1516
#include <cmath>
1617

@@ -22,6 +23,7 @@
2223
#include "TH2.h"
2324
#include "TH3.h"
2425
#include "TH2Poly.h"
26+
#include "TProfile2D.h"
2527
#include "TCanvas.h"
2628
#include "TLine.h"
2729
#include "TLatex.h"
@@ -303,16 +305,16 @@ TCanvas* painter::draw(const CalDet<T>& calDet, int nbins1D, float xMin1D, float
303305
const int bufferSize = TH1::GetDefaultBufferSize();
304306
TH1::SetDefaultBufferSize(Sector::MAXSECTOR * mapper.getPadsInSector());
305307

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(),
307309
nbins1D, xMin1D, xMax1D); // TODO: modify ranges
308310

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(),
310312
nbins1D, xMin1D, xMax1D); // TODO: modify ranges
311313

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(),
313315
330, -270, 270, 330, -270, 270);
314316

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(),
316318
330, -270, 270, 330, -270, 270);
317319

318320
for (ROC roc; !roc.looped(); ++roc) {
@@ -363,13 +365,15 @@ TCanvas* painter::draw(const CalDet<T>& calDet, int nbins1D, float xMin1D, float
363365
hAside2D->SetStats(0);
364366
hAside2D->SetTitleOffset(1.05, "XY");
365367
hAside2D->SetTitleSize(0.05, "XY");
368+
adjustPalette(hAside2D, 0.92);
366369
drawSectorsXY(Side::A);
367370

368371
c->cd(2);
369372
hCside2D->Draw("colz");
370373
hCside2D->SetStats(0);
371374
hCside2D->SetTitleOffset(1.05, "XY");
372375
hCside2D->SetTitleSize(0.05, "XY");
376+
adjustPalette(hCside2D, 0.92);
373377
drawSectorsXY(Side::C);
374378

375379
c->cd(3);
@@ -613,6 +617,153 @@ std::vector<TCanvas*> painter::makeSummaryCanvases(const CalDet<T>& calDet, int
613617
return vecCanvases;
614618
}
615619

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+
616767
//______________________________________________________________________________
617768
std::vector<TCanvas*> painter::makeSummaryCanvases(const std::string_view fileName, const std::string_view calPadNames, int nbins1D, float xMin1D, float xMax1D, bool onlyFilled)
618769
{

0 commit comments

Comments
 (0)