Project
Loading...
Searching...
No Matches
NoiseCalibEPN.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"
21
22using namespace o2::zdc;
23
25{
26 if (mVerbosity > DbgMedium) {
27 mModuleConfig->print();
28 }
29
30 // Inspect reconstruction parameters
32 ropt.print();
33 mRopt = (o2::zdc::RecoParamZDC*)&ropt;
34
35 // Inspect calibration parameters
36 const auto& opt = CalibParamZDC::Instance();
37 if (mVerbosity > DbgMedium) {
38 opt.print();
39 }
40 if (opt.debugOutput == true) {
42 }
43
44 int nbx = 4096 * NTimeBinsPerBC - NTimeBinsPerBC + 1;
45 double xmin = -2048 * NTimeBinsPerBC - 0.5;
46 double xmax = 2047 * NTimeBinsPerBC + 0.5;
47
48 for (int isig = 0; isig < NChannels; isig++) {
49 // Baseline single samples
50 if (mH[0][isig] == nullptr) {
51 mH[0][isig] = new o2::dataformats::FlatHisto1D<double>(4096, -2048.5, 2047.5);
52 } else {
53 mH[0][isig]->clear();
54 }
55 // Baseline single samples (cumulated)
56 if (mHSum[0][isig] == nullptr) {
57 if (mSaveDebugHistos) {
58 mHSum[0][isig] = new o2::dataformats::FlatHisto1D<double>(4096, -2048.5, 2047.5);
59 }
60 } else {
61 mHSum[0][isig]->clear();
62 }
63 // Bunch average of baseline samples
64 if (mH[1][isig] == nullptr) {
65 mH[1][isig] = new o2::dataformats::FlatHisto1D<double>(nbx, xmin, xmax);
66 } else {
67 mH[1][isig]->clear();
68 }
69 // Bunch average of baseline samples (cumulated)
70 if (mHSum[1][isig] == nullptr) {
71 if (mSaveDebugHistos) {
72 mHSum[1][isig] = new o2::dataformats::FlatHisto1D<double>(nbx, xmin, xmax);
73 }
74 } else {
75 mHSum[1][isig]->clear();
76 }
77 // Difference between single samples and average
78 if (mH[2][isig] == nullptr) {
79 mH[2][isig] = new o2::dataformats::FlatHisto1D<double>(nbx, xmin / double(NTimeBinsPerBC), xmax / double(NTimeBinsPerBC));
80 } else {
81 mH[2][isig]->clear();
82 }
83 // Difference between single samples and average (cumulated)
84 if (mHSum[2][isig] == nullptr) {
85 if (mSaveDebugHistos) {
86 mHSum[2][isig] = new o2::dataformats::FlatHisto1D<double>(nbx, xmin / double(NTimeBinsPerBC), xmax / double(NTimeBinsPerBC));
87 }
88 } else {
89 mHSum[2][isig]->clear();
90 }
91 }
92
93 mData.clear();
95
96 // Fill maps to decode the pattern of channels with hit
97 for (int ich = 0; ich < NChannels; ich++) {
98 // If the reconstruction parameters were not manually set
99 if (ropt.amod[ich] < 0 || ropt.ach[ich] < 0) {
100 for (int im = 0; im < NModules; im++) {
101 for (uint32_t ic = 0; ic < NChPerModule; ic++) {
102 if (mModuleConfig->modules[im].channelID[ic] == ich && mModuleConfig->modules[im].readChannel[ic]) {
103 ropt.amod[ich] = im;
104 ropt.ach[ich] = ic;
105 // Fill mask to identify all channels
106 mChMask[ich] = (0x1 << (4 * im + ic));
107 goto next_ich;
108 }
109 }
110 }
111 }
112 next_ich:;
113 if (mVerbosity > DbgMinimal) {
114 LOG(info) << "Channel " << ich << "(" << ChannelNames[ich] << ") mod " << ropt.amod[ich] << " ch " << ropt.ach[ich];
115 }
116 }
117
118 mInitDone = true;
119 return 0;
120}
121
122//______________________________________________________________________________
124{
125 mData.clear();
126 for (int ihis = 0; ihis < NoiseCalibData::NHA; ihis++) {
127 for (int isig = 0; isig < NChannels; isig++) {
128 mH[ihis][isig]->clear();
129 }
130 }
131}
132
133//______________________________________________________________________________
134int NoiseCalibEPN::process(const gsl::span<const o2::zdc::OrbitData>& orbitData, const gsl::span<const o2::zdc::BCData>& bcdata, const gsl::span<const o2::zdc::ChannelData>& chdata)
135{
136 if (!mInitDone) {
137 init();
138 }
139
140 // Prepare orbit information only if we need to fill debug histograms
141 std::map<uint32_t, int> orbit; // Orbit map for fast access
142 float offset[NChannels]; // Offset in current orbit
143 for (int ich = 0; ich < NChannels; ich++) {
144 offset[ich] = std::numeric_limits<float>::infinity();
145 }
146 if (mSaveDebugHistos) {
147 int norb = orbitData.size();
148 // if (mVerbosity >= DbgFull) {
149 // LOG(info) << "Dump of pedestal data lookup table";
150 // }
151 for (int iorb = 0; iorb < norb; iorb++) {
152 orbit[orbitData[iorb].ir.orbit] = iorb;
153 // if (mVerbosity >= DbgFull) {
154 // LOG(info) << "orbitData[" << orbitData[iorb].ir.orbit << "] = " << iorb;
155 // }
156 }
157 }
158
159 auto nbc = bcdata.size();
160 for (int ibc = 1; ibc < nbc; ibc++) {
161 auto& bcp = bcdata[ibc - 1];
162 auto& bcc = bcdata[ibc];
163 if (bcc.ir.bc != 0 || bcp.ir.bc != 3563 || (bcp.ir.orbit + 1) != bcc.ir.orbit) {
164 continue;
165 }
166 auto chEnt = bcc.ref.getFirstEntry();
167 auto nch = bcc.ref.getEntries();
168 // Extract pedestal information only if we need to fill debug histograms
169 if (mSaveDebugHistos) {
170 std::map<uint32_t, int>::iterator it = orbit.find(bcc.ir.orbit);
171 if (it != orbit.end()) {
172 auto& orbitdata = orbitData[it->second];
173 for (int ich = 0; ich < NChannels; ich++) {
174 auto myped = float(orbitdata.data[ich]) * mModuleConfig->baselineFactor;
175 if (myped >= ADCMin && myped <= ADCMax) {
176 // Pedestal information is present for this channel
177 offset[ich] = myped;
178 } else {
179 offset[ich] = std::numeric_limits<float>::infinity();
180 }
181 }
182 } else {
183 for (int ich = 0; ich < NChannels; ich++) {
184 offset[ich] = std::numeric_limits<float>::infinity();
185 }
186 }
187 }
188
189 for (int ich = 0; ich < nch; ich++) {
190 const auto& chd = chdata[chEnt++];
191 if (chd.id < NChannels) {
192 // Check trigger flags
193 ModuleTriggerMapData mtc, mtp;
194 mtp.w = bcp.moduleTriggers[mRopt->amod[chd.id]];
195 mtc.w = bcc.moduleTriggers[mRopt->amod[chd.id]];
196 if (mtp.f.Auto_m // Auto trigger in bunch -2
197 || mtp.f.Auto_0 || mtp.f.Alice_0 || (bcp.triggers & mChMask[chd.id]) // Trigger or hit in bunch -1
198 || mtc.f.Auto_0 || mtc.f.Alice_0 || (bcc.triggers & mChMask[chd.id]) // Trigger or hit in bunch -2
199 || mtc.f.Auto_1 || mtc.f.Alice_1 // Trigger in bunch +1
200 ) {
201#ifdef O2_ZDC_DEBUG
202 printf("%u.%04u SKIP %s%s%s%s%s%s%s%s%s\n",
203 mtp.f.Auto_m ? "p.Auto_m" : "",
204 mtp.f.Auto_0 ? "p.Auto_0" : "",
205 mtp.f.Alice_0 ? "p.Alice_0" : "",
206 (bcp.triggers & mChMask[chd.id]) ? "p.HIT" : "",
207 mtc.f.Auto_0 ? "c.Auto_0" : "",
208 mtc.f.Alice_0 ? "c.Alice_0" : "",
209 (bcc.triggers & mChMask[chd.id]) ? "c.HIT" : "",
210 mtc.f.Auto_1 ? "c.Auto_1" : "",
211 mtc.f.Alice_1 ? "c.Alice_1" : "");
212#endif
213 continue;
214 }
215 int ss = 0;
216 int sq = 0;
217 for (int is = 0; is < NTimeBinsPerBC; is++) {
218 auto s = chd.data[is];
219 mH[0][chd.id]->fill(s);
220 if (mSaveDebugHistos) {
221 mHSum[0][chd.id]->fill(s);
222 }
223 ss += s;
224 sq += s * s;
225 }
226 int v = NTimeBinsPerBC * sq - ss * ss;
227 if (v > 0) {
228 // This should always be the case
229 mData.addEntry(chd.id, v);
230 if (mSaveDebugHistos) {
231 mDataSum.addEntry(chd.id, v);
232 }
233 }
234 // Debug histograms
235 mH[1][chd.id]->fill(ss);
236 mH[2][chd.id]->fill(ss / double(NTimeBinsPerBC) - offset[chd.id]);
237 if (mSaveDebugHistos) {
238 mHSum[1][chd.id]->fill(ss);
239 mHSum[2][chd.id]->fill(ss / double(NTimeBinsPerBC) - offset[chd.id]);
240 }
241 }
242 }
243 }
244 return 0;
245}
246
247//______________________________________________________________________________
249{
250 if (mSaveDebugHistos) {
251 if (mVerbosity > DbgZero) {
252 mDataSum.print();
253 }
255 }
256 return 0;
257}
258
259//______________________________________________________________________________
260int NoiseCalibEPN::saveDebugHistos(const std::string fn)
261{
262 if (mVerbosity > DbgZero) {
263 LOG(info) << "Saving EPN debug histograms on file " << fn;
264 }
265 int ierr = mDataSum.saveDebugHistos(fn, true);
266 if (ierr != 0) {
267 return ierr;
268 }
269 TDirectory* cwd = gDirectory;
270 // N.B. We update file here because it has just been recreated
271 TFile* f = new TFile(fn.data(), "update");
272 if (f->IsZombie()) {
273 LOG(error) << "Cannot update file: " << fn;
274 return 1;
275 }
276 for (int32_t is = 0; is < NChannels; is++) {
277 auto p = mHSum[0][is]->createTH1F(TString::Format("hs%d", is).Data());
278 p->SetTitle(TString::Format("EPN Baseline samples %s", ChannelNames[is].data()));
279 p->Write("", TObject::kOverwrite);
280 }
281 for (int32_t is = 0; is < NChannels; is++) {
282 auto p = mHSum[1][is]->createTH1F(TString::Format("hss%d", is).Data());
283 p->SetTitle(TString::Format("EPN Bunch sum of samples %s", ChannelNames[is].data()));
284 p->Write("", TObject::kOverwrite);
285 }
286 for (int32_t is = 0; is < NChannels; is++) {
287 auto p = mHSum[2][is]->createTH1F(TString::Format("hsd%d", is).Data());
288 p->SetTitle(TString::Format("EPN Baseline estimation difference %s", ChannelNames[is].data()));
289 p->Write("", TObject::kOverwrite);
290 }
291 f->Close();
292 cwd->cd();
293 return 0;
294}
ZDC calibration common parameters.
uint64_t orbit
Definition RawEventData.h:6
unsigned int uint32_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
configStandalone Reconstruction rec_tpc float
char error[CURL_ERROR_SIZE]
NoiseCalibData mDataSum
int saveDebugHistos(const std::string fn="ZDCNoiseCalibEPN.root")
std::array< std::array< o2::dataformats::FlatHisto1D< double > *, NChannels >, NoiseCalibData::NHA > mHSum
int process(const gsl::span< const o2::zdc::OrbitData > &orbitdata, const gsl::span< const o2::zdc::BCData > &bcdata, const gsl::span< const o2::zdc::ChannelData > &chdata)
std::array< std::array< o2::dataformats::FlatHisto1D< double > *, NChannels >, NoiseCalibData::NHA > mH
const GLdouble * v
Definition glcorearb.h:832
GLdouble f
Definition glcorearb.h:310
GLintptr offset
Definition glcorearb.h:660
constexpr int NModules
Definition Constants.h:68
constexpr int NTimeBinsPerBC
Definition Constants.h:53
constexpr int NChPerModule
Definition Constants.h:69
constexpr int NChannels
Definition Constants.h:65
constexpr int DbgMinimal
Definition Constants.h:208
constexpr int DbgZero
Definition Constants.h:207
constexpr int ADCMin
Definition Constants.h:76
constexpr std::string_view ChannelNames[]
Definition Constants.h:147
constexpr int DbgMedium
Definition Constants.h:209
constexpr int ADCMax
Definition Constants.h:76
std::array< Module, MaxNModules > modules
int saveDebugHistos(const std::string fn, bool is_epn=false)
static constexpr int NHA
void addEntry(int isig, uint32_t val)
int32_t amod[NChannels]
int32_t ach[NChannels]
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
struct ModuleTriggerMap f
Definition BCData.h:48