]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGlobalTriggerBoard.cxx
c2ed96ece4ebd45b6a8af876e19b099a9d1b9de9
[u/mrichter/AliRoot.git] / MUON / AliMUONGlobalTriggerBoard.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONGlobalTriggerBoard
20 /// Global trigger implementation:
21 /// - inputs are regional responses
22 /// - output is a 12-bit word
23 /// - 4 bits per trigger level
24 ///
25 /// \author Rachid Guernane (LPCCFd), 
26 /// Corrected by Christian Finck (Subatech)
27 //-----------------------------------------------------------------------------
28
29 #include "AliMUONGlobalTriggerBoard.h"
30 #include "AliLog.h"
31 #include "TBits.h"
32
33 #include <Riostream.h>
34
35 /// \cond CLASSIMP
36 ClassImp(AliMUONGlobalTriggerBoard)
37 /// \endcond
38
39 //___________________________________________
40 AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(): AliMUONTriggerBoard()
41 {
42 /// Default constructor
43
44    for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
45    for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
46 }
47
48 //___________________________________________
49 AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(const char *name, Int_t a) : AliMUONTriggerBoard(name, a)
50 {
51 /// Standard constructor
52
53    for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
54    for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
55 }
56
57 //___________________________________________
58 AliMUONGlobalTriggerBoard::~AliMUONGlobalTriggerBoard()
59 {
60 /// Destructor
61 }
62
63 //___________________________________________
64 void AliMUONGlobalTriggerBoard::Mask(Int_t index, UInt_t mask)
65 {
66   /// mask global trigger board input index with value mask
67   if ( index >= 0 && index < 4 ) 
68   {
69     fMask[index]=mask;
70   }
71   else
72   {
73     AliError(Form("Index %d out of bounds (max %d)",index,3));
74   }  
75 }
76
77 //___________________________________________
78 void AliMUONGlobalTriggerBoard::Response()
79 {
80    /// compute the global trigger board
81    /// response according to the algo() method
82 // output from global trigger algorithm
83 // [+, -, US, LS] * [Hpt, Lpt]
84 // transformed to [usHpt, usLpt, lsHpt, lsLpt, sHpt, sLpt] according
85 // to Global Trigger Unit user manual
86
87    Int_t t[16];
88
89    BuildGlobalInput();
90    MaskGlobalInput();
91
92    for (Int_t i = 0; i < 16; ++i) 
93    {
94      t[i] = fRegionalResponse[i];
95    }
96    
97    
98    Int_t rank = 8;
99
100    for (Int_t i=0;i<4;i++)
101    {
102       Int_t ip = 0;
103       
104       for (Int_t j=0;j<rank;j++)
105       {
106          UShort_t lthres = Algo(t[2*j],t[2*j+1],"LPT");
107
108          UShort_t hthres = Algo(t[2*j],t[2*j+1],"HPT"); hthres <<= 4;
109
110          t[ip] = lthres | hthres;
111
112          ip++;
113       }
114       
115       rank /= 2; 
116    }
117    UChar_t sLpt, sHpt, lsLpt, lsHpt, usLpt, usHpt;
118    sLpt  = ((t[0] & 0xC)  != 0);
119    sHpt  = ((t[0] & 0xC0) != 0);
120    lsLpt = ((t[0] & 0x1)  != 0);
121    lsHpt = ((t[0] & 0x10) != 0);
122    usLpt = ((t[0] & 0x2 ) != 0);
123    usHpt = ((t[0] & 0x20) != 0);
124
125    sHpt  <<= 1;
126    lsLpt <<= 2;
127    lsHpt <<= 3;
128    usLpt <<= 4;
129    usHpt <<= 5;
130
131    fResponse = sLpt | sHpt | lsLpt | lsHpt | usLpt |usHpt;
132    
133
134 }
135
136 //___________________________________________
137 UShort_t AliMUONGlobalTriggerBoard::Algo(UShort_t i, UShort_t j, const char *thres)
138 {
139 /// global trigger algorithm
140 ///   a ,b = reg  response  =  Hpt (+|-|us|ls) |  Lpt (+|-|us|ls)  
141                            
142    TBits a(8), b(8); a.Set(8,&i); b.Set(8,&j);
143
144    TBits trg1(2), trg2(2), trg(2);
145
146    if (!strcmp(thres,"LPT"))
147    {
148       trg1[0] = a[2]; trg1[1] = a[3]; 
149       trg2[0] = b[2]; trg2[1] = b[3];
150    }
151    else
152    {
153       trg1[0] = a[6]; trg1[1] = a[7]; 
154       trg2[0] = b[6]; trg2[1] = b[7];         
155    }
156        
157    TBits trgLS1(1), trgUS1(1), trgLS2(1), trgUS2(1), trgLS(1), trgUS(1);
158
159    if (!strcmp(thres,"LPT"))
160    {
161       trgLS1[0] = a[0]; trgUS1[0] = a[1]; 
162       trgLS2[0] = b[0]; trgUS2[0] = b[1];
163    }
164    else
165    {
166       trgLS1[0] = a[4]; trgUS1[0] = a[5]; 
167       trgLS2[0] = b[4]; trgUS2[0] = b[5];         
168    }
169
170    trgLS[0] = ( trg1[0] & trg2[0] ) | ( trg1[1] & trg2[1] ) | trgLS1[0] | trgLS2[0];
171    trgUS[0] = ( trg1[0] & trg2[1] ) | ( trg1[1] & trg2[0] ) | trgUS1[0] | trgUS2[0];
172    
173    trg[0] = trg1[0] | trg2[0];
174    trg[1] = trg1[1] | trg2[1];
175    
176    TBits v(4);
177    
178    v[0] = trgLS[0];
179    v[1] = trgUS[0];
180    v[2] = trg[0];
181    v[3] = trg[1];
182
183    UShort_t rv = 0;
184    v.Get(&rv);
185    
186    return rv;
187 }
188
189 //___________________________________________
190 void AliMUONGlobalTriggerBoard::BuildGlobalInput()
191 {
192   /// build the 4 words (32bits) global input from the regional responses
193   /// the order of regional responses is:
194   /// 1R, 2R, 2-3R, 3R, 4R, 5R, 6R, 7R, 1L, 2L, 2-3L, 3L, 4L, 5L, 6L, 7L
195
196   for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
197
198   UShort_t regRespInv;
199   TBits rs(8), rsi(8);
200   for (Int_t iReg = 0; iReg < 16; iReg++) {
201
202     // invert bit in regional response
203     rs.Set(8,&fRegionalResponse[iReg]);
204     for (Int_t i = 0; i < 4; i++) {
205       rsi[2*i]   = rs[2*i+1];
206       rsi[2*i+1] = rs[2*i];
207     }
208     regRespInv = 0;
209     rsi.Get(&regRespInv);
210
211     if (iReg < 8) {    // right
212       // Lpt word
213       fGlobalInput[0] |=  (regRespInv & 0x0F)       << (4*iReg);
214       // Hpt word
215       fGlobalInput[2] |= ((regRespInv & 0xF0) >> 4) << (4*iReg);
216     } else {           // left
217       // Lpt word
218       fGlobalInput[1] |=  (regRespInv & 0x0F)       << (4*(iReg-8));
219       // Hpt word
220       fGlobalInput[3] |= ((regRespInv & 0xF0) >> 4) << (4*(iReg-8));
221     }
222
223   }
224
225 }
226
227 //___________________________________________
228 void AliMUONGlobalTriggerBoard::MaskGlobalInput()
229 {
230   /// Apply masks to global input and recalculate regional inputs before
231   /// applying the global response
232
233   UShort_t regRespInv;
234   TBits rs(8), rsi(8);
235
236   // global input with masks applied
237   UInt_t gitmp[4];
238
239   for (Int_t i = 0; i < 4; i++) {
240     gitmp[i] = fGlobalInput[i];
241     gitmp[i] &= fMask[i];
242   }
243
244   for (Int_t iReg = 0; iReg < 16; iReg++) {
245     fRegionalResponse[iReg] = 0;
246     if (iReg < 8) {    // right
247       // Lpt
248       fRegionalResponse[iReg] |=  (gitmp[0] >> (4*iReg))     & 0xF;
249       // Hpt
250       fRegionalResponse[iReg] |= ((gitmp[2] >> (4*iReg))     & 0xF) << 4;
251     } else {           // left
252       // Lpt
253       fRegionalResponse[iReg] |=  (gitmp[1] >> (4*(iReg-8))) & 0xF;
254       // Hpt
255       fRegionalResponse[iReg] |= ((gitmp[3] >> (4*(iReg-8))) & 0xF) << 4;
256     }
257     // invert bit in regional response
258     rs.Set(8,&fRegionalResponse[iReg]);
259     for (Int_t i = 0; i < 4; i++) {
260       rsi[2*i]   = rs[2*i+1];
261       rsi[2*i+1] = rs[2*i];
262     }
263     regRespInv = 0;
264     rsi.Get(&regRespInv);
265     fRegionalResponse[iReg] = regRespInv;
266   }
267
268 }
269
270 //___________________________________________
271 void AliMUONGlobalTriggerBoard::Scan(Option_t*) const
272 {
273   /// print global trigger output 
274   TBits w(6); w.Set(6,&fResponse);
275
276 // TRG[1:0]
277 // 00 noth
278 // 01 negative track
279 // 10 positive track
280 // 11 undef
281
282    Int_t iS[2] = {0,0};
283
284    iS[0] = (Int_t)w.TestBitNumber(0);
285    iS[1] = (Int_t)w.TestBitNumber(1);
286
287    Int_t iPU[2] = {w[4],w[5]};
288    Int_t iPL[2] = {w[2],w[3]};
289
290    printf("============================================\n");
291    printf(" Global Trigger output       Low pt  High pt\n");
292    printf(" number of Single           :\t");
293    for (Int_t i=0; i<2; i++) printf("%i\t",iS[i]);
294    printf("\n");
295    printf(" number of UnlikeSign pair  :\t"); 
296    for (Int_t i=0; i<2; i++) printf("%i\t",iPU[i]);
297    printf("\n");
298    printf(" number of LikeSign pair    :\t");  
299    for (Int_t i=0; i<2; i++) printf("%i\t",iPL[i]);
300    printf("\n");
301    printf("===================================================\n");
302    printf("\n");
303 }
304