Project
Loading...
Searching...
No Matches
ClusterWriterSpec.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 <algorithm>
15#include <cctype>
16#include <memory>
17#include <vector>
18#include <format>
19
22#include "Framework/DataRef.h"
23#include "TRKBase/AlmiraParam.h"
24#include "TRKBase/Specs.h"
29#include "Headers/DataHeader.h"
32
33using namespace o2::framework;
34
35namespace o2::trk
36{
37
38template <typename T>
40using PatternsType = std::vector<unsigned char>;
41using ROFrameType = std::vector<o2::trkft3::ROFRecord>;
43
44template <int DetID>
46{
47 static_assert(DetID == o2::detectors::DetID::TRK || DetID == o2::detectors::DetID::FT3, "only TRK and FT3 cluster writers are supported");
48 using ClustersType = std::vector<o2::trkft3::Cluster<DetID>>;
49 static constexpr o2::header::DataOrigin Origin = DetID == o2::detectors::DetID::TRK ? o2::header::gDataOriginTRK : o2::header::gDataOriginFT3;
50 const int nLayers = DetID == o2::detectors::DetID::TRK ? o2::trk::AlmiraParam::kNLayers : o2::trk::constants::MLOTDisks::nLayers;
51 const auto detName = Origin.as<std::string>();
52
53 auto compClusterSizes = std::make_shared<std::vector<size_t>>(nLayers, 0);
54 auto compClustersSizeGetter = [compClusterSizes](ClustersType const& compClusters, DataRef const& ref) {
55 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
56 (*compClusterSizes)[dh->subSpecification] = compClusters.size();
57 };
58 auto logger = [detName, compClusterSizes](ROFrameType const& rofs, DataRef const& ref) {
59 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
60 const auto i = dh->subSpecification;
61 LOG(info) << detName << "ClusterWriter on layer " << i
62 << " pulled " << (*compClusterSizes)[i] << " clusters, in " << rofs.size() << " RO frames";
63 };
64 auto getIndex = [](DataRef const& ref) -> size_t {
65 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
66 return static_cast<size_t>(dh->subSpecification);
67 };
68 auto getName = [](std::string base, size_t index) -> std::string {
69 return base + "_" + std::to_string(index);
70 };
71 auto detNameLC = detName;
72 std::transform(detNameLC.begin(), detNameLC.end(), detNameLC.begin(), [](unsigned char c) { return std::tolower(c); });
73
74 std::vector<InputSpec> vecInpSpecClus, vecInpSpecPatt, vecInpSpecROF, vecInpSpecLbl;
75 vecInpSpecClus.reserve(nLayers);
76 vecInpSpecPatt.reserve(nLayers);
77 vecInpSpecROF.reserve(nLayers);
78 vecInpSpecLbl.reserve(nLayers);
79 for (int iLayer = 0; iLayer < nLayers; iLayer++) {
80 vecInpSpecClus.emplace_back(getName(detName + "compclus", iLayer), Origin, "COMPCLUSTERS", iLayer);
81 vecInpSpecPatt.emplace_back(getName(detName + "patterns", iLayer), Origin, "PATTERNS", iLayer);
82 vecInpSpecROF.emplace_back(getName(detName + "ROframes", iLayer), Origin, "CLUSTERSROF", iLayer);
83 vecInpSpecLbl.emplace_back(getName(detName + "labels", iLayer), Origin, "CLUSTERSMCTR", iLayer);
84 }
85
86 return MakeRootTreeWriterSpec(std::format("{}-cluster-writer", detNameLC).c_str(),
87 std::format("o2clus_{}.root", detNameLC).c_str(),
88 MakeRootTreeWriterSpec::TreeAttributes{.name = "o2sim", .title = "Tree with " + detName + " clusters"},
89 BranchDefinition<ClustersType>{vecInpSpecClus,
90 detName + "ClusterComp", "compact-cluster-branch",
91 nLayers,
92 compClustersSizeGetter,
93 getIndex,
94 getName},
95 BranchDefinition<PatternsType>{vecInpSpecPatt,
96 detName + "ClusterPatt", "cluster-pattern-branch",
97 nLayers,
98 getIndex,
99 getName},
100 BranchDefinition<ROFrameType>{vecInpSpecROF,
101 detName + "ClustersROF", "cluster-rof-branch",
102 nLayers,
103 logger,
104 getIndex,
105 getName},
106 BranchDefinition<LabelsType>{vecInpSpecLbl,
107 detName + "ClusterMCTruth", "cluster-label-branch",
108 (useMC ? nLayers : 0),
109 getIndex,
110 getName})();
111}
112
114{
115 return getClusterWriterSpecT<o2::detectors::DetID::TRK>(useMC);
116}
117
119{
120 return getClusterWriterSpecT<o2::detectors::DetID::FT3>(useMC);
121}
122
124{
125 return getTRKClusterWriterSpec(useMC);
126}
127
128} // namespace o2::trk
std::string getName(const TDataMember *dm, int index, int size)
int32_t i
Definition of a container to keep Monte Carlo truth external to simulation objects.
Configurable generator for RootTreeWriter processor spec.
uint32_t c
Definition RawData.h:2
specs of the ALICE3 TRK
A container to hold and manage MC truth information/labels.
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
Generate a processor spec for the RootTreeWriter utility.
GLuint index
Definition glcorearb.h:781
GLint ref
Definition glcorearb.h:291
constexpr o2::header::DataOrigin gDataOriginTRK
Definition DataHeader.h:584
constexpr o2::header::DataOrigin gDataOriginFT3
Definition DataHeader.h:585
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< o2::trkft3::ROFRecord > ROFrameType
framework::DataProcessorSpec getTRKClusterWriterSpec(bool useMC)
framework::DataProcessorSpec getFT3ClusterWriterSpec(bool useMC)
framework::DataProcessorSpec getClusterWriterSpec(bool useMC)
std::vector< o2::MCCompLabel > LabelsType
std::vector< unsigned char > PatternsType
DataProcessorSpec getClusterWriterSpecT(bool useMC)
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
static constexpr size_t kNLayers
Definition AlmiraParam.h:29
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"