Project
Loading...
Searching...
No Matches
BaselineCalib.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>
20#include "Framework/Logger.h"
22#include "CCDB/CcdbApi.h"
23
24using namespace o2::zdc;
25
27{
28 // Inspect reconstruction parameters
29 const auto& opt = CalibParamZDC::Instance();
30 opt.print();
31 if (opt.debugOutput == true) {
33 }
34
35 if (mConfig == nullptr) {
36 LOG(fatal) << "o2::zdc::BaselineCalib: missing configuration object";
37 return -1;
38 }
39
40 if (mVerbosity > DbgZero) {
41 mModuleConfig->print();
42 mConfig->print();
43 }
44
45 clear();
46 mInitDone = true;
47 return 0;
48}
49
50//______________________________________________________________________________
52{
53 mData.clear();
54}
55
56//______________________________________________________________________________
58{
59#ifdef O2_ZDC_DEBUG
60 LOG(info) << "BaselineCalib::process(" << data << ")";
61 if (mVerbosity >= DbgFull) {
62 printf("Data to be added\n");
63 data->print();
64 }
65#endif
66
67 if (!mInitDone) {
68 init();
69 }
70
71#ifdef O2_ZDC_DEBUG
72 printf("Before adding\n");
73 if (mVerbosity >= DbgFull) {
74 mData.print();
75 }
76#endif
77
78 mData += data;
79
80 if (mVerbosity >= DbgFull) {
81 mData.print();
82 }
83 return 0;
84}
85
86//______________________________________________________________________________
87// Create calibration object
89{
90 if (mVerbosity > DbgZero) {
91 LOGF(info, "Finalizing BaselineCalibData object");
92 }
93
94 // Compute average baseline
95 float factor = mModuleConfig->baselineFactor;
96 for (int ic = 0; ic < NChannels; ic++) {
97 double sum = 0;
98 double nsum = 0;
99 double bmin = mConfig->cutLow[ic];
100 double bmax = mConfig->cutHigh[ic];
101 for (int ib = 0; ib < BaselineRange; ib++) {
102 double bval = (BaselineMin + ib) * factor;
103 if (bval >= bmin && bval <= bmax) {
104 nsum += mData.mHisto[ic].mData[ib];
105 sum += bval * mData.mHisto[ic].mData[ib];
106 }
107 }
108 if (nsum > 0 && mConfig->min_e[ic]) {
109 float ave = sum / nsum;
110 if (mVerbosity > DbgZero) {
111 LOGF(info, "Baseline %s %g events and cuts (%g:%g): %f", ChannelNames[ic].data(), nsum, bmin, bmax, ave);
112 }
113 mParamUpd.setCalib(ic, ave, true);
114 } else {
115 if (mParam == nullptr) {
116 LOGF(warn, "Baseline %s %g events and cuts (%g:%g): CANNOT UPDATE AND MISSING OLD VALUE", ChannelNames[ic].data(), nsum, bmin, bmax);
117 mParamUpd.setCalib(ic, -std::numeric_limits<float>::infinity(), false);
118 } else {
119 float val = mParam->getCalib(ic);
120 LOGF(warn, "Baseline %s %g events and cuts (%g:%g): %f NOT UPDATED", ChannelNames[ic].data(), nsum, bmin, bmax, val);
121 mParamUpd.setCalib(ic, val, false);
122 }
123 }
124 }
125
126 // Creating calibration object and info
127 auto clName = o2::utils::MemFileHelper::getClassName(mParamUpd);
128 mInfo.setObjectType(clName);
129 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
130 mInfo.setFileName(flName);
132 std::map<std::string, std::string> md;
133 md["config"] = mConfig->desc;
134 mInfo.setMetaData(md);
135 uint64_t starting = mData.mCTimeBeg;
136 if (starting >= 10000) {
137 starting = starting - 10000; // start 10 seconds before
138 }
139 uint64_t stopping = mData.mCTimeEnd + 10000; // stop 10 seconds after
140 mInfo.setStartValidityTimestamp(starting);
141 mInfo.setEndValidityTimestamp(stopping);
142 mInfo.setAdjustableEOV();
143 LOGF(info, "Validity: %llu:%llu", starting, stopping);
144
145 if (mSaveDebugHistos) {
146 LOG(info) << "Saving debug histograms";
148 }
149 return 0;
150}
151
152//______________________________________________________________________________
153int BaselineCalib::saveDebugHistos(const std::string fn)
154{
155 return mData.saveDebugHistos(fn, mModuleConfig->baselineFactor);
156}
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)
int process(const o2::zdc::BaselineCalibSummaryData *data)
int saveDebugHistos(const std::string fn="ZDCBaselineCalib.root")
float sum(float s, o2::dcs::DataPointValue v)
Definition dcs-ccdb.cxx:39
GLboolean * data
Definition glcorearb.h:298
GLuint GLfloat * val
Definition glcorearb.h:1582
const std::string CCDBPathBaselineCalib
Definition Constants.h:229
constexpr int NChannels
Definition Constants.h:65
constexpr int DbgFull
Definition Constants.h:210
constexpr int BaselineMin
Definition Constants.h:353
constexpr int DbgZero
Definition Constants.h:207
constexpr int BaselineRange
Definition Constants.h:353
constexpr std::string_view ChannelNames[]
Definition Constants.h:147
static std::string getClassName(const T &obj)
get the class name of the object
std::array< uint32_t, NW > mData
2^16 bins
int cutHigh[NChannels]
Baseline cut low.
uint32_t min_e[NChannels]
Baseline cut high.
std::string desc
Minimum entries to compute baseline.
int saveDebugHistos(const std::string fn, float factor)
uint64_t mCTimeEnd
Time of processed time frame.
BaselineCalibChData mHisto[NChannels]
Overflow at least one ZDC channel.
float getCalib(uint32_t ich) const
void setCalib(uint32_t ich, float val, bool ismodified=true)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"