Project
Loading...
Searching...
No Matches
CalibratorPadGainTracksSpec.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
15
16#ifndef O2_TPC_TPCCALIBRATORPADGAINTRACKSSPEC_H_
17#define O2_TPC_TPCCALIBRATORPADGAINTRACKSSPEC_H_
18
21#include "CCDB/CcdbApi.h"
23#include "Framework/Task.h"
29
30using namespace o2::framework;
32
33namespace o2::tpc
34{
35
37{
38 public:
39 CalibratorPadGainTracksDevice(std::shared_ptr<o2::base::GRPGeomRequest> req, const bool useLastExtractedMapAsReference) : mUseLastExtractedMapAsReference(useLastExtractedMapAsReference), mCCDBRequest(req) {}
41 {
43 const auto slotLength = ic.options().get<uint32_t>("tf-per-slot");
44 const auto maxDelay = ic.options().get<uint32_t>("max-delay");
45 const int minEntries = ic.options().get<int>("min-entries");
46 const int gainNorm = ic.options().get<int>("gainNorm");
47 const bool debug = ic.options().get<bool>("file-dump");
48 const bool storeNClCCDB = ic.options().get<bool>("store-NCl-CCDB");
49 const bool storeRMSCCDB = ic.options().get<bool>("store-RMS-CCDB");
50 const auto lowTrunc = ic.options().get<float>("lowTrunc");
51 const auto upTrunc = ic.options().get<float>("upTrunc");
52 const auto minAcceptedRelgain = ic.options().get<float>("minAcceptedRelgain");
53 const auto maxAcceptedRelgain = ic.options().get<float>("maxAcceptedRelgain");
54 const int minEntriesMean = ic.options().get<int>("minEntriesMean");
55 const auto disableLogTransform = ic.options().get<bool>("disable-log-transform");
56
57 mCalibrator = std::make_unique<CalibratorPadGainTracks>();
58 mCalibrator->setLogTransformQ(!disableLogTransform);
59 mCalibrator->setMinEntries(minEntries);
60 mCalibrator->setSlotLength(slotLength);
61 mCalibrator->setMaxSlotsDelay(maxDelay);
62 mCalibrator->setTruncationRange(lowTrunc, upTrunc);
63 mCalibrator->setRelGainRange(minAcceptedRelgain, maxAcceptedRelgain);
64 mCalibrator->setWriteDebug(debug);
65 mCalibrator->setNormalizationType(static_cast<CalibPadGainTracksBase::NormType>(gainNorm));
66 mCalibrator->setUseLastExtractedMapAsReference(mUseLastExtractedMapAsReference);
67 mCalibrator->setMinEntriesMean(minEntriesMean);
68 mCalibrator->setStoreNClCCDB(storeNClCCDB);
69 mCalibrator->setStoreRMSCCDB(storeRMSCCDB);
70 }
71
72 void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
73 {
75 }
76
77 void run(ProcessingContext& pc) final
78 {
80 const auto histomaps = pc.inputs().get<CalibPadGainTracksBase::DataTHistos*>("gainhistos");
81 o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
82 mCalibrator->process(*histomaps.get());
83 const auto& infoVec = mCalibrator->getTFinterval();
84 LOGP(detail, "Created {} objects for TF {} and time stamp {}", infoVec.size(), mCalibrator->getCurrentTFInfo().tfCounter, mCalibrator->getCurrentTFInfo().creation);
85
86 if (mCalibrator->hasCalibrationData()) {
87 mRunNumber = mCalibrator->getCurrentTFInfo().runNumber;
88 sendOutput(pc.outputs());
89 }
90 }
91
93 {
94 LOGP(info, "Finalizing calibration");
95 mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
96 sendOutput(eos.outputs());
97 }
98
99 private:
100 void sendOutput(DataAllocator& output)
101 {
102 auto calibrations = std::move(*mCalibrator).getCalibs();
103 const auto& intervals = mCalibrator->getTimeIntervals();
104
105 assert(calibrations.size() == intervals.size());
106 for (uint32_t iCalib = 0; iCalib < calibrations.size(); ++iCalib) {
107 const auto& calib = calibrations[iCalib];
108 const auto& infoVec = mCalibrator->getTFinterval();
109 const auto firstTF = infoVec[iCalib].first;
110 const auto lastTF = infoVec[iCalib].second;
111 LOGP(info, "Writing pad-by-pad gain map to CCDB for TF {} to {}", firstTF, lastTF);
112 o2::ccdb::CcdbObjectInfo ccdbInfo(CDBTypeMap.at(CDBType::CalPadGainResidual), std::string{}, std::string{}, std::map<std::string, std::string>{{"runNumber", std::to_string(mRunNumber)}}, intervals[iCalib].first, o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP);
113 auto imageIDCDelta = o2::ccdb::CcdbApi::createObjectImage(&calib, &ccdbInfo);
114 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", ccdbInfo.getPath(), ccdbInfo.getFileName(), imageIDCDelta->size(), ccdbInfo.getStartValidityTimestamp(), ccdbInfo.getEndValidityTimestamp());
115 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "TPC_CalibResGain", iCalib}, *imageIDCDelta.get());
116 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "TPC_CalibResGain", iCalib}, ccdbInfo);
117 }
118 mCalibrator->initOutput(); // empty the outputs after they are send
119 }
120
121 const bool mUseLastExtractedMapAsReference{false};
122 std::unique_ptr<CalibratorPadGainTracks> mCalibrator;
123 std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
124 uint64_t mRunNumber{0};
125};
126
128o2::framework::DataProcessorSpec getTPCCalibPadGainTracksSpec(const bool useLastExtractedMapAsReference)
129{
130 std::vector<OutputSpec> outputs;
131 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TPC_CalibResGain"}, Lifetime::Sporadic);
132 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TPC_CalibResGain"}, Lifetime::Sporadic);
133
134 std::vector<InputSpec> inputs{{"gainhistos", "TPC", "TRACKGAINHISTOS", 0, Lifetime::Sporadic}};
135 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
136 true, // GRPECS=true
137 false, // GRPLHCIF
138 false, // GRPMagField
139 false, // askMatLUT
141 inputs);
142 return DataProcessorSpec{
143 "tpc-calibrator-gainmap-tracks",
144 inputs,
145 outputs,
146 adaptFromTask<CalibratorPadGainTracksDevice>(ccdbRequest, useLastExtractedMapAsReference),
147 Options{
148 {"tf-per-slot", VariantType::UInt32, 100u, {"number of TFs per calibration time slot"}},
149 {"max-delay", VariantType::UInt32, 0u, {"number of slots in past to consider"}},
150 {"min-entries", VariantType::Int, 40, {"minimum entries per pad-by-pad histogram which are required"}},
151 {"lowTrunc", VariantType::Float, 0.05f, {"lower truncation range for calculating the rel gain"}},
152 {"upTrunc", VariantType::Float, 0.6f, {"upper truncation range for calculating the rel gain"}},
153 {"minAcceptedRelgain", VariantType::Float, 0.1f, {"minimum accpeted relative gain (if the gain is below this value it will be set to 1)"}},
154 {"maxAcceptedRelgain", VariantType::Float, 2.f, {"maximum accpeted relative gain (if the gain is above this value it will be set to 1)"}},
155 {"gainNorm", VariantType::Int, 1, {"normalization method for the extracted gain map: 0=no normalization, 1=median per stack, 2=median per region"}},
156 {"minEntriesMean", VariantType::Int, 40, {"minEntries minimum number of entries in pad-by-pad histogram to calculate the mean"}},
157 {"store-NCl-CCDB", VariantType::Bool, false, {"store the CalDet containing the number of clusters per pad in the CCDB"}},
158 {"store-RMS-CCDB", VariantType::Bool, false, {"store the RMS of each pad-by-pad histogram containing the number of clusters per pad in the CCDB"}},
159 {"disable-log-transform", VariantType::Bool, false, {"Disable the transformation of q/dedx -> log(1 + q/dedx)"}},
160 {"file-dump", VariantType::Bool, false, {"directly write calibration to a file"}}}};
161}
162
163} // namespace o2::tpc
164
165#endif
Simple interface to the CDB manager.
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
Definition of the Names Generator class.
std::ostringstream debug
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::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
static constexpr long INFINITE_TIMESTAMP
NormType
normalization type of the extracted gain map
void init(framework::InitContext &ic) final
CalibratorPadGainTracksDevice(std::shared_ptr< o2::base::GRPGeomRequest > req, const bool useLastExtractedMapAsReference)
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
void endOfStream(EndOfStreamContext &eos) final
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
constexpr TFType INFINITE_TF
Definition TimeSlot.h:30
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
Global TPC definitions and constants.
Definition SimTraits.h:167
o2::framework::DataProcessorSpec getTPCCalibPadGainTracksSpec(const bool useLastExtractedMapAsReference)
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:94
@ CalPadGainResidual
ResidualpPad gain calibration (e.g. from tracks)
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