Adding mask handling
[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)
19
20#include "AliMUONTriggerElectronics.h"
21#include "AliMUONTriggerCrate.h"
22#include "AliMUONConstants.h"
23#include "AliMUONLocalTriggerBoard.h"
24#include "AliMUONRegionalTriggerBoard.h"
25#include "AliMUONGlobalTriggerBoard.h"
26#include "AliMUONLocalTrigger.h"
27#include "AliMUONGlobalTrigger.h"
28#include "AliLoader.h"
8af755f4 29#include "AliRun.h"
30#include "AliMUON.h"
516d3280 31#include "AliMUONData.h"
32#include "AliMUONDigit.h"
33#include "AliLog.h"
34#include "AliLoader.h"
8af755f4 35#include "AliMUONTriggerConstants.h"
36#include "AliMpTriggerSegmentation.h"
37#include "AliMUONSegmentation.h"
38#include "AliMpVSegmentation.h"
39
40#include "TBits.h"
516d3280 41
42#include "Riostream.h"
43#include "TSystem.h"
44
63ed9c6b 45ClassImp(AliMUONTriggerElectronics)
46
2247f0b7 47const Int_t AliMUONTriggerElectronics::fgkNCrates = 16;
48
516d3280 49//___________________________________________
50AliMUONTriggerElectronics::AliMUONTriggerElectronics(AliMUONData *Data)
51: TTask("AliMUONTriggerElectronics",
52 "From trigger digits to Local and Global Trigger objects"),
53 fCrates(new TClonesArray("AliMUONTriggerCrate", fgkNCrates)),
54 fGlobalTriggerBoard(new AliMUONGlobalTriggerBoard),
55 fNCrates(0),
56 fMUONData(Data)
57{
58 if (!fMUONData)
59 {
60 AliFatal("NO MUON TRIGGER DATA");
61 }
62
63 for (Int_t i=0;i<16;i++)
64 {
65 fRegional[i] = 0;
66 for (Int_t j=0;j<16;j++) fLocal[i][j] = 0;
67 }
68
69 fGlobal = 0;
70
8af755f4 71 fCrateMap = new char*[234];
72 for (Int_t i=0;i<234;i++) fBoardMap[i] = 0;
73
516d3280 74 SetDataSource();
75 Factory();
76
77 AliWarning("ZERO-ALLY-LSB TO BE CHECKED!!!");
78 AliWarning("AliMUONLocalTriggerBoard Y_pos DIVIDED BY 2 TO BE CONSISTENT W/ AliMUONTrackReconstructor!!!");
79}
80
884a73f1 81//______________________________________________________________________________
82AliMUONTriggerElectronics::AliMUONTriggerElectronics(const AliMUONTriggerElectronics& right)
83 : TTask(right)
84{
85/// Protected copy constructor (not implemented)
86
87 AliFatal("Copy constructor not provided.");
88}
89
516d3280 90//___________________________________________
91AliMUONTriggerElectronics::~AliMUONTriggerElectronics()
92{
93 delete fGlobalTriggerBoard;
94 delete fCrates;
8af755f4 95
96 for (Int_t i=0;i<234;i++) if (fCrateMap[i]) {delete [] fCrateMap[i]; fCrateMap[i] = NULL;}
516d3280 97}
98
884a73f1 99//______________________________________________________________________________
100AliMUONTriggerElectronics&
101AliMUONTriggerElectronics::operator=(const AliMUONTriggerElectronics& right)
102{
103/// Protected assignement operator (not implemented)
104
105 // check assignement to self
106 if (this == &right) return *this;
107
108 AliFatal("Assignement operator not provided.");
109
110 return *this;
111}
112
516d3280 113//___________________________________________
114void AliMUONTriggerElectronics::Factory()
115{
116 ifstream myInputFile(gSystem->ExpandPathName(fSourceFileName.Data()), ios::in);
117
118 string sLine, sValue;
119
120 if ( !myInputFile )
121 {
122 AliError("TRIGGER ELECTRONICS CONFIGURATION FILE COULD NOT BE OPENED");
123 }
124 else
125 {
126 while (getline(myInputFile,sLine))
127 {
128 if (sLine.empty()) continue; // Ignore empty lines
129 else
130 {
131 const Int_t maxfields = 15; char **fields = new char*[maxfields];
132
133 char s[100];
134
135 if (sLine.find("Board",0) != string::npos)
136 {
137 strcpy(s,sLine.c_str());
138
139 Int_t numlines = 0;
140
141 for (char *token = strtok(s, " ");
142 token != NULL;
143 token = strtok(NULL, " "))
144 {
145 fields[numlines] = new char[strlen(token)+1];
146 strcpy(fields[numlines++],token);
147 }
148
149 char str[10]; strcpy(str, fields[6]); strcat(str, fields[7]);
150
151 AliMUONTriggerCrate *crate = Crate(str);
152
153 if (!crate)
154 {
155 AddCrate(str); crate = Crate(str);
156
157 AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
158 crate->AddBoard(rboard, 0);
159 }
160
161// CONVENTION: SLOT 0 HOLDS THE REGIONAL BOARD
162 Int_t sl = atoi(fields[10]);
163
164 AliMUONLocalTriggerBoard *board = new AliMUONLocalTriggerBoard(fields[4], sl);
165
8af755f4 166 if (strcmp(fields[1],"nn"))
167 {
168 Int_t sboard = atoi(fields[1]);
169
170 board->SetNumber(sboard);
171
172 fCrateMap[sboard-1] = new char[strlen(str)+1]; strcpy(fCrateMap[sboard-1], str);
8af755f4 173
174 fBoardMap[sboard-1] = sl;
175 }
176
177 board->SetCrate(str);
178
516d3280 179 crate->AddBoard(board, sl);
180
181 while (getline(myInputFile,sLine)) if (sLine.find("transv",0) != string::npos) break;
182
183 strcpy(s,sLine.c_str());
184
185 for (char *token = strtok(s, " ");
186 token != NULL;
187 token = strtok(NULL, " ")) if (!strcmp(token,"NONE")) board->SetTC(kFALSE);
188
189 while (getline(myInputFile,sLine)) if (sLine.find("Switch",0) != string::npos) break;
190
191 while (getline(myInputFile,sLine)) if (!sLine.empty()) break;
192
193 strcpy(s,sLine.c_str());
194
195 Int_t lines = 0;
196
197 for (char *token = strtok(s, " ");
198 token != NULL;
199 token = strtok(NULL, " ")) board->SetSwitch(lines++, atoi(token));
200
201 for (Int_t i = 0; i<numlines; i++)
202 if (fields[i]) {delete [] fields[i]; fields[i] = 0;}
203
204 delete [] fields; fields = 0;
205 }
206 }
207 }
208 }
209}
210
211//___________________________________________
212void AliMUONTriggerElectronics::Feed()
213{
214 for (Int_t ichamber=10; ichamber<14; ichamber++)
215 {
216 TClonesArray *MuonDigits = fMUONData->Digits(ichamber);
217 Int_t ndigits = MuonDigits->GetEntriesFast();
218
219 for (Int_t digit=0; digit<ndigits; digit++)
220 {
221 AliMUONDigit *mdig = static_cast<AliMUONDigit*>(MuonDigits->UncheckedAt(digit));
222
223 Int_t ix = mdig->PadX(), iy = mdig->PadY();
224
225// GET THE SUM OF THE CODED CHARGE
226// SEE CODING CONVENTION IN AliMUONChamberTrigger::DisIntegration
227 Int_t schg = 0;
8af755f4 228 for (Int_t ichg=0; ichg<10; ichg++) schg += mdig->TrackCharge(ichg);
516d3280 229
230// APPLY CONDITION ON SOFT BACKGROUND
231 Int_t tchg = schg - (Int_t(schg/10))*10;
232
233 if (schg<=10 || tchg>0)
234 {
235 Int_t cathode = mdig->Cathode();
236
237// Now identify local board from (ix,iy)
238 char name[10]; BoardName(ix,iy,name);
239
240 for (Int_t i=0;i<fgkNCrates;i++)
241 {
242 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
243
244 TObjArray *boards = cr->Boards();
245
246 AliMUONLocalTriggerBoard *b = (AliMUONLocalTriggerBoard*)boards->FindObject(name);
247
248 if (b)
249 {
250 Int_t digitindex = digit;
8af755f4 251
252// Y STRIP IS FIRED ONCE BUT ALL BOARDS FROM THE SAME MODULE ARE FED
253 if (cathode)
254 {
255 if (b->GetSwitch(6)) iy += 8;
256
257 char M1[20]; b->Module(M1);
258
259 for (Int_t j=0;j<fgkNCrates;j++)
260 {
261 AliMUONTriggerCrate *ca = (AliMUONTriggerCrate*)fCrates->UncheckedAt(j);
262
263 TObjArray *bs = ca->Boards();
264
265 for (Int_t k=1; k<bs->GetEntries()-1; k++)
266 {
267 AliMUONLocalTriggerBoard *h = (AliMUONLocalTriggerBoard*)bs->At(k);
268
269 if (h)
270 {
271 char M2[20]; h->Module(M2);
272
273 if (!strcmp(M1,M2)) h->Setbit(iy,cathode,ichamber-10);
274 }
275 }
276 }
277 }
278 else
516d3280 279 b->Setbit(iy,cathode,ichamber-10);
280
281 DigitFiredCircuit(b->GetI(), cathode, ichamber, digitindex);
282 }
283 }
284 }
285 }
286 }
287
288// Particular case of the columns with 22 local boards (2R(L) 3R(L))
289 AliMUONTriggerCrate *crate = 0x0; TObjArray *bs = 0x0;
290
291 char *scratess[4] = { "2R", "2L", "3L", "3R"};
292 char *scratesd[4] = {"2-3R", "2-3L", "2-3L", "2-3R"};
293 Int_t slotf[4] = { 2, 2, 10, 10};
294 Int_t slotd[4] = { 1, 1, 9, 9};
295
296 for (Int_t i=0; i<4; i++)
297 {
298 crate = (AliMUONTriggerCrate*)fCrates->FindObject(scratess[i]);
299 bs = crate->Boards();
300 AliMUONLocalTriggerBoard *desybb = (AliMUONLocalTriggerBoard*)bs->At(14);
301 AliMUONLocalTriggerBoard *fromcb = (AliMUONLocalTriggerBoard*)bs->At(15);
302 AliMUONLocalTriggerBoard *desxbb = (AliMUONLocalTriggerBoard*)bs->At(16);
303
304 crate = (AliMUONTriggerCrate*)fCrates->FindObject(scratesd[i]);
305 bs = crate->Boards();
306 AliMUONLocalTriggerBoard *frombb = (AliMUONLocalTriggerBoard*)bs->At(slotf[i]);
307 AliMUONLocalTriggerBoard *desycb = (AliMUONLocalTriggerBoard*)bs->At(slotd[i]);
308
309 UShort_t cX[2];
310
311// COPY X3-4 FROM BOARD 2 OF CRATE 2-3 TO BOARD 16 OF CRATE 2
312// COPY X3-4 FROM BOARD 10 OF CRATE 2-3 TO BOARD 16 OF CRATE 3
313 frombb->GetX34(cX); desxbb->SetX34(cX);
314
315// COPY X3-4 FROM BOARD 15 OF CRATE 2 TO BOARD 1 OF CRATE 2-3
316// COPY X3-4 FROM BOARD 15 OF CRATE 3 TO BOARD 9 OF CRATE 2-3
317 fromcb->GetX34(cX); desycb->SetX34(cX);
318
8af755f4 319 UShort_t cY[4];
516d3280 320
321 desybb->GetY(cY); frombb->SetY(cY);
322 }
323
8af755f4 324// FILL UP/DOWN OF CURRENT BOARD (DONE VIA J3 BUS IN REAL LIFE)
325 for (Int_t i=0; i<fgkNCrates; i++)
516d3280 326 {
8af755f4 327 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
328
329 TObjArray *boards = cr->Boards();
330
516d3280 331 for (Int_t j=1; j<boards->GetEntries()-1; j++)
332 {
333 TObject *o = boards->At(j);
8af755f4 334
516d3280 335 if (!o) break;
8af755f4 336
516d3280 337 AliMUONLocalTriggerBoard *currboard = (AliMUONLocalTriggerBoard*)o;
8af755f4 338
516d3280 339 AliMUONLocalTriggerBoard *neighbour = (AliMUONLocalTriggerBoard*)boards->At(j+1);
8af755f4 340
341 UShort_t cXY[2][4];
342
343 if (j==1) {neighbour->GetXY(cXY); currboard->SetXYU(cXY);}
344
345// LAST BOARD IN THE CRATE HAS NO UP EXCEPT FOR CRATES 2 & 3
346 if (j<boards->GetEntries()-2)
347 {
348 AliMUONLocalTriggerBoard *nextboard = (AliMUONLocalTriggerBoard*)boards->At(j+2);
349
350 currboard->GetXY(cXY); neighbour->SetXYD(cXY);
351 nextboard->GetXY(cXY); neighbour->SetXYU(cXY);
352
353 if (j==boards->GetEntries()-3) {neighbour->GetXY(cXY); nextboard->SetXYD(cXY);}
354 }
355 }
356 }
357}
516d3280 358
8af755f4 359//___________________________________________
360void AliMUONTriggerElectronics::FeedM()
361{
362 for (Int_t ichamber=10; ichamber<14; ichamber++)
363 {
364 TClonesArray *MuonDigits = fMUONData->Digits(ichamber);
365 Int_t ndigits = MuonDigits->GetEntriesFast();
366
8af755f4 367 for (Int_t digit=0; digit<ndigits; digit++)
368 {
369 AliMUONDigit *mdig = static_cast<AliMUONDigit*>(MuonDigits->UncheckedAt(digit));
370
371// CHECKME ! The TrackCharge is not ok with new digitizerV3 !
372// for (Int_t ichg=0; ichg<10; ichg++) schg += mdig->TrackCharge(ichg);
373// assert(schg==mdig->Signal());
374 Int_t schg = mdig->Signal();
516d3280 375
8af755f4 376// APPLY CONDITION ON SOFT BACKGROUND
377 Int_t tchg = schg - (Int_t(schg/10))*10;
516d3280 378
8af755f4 379 if (schg<=10 || tchg>0)
516d3280 380 {
8af755f4 381// mdig->Print();
516d3280 382
8af755f4 383 Int_t digitindex = digit;
384 Int_t detElemId = mdig->DetElemId();
385 Int_t cathode = mdig->Cathode();
386
387 const AliMpVSegmentation *seg = ((AliMUON*)gAlice->GetDetector("MUON"))->GetSegmentation()->GetMpSegmentation(detElemId,cathode);
388
389 Int_t ix = mdig->PadX(), iy = mdig->PadY();
390
391 AliDebug(3,Form("cathode %d ix %d iy %d ",cathode,ix,iy));
392
393 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
394
395 for (Int_t i=0; i<pad.GetNofLocations(); i++)
396 {
397 AliMpIntPair location = pad.GetLocation(i);
398
399 Int_t nboard = location.GetFirst();
400
401 Int_t ibitxy = location.GetSecond();
402
403
404 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->FindObject(fCrateMap[nboard-1]);
405
406 TObjArray *boards = cr->Boards();
407
408 AliMUONLocalTriggerBoard *b = (AliMUONLocalTriggerBoard*)boards->At(fBoardMap[nboard-1]);
409
410// if (b && nboard && b->GetNumber()==nboard)
411 if (b)
412 {
413 if (cathode && b->GetSwitch(6)) ibitxy += 8;
414
8af755f4 415 b->SetbitM(ibitxy,cathode,ichamber-10);
416
417 DigitFiredCircuit(b->GetI(), cathode, ichamber, digitindex);
418 }
8af755f4 419 }
420 }
516d3280 421 }
422 }
8af755f4 423
424// Particular case of the columns with 22 local boards (2R(L) 3R(L))
425 AliMUONTriggerCrate *crate = 0x0; TObjArray *bs = 0x0;
426
427 char *scratess[4] = { "2R", "2L", "3L", "3R"};
428 char *scratesd[4] = {"2-3R", "2-3L", "2-3L", "2-3R"};
429 Int_t slotf[4] = { 2, 2, 10, 10};
430 Int_t slotd[4] = { 1, 1, 9, 9};
431
432 for (Int_t i=0; i<4; i++)
433 {
434 crate = (AliMUONTriggerCrate*)fCrates->FindObject(scratess[i]);
435 bs = crate->Boards();
436 AliMUONLocalTriggerBoard *desybb = (AliMUONLocalTriggerBoard*)bs->At(14);
437 AliMUONLocalTriggerBoard *fromcb = (AliMUONLocalTriggerBoard*)bs->At(15);
438 AliMUONLocalTriggerBoard *desxbb = (AliMUONLocalTriggerBoard*)bs->At(16);
439
440 crate = (AliMUONTriggerCrate*)fCrates->FindObject(scratesd[i]);
441 bs = crate->Boards();
442 AliMUONLocalTriggerBoard *frombb = (AliMUONLocalTriggerBoard*)bs->At(slotf[i]);
443 AliMUONLocalTriggerBoard *desycb = (AliMUONLocalTriggerBoard*)bs->At(slotd[i]);
444
445 UShort_t cX[2];
446
447// COPY X3-4 FROM BOARD 2 OF CRATE 2-3 TO BOARD 16 OF CRATE 2
448// COPY X3-4 FROM BOARD 10 OF CRATE 2-3 TO BOARD 16 OF CRATE 3
449 frombb->GetX34(cX); desxbb->SetX34(cX);
450
451// COPY X3-4 FROM BOARD 15 OF CRATE 2 TO BOARD 1 OF CRATE 2-3
452// COPY X3-4 FROM BOARD 15 OF CRATE 3 TO BOARD 9 OF CRATE 2-3
453 fromcb->GetX34(cX); desycb->SetX34(cX);
454
455 UShort_t cY[4];
456
457 desybb->GetY(cY); frombb->SetY(cY);
458
459 frombb->GetY(cY); desxbb->SetY(cY);
460 fromcb->GetY(cY); desycb->SetY(cY);
461 }
462
516d3280 463// FILL UP/DOWN OF CURRENT BOARD (DONE VIA J3 BUS IN REAL LIFE)
8af755f4 464 for (Int_t i=0; i<fgkNCrates; i++)
516d3280 465 {
8af755f4 466 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
467
468 TObjArray *boards = cr->Boards();
469
516d3280 470 for (Int_t j=1; j<boards->GetEntries()-1; j++)
471 {
472 TObject *o = boards->At(j);
8af755f4 473
516d3280 474 if (!o) break;
8af755f4 475
516d3280 476 AliMUONLocalTriggerBoard *currboard = (AliMUONLocalTriggerBoard*)o;
8af755f4 477
516d3280 478 AliMUONLocalTriggerBoard *neighbour = (AliMUONLocalTriggerBoard*)boards->At(j+1);
8af755f4 479
516d3280 480 UShort_t cXY[2][4];
8af755f4 481
516d3280 482 if (j==1) {neighbour->GetXY(cXY); currboard->SetXYU(cXY);}
8af755f4 483
516d3280 484// LAST BOARD IN THE CRATE HAS NO UP EXCEPT FOR CRATES 2 & 3
485 if (j<boards->GetEntries()-2)
486 {
487 AliMUONLocalTriggerBoard *nextboard = (AliMUONLocalTriggerBoard*)boards->At(j+2);
8af755f4 488
516d3280 489 currboard->GetXY(cXY); neighbour->SetXYD(cXY);
490 nextboard->GetXY(cXY); neighbour->SetXYU(cXY);
8af755f4 491
516d3280 492 if (j==boards->GetEntries()-3) {neighbour->GetXY(cXY); nextboard->SetXYD(cXY);}
493 }
494 }
495 }
516d3280 496}
516d3280 497
498//___________________________________________
499void AliMUONTriggerElectronics::Feed(UShort_t pattern[2][4])
500{
501 for (Int_t i=0; i<fgkNCrates; i++)
502 {
503 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
504
505 TObjArray *boards = cr->Boards();
506
507 for (Int_t j=1; j<boards->GetEntries(); j++)
508 {
509 TObject *o = boards->At(j);
510
511 if (!o) break;
512
513 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
514
515 board->SetXY(pattern);
516 }
517 }
518}
519
520//___________________________________________
521void AliMUONTriggerElectronics::DumpOS()
522{
523 for (Int_t i=0;i<234;i++)
524 {
525 char name[20];
526 BuildName(i,name);
527
528 for (Int_t i=0; i<fgkNCrates; i++)
529 {
530 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
531
532 TObjArray *boards = cr->Boards();
533
534 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)boards->FindObject(name);
535
8af755f4 536 if (board) board->Scan("ALL");
516d3280 537 }
538 }
539}
540
541//___________________________________________
542void AliMUONTriggerElectronics::Scan(Option_t *option)
543{
544 for (Int_t i=0; i<fgkNCrates; i++)
545 {
546 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
547
548 TObjArray *boards = cr->Boards();
549
550 for (Int_t j=0; j<boards->GetEntries(); j++)
551 {
552 TObject *o = boards->At(j);
553
554 TString op = option;
555
556 Bool_t cdtion = kFALSE;
557
558 if (op.Contains("LOCAL")) cdtion = o->IsA() == AliMUONLocalTriggerBoard::Class();
559 if (op.Contains("REGIONAL")) cdtion = o->IsA() == AliMUONRegionalTriggerBoard::Class();
560 if (op.Contains("GLOBAL")) cdtion = o->IsA() == AliMUONGlobalTriggerBoard::Class();
561
562 if (!o || !cdtion) continue;
563
564 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
565
566 board->Scan();
567 }
568 }
569}
570
571//___________________________________________
572void AliMUONTriggerElectronics::Reset()
573{
574 for (Int_t i=0; i<fgkNCrates; i++)
575 {
576 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
577
578 TObjArray *boards = cr->Boards();
579
580 for (Int_t j=0; j<boards->GetEntries(); j++)
581 {
582 AliMUONTriggerBoard *b = (AliMUONTriggerBoard*)boards->At(j);
583
584 if (b) b->Reset();
585 }
586 }
8af755f4 587
588 for (Int_t i=0;i<16;i++)
589 {
590 fRegional[i] = 0;
591 for (Int_t j=0;j<16;j++) fLocal[i][j] = 0;
592 }
593
594 fGlobal = 0;
516d3280 595}
596
597//___________________________________________
598void AliMUONTriggerElectronics::LocalResponse()
599{
600// INTERFACE BOARDS
601 struct crates_t
602 {
603 TString name;
604 Int_t slots[5];
605 Int_t ns;
606 } crate[6];
607
608 crate[0].name = "2R"; crate[0].ns = 1; crate[0].slots[0] = 16;
609 crate[1].name = "2L"; crate[1].ns = 1; crate[1].slots[0] = 16;
610 crate[2].name = "3L"; crate[2].ns = 1; crate[2].slots[0] = 16;
611 crate[3].name = "3R"; crate[3].ns = 1; crate[3].slots[0] = 16;
612 crate[4].name = "2-3R"; crate[4].ns = 2; crate[4].slots[0] = 1; crate[4].slots[1] = 9;
613 crate[5].name = "2-3L"; crate[5].ns = 2; crate[5].slots[0] = 1; crate[5].slots[1] = 9;
614
615 for (Int_t i=0; i<fgkNCrates; i++)
616 {
617 Int_t iib = -1;
618
619 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
620
621 for (Int_t icr=0; icr<6; icr++)
622 {
623 const char *n = (crate[icr].name).Data();
624
625 AliMUONTriggerCrate *dcr = (AliMUONTriggerCrate*)fCrates->FindObject(n);
626
627// THIS CRATE CONTAINS AN INTERFACE BOARD
628 if ( dcr && !strcmp(cr->GetName(),dcr->GetName()) ) iib = icr;
629 }
630
631 TObjArray *boards = cr->Boards();
632
633 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
634
2247f0b7 635 UShort_t thisl[16]; for (Int_t j=0; j<16; j++) thisl[j] = 0;
636
516d3280 637 for (Int_t j=1; j<boards->GetEntries(); j++)
638 {
639 TObject *o = boards->At(j);
640
641 if (!o) break;
642
643 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
644
645 if (board)
646 {
647 board->Response();
648
649 fLocal[i][j-1] = board->GetResponse();
650
651// CRATE CONTAINING INTERFACE BOARD
652 if ( iib>-1 )
653 {
654 for (Int_t iid = 0; iid<crate[iib].ns; iid++)
655 {
656 if ( j == crate[iib].slots[iid] )
657 {
658 if ( fLocal[i][j-1] != 0 )
659 AliWarning(Form("Interface board %s in slot %d of crate %s has a non zero response",
660 board->GetName(),j,cr->GetName()));
661 }
662 }
663 }
516d3280 664
2247f0b7 665 thisl[j-1] = fLocal[i][j-1];
666 }
516d3280 667 }
2247f0b7 668
669 regb->SetLocalResponse(thisl);
516d3280 670 }
671}
672
673//___________________________________________
674void AliMUONTriggerElectronics::RegionalResponse()
675{
676 for (Int_t i=0; i<fgkNCrates; i++)
677 {
678 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
679
680 TObjArray *boards = cr->Boards();
681
682 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
683
684 if (regb)
685 {
686 regb->Response();
687
688 fRegional[i] = regb->GetResponse();
689 }
690 }
691}
692
693//___________________________________________
694void AliMUONTriggerElectronics::GlobalResponse()
695{
696 fGlobalTriggerBoard->SetRegionalResponse(fRegional);
697
698 fGlobalTriggerBoard->Response();
699
700 fGlobal = fGlobalTriggerBoard->GetResponse();
701}
702
703//___________________________________________
704void AliMUONTriggerElectronics::BoardName(Int_t ix, Int_t iy, char *name)
705{
706 TString s = (ix>0) ? "R" : "L";
707
708 Int_t board = iy / 16, bid[4] = {12,34,56,78};
709
710 ix = abs(ix);
711
712 Int_t line = ix / 10, column = ix - 10 * line;
713
714// old scheme: line==1 is line==9
715 line -= 9; line = TMath::Abs(line); line++;
716
717 sprintf(name,"%sC%dL%dB%d", s.Data(), column, line, bid[board]);
718
719 AliDebug(3, Form("Strip ( %d , %d ) connected to board %s ", ix, iy, name));
720}
721
722//___________________________________________
723void AliMUONTriggerElectronics::AddCrate(char *name)
724{
725 TClonesArray &lcrates = *fCrates;
726 new(lcrates[fNCrates++]) AliMUONTriggerCrate(name,17);
727}
728
729//___________________________________________
730AliMUONTriggerCrate* AliMUONTriggerElectronics::Crate(char *name)
731{
732 return (AliMUONTriggerCrate*)fCrates->FindObject(name);
733}
734
735//___________________________________________
736void AliMUONTriggerElectronics::BuildName(Int_t icirc, char name[20])
737{
738 const Int_t CircuitId[234] =
739 {
740 111, 121, 131, 141, 151, 161, 171,
741 211, 212, 221, 222, 231, 232, 241, 242, 251, 252, 261, 262, 271,
742 311, 312, 321, 322, 331, 332, 341, 342, 351, 352, 361, 362, 371,
743 411, 412, 413, 421, 422, 423, 424, 431, 432, 433, 434, 441, 442, 451, 452, 461, 462, 471,
744 521, 522, 523, 524, 531, 532, 533, 534, 541, 542, 551, 552, 561, 562, 571,
745 611, 612, 613, 621, 622, 623, 624, 631, 632, 633, 634, 641, 642, 651, 652, 661, 662, 671,
746 711, 712, 721, 722, 731, 732, 741, 742, 751, 752, 761, 762, 771,
747 811, 812, 821, 822, 831, 832, 841, 842, 851, 852, 861, 862, 871,
748 911, 921, 931, 941, 951, 961, 971,
749 -111, -121, -131, -141, -151, -161, -171,
750 -211, -212, -221, -222, -231, -232, -241, -242, -251, -252, -261, -262, -271,
751 -311, -312, -321, -322, -331, -332, -341, -342, -351, -352, -361, -362, -371,
752 -411, -412, -413, -421, -422, -423, -424, -431, -432, -433, -434, -441, -442, -451, -452, -461, -462, -471,
753 -521, -522, -523, -524, -531, -532, -533, -534, -541, -542, -551, -552, -561, -562, -571,
754 -611, -612, -613, -621, -622, -623, -624, -631, -632, -633, -634, -641, -642, -651, -652, -661, -662, -671,
755 -711, -712, -721, -722, -731, -732, -741, -742, -751, -752, -761, -762, -771,
756 -811, -812, -821, -822, -831, -832, -841, -842, -851, -852, -861, -862, -871,
757 -911, -921, -931, -941, -951, -961, -971
758 };
759
760 Int_t b[4] = {12, 34, 56, 78};
761
762 Int_t code = TMath::Abs(CircuitId[icirc]);
763
764 Int_t L = code / 100;
765
766 Int_t C = ( code - 100 * L ) / 10;
767
768 Int_t B = code - 100 * L - 10 * C;
769
770 const char *Side = (CircuitId[icirc]>0) ? "R" : "L";
771
772// L=1 AT TOP
773 L -= 9; L = abs(L); L++;
774
775 sprintf(name,"%sC%dL%dB%d",Side,C,L,b[B-1]);
776}
777
778//_______________________________________________________________________
779void
780AliMUONTriggerElectronics::Exec(Option_t*)
781{
782 Digits2Trigger();
783}
784
785//_______________________________________________________________________
786void AliMUONTriggerElectronics::Trigger()
787{
8af755f4 788 FeedM();
516d3280 789 LocalResponse();
790 RegionalResponse();
791 GlobalResponse();
792}
793/*
794//_______________________________________________________________________
795void AliMUONTriggerElectronics::DisableCrate(Int_t icrate)
796{
797 fRegional[icrate] = 0;
798}
799
800//_______________________________________________________________________
801void AliMUONTriggerElectronics::DisableCrate(char *Name)
802{
803 Int_t icrate;
804
805 for (Int_t i=0; i<fgkNCrates; i++)
806 {
807 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
808 if (strcmp(cr->GetName(),Name) )
809 continue;
810 else
811 {
812 icrate = i;
813 break;
814 }
815 }
816
817 fRegional[icrate] = 0;
818}
819
820//_______________________________________________________________________
821void AliMUONTriggerElectronics::DisableBoardInCrate(Int_t icrate, Int_t islot)
822{
823// BEWARE, REGIONAL BOARD IS IN SLOT 0
824 fLocal[icrate][islot] = 0;
825}
826*/
827//_______________________________________________________________________
828void AliMUONTriggerElectronics::Digits2Trigger()
829{
830 ClearDigitNumbers();
831
832 fMUONData->ResetTrigger();
833
834// RUN THE FULL BEE CHAIN
835 Trigger();
8af755f4 836// DumpOS();
837
516d3280 838 for (Int_t i=0; i<fgkNCrates; i++)
839 {
840 AliMUONTriggerCrate *cr = (AliMUONTriggerCrate*)fCrates->UncheckedAt(i);
841
842 TObjArray *boards = cr->Boards();
843
844 for (Int_t j=1; j<boards->GetEntries(); j++)
845 {
846 TObject *o = boards->At(j);
847
848 if (!o) break;
849
850 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
851
852 if (board)
853 {
854// L0 TRIGGER
855 if (board->Triggered())
856 {
857 Int_t localtr[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0};
858
859 Int_t icirc = board->GetI();
860
861 localtr[0] = icirc;
862 localtr[1] = board->GetStripX11();
863 localtr[2] = board->GetDev();
864 localtr[3] = board->GetStripY11();
865
866// SAVE LUT OUTPUT
867 localtr[4] = (fLocal[i][j-1] & 12) >> 2;
868 localtr[5] = (fLocal[i][j-1] & 48) >> 4;
869 localtr[6] = (fLocal[i][j-1] & 3);
870
2247f0b7 871 TBits rrr;
872 rrr.Set(6,&fLocal[i][j-1]);
873
516d3280 874// SAVE BIT PATTERN
875 localtr[7] = board->GetXY(0,0);
876 localtr[8] = board->GetXY(0,1);
877 localtr[9] = board->GetXY(0,2);
878 localtr[10] = board->GetXY(0,3);
879
880 localtr[11] = board->GetXY(1,0);
881 localtr[12] = board->GetXY(1,1);
882 localtr[13] = board->GetXY(1,2);
883 localtr[14] = board->GetXY(1,3);
884
885// ADD A NEW LOCAL TRIGGER
886 AliMUONLocalTrigger *pLocTrig = new AliMUONLocalTrigger(localtr, fDigitNumbers[icirc]);
887
888 fMUONData->AddLocalTrigger(*pLocTrig);
889 }
890 }
891 }
892 }
893
894// GLOBAL TRIGGER INFORMATION: [0] -> LOW PT
895// [1] -> HIGH PT
896// [2] -> ALL PT
897 Int_t GlobalSinglePlus[3], GlobalSingleMinus[3], GlobalSingleUndef[3];
898 Int_t GlobalPairUnlike[3], GlobalPairLike[3];
899
900 GlobalPairUnlike[0] = (fGlobal & 16) >> 4;
901 GlobalPairUnlike[1] = (fGlobal & 256) >> 8;
902 GlobalPairUnlike[2] = (fGlobal & 1);
903
904 GlobalPairLike[0] = (fGlobal & 32) >> 5;
905 GlobalPairLike[1] = (fGlobal & 512) >> 9;
906 GlobalPairLike[2] = (fGlobal & 2) >> 1;
907
908 GlobalSinglePlus[0] = ((fGlobal & 192) >> 6) == 2;
909 GlobalSinglePlus[1] = ((fGlobal & 3072) >> 10) == 2;
910 GlobalSinglePlus[2] = ((fGlobal & 12) >> 2) == 2;
911
912 GlobalSingleMinus[0] = ((fGlobal & 192) >> 6) == 1;
913 GlobalSingleMinus[1] = ((fGlobal & 3072) >> 10) == 1;
914 GlobalSingleMinus[2] = ((fGlobal & 12) >> 2) == 1;
915
916 GlobalSingleUndef[0] = ((fGlobal & 192) >> 6) == 3;
917 GlobalSingleUndef[1] = ((fGlobal & 3072) >> 10) == 3;
918 GlobalSingleUndef[2] = ((fGlobal & 12) >> 2) == 3;
919
920 AliMUONGlobalTrigger *pGloTrig = new AliMUONGlobalTrigger(GlobalSinglePlus, GlobalSingleMinus,
921 GlobalSingleUndef, GlobalPairUnlike,
922 GlobalPairLike);
923
924// ADD A LOCAL TRIGGER IN THE LIST
925 fMUONData->AddGlobalTrigger(*pGloTrig);
926
8af755f4 927// NOW RESET ELECTRONICS
516d3280 928 Reset();
929}
930
931//_______________________________________________________________________
932void AliMUONTriggerElectronics::ClearDigitNumbers()
933{
934// RESET fDigitNumbers
935 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++) fDigitNumbers[i].Set(0);
936}
937
938//_______________________________________________________________________
939void AliMUONTriggerElectronics::DigitFiredCircuit(Int_t circuit, Int_t cathode,
940 Int_t chamber, Int_t digit)
941{
942// REGISTERS THAT THE SPECIFIED DIGIT FIRED THE SPECIFIED CIRCUIT
943// THIS DIGIT GETS ADDED TO AN ARRAY WHICH WILL BE COPIED TO
944// AliMUONLocalTrigger WHEN SUCH AN OBJECT IS CREATED FOR EACH CIRCUIT
945 Int_t digitnumber = AliMUONLocalTrigger::EncodeDigitNumber(chamber, cathode, digit);
946 Int_t last = fDigitNumbers[circuit].GetSize();
947 fDigitNumbers[circuit].Set(last + 1);
948 fDigitNumbers[circuit][last] = digitnumber;
949}
950