forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOUtils.cxx
More file actions
145 lines (130 loc) · 5.81 KB
/
IOUtils.cxx
File metadata and controls
145 lines (130 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file IOUtils.cxx
/// \brief
///
#include "ITStracking/IOUtils.h"
#include <gsl/span>
#include <vector>
#include <array>
#include <string>
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <tuple>
#include <utility>
#include "ITSBase/GeometryTGeo.h"
#include "ITStracking/Constants.h"
#include "MathUtils/Utils.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
namespace
{
constexpr int PrimaryVertexLayerId{-1};
constexpr int EventLabelsSeparator{-1};
} // namespace
using namespace o2::its;
/// convert compact clusters to 3D spacepoints
void ioutils::convertCompactClusters(gsl::span<const itsmft::CompClusterExt> clusters,
gsl::span<const unsigned char>::iterator& pattIt,
std::vector<o2::BaseCluster<float>>& output,
const itsmft::TopologyDictionary* dict)
{
GeometryTGeo* geom = GeometryTGeo::Instance();
bool applyMisalignment = false;
const auto& conf = TrackerParamConfig::Instance();
const auto& chmap = getChipMappingITS();
for (int il = 0; il < chmap.NLayers; il++) {
if (conf.sysErrY2[il] > 0.f || conf.sysErrZ2[il] > 0.f) {
applyMisalignment = true;
break;
}
}
for (const auto& c : clusters) {
float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
auto& cl3d = output.emplace_back(c.getSensorID(), geom->getMatrixT2L(c.getSensorID()) ^ locXYZ); // local --> tracking
if (applyMisalignment) {
auto lrID = chmap.getLayer(c.getSensorID());
sigmaY2 += conf.sysErrY2[lrID];
sigmaZ2 += conf.sysErrZ2[lrID];
}
cl3d.setErrors(sigmaY2, sigmaZ2, sigmaYZ);
}
}
void ioutils::loadEventData(ROframe& event, gsl::span<const itsmft::CompClusterExt> clusters,
gsl::span<const unsigned char>::iterator& pattIt, const itsmft::TopologyDictionary* dict,
const dataformats::MCTruthContainer<MCCompLabel>* clsLabels)
{
if (clusters.empty()) {
std::cerr << "Missing clusters." << std::endl;
return;
}
event.clear();
GeometryTGeo* geom = GeometryTGeo::Instance();
geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));
int clusterId{0};
for (const auto& c : clusters) {
const int layer = geom->getLayer(c.getSensorID());
float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
auto sensorID = c.getSensorID();
// Inverse transformation to the local --> tracking
auto trkXYZ = geom->getMatrixT2L(sensorID) ^ locXYZ;
// Transformation to the local --> global
auto gloXYZ = geom->getMatrixL2G(sensorID) * locXYZ;
event.addTrackingFrameInfoToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), geom->getSensorRefAlpha(sensorID),
std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
std::array<float, 3>{sigmaY2, sigmaYZ, sigmaZ2});
/// Rotate to the global frame
event.addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), event.getClustersOnLayer(layer).size());
if (clsLabels) {
// event.addClusterLabelToLayer(layer, *(clsLabels->getLabels(clusterId).begin()));
event.setMClabelsContainer(clsLabels);
}
event.addClusterExternalIndexToLayer(layer, clusterId);
clusterId++;
}
}
int 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,
const dataformats::MCTruthContainer<MCCompLabel>* mcLabels)
{
event.clear();
GeometryTGeo* geom = GeometryTGeo::Instance();
geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));
int clusterId{0};
auto first = rof.getFirstEntry();
auto clusters_in_frame = rof.getROFData(clusters);
for (const auto& c : clusters_in_frame) {
const int layer = geom->getLayer(c.getSensorID());
float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
auto sensorID = c.getSensorID();
// Inverse transformation to the local --> tracking
auto trkXYZ = geom->getMatrixT2L(sensorID) ^ locXYZ;
// Transformation to the local --> global
auto gloXYZ = geom->getMatrixL2G(sensorID) * locXYZ;
event.addTrackingFrameInfoToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), geom->getSensorRefAlpha(sensorID),
std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
std::array<float, 3>{sigmaY2, sigmaYZ, sigmaZ2});
/// Rotate to the global frame
event.addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), event.getClustersOnLayer(layer).size());
if (mcLabels) {
// event.addClusterLabelToLayer(layer, *(mcLabels->getLabels(first + clusterId).begin()));
event.setMClabelsContainer(mcLabels);
}
event.addClusterExternalIndexToLayer(layer, first + clusterId);
clusterId++;
}
return (int)clusters_in_frame.size();
}