Project
Loading...
Searching...
No Matches
CalibPedestal.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
14
15#include <fmt/format.h>
16
17#include "TH2F.h"
18#include "TFile.h"
19
20#include "TPCBase/ROC.h"
21#include "MathUtils/fit.h"
23
24using namespace o2::tpc;
29
31 : CalibRawBase(padSubset),
32 mFirstTimeBin(0),
33 mLastTimeBin(500),
34 mADCMin(20),
35 mADCMax(140),
36 mNumberOfADCs(mADCMax - mADCMin + 1),
37 mStatisticsType(StatisticsType::GausFitFast),
38 mADCdata()
39
40{
41 mCalDets["Pedestals"] = CalPad("Pedestals");
42 mCalDets["Noise"] = CalPad("Noise");
43 mADCdata.resize(ROC::MaxROC);
44}
45//______________________________________________________________________________
47{
48 const auto& param = CalibPedestalParam::Instance();
49
50 mFirstTimeBin = param.FirstTimeBin;
51 mLastTimeBin = param.LastTimeBin;
52 mADCMin = param.ADCMin;
53 mADCMax = param.ADCMax;
54 mNumberOfADCs = mADCMax - mADCMin + 1;
55 mStatisticsType = param.StatType;
56}
57
58//______________________________________________________________________________
59Int_t CalibPedestal::updateROC(const Int_t roc, const Int_t row, const Int_t pad,
60 const Int_t timeBin, const Float_t signal)
61{
62 Int_t adcValue = Int_t(signal);
63 if (timeBin < mFirstTimeBin || timeBin > mLastTimeBin) {
64 return 0;
65 }
66 if (adcValue < mADCMin || adcValue > mADCMax) {
67 return 0;
68 }
69
71 Int_t bin = padInROC * mNumberOfADCs + (adcValue - mADCMin);
72 vectorType& adcVec = *getVector(ROC(roc), kTRUE);
73 ++(adcVec[bin]);
74
75 // printf("bin: %5d, val: %.2f\n", bin, adcVec[bin]);
76
77 return 0;
78}
79
80//______________________________________________________________________________
81CalibPedestal::vectorType* CalibPedestal::getVector(ROC roc, bool create /*=kFALSE*/)
82{
83 vectorType* vec = mADCdata[roc].get();
84 if (vec || !create) {
85 return vec;
86 }
87
88 const size_t numberOfPads = (roc.rocType() == RocType::IROC) ? mMapper.getPadsInIROC() : mMapper.getPadsInOROC();
89
90 vec = new vectorType;
91 vec->resize(numberOfPads * mNumberOfADCs);
92
93 mADCdata[roc] = std::unique_ptr<vectorType>(vec);
94
95 return vec;
96}
97
98//______________________________________________________________________________
100{
101 ROC roc;
102
103 std::vector<float> fitValues;
104
105 for (auto& vecPtr : mADCdata) {
106 auto vec = vecPtr.get();
107 if (!vec) {
108 ++roc;
109 continue;
110 }
111
112 CalROC& calROCPedestal = mCalDets["Pedestals"].getCalArray(roc);
113 CalROC& calROCNoise = mCalDets["Noise"].getCalArray(roc);
114
115 float* array = vec->data();
116
117 const size_t numberOfPads = (roc.rocType() == RocType::IROC) ? mMapper.getPadsInIROC() : mMapper.getPadsInOROC();
118
119 float pedestal{};
120 float noise{};
121
122 TF1 fg("fg", "gaus");
123 fg.SetRange(mADCMin - 0.5f, mADCMax + 1.5f);
124
125 for (Int_t ichannel = 0; ichannel < numberOfPads; ++ichannel) {
126 size_t offset = ichannel * mNumberOfADCs;
127 if (mStatisticsType == StatisticsType::GausFit) {
128 fit(mNumberOfADCs, array + offset, float(mADCMin) - 0.5f, float(mADCMax + 1) - 0.5f, fg); // -0.5 since ADC values are discrete
129 pedestal = fg.GetParameter(1);
130 noise = fg.GetParameter(2);
131 } else if (mStatisticsType == StatisticsType::GausFitFast) {
132 fitGaus(mNumberOfADCs, array + offset, float(mADCMin) - 0.5f, float(mADCMax + 1) - 0.5f, fitValues); // -0.5 since ADC values are discrete
133 pedestal = fitValues[1];
134 noise = fitValues[2];
135 } else if (mStatisticsType == StatisticsType::MeanStdDev) {
136 StatisticsData data = getStatisticsData(array + offset, mNumberOfADCs, double(mADCMin) - 0.5, double(mADCMax) - 0.5); // -0.5 since ADC values are discrete
137 pedestal = data.mCOG;
138 noise = data.mStdDev;
139 }
140 noise = std::abs(noise); // noise can be negative in gaus fit
141
142 calROCPedestal.setValue(ichannel, pedestal);
143 calROCNoise.setValue(ichannel, noise);
144
145 // printf("roc: %2d, channel: %4d, pedestal: %.2f, noise: %.2f\n", roc.getRoc(), ichannel, pedestal, noise);
146 }
147
148 ++roc;
149 }
150}
151
152//______________________________________________________________________________
154{
155 for (auto& vecPtr : mADCdata) {
156 auto vec = vecPtr.get();
157 if (!vec) {
158 continue;
159 }
160 vec->clear();
161 }
162}
163
164//______________________________________________________________________________
165void CalibPedestal::dumpToFile(const std::string filename, uint32_t type /* = 0*/)
166{
167 auto f = std::unique_ptr<TFile>(TFile::Open(filename.c_str(), "recreate"));
168 if (type == 0) {
169 f->WriteObject(&mCalDets["Pedestals"], "Pedestals");
170 f->WriteObject(&mCalDets["Noise"], "Noise");
171 f->Close();
172 } else if (type == 1) {
173 f->WriteObject(this, "CalibPedestal");
174 }
175}
176
177//______________________________________________________________________________
179{
180 auto* data = mADCdata[roc.getRoc()]->data();
181
182 const size_t numberOfPads = (roc.rocType() == RocType::IROC) ? mMapper.getPadsInIROC() : mMapper.getPadsInOROC();
183 TH2F* h2 = new TH2F(fmt::format("hADCValues_ROC{:02}", roc.getRoc()).data(), fmt::format("ADC values of ROC {:02}", roc.getRoc()).data(), numberOfPads, 0, numberOfPads, mNumberOfADCs, mADCMin, mADCMax);
184 h2->SetDirectory(nullptr);
185 for (int ichannel = 0; ichannel < numberOfPads; ++ichannel) {
186 size_t offset = ichannel * mNumberOfADCs;
187
188 for (int iADC = 0; iADC < mNumberOfADCs; ++iADC) {
189 h2->Fill(ichannel, mADCMin + iADC, (data + offset)[iADC]);
190 }
191 }
192
193 return h2;
194}
uint32_t roc
Definition RawData.h:3
void setValue(const size_t channel, const T &value)
Definition CalArray.h:95
TH2 * createControlHistogram(ROC roc)
generate a control histogram
void resetData()
Reset pedestal data.
CalibPedestal(PadSubset padSubset=PadSubset::ROC)
default constructor
Int_t updateROC(const Int_t roc, const Int_t row, const Int_t pad, const Int_t timeBin, const Float_t signal) final
void init()
initialize the clusterer from CalibPedestalParam
void dumpToFile(const std::string filename, uint32_t type=0) final
Dump the relevant data to file.
std::vector< float > vectorType
void analyse()
Analyse the buffered adc values and calculate noise and pedestal.
Base class for raw data calibrations.
const Mapper & mMapper
TPC mapper.
static constexpr unsigned short getPadsInIROC()
Definition Mapper.h:409
static constexpr unsigned short getPadsInOROC()
Definition Mapper.h:413
GlobalPadNumber getPadNumberInROC(const PadROCPos &rocPadPosition) const
Definition Mapper.h:96
Pad and row inside a ROC.
Definition PadROCPos.h:37
@ MaxROC
Definition ROC.h:47
GLenum array
Definition glcorearb.h:4274
GLdouble f
Definition glcorearb.h:310
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
GLenum GLfloat param
Definition glcorearb.h:271
TFitResultPtr fit(const size_t nBins, const T *arr, const T xMin, const T xMax, TF1 &func, std::string_view option="")
Definition fit.h:59
StatisticsData getStatisticsData(const T *arr, const size_t nBins, const double xMin, const double xMax)
Definition fit.h:470
Double_t fitGaus(const size_t nBins, const T *arr, const T xMin, const T xMax, std::vector< T > &param)
Definition fit.h:231
Global TPC definitions and constants.
Definition SimTraits.h:167
@ IROC
Definition Defs.h:48
StatisticsType
Statistics type.
Definition Defs.h:94
@ GausFitFast
Use fast gaus fit (less accurate error treatment)
@ MeanStdDev
Use mean and standard deviation.
@ GausFit
Use slow gaus fit (better fit stability)
PadSubset
Definition of the different pad subsets.
Definition Defs.h:63
unsigned short GlobalPadNumber
global pad number
Definition Defs.h:129
CalDet< float > CalPad
Definition CalDet.h:492
std::string filename()
std::vector< o2::ctf::BufferType > vec
std::vector< int > row