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
27void 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)
28{
29 if (!mTreeDump && outputFileName.size()) {
30 mTreeDump = std::make_unique<utils::TreeStreamRedirector>(outputFileName.data(), "recreate");
31 const auto fspath = fs::path(outputFileName);
32 const std::string path = fspath.parent_path().c_str();
33 const std::string baseName = fspath.stem().c_str();
35 mTreeDumpClOnly = std::make_unique<utils::TreeStreamRedirector>(fmt::format("{}/{}.cl.root", path, baseName).data(), "recreate");
36 }
37 }
38
39 std::vector<TrackInfo> tpcTrackInfos;
40 std::vector<TrackTPC> tpcTracks;
41 std::vector<std::vector<ClusterNativeAdd>> clusters;
42 std::vector<std::vector<ClusterGlobal>> clustersGlobalEvent;
43 std::vector<ClusterGlobal>* clustersGlobal{};
44 std::vector<o2::MCCompLabel> tpcTracksMCTruth;
45
46 ClExcludes excludes;
47
48 const o2::gpu::GPUTPCGeometry gpuGeom;
49
50 for (const auto& track : tracks) {
51 const int nCl = track.getNClusterReferences();
52 std::vector<ClusterNativeAdd>* clustersPtr{nullptr};
54 auto& trackInfo = tpcTrackInfos.emplace_back(track);
55 clustersPtr = &trackInfo.clusters;
56 } else {
57 tpcTracks.emplace_back(track);
58 clustersPtr = &clusters.emplace_back();
59 }
60 if (writeGlobal) {
61 clustersGlobal = &clustersGlobalEvent.emplace_back();
62 }
63 auto& clInfos = *clustersPtr;
64
65 for (int j = nCl - 1; j >= 0; j--) {
66 uint8_t sector, padrow;
67 uint32_t clusterIndexInRow;
68 track.getClusterReference(clRefs, j, sector, padrow, clusterIndexInRow);
69 const auto& cl = clusterIndex.clusters[sector][padrow][clusterIndexInRow];
70 auto& clInfo = clInfos.emplace_back(cl);
71 clInfo.sector = sector;
72 clInfo.padrow = padrow;
73 excludes[sector][padrow].emplace_back(clusterIndexInRow);
74
75 if (clustersGlobal) {
76 auto& clGlobal = clustersGlobal->emplace_back(ClusterGlobal{clInfo.gx(), clInfo.gy(), cl.qMax, cl.qTot, sector, padrow});
77 }
78 }
79 }
80
81 if (writeMC) {
82 for (const auto& mcLabel : mcLabels) {
83 tpcTracksMCTruth.emplace_back(mcLabel);
84 }
85 }
86
87 if (mTreeDump) {
88 auto& tree = (*mTreeDump) << "tpcrec";
89 if (writeTracks) {
90 // << "info=" << trackInfos
92 tree << "TPCTracks=" << tpcTrackInfos;
93 } else {
94 tree << "TPCTracks=" << tpcTracks;
96 tree << "cls=" << clusters;
98 auto& cltree = (*mTreeDump) << "cls";
99 cltree << "cls=" << clusters
100 << "\n";
101 }
102 }
103 }
104 if (writeGlobal) {
105 tree << "clsGlo=" << clustersGlobalEvent;
106 }
107 if (writeMC) {
108 tree << "TPCTracksMCTruth=" << tpcTracksMCTruth;
109 }
110 tree << "\n";
111 // << "clusters=" << clInfoVec
112 }
113
114 // ===| clusters not associated to tracks |===================================
115 utils::TreeStreamRedirector* treeDumpUn = nullptr;
116
118 treeDumpUn = mTreeDump.get();
119 } else if (noTrackClusterType == ClUnStorageType::SeparateFile && mTreeDumpClOnly) {
120 treeDumpUn = mTreeDumpClOnly.get();
121 }
122 if (treeDumpUn) {
123 std::vector<ClusterNativeAdd> clustersUn;
124 fillClNativeAdd(clusterIndex, clustersUn, &excludes);
125 auto& cltree = (*treeDumpUn) << "clsn";
126 cltree << "cls=" << clustersUn
127 << "\n";
128 }
129}
130
132{
133 if (mTreeDump) {
134 mTreeDump->Close();
135 }
136
137 mTreeDump.reset();
138}
139
140void TrackDump::fillClNativeAdd(ClusterNativeAccess const& clusterIndex, std::vector<ClusterNativeAdd>& clInfos, ClExcludes* excludes)
141{
142 const o2::gpu::GPUTPCGeometry gpuGeom;
143
144 for (int sector = 0; sector < MAXSECTOR; ++sector) {
145 for (int padrow = 0; padrow < MAXGLOBALPADROW; ++padrow) {
146
147 for (size_t icl = 0; icl < clusterIndex.nClusters[sector][padrow]; ++icl) {
148 if (excludes) {
149 const auto& exRow = (*excludes)[sector][padrow];
150 if (std::find(exRow.begin(), exRow.end(), icl) != exRow.end()) {
151 continue;
152 }
153 }
154 const auto& cl = clusterIndex.clusters[sector][padrow][icl];
155 auto& clInfo = clInfos.emplace_back(cl);
156 clInfo.sector = sector;
157 clInfo.padrow = padrow;
158 }
159 }
160 }
161}
162
164{
165 const o2::gpu::GPUTPCGeometry gpuGeom;
166 return getPad() - gpuGeom.NPads(padrow) / 2.f;
167}
168
170{
171 const o2::gpu::GPUTPCGeometry gpuGeom;
172 return gpuGeom.Row2X(padrow);
173}
174
176{
177 const o2::gpu::GPUTPCGeometry gpuGeom;
178 return gpuGeom.LinearPad2Y(sector, padrow, getPad());
179}
180
182{
183 const LocalPosition2D l2D{lx(), ly()};
184 const auto g2D = Mapper::LocalToGlobal(l2D, Sector(sector));
185 return g2D.x();
186}
187
189{
190 const LocalPosition2D l2D{lx(), ly()};
191 const auto g2D = Mapper::LocalToGlobal(l2D, Sector(sector));
192 return g2D.y();
193}
194
195float TrackDump::ClusterNativeAdd::lxc(float vertexTime) const
196{
197 float x{0.f}, y{0.f}, z{0.f};
198 if (corrMap) {
199 corrMap->Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime);
200 }
201 return x;
202}
203
204float TrackDump::ClusterNativeAdd::lyc(float vertexTime) const
205{
206 float x{0.f}, y{0.f}, z{0.f};
207 if (corrMap) {
208 corrMap->Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime);
209 }
210 return y;
211}
212
213float TrackDump::ClusterNativeAdd::gxc(float vertexTime) const
214{
215 const LocalPosition2D l2D{lxc(), lyc()};
216 const auto g2D = Mapper::LocalToGlobal(l2D, Sector(sector));
217 return g2D.x();
218}
219
220float TrackDump::ClusterNativeAdd::gyc(float vertexTime) const
221{
222 const LocalPosition2D l2D{lxc(), lyc()};
223 const auto g2D = Mapper::LocalToGlobal(l2D, Sector(sector));
224 return g2D.y();
225}
226
227float TrackDump::ClusterNativeAdd::zc(float vertexTime) const
228{
229 float x{0.f}, y{0.f}, z{0.f};
230 if (corrMap) {
231 corrMap->Transform(sector, padrow, getPad(), getTime(), x, y, z, vertexTime);
232 }
233 return z;
234}
235
236void TrackDump::ClusterNativeAdd::loadCorrMaps(std::string_view corrMapFile, std::string_view corrMapFileRef)
237{
238 auto fastTransformTmp = gpu::TPCFastTransform::loadFromFile(corrMapFile.data());
240 gpu::TPCFastTransformPOD::create(buffer, *fastTransformTmp);
241 corrMapBuffer = std::move(buffer);
242 corrMap = corrMapBuffer.get();
243}
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 TPCFastTransformPOD * create(aligned_unique_buffer_ptr< TPCFastTransformPOD > &destVector, const TPCFastTransform &src)
Create POD transform from old flat-buffer one. Provided vector will serve as a buffer.
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:122
bool writeTracks
write global cluster information for quick drawing
Definition TrackDump.h:119
bool writeMC
write MC track information for quick drawing
Definition TrackDump.h:121
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:27
ClUnStorageType noTrackClusterType
store unassociated clusters in separate tree
Definition TrackDump.h:123
void fillClNativeAdd(ClusterNativeAccess const &clusterIndex, std::vector< ClusterNativeAdd > &clInfos, ClExcludes *excludes=nullptr)
bool writeGlobal
write global cluster information for quick drawing
Definition TrackDump.h:120
std::vector< int >[MAXSECTOR][MAXGLOBALPADROW] ClExcludes
Definition TrackDump.h:112
std::string outputFileName
Name of the output file with the tree.
Definition TrackDump.h:118
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint buffer
Definition glcorearb.h:655
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:168
std::string getTime(uint64_t ts)
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 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()))