Skip to content

Commit 98c9183

Browse files
committed
Add voxel map binning
1 parent 90375b5 commit 98c9183

File tree

2 files changed

+85
-9
lines changed

2 files changed

+85
-9
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ struct painter {
5353
enum class Type : int {
5454
Pad, ///< drawing pads
5555
Stack, ///< drawing stacks
56-
FEC ///< drawing of FECs
56+
FEC, ///< drawing of FECs
57+
SCD, ///< drawing of FECs
5758
};
5859

5960
static std::array<int, 6> colors;
@@ -87,8 +88,10 @@ struct painter {
8788
/// create a vector of FEC corner coordinates for one full sector
8889
static std::vector<PadCoordinates> getFECCoordinatesSector();
8990

91+
static std::vector<painter::PadCoordinates> getSCDY2XCoordinatesSector(std::string binningStr);
92+
9093
/// \return returns coordinates for given type
91-
static std::vector<o2::tpc::painter::PadCoordinates> getCoordinates(const Type type);
94+
static std::vector<o2::tpc::painter::PadCoordinates> getCoordinates(const Type type, std::string binningStr = "");
9295

9396
/// binning vector with radial pad-row positions (in cm)
9497
/// \param roc roc number (0-35 IROC, 36-71 OROC, >=72 full sector)
@@ -143,11 +146,11 @@ struct painter {
143146
/// \param yMin minimum y coordinate of the histogram
144147
/// \param yMax maximum y coordinate of the histogram
145148
/// \param type granularity of the histogram (per pad or per stack)
146-
static TH2Poly* makeSectorHist(const std::string_view name = "hSector", const std::string_view title = "Sector;local #it{x} (cm);local #it{y} (cm)", const float xMin = 83.65f, const float xMax = 247.7f, const float yMin = -43.7f, const float yMax = 43.7f, const Type type = Type::Pad);
149+
static TH2Poly* makeSectorHist(const std::string_view name = "hSector", const std::string_view title = "Sector;local #it{x} (cm);local #it{y} (cm)", const float xMin = 83.65f, const float xMax = 247.7f, const float yMin = -43.7f, const float yMax = 43.7f, const Type type = Type::Pad, std::string binningStr = "");
147150

148151
/// make a side-wise histogram with correct pad corners
149152
/// \param type granularity of the histogram (per pad or per stack)
150-
static TH2Poly* makeSideHist(Side side, const Type type = Type::Pad);
153+
static TH2Poly* makeSideHist(Side side, const Type type = Type::Pad, std::string binningStr = "");
151154

152155
/// fill existing TH2Poly histogram for CalDet object
153156
/// \param h2D histogram to fill

Detectors/TPC/base/src/Painter.cxx

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "TPaletteAxis.h"
3333
#include "TObjArray.h"
3434

35+
#include "Algorithm/RangeTokenizer.h"
3536
#include "CommonUtils/StringUtils.h"
3637
#include "DataFormatsTPC/Defs.h"
3738
#include "TPCBase/ROC.h"
@@ -223,14 +224,86 @@ std::vector<painter::PadCoordinates> painter::getFECCoordinatesSector()
223224
return padCoords;
224225
}
225226

226-
std::vector<o2::tpc::painter::PadCoordinates> painter::getCoordinates(const Type type)
227+
std::vector<painter::PadCoordinates> painter::getSCDY2XCoordinatesSector(std::string binningStr)
228+
{
229+
const float deadZone = 1.5;
230+
const float secPhi = 20.0 * TMath::DegToRad();
231+
std::vector<painter::PadCoordinates> padCoords;
232+
const Mapper& mapper = Mapper::instance();
233+
const auto nPadRows = Mapper::PADROWS;
234+
std::vector<float> maxY2X(nPadRows);
235+
auto binCenters = o2::RangeTokenizer::tokenize<float>(binningStr);
236+
size_t nY2XBins = 20;
237+
std::vector<float> halfBinWidth;
238+
239+
auto setUniformBinning = [&binCenters, &halfBinWidth](int nY2XBins) {
240+
binCenters.resize(nY2XBins);
241+
halfBinWidth.resize(nY2XBins);
242+
for (int i = 0; i < nY2XBins; ++i) {
243+
const auto binWidth = 2.f / nY2XBins;
244+
halfBinWidth[i] = binWidth / 2.f;
245+
binCenters[i] = -1.f + (i + 0.5f) * binWidth;
246+
}
247+
};
248+
249+
if (binCenters.size() == 0) {
250+
LOGP(info, "Empty binning provided, will use default uniform y/x binning with {} bins", nY2XBins);
251+
setUniformBinning(nY2XBins);
252+
} else if (binCenters.size() == 1) {
253+
nY2XBins = static_cast<int>(binCenters.at(0));
254+
LOGP(info, "Setting uniform binning for y/x with {} bins", nY2XBins);
255+
setUniformBinning(nY2XBins);
256+
} else {
257+
nY2XBins = binCenters.size() - 1;
258+
if (std::abs(binCenters[0] + 1.f) > 1e-6 || std::abs(binCenters[nY2XBins] - 1.f) > 1e-6) {
259+
LOG(error) << "Provided binning for y/x not in range -1 to 1: " << binCenters[0] << " - " << binCenters[nY2XBins] << ". Using default uniform binning with " << nY2XBins << " bins";
260+
setUniformBinning(nY2XBins);
261+
} else {
262+
LOGP(info, "Setting custom binning for y/x with {} bins", nY2XBins);
263+
halfBinWidth.reserve(nY2XBins);
264+
halfBinWidth.clear();
265+
for (int i = 0; i < nY2XBins; ++i) {
266+
halfBinWidth.push_back(.5f * (binCenters[i + 1] - binCenters[i]));
267+
binCenters[i] = .5f * (binCenters[i] + binCenters[i + 1]);
268+
}
269+
binCenters.resize(nY2XBins);
270+
}
271+
}
272+
273+
for (int irow = 0; irow < nPadRows; ++irow) {
274+
const auto x = mapper.getPadCentre(PadPos(irow, 0)).X();
275+
maxY2X[irow] = std::tan(.5f * secPhi) - deadZone / x;
276+
const auto region = Mapper::REGION[irow];
277+
const auto ph = mapper.getPadRegionInfo(region).getPadHeight();
278+
const auto xPadBottom = x - ph / 2;
279+
const auto xPadTop = x + ph / 2;
280+
for (int iy2x = 0; iy2x < nY2XBins; ++iy2x) {
281+
auto& padCoord = padCoords.emplace_back();
282+
float yPadRight = 0;
283+
if (iy2x == 0) {
284+
yPadRight = maxY2X[irow] * (binCenters[iy2x] - halfBinWidth[iy2x]);
285+
} else {
286+
yPadRight = maxY2X[irow] * (binCenters[iy2x - 1] + halfBinWidth[iy2x - 1]);
287+
}
288+
const auto yPadLeft = maxY2X[irow] * (binCenters[iy2x] + halfBinWidth[iy2x]);
289+
padCoord.xVals = {xPadBottom, xPadTop, xPadTop, xPadBottom};
290+
padCoord.yVals = {yPadRight * xPadBottom, yPadRight * xPadTop, yPadLeft * xPadTop, yPadLeft * xPadBottom};
291+
}
292+
}
293+
294+
return padCoords;
295+
}
296+
297+
std::vector<o2::tpc::painter::PadCoordinates> painter::getCoordinates(const Type type, std::string binningStr)
227298
{
228299
if (type == Type::Pad) {
229300
return painter::getPadCoordinatesSector();
230301
} else if (type == Type::Stack) {
231302
return painter::getStackCoordinatesSector();
232303
} else if (type == Type::FEC) {
233304
return painter::getFECCoordinatesSector();
305+
} else if (type == Type::SCD) {
306+
return painter::getSCDY2XCoordinatesSector(binningStr);
234307
} else {
235308
LOGP(warning, "Wrong Type provided!");
236309
return std::vector<o2::tpc::painter::PadCoordinates>();
@@ -805,11 +878,11 @@ std::vector<TCanvas*> painter::makeSummaryCanvases(const std::string_view fileNa
805878
}
806879

807880
//______________________________________________________________________________
808-
TH2Poly* painter::makeSectorHist(const std::string_view name, const std::string_view title, const float xMin, const float xMax, const float yMin, const float yMax, const Type type)
881+
TH2Poly* painter::makeSectorHist(const std::string_view name, const std::string_view title, const float xMin, const float xMax, const float yMin, const float yMax, const Type type, std::string binningStr)
809882
{
810883
auto poly = new TH2Poly(name.data(), title.data(), xMin, xMax, yMin, yMax);
811884

812-
auto coords = painter::getCoordinates(type);
885+
auto coords = painter::getCoordinates(type, binningStr);
813886
for (const auto& coord : coords) {
814887
poly->AddBin(coord.xVals.size(), coord.xVals.data(), coord.yVals.data());
815888
}
@@ -818,12 +891,12 @@ TH2Poly* painter::makeSectorHist(const std::string_view name, const std::string_
818891
}
819892

820893
//______________________________________________________________________________
821-
TH2Poly* painter::makeSideHist(Side side, const Type type)
894+
TH2Poly* painter::makeSideHist(Side side, const Type type, std::string binningStr)
822895
{
823896
const auto s = (side == Side::A) ? "A" : "C";
824897
auto poly = new TH2Poly(fmt::format("hSide_{}", s).data(), fmt::format("{}-Side;#it{{x}} (cm);#it{{y}} (cm)", s).data(), -270., 270., -270., 270.);
825898

826-
auto coords = painter::getCoordinates(type);
899+
auto coords = painter::getCoordinates(type, binningStr);
827900
for (int isec = 0; isec < 18; ++isec) {
828901
const float angDeg = 10.f + isec * 20;
829902
for (auto coord : coords) {

0 commit comments

Comments
 (0)