forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalibdEdxCorrection.cxx
More file actions
183 lines (155 loc) · 5.22 KB
/
CalibdEdxCorrection.cxx
File metadata and controls
183 lines (155 loc) · 5.22 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
// 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.
#include "DataFormatsTPC/CalibdEdxCorrection.h"
#include <algorithm>
#include <string_view>
// o2 includes
#include "Framework/Logger.h"
#include "DataFormatsTPC/Defs.h"
#include "CommonUtils/TreeStreamRedirector.h"
// root includes
#include "TFile.h"
using namespace o2::tpc;
void CalibdEdxCorrection::clear()
{
for (auto& row : mParams) {
for (auto& x : row) {
x = 0.f;
}
}
for (auto& x : mChi2) {
x = 0.f;
}
mDims = -1;
}
void CalibdEdxCorrection::writeToFile(std::string_view fileName, std::string_view objName) const
{
std::unique_ptr<TFile> file(TFile::Open(fileName.data(), "recreate"));
if (!file) {
LOGP(error, "Failed to open file {} for writing", fileName.data());
return;
}
file->WriteObject(this, objName.data());
}
void CalibdEdxCorrection::loadFromFile(std::string_view fileName, std::string_view objName)
{
std::unique_ptr<TFile> file(TFile::Open(fileName.data()));
if (!file || file->IsZombie()) {
LOGP(error, "Failed to open file {}", fileName.data());
return;
}
auto tmp = file->Get<CalibdEdxCorrection>(objName.data());
if (tmp != nullptr) {
*this = *tmp;
} else {
LOGP(error, "Failed to load object with name {} from file {}", objName.data(), fileName.data());
}
}
void CalibdEdxCorrection::dumpToTree(const char* outFileName) const
{
o2::utils::TreeStreamRedirector pcstream(outFileName, "RECREATE");
pcstream.GetFile()->cd();
for (int sector = 0; sector < 2 * SECTORSPERSIDE; ++sector) {
for (int roc = 0; roc < GEMSTACKSPERSECTOR; ++roc) {
tpc::StackID stack{
sector,
static_cast<tpc::GEMstack>(roc)};
std::vector<float> qMaxCorrOut;
std::vector<float> qTotCorrOut;
std::vector<float> tglOut;
std::vector<float> snpOut;
for (float tgl = 0; tgl < 2; tgl += 0.01) {
for (float snp = 0; snp < 1; snp += 0.1) {
qMaxCorrOut.emplace_back(getCorrection(stack, ChargeType::Max, tgl, snp));
qTotCorrOut.emplace_back(getCorrection(stack, ChargeType::Tot, tgl, snp));
tglOut.emplace_back(tgl);
snpOut.emplace_back(snp);
}
}
pcstream << "tree"
<< "qMaxCorr=" << qMaxCorrOut
<< "qTotCorr=" << qTotCorrOut
<< "tgl=" << tglOut
<< "snp=" << snpOut
<< "roc=" << roc
<< "sector=" << sector
<< "\n";
}
}
}
const std::array<float, CalibdEdxCorrection::ParamSize> CalibdEdxCorrection::getMeanParams(ChargeType charge) const
{
std::array<float, ParamSize> params{};
for (int index = 0; index < FitSize / 2; ++index) {
std::transform(params.begin(), params.end(), mParams[index + charge * FitSize / 2], params.begin(), std::plus<>());
}
std::for_each(params.begin(), params.end(), [](auto& val) { val /= (0.5f * FitSize); });
return params;
}
const std::array<float, CalibdEdxCorrection::ParamSize> CalibdEdxCorrection::getMeanParams(const GEMstack stack, ChargeType charge) const
{
std::array<float, ParamSize> params{};
for (int index = 0; index < SECTORSPERSIDE * SIDES; ++index) {
std::transform(params.begin(), params.end(), getParams(StackID{index, stack}, charge), params.begin(), std::plus<>());
}
std::for_each(params.begin(), params.end(), [](auto& val) { val /= (SECTORSPERSIDE * SIDES); });
return params;
}
float CalibdEdxCorrection::getMeanParam(ChargeType charge, uint32_t param) const
{
if (param >= ParamSize) {
return 0.f;
}
float mean{};
for (int index = 0; index < FitSize / 2; ++index) {
mean += mParams[index + charge * FitSize / 2][param];
}
return mean / (0.5f * FitSize);
}
float CalibdEdxCorrection::getMeanParam(const GEMstack stack, ChargeType charge, uint32_t param) const
{
if (param >= ParamSize) {
return 0.f;
}
float mean{};
for (int index = 0; index < SECTORSPERSIDE * SIDES; ++index) {
mean += getParams(StackID{index, stack}, charge)[param];
}
return mean / (SECTORSPERSIDE * SIDES);
}
float CalibdEdxCorrection::getMeanEntries(ChargeType charge) const
{
float mean{};
for (int index = 0; index < FitSize / 2; ++index) {
mean += mEntries[index + charge * FitSize / 2];
}
return mean / (0.5f * FitSize);
}
float CalibdEdxCorrection::getMeanEntries(const GEMstack stack, ChargeType charge) const
{
float mean{};
for (int index = 0; index < SECTORSPERSIDE * SIDES; ++index) {
mean += getEntries(StackID{index, stack}, charge);
}
return mean / (SECTORSPERSIDE * SIDES);
}
void CalibdEdxCorrection::setUnity()
{
for (int i = 0; i < FitSize; ++i) {
for (int j = 0; j < ParamSize; ++j) {
mParams[i][j] = 0.f;
}
mParams[i][0] = 1.f; // constant term = 1
mChi2[i] = 0.f;
mEntries[i] = 0;
}
mDims = 0;
}