Project
Loading...
Searching...
No Matches
TrackBasedCalibSpec.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
18#include "Framework/Task.h"
25#include "Headers/DataHeader.h"
27#include "TStopwatch.h"
29#include <cstring>
30
31using namespace o2::framework;
32using namespace o2::globaltracking;
34
35namespace o2
36{
37namespace trd
38{
39
41{
42 public:
43 TRDTrackBasedCalibDevice(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, bool vdexb, bool gain) : mDataRequest(dr), mGGCCDBRequest(gr), mDoVdExBCalib(vdexb), mDoGainCalib(gain) {}
44 ~TRDTrackBasedCalibDevice() override = default;
45 void init(InitContext& ic) final;
46 void run(ProcessingContext& pc) final;
47 void finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj) final;
49
50 private:
51 void updateTimeDependentParams(framework::ProcessingContext& pc);
52
53 bool mDoGainCalib{false};
54 bool mDoVdExBCalib{false};
55
56 std::shared_ptr<DataRequest> mDataRequest;
57 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
58 TrackBasedCalib mCalibrator; // gather input data for calibration of vD, ExB and gain
59 TStopwatch mTimer;
60};
61
63{
65 if (getenv("ALIEN_JDL_LPMPRODUCTIONTYPE") && std::strcmp(getenv("ALIEN_JDL_LPMPRODUCTIONTYPE"), "MC") == 0) {
66 // apply artificial pad shift in case non-ideal alignment is used to compensate for shift in current alignment from real data
67 mCalibrator.setApplyShift(false);
68 }
69 mTimer.Stop();
70 mTimer.Reset();
71}
72
74{
75 mTimer.Start(false);
76 RecoContainer recoData;
77 recoData.collectData(pc, *mDataRequest.get());
78 updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
79 mCalibrator.setInput(recoData);
80
81 if (mDoVdExBCalib) {
82 mCalibrator.calculateAngResHistos();
83 pc.outputs().snapshot(Output{o2::header::gDataOriginTRD, "ANGRESHISTS", 0}, mCalibrator.getAngResHistos());
84 }
85
86 if (mDoGainCalib) {
87 mCalibrator.calculateGainCalibObjs();
88 pc.outputs().snapshot(Output{o2::header::gDataOriginTRD, "GAINCALIBHISTS", 0}, mCalibrator.getGainCalibHistos());
89 }
90
91 mCalibrator.reset();
92 mTimer.Stop();
93}
94
95void TRDTrackBasedCalibDevice::updateTimeDependentParams(ProcessingContext& pc)
96{
98 pc.inputs().get<o2::trd::NoiseStatusMCM*>("mcmnoisemap"); // just to trigger the finaliseCCDB
99 if (mDoGainCalib) {
100 pc.inputs().get<o2::trd::LocalGainFactor*>("localgainfactors"); // just to trigger the finaliseCCDB
101 }
102 static bool initOnceDone = false;
103 if (!initOnceDone) { // this params need to be queried only once
104 initOnceDone = true;
105 // init-once stuff
106 mCalibrator.init();
107 }
108}
109
111{
113 return;
114 }
115 if (matcher == ConcreteDataMatcher("TRD", "MCMNOISEMAP", 0)) {
116 LOG(info) << "NoiseStatusMCM object has been updated";
117 mCalibrator.setNoiseMapMCM((const o2::trd::NoiseStatusMCM*)obj);
118 return;
119 }
120 if (matcher == ConcreteDataMatcher("TRD", "LOCALGAINFACTORS", 0)) {
121 LOG(info) << "Local gain factors object has been updated";
122 mCalibrator.setLocalGainFactors((const o2::trd::LocalGainFactor*)obj);
123 return;
124 }
125}
126
128{
129 LOGF(info, "TRD track-based calibration total timing: Cpu: %.3e Real: %.3e s in %d slots",
130 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
131}
132
134{
135 std::vector<OutputSpec> outputs;
136 auto dataRequest = std::make_shared<DataRequest>();
137
138 GTrackID::mask_t srcTrk;
139 if (GTrackID::includesSource(GTrackID::Source::ITSTPC, src)) {
140 LOGF(info, "Found ITS-TPC tracks as input, loading ITS-TPC-TRD");
141 srcTrk |= GTrackID::getSourcesMask("ITS-TPC-TRD");
142 if (gain) {
143 srcTrk |= GTrackID::getSourcesMask("ITS-TPC");
144 }
145 }
146 if (GTrackID::includesSource(GTrackID::Source::TPC, src)) {
147 LOGF(info, "Found TPC tracks as input, loading TPC-TRD");
148 srcTrk |= GTrackID::getSourcesMask("TPC-TRD");
149 }
150 if (gain) {
151 srcTrk |= GTrackID::getSourcesMask("TPC");
152 }
153 GTrackID::mask_t srcClu = GTrackID::getSourcesMask("TRD"); // we don't need all clusters, only TRD tracklets
154 dataRequest->requestTracks(srcTrk, false);
155 dataRequest->requestClusters(srcClu, false);
156
157 auto& inputs = dataRequest->inputs;
158 inputs.emplace_back("mcmnoisemap", "TRD", "MCMNOISEMAP", 0, Lifetime::Condition, ccdbParamSpec("TRD/Calib/NoiseMapMCM"));
159 if (gain) {
160 inputs.emplace_back("localgainfactors", "TRD", "LOCALGAINFACTORS", 0, Lifetime::Condition, ccdbParamSpec("TRD/Calib/LocalGainFactor"));
161 }
162 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
163 false, // GRPECS=true
164 false, // GRPLHCIF
165 true, // GRPMagField
166 true, // askMatLUT
168 inputs,
169 true);
170 if (gain) {
171 outputs.emplace_back(o2::header::gDataOriginTRD, "GAINCALIBHISTS", 0, Lifetime::Timeframe);
172 }
173 if (vdexb) {
174 outputs.emplace_back(o2::header::gDataOriginTRD, "ANGRESHISTS", 0, Lifetime::Timeframe);
175 }
176 if (!gain && !vdexb) {
177 LOG(error) << "TRD track based calibration requested, but neither gain nor vD and ExB calibration enabled";
178 }
179
180 return DataProcessorSpec{
181 "trd-trackbased-calib",
182 inputs,
183 outputs,
184 AlgorithmSpec{adaptFromTask<TRDTrackBasedCalibDevice>(dataRequest, ggRequest, vdexb, gain)},
185 Options{}};
186}
187
188} // namespace trd
189} // namespace o2
Wrapper container for different reconstructed object types.
Definition of the GeometryManager class.
Helper for geometry and GRP related CCDB requests.
Header of the General Run Parameters object.
Definition of the Names Generator class.
Steers the creation of calibration input based on tracks.
Provides information required for TRD calibration which is based on the global tracking.
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static mask_t getSourcesMask(const std::string_view srcList)
void snapshot(const Output &spec, T const &object)
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
Simple noise status bit for each MCM of the TRD.
void endOfStream(framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void finaliseCCDB(framework::ConcreteDataMatcher &matcher, void *obj) final
void run(ProcessingContext &pc) final
TRDTrackBasedCalibDevice(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, bool vdexb, bool gain)
~TRDTrackBasedCalibDevice() override=default
void setInput(const o2::globaltracking::RecoContainer &input)
Initialize the input arrays.
void setNoiseMapMCM(const NoiseStatusMCM *map)
Set the MCM noise map.
void reset()
Reset the output.
void init()
Load geometry and apply magnetic field setting.
const auto & getGainCalibHistos() const
void calculateAngResHistos()
Main processing function for creating angular residual histograms for vDrift and ExB calibration.
void setLocalGainFactors(const LocalGainFactor *localGain)
const AngularResidHistos & getAngResHistos() const
GLenum src
Definition glcorearb.h:1767
constexpr o2::header::DataOrigin gDataOriginTRD
Definition DataHeader.h:577
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
framework::DataProcessorSpec getTRDTrackBasedCalibSpec(o2::dataformats::GlobalTrackID::mask_t src, bool vdexb, bool gain)
create a processor spec
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"