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