Project
Loading...
Searching...
No Matches
WaveformCalibData.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
12#include <TH1.h>
13#include <TFile.h>
14#include <TDirectory.h>
15#include "Framework/Logger.h"
17
18using namespace o2::zdc;
19
20//______________________________________________________________________________
22{
23 LOGF(info, "WaveformCalibData mN = %d/%d [%llu : %llu]", mN, NBT, mCTimeBeg, mCTimeEnd);
24 for (int32_t is = 0; is < NChannels; is++) {
25 if (getEntries(is) > 0) {
26 LOGF(info, "WaveformCalibData %2d %s: entries=%d [%d:%d:%d]", is, ChannelNames[is].data(), getEntries(is), getFirstValid(is), mPeak, getLastValid(is));
27 }
28 }
29}
30
31//______________________________________________________________________________
33{
34 if (mN != other.mN) {
35 LOG(fatal) << "Mixing waveform with different configurations mN = " << mN << " != " << other.mN;
36 return *this;
37 }
38 if (mPeak != other.mPeak) {
39 LOG(fatal) << "Mixing waveform with different configurations mPeak = " << mPeak << " != " << other.mPeak;
40 return *this;
41 }
42 if (mCTimeBeg == 0 || other.mCTimeBeg < mCTimeBeg) {
43 mCTimeBeg = other.mCTimeBeg;
44 }
45 if (other.mCTimeEnd > mCTimeEnd) {
46 mCTimeEnd = other.mCTimeEnd;
47 }
48 for (int32_t is = 0; is < NChannels; is++) {
49 mWave[is] += other.mWave[is];
50 }
51#ifdef O2_ZDC_DEBUG
52 LOG(info) << __func__;
53 print();
54#endif
55 return *this;
56}
57
59{
60 if (other.mEntries > 0) {
61 if (other.mFirstValid > mFirstValid) {
62#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
63 printf("WaveformCalibChData::+= mFirstValid %5d -> %5d\n", mFirstValid, other.mFirstValid);
64#endif
65 mFirstValid = other.mFirstValid;
66 }
67 if (other.mLastValid < mLastValid) {
68#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
69 printf("WaveformCalibChData::+= mLastValid %5d -> %5d\n", mLastValid, other.mLastValid);
70#endif
71 mLastValid = other.mLastValid;
72 }
73 mEntries = mEntries + other.mEntries;
74 for (int32_t i = mFirstValid; i <= mLastValid; i++) {
75 mData[i] = mData[i] + other.mData[i];
76 }
77 }
78 return *this;
79}
80
81//______________________________________________________________________________
83{
84 mCTimeBeg = ctime;
85 mCTimeEnd = ctime;
86#ifdef O2_ZDC_DEBUG
87 LOGF(info, "WaveformCalibData::setCreationTime %llu", ctime);
88#endif
89}
90
91//______________________________________________________________________________
93{
94 if (is < 0 || is >= NChannels) {
95 LOGF(error, "WaveformCalibData::getEntries channel index %d is out of range", is);
96 return 0;
97 }
98 return mWave[is].getEntries();
99}
100
102{
103 return mEntries;
104}
105
106//______________________________________________________________________________
108{
109 if (is < 0 || is >= NChannels) {
110 LOGF(error, "WaveformCalibData::getFirstValid channel index %d is out of range", is);
111 return 0;
112 }
113 return mWave[is].getFirstValid();
114}
115
117{
118 return mFirstValid;
119}
120
121//______________________________________________________________________________
123{
124 if (is < 0 || is >= NChannels) {
125 LOGF(error, "WaveformCalibData::getLastValid channel index %d is out of range", is);
126 return 0;
127 }
128 return mWave[is].getLastValid();
129}
130
132{
133 return mLastValid;
134}
135
136//______________________________________________________________________________
138{
139 if (n > 0 && n <= NBT) {
140 mN = n;
141 for (int is = 0; is < NChannels; is++) {
142 mWave[is].setN(n);
143 }
144 } else {
145 LOG(warn) << "WaveformCalibData " << __func__ << " wrong stored b.c. setting " << n << " not in range [1:" << NBT << "]";
146 }
147}
148
150{
151 if (n > 0 && n <= NBT) {
152 mFirstValid = 0;
153 mLastValid = n * NTimeBinsPerBC * TSN - 1;
154 } else {
155 LOG(warn) << "WaveformCalibChData " << __func__ << " wrong stored b.c. setting " << n << " not in range [1:" << NBT << "]";
156 }
157}
158
159//______________________________________________________________________________
160int WaveformCalibData::saveDebugHistos(const std::string fn)
161{
162 TDirectory* cwd = gDirectory;
163 TFile* f = new TFile(fn.data(), "recreate");
164 if (f->IsZombie()) {
165 LOG(error) << "Cannot create file: " << fn;
166 return 1;
167 }
168 for (int32_t is = 0; is < NChannels; is++) {
169 if (mWave[is].mEntries > 0) {
170 TString n = TString::Format("h%d", is);
171 TString t = TString::Format("Waveform %d %s", is, ChannelNames[is].data());
172 int nbx = mWave[is].mLastValid - mWave[is].mFirstValid + 1;
173 float min = mWave[is].mFirstValid - mPeak - 0.5;
174 float max = mWave[is].mLastValid - mPeak + 0.5;
175 TH1F h(n, t, nbx, min, max);
176 for (int ibx = 0; ibx < nbx; ibx++) {
177 h.SetBinContent(ibx + 1, mWave[is].mData[mWave[is].mFirstValid + ibx]);
178 }
179 h.SetEntries(mWave[is].mEntries);
180 h.Write("", TObject::kOverwrite);
181 } else {
182 LOG(warn) << "WaveformCalibData " << __func__ << " waveform for ch " << is << " has too few entries: " << mWave[is].mEntries;
183 }
184 }
185 f->Close();
186 cwd->cd();
187 return 0;
188}
189
190//______________________________________________________________________________
191int WaveformCalibData::dumpCalib(const std::string fn)
192{
193 TDirectory* cwd = gDirectory;
194 TFile* f = new TFile(fn.data(), "recreate");
195 if (f->IsZombie()) {
196 LOG(error) << "Cannot create file: " << fn;
197 return 1;
198 }
199 f->WriteObjectAny((void*)this, o2::zdc::WaveformCalibData::Class(), "WaveformCalibData");
200 f->Close();
201 cwd->cd();
202 return 0;
203}
204
205//______________________________________________________________________________
207{
208 mCTimeBeg = 0;
209 mCTimeEnd = 0;
210 mN = 0;
211 mPeak = 0;
212 for (int32_t is = 0; is < NChannels; is++) {
213 mWave[is].clear();
214 }
215}
216
217//______________________________________________________________________________
219{
220 mCTimeBeg = 0;
221 mCTimeEnd = 0;
222 for (int32_t is = 0; is < NChannels; is++) {
223 mWave[is].clear();
224 }
225}
226
228{
229 mEntries = 0;
230 mFirstValid = -1;
231 mLastValid = -1;
232 for (int iw = 0; iw < NW; iw++) {
233 mData[iw] = 0;
234 }
235}
int32_t i
Waveform calibration intermediate data.
Class for time synchronization of RawReader instances.
GLdouble n
Definition glcorearb.h:1982
GLdouble f
Definition glcorearb.h:310
GLboolean * data
Definition glcorearb.h:298
constexpr int NTimeBinsPerBC
Definition Constants.h:53
constexpr int NChannels
Definition Constants.h:65
constexpr int TSN
Definition Constants.h:94
constexpr std::string_view ChannelNames[]
Definition Constants.h:147
int mLastValid
First bin with valid data.
WaveformCalibChData & operator+=(const WaveformCalibChData &other)
Waveform.
std::array< float, NW > mData
Number of waveforms added.
uint32_t mEntries
Last bin with valid data.
int mPeak
Number of bunches in waveform.
int dumpCalib(const std::string fn)
std::array< WaveformCalibChData, NChannels > mWave
Peak position.
int mN
Time of processed time frame.
uint64_t mCTimeEnd
Time of processed time frame.
WaveformCalibData & operator+=(const WaveformCalibData &other)
int saveDebugHistos(const std::string fn)
void setCreationTime(uint64_t ctime)
constexpr size_t min
constexpr size_t max
VectorOfTObjectPtrs other
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"