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