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