Project
Loading...
Searching...
No Matches
TOFChannelCalibratorSpec.h
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#ifndef O2_CALIBRATION_TOFCHANNEL_CALIBRATOR_H
13#define O2_CALIBRATION_TOFCHANNEL_CALIBRATOR_H
14
17
24#include "Framework/Task.h"
29#include "CCDB/CcdbApi.h"
30#include "CCDB/CcdbObjectInfo.h"
31#include <limits>
32#include "TFile.h"
34
35#include <TSystem.h>
36
37using namespace o2::framework;
38
39namespace o2
40{
41namespace calibration
42{
43
44template <class T>
46{
47
50
51 public:
52 explicit TOFChannelCalibDevice(std::shared_ptr<o2::base::GRPGeomRequest> req, bool useCCDB, bool attachChannelOffsetToLHCphase, bool isCosmics, bool perstrip = false, bool safe = false) : mCCDBRequest(req), mUseCCDB(useCCDB), mAttachToLHCphase(attachChannelOffsetToLHCphase), mCosmics(isCosmics), mDoPerStrip(perstrip), mSafeMode(safe) {}
53
55 {
57 int minEnt = ic.options().get<int>("min-entries"); //std::max(50, ic.options().get<int>("min-entries"));
58 int nb = std::max(500, ic.options().get<int>("nbins"));
59 mRange = ic.options().get<float>("range");
60 int isTest = ic.options().get<bool>("do-TOF-channel-calib-in-test-mode");
61 bool updateAtEORonly = ic.options().get<bool>("update-at-end-of-run-only");
62 auto slotL = ic.options().get<uint32_t>("tf-per-slot");
63 auto delay = ic.options().get<uint32_t>("max-delay");
64 auto updateInterval = ic.options().get<uint32_t>("update-interval");
65 auto deltaUpdateInterval = ic.options().get<uint32_t>("delta-update-interval");
66 mCalibrator = std::make_unique<o2::tof::TOFChannelCalibrator<T>>(minEnt, nb, mRange);
67
68 mCalibrator->doPerStrip(mDoPerStrip);
69 mCalibrator->doSafeMode(mSafeMode);
70
71 // default behaviour is to have only 1 slot at a time, accepting everything for it till the
72 // minimum statistics is reached;
73 // if one defines a different slot length and delay,
74 // the usual time slot calibration behaviour is used;
75 // if one defines that the calibration should happen only at the end of the run,
76 // then the slot length and delay won't matter
77 mCalibrator->setSlotLength(slotL);
78 mCalibrator->setCheckIntervalInfiniteSlot(updateInterval);
79 mCalibrator->setCheckDeltaIntervalInfiniteSlot(deltaUpdateInterval);
80 mCalibrator->setMaxSlotsDelay(delay);
81
82 if (updateAtEORonly) { // has priority over other settings
83 mCalibrator->setUpdateAtTheEndOfRunOnly();
84 }
85
86 mCalibrator->setIsTest(isTest);
87 mCalibrator->setDoCalibWithCosmics(mCosmics);
88
89 // calibration objects set to zero
90 mPhase.addLHCphase(0, 0);
92
93 if (gSystem->AccessPathName("localTimeSlewing.root") == false) {
94 TFile* fsleewing = TFile::Open("localTimeSlewing.root");
95 if (fsleewing) {
96 TimeSlewing* ob = (TimeSlewing*)fsleewing->Get("ccdb_object");
97 mTimeSlewing = *ob;
98 return;
99 }
100 } else {
101 for (int ich = 0; ich < TimeSlewing::NCHANNELS; ich++) {
102 mTimeSlewing.addTimeSlewingInfo(ich, 0, 0);
104 int channelInSector = ich % TimeSlewing::NCHANNELXSECTOR;
105 mTimeSlewing.setFractionUnderPeak(sector, channelInSector, 1);
106 }
107 }
108 }
109
110 //_________________________________________________________________
111 void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
112 {
114 mUpdateCCDB = false;
115 if (matcher == ConcreteDataMatcher("TOF", "LHCphaseCal", 0)) {
116 mUpdateCCDB = true;
117 return;
118 }
119 if (matcher == ConcreteDataMatcher("TOF", "ChannelCalibCal", 0)) {
120 mUpdateCCDB = true;
121 return;
122 }
123 }
124
126 {
128 long startTimeLHCphase = 0;
129 long startTimeChCalib = 0;
130 o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
131 auto tfcounter = mCalibrator->getCurrentTFInfo().tfCounter;
132
133 if (mUseCCDB) { // read calibration objects from ccdb
134 const auto lhcPhaseIn = pc.inputs().get<LHCphase*>("tofccdbLHCphase");
135 const auto channelCalibIn = pc.inputs().get<TimeSlewing*>("tofccdbChannelCalib");
136
137 if (!mcalibTOFapi) {
138 LHCphase* lhcPhase = new LHCphase(std::move(*lhcPhaseIn));
139 TimeSlewing* channelCalib = new TimeSlewing(std::move(*channelCalibIn));
140 mcalibTOFapi = new o2::tof::CalibTOFapi(long(0), lhcPhase, channelCalib);
141 mUpdateCCDB = false;
142 } else {
143 // if the calib objects were updated, we need to update the mcalibTOFapi
144 if (mUpdateCCDB) {
145 delete mcalibTOFapi;
146 LHCphase* lhcPhase = new LHCphase(*lhcPhaseIn);
147 TimeSlewing* channelCalib = new TimeSlewing(std::move(*channelCalibIn));
148 mcalibTOFapi = new o2::tof::CalibTOFapi(long(0), lhcPhase, channelCalib);
149 mUpdateCCDB = false;
150 }
151 }
152 } else { // we use "fake" initial calibrations
153 if (!mcalibTOFapi) {
154 mcalibTOFapi = new o2::tof::CalibTOFapi(long(0), &mPhase, &mTimeSlewing);
155 }
156 }
157
158 mCalibrator->setCalibTOFapi(mcalibTOFapi);
159
160 auto data = pc.inputs().get<gsl::span<T>>("input");
161 LOG(detail) << "Processing TF " << tfcounter << " with " << data.size() << " tracks";
162
163 if (mUseCCDB) { // setting the timestamp to get the LHCPhase correction; if we don't use CCDB, then it can stay to 0 as set when creating the calibTOFapi above
164 const auto tfOrbitFirst = pc.services().get<o2::framework::TimingInfo>().firstTForbit;
165 mcalibTOFapi->setTimeStamp(0.001 * (o2::base::GRPGeomHelper::instance().getOrbitResetTimeMS() + tfOrbitFirst * o2::constants::lhc::LHCOrbitMUS * 0.001)); // in seconds
166 }
167
168 mCalibrator->process(data);
169
170 sendOutput(pc.outputs());
171 }
172
174 {
175 mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
176 sendOutput(ec.outputs());
177 }
178
179 private:
180 std::unique_ptr<o2::tof::TOFChannelCalibrator<T>> mCalibrator;
181 std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
182 o2::tof::CalibTOFapi* mcalibTOFapi = nullptr;
183 LHCphase mPhase;
184 TimeSlewing mTimeSlewing;
185 float mRange = 24000.f;
186 bool mUseCCDB = false;
187 bool mAttachToLHCphase = false; // whether to use or not previously defined LHCphase
188 bool mCosmics = false;
189 bool mDoPerStrip = false;
190 bool mSafeMode = false;
191 bool mUpdateCCDB = false;
192
193 //________________________________________________________________
194 void sendOutput(DataAllocator& output)
195 {
196 // extract CCDB infos and calibration objects, convert it to TMemFile and send them to the output
197 // TODO in principle, this routine is generic, can be moved to Utils.h
199 const auto& payloadVec = mCalibrator->getTimeSlewingVector();
200 auto& infoVec = mCalibrator->getTimeSlewingInfoVector(); // use non-const version as we update it
201 assert(payloadVec.size() == infoVec.size());
202
203 for (uint32_t i = 0; i < payloadVec.size(); i++) {
204 auto& w = infoVec[i];
205 auto image = o2::ccdb::CcdbApi::createObjectImage(&payloadVec[i], &w);
206 LOG(info) << "Sending object " << w.getPath() << "/" << w.getFileName() << " of size " << image->size()
207 << " bytes, valid for " << w.getStartValidityTimestamp() << " : " << w.getEndValidityTimestamp();
208
209 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "TOF_CHANCALIB", i}, *image.get()); // vector<char>
210 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "TOF_CHANCALIB", i}, w); // root-serialized
211 }
212 if (payloadVec.size()) {
213 mCalibrator->initOutput(); // reset the outputs once they are already sent
214 }
215 }
216};
217
218} // namespace calibration
219
220namespace framework
221{
222
223template <class T>
224DataProcessorSpec getTOFChannelCalibDeviceSpec(bool useCCDB, bool attachChannelOffsetToLHCphase = false, bool isCosmics = false, bool perstrip = false, bool safe = false)
225{
228
229 std::vector<OutputSpec> outputs;
230 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TOF_CHANCALIB"}, Lifetime::Sporadic);
231 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TOF_CHANCALIB"}, Lifetime::Sporadic);
232
233 std::vector<InputSpec> inputs;
234 if (!isCosmics) {
235 inputs.emplace_back("input", "TOF", "CALIBDATA");
236 } else {
237 inputs.emplace_back("input", "TOF", "INFOCALCLUS");
238 }
239 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
240 true, // GRPECS=true
241 false, // GRPLHCIF
242 false, // GRPMagField
243 false, // askMatLUT
245 inputs);
246 if (useCCDB) {
247 inputs.emplace_back("tofccdbLHCphase", o2::header::gDataOriginTOF, "LHCphase", 0, Lifetime::Condition, ccdbParamSpec("TOF/Calib/LHCphase"));
248 inputs.emplace_back("tofccdbChannelCalib", o2::header::gDataOriginTOF, "ChannelCalib", 0, Lifetime::Condition, ccdbParamSpec("TOF/Calib/ChannelCalib"));
249 }
250
251 return DataProcessorSpec{
252 "calib-tofchannel-calibration",
253 inputs,
254 outputs,
255 AlgorithmSpec{adaptFromTask<device>(ccdbRequest, useCCDB, attachChannelOffsetToLHCphase, isCosmics, perstrip, safe)},
256 Options{
257 {"min-entries", VariantType::Int, 500, {"minimum number of entries to fit channel histos"}},
258 {"nbins", VariantType::Int, 1000, {"number of bins for t-texp"}},
259 {"range", VariantType::Float, 24000.f, {"range for t-text"}},
260 {"do-TOF-channel-calib-in-test-mode", VariantType::Bool, false, {"to run in test mode for simplification"}},
261 {"ccdb-path", VariantType::String, o2::base::NameConf::getCCDBServer(), {"Path to CCDB"}},
262 {"update-at-end-of-run-only", VariantType::Bool, false, {"to update the CCDB only at the end of the run; has priority over calibrating in time slots"}},
263 {"tf-per-slot", VariantType::UInt32, 0u, {"number of TFs per calibration time slot, if 0: close once statistics reached"}},
264 {"max-delay", VariantType::UInt32, 0u, {"number of slots in past to consider"}},
265 {"update-interval", VariantType::UInt32, 10u, {"number of TF after which to try to finalize calibration"}},
266 {"delta-update-interval", VariantType::UInt32, 10u, {"number of TF after which to try to finalize calibration, if previous attempt failed"}}}};
267}
268
269} // namespace framework
270} // namespace o2
271
272#endif
Class to store the output of the matching to TOF for calibration.
Utils and constants for calibration and related workflows.
unsigned int uint32_t
int32_t i
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
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 Print launch bounds used for RTC code as debugging for exit after Allow RTC with slave GPUReconstruction instances with optConstexpr and optSpecialcode Maximum number of RTC cache files per backend in the cache the oldest are Prepend RTC compilation commands by this string Load a parameter object containing the launch bounds from a file h configStandalone Processing proc_param TPC Cluster Z Error Parameterization h configStandalone Processing settings for neural network proc_nn std::string Specify inference device(cpu(default), rocm, cuda)") AddOption(nnInferenceDeviceId
Helper for geometry and GRP related CCDB requests.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of the Names Generator class.
void checkUpdates(o2::framework::ProcessingContext &pc)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static std::string getCCDBServer()
Definition NameConf.cxx:123
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void init(o2::framework::InitContext &ic) final
TOFChannelCalibDevice(std::shared_ptr< o2::base::GRPGeomRequest > req, bool useCCDB, bool attachChannelOffsetToLHCphase, bool isCosmics, bool perstrip=false, bool safe=false)
void run(o2::framework::ProcessingContext &pc) final
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:109
static constexpr long INFINITE_TIMESTAMP_SECONDS
void addLHCphase(int timestamp, float phaseLHC)
void addTimeSlewingInfo(int channel, float tot, float time)
void setFractionUnderPeak(int sector, int channel, float value)
void setTimeStamp(long t)
Definition CalibTOFapi.h:66
GLeglImageOES image
Definition glcorearb.h:4021
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:578
constexpr TFType INFINITE_TF
Definition TimeSlot.h:30
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static void fillTFIDInfo(o2::framework::ProcessingContext &pc, o2::dataformats::TFIDInfo &ti)
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"