Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 :
16 : // Class provides a set of static methods to convert absolute number of pad to pair (X,Y)
17 : // and vice versa
18 : // and some other
19 : // Author - Mikhail Stolpovskiy, IHEP Protvino (2013)
20 :
21 : #include "AliPHOSCpvParam.h"
22 : // #include "AliPHOSCpvRawStream.h"
23 :
24 22 : ClassImp(AliPHOSCpvParam);
25 :
26 : using namespace std;
27 :
28 : //====================================================================================
29 22 : AliPHOSCpv3GConnection AliPHOSCpvParam::fConnection;
30 : //====================================================================================
31 : Bool_t AliPHOSCpvParam::DecodeRawWord(Int_t ddl,Int_t rWord, Int_t & abs, Int_t & q, Int_t & eType) {
32 :
33 : //std::cout<<"ddl = "<<ddl<<", mod = "<<DDL2Mod(ddl)<<std::endl;
34 :
35 0 : if (((rWord >> 27) & 1)) { //check if it's end_of_event word for 3gassiplex card.
36 0 : eType = -1;
37 0 : return kFALSE;
38 : }
39 :
40 : //std::cout<<"AliPHOSCpvParam::DecodeRawWord(): passed ((rWord >> 27) & 1)"<<std::endl;
41 :
42 : UInt_t statusControlRow = 0x32a8;
43 0 : UInt_t rowControlWord = rWord & 0xfbff;
44 0 : if(rowControlWord == statusControlRow) {
45 0 : eType = -1;
46 0 : return kFALSE;
47 : }
48 :
49 : //std::cout<<"AliPHOSCpvParam::DecodeRawWord(): passed rowControlWord == statusControlRow"<<std::endl;
50 :
51 :
52 0 : abs = rWord>>12;
53 0 : q = rWord & 0xfff;
54 0 : abs |= (DDL2Mod(ddl))<<15;
55 0 : if(!IsValidAbs(abs)) {
56 0 : eType = -1;
57 0 : return kFALSE;
58 : }
59 : //std::cout<<"AliPHOSCpvParam::DecodeRawWord(): passed IsValidAbs(abs)"<<std::endl;
60 0 : if(A2Pad(abs) >= kNPadAdd) {
61 : // eType = AliPHOSCpvRawStream::kWrongPadErr; // Eliminate circular dependence AliPHOSCpvParam <-> AliPHOSCpvRawStream!
62 0 : eType = 4;
63 0 : return kFALSE;
64 : }
65 :
66 : //Printf("AliPHOSCpvParam::DecodeRawWord: mod, cc, 3g, pad , q = %d, %d, %d, %d, %d",A2Mod(abs),A2CC(abs),A23G(abs),A2Pad(abs), q);
67 :
68 0 : return kTRUE;
69 0 : }
70 : //====================================================================================
71 : Int_t AliPHOSCpvParam::Abs(Int_t ddl,Int_t columnCtrl,Int_t gassiplex3,Int_t pad) {
72 0 : if(ddl<0 || ddl>=kNDDL ||
73 0 : columnCtrl<0 || columnCtrl>=kNRows ||
74 0 : gassiplex3<0 || gassiplex3>=kN3GAdd ||
75 0 : pad<0 || pad>=kNPadAdd) return -1;
76 0 : Int_t module = DDL2Mod(ddl); // module is number of CPV module (1-5) accordance to the PHOS offline
77 0 : if(module == -1) return -1;
78 0 : return module<<15
79 0 : | (columnCtrl+1)<<10
80 0 : | (gassiplex3+1)<<6
81 0 : | pad;
82 0 : }
83 : //====================================================================================
84 : Bool_t AliPHOSCpvParam::IsValidAbs(Int_t abs) {
85 : // Printf("AliPHOSCpvParam::IsValidAbs: abs = %d",abs);
86 0 : Int_t mod = A2Mod(abs),
87 0 : cc = A2CC(abs),
88 0 : g3 = A23G(abs),
89 0 : pad = A2Pad(abs);
90 : // Printf("mod = %d, cc = %d, g3 = %d, pad = %d",mod,cc,g3,pad);
91 0 : if(mod<1 || mod>kNModules ||
92 0 : cc <0 || cc >=kNRows ||
93 0 : g3 <0 || g3 >=kN3GAdd ||
94 0 : pad<0 || pad>=kNPadAdd) return kFALSE;
95 0 : return kTRUE;
96 0 : }
97 : //====================================================================================
98 0 : Int_t AliPHOSCpvParam::A2DDL(Int_t abs) { return Mod2DDL(A2Mod(abs));}
99 : //====================================================================================
100 0 : Int_t AliPHOSCpvParam::A2Mod(Int_t abs) { /*cout << "module is" << (abs>>15) << endl;*/ return abs>>15; }
101 : //====================================================================================
102 : Int_t AliPHOSCpvParam::DDL2Mod(Int_t ddl) {
103 0 : switch(ddl) {
104 0 : case (0) : return 5; break;
105 0 : case (2) : return 4; break;
106 0 : case (4) : return 3; break;
107 0 : case (6) : return 2; break;
108 0 : case (8) : return 1; break;
109 0 : default : return -1; break;
110 : }
111 0 : }
112 : //====================================================================================
113 : Int_t AliPHOSCpvParam::Mod2DDL(Int_t mod) {
114 0 : switch(mod) {
115 0 : case (1) : return 8; break;
116 0 : case (2) : return 6; break;
117 0 : case (3) : return 4; break;
118 0 : case (4) : return 2; break;
119 0 : case (5) : return 0; break;
120 0 : default : return -1; break;
121 : }
122 0 : }
123 : //====================================================================================
124 0 : Int_t AliPHOSCpvParam::A2CC (Int_t abs) { return ((abs >> 10) & 0x1f) - 1; }
125 : //====================================================================================
126 0 : Int_t AliPHOSCpvParam::A23G (Int_t abs) { return ((abs >> 6 ) & 0xf) - 1; }
127 : //====================================================================================
128 0 : Int_t AliPHOSCpvParam::A2Pad(Int_t abs) { return abs & 0x3f; }
129 : //====================================================================================
130 : Int_t AliPHOSCpvParam::A2X (Int_t abs) {
131 0 : if(!IsValidAbs(abs)) {
132 : // Printf("AliPHOSCpvParam::A2X: abs is not valid!");
133 0 : return -1;
134 : }
135 0 : return (kNRows - 1 - A2CC(abs))*(kPadPcX/kNRows) + ( fConnection.Pad2X(A2Pad(abs)));
136 0 : }
137 : //====================================================================================
138 : Int_t AliPHOSCpvParam::A2Y (Int_t abs) {
139 0 : if(!IsValidAbs(abs)) {
140 : // Printf("AliPHOSCpvParam::A2Y: abs is not valid!");
141 0 : return -1;
142 : }
143 : //return A23G(abs)*(kPadPcY/kN3GAdd) + connection.Ch2Y(A2Pad(abs));
144 : //return (kN3GAdd - 1 - A23G(abs))*(kPadPcY/kN3GAdd) + (kPadPcY/kN3GAdd - 1 - fConnection.pad2Y(A2Pad(abs)));
145 0 : return (A23G(abs))*(kPadPcY/kN3GAdd) + (5-fConnection.Pad2Y(A2Pad(abs)));
146 : //return (kN3GAdd - 1 - A23G(abs))*(kPadPcY/kN3GAdd) + connection.Ch2Y(A2Pad(abs));
147 0 : }
148 : //====================================================================================
149 : Int_t AliPHOSCpvParam::XY2A (Int_t ddl, Int_t x, Int_t y) {
150 0 : if(x<kMinPx || x>kMaxPx || y<kMinPy || y>kMaxPy) return -1;
151 0 : return Abs(ddl,X2CC(x),Y23G(y),XY2Pad(x,y));
152 0 : } // XY2A
153 : //====================================================================================
154 : Int_t AliPHOSCpvParam::X2CC (Int_t x) {
155 0 : if(x<kMinPx|| x>kMaxPx) return -1;
156 0 : return kNRows - 1 - x/(kPadPcX/kNRows);
157 0 : } // X2CC
158 : //====================================================================================
159 : Int_t AliPHOSCpvParam::Y23G (Int_t y) {
160 0 : if(y<kMinPy || y>kMaxPy) return -1;
161 0 : return y/(kPadPcY/kN3GAdd);
162 0 : } // Y23G
163 : //====================================================================================
164 : Int_t AliPHOSCpvParam::XY2Pad(Int_t x, Int_t y) {
165 0 : if(x<kMinPx || x>kMaxPx || y<kMinPy || y>kMaxPy) return -1;
166 0 : Int_t xPad = x - (kNRows - 1 - X2CC(x))*(kPadPcX/kNRows);
167 : //Int_t yPad = y - (kN3GAdd- 1 - Y23G(y))*(kPadPcY/kN3GAdd);
168 0 : Int_t yPad = y - (Y23G(y))*(kPadPcY/kN3GAdd);
169 : //return connection.XY2Ch(xPad,yPad);
170 : //return fConnection.XY2pad(xPad,kPadPcY/kN3GAdd - 1 - yPad);
171 0 : return fConnection.XY2Pad(xPad,5-yPad);
172 0 : } // XY2Pad
173 : //====================================================================================
174 : Bool_t AliPHOSCpvParam::GetLimOfCConX( Int_t cc, Int_t &xmin, Int_t &xmax) {
175 : //cout<<"cc="<<cc;
176 0 : if(cc < 0 || cc > kNRows) return kFALSE;
177 0 : Int_t a1 = Abs(0,cc,0,fConnection.XY2Pad(0,0)),
178 0 : a2 = Abs(0,cc,0,fConnection.XY2Pad(7,0));
179 0 : if(!(IsValidAbs(a1) && IsValidAbs(a2))) return kFALSE;
180 0 : xmin = A2X(a1);
181 0 : xmax = A2X(a2);
182 : //cout<<": xmin = "<<xmin<<" xmax = "<<xmax<<endl;
183 0 : return kTRUE;
184 0 : } // GetLimOfCConX
185 : //====================================================================================
186 : Bool_t AliPHOSCpvParam::GetLimOf3GonY( Int_t g3, Int_t &ymin, Int_t &ymax) {
187 0 : if(g3 < 0 || g3 > kN3GAdd) return kFALSE;
188 0 : Int_t a1 = Abs(0,0,g3,fConnection.XY2Pad(0,0)),
189 0 : a2 = Abs(0,0,g3,fConnection.XY2Pad(0,5));
190 0 : if(!(IsValidAbs(a1) && IsValidAbs(a2))) return kFALSE;
191 0 : ymin = A2Y(a1);
192 0 : ymax = A2Y(a2);
193 0 : return kTRUE;
194 0 : } // GetLimOf3GonY
195 : //====================================================================================
196 : Int_t AliPHOSCpvParam::A2fId(Int_t abs) {
197 : Int_t fId = 17920;
198 0 : fId += kPadPcX*kPadPcY*(A2DDL(abs)-1);
199 0 : fId += (kPadPcX/kNRows )*A2CC(abs);
200 0 : fId += (kPadPcY/kN3GAdd)*A23G(abs);
201 0 : fId += A2Pad(abs);
202 0 : return fId;
203 : } // A2fId
|