]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGlobalTriggerBoard.cxx
ADC scale for SDD in simulation calibrated on real cosmic data (F. Prino)
[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    MaskRegionalInput();
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[1]; trgUS1[0] = a[0]; 
162       //trgLS2[0] = b[1]; trgUS2[0] = b[0];
163       trgLS1[0] = a[0]; trgUS1[0] = a[1]; 
164       trgLS2[0] = b[0]; trgUS2[0] = b[1];
165    }
166    else
167    {
168       //trgLS1[0] = a[5]; trgUS1[0] = a[4]; 
169       //trgLS2[0] = b[5]; trgUS2[0] = b[4];         
170       trgLS1[0] = a[4]; trgUS1[0] = a[5]; 
171       trgLS2[0] = b[4]; trgUS2[0] = b[5];         
172    }
173
174    trgLS[0] = ( trg1[0] & trg2[0] ) | ( trg1[1] & trg2[1] ) | trgLS1[0] | trgLS2[0];
175    trgUS[0] = ( trg1[0] & trg2[1] ) | ( trg1[1] & trg2[0] ) | trgUS1[0] | trgUS2[0];
176    
177    trg[0] = trg1[0] | trg2[0];
178    trg[1] = trg1[1] | trg2[1];
179    
180    TBits v(4);
181    
182    //v[0] = trgUS[0];
183    //v[1] = trgLS[0];
184    v[0] = trgLS[0];
185    v[1] = trgUS[0];
186    v[2] = trg[0];
187    v[3] = trg[1];
188
189    UShort_t rv = 0;
190    v.Get(&rv);
191    
192    return rv;
193 }
194
195 //___________________________________________
196 void AliMUONGlobalTriggerBoard::BuildGlobalInput()
197 {
198   /// build the 4 words (32bits) global input from the regional responses
199   /// the order of regional responses is:
200   /// 1R, 2R, 2-3R, 3R, 4R, 5R, 6R, 7R, 1L, 2L, 2-3L, 3L, 4L, 5L, 6L, 7L
201
202   for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
203
204   for (Int_t iReg = 0; iReg < 16; iReg++) {
205     if (iReg < 8) {    // right
206       // Lpt word
207       fGlobalInput[0] |=  (fRegionalResponse[iReg] & 0x0F)       << (4*iReg);
208       // Hpt word
209       fGlobalInput[2] |= ((fRegionalResponse[iReg] & 0xF0) >> 4) << (4*iReg);
210     } else {           // left
211       // Lpt word
212       fGlobalInput[1] |=  (fRegionalResponse[iReg] & 0x0F)       << (4*(iReg-8));
213       // Hpt word
214       fGlobalInput[3] |= ((fRegionalResponse[iReg] & 0xF0) >> 4) << (4*(iReg-8));
215     }
216
217   }
218
219 }
220
221 //___________________________________________
222 void AliMUONGlobalTriggerBoard::MaskRegionalInput()
223 {
224   /// Apply masks to global input and recalculate regional inputs before
225   /// applying the global response
226
227   // temporary global inputs with masks applied
228   UInt_t gitmp[4];
229
230   for (Int_t i = 0; i < 4; i++) {
231     gitmp[i] = fGlobalInput[i];
232     gitmp[i] &= fMask[i];
233   }
234
235   for (Int_t iReg = 0; iReg < 16; iReg++) {
236     fRegionalResponse[iReg] = 0;
237     if (iReg < 8) {    // right
238       // Lpt
239       fRegionalResponse[iReg] |=  (gitmp[0] >> (4*iReg))     & 0xF;
240       // Hpt
241       fRegionalResponse[iReg] |= ((gitmp[2] >> (4*iReg))     & 0xF) << 4;
242     } else {           // left
243       // Lpt
244       fRegionalResponse[iReg] |=  (gitmp[1] >> (4*(iReg-8))) & 0xF;
245       // Hpt
246       fRegionalResponse[iReg] |= ((gitmp[3] >> (4*(iReg-8))) & 0xF) << 4;
247     }
248   }
249
250 }
251
252 //___________________________________________
253 void AliMUONGlobalTriggerBoard::Scan(Option_t*) const
254 {
255   /// print global trigger output 
256   TBits w(6); w.Set(6,&fResponse);
257
258 // TRG[1:0]
259 // 00 noth
260 // 01 negative track
261 // 10 positive track
262 // 11 undef
263
264    Int_t iS[2] = {0,0};
265
266    iS[0] = (Int_t)w.TestBitNumber(0);
267    iS[1] = (Int_t)w.TestBitNumber(1);
268
269    Int_t iPU[2] = {w[4],w[5]};
270    Int_t iPL[2] = {w[2],w[3]};
271
272    printf("============================================\n");
273    printf(" Global Trigger output       Low pt  High pt\n");
274    printf(" number of Single           :\t");
275    for (Int_t i=0; i<2; i++) printf("%i\t",iS[i]);
276    printf("\n");
277    printf(" number of UnlikeSign pair  :\t"); 
278    for (Int_t i=0; i<2; i++) printf("%i\t",iPU[i]);
279    printf("\n");
280    printf(" number of LikeSign pair    :\t");  
281    for (Int_t i=0; i<2; i++) printf("%i\t",iPL[i]);
282    printf("\n");
283    printf("===================================================\n");
284    printf("\n");
285 }
286