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, GTrackID::mask_t src, GTrackID::mask_t srcPVVeto, bool usePV, bool useMC) : mDataRequest(dr), mGGCCDBRequest(gr), mSeedSources(src), mPVVetoSources(srcPVVeto), 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 GTrackID::mask_t mSeedSources; // track sources used as legs
85 GTrackID::mask_t mPVVetoSources; // sources whose PV contributors veto the legs they contain
86 bool mUseMC = true;
87 bool mUsePVInfo = false;
88 TStopwatch mTimer;
89};
90
92{
93 mTimer.Stop();
94 mTimer.Reset();
96 mMatching.setDebugFlag(ic.options().get<int>("debug-tree-flags"));
97 mMatching.setUseMC(mUseMC);
98 mMatching.setUsePVInfo(mUsePVInfo);
99 mMatching.setSeedSources(mSeedSources);
100 mMatching.setPVVetoSources(mPVVetoSources);
101 //
102}
103
105{
106 mTimer.Start(false);
107 RecoContainer recoData;
108 recoData.collectData(pc, *mDataRequest.get());
109 updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
110 storeConfigs(pc);
111 mMatching.process(recoData);
112 pc.outputs().snapshot(Output{"GLO", "COSMICTRC", 0}, mMatching.getCosmicTracks());
113 if (mUseMC) {
114 pc.outputs().snapshot(Output{"GLO", "COSMICTRC_MC", 0}, mMatching.getCosmicTracksLbl());
115 }
116 mTimer.Stop();
117}
118
119void CosmicsMatchingSpec::storeConfigs(ProcessingContext& pc)
120{
121 static bool first = true;
122 if (first) {
123 first = false;
125 const auto& conf = MatchCosmicsParams::Instance();
127 TMap md;
128 md.SetOwnerKeyValue();
129 md.Add(new TObjString(conf.getName().c_str()), new TObjString(o2::conf::ConfigurableParam::asJSON(conf.getName()).c_str()));
130 pc.outputs().snapshot(Output{"META", "COSMICMATCHER", 0}, md);
131 }
132 }
133}
134
135void CosmicsMatchingSpec::updateTimeDependentParams(ProcessingContext& pc)
136{
138 mTPCVDriftHelper.extractCCDBInputs(pc);
139 auto const& raw = pc.inputs().get<const char*>("corrMap");
140 mCorrMap = &gpu::TPCFastTransformPOD::get(raw);
141 static bool initOnceDone = false;
142 if (!initOnceDone) { // this params need to be queried only once
143 initOnceDone = true;
144 o2::its::GeometryTGeo::Instance()->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2GRot) | o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L));
145
146 // pc.inputs().get<o2::itsmft::TopologyDictionary*>("cldict"); // called by the RecoContainer
147 // also alpParams is called by the RecoContainer
150 if (!grp->isDetContinuousReadOut(DetID::ITS)) {
151 mMatching.setITSROFrameLengthMUS(alpParams.roFrameLengthTrig / 1.e3); // ITS ROFrame duration in \mus
152 } else {
153 mMatching.setITSROFrameLengthMUS(alpParams.roFrameLengthInBC * o2::constants::lhc::LHCBunchSpacingNS * 1e-3); // ITS ROFrame duration in \mus
154 }
155 mMatching.init();
156 }
157 mMatching.setTPCCorrMaps(mCorrMap);
158 if (mTPCVDriftHelper.isUpdated()) {
159 LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
160 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
161 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
162 mTPCVDriftHelper.getSourceName());
163 mMatching.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
164 mTPCVDriftHelper.acknowledgeUpdate();
165 }
166}
167
169{
171 return;
172 }
173 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
174 return;
175 }
176 if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) {
177 LOG(info) << "cluster dictionary updated";
178 mMatching.setITSDict((const o2::itsmft::TopologyDictionary*)obj);
179 return;
180 }
181}
182
184{
185 mMatching.end();
186 LOGF(info, "Cosmics matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
187 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
188}
189
191{
192 return GTrackID::includesDet(o2::detectors::DetID::ITS, src) ? GTrackID::getSourceMask(GTrackID::ITS) & ~src : GTrackID::mask_t{};
193}
194
196{
197 auto src = srcPVContributors;
199 src |= GTrackID::getSourceMask(GTrackID::ITSTPCTRD);
200 }
202 src |= GTrackID::getSourceMask(GTrackID::TPCTRD);
203 }
205 src |= GTrackID::getSourceMask(GTrackID::ITSTPC);
206 }
207 return src;
208}
209
210DataProcessorSpec getCosmicsMatchingSpec(GTrackID::mask_t src, bool usePV, bool useMC, bool itsStag, bool useTOFClusters, GTrackID::mask_t srcPVContributors)
211{
212 std::vector<OutputSpec> outputs;
213 Options opts{
214 {"material-lut-path", VariantType::String, "", {"Path of the material LUT file"}},
215 {"debug-tree-flags", VariantType::Int, 0, {"DebugFlagTypes bit-pattern for debug tree"}}};
216
217 auto dataRequest = std::make_shared<DataRequest>();
218 dataRequest->setITSPerLayer(itsStag);
219
220 dataRequest->requestTracks(src, useMC);
221 dataRequest->requestTracks(getLegITSSources(src), false); // the refit of legs with an ITS part reads their ITS track
222 dataRequest->requestClusters(src, false); // no MC labels for clusters needed for refit only
223 if (useTOFClusters) {
224 dataRequest->requestTOFClusters(false); // TOF flight pairs of the candidate pairs (MatchCosmicsParams::tofFlightSelection)
225 }
226 if (usePV) {
227 dataRequest->requestPrimaryVertices(useMC);
228 // global tracks whose primary-vertex contributors veto their TPC track as a leg (MatchCosmicsParams::discardPVContributors), not legs
229 dataRequest->requestTracks(addPVContributorParents(srcPVContributors) & ~src, useMC); // same MC flag: some requests are shared with the legs
230 }
231
232 outputs.emplace_back("GLO", "COSMICTRC", 0, Lifetime::Timeframe);
233 if (useMC) {
234 outputs.emplace_back("GLO", "COSMICTRC_MC", 0, Lifetime::Timeframe);
235 }
236
237 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
238 true, // GRPECS=true
239 false, // GRPLHCIF
240 true, // GRPMagField
241 true, // askMatLUT
243 dataRequest->inputs,
244 true);
245 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
246 dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe);
247
248 outputs.emplace_back("META", "COSMICMATCHER", 0, Lifetime::Sporadic);
249
250 return DataProcessorSpec{
251 "cosmics-matcher",
252 dataRequest->inputs,
253 outputs,
254 AlgorithmSpec{adaptFromTask<CosmicsMatchingSpec>(dataRequest, ggRequest, src, usePV ? srcPVContributors : GTrackID::mask_t{}, usePV, useMC)},
255 opts};
256}
257
258} // namespace globaltracking
259} // namespace o2
Class of a TPC cluster in TPC-native coordinates (row, time)
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 the ITS/MFT clusterer settings.
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:138
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:60
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
CosmicsMatchingSpec(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, GTrackID::mask_t src, GTrackID::mask_t srcPVVeto, bool usePV, bool useMC)
void run(ProcessingContext &pc) final
void setITSROFrameLengthMUS(float fums)
void setPVVetoSources(GTrackID::mask_t src)
sources whose PV contributors veto the legs they contain
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 setSeedSources(GTrackID::mask_t src)
track sources used as legs (other loaded ones resolve PV contributors)
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
GLint first
Definition glcorearb.h:399
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:579
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
o2::dataformats::GlobalTrackID::mask_t getLegITSSources(o2::dataformats::GlobalTrackID::mask_t src)
o2::dataformats::GlobalTrackID::mask_t addPVContributorParents(o2::dataformats::GlobalTrackID::mask_t srcPVContributors)
srcPVContributors plus the parent matches needed to resolve their single-detector parts (RecoContaine...
framework::DataProcessorSpec getCosmicsMatchingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool usePV, bool useMC, bool itsStag, bool useTOFClusters=false, o2::dataformats::GlobalTrackID::mask_t srcPVContributors={})
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)
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"