Project
Loading...
Searching...
No Matches
TDCCalib.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 <TPad.h>
15#include <TString.h>
16#include <TStyle.h>
17#include <TDirectory.h>
18#include <TPaveStats.h>
19#include <TAxis.h>
23#include "ZDCCalib/TDCCalib.h"
25#include "Framework/Logger.h"
26#include "CCDB/CcdbApi.h"
27
28using namespace o2::zdc;
29
31{
32 if (mTDCCalibConfig == nullptr) {
33 LOG(fatal) << "o2::zdc::TDCCalib: missing configuration object";
34 return -1;
35 }
36
37 // Inspect calibration parameters
38 const auto& opt = CalibParamZDC::Instance();
39 opt.print();
40 if (opt.debugOutput == true) {
42 }
43
44 clear();
45 auto* cfg = mTDCCalibConfig;
46 int ih = 0;
47 // clang-format off
48 for (int i = 0; i < TDCCalibData::NTDC; i++) {
49 mCTDC[i] = new o2::dataformats::FlatHisto1D<float>(cfg->nb1[ih],cfg->amin1[ih],cfg->amax1[ih]); //sum of TF histograms
50 ih++;
51 }
52 // clang-format on
53 mInitDone = true;
54 return 0;
55}
56
57//______________________________________________________________________________
58// Update calibration coefficients
60{
61 if (mVerbosity > DbgZero) {
62 LOGF(info, "Computing TDC Calibration coefficients");
63 }
64 for (int ih = 0; ih < TDCCalibData::NTDC; ih++) {
65 LOGF(info, "%s %d events and cuts (%g:%g)", TDCCalibData::CTDC[ih], mData.entries[ih], mTDCCalibConfig->cutLow[ih], mTDCCalibConfig->cutHigh[ih]);
66
67 if (!mTDCCalibConfig->enabled[ih]) {
68 LOGF(info, "DISABLED processing of RUN3 data for ih = %d: %s", ih, TDCCalibData::CTDC[ih]);
69 assign(ih, false);
70 }
71
72 else if (mData.entries[ih] >= mTDCCalibConfig->min_e[ih]) { //if number of events > minimum value accpeted -> process
73 LOGF(info, "Processed RUN3 data for ih = %d: %s", ih, TDCCalibData::CTDC[ih]);
74 assign(ih, true);
75 } else {
76 LOGF(info, "FAILED processing RUN3 data for ih = %d: %s: TOO FEW EVENTS: %d", ih, TDCCalibData::CTDC[ih], mData.entries[ih]);
77 assign(ih, false);
78 }
79 }
80
81 auto clName = o2::utils::MemFileHelper::getClassName(mTDCParamUpd);
82 mInfo.setObjectType(clName);
83 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
84 mInfo.setFileName(flName);
86 std::map<std::string, std::string> md;
87 md["config"] = mTDCCalibConfig->desc;
88 mInfo.setMetaData(md);
89 uint64_t starting = mData.mCTimeBeg;
90 if (starting >= 10000) {
91 starting = starting - 10000; // start 10 seconds before
92 }
93 uint64_t stopping = mData.mCTimeEnd + 10000; // stop 10 seconds after
94 mInfo.setStartValidityTimestamp(starting);
95 mInfo.setEndValidityTimestamp(stopping);
96
97 if (mSaveDebugHistos) {
98 write();
99 }
100 return 0;
101}
102
103//______________________________________________________________________________
104// Update calibration object for the ten TDCs
105// ismod=false if it was not possible to update the calibration coefficients
106// due to low statistics
107// ismod=true if the calibration was updated
108void TDCCalib::assign(int ih, bool ismod)
109{
110 if (ih >= 0 && ih <= 9) {
111 auto oldval = mTDCParam->getShift(ih); //old value from calibration object (TDCCalib)
112 if (ismod == true) { //ismod == true
113 auto val = oldval;
114 auto shift = extractShift(ih);
115 //Change wrt previous shift
116 val = val + shift;
117 if (val < 0) { //negative value or = 25ns shift is not acceptable
118 LOGF(error, "Negative value of shift: %8.6f not acceptable", val);
119 }
120
121 else if (val >= 25) {
122 LOGF(error, "Value of shift: %8.6f >= 25 ns not acceptable", val);
123 }
124
125 if (mVerbosity > DbgZero) {
126 LOGF(info, "%s updated %8.6f -> %8.6f", TDCCalibData::CTDC[ih], oldval, val);
127 }
128 mTDCParamUpd.setShift(ih, val);
129 }
130
131 else { //ismod == false
132 if (mVerbosity > DbgZero) {
133 LOGF(info, "%s NOT CHANGED %8.6f", TDCCalibData::CTDC[ih], oldval);
134 }
135 mTDCParamUpd.setShift(ih, oldval);
136 }
137 }
138
139 else { //TDC index out of range
140 LOG(fatal) << "TDCCalib::assign accessing not existing ih = " << ih;
141 }
142}
143
144void TDCCalib::clear(int ih)
145{
146 int ihstart = 0;
147 int ihstop = TDCCalibData::NTDC;
148
149 for (int32_t ii = ihstart; ii < ihstop; ii++) {
150 if (mCTDC[ii]) {
151 mCTDC[ii]->clear();
152 }
153 }
154}
155
157{
158 if (!mInitDone) {
159 init();
160 }
161 mData += data;
162 return 0;
163}
164
166{
167 if (!mInitDone) {
168 init();
169 }
170
171 constexpr int nh = TDCCalibData::NTDC;
172
173 if (ih >= 0 && ih < nh) {
174 mCTDC[ih]->add(h1);
175 } else {
176 LOG(error) << "TDCCalib::add: unsupported FlatHisto1D " << ih;
177 }
178}
179
181{
182 // Extract the TDC shift
183 auto h1 = mCTDC[ih]->createTH1F(TDCCalibData::CTDC[ih]); // createTH1F(histo_name)
184 //h1->Draw("HISTO");
185 int nEntries = h1->GetEntries();
186 // std::cout << nEntries << std::endl;
187 if ((ih >= 0 && ih <= 9) && (nEntries >= mTDCCalibConfig->min_e[ih])) { //TDC number is ok and more than minimum entries
188 double avgShift = h1->GetMean();
189 return avgShift;
190 } else {
191 LOG(error) << "TDCCalib::extractShift TDC out of range " << ih;
192 return 0;
193 }
194}
195
196int TDCCalib::write(const std::string fn)
197{
198 if (mVerbosity > DbgZero) {
199 LOG(info) << "Saving aggregator histos on file " << fn;
200 }
201 TDirectory* cwd = gDirectory;
202 TFile* f = new TFile(fn.data(), "recreate");
203 if (f->IsZombie()) {
204 LOG(error) << "Cannot create file: " << fn;
205 return 1;
206 }
207 for (int32_t ih = 0; ih < TDCCalibData::NTDC; ih++) {
208 if (mCTDC[ih]) {
209 auto p = mCTDC[ih]->createTH1F(TDCCalibData::CTDC[ih]); // createTH1F(histo_name)
210 p->SetTitle(TDCCalibData::CTDC[ih]);
211 p->Write("", TObject::kOverwrite);
212 if (mVerbosity > DbgMinimal) {
213 LOG(info) << p->GetName() << " entries: " << p->GetEntries();
214 }
215 }
216 }
217 f->Close();
218 cwd->cd();
219 return 0;
220}
ZDC calibration common parameters.
int32_t i
TDC calibration intermediate data.
Parameters to correct TDCs (produced by QA)
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, o2::dataformats::FlatHisto1D< float > &h1)
Definition TDCCalib.cxx:165
double extractShift(int ih)
Definition TDCCalib.cxx:180
int write(const std::string fn="ZDCTDCCalib.root")
Definition TDCCalib.cxx:196
int process(const gsl::span< const o2::zdc::BCRecData > &bcrec, const gsl::span< const o2::zdc::ZDCEnergy > &energy, const gsl::span< const o2::zdc::ZDCTDCData > &tdc, const gsl::span< const uint16_t > &info)
void clear(int ih=-1)
Definition TDCCalib.cxx:144
void setSaveDebugHistos()
Definition TDCCalib.h:58
GLdouble f
Definition glcorearb.h:310
GLboolean * data
Definition glcorearb.h:298
GLuint GLfloat * val
Definition glcorearb.h:1582
const std::string CCDBPathTDCCalib
Definition Constants.h:221
constexpr int DbgMinimal
Definition Constants.h:208
constexpr int DbgZero
Definition Constants.h:207
static std::string getClassName(const T &obj)
get the class name of the object
bool enabled[NTDCChannels]
double min_e[NTDCChannels]
double cutLow[NTDCChannels]
double cutHigh[NTDCChannels]
uint64_t mCTimeBeg
ZNAC, ZNAS, ZPAC, ZPAS, ZEM1, ZEM2, ZNCC, ZNCS, ZPCC, ZPCS.
uint64_t mCTimeEnd
Time of processed time frame.
static constexpr const char * CTDC[NTDC]
Time of processed time frame.
static constexpr int NTDC
void setShift(uint32_t ich, float val)
float getShift(uint32_t ich) const
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
vec clear()