]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/EMCALUtils/AliEMCALTriggerMappingV2.cxx
8fab483f2d9f05b460ba83edec74f08479a23d09
[u/mrichter/AliRoot.git] / EMCAL / EMCALUtils / AliEMCALTriggerMappingV2.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  
19
20
21 Author: 
22 H. YOKOYAMA Tsukuba University
23 R. GUERNANE LPSC Grenoble CNRS/IN2P3
24 */
25
26 #include "AliEMCALTriggerMapping.h"
27 #include "AliEMCALTriggerMappingV2.h"
28 #include "AliEMCALGeometry.h"
29 #include "AliLog.h"
30
31 ClassImp(AliEMCALTriggerMappingV2)
32
33 //________________________________________________________________________________________________
34 AliEMCALTriggerMappingV2::AliEMCALTriggerMappingV2() : AliEMCALTriggerMapping()
35 {
36   // Ctor
37   SetUniqueID(2);
38   
39   for(Int_t iTRU=0; iTRU<46; iTRU++){
40     fTRUFastOROffsetX[iTRU] = 0 ;
41     fTRUFastOROffsetY[iTRU] = 0 ;
42     fnFastORInTRUPhi[ iTRU] = 0 ;
43     fnFastORInTRUEta[ iTRU] = 0 ;
44   }
45   for(Int_t iSM=0; iSM<20; iSM++){
46     fSMFastOROffsetX[ iSM]  = 0 ;
47     fSMFastOROffsetY[ iSM]  = 0 ;
48     fnFastORInSMPhi[  iSM]  = 0 ;
49     fnFastORInSMEta[  iSM]  = 0 ;
50   }
51   fnModuleInEMCALPhi  = 0 ;
52
53   Init_TRU_offset()  ;
54   Init_SM_offset()   ;
55 }
56 //________________________________________________________________________________________________
57 AliEMCALTriggerMappingV2::AliEMCALTriggerMappingV2(const Int_t ntru, const AliEMCALGeometry* geo) : AliEMCALTriggerMapping(ntru, geo)
58 {
59   // Ctor
60   SetUniqueID(2);
61   
62   for(Int_t iTRU=0; iTRU<46; iTRU++){
63     fTRUFastOROffsetX[iTRU] = geo.fTRUFastOROffsetX[iTRU] ;
64     fTRUFastOROffsetY[iTRU] = geo.fTRUFastOROffsetY[iTRU] ;
65     fnFastORInTRUPhi[ iTRU] = geo.fnFastORInTRUPhi[ iTRU] ;
66     fnFastORInTRUEta[ iTRU] = geo.fnFastORInTRUEta[ iTRU] ;
67   }
68   for(Int_t iSM=0; iSM<20; iSM++){
69     fSMFastOROffsetX[ iSM]  = geo.fSMFastOROffsetX[ iSM]  ;
70     fSMFastOROffsetY[ iSM]  = geo.fSMFastOROffsetY[ iSM]  ;
71     fnFastORInSMPhi[  iSM]  = geo.fnFastORInSMPhi[  iSM]  ;
72     fnFastORInSMEta[  iSM]  = geo.fnFastORInSMEta[  iSM]  ;
73   }
74   fnModuleInEMCALPhi  = geo.fnModuleInEMCALPhi  ;
75 }
76
77 //________________________________________________________________________________________________
78 Bool_t AliEMCALTriggerMappingV2::GetAbsFastORIndexFromTRU(const Int_t iTRU, const Int_t iADC, Int_t& id) const
79 {
80   //Trigger mapping method, get  FastOr Index from TRU
81   if (iTRU > fNTotalTRU-1     || iTRU < 0 || 
82       iADC > fNModulesInTRU-1 || iADC < 0
83   ){
84     AliError(Form("Out of range! iTRU=%d, iADC=%d", iTRU, iADC));       
85     return kFALSE;
86   }
87   Int_t x = fTRUFastOROffsetX[iTRU] +    (iADC % fnFastORInTRUEta[iTRU])  ;
88   Int_t y = fTRUFastOROffsetY[iTRU] + int(iADC / fnFastORInTRUEta[iTRU])  ;
89   id      = y*fNEta*2 + x         ;
90   return kTRUE  ;
91 }
92
93 //________________________________________________________________________________________________
94 Bool_t AliEMCALTriggerMappingV2::GetAbsFastORIndexFromPositionInTRU(const Int_t iTRU, const Int_t iEta, const Int_t iPhi, Int_t& id) const
95 {
96   //Trigger mapping method, get Index if FastOr from Position in TRU
97   if (iTRU > fNTotalTRU-1               || iTRU < 0 || 
98       iEta > fnFastORInTRUEta[iTRU] - 1 || iEta < 0 ||
99       iPhi > fnFastORInTRUPhi[iTRU] - 1 || iPhi < 0
100   ){
101     AliError(Form("Out of range! iTRU=%d, iEta=%d, iPhi=%d", iTRU, iEta, iPhi));        
102     return kFALSE;
103   }
104   Int_t x = fTRUFastOROffsetX[iTRU] + iEta  ;
105   Int_t y = fTRUFastOROffsetY[iTRU] + iPhi  ;
106   id      = y*fNEta*2 + x         ;
107   return kTRUE  ;
108 }
109
110 //________________________________________________________________________________________________
111 Bool_t AliEMCALTriggerMappingV2::GetAbsFastORIndexFromPositionInSM(const Int_t  iSM, const Int_t iEta, const Int_t iPhi, Int_t& id) const
112 {
113   //Trigger mapping method, from position in SM Index get FastOR index 
114   if (iSM  > fNumberOfSuperModules-1  || iSM  < 0 || 
115       iEta > fnFastORInSMEta[iSM] -1  || iEta < 0 ||
116       iPhi > fnFastORInSMPhi[iSM] -1  || iPhi < 0
117   ){
118     AliError(Form("Out of range! iSM=%d, iEta=%d, iPhi=%d", iSM, iEta, iPhi));  
119     return kFALSE;
120   }
121   Int_t x = fSMFastOROffsetX[iSM] + iEta  ;
122   Int_t y = fSMFastOROffsetY[iSM] + iPhi  ;
123   id      = y*fNEta*2 + x         ;
124   return kTRUE  ;
125 }
126
127 //________________________________________________________________________________________________
128 Bool_t AliEMCALTriggerMappingV2::GetAbsFastORIndexFromPositionInEMCAL(const Int_t iEta, const Int_t iPhi, Int_t& id) const
129 {
130   //Trigger mapping method, from position in EMCAL Index get FastOR index 
131   if (
132       iEta > 2 * fNEta - 1          || iEta < 0 || 
133       iPhi > fnModuleInEMCALPhi - 1 || iPhi < 0  
134   ){
135     AliError(Form("Out of range! eta: %2d phi: %2d", iEta, iPhi));
136     return kFALSE;
137   }
138   id      = iPhi*fNEta*2 + iEta       ;
139   return kTRUE  ;
140 }
141
142 //________________________________________________________________________________________________
143 Bool_t AliEMCALTriggerMappingV2::GetTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iADC) const
144 {
145   //Trigger mapping method, get TRU number from FastOr Index
146   Int_t iEta_TRU , iPhi_TRU , iSM , iEta_SM , iPhi_SM ;
147   return GetInfoFromAbsFastORIndex(
148     id   , 
149     iTRU , iADC , iEta_TRU , iPhi_TRU , 
150     iSM  ,        iEta_SM  , iPhi_SM  
151     );
152 }
153
154 //________________________________________________________________________________________________
155 Bool_t AliEMCALTriggerMappingV2::GetPositionInTRUFromAbsFastORIndex(const Int_t id, Int_t& iTRU, Int_t& iEta, Int_t& iPhi) const
156 {
157   //Trigger mapping method, get position in TRU from FasOr Index
158   Int_t iADC , iSM , iEta_SM , iPhi_SM ;
159   return GetInfoFromAbsFastORIndex(
160     id   , 
161     iTRU , iADC , iEta     , iPhi     , 
162     iSM  ,        iEta_SM  , iPhi_SM  
163     );
164 }
165
166 //________________________________________________________________________________________________
167 Bool_t AliEMCALTriggerMappingV2::GetPositionInSMFromAbsFastORIndex(const Int_t id, Int_t& iSM, Int_t& iEta, Int_t& iPhi) const
168 {
169   //Trigger mapping method, get position in Super Module from FasOr Index
170   Int_t iTRU , iADC , iEta_TRU , iPhi_TRU ;
171   return GetInfoFromAbsFastORIndex(
172     id   , 
173     iTRU , iADC , iEta_TRU , iPhi_TRU , 
174     iSM  ,        iEta     , iPhi  
175     );
176 }
177
178 //________________________________________________________________________________________________
179 Bool_t AliEMCALTriggerMappingV2::GetPositionInEMCALFromAbsFastORIndex(const Int_t id, Int_t& iEta, Int_t& iPhi) const
180 {
181   //Trigger mapping method, get position in EMCAL from FastOR index
182   Int_t nModule = fNEta * 2 * fnModuleInEMCALPhi;
183   if (id > nModule-1 || id < 0){
184     AliError("Id out of range!");
185     return kFALSE;
186   }
187   iEta  = id % (2*fNEta) ;
188   iPhi  = id / (2*fNEta) ;
189   return kTRUE;
190 }
191
192 //________________________________________________________________________________________________
193 Bool_t AliEMCALTriggerMappingV2::GetFastORIndexFromCellIndex(const Int_t id, Int_t& idx) const
194 {
195   // Trigger mapping method, from cell index get FastOR index 
196
197   Int_t iSupMod, nModule, nIphi, nIeta, iphim, ietam;
198   Bool_t isOK = fGeometry->GetCellIndex( id, iSupMod, nModule, nIphi, nIeta );
199   fGeometry->GetModulePhiEtaIndexInSModule( iSupMod, nModule, iphim, ietam );
200   
201   if (isOK && GetAbsFastORIndexFromPositionInSM(iSupMod, ietam, iphim, idx)) return kTRUE;
202   return kFALSE;
203 }
204
205 //________________________________________________________________________________________________
206 Bool_t AliEMCALTriggerMappingV2::GetCellIndexFromFastORIndex(const Int_t id, Int_t idx[4]) const
207 {
208   //Trigger mapping method, from FASTOR index get cell index 
209   Int_t iSM=-1, iEta=-1, iPhi=-1;
210   if (GetPositionInSMFromAbsFastORIndex(id, iSM, iEta, iPhi))
211   {
212     Int_t ix = 2 * iEta;
213     Int_t iy = 2 * iPhi;
214     idx[0] = fGeometry->GetAbsCellIdFromCellIndexes(iSM, iy    , ix    );
215     idx[1] = fGeometry->GetAbsCellIdFromCellIndexes(iSM, iy    , ix + 1);
216     idx[2] = fGeometry->GetAbsCellIdFromCellIndexes(iSM, iy + 1, ix    );
217     idx[3] = fGeometry->GetAbsCellIdFromCellIndexes(iSM, iy + 1, ix + 1);
218     return kTRUE;
219   }
220   return kFALSE;
221 }
222
223 //________________________________________________________________________________________________
224 Bool_t AliEMCALTriggerMappingV2::GetTRUIndexFromSTUIndex(const Int_t id, Int_t& idx) const
225 {
226   //Trigger mapping method, from STU index get TRU index 
227   idx = GetTRUIndexFromSTUIndex(id);
228   return kTRUE;
229 }
230
231 //________________________________________________________________________________________________
232 Int_t AliEMCALTriggerMappingV2::GetTRUIndexFromSTUIndex(const Int_t id) const
233 {
234   //Trigger mapping method, from STU index get TRU index 
235   if (id > fNTotalTRU-1 || id < 0){
236     AliError(Form("TRU index out of range: %d",id));
237   }
238   return id ;
239 }
240
241 //________________________________________________________________________________________________
242 Bool_t AliEMCALTriggerMappingV2::GetTRUIndexFromOnlineIndex(const Int_t id, Int_t& idx) const
243 {
244   //Trigger mapping method, from STU index get TRU index 
245   idx = GetTRUIndexFromOnlineIndex(id);
246   return kTRUE;
247 }
248
249 //________________________________________________________________________________________________
250 Int_t AliEMCALTriggerMappingV2::GetTRUIndexFromOnlineIndex(const Int_t id) const
251 {
252   //Trigger mapping method, from STU index get TRU index 
253   if (id > fNTotalTRU-1 || id < 0){
254     AliError(Form("TRU index out of range: %d",id));
255   }
256   return id;
257 }
258
259 //________________________________________________________________________________________________
260 Bool_t AliEMCALTriggerMappingV2::GetOnlineIndexFromTRUIndex(const Int_t id, Int_t& idx) const
261 {
262   //Trigger mapping method, from STU index get TRU index 
263   idx = GetOnlineIndexFromTRUIndex(id);
264   return kTRUE;
265 }
266
267 //________________________________________________________________________________________________
268 Int_t AliEMCALTriggerMappingV2::GetOnlineIndexFromTRUIndex(const Int_t id) const
269 {
270   //Trigger mapping method, from STU index get TRU index 
271   if (id > fNTotalTRU-1 || id < 0){
272     AliError(Form("TRU index out of range: %d",id));
273   }
274   return id;
275 }
276
277 //________________________________________________________________________________________________
278 Bool_t AliEMCALTriggerMappingV2::GetFastORIndexFromL0Index(const Int_t iTRU, const Int_t id, Int_t idx[], const Int_t size) const
279 {
280   //Trigger mapping method, from L0 index get FastOR index 
281
282   if (size <= 0 ||size > 4){
283     AliError("Size not supported!");
284     return kFALSE;
285   }
286                 
287   Int_t motif[4];
288   motif[0] = 0;
289   motif[1] = 1;
290   motif[2] = fnFastORInTRUEta[iTRU]     ;
291   motif[3] = fnFastORInTRUEta[iTRU] + 1 ;
292  
293   switch (size)
294   {
295     case 1: // Cosmic trigger
296       if (!GetAbsFastORIndexFromTRU(iTRU, id, idx[1])) return kFALSE;
297       break;
298     case 4: // 4 x 4
299       for (Int_t k = 0; k < 4; k++)
300       {
301         Int_t iADC = motif[k] + fnFastORInTRUEta[iTRU] * int(id/(fnFastORInTRUEta[iTRU]-1)) + (id%(fnFastORInTRUEta[iTRU]-1));
302                                 
303         if (!GetAbsFastORIndexFromTRU(iTRU, iADC, idx[k])) return kFALSE;
304       }
305       break;
306     default:
307       break;
308   }
309         
310   return kTRUE;
311 }
312
313 //________________________________________________________________________________________________
314 Bool_t AliEMCALTriggerMappingV2::Init_TRU_offset(){
315   fTRUFastOROffsetX[0]   = 0 ;
316   fTRUFastOROffsetY[0]   = 0 ;
317   Int_t iTRU  = 0 ;
318
319   for(int iSM=0; iSM<fNumberOfSuperModules; iSM++){
320     Int_t       SM_type   = GetSMType(iSM);
321     Int_t       TRU_type  = 0             ;
322     
323     Int_t nTRU_inSM         = fNTRU                ;
324     Int_t nTRU_inSM_phi     = fNTRUPhi             ;
325     Int_t nTRU_inSM_eta     = fNTRUEta             ;
326     Int_t nModule_inTRU_phi = fNModulesInTRUPhi    ;
327     Int_t nModule_inTRU_eta = fNModulesInTRUEta    ;
328     
329     //kEMCAL_Standard -> default value
330     if(     SM_type == kEMCAL_3rd      ){
331       nTRU_inSM         = (Int_t)((Float_t)nTRU_inSM         / 3. );
332       nTRU_inSM_eta     = (Int_t)((Float_t)nTRU_inSM_eta     / 3. );
333       nModule_inTRU_phi = (Int_t)((Float_t)nModule_inTRU_phi / 3. );
334       nModule_inTRU_eta = nModule_inTRU_eta                  * 3   ;
335     }
336     else if(SM_type == kDCAL_Standard  ){
337       nTRU_inSM         = (Int_t)((Float_t)nTRU_inSM      * 2./3. );
338       nTRU_inSM_eta     = (Int_t)((Float_t)nTRU_inSM_eta  * 2./3. );
339     }
340     else if(SM_type == kDCAL_Ext       ){
341       nTRU_inSM         = (Int_t)((Float_t)nTRU_inSM         / 3. );
342       nTRU_inSM_eta     = (Int_t)((Float_t)nTRU_inSM_eta     / 3. );
343       nModule_inTRU_phi = (Int_t)((Float_t)nModule_inTRU_phi / 3. );
344       nModule_inTRU_eta =                  nModule_inTRU_eta * 3   ;
345     }
346
347     //TRU ieta/iphi offset calculation 
348     for(Int_t i=0; i<nTRU_inSM; i++){
349       fnFastORInTRUPhi[iTRU]  = nModule_inTRU_phi ;
350       fnFastORInTRUEta[iTRU]  = nModule_inTRU_eta ;
351       if((iTRU+1) >= fNTotalTRU)break;
352       
353       TRU_type  = 0 ;
354       if( i==nTRU_inSM-1 ){//last TRU in SM
355         if(      iSM%2==0 && SM_type==kDCAL_Standard ) TRU_type = 2  ;//left  DCAL 
356         else if( iSM%2==1 && SM_type==kDCAL_Standard ) TRU_type = 3  ;//right DCAL 
357         else if( iSM%2==1                            ) TRU_type = 1  ;//right EMCAL
358       }
359       if(      TRU_type == 0){
360         fTRUFastOROffsetX[iTRU+1]  = fTRUFastOROffsetX[iTRU] + nModule_inTRU_eta      ;
361         fTRUFastOROffsetY[iTRU+1]  = fTRUFastOROffsetY[iTRU]                          ;
362       }else if(TRU_type == 1){
363         fTRUFastOROffsetX[iTRU+1]  = 0                                                ;
364         fTRUFastOROffsetY[iTRU+1]  = fTRUFastOROffsetY[iTRU] + nModule_inTRU_phi      ;
365       }else if(TRU_type == 2){
366         fTRUFastOROffsetX[iTRU+1]  = fTRUFastOROffsetX[iTRU] + nModule_inTRU_eta * 3  ;
367         fTRUFastOROffsetY[iTRU+1]  = fTRUFastOROffsetY[iTRU]                          ;
368       }else if(TRU_type == 3){
369         fTRUFastOROffsetX[iTRU+1]  = 0                                                ;
370         fTRUFastOROffsetY[iTRU+1]  = fTRUFastOROffsetY[iTRU] + nModule_inTRU_phi      ;
371       }
372       iTRU++  ;
373     }//TRU loop
374   }//SM loop
375   
376   return kTRUE ;
377 }
378
379 //________________________________________________________________________________________________
380 Bool_t AliEMCALTriggerMappingV2::Init_SM_offset(){
381
382   fSMFastOROffsetX[0]  = 0 ;
383   fSMFastOROffsetY[0]  = 0 ;
384   fnModuleInEMCALPhi  = 0 ;
385
386   for(int iSM=0; iSM<fNumberOfSuperModules; iSM++){
387     Int_t SM_type = GetSMType(iSM);
388     
389     Int_t nModule_inSM_phi  = fNPhi    ;
390     Int_t nModule_inSM_eta  = fNEta    ;
391     
392     //kEMCAL_Standard:kEMCAL_Half -> default value
393     if(     SM_type == kEMCAL_3rd      ){
394       nModule_inSM_phi  = (Int_t)((Float_t)nModule_inSM_phi      / 3.);
395     }
396     else if(SM_type == kDCAL_Standard  ){
397       nModule_inSM_eta  = (Int_t)((Float_t)nModule_inSM_eta * 2. / 3.);
398     }
399     else if(SM_type == kDCAL_Ext       ){
400       nModule_inSM_phi  = (Int_t)((Float_t)nModule_inSM_phi      / 3.);
401     }
402
403     fnFastORInSMPhi[iSM]  = nModule_inSM_phi ;
404     fnFastORInSMEta[iSM]  = nModule_inSM_eta ;
405     if( (iSM+1) >= fNumberOfSuperModules)break  ;
406
407     if(iSM%2 == 1){//right SM
408       fSMFastOROffsetX[iSM+1]  = 0                                        ;
409       fSMFastOROffsetY[iSM+1]  = fSMFastOROffsetY[iSM] + nModule_inSM_phi ;
410     }
411     else{//left SM
412       fnModuleInEMCALPhi += nModule_inSM_phi  ;
413       if(SM_type == kDCAL_Standard){
414         fSMFastOROffsetX[iSM+1]  = fSMFastOROffsetX[iSM] + nModule_inSM_eta * 2 ;
415         fSMFastOROffsetY[iSM+1]  = fSMFastOROffsetY[iSM]                        ;
416       }else{
417         fSMFastOROffsetX[iSM+1]  = fSMFastOROffsetX[iSM] + nModule_inSM_eta     ;
418         fSMFastOROffsetY[iSM+1]  = fSMFastOROffsetY[iSM]                        ;
419       }
420     }
421   }//SM loop
422   return kTRUE ;
423 }
424
425 //________________________________________________________________________________________________
426 Bool_t AliEMCALTriggerMappingV2::GetInfoFromAbsFastORIndex(
427     const Int_t id, 
428     Int_t& iTRU , Int_t& iADC , Int_t& iEta_TRU , Int_t& iPhi_TRU , 
429     Int_t& iSM  ,               Int_t& iEta_SM  , Int_t& iPhi_SM  
430     ) const
431 {
432
433   Int_t nModule = fNEta * 2 * fnModuleInEMCALPhi;
434   if (id > nModule-1 || id < 0){
435     AliError("Id out of range!");
436     return kFALSE;
437   }
438         
439   Int_t x       = id % (fNEta * 2) ;
440   Int_t y       = id / (fNEta * 2) ;
441   if(y >= fNPhi*5 + 4)  y = y + 8 ;
442   
443   Int_t y_class     = int(y/fNModulesInTRUPhi)   ;
444   Int_t x_class     = int(x/fNModulesInTRUEta)   ;
445   iTRU = y_class*(fNTRUEta*2) + x_class ;
446   
447   Int_t Cside       = int(x/fNEta);//Cside SM
448   //y_class = 5 : EMCAL 1/3 SM
449   //y_class = 9 : DCAL  1/3 SM
450   Int_t DCAL_sepC   = (y_class>5 && y_class<9 && Cside==1)? 1 : 0 ;
451   Bool_t IsPHOS     = (y_class>5 && y_class<9 && (x_class==2 || x_class==3))? kTRUE : kFALSE ;
452
453   if(y_class==5 || y_class==9 ) iTRU = iTRU - (x_class%3) - Cside*2 ;
454   if(y_class> 5               ) iTRU = iTRU - 2 - (y_class-5)*2 - DCAL_sepC*2 ;
455
456   iADC = (y_class==5 || y_class==9)? (y%(fNModulesInTRUPhi/3))*(fNModulesInTRUEta*3) + (x%(fNModulesInTRUEta*3)) :
457                                      (y% fNModulesInTRUPhi   )* fNModulesInTRUEta    + (x% fNModulesInTRUEta   ) ;
458
459   iSM       = int(y/fNPhi)*2 + Cside  ; 
460   iEta_TRU  = (y_class==5 || y_class==9)? x%(fNModulesInTRUEta*3) : x%(fNModulesInTRUEta);
461   iPhi_TRU  = y%fNModulesInTRUPhi;
462   iEta_SM   = (DCAL_sepC == 1)? (x%fNEta - 8) : (x%fNEta);
463   iPhi_SM   = y%fNPhi;
464
465   if(IsPHOS){
466     iTRU      = -1  ;
467     iADC      = -1  ;
468     iSM       = -1  ;
469     iEta_TRU  = -1  ;
470     iPhi_TRU  = -1  ;
471     iEta_SM   = -1  ;
472     iPhi_SM   = -1  ;
473   }
474   return kTRUE;
475 }
476