Project
Loading...
Searching...
No Matches
Mapper.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
12#include <fstream>
13#include <iostream>
14#include <string>
15#include <sstream>
16#include <cstdlib>
17#include <cmath>
18
19#include "TPCBase/Mapper.h"
20#include "Framework/Logger.h"
21
22namespace o2
23{
24namespace tpc
25{
26constexpr std::array<double, SECTORSPERSIDE> Mapper::SinsPerSector /*{{
27 0,
28 0.3420201433256687129080830800376133993268,
29 0.6427876096865392518964199553010985255241,
30 0.8660254037844385965883020617184229195118,
31 0.9848077530122080203156542665965389460325,
32 0.9848077530122080203156542665965389460325,
33 0.866025403784438707610604524234076961875,
34 0.6427876096865394739410248803324066102505,
35 0.3420201433256688794415367738110944628716,
36 0.,
37 -0.3420201433256686573969318487797863781452,
38 -0.6427876096865392518964199553010985255241,
39 -0.8660254037844383745436971366871148347855,
40 -0.9848077530122080203156542665965389460325,
41 -0.9848077530122081313379567291121929883957,
42 -0.8660254037844385965883020617184229195118,
43 -0.6427876096865395849633273428480606526136,
44 -0.3420201433256686018857806175219593569636
45 }}*/
46 ;
47
48// static constexpr std::array<int, 2> test{1,2};
49
50constexpr std::array<double, SECTORSPERSIDE> Mapper::CosinsPerSector /*{{
51 1,
52 0.9396926207859084279050421173451468348503,
53 0.7660444431189780134516809084743726998568,
54 0.5000000000000001110223024625156540423632,
55 0.1736481776669304144533612088707741349936,
56 -0.1736481776669303034310587463551200926304,
57 -0.4999999999999997779553950749686919152737,
58 -0.7660444431189779024293784459587186574936,
59 -0.9396926207859083168827396548294927924871,
60 -1,
61 -0.9396926207859084279050421173451468348503,
62 -0.7660444431189780134516809084743726998568,
63 -0.5000000000000004440892098500626161694527,
64 -0.1736481776669303311866343619840336032212,
65 0.1736481776669299703641513588081579655409,
66 0.5000000000000001110223024625156540423632,
67 0.7660444431189777914070759834430646151304,
68 0.9396926207859084279050421173451468348503
69 }}*/
70 ;
71
72Mapper::Mapper(const std::string& mappingDir)
73 : mMapGlobalPadToPadPos(mPadsInSector),
74 mMapGlobalPadCentre(mPadsInSector),
75 mMapPadPosGlobalPad(),
76 mMapFECIDGlobalPad(FECInfo::globalSAMPAId(91, 0, 0)),
77 mMapGlobalPadFECInfo(mPadsInSector),
78 mMapPadRegionInfo(),
79 mMapPartitionInfo()
80{
81 load(mappingDir);
82 loadTraceLengths(mappingDir);
83}
84
85bool Mapper::readMappingFile(std::string file)
86{
87 // ===| Mapping file layout |=================================================
88 // Col 0 -> INDEX
89 // Col 1 -> PADROW
90 // Col 2 -> PAD
91 // Col 3 -> X coordinate
92 // Col 4 -> y coordinate
93 // Col 5 -> Connector
94 // Col 6 -> Pin
95 // Col 7 -> Partion
96 // Col 8 -> Region
97 // Col 9 -> FEC
98 // Col 10 -> FEC Connector
99 // Col 11 -> FEC Channel
100 // Col 12 -> SAMPA Chip
101 // Col 13 -> SAMPA Channel
102
103 // ===| Input variables |=====================================================
104 // pad info
105 GlobalPadNumber padIndex;
106 unsigned int padRow;
107 unsigned int pad;
108 float xPos;
109 float yPos;
110
111 // pad plane info
112 unsigned int connector;
113 unsigned int pin;
114 unsigned int partion;
115 unsigned int region;
116
117 // FEC info
118 unsigned int fecIndex;
119 unsigned int fecConnector;
120 unsigned int fecChannel;
121 unsigned int sampaChip;
122 unsigned int sampaChannel;
123
124 std::string line;
125 std::ifstream infile(file, std::ifstream::in);
126 if (!infile.is_open()) {
127 LOGP(fatal, "could not open file {}", file);
128 }
129 while (std::getline(infile, line)) {
130 std::stringstream streamLine(line);
131 streamLine
132 // pad info
133 >> padIndex >> padRow >> pad >> xPos >> yPos
134
135 // pad plane info
136 >> connector >> pin >> partion >> region
137
138 // FEC info
139 >> fecIndex >> fecConnector >> fecChannel >> sampaChip >> sampaChannel;
140
141 // the x and y positions are in mm
142 // in the mapping files, the values are given for sector C04 in the global ALICE coordinate system
143 // however, we need it in the local tracking system. Therefore:
144 const float localX = yPos / 10.f;
145 const float localY = -xPos / 10.f;
146 // with the pad counting (looking to C-Side pad 0,0 is bottom left -- pad-side front view)
147 // these values are for the C-Side
148 // For the A-Side the localY position must be mirrored
149
150 mMapGlobalPadToPadPos[padIndex] = PadPos(padRow, pad);
151 mMapPadPosGlobalPad[PadPos(padRow, pad)] = padIndex;
152 mMapGlobalPadFECInfo[padIndex] = FECInfo(fecIndex, /*fecConnector, fecChannel,*/ sampaChip, sampaChannel);
153 mMapFECIDGlobalPad[FECInfo::globalSAMPAId(fecIndex, sampaChip, sampaChannel)] = padIndex;
154 mMapGlobalPadCentre[padIndex] = PadCentre(localX, localY);
155
156 // std::cout
157 //<< padIndex<< " "
158 //<< padRow<< " "
159 //<< pad<< " "
160 //<< xPos<< " "
161 //<< yPos<< " "
162 //<< " "
164 //<< connector<< " "
165 //<< pin<< " "
166 //<< partion<< " "
167 //<< region<< " "
168 //<< " "
170 //<< fecIndex<< " "
171 //<< fecConnector<< " "
172 //<< fecChannel<< " "
173 //<< sampaChip<< " "
174 //<< sampaChannel << std::endl;
175 }
176 return true;
177}
178
179void Mapper::load(const std::string& mappingDir)
180{
181
182 // std::string inputDir(std::getenv("ALICEO2"));
183 std::string inputDir = mappingDir;
184 if (!inputDir.size()) {
185 // const char* aliceO2env=std::getenv("ALICEO2");
186 // if (aliceO2env) inputDir=aliceO2env;
187 // readMappingFile(inputDir+"/Detectors/TPC/base/files/TABLE-IROC.txt");
188 // readMappingFile(inputDir+"/Detectors/TPC/base/files/TABLE-OROC1.txt");
189 // readMappingFile(inputDir+"/Detectors/TPC/base/files/TABLE-OROC2.txt");
190 // readMappingFile(inputDir+"/Detectors/TPC/base/files/TABLE-OROC3.txt");
191
192 const char* aliceO2env = std::getenv("O2_ROOT");
193 if (aliceO2env) {
194 inputDir = aliceO2env;
195 }
196 inputDir += "/share/Detectors/TPC/files";
197 }
198 readMappingFile(inputDir + "/TABLE-IROC.txt");
199 readMappingFile(inputDir + "/TABLE-OROC1.txt");
200 readMappingFile(inputDir + "/TABLE-OROC2.txt");
201 readMappingFile(inputDir + "/TABLE-OROC3.txt");
202
203 initPadRegionsAndPartitions();
204}
205
206void Mapper::initPadRegionsAndPartitions()
207{
208 // original values for pad widht and height and pad row position are in mm
209 // the ALICE coordinate system is in cm
210 mMapPadRegionInfo[0] = PadRegionInfo(0, 0, 17, 7.5 / 10., 4.16 / 10., 848.5 / 10., 0, 33.20, 0);
211 mMapPadRegionInfo[1] = PadRegionInfo(1, 0, 15, 7.5 / 10., 4.20 / 10., 976.0 / 10., 17, 33.00, 17);
212 mMapPadRegionInfo[2] = PadRegionInfo(2, 1, 16, 7.5 / 10., 4.20 / 10., 1088.5 / 10., 32, 33.08, 32);
213 mMapPadRegionInfo[3] = PadRegionInfo(3, 1, 15, 7.5 / 10., 4.36 / 10., 1208.5 / 10., 48, 31.83, 48);
214 mMapPadRegionInfo[4] = PadRegionInfo(4, 2, 18, 10 / 10., 6.00 / 10., 1347.0 / 10., 0, 38.00, 63);
215 mMapPadRegionInfo[5] = PadRegionInfo(5, 2, 16, 10 / 10., 6.00 / 10., 1527.0 / 10., 18, 38.00, 81);
216 mMapPadRegionInfo[6] = PadRegionInfo(6, 3, 16, 12 / 10., 6.08 / 10., 1708.0 / 10., 0, 47.90, 97);
217 mMapPadRegionInfo[7] = PadRegionInfo(7, 3, 14, 12 / 10., 5.88 / 10., 1900.0 / 10., 16, 49.55, 113);
218 mMapPadRegionInfo[8] = PadRegionInfo(8, 4, 13, 15 / 10., 6.04 / 10., 2089.0 / 10., 0, 59.39, 127);
219 mMapPadRegionInfo[9] = PadRegionInfo(9, 4, 12, 15 / 10., 6.07 / 10., 2284.0 / 10., 0, 64.70, 140);
220
221 mMapPartitionInfo[0] = PartitionInfo(15, 0, 32, 0, 2400);
222 mMapPartitionInfo[1] = PartitionInfo(18, 15, 31, 32, 2880);
223 mMapPartitionInfo[2] = PartitionInfo(18, 15 + 18, 34, 32 + 31, 2880);
224 mMapPartitionInfo[3] = PartitionInfo(20, 15 + 18 + 18, 30, 32 + 31 + 34, 3200);
225 mMapPartitionInfo[4] = PartitionInfo(20, 15 + 18 + 18 + 20, 25, 32 + 31 + 34 + 30, 3200);
226
227 int globalRow = 0;
228 int padsInRow = 0;
229 int padOffset = 0;
230 for (const auto& reg : mMapPadRegionInfo) {
231 for (int row = 0; row < reg.getNumberOfPadRows(); ++row) {
232 mMapPadOffsetPerRow[globalRow] = padOffset;
233 padsInRow = reg.getPadsInRowRegion(row);
234 mMapNumberOfPadsPerRow[globalRow] = padsInRow;
235 ++globalRow;
236 padOffset += padsInRow;
237 }
238 }
239}
240
241//______________________________________________________________________________
242void Mapper::loadTraceLengths(std::string_view mappingDir)
243{
244 std::string inputDir = mappingDir.data();
245 if (!inputDir.size()) {
246 const char* aliceO2env = std::getenv("O2_ROOT");
247 if (aliceO2env) {
248 inputDir = aliceO2env;
249 }
250 inputDir += "/share/Detectors/TPC/files";
251 }
252
253 mTraceLengthsIROC.reserve(Mapper::getPadsInIROC());
254 mTraceLengthsOROC.reserve(Mapper::getPadsInOROC());
255 setTraceLengths(inputDir + "/LENGTH-IROC.txt", mTraceLengthsIROC);
256 setTraceLengths(inputDir + "/LENGTH-OROC1.txt", mTraceLengthsOROC);
257 setTraceLengths(inputDir + "/LENGTH-OROC2.txt", mTraceLengthsOROC);
258 setTraceLengths(inputDir + "/LENGTH-OROC3.txt", mTraceLengthsOROC);
259
260 assert(mTraceLengthsIROC.size() == Mapper::getPadsInIROC());
261 assert(mTraceLengthsOROC.size() == Mapper::getPadsInOROC());
262}
263
264//______________________________________________________________________________
265void Mapper::setTraceLengths(std::string_view inputFile, std::vector<float>& length)
266{
267
268 std::ifstream infile(inputFile.data(), std::ifstream::in);
269 if (!infile.is_open()) {
270 LOGP(fatal, "could not open file {}", inputFile);
271 }
272
273 // e.g. IROC file
274 // Col 0 -> INDEX (0 - 5279)
275 // Col 1 -> PADROW (0 - 62)
276 // Col 2 -> PAD (0 - (Np-1))
277 // Col 3 -> Connector (1 - 132)
278 // Col 4 -> Pin (1 - 40)
279 // Col 5 -> Trace length (mm)
280 // Col 6 -> Number of vias
281
282 unsigned int index{};
283 unsigned int padrow{};
284 unsigned int pad{};
285 unsigned int connector{};
286 unsigned int pin{};
287 float traceLength{};
288 unsigned int numberOfVias{};
289
290 std::string line;
291 while (std::getline(infile, line)) {
292 std::stringstream streamLine(line);
293 streamLine >> index >> padrow >> pad >> connector >> pin >> traceLength >> numberOfVias;
294
295 traceLength /= 10.f;
296
297 length.emplace_back(traceLength);
298 }
299}
300
301bool Mapper::isEdgePad(int rowInSector, int padInRow)
302{
303 const auto& mapper = instance();
304 return (padInRow == 0) || (padInRow == mapper.getNumberOfPadsInRowSector(rowInSector) - 1);
305}
306
307bool Mapper::isFirstOrLastRowInStack(int rowInSector)
308{
309 if (rowInSector == 0 || rowInSector == PADROWS - 1) {
310 return true;
311 }
312
313 const auto& mapper = instance();
314 for (int i = 1; i < 4; ++i) {
315 if (rowInSector == ROWOFFSETSTACK[i] || rowInSector == ROWOFFSETSTACK[i] - 1) {
316 return true;
317 }
318 }
319 return false;
320}
321
322bool Mapper::isBelowSpacerCross(int rowInSector, int padInRow)
323{
324 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};
325 if (ROWSBELOWCROSS[rowInSector]) {
326 return true;
327 }
328
329 const auto& mapper = instance();
330 const auto padCenter = mapper.getNumberOfPadsInRowSector(rowInSector) / 2;
331 if (padInRow == padCenter || padInRow == padCenter - 1) {
332 return true;
333 }
334 return false;
335}
336
337} // namespace tpc
338} // namespace o2
int32_t i
uint32_t padrow
Definition RawData.h:5
GLuint index
Definition glcorearb.h:781
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
math_utils::Point2D< float > PadCentre
Pad centres as 2D float.
Definition Defs.h:122
unsigned short GlobalPadNumber
global pad number
Definition Defs.h:129
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< int > row