Project
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
CalibdEdxSpec.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
15
17
18// o2 includes
19#include "CCDB/CcdbApi.h"
20#include "CCDB/CcdbObjectInfo.h"
21// #include "CommonUtils/NameConf.h"
23// #include "DataFormatsParameters/GRPObject.h"
25#include "Framework/Task.h"
32#include "TPCBase/CDBTypes.h"
33#include "TPCBase/Utils.h"
35
36using namespace o2::framework;
37
38namespace o2::tpc
39{
40
41class CalibdEdxDevice : public Task
42{
43 public:
44 CalibdEdxDevice(std::shared_ptr<o2::base::GRPGeomRequest> req, const o2::base::Propagator::MatCorrType matType) : mCCDBRequest(req), mMatType(matType) {}
45
47 {
49 const auto minEntriesSector = ic.options().get<int>("min-entries-sector");
50 const auto minEntries1D = ic.options().get<int>("min-entries-1d");
51 const auto minEntries2D = ic.options().get<int>("min-entries-2d");
52 const auto fitPasses = ic.options().get<int>("fit-passes");
53 const auto fitThreshold = ic.options().get<float>("fit-threshold");
54 const auto fitThresholdLowFactor = ic.options().get<float>("fit-threshold-low-factor");
55
56 const auto dEdxBins = ic.options().get<int>("dedxbins");
57 const auto mindEdx = ic.options().get<float>("min-dedx");
58 const auto maxdEdx = ic.options().get<float>("max-dedx");
59 const auto angularBins = ic.options().get<int>("angularbins");
60 const auto fitSnp = ic.options().get<bool>("fit-snp");
61 mMakeGaussianFits = !ic.options().get<bool>("disable-gaussian-fits");
62
63 mDumpToFile = ic.options().get<int>("file-dump");
64
65 mCalib = std::make_unique<CalibdEdx>(dEdxBins, mindEdx, maxdEdx, angularBins, fitSnp);
66 mCalib->setApplyCuts(false);
67 mCalib->setSectorFitThreshold(minEntriesSector);
68 mCalib->set1DFitThreshold(minEntries1D);
69 mCalib->set2DFitThreshold(minEntries2D);
70 mCalib->setElectronCut(fitThreshold, fitPasses, fitThresholdLowFactor);
71 mCalib->setMaterialType(mMatType);
72
73 mCustomdEdxFileName = o2::gpu::GPUConfigurableParamGPUSettingsO2::Instance().dEdxCorrFile;
74 mDisableTimeGain = o2::gpu::GPUConfigurableParamGPUSettingsO2::Instance().dEdxDisableResidualGain;
75
76 if (mDisableTimeGain) {
77 LOGP(info, "TimeGain correction was disabled via GPU_global.dEdxDisableResidualGain=1");
78 }
79
80 if (!mDisableTimeGain && !mCustomdEdxFileName.empty()) {
81 std::unique_ptr<TFile> fdEdxCustom(TFile::Open(mCustomdEdxFileName.data()));
82 if (!fdEdxCustom || !fdEdxCustom->IsOpen() || fdEdxCustom->IsZombie()) {
83 LOGP(error, "Could not open custom TimeGain file {}", mCustomdEdxFileName);
84 } else {
85 auto timeGain = fdEdxCustom->Get<o2::tpc::CalibdEdxCorrection>("CalibdEdxCorrection");
86
87 if (!timeGain) {
88 timeGain = fdEdxCustom->Get<o2::tpc::CalibdEdxCorrection>("ccdb_object");
89 }
90
91 if (!timeGain) {
92 LOGP(error, "Could not load 'CalibdEdxCorrection' from file {}", mCustomdEdxFileName);
93 } else {
94 const auto meanParamTot = timeGain->getMeanParams(ChargeType::Tot);
95 LOGP(info, "Loaded custom TimeGain from file {} with {} dimensions and mean qTot Params {}", mCustomdEdxFileName, timeGain->getDims(), utils::elementsToString(meanParamTot));
96 mCalib->setCalibrationInput(*timeGain);
97 }
98 }
99 }
100 }
101
102 void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
103 {
105 return;
106 }
107 if ((mDisableTimeGain == 0) && mCustomdEdxFileName.empty() && (matcher == ConcreteDataMatcher("TPC", "TIMEGAIN", 0))) {
108 mCalib->setCalibrationInput(*(o2::tpc::CalibdEdxCorrection*)obj);
109 const auto meanParamTot = mCalib->getCalibrationInput().getMeanParams(ChargeType::Tot);
110 LOGP(info, "Updating TimeGain with {} dimensions and mean qTot Params {}", mCalib->getCalibrationInput().getDims(), utils::elementsToString(meanParamTot));
111 return;
112 }
113 }
114
115 void run(ProcessingContext& pc) final
116 {
118 checkUpdates(pc);
119 const auto tfcounter = o2::header::get<DataProcessingHeader*>(pc.inputs().get("tracks").header)->startTime;
120 const auto tracks = pc.inputs().get<gsl::span<TrackTPC>>("tracks");
121
122 LOGP(detail, "Processing TF {} with {} tracks", tfcounter, tracks.size());
123 mCalib->fill(tracks);
124
125 // store run number and CCDB time only once
126 if ((mTimeStampStart == 0) || (pc.services().get<o2::framework::TimingInfo>().timeslice == 0)) {
127 mRunNumber = processing_helpers::getRunNumber(pc);
128 mTimeStampStart = processing_helpers::getTimeStamp(pc, o2::base::GRPGeomHelper::instance().getOrbitResetTimeMS());
129 LOGP(info, "Setting start time stamp for writing to CCDB to {}", mTimeStampStart);
130 }
131 }
132
134 {
135 LOGP(info, "Finalizing calibration");
136 mCalib->finalize(mMakeGaussianFits);
137 mCalib->print();
138 sendOutput(eos.outputs());
139
140 if (mDumpToFile) {
141 mCalib->dumpToFile("calibdEdx_Obj.root");
142 mCalib->getCalib().writeToFile("calibdEdx.root");
143 if (mDumpToFile > 1) {
144 mCalib->writeTTree("calibdEdx.histo.tree.root");
145 }
146 }
147 }
148
149 private:
150 void sendOutput(DataAllocator& output)
151 {
152 const auto& corr = mCalib->getCalib();
153 o2::ccdb::CcdbObjectInfo info(CDBTypeMap.at(CDBType::CalTimeGain), std::string{}, std::string{}, std::map<std::string, std::string>{{"runNumber", std::to_string(mRunNumber)}}, mTimeStampStart, o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP);
154 auto image = o2::ccdb::CcdbApi::createObjectImage(&corr, &info);
155 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", info.getPath(), info.getFileName(), image->size(), info.getStartValidityTimestamp(), info.getEndValidityTimestamp());
156 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "TPC_CalibdEdx", 0}, *image.get());
157 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "TPC_CalibdEdx", 0}, info);
158 }
159
160 void checkUpdates(ProcessingContext& pc) const
161 {
162 if (pc.inputs().isValid("tpctimegain")) {
163 pc.inputs().get<o2::tpc::CalibdEdxCorrection*>("tpctimegain");
164 } else {
165 return;
166 }
167 }
168
169 std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
170 const o2::base::Propagator::MatCorrType mMatType{};
171 int mDumpToFile{};
172 uint64_t mRunNumber{0};
173 uint64_t mTimeStampStart{0};
174 std::unique_ptr<CalibdEdx> mCalib;
175 bool mMakeGaussianFits{true};
176 bool mDisableTimeGain{false};
177 std::string mCustomdEdxFileName{};
178};
179
181{
182 const bool enableAskMatLUT = matType == o2::base::Propagator::MatCorrType::USEMatCorrLUT;
183 std::vector<OutputSpec> outputs;
184 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TPC_CalibdEdx"}, Lifetime::Sporadic);
185 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TPC_CalibdEdx"}, Lifetime::Sporadic);
186 std::vector<InputSpec> inputs{{"tracks", "TPC", "MIPS", Lifetime::Sporadic}};
187 inputs.emplace_back("tpctimegain", "TPC", "TIMEGAIN", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalTimeGain), {}, 1)); // time-dependent
188
189 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
190 false, // GRPECS=true
191 false, // GRPLHCIF
192 true, // GRPMagField
193 enableAskMatLUT, // askMatLUT
195 inputs,
196 true,
197 true);
198
199 return DataProcessorSpec{
200 "tpc-calib-dEdx",
201 inputs,
202 outputs,
203 adaptFromTask<CalibdEdxDevice>(ccdbRequest, matType),
204 Options{
205 {"min-entries-sector", VariantType::Int, 1000, {"min entries per GEM stack to enable sector by sector correction. Below this value we only perform one fit per ROC type (IROC, OROC1, ...; no side nor sector information)."}},
206 {"min-entries-1d", VariantType::Int, 10000, {"minimum entries per stack to fit 1D correction"}},
207 {"min-entries-2d", VariantType::Int, 50000, {"minimum entries per stack to fit 2D correction"}},
208 {"fit-passes", VariantType::Int, 3, {"number of fit iterations"}},
209 {"fit-threshold", VariantType::Float, 0.2f, {"dEdx width around the MIP peak used in the fit"}},
210 {"fit-threshold-low-factor", VariantType::Float, 1.5f, {"factor for low dEdx width around the MIP peak used in the fit"}},
211
212 {"dedxbins", VariantType::Int, 70, {"number of dEdx bins"}},
213 {"min-dedx", VariantType::Float, 10.0f, {"minimum value for dEdx histograms"}},
214 {"max-dedx", VariantType::Float, 90.0f, {"maximum value for dEdx histograms"}},
215 {"angularbins", VariantType::Int, 36, {"number of angular bins: Tgl and Snp"}},
216 {"fit-snp", VariantType::Bool, false, {"enable Snp correction"}},
217 {"disable-gaussian-fits", VariantType::Bool, false, {"disable calibration with gaussian fits and use mean instead"}},
218
219 {"file-dump", VariantType::Int, 0, {"directly dump calibration to file"}}}};
220}
221
222} // namespace o2::tpc
CDB Type definitions for TPC.
Workflow for time based dE/dx calibration.
This file provides the container used for time based residual dE/dx calibration.
Utils and constants for calibration and related workflows.
Helper for geometry and GRP related CCDB requests.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
static constexpr long INFINITE_TIMESTAMP
bool isValid(std::string const &s) const
Helper method to be used to check if a given part of the InputRecord is present.
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
CalibdEdxDevice(std::shared_ptr< o2::base::GRPGeomRequest > req, const o2::base::Propagator::MatCorrType matType)
void init(framework::InitContext &ic) final
void endOfStream(EndOfStreamContext &eos) final
void run(ProcessingContext &pc) final
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
GLeglImageOES image
Definition glcorearb.h:4021
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)
std::vector< ConfigParamSpec > Options
uint64_t getTimeStamp(o2::framework::ProcessingContext &pc)
uint64_t getRunNumber(o2::framework::ProcessingContext &pc)
std::string elementsToString(Iterator begin, Iterator end, const std::string separator=", ")
Definition Utils.h:74
Global TPC definitions and constants.
Definition SimTraits.h:167
@ Tot
Definition Defs.h:72
o2::framework::DataProcessorSpec getCalibdEdxSpec(const o2::base::Propagator::MatCorrType matType)
create a processor spec
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:95
@ CalTimeGain
Gain variation over time.
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43