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.
14
15#include "MFTTracking/IOUtils.h"
16
17#include <iostream>
18#include <cstdlib>
19#include <fstream>
20#include <sstream>
21#include <tuple>
22#include <unordered_set>
23#include <utility>
24
25#include "MFTBase/GeometryTGeo.h"
28#include "MathUtils/Utils.h"
29#include "MathUtils/Cartesian.h"
33
34namespace o2
35{
36namespace mft
37{
38
39//_________________________________________________________
40template <typename T>
41int ioutils::loadROFrameData(const o2::itsmft::ROFRecord& rof, ROframe<T>& event, gsl::span<const itsmft::CompClusterExt> clusters, gsl::span<const unsigned char>::iterator& pattIt, const itsmft::TopologyDictionary* dict, const dataformats::MCTruthContainer<MCCompLabel>* mcLabels, const o2::mft::Tracker<T>* tracker, ROFFilter& filter)
42{
43 event.clear();
46 int clusterId{0};
47 auto first = rof.getFirstEntry();
48 auto clusters_in_frame = rof.getROFData(clusters);
49 auto nClusters = clusters_in_frame.size();
50 int clusterSize = -999;
51
52 bool skip_ROF = true;
53 auto& trackingParam = MFTTrackingParam::Instance();
54 if (filter(rof) && trackingParam.isPassingMultCut(nClusters)) {
55 LOG(debug) << " ROF selected! ; nClusters = " << nClusters << " ; orbit = " << rof.getBCData().orbit << " ; bc = " << rof.getBCData().bc;
56 skip_ROF = false;
57 event.Reserve(nClusters);
58 } else {
59 nClusters = 0;
60 }
61
62 for (auto& c : clusters_in_frame) {
63 auto sensorID = c.getSensorID();
64 int layer = geom->getLayer(sensorID);
65 auto pattID = c.getPatternID();
67 float sigmaX2 = ioutils::DefClusError2Row, sigmaY2 = ioutils::DefClusError2Col; // Dummy COG errors (about half pixel size)
69 sigmaX2 = dict->getErr2X(pattID); // ALPIDE local X coordinate => MFT global X coordinate (ALPIDE rows)
70 sigmaY2 = dict->getErr2Z(pattID); // ALPIDE local Z coordinate => MFT global Y coordinate (ALPIDE columns)
71 if (!dict->isGroup(pattID)) {
72 locXYZ = dict->getClusterCoordinates(c);
73 clusterSize = dict->getNpixels(pattID);
74 } else {
75 o2::itsmft::ClusterPattern patt(pattIt);
76 locXYZ = dict->getClusterCoordinates(c, patt);
77 clusterSize = patt.getNPixels();
78 }
79 } else {
80 o2::itsmft::ClusterPattern patt(pattIt);
81 locXYZ = dict->getClusterCoordinates(c, patt, false);
82 clusterSize = patt.getNPixels();
83 }
84 if (skip_ROF) { // Skip filtered-out ROFs after processing pattIt
85 clusterId++;
86 continue;
87 }
88 // Transformation to the local --> global
89 auto gloXYZ = geom->getMatrixL2G(sensorID) * locXYZ;
90
91 auto clsPoint2D = math_utils::Point2D<Float_t>(gloXYZ.x(), gloXYZ.y());
92 Float_t rCoord = clsPoint2D.R();
93 Float_t phiCoord = clsPoint2D.Phi();
95 int rBinIndex = tracker->getRBinIndex(rCoord, layer);
96 int phiBinIndex = tracker->getPhiBinIndex(phiCoord);
97 int binIndex = tracker->getBinIndex(rBinIndex, phiBinIndex);
98 event.addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), phiCoord, rCoord, event.getClustersInLayer(layer).size(), binIndex, sigmaX2, sigmaY2, sensorID);
99 if (mcLabels) {
100 event.addClusterLabelToLayer(layer, *(mcLabels->getLabels(first + clusterId).begin()));
101 }
102 event.addClusterExternalIndexToLayer(layer, first + clusterId);
103 event.addClusterSizeToLayer(layer, clusterSize);
104 clusterId++;
105 }
106 return nClusters;
107}
108
109//_________________________________________________________
111void ioutils::convertCompactClusters(gsl::span<const itsmft::CompClusterExt> clusters,
112 gsl::span<const unsigned char>::iterator& pattIt,
113 std::vector<o2::BaseCluster<float>>& output,
114 const itsmft::TopologyDictionary* dict)
115{
118
119 for (auto& c : clusters) {
120 auto chipID = c.getChipID();
121 auto pattID = c.getPatternID();
123 float sigmaX2 = DefClusError2Row, sigmaY2 = DefClusError2Col;
125 sigmaX2 = dict->getErr2X(pattID); // ALPIDE local Y coordinate => MFT global X coordinate (ALPIDE rows)
126 sigmaY2 = dict->getErr2Z(pattID); // ALPIDE local Z coordinate => MFT global Y coordinate (ALPIDE columns)
127 if (!dict->isGroup(pattID)) {
128 locXYZ = dict->getClusterCoordinates(c);
129 } else {
130 o2::itsmft::ClusterPattern patt(pattIt);
131 locXYZ = dict->getClusterCoordinates(c, patt);
132 }
133 } else {
134 o2::itsmft::ClusterPattern patt(pattIt);
135 locXYZ = dict->getClusterCoordinates(c, patt, false);
136 }
137
138 // Transformation to the local --> global
139 auto gloXYZ = geom->getMatrixL2G(chipID) * locXYZ;
140
141 auto& cl3d = output.emplace_back(c.getSensorID(), gloXYZ); // local --> global
142 cl3d.setErrors(sigmaX2, sigmaY2, 0);
143 }
144}
145
146//_________________________________________________________
147template <typename T>
148int ioutils::loadROFrameData(const o2::itsmft::ROFRecord& rof, ROframe<T>& event, gsl::span<const itsmft::CompClusterExt> clusters, gsl::span<const unsigned char>::iterator& pattIt, const itsmft::TopologyDictionary* dict, const dataformats::MCTruthContainer<MCCompLabel>* mcLabels, const o2::mft::Tracker<T>* tracker)
149{
150 ROFFilter noFilter = [](const o2::itsmft::ROFRecord r) { return true; };
151 return ioutils::loadROFrameData(rof, event, clusters, pattIt, dict, mcLabels, tracker, noFilter);
152}
153
154//_________________________________________________________
155template int o2::mft::ioutils::loadROFrameData<o2::mft::TrackLTF>(const o2::itsmft::ROFRecord&, ROframe<o2::mft::TrackLTF>&, gsl::span<const itsmft::CompClusterExt>,
156 gsl::span<const unsigned char>::iterator&, const itsmft::TopologyDictionary*,
158
159template int o2::mft::ioutils::loadROFrameData<o2::mft::TrackLTFL>(const o2::itsmft::ROFRecord&, ROframe<o2::mft::TrackLTFL>&, gsl::span<const itsmft::CompClusterExt>,
160 gsl::span<const unsigned char>::iterator&, const itsmft::TopologyDictionary*,
162template int o2::mft::ioutils::loadROFrameData<o2::mft::TrackLTF>(const o2::itsmft::ROFRecord&, ROframe<o2::mft::TrackLTF>&, gsl::span<const itsmft::CompClusterExt>,
163 gsl::span<const unsigned char>::iterator&, const itsmft::TopologyDictionary*,
166
167template int o2::mft::ioutils::loadROFrameData<o2::mft::TrackLTFL>(const o2::itsmft::ROFRecord&, ROframe<o2::mft::TrackLTFL>&, gsl::span<const itsmft::CompClusterExt>,
168 gsl::span<const unsigned char>::iterator&, const itsmft::TopologyDictionary*,
171
172} // namespace mft
173} // namespace o2
General auxilliary methods.
Definition of the ITSMFT compact cluster.
Definition of the ClusterTopology class.
Load pulled clusters, for a given read-out-frame, in a dedicated container.
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
std::ostringstream debug
int clusterSize
int nClusters
A container to hold and manage MC truth information/labels.
gsl::span< TruthElement > getLabels(uint32_t dataindex)
const Mat3D & getMatrixL2G(int sensID) const
int getNPixels() const
Returns the number of fired pixels.
static constexpr unsigned short InvalidPatternID
Definition CompCluster.h:46
const BCData & getBCData() const
Definition ROFRecord.h:58
gsl::span< const T > getROFData(const gsl::span< const T > tfdata) const
Definition ROFRecord.h:73
int getFirstEntry() const
Definition ROFRecord.h:63
math_utils::Point3D< T > getClusterCoordinates(const CompCluster &cl) const
float getErr2X(int n) const
Returns the error^2 on the x position of the COG for the n_th element.
int getNpixels(int n) const
Returns the number of fired pixels of the n_th element.
bool isGroup(int n) const
Returns true if the element corresponds to a group of rare topologies.
float getErr2Z(int n) const
Returns the error^2 on the z position of the COG for the n_th element.
void fillMatrixCache(Int_t mask) override
Int_t getLayer(Int_t index) const
get layer index (0:9) from the chip index
static GeometryTGeo * Instance()
const Int_t getBinIndex(const Int_t rIndex, const Int_t phiIndex) const
const Int_t getPhiBinIndex(const Float_t phi) const
const Int_t getRBinIndex(const Float_t r, const Int_t layer) const
struct _cl_event * event
Definition glcorearb.h:2982
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLboolean r
Definition glcorearb.h:1233
void bringTo02PiGen(float &phi)
Definition Utils.h:80
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 into std::vector<o2::BaseCluster<float>>
Definition IOUtils.cxx:111
constexpr float DefClusError2Col
Definition IOUtils.h:57
constexpr float DefClusError2Row
Definition IOUtils.h:56
int loadROFrameData(const o2::itsmft::ROFRecord &rof, ROframe< T > &events, gsl::span< const itsmft::CompClusterExt > clusters, gsl::span< const unsigned char >::iterator &pattIt, const itsmft::TopologyDictionary *dict, const dataformats::MCTruthContainer< MCCompLabel > *mClsLabels=nullptr, const o2::mft::Tracker< T > *tracker=nullptr)
Definition IOUtils.cxx:148
std::function< bool(const ROFRecord &)> ROFFilter
Definition Tracker.h:40
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
uint32_t orbit
LHC orbit.
uint16_t bc
bunch crossing ID of interaction
static constexpr int L2G
Definition Cartesian.h:54
static constexpr int T2L
Definition Cartesian.h:55
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters