]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONLocalTriggerBoard.cxx
Move to new mapping
[u/mrichter/AliRoot.git] / MUON / AliMUONLocalTriggerBoard.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 /* $Id$ */
17
18 //_________________________________________________________________________
19 // Implementation of local trigger board objects
20 // A local trigger board has as input a bit pattern and returns 
21 // the local trigger response after comparison w/ a LUT
22 //
23 //*-- Author: Rachid Guernane (LPCCFd)
24
25 #include "AliMUONLocalTriggerBoard.h"
26 #include "AliMUONTriggerLut.h"
27 #include "AliMUONTriggerConstants.h"
28 #include "AliLog.h"
29
30 #include <TBits.h>
31
32 #include <Riostream.h>
33
34 //___________________________________________
35 AliMUONLocalTriggerBoard::AliMUONLocalTriggerBoard()
36 {
37    fNumber = 0;
38
39    for (Int_t i=0; i<2; i++) 
40       for (Int_t j=0; j<4; j++) 
41       {
42          fXY[i][j] = fXYU[i][j] = fXYD[i][j] = 0;
43
44          fMask[i][j] = 0xFFFF;
45       }
46
47    for (Int_t i=0; i<10; i++) fSwitch[i] = 0;
48
49    fTC = kTRUE;
50
51    fLUT = 0x0;
52
53    for (Int_t i=0; i<5; i++) fMinDevStrip[i] = fMinDev[i] = fCoordY[i] = 0;
54
55    fOutput = 0;
56    
57    fStripX11 = fStripY11 = fDev = 0;
58
59    for (Int_t i=0; i<2; i++) fLutLpt[i] = fLutHpt[i] = fLutApt[i] = 0;
60 }
61
62 //___________________________________________
63 AliMUONLocalTriggerBoard::AliMUONLocalTriggerBoard(const char *name, Int_t a) : AliMUONTriggerBoard(name, a)
64 {
65    fNumber = 0;
66    
67    for (Int_t i=0; i<2; i++) 
68       for (Int_t j=0; j<4; j++) 
69       {
70          fXY[i][j] = fXYU[i][j] = fXYD[i][j] = 0;
71
72          fMask[i][j] = 0xFFFF;
73       }
74
75    for (Int_t i=0; i<10; i++) fSwitch[i] = 0;
76
77    fTC = kTRUE;
78
79    fLUT = new AliMUONTriggerLut();
80
81    for (Int_t i=0; i<5; i++) fMinDevStrip[i] = fMinDev[i] = fCoordY[i] = 0;
82
83    fOutput = 0;
84    
85    fStripX11 = fStripY11 = fDev = 0;
86
87    for (Int_t i=0; i<2; i++) fLutLpt[i] = fLutHpt[i] = fLutApt[i] = 0;
88 }
89
90 //___________________________________________
91 void AliMUONLocalTriggerBoard::Reset()
92 {
93    for (Int_t i=0; i<2; i++) 
94       for (Int_t j=0; j<4; j++) 
95          fXY[i][j] = fXYU[i][j] = fXYD[i][j] = 0;
96
97    fResponse = 0;
98
99    for (Int_t i=0; i<5; i++) fMinDevStrip[i] = fMinDev[i] = fCoordY[i] = 0;
100
101    fOutput = 0;
102    
103    fStripX11 = fStripY11 = fDev = 0;
104
105    for (Int_t i=0; i<2; i++) fLutLpt[i] = fLutHpt[i] = fLutApt[i] = 0;
106 }
107
108 //___________________________________________
109 void AliMUONLocalTriggerBoard::Setbit(Int_t strip, Int_t cathode, Int_t chamber)
110 {
111 // 0 .. LBS   :   N-1 .. MSB
112    TBits w, m;
113
114    UShort_t xy = fXY[cathode][chamber], mask = fMask[cathode][chamber];
115
116    w.Set(16,&xy);
117    m.Set(16,&mask);
118
119    Int_t s = strip - int(strip / 16) * 16;
120
121    w.SetBitNumber(s);
122    
123    w &= m;
124
125    UShort_t value;
126
127    w.Get(&value);
128
129    fXY[cathode][chamber] = value;
130 }
131
132 //___________________________________________
133 void AliMUONLocalTriggerBoard::SetbitM(Int_t strip, Int_t cathode, Int_t chamber)
134 {
135 // 0 .. LBS   :   N-1 .. MSB
136    TBits w, m;
137
138    UShort_t xy = fXY[cathode][chamber], mask = fMask[cathode][chamber];
139
140    w.Set(16,&xy);
141    m.Set(16,&mask);
142
143 //    Int_t s = strip - int(strip / 16) * 16;
144
145    w.SetBitNumber(strip);
146    
147    w &= m;
148
149    UShort_t value;
150
151    w.Get(&value);
152
153    fXY[cathode][chamber] = value;
154 }
155
156 //___________________________________________
157 void AliMUONLocalTriggerBoard::Pattern(Option_t *option)
158 {
159    TString op = option;
160    
161    if (op.Contains("X")) BP("X");
162
163    if (op.Contains("Y")) BP("Y");
164 }
165
166
167 //___________________________________________
168 void AliMUONLocalTriggerBoard::BP(Option_t *option)
169 {
170 // RESPECT THE OLD PRINTOUT FORMAT
171
172    TString op = option;
173
174         TString nn = GetName();
175
176    if (op.Contains("X"))
177    {
178       printf("-------- TRIGGER INPUT ---------\n");
179       printf("===============================================================\n");
180       printf("                            5432109876543210");
181
182       char *x[4] = {"XMC11","XMC12","XMC21","XMC22"};
183       char *s[4] = {"                      ",
184                     "                      ",
185                     "              ",
186                     "              "};
187       
188       for (Int_t ch=0; ch<4; ch++)
189       { 
190          printf("\n %s%s", x[ch], s[ch]);
191
192          UShort_t xy = fXY[0][ch];
193
194          TBits w(16); w.Set(16,&xy);
195
196          if (ch<2) cout << w;
197          else
198          {
199             UShort_t xyd = fXYD[0][ch], xyu = fXYU[0][ch];
200             TBits dw(16), uw(16); dw.Set(16,&xyd); uw.Set(16,&xyu); 
201
202             TBits ew(32);
203          
204             for (Int_t i=0;i<16;i++) ew[i+8] = w[i];
205
206             for (Int_t i=0;i<8;i++) 
207             {
208                ew[i]    = dw[i+8]; // 8 MSB
209                ew[i+24] = uw[i];   // 
210             }
211
212             cout << ew;
213          }
214       }
215    
216       printf("\n                    ");
217       printf("10987654321098765432109876543210\n");
218    }
219
220    if (op.Contains("Y"))
221    {
222       printf("---------------------------------------------------------------\n");
223       printf("                            ");
224
225 /*    OLD NUMBERING STYLE    */
226 /**/
227       Int_t idCircuit = 0, absidModule = 0;
228
229                 if (!(nn.Contains("Int"))) 
230                 {
231                         idCircuit   = AliMUONTriggerConstants::CircuitId(GetI());
232                         absidModule = TMath::Abs(Int_t(idCircuit/10));
233                 }
234                 
235       Int_t iModule=0;
236
237       for (Int_t i=0; i<63; i++) 
238       {
239          if (AliMUONTriggerConstants::ModuleId(i)==absidModule) 
240          { 
241             iModule=i;
242             break;
243          }
244       }
245
246       Int_t nStrip = AliMUONTriggerConstants::NstripY(iModule);
247       for (Int_t istrip=nStrip-1; istrip>=0; istrip--) {
248          if (istrip>9)  printf("%i",istrip-10*Int_t(istrip/10));
249          if (istrip<10) printf("%i",istrip);
250       }
251 /**/
252 /*                           */
253
254       UShort_t xyval = 0;
255
256       if (fSwitch[1])
257       {
258          xyval = fXY[1][0];
259          TBits v11(8); v11.Set(8,&xyval);
260          printf("\n YMC11                      ");
261          cout << v11;         
262
263          xyval = fXY[1][1];
264          TBits v12(8); v12.Set(8,&xyval);
265          printf("\n YMC12                      ");
266          cout << v12;
267
268          xyval = fXY[1][2];
269          TBits v21(8); v21.Set(8,&xyval);
270          printf("\n YMC21                      ");         
271          cout << v21;
272
273          xyval = fXY[1][3];
274          TBits v22(8); v22.Set(8,&xyval);
275          printf("\n YMC22                      ");
276          cout << v22 << endl;
277       }
278       else
279       {
280          xyval = fXY[1][0];
281          TBits v11(16); v11.Set(16,&xyval);
282          printf("\n YMC11                      ");
283          cout << v11;         
284
285          xyval = fXY[1][1];
286          TBits v12(16); v12.Set(16,&xyval);
287          printf("\n YMC12                      ");
288          cout << v12;
289
290          xyval = fXY[1][2];
291          TBits v21(16); v21.Set(16,&xyval);
292          printf("\n YMC21                      ");         
293          cout << v21;
294
295          xyval = fXY[1][3];
296          TBits v22(16); v22.Set(16,&xyval);
297          printf("\n YMC22                      ");
298          cout << v22 << endl;
299       }
300
301 //    tmp
302       printf("---------------------------------------------------------------");
303       printf("\n upper part of circuit %i",idCircuit);
304       printf("\n UMC21                      ");
305       xyval = fXYU[1][2];
306       TBits wu21(16); wu21.Set(16,&xyval);
307       cout << wu21;
308       printf("\n UMC22                      ");
309       xyval = fXYU[1][3];
310       TBits wu22(16); wu22.Set(16,&xyval);
311       cout << wu22;
312       printf("\n lower part of circuit %i",idCircuit);
313       printf("\n LMC21                      ");
314       xyval = fXYD[1][2];
315       TBits wl21(16); wl21.Set(16,&xyval);
316       cout << wl21;
317       printf("\n LMC22                      ");
318       xyval = fXYD[1][3];
319       TBits wl22(16); wl22.Set(16,&xyval);
320       cout << wl22;
321       printf("\n");
322       printf("===============================================================\n");
323    }
324 }
325
326 //___________________________________________
327 void AliMUONLocalTriggerBoard::Conf()
328 {
329    cout << "Switch(" << GetName() << ")" 
330         << " x2d = "           << fSwitch[0] 
331         << " x2m = "           << fSwitch[1] 
332         << " x2u = "           << fSwitch[2] 
333         << " OR[0] = "         << fSwitch[3] 
334         << " OR[1] = "         << fSwitch[4] 
335         << " EN-Y = "          << fSwitch[5] 
336         << " ZERO-ALLY-LSB = " << fSwitch[6] 
337         << " ZERO-down = "     << fSwitch[7] 
338         << " ZERO-middle = "   << fSwitch[8] 
339         << " ZERO-up = "       << fSwitch[9] 
340         << " trans. conn. "    << fTC 
341         << " Slot = "          << fSlot 
342         << endl;
343 }
344
345 //___________________________________________
346 void AliMUONLocalTriggerBoard::Module(char *mod)
347 {
348    const Int_t maxfields = 2; char **fields = new char*[maxfields];
349
350    char s[100]; strcpy(s, GetName());
351
352    Int_t numlines = 0;
353
354    for (char *token = strtok(s, "B");
355         token != NULL;
356         token = strtok(NULL, " "))
357    {
358       fields[numlines] = new char[strlen(token)+1];
359       strcpy(fields[numlines++],token);
360    }
361  
362    strcpy(mod,fields[0]);
363 }
364
365 //___________________________________________
366 void AliMUONLocalTriggerBoard::TrigX(Int_t ch1q[16], Int_t ch2q[16], Int_t ch3q[32], Int_t ch4q[32], 
367                                      Int_t coinc44)
368 {
369 // note : coinc44 = flag 0 or 1 (0 coincidence -> 3/4, 1 coincidence -> 4/4)
370 //---------------------------------------------------------
371 // step # 1 : declustering, reduction DS, calculate sgle & dble
372 //---------------------------------------------------------
373    Int_t ch1e[19], ch2e[20], ch3e[35], ch4e[36]; 
374    Int_t sgleHit1[31], sgleHit2[63];
375    Int_t dbleHit1[31], dbleHit2[63];
376
377    Int_t i;
378    Int_t j;
379    Int_t istrip;
380
381    for (i=0; i<31; i++) {
382       sgleHit1[i]=0;
383       dbleHit1[i]=0;
384    }
385    for (i=0; i<63; i++) {
386       sgleHit2[i]=0;
387       dbleHit2[i]=0;
388    }
389
390 //--- inititialize che using chq 
391    for (i=0; i<19; i++) {
392       if (i<1||i>16)  ch1e[i]=0; 
393       else            ch1e[i]=ch1q[i-1]; 
394    }
395    for (i=0; i<20; i++) {
396       if (i<2||i>17) ch2e[i]=0; 
397       else           ch2e[i]=ch2q[i-2]; 
398    }
399    for (i=0; i<35; i++) {
400       if (i<1||i>32) ch3e[i]=0; 
401       else           ch3e[i]=ch3q[i-1];
402    }
403    for (i=0; i<36; i++) {
404       if (i<2||i>33) ch4e[i]=0; 
405       else           ch4e[i]=ch4q[i-2];
406    }
407
408
409 //--- calculate dble & sgle first station
410    for (i=0; i<=15; i++) {                   
411       sgleHit1[2*i] = (!ch1e[i+1]|(ch1e[i]^ch1e[i+2])) & 
412          (!ch2e[i+2] | (ch2e[i+1]^ch2e[i+3]));
413
414       dbleHit1[2*i] = ch1e[i+1]&!(ch1e[i+2]^ch1e[i]) & 
415          (ch2e[i+2] | (!ch2e[i]&ch2e[i+1]) | (ch2e[i+3]&!ch2e[i+4]));
416    }
417
418    for (i=0; i<=14; i++) {               
419       sgleHit1[2*i+1] = (!ch1e[i+1]|!ch1e[i+2]|(ch1e[i]^ch1e[i+3])) & 
420          (!ch2e[i+2] | !ch2e[i+3] | (ch2e[i+1]^ch2e[i+4]));
421       dbleHit1[2*i+1] = ch1e[i+1]&ch1e[i+2]&!(ch1e[i]^ch1e[i+3]) & 
422          (ch2e[i+2]&(!ch2e[i+1]|!ch2e[i]) | 
423           ch2e[i+3]&(ch2e[i+2]|!ch2e[i+4]|!ch2e[i+5]));
424    }
425
426 //--- calculate dble & sgle second station
427    for (i=0; i<=31; i++) {               
428       sgleHit2[2*i] = (!ch3e[i+1]|(ch3e[i]^ch3e[i+2])) & 
429          (!ch4e[i+2] | (ch4e[i+1]^ch4e[i+3]));
430       dbleHit2[2*i] = ch3e[i+1]&!(ch3e[i+2]^ch3e[i]) & 
431          (ch4e[i+2] | (!ch4e[i]&ch4e[i+1]) | (ch4e[i+3]&!ch4e[i+4]));
432    }
433   
434    for (i=0; i<=30; i++) {               
435       sgleHit2[2*i+1] = (!ch3e[i+1]|!ch3e[i+2]|(ch3e[i]^ch3e[i+3])) & 
436          (!ch4e[i+2] | !ch4e[i+3] | (ch4e[i+1]^ch4e[i+4]));
437       dbleHit2[2*i+1] = ch3e[i+1]&ch3e[i+2]&!(ch3e[i]^ch3e[i+3]) & 
438          (ch4e[i+2]&(!ch4e[i+1]|!ch4e[i]) | 
439           ch4e[i+3]&(ch4e[i+2]|!ch4e[i+4]|!ch4e[i+5]));
440    }
441
442 //--- 
443    if(AliDebugLevel()==3||AliDebugLevel()==5) {
444       printf("===============================================================\n");
445       printf(" X plane after sgle and dble \n");
446       printf("                       0987654321098765432109876543210");
447       printf("\n SGLE1                 ");
448       for (istrip=30; istrip>=0; istrip--) printf("%i",(!sgleHit1[istrip]));
449       printf("\n DBLE1                 ");
450       for (istrip=30; istrip>=0; istrip--) printf("%i",dbleHit1[istrip]);
451       printf("\n SGLE2 ");
452       for (istrip=62; istrip>=0; istrip--) printf("%i",(!sgleHit2[istrip]));
453       printf("\n DBLE2 ");
454       for (istrip=62; istrip>=0; istrip--) printf("%i",dbleHit2[istrip]);
455       printf("\n       210987654321098765432109876543210987654321098765432109876543210\n");
456    }
457   
458 //---------------------------------------------------------
459 // step # 2 : coincidence 3/4
460 //---------------------------------------------------------
461    Int_t rearImage[31][31];
462    for (i=0; i<31; i++) {
463       for (j=0; j<31; j++) {
464          rearImage[i][j]=0;
465       }
466    }
467
468    Int_t notOr1=!dbleHit1[30] & !dbleHit1[29] & !dbleHit1[28] & !dbleHit1[27] & 
469       !dbleHit1[26] & !dbleHit1[25] & !dbleHit1[24] & !dbleHit1[23] &
470       !dbleHit1[22] & !dbleHit1[21] & !dbleHit1[20] & !dbleHit1[19] & 
471       !dbleHit1[18] & !dbleHit1[17] & !dbleHit1[16] & !dbleHit1[15] & 
472       !dbleHit1[14] & !dbleHit1[13] & !dbleHit1[12] & !dbleHit1[11] & 
473       !dbleHit1[10] & !dbleHit1[9]  & !dbleHit1[8]  & !dbleHit1[7]  & 
474       !dbleHit1[6]  & !dbleHit1[5]  & !dbleHit1[4]  & !dbleHit1[3]  & 
475       !dbleHit1[2]  & !dbleHit1[1]  & !dbleHit1[0]  & !coinc44;
476
477    Int_t notOr2= !dbleHit2[62] & !dbleHit2[61] & !dbleHit2[60] & !dbleHit2[59] & 
478       !dbleHit2[58] & !dbleHit2[57] & !dbleHit2[56] & !dbleHit2[55] & 
479       !dbleHit2[54] & !dbleHit2[53] & !dbleHit2[52] & !dbleHit2[51] & 
480       !dbleHit2[50] & !dbleHit2[49] & !dbleHit2[48] & !dbleHit2[47] & 
481       !dbleHit2[46] & !dbleHit2[45] & !dbleHit2[44] & !dbleHit2[43] & 
482       !dbleHit2[42] & !dbleHit2[41] & !dbleHit2[40] & !dbleHit2[39] & 
483       !dbleHit2[38] & !dbleHit2[37] & !dbleHit2[36] & !dbleHit2[35] & 
484       !dbleHit2[34] & !dbleHit2[33] & !dbleHit2[32] & !dbleHit2[31] &
485       !dbleHit2[30] & !dbleHit2[29] & !dbleHit2[28] & !dbleHit2[27] & 
486       !dbleHit2[26] & !dbleHit2[25] & !dbleHit2[24] & !dbleHit2[23] & 
487       !dbleHit2[22] & !dbleHit2[21] & !dbleHit2[20] & !dbleHit2[19] & 
488       !dbleHit2[18] & !dbleHit2[17] & !dbleHit2[16] & !dbleHit2[15] & 
489       !dbleHit2[14] & !dbleHit2[13] & !dbleHit2[12] & !dbleHit2[11] & 
490       !dbleHit2[10] & !dbleHit2[9]  & !dbleHit2[8]  & !dbleHit2[7]  & 
491       !dbleHit2[6]  & !dbleHit2[5]  & !dbleHit2[4]  & !dbleHit2[3]  & 
492       !dbleHit2[2]  & !dbleHit2[1]  & !dbleHit2[0]  & !coinc44; 
493
494 // DS reduction
495    for (i=0; i<31; i++) {
496       sgleHit1[i] = !sgleHit1[i]&notOr1;
497    }
498    for (i=0; i<63; i++) {
499       sgleHit2[i] = !sgleHit2[i]&notOr2;
500    }
501
502 // extract rearImage
503    for (i=0; i<31; i++){
504       Int_t tmpSgleHit2[31];
505       Int_t tmpDbleHit2[31];
506       for (j=0; j<31; j++){
507          tmpSgleHit2[j] = sgleHit2[i+j+1];
508          tmpDbleHit2[j] = dbleHit2[i+j+1];
509       }
510
511       for (Int_t k=0; k<31; k++) {
512          rearImage[i][k]=(sgleHit1[i]&tmpDbleHit2[k])|
513             (dbleHit1[i]&(tmpSgleHit2[k]|tmpDbleHit2[k]));
514       }
515    }
516
517    //-----------
518    if(AliDebugLevel()==3||AliDebugLevel()==5) {
519       printf("===============================================================\n");
520       for (i=30; i>=0; i--) {
521          printf("%i \t",i);
522          for (istrip=31; istrip>=0; istrip--) printf("%i",rearImage[i][istrip]);
523          printf("\n");   
524       }
525    }
526
527 //---------------------------------------------------------
528 // step # 3 : calculate deviation
529 //--------------------------------------------------------- 
530    Int_t dev[31][6];
531    for (i=0; i<31; i++) {
532       for (j=0; j<6; j++) {
533          dev[i][j]=0;
534       }
535    }
536
537    for (i=0; i<31; i++){
538       Int_t leftDev[5], rightDev[5]; 
539       Int_t orL1, andL1, andL2, orR1, orR2, andR1, andR2, andR3;
540
541 // calculate Left deviation
542       orL1=rearImage[i][16]|rearImage[i][18]|rearImage[i][20]|rearImage[i][22];
543       andL1=!rearImage[i][17]&!rearImage[i][19]&!rearImage[i][21] & !orL1; 
544       andL2=!rearImage[i][23]&!rearImage[i][24]&!rearImage[i][25]&!rearImage[i][26];
545  
546       leftDev[0] = (rearImage[i][16]|!rearImage[i][17]) & 
547          (rearImage[i][16]|rearImage[i][18]|!rearImage[i][19]&
548           (rearImage[i][20]|!rearImage[i][21])) &
549          (orL1|!rearImage[i][23]&(rearImage[i][24]|!rearImage[i][25])) & 
550          (orL1|rearImage[i][24]|rearImage[i][26]|!rearImage[i][27]&
551           (rearImage[i][28]|!rearImage[i][29]));
552                                 
553       leftDev[1] = !rearImage[i][16] & 
554          !(!rearImage[i][17]&!rearImage[i][18]&!rearImage[i][21]&!rearImage[i][22] & 
555            (!rearImage[i][25]&!rearImage[i][26]&(rearImage[i][27]|rearImage[i][28]))) &
556          (rearImage[i][17]|rearImage[i][18] | !rearImage[i][19]&!rearImage[i][20]) &
557          (rearImage[i][17]|rearImage[i][18]|rearImage[i][21]|rearImage[i][22] | 
558           !rearImage[i][23]&!rearImage[i][24]);
559                                 
560       leftDev[2] = (!rearImage[i][16]&!rearImage[i][17]&!rearImage[i][18]) & 
561          (rearImage[i][19]|rearImage[i][20]|rearImage[i][21]|rearImage[i][22] | andL2);
562                 
563       leftDev[3] = andL1;
564                 
565       leftDev[4] = 
566          !rearImage[i][27]&!rearImage[i][28]&!rearImage[i][29]&!rearImage[i][30] & 
567          andL1 & andL2;
568
569       // calculate Right deviation
570       orR1=rearImage[i][8]|rearImage[i][10]|rearImage[i][12]|rearImage[i][14];
571       orR2=rearImage[i][8]|rearImage[i][9]|rearImage[i][10]|rearImage[i][11];
572       andR1=!rearImage[i][12]&!rearImage[i][13]&!rearImage[i][14]&!rearImage[i][15];
573       andR2=
574          !rearImage[i][8]&!rearImage[i][9]&!rearImage[i][10]&!rearImage[i][11] & andR1;
575       andR3=!rearImage[i][4]&!rearImage[i][5]&!rearImage[i][6]&!rearImage[i][7]; 
576                 
577       rightDev[0] = !rearImage[i][15]&(rearImage[i][14]|!rearImage[i][13]) & 
578          ((rearImage[i][12]|rearImage[i][14]|!rearImage[i][11]&
579            (rearImage[i][10]|!rearImage[i][9])) &
580           ((orR1|!rearImage[i][7]&(rearImage[i][6]|!rearImage[i][5])) & 
581            (orR1|rearImage[i][4]|rearImage[i][6]|!rearImage[i][3]&(rearImage[i][2]|
582                                                                    !rearImage[i][1]))));
583                                 
584       rightDev[1] = !rearImage[i][15]&!rearImage[i][14] & 
585          !(!rearImage[i][4]&!rearImage[i][5]&!rearImage[i][8]&!rearImage[i][9] &
586            (!rearImage[i][12]&!rearImage[i][13]&(rearImage[i][2]|rearImage[i][3]))) &
587          (rearImage[i][12]|rearImage[i][13] | !rearImage[i][10]&!rearImage[i][11]) & 
588          (rearImage[i][8]|rearImage[i][9]|rearImage[i][12]|rearImage[i][13] | 
589           !rearImage[i][6]&!rearImage[i][7]);
590                 
591       rightDev[2] = andR1 & (orR2 | andR3); 
592       rightDev[3] = andR2;              
593       rightDev[4] = 
594          !rearImage[i][0]&!rearImage[i][1]&!rearImage[i][2]&!rearImage[i][3] & 
595          andR2 & andR3 ;
596
597       // compare Left & Right deviations
598       Int_t tmpLeftDev=0, tmpRightDev=0;
599       for (j=0; j<5; j++){
600          tmpLeftDev  = tmpLeftDev + Int_t(leftDev[j]<<j); 
601          tmpRightDev = tmpRightDev + Int_t(rightDev[j]<<j); 
602       }
603
604       // assign mimimum deviation do dev[][]
605       if (tmpLeftDev < tmpRightDev ){
606          for (j=0; j<5; j++){ dev[i][j]=leftDev[j];}
607          dev[i][5]=1;
608       } else {
609          for (j=0; j<5; j++){ dev[i][j]=rightDev[j];}
610          dev[i][5]=0;
611       }
612    }
613   
614 //---
615    if(AliDebugLevel()==3||AliDebugLevel()==5) {
616       printf("===============================================================\n");
617       for (i=30; i>=0; i--) {
618          printf("%i \t",i);
619          for (istrip=5; istrip>=0; istrip--) printf("%i",dev[i][istrip]);
620          printf(" \n");
621       }
622    }
623
624 //---------------------------------------------------------
625 // step # 4 : sort deviation
626 //--------------------------------------------------------- 
627    Int_t bga1[16], bga2[8], bga3[4], bga4[2], bga5;
628    Int_t tmpbga1[16][6], tmpbga2[8][6], tmpbga3[4][6], tmpbga4[2][6], tmpbga5[6];
629    Int_t tmpMax[6]={1,1,1,1,1,0};
630
631    for (i=0; i<15; i++) {
632       Sort2x5(dev[2*i],dev[2*i+1],tmpbga1[i],bga1[i]);
633    }  
634    Sort2x5(dev[30],tmpMax,tmpbga1[15],bga1[15]);
635
636 //--    
637    if(AliDebugLevel()==3||AliDebugLevel()==5) {
638       printf("===============================================================\n");
639       printf(" sorting : 1st level \n");
640       for (i=15; i>=0; i--) {
641          printf("\t %i \t",bga1[i]);    
642          for (j=5; j>=0; j--) printf("%i",tmpbga1[i][j]); 
643          printf(" \n");
644       }
645    }
646
647    for (i=0; i<8; i++) {  
648       Sort2x5(tmpbga1[2*i],tmpbga1[2*i+1],tmpbga2[i],bga2[i]);
649    }
650
651 //--    
652    if(AliDebugLevel()==3||AliDebugLevel()==5) {
653       printf("===============================================================\n");
654       printf(" sorting : 2nd level \n");
655       for (i=7; i>=0; i--) {
656          printf("\t %i \t",bga2[i]);    
657          for (j=5; j>=0; j--) printf("%i",tmpbga1[i][j]);       
658          printf(" \n");
659       }
660    }
661   
662    for (i=0; i<4; i++) {  
663       Sort2x5(tmpbga2[2*i],tmpbga2[2*i+1],tmpbga3[i],bga3[i]);
664    }
665
666 //--    
667    if(AliDebugLevel()==3||AliDebugLevel()==5) {
668       printf("===============================================================\n");
669       printf(" sorting : 3rd level \n");
670       for (i=3; i>=0; i--) {
671          printf("\t %i \t",bga3[i]);    
672          for (j=5; j>=0; j--) printf("%i",tmpbga3[i][j]); 
673          printf(" \n");
674       }
675    }
676
677    for (i=0; i<2; i++) {  
678       Sort2x5(tmpbga3[2*i],tmpbga3[2*i+1],tmpbga4[i],bga4[i]);
679    }
680
681 //--    
682    if(AliDebugLevel()==3||AliDebugLevel()==5) {
683       printf("===============================================================\n");
684       printf(" sorting : 4th level \n");
685       for (i=1; i>=0; i--) {
686          printf("\t %i \t",bga4[i]);    
687          for (j=5; j>=0; j--) printf("%i",tmpbga4[i][j]);
688          printf(" \n");
689       }
690    }
691   
692    Sort2x5(tmpbga4[0],tmpbga4[1],tmpbga5,bga5);
693
694    // coding from 6 to 5 bits 
695    fMinDev[4] = tmpbga5[5] | tmpbga5[4];
696    for (i=0; i<4; i++) { 
697       fMinDev[i]=tmpbga5[i] & !tmpbga5[4];
698    }
699
700    // find address of strip with minimum deviation 
701    fMinDevStrip[4]=bga5;
702    if (bga5<=1) fMinDevStrip[3]=bga4[bga5];
703
704    Int_t tmpAd=fMinDevStrip[3]+fMinDevStrip[4]*2;
705    if (tmpAd<=3) fMinDevStrip[2]=bga3[tmpAd];
706
707    tmpAd=fMinDevStrip[2]+fMinDevStrip[3]*2+fMinDevStrip[4]*4;
708    if (tmpAd<=7) fMinDevStrip[1]=bga2[tmpAd];
709
710    tmpAd=fMinDevStrip[1]+fMinDevStrip[2]*2+fMinDevStrip[3]*4+fMinDevStrip[4]*8;
711    if (tmpAd<=15) fMinDevStrip[0]=bga1[tmpAd];
712
713    if(AliDebugLevel()==3||AliDebugLevel()==5) {
714       printf("===============================================================\n");
715       printf("minDevStrip = ");
716       for  (i=4; i>=0; i--) printf("%i",fMinDevStrip[i]);
717       printf(" minDev = ");
718       for  (i=4; i>=0; i--) printf("%i",fMinDev[i]); 
719       printf(" \n");
720       printf("===============================================================\n");
721    }
722
723 }
724
725 //___________________________________________
726 void AliMUONLocalTriggerBoard::Sort2x5(Int_t dev1[6], Int_t dev2[6],
727                                        Int_t minDev[6], Int_t &dev1GTdev2)
728
729 // returns minimun between dev1 and dev2
730    Int_t tmpDev1=0, tmpDev2=0;
731
732    for (Int_t j=0; j<5; j++)
733    {
734       tmpDev1 += Int_t(dev1[j]<<j); 
735       tmpDev2 += Int_t(dev2[j]<<j); 
736    }
737
738    if (tmpDev1<=tmpDev2)
739    {
740       for (Int_t j=0; j<=5; j++) minDev[j]=dev1[j];
741       dev1GTdev2=0;
742    } 
743    else 
744    {
745       for (Int_t j=0; j<=5; j++) minDev[j]=dev2[j];
746       dev1GTdev2=1;   
747    }
748 }
749
750 //___________________________________________
751 void AliMUONLocalTriggerBoard::TrigY(Int_t y1[16], Int_t y2[16], Int_t y3[16], Int_t y4[16],
752                                      Int_t y3u[16], Int_t y3d[16], Int_t y4u[16], Int_t y4d[16],
753                                      Int_t coinc44)
754 {
755 // note : resMid = 1 -> cancel 
756 //---------------------------------------------------------
757 // step # 1 : prehandling Y
758 //--------------------------------------------------------- 
759    Int_t i;
760    Int_t istrip;
761
762    for (i=0; i<16; i++)
763    {
764       y3[i]=y3[i]&!fSwitch[8];
765       y4[i]=y4[i]&!fSwitch[8];
766    }
767
768 // 10/29/04 fZeroAllYLSB added
769 //    for (i=0; i<8; i++)
770 //    {
771 //       y1[i] = y1[i]&!fSwitch[6];     
772 //       y2[i] = y2[i]&!fSwitch[6];      
773 //       y3[i] = y3[i]&!fSwitch[6];      
774 //       y4[i] = y4[i]&!fSwitch[6];
775 //    }
776
777    Int_t ch1[16], ch2[16], ch3[16], ch4[16];
778
779    Int_t tmpy3to16[16], tmpy4to16[16];
780    Int_t tmpy3uto16[16], tmpy3dto16[16], tmpy4uto16[16], tmpy4dto16[16];
781    for (i=0; i<8; i++){
782       ch1[2*i]   = y1[i]&fSwitch[1] | y1[2*i]&!fSwitch[1];              
783       ch1[2*i+1] = y1[i]&fSwitch[1] | y1[2*i+1]&!fSwitch[1];
784
785       ch2[2*i]   = y2[i]&fSwitch[1] | y2[2*i]&!fSwitch[1];              
786       ch2[2*i+1] = y2[i]&fSwitch[1] | y2[2*i+1]&!fSwitch[1];
787
788       tmpy3to16[2*i  ] = y3[i]&fSwitch[1] | y3[2*i  ]&!fSwitch[1];              
789       tmpy3to16[2*i+1] = y3[i]&fSwitch[1] | y3[2*i+1]&!fSwitch[1];
790
791       tmpy4to16[2*i  ] = y4[i]&fSwitch[1] | y4[2*i  ]&!fSwitch[1];
792       tmpy4to16[2*i+1] = y4[i]&fSwitch[1] | y4[2*i+1]&!fSwitch[1];
793
794       tmpy3uto16[2*i  ] = y3u[i]&fSwitch[2] | y3u[2*i  ]&!fSwitch[2]; 
795       tmpy3uto16[2*i+1] = y3u[i]&fSwitch[2] | y3u[2*i+1]&!fSwitch[2];
796
797       tmpy4uto16[2*i  ] = y4u[i]&fSwitch[2] | y4u[2*i  ]&!fSwitch[2]; 
798       tmpy4uto16[2*i+1] = y4u[i]&fSwitch[2] | y4u[2*i+1]&!fSwitch[2];
799
800       tmpy3dto16[2*i  ] = y3d[i]&fSwitch[0] | y3d[2*i  ]&!fSwitch[0]; 
801       tmpy3dto16[2*i+1] = y3d[i]&fSwitch[0] | y3d[2*i+1]&!fSwitch[0];
802     
803       tmpy4dto16[2*i  ] = y4d[i]&fSwitch[0] | y4d[2*i  ]&!fSwitch[0]; 
804       tmpy4dto16[2*i+1] = y4d[i]&fSwitch[0] | y4d[2*i+1]&!fSwitch[0];
805    }
806   
807    if (fSwitch[3]==0&&fSwitch[4]==0){
808       for (i=0; i<16; i++){
809          ch3[i] = tmpy3to16[i];
810          ch4[i] = tmpy4to16[i];
811       }
812    }
813    if (fSwitch[3]==0&&fSwitch[4]==1){
814       for (i=0; i<16; i++){
815          ch3[i] = tmpy3dto16[i]|tmpy3to16[i];
816          ch4[i] = tmpy4dto16[i]|tmpy4to16[i];
817       }
818    }
819    if (fSwitch[3]==1&&fSwitch[4]==0){
820       for (i=0; i<16; i++){
821          ch3[i] = tmpy3uto16[i]|tmpy3to16[i];
822          ch4[i] = tmpy4uto16[i]|tmpy4to16[i];
823       }
824    }
825    if (fSwitch[3]==1&&fSwitch[4]==1){
826       for (i=0; i<16; i++){
827          ch3[i] = tmpy3dto16[i]|tmpy3to16[i]|tmpy3uto16[i];
828          ch4[i] = tmpy4dto16[i]|tmpy4to16[i]|tmpy4uto16[i];
829       }
830    }
831
832 // debug
833    if(AliDebugLevel()==4||AliDebugLevel()==5) {
834       printf("===============================================================\n");  
835       printf(" Y plane after PreHandling x2m x2u x2d orMud %i %i %i %i %i \n",
836              fSwitch[1],fSwitch[2], fSwitch[0],fSwitch[3],fSwitch[4]);
837       printf("                            ");
838       for (istrip=15; istrip>=0; istrip--) {
839          if (istrip>9)  printf("%i",istrip-10*Int_t(istrip/10));
840          if (istrip<10) printf("%i",istrip);
841       }  
842       printf("\n YMC11                      ");
843       for (istrip=15; istrip>=0; istrip--) printf("%i",ch1[istrip]); 
844       printf("\n YMC12                      ");
845       for (istrip=15; istrip>=0; istrip--) printf("%i",ch2[istrip]); 
846       printf("\n YMC21                      ");
847       for (istrip=15; istrip>=0; istrip--) printf("%i",ch3[istrip]); 
848       printf("\n YMC22                      ");
849       for (istrip=15; istrip>=0; istrip--) printf("%i",ch4[istrip]); 
850       printf(" \n"); 
851    }
852 //debug
853   
854 //---------------------------------------------------------
855 // step # 2 : calculate sgle and dble, apply DS reduction
856 //--------------------------------------------------------- 
857    Int_t sgle1[16], dble1[16];
858    Int_t sgle2[16], dble2[16];
859
860    // Calculate simple and double hits
861    for (i=0; i<16; i++) {
862       dble1[i] = ch1[i] & ch2[i];
863       dble2[i] = ch3[i] & ch4[i];
864     
865       sgle1[i] = (ch1[i]|ch2[i]);
866       sgle2[i] = (ch3[i]|ch4[i]);
867    }
868
869    //debug
870    if(AliDebugLevel()==4||AliDebugLevel()==5) {
871       printf("===============================================================\n");
872       printf(" Y plane after sgle dble \n"); 
873       printf("                            ");
874       for (istrip=15; istrip>=0; istrip--) {
875          if (istrip>9)  printf("%i",istrip-10*Int_t(istrip/10));
876          if (istrip<10) printf("%i",istrip);
877       }  
878       printf("\n SGLE1                      ");
879       for (istrip=15; istrip>=0; istrip--) printf("%i",sgle1[istrip]); 
880       printf("\n DBLE1                      ");
881       for (istrip=15; istrip>=0; istrip--) printf("%i",dble1[istrip]); 
882       printf("\n SGLE2                      ");
883       for (istrip=15; istrip>=0; istrip--) printf("%i",sgle2[istrip]); 
884       printf("\n DBLE2                      ");
885       for (istrip=15; istrip>=0; istrip--) printf("%i",dble2[istrip]); 
886       printf(" \n"); 
887    }
888    //debug
889
890    // DS Reduction 
891    Int_t notOr1, notOr2;
892
893    notOr1=!dble1[15] & !dble1[14] & !dble1[13] & !dble1[12] & 
894       !dble1[11] & !dble1[10] & !dble1[9]  & !dble1[8]  & 
895       !dble1[7]  & !dble1[6]  & !dble1[5]  & !dble1[4]  & 
896       !dble1[3]  & !dble1[2]  & !dble1[1]  & !dble1[0];
897
898    notOr2=!dble2[15] & !dble2[14] & !dble2[13] & !dble2[12] & 
899       !dble2[11] & !dble2[10] & !dble2[9]  & !dble2[8]  & 
900       !dble2[7]  & !dble2[6]  & !dble2[5]  & !dble2[4]  & 
901       !dble2[3]  & !dble2[2]  & !dble2[1]  & !dble2[0];
902
903    for (i=0; i<16; i++) {
904       sgle1[i] = sgle1[i] & notOr1 & !coinc44;
905       sgle2[i] = sgle2[i] & notOr2 & !coinc44;
906    }
907
908 //---------------------------------------------------------
909 // step # 3 : 3/4 coincidence 
910 //--------------------------------------------------------- 
911    Int_t frontImage[16];
912
913    for (i=1; i<15; i++) {
914       frontImage[i] = (dble1[i] | sgle1[i]) & 
915          (dble2[i+1] | dble2[i] | dble2[i-1]) |
916          dble1[i] & (sgle2[i+1] | sgle2[i] | sgle2[i-1]);
917    }
918    frontImage[0] = (dble1[0] | sgle1[0]) & 
919       (dble2[1] | dble2[0]) | dble1[0] & (sgle2[1] | sgle2[0]);
920
921    frontImage[15] = (dble1[15] | sgle1[15]) & 
922       (dble2[15] | dble2[14]) | dble1[15] & (sgle2[15] | sgle2[14]);
923
924
925 //debug
926    if(AliDebugLevel()==4||AliDebugLevel()==5) {
927       printf("===============================================================\n");
928       printf(" Y plane frontImage\n");
929       printf("                            ");
930       for (istrip=15; istrip>=0; istrip--) {
931          if (istrip>9)  printf("%i",istrip-10*Int_t(istrip/10));
932          if (istrip<10) printf("%i",istrip);
933       }
934       printf("\n                            ");
935       for (istrip=15; istrip>=0; istrip--) printf("%i",frontImage[istrip]); 
936       printf("\n");
937    }
938 //debug
939
940 //---------------------------------------------------------
941 // step # 4 : Y position 
942 //--------------------------------------------------------- 
943    Int_t or1, or2, and1, and2, and3;
944
945    or1  = frontImage[7]|frontImage[5]|frontImage[3]|frontImage[1];
946    or2  = frontImage[7]|frontImage[6]|frontImage[5]|frontImage[4];
947    and1 = !frontImage[3]&!frontImage[2]&!frontImage[1]&!frontImage[0];
948    and2 = !frontImage[7]&!frontImage[6]&!frontImage[5]&!frontImage[4] & and1;
949    and3 = !frontImage[11]&!frontImage[10]&!frontImage[9]&!frontImage[8]; 
950  
951    fCoordY[0] = !frontImage[0]&(frontImage[1]|!frontImage[2]) & 
952       (frontImage[3]|frontImage[1]|!frontImage[4]&(frontImage[5]|!frontImage[6])) &
953       (or1|!frontImage[8]&(frontImage[9]|!frontImage[10])) & 
954       (or1|frontImage[11]|frontImage[9]|!frontImage[12]&(frontImage[13]|!frontImage[14]));
955  
956    fCoordY[1] = !frontImage[0]&!frontImage[1] & 
957       !(!frontImage[11]&!frontImage[10]&!frontImage[7]&!frontImage[6] & 
958         !frontImage[3]&!frontImage[2]&(frontImage[13]|frontImage[12])) &
959       (frontImage[3]|frontImage[2] | !frontImage[5]&!frontImage[4]) & 
960       (frontImage[7]|frontImage[6]|frontImage[3]|frontImage[2] | 
961        !frontImage[9]&!frontImage[8]);
962                 
963    fCoordY[2] = and1 & (or2 | and3);
964                 
965    fCoordY[3] = and2;
966                 
967    fCoordY[4] = !frontImage[15]&!frontImage[14]&!frontImage[13]&!frontImage[12] &
968       and2 & and3 ;
969 }
970
971 //___________________________________________
972 void AliMUONLocalTriggerBoard::LocalTrigger()
973 {
974    Int_t deviation=0, iStripY=0;
975
976    for (Int_t i=0; i<4; i++) deviation += static_cast<int>( fMinDev[i] << i );
977    for (Int_t i=0; i<4; i++) iStripY   += static_cast<int>( fCoordY[i] << i );
978
979    if (fMinDev[4]==1 && !deviation) fOutput=0;     // No trigger
980    else 
981    {
982       if (fCoordY[4]==1 && iStripY==15) fOutput=0; // No trigger
983       else 
984          fOutput=1;
985    }
986   
987    if (fOutput) 
988    { 
989       for (Int_t i=0; i<5; i++) fStripX11 += static_cast<int>( fMinDevStrip[i] << i );
990
991       fDev      = deviation;
992
993                 fStripY11 = iStripY;
994                 
995                 if ( fSwitch[1] && 
996                           (fSwitch[0] || fSwitch[2]) && 
997                           !(!fSwitch[0] && fSwitch[4]) && 
998                           !(!fSwitch[2] && fSwitch[3]) ) fStripY11 /= 2;
999
1000       Int_t sign = 0;
1001
1002       if ( !fMinDev[4] &&  deviation ) sign=-1;
1003       if ( !fMinDev[4] && !deviation ) sign= 0;
1004       if (  fMinDev[4]==1)             sign=+1;    
1005
1006       fDev *= sign; 
1007
1008 //    calculate deviation in [0;+30]
1009       fDev += 15;
1010
1011       Int_t icirc = GetI();
1012
1013 //    LEFT SHIFT OF ZERO-ALLY-LSB BOARDS TO ACCESS TO LUT
1014                 if (GetSwitch(6)) fStripY11 -= 8;
1015
1016 //    GET LUT OUTPUT FOR icirc/istripX1/deviation/istripY
1017       fLUT->GetLutOutput(icirc, fStripX11, fDev, fStripY11, fLutLpt, fLutHpt, fLutApt);
1018    }  
1019 }
1020
1021 //___________________________________________
1022 Int_t AliMUONLocalTriggerBoard::GetI()
1023 {
1024    const Int_t maxfields = 2; char **fields = new char*[maxfields];
1025
1026    char s[100]; strcpy(s, GetName());
1027
1028    Int_t numlines = 0;
1029
1030    for (char *token = strtok(s, "B");
1031         token != NULL;
1032         token = strtok(NULL, " "))
1033    {
1034       fields[numlines] = new char[strlen(token)+1];
1035       strcpy(fields[numlines++], token);
1036    }
1037
1038    TString l(fields[0]);
1039
1040    char copy = l[0];
1041
1042    Int_t L = atoi(&l[4]), C = atoi(&l[2]), S = (copy=='R') ? +1 : -1;
1043
1044    char *b[4] = {"12", "34", "56", "78"};
1045
1046    Int_t ib = 0;
1047
1048    for (Int_t i=0; i<4; i++) if (!strcmp(fields[1],b[i])) {ib = i; break;} ib++;
1049
1050 // L=1 ON TOP
1051    L -= 9; L = abs(L); L++;
1052
1053    Int_t code = 100 * L + 10 * C + ib;
1054
1055    code *= S;
1056
1057    Int_t ic = 0;
1058
1059    for (Int_t i=0; i<234; i++) if (AliMUONTriggerConstants::CircuitId(i) == code) {ic = i; break;}
1060
1061    return ic;
1062 }
1063
1064 //___________________________________________
1065 void AliMUONLocalTriggerBoard::Mask(UShort_t M[2][4])
1066 {
1067    for (Int_t i=0; i<2; i++)
1068       for (Int_t j=0; j<4; j++)
1069          fMask[i][j] = M[i][j];
1070 }
1071
1072 //___________________________________________
1073 void AliMUONLocalTriggerBoard::Scan(Option_t *option)
1074 {
1075    TString op = option;
1076
1077    if (op.Contains("CONF")) Conf();
1078
1079    if (op.Contains("BITP")) Pattern();
1080
1081    if (op.Contains("RESPI")) Resp("I");
1082
1083    if (op.Contains("RESPF")) Resp("F"); 
1084
1085    if (op.Contains("ALL"))
1086    {
1087       Conf();
1088       Pattern();
1089       Resp("I");
1090       Resp("F");
1091    }
1092 }
1093
1094 //___________________________________________
1095 void AliMUONLocalTriggerBoard::Resp(Option_t *option)
1096 {
1097    TString op = option;
1098
1099    if (op.Contains("I"))
1100    {
1101 //    print Local trigger output before the LuT step
1102       printf("===============================================================\n");
1103       printf("-------- TRIGGER OUTPUT --------\n");
1104       printf("minDevStrip = ");
1105       for  (Int_t i=4; i>=0; i--) printf("%i",fMinDevStrip[i]);
1106       printf(" minDev = ");
1107       for  (Int_t i=4; i>=0; i--) printf("%i",fMinDev[i]);
1108       printf(" coordY = ");
1109       for  (Int_t i=4; i>=0; i--) printf("%i",fCoordY[i]); 
1110       printf(" \n");
1111    }
1112
1113    if (op.Contains("F"))
1114    {
1115       Int_t icirc = GetI();
1116       Int_t idCircuit = AliMUONTriggerConstants::CircuitId(icirc);
1117
1118       Int_t deviation = 0, iStripY = 0;
1119
1120       for (Int_t i=0; i<4; i++) iStripY   += static_cast<int>( fCoordY[i] << i );
1121
1122       for (Int_t i=0; i<4; i++) deviation += Int_t(fMinDev[i]<<i);   
1123
1124       Float_t pt = 0.; //triggerCircuit->PtCal(fStripX11, fDev, fStripY11);
1125       printf("-------------------------------------------\n");
1126       printf(" Local Trigger info for circuit Id %i (number %i ) \n", idCircuit, icirc);
1127       printf(" istripX1 signDev deviation istripY = %i %i %i %i \n", fStripX11, fMinDev[4], deviation, iStripY);
1128       printf(" pt = %f  (GeV/c) \n", pt);
1129       printf("-------------------------------------------\n");
1130       printf(" Local Trigger Lut Output = Lpt : ");
1131       for (Int_t i=1; i>=0; i--) printf("%i", fLutLpt[i]);
1132       printf(" Hpt : ");
1133       for (Int_t i=1; i>=0; i--) printf("%i", fLutHpt[i]);
1134       printf(" Apt : ");
1135       for (Int_t i=1; i>=0; i--) printf("%i", fLutApt[i]);
1136       printf("\n");
1137       printf("-------------------------------------------\n");
1138    }      
1139 //    else
1140 //    {
1141       
1142 //    }
1143 }
1144
1145 //___________________________________________
1146 void AliMUONLocalTriggerBoard::Mask(char *chan, UShort_t M)
1147 {
1148    char *cath[2] = {"X", "Y"};
1149    
1150    char *cham[4] = {"1", "2", "3", "4"};
1151    
1152    for (Int_t i=0; i<2; i++)
1153       for (Int_t j=0; j<4; j++) 
1154       {
1155          strcat(cath[i],cham[j]);
1156
1157          if (!strcmp(cath[i],chan)) fMask[i][j] = M;
1158       }
1159 }
1160
1161 //___________________________________________
1162 void AliMUONLocalTriggerBoard::Response()
1163 {
1164    Int_t X1[16], X2[16], XX3[32], XX4[32];
1165
1166    TBits x1(16), x2(16), x3(16), x4(16);
1167
1168    UShort_t xyv = 0;
1169
1170    xyv = fXY[0][0]; x1.Set(16,&xyv);
1171    xyv = fXY[0][1]; x2.Set(16,&xyv);
1172    xyv = fXY[0][2]; x3.Set(16,&xyv);
1173    xyv = fXY[0][3]; x4.Set(16,&xyv);
1174
1175    TBits x3u(16), x4u(16), x3d(16), x4d(16);
1176
1177    xyv = fXYU[0][2]; x3u.Set(16,&xyv);
1178    xyv = fXYU[0][3]; x4u.Set(16,&xyv);
1179
1180    xyv = fXYD[0][2]; x3d.Set(16,&xyv);
1181    xyv = fXYD[0][3]; x4d.Set(16,&xyv);
1182
1183    for (Int_t i=0;i<16;i++)
1184    {
1185       X1[i] = x1[i];
1186       X2[i] = x2[i];
1187       
1188       XX3[i+8] = x3[i];
1189       XX4[i+8] = x4[i];  
1190    }
1191
1192    for (Int_t i=0;i<8;i++)
1193    {
1194       XX3[i] = x3d[i+8];
1195       XX4[i] = x4d[i+8];
1196
1197       XX3[i+24] = x3u[i];
1198       XX4[i+24] = x4u[i];
1199    }
1200    
1201    Int_t coinc44 = 0;
1202    
1203    TrigX(X1, X2, XX3, XX4, coinc44);   
1204
1205    Int_t Y1[16], Y2[16], Y3[16], Y4[16];
1206    
1207    Int_t Y3U[16], Y3D[16], Y4U[16], Y4D[16];
1208
1209    TBits y1(16), y2(16), y3(16), y4(16);
1210
1211    TBits y3u(16), y3d(16), y4u(16), y4d(16);
1212
1213    xyv = fXY[1][0]; y1.Set(16,&xyv);
1214    xyv = fXY[1][1]; y2.Set(16,&xyv);
1215    xyv = fXY[1][2]; y3.Set(16,&xyv);
1216    xyv = fXY[1][3]; y4.Set(16,&xyv);
1217
1218    xyv = fXYU[1][2]; y3u.Set(16,&xyv);
1219    xyv = fXYD[1][2]; y3d.Set(16,&xyv);
1220    xyv = fXYU[1][3]; y4u.Set(16,&xyv);
1221    xyv = fXYD[1][3]; y4d.Set(16,&xyv);
1222
1223    for (Int_t i=0;i<16;i++)
1224    {
1225       Y1[i] = y1[i];
1226       Y2[i] = y2[i];
1227       Y3[i] = y3[i];
1228       Y4[i] = y4[i];
1229       
1230       Y3U[i] = y3u[i];
1231       Y3D[i] = y3d[i];
1232       
1233       Y4U[i] = y4u[i];
1234       Y4D[i] = y4d[i];
1235    }
1236
1237    TrigY(Y1, Y2, Y3, Y4, Y3U, Y3D, Y4U, Y4D, coinc44);
1238    
1239 // ASIGN fLutLpt, fLutHpt, fLutApt
1240    LocalTrigger(); 
1241
1242    fResponse = fLutApt[0]                      + 
1243                static_cast<int>(fLutApt[1]<<1) + 
1244                static_cast<int>(fLutLpt[0]<<2) + 
1245                static_cast<int>(fLutLpt[1]<<3) + 
1246                static_cast<int>(fLutHpt[0]<<4) + 
1247                static_cast<int>(fLutHpt[1]<<5);
1248 }
1249
1250 ClassImp(AliMUONLocalTriggerBoard)
1251