Project
Loading...
Searching...
No Matches
CalibLaserTracksSpec.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_TPC_CalibLaserTracksSpec_H
13#define O2_TPC_CalibLaserTracksSpec_H
14
17
18#include "TFile.h"
22#include "Framework/Task.h"
26#include "CCDB/CcdbApi.h"
27#include "CCDB/CcdbObjectInfo.h"
30
32
33using namespace o2::framework;
34
35namespace o2::tpc
36{
37
39{
40 public:
42 {
43 mWriteDebug = ic.options().get<bool>("write-debug");
44 mCalib.setWriteDebugTree(mWriteDebug);
45 mMinNumberTFs = ic.options().get<int>("min-tfs");
46 mOnlyPublishOnEOS = ic.options().get<bool>("only-publish-on-eos");
47 mNormalize = !ic.options().get<bool>("ignore-normalization");
48 auto finishFunction = [this]() {
49 if (!mPublished) {
50 const auto nTFs = mCalib.getCalibData().processedTFs;
51 const auto nMatchA = mCalib.getMatchedPairsA();
52 const auto nMatchC = mCalib.getMatchedPairsC();
53 LOGP(error, "Calibration data was not published, laser track calibration might not have enough statistics: {} ({}) matched tracks in {} TFs on the A (C) < {} min TFs * {} min matches per side per TF? Or eos was not called by the framework.", nMatchA, nMatchC, nTFs, mMinNumberTFs, CalibLaserTracks::MinTrackPerSidePerTF);
54 }
55 };
56 ic.services().get<CallbackService>().set<CallbackService::Id::Stop>(finishFunction);
57 }
58
60 {
61 const auto dph = o2::header::get<o2::framework::DataProcessingHeader*>(pc.inputs().get("input").header);
62 if (!dph) {
63 LOGP(warning, "CalibLaserTracksDevice::run: No DataProcessingHeader found for \"input\". Only conditions? Skipping event.");
64 return;
65 }
66 mTPCVDriftHelper.extractCCDBInputs(pc);
67 const auto timestamp = pc.services().get<o2::framework::TimingInfo>().creation;
68
69 // if reference temperature / pressure of VDrift object is zero then it was not corrected
70 const float tp = (mTPCVDriftHelper.getVDriftObject().refTP == 0) ? mTPCVDriftHelper.getPTHelper().getTP(timestamp) : mTPCVDriftHelper.getVDriftObject().refTP;
71 if (mTPCVDriftHelper.isUpdated()) {
72 mTPCVDriftHelper.acknowledgeUpdate();
73 mCalib.setVDriftRef(mTPCVDriftHelper.getVDriftObject().getVDrift());
74 LOGP(info, "Updated reference drift velocity to: {}", mTPCVDriftHelper.getVDriftObject().getVDrift());
75 }
76 const auto startTime = dph->startTime;
77 const auto endTime = dph->startTime + dph->duration;
78 mRunNumber = processing_helpers::getRunNumber(pc);
79
80 auto data = pc.inputs().get<gsl::span<TrackTPC>>("input");
81 mCalib.setTFtimes(startTime, endTime);
82 mCalib.fill(data, tp);
83
84 if (!mOnlyPublishOnEOS && mCalib.hasEnoughData(mMinNumberTFs) && !mPublished) {
85 sendOutput(pc.outputs());
86 }
87 }
88
90 {
91 LOGP(info, "CalibLaserTracksDevice::endOfStream: Finalizing calibration");
92 if (!mCalib.hasEnoughData(mMinNumberTFs)) {
93 const auto nTFs = mCalib.getCalibData().processedTFs;
94 const auto nMatchA = mCalib.getMatchedPairsA();
95 const auto nMatchC = mCalib.getMatchedPairsC();
96 LOGP(warning, "laser track calibration does not have enough statistics: {} ({}) matched tracks in {} TFs on the A (C) < {} min TFs * {} min matches per side per TF ", nMatchA, nMatchC, nTFs, mMinNumberTFs, CalibLaserTracks::MinTrackPerSidePerTF);
97 }
98 sendOutput(ec.outputs());
99 }
100
101 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final
102 {
103 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
104 return;
105 }
106 }
107
108 private:
109 CalibLaserTracks mCalib;
110 o2::tpc::VDriftHelper mTPCVDriftHelper{};
111 uint64_t mRunNumber{0};
112 int mMinNumberTFs{100};
113 bool mPublished{false};
114 bool mOnlyPublishOnEOS{false};
115 bool mNormalize{true};
116 bool mWriteDebug{false};
117
118 //________________________________________________________________
119 void sendOutput(DataAllocator& output)
120 {
121 mCalib.finalize();
122 mCalib.print();
123
124 std::map<std::string, std::string> md;
125
127 auto ltrCalib = mCalib.getCalibData();
128 if (!ltrCalib.isValid()) {
129 LOGP(error, "Invalid Laser calibration (corrections: A-side={}, C-side={}, NTracks: A-side={} C-side={}), will NOT upload to CCDB", ltrCalib.dvCorrectionA, ltrCalib.dvCorrectionC, ltrCalib.nTracksA, ltrCalib.nTracksC);
130 return;
131 }
132
133 if (mNormalize) {
134 ltrCalib.normalize(0.);
135 LOGP(info, "After normalization: correction factors: {} / {} for A- / C-Side, reference: {}, vdrift correction: {}", ltrCalib.dvCorrectionA, ltrCalib.dvCorrectionC, ltrCalib.refVDrift, ltrCalib.getDriftVCorrection());
136 }
137
139 auto image = o2::ccdb::CcdbApi::createObjectImage(&ltrCalib, &w);
140
141 md = w.getMetaData();
142 md[o2::base::NameConf::CCDBRunTag.data()] = std::to_string(mRunNumber);
143 w.setMetaData(md);
144
145 const auto now = std::chrono::system_clock::now();
146 const long timeStart = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
147 // const auto timeStart = ltrCalib.firstTime; //TODO: use once it is a correct time not TFid
149
150 w.setPath("TPC/Calib/LaserTracks");
151 w.setStartValidityTimestamp(timeStart);
152 w.setEndValidityTimestamp(timeEnd);
153
154 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", w.getPath(), w.getFileName(), image->size(), w.getStartValidityTimestamp(), w.getEndValidityTimestamp());
155 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "TPC_CalibLtr", 0}, *image.get());
156 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "TPC_CalibLtr", 0}, w);
157
158 mPublished = true;
159
160 if (mWriteDebug) {
161 TFile f("LaserTracks.snapshot.root", "recreate");
162 f.WriteObject(&ltrCalib, "ccdb_object");
163 }
164 }
165};
166
167DataProcessorSpec getCalibLaserTracks(const std::string inputSpec)
168{
169 using device = o2::tpc::CalibLaserTracksDevice;
170
171 std::vector<OutputSpec> outputs;
172 outputs.emplace_back(ConcreteDataTypeMatcher{"TPC", "LtrCalibData"}, Lifetime::Sporadic);
173 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TPC_CalibLtr"}, Lifetime::Sporadic);
174 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TPC_CalibLtr"}, Lifetime::Sporadic);
175 std::vector<InputSpec> inputs = select(inputSpec.data());
177
178 return DataProcessorSpec{
179 "tpc-calib-laser-tracks",
180 inputs,
181 outputs,
182 AlgorithmSpec{adaptFromTask<device>()},
183 Options{
184 {"write-debug", VariantType::Bool, false, {"write a debug output tree."}},
185 {"min-tfs", VariantType::Int, 100, {"minimum number of TFs with enough laser tracks to finalize the calibration."}},
186 {"only-publish-on-eos", VariantType::Bool, false, {"only publish the calibration on eos, not during running"}},
187 {"ignore-normalization", VariantType::Bool, false, {"ignore normalization of reference to have mean correction factor 1"}},
188 }};
189}
190
191} // namespace o2::tpc
192
193#endif
calibration using laser tracks
Utils and constants for calibration and related workflows.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of the Names Generator class.
Helper class to extract VDrift from different sources.
static constexpr std::string_view CCDBRunTag
Definition NameConf.h:69
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
static constexpr long INFINITE_TIMESTAMP
void run(o2::framework::ProcessingContext &pc) final
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
void init(o2::framework::InitContext &ic) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void finalize()
Finalize full processing.
size_t getMatchedPairsC() const
number of associated laser tracks for all processed TFs on the C-Side
bool hasEnoughData(size_t numTFs=1) const
static constexpr size_t MinTrackPerSidePerTF
void fill(const gsl::span< const TrackTPC > tracks, float tp=0)
void setWriteDebugTree(bool write)
void print() const
print information
size_t getMatchedPairsA() const
number of associated laser tracks for all processed TFs on the A-Side
void setTFtimes(uint64_t tfStart, uint64_t tfEnd=0)
const LtrCalibData & getCalibData()
drift velocity fit information for full data set
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, bool laser=true, bool itstpcTgl=true)
void extractCCDBInputs(o2::framework::ProcessingContext &pc, bool laser=true, bool itstpcTgl=true)
const auto & getPTHelper() const
const VDriftCorrFact & getVDriftObject() const
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
bool isUpdated() const
GLeglImageOES image
Definition glcorearb.h:4021
GLdouble f
Definition glcorearb.h:310
GLboolean * data
Definition glcorearb.h:298
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
uint64_t now() noexcept
Definition Clock.h:69
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > select(char const *matcher="")
uint64_t getRunNumber(o2::framework::ProcessingContext &pc)
Global TPC definitions and constants.
Definition SimTraits.h:167
DataProcessorSpec getCalibLaserTracks(const std::string inputSpec)
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
size_t processedTFs
number of processed TFs with laser track candidates
float refTP
reference temperature / pressure for which refVDrift was extracted