-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathMapper.cxx
More file actions
338 lines (299 loc) · 11.6 KB
/
Mapper.cxx
File metadata and controls
338 lines (299 loc) · 11.6 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
// 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.
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include "TPCBase/Mapper.h"
#include "GPUCommonLogger.h"
namespace o2
{
namespace tpc
{
constexpr std::array<double, SECTORSPERSIDE> Mapper::SinsPerSector /*{{
0,
0.3420201433256687129080830800376133993268,
0.6427876096865392518964199553010985255241,
0.8660254037844385965883020617184229195118,
0.9848077530122080203156542665965389460325,
0.9848077530122080203156542665965389460325,
0.866025403784438707610604524234076961875,
0.6427876096865394739410248803324066102505,
0.3420201433256688794415367738110944628716,
0.,
-0.3420201433256686573969318487797863781452,
-0.6427876096865392518964199553010985255241,
-0.8660254037844383745436971366871148347855,
-0.9848077530122080203156542665965389460325,
-0.9848077530122081313379567291121929883957,
-0.8660254037844385965883020617184229195118,
-0.6427876096865395849633273428480606526136,
-0.3420201433256686018857806175219593569636
}}*/
;
// static constexpr std::array<int, 2> test{1,2};
constexpr std::array<double, SECTORSPERSIDE> Mapper::CosinsPerSector /*{{
1,
0.9396926207859084279050421173451468348503,
0.7660444431189780134516809084743726998568,
0.5000000000000001110223024625156540423632,
0.1736481776669304144533612088707741349936,
-0.1736481776669303034310587463551200926304,
-0.4999999999999997779553950749686919152737,
-0.7660444431189779024293784459587186574936,
-0.9396926207859083168827396548294927924871,
-1,
-0.9396926207859084279050421173451468348503,
-0.7660444431189780134516809084743726998568,
-0.5000000000000004440892098500626161694527,
-0.1736481776669303311866343619840336032212,
0.1736481776669299703641513588081579655409,
0.5000000000000001110223024625156540423632,
0.7660444431189777914070759834430646151304,
0.9396926207859084279050421173451468348503
}}*/
;
Mapper::Mapper(const std::string& mappingDir)
: mMapGlobalPadToPadPos(mPadsInSector),
mMapGlobalPadCentre(mPadsInSector),
mMapPadPosGlobalPad(),
mMapFECIDGlobalPad(FECInfo::globalSAMPAId(91, 0, 0)),
mMapGlobalPadFECInfo(mPadsInSector),
mMapPadRegionInfo(),
mMapPartitionInfo()
{
load(mappingDir);
loadTraceLengths(mappingDir);
}
bool Mapper::readMappingFile(std::string file)
{
// ===| Mapping file layout |=================================================
// Col 0 -> INDEX
// Col 1 -> PADROW
// Col 2 -> PAD
// Col 3 -> X coordinate
// Col 4 -> y coordinate
// Col 5 -> Connector
// Col 6 -> Pin
// Col 7 -> Partion
// Col 8 -> Region
// Col 9 -> FEC
// Col 10 -> FEC Connector
// Col 11 -> FEC Channel
// Col 12 -> SAMPA Chip
// Col 13 -> SAMPA Channel
// ===| Input variables |=====================================================
// pad info
GlobalPadNumber padIndex;
unsigned int padRow;
unsigned int pad;
float xPos;
float yPos;
// pad plane info
unsigned int connector;
unsigned int pin;
unsigned int partion;
unsigned int region;
// FEC info
unsigned int fecIndex;
unsigned int fecConnector;
unsigned int fecChannel;
unsigned int sampaChip;
unsigned int sampaChannel;
std::string line;
std::ifstream infile(file, std::ifstream::in);
if (!infile.is_open()) {
LOGP(fatal, "could not open file {}", file);
}
while (std::getline(infile, line)) {
std::stringstream streamLine(line);
streamLine
// pad info
>> padIndex >> padRow >> pad >> xPos >> yPos
// pad plane info
>> connector >> pin >> partion >> region
// FEC info
>> fecIndex >> fecConnector >> fecChannel >> sampaChip >> sampaChannel;
// the x and y positions are in mm
// in the mapping files, the values are given for sector C04 in the global ALICE coordinate system
// however, we need it in the local tracking system. Therefore:
const float localX = yPos / 10.f;
const float localY = -xPos / 10.f;
// with the pad counting (looking to C-Side pad 0,0 is bottom left -- pad-side front view)
// these values are for the C-Side
// For the A-Side the localY position must be mirrored
mMapGlobalPadToPadPos[padIndex] = PadPos(padRow, pad);
mMapPadPosGlobalPad[PadPos(padRow, pad)] = padIndex;
mMapGlobalPadFECInfo[padIndex] = FECInfo(fecIndex, /*fecConnector, fecChannel,*/ sampaChip, sampaChannel);
mMapFECIDGlobalPad[FECInfo::globalSAMPAId(fecIndex, sampaChip, sampaChannel)] = padIndex;
mMapGlobalPadCentre[padIndex] = PadCentre(localX, localY);
// std::cout
//<< padIndex<< " "
//<< padRow<< " "
//<< pad<< " "
//<< xPos<< " "
//<< yPos<< " "
//<< " "
//// pad plane info<< " "
//<< connector<< " "
//<< pin<< " "
//<< partion<< " "
//<< region<< " "
//<< " "
//// FEC info<< " "
//<< fecIndex<< " "
//<< fecConnector<< " "
//<< fecChannel<< " "
//<< sampaChip<< " "
//<< sampaChannel << std::endl;
}
return true;
}
void Mapper::load(const std::string& mappingDir)
{
// std::string inputDir(std::getenv("ALICEO2"));
std::string inputDir = mappingDir;
if (!inputDir.size()) {
// const char* aliceO2env=std::getenv("ALICEO2");
// if (aliceO2env) inputDir=aliceO2env;
// readMappingFile(inputDir+"/Detectors/TPC/base/files/TABLE-IROC.txt");
// readMappingFile(inputDir+"/Detectors/TPC/base/files/TABLE-OROC1.txt");
// readMappingFile(inputDir+"/Detectors/TPC/base/files/TABLE-OROC2.txt");
// readMappingFile(inputDir+"/Detectors/TPC/base/files/TABLE-OROC3.txt");
const char* aliceO2env = std::getenv("O2_ROOT");
if (aliceO2env) {
inputDir = aliceO2env;
}
inputDir += "/share/Detectors/TPC/files";
}
readMappingFile(inputDir + "/TABLE-IROC.txt");
readMappingFile(inputDir + "/TABLE-OROC1.txt");
readMappingFile(inputDir + "/TABLE-OROC2.txt");
readMappingFile(inputDir + "/TABLE-OROC3.txt");
initPadRegionsAndPartitions();
}
void Mapper::initPadRegionsAndPartitions()
{
// original values for pad widht and height and pad row position are in mm
// the ALICE coordinate system is in cm
mMapPadRegionInfo[0] = PadRegionInfo(0, 0, 17, 7.5 / 10., 4.16 / 10., 848.5 / 10., 0, 33.20, 0);
mMapPadRegionInfo[1] = PadRegionInfo(1, 0, 15, 7.5 / 10., 4.20 / 10., 976.0 / 10., 17, 33.00, 17);
mMapPadRegionInfo[2] = PadRegionInfo(2, 1, 16, 7.5 / 10., 4.20 / 10., 1088.5 / 10., 32, 33.08, 32);
mMapPadRegionInfo[3] = PadRegionInfo(3, 1, 15, 7.5 / 10., 4.36 / 10., 1208.5 / 10., 48, 31.83, 48);
mMapPadRegionInfo[4] = PadRegionInfo(4, 2, 18, 10 / 10., 6.00 / 10., 1347.0 / 10., 0, 38.00, 63);
mMapPadRegionInfo[5] = PadRegionInfo(5, 2, 16, 10 / 10., 6.00 / 10., 1527.0 / 10., 18, 38.00, 81);
mMapPadRegionInfo[6] = PadRegionInfo(6, 3, 16, 12 / 10., 6.08 / 10., 1708.0 / 10., 0, 47.90, 97);
mMapPadRegionInfo[7] = PadRegionInfo(7, 3, 14, 12 / 10., 5.88 / 10., 1900.0 / 10., 16, 49.55, 113);
mMapPadRegionInfo[8] = PadRegionInfo(8, 4, 13, 15 / 10., 6.04 / 10., 2089.0 / 10., 0, 59.39, 127);
mMapPadRegionInfo[9] = PadRegionInfo(9, 4, 12, 15 / 10., 6.07 / 10., 2284.0 / 10., 0, 64.70, 140);
mMapPartitionInfo[0] = PartitionInfo(15, 0, 32, 0, 2400);
mMapPartitionInfo[1] = PartitionInfo(18, 15, 31, 32, 2880);
mMapPartitionInfo[2] = PartitionInfo(18, 15 + 18, 34, 32 + 31, 2880);
mMapPartitionInfo[3] = PartitionInfo(20, 15 + 18 + 18, 30, 32 + 31 + 34, 3200);
mMapPartitionInfo[4] = PartitionInfo(20, 15 + 18 + 18 + 20, 25, 32 + 31 + 34 + 30, 3200);
int globalRow = 0;
int padsInRow = 0;
int padOffset = 0;
for (const auto& reg : mMapPadRegionInfo) {
for (int row = 0; row < reg.getNumberOfPadRows(); ++row) {
mMapPadOffsetPerRow[globalRow] = padOffset;
padsInRow = reg.getPadsInRowRegion(row);
mMapNumberOfPadsPerRow[globalRow] = padsInRow;
++globalRow;
padOffset += padsInRow;
}
}
}
//______________________________________________________________________________
void Mapper::loadTraceLengths(std::string_view mappingDir)
{
std::string inputDir = mappingDir.data();
if (!inputDir.size()) {
const char* aliceO2env = std::getenv("O2_ROOT");
if (aliceO2env) {
inputDir = aliceO2env;
}
inputDir += "/share/Detectors/TPC/files";
}
mTraceLengthsIROC.reserve(Mapper::getPadsInIROC());
mTraceLengthsOROC.reserve(Mapper::getPadsInOROC());
setTraceLengths(inputDir + "/LENGTH-IROC.txt", mTraceLengthsIROC);
setTraceLengths(inputDir + "/LENGTH-OROC1.txt", mTraceLengthsOROC);
setTraceLengths(inputDir + "/LENGTH-OROC2.txt", mTraceLengthsOROC);
setTraceLengths(inputDir + "/LENGTH-OROC3.txt", mTraceLengthsOROC);
assert(mTraceLengthsIROC.size() == Mapper::getPadsInIROC());
assert(mTraceLengthsOROC.size() == Mapper::getPadsInOROC());
}
//______________________________________________________________________________
void Mapper::setTraceLengths(std::string_view inputFile, std::vector<float>& length)
{
std::ifstream infile(inputFile.data(), std::ifstream::in);
if (!infile.is_open()) {
LOGP(fatal, "could not open file {}", inputFile);
}
// e.g. IROC file
// Col 0 -> INDEX (0 - 5279)
// Col 1 -> PADROW (0 - 62)
// Col 2 -> PAD (0 - (Np-1))
// Col 3 -> Connector (1 - 132)
// Col 4 -> Pin (1 - 40)
// Col 5 -> Trace length (mm)
// Col 6 -> Number of vias
unsigned int index{};
unsigned int padrow{};
unsigned int pad{};
unsigned int connector{};
unsigned int pin{};
float traceLength{};
unsigned int numberOfVias{};
std::string line;
while (std::getline(infile, line)) {
std::stringstream streamLine(line);
streamLine >> index >> padrow >> pad >> connector >> pin >> traceLength >> numberOfVias;
traceLength /= 10.f;
length.emplace_back(traceLength);
}
}
bool Mapper::isEdgePad(int rowInSector, int padInRow)
{
const auto& mapper = instance();
return (padInRow == 0) || (padInRow == mapper.getNumberOfPadsInRowSector(rowInSector) - 1);
}
bool Mapper::isFirstOrLastRowInStack(int rowInSector)
{
if (rowInSector == 0 || rowInSector == PADROWS - 1) {
return true;
}
const auto& mapper = instance();
for (int i = 1; i < 4; ++i) {
if (rowInSector == ROWOFFSETSTACK[i] || rowInSector == ROWOFFSETSTACK[i] - 1) {
return true;
}
}
return false;
}
bool Mapper::isBelowSpacerCross(int rowInSector, int padInRow)
{
static std::vector<bool> ROWSBELOWCROSS{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (ROWSBELOWCROSS[rowInSector]) {
return true;
}
const auto& mapper = instance();
const auto padCenter = mapper.getNumberOfPadsInRowSector(rowInSector) / 2;
if (padInRow == padCenter || padInRow == padCenter - 1) {
return true;
}
return false;
}
} // namespace tpc
} // namespace o2