Project
Loading...
Searching...
No Matches
ClustererSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 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
17#include "Framework/Logger.h"
19
20#include <format>
21
22namespace o2::trk
23{
24
26{
27 mNThreads = std::max(1, ic.options().get<int>("nthreads"));
28#ifdef O2_WITH_ACTS
29 mUseACTS = ic.options().get<bool>("useACTS");
30#endif
31}
32
34{
35 o2::base::GeometryManager::loadGeometry("sgn_geometry.root", false, true);
36
37 uint64_t totalClusters = 0;
38 for (int iLayer = 0; iLayer < mLayers; ++iLayer) {
39 auto digits = pc.inputs().get<gsl::span<o2::itsmft::Digit>>(std::format("digits_{}", iLayer));
40 auto rofs = pc.inputs().get<gsl::span<o2::itsmft::ROFRecord>>(std::format("ROframes_{}", iLayer));
41
42 gsl::span<const char> labelbuffer;
43 if (mUseMC) {
44 labelbuffer = pc.inputs().get<gsl::span<char>>(std::format("labels_{}", iLayer));
45 }
47
48 std::vector<o2::trk::Cluster> clusters;
49 std::vector<unsigned char> patterns;
50 std::vector<o2::trk::ROFRecord> clusterROFs;
51 std::unique_ptr<o2::dataformats::MCTruthContainer<o2::MCCompLabel>> clusterLabels;
52 if (mUseMC) {
53 clusterLabels = std::make_unique<o2::dataformats::MCTruthContainer<o2::MCCompLabel>>();
54 }
55
56#ifdef O2_WITH_ACTS
57 if (mUseACTS) {
58 LOG(info) << "Running TRKClusterer with ACTS on layer " << iLayer;
59 mClustererACTS.process(digits,
60 rofs,
62 patterns,
63 clusterROFs,
64 mUseMC ? &labels : nullptr,
65 clusterLabels.get());
66 } else
67#endif
68 {
69 LOG(info) << "Running TRKClusterer on layer " << iLayer;
70 mClusterer.process(digits,
71 rofs,
73 patterns,
74 clusterROFs,
75 mUseMC ? &labels : nullptr,
76 clusterLabels.get());
77 }
78
79 const auto subspec = static_cast<o2::framework::DataAllocator::SubSpecificationType>(iLayer);
80 pc.outputs().snapshot(o2::framework::Output{"TRK", "COMPCLUSTERS", subspec}, clusters);
81 pc.outputs().snapshot(o2::framework::Output{"TRK", "PATTERNS", subspec}, patterns);
82 pc.outputs().snapshot(o2::framework::Output{"TRK", "CLUSTERSROF", subspec}, clusterROFs);
83 if (mUseMC) {
84 pc.outputs().snapshot(o2::framework::Output{"TRK", "CLUSTERSMCTR", subspec}, *clusterLabels);
85 }
86 totalClusters += clusters.size();
87 LOGP(info, "TRKClusterer layer {} pushed {} clusters in {} ROFs", iLayer, clusters.size(), clusterROFs.size());
88 }
89
90 LOGP(info, "TRKClusterer produced {} clusters", totalClusters);
91}
92
94{
95 static constexpr int nLayers = o2::trk::AlmiraParam::kNLayers;
96 std::vector<o2::framework::InputSpec> inputs;
97 for (int iLayer = 0; iLayer < nLayers; ++iLayer) {
98 inputs.emplace_back(std::format("digits_{}", iLayer), "TRK", "DIGITS", iLayer, o2::framework::Lifetime::Timeframe);
99 inputs.emplace_back(std::format("ROframes_{}", iLayer), "TRK", "DIGITSROF", iLayer, o2::framework::Lifetime::Timeframe);
100 if (useMC) {
101 inputs.emplace_back(std::format("labels_{}", iLayer), "TRK", "DIGITSMCTR", iLayer, o2::framework::Lifetime::Timeframe);
102 }
103 }
104
105 std::vector<o2::framework::OutputSpec> outputs;
106 for (int iLayer = 0; iLayer < nLayers; ++iLayer) {
107 outputs.emplace_back("TRK", "COMPCLUSTERS", iLayer, o2::framework::Lifetime::Timeframe);
108 outputs.emplace_back("TRK", "PATTERNS", iLayer, o2::framework::Lifetime::Timeframe);
109 outputs.emplace_back("TRK", "CLUSTERSROF", iLayer, o2::framework::Lifetime::Timeframe);
110 if (useMC) {
111 outputs.emplace_back("TRK", "CLUSTERSMCTR", iLayer, o2::framework::Lifetime::Timeframe);
112 }
113 }
114
116 "trk-clusterer",
117 inputs,
118 outputs,
119 o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<o2::trk::ClustererDPL>(useMC)},
120 o2::framework::Options{{"nthreads", o2::framework::VariantType::Int, 1, {"Number of clustering threads"}}
121#ifdef O2_WITH_ACTS
122 ,
123 {"useACTS", o2::framework::VariantType::Bool, false, {"Use ACTS for clustering"}}
124#endif
125 }};
126}
127
128} // namespace o2::trk
std::vector< std::string > labels
A const (ready only) version of MCTruthContainer.
Definition of the GeometryManager class.
static void loadGeometry(std::string_view geomFilePath="", bool applyMisalignment=false, bool preferAlignedFile=true)
void snapshot(const Output &spec, T const &object)
o2::header::DataHeader::SubSpecificationType SubSpecificationType
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.
void init(o2::framework::InitContext &ic) final
void run(o2::framework::ProcessingContext &pc) final
virtual void process(gsl::span< const Digit > digits, gsl::span< const DigROFRecord > digitROFs, std::vector< o2::trk::Cluster > &clusters, std::vector< unsigned char > &patterns, std::vector< o2::trk::ROFRecord > &clusterROFs, const ConstDigitTruth *digitLabels=nullptr, ClusterTruth *clusterLabels=nullptr, gsl::span< const DigMC2ROFRecord > digMC2ROFs={}, std::vector< o2::trk::MC2ROFRecord > *clusterMC2ROFs=nullptr)
Definition Clusterer.cxx:71
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getClustererSpec(bool useMC)
static constexpr size_t kNLayers
Definition AlmiraParam.h:28
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters
std::vector< Digit > digits