Project
Loading...
Searching...
No Matches
NoiseCalib.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 <TROOT.h>
13#include <TFile.h>
14#include <TH1.h>
15#include <TString.h>
16#include <TStyle.h>
17#include <TDirectory.h>
19#include "ZDCCalib/NoiseCalib.h"
20#include "Framework/Logger.h"
22#include "CCDB/CcdbApi.h"
23
24using namespace o2::zdc;
25
27{
28 // Inspect calibration parameters
29 const auto& opt = CalibParamZDC::Instance();
30 opt.print();
31 if (opt.debugOutput == true) {
33 }
34
35 int nbx = 4096 * NTimeBinsPerBC - NTimeBinsPerBC + 1;
36 double xmin = -2048 * NTimeBinsPerBC - 0.5;
37 double xmax = 2047 * NTimeBinsPerBC + 0.5;
38
39 for (int isig = 0; isig < NChannels; isig++) {
40 // Baseline single samples
41 if (mH[0][isig] == nullptr) {
42 mH[0][isig] = new o2::dataformats::FlatHisto1D<double>(4096, -2048.5, 2047.5);
43 } else {
44 mH[0][isig]->clear();
45 }
46 // Bunch average of baseline samples
47 if (mH[1][isig] == nullptr) {
48 mH[1][isig] = new o2::dataformats::FlatHisto1D<double>(nbx, xmin, xmax);
49 } else {
50 mH[1][isig]->clear();
51 }
52 // Difference between single samples and average
53 if (mH[2][isig] == nullptr) {
54 mH[2][isig] = new o2::dataformats::FlatHisto1D<double>(nbx, xmin / double(NTimeBinsPerBC), xmax / double(NTimeBinsPerBC));
55 } else {
56 mH[2][isig]->clear();
57 }
58 }
59
60 clear();
61 mInitDone = true;
62 return 0;
63}
64
65//______________________________________________________________________________
67{
68 mData.clear();
69}
70
71//______________________________________________________________________________
73{
74 if (!mInitDone) {
75 init();
76 }
77 if (mVerbosity >= DbgFull) {
78 data->print();
79 }
80 mData += data;
81 if (mVerbosity >= DbgFull) {
82 mData.print();
83 }
84 return 0;
85}
86
87//______________________________________________________________________________
88// Add histograms
90{
91 if (!mInitDone) {
92 init();
93 }
94 if (ih >= 0 && ih < NChannels && iarr >= 0 && iarr < NHA) {
95 mH[iarr][ih]->add(h1);
96 } else {
97 LOG(error) << "InterCalib::add: unsupported FlatHisto1D ih=" << ih << " iarr=" << iarr;
98 }
99}
100
101//______________________________________________________________________________
102// Create calibration object
104{
105 if (mVerbosity > DbgZero) {
106 LOGF(info, "Finalizing NoiseCalibData object");
107 mData.print();
108 }
109 if (mSaveDebugHistos) {
111 }
112
113 for (int isig = 0; isig < NChannels; isig++) {
114 uint64_t en = 0;
115 double mean = 0, var = 0;
116 // N.B. Histogram is used to evaluate mean variance -> OK to use mean!
117 mData.getStat(isig, en, mean, var);
118 if (en > 0) {
119 double stdev = std::sqrt(mean / double(NTimeBinsPerBC) / double(NTimeBinsPerBC - 1));
120 mParam.setCalib(isig, stdev);
121 mParam.entries[isig] = en;
122 }
123 }
124
125 if (mVerbosity > DbgZero) {
126 mParam.print();
127 }
128
129 // Creating calibration object and info
130 auto clName = o2::utils::MemFileHelper::getClassName(mParam);
131 mInfo.setObjectType(clName);
132 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
133 mInfo.setFileName(flName);
135
136 const auto& opt = CalibParamZDC::Instance();
137 std::map<std::string, std::string> md;
138 md["config"] = opt.descr;
139 mInfo.setMetaData(md);
140 uint64_t starting = mData.mCTimeBeg;
141 if (starting >= 10000) {
142 starting = starting - 10000; // start 10 seconds before
143 }
144 uint64_t stopping = mData.mCTimeEnd + 10000; // stop 10 seconds after
145 mInfo.setStartValidityTimestamp(starting);
146 mInfo.setEndValidityTimestamp(stopping);
147 mInfo.setAdjustableEOV();
148 LOGF(info, "Validity: %llu:%llu", starting, stopping);
149
150 return 0;
151}
152
153//______________________________________________________________________________
154int NoiseCalib::saveDebugHistos(const std::string fn)
155{
156 LOG(info) << "Saving debug histograms on file " << fn;
157 int ierr = mData.saveDebugHistos(fn);
158 if (ierr != 0) {
159 return ierr;
160 }
161 TDirectory* cwd = gDirectory;
162 TFile* f = new TFile(fn.data(), "update");
163 if (f->IsZombie()) {
164 LOG(error) << "Cannot update file: " << fn;
165 return 1;
166 }
167 for (int32_t is = 0; is < NChannels; is++) {
168 auto p = mH[0][is]->createTH1F(TString::Format("hs%d", is).Data());
169 p->SetTitle(TString::Format("Baseline samples %s", ChannelNames[is].data()));
170 p->Write("", TObject::kOverwrite);
171 }
172 for (int32_t is = 0; is < NChannels; is++) {
173 auto p = mH[1][is]->createTH1F(TString::Format("hss%d", is).Data());
174 p->SetTitle(TString::Format("Bunch sum of samples %s", ChannelNames[is].data()));
175 p->Write("", TObject::kOverwrite);
176 }
177 for (int32_t is = 0; is < NChannels; is++) {
178 auto p = mH[2][is]->createTH1F(TString::Format("hsd%d", is).Data());
179 p->SetTitle(TString::Format("Baseline estimation difference %s", ChannelNames[is].data()));
180 p->Write("", TObject::kOverwrite);
181 }
182 f->Close();
183 cwd->cd();
184 return 0;
185}
ZDC calibration common parameters.
static std::string generateFileName(const std::string &inp)
Definition CcdbApi.cxx:798
void setStartValidityTimestamp(long start)
void setFileName(const std::string &nm)
void setPath(const std::string &path)
void setEndValidityTimestamp(long end)
void setObjectType(const std::string &tp)
void setMetaData(const std::map< std::string, std::string > &md)
void add(int ih, int iarr, o2::dataformats::FlatHisto1D< double > &h1)
void setSaveDebugHistos()
Definition NoiseCalib.h:43
static constexpr int NHA
Definition NoiseCalib.h:54
int process(const o2::zdc::NoiseCalibSummaryData *data)
std::array< std::array< o2::dataformats::FlatHisto1D< double > *, NChannels >, NHA > mH
Definition NoiseCalib.h:55
int saveDebugHistos(const std::string fn="ZDCNoiseCalib.root")
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 DbgFull
Definition Constants.h:210
constexpr int DbgZero
Definition Constants.h:207
constexpr std::string_view ChannelNames[]
Definition Constants.h:147
const std::string CCDBPathNoiseCalib
Definition Constants.h:231
static std::string getClassName(const T &obj)
get the class name of the object
int saveDebugHistos(const std::string fn, bool is_epn=false)
uint64_t mCTimeEnd
Time of processed time frame.
int getStat(int is, uint64_t &en, double &mean, double &var) const
uint64_t entries[NChannels]
Definition NoiseParam.h:31
void setCalib(uint32_t ich, float val)
void print() const
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"