Project
Loading...
Searching...
No Matches
CosmicsMatchingSpec.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
13
14#include <TMap.h>
15#include <TObjString.h>
16#include <vector>
17#include <string>
18#include "TStopwatch.h"
44#include "Headers/DataHeader.h"
49#include "Framework/Task.h"
54#include "TPCFastTransformPOD.h"
55
56using namespace o2::framework;
57using MCLabelsTr = gsl::span<const o2::MCCompLabel>;
60
61namespace o2
62{
63namespace globaltracking
64{
65
67{
68 public:
69 CosmicsMatchingSpec(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, bool usePV, bool useMC) : mDataRequest(dr), mGGCCDBRequest(gr), mUsePVInfo(usePV), mUseMC(useMC) {}
70 ~CosmicsMatchingSpec() override = default;
71 void init(InitContext& ic) final;
72 void run(ProcessingContext& pc) final;
74 void finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj) final;
75
76 private:
77 void updateTimeDependentParams(ProcessingContext& pc);
78 void storeConfigs(ProcessingContext& pc);
79 std::shared_ptr<DataRequest> mDataRequest;
80 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
81 o2::tpc::VDriftHelper mTPCVDriftHelper{};
82 const o2::gpu::TPCFastTransformPOD* mCorrMap{nullptr};
83 o2::globaltracking::MatchCosmics mMatching; // matching engine
84 bool mUseMC = true;
85 bool mUsePVInfo = false;
86 TStopwatch mTimer;
87};
88
90{
91 mTimer.Stop();
92 mTimer.Reset();
94 mMatching.setDebugFlag(ic.options().get<int>("debug-tree-flags"));
95 mMatching.setUseMC(mUseMC);
96 mMatching.setUsePVInfo(mUsePVInfo);
97 //
98}
99
101{
102 mTimer.Start(false);
103 RecoContainer recoData;
104 recoData.collectData(pc, *mDataRequest.get());
105 updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
106 storeConfigs(pc);
107 mMatching.process(recoData);
108 pc.outputs().snapshot(Output{"GLO", "COSMICTRC", 0}, mMatching.getCosmicTracks());
109 if (mUseMC) {
110 pc.outputs().snapshot(Output{"GLO", "COSMICTRC_MC", 0}, mMatching.getCosmicTracksLbl());
111 }
112 mTimer.Stop();
113}
114
115void CosmicsMatchingSpec::storeConfigs(ProcessingContext& pc)
116{
117 static bool first = true;
118 if (first) {
119 first = false;
121 const auto& conf = MatchCosmicsParams::Instance();
123 TMap md;
124 md.SetOwnerKeyValue();
125 md.Add(new TObjString(conf.getName().c_str()), new TObjString(o2::conf::ConfigurableParam::asJSON(conf.getName()).c_str()));
126 pc.outputs().snapshot(Output{"META", "COSMICMATCHER", 0}, md);
127 }
128 }
129}
130
131void CosmicsMatchingSpec::updateTimeDependentParams(ProcessingContext& pc)
132{
134 mTPCVDriftHelper.extractCCDBInputs(pc);
135 auto const& raw = pc.inputs().get<const char*>("corrMap");
136 mCorrMap = &gpu::TPCFastTransformPOD::get(raw);
137 static bool initOnceDone = false;
138 if (!initOnceDone) { // this params need to be queried only once
139 initOnceDone = true;
141
142 // pc.inputs().get<o2::itsmft::TopologyDictionary*>("cldict"); // called by the RecoContainer
143 // also alpParams is called by the RecoContainer
146 if (!grp->isDetContinuousReadOut(DetID::ITS)) {
147 mMatching.setITSROFrameLengthMUS(alpParams.roFrameLengthTrig / 1.e3); // ITS ROFrame duration in \mus
148 } else {
149 mMatching.setITSROFrameLengthMUS(alpParams.roFrameLengthInBC * o2::constants::lhc::LHCBunchSpacingNS * 1e-3); // ITS ROFrame duration in \mus
150 }
151 mMatching.init();
152 }
153 mMatching.setTPCCorrMaps(mCorrMap);
154 if (mTPCVDriftHelper.isUpdated()) {
155 LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
156 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
157 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
158 mTPCVDriftHelper.getSourceName());
159 mMatching.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
160 mTPCVDriftHelper.acknowledgeUpdate();
161 }
162}
163
165{
167 return;
168 }
169 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
170 return;
171 }
172 if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) {
173 LOG(info) << "cluster dictionary updated";
174 mMatching.setITSDict((const o2::itsmft::TopologyDictionary*)obj);
175 return;
176 }
177}
178
180{
181 mMatching.end();
182 LOGF(info, "Cosmics matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
183 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
184}
185
187{
188 std::vector<OutputSpec> outputs;
189 Options opts{
190 {"material-lut-path", VariantType::String, "", {"Path of the material LUT file"}},
191 {"debug-tree-flags", VariantType::Int, 0, {"DebugFlagTypes bit-pattern for debug tree"}}};
192
193 auto dataRequest = std::make_shared<DataRequest>();
194
195 dataRequest->requestTracks(src, useMC);
196 dataRequest->requestClusters(src, false); // no MC labels for clusters needed for refit only
197 if (usePV) {
198 dataRequest->requestPrimaryVertices(useMC);
199 }
200
201 outputs.emplace_back("GLO", "COSMICTRC", 0, Lifetime::Timeframe);
202 if (useMC) {
203 outputs.emplace_back("GLO", "COSMICTRC_MC", 0, Lifetime::Timeframe);
204 }
205
206 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
207 true, // GRPECS=true
208 false, // GRPLHCIF
209 true, // GRPMagField
210 true, // askMatLUT
212 dataRequest->inputs,
213 true);
214 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
215 dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe);
216
217 outputs.emplace_back("META", "COSMICMATCHER", 0, Lifetime::Sporadic);
218
219 return DataProcessorSpec{
220 "cosmics-matcher",
221 dataRequest->inputs,
222 outputs,
223 AlgorithmSpec{adaptFromTask<CosmicsMatchingSpec>(dataRequest, ggRequest, usePV, useMC)},
224 opts};
225}
226
227} // namespace globaltracking
228} // namespace o2
Class of a TPC cluster in TPC-native coordinates (row, time)
Definition of the ITS/MFT clusterer settings.
Definition of the ITSMFT compact cluster.
gsl::span< const o2::MCCompLabel > MCLabelsTr
Wrapper container for different reconstructed object types.
Definition of the ClusterTopology class.
Definition of the Names Generator class.
Definition of the GeometryManager class.
o2::raw::RawFileWriter * raw
Helper for geometry and GRP related CCDB requests.
Header of the General Run Parameters object.
Accessor for TrackParCov derived objects from multiple containers.
Global index for barrel track: provides provenance (detectors combination), index in respective array...
Definition of the GeometryTGeo class.
Definition of the ITSMFT ROFrame (trigger) record.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Configurable params for cosmics matching.
Class to perform matching/refit of cosmic tracks legs.
Class to store the output of the matching to TOF.
POD correction map.
Definition of the ITS track.
Result of refitting TPC-ITS matched track.
Result of refitting TPC with TOF match constraint.
Helper class to extract VDrift from different sources.
Helper class to obtain TPC clusters / digits / labels from DPL.
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static std::string getConfigOutputFileName(const std::string &procName, const std::string &confName="", bool json=true)
Definition NameConf.cxx:120
static std::string asJSON(std::string const &keyOnly="")
static void write(std::string const &filename, std::string const &keyOnly="")
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
static constexpr ID ITS
Definition DetID.h:63
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
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.
ServiceRegistryRef services()
The services registry associated with this processing context.
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
CosmicsMatchingSpec(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, bool usePV, bool useMC)
void setITSROFrameLengthMUS(float fums)
void setITSDict(const o2::itsmft::TopologyDictionary *dict)
void setDebugFlag(UInt_t flag, bool on=true)
set the name of output debug file
void setTPCVDrift(const o2::tpc::VDriftCorrFact &v)
void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD *maph)
void process(const o2::globaltracking::RecoContainer &data)
static GeometryTGeo * Instance()
void fillMatrixCache(int mask) override
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 VDriftCorrFact & getVDriftObject() const
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
static std::string_view getSourceName(Source s)
bool isUpdated() const
GLenum src
Definition glcorearb.h:1767
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
constexpr double LHCBunchSpacingNS
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
framework::DataProcessorSpec getCosmicsMatchingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool usePV, bool useMC)
create a processor spec
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string name
The name of the associated DataProcessorSpec.
Definition DeviceSpec.h:50
size_t inputTimesliceId
The time pipelining id of this particular device.
Definition DeviceSpec.h:68
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
static constexpr int T2L
Definition Cartesian.h:55
static constexpr int T2GRot
Definition Cartesian.h:57
float refTimeOffset
additive time offset reference (\mus)
float refVDrift
reference vdrift for which factor was extracted
float timeOffsetCorr
additive time offset correction (\mus)
float corrFact
drift velocity correction factor (multiplicative)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"