Project
Loading...
Searching...
No Matches
TDCCalibEPN.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"
26#include "ZDCReconstruction/ZDCTDCParam.h" //added by me
27#include "Framework/Logger.h"
28
29using namespace o2::zdc;
30
32{
33 if (mTDCCalibConfig == nullptr) {
34 LOG(fatal) << "o2::zdc::TDCCalibEPN: missing configuration object";
35 return -1;
36 }
37
38 // Inspect calibration parameters
39 const auto& opt = CalibParamZDC::Instance();
40 opt.print();
41 if (opt.debugOutput == true) {
43 }
44
45 clear();
46 auto* cfg = mTDCCalibConfig;
47 int ih;
48 // clang-format off
49 for (int iTDC = 0; iTDC < NTDC; iTDC++) {
50 mTDC[iTDC] = new o2::dataformats::FlatHisto1D<float>(cfg->nb1[iTDC], cfg->amin1[iTDC], cfg->amax1[iTDC]);
51 if(mSaveDebugHistos){
52 mTDCSum[iTDC] = new o2::dataformats::FlatHisto1D<float>(cfg->nb1[iTDC], cfg->amin1[iTDC], cfg->amax1[iTDC]);
53 }
54 }
55 // clang-format on
56 mInitDone = true;
57 return 0;
58}
59
60//----//
61
62int TDCCalibEPN::process(const gsl::span<const o2::zdc::BCRecData>& RecBC,
63 const gsl::span<const o2::zdc::ZDCEnergy>& Energy,
64 const gsl::span<const o2::zdc::ZDCTDCData>& TDCData,
65 const gsl::span<const uint16_t>& Info)
66{
67 if (!mInitDone) {
68 init();
69 }
70 if (mVerbosity > DbgMinimal) {
71 LOG(info) << "o2::zdc::TDCCalibEPN processing " << RecBC.size() << " b.c. @ TS " << mData.mCTimeBeg << " : " << mData.mCTimeEnd;
72 }
74 ev.init(RecBC, Energy, TDCData, Info);
75 while (ev.next()) {
76 if (ev.getNInfo() > 0) {
77 auto& decodedInfo = ev.getDecodedInfo();
78 for (uint16_t info : decodedInfo) {
79 uint8_t ch = (info >> 10) & 0x1f;
80 uint16_t code = info & 0x03ff;
81 // hmsg->Fill(ch, code);
82 }
83 if (mVerbosity > DbgMinimal) {
84 ev.print();
85 }
86 // Need clean data (no messages)
87 // We are sure there is no pile-up in any channel (too restrictive?)
88 continue;
89 }
90 if (ev.getNEnergy() > 0 && ev.mCurB.triggers == 0) {
91 LOGF(info, "%9u.%04u Untriggered bunch", ev.mCurB.ir.orbit, ev.mCurB.ir.bc);
92 // Skip!
93 continue;
94 }
95
96 // Fill 1d histograms with tdc values. Check if channel is acquired or not
97 for (int itdc = 0; itdc < NTDC; itdc++) { // loop over all TDCs
98 int nhits = ev.NtdcV(itdc);
99
100 if (nhits > 0) {
101 // call fill function to fill histo
102 fill1D(itdc, nhits, ev);
103 }
104 }
105 }
106 return 0;
107}
108
109//----//
110
112{
113 if (mVerbosity > DbgZero) {
114 LOGF(info, "TDCCalibEPN::endOfRun ts (%llu:%llu)", mData.mCTimeBeg, mData.mCTimeEnd);
115 if (mVerbosity > DbgMinimal) {
116 for (int ih = 0; ih < NTDC; ih++) {
117 LOGF(info, "%s %i events and cuts (%g:%g)", TDCCalibData::CTDC[ih], mData.entries[ih], mTDCCalibConfig->cutLow[ih], mTDCCalibConfig->cutHigh[ih]);
118 }
119 }
120 }
121 if (mSaveDebugHistos) {
122 write();
123 }
124 return 0;
125}
126
127//----//
128
130{
131 for (int32_t ii = 0; ii < NTDC; ii++) {
132 if (mTDC[ii]) {
133 mTDC[ii]->clear();
134 }
135 mData.entries[ii] = 0;
136 }
137 mData.mCTimeBeg = 0;
138 mData.mCTimeEnd = 0;
139}
140
141//----//
142
143void TDCCalibEPN::fill1D(int iTDC, int nHits, o2::zdc::RecEventFlat ev)
144{
145 // Get TDC values
146 float tdcVal[nHits];
147 for (int i = 0; i < nHits; i++) {
148 tdcVal[i] = ev.tdcV(iTDC, i);
149 }
150
151 // Fill histo
152 for (int hit = 0; hit < nHits; hit++) {
153 mTDC[iTDC]->fill(tdcVal[hit]);
154 if (mSaveDebugHistos) {
155 mTDCSum[iTDC]->fill(tdcVal[hit]);
156 }
157 }
158 mData.entries[iTDC] += nHits;
159}
160
161//----//
162
163int TDCCalibEPN::write(const std::string fn)
164{
165 if (mVerbosity > DbgZero) {
166 LOG(info) << "Saving EPN debug histograms on file " << fn;
167 }
168 TDirectory* cwd = gDirectory;
169 TFile* f = new TFile(fn.data(), "recreate");
170 if (f->IsZombie()) {
171 LOG(error) << "Cannot create file: " << fn;
172 return 1;
173 }
174 for (int32_t ih = 0; ih < NTDC; ih++) {
175 if (mTDCSum[ih]) {
176 auto p = mTDCSum[ih]->createTH1F(TDCCalibData::CTDC[ih]);
177 p->SetTitle(TDCCalibData::CTDC[ih]);
178 p->Write("", TObject::kOverwrite);
179 if (mVerbosity > DbgMinimal) {
180 LOG(info) << p->GetName() << " entries: " << p->GetEntries();
181 }
182 }
183 }
184 f->Close();
185 cwd->cd();
186 return 0;
187}
ZDC calibration common parameters.
int32_t i
TDC calibration intermediate data.
ZDC Energy calibration.
Parameters to correct TDCs (produced by QA)
ZDC Tower calibration.
int write(const std::string fn="ZDCTDCCalibEPN.root")
void fill1D(int iTDC, int nHits, o2::zdc::RecEventFlat ev)
TDCCalibData mData
Definition TDCCalibEPN.h:66
std::array< o2::dataformats::FlatHisto1D< float > *, NTDC > mTDC
Definition TDCCalibEPN.h:68
std::array< o2::dataformats::FlatHisto1D< float > *, NTDC > mTDCSum
Definition TDCCalibEPN.h:69
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 NTDC
Definition TDCCalibEPN.h:50
GLdouble f
Definition glcorearb.h:310
constexpr int DbgMinimal
Definition Constants.h:208
constexpr int DbgZero
Definition Constants.h:207
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
int NtdcV(uint8_t ich) const
float tdcV(uint8_t ich, uint64_t ipos) const
BCRecData mCurB
End of sequence.
NElem getNEnergy() const
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
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.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"