Project
Loading...
Searching...
No Matches
TrackMatcherSpec.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
16
17#include "TrackMatcherSpec.h"
18
19#include <chrono>
20#include <string>
21#include <vector>
22
23#include <gsl/span>
24
27#include "Framework/Task.h"
28#include "Framework/Logger.h"
37
38namespace o2
39{
40namespace muon
41{
42
43using namespace o2::framework;
44
46{
47 public:
48 TrackMatcherTask(bool useMC = false) : mUseMC(useMC) {}
49
50 //_________________________________________________________________________________________________
52 void init(InitContext& ic)
53 {
54 LOG(info) << "initializing track matching";
55
56 auto config = ic.options().get<std::string>("mch-config");
57 if (!config.empty()) {
58 conf::ConfigurableParam::updateFromFile(config, "MUONMatching", true);
59 }
60 mTrackMatcher.init();
61
62 auto stop = [this]() {
63 LOG(info) << "track matching duration = " << mElapsedTime.count() << " s";
64 };
65 ic.services().get<CallbackService>().set<CallbackService::Id::Stop>(stop);
66 }
67
68 //_________________________________________________________________________________________________
71 {
72 auto mchROFs = pc.inputs().get<gsl::span<mch::ROFRecord>>("mchrofs");
73 auto mchTracks = pc.inputs().get<gsl::span<mch::TrackMCH>>("mchtracks");
74 auto midROFs = pc.inputs().get<gsl::span<mid::ROFRecord>>("midrofs");
75 auto midTracks = pc.inputs().get<gsl::span<mid::Track>>("midtracks");
76
77 auto tStart = std::chrono::high_resolution_clock::now();
78 mTrackMatcher.match(mchROFs, mchTracks, midROFs, midTracks);
79 auto tEnd = std::chrono::high_resolution_clock::now();
80 mElapsedTime += tEnd - tStart;
81
82 pc.outputs().snapshot(OutputRef{"muontracks"}, mTrackMatcher.getMuons());
83
84 if (mUseMC) {
85 auto mchTrackLabels = pc.inputs().get<gsl::span<MCCompLabel>>("mchtracklabels");
86 auto midTrackLabels = pc.inputs().get<gsl::span<MCCompLabel>>("midtracklabels");
87
88 std::vector<MCCompLabel> muonLabels;
89 for (const auto& muon : mTrackMatcher.getMuons()) {
90 const auto& mchTrackLabel = mchTrackLabels[muon.getMCHRef().getIndex()];
91 const auto& midTrackLabel = midTrackLabels[muon.getMIDRef().getIndex()];
92 muonLabels.push_back(mchTrackLabel);
93 // tag fake matching (different labels or at least one of them is fake)
94 muonLabels.back().setFakeFlag(midTrackLabel.compare(mchTrackLabel) != 1);
95 }
96
97 pc.outputs().snapshot(OutputRef{"muontracklabels"}, muonLabels);
98 }
99 }
100
101 private:
102 bool mUseMC = false;
103 TrackMatcher mTrackMatcher{};
104 std::chrono::duration<double> mElapsedTime{};
105};
106
107//_________________________________________________________________________________________________
109{
110 std::vector<InputSpec> inputSpecs{InputSpec{"mchrofs", "MCH", "TRACKROFS", 0, Lifetime::Timeframe},
111 InputSpec{"mchtracks", "MCH", "TRACKS", 0, Lifetime::Timeframe},
112 InputSpec{"midrofs", "MID", "TRACKROFS", 0, Lifetime::Timeframe},
113 InputSpec{"midtracks", "MID", "TRACKS", 0, Lifetime::Timeframe}};
114
115 std::vector<OutputSpec> outputSpecs{OutputSpec{{"muontracks"}, "GLO", "MTC_MCHMID", 0, Lifetime::Timeframe}};
116
117 if (useMC) {
118 inputSpecs.emplace_back(InputSpec{"mchtracklabels", "MCH", "TRACKLABELS", 0, Lifetime::Timeframe});
119 inputSpecs.emplace_back(InputSpec{"midtracklabels", "MID", "TRACKLABELS", 0, Lifetime::Timeframe});
120
121 outputSpecs.emplace_back(OutputSpec{{"muontracklabels"}, "GLO", "MCMTC_MCHMID", 0, Lifetime::Timeframe});
122 }
123
124 return DataProcessorSpec{
125 name,
126 inputSpecs,
127 outputSpecs,
128 AlgorithmSpec{adaptFromTask<TrackMatcherTask>(useMC)},
129 Options{{"mch-config", VariantType::String, "", {"JSON or INI file with matching parameters"}}}};
130}
131
132} // namespace muon
133} // namespace o2
Reconstructed MID track.
Definition of the MCH ROFrame record.
Definition of the MID event record.
Definition of the MUON track.
Definition of the MCH track.
Definition of a data processor to match MCH and MID tracks.
Definition of a class to match MCH and MID tracks.
static void updateFromFile(std::string const &, std::string const &paramsList="", bool unchangedOnly=false)
void snapshot(const Output &spec, T const &object)
ServiceRegistryRef services()
Definition InitContext.h:34
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.
TrackMatcherTask(bool useMC=false)
void run(ProcessingContext &pc)
run the track matching
void init(InitContext &ic)
prepare the track matching
Class to match MCH and MID tracks.
void init()
prepare to run the matching algorithm
const std::vector< TrackMCHMID > & getMuons() const
get the MCH-MID matched tracks
void match(gsl::span< const mch::ROFRecord > &mchROFs, gsl::span< const mch::TrackMCH > &mchTracks, gsl::span< const mid::ROFRecord > &midROFs, gsl::span< const mid::Track > &midTracks)
run the matching algorithm
GLuint const GLchar * name
Definition glcorearb.h:781
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
DataProcessorSpec getTrackMatcherSpec(bool useMC, const char *name)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< o2::mid::ROFRecord > midROFs
std::vector< o2::mch::ROFRecord > mchROFs
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"