Reading muon trigger scalers with the DA of the muon trigger and transfer
[u/mrichter/AliRoot.git] / PHOS / PHOSbase / AliPHOSCpvParam.cxx
CommitLineData
0d931d35 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
24ClassImp(AliPHOSCpvParam);
25
26using namespace std;
27
28//====================================================================================
29AliPHOSCpv3GConnection AliPHOSCpvParam::fConnection;
30//====================================================================================
31Bool_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 if (((rWord >> 27) & 1)) { //check if it's end_of_event word for 3gassiplex card.
36 eType = -1;
37 return kFALSE;
38 }
39
40 //std::cout<<"AliPHOSCpvParam::DecodeRawWord(): passed ((rWord >> 27) & 1)"<<std::endl;
41
42 UInt_t statusControlRow = 0x32a8;
43 UInt_t rowControlWord = rWord & 0xfbff;
44 if(rowControlWord == statusControlRow) {
45 eType = -1;
46 return kFALSE;
47 }
48
49 //std::cout<<"AliPHOSCpvParam::DecodeRawWord(): passed rowControlWord == statusControlRow"<<std::endl;
50
51
52 abs = rWord>>12;
53 q = rWord & 0xfff;
54 abs |= (DDL2Mod(ddl))<<15;
55 if(!IsValidAbs(abs)) {
56 eType = -1;
57 return kFALSE;
58 }
59 //std::cout<<"AliPHOSCpvParam::DecodeRawWord(): passed IsValidAbs(abs)"<<std::endl;
60 if(A2Pad(abs) >= kNPadAdd) {
61 // eType = AliPHOSCpvRawStream::kWrongPadErr; // Eliminate circular dependence AliPHOSCpvParam <-> AliPHOSCpvRawStream!
62 eType = 4;
63 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 return kTRUE;
69}
70//====================================================================================
71Int_t AliPHOSCpvParam::Abs(Int_t ddl,Int_t columnCtrl,Int_t gassiplex3,Int_t pad) {
72 if(ddl<0 || ddl>=kNDDL ||
73 columnCtrl<0 || columnCtrl>=kNRows ||
74 gassiplex3<0 || gassiplex3>=kN3GAdd ||
75 pad<0 || pad>=kNPadAdd) return -1;
76 Int_t module = DDL2Mod(ddl); // module is number of CPV module (1-5) accordance to the PHOS offline
77 if(module == -1) return -1;
78 return module<<15
79 | (columnCtrl+1)<<10
80 | (gassiplex3+1)<<6
81 | pad;
82}
83//====================================================================================
84Bool_t AliPHOSCpvParam::IsValidAbs(Int_t abs) {
85 // Printf("AliPHOSCpvParam::IsValidAbs: abs = %d",abs);
86 Int_t mod = A2Mod(abs),
87 cc = A2CC(abs),
88 g3 = A23G(abs),
89 pad = A2Pad(abs);
90 // Printf("mod = %d, cc = %d, g3 = %d, pad = %d",mod,cc,g3,pad);
91 if(mod<1 || mod>kNModules ||
92 cc <0 || cc >=kNRows ||
93 g3 <0 || g3 >=kN3GAdd ||
94 pad<0 || pad>=kNPadAdd) return kFALSE;
95 return kTRUE;
96}
97//====================================================================================
98Int_t AliPHOSCpvParam::A2DDL(Int_t abs) { return Mod2DDL(A2Mod(abs));}
99//====================================================================================
100Int_t AliPHOSCpvParam::A2Mod(Int_t abs) { /*cout << "module is" << (abs>>15) << endl;*/ return abs>>15; }
101//====================================================================================
102Int_t AliPHOSCpvParam::DDL2Mod(Int_t ddl) {
103 switch(ddl) {
104 case (0) : return 5; break;
105 case (2) : return 4; break;
106 case (4) : return 3; break;
107 case (6) : return 2; break;
108 case (8) : return 1; break;
109 default : return -1; break;
110 }
111}
112//====================================================================================
113Int_t AliPHOSCpvParam::Mod2DDL(Int_t mod) {
114 switch(mod) {
115 case (1) : return 8; break;
116 case (2) : return 6; break;
117 case (3) : return 4; break;
118 case (4) : return 2; break;
119 case (5) : return 0; break;
120 default : return -1; break;
121 }
122}
123//====================================================================================
124Int_t AliPHOSCpvParam::A2CC (Int_t abs) { return ((abs >> 10) & 0x1f) - 1; }
125//====================================================================================
126Int_t AliPHOSCpvParam::A23G (Int_t abs) { return ((abs >> 6 ) & 0xf) - 1; }
127//====================================================================================
128Int_t AliPHOSCpvParam::A2Pad(Int_t abs) { return abs & 0x3f; }
129//====================================================================================
130Int_t AliPHOSCpvParam::A2X (Int_t abs) {
131 if(!IsValidAbs(abs)) {
132 // Printf("AliPHOSCpvParam::A2X: abs is not valid!");
133 return -1;
134 }
135 return (kNRows - 1 - A2CC(abs))*(kPadPcX/kNRows) + ( fConnection.Pad2X(A2Pad(abs)));
136}
137//====================================================================================
138Int_t AliPHOSCpvParam::A2Y (Int_t abs) {
139 if(!IsValidAbs(abs)) {
140 // Printf("AliPHOSCpvParam::A2Y: abs is not valid!");
141 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 return (A23G(abs))*(kPadPcY/kN3GAdd) + (5-fConnection.Pad2Y(A2Pad(abs)));
146 //return (kN3GAdd - 1 - A23G(abs))*(kPadPcY/kN3GAdd) + connection.Ch2Y(A2Pad(abs));
147}
148//====================================================================================
149Int_t AliPHOSCpvParam::XY2A (Int_t ddl, Int_t x, Int_t y) {
150 if(x<kMinPx || x>kMaxPx || y<kMinPy || y>kMaxPy) return -1;
151 return Abs(ddl,X2CC(x),Y23G(y),XY2Pad(x,y));
152} // XY2A
153//====================================================================================
154Int_t AliPHOSCpvParam::X2CC (Int_t x) {
155 if(x<kMinPx|| x>kMaxPx) return -1;
156 return kNRows - 1 - x/(kPadPcX/kNRows);
157} // X2CC
158//====================================================================================
159Int_t AliPHOSCpvParam::Y23G (Int_t y) {
160 if(y<kMinPy || y>kMaxPy) return -1;
161 return y/(kPadPcY/kN3GAdd);
162} // Y23G
163//====================================================================================
164Int_t AliPHOSCpvParam::XY2Pad(Int_t x, Int_t y) {
165 if(x<kMinPx || x>kMaxPx || y<kMinPy || y>kMaxPy) return -1;
166 Int_t xPad = x - (kNRows - 1 - X2CC(x))*(kPadPcX/kNRows);
167 //Int_t yPad = y - (kN3GAdd- 1 - Y23G(y))*(kPadPcY/kN3GAdd);
168 Int_t yPad = y - (Y23G(y))*(kPadPcY/kN3GAdd);
169 //return connection.XY2Ch(xPad,yPad);
170 //return fConnection.XY2pad(xPad,kPadPcY/kN3GAdd - 1 - yPad);
171 return fConnection.XY2Pad(xPad,5-yPad);
172} // XY2Pad
173//====================================================================================
174Bool_t AliPHOSCpvParam::GetLimOfCConX( Int_t cc, Int_t &xmin, Int_t &xmax) {
175 //cout<<"cc="<<cc;
176 if(cc < 0 || cc > kNRows) return kFALSE;
177 Int_t a1 = Abs(0,cc,0,fConnection.XY2Pad(0,0)),
178 a2 = Abs(0,cc,0,fConnection.XY2Pad(7,0));
179 if(!(IsValidAbs(a1) && IsValidAbs(a2))) return kFALSE;
180 xmin = A2X(a1);
181 xmax = A2X(a2);
182 //cout<<": xmin = "<<xmin<<" xmax = "<<xmax<<endl;
183 return kTRUE;
184} // GetLimOfCConX
185//====================================================================================
186Bool_t AliPHOSCpvParam::GetLimOf3GonY( Int_t g3, Int_t &ymin, Int_t &ymax) {
187 if(g3 < 0 || g3 > kN3GAdd) return kFALSE;
188 Int_t a1 = Abs(0,0,g3,fConnection.XY2Pad(0,0)),
189 a2 = Abs(0,0,g3,fConnection.XY2Pad(0,5));
190 if(!(IsValidAbs(a1) && IsValidAbs(a2))) return kFALSE;
191 ymin = A2Y(a1);
192 ymax = A2Y(a2);
193 return kTRUE;
194} // GetLimOf3GonY
195//====================================================================================
196Int_t AliPHOSCpvParam::A2fId(Int_t abs) {
197 Int_t fId = 17920;
198 fId += kPadPcX*kPadPcY*(A2DDL(abs)-1);
199 fId += (kPadPcX/kNRows )*A2CC(abs);
200 fId += (kPadPcY/kN3GAdd)*A23G(abs);
201 fId += A2Pad(abs);
202 return fId;
203} // A2fId