|
| 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 "TPCBase/CDBInterface.h" |
| 13 | +#include "TPCCalibration/VDriftHelper.h" |
| 14 | +#include "DataFormatsTPC/LtrCalibData.h" |
| 15 | +#include "TPCBase/ParameterGas.h" |
| 16 | +#include "Framework/Logger.h" |
| 17 | +#include "Framework/ProcessingContext.h" |
| 18 | +#include "Framework/CCDBParamSpec.h" |
| 19 | +#include "Framework/InputRecord.h" |
| 20 | +#include "Framework/ConcreteDataMatcher.h" |
| 21 | + |
| 22 | +using namespace o2::tpc; |
| 23 | +using namespace o2::framework; |
| 24 | + |
| 25 | +//________________________________________________________ |
| 26 | +VDriftHelper::VDriftHelper() |
| 27 | +{ |
| 28 | + const auto& gaspar = o2::tpc::ParameterGas::Instance(); |
| 29 | + mVD.corrFact = 1.0; |
| 30 | + mVD.refVDrift = gaspar.DriftV; |
| 31 | + // was it imposed from the command line? |
| 32 | + if (o2::conf::ConfigurableParam::getProvenance("TPCGasParam.DriftV") == o2::conf::ConfigurableParam::EParamProvenance::kRT) { // we stick to this value |
| 33 | + mVD.creationTime = std::numeric_limits<long>::max(); |
| 34 | + LOGP(info, "TPC VDrift was set from command line to {}, will neglect update from CCDB", mVD.refVDrift); |
| 35 | + } else { |
| 36 | + mVD.creationTime = 1; // just to be above 0 |
| 37 | + } |
| 38 | + mUpdated = true; |
| 39 | + mSource = Source::GasParam; |
| 40 | +} |
| 41 | + |
| 42 | +//________________________________________________________ |
| 43 | +void VDriftHelper::accountLaserCalibration(const LtrCalibData* calib, long fallBackTimeStamp) |
| 44 | +{ |
| 45 | + if (!calib) { |
| 46 | + return; |
| 47 | + } |
| 48 | + // old entries of laser calib have no update time assigned |
| 49 | + long updateTS = calib->creationTime > 0 ? calib->creationTime : fallBackTimeStamp; |
| 50 | + LOG(info) << "accountLaserCalibration " << calib->getDriftVCorrection() << " t " << updateTS << " vs " << mVD.creationTime; |
| 51 | + if (updateTS < mVD.creationTime) { // prefer current value |
| 52 | + return; |
| 53 | + } |
| 54 | + // old entries of laser calib have no reference assigned |
| 55 | + float ref = calib->refVDrift > 0. ? calib->refVDrift : o2::tpc::ParameterGas::Instance().DriftV; |
| 56 | + float corr = calib->getDriftVCorrection(); |
| 57 | + if (corr > 0.) { // laser correction is inverse multiplicative |
| 58 | + mVD.refVDrift = ref; |
| 59 | + mVD.corrFact = 1. / corr; |
| 60 | + mUpdated = true; |
| 61 | + mSource = Source::Laser; |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +//________________________________________________________ |
| 66 | +void VDriftHelper::accountDriftCorrectionITSTPCTgl(const VDriftCorrFact* calib) |
| 67 | +{ |
| 68 | + LOG(info) << "accountDriftCorrectionITSTPCTgl " << calib->corrFact << " t " << calib->creationTime << " vs " << mVD.creationTime; |
| 69 | + if (!calib || calib->creationTime < mVD.creationTime) { // prefer current value |
| 70 | + return; |
| 71 | + } |
| 72 | + mVD = *calib; |
| 73 | + mUpdated = true; |
| 74 | + mSource = Source::ITSTPCTgl; |
| 75 | +} |
| 76 | + |
| 77 | +//________________________________________________________ |
| 78 | +void VDriftHelper::extractCCDBInputs(ProcessingContext& pc, bool laser, bool itstpcTgl) |
| 79 | +{ |
| 80 | + if (laser) { |
| 81 | + pc.inputs().get<o2::tpc::LtrCalibData*>("laserCalib"); |
| 82 | + } |
| 83 | + if (itstpcTgl) { |
| 84 | + pc.inputs().get<o2::tpc::VDriftCorrFact*>("vdriftTgl"); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +//________________________________________________________ |
| 89 | +void VDriftHelper::requestCCDBInputs(std::vector<InputSpec>& inputs, bool laser, bool itstpcTgl) |
| 90 | +{ |
| 91 | + if (laser) { |
| 92 | + addInput(inputs, {"laserCalib", "TPC", "CalibLaserTracks", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalLaserTracks))}); |
| 93 | + } |
| 94 | + if (itstpcTgl) { |
| 95 | + // VDrift calibration may change during the run (in opposite to Laser calibration, at least at the moment), so ask per-TF query |
| 96 | + addInput(inputs, {"vdriftTgl", "TPC", "VDriftTgl", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalVDriftTgl), {}, 1)}); |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +//________________________________________________________ |
| 101 | +void VDriftHelper::addInput(std::vector<InputSpec>& inputs, InputSpec&& isp) |
| 102 | +{ |
| 103 | + if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) { |
| 104 | + inputs.emplace_back(isp); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +//________________________________________________________ |
| 109 | +bool VDriftHelper::accountCCDBInputs(const ConcreteDataMatcher& matcher, void* obj) |
| 110 | +{ |
| 111 | + if (matcher == ConcreteDataMatcher("TPC", "VDriftTgl", 0)) { |
| 112 | + accountDriftCorrectionITSTPCTgl(static_cast<VDriftCorrFact*>(obj)); |
| 113 | + return true; |
| 114 | + } |
| 115 | + if (matcher == ConcreteDataMatcher("TPC", "CalibLaserTracks", 0)) { |
| 116 | + accountLaserCalibration(static_cast<LtrCalibData*>(obj)); |
| 117 | + return true; |
| 118 | + } |
| 119 | + return false; |
| 120 | +} |
0 commit comments