Project
Loading...
Searching...
No Matches
IOUtils.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.
15
16#include "ITStracking/IOUtils.h"
17
18#include <gsl/span>
19#include <vector>
20#include <array>
21#include <string>
22#include <iostream>
23#include <cstdlib>
24#include <fstream>
25#include <sstream>
26#include <tuple>
27#include <utility>
28
31#include "MathUtils/Utils.h"
34
35namespace
36{
37constexpr int PrimaryVertexLayerId{-1};
38constexpr int EventLabelsSeparator{-1};
39} // namespace
40
41using namespace o2::its;
42
44void ioutils::convertCompactClusters(gsl::span<const itsmft::CompClusterExt> clusters,
45 gsl::span<const unsigned char>::iterator& pattIt,
46 std::vector<o2::BaseCluster<float>>& output,
48{
50 bool applyMisalignment = false;
51 const auto& conf = TrackerParamConfig::Instance();
52 const auto& chmap = getChipMappingITS();
53 for (int il = 0; il < chmap.NLayers; il++) {
54 if (conf.sysErrY2[il] > 0.f || conf.sysErrZ2[il] > 0.f) {
55 applyMisalignment = true;
56 break;
57 }
58 }
59
60 for (const auto& c : clusters) {
61 float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
62 auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
63 auto& cl3d = output.emplace_back(c.getSensorID(), geom->getMatrixT2L(c.getSensorID()) ^ locXYZ); // local --> tracking
64 if (applyMisalignment) {
65 auto lrID = chmap.getLayer(c.getSensorID());
66 sigmaY2 += conf.sysErrY2[lrID];
67 sigmaZ2 += conf.sysErrZ2[lrID];
68 }
69 cl3d.setErrors(sigmaY2, sigmaZ2, sigmaYZ);
70 }
71}
72
73void ioutils::loadEventData(ROframe& event, gsl::span<const itsmft::CompClusterExt> clusters,
74 gsl::span<const unsigned char>::iterator& pattIt, const itsmft::TopologyDictionary* dict,
76{
77 if (clusters.empty()) {
78 std::cerr << "Missing clusters." << std::endl;
79 return;
80 }
81 event.clear();
84 int clusterId{0};
85
86 for (const auto& c : clusters) {
87 const int layer = geom->getLayer(c.getSensorID());
88 float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
89 auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
90 auto sensorID = c.getSensorID();
91 // Inverse transformation to the local --> tracking
92 auto trkXYZ = geom->getMatrixT2L(sensorID) ^ locXYZ;
93 // Transformation to the local --> global
94 auto gloXYZ = geom->getMatrixL2G(sensorID) * locXYZ;
95
96 event.addTrackingFrameInfoToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), geom->getSensorRefAlpha(sensorID),
97 std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
98 std::array<float, 3>{sigmaY2, sigmaYZ, sigmaZ2});
99
101 event.addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), event.getClustersOnLayer(layer).size());
102 if (clsLabels) {
103 // event.addClusterLabelToLayer(layer, *(clsLabels->getLabels(clusterId).begin()));
104 event.setMClabelsContainer(clsLabels);
105 }
106 event.addClusterExternalIndexToLayer(layer, clusterId);
107 clusterId++;
108 }
109}
110
111int ioutils::loadROFrameData(const o2::itsmft::ROFRecord& rof, ROframe& event, gsl::span<const itsmft::CompClusterExt> clusters, gsl::span<const unsigned char>::iterator& pattIt, const itsmft::TopologyDictionary* dict,
113{
114 event.clear();
117 int clusterId{0};
118
119 auto first = rof.getFirstEntry();
120 auto clusters_in_frame = rof.getROFData(clusters);
121 for (const auto& c : clusters_in_frame) {
122 const int layer = geom->getLayer(c.getSensorID());
123 float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
124 auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
125 auto sensorID = c.getSensorID();
126 // Inverse transformation to the local --> tracking
127 auto trkXYZ = geom->getMatrixT2L(sensorID) ^ locXYZ;
128 // Transformation to the local --> global
129 auto gloXYZ = geom->getMatrixL2G(sensorID) * locXYZ;
130
131 event.addTrackingFrameInfoToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), geom->getSensorRefAlpha(sensorID),
132 std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
133 std::array<float, 3>{sigmaY2, sigmaYZ, sigmaZ2});
134
136 event.addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), event.getClustersOnLayer(layer).size());
137 if (mcLabels) {
138 // event.addClusterLabelToLayer(layer, *(mcLabels->getLabels(first + clusterId).begin()));
139 event.setMClabelsContainer(mcLabels);
140 }
141 event.addClusterExternalIndexToLayer(layer, first + clusterId);
142 clusterId++;
143 }
144 return (int)clusters_in_frame.size();
145}
General auxilliary methods.
Definition of the GeometryTGeo class.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of a container to keep Monte Carlo truth external to simulation objects.
uint32_t c
Definition RawData.h:2
A container to hold and manage MC truth information/labels.
const Mat3D & getMatrixL2G(int sensID) const
const Mat3D & getMatrixT2L(int lay, int hba, int sta, int det) const
int getLayer(int index) const
Get chip layer, from 0.
float getSensorRefAlpha(int isn) const
static GeometryTGeo * Instance()
void fillMatrixCache(int mask) override
gsl::span< const T > getROFData(const gsl::span< const T > tfdata) const
Definition ROFRecord.h:73
int getFirstEntry() const
Definition ROFRecord.h:63
struct _cl_event * event
Definition glcorearb.h:2982
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
void convertCompactClusters(gsl::span< const itsmft::CompClusterExt > clusters, gsl::span< const unsigned char >::iterator &pattIt, std::vector< o2::BaseCluster< float > > &output, const itsmft::TopologyDictionary *dict)
convert compact clusters to 3D spacepoints
Definition IOUtils.cxx:44
o2::math_utils::Point3D< T > extractClusterData(const itsmft::CompClusterExt &c, iterator &iter, const itsmft::TopologyDictionary *dict, T &sig2y, T &sig2z)
Definition IOUtils.h:76
void loadEventData(ROframe &events, gsl::span< const itsmft::CompClusterExt > clusters, gsl::span< const unsigned char >::iterator &pattIt, const itsmft::TopologyDictionary *dict, const dataformats::MCTruthContainer< MCCompLabel > *clsLabels=nullptr)
Definition IOUtils.cxx:73
int loadROFrameData(const o2::itsmft::ROFRecord &rof, ROframe &events, gsl::span< const itsmft::CompClusterExt > clusters, gsl::span< const unsigned char >::iterator &pattIt, const itsmft::TopologyDictionary *dict, const dataformats::MCTruthContainer< MCCompLabel > *mClsLabels=nullptr)
Definition IOUtils.cxx:111
static constexpr int L2G
Definition Cartesian.h:54
static constexpr int T2L
Definition Cartesian.h:55
std::vector< Cluster > clusters