Project
Loading...
Searching...
No Matches
CorrectdEdxDistortions.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
16
18#include "TPCFastTransform.h"
20
22
24
25void o2::tpc::CorrectdEdxDistortions::setStreamer(const char* debugRootFile)
26{
27 mStreamer = std::make_unique<o2::utils::TreeStreamRedirector>(debugRootFile, "recreate");
28};
29
30void o2::tpc::CorrectdEdxDistortions::setSCCorrFromFile(const char* scAvgFile, const char* scDerFile, const float lumi)
31{
32 auto avg = o2::gpu::TPCFastTransform::loadFromFile(scAvgFile, "ccdb_object");
33 auto der = o2::gpu::TPCFastTransform::loadFromFile(scDerFile, "ccdb_object");
34 if (!avg || !der) {
35 LOGP(warn, "Couldnt load all sc correction objects from local file");
36 return;
37 }
38 avg->rectifyAfterReadingFromFile();
39 der->rectifyAfterReadingFromFile();
40 setCorrectionMaps(avg, der, lumi);
41}
42
44{
45 if (!avg || !der) {
46 LOGP(warn, "Nullptr detected in setting the correction maps");
47 return;
48 }
49 mCorrAvg = std::unique_ptr<o2::gpu::TPCFastTransform>(new o2::gpu::TPCFastTransform);
50 mCorrAvg->cloneFromObject(*avg, nullptr);
51 mCorrAvg->rectifyAfterReadingFromFile();
52
53 mCorrDer = std::unique_ptr<o2::gpu::TPCFastTransform>(new o2::gpu::TPCFastTransform);
54 mCorrDer->cloneFromObject(*der, nullptr);
55 mCorrDer->rectifyAfterReadingFromFile();
56
57 mCorrAvg->setApplyCorrectionOn();
58 mCorrDer->setApplyCorrectionOn();
59}
60
62{
63 setCorrectionMaps(avg, der);
64 setLumi(lumi);
65}
66
68{
69 if (!mCorrAvg || !mCorrDer) {
70 LOGP(warn, "Nullptr detected in accessing the correction maps");
71 return;
72 }
73 const float lumiAvg = mCorrAvg->getLumi();
74 const float lumiDer = mCorrDer->getLumi();
75 mScaleDer = (lumi - lumiAvg) / lumiDer;
76 LOGP(info, "Setting mScaleDer: {} for inst lumi: {} avg lumi: {} deriv. lumi: {}", mScaleDer, lumi, lumiAvg, lumiDer);
77}
78
79float o2::tpc::CorrectdEdxDistortions::getCorrection(const float time, unsigned char sector, unsigned char padrow, int pad) const
80{
81 //
82 // Get the corrections at the previous and next padrow and interpolate them to the start and end position of current pad
83 // Calculate from corrected position the radial distortions and compare the effective length of distorted electrons with pad length
84 //
85
86 // localY of current pad
87 const float ly = mTPCGeometry.LinearPad2Y(sector, padrow, pad);
88
89 // get correction at "pad + 0.5*padlength" pos1 and dont extrapolate/interpolate across GEM gaps
90 const int row1 = ((padrow == mTPCGeometry.EndIROC() - 1) || (padrow == mTPCGeometry.EndOROC1() - 1) || (padrow == mTPCGeometry.EndOROC2() - 1)) ? padrow : std::clamp(padrow + 1, 0, GPUCA_ROW_COUNT - 1);
91
92 float lxT_1 = 0;
93 float lyT_1 = 0;
94 float lzT_1 = 0;
95 mCorrAvg->Transform(sector, row1, pad, time, lxT_1, lyT_1, lzT_1, 0, mCorrDer.get(), nullptr, mScaleDer, 0, 1);
96
97 // correct for different localY position of pads
98 lyT_1 += ly - mTPCGeometry.LinearPad2Y(sector, row1, pad);
99
100 // get radius of upper pad
101 const float r_1_f = std::sqrt(lxT_1 * lxT_1 + lyT_1 * lyT_1);
102
103 // get correction at "pad - 0.5*padlength" pos0 and dont extrapolate/interpolate across GEM gaps
104 const int row0 = ((padrow == mTPCGeometry.EndIROC()) || (padrow == mTPCGeometry.EndOROC1()) || (padrow == mTPCGeometry.EndOROC2())) ? padrow : std::clamp(padrow - 1, 0, GPUCA_ROW_COUNT - 1);
105
106 // check if previous pad row has enough pads
107 const unsigned char pad0 = std::clamp(static_cast<int>(pad), 0, mTPCGeometry.NPads(row0) - 1);
108 float lxT_0 = 0;
109 float lyT_0 = 0;
110 float lzT_0 = 0;
111 mCorrAvg->Transform(sector, row0, pad0, time, lxT_0, lyT_0, lzT_0, 0, mCorrDer.get(), nullptr, mScaleDer, 0, 1);
112
113 // correct for different localY position of pads
114 lyT_0 += ly - mTPCGeometry.LinearPad2Y(sector, row0, pad0);
115
116 // get radius of lower pad
117 const float r_0_f = std::sqrt(lxT_0 * lxT_0 + lyT_0 * lyT_0);
118
119 // effective radial length of electrons
120 const float dr_f = r_1_f - r_0_f;
121
122 // position of upper and lower pad edge
123 const float x_0 = padrow - 0.5;
124 const float x_1 = padrow + 0.5;
125
126 // interpolate corrections to upper and lower pad edge
127 const int deltaRow = (row1 - row0);
128 const float d_StartPad = (r_0_f * (row1 - x_0) + r_1_f * (x_0 - row0)) / deltaRow;
129 const float d_EndPad = (r_0_f * (row1 - x_1) + r_1_f * (x_1 - row0)) / deltaRow;
130 const float scCorr = (d_EndPad - d_StartPad) / mTPCGeometry.PadHeight(padrow);
131
132 // check if corrected position is still reasonable
133 const bool isOk = ((lxT_1 < mLX0Min) || (lxT_0 < mLX1Min) || (scCorr < mScCorrMin) || (scCorr > mScCorrMax)) ? false : true;
134
135 // store debug informations
136 if (mStreamer) {
137 const float lx = mTPCGeometry.Row2X(padrow);
138
139 // original correction
140 float lxT = 0;
141 float lyT = 0;
142 float lzT = 0;
143 mCorrAvg->Transform(sector, padrow, pad, time, lxT, lyT, lzT, 0, mCorrDer.get(), nullptr, mScaleDer, 0, 1);
144
145 (*mStreamer) << "tree"
146 << "sector=" << sector
147 << "padrow=" << padrow
148 << "row0=" << row0
149 << "row1=" << row1
150 << "pad0=" << pad0
151 << "pad=" << pad
152 << "time=" << time
153 << "lx=" << lx
154 << "lxT=" << lxT
155 << "lyT=" << lyT
156 << "lzT=" << lzT
157 << "lxT_0=" << lxT_0
158 << "lxT_1=" << lxT_1
159 << "ly=" << ly
160 << "lyT_0=" << lyT_0
161 << "lyT_1=" << lyT_1
162 << "lzT_0=" << lzT_0
163 << "lzT_1=" << lzT_1
164 << "d_StartPad=" << d_StartPad
165 << "d_EndPad=" << d_EndPad
166 << "r_0_f=" << r_0_f
167 << "r_1_f=" << r_1_f
168 << "scCorr=" << scCorr
169 << "isOk=" << isOk
170 << "\n";
171 }
172
173 return isOk ? scCorr : 1;
174}
int16_t time
Definition RawEventData.h:4
#define GPUCA_ROW_COUNT
uint32_t padrow
Definition RawData.h:5
Definition of TPCFastTransform class.
static TPCFastTransform * loadFromFile(std::string inpFName="", std::string name="")
float getCorrection(const float time, unsigned char sector, unsigned char padrow, int pad) const
void setCorrectionMaps(o2::gpu::TPCFastTransform *avg, o2::gpu::TPCFastTransform *der, const float lumi)
void setSCCorrFromFile(const char *scAvgFile, const char *scDerFile, const float lumi=-1)
~CorrectdEdxDistortions()
Default destructor.
void setStreamer(const char *debugRootFile="debug_sc_corrections.root")
enable the debug streamer
CorrectdEdxDistortions()
Default constructor.
LumiInfo lumi