Project
Loading...
Searching...
No Matches
Geometry.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 "CPVBase/Geometry.h"
13#include <fairlogger/Logger.h>
14
15using namespace o2::cpv;
16
18
19unsigned short Geometry::relToAbsId(short moduleNumber, short iphi, short iz)
20{
21 // converts module number, phi and z coordunates to absId
22 return kNumberOfCPVPadsPhi * kNumberOfCPVPadsZ * (moduleNumber - 2) + kNumberOfCPVPadsZ * iphi + iz;
23}
24
25bool Geometry::absToRelNumbering(unsigned short absId, short* relId)
26{
27 // Converts the absolute numbering into the following array
28 // relId[0] = CPV Module number 1:fNModules
29 // relId[1] = Column number inside a CPV module (Phi coordinate)
30 // relId[2] = Row number inside a CPV module (Z coordinate)
31 if (absId >= kNCHANNELS) {
32 LOG(debug) << "Wrong absId = " << absId << " > kNCHANNELS=" << kNCHANNELS;
33 return false;
34 }
35 const short nCPV = kNumberOfCPVPadsPhi * kNumberOfCPVPadsZ;
36 relId[0] = absId / nCPV + 2;
37 absId -= (relId[0] - 2) * nCPV;
38 relId[1] = absId / kNumberOfCPVPadsZ;
39 relId[2] = absId % kNumberOfCPVPadsZ;
40
41 return true;
42}
43short Geometry::absIdToModule(unsigned short absId)
44{
45
46 return 2 + absId / (kNumberOfCPVPadsPhi * kNumberOfCPVPadsZ);
47}
48
49short Geometry::areNeighbours(unsigned short absId1, unsigned short absId2)
50{
51
52 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
53 // = 1 are neighbour
54 // = 2 are not neighbour but do not continue searching
55 // =-1 are not neighbour, continue searching, but do not look before d2 next
56 // time
57 // neighbours are defined as digits having at least a common vertex
58 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
59 // which is compared to a digit (d2) not yet in a cluster
60
61 short relId1[3];
62 absToRelNumbering(absId1, relId1);
63
64 short relId2[3];
65 absToRelNumbering(absId2, relId2);
66
67 if (relId1[0] == relId2[0]) { // inside the same CPV module
68 short rowdiff = TMath::Abs(relId1[1] - relId2[1]);
69 short coldiff = TMath::Abs(relId1[2] - relId2[2]);
70
71 // if ((coldiff <= 1) && (rowdiff <= 1)) { // At least common vertex
72 if (coldiff + rowdiff <= 1) { // Common side
73 return 1;
74 } else {
75 if ((relId2[1] > relId1[1]) && (relId2[2] > relId1[2] + 1)) {
76 return 2; // Difference in row numbers is too large to look further
77 }
78 }
79 return 0;
80
81 } else {
82 if (relId1[0] > relId2[0]) { // we switched to the next module
83 return -1;
84 }
85 return 2;
86 }
87 return 0;
88}
89void Geometry::absIdToRelPosInModule(unsigned short absId, float& x, float& z)
90{
91 // Calculate from absId of a cell its position in module
92
93 short relId[3];
94 absToRelNumbering(absId, relId);
95
96 x = (relId[1] - kNumberOfCPVPadsPhi / 2 + 0.5) * kCPVPadSizePhi;
97 z = (relId[2] - kNumberOfCPVPadsZ / 2 + 0.5) * kCPVPadSizeZ;
98}
99bool Geometry::relToAbsNumbering(const short* relId, unsigned short& absId)
100{
101
102 absId =
103 (relId[0] - 2) * kNumberOfCPVPadsPhi * kNumberOfCPVPadsZ + // the offset of PHOS modules
104 relId[1] * kNumberOfCPVPadsZ + // the offset along phi
105 relId[2]; // the offset along z
106
107 return true;
108}
109bool Geometry::hwaddressToAbsId(short ccId, short dil, short gas, short pad, unsigned short& absId)
110{
111 // check if hw address is valid
112 bool isGoodHWAddress = true;
113 if (pad < 0 || pad >= kNPAD) {
114 LOG(debug) << "Geometry::hwaddressToAbsId() : Wrong pad address: pad=" << pad << " >= kNPAD=" << kNPAD;
115 isGoodHWAddress = false;
116 }
117 if (dil < 0 || dil >= kNDilogic) {
118 LOG(debug) << "Geometry::hwaddressToAbsId() : Wrong dil address: dil=" << dil << " >= kNDilogic=" << kNDilogic;
119 isGoodHWAddress = false;
120 }
121 if (gas < 0 || gas >= kNGas) {
122 LOG(debug) << "Geometry::hwaddressToAbsId() : Wrong gasiplex address: gas=" << gas << " >= kNGas=" << kNGas;
123 isGoodHWAddress = false;
124 }
125 // return false in no success case
126 if (!isGoodHWAddress) {
127 return false;
128 }
129
130 short pZ = mPadToZ[pad];
131 short pPhi = mPadToPhi[pad];
132 short relId[3] = {short(ccId / 8 + 2), short((ccId % 8) * 16 + (dil / 2) * 8 + pPhi), short(59 - ((dil % 2) * 30 + gas * 6 + pZ))};
133
134 return relToAbsNumbering(relId, absId);
135}
136
137bool Geometry::absIdToHWaddress(unsigned short absId, short& ccId, short& dil, short& gas, short& pad)
138{
139 // Convert absId to hw address
140 // Arguments: ccId: 0 -- 7 - mod 2; 8...15 mod 3; 16...23 mod 4
141 // dilogic: 0..3, gas=0..5, pad:0..47
142
143 short relId[3];
144 if (!absToRelNumbering(absId, relId)) {
145 return false; // wrong absId passed
146 }
147
148 ccId = (relId[0] - 2) * 8 + relId[1] / 16;
149 dil = 2 * ((relId[1] % 16) / 8) + (59 - relId[2]) / 30; // Dilogic# 0..3
150 gas = ((59 - relId[2]) % 30) / 6; // gasiplex# 0..4
151 pad = mPadMap[(59 - relId[2]) % 6][relId[1] % 8]; // pad 0..47
152
153 return true;
154}
ClassImp(Geometry)
std::ostringstream debug
static constexpr short mPadToPhi[48]
Definition Geometry.h:109
static constexpr short mPadToZ[48]
Definition Geometry.h:108
static constexpr short mPadMap[6][8]
Definition Geometry.h:102
static constexpr short kNCHANNELS
Definition Geometry.h:30
static constexpr short kNumberOfCPVPadsPhi
Definition Geometry.h:28
static constexpr short kNDilogic
Definition Geometry.h:35
static bool absIdToHWaddress(unsigned short absId, short &ccId, short &dil, short &gas, short &pad)
Definition Geometry.cxx:137
static short absIdToModule(unsigned short absId)
Definition Geometry.cxx:43
static bool relToAbsNumbering(const short *relId, unsigned short &absId)
Definition Geometry.cxx:99
static constexpr short kNGas
Definition Geometry.h:36
static constexpr float kCPVPadSizePhi
Definition Geometry.h:31
static short areNeighbours(unsigned short absId1, unsigned short absId2)
Definition Geometry.cxx:49
static void absIdToRelPosInModule(unsigned short absId, float &x, float &z)
Definition Geometry.cxx:89
static bool absToRelNumbering(unsigned short absId, short *relId)
Definition Geometry.cxx:25
static unsigned short relToAbsId(short moduleNumber, short iphi, short iz)
Definition Geometry.cxx:19
static constexpr short kNPAD
Definition Geometry.h:34
static bool hwaddressToAbsId(short ccId, short dil, short gas, short pad, unsigned short &absId)
Definition Geometry.cxx:109
static constexpr float kCPVPadSizeZ
Definition Geometry.h:32
static constexpr short kNumberOfCPVPadsZ
Definition Geometry.h:29
GLint GLenum GLint x
Definition glcorearb.h:403
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"