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