Skip to content

Commit 53bd9ce

Browse files
matthias-kleinerdavidrohr
authored andcommitted
TPC IDCs: add drawing of IDCs as GIF
1 parent a682e3d commit 53bd9ce

4 files changed

Lines changed: 186 additions & 10 deletions

File tree

Detectors/TPC/calibration/include/TPCCalibration/IDCDrawHelper.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ class IDCDrawHelper
6666
static void drawRadialProfile(const IDCDraw& idc, TH2F& hist, const o2::tpc::Side side);
6767
static void drawIDCZeroStackCanvas(const IDCDraw& idc, const o2::tpc::Side side, const std::string_view type, const int nbins1D, const float xMin1D, const float xMax1D, TCanvas& outputCanvas, int integrationInterval);
6868

69+
struct IDCDrawGIF {
70+
std::function<float(const unsigned int, const unsigned int, const unsigned int, const unsigned int, const unsigned int)> mIDCFunc; ///< function returning the value which will be drawn for sector, region, row, pad
71+
std::function<float(const o2::tpc::Side side, const unsigned int)> mIDCOneFunc; ///< function returning the value which will be drawn for side, slice
72+
};
73+
74+
/// \brief make a GIF of IDCs for A and C side and the 1D IDCs
75+
/// \param idc IDCDraw struct containing function to get the IDCs + 1D IDCs which will be drawn
76+
/// \param zAxisTitle axis title of the z axis
77+
/// \param fileName name of the output file (.gif is added automatically)
78+
/// \param minZ min z value for drawing (if minZ > maxZ automatic z axis)
79+
/// \param maxZ max z value for drawing (if minZ > maxZ automatic z axis)
80+
/// \param run run of the IDCs (if =-1 then no run number is drawn)
81+
static void drawSideGIF(const IDCDrawGIF& idcs, const unsigned int slices, const std::string zAxisTitle, const std::string filename = "IDCs", const float minZ = 0, const float maxZ = -1, const int run = -1);
82+
6983
/// \return returns z axis title
7084
/// \param type IDC type
7185
/// \param compression compression of the IDCs if used (only for IDCDelta)

Detectors/TPC/calibration/include/TPCCalibration/IDCFactorization.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ class IDCFactorization : public IDCGroupHelperSector
238238
/// \param filename name of the output file. If empty the canvas is drawn.
239239
void drawIDCsSide(const o2::tpc::Side side, const unsigned int integrationInterval, const float minZ = 0, const float maxZ = -1, const std::string filename = "IDCsSide.pdf") const { drawIDCHelper(true, side == Side::A ? Sector(0) : Sector(Sector::MAXSECTOR - 1), integrationInterval, filename, minZ, maxZ); }
240240

241+
/// draw GIF for IDCs
242+
/// \param integrationIntervals number of ms to draw
243+
void drawIDCsSideGIF(const unsigned int integrationIntervals = 0, const float minZ = 0, const float maxZ = -1, const int run = -1, const std::string filename = "IDCsSideGIF") const { drawIDCHelper(true, Sector(0), integrationIntervals, filename, minZ, maxZ, true, run); }
244+
241245
/// draw IDC zero I_0(r,\phi) = <I(r,\phi,t)>_t
242246
/// \param side side which will be drawn
243247
/// \param filename name of the output file. If empty the canvas is drawn.
@@ -344,7 +348,7 @@ class IDCFactorization : public IDCGroupHelperSector
344348
void drawIDCDeltaHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const IDCDeltaCompression compression, const std::string filename, const float minZ, const float maxZ) const;
345349

346350
/// helper function for drawing IDCs
347-
void drawIDCHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const std::string filename, const float minZ, const float maxZ) const;
351+
void drawIDCHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const std::string filename, const float minZ, const float maxZ, const bool drawGIF = false, const int run = 0) const;
348352

349353
/// helper function for drawing IDCZero
350354
void drawIDCZeroHelper(const bool type, const Sector sector, const std::string filename, const float minZ, const float maxZ) const;

Detectors/TPC/calibration/src/IDCDrawHelper.cxx

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "TH2Poly.h"
1616
#include "TCanvas.h"
1717
#include "TLatex.h"
18+
#include "TGraphErrors.h"
19+
#include "TMultiGraph.h"
1820
#include <fmt/format.h>
1921

2022
unsigned int o2::tpc::IDCDrawHelper::getPad(const unsigned int pad, const unsigned int region, const unsigned int row, const Side side)
@@ -266,8 +268,143 @@ std::string o2::tpc::IDCDrawHelper::getZAxisTitle(const IDCType type, const IDCD
266268
}
267269
}
268270
case IDCType::IDCOne: {
269-
return fmt::format("#Delta#it{{{}}}_{{1}}", stype);
271+
return fmt::format("#it{{{}}}_{{1}}", stype);
270272
break;
271273
}
272274
}
273275
}
276+
277+
void o2::tpc::IDCDrawHelper::drawSideGIF(const IDCDrawGIF& idcs, const unsigned int slices, const std::string zAxisTitle, const std::string filename, const float minZ, const float maxZ, const int run)
278+
{
279+
const int gifSpeed = 40;
280+
281+
TCanvas can("canvas", "canvas", 3350, 2000);
282+
TPad padIDCA("padIDCA", "padIDCA", 0, 0.25, 0.5, 1);
283+
TPad padIDCC("padIDCC", "padIDCC", 0.5, 0.25, 1, 1);
284+
TPad padIDCOne("padIDCOne", "padIDCOne", 0, 0, 1, 0.25);
285+
286+
const float tm = 0.04f;
287+
const float rm = 0.14f;
288+
const float lm = 0.1f;
289+
const float bm = 0.2f;
290+
padIDCA.SetTopMargin(tm);
291+
padIDCA.SetRightMargin(rm);
292+
padIDCA.SetLeftMargin(lm);
293+
padIDCC.SetTopMargin(tm);
294+
padIDCC.SetRightMargin(rm);
295+
padIDCC.SetLeftMargin(lm);
296+
padIDCOne.SetTopMargin(tm);
297+
padIDCOne.SetRightMargin(rm / 2);
298+
padIDCOne.SetLeftMargin(lm / 2);
299+
padIDCOne.SetBottomMargin(bm);
300+
301+
padIDCA.Draw();
302+
padIDCC.Draw();
303+
padIDCOne.Draw();
304+
305+
std::array<TGraphErrors, SIDES> graphIDCOne;
306+
std::array<TGraphErrors, SIDES> graphIDCOneSlice;
307+
TMultiGraph multiGraph;
308+
float minY = 1000;
309+
float maxY = -1;
310+
const float widthLine = 0.005f;
311+
const float idcWH = 0.5; // IDC width half: 1ms/2
312+
for (unsigned int sideT = 0; sideT < SIDES; ++sideT) {
313+
const Side side = (sideT == 0) ? Side::A : Side::C;
314+
const auto col = (sideT == 0) ? (kGreen + 2) : kBlue;
315+
graphIDCOne[sideT].SetFillColorAlpha(col, 0.3);
316+
graphIDCOne[sideT].SetLineWidth(5);
317+
graphIDCOneSlice[sideT] = graphIDCOne[sideT];
318+
graphIDCOneSlice[sideT].Set(1);
319+
graphIDCOneSlice[sideT].SetFillColorAlpha(col, 1);
320+
for (unsigned int slice = 0; slice < slices; ++slice) {
321+
const auto idc = idcs.mIDCOneFunc(side, slice);
322+
if (idc < minY) {
323+
minY = idc;
324+
}
325+
if (idc > maxY) {
326+
maxY = idc;
327+
}
328+
graphIDCOne[sideT].AddPoint(slice + idcWH, idc);
329+
graphIDCOne[sideT].SetPointError(slice, idcWH, widthLine);
330+
}
331+
multiGraph.Add(&graphIDCOne[sideT]);
332+
}
333+
334+
const int font = 63;
335+
const int fontsize = 50;
336+
multiGraph.GetXaxis()->SetTitleFont(font);
337+
multiGraph.GetXaxis()->SetLabelFont(font);
338+
multiGraph.GetYaxis()->SetTitleFont(font);
339+
multiGraph.GetYaxis()->SetLabelFont(font);
340+
multiGraph.GetXaxis()->SetLabelSize(fontsize);
341+
multiGraph.GetXaxis()->SetTitleSize(fontsize);
342+
multiGraph.GetYaxis()->SetLabelSize(fontsize);
343+
multiGraph.GetYaxis()->SetTitleSize(fontsize);
344+
multiGraph.GetXaxis()->SetTitle("#it{t} (ms)");
345+
multiGraph.GetXaxis()->SetTitleOffset(0.9f);
346+
multiGraph.GetYaxis()->SetTitleOffset(1.5f);
347+
multiGraph.GetYaxis()->SetTitle(IDCDrawHelper::getZAxisTitle(IDCType::IDCOne).data());
348+
multiGraph.SetMinimum(0.9 * minY);
349+
multiGraph.SetMaximum(1.1 * maxY);
350+
multiGraph.GetXaxis()->SetLimits(0, slices);
351+
352+
for (unsigned int slice = 0; slice < slices; ++slice) {
353+
LOGP(info, "Drawing slice {} from {}", slice, slices - 1);
354+
IDCDrawHelper::IDCDraw drawFun;
355+
std::function<float(const unsigned int, const unsigned int, const unsigned int, const unsigned int)> idcFunc = [slice, idcs](const unsigned int sector, const unsigned int region, const unsigned int irow, const unsigned int pad) {
356+
return idcs.mIDCFunc(sector, region, irow, pad, slice);
357+
};
358+
drawFun.mIDCFunc = idcFunc;
359+
360+
TH2Poly* poly[SIDES]{nullptr, nullptr};
361+
for (int sideT = 0; sideT < SIDES; ++sideT) {
362+
const Side side = (sideT == 0) ? Side::A : Side::C;
363+
poly[sideT] = o2::tpc::IDCDrawHelper::drawSide(drawFun, side, zAxisTitle);
364+
poly[sideT]->GetXaxis()->SetTitleFont(font);
365+
poly[sideT]->GetXaxis()->SetLabelFont(font);
366+
poly[sideT]->GetYaxis()->SetTitleFont(font);
367+
poly[sideT]->GetYaxis()->SetLabelFont(font);
368+
poly[sideT]->GetXaxis()->SetLabelSize(fontsize);
369+
poly[sideT]->GetXaxis()->SetTitleSize(fontsize);
370+
poly[sideT]->GetYaxis()->SetLabelSize(fontsize);
371+
poly[sideT]->GetYaxis()->SetTitleSize(fontsize);
372+
373+
if (minZ < maxZ) {
374+
poly[sideT]->SetMinimum(minZ);
375+
poly[sideT]->SetMaximum(maxZ);
376+
}
377+
378+
if (sideT == 0) {
379+
padIDCA.cd();
380+
} else {
381+
padIDCC.cd();
382+
}
383+
384+
poly[sideT]->Draw("colz");
385+
const std::string sideName = (side == Side::A) ? "A-Side" : "C-Side";
386+
TLatex latex;
387+
const auto col = (side == Side::A) ? (kGreen + 2) : kBlue;
388+
latex.SetTextColor(col);
389+
latex.DrawLatexNDC(0.13, 0.9, sideName.data());
390+
if (run > 0) {
391+
latex.DrawLatexNDC(0.62, 0.9, fmt::format("Run {}", run).data());
392+
}
393+
graphIDCOneSlice[sideT].SetPoint(0, slice + idcWH, idcs.mIDCOneFunc(side, slice));
394+
graphIDCOneSlice[sideT].SetPointError(0, idcWH, widthLine);
395+
}
396+
397+
padIDCOne.cd();
398+
multiGraph.Draw("ZA E2");
399+
graphIDCOneSlice[0].Draw("Z E2 SAME");
400+
graphIDCOneSlice[1].Draw("Z E2 SAME");
401+
402+
can.Print(Form("%s.gif+%i", filename.data(), gifSpeed));
403+
if (slice == (slices - 1)) {
404+
can.Print(Form("%s.gif++", filename.data()));
405+
}
406+
407+
delete poly[0];
408+
delete poly[1];
409+
}
410+
}

Detectors/TPC/calibration/src/IDCFactorization.cxx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,17 +786,38 @@ void o2::tpc::IDCFactorization::drawIDCZeroHelper(const bool type, const Sector
786786
type ? IDCDrawHelper::drawSide(drawFun, sector.side(), zAxisTitle, filename, minZ, maxZ) : IDCDrawHelper::drawSector(drawFun, 0, Mapper::NREGIONS, sector, zAxisTitle, filename, minZ, maxZ);
787787
}
788788

789-
void o2::tpc::IDCFactorization::drawIDCHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const std::string filename, const float minZ, const float maxZ) const
789+
void o2::tpc::IDCFactorization::drawIDCHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const std::string filename, const float minZ, const float maxZ, const bool drawGIF, const int run) const
790790
{
791-
std::function<float(const unsigned int, const unsigned int, const unsigned int, const unsigned int)> idcFunc = [this, integrationInterval](const unsigned int sector, const unsigned int region, const unsigned int irow, const unsigned int pad) {
792-
return this->getIDCValUngrouped(sector, region, irow, pad, integrationInterval);
793-
};
791+
const std::string zAxisTitleDraw = IDCDrawHelper::getZAxisTitle(IDCType::IDC);
792+
if (!drawGIF) {
793+
std::function<float(const unsigned int, const unsigned int, const unsigned int, const unsigned int)> idcFunc = [this, integrationInterval](const unsigned int sector, const unsigned int region, const unsigned int irow, const unsigned int pad) {
794+
return this->getIDCValUngrouped(sector, region, irow, pad, integrationInterval);
795+
};
794796

795-
IDCDrawHelper::IDCDraw drawFun;
796-
drawFun.mIDCFunc = idcFunc;
797+
IDCDrawHelper::IDCDraw drawFun;
798+
drawFun.mIDCFunc = idcFunc;
797799

798-
const std::string zAxisTitleDraw = IDCDrawHelper::getZAxisTitle(IDCType::IDC);
799-
type ? IDCDrawHelper::drawSide(drawFun, sector.side(), zAxisTitleDraw, filename, minZ, maxZ) : IDCDrawHelper::drawSector(drawFun, 0, Mapper::NREGIONS, sector, zAxisTitleDraw, filename, minZ, maxZ);
800+
type ? IDCDrawHelper::drawSide(drawFun, sector.side(), zAxisTitleDraw, filename, minZ, maxZ) : IDCDrawHelper::drawSector(drawFun, 0, Mapper::NREGIONS, sector, zAxisTitleDraw, filename, minZ, maxZ);
801+
} else {
802+
std::function<float(const unsigned int, const unsigned int, const unsigned int, const unsigned int, const unsigned int)> idcFunc = [this](const unsigned int sector, const unsigned int region, const unsigned int irow, const unsigned int pad, const unsigned int slice) {
803+
return this->getIDCValUngrouped(sector, region, irow, pad, slice);
804+
};
805+
806+
if (mIDCOne.front().mIDCOne.empty()) {
807+
LOGP(warning, "Factorised IDCs are missing!");
808+
return;
809+
}
810+
811+
std::function<float(const o2::tpc::Side, const unsigned int)> idcOneFunc = [this](const o2::tpc::Side side, const unsigned int slice) {
812+
return this->getIDCOneVec(side)[slice];
813+
};
814+
815+
IDCDrawHelper::IDCDrawGIF drawFun;
816+
drawFun.mIDCFunc = idcFunc;
817+
drawFun.mIDCOneFunc = idcOneFunc;
818+
const int nSlices = (integrationInterval == 0) ? getNIntegrationIntervals() : integrationInterval;
819+
IDCDrawHelper::drawSideGIF(drawFun, nSlices, zAxisTitleDraw, filename, minZ, maxZ, run);
820+
}
800821
}
801822

802823
void o2::tpc::IDCFactorization::setGainMap(const char* inpFile, const char* mapName)

0 commit comments

Comments
 (0)