]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCmapper.cxx
Digits and raw data updated for commissioning
[u/mrichter/AliRoot.git] / TPC / AliTPCmapper.cxx
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: Christian.Lippmann@cern.ch
19 //  
20 // Class to map detector coordinates (row, pad, sector, ...) to
21 // hardware coordinates (RCU, Branch, FEC, Altro, channel, Equipment ID, ...)
22 //
23 // Note: There are two different ways to number padrows:
24 // 1) for each ROC, like 0 ... 62 for an IROC and 0 ... 95 for an OROC,
25 // 2) for each sector, from 0 ... 158.
26 // If the second numbering is used, it is denoted by the variable name
27 // sectorpadrow in this class.
28 //
29 // Note: There are two different ways to number sectors:
30 // 1) Sectors contain one IROC and one OROC and are counted from 0 to 17 on
31 //    each of the two sides (A=0 and C=1),
32 // 2) ROCs are numbered from 0 to 71 where the ROCs 0 ... 35 are IROCS and
33 //    ROCs 36 ... 71 are OROCs. A ROC is often named "sector" in aliroot,
34 //    which can be very confusing!
35 //-------------------------------------------------------------------------
36
37 //#include <stdio.h>
38 #include <TMath.h>
39 #include <TSystem.h>
40 #include <TString.h>
41
42 #include "AliTPCmapper.h"
43 #include "AliTPCAltroMapping.h"
44 #include "AliTPCROC.h"
45 #include "AliLog.h"
46
47 ClassImp(AliTPCmapper)
48
49 //______________________________________________________________
50 AliTPCmapper::AliTPCmapper() :
51   fNside(0),
52   fNsector(0),
53   fNrcu(0),
54   fNbranch(0),
55   fNaltro(0),
56   fNchannel(0),
57   fNpadrow(0),
58   fNpadrowIROC(0),
59   fNpadrowOROC(0),
60   fROC(NULL)
61 {
62   // Constructor
63   Init();
64 }
65
66 //______________________________________________________________
67 AliTPCmapper::~AliTPCmapper()
68 {
69   // Destructor
70
71   delete fROC;
72
73   for ( Int_t i = 0; i < fNrcu; i++ ) {
74     delete fMapping[i];
75     fMapping[i] = 0;
76   }
77 }
78
79
80 //_____________________________________________________________________________
81 AliTPCmapper::AliTPCmapper(const AliTPCmapper& mapper) :
82   TObject(mapper),
83   fNside(mapper.fNside),
84   fNsector(mapper.fNsector),
85   fNrcu(mapper.fNrcu),
86   fNbranch(mapper.fNbranch),
87   fNaltro(mapper.fNaltro),
88   fNchannel(mapper.fNchannel),
89   fNpadrow(mapper.fNpadrow),
90   fNpadrowIROC(mapper.fNpadrowIROC),
91   fNpadrowOROC(mapper.fNpadrowOROC),
92   fROC(mapper.fROC)
93 {
94   // Copy Constructor
95   for ( Int_t i = 0; i < fNrcu; i++ ) fMapping[i] = mapper.fMapping[i];
96 }
97
98 //_____________________________________________________________________________
99 AliTPCmapper& AliTPCmapper::operator = (const AliTPCmapper& mapper)
100 {
101   // Assignment operator
102
103   if(&mapper == this) return *this;
104   ((TObject *)this)->operator=(mapper);
105
106   for ( Int_t i = 0; i < fNrcu; i++ ) fMapping[i] = mapper.fMapping[i];
107   fROC = mapper.fROC;
108
109   fNside = mapper.fNside;
110   fNsector = mapper.fNsector;
111   fNrcu = mapper.fNrcu;
112   fNbranch = mapper.fNbranch;
113   fNaltro = mapper.fNaltro;
114   fNchannel = mapper.fNchannel;
115   fNpadrow = mapper.fNpadrow;
116   fNpadrowIROC = mapper.fNpadrowIROC;
117   fNpadrowOROC = mapper.fNpadrowOROC;
118
119   return *this;
120 }
121
122 //______________________________________________________________
123 void AliTPCmapper::Init()
124 {
125   // Initialize all
126   fNside = 2;
127   fNsector = 18;
128   fNrcu = 6;
129   fNbranch = 2;
130   fNaltro = 8;
131   fNchannel = 15;
132
133   // Load and read mapping files. AliTPCAltroMapping contains the mapping for
134   // each patch (rcu).
135   TString path = gSystem->Getenv("ALICE_ROOT");
136   path += "/TPC/mapping/Patch";
137   TString path2;
138   for(Int_t i = 0; i < fNrcu; i++) {
139     path2 = path;
140     path2 += i;
141     path2 += ".data";
142     fMapping[i] = new AliTPCAltroMapping(path2.Data());
143   }
144
145   // Create instance of AliTPCROC object
146   fROC = AliTPCROC::Instance();
147
148   fNpadrowIROC = fROC->GetNRows(0);
149   fNpadrowOROC = fROC->GetNRows(36);
150   fNpadrow = fNpadrowIROC+fNpadrowOROC;
151
152 }
153
154
155 //_____________________________________________________________________________
156 Int_t AliTPCmapper::GetHWAddress(Int_t roc, Int_t padrow, Int_t pad) const
157 {
158   // Get the hardware address from pad coordinates for a given ROC
159   Int_t patch = GetPatch(roc, padrow, pad);
160   if ( patch < 0 ) return -1;
161   return fMapping[patch]->GetHWAddress(padrow, pad, roc);
162 }
163
164
165 //_____________________________________________________________________________
166 Int_t AliTPCmapper::GetHWAddressSector(Int_t sectorpadrow, Int_t pad) const
167 {
168   // Get the hardware address from pad coordinates
169   Int_t patch = 0;
170   if ( sectorpadrow < fNpadrowIROC   ) {
171     patch = GetPatch(0,  sectorpadrow, pad);
172     return fMapping[patch]->GetHWAddress(sectorpadrow, pad, 0);
173   } else if ( sectorpadrow < fNpadrow ) {
174     patch = GetPatch(36, sectorpadrow - fNpadrowIROC, pad);
175     return fMapping[patch]->GetHWAddress(sectorpadrow - fNpadrowIROC,
176                                          pad, 36);
177   } else {
178     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
179     return -1;
180   }
181 }
182
183
184 //_____________________________________________________________________________
185 Int_t AliTPCmapper::GetRcu(Int_t roc, Int_t padrow, Int_t pad) const
186 {
187   // Get the patch (rcu) index from the pad coordinates. The Roc index is
188   // needed as well to determine if it is IROC or OROC. 
189   return GetPatch(roc, padrow, pad);
190 }
191
192
193 //_____________________________________________________________________________
194 Int_t AliTPCmapper::GetPatch(Int_t roc, Int_t padrow, Int_t pad) const
195 {
196   // Get the patch (rcu) index from the pad coordinates. The Roc index is
197   // needed as well to determine if it is IROC or OROC. 
198
199   if ( (padrow < 0) || (pad < 0) || (roc < 0) ) {
200     AliWarning(Form("Pad coordinates outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
201     return -1;
202   }
203
204   if ( roc < 36 ) {
205     // IROC (0 ... 35)
206     Int_t padsInRow = GetNpads(padrow);
207     if ( (padsInRow < 0) || (pad >= padsInRow) ) {
208       AliWarning(Form("Pad index outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
209       return -1;
210     }
211     if ( padrow < 30 ) {                  return 0;
212     } else if ( padrow == 30 ) {          // padrow 30 is shared between rcus 0 and 1
213       if ( (pad < 37) || (pad > 48) )     return 1;
214       else                                return 0;
215     } else if ( padrow < fNpadrowIROC ) { return 1;
216     } else {
217       AliWarning(Form("Padrow outside range (padrow %d, roc %d) !", padrow, roc));
218       return -1;
219     }
220   } else if ( roc < 72 ) {
221     // OROC (36 ... 71)
222     Int_t padsInRow = GetNpads(fNpadrowIROC+padrow);
223     if ( (padsInRow < 0) || (pad >= padsInRow) ) {
224       AliWarning(Form("Pad index outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
225       return -1;
226     }
227     if ( padrow < 27 ) {                  return 2;
228     } else if ( padrow == 27 ) {          // padrow 27 is shared between rcus 2 and 3
229       if ( (pad >= 43) && (pad <= 46) )   return 3;
230       else                                return 2;
231     } else if ( padrow < 54 ) {           return 3;
232     } else if ( padrow < 76 ) {           return 4;
233     } else if ( padrow == 76) {           // padrow 76 is shared between rcus 4 and 5
234       if ( (pad >= 33) && (pad <= 88) )   return 5;
235       else                                return 4;
236     } else if ( padrow < fNpadrowOROC ) { return 5;
237     } else {
238       AliWarning(Form("Padrow outside range (padrow %d, roc %d) !", padrow, roc));
239       return -1;
240     }
241   }
242   return -1;
243 }
244
245
246 //_____________________________________________________________________________
247 Int_t AliTPCmapper::GetRcuSector(Int_t sectorpadrow, Int_t pad) const
248 {
249   // Get the patch (rcu) index from the pad coordinates for a sector
250   return GetPatchSector(sectorpadrow, pad);
251 }
252
253
254 //_____________________________________________________________________________
255 Int_t AliTPCmapper::GetPatchSector(Int_t sectorpadrow, Int_t pad) const
256 {
257   // Get the patch (rcu) index from the pad coordinates for a sector
258   if ( sectorpadrow >= fNpadrow ) {
259     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
260     return -1;
261   }
262   if ( sectorpadrow < fNpadrowIROC ) return GetPatch(0,  sectorpadrow, pad);
263   else                               return GetPatch(36, sectorpadrow-fNpadrowIROC, pad);
264 }
265
266
267 //_____________________________________________________________________________
268 Int_t AliTPCmapper::GetPadRow(Int_t patch, Int_t hwAddress) const
269 {
270   // Get Pad Row (for a ROC) from the hardware address
271   return fMapping[patch]->GetPadRow(hwAddress);
272 }
273
274
275 //_____________________________________________________________________________
276   Int_t AliTPCmapper::GetSectorPadRow(Int_t patch, Int_t hwAddress) const
277 {
278   // Get Pad Row (for full sector) from the hardware address
279   if ( patch < 2 ) return GetPadRow(patch, hwAddress);
280   else             return GetPadRow(patch, hwAddress) + fNpadrowIROC;
281 }
282
283
284 //_____________________________________________________________________________
285 Int_t AliTPCmapper::GetPad(Int_t patch, Int_t hwAddress) const
286 {
287   // Get Pad index from the hardware address
288   return fMapping[patch]->GetPad(hwAddress);
289 }
290
291
292 //_____________________________________________________________________________
293 Int_t AliTPCmapper::GetPadRow(Int_t patch, Int_t branch, Int_t fec, Int_t chip,
294                               Int_t channel) const
295 {
296   // Get pad row (for a ROC) from hardware coordinates
297   if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
298        || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
299     AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
300                     patch, branch, fec, chip, channel));
301     return -1;
302   }
303   return GetPadRow(patch, CodeHWAddress(branch, fec, chip, channel));
304 }
305
306
307 //_____________________________________________________________________________
308 Int_t AliTPCmapper::GetSectorPadRow(Int_t patch, Int_t branch, Int_t fec, Int_t chip,
309                                     Int_t channel) const
310 {
311   // Get Pad Row (for full sector) from the hardware address
312   if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
313        || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
314     AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
315                     patch, branch, fec, chip, channel));
316     return -1;
317   }
318   if ( patch < 2 ) return GetPadRow(patch, branch, fec, chip, channel);
319   else             return GetPadRow(patch, branch, fec, chip, channel) + fNpadrowIROC;
320 }
321
322
323 //_____________________________________________________________________________
324   Int_t AliTPCmapper::GetPad(Int_t patch, Int_t branch, Int_t fec, Int_t chip, Int_t channel) const
325 {
326   // Get pad from hardware coordinates
327   if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
328        || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
329     AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
330                     patch, branch, fec, chip, channel));
331     return -1;
332   }
333   return GetPad(patch, CodeHWAddress(branch, fec, chip, channel));
334 }
335
336
337 //_____________________________________________________________________________
338 Int_t AliTPCmapper::GetBranch(Int_t roc, Int_t padrow, Int_t pad) const
339 {
340   // Get the branch to which this pad is connected. The FECs connected to
341   // one RCU are divided into two branches: A(=0) and B(=1). This information
342   // can be extracted from the hardware address.
343   return DecodedHWAddressBranch(GetHWAddress(roc, padrow, pad));
344 }
345
346
347 //_____________________________________________________________________________
348 Int_t AliTPCmapper::GetBranchSector(Int_t sectorpadrow, Int_t pad) const
349 {
350   // Get Branch from pad coordinates, where sectorpadrow is counted
351   // for a full sector (0 ... 158)
352   return DecodedHWAddressBranch(GetHWAddressSector(sectorpadrow, pad));
353 }
354
355
356 //_____________________________________________________________________________
357 Int_t AliTPCmapper::GetFEChw(Int_t roc, Int_t padrow, Int_t pad) const
358 {
359   // Get the FEC number in hardware numbering. The FECs are numbered from 0 (in the
360   // center of the partition) to 8 (partition 3, 4, 5), 9 (partition 0, 2), 11
361   // (partition 1, branch A) or 12 (partition 1, branch B). This information
362   // can be extracted from the hardware address.
363   return DecodedHWAddressFECaddr(GetHWAddress(roc, padrow, pad));
364 }
365
366
367 //_____________________________________________________________________________
368 Int_t AliTPCmapper::GetFEChwSector(Int_t sectorpadrow, Int_t pad) const
369 {
370   // Get the FEC number in hardware numbering from pad coordinates, where 
371   // sectorpadrow is counted for a full sector (0 ... 158)
372   return DecodedHWAddressFECaddr(GetHWAddressSector(sectorpadrow, pad));
373 }
374
375
376 //_____________________________________________________________________________
377 Int_t AliTPCmapper::GetFEC(Int_t roc, Int_t padrow, Int_t pad) const
378 {
379   // Get the FEC number in offline-oriented numbering. The FECs are numbered from 0
380   // 17 (partition 3, 4, 5), 19 (partition 0, 2) or 24 (partition 1).
381   Int_t patch  = GetPatch(roc, padrow, pad);
382   Int_t fec    = DecodedHWAddressFECaddr(GetHWAddress(roc, padrow, pad));
383   Int_t branch = DecodedHWAddressBranch(GetHWAddress(roc, padrow, pad));
384   if ( (fec < 0) || (branch < 0) || (patch < 0) ) return -1;
385   return HwToOffline(patch, branch, fec);
386 }
387
388
389 //_____________________________________________________________________________
390 Int_t AliTPCmapper::GetFECSector(Int_t sectorpadrow, Int_t pad) const
391 {
392   // Get the FEC number in offline-oriented numbering. Sectorpadrow is
393   // counted for a full sector (0 ... 158)
394   Int_t patch  = GetPatchSector(sectorpadrow, pad);
395   Int_t fec    = DecodedHWAddressFECaddr(GetHWAddressSector(sectorpadrow, pad));
396   Int_t branch = DecodedHWAddressBranch(GetHWAddressSector(sectorpadrow, pad));
397   if ( (fec < 0) || (branch < 0) || (patch < 0) ) return -1;
398   return HwToOffline(patch, branch, fec);
399 }
400
401
402 //_____________________________________________________________________________
403 Int_t AliTPCmapper::GetChip(Int_t roc, Int_t padrow, Int_t pad) const
404 {
405   // Get Chip (ALTRO) index (0 ... 7) from pad coordinates
406   return DecodedHWAddressChipaddr(GetHWAddress(roc, padrow, pad));
407 }
408
409
410 //_____________________________________________________________________________
411 Int_t AliTPCmapper::GetChipSector(Int_t sectorpadrow, Int_t pad) const
412 {
413   // Get Chip (ALTRO) index (0 ... 7) from pad coordinates, where 
414   // sectorpadrow is counted for a full sector (0 ... 158)
415   return DecodedHWAddressChipaddr(GetHWAddressSector(sectorpadrow, pad));
416 }
417
418
419 //_____________________________________________________________________________
420 Int_t AliTPCmapper::GetChannel(Int_t roc, Int_t padrow, Int_t pad) const
421 {
422   // Get Channel index (0 ... 15) from pad coordinates
423   return DecodedHWAddressChanneladdr(GetHWAddress(roc, padrow, pad));
424 }
425
426
427 //_____________________________________________________________________________
428 Int_t AliTPCmapper::GetChannelSector(Int_t sectorpadrow, Int_t pad) const
429 {
430   // Get Channel index (0 ... 15) from pad coordinates, where 
431   // sectorpadrow is counted for a full sector (0 ... 158)
432   return DecodedHWAddressChanneladdr(GetHWAddressSector(sectorpadrow, pad));
433 }
434
435
436 //_____________________________________________________________________________
437 Int_t AliTPCmapper::CodeHWAddress(Int_t branch, Int_t fec, Int_t chip, Int_t channel) const
438 {
439   // Get Hardware address from channel, altro, fec and branch coordinates
440   return ((branch&1)<<11) + ((fec&0xf)<<7) + ((chip&0x7)<<4) + (channel&0xf);
441 }
442
443
444 //_____________________________________________________________________________
445 Int_t AliTPCmapper::DecodedHWAddressBranch(Int_t hwAddress) const
446 {
447   // Get branch index (0, 1) from hardware address
448   if ( hwAddress < 0 ) return -1;
449   return ((hwAddress>>11)&1);
450 }
451
452
453 //_____________________________________________________________________________
454 Int_t AliTPCmapper::DecodedHWAddressFECaddr(Int_t hwAddress) const
455 {
456   // Get FEC index (0 ... 12) from hardware address
457   if ( hwAddress < 0 ) return -1;
458   return ((hwAddress>>7)&0xf);
459 }
460
461
462 //_____________________________________________________________________________
463 Int_t AliTPCmapper::DecodedHWAddressChipaddr(Int_t hwAddress) const
464 {
465   // Get ALTRO index (0 ... 7) from hardware address
466   if ( hwAddress < 0 ) return -1;
467   return ((hwAddress>>4)&0x7);
468 }
469
470
471 //_____________________________________________________________________________
472 Int_t AliTPCmapper::DecodedHWAddressChanneladdr(Int_t hwAddress) const
473 {
474   // Get channel index (0 ... 15) from hardware address
475   if ( hwAddress < 0 ) return -1;
476   return ((hwAddress&0xf));
477 }
478
479
480 //______________________________________________________________
481 Int_t AliTPCmapper::GetNpads(Int_t roc, Int_t padrow) const{
482   // Get number of pads in padrow for this ROC.
483   return fROC->GetNPads((UInt_t)roc, (UInt_t)padrow);
484 }
485
486
487 //______________________________________________________________
488 Int_t AliTPCmapper::GetNpads(Int_t sectorpadrow) const{
489   // Get number of pads in padrow, where sectorpadrow is counted for a full sector (0 ... 158)
490
491   if ( sectorpadrow >= fNpadrow ) {
492     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
493     return -1;
494   }
495   if ( sectorpadrow < fNpadrowIROC ) return GetNpads(0,  sectorpadrow);  // IROC
496   else  return GetNpads(36, sectorpadrow - fNpadrowIROC);                // OROC
497
498   return -1;
499 }
500
501
502 //______________________________________________________________
503 Int_t AliTPCmapper::GetNpadrows(Int_t roc) const
504 {
505   // Get number of padrows
506   return fROC->GetNRows(roc);
507 }
508
509
510 //______________________________________________________________
511 /*
512 Double_t AliTPCmapper::GetPadXlocal(Int_t sectorpadrow) const
513 {
514   // Get local x coordinate of pad, where sectorpadrow is counted for a full sector (0 ... 158)
515
516   if ( sectorpadrow >= fNpadrow ) {
517     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
518     return -1.0;
519   }
520
521   //IROC
522   if ( sectorpadrow < fNpadrowIROC )
523     return (852.25 + 7.5*(Double_t)sectorpadrow)/10.; //divide by 10 to get cm
524
525   sectorpadrow -= fNpadrowIROC;
526
527   if ( sectorpadrow < 64 ) //OROC inner part
528     return (10.* sectorpadrow + 1351.)/10.;         //divide by 10 to get cm
529
530   //OROC outer part
531   return (15.*(sectorpadrow - 64) + 1993.5)/10.;    //divide by 10 to get cm
532 }
533 */
534
535 //______________________________________________________________
536 /*
537 Double_t AliTPCmapper::GetPadYlocal(Int_t sectorpadrow, Int_t pad) const
538 {
539   // Get local y coordinate of pad, where sectorpadrow is counted for a full sector (0 ... 158)
540
541   if ( sectorpadrow >= fNpadrow ) {
542     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
543     return -1.0;
544   }
545
546   Int_t padsInRow = GetNpads(sectorpadrow);
547   if ( (padsInRow < 0) || (pad >= padsInRow) ) {
548     AliWarning(Form("Pad index outside range (pad %d) !", pad));
549     return -1.0;
550   }
551
552   //IROC
553   if ( sectorpadrow < fNpadrowIROC )
554     return (2.* padsInRow - 4.*pad - 2.)*1.e-1;  //divide by 10 to get cm
555
556   //OROC
557   return (3.* padsInRow -6.*pad - 3.)*1.e-1;  //divide by 10 to get cm
558 }
559 */
560
561 //______________________________________________________________
562 /*
563 Double_t AliTPCmapper::GetPadXglobal(Int_t sectorpadrow, Int_t pad, Int_t sector) const
564 {
565   // Get global x coordinate of pad, where sectorpadrow is counted for a full sector (0 ... 158)
566
567   if ( sectorpadrow >= fNpadrow ) {
568     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
569     return -1.0;
570   }
571
572   Int_t padsInRow = GetNpads(sectorpadrow);
573   if ( (padsInRow < 0) || (pad >= padsInRow) ) {
574     AliWarning(Form("Pad index outside range (pad %d) !", pad));
575     return -1.0;
576   }
577
578   Double_t angle = (Double_t)(( sector * 20. ) + 10. ) * TMath::DegToRad();
579   return GetPadXlocal(sectorpadrow) * TMath::Cos(angle) -
580     GetPadYlocal(sectorpadrow, pad) * TMath::Sin(angle);
581 }
582 */
583
584 //______________________________________________________________
585 /*
586 Double_t AliTPCmapper::GetPadYglobal(Int_t sectorpadrow, Int_t pad,Int_t sector) const
587 {
588   // Get global y coordinate of pad, where sectorpadrow is counted for a full sector (0 ... 158)
589
590   if ( sectorpadrow >= fNpadrow ) {
591     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
592     return -1.0;
593   }
594
595   Int_t padsInRow = GetNpads(sectorpadrow);
596   if ( (padsInRow < 0) || (pad >= padsInRow) ) {
597     AliWarning(Form("Pad index outside range (pad %d) !", pad));
598     return -1.0;
599   }
600
601   Double_t angle = (Double_t)(( sector * 20. ) + 10. ) * TMath::DegToRad();
602   return GetPadXlocal(sectorpadrow) * TMath::Sin(angle) +
603     GetPadYlocal(sectorpadrow, pad) * TMath::Cos(angle);
604 }
605 */
606
607 //______________________________________________________________
608 /*
609 Double_t AliTPCmapper::GetPadWidth(Int_t sectorpadrow) const
610 {
611   //  Get pad width, where sectorpadrow is counted for a full sector (0 ... 158)
612
613   if ( sectorpadrow >= fNpadrow ) {
614     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
615     return -1.0;
616   }
617
618   if (sectorpadrow < fNpadrowIROC ) // IROC
619     return 0.4;
620   return 0.6;
621 }
622 */
623
624 //______________________________________________________________
625 /*
626 Double_t AliTPCmapper::GetPadLength(Int_t sectorpadrow) const
627 {
628   // Get pad length, where sectorpadrow is counted for a full sector (0 ... 158)
629
630   if ( sectorpadrow >= fNpadrow ) {
631     AliWarning(Form("Padrow outside range (sectorpadrow %d) !", sectorpadrow));
632     return -1.0;
633   }
634
635   if ( sectorpadrow < fNpadrowIROC ) return  0.75;
636   if ( sectorpadrow < 127 )          return 1.0;
637   return 1.5;
638 }
639 */
640
641 //_____________________________________________________________________________
642 Int_t AliTPCmapper::GetNfec(Int_t patch) const
643 {
644   // Get size of readout partition (number of FECs) for this rcu (patch) index (0 ... 5)
645   Int_t retval = 0;
646   switch(patch){
647   case(0):
648     retval = 18;
649     break;
650   case(1):
651     retval = 25;
652     break;
653   case(2):
654     retval = 18;
655     break;
656   case(3):
657     retval = 20;
658     break;
659   case(4):
660     retval = 20;
661     break;
662   case(5):
663     retval = 20;
664     break;
665   };
666   return retval;
667 }
668
669
670 //_____________________________________________________________________________
671 Int_t AliTPCmapper::GetNfec(Int_t patch, Int_t branch) const
672 {
673   // Get size of readout partition (number of FECs) for this branch
674   Int_t retval = 0;
675   switch(patch){
676   case(0):
677     retval = 9;
678     break;
679   case(1):
680     retval = 13;
681     break;
682   case(2):
683     retval = 9;
684     break;
685   case(3):
686     retval = 10;
687     break;
688   case(4):
689     retval = 10;
690     break;
691   case(5):
692     retval = 10;
693     break;
694   };
695   
696   if( (branch == 1) && (patch == 1) ){
697     retval = 12;
698   }
699   return retval;
700 }
701
702
703 //_____________________________________________________________________________
704 Int_t AliTPCmapper::OfflineToHwFec(Int_t patch, Int_t fec) const
705 {
706   // Convert FEC position in offline-like numbering to hardware numbering (fec).
707
708   if ( (patch < 0) || (fec < 0) ) {
709     AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
710     return -1;
711   }
712   if ( (patch > 5) || (fec >= GetNfec(patch)) ) {
713     AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
714     return -1;
715   }
716
717   Int_t fecsInBranchA = GetNfec(patch, 0);
718   if ( fec < fecsInBranchA ) // branch A
719     return (fecsInBranchA - 1 - fec);
720   else                       // branch B
721     return (fec - fecsInBranchA);
722
723   return -1;
724 }
725
726
727 //_____________________________________________________________________________
728 Int_t AliTPCmapper::OfflineToHwBranch(Int_t patch, Int_t fec) const
729 {
730   // Convert fec position in offline-like numbering to hardware numbering (branch).
731
732   if ( (patch < 0) || (fec < 0) ) {
733     AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
734     return -1;
735   }
736   if ( (patch > 5) || (fec >= GetNfec(patch)) ) {
737     AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
738     return -1;
739   }
740   if ( fec < GetNfec(patch, 0) ) return 0; // branch A
741   else                                         return 1; // branch B
742
743   return -1;
744 }
745
746
747 //_____________________________________________________________________________
748 Int_t AliTPCmapper::HwToOffline(Int_t patch, Int_t branch, Int_t fec) const
749 {
750   // Convert hardware FEC position (branch, fec) to the offline-oriented numbering
751
752   if ( (patch < 0) || (fec < 0) || (branch < 0) ) {
753     AliWarning(Form("Patch (%d), branch (%d) or Fec number (%d) outside range !", patch, branch, fec));
754     return -1;
755   }
756   if ( (patch > 5) || (branch > 1) || (fec >= GetNfec(patch, branch)) ) {
757     AliWarning(Form("Patch (%d), branch (%d) or Fec number (%d) outside range !", patch, branch, fec));
758     return -1;
759   }
760   Int_t fecsInBranchA = GetNfec(patch, 0);
761   if ( branch == 0 )  // branch A
762     return (fecsInBranchA - 1 - fec);
763   else                // branch B
764     return (fec + fecsInBranchA);
765
766   return -1;
767 }
768
769
770 //_____________________________________________________________________________
771 Int_t AliTPCmapper::GetEquipmentID(Int_t roc, Int_t padrow, Int_t pad) const
772 {
773   // Get EqID from pad coordinate. The Roc index is
774   // needed as well to determine if it is IROC or OROC. 
775
776   Int_t side = GetSideFromRoc(roc);
777   if ( side < 0 ) return -1;
778   Int_t sector = GetSectorFromRoc(roc);
779   if ( sector < 0 ) return -1;
780   Int_t patch = GetPatch(roc, padrow, pad);
781   if ( patch < 0 ) return -1;
782   return GetEquipmentIDfromPatch(side, sector, patch);
783 }
784
785
786 //_____________________________________________________________________________
787 Int_t AliTPCmapper::GetEquipmentIDsector(Int_t side, Int_t sector, Int_t sectorpadrow, Int_t pad) const
788 {
789   // Get EqID from pad coordinate, where padrow is counted for a full sector (0 ... 158)
790   Int_t patch = GetPatchSector(sectorpadrow, pad);
791   if ( patch < 0 ) return -1;
792   Int_t roc = GetRocFromPatch(side, sector, patch);
793   if ( roc < 0 ) return -1;
794
795   if ( sectorpadrow < fNpadrowIROC )
796     return GetEquipmentID(roc, sectorpadrow, pad);
797   else
798     return GetEquipmentID(roc, sectorpadrow-fNpadrowIROC, pad);
799 }
800
801
802 //_____________________________________________________________________________
803 Int_t AliTPCmapper::GetEquipmentIDfromPatch(Int_t side, Int_t sector, Int_t patch) const
804 {
805   // Get EqID from patch (rcu).
806
807   Int_t roc = GetRocFromPatch(side, sector, patch);
808   Int_t ddl = 0;
809   if (patch < 2)  // IROC
810     ddl = roc*2 + patch;
811   else            // OROC
812     ddl = (roc-36)*4 + 36*2 + (patch-2);
813   // Add offset. TPC has detectorID = 3
814   return (ddl+(3<<8));
815 }
816
817
818 //_____________________________________________________________________________
819 Int_t AliTPCmapper::GetPatchFromEquipmentID(Int_t equipmentID) const
820 {
821   // Get rcu (patch) index (0 ... 5) from equipment ID
822   Int_t retval = 0;
823
824   if ( (equipmentID < (3<<8)) || (equipmentID > 983) ) {
825     AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
826     return -1;
827   }
828   if ( ( (int)equipmentID - 840 ) < 0) retval = (equipmentID-768)%2;
829   else                                 retval = (equipmentID-840)%4 + 2;
830   return retval;
831 }
832
833
834 //_____________________________________________________________________________
835 Int_t AliTPCmapper::GetSideFromEquipmentID(Int_t equipmentID) const
836 {
837   // Get side from Eq ID
838   if ( (equipmentID < (3<<8)) ) {
839     AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
840     return -1;
841   }
842   if      ( equipmentID < 804 ) return 0;
843   else if ( equipmentID < 840 ) return 1;
844   else if ( equipmentID < 912 ) return 0;
845   else if ( equipmentID < 984 ) return 1;
846   else {
847     AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
848     return -1;
849   }
850 }
851
852
853 //_____________________________________________________________________________
854 Int_t AliTPCmapper::GetSectorFromEquipmentID(Int_t equipmentID) const
855 {
856   // Get sector index (0 ... 17) from equipment ID
857   Int_t retval = 0;
858
859   if ( (equipmentID < (3<<8)) || (equipmentID > 983) ) {
860     AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
861     return -1;
862   }
863   if ( (equipmentID - 840) < 0 ) retval = (equipmentID-768)/2;
864   else                           retval = (equipmentID-840)/4;
865   return retval;
866 }
867
868
869 //_____________________________________________________________________________
870 Int_t AliTPCmapper::GetRocFromEquipmentID(Int_t equipmentID) const
871 {
872   // Get ROC index (0 ... 71) from equipment ID
873   Int_t side   = GetSideFromEquipmentID(equipmentID);
874   if ( side < 0 ) return -1;
875   Int_t sector = GetSectorFromEquipmentID(equipmentID);
876   if ( sector < 0 ) return -1;
877   Int_t patch  = GetPatchFromEquipmentID(equipmentID);
878   if ( patch < 0 ) return -1;
879
880   return GetRocFromPatch(side, sector, patch);
881 }
882
883
884 //_____________________________________________________________________________
885 Int_t AliTPCmapper::GetSectorFromRoc(Int_t roc) const
886 {
887   // get the sector number (0 ... 17) from the roc number (0 ... 71)
888
889   if ( roc < 0 ) {
890     AliWarning(Form("Roc outside range (roc %d) !", roc));
891     return -1;
892   } else if ( roc < 18 ) {   // inner sector, A side
893     return roc;
894   } else if ( roc < 36 ) {   // inner sector, C side
895     return (roc-18);
896   } else if ( roc < 54 ) {   // outer sector, A side
897     return (roc-36);
898   } else if ( roc < 72 ) {   // outer sector, C side
899     return (roc-54);
900   } else {
901     AliWarning(Form("Roc outside range (roc %d) !", roc));
902     return -1;
903   }
904 }
905
906
907 //_____________________________________________________________________________
908 Int_t AliTPCmapper::GetSideFromRoc(Int_t roc) const
909 {
910   // get the side (0, 1) from the roc number (0 ... 71)
911
912   if ( roc < 0 ) {
913     AliWarning(Form("Roc outside range (roc %d) !", roc));
914     return -1;
915   } else if ( roc < 18 ) {   // inner sector, A side
916     return 0;
917   } else if ( roc < 36 ) {   // inner sector, C side
918     return 1;
919   } else if ( roc < 54 ) {   // outer sector, A side
920     return 0;
921   } else if ( roc < 72 ) {   // outer sector, C side
922     return 1;
923   } else { 
924     AliWarning(Form("Roc outside range (roc %d) !", roc));
925     return -1;
926   } 
927 }
928
929
930 //_____________________________________________________________________________
931 Int_t AliTPCmapper::GetRocFromPatch(Int_t side, Int_t sector, Int_t patch) const
932 {
933   // Get Roc (0 ... 71) from side (0, 1), sector (0 ... 17) and patch (0 ... 5)
934
935   if ( (side < 0) || (side >= fNside) ) {
936     AliWarning(Form("Side outside range (side %d) !", side));
937     return -1;
938   }
939   if ( (sector < 0) || (sector >= fNsector) ) {
940     AliWarning(Form("Sector outside range (sector %d) !", sector));
941     return -1;
942   }
943   if ( (patch < 0) || (patch >= fNrcu) ) {
944     AliWarning(Form("Patch (rcu) outside range (patch %d) !", patch));
945     return -1;
946   }
947
948   if ( side == 0 ) { // A side
949     if ( patch < 2 ) return sector;         // IROC
950     else             return 36+sector;      // OROC
951   } else {           // C side
952     if ( patch < 2 ) return 18+(17-sector); // IROC
953     else             return 54+(17-sector); // OROC
954   }
955 }
956
957
958 //_____________________________________________________________________________
959 Int_t AliTPCmapper::GetRoc(Int_t side, Int_t sector, Int_t sectorpadrow, Int_t pad) const
960 {
961   // Get Roc (0 ... 71) from side (0, 1), sector (0 ... 17) and pad coordinates
962
963   Int_t patch = GetPatchSector(sectorpadrow, pad);
964   if ( patch < 0 ) return -1;
965   return GetRocFromPatch(side, sector, patch);
966 }
967
968
969 //_____________________________________________________________________________
970   Bool_t AliTPCmapper::IsIROC(Int_t roc) const
971 {
972   // Is this ROC an IROC?
973   if ( roc < 0 ) {
974     AliWarning(Form("Roc outside range (roc %d) !", roc));
975     return -1;
976   } else if ( roc < 36 ) {   // inner sector
977     return true;
978   } else if ( roc < 72 ) {   // outer sector, C side
979     return false;
980   } else {
981     AliWarning(Form("Roc outside range (roc %d) !", roc));
982     return -1;
983   }
984 }
985
986
987 //_____________________________________________________________________________
988   Bool_t AliTPCmapper::IsOROC(Int_t roc) const
989 {
990   // Is this ROC an OROC?
991   if ( roc < 0 ) {
992     AliWarning(Form("Roc outside range (roc %d) !", roc));
993     return -1;
994   } else if ( roc < 36 ) {   // inner sector
995     return false;
996   } else if ( roc < 72 ) {   // outer sector, C side
997     return true;
998   } else {
999     AliWarning(Form("Roc outside range (roc %d) !", roc));
1000     return -1;
1001   }
1002 }
1003
1004 // EOF