Project
Loading...
Searching...
No Matches
PreClusterFinderMapping.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
13
14#include <cassert>
15#include <fstream>
16#include <iostream>
17#include <stdexcept>
18
19#include <TMath.h>
20
21#include <fairlogger/Logger.h>
22
24
26
27namespace o2::mch
28{
29
30using namespace std;
31
32//_________________________________________________________________________________________________
33auto Mapping::addNeighbour(MpPad& pad)
34{
36 return [&pad](int neighbourID) {
37 if (pad.nNeighbours == 10) {
38 throw runtime_error("maximum number of neighbouring pads exceeded");
39 }
40 pad.neighbours[pad.nNeighbours] = neighbourID;
41 ++pad.nNeighbours;
42 };
43}
44
45//_________________________________________________________________________________________________
46auto Mapping::addPad(MpDE& de, const mapping::Segmentation& segmentation)
47{
49 return [&de, &segmentation](int padID) {
50 MpPad& pad = de.pads[padID];
51 double padX = segmentation.padPositionX(padID);
52 double padY = segmentation.padPositionY(padID);
53 double padSizeX = segmentation.padSizeX(padID);
54 double padSizeY = segmentation.padSizeY(padID);
55 pad.area[0][0] = padX - padSizeX / 2.;
56 pad.area[0][1] = padX + padSizeX / 2.;
57 pad.area[1][0] = padY - padSizeY / 2.;
58 pad.area[1][1] = padY + padSizeY / 2.;
59 pad.nNeighbours = 0;
60 segmentation.forEachNeighbouringPad(padID, addNeighbour(pad));
61 };
62}
63
64//_________________________________________________________________________________________________
65auto Mapping::removeNeighbouringPadsInCorners(MpDE& de)
66{
69 return [&de](int padID) {
70 auto connectedByCorners = [](float area1[2][2], float area2[2][2]) -> bool {
71 constexpr float precision = -1.e-4; // overlap precision in cm: negative = decrease pad size
72 return (area1[0][0] - area2[0][1] > precision || area2[0][0] - area1[0][1] > precision) &&
73 (area1[1][0] - area2[1][1] > precision || area2[1][0] - area1[1][1] > precision);
74 };
75 MpPad& pad = de.pads[padID];
76 uint8_t nSelectedNeighbours = 0;
77 for (auto i = 0; i < pad.nNeighbours; ++i) {
78 MpPad& neighbour = de.pads[pad.neighbours[i]];
79 if (!connectedByCorners(pad.area, neighbour.area)) {
80 pad.neighbours[nSelectedNeighbours] = pad.neighbours[i];
81 ++nSelectedNeighbours;
82 }
83 }
84 pad.nNeighbours = nSelectedNeighbours;
85 };
86}
87
88//_________________________________________________________________________________________________
89std::vector<std::unique_ptr<Mapping::MpDE>> Mapping::createMapping()
90{
92
93 std::vector<std::unique_ptr<MpDE>> detectionElements{};
94
95 // create the internal mapping for each DE
96 mapping::forEachDetectionElement([&detectionElements](int deID) {
97 auto& segmentation = mapping::segmentation(deID);
98 detectionElements.push_back(std::make_unique<MpDE>());
99 MpDE& de(*(detectionElements.back()));
100 de.uid = deID;
101 de.nPads[0] = segmentation.bending().nofPads();
102 de.nPads[1] = segmentation.nonBending().nofPads();
103 de.pads = std::make_unique<MpPad[]>(de.nPads[0] + de.nPads[1]);
104 segmentation.forEachPad(addPad(de, segmentation));
105 if (PreClusterFinderParam::Instance().excludeCorners) {
106 segmentation.forEachPad(removeNeighbouringPadsInCorners(de));
107 }
108 });
109
110 return detectionElements;
111}
112
113//_________________________________________________________________________________________________
114bool Mapping::areOverlapping(float area1[2][2], float area2[2][2], float precision)
115{
118
119 if (area1[0][0] - area2[0][1] > precision) {
120 return false;
121 }
122 if (area2[0][0] - area1[0][1] > precision) {
123 return false;
124 }
125 if (area1[1][0] - area2[1][1] > precision) {
126 return false;
127 }
128 if (area2[1][0] - area1[1][1] > precision) {
129 return false;
130 }
131
132 return true;
133}
134
135//_________________________________________________________________________________________________
136bool Mapping::areOverlappingExcludeCorners(float area1[2][2], float area2[2][2])
137{
139
140 // precision in cm: positive = increase pad size / negative = decrease pad size
141 constexpr float precision = 1.e-4;
142
143 if (areOverlapping(area1, area2, precision)) {
144 for (int ip1 = 0; ip1 < 2; ++ip1) {
145 for (int ip2 = 0; ip2 < 2; ++ip2) {
146 if (TMath::Abs(area1[0][ip1] - area2[0][1 - ip1]) < precision &&
147 TMath::Abs(area1[1][ip2] - area2[1][1 - ip2]) < precision) {
148 return false;
149 }
150 }
151 }
152 return true;
153 }
154
155 return false;
156}
157
158} // namespace o2
int32_t i
Configurable parameters for MCH preclustering.
static std::vector< std::unique_ptr< MpDE > > createMapping()
static bool areOverlappingExcludeCorners(float area1[2][2], float area2[2][2])
static bool areOverlapping(float area1[2][2], float area2[2][2], float precision)
double padPositionX(int dePadIndex) const
double padSizeY(int dePadIndex) const
const CathodeSegmentation & nonBending() const
const CathodeSegmentation & bending() const
void forEachNeighbouringPad(int dePadIndex, CALLABLE &&func) const
void forEachPad(CALLABLE &&func) const
double padPositionY(int dePadIndex) const
double padSizeX(int dePadIndex) const
GLenum GLint GLint * precision
Definition glcorearb.h:1899
uint8_t itsSharedClusterMap uint8_t
RuntimeErrorRef runtime_error(const char *)
double padSizeY(int i)
double padSizeX(int i)
O2MCHMAPPINGIMPL3_EXPORT const Segmentation & segmentation(int detElemId)
void forEachDetectionElement(CALLABLE &&func)
Defining DataPointCompositeObject explicitly as copiable.
uint16_t de