14-sep-2006 NvE Typo corrected in AliSignal copy ctor.
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerElectronics.cxx
CommitLineData
516d3280 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//*-- Author: Rachid Guernane (LPCCFd)
f4678817 19//* Manager class for muon trigger electronics
20//* Client of trigger board classes
21//*
22//*
516d3280 23
24#include "AliMUONTriggerElectronics.h"
25#include "AliMUONTriggerCrate.h"
f1e8d46c 26#include "AliMUONTriggerCrateStore.h"
516d3280 27#include "AliMUONConstants.h"
28#include "AliMUONLocalTriggerBoard.h"
29#include "AliMUONRegionalTriggerBoard.h"
30#include "AliMUONGlobalTriggerBoard.h"
31#include "AliMUONLocalTrigger.h"
47dc4ee7 32#include "AliMUONRegionalTrigger.h"
516d3280 33#include "AliMUONGlobalTrigger.h"
8af755f4 34#include "AliMUON.h"
516d3280 35#include "AliMUONData.h"
36#include "AliMUONDigit.h"
8af755f4 37#include "AliMUONSegmentation.h"
4c0f0f5d 38#include "AliMUONCalibrationData.h"
39#include "AliMUONVCalibParam.h"
516d3280 40
f4678817 41#include "AliMpVSegmentation.h"
42
43#include "AliLog.h"
44#include "AliLoader.h"
45#include "AliRun.h"
46
47//#include "Riostream.h"
48#include "TBits.h"
516d3280 49#include "TSystem.h"
50
63ed9c6b 51ClassImp(AliMUONTriggerElectronics)
52
516d3280 53//___________________________________________
4c0f0f5d 54AliMUONTriggerElectronics::AliMUONTriggerElectronics(AliMUONData *Data, AliMUONCalibrationData* calibData)
516d3280 55: TTask("AliMUONTriggerElectronics",
56 "From trigger digits to Local and Global Trigger objects"),
43368512 57 fSourceFileName(),
f1e8d46c 58 fCrates(new AliMUONTriggerCrateStore),
516d3280 59 fGlobalTriggerBoard(new AliMUONGlobalTriggerBoard),
516d3280 60 fMUONData(Data)
61{
f4678817 62//* CONSTRUCTOR
63//*
516d3280 64 if (!fMUONData)
65 {
66 AliFatal("NO MUON TRIGGER DATA");
67 }
68
f1e8d46c 69 SetDataSource();
70 Factory(calibData);
71 LoadMasks(calibData);
516d3280 72}
73
74//___________________________________________
75AliMUONTriggerElectronics::~AliMUONTriggerElectronics()
76{
f4678817 77//* DESTRUCTOR
78//*
516d3280 79 delete fGlobalTriggerBoard;
80 delete fCrates;
81}
82
83//___________________________________________
4c0f0f5d 84void AliMUONTriggerElectronics::Factory(AliMUONCalibrationData* calibData)
516d3280 85{
f1e8d46c 86 //* BUILD ALL ELECTRONICS
87 //*
e93b11d0 88
89// get coinc44 from AliMUON (added 12/09/06)
90 AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
91 Int_t coinc44 = pMUON->GetTriggerCoinc44();
92 if (coinc44 != 0 && coinc44 != 1) {
93 AliFatal("Coinc 44 should be equal to 0 or 1");
94 return;
95 }
96
f1e8d46c 97 fCrates->ReadFromFile(gSystem->ExpandPathName(fSourceFileName.Data()));
98
99 if ( !calibData ) return;
100
101 AliMUONTriggerLut* lut = calibData->TriggerLut();
102
103 if (!lut) return;
104
105 AliMUONLocalTriggerBoard* localBoard;
106
107 fCrates->FirstLocalBoard();
108
109 while ( (localBoard=fCrates->NextLocalBoard()) )
110 {
111 localBoard->SetLUT(lut);
e93b11d0 112 localBoard->SetCoinc44(coinc44);
f1e8d46c 113 }
8af755f4 114}
516d3280 115
8af755f4 116//___________________________________________
117void AliMUONTriggerElectronics::FeedM()
118{
f4678817 119//* FILL INPUTS
120//*
43368512 121 for (Int_t ichamber=10; ichamber<14; ichamber++)
122 {
f4678817 123 TClonesArray *muonDigits = fMUONData->Digits(ichamber);
124 Int_t ndigits = muonDigits->GetEntriesFast();
8af755f4 125
8af755f4 126 for (Int_t digit=0; digit<ndigits; digit++)
43368512 127 {
128 AliMUONDigit *mdig = static_cast<AliMUONDigit*>(muonDigits->UncheckedAt(digit));
8af755f4 129
43368512 130 // CHECKME ! The TrackCharge is not ok with new digitizerV3 !
131 // for (Int_t ichg=0; ichg<10; ichg++) schg += mdig->TrackCharge(ichg);
132 // assert(schg==mdig->Signal());
133 Int_t schg = mdig->Signal();
516d3280 134
43368512 135 // APPLY CONDITION ON SOFT BACKGROUND
136 Int_t tchg = schg - (Int_t(schg/10))*10;
516d3280 137
43368512 138 if (schg<=10 || tchg>0)
139 {
140 // mdig->Print();
516d3280 141
43368512 142 Int_t digitindex = digit;
143 Int_t detElemId = mdig->DetElemId();
144 Int_t cathode = mdig->Cathode();
8af755f4 145
43368512 146 const AliMpVSegmentation *seg =
147 ((AliMUON*)gAlice->GetDetector("MUON"))->GetSegmentation()->GetMpSegmentation(detElemId,cathode);
8af755f4 148
43368512 149 Int_t ix = mdig->PadX(), iy = mdig->PadY();
8af755f4 150
43368512 151 AliDebug(3,Form("cathode %d ix %d iy %d ",cathode,ix,iy));
8af755f4 152
43368512 153 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
8af755f4 154
43368512 155 for (Int_t i=0; i<pad.GetNofLocations(); i++)
156 {
157 AliMpIntPair location = pad.GetLocation(i);
8af755f4 158
43368512 159 Int_t nboard = location.GetFirst();
8af755f4 160
43368512 161 Int_t ibitxy = location.GetSecond();
8af755f4 162
43368512 163 AliMUONLocalTriggerBoard *b = fCrates->LocalBoard(nboard);
8af755f4 164
43368512 165 if (b)
166 {
167 if (cathode && b->GetSwitch(6)) ibitxy += 8;
8af755f4 168
43368512 169 b->SetbitM(ibitxy,cathode,ichamber-10);
8af755f4 170
43368512 171 DigitFiredCircuit(b->GetI(), cathode, ichamber, digitindex);
172 }
173 else
174 {
175 AliError(Form("Could not get local board number %d",b->GetNumber()));
176 }
177 }
178 }
179 }
180 }
8af755f4 181
43368512 182 // Particular case of the columns with 22 local boards (2R(L) 3R(L))
183 AliMUONTriggerCrate *crate = 0x0; TObjArray *bs = 0x0;
8af755f4 184
43368512 185 char *scratess[4] = { "2R", "2L", "3L", "3R"};
186 char *scratesd[4] = {"2-3R", "2-3L", "2-3L", "2-3R"};
187 Int_t slotf[4] = { 2, 2, 10, 10};
188 Int_t slotd[4] = { 1, 1, 9, 9};
8af755f4 189
43368512 190 for (Int_t i = 0; i < 4; i++)
191 {
f1e8d46c 192 crate = fCrates->Crate(scratess[i]);
8af755f4 193 bs = crate->Boards();
194 AliMUONLocalTriggerBoard *desybb = (AliMUONLocalTriggerBoard*)bs->At(14);
195 AliMUONLocalTriggerBoard *fromcb = (AliMUONLocalTriggerBoard*)bs->At(15);
196 AliMUONLocalTriggerBoard *desxbb = (AliMUONLocalTriggerBoard*)bs->At(16);
197
f1e8d46c 198 crate = fCrates->Crate(scratesd[i]);
8af755f4 199 bs = crate->Boards();
200 AliMUONLocalTriggerBoard *frombb = (AliMUONLocalTriggerBoard*)bs->At(slotf[i]);
201 AliMUONLocalTriggerBoard *desycb = (AliMUONLocalTriggerBoard*)bs->At(slotd[i]);
202
203 UShort_t cX[2];
204
43368512 205 // COPY X3-4 FROM BOARD 2 OF CRATE 2-3 TO BOARD 16 OF CRATE 2
206 // COPY X3-4 FROM BOARD 10 OF CRATE 2-3 TO BOARD 16 OF CRATE 3
8af755f4 207 frombb->GetX34(cX); desxbb->SetX34(cX);
208
43368512 209 // COPY X3-4 FROM BOARD 15 OF CRATE 2 TO BOARD 1 OF CRATE 2-3
210 // COPY X3-4 FROM BOARD 15 OF CRATE 3 TO BOARD 9 OF CRATE 2-3
8af755f4 211 fromcb->GetX34(cX); desycb->SetX34(cX);
212
213 UShort_t cY[4];
214
215 desybb->GetY(cY); frombb->SetY(cY);
216
217 frombb->GetY(cY); desxbb->SetY(cY);
218 fromcb->GetY(cY); desycb->SetY(cY);
43368512 219 }
8af755f4 220
43368512 221 // FILL UP/DOWN OF CURRENT BOARD (DONE VIA J3 BUS IN REAL LIFE)
222 AliMUONTriggerCrate* cr;
f1e8d46c 223
43368512 224 fCrates->FirstCrate();
f1e8d46c 225
43368512 226 while ( ( cr = fCrates->NextCrate() ) )
227 {
228 TObjArray *boards = cr->Boards();
8af755f4 229
43368512 230 for (Int_t j = 1; j < boards->GetEntries()-1; j++)
231 {
232 TObject *o = boards->At(j);
8af755f4 233
43368512 234 if (!o) break;
8af755f4 235
43368512 236 AliMUONLocalTriggerBoard *currboard = (AliMUONLocalTriggerBoard*)o;
8af755f4 237
43368512 238 AliMUONLocalTriggerBoard *neighbour = (AliMUONLocalTriggerBoard*)boards->At(j+1);
8af755f4 239
43368512 240 UShort_t cXY[2][4];
8af755f4 241
43368512 242 if (j==1) {neighbour->GetXY(cXY); currboard->SetXYU(cXY);}
8af755f4 243
43368512 244 // LAST BOARD IN THE CRATE HAS NO UP EXCEPT FOR CRATES 2 & 3
245 if (j < boards->GetEntries()-2)
246 {
247 AliMUONLocalTriggerBoard *nextboard = (AliMUONLocalTriggerBoard*)boards->At(j+2);
8af755f4 248
43368512 249 currboard->GetXY(cXY); neighbour->SetXYD(cXY);
250 nextboard->GetXY(cXY); neighbour->SetXYU(cXY);
8af755f4 251
43368512 252 if (j==boards->GetEntries()-3) {neighbour->GetXY(cXY); nextboard->SetXYD(cXY);}
253 }
254 }
255 }
516d3280 256}
516d3280 257
258//___________________________________________
259void AliMUONTriggerElectronics::Feed(UShort_t pattern[2][4])
260{
f1e8d46c 261 //* FILL INPUTS
262 //*
263 AliMUONTriggerCrate* cr;
264
265 fCrates->FirstCrate();
266
267 while ( ( cr = fCrates->NextCrate() ) )
268 {
269 TObjArray *boards = cr->Boards();
270
43368512 271 for (Int_t j = 1; j < boards->GetEntries(); j++)
f1e8d46c 272 {
273 TObject *o = boards->At(j);
274
275 if (!o) break;
276
277 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
278
279 board->SetXY(pattern);
280 }
516d3280 281 }
282}
283
284//___________________________________________
285void AliMUONTriggerElectronics::DumpOS()
286{
f4678817 287//* DUMP IN THE OLD WAY
288//*
43368512 289 for (Int_t i= 0; i < 234;i++)
516d3280 290 {
f1e8d46c 291 AliMUONLocalTriggerBoard *board = fCrates->LocalBoard(i);
516d3280 292
43368512 293 if (board) board->Scan("ALL");
516d3280 294 }
295}
296
297//___________________________________________
298void AliMUONTriggerElectronics::Scan(Option_t *option)
299{
f1e8d46c 300 //* SCAN
301 //*
516d3280 302
f1e8d46c 303 AliMUONTriggerCrate* cr;
304
305 fCrates->FirstCrate();
306
307 while ( ( cr = fCrates->NextCrate() ) )
43368512 308 {
f1e8d46c 309 TObjArray *boards = cr->Boards();
310
43368512 311 for (Int_t j = 0; j < boards->GetEntries(); j++)
f1e8d46c 312 {
313 TObject *o = boards->At(j);
314
315 TString op = option;
316
317 Bool_t cdtion = kFALSE;
318
319 if (op.Contains("LOCAL")) cdtion = o->IsA() == AliMUONLocalTriggerBoard::Class();
320 if (op.Contains("REGIONAL")) cdtion = o->IsA() == AliMUONRegionalTriggerBoard::Class();
321 if (op.Contains("GLOBAL")) cdtion = o->IsA() == AliMUONGlobalTriggerBoard::Class();
322
323 if (!o || !cdtion) continue;
324
325 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
326
327 board->Scan();
328 }
329 }
516d3280 330}
331
332//___________________________________________
333void AliMUONTriggerElectronics::Reset()
334{
f1e8d46c 335 //* RESET
336 //*
337
338 AliMUONTriggerCrate* cr;
339
340 fCrates->FirstCrate();
341
342 while ( ( cr = fCrates->NextCrate() ) )
516d3280 343 {
516d3280 344 TObjArray *boards = cr->Boards();
345
346 for (Int_t j=0; j<boards->GetEntries(); j++)
347 {
348 AliMUONTriggerBoard *b = (AliMUONTriggerBoard*)boards->At(j);
349
350 if (b) b->Reset();
351 }
352 }
353}
354
4c0f0f5d 355//_______________________________________________________________________
356void AliMUONTriggerElectronics::LoadMasks(AliMUONCalibrationData* calibData)
357{
358 // LOAD MASKS FROM CDB
359
360
361 // SET MASKS
f1e8d46c 362
363 AliMUONTriggerCrate* cr;
364
365 fCrates->FirstCrate();
366
367 Int_t irb(0);
368
369 while ( ( cr = fCrates->NextCrate() ) )
43368512 370 {
4c0f0f5d 371 TObjArray *boards = cr->Boards();
372
373 AliMUONRegionalTriggerBoard *regb =
374 (AliMUONRegionalTriggerBoard*)boards->At(0);
375
f1e8d46c 376 AliMUONVCalibParam* regionalBoardMasks = calibData->RegionalTriggerBoardMasks(irb);
4c0f0f5d 377
378 for ( Int_t i = 0; i < regionalBoardMasks->Size(); ++i )
379 {
380 UShort_t rmask = static_cast<UShort_t>(regionalBoardMasks->ValueAsInt(i) & 0x3F);
381 regb->Mask(i,rmask);
382 }
383
43368512 384 for (Int_t j = 1; j < boards->GetEntries(); j++)
4c0f0f5d 385 {
386 AliMUONLocalTriggerBoard *b = (AliMUONLocalTriggerBoard*)boards->At(j);
387
388 Int_t cardNumber = b->GetNumber();
389
390 if (cardNumber) // interface board are not interested
391 {
392 AliMUONVCalibParam* localBoardMasks = calibData->LocalTriggerBoardMasks(cardNumber);
393 for ( Int_t i = 0; i < localBoardMasks->Size(); ++i )
394 {
395 UShort_t lmask = static_cast<UShort_t>(localBoardMasks->ValueAsInt(i) & 0xFFFF);
396 b->Mask(i,lmask);
397 }
398 }
399 }
f1e8d46c 400 ++irb;
4c0f0f5d 401 }
402
403 AliMUONVCalibParam* globalBoardMasks = calibData->GlobalTriggerBoardMasks();
404 for ( Int_t i = 0; i < globalBoardMasks->Size(); ++i )
405 {
406 UShort_t gmask = static_cast<UShort_t>(globalBoardMasks->ValueAsInt(i) & 0xFFF);
407 fGlobalTriggerBoard->Mask(i,gmask);
408 }
409}
410
411
516d3280 412//___________________________________________
413void AliMUONTriggerElectronics::LocalResponse()
414{
f1e8d46c 415 // INTERFACE BOARDS
43368512 416 struct crates_t
f1e8d46c 417 {
418 TString name;
419 Int_t slots[5];
420 Int_t ns;
43368512 421
422 crates_t() : name(""), ns(0) {}
f1e8d46c 423 } crate[6];
516d3280 424
43368512 425 crate[0].name = "2R"; crate[0].ns = 1; crate[0].slots[0] = 16;
426 crate[1].name = "2L"; crate[1].ns = 1; crate[1].slots[0] = 16;
427 crate[2].name = "3L"; crate[2].ns = 1; crate[2].slots[0] = 16;
428 crate[3].name = "3R"; crate[3].ns = 1; crate[3].slots[0] = 16;
429 crate[4].name = "2-3R"; crate[4].ns = 2; crate[4].slots[0] = 1; crate[4].slots[1] = 9;
430 crate[5].name = "2-3L"; crate[5].ns = 2; crate[5].slots[0] = 1; crate[5].slots[1] = 9;
516d3280 431
f1e8d46c 432 AliMUONTriggerCrate* cr;
433
434 fCrates->FirstCrate();
435
436 while ( ( cr = fCrates->NextCrate() ) )
43368512 437 {
f1e8d46c 438 Int_t iib = -1;
439
440 for (Int_t icr=0; icr<6; icr++)
441 {
43368512 442 const char *n = (crate[icr].name).Data();
516d3280 443
f1e8d46c 444 AliMUONTriggerCrate *dcr = fCrates->Crate(n);
445
446 // THIS CRATE CONTAINS AN INTERFACE BOARD
447 if ( dcr && !strcmp(cr->GetName(),dcr->GetName()) ) iib = icr;
448 }
449
450 TObjArray *boards = cr->Boards();
451
452 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
453
454 UShort_t thisl[16]; for (Int_t j=0; j<16; j++) thisl[j] = 0;
455
456 for (Int_t j=1; j<boards->GetEntries(); j++)
457 {
43368512 458 TObject *o = boards->At(j);
f1e8d46c 459
43368512 460 if (!o) break;
f1e8d46c 461
43368512 462 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
f1e8d46c 463
43368512 464 if (board)
465 {
466 board->Response();
516d3280 467
43368512 468 UShort_t tmp = board->GetResponse();
f1e8d46c 469
43368512 470 // CRATE CONTAINING INTERFACE BOARD
471 if ( iib>-1 )
472 {
473 for (Int_t iid = 0; iid<crate[iib].ns; iid++)
474 {
475 if ( j == crate[iib].slots[iid] )
476 {
477 if ( tmp != 0 )
478 AliWarning(Form("Interface board %s in slot %d of crate %s has a non zero response",
479 board->GetName(),j,cr->GetName()));
480 }
481 }
482 }
f1e8d46c 483
43368512 484 thisl[j-1] = tmp;
485 }
516d3280 486 }
f1e8d46c 487
488 regb->SetLocalResponse(thisl);
489 }
516d3280 490}
491
492//___________________________________________
493void AliMUONTriggerElectronics::RegionalResponse()
494{
f1e8d46c 495 /// Compute the response for all regional cards.
496 AliMUONTriggerCrate* cr;
497
498 fCrates->FirstCrate();
499
500 while ( ( cr = fCrates->NextCrate() ) )
43368512 501 {
516d3280 502 TObjArray *boards = cr->Boards();
503
504 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
505
506 if (regb)
507 {
508 regb->Response();
516d3280 509 }
510 }
511}
512
513//___________________________________________
514void AliMUONTriggerElectronics::GlobalResponse()
515{
f1e8d46c 516 /// Compute the global response
516d3280 517
f1e8d46c 518 UShort_t regional[16];
519
520 AliMUONTriggerCrate* cr;
521
522 fCrates->FirstCrate();
523 Int_t irb(0);
524
525 if ( !fCrates->NumberOfCrates() >= 16 )
526 {
527 AliFatal(Form("Something is wrong : too many crates %d",
528 fCrates->NumberOfCrates()));
529 }
530
531 while ( ( cr = fCrates->NextCrate() ) )
43368512 532 {
f1e8d46c 533 AliMUONTriggerBoard* rb =
534 static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
535 regional[irb] = rb->GetResponse();
536 ++irb;
537 }
538
539 fGlobalTriggerBoard->SetRegionalResponse(regional);
540 fGlobalTriggerBoard->Response();
516d3280 541}
542
543//___________________________________________
544void AliMUONTriggerElectronics::BoardName(Int_t ix, Int_t iy, char *name)
545{
f4678817 546//* BOARD NAME FROM PAD INFO (OLD MAPPING)
547//*
516d3280 548 TString s = (ix>0) ? "R" : "L";
549
550 Int_t board = iy / 16, bid[4] = {12,34,56,78};
551
552 ix = abs(ix);
553
554 Int_t line = ix / 10, column = ix - 10 * line;
555
556// old scheme: line==1 is line==9
557 line -= 9; line = TMath::Abs(line); line++;
558
559 sprintf(name,"%sC%dL%dB%d", s.Data(), column, line, bid[board]);
560
561 AliDebug(3, Form("Strip ( %d , %d ) connected to board %s ", ix, iy, name));
562}
563
516d3280 564//___________________________________________
565void AliMUONTriggerElectronics::BuildName(Int_t icirc, char name[20])
566{
f4678817 567//* GET BOARD NAME FROM OLD NUMBERING
568//*
569 const Int_t kCircuitId[234] =
516d3280 570 {
571 111, 121, 131, 141, 151, 161, 171,
572 211, 212, 221, 222, 231, 232, 241, 242, 251, 252, 261, 262, 271,
573 311, 312, 321, 322, 331, 332, 341, 342, 351, 352, 361, 362, 371,
574 411, 412, 413, 421, 422, 423, 424, 431, 432, 433, 434, 441, 442, 451, 452, 461, 462, 471,
575 521, 522, 523, 524, 531, 532, 533, 534, 541, 542, 551, 552, 561, 562, 571,
576 611, 612, 613, 621, 622, 623, 624, 631, 632, 633, 634, 641, 642, 651, 652, 661, 662, 671,
577 711, 712, 721, 722, 731, 732, 741, 742, 751, 752, 761, 762, 771,
578 811, 812, 821, 822, 831, 832, 841, 842, 851, 852, 861, 862, 871,
579 911, 921, 931, 941, 951, 961, 971,
580 -111, -121, -131, -141, -151, -161, -171,
581 -211, -212, -221, -222, -231, -232, -241, -242, -251, -252, -261, -262, -271,
582 -311, -312, -321, -322, -331, -332, -341, -342, -351, -352, -361, -362, -371,
583 -411, -412, -413, -421, -422, -423, -424, -431, -432, -433, -434, -441, -442, -451, -452, -461, -462, -471,
584 -521, -522, -523, -524, -531, -532, -533, -534, -541, -542, -551, -552, -561, -562, -571,
585 -611, -612, -613, -621, -622, -623, -624, -631, -632, -633, -634, -641, -642, -651, -652, -661, -662, -671,
586 -711, -712, -721, -722, -731, -732, -741, -742, -751, -752, -761, -762, -771,
587 -811, -812, -821, -822, -831, -832, -841, -842, -851, -852, -861, -862, -871,
588 -911, -921, -931, -941, -951, -961, -971
589 };
590
591 Int_t b[4] = {12, 34, 56, 78};
592
f4678817 593 Int_t code = TMath::Abs(kCircuitId[icirc]);
516d3280 594
f4678817 595 Int_t lL = code / 100;
516d3280 596
f4678817 597 Int_t cC = ( code - 100 * lL ) / 10;
516d3280 598
f4678817 599 Int_t bB = code - 100 * lL - 10 * cC;
516d3280 600
f4678817 601 const char *side = (kCircuitId[icirc]>0) ? "R" : "L";
516d3280 602
f4678817 603// lL=1 AT TOP
604 lL -= 9; lL = abs(lL); lL++;
516d3280 605
f4678817 606 sprintf(name,"%sC%dL%dB%d",side,cC,lL,b[bB-1]);
516d3280 607}
608
609//_______________________________________________________________________
610void
611AliMUONTriggerElectronics::Exec(Option_t*)
612{
f4678817 613//*
614//*
516d3280 615 Digits2Trigger();
616}
617
618//_______________________________________________________________________
619void AliMUONTriggerElectronics::Trigger()
620{
f4678817 621//*
622//*
8af755f4 623 FeedM();
516d3280 624 LocalResponse();
625 RegionalResponse();
626 GlobalResponse();
627}
516d3280 628
516d3280 629//_______________________________________________________________________
630void AliMUONTriggerElectronics::Digits2Trigger()
631{
f1e8d46c 632 /// Main method to go from digits to trigger decision
516d3280 633
47dc4ee7 634 AliMUONRegionalTrigger *pRegTrig = new AliMUONRegionalTrigger();
635
f1e8d46c 636 ClearDigitNumbers();
637
638 fMUONData->ResetTrigger();
639
640 // RUN THE FULL BEE CHAIN
641 Trigger();
642 // DumpOS();
8af755f4 643
f1e8d46c 644 AliMUONTriggerCrate* cr;
645
646 fCrates->FirstCrate();
647
648 while ( ( cr = fCrates->NextCrate() ) )
649 {
650 TObjArray *boards = cr->Boards();
47dc4ee7 651
652 UInt_t regInpLpt = 0;
653 UInt_t regInpHpt = 0;
654 UShort_t localMask = 0x0;
655
656 AliMUONRegionalTriggerBoard *regBoard = (AliMUONRegionalTriggerBoard*)boards->At(0);
657
658 for (Int_t j = 1; j < boards->GetEntries(); j++)
f1e8d46c 659 {
660 TObject *o = boards->At(j);
661
662 if (!o) break;
663
664 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
665
666 if (board)
667 {
668 // L0 TRIGGER
669 if (board->Triggered())
670 {
671 Int_t localtr[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0};
672
673 Int_t icirc = board->GetNumber();
674
675 localtr[0] = icirc;
676 localtr[1] = board->GetStripX11();
677 localtr[2] = board->GetDev();
678 localtr[3] = board->GetStripY11();
679
680 // SAVE LUT OUTPUT
681 UShort_t response = board->GetResponse();
682 localtr[4] = (response & 12) >> 2;
683 localtr[5] = (response & 48) >> 4;
684 localtr[6] = (response & 3);
47dc4ee7 685
686 // calculates regional inputs from local for the moment
687 UInt_t hPt = (response >> 4) & 0x3;
688 UInt_t lPt = (response >> 2) & 0x3;
689
690 regInpHpt |= hPt << (30 - (j-1)*2);
691 regInpLpt |= lPt << (30 - (j-1)*2);
692 localMask |= (0x1 << (j-1)); // local mask
693
694
f1e8d46c 695 TBits rrr;
696 rrr.Set(6,&response);
697
698 // SAVE BIT PATTERN
699 localtr[7] = board->GetXY(0,0);
700 localtr[8] = board->GetXY(0,1);
701 localtr[9] = board->GetXY(0,2);
702 localtr[10] = board->GetXY(0,3);
703
704 localtr[11] = board->GetXY(1,0);
705 localtr[12] = board->GetXY(1,1);
706 localtr[13] = board->GetXY(1,2);
707 localtr[14] = board->GetXY(1,3);
708
709 // ADD A NEW LOCAL TRIGGER
710 AliMUONLocalTrigger *pLocTrig = new AliMUONLocalTrigger(localtr, fDigitNumbers[icirc]);
711
712 fMUONData->AddLocalTrigger(*pLocTrig);
47dc4ee7 713 delete pLocTrig;
f1e8d46c 714 }
516d3280 715 }
f1e8d46c 716 }
47dc4ee7 717 pRegTrig->SetLocalOutput(regInpLpt, 0);
718 pRegTrig->SetLocalOutput(regInpHpt, 1);
719 pRegTrig->SetLocalMask(localMask);
720 pRegTrig->SetOutput((regBoard->GetResponse() >> 4) & 0xF); // to be uniformized (oct06 ?)
721
722 fMUONData->AddRegionalTrigger(*pRegTrig);
723
f1e8d46c 724 }
47dc4ee7 725 delete pRegTrig;
f1e8d46c 726
727 // GLOBAL TRIGGER INFORMATION: [0] -> LOW PT
728 // [1] -> HIGH PT
729 // [2] -> ALL PT
730 Int_t globalSinglePlus[3], globalSingleMinus[3], globalSingleUndef[3];
731 Int_t globalPairUnlike[3], globalPairLike[3];
732
733 UShort_t global = fGlobalTriggerBoard->GetResponse();
734
735 globalPairUnlike[0] = (global & 16) >> 4;
736 globalPairUnlike[1] = (global & 256) >> 8;
737 globalPairUnlike[2] = (global & 1);
738
739 globalPairLike[0] = (global & 32) >> 5;
740 globalPairLike[1] = (global & 512) >> 9;
741 globalPairLike[2] = (global & 2) >> 1;
742
743 globalSinglePlus[0] = ((global & 192) >> 6) == 2;
744 globalSinglePlus[1] = ((global & 3072) >> 10) == 2;
745 globalSinglePlus[2] = ((global & 12) >> 2) == 2;
746
747 globalSingleMinus[0] = ((global & 192) >> 6) == 1;
748 globalSingleMinus[1] = ((global & 3072) >> 10) == 1;
749 globalSingleMinus[2] = ((global & 12) >> 2) == 1;
750
751 globalSingleUndef[0] = ((global & 192) >> 6) == 3;
752 globalSingleUndef[1] = ((global & 3072) >> 10) == 3;
753 globalSingleUndef[2] = ((global & 12) >> 2) == 3;
754
755 AliMUONGlobalTrigger *pGloTrig = new AliMUONGlobalTrigger(globalSinglePlus, globalSingleMinus,
756 globalSingleUndef, globalPairUnlike,
757 globalPairLike);
758
759 // ADD A LOCAL TRIGGER IN THE LIST
760 fMUONData->AddGlobalTrigger(*pGloTrig);
47dc4ee7 761 delete pGloTrig;
762
f1e8d46c 763 // NOW RESET ELECTRONICS
764 Reset();
516d3280 765}
766
767//_______________________________________________________________________
768void AliMUONTriggerElectronics::ClearDigitNumbers()
769{
770// RESET fDigitNumbers
771 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++) fDigitNumbers[i].Set(0);
772}
773
774//_______________________________________________________________________
775void AliMUONTriggerElectronics::DigitFiredCircuit(Int_t circuit, Int_t cathode,
776 Int_t chamber, Int_t digit)
777{
778// REGISTERS THAT THE SPECIFIED DIGIT FIRED THE SPECIFIED CIRCUIT
779// THIS DIGIT GETS ADDED TO AN ARRAY WHICH WILL BE COPIED TO
780// AliMUONLocalTrigger WHEN SUCH AN OBJECT IS CREATED FOR EACH CIRCUIT
781 Int_t digitnumber = AliMUONLocalTrigger::EncodeDigitNumber(chamber, cathode, digit);
782 Int_t last = fDigitNumbers[circuit].GetSize();
783 fDigitNumbers[circuit].Set(last + 1);
784 fDigitNumbers[circuit][last] = digitnumber;
785}
786