1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-------------------------------------------------------------------------
19 // Authors: Christian.Lippmann@cern.ch, J.Wiechula@gsi.de
20 // Class to map detector coordinates (row, pad, sector, ...) to
21 // hardware coordinates (RCU, Branch, FEC, Altro, channel, Equipment ID, ...)
23 // There are two different ways to number padrows:
24 // 1) local padrow: for each ROC, 0 ... 62 for an IROC, 0 ... 95 for an OROC,
25 // 2) global padrow: for each sector, from 0 ... 158.
26 // If the global numbering is used, it is denoted by the variable name
27 // globalpadrow in this class.
29 // 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!
36 //-------------------------------------------------------------------------
42 #include "AliTPCmapper.h"
43 #include "AliTPCAltroMapping.h"
44 #include "AliTPCROC.h"
48 ClassImp(AliTPCmapper)
49 //______________________________________________________________
50 AliTPCmapper::AliTPCmapper() :
65 for ( Int_t i = 0; i < 6; i++ ) fMapping[i]=0;
68 //______________________________________________________________
69 AliTPCmapper::AliTPCmapper(const char * dirname) :
84 // dirname - specify the directory with the ascii Altro mapping files
89 //______________________________________________________________
90 AliTPCmapper::~AliTPCmapper()
94 for ( Int_t i = 0; i < fNrcu; i++ ) {
101 //_____________________________________________________________________________
102 AliTPCmapper::AliTPCmapper(const AliTPCmapper& mapper) :
104 fNside(mapper.fNside),
105 fNsector(mapper.fNsector),
107 fNbranch(mapper.fNbranch),
108 fNaltro(mapper.fNaltro),
109 fNchannel(mapper.fNchannel),
110 fNpadrow(mapper.fNpadrow),
111 fNpadrowIROC(mapper.fNpadrowIROC),
112 fNpadrowOROC(mapper.fNpadrowOROC),
113 fTpcDdlOffset(mapper.fTpcDdlOffset)
116 for ( Int_t i = 0; i < 6; i++ ) fMapping[i]=0;
117 for ( Int_t i = 0; i < fNrcu; i++ ) fMapping[i] = mapper.fMapping[i];
120 //_____________________________________________________________________________
121 AliTPCmapper& AliTPCmapper::operator = (const AliTPCmapper& mapper)
123 // Assignment operator
125 if(&mapper == this) return *this;
126 ((TObject *)this)->operator=(mapper);
128 for ( Int_t i = 0; i < fNrcu; i++ ) fMapping[i] = mapper.fMapping[i];
130 fNside = mapper.fNside;
131 fNsector = mapper.fNsector;
132 fNrcu = mapper.fNrcu;
133 fNbranch = mapper.fNbranch;
134 fNaltro = mapper.fNaltro;
135 fNchannel = mapper.fNchannel;
136 fNpadrow = mapper.fNpadrow;
137 fNpadrowIROC = mapper.fNpadrowIROC;
138 fNpadrowOROC = mapper.fNpadrowOROC;
139 fTpcDdlOffset = mapper.fTpcDdlOffset;
144 //______________________________________________________________
145 void AliTPCmapper::Init(const char *dirname)
155 // Load and read mapping files. AliTPCAltroMapping contains the mapping for
159 path =gSystem->Getenv("ALICE_ROOT");
160 path += "/TPC/mapping/Patch";
167 for(Int_t i = 0; i < fNrcu; i++) {
171 fMapping[i] = new AliTPCAltroMapping(path2.Data());
174 // Get instance of AliTPCROC object
175 AliTPCROC *fROC = AliTPCROC::Instance();
176 fNpadrowIROC = fROC->GetNRows(0);
177 fNpadrowOROC = fROC->GetNRows(36);
178 fNpadrow = fNpadrowIROC+fNpadrowOROC;
181 fTpcDdlOffset = daq.DdlIDOffset("TPC");
186 //_____________________________________________________________________________
187 Int_t AliTPCmapper::GetHWAddress(Int_t roc, Int_t padrow, Int_t pad) const
189 // Get the hardware address from pad coordinates for a given ROC
190 Int_t patch = GetPatch(roc, padrow, pad);
191 if ( (patch >= fNrcu) || (patch < 0) ) return -1;
192 return fMapping[patch]->GetHWAddress(padrow, pad, roc);
196 //_____________________________________________________________________________
197 Int_t AliTPCmapper::GetHWAddressSector(Int_t globalpadrow, Int_t pad) const
199 // Get the hardware address from pad coordinates
202 if ( globalpadrow < fNpadrowIROC ) {
203 patch = GetPatch(0, globalpadrow, pad);
205 hwAddress = fMapping[patch]->GetHWAddress(globalpadrow, pad, 0);
206 } else if ( globalpadrow < fNpadrow ) {
207 patch = GetPatch(36, globalpadrow - fNpadrowIROC, pad);
209 hwAddress = fMapping[patch]->GetHWAddress(globalpadrow - fNpadrowIROC, pad, 36);
211 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
218 //_____________________________________________________________________________
219 Int_t AliTPCmapper::GetRcu(Int_t roc, Int_t padrow, Int_t pad) const
221 // Get the patch (rcu) index from the pad coordinates. The Roc index is
222 // needed as well to determine if it is IROC or OROC.
223 return GetPatch(roc, padrow, pad);
227 //_____________________________________________________________________________
228 Int_t AliTPCmapper::GetPatch(Int_t roc, Int_t padrow, Int_t pad) const
230 // Get the patch (rcu) index from the pad coordinates. The Roc index is
231 // needed as well to determine if it is IROC or OROC.
233 if ( (padrow < 0) || (pad < 0) || (roc < 0) ) {
234 AliWarning(Form("Pad coordinates outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
239 // IROC (ROCs 0 ... 35)
240 Int_t padsInRow = GetNpads(padrow);
241 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
242 AliWarning(Form("Pad index outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
245 if ( padrow < 30 ) { return 0;
246 } else if ( padrow == 30 ) { // padrow 30 is shared between rcus 0 and 1
247 if ( (pad < 37) || (pad > 48) ) return 1;
249 } else if ( padrow < fNpadrowIROC ) { return 1;
251 AliWarning(Form("Padrow outside range (padrow %d, roc %d) !", padrow, roc));
254 } else if ( roc < 72 ) {
255 // OROC (ROCs 36 ... 71)
256 Int_t padsInRow = GetNpads(fNpadrowIROC+padrow);
257 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
258 AliWarning(Form("Pad index outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
261 if ( padrow < 27 ) { return 2;
262 } else if ( padrow == 27 ) { // padrow 27 is shared between rcus 2 and 3
263 if ( (pad >= 43) && (pad <= 46) ) return 3;
265 } else if ( padrow < 54 ) { return 3;
266 } else if ( padrow < 76 ) { return 4;
267 } else if ( padrow == 76) { // padrow 76 is shared between rcus 4 and 5
268 if ( (pad >= 33) && (pad <= 88) ) return 5;
270 } else if ( padrow < fNpadrowOROC ) { return 5;
272 AliWarning(Form("Padrow outside range (padrow %d, roc %d) !", padrow, roc));
280 //_____________________________________________________________________________
281 Int_t AliTPCmapper::GetRcuSector(Int_t globalpadrow, Int_t pad) const
283 // Get the patch (rcu) index from the pad coordinates for a sector
284 return GetPatchSector(globalpadrow, pad);
288 //_____________________________________________________________________________
289 Int_t AliTPCmapper::GetPatchSector(Int_t globalpadrow, Int_t pad) const
291 // Get the patch (rcu) index from the pad coordinates for a sector
292 if ( globalpadrow >= fNpadrow ) {
293 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
296 if ( globalpadrow < fNpadrowIROC ) return GetPatch(0, globalpadrow, pad);
297 else return GetPatch(36, globalpadrow-fNpadrowIROC, pad);
301 //_____________________________________________________________________________
302 Int_t AliTPCmapper::GetPadRow(Int_t patch, Int_t hwAddress) const
304 // Get Pad Row (for a ROC) from the hardware address
305 if ( (patch >= fNrcu) || (patch < 0) ) {
306 AliWarning(Form("Patch index outside range (patch %d) !", patch));
309 return fMapping[patch]->GetPadRow(hwAddress);
313 //_____________________________________________________________________________
314 Int_t AliTPCmapper::GetGlobalPadRow(Int_t patch, Int_t hwAddress) const
316 // Get Pad Row (for full sector) from the hardware address
317 if ( patch < 2 ) return GetPadRow(patch, hwAddress);
318 else return GetPadRow(patch, hwAddress) + fNpadrowIROC;
322 //_____________________________________________________________________________
323 Int_t AliTPCmapper::GetPad(Int_t patch, Int_t hwAddress) const
325 // Get Pad index from the hardware address
326 if ( (patch >= fNrcu) || (patch < 0) ) {
327 AliWarning(Form("Patch index outside range (patch %d) !", patch));
330 return fMapping[patch]->GetPad(hwAddress);
334 //_____________________________________________________________________________
335 Int_t AliTPCmapper::GetPadRow(Int_t patch, Int_t branch, Int_t fec, Int_t chip,
338 // Get pad row (for a ROC) from hardware coordinates
339 if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
340 || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
341 AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
342 patch, branch, fec, chip, channel));
345 return GetPadRow(patch, CodeHWAddress(branch, fec, chip, channel));
349 //_____________________________________________________________________________
350 Int_t AliTPCmapper::GetGlobalPadRow(Int_t patch, Int_t branch, Int_t fec, Int_t chip,
353 // Get Pad Row (for full sector) from the hardware address
354 if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
355 || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
356 AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
357 patch, branch, fec, chip, channel));
360 if ( patch < 2 ) return GetPadRow(patch, branch, fec, chip, channel);
361 else return GetPadRow(patch, branch, fec, chip, channel) + fNpadrowIROC;
365 //_____________________________________________________________________________
366 Int_t AliTPCmapper::GetPad(Int_t patch, Int_t branch, Int_t fec, Int_t chip, Int_t channel) const
368 // Get pad from hardware coordinates
369 if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
370 || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
371 AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
372 patch, branch, fec, chip, channel));
375 return GetPad(patch, CodeHWAddress(branch, fec, chip, channel));
379 //_____________________________________________________________________________
380 Int_t AliTPCmapper::GetBranch(Int_t roc, Int_t padrow, Int_t pad) const
382 // Get the branch to which this pad is connected. The FECs connected to
383 // one RCU are divided into two branches: A(=0) and B(=1). This information
384 // can be extracted from the hardware address.
385 return DecodedHWAddressBranch(GetHWAddress(roc, padrow, pad));
389 //_____________________________________________________________________________
390 Int_t AliTPCmapper::GetBranchSector(Int_t globalpadrow, Int_t pad) const
392 // Get Branch from pad coordinates, where globalpadrow is counted
393 // for a full sector (0 ... 158)
394 return DecodedHWAddressBranch(GetHWAddressSector(globalpadrow, pad));
398 //_____________________________________________________________________________
399 Int_t AliTPCmapper::GetFEChw(Int_t roc, Int_t padrow, Int_t pad) const
401 // Get the FEC number in hardware numbering. The FECs are numbered from 0 (in the
402 // center of the partition) to 8 (partition 3, 4, 5), 9 (partition 0, 2), 11
403 // (partition 1, branch A) or 12 (partition 1, branch B). This information
404 // can be extracted from the hardware address.
405 return DecodedHWAddressFECaddr(GetHWAddress(roc, padrow, pad));
409 //_____________________________________________________________________________
410 Int_t AliTPCmapper::GetFEChwSector(Int_t globalpadrow, Int_t pad) const
412 // Get the FEC number in hardware numbering from pad coordinates, where
413 // globalpadrow is counted for a full sector (0 ... 158)
414 return DecodedHWAddressFECaddr(GetHWAddressSector(globalpadrow, pad));
418 //_____________________________________________________________________________
419 Int_t AliTPCmapper::GetFEC(Int_t roc, Int_t padrow, Int_t pad) const
421 // Get the FEC number in offline-oriented numbering. The FECs are numbered from 0
422 // 17 (partition 3, 4, 5), 19 (partition 0, 2) or 24 (partition 1).
423 Int_t patch = GetPatch(roc, padrow, pad);
424 Int_t fec = DecodedHWAddressFECaddr(GetHWAddress(roc, padrow, pad));
425 Int_t branch = DecodedHWAddressBranch(GetHWAddress(roc, padrow, pad));
426 if ( (fec < 0) || (branch < 0) || (patch < 0) ) return -1;
427 return HwToOffline(patch, branch, fec);
431 //_____________________________________________________________________________
432 Int_t AliTPCmapper::GetFECSector(Int_t globalpadrow, Int_t pad) const
434 // Get the FEC number in offline-oriented numbering. globalpadrow is
435 // counted for a full sector (0 ... 158)
436 Int_t patch = GetPatchSector(globalpadrow, pad);
437 Int_t fec = DecodedHWAddressFECaddr(GetHWAddressSector(globalpadrow, pad));
438 Int_t branch = DecodedHWAddressBranch(GetHWAddressSector(globalpadrow, pad));
439 if ( (fec < 0) || (branch < 0) || (patch < 0) ) return -1;
440 return HwToOffline(patch, branch, fec);
444 //_____________________________________________________________________________
445 Int_t AliTPCmapper::GetChip(Int_t roc, Int_t padrow, Int_t pad) const
447 // Get Chip (ALTRO) index (0 ... 7) from pad coordinates
448 return DecodedHWAddressChipaddr(GetHWAddress(roc, padrow, pad));
452 //_____________________________________________________________________________
453 Int_t AliTPCmapper::GetChipSector(Int_t globalpadrow, Int_t pad) const
455 // Get Chip (ALTRO) index (0 ... 7) from pad coordinates, where
456 // globalpadrow is counted for a full sector (0 ... 158)
457 return DecodedHWAddressChipaddr(GetHWAddressSector(globalpadrow, pad));
461 //_____________________________________________________________________________
462 Int_t AliTPCmapper::GetChannel(Int_t roc, Int_t padrow, Int_t pad) const
464 // Get Channel index (0 ... 15) from pad coordinates
465 return DecodedHWAddressChanneladdr(GetHWAddress(roc, padrow, pad));
469 //_____________________________________________________________________________
470 Int_t AliTPCmapper::GetChannelSector(Int_t globalpadrow, Int_t pad) const
472 // Get Channel index (0 ... 15) from pad coordinates, where
473 // globalpadrow is counted for a full sector (0 ... 158)
474 return DecodedHWAddressChanneladdr(GetHWAddressSector(globalpadrow, pad));
478 //_____________________________________________________________________________
479 Int_t AliTPCmapper::CodeHWAddress(Int_t branch, Int_t fec, Int_t chip, Int_t channel) const
481 // Get Hardware address from channel, altro, fec and branch coordinates
482 return ((branch&1)<<11) + ((fec&0xf)<<7) + ((chip&0x7)<<4) + (channel&0xf);
486 //_____________________________________________________________________________
487 Int_t AliTPCmapper::DecodedHWAddressBranch(Int_t hwAddress) const
489 // Get branch index (0, 1) from hardware address
490 if ( hwAddress < 0 ) return -1;
491 return ((hwAddress>>11)&1);
495 //_____________________________________________________________________________
496 Int_t AliTPCmapper::DecodedHWAddressFECaddr(Int_t hwAddress) const
498 // Get FEC index (0 ... 12) from hardware address
499 if ( hwAddress < 0 ) return -1;
500 return ((hwAddress>>7)&0xf);
504 //_____________________________________________________________________________
505 Int_t AliTPCmapper::DecodedHWAddressChipaddr(Int_t hwAddress) const
507 // Get ALTRO index (0 ... 7) from hardware address
508 if ( hwAddress < 0 ) return -1;
509 return ((hwAddress>>4)&0x7);
513 //_____________________________________________________________________________
514 Int_t AliTPCmapper::DecodedHWAddressChanneladdr(Int_t hwAddress) const
516 // Get channel index (0 ... 15) from hardware address
517 if ( hwAddress < 0 ) return -1;
518 return ((hwAddress&0xf));
522 //______________________________________________________________
523 Int_t AliTPCmapper::GetNpads(Int_t roc, Int_t padrow) const{
524 // Get number of pads in padrow for this ROC.
525 AliTPCROC *fROC = AliTPCROC::Instance();
526 Int_t retval = fROC->GetNPads((UInt_t)roc, (UInt_t)padrow);
531 //______________________________________________________________
532 Int_t AliTPCmapper::GetNpads(Int_t globalpadrow) const{
533 // Get number of pads in padrow, where globalpadrow is counted for a full sector (0 ... 158)
535 if ( globalpadrow >= fNpadrow ) {
536 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
539 if ( globalpadrow < fNpadrowIROC ) return GetNpads(0, globalpadrow); // IROC
540 else return GetNpads(36, globalpadrow - fNpadrowIROC); // OROC
546 //______________________________________________________________
547 Int_t AliTPCmapper::GetNpadrows(Int_t roc) const
549 // Get number of padrows
550 if (roc < 36) return fNpadrowIROC;
551 else if (roc < 72) return fNpadrowOROC;
556 //______________________________________________________________
558 Double_t AliTPCmapper::GetPadXlocal(Int_t globalpadrow) const
560 // Get local x coordinate of pad, where globalpadrow is counted for a full sector (0 ... 158)
562 if ( globalpadrow >= fNpadrow ) {
563 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
568 if ( globalpadrow < fNpadrowIROC )
569 return (852.25 + 7.5*(Double_t)globalpadrow)/10.; //divide by 10 to get cm
571 globalpadrow -= fNpadrowIROC;
573 if ( globalpadrow < 64 ) //OROC inner part
574 return (10.* globalpadrow + 1351.)/10.; //divide by 10 to get cm
577 return (15.*(globalpadrow - 64) + 1993.5)/10.; //divide by 10 to get cm
581 //______________________________________________________________
583 Double_t AliTPCmapper::GetPadYlocal(Int_t globalpadrow, Int_t pad) const
585 // Get local y coordinate of pad, where globalpadrow is counted for a full sector (0 ... 158)
587 if ( globalpadrow >= fNpadrow ) {
588 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
592 Int_t padsInRow = GetNpads(globalpadrow);
593 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
594 AliWarning(Form("Pad index outside range (pad %d) !", pad));
599 if ( globalpadrow < fNpadrowIROC )
600 return (2.* padsInRow - 4.*pad - 2.)*1.e-1; //divide by 10 to get cm
603 return (3.* padsInRow -6.*pad - 3.)*1.e-1; //divide by 10 to get cm
607 //______________________________________________________________
609 Double_t AliTPCmapper::GetPadXglobal(Int_t globalpadrow, Int_t pad, Int_t sector) const
611 // Get global x coordinate of pad, where globalpadrow is counted for a full sector (0 ... 158)
613 if ( globalpadrow >= fNpadrow ) {
614 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
618 Int_t padsInRow = GetNpads(globalpadrow);
619 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
620 AliWarning(Form("Pad index outside range (pad %d) !", pad));
624 Double_t angle = (Double_t)(( sector * 20. ) + 10. ) * TMath::DegToRad();
625 return GetPadXlocal(globalpadrow) * TMath::Cos(angle) -
626 GetPadYlocal(globalpadrow, pad) * TMath::Sin(angle);
630 //______________________________________________________________
632 Double_t AliTPCmapper::GetPadYglobal(Int_t globalpadrow, Int_t pad,Int_t sector) const
634 // Get global y coordinate of pad, where globalpadrow is counted for a full sector (0 ... 158)
636 if ( globalpadrow >= fNpadrow ) {
637 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
641 Int_t padsInRow = GetNpads(globalpadrow);
642 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
643 AliWarning(Form("Pad index outside range (pad %d) !", pad));
647 Double_t angle = (Double_t)(( sector * 20. ) + 10. ) * TMath::DegToRad();
648 return GetPadXlocal(globalpadrow) * TMath::Sin(angle) +
649 GetPadYlocal(globalpadrow, pad) * TMath::Cos(angle);
653 //______________________________________________________________
655 Double_t AliTPCmapper::GetPadWidth(Int_t globalpadrow) const
657 // Get pad width, where globalpadrow is counted for a full sector (0 ... 158)
659 if ( globalpadrow >= fNpadrow ) {
660 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
664 if (globalpadrow < fNpadrowIROC ) // IROC
670 //______________________________________________________________
672 Double_t AliTPCmapper::GetPadLength(Int_t globalpadrow) const
674 // Get pad length, where globalpadrow is counted for a full sector (0 ... 158)
676 if ( globalpadrow >= fNpadrow ) {
677 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
681 if ( globalpadrow < fNpadrowIROC ) return 0.75;
682 if ( globalpadrow < 127 ) return 1.0;
687 //_____________________________________________________________________________
688 Int_t AliTPCmapper::GetNfec(Int_t patch) const
690 // Get size of readout partition (number of FECs) for this rcu (patch) index (0 ... 5)
716 //_____________________________________________________________________________
717 Int_t AliTPCmapper::GetNfec(Int_t patch, Int_t branch) const
719 // Get size of readout partition (number of FECs) for this branch
742 if( (branch == 1) && (patch == 1) ){
750 //_____________________________________________________________________________
751 Int_t AliTPCmapper::OfflineToHwFec(Int_t patch, Int_t fec) const
753 // Convert FEC position in offline-like numbering to hardware numbering (fec).
755 if ( (patch < 0) || (fec < 0) ) {
756 AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
759 if ( (patch > 5) || (fec >= GetNfec(patch)) ) {
760 AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
764 Int_t fecsInBranchA = GetNfec(patch, 0);
765 if ( fec < fecsInBranchA ) // branch A
766 return (fecsInBranchA - 1 - fec);
768 return (fec - fecsInBranchA);
774 //_____________________________________________________________________________
775 Int_t AliTPCmapper::OfflineToHwBranch(Int_t patch, Int_t fec) const
777 // Convert fec position in offline-like numbering to hardware numbering (branch).
779 if ( (patch < 0) || (fec < 0) ) {
780 AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
783 if ( (patch > 5) || (fec >= GetNfec(patch)) ) {
784 AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
787 if ( fec < GetNfec(patch, 0) ) return 0; // branch A
788 else return 1; // branch B
794 //_____________________________________________________________________________
795 Int_t AliTPCmapper::HwToOffline(Int_t patch, Int_t branch, Int_t fec) const
797 // Convert hardware FEC position (branch, fec) to the offline-oriented numbering
799 if ( (patch < 0) || (fec < 0) || (branch < 0) ) {
800 AliWarning(Form("Patch (%d), branch (%d) or Fec number (%d) outside range !", patch, branch, fec));
803 if ( (patch > 5) || (branch > 1) || (fec >= GetNfec(patch, branch)) ) {
804 AliWarning(Form("Patch (%d), branch (%d) or Fec number (%d) outside range !", patch, branch, fec));
807 Int_t fecsInBranchA = GetNfec(patch, 0);
808 if ( branch == 0 ) // branch A
809 return (fecsInBranchA - 1 - fec);
811 return (fec + fecsInBranchA);
817 //_____________________________________________________________________________
818 Int_t AliTPCmapper::GetEquipmentID(Int_t roc, Int_t padrow, Int_t pad) const
820 // Get EqID from pad coordinate. The Roc index is
821 // needed as well to determine if it is IROC or OROC.
823 Int_t side = GetSideFromRoc(roc);
824 if ( side < 0 ) return -1;
825 Int_t sector = GetSectorFromRoc(roc);
826 if ( sector < 0 ) return -1;
827 Int_t patch = GetPatch(roc, padrow, pad);
828 if ( patch < 0 ) return -1;
829 return GetEquipmentIDfromPatch(side, sector, patch);
833 //_____________________________________________________________________________
834 Int_t AliTPCmapper::GetEquipmentIDsector(Int_t side, Int_t sector, Int_t globalpadrow, Int_t pad) const
836 // Get EqID from pad coordinate, where padrow is counted for a full sector (0 ... 158)
837 Int_t patch = GetPatchSector(globalpadrow, pad);
838 if ( patch < 0 ) return -1;
839 Int_t roc = GetRocFromPatch(side, sector, patch);
840 if ( roc < 0 ) return -1;
842 if ( globalpadrow < fNpadrowIROC )
843 return GetEquipmentID(roc, globalpadrow, pad);
845 return GetEquipmentID(roc, globalpadrow-fNpadrowIROC, pad);
849 //_____________________________________________________________________________
850 Int_t AliTPCmapper::GetEquipmentIDfromPatch(Int_t side, Int_t sector, Int_t patch) const
852 // Get EqID from patch (rcu).
854 Int_t roc = GetRocFromPatch(side, sector, patch);
856 if (patch < 2) // IROC
859 ddl = (roc-36)*4 + 36*2 + (patch-2);
860 // Add offset. TPC has detectorID = 3
861 return ddl+fTpcDdlOffset;
865 //_____________________________________________________________________________
866 Int_t AliTPCmapper::GetPatchFromEquipmentID(Int_t equipmentID) const
868 // Get rcu (patch) index (0 ... 5) from equipment ID
871 if ( (equipmentID < fTpcDdlOffset) || (equipmentID > 983) ) {
872 AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
875 if ( ( (int)equipmentID - 840 ) < 0) retval = (equipmentID-768)%2;
876 else retval = (equipmentID-840)%4 + 2;
881 //_____________________________________________________________________________
882 Int_t AliTPCmapper::GetSideFromEquipmentID(Int_t equipmentID) const
884 // Get side from Eq ID
885 if ( equipmentID < fTpcDdlOffset ) {
886 AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
889 if ( equipmentID < 804 ) return 0;
890 else if ( equipmentID < 840 ) return 1;
891 else if ( equipmentID < 912 ) return 0;
892 else if ( equipmentID < 984 ) return 1;
894 AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
900 //_____________________________________________________________________________
901 Int_t AliTPCmapper::GetSectorFromEquipmentID(Int_t equipmentID) const
903 // Get sector index (0 ... 17) from equipment ID
905 if ( (equipmentID < fTpcDdlOffset) || (equipmentID >= fTpcDdlOffset+216) ) {
906 AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
909 Int_t side = GetSideFromEquipmentID(equipmentID);
910 if ( side < 0 ) return -1;
912 if ( (equipmentID - 840) < 0 ) { // IROC
913 if ( side == 0 ) retval = (equipmentID-fTpcDdlOffset)/2;
914 else retval = (equipmentID-fTpcDdlOffset-18*2)/2;
916 if ( side == 0 ) retval = (equipmentID-840)/4;
917 else retval = (equipmentID-840-18*4)/4;
923 //_____________________________________________________________________________
924 Int_t AliTPCmapper::GetRocFromEquipmentID(Int_t equipmentID) const
926 // Get ROC index (0 ... 71) from equipment ID
927 Int_t side = GetSideFromEquipmentID(equipmentID);
928 if ( side < 0 ) return -1;
929 Int_t sector = GetSectorFromEquipmentID(equipmentID);
930 if ( sector < 0 ) return -1;
931 Int_t patch = GetPatchFromEquipmentID(equipmentID);
932 if ( patch < 0 ) return -1;
934 return GetRocFromPatch(side, sector, patch);
938 //_____________________________________________________________________________
939 Int_t AliTPCmapper::GetSectorFromRoc(Int_t roc) const
941 // get the sector number (0 ... 17) from the roc number (0 ... 71)
944 AliWarning(Form("Roc outside range (roc %d) !", roc));
946 } else if ( roc < 18 ) { // inner sector, A side
948 } else if ( roc < 36 ) { // inner sector, C side
950 } else if ( roc < 54 ) { // outer sector, A side
952 } else if ( roc < 72 ) { // outer sector, C side
955 AliWarning(Form("Roc outside range (roc %d) !", roc));
961 //_____________________________________________________________________________
962 Int_t AliTPCmapper::GetSideFromRoc(Int_t roc) const
964 // get the side (0, 1) from the roc number (0 ... 71)
967 AliWarning(Form("Roc outside range (roc %d) !", roc));
969 } else if ( roc < 18 ) { // inner sector, A side
971 } else if ( roc < 36 ) { // inner sector, C side
973 } else if ( roc < 54 ) { // outer sector, A side
975 } else if ( roc < 72 ) { // outer sector, C side
978 AliWarning(Form("Roc outside range (roc %d) !", roc));
984 //_____________________________________________________________________________
985 Int_t AliTPCmapper::GetRocFromPatch(Int_t side, Int_t sector, Int_t patch) const
987 // Get Roc (0 ... 71) from side (0, 1), sector (0 ... 17) and patch (0 ... 5)
989 if ( (side < 0) || (side >= fNside) ) {
990 AliWarning(Form("Side outside range (side %d) !", side));
993 if ( (sector < 0) || (sector >= fNsector) ) {
994 AliWarning(Form("Sector outside range (sector %d) !", sector));
997 if ( (patch < 0) || (patch >= fNrcu) ) {
998 AliWarning(Form("Patch (rcu) outside range (patch %d) !", patch));
1002 if ( side == 0 ) { // A side
1003 if ( patch < 2 ) return sector; // IROC
1004 else return 36+sector; // OROC
1006 if ( patch < 2 ) return 18+sector; // IROC
1007 else return 54+sector; // OROC
1012 //_____________________________________________________________________________
1013 Int_t AliTPCmapper::GetRoc(Int_t side, Int_t sector, Int_t globalpadrow, Int_t pad) const
1015 // Get Roc (0 ... 71) from side (0, 1), sector (0 ... 17) and pad coordinates
1017 Int_t patch = GetPatchSector(globalpadrow, pad);
1018 if ( patch < 0 ) return -1;
1019 return GetRocFromPatch(side, sector, patch);
1023 //_____________________________________________________________________________
1024 Bool_t AliTPCmapper::IsIROC(Int_t roc) const
1026 // Is this ROC an IROC?
1028 AliWarning(Form("Roc outside range (roc %d) !", roc));
1030 } else if ( roc < 36 ) { // inner sector
1032 } else if ( roc < 72 ) { // outer sector, C side
1035 AliWarning(Form("Roc outside range (roc %d) !", roc));
1041 //_____________________________________________________________________________
1042 Bool_t AliTPCmapper::IsOROC(Int_t roc) const
1044 // Is this ROC an OROC?
1046 AliWarning(Form("Roc outside range (roc %d) !", roc));
1048 } else if ( roc < 36 ) { // inner sector
1050 } else if ( roc < 72 ) { // outer sector, C side
1053 AliWarning(Form("Roc outside range (roc %d) !", roc));