Project
Loading...
Searching...
No Matches
VDriftHelper.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
18#include "Framework/Logger.h"
23
24using namespace o2::tpc;
25using namespace o2::framework;
26
27//________________________________________________________
29{
30 const auto& gaspar = o2::tpc::ParameterGas::Instance();
31 const auto& detpar = o2::tpc::ParameterDetector::Instance();
32 const auto& elpar = o2::tpc::ParameterElectronics::Instance();
33 mVD.corrFact = 1.0;
34 mVD.refVDrift = gaspar.DriftV;
35 mVD.refTimeOffset = detpar.DriftTimeOffset * elpar.ZbinWidth; // convert time bins to \mus
36 // was it imposed from the command line?
37 mVD.creationTime = 1; // just to be above 0
38 if (o2::conf::ConfigurableParam::getProvenance("TPCGasParam.DriftV") == o2::conf::ConfigurableParam::EParamProvenance::kRT) { // we stick to this value
39 mVD.creationTime = std::numeric_limits<long>::max();
40 mForceParamDrift = true;
41 LOGP(info, "TPC VDrift was set from command line to {}, will neglect update from CCDB", mVD.refVDrift);
42 }
43 if (o2::conf::ConfigurableParam::getProvenance("TPCDetParam.DriftTimeOffset") == o2::conf::ConfigurableParam::EParamProvenance::kRT) { // we stick to this value
44 mVD.creationTime = std::numeric_limits<long>::max();
45 mForceParamOffset = true;
46 LOGP(info, "TPC dridt time offset was set from command line to {} mus ({} TB), will neglect update from CCDB",
47 mVD.refTimeOffset, detpar.DriftTimeOffset);
48 }
49
50 mUpdated = true;
52}
53
54//________________________________________________________
55void VDriftHelper::accountLaserCalibration(const LtrCalibData* calib, long fallBackTimeStamp)
56{
57 if (!calib || mForceParamDrift) { // laser may set only DriftParam (the offset is 0)
58 return;
59 }
60 if (!calib->isValid()) {
61 LOGP(warn, "Ignoring invalid laser calibration (corrections: A-side={}, C-side={}, NTracks: A-side={} C-side={})", calib->dvCorrectionA, calib->dvCorrectionC, calib->nTracksA, calib->nTracksC);
62 return;
63 }
64 // old entries of laser calib have no update time assigned
65 long updateTS = calib->creationTime > 0 ? calib->creationTime : fallBackTimeStamp;
66 LOG(info) << "accountLaserCalibration " << calib->refVDrift << " / " << calib->getDriftVCorrection() << " t " << updateTS << " vs " << mVDLaser.creationTime;
67 // old entries of laser calib have no reference assigned
68 float ref = calib->refVDrift > 0. ? calib->refVDrift : o2::tpc::ParameterGas::Instance().DriftV;
69 float corr = calib->getDriftVCorrection();
70 if (corr > 0.) { // laser correction is inverse multiplicative
71 static bool firstCall = true;
72 auto prevRef = mVDLaser.refVDrift;
74 mVDLaser.corrFact = 1. / corr;
77 mUpdated = true;
79 if (mMayRenormSrc & (0x1U << Source::Laser)) { // this was 1st setting?
80 if (corr != 1.f) { // this may happen if old-style (non-normalized) standalone or non-normalized run-time laset calibration is used
81 LOGP(warn, "VDriftHelper: renorming initinal TPC refVDrift={}/correction={} to {}/1.0, source: {}", mVDLaser.refVDrift, mVDLaser.corrFact, mVDLaser.getVDrift(), getSourceName(mSource));
82 mVDLaser.normalize(); // renorm reference to have correction = 1.
83 }
84 mMayRenormSrc &= ~(0x1U << Source::Laser); // unset MayRenorm
85 } else if (ref != prevRef) { // we want to keep the same reference over the run, this may happen if run-time laser calibration is supplied
86 LOGP(warn, "VDriftHelper: renorming updated TPC refVDrift={}/correction={} previous refVDrift {}, source: {}", mVDLaser.refVDrift, mVDLaser.corrFact, prevRef, getSourceName(mSource));
87 mVDLaser.normalize(prevRef);
88 }
89 }
90}
91
92//________________________________________________________
94{
95 if (!calib || (mForceParamDrift && mForceParamOffset)) {
96 return;
97 }
98 LOG(info) << "accountDriftCorrectionITSTPCTgl " << calib->corrFact << " t " << calib->creationTime << " vs " << mVDTPCITSTgl.creationTime;
99 auto prevRefVDrift = mVDTPCITSTgl.refVDrift;
100 auto prevRefTOffs = mVDTPCITSTgl.refTimeOffset;
101 mVDTPCITSTgl = *calib;
102 mUpdated = true;
104 if (mMayRenormSrc & (0x1U << Source::ITSTPCTgl)) { // this was 1st setting?
105 if (!mForceParamDrift && mVDTPCITSTgl.corrFact != 1.f) { // this may happen if calibration from prevous run is used
106 LOGP(warn, "VDriftHelper: renorming initinal TPC refVDrift={}/correction={} to {}/1.0, source: {}", mVDTPCITSTgl.refVDrift, mVDTPCITSTgl.corrFact, mVDTPCITSTgl.getVDrift(), getSourceName(mSource));
107 mVDTPCITSTgl.normalize(); // renorm reference to have correction = 1.
108 }
110 LOGP(warn, "VDriftHelper: renorming initinal TPC refTimeOffset={}/correction={} to {}/0.0, source: {}", mVDTPCITSTgl.refTimeOffset, mVDTPCITSTgl.timeOffsetCorr, mVDTPCITSTgl.getTimeOffset(), getSourceName());
112 }
113 mMayRenormSrc &= ~(0x1U << Source::ITSTPCTgl); // unset MayRenorm
114 } else {
115 if (!mForceParamDrift && mVDTPCITSTgl.refVDrift != prevRefVDrift) { // we want to keep the same reference over the run, this should not happen!
116 LOGP(warn, "VDriftHelper: renorming updated TPC refVDrift={}/correction={} previous refVDrift {}, source: {}", mVDTPCITSTgl.refVDrift, mVDTPCITSTgl.corrFact, prevRefVDrift, getSourceName());
117 mVDTPCITSTgl.normalize(prevRefVDrift);
118 }
119 if (!mForceParamOffset && mVDTPCITSTgl.refTimeOffset != prevRefTOffs) { // we want to keep the same reference over the run, this should not happen!
120 LOGP(warn, "VDriftHelper: renorming updated TPC refTimeOffset={}/correction={} previous refTimeOffset {}, source: {}", mVDTPCITSTgl.refTimeOffset, mVDTPCITSTgl.timeOffsetCorr, prevRefTOffs, getSourceName());
121 mVDTPCITSTgl.normalizeOffset(prevRefTOffs);
122 }
123 }
124}
125
126//________________________________________________________
128{
129 if (mForceParamDrift && mForceParamOffset) { // fixed from the command line
130 return;
131 }
132 if (laser && !mForceParamDrift) {
133 pc.inputs().get<o2::tpc::LtrCalibData*>("laserCalib");
134 }
135 if (itstpcTgl) {
136 pc.inputs().get<o2::tpc::VDriftCorrFact*>("vdriftTgl");
137 }
138 if (mUpdated) { // there was a change
139 // prefer among laser and tgl VDrift the one with the latest update time
140 auto saveVD = mVD;
143
144 if (mForceParamDrift) {
145 mVD.refVDrift = saveVD.refVDrift;
146 mVD.corrFact = saveVD.corrFact;
147 mVD.corrFactErr = 0.f;
148 }
149 if (mForceParamOffset) {
150 mVD.refTimeOffset = saveVD.refTimeOffset;
151 mVD.timeOffsetCorr = 0.f;
152 }
154 auto loseCTime = loserVD.creationTime;
155 loserVD = mVD; // override alternative VD to avoid normalization problems later
156 loserVD.creationTime = loseCTime;
157 std::string rep = fmt::format("Prefer TPC Drift from {} with time {} to {} with time {}",
161 std::string impos = mForceParamDrift ? "VDrift" : "";
162 if (mForceParamOffset) {
163 impos += mForceParamDrift ? " and DriftTimeOffset" : "DriftTimeOffset";
164 }
165 rep += fmt::format(" but {} imposed from command line", impos);
166 }
167 LOGP(info, "{}", rep);
168 }
169}
170
171//________________________________________________________
172void VDriftHelper::requestCCDBInputs(std::vector<InputSpec>& inputs, bool laser, bool itstpcTgl)
173{
174 if (laser) {
175 addInput(inputs, {"laserCalib", "TPC", "CalibLaserTracks", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalLaserTracks))});
176 }
177 if (itstpcTgl) {
178 // VDrift calibration may change during the run (in opposite to Laser calibration, at least at the moment), so ask per-TF query
179 addInput(inputs, {"vdriftTgl", "TPC", "VDriftTgl", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalVDriftTgl), {}, 1)});
180 }
181}
182
183//________________________________________________________
184void VDriftHelper::addInput(std::vector<InputSpec>& inputs, InputSpec&& isp)
185{
186 if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
187 inputs.emplace_back(isp);
188 }
189}
190
191//________________________________________________________
193{
194 if (matcher == ConcreteDataMatcher("TPC", "VDriftTgl", 0)) {
196 return true;
197 }
198 if (matcher == ConcreteDataMatcher("TPC", "CalibLaserTracks", 0)) {
199 accountLaserCalibration(static_cast<LtrCalibData*>(obj));
200 return true;
201 }
202 return false;
203}
Simple interface to the CDB manager.
uint64_t laser
calibration data from laser track calibration
Definition of the parameter class for the detector.
Definition of the parameter class for the detector electronics.
Definition of the parameter class for the detector gas.
Helper class to extract VDrift from different sources.
static EParamProvenance getProvenance(const std::string &key)
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, bool laser=true, bool itstpcTgl=true)
VDriftCorrFact mVDLaser
void extractCCDBInputs(o2::framework::ProcessingContext &pc, bool laser=true, bool itstpcTgl=true)
static void addInput(std::vector< o2::framework::InputSpec > &inputs, o2::framework::InputSpec &&isp)
std::string_view getSourceName() const
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
static constexpr std::array< std::string_view, NSources > SourceNames
VDriftCorrFact mVD
void accountDriftCorrectionITSTPCTgl(const VDriftCorrFact *calib)
VDriftCorrFact mVDTPCITSTgl
void accountLaserCalibration(const LtrCalibData *calib, long fallBackTimeStamp=2)
GLint ref
Definition glcorearb.h:291
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
Global TPC definitions and constants.
Definition SimTraits.h:167
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:94
@ CalVDriftTgl
ITS-TPC difTgl vdrift calibration.
@ CalLaserTracks
Laser track calibration data.
float getDriftVCorrection() const
float dvCorrectionA
drift velocity correction factor A-Side (inverse multiplicative)
float dvCorrectionC
drift velocity correction factor C-Side (inverse multiplicative)
uint16_t nTracksC
number of tracks used for C-Side fit
long creationTime
time of creation
uint16_t nTracksA
number of tracks used for A-Side fit
float refTimeOffset
additive time offset reference (\mus)
float refVDrift
reference vdrift for which factor was extracted
float DriftV
Drift velocity [cm/us].
long creationTime
time of creation
void normalizeOffset(float newRefTimeOffset=-999.)
float corrFactErr
stat error of correction factor
void normalize(float newVRef=0.f)
float refTimeOffset
additive time offset reference (\mus)
float refVDrift
reference vdrift for which factor was extracted
float getTimeOffset() const
float timeOffsetCorr
additive time offset correction (\mus)
float corrFact
drift velocity correction factor (multiplicative)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"