forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPainter.h
More file actions
261 lines (218 loc) · 11.8 KB
/
Painter.h
File metadata and controls
261 lines (218 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef ALICEO2_TPC_PAINTER_H_
#define ALICEO2_TPC_PAINTER_H_
///
/// \file Painter.h
/// \author Jens Wiechula, Jens.Wiechula@ikf.uni-frankfurt.de
///
#include <vector>
#include <string>
#include <string_view>
#include "DataFormatsTPC/Defs.h"
#include "DataFormatsTPC/LtrCalibData.h"
class TH1;
class TH2;
class TH3F;
class TH2Poly;
class TCanvas;
class TMultiGraph;
class TTree;
namespace o2::tpc
{
template <class T>
class CalDet;
template <class T>
class CalArray;
/// \namespace painter
/// \brief Drawing helper functions
///
/// In this namespace drawing function for calibration objects are implemented
///
/// origin: TPC
/// \author Jens Wiechula, Jens.Wiechula@ikf.uni-frankfurt.de
struct painter {
enum class Type : int {
Pad, ///< drawing pads
Stack, ///< drawing stacks
FEC, ///< drawing of FECs
SCD, ///< drawing of FECs
};
static std::array<int, 6> colors;
static std::array<int, 10> markers;
/// pad corner coordinates
struct PadCoordinates {
std::vector<double> xVals = std::vector<double>(4);
std::vector<double> yVals = std::vector<double>(4);
void rotate(float angDeg)
{
const auto ang = 0.017453292519943295 * angDeg;
const auto cs = std::cos(ang);
const auto sn = std::sin(ang);
for (size_t i = 0; i < xVals.size(); ++i) {
const auto x = xVals[i] * cs - yVals[i] * sn;
const auto y = xVals[i] * sn + yVals[i] * cs;
xVals[i] = x;
yVals[i] = y;
}
}
};
/// create a vector of pad corner coordinate for one full sector
static std::vector<PadCoordinates> getPadCoordinatesSector();
/// create a vector of stack corner coordinate for one full sector
static std::vector<PadCoordinates> getStackCoordinatesSector();
/// create a vector of FEC corner coordinates for one full sector
static std::vector<PadCoordinates> getFECCoordinatesSector();
static std::vector<painter::PadCoordinates> getSCDY2XCoordinatesSector(std::string binningStr);
/// \return returns coordinates for given type
static std::vector<o2::tpc::painter::PadCoordinates> getCoordinates(const Type type, std::string binningStr = "");
/// binning vector with radial pad-row positions (in cm)
/// \param roc roc number (0-35 IROC, 36-71 OROC, >=72 full sector)
static std::vector<double> getRowBinningCM(uint32_t roc = 72);
/// ROC title from ROC number
static std::string getROCTitle(const int rocNumber);
// using T=float;
/// Drawing of a CalDet object
/// \param CalDet object to draw
/// \return TCanvas containing CalDet content
template <class T>
static TCanvas* draw(const CalDet<T>& calDet, int nbins1D = 300, float xMin1D = 0, float xMax1D = 0, TCanvas* outputCanvas = nullptr);
/// Drawing of a CalDet object
/// \param CalArray object to draw
/// \return TCanvas containing CalArray content
template <class T>
static TCanvas* draw(const CalArray<T>& calArray);
/// fill existing 2D histogram for CalDet object
/// \param h2D histogram to fill
/// \param CalDet object with data
/// \param side side which to get the histogram for
template <class T>
static void fillHistogram2D(TH2& h2D, const CalDet<T>& calDet, Side side);
/// fill existing 2D histogram for CalArray object
/// \param h2D histogram to fill
/// \param CalArray object with data
template <class T>
static void fillHistogram2D(TH2& h2D, const CalArray<T>& calArray);
/// get 2D histogram for CalDet object
/// \param CalDet object with data
/// \param side side which to get the histogram for
/// \return 2D histogram with data
template <class T>
static TH2* getHistogram2D(const CalDet<T>& calDet, Side side);
/// get 2D histogram for CalArray object
/// \param CalDet object with data
/// \param side side which to get the histogram for
/// \return 2D histogram with data
template <class T>
static TH2* getHistogram2D(const CalArray<T>& calArray);
/// make a sector-wise histogram with correct pad corners
/// \param xMin minimum x coordinate of the histogram
/// \param xMax maximum x coordinate of the histogram
/// \param yMin minimum y coordinate of the histogram
/// \param yMax maximum y coordinate of the histogram
/// \param type granularity of the histogram (per pad or per stack)
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 = "");
/// make a side-wise histogram with correct pad corners
/// \param type granularity of the histogram (per pad or per stack)
static TH2Poly* makeSideHist(Side side, const Type type = Type::Pad, std::string binningStr = "");
/// fill existing TH2Poly histogram for CalDet object
/// \param h2D histogram to fill
/// \param CalDet object with data
/// \param side side which to get the histogram for
template <class T>
static void fillPoly2D(TH2Poly& h2D, const CalDet<T>& calDet, Side side);
/// Create summary canvases for a CalDet object
///
/// 1 Canvas with 2D and 1D distributions for each side
/// 1 Canvas with 2D distributions for all ROCs
/// 1 Canvas with 1D distributions for all ROCs
/// \param CalDet object to draw
/// \param nbins1D number of bins used for the 1D projections
/// \param xMin1D minimum value for 1D distribution (xMin = 0 and xMax = 0 for auto scaling)
/// \param xMax1D maximum value for 1D distribution (xMin = 0 and xMax = 0 for auto scaling)
/// \param outputCanvases if outputCanvases are given, use them instead of creating new ones, 3 are required
/// \return TCanvas containing CalDet content
template <class T>
static std::vector<TCanvas*> makeSummaryCanvases(const CalDet<T>& calDet, int nbins1D = 300, float xMin1D = 0, float xMax1D = 0, bool onlyFilled = true, std::vector<TCanvas*>* outputCanvases = nullptr);
/// Create summary canvases for a CalDet object
///
/// 1 Canvas with 2D and 1D distributions for each side
/// 1 Canvas with 2D distributions for all ROCs
/// 1 Canvas with 1D distributions for all ROCs
/// \param CalDet object to draw
/// \param nbins1D number of bins used for the 1D projections
/// \param xMin1D minimum value for 1D distribution (xMin = 0 and xMax = 0 for auto scaling)
/// \param xMax1D maximum value for 1D distribution (xMin = 0 and xMax = 0 for auto scaling)
/// \param fileName input file name
/// \param calPadNames comma separated list of names of the CalPad objects as stored in the file.
/// \return TCanvas containing CalDet content
static std::vector<TCanvas*> makeSummaryCanvases(const std::string_view fileName, const std::string_view calPadNames, int nbins1D = 300, float xMin1D = 0, float xMax1D = 0, bool onlyFilled = true);
/// Create summary canvases from pad calibration tree dumped via CalibTreeDump
///
/// 1 Canvas with 2D and 1D distributions for each side
/// 1 Canvas with 2D distributions for all ROCs
/// 1 Canvas with 1D distributions for all ROCs
/// \param tree input calibTree
/// \param draw draw string to use for the variable (1D)
/// \param cut cut string to use (default 1 = no cut)
/// \param nbins1D number of bins used for the 1D projections, if negative, exclude per ROC histograms
/// \param xMin1D minimum value for 1D distribution (xMin = 0 and xMax = 0 for auto scaling)
/// \param xMax1D maximum value for 1D distribution (xMin = 0 and xMax = 0 for auto scaling)
/// \return TCanvas containing CalDet content
static std::vector<TCanvas*> makeSummaryCanvases(TTree& tree, const std::string_view draw, std::string_view cut = "1", int nbins1D = 300, float xMin1D = 0, float xMax1D = 0);
/// draw sector boundaris, side name and sector numbers
static void drawSectorsXY(Side side, int sectorLineColor = 920, int sectorTextColor = 1);
/// draw information of the sector: pad number in row
/// \param padTextColor text color of pad number
/// \param lineScalePS setting the width of the lines of the pads which are drawn
static void drawSectorLocalPadNumberPoly(short padTextColor = kBlack, float lineScalePS = 1);
/// draw information of the sector: pad row in region, global pad row, lines for separating the regions
/// \param regionLineColor color of the line which is drawn at the start of a sector
/// \param rowTextColor color of the text which is drawn
static void drawSectorInformationPoly(short regionLineColor = kRed, short rowTextColor = kRed);
/// convert std::vector<CalDet> objects (pad granularity) to a 3D-histogram with rxphixz binning. Each CalDet will be filled in a unique slice in the histogram
/// \param calDet input objects which will be converted to a 3D histogram
/// \param norm whether to normalize the histogram (weighted mean) or to just integrate the values of the CalDet
/// \param nRBins number of bins in r direction of the output histogram
/// \param rMin min r value of the output histogram
/// \param rMax max r value of the output histogram
/// \param nPhiBins number of bins in phi direction of the output histogram
/// \param zMax z range of the output histogram (-zMax to zMax)
template <typename DataT>
static TH3F convertCalDetToTH3(const std::vector<CalDet<DataT>>& calDet, const bool norm = true, const int nRBins = 150, const float rMin = 83.5, const float rMax = 254.5, const int nPhiBins = 720, const float zMax = 1);
/// make summary canvases for laser calibration data
static std::vector<TCanvas*> makeSummaryCanvases(const LtrCalibData& ltr, std::vector<TCanvas*>* outputCanvases = nullptr);
/// make a canvas for junk detection data
static TCanvas* makeJunkDetectionCanvas(const TObjArray* data, TCanvas* outputCanvas = nullptr);
/// Adjust the X2 position and the tick length of the color axis
/// \param h histogram to get z axis
/// \param x2ndc new x2 value of color axis in NDC
/// \param tickLength tick length of the color axis
static void adjustPalette(TH1* h, float x2ndc, float tickLength = 0.015);
/// Make a multi graph with sparse option
///
/// Produce a multi graph from a tree, where `varX` is a common x variable, e.g. a run number.
/// TTree::Draw is used to fill the variables, so all expressions supported can be used.
/// As in TTree::Draw, varsY have to be seperated by a ':'. For each variable a Graph will be created.
/// Optionally one can give 'errVarsY', which must have the same number of entries as 'varsY'.
/// In case the 'sparse' option is set (default), the x-axis will have as many bins as `varX` has entries. The bins will be labelled accordingly.
/// Colors and marker are assigned automatically using the ones defined in 'colors' and 'markers'
///
/// \param tree the input tree to use
/// \param varX the x variable to create the sparse binning from
/// \param varsY the y variable for ech of which to create a graph, separated by ':'
/// \param errVarsY the y variable errors, separated by ':', same number of variables as in varsY required
/// \param cuts cut string to be used in the TTree::Draw
/// \param makeSparse make a sparse graph (default)
static TMultiGraph* makeMultiGraph(TTree& tree, std::string_view varX, std::string_view varsY, std::string_view errVarsY = "", std::string_view cut = "", bool makeSparse = true);
}; // struct painter
} // namespace o2::tpc
#endif // ALICEO2_TPC_PAINTER_H_