Project
Loading...
Searching...
No Matches
CalibdEdxCorrection.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
13
14#include <algorithm>
15#include <string_view>
16
17#ifndef GPUCA_STANDALONE
18// o2 includes
19#include "Framework/Logger.h"
20#include "DataFormatsTPC/Defs.h"
22
23// root includes
24#include "TFile.h"
25#endif
26
27using namespace o2::tpc;
28
29void CalibdEdxCorrection::clear()
30{
31 for (auto& row : mParams) {
32 for (auto& x : row) {
33 x = 0.f;
34 }
35 }
36 for (auto& x : mChi2) {
37 x = 0.f;
38 }
39 mDims = -1;
40}
41
42#ifndef GPUCA_STANDALONE
43
44void CalibdEdxCorrection::writeToFile(std::string_view fileName, std::string_view objName) const
45{
46 std::unique_ptr<TFile> file(TFile::Open(fileName.data(), "recreate"));
47 if (!file) {
48 LOGP(error, "Failed to open file {} for writing", fileName.data());
49 return;
50 }
51
52 file->WriteObject(this, objName.data());
53}
54
55void CalibdEdxCorrection::loadFromFile(std::string_view fileName, std::string_view objName)
56{
57 std::unique_ptr<TFile> file(TFile::Open(fileName.data()));
58 if (!file || file->IsZombie()) {
59 LOGP(error, "Failed to open file {}", fileName.data());
60 return;
61 }
62
63 auto tmp = file->Get<CalibdEdxCorrection>(objName.data());
64 if (tmp != nullptr) {
65 *this = *tmp;
66 } else {
67 LOGP(error, "Failed to load object with name {} from file {}", objName.data(), fileName.data());
68 }
69}
70
71void CalibdEdxCorrection::dumpToTree(const char* outFileName) const
72{
73 o2::utils::TreeStreamRedirector pcstream(outFileName, "RECREATE");
74 pcstream.GetFile()->cd();
75
76 for (int sector = 0; sector < 2 * SECTORSPERSIDE; ++sector) {
77 for (int roc = 0; roc < GEMSTACKSPERSECTOR; ++roc) {
79 sector,
80 static_cast<tpc::GEMstack>(roc)};
81
82 std::vector<float> qMaxCorrOut;
83 std::vector<float> qTotCorrOut;
84 std::vector<float> tglOut;
85 std::vector<float> snpOut;
86
87 for (float tgl = 0; tgl < 2; tgl += 0.01) {
88 for (float snp = 0; snp < 1; snp += 0.1) {
89 qMaxCorrOut.emplace_back(getCorrection(stack, ChargeType::Max, tgl, snp));
90 qTotCorrOut.emplace_back(getCorrection(stack, ChargeType::Tot, tgl, snp));
91 tglOut.emplace_back(tgl);
92 snpOut.emplace_back(snp);
93 }
94 }
95
96 pcstream << "tree"
97 << "qMaxCorr=" << qMaxCorrOut
98 << "qTotCorr=" << qTotCorrOut
99 << "tgl=" << tglOut
100 << "snp=" << snpOut
101 << "roc=" << roc
102 << "sector=" << sector
103 << "\n";
104 }
105 }
106}
107
108const std::array<float, CalibdEdxCorrection::ParamSize> CalibdEdxCorrection::getMeanParams(ChargeType charge) const
109{
110 std::array<float, ParamSize> params{};
111
112 for (int index = 0; index < FitSize / 2; ++index) {
113 std::transform(params.begin(), params.end(), mParams[index + charge * FitSize / 2], params.begin(), std::plus<>());
114 }
115 std::for_each(params.begin(), params.end(), [](auto& val) { val /= (0.5f * FitSize); });
116 return params;
117}
118
119const std::array<float, CalibdEdxCorrection::ParamSize> CalibdEdxCorrection::getMeanParams(const GEMstack stack, ChargeType charge) const
120{
121 std::array<float, ParamSize> params{};
122
123 for (int index = 0; index < SECTORSPERSIDE * SIDES; ++index) {
124 std::transform(params.begin(), params.end(), getParams(StackID{index, stack}, charge), params.begin(), std::plus<>());
125 }
126 std::for_each(params.begin(), params.end(), [](auto& val) { val /= (SECTORSPERSIDE * SIDES); });
127 return params;
128}
129
131{
132 if (param >= ParamSize) {
133 return 0.f;
134 }
135 float mean{};
136 for (int index = 0; index < FitSize / 2; ++index) {
137 mean += mParams[index + charge * FitSize / 2][param];
138 }
139
140 return mean / (0.5f * FitSize);
141}
142
144{
145 if (param >= ParamSize) {
146 return 0.f;
147 }
148 float mean{};
149 for (int index = 0; index < SECTORSPERSIDE * SIDES; ++index) {
150 mean += getParams(StackID{index, stack}, charge)[param];
151 }
152
153 return mean / (SECTORSPERSIDE * SIDES);
154}
155
157{
158 float mean{};
159 for (int index = 0; index < FitSize / 2; ++index) {
160 mean += mEntries[index + charge * FitSize / 2];
161 }
162
163 return mean / (0.5f * FitSize);
164}
165
167{
168 float mean{};
169 for (int index = 0; index < SECTORSPERSIDE * SIDES; ++index) {
170 mean += getEntries(StackID{index, stack}, charge);
171 }
172
173 return mean / (SECTORSPERSIDE * SIDES);
174}
175
177{
178 for (int i = 0; i < FitSize; ++i) {
179 for (int j = 0; j < ParamSize; ++j) {
180 mParams[i][j] = 0.f;
181 }
182 mParams[i][0] = 1.f; // constant term = 1
183 mChi2[i] = 0.f;
184 mEntries[i] = 0;
185 }
186 mDims = 0;
187}
188
189#endif // GPUCA_STANDALONE
int16_t charge
Definition RawEventData.h:5
int32_t i
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
char error[CURL_ERROR_SIZE]
uint32_t roc
Definition RawData.h:3
uint32_t j
Definition RawData.h:0
uint32_t stack
Definition RawData.h:1
void dumpToTree(const char *outFileName="calib_dedx.root") const
const std::array< float, ParamSize > getMeanParams(ChargeType charge) const
Parameters averaged over all stacks.
void writeToFile(std::string_view fileName, std::string_view objName="ccdb_object") const
void loadFromFile(std::string_view fileName, std::string_view objName="ccdb_object")
float getMeanParam(ChargeType charge, uint32_t param) const
Single fit parameters averaged over all sectors for a stack type.
void setUnity()
set all corrections to 1, used for default initialization and to reset corrections
float getMeanEntries(ChargeType charge) const
Single fit parameters averaged over all sectors for a stack type.
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint index
Definition glcorearb.h:781
GLenum const GLfloat * params
Definition glcorearb.h:272
GLuint GLfloat * val
Definition glcorearb.h:1582
GLenum GLfloat param
Definition glcorearb.h:271
Global TPC definitions and constants.
GEMstack
TPC GEM stack types.
Definition Defs.h:55
ChargeType
Definition Defs.h:72
@ Tot
Definition Defs.h:74
@ Max
Definition Defs.h:73
GEM stack identification.
Definition Defs.h:79
std::vector< int > row