In trigger:
[u/mrichter/AliRoot.git] / MUON / AliMUONGlobalTriggerBoard.cxx
CommitLineData
d15ca731 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
3d1463c8 18//-----------------------------------------------------------------------------
c4ee792d 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///
c05673c9 25/// \author Rachid Guernane (LPCCFd),
26/// Corrected by Christian Finck (Subatech)
3d1463c8 27//-----------------------------------------------------------------------------
d15ca731 28
29#include "AliMUONGlobalTriggerBoard.h"
41922e78 30#include "AliLog.h"
d15ca731 31#include "TBits.h"
32
33#include <Riostream.h>
34
c05673c9 35/// \cond CLASSIMP
d15ca731 36ClassImp(AliMUONGlobalTriggerBoard)
c05673c9 37/// \endcond
d15ca731 38
39//___________________________________________
c05673c9 40AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(): AliMUONTriggerBoard()
d15ca731 41{
71a2d3aa 42/// Default constructor
43
d15ca731 44 for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
41a38dec 45 for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
d15ca731 46}
47
48//___________________________________________
49AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(const char *name, Int_t a) : AliMUONTriggerBoard(name, a)
50{
71a2d3aa 51/// Standard constructor
52
d15ca731 53 for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
41a38dec 54 for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
d15ca731 55}
56
71a2d3aa 57//___________________________________________
58AliMUONGlobalTriggerBoard::~AliMUONGlobalTriggerBoard()
59{
60/// Destructor
61}
62
41922e78 63//___________________________________________
41a38dec 64void AliMUONGlobalTriggerBoard::Mask(Int_t index, UInt_t mask)
41922e78 65{
c05673c9 66 /// mask global trigger board input index with value mask
41a38dec 67 if ( index >= 0 && index < 4 )
41922e78 68 {
69 fMask[index]=mask;
70 }
71 else
72 {
41a38dec 73 AliError(Form("Index %d out of bounds (max %d)",index,3));
41922e78 74 }
75}
76
d15ca731 77//___________________________________________
78void AliMUONGlobalTriggerBoard::Response()
79{
c05673c9 80 /// compute the global trigger board
81 /// response according to the algo() method
71a2d3aa 82// output from global trigger algorithm
254985cb 83// [+, -, US, LS] * [Hpt, Lpt]
71a2d3aa 84// transformed to [usHpt, usLpt, lsHpt, lsLpt, sHpt, sLpt] according
85// to Global Trigger Unit user manual
d15ca731 86
8d4fefab 87 Int_t t[16];
d15ca731 88
41a38dec 89 BuildGlobalInput();
f4e2cda2 90 MaskGlobalInput();
41a38dec 91
c05673c9 92 for (Int_t i = 0; i < 16; ++i)
93 {
41a38dec 94 t[i] = fRegionalResponse[i];
c05673c9 95 }
96
254985cb 97
d15ca731 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 {
ad705f30 106 UShort_t lthres = Algo(t[2*j],t[2*j+1],"LPT");
d15ca731 107
ad705f30 108 UShort_t hthres = Algo(t[2*j],t[2*j+1],"HPT"); hthres <<= 4;
d15ca731 109
ad705f30 110 t[ip] = lthres | hthres;
d15ca731 111
112 ip++;
113 }
114
115 rank /= 2;
116 }
8d4fefab 117 UChar_t sLpt, sHpt, lsLpt, lsHpt, usLpt, usHpt;
118 sLpt = ((t[0] & 0xC) != 0);
119 sHpt = ((t[0] & 0xC0) != 0);
254985cb 120 lsLpt = ((t[0] & 0x1) != 0);
254985cb 121 lsHpt = ((t[0] & 0x10) != 0);
254985cb 122 usLpt = ((t[0] & 0x2 ) != 0);
254985cb 123 usHpt = ((t[0] & 0x20) != 0);
8d4fefab 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;
254985cb 132
133
d15ca731 134}
135
136//___________________________________________
a6e0ebfe 137UShort_t AliMUONGlobalTriggerBoard::Algo(UShort_t i, UShort_t j, const char *thres)
d15ca731 138{
254985cb 139/// global trigger algorithm
140/// a ,b = reg response = Hpt (+|-|us|ls) | Lpt (+|-|us|ls)
141
ad705f30 142 TBits a(8), b(8); a.Set(8,&i); b.Set(8,&j);
d15ca731 143
144 TBits trg1(2), trg2(2), trg(2);
145
ad705f30 146 if (!strcmp(thres,"LPT"))
d15ca731 147 {
148 trg1[0] = a[2]; trg1[1] = a[3];
149 trg2[0] = b[2]; trg2[1] = b[3];
150 }
d15ca731 151 else
152 {
ad705f30 153 trg1[0] = a[6]; trg1[1] = a[7];
154 trg2[0] = b[6]; trg2[1] = b[7];
d15ca731 155 }
156
157 TBits trgLS1(1), trgUS1(1), trgLS2(1), trgUS2(1), trgLS(1), trgUS(1);
158
ad705f30 159 if (!strcmp(thres,"LPT"))
d15ca731 160 {
254985cb 161 trgLS1[0] = a[0]; trgUS1[0] = a[1];
162 trgLS2[0] = b[0]; trgUS2[0] = b[1];
d15ca731 163 }
d15ca731 164 else
165 {
254985cb 166 trgLS1[0] = a[4]; trgUS1[0] = a[5];
167 trgLS2[0] = b[4]; trgUS2[0] = b[5];
d15ca731 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
254985cb 178 v[0] = trgLS[0];
179 v[1] = trgUS[0];
d15ca731 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
41a38dec 189//___________________________________________
190void 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
f4e2cda2 198 UShort_t regRespInv;
199 TBits rs(8), rsi(8);
41a38dec 200 for (Int_t iReg = 0; iReg < 16; iReg++) {
f4e2cda2 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
41a38dec 211 if (iReg < 8) { // right
212 // Lpt word
f4e2cda2 213 fGlobalInput[0] |= (regRespInv & 0x0F) << (4*iReg);
41a38dec 214 // Hpt word
f4e2cda2 215 fGlobalInput[2] |= ((regRespInv & 0xF0) >> 4) << (4*iReg);
41a38dec 216 } else { // left
217 // Lpt word
f4e2cda2 218 fGlobalInput[1] |= (regRespInv & 0x0F) << (4*(iReg-8));
41a38dec 219 // Hpt word
f4e2cda2 220 fGlobalInput[3] |= ((regRespInv & 0xF0) >> 4) << (4*(iReg-8));
41a38dec 221 }
222
223 }
224
225}
226
227//___________________________________________
f4e2cda2 228void AliMUONGlobalTriggerBoard::MaskGlobalInput()
41a38dec 229{
230 /// Apply masks to global input and recalculate regional inputs before
231 /// applying the global response
232
f4e2cda2 233 UShort_t regRespInv;
234 TBits rs(8), rsi(8);
235
236 // global input with masks applied
41a38dec 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 }
f4e2cda2 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;
41a38dec 266 }
267
268}
269
d15ca731 270//___________________________________________
edd00c2d 271void AliMUONGlobalTriggerBoard::Scan(Option_t*) const
d15ca731 272{
c05673c9 273 /// print global trigger output
bf309e6d 274 TBits w(6); w.Set(6,&fResponse);
d15ca731 275
276// TRG[1:0]
277// 00 noth
278// 01 negative track
279// 10 positive track
280// 11 undef
281
bf309e6d 282 Int_t iS[2] = {0,0};
d15ca731 283
bf309e6d 284 iS[0] = (Int_t)w.TestBitNumber(0);
285 iS[1] = (Int_t)w.TestBitNumber(1);
d15ca731 286
bf309e6d 287 Int_t iPU[2] = {w[4],w[5]};
288 Int_t iPL[2] = {w[2],w[3]};
d15ca731 289
ad705f30 290 printf("============================================\n");
291 printf(" Global Trigger output Low pt High pt\n");
bf309e6d 292 printf(" number of Single :\t");
293 for (Int_t i=0; i<2; i++) printf("%i\t",iS[i]);
d15ca731 294 printf("\n");
295 printf(" number of UnlikeSign pair :\t");
ad705f30 296 for (Int_t i=0; i<2; i++) printf("%i\t",iPU[i]);
d15ca731 297 printf("\n");
298 printf(" number of LikeSign pair :\t");
ad705f30 299 for (Int_t i=0; i<2; i++) printf("%i\t",iPL[i]);
d15ca731 300 printf("\n");
301 printf("===================================================\n");
302 printf("\n");
303}
304