Project
Loading...
Searching...
No Matches
InterCalibEPN.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>
19#include <TPaveStats.h>
20#include <TAxis.h>
23#include "ZDCCalib/InterCalib.h"
26#include "Framework/Logger.h"
27
28using namespace o2::zdc;
29
31{
32 if (mInterCalibConfig == nullptr) {
33 LOG(fatal) << "o2::zdc::InterCalibEPN: 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 = mInterCalibConfig;
46
47 // clang-format off
48 for(int ih=0; ih<NH; ih++){
49 if(ih == HidZNI || ih == HidZPI){
50 // Avoid duplication
51 mH[ih] = nullptr;
52 mH[NH+ih] = nullptr;
53 }else{
54 mH[ih] = new o2::dataformats::FlatHisto1D<float>(cfg->nb1[ih],cfg->amin1[ih],cfg->amax1[ih]);
55 mH[NH+ih] = new o2::dataformats::FlatHisto1D<float>(cfg->nb1[ih],cfg->amin1[ih],cfg->amax1[ih]);
56 }
57 mC[ih] = new o2::dataformats::FlatHisto2D<float>(cfg->nb2[ih],cfg->amin2[ih],cfg->amax2[ih],cfg->nb2[ih],cfg->amin2[ih],cfg->amax2[ih]);
58 }
59 // clang-format on
60 mInitDone = true;
61 return 0;
62}
63
64int InterCalibEPN::process(const gsl::span<const o2::zdc::BCRecData>& RecBC,
65 const gsl::span<const o2::zdc::ZDCEnergy>& Energy,
66 const gsl::span<const o2::zdc::ZDCTDCData>& TDCData,
67 const gsl::span<const uint16_t>& Info)
68{
69 if (!mInitDone) {
70 init();
71 }
72 if (mVerbosity > DbgMinimal) {
73 LOG(info) << "o2::zdc::InterCalibEPN processing " << RecBC.size() << " b.c. @ TS " << mData.mCTimeBeg << " : " << mData.mCTimeEnd;
74 }
76 ev.init(RecBC, Energy, TDCData, Info);
77 while (ev.next()) {
78 if (ev.getNInfo() > 0) {
79 auto& decodedInfo = ev.getDecodedInfo();
80 for (uint16_t info : decodedInfo) {
81 uint8_t ch = (info >> 10) & 0x1f;
82 uint16_t code = info & 0x03ff;
83 // hmsg->Fill(ch, code);
84 }
85 if (mVerbosity > DbgMinimal) {
86 ev.print();
87 }
88 // Need clean data (no messages)
89 // We are sure there is no pile-up in any channel (too restrictive?)
90 continue;
91 }
92 if (ev.getNEnergy() > 0 && ev.mCurB.triggers == 0) {
93 LOGF(info, "%9u.%04u Untriggered bunch", ev.mCurB.ir.orbit, ev.mCurB.ir.bc);
94 // Skip!
95 continue;
96 }
97 // Select hadronic collisions by requiring a signal in ZEM calorimeters
98 if (ev.TDCVal[TDCZEM1].size() == 0 || ev.TDCVal[TDCZEM2].size() == 0) {
99 continue;
100 }
101 if (mInterCalibConfig->cross_check == false) {
102 if ((ev.ezdcDecoded & MaskZNA) == MaskZNA) {
103 cumulate(HidZNA, ev.EZDC(IdZNAC), ev.EZDC(IdZNA1), ev.EZDC(IdZNA2), ev.EZDC(IdZNA3), ev.EZDC(IdZNA4), 1.);
104 }
105 if ((ev.ezdcDecoded & MaskZPA) == MaskZPA) {
106 float x, rms;
107 ev.centroidZPA(x, rms);
108 cumulate(HidZPA, ev.EZDC(IdZPAC), ev.EZDC(IdZPA1), ev.EZDC(IdZPA2), ev.EZDC(IdZPA3), ev.EZDC(IdZPA4), 1.);
109 if (x < -(mInterCalibConfig->xcut_ZPA) && rms >= mInterCalibConfig->rms_cut_ZP) {
110 cumulate(HidZPAX, ev.EZDC(IdZPAC), ev.EZDC(IdZPA1), ev.EZDC(IdZPA2), ev.EZDC(IdZPA3), ev.EZDC(IdZPA4), 1.);
111 }
112 }
113 if ((ev.ezdcDecoded & MaskZNC) == MaskZNC) {
114 cumulate(HidZNC, ev.EZDC(IdZNCC), ev.EZDC(IdZNC1), ev.EZDC(IdZNC2), ev.EZDC(IdZNC3), ev.EZDC(IdZNC4), 1.);
115 }
116 if ((ev.ezdcDecoded & MaskZPC) == MaskZPC) {
117 float x, rms;
118 ev.centroidZPC(x, rms);
119 cumulate(HidZPC, ev.EZDC(IdZPCC), ev.EZDC(IdZPC1), ev.EZDC(IdZPC2), ev.EZDC(IdZPC3), ev.EZDC(IdZPC4), 1.);
120 if (x > (mInterCalibConfig->xcut_ZPC) && rms >= mInterCalibConfig->rms_cut_ZP) {
121 cumulate(HidZPCX, ev.EZDC(IdZPCC), ev.EZDC(IdZPC1), ev.EZDC(IdZPC2), ev.EZDC(IdZPC3), ev.EZDC(IdZPC4), 1.);
122 }
123 }
124 } else {
125 if ((ev.ezdcDecoded & MaskAllZNA) == MaskAllZNA) {
126 cumulate(HidZNA, ev.EZDC(IdZNASum), ev.EZDC(IdZNA1), ev.EZDC(IdZNA2), ev.EZDC(IdZNA3), ev.EZDC(IdZNA4), 1.);
127 }
128 if ((ev.ezdcDecoded & MaskAllZPA) == MaskAllZPA) {
129 float x, rms;
130 ev.centroidZPA(x, rms);
131 cumulate(HidZPA, ev.EZDC(IdZPASum), ev.EZDC(IdZPA1), ev.EZDC(IdZPA2), ev.EZDC(IdZPA3), ev.EZDC(IdZPA4), 1.);
132 if (x < -(mInterCalibConfig->xcut_ZPA)) {
133 cumulate(HidZPAX, ev.EZDC(IdZPASum), ev.EZDC(IdZPA1), ev.EZDC(IdZPA2), ev.EZDC(IdZPA3), ev.EZDC(IdZPA4), 1.);
134 }
135 }
136 if ((ev.ezdcDecoded & MaskAllZNC) == MaskAllZNC) {
137 cumulate(HidZNC, ev.EZDC(IdZNCSum), ev.EZDC(IdZNC1), ev.EZDC(IdZNC2), ev.EZDC(IdZNC3), ev.EZDC(IdZNC4), 1.);
138 }
139 if ((ev.ezdcDecoded & MaskAllZPC) == MaskAllZPC) {
140 float x, rms;
141 ev.centroidZPC(x, rms);
142 cumulate(HidZPC, ev.EZDC(IdZPCSum), ev.EZDC(IdZPC1), ev.EZDC(IdZPC2), ev.EZDC(IdZPC3), ev.EZDC(IdZPC4), 1.);
143 if (x > (mInterCalibConfig->xcut_ZPC)) {
144 cumulate(HidZPCX, ev.EZDC(IdZPCSum), ev.EZDC(IdZPC1), ev.EZDC(IdZPC2), ev.EZDC(IdZPC3), ev.EZDC(IdZPC4), 1.);
145 }
146 }
147 }
148
149 if ((ev.ezdcDecoded & MaskZEM) == MaskZEM) {
150 cumulate(HidZEM, ev.EZDC(IdZEM1), ev.EZDC(IdZEM2), 0., 0., 0., 1.);
151 }
152 if ((ev.ezdcDecoded & MaskZNA) == MaskZNA && (ev.ezdcDecoded & MaskZNC) == MaskZNC) {
153 cumulate(HidZNI, ev.EZDC(IdZNAC), ev.EZDC(IdZNCC), 0., 0., 0., 1.);
154 }
155 if ((ev.ezdcDecoded & MaskZPA) == MaskZPA && (ev.ezdcDecoded & MaskZPC) == MaskZPC) {
156 cumulate(HidZPI, ev.EZDC(IdZPAC), ev.EZDC(IdZPCC), 0., 0., 0., 1.);
157 }
158 }
159 return 0;
160}
161
163{
164 if (mVerbosity > DbgZero) {
165 LOGF(info, "InterCalibEPN::endOfRun ts (%llu:%llu)", mData.mCTimeBeg, mData.mCTimeEnd);
166 for (int ih = 0; ih < NH; ih++) {
167 LOGF(info, "%s %g events and cuts (%g:%g)", InterCalibData::DN[ih], mData.mSum[ih][5][5], mInterCalibConfig->cutLow[ih], mInterCalibConfig->cutHigh[ih]);
168 }
169 }
170 if (mSaveDebugHistos) {
172 }
173 return 0;
174}
175
176int InterCalibEPN::process(const char* hname, int ic)
177{
178 // Run 2 ZDC calibration is based on multi-dimensional histograms
179 // with dimensions:
180 // TC, T1, T2, T3, T4, Trigger
181 // ic is the number of the selected trigger class
182 THnSparse* hs = (THnSparse*)gROOT->FindObject(hname);
183 if (hs == nullptr) {
184 LOGF(error, "Not found: %s\n", hname);
185 return -1;
186 }
187 if (!hs->InheritsFrom(THnSparse::Class())) {
188 LOGF(error, "Not a THnSparse: %s\n", hname);
189 hs->IsA()->Print();
190 return -1;
191 }
192 TString hn = hname;
193 int ih = -1;
194 if (hn.EqualTo("hZNA")) {
195 ih = HidZNA;
196 } else if (hn.EqualTo("hZPA")) {
197 ih = HidZPA;
198 } else if (hn.EqualTo("hZNC")) {
199 ih = HidZNC;
200 } else if (hn.EqualTo("hZPC")) {
201 ih = HidZPC;
202 } else if (hn.EqualTo("hZEM")) {
203 ih = HidZEM;
204 } else if (hn.EqualTo("hZNI")) {
205 ih = HidZNI;
206 } else if (hn.EqualTo("hZPI")) {
207 ih = HidZPI;
208 } else if (hn.EqualTo("hZPAX")) {
209 ih = HidZPAX;
210 } else if (hn.EqualTo("hZPCX")) {
211 ih = HidZPCX;
212 } else {
213 LOGF(error, "Not recognized histogram name: %s\n", hname);
214 return -1;
215 }
216 clear(ih);
217 const int32_t dim = 6;
218 double x[dim];
219 int32_t bins[dim];
220 int64_t nb = hs->GetNbins();
221 int64_t nn = 0;
222 LOGF(info, "Histogram %s has %ld bins\n", hname, nb);
223 double cutl = mInterCalibConfig->cutLow[ih];
224 double cuth = mInterCalibConfig->cutHigh[ih];
225 double contt = 0;
226 for (int64_t i = 0; i < nb; i++) {
227 double cont = hs->GetBinContent(i, bins);
228 if (cont <= 0) {
229 continue;
230 }
231 for (int32_t d = 0; d < dim; ++d) {
232 x[d] = hs->GetAxis(d)->GetBinCenter(bins[d]);
233 }
234 if (TMath::Nint(x[5] - ic) == 0 && x[0] > cutl && x[0] < cuth) {
235 nn++;
236 contt += cont;
237 cumulate(ih, x[0], x[1], x[2], x[3], x[4], cont);
238 }
239 }
240 LOGF(info, "Trigger class selection %d and %d bins %g events and cuts (%g:%g): %ld", ic, nn, contt, cutl, cuth);
241 return 0;
242}
243
245{
246 int ihstart = 0;
247 int ihstop = NH;
248 if (ih >= 0 && ih < NH) {
249 ihstart = ih;
250 ihstop = ih + 1;
251 }
252 for (int32_t ii = ihstart; ii < ihstop; ii++) {
253 for (int32_t i = 0; i < NPAR; i++) {
254 for (int32_t j = 0; j < NPAR; j++) {
255 mData.mSum[ii][i][j] = 0;
256 }
257 }
258 if (mH[ii]) {
259 mH[ii]->clear();
260 }
261 if (mC[ii]) {
262 mC[ii]->clear();
263 }
264 }
265}
266
267void InterCalibEPN::cumulate(int ih, double tc, double t1, double t2, double t3, double t4, double w = 1)
268{
269 constexpr double minfty = -std::numeric_limits<double>::infinity();
270 // printf("%s: ih=%d tc=%g t1=%g t2=%g t3=%g t4=%g w=%g\n",__func__,ih, tc, t1, t2, t3, t4, w); fflush(stdout);
271 if (tc < mInterCalibConfig->cutLow[ih] || tc > mInterCalibConfig->cutHigh[ih]) {
272 return;
273 }
274 if ((ih == HidZPA || ih == HidZPAX)) {
275 if (t1 < mInterCalibConfig->towerCutLow_ZPA[0] || t2 < mInterCalibConfig->towerCutLow_ZPA[1] || t3 < mInterCalibConfig->towerCutLow_ZPA[2] || t4 < mInterCalibConfig->towerCutLow_ZPA[3]) {
276 return;
277 }
278 if (t1 > mInterCalibConfig->towerCutHigh_ZPA[0] || t2 > mInterCalibConfig->towerCutHigh_ZPA[1] || t3 > mInterCalibConfig->towerCutHigh_ZPA[2] || t4 > mInterCalibConfig->towerCutHigh_ZPA[3]) {
279 return;
280 }
281 }
282 if (ih == HidZPC || ih == HidZPCX) {
283 if (t1 < mInterCalibConfig->towerCutLow_ZPC[0] || t2 < mInterCalibConfig->towerCutLow_ZPC[1] || t3 < mInterCalibConfig->towerCutLow_ZPC[2] || t4 < mInterCalibConfig->towerCutLow_ZPC[3]) {
284 return;
285 }
286 if (t1 > mInterCalibConfig->towerCutHigh_ZPC[0] || t2 > mInterCalibConfig->towerCutHigh_ZPC[1] || t3 > mInterCalibConfig->towerCutHigh_ZPC[2] || t4 > mInterCalibConfig->towerCutHigh_ZPC[3]) {
287 return;
288 }
289 }
290 double val[NPAR] = {tc, t1, t2, t3, t4, 1};
291 if (tc > minfty && t1 > minfty && t2 > minfty && t3 > minfty && t4 > minfty) {
292 for (int32_t i = 0; i < NPAR; i++) {
293 for (int32_t j = i; j < NPAR; j++) {
294 mData.mSum[ih][i][j] += val[i] * val[j] * w;
295 }
296 }
297 }
298 // mData.mSum[ih][5][5] contains the number of analyzed events
299 double sumquad = val[1] + val[2] + val[3] + val[4];
300 // Avoid filling duplicate histograms
301 if (mH[ih] != nullptr) {
302 mH[ih]->fill(sumquad, w);
303 }
304 if (mH[ih + NH] != nullptr) {
305 mH[ih + NH]->fill(val[0]);
306 }
307 mC[ih]->fill(val[0], sumquad, w);
308}
309
310//______________________________________________________________________________
311int InterCalibEPN::saveDebugHistos(const std::string fn)
312{
313 TDirectory* cwd = gDirectory;
314 TFile* f = new TFile(fn.data(), "recreate");
315 if (f->IsZombie()) {
316 LOG(error) << "Cannot create file: " << fn;
317 return 1;
318 }
319 for (int32_t ih = 0; ih < (2 * NH); ih++) {
320 if (mH[ih]) {
321 auto p = mH[ih]->createTH1F(InterCalib::mHUncN[ih]);
322 p->SetTitle(InterCalib::mHUncT[ih]);
323 p->Write("", TObject::kOverwrite);
324 }
325 }
326 for (int32_t ih = 0; ih < NH; ih++) {
327 if (mC[ih]) {
328 auto p = mC[ih]->createTH2F(InterCalib::mCUncN[ih]);
329 p->SetTitle(InterCalib::mCUncT[ih]);
330 p->Write("", TObject::kOverwrite);
331 }
332 }
333 f->Close();
334 cwd->cd();
335 return 0;
336}
ZDC calibration common parameters.
const auto bins
Definition PID.cxx:49
int32_t i
Intercalibration intermediate data.
uint32_t j
Definition RawData.h:0
ZDC Energy calibration.
ZDC Tower calibration.
static constexpr int HidZPC
static constexpr int HidZPI
static constexpr int HidZNA
std::array< o2::dataformats::FlatHisto2D< float > *, NH > mC
int saveDebugHistos(const std::string fn="ZDCInterCalibEPN.root")
static constexpr int HidZNI
static constexpr int HidZEM
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)
static constexpr int HidZPAX
static constexpr int HidZPCX
static constexpr int NPAR
static constexpr int HidZPA
static constexpr int NH
static constexpr int HidZNC
void cumulate(int ih, double tc, double t1, double t2, double t3, double t4, double w)
std::array< o2::dataformats::FlatHisto1D< float > *, 2 *NH > mH
static constexpr const char * mHUncT[2 *NH]
Definition InterCalib.h:91
static constexpr const char * mHUncN[2 *NH]
Definition InterCalib.h:89
static constexpr const char * mCUncT[NH]
Definition InterCalib.h:94
static constexpr const char * mCUncN[NH]
Definition InterCalib.h:93
GLint GLenum GLint x
Definition glcorearb.h:403
GLdouble f
Definition glcorearb.h:310
GLuint GLfloat * val
Definition glcorearb.h:1582
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition glcorearb.h:5034
constexpr int IdZNCSum
constexpr int IdZPC4
constexpr int IdZPA2
constexpr int IdZNA3
constexpr int IdZNA1
constexpr int IdZPA1
constexpr int IdZPCSum
constexpr int IdZNC2
constexpr int IdZEM1
constexpr uint32_t MaskZNA
Definition Constants.h:137
constexpr int IdZNCC
constexpr int IdZPAC
constexpr uint32_t MaskAllZNA
Definition Constants.h:138
constexpr int IdZPC2
constexpr uint32_t MaskZNC
Definition Constants.h:142
constexpr int IdZPA4
constexpr uint32_t MaskAllZPA
Definition Constants.h:140
constexpr int IdZNC1
constexpr int IdZNC3
constexpr int IdZPCC
constexpr int IdZPC1
constexpr int IdZPA3
constexpr int DbgMinimal
Definition Constants.h:208
constexpr int IdZNC4
constexpr int IdZEM2
constexpr uint32_t MaskZEM
Definition Constants.h:141
constexpr uint32_t MaskZPA
Definition Constants.h:139
constexpr int IdZNA2
constexpr uint32_t MaskAllZPC
Definition Constants.h:145
constexpr int DbgZero
Definition Constants.h:207
constexpr int IdZNASum
constexpr uint32_t MaskAllZNC
Definition Constants.h:143
constexpr int IdZPC3
constexpr int IdZNA4
constexpr int IdZNAC
constexpr uint32_t MaskZPC
Definition Constants.h:144
constexpr int IdZPASum
uint32_t orbit
LHC orbit.
uint16_t bc
bunch crossing ID of interaction
uint32_t triggers
Definition BCRecData.h:34
o2::InteractionRecord ir
Definition BCRecData.h:32
double mSum[NH][NPAR][NPAR]
ZNA, ZPA, ZNC, ZPC, ZEM, ZNI, ZPI, ZPAX, ZPCX.
uint64_t mCTimeEnd
Time of processed time frame.
static constexpr const char * DN[NH]
Time of processed time frame.
uint64_t mCTimeBeg
Cumulated sums.
void centroidZPA(float &x, float &rms)
std::vector< float > TDCVal[NTDCChannels]
signal in ZDCs
BCRecData mCurB
End of sequence.
NElem getNEnergy() const
float EZDC(uint8_t ich) const
uint32_t ezdcDecoded
pattern of channels acquired
void init(const std::vector< o2::zdc::BCRecData > *RecBC, const std::vector< o2::zdc::ZDCEnergy > *Energy, const std::vector< o2::zdc::ZDCTDCData > *TDCData, const std::vector< uint16_t > *Info)
Trigger mask for printout.
const std::vector< uint16_t > & getDecodedInfo()
NElem getNInfo() const
void centroidZPC(float &x, float &rms)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
vec clear()