Correct sign for calculated b_y (outside measured region).
[u/mrichter/AliRoot.git] / TPC / AliTPCmapper.cxx
CommitLineData
bb18c002 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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//-------------------------------------------------------------------------
17// AliTPCmapper
18// Origin: Jens Wiechula (j.wiechula@gsi.de)
19//
20// class to map (row,pad,sector) to (RCU, Branch, FEC, Altro, Altro channel)
21// create Altro address
22
23
24#include <stdio.h>
25#include <TMath.h>
26#include <TSystem.h>
27
28#include "AliTPCmapper.h"
29
30
31ClassImp(AliTPCmapper)
32
33
34//______________________________________________________________
35AliTPCmapper::AliTPCmapper()
36{
37 Init();
38 ReadMapping();
39}
40
41//______________________________________________________________
42void AliTPCmapper::Init()
43{
44
45 //Initialize arrays
46 for (Int_t i=0; i<kNrcu; i++){
47 for (Int_t j=0; j<kNbranch; j++){
48 for (Int_t k=0; k<kNfecMax; k++){
49 for (Int_t l=0; l<kNaltro; l++){
50 for (Int_t m=0; m<kNchannel; m++){
51 fAddressToRow[i][j][k][l][m] = -1;
52 fAddressToPad[i][j][k][l][m] = -1;
53 }
54 }
55 }
56 }
57 }
58
59 for (Int_t i=0; i<kNpadrow; i++){
60 for (Int_t j=0; j<kNpadMax; j++){
61 fRowPadToRCU[i][j] = -1;
62 fRowPadToBranch[i][j] = -1;
63 fRowPadToFEC[i][j] = -1;
64 fRowPadToAltro[i][j] = -1;
65 fRowPadToChannel[i][j] = -1;
66 fRowPadToPadsec[i][j] = -1;
67 }
68 }
69
70 for (Int_t i=0; i<kNpadSector; i++){
71 fPadsecToRow[i]=-1;
72 fPadsecToPad[i]=-1;
73 }
74
75// for (Int_t i=0; i<kNaddrSize; i++)
76// fAddressArray[i] = 0;
77
78 strcpy(fMapfileName,gSystem->ExpandPathName("$ALICE_ROOT/TPC/final_mapping.txt"));
79}
80
81//______________________________________________________________
82Int_t AliTPCmapper::ReadMapping()
83{
0e75e410 84 FILE *fin;
bb18c002 85 char line[255];
86
87 int pad = -1, row = -1;
88 int rcu = -1, bra = -1, fec = -1, alt = -1, chn = -1;
89 int padsec = 0;
90
91
0e75e410 92 fin = fopen(fMapfileName,"r");
93 if (!fin){
bb18c002 94 fprintf(stderr, "cannot open file '%s'!\n",fMapfileName);
95 return 1;
96 }
97
0e75e410 98 fgets(line,256,fin);
bb18c002 99 while (sscanf(line,"%d %d %d %d %d %d %d %d",
100 &padsec, &row, &pad,
101 &rcu, &bra, &fec, &alt, &chn
102 )!=8){
0e75e410 103 fgets(line, 256, fin);
bb18c002 104 fprintf(stderr,"%s",line);
105 }
106
0e75e410 107 while (!feof(fin)){
bb18c002 108 sscanf(line,"%d %d %d %d %d %d %d %d",
109 &padsec, &row, &pad,
110 &rcu, &bra, &fec, &alt, &chn
111 );
112 fAddressToRow[rcu][bra][fec][alt][chn] = row;
113 fAddressToPad[rcu][bra][fec][alt][chn] = pad;
114
115 fRowPadToRCU[row][pad] = rcu;
116 fRowPadToBranch[row][pad] = bra;
117 fRowPadToFEC[row][pad] = fec;
118 fRowPadToAltro[row][pad] = alt;
119 fRowPadToChannel[row][pad] = chn;
120 fRowPadToPadsec[row][pad] = padsec;
121
122 fPadsecToRow[padsec] = row;
123 fPadsecToPad[padsec] = pad;
124
125
126
0e75e410 127 fgets(line, 256, fin);
bb18c002 128 }
129
0e75e410 130 fclose(fin);
bb18c002 131
132 return 0;
133}
134
135//______________________________________________________________
136void AliTPCmapper::PrintRBFACinfo(Int_t row, Int_t pad)
137{
138 fprintf(stderr,"RCU: %d, Branch: %d, FEC: %2d, Altro: %d, Channel: %2d\n",
139 GetRCUs(row,pad), GetBranchS(row,pad),
140 GetFECs(row,pad), GetAltroS(row,pad),
141 GetChannelS(row,pad));
142
143}
144
145//______________________________________________________________
0e75e410 146Int_t AliTPCmapper::GetPadsInRowS(Int_t row) const{
147 //
148 //GetPadsInRowS
149 //
bb18c002 150 if ( row == 0 )
151 return 68;
152
153 if ( row < 63 )
154 return 2*(Int_t)(row/3.+33.67);
155
156 row -= 63;
157 Double_t k1=10./6.*tan(TMath::Pi()/18.);
158
159 if ( row < 64 )
160 return 2*(Int_t)(k1 * row + 37.75);
161
162 Double_t k2=15./6.*tan(TMath::Pi()/18.);
163 return 2*(Int_t)(k2 * (row-64) + 56.66);
164}
165
166//______________________________________________________________
0e75e410 167Double_t AliTPCmapper::GetPadXlocalS(Int_t row, Int_t pad) const {
168 //
169 //GetPadXlocalS
170 //
bb18c002 171 if ( row < 63 ) //IROC
172 return (852.25 + 7.5 * (Double_t)row)*1.e-1; //divide by 10 to get cm
173
174 row -= 63;
175
176 if ( row < 64 ) //OROC inner part
177 return (10.* row + 1351.)*1.e-1; //divide by 10 to get cm
178
179
180 //OROC outer part
181 return (15.*(row - 64) + 1993.5)*1.e-1; //divide by 10 to get cm
182}
183
184//______________________________________________________________
0e75e410 185Double_t AliTPCmapper::GetPadXlocalS(Int_t padsector) const{
186 //
187 //GetPadXlocalS
188 //
bb18c002 189 Int_t row=GetRowFromPadSector(padsector);
190 Int_t pad=GetPadFromPadSector(padsector);
191 return GetPadXlocalS(row,pad);
192}
193
194//______________________________________________________________
0e75e410 195Double_t AliTPCmapper::GetPadYlocalS(Int_t row, Int_t pad) const{
196 //
197 //:GetPadYlocalS
198 //
bb18c002 199 Int_t padsInRow = GetPadsInRowS(row);
200
201 if ( row < 63 ) //IROC
202 return (2.* padsInRow - 4.*pad - 2.)*1.e-1; //divide by 10 to get cm
203
204 //OROC
205 return (3.* padsInRow -6.*pad - 3.)*1.e-1; //divide by 10 to get cm
206}
207
208//______________________________________________________________
0e75e410 209Double_t AliTPCmapper::GetPadYlocalS(Int_t padsector) const{
210 //
211 //:GetPadYlocalS
212 //
bb18c002 213 Int_t row = GetRowFromPadSector(padsector);
214 Int_t pad = GetPadFromPadSector(padsector);
215 return GetPadYlocalS(row,pad);
216}
217
218//______________________________________________________________
0e75e410 219Double_t AliTPCmapper::GetPadXglobalS(Int_t row, Int_t pad,Int_t sector) const{
220 //
221 // GetPadXglobalS
222 //
bb18c002 223 Double_t angle = (Double_t)(( sector * 20. ) +10. ) * TMath::DegToRad();
224 return GetPadXlocalS(row,pad)*TMath::Cos(angle) -
225 GetPadYlocalS(row,pad)*TMath::Sin(angle);
226}
227
228//______________________________________________________________
0e75e410 229Double_t AliTPCmapper::GetPadYglobalS(Int_t row, Int_t pad,Int_t sector) const{
230 //
231 // GetPadYglobalS
232 //
bb18c002 233 Double_t angle = (Double_t)(( sector * 20. ) + 10. ) * TMath::DegToRad();
234 return GetPadXlocalS(row,pad)*TMath::Sin(angle) +
235 GetPadYlocalS(row,pad)*TMath::Cos(angle);
236}
237
238//______________________________________________________________
0e75e410 239Double_t AliTPCmapper::GetPadWidthS(Int_t row) const
bb18c002 240{
0e75e410 241 //
242 // :GetPadWidthS
243 //
bb18c002 244 if (row < 63 ) return .4;
245 return .6;
246}
247
248//______________________________________________________________
0e75e410 249Double_t AliTPCmapper::GetPadLengthS(Int_t row) const
bb18c002 250{
0e75e410 251 //
252 // GetPadLengthS
253 //
254
bb18c002 255 if ( row < 63 ) return .75;
256 if ( row < 127 ) return 1.;
257 return 1.5;
258}
259
260//______________________________________________________________
11c5d692 261Int_t AliTPCmapper::GetAltroAddrwPatch(Int_t row, Int_t pad) const
bb18c002 262{
0e75e410 263 //
264 // :GetAltroAddrwPatch
265 //
bb18c002 266 return GetChannelS(row,pad)+
267 (GetAltroS (row,pad) <<4)+
268 (GetFECs (row,pad) <<7)+
269 (GetBranchS(row,pad) <<11)+
270 (GetRCUs (row,pad) <<12);
271}
272
273//______________________________________________________________
11c5d692 274Int_t AliTPCmapper::GetAltroAddrwPatch(Int_t padsector) const
bb18c002 275{
0e75e410 276 //
277 // GetAltroAddrwPatch
278 //
bb18c002 279 return GetAltroAddrwPatch(GetRowFromPadSector(padsector),GetPadFromPadSector(padsector));
280}
281
282//______________________________________________________________
0e75e410 283Int_t AliTPCmapper::GetRow(Int_t altroaddr) const
bb18c002 284{
0e75e410 285 //
286 // GetRow
287 //
bb18c002 288 Int_t rcu = (altroaddr>>12)&0x07;
289 Int_t bra = (altroaddr>>11)&0x01;
290 Int_t fec = (altroaddr>>7)&0x0F;
291 Int_t alt = (altroaddr>>4)&0x07;
292 Int_t chn = (altroaddr)&0x0F;
293 return GetRow(rcu,bra,fec,alt,chn);
294}
295
296//______________________________________________________________
0e75e410 297Int_t AliTPCmapper::GetPad(Int_t altroaddr) const
bb18c002 298{
0e75e410 299 //
300 // GetPad
301 //
bb18c002 302 Int_t rcu = (altroaddr>>12)&0x07;
303 Int_t bra = (altroaddr>>11)&0x01;
304 Int_t fec = (altroaddr>>7)&0x0F;
305 Int_t alt = (altroaddr>>4)&0x07;
306 Int_t chn = (altroaddr)&0x0F;
307 return GetPad(rcu,bra,fec,alt,chn);
308}
309
310//______________________________________________________________
311void AliTPCmapper::PrintAddressArray(Int_t row, Int_t pad)
312{
0e75e410 313 //
314 // PrintAddressArray
315 //
bb18c002 316 Bool_t a[kNaddrSize];
317
318 Int_t addr = GetAltroAddrwPatch(row,pad);
319 for (Int_t i=0; i<kNaddrSize; i++)
320 a[i] = addr&(Int_t)TMath::Power(2,i);
321
322 fprintf(stderr,"Par|Bro|BC/|Bra| FEC HW | Altro |Altro Chann.| Instruction \n");
323 fprintf(stderr,"ity|adc|AL |nch| Address |Chip Addr| Address | Code \n");
324 fprintf(stderr,"-------------------------------------------------------------------\n");
325 fprintf(stderr," %d | %d | %d | %d | %d %d %d %d | %d %d %d | %d %d %d %d | %d %d %d %d %d\n",
326 a[19],a[18],a[17],a[16],a[15],a[14],a[13],a[12],a[11],
327 a[10],a[9],a[8],a[7],a[6],a[5],a[4],a[3],a[2],a[1],a[0]);
328
329 fprintf(stderr,"-------------------------------------------------------------------\n");
330 fprintf(stderr,"19 |18 |17 |16 |15 14 13 12 |11 10 9 | 8 7 6 5 | 4 3 2 1 0\n\n");
331
332}
333
334//______________________________________________________________
335AliTPCmapper::~AliTPCmapper()
336{
337// delete fAddressArray;
338
339}