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