forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIDCCCDBHelper.h
More file actions
279 lines (222 loc) · 14.4 KB
/
IDCCCDBHelper.h
File metadata and controls
279 lines (222 loc) · 14.4 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// 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.
/// \file IDCCCDBHelper.h
/// \brief helper class for accessing IDCs from CCDB
/// \author Matthias Kleiner <mkleiner@ikf.uni-frankfurt.de>
#ifndef ALICEO2_TPC_IDCCCDBHELPER_H_
#define ALICEO2_TPC_IDCCCDBHELPER_H_
#include <Framework/Logger.h>
#include "DataFormatsTPC/Defs.h"
#include "TPCBaseRecSim/PadFlags.h"
#include "TPCBase/Sector.h"
#include "Rtypes.h"
#include <fmt/format.h>
class TCanvas;
namespace o2::tpc
{
class IDCGroupHelperSector;
struct IDCZero;
struct IDCOne;
struct FourierCoeff;
template <typename DataT>
struct IDCDelta;
enum class PadFlags : unsigned short;
template <class T>
class CalDet;
/*
Usage
o2::tpc::IDCCCDBHelper<unsigned short> helper;
// setting the IDC members manually
helper.setIDCDelta(IDCDelta<DataT>* idcDelta);
helper.setIDCZero(IDCZero* idcZero);
helper.setIDCOne(IDCOne* idcOne);
helper.setGroupingParameter(IDCGroupHelperSector* helperSector);
// draw or access the IDCs
const unsigned int sector = 10;
const unsigned int integrationInterval = 0;
helper.drawIDCZeroSide(o2::tpc::Side::A);
helper.drawIDCDeltaSector(sector, integrationInterval);
helper.drawIDCDeltaSide(o2::tpc::Side::A, integrationInterval);
helper.drawIDCSide(o2::tpc::Side::A, integrationInterval);
TODO add drawing of 1D-distributions
*/
/// \tparam DataT the data type for the IDCDelta which are stored in the CCDB (unsigned short, unsigned char, float)
template <typename DataT = unsigned short>
class IDCCCDBHelper
{
public:
/// constructor
IDCCCDBHelper() = default;
/// setting the IDCDelta class member
void setIDCDelta(IDCDelta<DataT>* idcDelta, const Side side = Side::A) { mIDCDelta[side] = idcDelta; }
/// setting the 0D-IDCs
void setIDCZero(IDCZero* idcZero, const Side side = Side::A) { mIDCZero[side] = idcZero; }
/// setting the 1D-IDCs
void setIDCOne(IDCOne* idcOne, const Side side = Side::A) { mIDCOne[side] = idcOne; }
/// setting the fourier coefficients
void setFourierCoeffs(FourierCoeff* fourier, const Side side = Side::A) { mFourierCoeff[side] = fourier; }
/// set scaling of IDC0 to 1
/// \param rejectOutlier do not take outlier into account
void setIDCZeroScale(const bool rejectOutlier = true);
/// setting the grouping parameters
void setGroupingParameter(IDCGroupHelperSector* helperSector, const Side side = Side::A) { mHelperSector[side] = helperSector; }
/// \return returns the number of integration intervals for IDCDelta
unsigned int getNIntegrationIntervalsIDCDelta(const o2::tpc::Side side) const;
/// \return returns the number of integration intervals for IDCOne
unsigned int getNIntegrationIntervalsIDCOne(const o2::tpc::Side side) const;
/// \return returns the stored IDC0 value for local ungrouped pad row and ungrouped pad
/// \param sector sector
/// \param region region
/// \param urow row of the ungrouped IDCs
/// \param upad pad number of the ungrouped IDCs
float getIDCZeroVal(const unsigned int sector, const unsigned int region, unsigned int urow, unsigned int upad) const;
/// \return returns the stored DeltaIDC value for local ungrouped pad row and ungrouped pad
/// \param sector sector
/// \param region region
/// \param urow row of the ungrouped IDCs
/// \param upad pad number of the ungrouped IDCs
/// \param integrationInterval integration interval
float getIDCDeltaVal(const unsigned int sector, const unsigned int region, unsigned int urow, unsigned int upad, unsigned int integrationInterval) const;
/// \return returns IDCOne value
/// \param side side of the TPC
/// \param integrationInterval integration interval
float getIDCOneVal(const o2::tpc::Side side, const unsigned int integrationInterval) const;
/// create the outlier map with the set unscaled IDC0 map
void createOutlierMap();
/// \return returns the IDC value which is calculated with: (IDCDelta + 1) * IDCOne * IDCZero
/// \param sector sector
/// \param region region
/// \param urow row of the ungrouped IDCs
/// \param upad pad number of the ungrouped IDCs
/// \param integrationInterval integration interval
float getIDCVal(const unsigned int sector, const unsigned int region, unsigned int urow, unsigned int upad, unsigned int integrationInterval) const;
/// draw IDC zero I_0(r,\phi) = <I(r,\phi,t)>_t
/// \param side side which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCZeroSide(const o2::tpc::Side side, const std::string filename = "IDCZeroSide.pdf", const float minZ = 0, const float maxZ = -1) const { drawIDCZeroHelper(true, side == Side::A ? Sector(0) : Sector(Sector::MAXSECTOR - 1), filename, minZ, maxZ); }
/// draw IDCDelta for one side for one integration interval
/// \param side side which will be drawn
/// \param integrationInterval which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCDeltaSide(const o2::tpc::Side side, const unsigned int integrationInterval, const std::string filename = "IDCDeltaSide.pdf", const float minZ = 0, const float maxZ = -1) const { drawIDCDeltaHelper(true, side == Side::A ? Sector(0) : Sector(Sector::MAXSECTOR - 1), integrationInterval, filename, minZ, maxZ); }
/// draw IDCs which is calculated with: (IDCDelta + 1) * IDCOne * IDCZero
/// \param side side which will be drawn
/// \param integrationInterval which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCSide(const o2::tpc::Side side, const unsigned int integrationInterval, const std::string filename = "IDCSide.pdf", const float minZ = 0, const float maxZ = -1) const { drawIDCHelper(true, side == Side::A ? Sector(0) : Sector(Sector::MAXSECTOR - 1), integrationInterval, filename, minZ, maxZ); }
/// draw IDC zero I_0(r,\phi) = <I(r,\phi,t)>_t
/// \param sector sector which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCZeroSector(const unsigned int sector, const std::string filename = "IDCZeroSector.pdf", const float minZ = 0, const float maxZ = -1) const { drawIDCZeroHelper(false, Sector(sector), filename, minZ, maxZ); }
/// draw IDCDelta for one sector for one integration interval
/// \param sector sector which will be drawn
/// \param integrationInterval which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCDeltaSector(const unsigned int sector, const unsigned int integrationInterval, const std::string filename = "IDCDeltaSector.pdf", const float minZ = 0, const float maxZ = -1) const { drawIDCDeltaHelper(false, Sector(sector), integrationInterval, filename, minZ, maxZ); }
/// draw IDC zero I_0(r,\phi) = <I(r,\phi,t)>_t
/// \param sector sector which will be drawn
/// \param integrationInterval which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCSector(const unsigned int sector, const unsigned int integrationInterval, const std::string filename = "IDCSector.pdf", const float minZ = 0, const float maxZ = -1) const { drawIDCHelper(false, Sector(sector), integrationInterval, filename, minZ, maxZ); }
/// draw the status map for the flags (for debugging) for a sector
/// \param sector sector which will be drawn
/// \flag flag which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawPadStatusFlagsMapSector(const unsigned int sector, const PadFlags flag, const std::string filename = "PadStatusFlags_Sector.pdf") const { drawPadFlagMap(false, Sector(sector), filename, flag); }
/// draw the status map for the flags (for debugging) for a full side
/// \param side side which will be drawn
/// \param flag which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawPadStatusFlagsMapSide(const o2::tpc::Side side, const PadFlags flag, const std::string filename = "PadStatusFlags_Side.pdf") const { drawPadFlagMap(true, side == Side::A ? Sector(0) : Sector(Sector::MAXSECTOR - 1), filename, flag); }
TCanvas* drawIDCZeroCanvas(TCanvas* outputCanvas, std::string_view type, int nbins1D, float xMin1D, float xMax1D, int integrationInterval = -1) const;
TCanvas* drawIDCZeroScale(TCanvas* outputCanvas, const bool rejectOutlier = true) const;
TCanvas* drawIDCZeroRadialProfile(TCanvas* outputCanvas, int nbinsY, float yMin, float yMax) const;
TCanvas* drawIDCZeroStackCanvas(TCanvas* outputCanvas, Side side, std::string_view type, int nbins1D, float xMin1D, float xMax1D, int integrationInterval = -1) const;
TCanvas* drawIDCOneCanvas(TCanvas* outputCanvas, int nbins1D, float xMin1D, float xMax1D, int integrationIntervals = -1) const;
TCanvas* drawFourierCoeff(TCanvas* outputCanvas, Side side, int nbins1D, float xMin1D, float xMax1D) const;
/// dumping the loaded IDC0, IDC1 to a tree for debugging
/// \param side TPC side of the data which will be dumped
/// \param outFileName name of the output file
void dumpToTree(const Side side, const char* outFileName = "IDCCCDBTree.root") const;
/// dumping the loaded fourier coefficients to a tree
/// \param outFileName name of the output file
void dumpToFourierCoeffToTree(const char* outFileName = "FourierCCDBTree.root") const;
/// dumping the loaded IDC0, IDC1 to a tree for debugging
/// \param side TPC side of the data which will be dumped
/// \param outFileName name of the output file
void dumpToTreeIDCDelta(const Side side, const char* outFileName = "IDCCCDBTreeDeltaIDC.root") const;
/// convert the loaded IDC0 map to a CalDet<float>
/// \return returns CalDet containing the IDCZero
CalDet<float> getIDCZeroCalDet() const;
/// convert the loaded IDCDelta to a vector of CalDets
/// \return returns std vector of CalDets containing the IDCDelta
std::vector<CalDet<float>> getIDCDeltaCalDet() const;
/// \return returns pointer to pad status map
CalDet<PadFlags>* getPadStatusMap() const { return mPadFlagsMap.get(); }
/// \return returns pointer to pad status map
void setPadStatusMap(const CalDet<PadFlags>& outliermap) { mPadFlagsMap = std::make_unique<CalDet<PadFlags>>(outliermap); }
/// scale the stored IDC0 to 1
/// \param factor to scale the IDC0s with (IDC0/=factor)
/// \param side TPC side of the IDCs
void scaleIDC0(const float factor, const Side side);
/// \returns mean of IDC0
/// \param side TPC side of the IDCs
/// \param idcZero IDCZero object for which to get the mean
/// \param outlierMap possible map containing the outliers which will not be taken into account (if nullptr all IDCs are taken into account)
static float getMeanIDC0(const Side side, const IDCZero& idcZero, const CalDet<PadFlags>* outlierMap);
/// \return return for the set outlier map the total number of outliers per side .first=A-side, .second=C-side
std::pair<int, int> getNOutliers() const;
/// get median of IDC0 for given stack and sector
/// \param idcZero IDCZero object for which to get the mean
/// \param sector TPC sector
/// \param stack stack in sector
static float getStackMedian(const IDCZero& idczero, const Sector sector, const GEMstack stack);
/// get medians per stack for given side
/// \param idcZero IDCZero object for which to get the mean
/// \param side TPC side of the IDCZero
static std::array<float, o2::tpc::GEMSTACKSPERSECTOR * o2::tpc::SECTORSPERSIDE> getStackMedian(const IDCZero& idczero, const Side side);
private:
///\ to scale IDC0 from its total
float mScaleIDC0Aside = 1.0;
float mScaleIDC0Cside = 1.0;
std::array<IDCZero*, SIDES> mIDCZero = {nullptr, nullptr}; ///< 0D-IDCs: ///< I_0(r,\phi) = <I(r,\phi,t)>_t
std::array<IDCDelta<DataT>*, SIDES> mIDCDelta = {nullptr, nullptr}; ///< compressed or uncompressed Delta IDC: \Delta I(r,\phi,t) = I(r,\phi,t) / ( I_0(r,\phi) * I_1(t) )
std::array<IDCOne*, SIDES> mIDCOne = {nullptr, nullptr}; ///< I_1(t) = <I(r,\phi,t) / I_0(r,\phi)>_{r,\phi}
std::array<IDCGroupHelperSector*, SIDES> mHelperSector = {nullptr, nullptr}; ///< helper for accessing IDC0 and IDC-Delta
std::array<FourierCoeff*, SIDES> mFourierCoeff = {nullptr, nullptr}; ///< fourier coefficients of IDCOne
std::unique_ptr<CalDet<PadFlags>> mPadFlagsMap; ///< status flag for each pad (i.e. if the pad is dead)
/// helper function for drawing IDCZero
/// \param sector sector which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCZeroHelper(const bool type, const Sector sector, const std::string filename, const float minZ, const float maxZ) const;
/// helper function for drawing IDCDelta
/// \param sector sector which will be drawn
/// \param integrationInterval which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCDeltaHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const std::string filename, const float minZ, const float maxZ) const;
/// helper function for drawing IDC
/// \param sector sector which will be drawn
/// \param integrationInterval which will be drawn
/// \param filename name of the output file. If empty the canvas is drawn.
void drawIDCHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const std::string filename, const float minZ, const float maxZ) const;
/// helper function for drawing
void drawPadFlagMap(const bool type, const Sector sector, const std::string filename, const PadFlags flag) const;
/// \return returns index to data from ungrouped pad and row
/// \param sector sector
/// \param region region
/// \param urow row of the ungrouped IDCs
/// \param upad pad number of the ungrouped IDCs
/// \param integrationInterval integration interval
static unsigned int getUngroupedIndexGlobal(const unsigned int sector, const unsigned int region, unsigned int urow, unsigned int upad, unsigned int integrationInterval);
ClassDefNV(IDCCCDBHelper, 3)
};
} // namespace o2::tpc
#endif