Project
Loading...
Searching...
No Matches
IonTailCorrection.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
17#include <cmath>
18#include <vector>
19#include <algorithm>
20#include <filesystem>
21
22#include "TPCBase/Utils.h"
23#include "TPCBase/CRU.h"
26
27using namespace o2::tpc;
28
30{
31 const auto& settings = IonTailSettings::Instance();
32 mKTime = settings.kTime;
33 mITMultFactor = settings.ITMultFactor;
34 LOGP(info, "IT settings: kTime = {}, ITMultFactor = {}, padITCorrFile = {}",
35 settings.kTime, settings.ITMultFactor, settings.padITCorrFile);
36
37 if (!settings.padITCorrFile.empty()) {
38 loadITPadValuesFromFile(settings.padITCorrFile);
39 }
40}
41
43{
44 using Streamer = o2::utils::DebugStreamer;
45
46 if (digits.size() == 0) {
47 return;
48 }
49
50 // make sure we process the digits pad-by-pad in increasing time order
52
53 int lastRow = -1;
54 int lastPad = -1;
55 int lastTime = digits.front().getTimeStamp();
56 float cumul = 0;
57
58 // default IT parameters are replaced below,
59 // in case pad-by-pad values were set up
60 float kAmp = std::abs(mITMultFactor) * 0.1276;
61 if (mITMultFactor < 0) {
62 kAmp = kAmp / (1 + kAmp);
63 }
64
65 float kTime = mKTime;
66 float tailSlopeUnit = std::exp(-kTime);
67
68 for (auto& digit : digits) {
69 const auto sector = CRU(digit.getCRU()).sector();
70 const auto row = digit.getRow();
71 const auto pad = digit.getPad();
72 const auto time = digit.getTimeStamp();
73
74 if (mFraction) {
75 kAmp = mFraction->getValue(sector, row, pad) * std::abs(mITMultFactor);
76 if (mITMultFactor < 0) {
77 kAmp = kAmp / (1 + kAmp);
78 }
79 }
80 if (mExpLambda) {
81 tailSlopeUnit = mExpLambda->getValue(sector, row, pad);
82 kTime = -std::log(tailSlopeUnit);
83 }
84
85 // reset charge cumulation if pad has changed
86 if (row != lastRow || pad != lastPad) {
87 cumul = 0;
88 lastTime = time;
89 }
90
91 // cumulate charge also over missing time stamps
92 while (lastTime + 1 < time) {
93 auto origCuml = cumul;
94 cumul *= tailSlopeUnit;
95
96 if (Streamer::checkStream(o2::utils::StreamFlags::streamITCorr)) {
97 streamData(digit.getCRU(), row, pad, time, lastTime, kAmp, kTime, tailSlopeUnit, origCuml, cumul, 0, 0);
98 }
99
100 ++lastTime;
101
102 if (cumul < 0.1) {
103 cumul = 0;
104 break;
105 }
106 }
107
108 const auto origCharge = digit.getChargeFloat();
109 const auto charge = origCharge + mSign * kAmp * (1 - tailSlopeUnit) * cumul;
110 digit.setCharge(charge);
111
112 const auto origCuml = cumul;
113 cumul += origCharge;
114 cumul *= tailSlopeUnit;
115
116 if (Streamer::checkStream(o2::utils::StreamFlags::streamITCorr)) {
117 streamData(digit.getCRU(), row, pad, time, lastTime, kAmp, kTime, tailSlopeUnit, origCuml, cumul, origCharge, charge);
118 }
119
120 lastRow = row;
121 lastPad = pad;
122 lastTime = time;
123 }
124
125 // sort back
127}
128
130{
131 // sort digits
132 std::sort(digits.begin(), digits.end(), [](const auto& a, const auto& b) {
133 if (a.getRow() < b.getRow()) {
134 return true;
135 }
136 if (a.getRow() == b.getRow()) {
137 if (a.getPad() < b.getPad()) {
138 return true;
139 } else if (a.getPad() == b.getPad()) {
140 return a.getTimeStamp() < b.getTimeStamp();
141 }
142 }
143 return false;
144 });
145}
146
148{
149 // sort digits
150 std::sort(digits.begin(), digits.end(), [](const auto& a, const auto& b) {
151 if (a.getTimeStamp() < b.getTimeStamp()) {
152 return true;
153 }
154 if (a.getTimeStamp() == b.getTimeStamp()) {
155 if (a.getRow() < b.getRow()) {
156 return true;
157 } else if (a.getRow() == b.getRow()) {
158 return a.getPad() < b.getPad();
159 }
160 }
161 return false;
162 });
163}
164
165void IonTailCorrection::loadITPadValuesFromFile(std::string_view itParamFile)
166{
167 if (!std::filesystem::exists(itParamFile)) {
168 LOGP(fatal, "Could not find IF param file {}", itParamFile);
169 }
170
171 auto calDets = utils::readCalPads(itParamFile, "fraction,expLambda");
172 if (!calDets[0]) {
173 LOGP(fatal, "Could not read IT fraction object from file {}", itParamFile);
174 }
175 if (!calDets[1]) {
176 LOGP(fatal, "Could not read IT expLambda object from file {}", itParamFile);
177 }
178
179 mFraction.reset(calDets[0]);
180 mExpLambda.reset(calDets[1]);
181
182 LOGP(info, "Loaded ion tail correction values from file {}", itParamFile);
183}
184
185void IonTailCorrection::streamData(int cru, int row, int pad, int time, int lastTime, float kAmp, float kTime, float tailSlopeUnit, float origCumul, float cumul, float origCharge, float charge)
186{
187 mStreamer.setStreamer("debug_ITCorr", "UPDATE");
188
189 mStreamer.getStreamer()
190 << "itCorr"
191 << "cru=" << cru
192 << "row=" << row
193 << "pad=" << pad
194 << "time=" << lastTime
195
196 << "kAmp=" << kAmp
197 << "kTime=" << kTime
198 << "tailSlopeUnit=" << tailSlopeUnit
199 << "itMultFactor=" << mITMultFactor
200
201 << "origCharge=" << origCharge
202 << "charge=" << charge
203 << "\n";
204}
int16_t charge
Definition RawEventData.h:5
int16_t time
Definition RawEventData.h:4
int32_t lastTime
int32_t lastRow
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
configStandalone Reconstruction settings
Implementation of the ion tail correction from TPC digits.
const Sector sector() const
Definition CRU.h:65
static void sortDigitsOneSectorPerTimeBin(std::vector< Digit > &digits)
void streamData(int cru, int row, int pad, int time, int lastTime, float kAmp, float kTime, float tailSlopeUnit, float origCumul, float cumul, float origCharge, float charge)
void filterDigitsDirect(std::vector< Digit > &digits)
static void sortDigitsOneSectorPerPad(std::vector< Digit > &digits)
Sort digits of a single sector per pad in increasing time bin order.
void loadITPadValuesFromFile(std::string_view itParamFile)
class to enable streaming debug information to root files
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
std::vector< CalPad * > readCalPads(const std::string_view fileName, const std::vector< std::string > &calPadNames)
Definition Utils.cxx:190
Global TPC definitions and constants.
@ streamITCorr
stream ion tail correction information
std::vector< Digit > digits
std::vector< int > row