]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerDecision.cxx
includes cleanup
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerDecision.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 $Log$
17 Revision 1.6  2001/01/26 21:57:09  morsch
18 Use access functions to AliMUONDigit member data.
19
20 Revision 1.5  2000/10/02 16:58:29  egangler
21 Cleaning of the code :
22 -> coding conventions
23 -> void Streamers
24 -> some useless includes removed or replaced by "class" statement
25
26 Revision 1.4  2000/07/03 11:54:57  morsch
27 AliMUONSegmentation and AliMUONHitMap have been replaced by AliSegmentation and AliHitMap in STEER
28 The methods GetPadIxy and GetPadXxy of AliMUONSegmentation have changed name to GetPadI and GetPadC.
29
30 Revision 1.3  2000/06/25 17:02:19  pcrochet
31 scope problem on HP, i declared once, pow replaced by TMath::Power (PH)
32
33 Revision 1.2  2000/06/15 07:58:49  morsch
34 Code from MUON-dev joined
35
36 Revision 1.1.2.8  2000/06/14 14:54:34  morsch
37 Complete redesign, make use of TriggerCircuit and TriggerLut (PC)
38
39 Revision 1.1.2.5  2000/04/26 19:59:57  morsch
40 Constructor added.
41
42 Revision 1.1.2.4  2000/04/26 12:31:30  morsch
43 Modifications by P. Crochet:
44 - adapted to the new Trigger chamber geometry
45 - condition on soft background added
46 - contructor added in AliMUONTriggerDecision.h
47 - single-undefined taken into account in the output of GlobalTrigger()
48 - some bugs fixed
49
50 Revision 1.1.2.3  2000/03/21 09:29:58  morsch
51 Put back comments
52
53 Revision 1.1.2.2  2000/03/21 09:24:34  morsch
54 Author and responsible for the code: Philippe Crochet
55 */
56
57 #include "AliMUONTriggerCircuit.h"
58 #include "AliMUONTriggerDecision.h"
59 #include "AliMUONTriggerLut.h"
60 #include "AliMUONHitMapA1.h"
61 #include "AliRun.h"
62 #include "AliMUON.h"
63 #include "AliSegmentation.h"
64 #include "AliMUONResponse.h"
65 #include "AliMUONChamber.h"
66 #include "AliMUONDigit.h"
67
68
69 #include <TF1.h>
70 #include <TTree.h>
71 #include <TCanvas.h>
72 #include <TH1.h>
73 #include <TPad.h>
74 #include <TGraph.h> 
75 #include <TPostScript.h> 
76 #include <TMinuit.h> 
77 #include <iostream.h> 
78
79 //----------------------------------------------------------------------
80 ClassImp(AliMUONTriggerDecision)
81
82 //----------------------------------------------------------------------
83 AliMUONTriggerDecision::AliMUONTriggerDecision(Int_t iprint)
84 {
85 // Constructor 
86   fDebug = iprint;            // print option
87 // iprint = 0 : don't print anything
88 // iprint = 1 : print Global Trigger Output
89 // iprint = 2 : print Local and Global Trigger Outputs
90 // iprint = 3 : iprint = 2 + detailed info on X strips
91 // iprint = 4 : iprint = 2 + detailed info on Y strip
92 // iprint = 5 : iprint = 2 + detailed info on X and Y strips
93 // Note : with iprint>2, the strips detailed info is given for all circuits
94
95 // Global Trigger information
96   Int_t i;
97   Int_t icirc;
98   Int_t istrip;
99
100   for (i=0; i<3; i++) {   // [0] : Low pt, [1] : High pt, [2] : All pt 
101     fGlobalSinglePlus[i]=0;     // tot num of single plus 
102     fGlobalSingleMinus[i]=0;    // tot num of single minus
103     fGlobalSingleUndef[i]=0;    // tot num of single undefined
104     fGlobalPairUnlike[i]=0;     // tot num of unlike-sign pairs
105     fGlobalPairLike[i]=0;       // tot num of like-sign pairs
106   }
107   // Local Trigger information
108   for (icirc=0; icirc<234; icirc++){
109     fTrigger[icirc]=0;                   // trigger or not
110     fStripX11[icirc]=0;                   // X strip in MC11 which triggers 
111     fDev[icirc]=0;                        // deviation which triggers 
112     fStripY11[icirc]=0;                   // Y strip in MC11 which triggers 
113     for (i=0; i<2; i++) {           // pt information via LuT
114       fLutLpt[icirc][i]=fLutHpt[icirc][i]=fLutApt[icirc][i]=0;    
115     }
116   }
117   // bit pattern
118   for (icirc=0; icirc<234; icirc++) {
119     for (istrip=0; istrip<16; istrip++) {
120       fXbit11[icirc][istrip]=fXbit12[icirc][istrip]=0;
121       fYbit11[icirc][istrip]=fYbit12[icirc][istrip]=0;
122       fYbit21[icirc][istrip]=fYbit22[icirc][istrip]=0;
123       fYbit21U[icirc][istrip]=fYbit22U[icirc][istrip]=0;
124       fYbit21D[icirc][istrip]=fYbit22D[icirc][istrip]=0;
125     }
126     for (istrip=0; istrip<32; istrip++) {
127       fXbit21[icirc][istrip]=fXbit22[icirc][istrip]=0;
128     }
129   }
130 }
131
132 //----------------------------------------------------------------------
133 AliMUONTriggerDecision::~AliMUONTriggerDecision()
134 {
135 // Destructor
136 }
137
138 //----------------------------------------------------------------------
139 void AliMUONTriggerDecision::Trigger(){
140 // main method of the class which calls the overall Trigger procedure
141 //  cout << " In AliMUONTriggerDecision::Trigger " << "\n";
142
143   ResetBit();
144   SetBit();
145   SetBitUpDownY();
146
147   Int_t coinc44=0, resetMid=0; // initialize coincidence
148
149   AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");  
150   AliMUONTriggerCircuit* triggerCircuit;
151
152   for (Int_t icirc=0; icirc<234; icirc++) {  // loop on circuits
153     triggerCircuit = &(pMUON->TriggerCircuit(icirc));     
154     //    Int_t idCircuit=triggerCircuit->GetIdCircuit(); 
155     
156     Int_t minDevStrip[5], minDev[5], coordY[5];
157     for (Int_t i=0; i<5; i++) {
158       minDevStrip[i]=minDev[i]=coordY[i]=0;
159     }
160     Int_t x2m=triggerCircuit->GetX2m();
161     Int_t x2ud=triggerCircuit->GetX2ud();
162     Int_t orMud[2]={0,0};
163     triggerCircuit->GetOrMud(orMud);
164         
165 // call triggerX
166     TrigX(fXbit11[icirc],fXbit12[icirc],fXbit21[icirc],fXbit22[icirc], 
167           coinc44, minDevStrip, minDev);
168 // call triggerY
169     TrigY(fYbit11[icirc],fYbit12[icirc],fYbit21[icirc],fYbit22[icirc],
170           fYbit21U[icirc],fYbit21D[icirc],fYbit22U[icirc],fYbit22D[icirc],
171           x2m,x2ud,orMud,resetMid,coinc44,coordY);
172 // call LocalTrigger     
173     Int_t iTrigger=0;
174     LocalTrigger(icirc, minDevStrip, minDev, coordY, iTrigger);
175
176     if (iTrigger==1&&fDebug>1) { 
177       PrintBitPatXInput(icirc);
178       PrintBitPatYInput(icirc);
179       PrintLocalOutput(minDevStrip, minDev, coordY);
180     }      
181   }  //  end loop on circuits
182
183 // call Global Trigger
184   GlobalTrigger();
185   //  cout << " Leaving AliMUONTriggerDecision::Trigger " << "\n";
186 }
187
188 //----------------------------------------------------------------------
189 void AliMUONTriggerDecision::ResetBit(){
190 // reset bit pattern, global and local trigger output tables to 0
191   
192     Int_t i;
193     Int_t icirc;
194     Int_t istrip;
195
196   for (icirc=0; icirc<234; icirc++) {
197     for (istrip=0; istrip<16; istrip++) {
198       fXbit11[icirc][istrip]=fXbit12[icirc][istrip]=0;
199       fYbit11[icirc][istrip]=fYbit12[icirc][istrip]=0;
200       fYbit21[icirc][istrip]=fYbit22[icirc][istrip]=0;
201       fYbit21U[icirc][istrip]=fYbit22U[icirc][istrip]=0;
202       fYbit21D[icirc][istrip]=fYbit22D[icirc][istrip]=0;
203     }
204     for (istrip=0; istrip<32; istrip++) {
205       fXbit21[icirc][istrip]=fXbit22[icirc][istrip]=0;
206     }
207   }
208   for (i=0; i<3; i++) { 
209     fGlobalSinglePlus[i]=0;
210     fGlobalSingleMinus[i]=0;
211     fGlobalSingleUndef[i]=0;
212     fGlobalPairLike[i]=0;
213     fGlobalPairLike[i]=0;
214   }
215   for (icirc=0; icirc<234; icirc++){
216     fTrigger[icirc]=0;
217     fStripX11[icirc]=0;
218     fDev[icirc]=0;                      
219     fStripY11[icirc]=0;                 
220     for (i=0; i<2; i++) {         
221       fLutLpt[icirc][i]=fLutHpt[icirc][i]=fLutApt[icirc][i]=0;    
222     }
223   }
224 }
225
226 //----------------------------------------------------------------------
227 void AliMUONTriggerDecision::SetBit(){
228 // 1) loop over chambers and cathodes
229 // 2) load digits 
230 // 3) remove soft background
231 // 4) set the bit patterns
232
233   AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");  
234   AliMUONTriggerCircuit* triggerCircuit;
235
236   for (Int_t chamber=11; chamber<15; chamber++){
237     for (Int_t cathode=1; cathode<3; cathode++){
238       
239       AliMUONChamber*   iChamber;
240       AliSegmentation*  segmentation;
241       
242       TClonesArray *muonDigits  = pMUON->DigitsAddress(chamber-1);
243       if (muonDigits == 0) return;
244       
245       gAlice->ResetDigits();
246       
247       Int_t nent=(Int_t)gAlice->TreeD()->GetEntries();
248       gAlice->TreeD()->GetEvent(nent-2+cathode-1);
249       Int_t ndigits = muonDigits->GetEntriesFast();
250       if (ndigits == 0) return;
251       
252       iChamber = &(pMUON->Chamber(chamber-1));
253       segmentation=iChamber->SegmentationModel(cathode);
254       AliMUONDigit  *mdig;
255       
256       for (Int_t digit=0; digit<ndigits; digit++) {
257         mdig    = (AliMUONDigit*)muonDigits->UncheckedAt(digit);
258 // get the center of the pad Id 
259         Int_t ix=mdig->PadX();
260         Int_t iy=mdig->PadY();
261 // get the sum of the coded charge 
262 // see coding convention in AliMUONChamberTrigger::DisIntegration       
263         Int_t sumCharge=0;
264         for (Int_t icharge=0; icharge<10; icharge++) {
265           sumCharge=sumCharge+mdig->TrackCharge(icharge);
266         }
267 // apply condition on soft background   
268         Int_t testCharge=sumCharge-(Int_t(sumCharge/10))*10;
269         testCharge=sumCharge-testCharge*10;
270         if(sumCharge<=10||testCharge>0) {         
271 // code pad
272           Int_t code=TMath::Abs(ix)*100+iy;
273           if (ix<0) { code=-code; }
274           
275           Int_t icirc;
276           Int_t istrip;
277           Int_t nStrip;
278
279           if (cathode==1) {
280             switch (chamber)
281               {
282               case 11:
283                 for (icirc=0; icirc<234; icirc++) {               
284                   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
285                   for (istrip=0; istrip<16; istrip++) {
286                     if (triggerCircuit->GetXcode(0,istrip)==code) 
287                       fXbit11[icirc][istrip]=1;
288                   }
289                 }
290                 break;
291               case 12:
292                 for (icirc=0; icirc<234; icirc++) {
293                   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
294                   for (istrip=0; istrip<16; istrip++) {
295                     if (triggerCircuit->GetXcode(1,istrip)==code) 
296                       fXbit12[icirc][istrip]=1;
297                   }
298                 }
299                 break;
300               case 13:
301                 for (icirc=0; icirc<234; icirc++) {
302                   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
303                   for (istrip=0; istrip<32; istrip++) {
304                     if (triggerCircuit->GetXcode(2,istrip)==code) 
305                       fXbit21[icirc][istrip]=1;
306                   }
307                 }
308                 break;
309               case 14:
310                 for (icirc=0; icirc<234; icirc++) {
311                   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
312                   for (istrip=0; istrip<32; istrip++) {
313                     if (triggerCircuit->GetXcode(3,istrip)==code) 
314                       fXbit22[icirc][istrip]=1;             
315                   }
316                 }               
317                 break;
318               }
319             
320           } else {                // Y plane 
321             switch (chamber)
322               {
323               case 11:
324                 for (icirc=0; icirc<234; icirc++) {
325                   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
326                   nStrip=triggerCircuit->GetNstripY();
327                   for (istrip=0; istrip<nStrip; istrip++) {
328                     if (triggerCircuit->GetYcode(0,istrip)==code) 
329                       fYbit11[icirc][istrip]=1;
330                   }
331                 }
332                 break;
333               case 12:
334                 for (icirc=0; icirc<234; icirc++) {
335                   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
336                   nStrip=triggerCircuit->GetNstripY(); 
337                   for (istrip=0; istrip<nStrip; istrip++) {
338                     if (triggerCircuit->GetYcode(1,istrip)==code) 
339                       fYbit12[icirc][istrip]=1;
340                   }
341                 }
342                 break;
343               case 13:
344                 for (icirc=0; icirc<234; icirc++) {
345                   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
346                   nStrip=triggerCircuit->GetNstripY();    
347                   for (istrip=0; istrip<nStrip; istrip++) {
348                     if (triggerCircuit->GetYcode(2,istrip)==code) 
349                       fYbit21[icirc][istrip]=1;
350                   }
351                 }
352                 break;
353               case 14:
354                 for (icirc=0; icirc<234; icirc++) {
355                   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
356                   nStrip=triggerCircuit->GetNstripY();    
357                   for (istrip=0; istrip<nStrip; istrip++) {
358                     if (triggerCircuit->GetYcode(3,istrip)==code) 
359                       fYbit22[icirc][istrip]=1;                          
360                   }
361                 }               
362                 break;
363               }
364           } // if cathode
365         }  // remove soft background
366       }   // end loop on digit
367     }    // end loop on cathode
368   }     // end loop on chamber
369 }  
370
371 //----------------------------------------------------------------------
372 void AliMUONTriggerDecision::SetBitUpDownY(){
373 // Set Y bit for up and down parts of circuits
374   Int_t idModule, nStripX, nStripY, iPosCircuit;
375
376   AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
377   
378   for (Int_t icirc=0; icirc<234; icirc++) {
379
380     AliMUONTriggerCircuit* circuit;   // current circuit
381     AliMUONTriggerCircuit* circuitD;  // circuit Down
382     AliMUONTriggerCircuit* circuitU;  // circuit Up
383
384     circuit = &(pMUON->TriggerCircuit(icirc));  
385     idModule=circuit->GetIdModule();      // corresponding module Id.
386     nStripX=circuit->GetNstripX();        // number of X strips
387     nStripY=circuit->GetNstripY();        // number of Y strips
388     iPosCircuit=circuit->GetPosCircuit(); // position of circuit in module
389
390 // fill lower part
391     if (iPosCircuit==1) {               // need to scan lower module       
392       if(idModule<91&&TMath::Abs(idModule)!=41&&idModule>-91) { 
393         Int_t icircD=circuit->GetICircuitD();
394         circuitD = &(pMUON->TriggerCircuit(icircD));  
395         Int_t nStripD=circuitD->GetNstripY();
396                 
397         if (TMath::Abs(idModule)==42) { // shift of +8 bits
398           for (Int_t istrip=0; istrip<nStripD; istrip++) {
399             fYbit21D[icirc][istrip+8]=fYbit21[icircD][istrip];
400             fYbit22D[icirc][istrip+8]=fYbit22[icircD][istrip];
401           }       
402         } else if (TMath::Abs(idModule)==52) { // shift of -8 bits
403           for (Int_t istrip=0; istrip<nStripD; istrip++) {
404             fYbit21D[icirc][istrip]=fYbit21[icircD][istrip+8];
405             fYbit22D[icirc][istrip]=fYbit22[icircD][istrip+8];
406           }
407         } else {
408           for (Int_t istrip=0; istrip<nStripD; istrip++) {
409             fYbit21D[icirc][istrip]=fYbit21[icircD][istrip];
410             fYbit22D[icirc][istrip]=fYbit22[icircD][istrip];
411           }
412         }
413       }      
414     } else {                         // lower strips within same module       
415       for (Int_t istrip=0; istrip<nStripY; istrip++) { 
416         fYbit21D[icirc][istrip]=fYbit21[icirc][istrip];
417         fYbit22D[icirc][istrip]=fYbit22[icirc][istrip];
418       }
419     }    
420     
421 // fill upper part
422     if ((iPosCircuit==1&&nStripX==16)||(iPosCircuit==2&&nStripX==32)|| 
423         (iPosCircuit==3&&nStripX==48)||(iPosCircuit==4&&nStripX==64)) {   
424       if ((idModule>17||idModule<-17)&&TMath::Abs(idModule)!=61) {  
425         Int_t icircU=circuit->GetICircuitU();
426         circuitU = &(pMUON->TriggerCircuit(icircU));  
427         Int_t nStripU=circuitU->GetNstripY();           
428         
429         if (TMath::Abs(idModule)==62) { // shift of +8 bits
430           for (Int_t istrip=0; istrip<nStripU; istrip++) {
431             fYbit21U[icirc][istrip+8]=fYbit21[icircU][istrip];
432             fYbit22U[icirc][istrip+8]=fYbit22[icircU][istrip];
433           }       
434         } else if (TMath::Abs(idModule)==52) { // shift of -8 bits
435           for (Int_t istrip=0; istrip<nStripU; istrip++) {
436             fYbit21U[icirc][istrip]=fYbit21[icircU][istrip+8];
437             fYbit22U[icirc][istrip]=fYbit22[icircU][istrip+8];
438           }
439         } else {
440           for (Int_t istrip=0; istrip<nStripU; istrip++) {
441             fYbit21U[icirc][istrip]=fYbit21[icircU][istrip];
442             fYbit22U[icirc][istrip]=fYbit22[icircU][istrip];
443           }
444         }
445       }      
446     } else {                       // upper strips within same module       
447       for (Int_t istrip=0; istrip<nStripY; istrip++) { 
448         fYbit21U[icirc][istrip]=fYbit21[icirc][istrip];
449         fYbit22U[icirc][istrip]=fYbit22[icirc][istrip];
450       }
451     } 
452   } // loop on circuit
453 }
454
455 //----------------------------------------------------------------------
456 // x part of trigger Algo
457 //----------------------------------------------------------------------
458 //----------------------------------------------------------------------
459 void AliMUONTriggerDecision::TrigX(Int_t ch1q[16], Int_t ch2q[16], 
460                                    Int_t ch3q[32], Int_t ch4q[32], 
461                                    Int_t coinc44, Int_t minDevStrip[5], 
462                                    Int_t minDev[5]){
463 // note : coinc44 = flag 0 or 1 (0 coincidence -> 3/4, 1 coincidence -> 4/4)
464 //---------------------------------------------------------
465 // step # 1 : declustering, reduction DS, calculate sgle & dble
466 //---------------------------------------------------------
467   Int_t ch1e[19], ch2e[20], ch3e[35], ch4e[36]; 
468   Int_t sgleHit1[31], sgleHit2[63];
469   Int_t dbleHit1[31], dbleHit2[63];
470
471   Int_t i;
472   Int_t j;
473   Int_t istrip;
474
475   for (i=0; i<31; i++) {
476     sgleHit1[i]=0;
477     dbleHit1[i]=0;
478   }
479   for (i=0; i<63; i++) {
480     sgleHit2[i]=0;
481     dbleHit2[i]=0;
482   }
483
484 //--- inititialize che using chq 
485   for (i=0; i<19; i++) {
486     if (i<1||i>16)  ch1e[i]=0; 
487     else            ch1e[i]=ch1q[i-1]; 
488   }
489   for (i=0; i<20; i++) {
490     if (i<2||i>17) ch2e[i]=0; 
491     else           ch2e[i]=ch2q[i-2]; 
492   }
493   for (i=0; i<35; i++) {
494     if (i<1||i>32) ch3e[i]=0; 
495     else           ch3e[i]=ch3q[i-1];
496   }
497   for (i=0; i<36; i++) {
498     if (i<2||i>33) ch4e[i]=0; 
499     else           ch4e[i]=ch4q[i-2];
500   }
501
502
503 //--- calculate dble & sgle first station
504   for (i=0; i<=15; i++) {                   
505     sgleHit1[2*i] = (!ch1e[i+1]|(ch1e[i]^ch1e[i+2])) & 
506       (!ch2e[i+2] | (ch2e[i+1]^ch2e[i+3]));
507
508     dbleHit1[2*i] = ch1e[i+1]&!(ch1e[i+2]^ch1e[i]) & 
509       (ch2e[i+2] | (!ch2e[i]&ch2e[i+1]) | (ch2e[i+3]&!ch2e[i+4]));
510   }
511
512   for (i=0; i<=14; i++) {               
513     sgleHit1[2*i+1] = (!ch1e[i+1]|!ch1e[i+2]|(ch1e[i]^ch1e[i+3])) & 
514       (!ch2e[i+2] | !ch2e[i+3] | (ch2e[i+1]^ch2e[i+4]));
515     dbleHit1[2*i+1] = ch1e[i+1]&ch1e[i+2]&!(ch1e[i]^ch1e[i+3]) & 
516       (ch2e[i+2]&(!ch2e[i+1]|!ch2e[i]) | 
517               ch2e[i+3]&(ch2e[i+2]|!ch2e[i+4]|!ch2e[i+5]));
518   }
519
520 //--- calculate dble & sgle second station
521   for (i=0; i<=31; i++) {               
522     sgleHit2[2*i] = (!ch3e[i+1]|(ch3e[i]^ch3e[i+2])) & 
523       (!ch4e[i+2] | (ch4e[i+1]^ch4e[i+3]));
524     dbleHit2[2*i] = ch3e[i+1]&!(ch3e[i+2]^ch3e[i]) & 
525       (ch4e[i+2] | (!ch4e[i]&ch4e[i+1]) | (ch4e[i+3]&!ch4e[i+4]));
526   }
527   
528   for (i=0; i<=30; i++) {               
529     sgleHit2[2*i+1] = (!ch3e[i+1]|!ch3e[i+2]|(ch3e[i]^ch3e[i+3])) & 
530       (!ch4e[i+2] | !ch4e[i+3] | (ch4e[i+1]^ch4e[i+4]));
531     dbleHit2[2*i+1] = ch3e[i+1]&ch3e[i+2]&!(ch3e[i]^ch3e[i+3]) & 
532       (ch4e[i+2]&(!ch4e[i+1]|!ch4e[i]) | 
533        ch4e[i+3]&(ch4e[i+2]|!ch4e[i+4]|!ch4e[i+5]));
534   }
535
536 //--- 
537   if(fDebug==3||fDebug==5) {
538     cout << "===============================================================" << "\n";
539     cout << " X plane after sgle and dble " << " \n";
540     cout << "                       0987654321098765432109876543210";
541     cout << "\n SGLE1                 ";
542     for (istrip=30; istrip>=0; istrip--) { cout << (!sgleHit1[istrip]); }
543     cout << "\n DBLE1                 ";
544     for (istrip=30; istrip>=0; istrip--) { cout << dbleHit1[istrip]; }
545     cout << "\n SGLE2 ";
546     for (istrip=62; istrip>=0; istrip--) { cout << (!sgleHit2[istrip]); }
547     cout << "\n DBLE2 ";
548     for (istrip=62; istrip>=0; istrip--) { cout << dbleHit2[istrip]; }
549     cout << "\n       210987654321098765432109876543210987654321098765432109876543210" << "\n";
550   }
551   
552 //---------------------------------------------------------
553 // step # 2 : coincidence 3/4
554 //---------------------------------------------------------
555   Int_t rearImage[31][31];
556   for (i=0; i<31; i++) {
557     for (j=0; j<31; j++) {
558       rearImage[i][j]=0;
559     }
560   }
561
562  Int_t notOr1=!dbleHit1[30] & !dbleHit1[29] & !dbleHit1[28] & !dbleHit1[27] & 
563  !dbleHit1[26] & !dbleHit1[25] & !dbleHit1[24] & !dbleHit1[23] &
564  !dbleHit1[22] & !dbleHit1[21] & !dbleHit1[20] & !dbleHit1[19] & 
565  !dbleHit1[18] & !dbleHit1[17] & !dbleHit1[16] & !dbleHit1[15] & 
566  !dbleHit1[14] & !dbleHit1[13] & !dbleHit1[12] & !dbleHit1[11] & 
567  !dbleHit1[10] & !dbleHit1[9]  & !dbleHit1[8]  & !dbleHit1[7]  & 
568  !dbleHit1[6]  & !dbleHit1[5]  & !dbleHit1[4]  & !dbleHit1[3]  & 
569  !dbleHit1[2]  & !dbleHit1[1]  & !dbleHit1[0]  & !coinc44;
570
571  Int_t notOr2= !dbleHit2[62] & !dbleHit2[61] & !dbleHit2[60] & !dbleHit2[59] & 
572  !dbleHit2[58] & !dbleHit2[57] & !dbleHit2[56] & !dbleHit2[55] & 
573  !dbleHit2[54] & !dbleHit2[53] & !dbleHit2[52] & !dbleHit2[51] & 
574  !dbleHit2[50] & !dbleHit2[49] & !dbleHit2[48] & !dbleHit2[47] & 
575  !dbleHit2[46] & !dbleHit2[45] & !dbleHit2[44] & !dbleHit2[43] & 
576  !dbleHit2[42] & !dbleHit2[41] & !dbleHit2[40] & !dbleHit2[39] & 
577  !dbleHit2[38] & !dbleHit2[37] & !dbleHit2[36] & !dbleHit2[35] & 
578  !dbleHit2[34] & !dbleHit2[33] & !dbleHit2[32] & !dbleHit2[31] &
579  !dbleHit2[30] & !dbleHit2[29] & !dbleHit2[28] & !dbleHit2[27] & 
580  !dbleHit2[26] & !dbleHit2[25] & !dbleHit2[24] & !dbleHit2[23] & 
581  !dbleHit2[22] & !dbleHit2[21] & !dbleHit2[20] & !dbleHit2[19] & 
582  !dbleHit2[18] & !dbleHit2[17] & !dbleHit2[16] & !dbleHit2[15] & 
583  !dbleHit2[14] & !dbleHit2[13] & !dbleHit2[12] & !dbleHit2[11] & 
584  !dbleHit2[10] & !dbleHit2[9]  & !dbleHit2[8]  & !dbleHit2[7]  & 
585  !dbleHit2[6]  & !dbleHit2[5]  & !dbleHit2[4]  & !dbleHit2[3]  & 
586  !dbleHit2[2]  & !dbleHit2[1]  & !dbleHit2[0]  & !coinc44;      
587
588 // DS reduction
589  for (i=0; i<31; i++) {
590    sgleHit1[i] = !sgleHit1[i]&notOr1;
591  }
592  for (i=0; i<63; i++) {
593    sgleHit2[i] = !sgleHit2[i]&notOr2;
594  }
595
596 // extract rearImage
597  for (i=0; i<31; i++){
598    Int_t tmpSgleHit2[31];
599    Int_t tmpDbleHit2[31];
600    for (j=0; j<31; j++){
601      tmpSgleHit2[j] = sgleHit2[i+j+1];
602      tmpDbleHit2[j] = dbleHit2[i+j+1];
603    }
604
605    for (Int_t k=0; k<31; k++) {
606      rearImage[i][k]=(sgleHit1[i]&tmpDbleHit2[k])|
607        (dbleHit1[i]&(tmpSgleHit2[k]|tmpDbleHit2[k]));
608    }
609  }
610
611   //-----------
612  if(fDebug==3||fDebug==5) {
613     cout << "===============================================================" << "\n";
614    for (i=30; i>=0; i--) {
615      cout << i << "\t ";
616      for (istrip=31; istrip>=0; istrip--) {
617        cout << rearImage[i][istrip];
618      }
619      cout << " " << "\n";
620    }
621  }
622   
623
624 //---------------------------------------------------------
625 // step # 3 : calculate deviation
626 //--------------------------------------------------------- 
627  Int_t dev[31][6];
628  for (i=0; i<31; i++) {
629    for (j=0; j<6; j++) {
630      dev[i][j]=0;
631    }
632  }
633
634  for (i=0; i<31; i++){
635    Int_t leftDev[5], rightDev[5]; 
636    Int_t orL1, andL1, andL2, orR1, orR2, andR1, andR2, andR3;
637
638 // calculate Left deviation
639  orL1=rearImage[i][16]|rearImage[i][18]|rearImage[i][20]|rearImage[i][22];
640  andL1=!rearImage[i][17]&!rearImage[i][19]&!rearImage[i][21] & !orL1; 
641  andL2=!rearImage[i][23]&!rearImage[i][24]&!rearImage[i][25]&!rearImage[i][26];
642  
643  leftDev[0] = (rearImage[i][16]|!rearImage[i][17]) & 
644  (rearImage[i][16]|rearImage[i][18]|!rearImage[i][19]&
645  (rearImage[i][20]|!rearImage[i][21])) &
646  (orL1|!rearImage[i][23]&(rearImage[i][24]|!rearImage[i][25])) & 
647  (orL1|rearImage[i][24]|rearImage[i][26]|!rearImage[i][27]&
648  (rearImage[i][28]|!rearImage[i][29]));
649                                 
650  leftDev[1] = !rearImage[i][16] & 
651  !(!rearImage[i][17]&!rearImage[i][18]&!rearImage[i][21]&!rearImage[i][22] & 
652  (!rearImage[i][25]&!rearImage[i][26]&(rearImage[i][27]|rearImage[i][28]))) &
653  (rearImage[i][17]|rearImage[i][18] | !rearImage[i][19]&!rearImage[i][20]) &
654  (rearImage[i][17]|rearImage[i][18]|rearImage[i][21]|rearImage[i][22] | 
655  !rearImage[i][23]&!rearImage[i][24]);
656                                 
657  leftDev[2] = (!rearImage[i][16]&!rearImage[i][17]&!rearImage[i][18]) & 
658  (rearImage[i][19]|rearImage[i][20]|rearImage[i][21]|rearImage[i][22] | andL2);
659                 
660  leftDev[3] = andL1;
661                 
662  leftDev[4] = 
663  !rearImage[i][27]&!rearImage[i][28]&!rearImage[i][29]&!rearImage[i][30] & 
664  andL1 & andL2;
665
666  // calculate Right deviation
667  orR1=rearImage[i][8]|rearImage[i][10]|rearImage[i][12]|rearImage[i][14];
668  orR2=rearImage[i][8]|rearImage[i][9]|rearImage[i][10]|rearImage[i][11];
669  andR1=!rearImage[i][12]&!rearImage[i][13]&!rearImage[i][14]&!rearImage[i][15];
670  andR2=
671  !rearImage[i][8]&!rearImage[i][9]&!rearImage[i][10]&!rearImage[i][11] & andR1;
672  andR3=!rearImage[i][4]&!rearImage[i][5]&!rearImage[i][6]&!rearImage[i][7]; 
673                 
674  rightDev[0] = !rearImage[i][15]&(rearImage[i][14]|!rearImage[i][13]) & 
675  ((rearImage[i][12]|rearImage[i][14]|!rearImage[i][11]&
676  (rearImage[i][10]|!rearImage[i][9])) &
677  ((orR1|!rearImage[i][7]&(rearImage[i][6]|!rearImage[i][5])) & 
678  (orR1|rearImage[i][4]|rearImage[i][6]|!rearImage[i][3]&(rearImage[i][2]|
679  !rearImage[i][1]))));
680                                 
681  rightDev[1] = !rearImage[i][15]&!rearImage[i][14] & 
682  !(!rearImage[i][4]&!rearImage[i][5]&!rearImage[i][8]&!rearImage[i][9] &
683  (!rearImage[i][12]&!rearImage[i][13]&(rearImage[i][2]|rearImage[i][3]))) &
684  (rearImage[i][12]|rearImage[i][13] | !rearImage[i][10]&!rearImage[i][11]) & 
685  (rearImage[i][8]|rearImage[i][9]|rearImage[i][12]|rearImage[i][13] | 
686  !rearImage[i][6]&!rearImage[i][7]);
687                 
688  rightDev[2] = andR1 & (orR2 | andR3); 
689  rightDev[3] = andR2;           
690  rightDev[4] = 
691  !rearImage[i][0]&!rearImage[i][1]&!rearImage[i][2]&!rearImage[i][3] & 
692  andR2 & andR3 ;
693
694  // compare Left & Right deviations
695  Int_t tmpLeftDev=0, tmpRightDev=0;
696  for (j=0; j<5; j++){
697    tmpLeftDev  = tmpLeftDev + Int_t(leftDev[j]*TMath::Power(2,j)); 
698    tmpRightDev = tmpRightDev + Int_t(rightDev[j]*TMath::Power(2,j)); 
699  }
700
701  // assign mimimum deviation do dev[][]
702  if (tmpLeftDev < tmpRightDev ){
703    for (j=0; j<5; j++){ dev[i][j]=leftDev[j];}
704    dev[i][5]=1;
705  } else {
706    for (j=0; j<5; j++){ dev[i][j]=rightDev[j];}
707    dev[i][5]=0;
708  }
709   }
710   
711 //---
712   if(fDebug==3||fDebug==5) {
713     cout << "===============================================================" << "\n";
714     for (i=30; i>=0; i--) {
715       cout << i << "\t ";
716       for (istrip=5; istrip>=0; istrip--) { cout << dev[i][istrip]; }
717       cout << " " << "\n";
718     }
719   }
720
721 //---------------------------------------------------------
722 // step # 4 : sort deviation
723 //--------------------------------------------------------- 
724  Int_t bga1[16], bga2[8], bga3[4], bga4[2], bga5;
725  Int_t tmpbga1[16][6], tmpbga2[8][6], tmpbga3[4][6], tmpbga4[2][6], tmpbga5[6];
726  Int_t tmpMax[6]={1,1,1,1,1,0};
727
728   for (i=0; i<15; i++) {
729     Sort2x5(dev[2*i],dev[2*i+1],tmpbga1[i],bga1[i]);
730   }  
731     Sort2x5(dev[30],tmpMax,tmpbga1[15],bga1[15]);
732
733 //--    
734   if(fDebug==3||fDebug==5) {
735     cout << "===============================================================" << "\n";
736     cout << " sorting : 1st level " << "\n";
737     for (i=15; i>=0; i--) {
738       cout << i << "\t " << bga1[i] << "\t";    
739       for (j=5; j>=0; j--) {
740         cout << tmpbga1[i][j]; 
741       }
742       cout << " " << "\n";
743     }
744   }
745
746   for (i=0; i<8; i++) {  
747     Sort2x5(tmpbga1[2*i],tmpbga1[2*i+1],tmpbga2[i],bga2[i]);
748   }
749
750 //--    
751   if(fDebug==3||fDebug==5) {
752     cout << "===============================================================" << "\n";
753     cout << " sorting : 2nd level " << "\n";
754     for (i=7; i>=0; i--) {
755       cout << i << "\t " << bga2[i] << "\t";    
756       for (j=5; j>=0; j--) {
757         cout << tmpbga2[i][j]; 
758       }
759       cout << " " << "\n";
760     }
761   }
762     
763   for (i=0; i<4; i++) {  
764     Sort2x5(tmpbga2[2*i],tmpbga2[2*i+1],tmpbga3[i],bga3[i]);
765   }
766
767 //--    
768   if(fDebug==3||fDebug==5) {
769     cout << "===============================================================" << "\n";
770     cout << " sorting : 3rd level " << "\n";
771     for (i=3; i>=0; i--) {
772       cout << i << "\t " << bga3[i] << "\t";    
773       for (j=5; j>=0; j--) {
774         cout << tmpbga3[i][j]; 
775       }
776       cout << " " << "\n";
777     }
778   }
779
780   for (i=0; i<2; i++) {  
781     Sort2x5(tmpbga3[2*i],tmpbga3[2*i+1],tmpbga4[i],bga4[i]);
782   }
783
784 //--    
785   if(fDebug==3||fDebug==5) {
786     cout << "===============================================================" << "\n";
787     cout << " sorting : 4th level " << "\n";
788     for (i=1; i>=0; i--) {
789       cout << i << "\t " << bga4[i] << "\t";    
790       for (j=5; j>=0; j--) {
791         cout << tmpbga4[i][j]; 
792       }
793       cout << " " << "\n";
794     }
795   }
796   
797     Sort2x5(tmpbga4[0],tmpbga4[1],tmpbga5,bga5);
798
799  // coding from 6 to 5 bits 
800     minDev[4] = tmpbga5[5] | tmpbga5[4];
801     for (i=0; i<4; i++) { 
802       minDev[i]=tmpbga5[i] & !tmpbga5[4];
803     }
804
805  // find address of strip with minimum deviation 
806     minDevStrip[4]=bga5;
807     if (bga5<=1) minDevStrip[3]=bga4[bga5];
808
809     Int_t tmpAd=minDevStrip[3]+minDevStrip[4]*2;
810     if (tmpAd<=3) minDevStrip[2]=bga3[tmpAd];
811
812     tmpAd=minDevStrip[2]+minDevStrip[3]*2+minDevStrip[4]*4;
813     if (tmpAd<=7) minDevStrip[1]=bga2[tmpAd];
814
815     tmpAd=minDevStrip[1]+minDevStrip[2]*2+minDevStrip[3]*4+minDevStrip[4]*8;
816     if (tmpAd<=15) minDevStrip[0]=bga1[tmpAd];
817
818   if(fDebug==3||fDebug==5) {
819     cout << "===============================================================" << "\n";
820     cout << "minDevStrip = ";
821     for  (i=4; i>=0; i--) {cout << minDevStrip[i];}
822     cout << " minDev = ";
823     for  (i=4; i>=0; i--) {cout << minDev[i];} 
824     cout << " " << "\n";
825     cout << "===============================================================" << "\n";
826   }
827
828 }
829
830 //---------------------------------------------
831 void AliMUONTriggerDecision::Sort2x5(Int_t dev1[6], Int_t dev2[6],
832                                      Int_t minDev[6], Int_t &dev1GTdev2){ 
833 // returns minimun between dev1 and dev2
834  Int_t tmpDev1=0, tmpDev2=0;
835  for (Int_t j=0; j<5; j++){
836    tmpDev1 = tmpDev1 + Int_t(dev1[j]*TMath::Power(2,j)); 
837    tmpDev2 = tmpDev2 + Int_t(dev2[j]*TMath::Power(2,j)); 
838  }
839  if (tmpDev1 <= tmpDev2 ){
840    for (Int_t j=0; j<=5; j++) { minDev[j]=dev1[j];}
841    dev1GTdev2=0;
842  } else {
843    for (Int_t j=0; j<=5; j++) { minDev[j]=dev2[j];}
844    dev1GTdev2=1;   
845  }
846 }
847
848 //----------------------------------------------------------------------
849 // y part of trigger Algo 
850 //----------------------------------------------------------------------
851 //----------------------------------------------------------------------
852 void AliMUONTriggerDecision::TrigY(Int_t y1[16], Int_t y2[16], 
853                                    Int_t y3[16], Int_t y4[16],
854                                    Int_t y3u[16], Int_t y3d[16], 
855                                    Int_t y4u[16], Int_t y4d[16],
856                                    Int_t x2m, Int_t x2ud, Int_t orMud[2], 
857                                    Int_t resetMid, Int_t coinc44, 
858                                    Int_t coordY[5]){
859 // note : resMid = 1 -> cancel 
860 //---------------------------------------------------------
861 // step # 1 : prehandling Y
862 //--------------------------------------------------------- 
863     Int_t i;
864     Int_t istrip;
865
866   for (i=0; i<16; i++){
867     y3[i]=y3[i]&!resetMid;
868     y4[i]=y4[i]&!resetMid;
869   }
870
871   Int_t ch1[16], ch2[16], ch3[16], ch4[16];
872
873   Int_t tmpy3to16[16], tmpy4to16[16];
874   Int_t tmpy3uto16[16], tmpy3dto16[16], tmpy4uto16[16], tmpy4dto16[16];
875   for (i=0; i<8; i++){
876     ch1[2*i]   = y1[i]&x2m | y1[2*i]&!x2m;              
877     ch1[2*i+1] = y1[i]&x2m | y1[2*i+1]&!x2m;
878
879     ch2[2*i]   = y2[i]&x2m | y2[2*i]&!x2m;              
880     ch2[2*i+1] = y2[i]&x2m | y2[2*i+1]&!x2m;
881
882     tmpy3to16[2*i]   = y3[i]&x2m | y3[2*i]&!x2m;                
883     tmpy3to16[2*i+1] = y3[i]&x2m | y3[2*i+1]&!x2m;
884
885     tmpy4to16[2*i]   = y4[i]&x2m | y4[2*i]&!x2m;
886     tmpy4to16[2*i+1] = y4[i]&x2m | y4[2*i+1]&!x2m;
887
888     tmpy3uto16[2*i]   = y3u[i]&x2ud | y3u[2*i]&!x2ud; 
889     tmpy3uto16[2*i+1] = y3u[i]&x2ud | y3u[2*i+1]&!x2ud;
890
891     tmpy4uto16[2*i]   = y4u[i]&x2ud | y4u[2*i]&!x2ud; 
892     tmpy4uto16[2*i+1] = y4u[i]&x2ud | y4u[2*i+1]&!x2ud;
893
894     tmpy3dto16[2*i]   = y3d[i]&x2ud | y3d[2*i]&!x2ud; 
895     tmpy3dto16[2*i+1] = y3d[i]&x2ud | y3d[2*i+1]&!x2ud;
896     
897     tmpy4dto16[2*i]   = y4d[i]&x2ud | y4d[2*i]&!x2ud; 
898     tmpy4dto16[2*i+1] = y4d[i]&x2ud | y4d[2*i+1]&!x2ud;
899   }
900   
901   if (orMud[0]==0&&orMud[1]==0){
902     for (i=0; i<16; i++){
903       ch3[i] = tmpy3to16[i];
904       ch4[i] = tmpy4to16[i];
905     }
906   }
907   if (orMud[0]==0&&orMud[1]==1){
908       for (i=0; i<16; i++){
909         ch3[i] = tmpy3uto16[i]|tmpy3to16[i];
910         ch4[i] = tmpy4uto16[i]|tmpy4to16[i];
911       }
912   }
913   if (orMud[0]==1&&orMud[1]==0){
914       for (i=0; i<16; i++){
915         ch3[i] = tmpy3dto16[i]|tmpy3to16[i];
916         ch4[i] = tmpy4dto16[i]|tmpy4to16[i];
917       }
918   }
919   if (orMud[0]==1&&orMud[1]==1){
920       for (i=0; i<16; i++){
921         ch3[i] = tmpy3dto16[i]|tmpy3to16[i]|tmpy3uto16[i];
922         ch4[i] = tmpy4dto16[i]|tmpy4to16[i]|tmpy4uto16[i];
923       }
924   }
925
926 // debug
927   if(fDebug==4||fDebug==5) {
928     cout << "===============================================================" << "\n";  
929     cout << " Y plane after PreHandling x2m x2ud orMud " 
930          << x2m << " , " << x2ud << " , " << orMud[0] << orMud[1] << "\n"; 
931     cout << "                            ";
932     for (istrip=15; istrip>=0; istrip--) {
933       if (istrip>9) cout << istrip-10*Int_t(istrip/10);
934       if (istrip<10) cout << istrip;
935     }  
936     cout << "\n YMC11                      ";
937     for (istrip=15; istrip>=0; istrip--) {
938       cout << ch1[istrip]; 
939     }
940     cout << "\n YMC12                      ";
941     for (istrip=15; istrip>=0; istrip--) {
942       cout << ch2[istrip]; 
943     }
944     cout << "\n YMC21                      ";
945     for (istrip=15; istrip>=0; istrip--) {
946       cout << ch3[istrip]; 
947     }
948     cout << "\n YMC22                      ";
949     for (istrip=15; istrip>=0; istrip--) {
950       cout << ch4[istrip]; 
951     }
952     cout << " \n"; 
953   }
954 //debug
955   
956 //---------------------------------------------------------
957 // step # 2 : calculate sgle and dble, apply DS reduction
958 //--------------------------------------------------------- 
959   Int_t sgle1[16], dble1[16];
960   Int_t sgle2[16], dble2[16];
961
962   // Calculate simple and double hits
963   for (i=0; i<16; i++) {
964     dble1[i] = ch1[i] & ch2[i];
965     dble2[i] = ch3[i] & ch4[i];
966     
967     sgle1[i] = (ch1[i]|ch2[i]);
968     sgle2[i] = (ch3[i]|ch4[i]);
969   }
970
971   //debug
972   if(fDebug==4||fDebug==5) {
973     cout << "===============================================================" << "\n";
974     cout << " Y plane after sgle dble " << "\n"; 
975     cout << "                            ";
976     for (istrip=15; istrip>=0; istrip--) {
977       if (istrip>9) { cout << istrip-10*Int_t(istrip/10);}
978       if (istrip<10) { cout << istrip;}
979     }  
980     cout << "\n SGLE1                      ";
981     for (istrip=15; istrip>=0; istrip--) {
982       cout << sgle1[istrip]; 
983     }
984     cout << "\n DBLE1                      ";
985     for (istrip=15; istrip>=0; istrip--) {
986       cout << dble1[istrip]; 
987     }
988     cout << "\n SGLE2                      ";
989     for (istrip=15; istrip>=0; istrip--) {
990       cout << sgle2[istrip]; 
991     }
992     cout << "\n DBLE2                      ";
993     for (istrip=15; istrip>=0; istrip--) {
994       cout << dble2[istrip]; 
995     }
996     cout << " \n"; 
997   }
998   //debug
999
1000   // DS Reduction 
1001   Int_t notOr1, notOr2;
1002
1003   notOr1=!dble1[15] & !dble1[14] & !dble1[13] & !dble1[12] & 
1004          !dble1[11] & !dble1[10] & !dble1[9]  & !dble1[8]  & 
1005          !dble1[7]  & !dble1[6]  & !dble1[5]  & !dble1[4]  & 
1006          !dble1[3]  & !dble1[2]  & !dble1[1]  & !dble1[0];
1007
1008   notOr2=!dble2[15] & !dble2[14] & !dble2[13] & !dble2[12] & 
1009          !dble2[11] & !dble2[10] & !dble2[9]  & !dble2[8]  & 
1010          !dble2[7]  & !dble2[6]  & !dble2[5]  & !dble2[4]  & 
1011          !dble2[3]  & !dble2[2]  & !dble2[1]  & !dble2[0];
1012
1013   for (i=0; i<16; i++) {
1014     sgle1[i] = sgle1[i] & notOr1 & !coinc44;
1015     sgle2[i] = sgle2[i] & notOr2 & !coinc44;
1016   }
1017
1018 //---------------------------------------------------------
1019 // step # 3 : 3/4 coincidence 
1020 //--------------------------------------------------------- 
1021   Int_t frontImage[16];
1022
1023   for (i=1; i<15; i++) {
1024   frontImage[i] = (dble1[i] | sgle1[i]) & 
1025     (dble2[i+1] | dble2[i] | dble2[i-1]) |
1026      dble1[i] & (sgle2[i+1] | sgle2[i] | sgle2[i-1]);
1027   }
1028   frontImage[0] = (dble1[0] | sgle1[0]) & 
1029     (dble2[1] | dble2[0]) | dble1[0] & (sgle2[1] | sgle2[0]);
1030
1031   frontImage[15] = (dble1[15] | sgle1[15]) & 
1032     (dble2[15] | dble2[14]) | dble1[15] & (sgle2[15] | sgle2[14]);
1033
1034
1035 //debug
1036   if(fDebug==4||fDebug==5) {
1037     cout << "===============================================================" << "\n";
1038     cout << " Y plane frontImage\n";
1039     cout << "                            ";
1040   for (istrip=15; istrip>=0; istrip--) {
1041     if (istrip>9) cout << istrip-10*Int_t(istrip/10);
1042     if (istrip<10) cout << istrip;
1043   }
1044     cout << "\n                            ";
1045     for (istrip=15; istrip>=0; istrip--) {
1046       cout << frontImage[istrip]; 
1047     }
1048     cout << "\n";
1049   }
1050 //debug
1051
1052 //---------------------------------------------------------
1053 // step # 4 : Y position 
1054 //--------------------------------------------------------- 
1055   Int_t or1, or2, and1, and2, and3;
1056
1057  or1  = frontImage[7]|frontImage[5]|frontImage[3]|frontImage[1];
1058  or2  = frontImage[7]|frontImage[6]|frontImage[5]|frontImage[4];
1059  and1 = !frontImage[3]&!frontImage[2]&!frontImage[1]&!frontImage[0];
1060  and2 = !frontImage[7]&!frontImage[6]&!frontImage[5]&!frontImage[4] & and1;
1061  and3 = !frontImage[11]&!frontImage[10]&!frontImage[9]&!frontImage[8]; 
1062  
1063  coordY[0] = !frontImage[0]&(frontImage[1]|!frontImage[2]) & 
1064 (frontImage[3]|frontImage[1]|!frontImage[4]&(frontImage[5]|!frontImage[6])) &
1065 (or1|!frontImage[8]&(frontImage[9]|!frontImage[10])) & 
1066 (or1|frontImage[11]|frontImage[9]|!frontImage[12]&(frontImage[13]|!frontImage[14]));
1067  
1068  coordY[1] = !frontImage[0]&!frontImage[1] & 
1069 !(!frontImage[11]&!frontImage[10]&!frontImage[7]&!frontImage[6] & 
1070   !frontImage[3]&!frontImage[2]&(frontImage[13]|frontImage[12])) &
1071   (frontImage[3]|frontImage[2] | !frontImage[5]&!frontImage[4]) & 
1072   (frontImage[7]|frontImage[6]|frontImage[3]|frontImage[2] | 
1073 !frontImage[9]&!frontImage[8]);
1074                 
1075  coordY[2] = and1 & (or2 | and3);
1076                 
1077  coordY[3] = and2;
1078                 
1079  coordY[4] = !frontImage[15]&!frontImage[14]&!frontImage[13]&!frontImage[12] &
1080  and2 & and3 ;
1081
1082 }
1083 //----------------------------------------------------------------------
1084 // end of trigger Algo
1085 //----------------------------------------------------------------------
1086
1087 //----------------------------------------------------------------------
1088 void AliMUONTriggerDecision::LocalTrigger(Int_t icirc, 
1089                                           Int_t minDevStrip[5], 
1090                                           Int_t minDev[5], Int_t coordY[5], 
1091                                           Int_t &iTrigger){
1092 // returns local trigger answer for circuit icirc
1093   Int_t i;
1094
1095   AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");  
1096   AliMUONTriggerCircuit* triggerCircuit;
1097   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
1098   Int_t idCircuit=triggerCircuit->GetIdCircuit();
1099   
1100   Int_t signDev=minDev[4];   
1101   Int_t deviation=0;
1102   for (i=0; i<4; i++) {          // extract deviation
1103     deviation = deviation+Int_t(minDev[i]*TMath::Power(2,i));   
1104   }
1105   
1106   Int_t istripX1Circ=0;
1107   for (i=0; i<5; i++) {          // extract X1 strip fired 
1108     istripX1Circ = istripX1Circ+Int_t(minDevStrip[i]*TMath::Power(2,i));   
1109   }
1110   
1111   Int_t iStripY=0;
1112   for (i=0; i<4; i++) {          // extract Y strip fired 
1113     iStripY = iStripY+Int_t(coordY[i]*TMath::Power(2,i));   
1114   }
1115
1116 // trigger or not 
1117   if (signDev==1&&deviation==0) {      // something in X ?
1118     iTrigger=0;    
1119   } else {
1120     if (coordY[4]==1&&iStripY==15) {   // something in Y ?
1121       iTrigger=0;
1122     } else {
1123       iTrigger=1;
1124     }
1125   }
1126   
1127   if (iTrigger==1) { 
1128 // fill fTrigger fStripX11 fStripY11 
1129     fTrigger[icirc] = 1;
1130     fStripX11[icirc] = istripX1Circ;
1131     fStripY11[icirc] = iStripY;
1132     
1133 // calculate deviation in [0+30]
1134     Int_t sign=0;
1135     if (signDev==0&&deviation!=0) sign=-1;
1136     if (signDev==0&&deviation==0) sign=0;
1137     if (signDev==1)               sign=1;    
1138     fDev[icirc] = sign * deviation + 15; // fill fDev 
1139
1140 // get Lut output for circuit/istripX/idev/istripY
1141     AliMUONTriggerLut* lut = new AliMUONTriggerLut;    
1142     //    lut->StartEvent();
1143     lut->GetLutOutput(icirc,fStripX11[icirc],fDev[icirc],fStripY11[icirc],
1144                       fLutLpt[icirc],fLutHpt[icirc],fLutApt[icirc]);
1145     //    lut->FinishEvent();
1146     delete lut;
1147     
1148     if (fDebug>1) {
1149       Float_t pt= // get ptCal corresponding to istripX1Circ/idev/iStripY
1150       triggerCircuit->PtCal(fStripX11[icirc],fDev[icirc],fStripY11[icirc]);
1151       cout << "-------------------------------------------" << "\n";
1152       cout << " Local Trigger info for circuit Id " << idCircuit 
1153            << " (number " << icirc << ")" << "\n";
1154       cout << " istripX1 signDev deviation istripY = " 
1155            << istripX1Circ << " , " << signDev 
1156            << " , " << deviation << " , " << iStripY << "\n";      
1157       cout << " pt = " << pt << " (GeV/c) " << "\n";
1158       cout << "-------------------------------------------" << "\n";
1159       cout << " Local Trigger Lut Output = Lpt : " ;
1160       for (i=1; i>=0; i--) { cout << fLutLpt[icirc][i] ; }
1161       cout << " Hpt : ";
1162       for (i=1; i>=0; i--) { cout << fLutHpt[icirc][i] ; }
1163       cout << " Apt : ";
1164       for (i=1; i>=0; i--) { cout << fLutApt[icirc][i] ; }        
1165       cout << "\n";
1166       cout << "-------------------------------------------" << "\n";
1167     } // fDebug > 1    
1168   }  // local trigger = 1
1169 }
1170
1171 //----------------------------------------------------------------------
1172 void AliMUONTriggerDecision::GlobalTrigger(){
1173 // loop on Lut[icirc] and give Global Trigger output
1174     Int_t i;
1175
1176   for (Int_t icirc=0; icirc<234; icirc++){
1177     if (fLutLpt[icirc][0]==1&&fLutLpt[icirc][1]==1) 
1178       fGlobalSingleUndef[0] = fGlobalSingleUndef[0] + 1;
1179     if (fLutHpt[icirc][0]==1&&fLutHpt[icirc][1]==1) 
1180       fGlobalSingleUndef[1] = fGlobalSingleUndef[1] + 1;
1181     if (fLutApt[icirc][0]==1&&fLutApt[icirc][1]==1) 
1182       fGlobalSingleUndef[2] = fGlobalSingleUndef[2] + 1;
1183     
1184     if (fLutLpt[icirc][0]==0&&fLutLpt[icirc][1]==1) 
1185       fGlobalSinglePlus[0] = fGlobalSinglePlus[0] + 1;
1186     if (fLutHpt[icirc][0]==0&&fLutHpt[icirc][1]==1) 
1187       fGlobalSinglePlus[1] = fGlobalSinglePlus[1] + 1;
1188     if (fLutApt[icirc][0]==0&&fLutApt[icirc][1]==1) 
1189       fGlobalSinglePlus[2] = fGlobalSinglePlus[2] + 1;
1190
1191     if (fLutLpt[icirc][0]==1&&fLutLpt[icirc][1]==0) 
1192       fGlobalSingleMinus[0] = fGlobalSingleMinus[0] + 1;
1193     if (fLutHpt[icirc][0]==1&&fLutHpt[icirc][1]==0) 
1194       fGlobalSingleMinus[1] = fGlobalSingleMinus[1] + 1;
1195     if (fLutApt[icirc][0]==1&&fLutApt[icirc][1]==0) 
1196       fGlobalSingleMinus[2] = fGlobalSingleMinus[2] + 1;
1197   }
1198
1199   // like sign low, high and all pt
1200   for (i=0; i<3; i++) {
1201     fGlobalPairLike[i]=fGlobalSingleMinus[i]*(fGlobalSingleMinus[i]-1)/2 + 
1202       fGlobalSinglePlus[i]*(fGlobalSinglePlus[i]-1)/2 + 
1203       fGlobalSingleUndef[i]*(fGlobalSingleUndef[i]-1)/2 + 
1204       fGlobalSingleUndef[i]*fGlobalSinglePlus[i] + 
1205       fGlobalSingleUndef[i]*fGlobalSingleMinus[i];
1206   }
1207
1208   // unlike sign low, high and all pt
1209   for (i=0; i<3; i++) {
1210     fGlobalPairUnlike[i]=fGlobalSingleMinus[i]*fGlobalSinglePlus[i] +
1211       fGlobalSingleUndef[i]*(fGlobalSingleUndef[i]-1)/2 + 
1212       fGlobalSingleUndef[i]*fGlobalSinglePlus[i] + 
1213       fGlobalSingleUndef[i]*fGlobalSingleMinus[i]; 
1214   }
1215   
1216   if (fDebug>=1) {
1217     cout << "\n";
1218     cout << "===================================================" << "\n";
1219     cout << " Global Trigger output       " << "Low pt  High pt   All"  << "\n";
1220     cout << " number of Single Plus      :\t";
1221     for (i=0; i<3; i++) { cout << fGlobalSinglePlus[i] <<"\t";}
1222     cout << "\n";
1223     cout << " number of Single Minus     :\t";
1224     for (i=0; i<3; i++) { cout << fGlobalSingleMinus[i] <<"\t";}
1225     cout << "\n";
1226     cout << " number of Single Undefined :\t"; 
1227     for (i=0; i<3; i++) { cout << fGlobalSingleUndef[i] <<"\t";}
1228     cout << "\n";
1229     cout << " number of UnlikeSign pair  :\t"; 
1230     for (i=0; i<3; i++) { cout << fGlobalPairUnlike[i] <<"\t";}
1231     cout << "\n";
1232     cout << " number of LikeSign pair    :\t";  
1233     for (i=0; i<3; i++) { cout << fGlobalPairLike[i] <<"\t";}
1234     cout << "\n";
1235     cout << "===================================================" << "\n";
1236   }
1237 }
1238
1239 //----------------------------------------------------------------------
1240 void AliMUONTriggerDecision::PrintBitPatXInput(Int_t icirc){
1241 // print bit pattern for X strips
1242
1243     Int_t istrip;
1244
1245   cout << "-------- TRIGGER INPUT ---------" << "\n";
1246   cout << "===============================================================" << "\n";
1247   cout << "                            5432109876543210";
1248   cout << "\n XMC11                      ";
1249   for (istrip=15; istrip>=0; istrip--) {
1250     cout << fXbit11[icirc][istrip]; 
1251   }
1252   cout << "\n XMC12                      ";
1253   for (istrip=15; istrip>=0; istrip--) {
1254     cout << fXbit12[icirc][istrip]; 
1255   }
1256   cout << "\n XMC21              ";
1257   for (istrip=31; istrip>=0; istrip--) {
1258     cout << fXbit21[icirc][istrip]; 
1259   }
1260   cout << "\n XMC22              ";
1261   for (istrip=31; istrip>=0; istrip--) {
1262     cout << fXbit22[icirc][istrip]; 
1263   }
1264   cout << "\n                    ";
1265   cout << "10987654321098765432109876543210" << "\n";
1266 }
1267
1268 //----------------------------------------------------------------------
1269 void AliMUONTriggerDecision::PrintBitPatYInput(Int_t icirc){
1270 // print bit pattern for Y strips
1271
1272     Int_t istrip;
1273
1274   AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");  
1275   AliMUONTriggerCircuit* triggerCircuit;
1276   triggerCircuit = &(pMUON->TriggerCircuit(icirc));       
1277   Int_t idCircuit=triggerCircuit->GetIdCircuit();
1278   Int_t nStrip=triggerCircuit->GetNstripY();
1279
1280   cout << "---------------------------------------------------------------" << "\n";
1281   cout << "                            ";
1282   for (istrip=nStrip-1; istrip>=0; istrip--) {
1283     if (istrip>9) { cout << istrip-10*Int_t(istrip/10);}
1284     if (istrip<10) { cout << istrip;}
1285   }
1286   cout << "\n YMC11                      ";
1287   for (istrip=nStrip-1; istrip>=0; istrip--) {
1288     cout << fYbit11[icirc][istrip]; 
1289   }
1290   cout << "\n YMC12                      ";
1291   for (istrip=nStrip-1; istrip>=0; istrip--) {
1292     cout << fYbit12[icirc][istrip]; 
1293   }
1294   cout << "\n YMC21                      ";
1295   for (istrip=nStrip-1; istrip>=0; istrip--) {
1296     cout << fYbit21[icirc][istrip]; 
1297   }
1298   cout << "\n YMC22                      ";
1299   for (istrip=nStrip-1; istrip>=0; istrip--) {
1300     cout << fYbit22[icirc][istrip]; 
1301   }
1302   cout << "\n";
1303 // tmp
1304   cout << "---------------------------------------------------------------";
1305   cout << "\n upper part of circuit " << idCircuit ;
1306   cout << "\n UMC21                      ";
1307   for (istrip=15; istrip>=0; istrip--) {
1308     cout << fYbit21U[icirc][istrip]; 
1309   }
1310   cout << "\n UMC22                      ";
1311   for (istrip=15; istrip>=0; istrip--) {
1312     cout << fYbit22U[icirc][istrip]; 
1313   }
1314
1315   cout << "\n lower part of circuit " << idCircuit ;
1316   cout << "\n LMC21                      ";
1317   for (istrip=15; istrip>=0; istrip--) {
1318     cout << fYbit21D[icirc][istrip]; 
1319   }
1320   cout << "\n LMC22                      ";
1321   for (istrip=15; istrip>=0; istrip--) {
1322     cout << fYbit22D[icirc][istrip]; 
1323   }
1324   cout << "\n";
1325   cout << "===============================================================" << "\n";
1326 }
1327 //----------------------------------------------------------------------
1328 void AliMUONTriggerDecision::PrintLocalOutput(Int_t minDevStrip[5], 
1329                                               Int_t minDev[5], 
1330                                               Int_t coordY[5]){
1331 // print Local trigger output before the LuT step
1332
1333     Int_t i;
1334
1335   cout << "===============================================================" << "\n";
1336   cout << "-------- TRIGGER OUTPUT --------" << "\n";
1337   cout << "minDevStrip = ";
1338   for  (i=4; i>=0; i--) {cout << minDevStrip[i];}
1339   cout << " minDev = ";
1340   for  (i=4; i>=0; i--) {cout << minDev[i];} 
1341   cout << " coordY = ";
1342   for  (i=4; i>=0; i--) {cout << coordY[i];} 
1343   cout << " " << "\n";  
1344 }
1345
1346 //----------------------------------------------------------------------
1347 //--- methods which return member data related info
1348 //----------------------------------------------------------------------
1349 Int_t AliMUONTriggerDecision::GetITrigger(Int_t icirc){
1350 // returns Local Trigger Status
1351   return fTrigger[icirc];
1352 }
1353 //----------------------------------------------------------------------
1354 Int_t AliMUONTriggerDecision::GetStripX11(Int_t icirc){
1355 // returns fStripX11
1356   return fStripX11[icirc];
1357 }
1358 //----------------------------------------------------------------------
1359 Int_t AliMUONTriggerDecision::GetDev(Int_t icirc){
1360 // returns idev
1361   return fDev[icirc];
1362 }
1363 //----------------------------------------------------------------------
1364 Int_t AliMUONTriggerDecision::GetStripY11(Int_t icirc){
1365 // returns fStripY11;
1366    return fStripY11[icirc];
1367 }
1368 //----------------------------------------------------------------------
1369 void AliMUONTriggerDecision::GetLutOutput(Int_t icirc, Int_t lpt[2], 
1370                                           Int_t hpt[2], Int_t apt[2]){
1371 // returns Look up Table output
1372   for (Int_t i=0; i<2; i++) {
1373     lpt[i]=fLutLpt[icirc][i];
1374     hpt[i]=fLutHpt[icirc][i];
1375     apt[i]=fLutApt[icirc][i];
1376   }
1377 }
1378 //----------------------------------------------------------------------
1379 void AliMUONTriggerDecision::GetGlobalTrigger(Int_t singlePlus[3], 
1380                                               Int_t singleMinus[3], 
1381                                               Int_t singleUndef[3],
1382                                               Int_t pairUnlike[3], 
1383                                               Int_t pairLike[3]){
1384 // returns Global Trigger information (0,1,2 : Lpt,Hpt,Apt)
1385   for (Int_t i=0; i<3; i++) { 
1386     singlePlus[i]  = fGlobalSinglePlus[i];
1387     singleMinus[i] = fGlobalSingleMinus[i];
1388     singleUndef[i] = fGlobalSingleUndef[i];
1389     pairUnlike[i]  = fGlobalPairUnlike[i];
1390     pairLike[i]    = fGlobalPairLike[i];    
1391   }
1392 }
1393 //----------------------------------------------------------------------
1394 //--- end of methods which return member data related info
1395 //----------------------------------------------------------------------
1396 //----------------------------------------------------------------------
1397 /*
1398 void AliMUONTriggerDecision::AddLocalTrigger(const AliMUONLocalTrigger c){
1399 // Add a Local Trigger copy to the list
1400   AliMUON *MUON=(AliMUON*)gAlice->GetModule("MUON");
1401   MUON->AddLocalTrigger(c); 
1402   fNLocalTriggers++;
1403 }
1404 */