]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/ITS/AliSPDUtils.cxx
Moving PWG1 to PWGPP
[u/mrichter/AliRoot.git] / PWGPP / ITS / AliSPDUtils.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 //-----------------------------------------------------------------------
18 // Author : A. Mastroserio
19 //-----------------------------------------------------------------------
20
21
22 #ifndef ALISPDUTILS_CXX
23 #define ALISPDUTILS_CXX
24
25 #include <TString.h>
26 #include "AliSPDUtils.h"
27 ClassImp(AliSPDUtils)
28   //______________________________________________________________________________
29   const Int_t AliSPDUtils::fgkDDLModuleMap[20][12] = {
30     { 4, 5, 0, 1, 80, 81, 84, 85, 88, 89, 92, 93},
31     {12,13, 8, 9, 96, 97,100,101,104,105,108,109},
32     {20,21,16,17,112,113,116,117,120,121,124,125},
33     {28,29,24,25,128,129,132,133,136,137,140,141},
34     {36,37,32,33,144,145,148,149,152,153,156,157},
35     {44,45,40,41,160,161,164,165,168,169,172,173},
36     {52,53,48,49,176,177,180,181,184,185,188,189},
37     {60,61,56,57,192,193,196,197,200,201,204,205},
38     {68,69,64,65,208,209,212,213,216,217,220,221},
39     {76,77,72,73,224,225,228,229,232,233,236,237},
40     { 7, 6, 3, 2, 83, 82, 87, 86, 91, 90, 95, 94},
41     {15,14,11,10, 99, 98,103,102,107,106,111,110},
42     {23,22,19,18,115,114,119,118,123,122,127,126},
43     {31,30,27,26,131,130,135,134,139,138,143,142},
44     {39,38,35,34,147,146,151,150,155,154,159,158},
45     {47,46,43,42,163,162,167,166,171,170,175,174},
46     {55,54,51,50,179,178,183,182,187,186,191,190},
47     {63,62,59,58,195,194,199,198,203,202,207,206},
48     {71,70,67,66,211,210,215,214,219,218,223,222},
49     {79,78,75,74,227,226,231,230,235,234,239,238}
50   };
51 //___________________________________________________________________________
52 AliSPDUtils::~AliSPDUtils() {
53   //
54   //destructor
55   //
56 }
57 //__________________________________________________________________________
58 Bool_t AliSPDUtils::OfflineToOnline(UInt_t module, UInt_t colM, UInt_t rowM, UInt_t& eq, UInt_t& hs, UInt_t& chip, UInt_t& col, UInt_t& row) {
59   // converts offline coordinates to online
60   eq = GetOnlineEqIdFromOffline(module);
61   hs = GetOnlineHSFromOffline(module);
62   chip = GetOnlineChipFromOffline(module,colM);
63   col = GetOnlineColFromOffline(module,colM);
64   row = GetOnlineRowFromOffline(module,rowM);
65   if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE;
66   else return kTRUE;
67 }
68 //__________________________________________________________________________
69 Bool_t AliSPDUtils::OnlineToOffline(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row, UInt_t& module, UInt_t& colM, UInt_t& rowM) {
70   // converts online coordinates to offline
71   module = GetOfflineModuleFromOnline(eq,hs,chip);
72   colM = GetOfflineColFromOnline(eq,hs,chip,col);
73   rowM = GetOfflineRowFromOnline(eq,hs,chip,row);
74   if (module>=240 || colM>=160 || rowM>=256) return kFALSE;
75   else return kTRUE;
76 }
77 //__________________________________________________________________________
78 Bool_t AliSPDUtils::GetOfflineFromOfflineChipKey(UInt_t chipkey,UInt_t& module, UInt_t& chip){
79   // converts offline chip key to offline chip coordinates (V. Altini)
80   if (chipkey>=1200) {
81     TString errMess = Form("%d is not a valid Chip Key number",chipkey);
82     printf(" ERROR : %s\n", errMess.Data());
83     return 0;
84   }
85
86   module = chipkey/5;
87   chip=chipkey%20%5;
88
89   return 1;
90 }
91 //________________________________________________________________________
92 UInt_t AliSPDUtils::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
93   // online->offline (module)
94   if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
95   else return 240;
96 }
97 //________________________________________________________________________
98 UInt_t AliSPDUtils::GetOfflineChipKeyFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
99   // online->offline (chip key: 0-1199)
100   if (eqId<20 && hs<6 && chip<10) {
101     UInt_t module = GetOfflineModuleFromOnline(eqId,hs,chip);
102     UInt_t chipInModule = ( chip>4 ? chip-5 : chip );
103     if(eqId>9) chipInModule = 4 - chipInModule;  // side C only
104     return (module*5 + chipInModule);
105   } else return 1200;
106 }
107 //__________________________________________________________________________
108 UInt_t AliSPDUtils::GetOnlineEqIdFromOffline(UInt_t module) {
109   // offline->online (eq)
110   for (UInt_t eqId=0; eqId<20; eqId++) {
111     for (UInt_t iModule=0; iModule<12; iModule++) {
112       if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId;
113     }
114   }
115   return 20; // error
116 }
117 //__________________________________________________________________________
118 UInt_t AliSPDUtils::GetOnlineHSFromOffline(UInt_t module) {
119   // offline->online (hs)
120   for (UInt_t eqId=0; eqId<20; eqId++) {
121     for (UInt_t iModule=0; iModule<12; iModule++) {
122       if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2;
123     }
124   }
125   return 6; // error
126 }
127 //__________________________________________________________________________
128 UInt_t AliSPDUtils::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
129   // offline->online (chip)
130   for (UInt_t eq=0; eq<20; eq++) {
131     for (UInt_t iModule=0; iModule<12; iModule++) {
132       if (GetModuleNumber(eq,iModule)==(Int_t)module) {
133         if (module<80) {
134           if (eq<10) { // side A
135             return (159-colM)/32 + 5*(iModule%2);
136           }
137           else { // side C
138             return colM/32 + 5*(iModule%2);
139           }
140         }
141         else if (module<240) {
142           if (eq<10) { // side A
143             return colM/32 + 5*(iModule%2);
144           }
145           else { // side C
146             return (159-colM)/32 + 5*(iModule%2);
147           }
148         }
149       }
150     }
151   }
152   return 10; // error
153 }
154 //__________________________________________________________________________
155 Int_t AliSPDUtils::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
156   if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
157   else return 240;
158 }
159 //__________________________________________________________________________
160 UInt_t AliSPDUtils::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
161   // offline->online (col)
162   if (module<80) { // inner layer
163     return colM%32;
164   }
165   else if (module<240) { // outer layer
166     return colM%32;
167   }
168   return 32; // error
169 }
170 //__________________________________________________________________________
171 UInt_t AliSPDUtils::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
172   // offline->online (row)
173   if (module<80) { // inner layer
174     return (255-rowM);
175   }
176   else if (module<240) { // outer layer
177     return (255-rowM);
178   }
179   return 256; // error
180 }
181 //__________________________________________________________________________
182 UInt_t AliSPDUtils::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
183   // online->offline (col)
184   if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error
185   UInt_t offset = 32 * (chip % 5);
186   if (hs<2) {
187     if (eqId<10) {
188       return 159 - (31-col + offset); // inner layer, side A
189     }
190     else {
191       return col + offset; // inner layer, side C
192     }
193   }
194   else {
195     if (eqId<10) {
196       return (col + offset); // outer layer, side A
197     }
198     else {
199       return 159 - (31-col + offset); // outer layer, side C
200     }
201   }
202 }
203 //__________________________________________________________________________
204 UInt_t AliSPDUtils::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
205   // online->offline (row)
206   if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error
207   return 255-row;
208 }
209 //__________________________________________________________________________
210 Bool_t AliSPDUtils::GetOnlineFromOfflineChipKey(UInt_t chipkey,UInt_t& eq, UInt_t& hs, UInt_t& chip){
211   // online Eq, hs and chip from offline chipkey (V. Altini)
212   if (chipkey>=1200) {
213     TString errMess = Form("%d is not a valid Chip Key number",chipkey);
214     printf("ERROR : %s \n", errMess.Data());
215     return 0;
216   }
217
218   eq = GetOnlineEqIdFromOffline(chipkey/5);
219   hs = GetOnlineHSFromOffline(chipkey/5);
220   chip=chipkey%20;
221   if(chip>9) chip=19-chip;
222
223   return 1;
224 }
225
226 #endif