Line data Source code
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 : #include "AliEMCALTriggerMapping.h"
17 : #include "AliEMCALTriggerMappingV1.h"
18 : #include "AliEMCALGeometry.h"
19 : #include "AliLog.h"
20 :
21 72 : ClassImp(AliEMCALTriggerMappingV1)
22 :
23 : //________________________________________________________________________________________________
24 0 : AliEMCALTriggerMappingV1::AliEMCALTriggerMappingV1() : AliEMCALTriggerMapping()
25 0 : {
26 : // Ctor
27 :
28 0 : SetUniqueID(1);
29 0 : }
30 : //________________________________________________________________________________________________
31 3 : AliEMCALTriggerMappingV1::AliEMCALTriggerMappingV1(Int_t ntru, const AliEMCALGeometry* geo) : AliEMCALTriggerMapping(ntru, geo)
32 15 : {
33 : // Ctor
34 :
35 3 : SetUniqueID(1);
36 6 : }
37 :
38 : //________________________________________________________________________________________________
39 : Bool_t AliEMCALTriggerMappingV1::GetAbsFastORIndexFromTRU(Int_t iTRU, Int_t iADC, Int_t& id) const
40 : {
41 : //Trigger mapping method, get FastOr Index from TRU
42 :
43 0 : if (iTRU > fNTRU - 1 || iTRU < 0 || iADC > 95 || iADC < 0) {
44 0 : AliError("TRU out of range!");
45 0 : return kFALSE;
46 : }
47 :
48 0 : id = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
49 0 : id += iTRU * 96;
50 0 : return kTRUE;
51 0 : }
52 :
53 : //________________________________________________________________________________________________
54 : Bool_t AliEMCALTriggerMappingV1::GetTRUFromAbsFastORIndex(Int_t id, Int_t& iTRU, Int_t& iADC) const
55 : {
56 : // Trigger mapping method, get TRU number from FastOr Index
57 :
58 0 : if (id > fNTRU * 96 - 1 || id < 0) {
59 0 : AliError("Fast-OR ID is out of range!");
60 0 : return kFALSE;
61 : }
62 :
63 0 : iTRU = id / 96;
64 0 : iADC = id % 96;
65 0 : iADC = ( iTRU % 2 ) ? iADC%4 + 4 * (23 - int(iADC/4)) : (3 - iADC%4) + 4 * int(iADC/4);
66 0 : return kTRUE;
67 0 : }
68 :
69 : //________________________________________________________________________________________________
70 : Bool_t AliEMCALTriggerMappingV1::GetPositionInTRUFromAbsFastORIndex(Int_t id, Int_t& iTRU, Int_t& iEta, Int_t& iPhi) const
71 : {
72 : // Trigger mapping method, get position in TRU from FasOr Index
73 :
74 0 : Int_t iADC = -1;
75 0 : if (!GetTRUFromAbsFastORIndex(id, iTRU, iADC)) return kFALSE;
76 :
77 0 : Int_t x = iADC / 4;
78 0 : Int_t y = iADC % 4;
79 0 : if ( iTRU % 2 ) { // C side
80 0 : iEta = 23 - x;
81 0 : iPhi = y;
82 0 : }
83 : else { // A side
84 0 : iEta = x;
85 0 : iPhi = 3 - y;
86 : }
87 : return kTRUE;
88 0 : }
89 :
90 : //________________________________________________________________________________________________
91 : Bool_t AliEMCALTriggerMappingV1::GetPositionInSMFromAbsFastORIndex(Int_t id, Int_t& iSM, Int_t& iEta, Int_t& iPhi) const
92 : {
93 : //Trigger mapping method, get position in Super Module from FasOr Index
94 :
95 0 : Int_t iTRU = -1;
96 0 : if (!GetPositionInTRUFromAbsFastORIndex(id, iTRU, iEta, iPhi)) return kFALSE;
97 0 : if (iTRU % 2) { // C side
98 0 : iSM = 2 * (int(int(iTRU / 2) / 3)) + 1;
99 0 : } else { // A side
100 0 : iSM = 2 * (int(int(iTRU / 2) / 3));
101 : }
102 0 : iPhi += 4 * int((iTRU % 6) / 2);
103 0 : return kTRUE;
104 0 : }
105 :
106 : //________________________________________________________________________________________________
107 : Bool_t AliEMCALTriggerMappingV1::GetPositionInEMCALFromAbsFastORIndex(Int_t id, Int_t& iEta, Int_t& iPhi) const
108 : {
109 : //Trigger mapping method, get position in EMCAL from FastOR index
110 :
111 0 : Int_t iSM = -1;
112 0 : if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi)) {
113 0 : if (iSM % 2) iEta += 24;
114 0 : iPhi += 12 * int(iSM / 2);
115 0 : return kTRUE;
116 : }
117 0 : return kFALSE;
118 0 : }
119 :
120 : //________________________________________________________________________________________________
121 : Bool_t AliEMCALTriggerMappingV1::GetAbsFastORIndexFromPositionInTRU(Int_t iTRU, Int_t iEta, Int_t iPhi, Int_t& id) const
122 : {
123 : //Trigger mapping method, get Index if FastOr from Position in TRU
124 0 : if (iTRU < 0 || iTRU > fNTRU - 1 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 3) {
125 0 : AliError(Form("Out of range! iTRU=%d, iEta=%d, iPhi=%d", iTRU, iEta, iPhi));
126 0 : return kFALSE;
127 : }
128 0 : id = iPhi + 4 * iEta + iTRU * 96;
129 0 : return kTRUE;
130 0 : }
131 :
132 : //________________________________________________________________________________________________
133 : Bool_t AliEMCALTriggerMappingV1::GetAbsFastORIndexFromPositionInSM(Int_t iSM, Int_t iEta, Int_t iPhi, Int_t& id) const
134 : {
135 : // Trigger mapping method, from position in SM Index get FastOR index
136 :
137 0 : if (iSM < 0 || iSM >= 12 || iEta < 0 || iEta > 23 || iPhi < 0 || iPhi > 11) {
138 0 : AliError(Form("Out of range! iSM=%d, iEta=%d, iPhi=%d", iSM, iEta, iPhi));
139 0 : return kFALSE;
140 : }
141 :
142 : Int_t x = iEta;
143 0 : Int_t y = iPhi % 4;
144 0 : Int_t iOff = (iSM % 2) ? 1 : 0;
145 0 : Int_t iTRU = 2 * int(iPhi / 4) + 6 * int(iSM / 2) + iOff;
146 0 : if (GetAbsFastORIndexFromPositionInTRU(iTRU, x, y, id)) {
147 0 : return kTRUE;
148 : }
149 0 : return kFALSE;
150 0 : }
151 :
152 : //________________________________________________________________________________________________
153 : Bool_t AliEMCALTriggerMappingV1::GetAbsFastORIndexFromPositionInEMCAL(Int_t iEta, Int_t iPhi, Int_t& id) const
154 : {
155 : // Trigger mapping method, from position in EMCAL Index get FastOR index
156 :
157 0 : if (iEta < 0 || iEta > 47 || iPhi < 0 || iPhi > 63) {
158 0 : AliError(Form("Out of range! iEta: %2d iPhi: %2d", iEta, iPhi));
159 0 : return kFALSE;
160 : }
161 :
162 0 : Int_t s = int(iEta / 24) + 2 * int(iPhi / 12);
163 0 : Int_t x = iEta % 24;
164 0 : Int_t y = iPhi % 12;
165 0 : if (GetAbsFastORIndexFromPositionInSM(s, x, y, id)) {
166 0 : return kTRUE;
167 : }
168 0 : return kFALSE;
169 0 : }
170 :
171 : //________________________________________________________________________________________________
172 : Bool_t AliEMCALTriggerMappingV1::GetFastORIndexFromCellIndex(Int_t id, Int_t& idx) const
173 : {
174 : // Trigger mapping method, from cell index get FastOR index
175 :
176 0 : Int_t iSupMod, nModule, nIphi, nIeta, iphim, ietam;
177 0 : Bool_t isOK = fGeometry->GetCellIndex( id, iSupMod, nModule, nIphi, nIeta );
178 0 : fGeometry->GetModulePhiEtaIndexInSModule( iSupMod, nModule, iphim, ietam );
179 :
180 0 : if (isOK && GetAbsFastORIndexFromPositionInSM(iSupMod, ietam, iphim, idx)) return kTRUE;
181 0 : return kFALSE;
182 0 : }
183 :
184 : //________________________________________________________________________________________________
185 : Bool_t AliEMCALTriggerMappingV1::GetCellIndexFromFastORIndex(Int_t id, Int_t idx[4]) const
186 : {
187 : // Trigger mapping method, from FASTOR index get cell index
188 :
189 0 : Int_t iSM=-1, iEta=-1, iPhi=-1;
190 0 : if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi)) {
191 0 : Int_t ix = 2 * iEta;
192 0 : Int_t iy = 2 * iPhi;
193 0 : for (Int_t i = 0; i < 2; i++) {
194 0 : for (Int_t j = 0; j < 2; j++) {
195 0 : idx[2 * i + j] = fGeometry->GetAbsCellIdFromCellIndexes(iSM, iy + i, ix + j);
196 : }
197 : }
198 : return kTRUE;
199 : }
200 0 : return kFALSE;
201 0 : }
202 :
203 : //________________________________________________________________________________________________
204 : Bool_t AliEMCALTriggerMappingV1::GetTRUIndexFromSTUIndex(Int_t id, Int_t& idx, Int_t detector) const
205 : {
206 : // STU mapping: TRU# 0 and 16 are missing
207 :
208 0 : if (id > 31 || id < 0) {
209 0 : AliError(Form("TRU index out of range: %d",id));
210 0 : return kFALSE;
211 : }
212 :
213 0 : idx = GetTRUIndexFromSTUIndex(id, detector);
214 0 : return kTRUE;
215 0 : }
216 :
217 : //________________________________________________________________________________________________
218 : Int_t AliEMCALTriggerMappingV1::GetTRUIndexFromSTUIndex(Int_t id, Int_t detector) const
219 : {
220 : // STU mapping: TRU# 0 and 16 are missing
221 :
222 0 : if (id > 31 || id < 0) {
223 0 : AliError(Form("TRU index out of range: %d",id));
224 0 : }
225 0 : return (id > 15) ? 2 * (31 - id) : 2 * (15 - id) + 1;
226 : }
227 :
228 : //________________________________________________________________________________________________
229 : Bool_t AliEMCALTriggerMappingV1::GetTRUIndexFromOnlineIndex(Int_t id, Int_t& idx) const
230 : {
231 : //Trigger mapping method, from STU index get TRU index
232 :
233 0 : idx = GetTRUIndexFromOnlineIndex(id);
234 0 : if (idx > fNTRU - 1 || idx < 0) {
235 0 : AliError(Form("TRU index out of range: %d",idx));
236 0 : return kFALSE;
237 : }
238 0 : return kTRUE;
239 0 : }
240 :
241 : //________________________________________________________________________________________________
242 : Int_t AliEMCALTriggerMappingV1::GetTRUIndexFromOnlineIndex(Int_t id) const
243 : {
244 : //Trigger mapping method, from STU index get TRU index
245 :
246 0 : if (id > fNTRU - 1 || id < 0) {
247 0 : AliError(Form("TRU index out of range: %d",id));
248 0 : }
249 :
250 0 : if (id == 31) {
251 0 : return 31;
252 : }
253 :
254 0 : Int_t idx = ((id % 6) < 3) ? 6 * int(id / 6) + 2 * (id % 3) : 6 * int(id / 6) + 2 * (2 - (id % 3)) + 1;
255 :
256 : return idx;
257 0 : }
258 :
259 : ///
260 : /// \return TRU global offline number from:
261 : /// \param hwAdd: hardware address
262 : /// \param ddl number
263 : /// \param sm: uper-module number
264 : /// Used in AliEMCALTriggerRawDigitMaker::Add()
265 : ///
266 : Int_t AliEMCALTriggerMappingV1::GetTRUIndexFromOnlineHwAdd(Int_t hwAdd, Int_t ddl, Int_t sm) const
267 : {
268 : // 1/3 SMs
269 0 : if ( sm == 10 ) return 30;
270 0 : if ( sm == 11 ) return 31;
271 :
272 : // Full EMCal
273 :
274 0 : UShort_t iBranch = ( hwAdd >> 11 ) & 0x1; // 0/1
275 :
276 0 : Int_t iTRU = ( (ddl << 1) | iBranch ) - 1; // 0..2
277 :
278 0 : iTRU = (sm % 2) ? 2 * (2 - iTRU) + 1 : 2 * iTRU;
279 :
280 0 : iTRU += 6 * int(sm/2);
281 :
282 0 : if (iTRU > 31 || iTRU < 0)
283 : {
284 0 : AliError(Form("TRU index out of range: %d",iTRU));
285 0 : return -1;
286 : }
287 :
288 0 : return iTRU;
289 0 : }
290 :
291 :
292 : //________________________________________________________________________________________________
293 : Bool_t AliEMCALTriggerMappingV1::GetOnlineIndexFromTRUIndex(Int_t id, Int_t& idx) const
294 : {
295 : //Trigger mapping method, from STU index get TRU index
296 :
297 0 : idx = GetOnlineIndexFromTRUIndex(id);
298 0 : if (idx > fNTRU-1 || idx < 0)
299 : {
300 0 : AliError(Form("TRU index out of range: %d",idx));
301 0 : return kFALSE;
302 : }
303 0 : return kTRUE;
304 0 : }
305 : //________________________________________________________________________________________________
306 : Int_t AliEMCALTriggerMappingV1::GetOnlineIndexFromTRUIndex(Int_t id) const
307 : {
308 : //Trigger mapping method, from STU index get TRU index
309 :
310 60 : if (id > fNTRU-1 || id < 0)
311 : {
312 0 : AliError(Form("TRU index out of range: %d",id));
313 0 : }
314 30 : if (id == 31) {
315 0 : return 31;
316 : }
317 :
318 90 : Int_t idx = (id % 2) ? int((6 - (id % 6)) / 2) + 3 * (2 * int(id / 6) + 1) : 3 * int(id / 6) + int(id / 2);
319 :
320 : return idx;
321 30 : }
322 :
323 : //________________________________________________________________________________________________
324 : Bool_t AliEMCALTriggerMappingV1::GetFastORIndexFromL0Index(Int_t iTRU, Int_t id, Int_t idx[], Int_t size) const
325 : {
326 : //Trigger mapping method, from L0 index get FastOR index
327 :
328 0 : if (size <= 0 || size > 4) {
329 0 : AliError("Size not supported!");
330 0 : return kFALSE;
331 : }
332 :
333 0 : Int_t motif[4] = {0, 1, 4, 5};
334 0 : switch (size) {
335 : case 1: // Cosmic trigger
336 0 : if (!GetAbsFastORIndexFromTRU(iTRU, id, idx[1])) return kFALSE;
337 : break;
338 : case 4: // 4 x 4
339 0 : for (Int_t k = 0; k < 4; k++) {
340 0 : Int_t iADC = motif[k] + 4 * int(id / 3) + (id % 3);
341 :
342 0 : if (!GetAbsFastORIndexFromTRU(iTRU, iADC, idx[k])) return kFALSE;
343 0 : }
344 : break;
345 : default:
346 : break;
347 : }
348 :
349 0 : return kTRUE;
350 0 : }
351 :
352 :
353 :
|