Project
Loading...
Searching...
No Matches
tof-matcher-workflow.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
31#include "TOFBase/Utils.h"
33#include "TSystem.h"
37
38using namespace o2::framework;
41// ------------------------------------------------------------------
42void customize(std::vector<o2::framework::CallbacksPolicy>& policies)
43{
45}
46
47void customize(std::vector<o2::framework::CompletionPolicy>& policies)
48{
49 // ordered policies for the writers
50 policies.push_back(CompletionPolicyHelpers::consumeWhenAllOrdered(".*(?:TOF|tof).*[W,w]riter.*"));
51}
52
53// we need to add workflow options before including Framework/runDataProcessing
54void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
55{
56 // option allowing to set parameters
57 std::vector<o2::framework::ConfigParamSpec> options{
58 {"disable-mc", o2::framework::VariantType::Bool, false, {"disable MC propagation even if available"}},
59 {"tof-lanes", o2::framework::VariantType::Int, 1, {"number of parallel lanes up to the matcher"}},
60 {"disable-root-input", o2::framework::VariantType::Bool, false, {"disable root-files input reader"}},
61 {"disable-root-output", o2::framework::VariantType::Bool, false, {"disable root-files output writer"}},
62 {"track-sources", VariantType::String, std::string{GID::ALL}, {"comma-separated list of sources to use: allowed TPC,ITS-TPC,TPC-TRD,ITS-TPC-TRD (all)"}},
63 {"use-fit", o2::framework::VariantType::Bool, false, {"enable access to fit info for calibration"}},
64 {"use-ccdb", o2::framework::VariantType::Bool, false, {"enable access to ccdb tof calibration objects"}},
65 {"strict-matching", o2::framework::VariantType::Bool, false, {"High purity preliminary matching"}},
66 {"output-type", o2::framework::VariantType::String, "matching-info", {"matching-info, calib-info"}},
67 {"enable-dia", o2::framework::VariantType::Bool, false, {"to require diagnostic freq and then write to calib outputs (obsolete since now default)"}},
68 {"trd-extra-tolerance", o2::framework::VariantType::Float, 500.0f, {"Extra time tolerance for TRD tracks in ns"}},
69 {"refit-tpc-tof", o2::framework::VariantType::Bool, false, {"Refit unconstrained TPC tracks matched to TOF (if false - just move)"}},
70 {"write-matchable", o2::framework::VariantType::Bool, false, {"write all matchable pairs in a file (o2matchable_tof.root)"}},
71 {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}},
72 {"combine-devices", o2::framework::VariantType::Bool, false, {"merge DPL source/writer devices"}}};
75 std::swap(workflowOptions, options);
76}
77
78// ------------------------------------------------------------------
79
81
83{
84 WorkflowSpec specs;
85
86 // Update the (declared) parameters if changed from the command line
87 o2::conf::ConfigurableParam::updateFromString(configcontext.options().get<std::string>("configKeyValues"));
88 // write the configuration used for the workflow
89 o2::conf::ConfigurableParam::writeINI("o2match-tof-workflow_configuration.ini");
90
91 auto useMC = !configcontext.options().get<bool>("disable-mc");
92 auto disableRootIn = configcontext.options().get<bool>("disable-root-input");
93 auto disableRootOut = configcontext.options().get<bool>("disable-root-output");
94 auto useFIT = configcontext.options().get<bool>("use-fit");
95 auto useCCDB = configcontext.options().get<bool>("use-ccdb");
96 auto strict = configcontext.options().get<bool>("strict-matching");
97 auto diagnostic = configcontext.options().get<bool>("enable-dia");
98 auto extratolerancetrd = configcontext.options().get<float>("trd-extra-tolerance");
99 auto writeMatchable = configcontext.options().get<bool>("write-matchable");
100 auto sclOpt = o2::tpc::CorrectionMapsOptions::parseGlobalOptions(configcontext.options());
101 bool writematching = 0;
102 bool writecalib = 0;
103 bool refitTPCTOF = configcontext.options().get<bool>("refit-tpc-tof");
104 auto outputType = configcontext.options().get<std::string>("output-type");
105 auto nLanes = configcontext.options().get<int>("tof-lanes");
106 if (outputType.rfind("matching-info") < outputType.size()) {
107 writematching = 1;
108 }
109 if (outputType.rfind("calib-info") < outputType.size()) {
110 writecalib = 1;
111 if (!diagnostic) {
112 diagnostic = true;
113 LOG(info) << "Diagnostic switched on since required for calibInfo time";
114 }
115 }
116
117 // if (!writecalib) {
118 // useFIT = false;
119 // }
120
121 LOG(debug) << "TOF MATCHER WORKFLOW configuration";
122 LOG(debug) << "TOF track inputs = " << configcontext.options().get<std::string>("track-sources");
123 LOG(debug) << "TOF output = " << outputType;
124 LOG(debug) << "TOF disable-mc = " << configcontext.options().get<std::string>("disable-mc");
125 LOG(debug) << "TOF use-ccdb = " << useCCDB;
126 LOG(debug) << "TOF use-fit = " << useFIT;
127 LOG(debug) << "TOF disable-root-input = " << disableRootIn;
128 LOG(debug) << "TOF disable-root-output = " << disableRootOut;
129 LOG(debug) << "TOF matching in strict mode = " << strict;
130 LOG(debug) << "TOF extra time tolerance for TRD tracks = " << extratolerancetrd;
131 LOG(debug) << "Store all matchables = " << writeMatchable;
132 LOG(debug) << "TOF Nlanes for matcher = " << nLanes;
133
134 //GID::mask_t alowedSources = GID::getSourcesMask("TPC,ITS-TPC");
135 GID::mask_t alowedSources = GID::getSourcesMask("TPC,ITS-TPC,TPC-TRD,ITS-TPC-TRD");
136
137 GID::mask_t src = alowedSources & GID::getSourcesMask(configcontext.options().get<std::string>("track-sources"));
138 if (strict && (src & ~GID::getSourcesMask("TPC,TPC-TRD")).any()) {
139 LOGP(warning, "In strict matching mode only TPC and TPC-TRD sources allowed, {} asked, redefining", GID::getSourcesNames(src));
140 src &= GID::getSourcesMask("TPC,TPC-TRD");
141 }
142 GID::mask_t mcmaskcl;
144 GID::mask_t clustermask = GID::getSourcesMask("TOF");
145 if (useFIT) {
146 clustermask |= GID::getSourceMask(GID::FT0);
147 }
148 if (src[GID::TPC] && refitTPCTOF) { // load clusters
149 clustermask |= GID::getSourceMask(GID::TPC);
150 }
151 if (sclOpt.requestCTPLumi) {
152 src = src | GID::getSourcesMask("CTP");
153 }
154 if (useMC) {
155 mcmaskcl |= GID::getSourceMask(GID::TOF);
156 }
157 // pass strict flag to fetch eventual TPC-TRD input with correct subspec
158 WorkflowSpec inputspecs;
159 o2::globaltracking::InputHelper::addInputSpecs(configcontext, inputspecs, clustermask, nonemask, src, useMC, mcmaskcl, GID::getSourcesMask(GID::ALL), strict);
160 if (configcontext.options().get<bool>("combine-devices")) {
161 std::vector<DataProcessorSpec> unmerged;
162 specs.push_back(specCombiner("TOF-readers", inputspecs, unmerged));
163 if (unmerged.size() > 0) {
164 LOG(fatal) << "Unexpected DPL device merge problem";
165 }
166 } else {
167 for (auto& s : inputspecs) {
168 specs.push_back(s);
169 }
170 }
171 if (!configcontext.options().get<bool>("disable-root-input")) {
172 specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt));
173 }
174 specs.emplace_back(o2::globaltracking::getTOFMatcherSpec(src, useMC, useFIT, refitTPCTOF, strict, extratolerancetrd, writeMatchable, sclOpt.requestCTPLumi, nLanes)); // doTPCrefit not yet supported (need to load TPC clusters?)
175
176 if (!disableRootOut) {
177 std::vector<DataProcessorSpec> writers;
178 if (writematching) {
179 if (GID::includesSource(GID::TPC, src)) { // matching to TPC was requested
180 writers.emplace_back(o2::tof::getTOFMatchedWriterSpec(useMC, "o2match_tof_tpc.root", true, (int)o2::dataformats::MatchInfoTOFReco::TrackType::TPC, strict));
181 }
182 if (GID::includesSource(GID::ITSTPC, src)) { // matching to ITS-TPC was requested, there is not strict mode in this case
183 writers.emplace_back(o2::tof::getTOFMatchedWriterSpec(useMC, "o2match_tof_itstpc.root", false, (int)o2::dataformats::MatchInfoTOFReco::TrackType::ITSTPC, false));
184 }
185 if (GID::includesSource(GID::TPCTRD, src)) { // matching to TPC-TRD was requested, there is not strict mode in this case
186 writers.emplace_back(o2::tof::getTOFMatchedWriterSpec(useMC, "o2match_tof_tpctrd.root", false, (int)o2::dataformats::MatchInfoTOFReco::TrackType::TPCTRD, strict));
187 }
188 if (GID::includesSource(GID::ITSTPCTRD, src)) { // matching to ITS-TPC-TRD was requested, there is not strict mode in this case
189 writers.emplace_back(o2::tof::getTOFMatchedWriterSpec(useMC, "o2match_tof_itstpctrd.root", false, (int)o2::dataformats::MatchInfoTOFReco::TrackType::ITSTPCTRD, false));
190 }
191 }
192 if (writecalib) {
193 writers.emplace_back(o2::tof::getTOFCalibWriterSpec("o2calib_tof.root", 0, diagnostic));
194 }
195
196 if (writeMatchable) {
197 specs.emplace_back(o2::tof::getTOFMatchableWriterSpec("o2matchable_tof.root"));
198 }
199
200 if (configcontext.options().get<bool>("combine-devices")) {
201 std::vector<DataProcessorSpec> unmerged;
202 specs.push_back(specCombiner("TOF-writers", writers, unmerged));
203 if (unmerged.size() > 0) {
204 LOG(fatal) << "Unexpected DPL device merge problem";
205 }
206 } else {
207 for (auto& s : writers) {
208 specs.push_back(s);
209 }
210 }
211 }
212
213 // configure dpl timer to inject correct firstTForbit: start from the 1st orbit of TF containing 1st sampled orbit
214 o2::raw::HBFUtilsInitializer hbfIni(configcontext, specs);
215
216 return std::move(specs);
217}
Helper class to parse options for correction maps.
std::ostringstream debug
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Global index for barrel track: provides provenance (detectors combination), index in respective array...
Helper function to tokenize sequences and ranges of integral numbers.
DPL completion policy helper for TPC scetor data.
static void writeINI(std::string const &filename, std::string const &keyOnly="")
static void updateFromString(std::string const &)
static mask_t getSourcesMask(const std::string_view srcList)
static std::string getSourcesNames(mask_t srcm)
static constexpr std::string_view NONE
keywork for no sources
static constexpr std::string_view ALL
keywork for all sources
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
ConfigParamRegistry & options() const
static int addInputSpecs(const o2::framework::ConfigContext &configcontext, o2::framework::WorkflowSpec &specs, GID::mask_t maskClusters, GID::mask_t maskMatches, GID::mask_t maskTracks, bool useMC=true, GID::mask_t maskClustersMC=GID::getSourcesMask(GID::ALL), GID::mask_t maskTracksMC=GID::getSourcesMask(GID::ALL), bool subSpecStrict=false)
static void addGlobalOptions(std::vector< o2::framework::ConfigParamSpec > &options)
static CorrectionMapsGloOpts parseGlobalOptions(const o2::framework::ConfigParamRegistry &opts)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
o2::framework::DataProcessorSpec specCombiner(std::string const &name, std::vector< DataProcessorSpec > const &speccollection, std::vector< DataProcessorSpec > &remaining)
std::vector< DataProcessorSpec > WorkflowSpec
framework::DataProcessorSpec getTOFMatcherSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, bool requestCTPLumi, int nlanes=1)
create a processor spec
o2::framework::DataProcessorSpec getTOFMatchedWriterSpec(bool useMC, const char *outdef="o2match_tof.root", bool writeTracks=false, int mode=0, bool strict=false)
o2::framework::DataProcessorSpec getTOFMatchableWriterSpec(const char *outdef="o2matchable_tof.root")
o2::framework::DataProcessorSpec getTOFCalibWriterSpec(const char *outdef="o2calib_tof.root", bool toftpc=false, bool addDia=false, bool onlyDia=false)
o2::framework::DataProcessorSpec getTPCScalerSpec(const o2::tpc::CorrectionMapsGloOpts &sclOpts)
static CompletionPolicy consumeWhenAllOrdered(const char *name, CompletionPolicy::Matcher matcher)
as consumeWhenAll, but ensures that records are processed with incremental timeSlice (DataHeader::sta...
static void addNewTimeSliceCallback(std::vector< o2::framework::CallbacksPolicy > &policies)
static void addConfigOption(std::vector< o2::framework::ConfigParamSpec > &opts, const std::string &defOpt=std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE))
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
WorkflowSpec defineDataProcessing(ConfigContext const &configcontext)
void customize(std::vector< o2::framework::CallbacksPolicy > &policies)