Project
Loading...
Searching...
No Matches
PHOSL1phaseCalibrator.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
15#include "CCDB/CcdbApi.h"
16#include "CCDB/CcdbObjectInfo.h"
19#include "PHOSBase/Geometry.h"
20
21#include "FairLogger.h"
22
23using namespace o2::phos;
24
26
28{
29 for (int d = mDDL; d--;) {
30 for (int b = 4; b--;) {
31 mMean[d][b] = 0.;
32 mRMS[d][b] = 0;
33 }
34 mNorm[d] = 0.;
35 }
36 for (int bc = 0; bc < 4; ++bc) {
37 mQcHisto[bc].fill(0);
38 }
39}
41{
42 mRunStartTime = other.mRunStartTime;
43 mBadMap = nullptr;
44}
46{
47 LOG(info) << "Collected statistics per ddl: " << mNorm[1] << " " << mNorm[2] << " " << mNorm[3] << " " << mNorm[4] << " " << mNorm[5] << " " << mNorm[6] << " " << mNorm[7] << " " << mNorm[8] << " " << mNorm[9] << " " << mNorm[10] << " " << mNorm[11] << " " << mNorm[12] << " " << mNorm[13];
48}
49
50void PHOSL1phaseSlot::fill(const gsl::span<const Cell>& cells, const gsl::span<const TriggerRecord>& trs)
51{
52 if (!mBadMap) {
53 LOG(info) << "Retrieving BadMap from CCDB";
54 auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance();
55 ccdbManager.setURL(o2::base::NameConf::getCCDBServer());
56 LOG(info) << " set-up CCDB " << o2::base::NameConf::getCCDBServer();
57 mBadMap = ccdbManager.get<o2::phos::BadChannelsMap>("PHS/Calib/BadMap");
58 LOG(info) << "Retrieving Calibration from CCDB";
59 mCalibParams = ccdbManager.get<o2::phos::CalibParams>("PHS/Calib/CalibParams");
60 }
61
62 for (auto& tr : trs) {
63
64 int firstCellInEvent = tr.getFirstEntry();
65 int lastCellInEvent = firstCellInEvent + tr.getNumberOfObjects();
66
67 for (int i = firstCellInEvent; i < lastCellInEvent; i++) {
68 const Cell& c = cells[i];
69
70 if (c.getTRU()) {
71 continue;
72 }
73 short absId = c.getAbsId();
74 if (!mBadMap->isChannelGood(absId)) {
75 continue;
76 }
77
78 float e = 0., t = 0.;
79 if (c.getHighGain()) {
80 e = c.getEnergy() * mCalibParams->getGain(absId);
81 t = c.getTime() - mCalibParams->getHGTimeCalib(absId);
82 } else {
83 e = c.getEnergy() * mCalibParams->getGain(absId) * mCalibParams->getHGLGRatio(absId);
84 t = c.getTime() - mCalibParams->getLGTimeCalib(absId);
85 }
86 if (e > mEmin && t > mTimeMin && t < mTimeMax) {
87 char relid[3];
89 int ddl = (relid[0] - 1) * 4 + (relid[1] - 1) / 16 - 2;
90 for (int b = 0; b < 4; b++) {
91 int timeshift = tr.getBCData().bc % 4 - b;
92 if (timeshift < 0) {
93 timeshift += 4;
94 }
95 float tcorr = t - timeshift * 25e-9;
96 mMean[ddl][b] += tcorr;
97 mRMS[ddl][b] += tcorr * tcorr;
98 int it = (tcorr + 200.e-9) / 4.e-9;
99 if (it >= 0 && it < 100) {
100 mQcHisto[b][ddl * 100 + it]++;
101 }
102 }
103 mNorm[ddl] += 1.;
104 }
105 }
106 }
107}
108void PHOSL1phaseSlot::addMeanRms(std::array<std::array<float, 4>, 14>& sumMean,
109 std::array<std::array<float, 4>, 14>& sumRMS,
110 std::array<float, 14>& sumNorm)
111{
112 for (int d = mDDL; d--;) {
113 for (int b = 4; b--;) {
114 sumMean[d][b] += mMean[d][b];
115 sumRMS[d][b] += mRMS[d][b];
116 }
117 sumNorm[d] += mNorm[d];
118 }
119}
120void PHOSL1phaseSlot::addQcHistos(std::array<unsigned int, 1400> (&sum)[5])
121{
122 for (int bc = 4; bc--;) {
123 for (int it = 1400; it--;) {
124 sum[bc][it] += mQcHisto[bc][it];
125 }
126 }
127}
129{
130 for (int d = mDDL; d--;) {
131 for (int b = 4; b--;) {
132 mMean[d][b] += prev->mMean[d][b];
133 mRMS[d][b] += prev->mRMS[d][b];
134 }
135 mNorm[d] += prev->mNorm[d];
136 }
137 for (int bc = 4; bc--;) {
138 for (int it = 1400; it--;) {
139 mQcHisto[bc][it] += prev->mQcHisto[bc][it];
140 }
141 }
142}
144{
145 for (int d = mDDL; d--;) {
146 for (int b = 4; b--;) {
147 mMean[d][b] = 0.;
148 mRMS[d][b] = 0;
149 }
150 mNorm[d] = 0.;
151 }
152 for (int bc = 4; bc--;) {
153 mQcHisto[bc].fill(0);
154 }
155}
156
157//==============================================================
158
160{
161 for (int d = mDDL; d--;) {
162 for (int b = 4; b--;) {
163 mMean[d][b] = 0.;
164 mRMS[d][b] = 0;
165 }
166 mNorm[d] = 0.;
167 }
168 for (int bc = 0; bc < 4; ++bc) {
169 mQcHisto[bc].fill(0);
170 }
171}
173{
174 // otherwize will be merged with next Slot
175 return true;
176}
181{
182 // Extract results for the single slot
183 PHOSL1phaseSlot* ct = slot.getContainer();
184 ct->addMeanRms(mMean, mRMS, mNorm);
185 ct->addQcHistos(mQcHisto);
186 ct->clear();
187}
188
190{
191
192 auto& cont = getSlots();
193 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
194 slot.setContainer(std::make_unique<PHOSL1phaseSlot>());
195 return slot;
196}
197
198bool PHOSL1phaseCalibrator::process(TFType tf, const gsl::span<const Cell>& cells, const gsl::span<const TriggerRecord>& tr)
199{
200
201 // process current TF
202 auto& slotTF = getSlotForTF(tf);
203 slotTF.getContainer()->setRunStartTime(tf);
204 slotTF.getContainer()->fill(cells, tr);
205
206 return true;
207}
209{
210
211 auto& cont = getSlots();
212 for (auto& slot : cont) {
213 finalizeSlot(slot);
214 }
215
216 // Calculate L1phases: First evaluate RMS and mean for 4 possible values of shift b
217 // then find the smallest RMS, if two RMS are close, choose those b which produces mean closer to 0
218 mL1phase = 0;
219 for (int d = 0; d < mDDL; d++) {
220 int iMinRMS = 0, iMinMean = 0;
221 if (mNorm[d] == 0) { // leave phase=0
222 continue;
223 }
224 float minMean = 0, minRMS = 0, subminRMS = 0;
225 for (int b = 0; b < 4; b++) {
226 float av = mMean[d][b] / mNorm[d];
227 float avRMS = mRMS[d][b] / mNorm[d] - av * av;
228 av = abs(av);
229
230 if (b == 0) {
231 minRMS = avRMS;
232 minMean = av;
233 } else {
234 if (minRMS > avRMS) {
235 subminRMS = minRMS;
236 minRMS = avRMS;
237 iMinRMS = b;
238 } else {
239 if (subminRMS == 0) {
240 subminRMS = avRMS;
241 } else {
242 if (avRMS < subminRMS) {
243 subminRMS = avRMS;
244 }
245 }
246 }
247 if (minMean > av) {
248 minMean = av;
249 iMinMean = b;
250 }
251 }
252 }
253
254 // select b for this ddl
255 int bestB = 0;
256 const float eps = 1.e-2; // rel. accuracy of RMS calculation
257 if (minRMS < subminRMS - eps * minRMS) { // clear minimum
258 bestB = iMinRMS;
259 } else { // RMS are slimilar, chose closer to zero Mean
260 bestB = iMinMean;
261 }
262 if (bestB != 0) { // copy the histogram content to final histo
263 for (int it = 100; it--;) {
264 mQcHisto[4][d * 100 + it] = mQcHisto[bestB][d * 100 + it];
265 }
266 }
267 mL1phase |= (bestB << (2 * d));
268 }
269}
uint64_t bc
Definition RawEventData.h:5
int32_t i
uint32_t c
Definition RawData.h:2
static std::string getCCDBServer()
Definition NameConf.cxx:110
const Container * getContainer() const
Definition TimeSlot.h:53
static BasicCCDBManager & instance()
CCDB container for bad (masked) channels in PHOS.
bool isChannelGood(short channelID) const
Get the status of a certain cell.
float getHGLGRatio(short cellID) const
Get High Gain to Low Gain ratio calibration coefficients.
Definition CalibParams.h:69
float getGain(short cellID) const
Get High Gain energy calibration coefficients.
Definition CalibParams.h:53
float getLGTimeCalib(short cellID) const
Get Low Gain time calibration coefficient.
float getHGTimeCalib(short cellID) const
Get High Gain time calibration coefficients.
Definition CalibParams.h:85
short getAbsId() const
Definition Cell.cxx:44
static bool absToRelNumbering(short absId, char *relid)
Definition Geometry.cxx:65
Slot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
bool hasEnoughData(const Slot &slot) const final
bool process(TFType tf, const gsl::span< const Cell > &clu, const gsl::span< const TriggerRecord > &trs)
void fill(const gsl::span< const Cell > &cells, const gsl::span< const TriggerRecord > &trs)
void addQcHistos(std::array< unsigned int, 1400 >(&sum)[5])
void merge(const PHOSL1phaseSlot *prev)
void addMeanRms(std::array< std::array< float, 4 >, 14 > &sumMean, std::array< std::array< float, 4 >, 14 > &sumRMS, std::array< float, 14 > &sumNorm)
float sum(float s, o2::dcs::DataPointValue v)
Definition dcs-ccdb.cxx:39
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
std::unique_ptr< GPUReconstructionTimeframe > tf
VectorOfTObjectPtrs other
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cell > cells