Skip to content

Commit e937178

Browse files
wiechuladavidrohr
authored andcommitted
histograms with exact pad corner coordinate
1 parent 64be864 commit e937178

File tree

3 files changed

+136
-3
lines changed

3 files changed

+136
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ class PadRegionInfo
9393
/// Return the row offset in the sector
9494
/// \return row offset in the sector
9595
unsigned char getGlobalRowOffset() const { return mGlobalRowOffset; }
96-
// const unsigned char getRowOffset() const { return mRowOffset; }
97-
// const float getXhelper() const { return mXhelper; }
96+
97+
/// Local row offset for geometry calculations
98+
unsigned char getRowOffset() const { return mRowOffset; }
99+
100+
/// Helper variable for geometry calculations
101+
float getXhelper() const { return mXhelper; }
98102

99103
/// Return the number of pads for the row in `padPos` (row in the sector)
100104
/// \param padPos pad position in the sector

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
class TH1;
2323
class TH2;
24+
class TH2Poly;
2425
class TCanvas;
2526

2627
namespace o2
@@ -44,6 +45,29 @@ class CalArray;
4445

4546
namespace painter
4647
{
48+
49+
/// pad corner coordinates
50+
struct PadCoordinates {
51+
std::array<double, 4> xVals;
52+
std::array<double, 4> yVals;
53+
54+
void rotate(float angDeg)
55+
{
56+
const auto ang = 0.017453292519943295 * angDeg;
57+
const auto cs = std::cos(ang);
58+
const auto sn = std::sin(ang);
59+
for (int i = 0; i < xVals.size(); ++i) {
60+
const auto x = xVals[i] * cs - yVals[i] * sn;
61+
const auto y = xVals[i] * sn + yVals[i] * cs;
62+
xVals[i] = x;
63+
yVals[i] = y;
64+
}
65+
}
66+
};
67+
68+
/// create a vector of pad corner coordinate for one full sector
69+
std::vector<PadCoordinates> getPadCoordinatesSector();
70+
4771
//using T=float;
4872
/// Drawing of a CalDet object
4973
/// \param CalDet object to draw
@@ -84,6 +108,19 @@ TH2* getHistogram2D(const CalDet<T>& calDet, Side side);
84108
template <class T>
85109
TH2* getHistogram2D(const CalArray<T>& calArray);
86110

111+
/// make a sector-wise histogram with correct pad corners
112+
TH2Poly* makeSectorHist(const std::string_view name = "hSector", const std::string_view title = "Sector;local #it{x} (cm);local #it{y} (cm)");
113+
114+
/// make a side-wise histogram with correct pad corners
115+
TH2Poly* makeSideHist(Side side);
116+
117+
/// fill existing TH2Poly histogram for CalDet object
118+
/// \param h2D histogram to fill
119+
/// \param CalDet object with data
120+
/// \param side side which to get the histogram for
121+
template <class T>
122+
void fillPoly2D(TH2Poly& h2D, const CalDet<T>& calDet, Side side);
123+
87124
/// Create summary canvases for a CalDet object
88125
///
89126
/// 1 Canvas with 2D and 1D distributions for each side

Detectors/TPC/base/src/Painter.cxx

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "TAxis.h"
1717
#include "TH1.h"
1818
#include "TH2.h"
19+
#include "TH2Poly.h"
1920
#include "TCanvas.h"
2021

2122
#include "TPCBase/ROC.h"
@@ -28,6 +29,41 @@
2829

2930
using namespace o2::tpc;
3031

32+
std::vector<painter::PadCoordinates> painter::getPadCoordinatesSector()
33+
{
34+
std::vector<painter::PadCoordinates> padCoords;
35+
36+
const auto& regInf = Mapper::instance().getMapPadRegionInfo();
37+
38+
for (const auto& padReg : regInf) {
39+
const auto npr = padReg.getNumberOfPadRows();
40+
const auto ro = padReg.getRowOffset();
41+
const auto xm = padReg.getXhelper();
42+
const auto ph = padReg.getPadHeight();
43+
const auto pw = padReg.getPadWidth();
44+
const auto yro = padReg.getRadiusFirstRow();
45+
const auto ks = ph / pw * std::tan(1.74532925199432948e-01);
46+
47+
for (int irow = 0; irow < npr; ++irow) {
48+
const auto npads = std::floor(ks * (irow + ro) + xm);
49+
for (int ipad = -npads; ipad < npads; ++ipad) {
50+
const auto xPadBottomRight = yro + ph * irow;
51+
const auto xPadTopRight = yro + ph * (irow + 1);
52+
const auto ri = xPadBottomRight;
53+
const auto yPadBottomRight = pw * ipad * xPadBottomRight / (ri + ph / 2);
54+
const auto yPadTopRight = pw * ipad * xPadTopRight / (ri + ph / 2);
55+
const auto yPadBottomLeft = pw * (ipad + 1) * xPadBottomRight / (ri + ph / 2);
56+
const auto yPadTopLeft = pw * (ipad + 1) * xPadTopRight / (ri + ph / 2);
57+
auto& padCoord = padCoords.emplace_back();
58+
padCoord.xVals = {xPadBottomRight, xPadTopRight, xPadTopRight, xPadBottomRight};
59+
padCoord.yVals = {yPadBottomRight, yPadTopRight, yPadTopLeft, yPadBottomLeft};
60+
}
61+
}
62+
}
63+
64+
return padCoords;
65+
}
66+
3167
template <class T>
3268
TCanvas* painter::draw(const CalDet<T>& calDet, int nbins1D, float xMin1D, float xMax1D, TCanvas* outputCanvas)
3369
{
@@ -328,7 +364,7 @@ std::vector<TCanvas*> painter::makeSummaryCanvases(const CalDet<T>& calDet, int
328364
return vecCanvases;
329365
}
330366

331-
//==============================================================================
367+
//______________________________________________________________________________
332368
std::vector<TCanvas*> painter::makeSummaryCanvases(const std::string_view fileName, const std::string_view calPadNames, int nbins1D, float xMin1D, float xMax1D, bool onlyFilled)
333369
{
334370
using namespace o2::tpc;
@@ -347,13 +383,69 @@ std::vector<TCanvas*> painter::makeSummaryCanvases(const std::string_view fileNa
347383
return vecCanvases;
348384
}
349385

386+
//______________________________________________________________________________
387+
TH2Poly* painter::makeSectorHist(const std::string_view name, const std::string_view title)
388+
{
389+
auto poly = new TH2Poly(name.data(), title.data(), 83.65, 247.7, -43.7, 43.7);
390+
391+
auto coords = painter::getPadCoordinatesSector();
392+
for (const auto& coord : coords) {
393+
poly->AddBin(coord.xVals.size(), coord.xVals.data(), coord.yVals.data());
394+
}
395+
396+
return poly;
397+
}
398+
399+
//______________________________________________________________________________
400+
TH2Poly* painter::makeSideHist(Side side)
401+
{
402+
const auto s = (side == Side::A) ? "A" : "C";
403+
auto poly = new TH2Poly(fmt::format("hSide_{}", s).data(), fmt::format("{}-Side;#it{{x}} (cm);#it{{y}} (cm)", s).data(), -270., 270., -270., 270.);
404+
405+
auto coords = painter::getPadCoordinatesSector();
406+
for (int isec = 0; isec < 18; ++isec) {
407+
const float angDeg = 10.f + isec * 20;
408+
for (auto coord : coords) {
409+
coord.rotate(angDeg);
410+
poly->AddBin(coord.xVals.size(), coord.xVals.data(), coord.yVals.data());
411+
}
412+
}
413+
414+
return poly;
415+
}
416+
417+
//______________________________________________________________________________
418+
template <class T>
419+
void painter::fillPoly2D(TH2Poly& h2D, const CalDet<T>& calDet, Side side)
420+
{
421+
static const Mapper& mapper = Mapper::instance();
422+
423+
int bin = 1;
424+
for (const auto& calROC : calDet.getData()) {
425+
ROC roc(calROC.getPadSubsetNumber());
426+
if (roc.side() != side) {
427+
continue;
428+
}
429+
430+
const int nrows = mapper.getNumberOfRowsROC(roc);
431+
for (int irow = 0; irow < nrows; ++irow) {
432+
const int padMax = mapper.getNumberOfPadsInRowROC(roc, irow) - 1;
433+
for (int ipad = 0; ipad <= padMax; ++ipad) {
434+
const auto val = calDet.getValue(roc, irow, (side == Side::A) ? ipad : padMax - ipad); // C-Side is mirrored
435+
h2D.SetBinContent(bin++, val);
436+
}
437+
}
438+
}
439+
}
440+
350441
// ===| explicit instantiations |===============================================
351442
// this is required to force the compiler to create instances with the types
352443
// we usually would like to deal with
353444
template TCanvas* painter::draw<float>(const CalDet<float>& calDet, int, float, float, TCanvas*);
354445
template std::vector<TCanvas*> painter::makeSummaryCanvases<float>(const CalDet<float>& calDet, int, float, float, bool, std::vector<TCanvas*>*);
355446
template TCanvas* painter::draw<float>(const CalArray<float>& calArray);
356447
template void painter::fillHistogram2D<float>(TH2& h2D, const CalDet<float>& calDet, Side side);
448+
template void painter::fillPoly2D<float>(TH2Poly& h2D, const CalDet<float>& calDet, Side side);
357449
template void painter::fillHistogram2D<float>(TH2& h2D, const CalArray<float>& calArray);
358450
template TH2* painter::getHistogram2D<float>(const CalDet<float>& calDet, Side side);
359451
template TH2* painter::getHistogram2D<float>(const CalArray<float>& calArray);

0 commit comments

Comments
 (0)