]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGlobalTriggerBoard.cxx
Adding AliMUONQAIndices in base
[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;
f25f84f5 46 for (Int_t i=0;i< 4;i++) fMask[i] = 0xffffffff;
d15ca731 47}
48
49//___________________________________________
50AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(const char *name, Int_t a) : AliMUONTriggerBoard(name, a)
51{
71a2d3aa 52/// Standard constructor
53
d15ca731 54 for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
41a38dec 55 for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
f25f84f5 56 for (Int_t i=0;i< 4;i++) fMask[i] = 0xffffffff;
d15ca731 57}
58
71a2d3aa 59//___________________________________________
60AliMUONGlobalTriggerBoard::~AliMUONGlobalTriggerBoard()
61{
62/// Destructor
63}
64
41922e78 65//___________________________________________
41a38dec 66void AliMUONGlobalTriggerBoard::Mask(Int_t index, UInt_t mask)
41922e78 67{
c05673c9 68 /// mask global trigger board input index with value mask
41a38dec 69 if ( index >= 0 && index < 4 )
41922e78 70 {
71 fMask[index]=mask;
72 }
73 else
74 {
41a38dec 75 AliError(Form("Index %d out of bounds (max %d)",index,3));
41922e78 76 }
77}
78
d15ca731 79//___________________________________________
80void AliMUONGlobalTriggerBoard::Response()
81{
c05673c9 82 /// compute the global trigger board
83 /// response according to the algo() method
71a2d3aa 84// output from global trigger algorithm
254985cb 85// [+, -, US, LS] * [Hpt, Lpt]
71a2d3aa 86// transformed to [usHpt, usLpt, lsHpt, lsLpt, sHpt, sLpt] according
87// to Global Trigger Unit user manual
d15ca731 88
8d4fefab 89 Int_t t[16];
d15ca731 90
41a38dec 91 BuildGlobalInput();
f4e2cda2 92 MaskGlobalInput();
41a38dec 93
c05673c9 94 for (Int_t i = 0; i < 16; ++i)
95 {
41a38dec 96 t[i] = fRegionalResponse[i];
c05673c9 97 }
98
254985cb 99
d15ca731 100 Int_t rank = 8;
101
102 for (Int_t i=0;i<4;i++)
103 {
104 Int_t ip = 0;
105
106 for (Int_t j=0;j<rank;j++)
107 {
ad705f30 108 UShort_t lthres = Algo(t[2*j],t[2*j+1],"LPT");
d15ca731 109
ad705f30 110 UShort_t hthres = Algo(t[2*j],t[2*j+1],"HPT"); hthres <<= 4;
d15ca731 111
ad705f30 112 t[ip] = lthres | hthres;
d15ca731 113
114 ip++;
115 }
116
117 rank /= 2;
118 }
8d4fefab 119 UChar_t sLpt, sHpt, lsLpt, lsHpt, usLpt, usHpt;
120 sLpt = ((t[0] & 0xC) != 0);
121 sHpt = ((t[0] & 0xC0) != 0);
254985cb 122 lsLpt = ((t[0] & 0x1) != 0);
254985cb 123 lsHpt = ((t[0] & 0x10) != 0);
254985cb 124 usLpt = ((t[0] & 0x2 ) != 0);
254985cb 125 usHpt = ((t[0] & 0x20) != 0);
8d4fefab 126
f25f84f5 127 // LSB is zero (trigger choice to send to CTP: sLpt or sHpt)
128
129 sLpt <<= 1;
130 sHpt <<= 2;
131 lsLpt <<= 3;
132 lsHpt <<= 4;
133 usLpt <<= 5;
134 usHpt <<= 6;
8d4fefab 135
136 fResponse = sLpt | sHpt | lsLpt | lsHpt | usLpt |usHpt;
254985cb 137
138
d15ca731 139}
140
141//___________________________________________
a6e0ebfe 142UShort_t AliMUONGlobalTriggerBoard::Algo(UShort_t i, UShort_t j, const char *thres)
d15ca731 143{
254985cb 144/// global trigger algorithm
145/// a ,b = reg response = Hpt (+|-|us|ls) | Lpt (+|-|us|ls)
146
ad705f30 147 TBits a(8), b(8); a.Set(8,&i); b.Set(8,&j);
d15ca731 148
149 TBits trg1(2), trg2(2), trg(2);
150
ad705f30 151 if (!strcmp(thres,"LPT"))
d15ca731 152 {
153 trg1[0] = a[2]; trg1[1] = a[3];
154 trg2[0] = b[2]; trg2[1] = b[3];
155 }
d15ca731 156 else
157 {
ad705f30 158 trg1[0] = a[6]; trg1[1] = a[7];
159 trg2[0] = b[6]; trg2[1] = b[7];
d15ca731 160 }
161
162 TBits trgLS1(1), trgUS1(1), trgLS2(1), trgUS2(1), trgLS(1), trgUS(1);
163
ad705f30 164 if (!strcmp(thres,"LPT"))
d15ca731 165 {
254985cb 166 trgLS1[0] = a[0]; trgUS1[0] = a[1];
167 trgLS2[0] = b[0]; trgUS2[0] = b[1];
d15ca731 168 }
d15ca731 169 else
170 {
254985cb 171 trgLS1[0] = a[4]; trgUS1[0] = a[5];
172 trgLS2[0] = b[4]; trgUS2[0] = b[5];
d15ca731 173 }
174
175 trgLS[0] = ( trg1[0] & trg2[0] ) | ( trg1[1] & trg2[1] ) | trgLS1[0] | trgLS2[0];
176 trgUS[0] = ( trg1[0] & trg2[1] ) | ( trg1[1] & trg2[0] ) | trgUS1[0] | trgUS2[0];
177
178 trg[0] = trg1[0] | trg2[0];
179 trg[1] = trg1[1] | trg2[1];
180
181 TBits v(4);
182
254985cb 183 v[0] = trgLS[0];
184 v[1] = trgUS[0];
d15ca731 185 v[2] = trg[0];
186 v[3] = trg[1];
187
188 UShort_t rv = 0;
189 v.Get(&rv);
190
191 return rv;
192}
193
41a38dec 194//___________________________________________
195void AliMUONGlobalTriggerBoard::BuildGlobalInput()
196{
197 /// build the 4 words (32bits) global input from the regional responses
198 /// the order of regional responses is:
199 /// 1R, 2R, 2-3R, 3R, 4R, 5R, 6R, 7R, 1L, 2L, 2-3L, 3L, 4L, 5L, 6L, 7L
200
201 for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
202
f4e2cda2 203 UShort_t regRespInv;
41a38dec 204 for (Int_t iReg = 0; iReg < 16; iReg++) {
f4e2cda2 205
a026ce9e 206 regRespInv = InvertPairBits(iReg);
f4e2cda2 207
41a38dec 208 if (iReg < 8) { // right
209 // Lpt word
f4e2cda2 210 fGlobalInput[0] |= (regRespInv & 0x0F) << (4*iReg);
41a38dec 211 // Hpt word
f4e2cda2 212 fGlobalInput[2] |= ((regRespInv & 0xF0) >> 4) << (4*iReg);
41a38dec 213 } else { // left
214 // Lpt word
f4e2cda2 215 fGlobalInput[1] |= (regRespInv & 0x0F) << (4*(iReg-8));
41a38dec 216 // Hpt word
f4e2cda2 217 fGlobalInput[3] |= ((regRespInv & 0xF0) >> 4) << (4*(iReg-8));
41a38dec 218 }
219
220 }
221
222}
223
224//___________________________________________
f4e2cda2 225void AliMUONGlobalTriggerBoard::MaskGlobalInput()
41a38dec 226{
227 /// Apply masks to global input and recalculate regional inputs before
228 /// applying the global response
229
41a38dec 230 UInt_t gitmp[4];
41a38dec 231 for (Int_t i = 0; i < 4; i++) {
ce27c536 232 fGlobalInput[i] &= fMask[i];
41a38dec 233 gitmp[i] = fGlobalInput[i];
41a38dec 234 }
235
a026ce9e 236 RecomputeRegional(gitmp);
237}
238
239
240//___________________________________________
241void AliMUONGlobalTriggerBoard::RecomputeRegional(UInt_t gitmp[4])
242{
243 //
244 /// Recomput regional response from global input
245 //
41a38dec 246 for (Int_t iReg = 0; iReg < 16; iReg++) {
247 fRegionalResponse[iReg] = 0;
248 if (iReg < 8) { // right
249 // Lpt
250 fRegionalResponse[iReg] |= (gitmp[0] >> (4*iReg)) & 0xF;
251 // Hpt
252 fRegionalResponse[iReg] |= ((gitmp[2] >> (4*iReg)) & 0xF) << 4;
253 } else { // left
254 // Lpt
255 fRegionalResponse[iReg] |= (gitmp[1] >> (4*(iReg-8))) & 0xF;
256 // Hpt
257 fRegionalResponse[iReg] |= ((gitmp[3] >> (4*(iReg-8))) & 0xF) << 4;
258 }
41a38dec 259
a026ce9e 260 fRegionalResponse[iReg] = InvertPairBits(iReg);
261 }
41a38dec 262}
263
d15ca731 264//___________________________________________
edd00c2d 265void AliMUONGlobalTriggerBoard::Scan(Option_t*) const
d15ca731 266{
c05673c9 267 /// print global trigger output
f25f84f5 268 TBits w(7); w.Set(7,&fResponse);
d15ca731 269
270// TRG[1:0]
271// 00 noth
272// 01 negative track
273// 10 positive track
274// 11 undef
275
bf309e6d 276 Int_t iS[2] = {0,0};
d15ca731 277
f25f84f5 278 iS[0] = (Int_t)w.TestBitNumber(1);
279 iS[1] = (Int_t)w.TestBitNumber(2);
d15ca731 280
f25f84f5 281 Int_t iPU[2] = {w[5],w[6]};
282 Int_t iPL[2] = {w[3],w[4]};
d15ca731 283
ad705f30 284 printf("============================================\n");
285 printf(" Global Trigger output Low pt High pt\n");
bf309e6d 286 printf(" number of Single :\t");
287 for (Int_t i=0; i<2; i++) printf("%i\t",iS[i]);
d15ca731 288 printf("\n");
289 printf(" number of UnlikeSign pair :\t");
ad705f30 290 for (Int_t i=0; i<2; i++) printf("%i\t",iPU[i]);
d15ca731 291 printf("\n");
292 printf(" number of LikeSign pair :\t");
ad705f30 293 for (Int_t i=0; i<2; i++) printf("%i\t",iPL[i]);
d15ca731 294 printf("\n");
295 printf("===================================================\n");
296 printf("\n");
297}
298
a026ce9e 299
300//___________________________________________
301UShort_t AliMUONGlobalTriggerBoard::InvertPairBits(Int_t iReg)
302{
303 //
304 /// invert "pair" bits in regional response
305 /// [+, -, US, LS] becomes [+, -, LS, US]
306 //
307 TBits rs(8), rsi(8);
308 rs.Set(8,&fRegionalResponse[iReg]);
309 for (Int_t i = 0; i < 4; i++) {
310 if (i%2 == 0) {
311 rsi[2*i] = rs[2*i+1];
312 rsi[2*i+1] = rs[2*i];
313 } else {
314 rsi[2*i] = rs[2*i];
315 rsi[2*i+1] = rs[2*i+1];
316 }
317 }
318 UShort_t regRespInv = 0;
319 rsi.Get(&regRespInv);
320 return regRespInv;
321}