3131#include " TPaveText.h"
3232#include " TPaletteAxis.h"
3333#include " TObjArray.h"
34+ #include " TMath.h"
3435
36+ #include " Algorithm/RangeTokenizer.h"
3537#include " CommonUtils/StringUtils.h"
3638#include " DataFormatsTPC/Defs.h"
3739#include " TPCBase/ROC.h"
@@ -223,14 +225,86 @@ std::vector<painter::PadCoordinates> painter::getFECCoordinatesSector()
223225 return padCoords;
224226}
225227
226- std::vector<o2::tpc::painter::PadCoordinates> painter::getCoordinates (const Type type)
228+ std::vector<painter::PadCoordinates> painter::getSCDY2XCoordinatesSector (std::string binningStr)
229+ {
230+ const float deadZone = 1.5 ;
231+ const float secPhi = 20.0 * TMath::DegToRad ();
232+ std::vector<painter::PadCoordinates> padCoords;
233+ const Mapper& mapper = Mapper::instance ();
234+ const auto nPadRows = Mapper::PADROWS;
235+ std::vector<float > maxY2X (nPadRows);
236+ auto binCenters = o2::RangeTokenizer::tokenize<float >(binningStr);
237+ size_t nY2XBins = 20 ;
238+ std::vector<float > halfBinWidth;
239+
240+ auto setUniformBinning = [&binCenters, &halfBinWidth](int nY2XBins) {
241+ binCenters.resize (nY2XBins);
242+ halfBinWidth.resize (nY2XBins);
243+ for (int i = 0 ; i < nY2XBins; ++i) {
244+ const auto binWidth = 2 .f / nY2XBins;
245+ halfBinWidth[i] = binWidth / 2 .f ;
246+ binCenters[i] = -1 .f + (i + 0 .5f ) * binWidth;
247+ }
248+ };
249+
250+ if (binCenters.size () == 0 ) {
251+ LOGP (info, " Empty binning provided, will use default uniform y/x binning with {} bins" , nY2XBins);
252+ setUniformBinning (nY2XBins);
253+ } else if (binCenters.size () == 1 ) {
254+ nY2XBins = static_cast <int >(binCenters.at (0 ));
255+ LOGP (info, " Setting uniform binning for y/x with {} bins" , nY2XBins);
256+ setUniformBinning (nY2XBins);
257+ } else {
258+ nY2XBins = binCenters.size () - 1 ;
259+ if (std::abs (binCenters[0 ] + 1 .f ) > 1e-6 || std::abs (binCenters[nY2XBins] - 1 .f ) > 1e-6 ) {
260+ LOG (error) << " Provided binning for y/x not in range -1 to 1: " << binCenters[0 ] << " - " << binCenters[nY2XBins] << " . Using default uniform binning with " << nY2XBins << " bins" ;
261+ setUniformBinning (nY2XBins);
262+ } else {
263+ LOGP (info, " Setting custom binning for y/x with {} bins" , nY2XBins);
264+ halfBinWidth.reserve (nY2XBins);
265+ halfBinWidth.clear ();
266+ for (int i = 0 ; i < nY2XBins; ++i) {
267+ halfBinWidth.push_back (.5f * (binCenters[i + 1 ] - binCenters[i]));
268+ binCenters[i] = .5f * (binCenters[i] + binCenters[i + 1 ]);
269+ }
270+ binCenters.resize (nY2XBins);
271+ }
272+ }
273+
274+ for (int irow = 0 ; irow < nPadRows; ++irow) {
275+ const auto x = mapper.getPadCentre (PadPos (irow, 0 )).X ();
276+ maxY2X[irow] = std::tan (.5f * secPhi) - deadZone / x;
277+ const auto region = Mapper::REGION[irow];
278+ const auto ph = mapper.getPadRegionInfo (region).getPadHeight ();
279+ const auto xPadBottom = x - ph / 2 ;
280+ const auto xPadTop = x + ph / 2 ;
281+ for (int iy2x = 0 ; iy2x < nY2XBins; ++iy2x) {
282+ auto & padCoord = padCoords.emplace_back ();
283+ float yPadRight = 0 ;
284+ if (iy2x == 0 ) {
285+ yPadRight = maxY2X[irow] * (binCenters[iy2x] - halfBinWidth[iy2x]);
286+ } else {
287+ yPadRight = maxY2X[irow] * (binCenters[iy2x - 1 ] + halfBinWidth[iy2x - 1 ]);
288+ }
289+ const auto yPadLeft = maxY2X[irow] * (binCenters[iy2x] + halfBinWidth[iy2x]);
290+ padCoord.xVals = {xPadBottom, xPadTop, xPadTop, xPadBottom};
291+ padCoord.yVals = {yPadRight * xPadBottom, yPadRight * xPadTop, yPadLeft * xPadTop, yPadLeft * xPadBottom};
292+ }
293+ }
294+
295+ return padCoords;
296+ }
297+
298+ std::vector<o2::tpc::painter::PadCoordinates> painter::getCoordinates (const Type type, std::string binningStr)
227299{
228300 if (type == Type::Pad) {
229301 return painter::getPadCoordinatesSector ();
230302 } else if (type == Type::Stack) {
231303 return painter::getStackCoordinatesSector ();
232304 } else if (type == Type::FEC) {
233305 return painter::getFECCoordinatesSector ();
306+ } else if (type == Type::SCD) {
307+ return painter::getSCDY2XCoordinatesSector (binningStr);
234308 } else {
235309 LOGP (warning, " Wrong Type provided!" );
236310 return std::vector<o2::tpc::painter::PadCoordinates>();
@@ -805,11 +879,11 @@ std::vector<TCanvas*> painter::makeSummaryCanvases(const std::string_view fileNa
805879}
806880
807881// ______________________________________________________________________________
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)
882+ 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 )
809883{
810884 auto poly = new TH2Poly (name.data (), title.data (), xMin, xMax, yMin, yMax);
811885
812- auto coords = painter::getCoordinates (type);
886+ auto coords = painter::getCoordinates (type, binningStr );
813887 for (const auto & coord : coords) {
814888 poly->AddBin (coord.xVals .size (), coord.xVals .data (), coord.yVals .data ());
815889 }
@@ -818,12 +892,12 @@ TH2Poly* painter::makeSectorHist(const std::string_view name, const std::string_
818892}
819893
820894// ______________________________________________________________________________
821- TH2Poly* painter::makeSideHist (Side side, const Type type)
895+ TH2Poly* painter::makeSideHist (Side side, const Type type, std::string binningStr )
822896{
823897 const auto s = (side == Side::A) ? " A" : " C" ;
824898 auto poly = new TH2Poly (fmt::format (" hSide_{}" , s).data (), fmt::format (" {}-Side;#it{{x}} (cm);#it{{y}} (cm)" , s).data (), -270 ., 270 ., -270 ., 270 .);
825899
826- auto coords = painter::getCoordinates (type);
900+ auto coords = painter::getCoordinates (type, binningStr );
827901 for (int isec = 0 ; isec < 18 ; ++isec) {
828902 const float angDeg = 10 .f + isec * 20 ;
829903 for (auto coord : coords) {
0 commit comments