Project
Loading...
Searching...
No Matches
PedestalData.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
17#include "fairlogger/Logger.h"
18#include <cmath>
19#include <iostream>
20#include <iterator>
21#include <limits>
22
24{
25
26PedestalData::PedestalData()
27{
28 mSolar2FeeLinkMapper = o2::mch::raw::createSolar2FeeLinkMapper<o2::mch::raw::ElectronicMapperGenerated>();
29 mElec2DetMapper = o2::mch::raw::createElec2DetMapper<o2::mch::raw::ElectronicMapperGenerated>();
30}
31
32void PedestalData::reset()
33{
34 mPedestals.clear();
35}
36
37PedestalData::PedestalMatrix PedestalData::initPedestalMatrix(uint16_t solarId)
38{
40 for (uint8_t d = 0; d < PedestalData::MAXDS; d++) {
41 // apply the mapping from SOLAR to detector
42 int deId = -1;
43 int dsIddet = -1;
44
45 o2::mch::raw::DsElecId dsElecId(solarId, d / 5, d % 5);
46 std::optional<o2::mch::raw::DsDetId> dsDetId = mElec2DetMapper(dsElecId);
47 if (dsDetId) {
48 deId = dsDetId->deId();
49 dsIddet = dsDetId->dsId();
50 }
51
52 for (uint8_t c = 0; c < PedestalData::MAXCHANNEL; c++) {
53
54 // check if the channel is associated to a detector pad
55 int padId = -1;
56 if (deId >= 0 && dsIddet >= 0) {
58 padId = segment.findPadByFEE(dsIddet, int(c));
59 }
60 if (padId >= 0) {
61 m[d][c].dsChannelId = DsChannelId{solarId, d, c};
62 mSize += 1;
63 }
64 }
65 }
66 return m;
67}
68
69void PedestalData::fill(gsl::span<const PedestalDigit> digits)
70{
71 bool mDebug = false;
72
73 for (auto& d : digits) {
74 uint16_t solarId = d.getSolarId();
75 uint8_t dsId = d.getDsId();
76 uint8_t channel = d.getChannel();
77
78 auto iPedestal = mPedestals.find(solarId);
79
80 if (iPedestal == mPedestals.end()) {
81 auto iPedestalsNew = mPedestals.emplace(std::make_pair(solarId, initPedestalMatrix(solarId)));
82 iPedestal = iPedestalsNew.first;
83 }
84
85 if (iPedestal == mPedestals.end()) {
86 LOGP(fatal, "failed to insert new element in padestals map");
87 break;
88 }
89
90 auto& ped = iPedestal->second[dsId][channel];
91
92 for (uint16_t i = 0; i < d.nofSamples(); i++) {
93 auto s = d.getSample(i);
94
95 ped.mEntries += 1;
96 uint64_t N = ped.mEntries;
97
98 double p0 = ped.mPedestal;
99 double p = p0 + (s - p0) / N;
100 ped.mPedestal = p;
101
102 double M0 = ped.mVariance;
103 double M = M0 + (s - p0) * (s - p);
104 ped.mVariance = M;
105 }
106
107 if (mDebug) {
108 LOGP(info, "solarId {} dsId {} ch {} nsamples {} entries{} mean {} variance {}",
109 (int)solarId, (int)dsId, (int)channel, d.nofSamples(), ped.mEntries, ped.mPedestal, ped.mVariance);
110 }
111 }
112}
113
114void PedestalData::merge(const PedestalData* prev)
115{
116 // merge data of 2 slots
117 LOGP(error, "not yet implemented");
118}
119
120void PedestalData::print() const
121{
122 for (const auto& p : const_cast<PedestalData&>(*this)) {
123 LOGP(info, fmt::runtime(p.asString()));
124 }
125}
126
127uint32_t PedestalData::size() const
128{
129 return mSize;
130}
131
132PedestalData::iterator PedestalData::begin()
133{
134 return PedestalData::iterator(this);
135}
136
137PedestalData::iterator PedestalData::end()
138{
139 return PedestalData::iterator(nullptr);
140}
141
142PedestalData::const_iterator PedestalData::cbegin() const
143{
144 return PedestalData::const_iterator(const_cast<PedestalData*>(this));
145}
146PedestalData::const_iterator PedestalData::cend() const
147{
148 return PedestalData::const_iterator(nullptr);
149}
150
151} // namespace o2::mch::calibration
int32_t i
uint32_t c
Definition RawData.h:2
Compute and store the mean and RMS of the pedestal digit amplitudes.
impl::PedestalDataIterator< PedestalChannel > iterator
static constexpr int MAXCHANNEL
impl::PedestalDataIterator< const PedestalChannel > const_iterator
std::array< std::array< PedestalChannel, MAXCHANNEL >, MAXDS > PedestalMatrix
A Segmentation lets you find pads of a detection element and then inspect those pads.
const GLfloat * m
Definition glcorearb.h:4066
GLuint segment
Definition glcorearb.h:4945
O2MCHMAPPINGIMPL3_EXPORT const Segmentation & segmentation(int detElemId)
std::vector< Digit > digits