Project
Loading...
Searching...
No Matches
SACFactorization.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
17#include "Framework/Logger.h"
18#include "TFile.h"
19#include <functional>
20#include <numeric>
21
22#if (defined(WITH_OPENMP) || defined(_OPENMP)) && !defined(__CLING__)
23#include <omp.h>
24#endif
25
26void o2::tpc::SACFactorization::dumpToFile(const char* outFileName, const char* outName) const
27{
28 TFile fOut(outFileName, "RECREATE");
29 fOut.WriteObject(this, outName);
30 fOut.Close();
31}
32
33void o2::tpc::SACFactorization::dumpToTree(int integrationIntervals, const char* outFileName) const
34{
35 o2::utils::TreeStreamRedirector pcstream(outFileName, "RECREATE");
36 pcstream.GetFile()->cd();
37
38 if (integrationIntervals <= 0) {
39 integrationIntervals = getNIntegrationIntervals();
40 }
41
42 const auto SACDeltaMedium = getSACDeltaMediumCompressed();
43 const auto SACDeltaHigh = getSACDeltaHighCompressed();
44 for (unsigned int integrationInterval = 0; integrationInterval < integrationIntervals; ++integrationInterval) {
45 std::vector<int32_t> vSACs(GEMSTACKS);
46 std::vector<float> vSACsZero(GEMSTACKS);
47 std::vector<float> vSACsDelta(GEMSTACKS);
48 std::vector<float> vSACsDeltaMedium(GEMSTACKS);
49 std::vector<float> vSACsDeltaHigh(GEMSTACKS);
50 std::vector<unsigned int> vStack(GEMSTACKS);
51 std::vector<int> vSACZeroCut(GEMSTACKS);
52
53 unsigned int index = 0;
54 for (unsigned int stack = 0; stack < GEMSTACKS; ++stack) {
55 vSACs[index] = getSACValue(stack, integrationInterval);
56 vSACsZero[index] = getSACZeroVal(stack);
57 vSACsDelta[index] = getSACDeltaVal(stack, integrationInterval);
58 vSACsDeltaMedium[index] = SACDeltaMedium.getValue(getSide(stack), getSACDeltaIndex(stack, integrationInterval));
59 vSACsDeltaHigh[index] = SACDeltaHigh.getValue(getSide(stack), getSACDeltaIndex(stack, integrationInterval));
60 vSACZeroCut[index] = mOutlierMap[stack];
61 vStack[index++] = stack;
62 }
63 float sacOneA = getSACOneVal(Side::A, integrationInterval);
64 float sacOneC = getSACOneVal(Side::C, integrationInterval);
65
66 pcstream << "tree"
67 << "integrationInterval=" << integrationInterval
68 << "SAC.=" << vSACs
69 << "SAC0.=" << vSACsZero
70 << "SAC1A=" << sacOneA
71 << "SAC1C=" << sacOneC
72 << "SACDeltaNoComp.=" << vSACsDelta
73 << "SACDeltaMediumComp.=" << vSACsDeltaMedium
74 << "SACDeltaHighComp.=" << vSACsDeltaHigh
75 << "stack.=" << vStack
76 << "SACZeroOutlier.=" << vSACZeroCut
77 << "\n";
78 }
79 pcstream.Close();
80}
81
83{
84 const unsigned int nSACsSide = GEMSTACKSPERSIDE;
85 mSACZero.clear();
86 mSACZero.resize(nSACsSide);
87
88#pragma omp parallel for num_threads(sNThreads)
89 for (unsigned int stack = 0; stack < GEMSTACKS; ++stack) {
90 const auto side = getSide(stack);
91 const auto sacZero = std::accumulate(mSACs[stack].begin(), mSACs[stack].end(), 0.f) / mSACs[stack].size();
92 mSACZero.setValueSACZero(sacZero, side, stack % GEMSTACKSPERSIDE);
93 }
94}
95
97{
98 const unsigned int integrationIntervals = getNIntegrationIntervals();
99 mSACOne.clear();
100 mSACOne.resize(integrationIntervals);
101
102#pragma omp parallel for num_threads(sNThreads)
103 for (int iSide = 0; iSide < SIDES; ++iSide) {
104
105 const int firstStack = (iSide == 0) ? 0 : GEMSTACKSPERSIDE;
106 const int lastStack = (iSide == 0) ? GEMSTACKSPERSIDE : GEMSTACKS;
107 const auto normFac = GEMSTACKSPERSIDE - std::accumulate(mOutlierMap.begin() + firstStack, mOutlierMap.begin() + lastStack, 0);
108 const Side side = (iSide == 0) ? Side::A : Side::C;
109 for (unsigned int interval = 0; interval < integrationIntervals; ++interval) {
110
111 float sacOne = 0;
112 for (unsigned int stackLocal = 0; stackLocal < GEMSTACKSPERSIDE; ++stackLocal) {
113 const int stack = stackLocal + iSide * GEMSTACKSPERSIDE;
114 const float sacZero = mSACZero.getValueIDCZero(side, stackLocal);
115 const float sacValue = mSACs[stack][interval];
116 if (mOutlierMap[stack] == 0) {
117 sacOne += (sacZero == 0) ? sacZero : sacValue / sacZero;
118 }
119 }
120
121 mSACOne.setValueIDCOne(sacOne / normFac, side, interval);
122 }
123 }
124}
125
127{
128 const unsigned int integrationIntervals = getNIntegrationIntervals();
129 const unsigned int nSACs = integrationIntervals * GEMSTACKSPERSIDE;
130 mSACDelta.resize(nSACs);
131
132#pragma omp parallel for num_threads(sNThreads)
133 for (unsigned int stack = 0; stack < GEMSTACKS; ++stack) {
134 const Side side = getSide(stack);
135 for (unsigned int interval = 0; interval < integrationIntervals; ++interval) {
136 const auto SACZero = getSACZeroVal(stack);
137 const auto SACOne = mSACOne.getValue(side, interval);
138 const auto sacVal = mSACs[stack][interval];
139 const auto mult = SACZero * SACOne;
140 const auto val = (mult != 0 && (mOutlierMap[stack] == 0)) ? sacVal / mult - 1 : 0;
141 mSACDelta.setSACDelta(side, getSACDeltaIndex(stack, interval), val);
142 }
143 }
144}
145
147{
148 LOGP(info, "Using {} threads for factorization of SACs", sNThreads);
149 LOGP(info, "Calculating SAC0");
150 calcSACZero();
151 LOGP(info, "Creating pad status map");
152 createStatusMap();
153 LOGP(info, "Calculating SAC1");
154 calcSACOne();
155 LOGP(info, "Calculating SACDelta");
156 calcSACDelta();
157}
158
160{
161 for (auto& val : mSACs) {
162 val.clear();
163 }
164}
165
166void o2::tpc::SACFactorization::drawSACDeltaHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const SACDeltaCompression compression, const std::string filename, const float minZ, const float maxZ) const
167{
168 std::function<float(const unsigned int, const unsigned int)> SACFunc;
169
170 const std::string zAxisTitle = SACDrawHelper::getZAxisTitle(SACType::IDCDelta);
171
173 switch (compression) {
174 case SACDeltaCompression::NO:
175 default: {
176 SACFunc = [this, integrationInterval](const unsigned int sector, const unsigned int stack) {
177 return this->getSACDeltaVal(getStack(sector, stack), integrationInterval);
178 };
179 drawFun.mSACFunc = SACFunc;
180 type ? SACDrawHelper::drawSide(drawFun, sector.side(), zAxisTitle, filename, minZ, maxZ) : SACDrawHelper::drawSector(drawFun, sector, zAxisTitle, filename, minZ, maxZ);
181 break;
182 }
183 case SACDeltaCompression::MEDIUM: {
184 const auto SACDeltaMedium = this->getSACDeltaMediumCompressed();
185 SACFunc = [this, &SACDeltaMedium, integrationInterval = integrationInterval](const unsigned int sector, const unsigned int stack) {
186 return SACDeltaMedium.getValue(Sector(sector).side(), getSACDeltaIndex(getStack(sector, stack), integrationInterval));
187 };
188 drawFun.mSACFunc = SACFunc;
189 type ? SACDrawHelper::drawSide(drawFun, sector.side(), zAxisTitle, filename, minZ, maxZ) : SACDrawHelper::drawSector(drawFun, sector, zAxisTitle, filename, minZ, maxZ);
190 break;
191 }
192 case SACDeltaCompression::HIGH: {
193 const auto SACDeltaHigh = this->getSACDeltaHighCompressed();
194 SACFunc = [this, &SACDeltaHigh, integrationInterval](const unsigned int sector, const unsigned int stack) {
195 return SACDeltaHigh.getValue(Sector(sector).side(), getSACDeltaIndex(getStack(sector, stack), integrationInterval));
196 };
197 drawFun.mSACFunc = SACFunc;
198 type ? SACDrawHelper::drawSide(drawFun, sector.side(), zAxisTitle, filename, minZ, maxZ) : SACDrawHelper::drawSector(drawFun, sector, zAxisTitle, filename, minZ, maxZ);
199 break;
200 }
201 }
202}
203
204void o2::tpc::SACFactorization::drawSACZeroHelper(const bool type, const Sector sector, const std::string filename, const float minZ, const float maxZ) const
205{
206 std::function<float(const unsigned int, const unsigned int)> SACFunc = [this](const unsigned int sector, const unsigned int stack) {
207 return this->getSACZeroVal(getStack(sector, stack));
208 };
209
210 SACDrawHelper::SACDraw drawFun;
211 drawFun.mSACFunc = SACFunc;
212 const std::string zAxisTitle = SACDrawHelper::getZAxisTitle(SACType::IDCZero);
213 type ? SACDrawHelper::drawSide(drawFun, sector.side(), zAxisTitle, filename, minZ, maxZ) : SACDrawHelper::drawSector(drawFun, sector, zAxisTitle, filename, minZ, maxZ);
214}
215
216void o2::tpc::SACFactorization::drawSACZeroOutlierHelper(const bool type, const Sector sector, const std::string filename, const float minZ, const float maxZ) const
217{
218 std::function<float(const unsigned int, const unsigned int)> SACFunc = [this](const unsigned int sector, const unsigned int stack) {
219 return this->mOutlierMap[getStack(sector, stack)];
220 };
221
222 SACDrawHelper::SACDraw drawFun;
223 drawFun.mSACFunc = SACFunc;
224 const std::string zAxisTitle = SACDrawHelper::getZAxisTitle(SACType::IDCZero) + " outlier";
225 type ? SACDrawHelper::drawSide(drawFun, sector.side(), zAxisTitle, filename, minZ, maxZ) : SACDrawHelper::drawSector(drawFun, sector, zAxisTitle, filename, minZ, maxZ);
226}
227
228void o2::tpc::SACFactorization::drawSACHelper(const bool type, const Sector sector, const unsigned int integrationInterval, const std::string filename, const float minZ, const float maxZ) const
229{
230 std::function<float(const unsigned int, const unsigned int)> SACFunc = [this, integrationInterval](const unsigned int sector, const unsigned int stack) {
231 return this->getSACValue(getStack(sector, stack), integrationInterval);
232 };
233
234 SACDrawHelper::SACDraw drawFun;
235 drawFun.mSACFunc = SACFunc;
236
237 const std::string zAxisTitle = SACDrawHelper::getZAxisTitle(SACType::IDC);
238 type ? SACDrawHelper::drawSide(drawFun, sector.side(), zAxisTitle, filename, minZ, maxZ) : SACDrawHelper::drawSector(drawFun, sector, zAxisTitle, filename, minZ, maxZ);
239}
240
242{
243 const auto& paramSAC = ParameterSAC::Instance();
244#pragma omp parallel for num_threads(sNThreads)
245 for (unsigned int stackInSector = 0; stackInSector < GEMSTACKSPERSECTOR; ++stackInSector) {
247 for (int iSide = 0; iSide < SIDES; ++iSide) {
248 const Side side = (iSide == 0) ? Side::A : Side::C;
249 for (int iter = 0; iter < 2; ++iter) {
250 const float median = (iter == 1) ? average.getMedian() : 0;
251 const float stdDev = (iter == 1) ? average.getStdDev() : 0;
252 for (int sector = 0; sector < SECTORSPERSIDE; ++sector) {
253 const int stackLocal = sector * GEMSTACKSPERSECTOR + stackInSector;
254 const float sacZero = mSACZero.getValueIDCZero(side, stackLocal);
255 if (iter == 0) {
256 average.addValue(sacZero);
257 } else {
258 // define outlier
259 const int stack = stackLocal + iSide * GEMSTACKSPERSIDE;
260 if ((sacZero > median + stdDev * paramSAC.maxSAC0Median) || (sacZero < median - stdDev * paramSAC.minSAC0Median)) {
261 mOutlierMap[stack] = 1;
262 } else {
263 mOutlierMap[stack] = 0;
264 }
265 }
266 }
267 }
268 average.clear();
269 }
270 }
271}
uint32_t side
Definition RawData.h:0
uint32_t stack
Definition RawData.h:1
class for performing robust averaging and outlier filtering
helper class for drawing SACs per sector/side
TPC factorization of SACs.
Definition of the parameters for the SAC processing.
void addValue(const float value, const float weight=1)
void clear()
clear the stored values
static std::string getZAxisTitle(const SACType type)
static void drawSide(const SACDraw &SAC, const o2::tpc::Side side, const std::string zAxisTitle, const std::string filename, const float minZ=0, const float maxZ=-1)
void reset()
resetting aggregated SACs
void dumpToTree(int intervals=-1, const char *outFileName="SACTree.root") const
void calcSACDelta()
calculate \Delta I(r,\phi,t) = I(r,\phi,t) / ( I_0(r,\phi) * I_1(t) )
void createStatusMap()
create outlier map using the SAC0
void calcSACOne()
calculate I_1(t) = <I(r,\phi,t) / I_0(r,\phi)>_{r,\phi}
void calcSACZero()
calculate I_0(r,\phi) = <I(r,\phi,t)>_t
void dumpToFile(const char *outFileName="SACFactorized.root", const char *outName="SACFactorized") const
GLuint GLuint end
Definition glcorearb.h:469
GLuint index
Definition glcorearb.h:781
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLfloat * val
Definition glcorearb.h:1582
GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat maxZ
Definition glcorearb.h:2910
GLfloat GLfloat minZ
Definition glcorearb.h:2910
constexpr unsigned char SECTORSPERSIDE
Definition Defs.h:40
@ IDC
integrated and grouped IDCs
@ IDCZero
IDC0: I_0(r,\phi) = <I(r,\phi,t)>_t.
@ IDCDelta
IDCDelta: \Delta I(r,\phi,t) = I(r,\phi,t) / ( I_0(r,\phi) * I_1(t) )
constexpr unsigned short GEMSTACKS
Definition Defs.h:60
Enum< T >::Iterator begin(Enum< T >)
Definition Defs.h:173
constexpr unsigned char SIDES
Definition Defs.h:41
Side
TPC readout sidE.
Definition Defs.h:35
@ A
Definition Defs.h:35
@ C
Definition Defs.h:36
constexpr unsigned short GEMSTACKSPERSECTOR
Definition Defs.h:57
constexpr unsigned short GEMSTACKSPERSIDE
Definition Defs.h:59
std::string filename()
std::function< float(const unsigned int, const unsigned int)> mSACFunc
function returning the value which will be drawn for sector, stack
float getValue(const Side side, const int interval) const