Project
Loading...
Searching...
No Matches
TrackDump.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
12#include <memory>
13#include <vector>
14#include <filesystem>
15#include <fmt/format.h>
16#include "GPUTPCGeometry.h"
17
18#include "DataFormatsTPC/Defs.h"
20#include "TPCBase/Mapper.h"
22
23using namespace o2::tpc;
24using namespace o2::tpc::constants;
25namespace fs = std::filesystem;
26
28
29void TrackDump::filter(const gsl::span<const TrackTPC> tracks, ClusterNativeAccess const& clusterIndex, const gsl::span<const o2::tpc::TPCClRefElem> clRefs, const gsl::span<const o2::MCCompLabel> mcLabels)
30{
31 if (!mTreeDump && outputFileName.size()) {
32 mTreeDump = std::make_unique<utils::TreeStreamRedirector>(outputFileName.data(), "recreate");
33 const auto fspath = fs::path(outputFileName);
34 const std::string path = fspath.parent_path().c_str();
35 const std::string baseName = fspath.stem().c_str();
37 mTreeDumpClOnly = std::make_unique<utils::TreeStreamRedirector>(fmt::format("{}/{}.cl.root", path, baseName).data(), "recreate");
38 }
39 }
40
41 std::vector<TrackInfo> tpcTrackInfos;
42 std::vector<TrackTPC> tpcTracks;
43 std::vector<std::vector<ClusterNativeAdd>> clusters;
44 std::vector<std::vector<ClusterGlobal>> clustersGlobalEvent;
45 std::vector<ClusterGlobal>* clustersGlobal{};
46 std::vector<o2::MCCompLabel> tpcTracksMCTruth;
47
48 ClExcludes excludes;
49
50 const o2::gpu::GPUTPCGeometry gpuGeom;
51
52 for (const auto& track : tracks) {
53 const int nCl = track.getNClusterReferences();
54 std::vector<ClusterNativeAdd>* clustersPtr{nullptr};
56 auto& trackInfo = tpcTrackInfos.emplace_back(track);
57 clustersPtr = &trackInfo.clusters;
58 } else {
59 tpcTracks.emplace_back(track);
60 clustersPtr = &clusters.emplace_back();
61 }
62 if (writeGlobal) {
63 clustersGlobal = &clustersGlobalEvent.emplace_back();
64 }
65 auto& clInfos = *clustersPtr;
66
67 for (int j = nCl - 1; j >= 0; j--) {
68 uint8_t sector, padrow;
69 uint32_t clusterIndexInRow;
70 track.getClusterReference(clRefs, j, sector, padrow, clusterIndexInRow);
71 const auto& cl = clusterIndex.clusters[sector][padrow][clusterIndexInRow];
72 auto& clInfo = clInfos.emplace_back(cl);
73 clInfo.sector = sector;
74 clInfo.padrow = padrow;
75 excludes[sector][padrow].emplace_back(clusterIndexInRow);
76
77 if (clustersGlobal) {
78 auto& clGlobal = clustersGlobal->emplace_back(ClusterGlobal{clInfo.gx(), clInfo.gy(), cl.qMax, cl.qTot, sector, padrow});
79 }
80 }
81 }
82
83 if (writeMC) {
84 for (const auto& mcLabel : mcLabels) {
85 tpcTracksMCTruth.emplace_back(mcLabel);
86 }
87 }
88
89 if (mTreeDump) {
90 auto& tree = (*mTreeDump) << "tpcrec";
91 if (writeTracks) {
92 // << "info=" << trackInfos
94 tree << "TPCTracks=" << tpcTrackInfos;
95 } else {
96 tree << "TPCTracks=" << tpcTracks;
98 tree << "cls=" << clusters;
100 auto& cltree = (*mTreeDump) << "cls";
101 cltree << "cls=" << clusters
102 << "\n";
103 }
104 }
105 }
106 if (writeGlobal) {
107 tree << "clsGlo=" << clustersGlobalEvent;
108 }
109 if (writeMC) {
110 tree << "TPCTracksMCTruth=" << tpcTracksMCTruth;
111 }
112 tree << "\n";
113 // << "clusters=" << clInfoVec
114 }
115
116 // ===| clusters not associated to tracks |===================================
117 utils::TreeStreamRedirector* treeDumpUn = nullptr;
118
120 treeDumpUn = mTreeDump.get();
121 } else if (noTrackClusterType == ClUnStorageType::SeparateFile && mTreeDumpClOnly) {
122 treeDumpUn = mTreeDumpClOnly.get();
123 }
124 if (treeDumpUn) {
125 std::vector<ClusterNativeAdd> clustersUn;
126 fillClNativeAdd(clusterIndex, clustersUn, &excludes);
127 auto& cltree = (*treeDumpUn) << "clsn";
128 cltree << "cls=" << clustersUn
129 << "\n";
130 }
131}
132
134{
135 if (mTreeDump) {
136 mTreeDump->Close();
137 }
138
139 mTreeDump.reset();
140}
141
142void TrackDump::fillClNativeAdd(ClusterNativeAccess const& clusterIndex, std::vector<ClusterNativeAdd>& clInfos, ClExcludes* excludes)
143{
144 const o2::gpu::GPUTPCGeometry gpuGeom;
145
146 for (int sector = 0; sector < MAXSECTOR; ++sector) {
147 for (int padrow = 0; padrow < MAXGLOBALPADROW; ++padrow) {
148
149 for (size_t icl = 0; icl < clusterIndex.nClusters[sector][padrow]; ++icl) {
150 if (excludes) {
151 const auto& exRow = (*excludes)[sector][padrow];
152 if (std::find(exRow.begin(), exRow.end(), icl) != exRow.end()) {
153 continue;
154 }
155 }
156 const auto& cl = clusterIndex.clusters[sector][padrow][icl];
157 auto& clInfo = clInfos.emplace_back(cl);
158 clInfo.sector = sector;
159 clInfo.padrow = padrow;
160 }
161 }
162 }
163}
164
166{
167 const o2::gpu::GPUTPCGeometry gpuGeom;
168 return getPad() - gpuGeom.NPads(padrow) / 2.f;
169}
170
172{
173 const o2::gpu::GPUTPCGeometry gpuGeom;
174 return gpuGeom.Row2X(padrow);
175}
176
178{
179 const o2::gpu::GPUTPCGeometry gpuGeom;
180 return gpuGeom.LinearPad2Y(sector, padrow, getPad());
181}
182
184{
185 const LocalPosition2D l2D{lx(), ly()};
186 const auto g2D = Mapper::LocalToGlobal(l2D, Sector(sector));
187 return g2D.x();
188}
189
191{
192 const LocalPosition2D l2D{lx(), ly()};
193 const auto g2D = Mapper::LocalToGlobal(l2D, Sector(sector));
194 return g2D.y();
195}
196
197float TrackDump::ClusterNativeAdd::lxc(float vertexTime) const
198{
199 float x{0.f}, y{0.f}, z{0.f};
200 if (sCorrHelper.getCorrMap()) {
201 sCorrHelper.Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime);
202 }
203 return x;
204}
205
206float TrackDump::ClusterNativeAdd::lyc(float vertexTime) const
207{
208 float x{0.f}, y{0.f}, z{0.f};
209 if (sCorrHelper.getCorrMap()) {
210 sCorrHelper.Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime);
211 }
212 return y;
213}
214
215float TrackDump::ClusterNativeAdd::gxc(float vertexTime) const
216{
217 const LocalPosition2D l2D{lxc(), lyc()};
218 const auto g2D = Mapper::LocalToGlobal(l2D, Sector(sector));
219 return g2D.x();
220}
221
222float TrackDump::ClusterNativeAdd::gyc(float vertexTime) const
223{
224 const LocalPosition2D l2D{lxc(), lyc()};
225 const auto g2D = Mapper::LocalToGlobal(l2D, Sector(sector));
226 return g2D.y();
227}
228
229float TrackDump::ClusterNativeAdd::zc(float vertexTime) const
230{
231 float x{0.f}, y{0.f}, z{0.f};
232 if (sCorrHelper.getCorrMap()) {
233 sCorrHelper.Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime);
234 }
235 return z;
236}
237
238void TrackDump::ClusterNativeAdd::loadCorrMaps(std::string_view corrMapFile, std::string_view corrMapFileRef)
239{
240 sCorrHelper.setOwner(true);
241 sCorrHelper.setCorrMap(gpu::TPCFastTransform::loadFromFile(corrMapFile.data()));
242 if (!corrMapFileRef.empty()) {
243 sCorrHelper.setCorrMapRef(gpu::TPCFastTransform::loadFromFile(corrMapFileRef.data()));
244 }
245}
Class of a TPC cluster in TPC-native coordinates (row, time)
uint32_t j
Definition RawData.h:0
uint32_t padrow
Definition RawData.h:5
static TPCFastTransform * loadFromFile(std::string inpFName="", std::string name="")
static GlobalPosition3D LocalToGlobal(const LocalPosition3D &pos, const double alpha)
Definition Mapper.h:461
ClStorageType clusterStorageType
instead of storing the clusters with the tracks, store them in a separate tree
Definition TrackDump.h:121
bool writeTracks
write global cluster information for quick drawing
Definition TrackDump.h:118
bool writeMC
write MC track information for quick drawing
Definition TrackDump.h:120
void filter(const gsl::span< const TrackTPC > tracks, ClusterNativeAccess const &clusterIndex, const gsl::span< const o2::tpc::TPCClRefElem > clRefs, const gsl::span< const MCCompLabel > mcLabels)
Definition TrackDump.cxx:29
ClUnStorageType noTrackClusterType
store unassociated clusters in separate tree
Definition TrackDump.h:122
void fillClNativeAdd(ClusterNativeAccess const &clusterIndex, std::vector< ClusterNativeAdd > &clInfos, ClExcludes *excludes=nullptr)
bool writeGlobal
write global cluster information for quick drawing
Definition TrackDump.h:119
std::vector< int >[MAXSECTOR][MAXGLOBALPADROW] ClExcludes
Definition TrackDump.h:111
std::string outputFileName
Name of the output file with the tree.
Definition TrackDump.h:117
GLint GLenum GLint x
Definition glcorearb.h:403
GLint y
Definition glcorearb.h:270
GLboolean * data
Definition glcorearb.h:298
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
constexpr int MAXSECTOR
Definition Constants.h:28
constexpr int MAXGLOBALPADROW
Definition Constants.h:34
Global TPC definitions and constants.
Definition SimTraits.h:167
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
const ClusterNative * clusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
float gxc(float vertexTime=0) const
float lyc(float vertexTime=0) const
float lxc(float vertexTime=0) const
float zc(float vertexTime=0) const
static gpu::CorrectionMapsHelper sCorrHelper
Definition TrackDump.h:27
static void loadCorrMaps(std::string_view corrMapFile, std::string_view corrMapFileRef="")
float gyc(float vertexTime=0) const
std::vector< Cluster > clusters
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))