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.
std::function< void(void *, const void *)> assign
int32_t i
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 First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
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
char error[CURL_ERROR_SIZE]
int32_t nEntries
Definition Objects.cxx:40
TDC calibration intermediate data.
Parameters to correct TDCs (produced by QA)
static std::string generateFileName(const std::string &inp)
Definition CcdbApi.cxx:905
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
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()