Project
Loading...
Searching...
No Matches
GlobalFwdMatchingSpec.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 <vector>
15#include <string>
16#include "TStopwatch.h"
17#include "Framework/Task.h"
35#include "TGeoGlobalMagField.h"
36#include "Field/MagneticField.h"
39
40using namespace o2::framework;
41using MCLabelsTr = gsl::span<const o2::MCCompLabel>;
43
44namespace o2
45{
46namespace globaltracking
47{
48
50{
51 public:
52 GlobalFwdMatchingDPL(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, bool useMC, bool MatchRootOutput)
53 : mDataRequest(dr), mGGCCDBRequest(gr), mUseMC(useMC), mMatchRootOutput(MatchRootOutput) {}
54 ~GlobalFwdMatchingDPL() override = default;
55 void init(InitContext& ic) final;
56 void run(ProcessingContext& pc) final;
57 void endOfStream(EndOfStreamContext& ec) final;
58 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
59
60 private:
61 void updateTimeDependentParams(ProcessingContext& pc);
62 std::shared_ptr<DataRequest> mDataRequest;
63 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
64 bool mMatchRootOutput = false;
65 o2::globaltracking::MatchGlobalFwd mMatching; // Forward matching engine
66 const o2::itsmft::TopologyDictionary* mMFTDict = nullptr; // cluster patterns dictionary
67
68 bool mUseMC = true;
69 TStopwatch mTimer;
70};
71
73{
75 mMatching.setMCTruthOn(mUseMC);
76
77 const auto& matchingParam = GlobalFwdMatchingParam::Instance();
78 if (matchingParam.isMatchUpstream() && mMatchRootOutput) {
79 LOG(fatal) << "Invalid MFTMCH matching configuration: matchUpstream and enable-match-output";
80 }
81}
82
84{
85 mTimer.Start(false);
86 RecoContainer recoData;
87 recoData.collectData(pc, *mDataRequest.get());
88 updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
89
90 mMatching.run(recoData);
91
92 const auto& matchingParam = GlobalFwdMatchingParam::Instance();
93
94 if (matchingParam.saveMode == kSaveTrainingData) {
95 pc.outputs().snapshot(Output{"GLO", "GLFWDMFT", 0}, mMatching.getMFTMatchingPlaneParams());
96 pc.outputs().snapshot(Output{"GLO", "GLFWDMCH", 0}, mMatching.getMCHMatchingPlaneParams());
97 pc.outputs().snapshot(Output{"GLO", "GLFWDINF", 0}, mMatching.getMFTMCHMatchInfo());
98 } else {
99 pc.outputs().snapshot(Output{"GLO", "GLFWD", 0}, mMatching.getMatchedFwdTracks());
100 }
101
102 if (mUseMC) {
103 pc.outputs().snapshot(Output{"GLO", "GLFWD_MC", 0}, mMatching.getMatchLabels());
104 }
105 if (mMatchRootOutput) {
106 pc.outputs().snapshot(Output{"GLO", "MTC_MFTMCH", 0}, mMatching.getMFTMCHMatchInfo());
107 }
108 mTimer.Stop();
109}
110
112{
113 LOGF(info, "Forward matcher total timing: Cpu: %.3e Real: %.3e s in %d slots",
114 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
115}
116
118{
120 if (matcher == ConcreteDataMatcher("GLO", "GRPMAGFIELD", 0)) {
122 }
123 return;
124 }
125 if (matcher == ConcreteDataMatcher("MFT", "CLUSDICT", 0)) {
126 LOG(info) << "cluster dictionary updated";
128 return;
129 }
130 if (matcher == ConcreteDataMatcher("MFT", "ALPIDEPARAM", 0)) {
131 LOG(info) << "MFT Alpide param updated";
132 return;
133 }
134}
135
136void GlobalFwdMatchingDPL::updateTimeDependentParams(ProcessingContext& pc)
137{
139 static bool initOnceDone = false;
140 if (!initOnceDone) { // this params need to be queried only once
141 initOnceDone = true;
142
143 auto field = static_cast<o2::field::MagneticField*>(TGeoGlobalMagField::Instance()->GetField());
144 double centerMFT[3] = {0, 0, -61.4}; // Field at center of MFT
145 auto Bz = field->getBz(centerMFT);
146 LOG(info) << "Setting Global forward matching Bz = " << Bz;
147 mMatching.setBz(Bz);
148 mMatching.setMFTTriggered(!o2::base::GRPGeomHelper::instance().getGRPECS()->isDetContinuousReadOut(o2::detectors::DetID::MFT));
149 if (o2::base::GRPGeomHelper::instance().getGRPECS()->getRunType() != o2::parameters::GRPECSObject::RunType::COSMICS) {
150 mMatching.setBunchFilling(o2::base::GRPGeomHelper::instance().getGRPLHCIF()->getBunchFilling());
151 }
152
153 // apply needed settings
155 if (mMatching.isMFTTriggered()) {
156 mMatching.setMFTROFrameLengthMUS(alpParams.roFrameLengthTrig / 1.e3); // MFT ROFrame duration in \mus
157 } else {
158 mMatching.setMFTROFrameLengthInBC(alpParams.roFrameLengthInBC); // MFT ROFrame duration in \mus
159 }
160 if (alpParams.roFrameBiasInBC != 0) {
161 mMatching.setMFTROFrameBiasInBC(alpParams.roFrameBiasInBC); // MFT ROFrame bias in BCs wrt orbit start
162 LOG(info) << "Setting MFT ROF bias to " << alpParams.roFrameBiasInBC << " BCs";
163 }
164
165 mMatching.init();
166 }
167 // we may have other params which need to be queried regularly
168}
169
170DataProcessorSpec getGlobalFwdMatchingSpec(bool useMC, bool matchRootOutput)
171{
172
173 const auto& matchingParam = GlobalFwdMatchingParam::Instance();
174
175 std::vector<OutputSpec> outputs;
176 auto dataRequest = std::make_shared<DataRequest>();
177
179
180 dataRequest->requestMFTClusters(false); // MFT clusters labels are not used
181 dataRequest->requestTracks(src, useMC);
182
183 if (matchingParam.isMatchUpstream()) {
184 dataRequest->requestMFTMCHMatches(useMC); // Request MFTMCH Matches
185 }
186
187 if (matchingParam.useMIDMatch) {
188 dataRequest->requestMCHMIDMatches(false); // Request MCHMID Matches. Labels are not used
189 }
190 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
191 true, // GRPECS=true
192 true, // GRPLHCIF
193 true, // GRPMagField
194 false, // askMatLUT
196 dataRequest->inputs,
197 true); // query only once all objects except mag.field
198
199 if (matchingParam.saveMode == kSaveTrainingData) {
200 outputs.emplace_back("GLO", "GLFWDMFT", 0, Lifetime::Timeframe);
201 outputs.emplace_back("GLO", "GLFWDMCH", 0, Lifetime::Timeframe);
202 outputs.emplace_back("GLO", "GLFWDINF", 0, Lifetime::Timeframe);
203 } else {
204 outputs.emplace_back("GLO", "GLFWD", 0, Lifetime::Timeframe);
205 }
206
207 if (useMC) {
208 outputs.emplace_back("GLO", "GLFWD_MC", 0, Lifetime::Timeframe);
209 }
210
211 if (matchRootOutput) {
212 outputs.emplace_back("GLO", "MTC_MFTMCH", 0, Lifetime::Timeframe);
213 }
214
215 return DataProcessorSpec{
216 "globalfwd-track-matcher",
217 dataRequest->inputs,
218 outputs,
219 AlgorithmSpec{adaptFromTask<GlobalFwdMatchingDPL>(dataRequest, ggRequest, useMC, matchRootOutput)},
220 Options{}};
221}
222
223} // namespace globaltracking
224} // namespace o2
Definition of the ITS/MFT clusterer settings.
gsl::span< const o2::MCCompLabel > MCLabelsTr
Wrapper container for different reconstructed object types.
Definition of the ITSMFT cluster.
Definition of the Names Generator class.
Helper for geometry and GRP related CCDB requests.
Header of the General Run Parameters object.
Global Forward Muon tracks.
Definition of the ITSMFT ROFrame (trigger) record.
Definition of the MagF class.
Class to perform MFT MCH (and MID) matching.
Definition of tools for track extrapolation.
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)
static constexpr ID MFT
Definition DetID.h:71
Double_t getBz(const Double_t *xyz) const
Method to calculate the field at point xyz.
void snapshot(const Output &spec, T const &object)
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
void endOfStream(EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
GlobalFwdMatchingDPL(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, bool useMC, bool MatchRootOutput)
void setMFTDictionary(const o2::itsmft::TopologyDictionary *d)
const std::vector< o2::dataformats::MatchInfoFwd > & getMFTMCHMatchInfo() const
void setBunchFilling(const o2::BunchFilling &bf)
set Bunch filling and init helpers for validation by BCs
const std::vector< o2::mft::TrackMFT > & getMFTMatchingPlaneParams() const
const std::vector< o2::track::TrackParCovFwd > & getMCHMatchingPlaneParams() const
void setMCTruthOn(bool v)
set MFT ROFrame duration in microseconds
void setMFTROFrameLengthMUS(float fums)
set MFT ROFrame duration in BC (continuous mode only)
void setMFTROFrameLengthInBC(int nbc)
set MFT ROFrame bias in BC (continuous mode only) or time shift applied already as MFTAlpideParam....
const std::vector< o2::dataformats::GlobalFwdTrack > & getMatchedFwdTracks() const
void run(const o2::globaltracking::RecoContainer &inp)
const std::vector< o2::MCCompLabel > & getMatchLabels() const
static void setField()
GLenum src
Definition glcorearb.h:1767
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
framework::DataProcessorSpec getGlobalFwdMatchingSpec(bool useMC, bool matchRootOutput)
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"