1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 // Class AliMUONTriggerElectronics
20 //--------------------------------
21 // Manager class for muon trigger electronics
22 // Client of trigger board classes
23 // Debugged by Ph. Crochet & Ch. Finck
24 // Interfaced with new mapping Ch. Finck
26 // Author: Rachid Guernane (LPCCFd)
27 //-----------------------------------------------------------------------------
29 #include "AliLoader.h"
31 #include "AliMUONCalibrationData.h"
32 #include "AliMUONVDigit.h"
33 #include "AliMUONVDigitStore.h"
34 #include "AliMUONGlobalTrigger.h"
35 #include "AliMUONGlobalTriggerBoard.h"
36 #include "AliMUONLocalTrigger.h"
37 #include "AliMUONLocalTriggerBoard.h"
38 #include "AliMUONRegionalTrigger.h"
39 #include "AliMUONRegionalTriggerBoard.h"
40 #include "AliMUONTriggerCrate.h"
41 #include "AliMUONTriggerCrateStore.h"
42 #include "AliMUONTriggerElectronics.h"
43 #include "AliMUONTriggerCrateConfig.h"
44 #include "AliMUONRegionalTriggerConfig.h"
45 #include "AliMUONGlobalCrateConfig.h"
46 #include "AliMUONVTriggerStore.h"
47 #include "AliMUONVCalibParam.h"
48 #include "AliMpCathodType.h"
50 #include "AliMpDEManager.h"
51 #include "AliMpSegmentation.h"
52 #include "AliMpVSegmentation.h"
53 #include "AliMpCathodType.h"
54 #include "AliMpTriggerCrate.h"
55 #include "AliMpLocalBoard.h"
56 #include "AliMpDDLStore.h"
57 #include "AliMpExMap.h"
58 #include "AliMpIntPair.h"
61 #include "AliLoader.h"
68 ClassImp(AliMUONTriggerElectronics)
71 //___________________________________________
72 AliMUONTriggerElectronics::AliMUONTriggerElectronics(AliMUONCalibrationData* calibData)
74 fCrates(new AliMUONTriggerCrateStore),
75 fGlobalTriggerBoard(new AliMUONGlobalTriggerBoard)
80 for (Int_t i = 0; i < 2; ++i) {
81 fCopyXInput[i] = new TList();
82 fCopyXInput[i]->SetOwner();
83 fCopyYInput[i] = new TList();
84 fCopyYInput[i]->SetOwner();
87 // force loading of mapping if not already done
88 if ( !AliMpDDLStore::Instance(kFALSE) )
90 AliMpCDB::LoadDDLStore();
99 //___________________________________________
100 AliMUONTriggerElectronics::~AliMUONTriggerElectronics()
104 delete fGlobalTriggerBoard;
106 for (Int_t i = 0; i < 2; ++i) {
107 delete fCopyXInput[i];
108 delete fCopyYInput[i];
113 //___________________________________________
114 void AliMUONTriggerElectronics::SetCopyInput()
116 /// set list of copy input
118 for (Int_t iDDL = 0; iDDL < 2; ++iDDL) {
120 for(Int_t iReg = 0; iReg < 8; ++iReg){ //reg loop
122 AliMpTriggerCrate* crateMapping = AliMpDDLStore::Instance()->GetTriggerCrate(iDDL, iReg);
124 for(Int_t iLocal = 0; iLocal < crateMapping->GetNofLocalBoards(); ++iLocal) {
126 Int_t localBoardFromId = crateMapping->GetLocalBoardId(iLocal);
127 if (!localBoardFromId) continue; //empty slot, should not happen
129 AliMpLocalBoard* localBoardFrom = AliMpDDLStore::Instance()->GetLocalBoard(localBoardFromId);
130 Int_t localBoardToId;
131 if ((localBoardToId = localBoardFrom->GetInputXto())) {
132 AliMpLocalBoard* localBoardTo = AliMpDDLStore::Instance()->GetLocalBoard(localBoardToId);
133 TString crateFrom = localBoardFrom->GetCrate();
134 Int_t slotFrom = localBoardFrom->GetSlot();
135 TString crateTo = localBoardTo->GetCrate();
136 Int_t slotTo = localBoardTo->GetSlot();
138 fCopyXInput[0]->Add(new AliMpIntPair(AliMpExMap::GetIndex(crateFrom), slotFrom));
139 fCopyXInput[1]->Add(new AliMpIntPair(AliMpExMap::GetIndex(crateTo), slotTo));
140 AliDebug(3, Form("copy xInputs from local %s_%d to %s_%d\n", crateFrom.Data(), slotFrom,
141 crateTo.Data(), slotTo));
144 if ((localBoardToId = localBoardFrom->GetInputYto())) {
145 AliMpLocalBoard* localBoardTo = AliMpDDLStore::Instance()->GetLocalBoard(localBoardToId);
146 TString crateFrom = localBoardFrom->GetCrate();
147 Int_t slotFrom = localBoardFrom->GetSlot();
148 TString crateTo = localBoardTo->GetCrate();
149 Int_t slotTo = localBoardTo->GetSlot();
151 fCopyYInput[0]->Add(new AliMpIntPair(AliMpExMap::GetIndex(crateFrom), slotFrom));
152 fCopyYInput[1]->Add(new AliMpIntPair(AliMpExMap::GetIndex(crateTo), slotTo));
153 AliDebug(3, Form("copy yInputs from local %s_%d to %s_%d\n", crateFrom.Data(), slotFrom,
154 crateTo.Data(), slotTo));
163 //___________________________________________
164 void AliMUONTriggerElectronics::Factory(AliMUONCalibrationData* calibData)
166 /// BUILD ALL ELECTRONICS
169 fCrates->ReadFromFile(calibData);
172 //___________________________________________
173 void AliMUONTriggerElectronics::Feed(const AliMUONVDigitStore& digitStore)
178 TIter next(digitStore.CreateTriggerIterator());
181 while ( ( mdig = static_cast<AliMUONVDigit*>(next()) ) )
183 // CHECKME ! The TrackCharge is not ok with new digitizerV3 !
184 // for (Int_t ichg=0; ichg<10; ichg++) schg += mdig->TrackCharge(ichg);
185 Int_t ichamber = AliMpDEManager::GetChamberId(mdig->DetElemId());
186 Int_t schg = (Int_t)(mdig->Charge() + 0.5);
188 // APPLY CONDITION ON SOFT BACKGROUND
189 Int_t tchg = schg - (Int_t(schg/10))*10;
191 if (schg<=10 || tchg>0)
193 Int_t detElemId = mdig->DetElemId();
194 Int_t cathode = mdig->Cathode();
196 const AliMpVSegmentation* seg =
197 AliMpSegmentation::Instance()
198 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
200 Int_t ix = mdig->PadX(), iy = mdig->PadY();
202 AliDebug(3,Form("cathode %d ix %d iy %d ",cathode,ix,iy));
204 AliMpPad pad = seg->PadByIndices(ix,iy,kTRUE);
206 for (Int_t i=0; i<pad.GetNofLocations(); i++)
208 Int_t nboard = pad.GetLocalBoardId(i);
210 Int_t ibitxy = pad.GetLocalBoardChannel(i);
212 AliMUONLocalTriggerBoard *b = fCrates->LocalBoard(nboard);
216 if (cathode && b->GetSwitch(6)) ibitxy += 8;
218 b->SetbitM(ibitxy,cathode,ichamber-10);
222 AliError(Form("Could not get local board number %d",b->GetNumber()));
228 // Particular case of the columns with 22 local boards (2R(L) 3R(L))
229 // fill copy input from mapping instead of hardcoded valued (Ch.F)
230 AliMUONTriggerCrate *crate = 0x0; TObjArray *bs = 0x0;
232 for (Int_t i = 0; i < fCopyXInput[0]->GetEntries(); ++i)
234 AliMpIntPair* pair = (AliMpIntPair*)fCopyXInput[0]->At(i);
235 TString crateFrom = AliMpExMap::GetString(pair->GetFirst());
236 Int_t slotFrom = pair->GetSecond();
238 pair = (AliMpIntPair*)fCopyXInput[1]->At(i);
239 TString crateTo = AliMpExMap::GetString(pair->GetFirst());
240 Int_t slotTo = pair->GetSecond();
242 AliDebug(3, Form("copy xInputs from local %s_%d to %s_%d\n", crateFrom.Data(), slotFrom,
243 crateTo.Data(), slotTo));
246 crate = fCrates->Crate(crateFrom);
247 bs = crate->Boards();
248 AliMUONLocalTriggerBoard *fromxb = (AliMUONLocalTriggerBoard*)bs->At(slotFrom);
249 crate = fCrates->Crate(crateTo);
250 bs = crate->Boards();
251 AliMUONLocalTriggerBoard *desxb = (AliMUONLocalTriggerBoard*)bs->At(slotTo);
252 fromxb->GetX34(cX); desxb->SetX34(cX);
257 for (Int_t i = 0; i < fCopyYInput[0]->GetEntries(); ++i)
259 AliMpIntPair* pair = (AliMpIntPair*)fCopyYInput[0]->At(i);
260 TString crateFrom = AliMpExMap::GetString(pair->GetFirst());
261 Int_t slotFrom = pair->GetSecond();
263 pair = (AliMpIntPair*)fCopyYInput[1]->At(i);
264 TString crateTo = AliMpExMap::GetString(pair->GetFirst());
265 Int_t slotTo = pair->GetSecond();
267 AliDebug(3, Form("copy yInputs from local %s_%d to %s_%d\n", crateFrom.Data(), slotFrom,
268 crateTo.Data(), slotTo));
271 crate = fCrates->Crate(crateFrom);
272 bs = crate->Boards();
273 AliMUONLocalTriggerBoard *fromyb = (AliMUONLocalTriggerBoard*)bs->At(slotFrom);
274 crate = fCrates->Crate(crateTo);
275 bs = crate->Boards();
276 AliMUONLocalTriggerBoard *desyb = (AliMUONLocalTriggerBoard*)bs->At(slotTo);
277 fromyb->GetY(cY); desyb->SetY(cY);
280 // FILL UP/DOWN OF CURRENT BOARD (DONE VIA J3 BUS IN REAL LIFE)
281 AliMUONTriggerCrate* cr;
282 TIter next2(fCrates->CreateCrateIterator());
284 while ( ( cr = static_cast<AliMUONTriggerCrate*>(next2()) ) )
286 TObjArray *boards = cr->Boards();
288 for (Int_t j = 1; j < boards->GetEntries()-1; j++)
290 TObject *o = boards->At(j);
294 AliMUONLocalTriggerBoard *currboard = (AliMUONLocalTriggerBoard*)o;
296 AliMUONLocalTriggerBoard *neighbour = (AliMUONLocalTriggerBoard*)boards->At(j+1);
300 if (j==1) {neighbour->GetXY(cXY); currboard->SetXYU(cXY);}
302 // LAST BOARD IN THE CRATE HAS NO UP EXCEPT FOR CRATES 2 & 3
303 if (j < boards->GetEntries()-2)
305 AliMUONLocalTriggerBoard *nextboard = (AliMUONLocalTriggerBoard*)boards->At(j+2);
307 currboard->GetXY(cXY); neighbour->SetXYD(cXY);
308 nextboard->GetXY(cXY); neighbour->SetXYU(cXY);
310 if (j==boards->GetEntries()-3) {neighbour->GetXY(cXY); nextboard->SetXYD(cXY);}
318 //___________________________________________
319 void AliMUONTriggerElectronics::Feed(UShort_t pattern[2][4])
323 AliMUONTriggerCrate* cr;
324 TIter next(fCrates->CreateCrateIterator());
326 while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
328 TObjArray *boards = cr->Boards();
330 for (Int_t j = 1; j < boards->GetEntries(); j++)
332 TObject *o = boards->At(j);
336 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
338 board->SetXY(pattern);
343 //___________________________________________
344 void AliMUONTriggerElectronics::DumpOS()
346 /// DUMP IN THE OLD WAY
348 for (Int_t i= 0; i < 234;i++)
350 AliMUONLocalTriggerBoard *board = fCrates->LocalBoard(i);
352 if (board) board->Scan("ALL");
356 //___________________________________________
357 void AliMUONTriggerElectronics::Scan(Option_t *option)
362 AliMUONTriggerCrate* cr;
363 TIter next(fCrates->CreateCrateIterator());
365 while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
367 TObjArray *boards = cr->Boards();
369 for (Int_t j = 0; j < boards->GetEntries(); j++)
371 TObject *o = boards->At(j);
375 Bool_t cdtion = kFALSE;
377 if (op.Contains("LOCAL")) cdtion = o->IsA() == AliMUONLocalTriggerBoard::Class();
378 if (op.Contains("REGIONAL")) cdtion = o->IsA() == AliMUONRegionalTriggerBoard::Class();
379 if (op.Contains("GLOBAL")) cdtion = o->IsA() == AliMUONGlobalTriggerBoard::Class();
381 if (!o || !cdtion) continue;
383 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
390 //___________________________________________
391 void AliMUONTriggerElectronics::Reset()
396 AliMUONTriggerCrate* cr;
397 TIter next(fCrates->CreateCrateIterator());
398 while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
400 TObjArray *boards = cr->Boards();
402 for (Int_t j=0; j<boards->GetEntries(); j++)
404 AliMUONTriggerBoard *b = (AliMUONTriggerBoard*)boards->At(j);
412 //_______________________________________________________________________
413 void AliMUONTriggerElectronics::LoadMasks(AliMUONCalibrationData* calibData)
415 /// Load mask from config in CDB
419 AliMUONRegionalTriggerConfig* regionalConfig = calibData->RegionalTriggerConfig();
421 AliWarning("No valid regional trigger configuration in CDB");
424 AliMUONTriggerCrate* cr;
425 TIter next(fCrates->CreateCrateIterator());
429 while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
431 TObjArray *boards = cr->Boards();
433 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
435 AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(cr->GetName());
439 AliError(Form("Crate %s not present in configuration !!!", cr->GetName()));
443 UShort_t rmask= crateConfig->GetMask();
447 for (Int_t j = 1; j < boards->GetEntries(); j++)
449 AliMUONLocalTriggerBoard *b = (AliMUONLocalTriggerBoard*)boards->At(j);
451 Int_t cardNumber = b->GetNumber();
453 if (cardNumber) // interface board are not interested
455 AliMUONVCalibParam* localBoardMasks = calibData->LocalTriggerBoardMasks(cardNumber);
456 for ( Int_t i = 0; i < localBoardMasks->Size(); ++i )
458 UShort_t lmask = static_cast<UShort_t>(localBoardMasks->ValueAsInt(i) & 0xFFFF);
466 AliMUONGlobalCrateConfig * globalConfig = calibData->GlobalTriggerCrateConfig();
468 AliWarning("No valid trigger crate configuration in CDB");
471 for (Int_t i = 0; i < 4; i++) {
472 gmask = globalConfig->GetGlobalMask(i);
473 fGlobalTriggerBoard->Mask(i,gmask);
477 //___________________________________________
478 void AliMUONTriggerElectronics::LocalResponse()
480 /// Compute the response for local cards
482 AliMUONTriggerCrate* cr;
483 TIter next(fCrates->CreateCrateIterator());
485 while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
488 TObjArray *boards = cr->Boards();
490 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
492 UShort_t thisl[16]; for (Int_t j=0; j<16; j++) thisl[j] = 0;
494 for (Int_t j = 1; j < boards->GetEntries(); j++)
496 TObject *o = boards->At(j);
500 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
502 if (board) // check if empty slot
506 UShort_t response = board->GetResponse();
508 // CRATE CONTAINING INTERFACE BOARD
509 if (board->GetNumber() == 0) // copy boards
512 AliWarning(Form("Interface board %s in slot %d of crate %s has a non zero response",
513 board->GetName(),j,cr->GetName()));
514 AliDebug(1, Form("local slot %d, number %d in crate %s\n", j, board->GetNumber(), cr->GetName()));
518 thisl[j-1] = response;
522 regb->SetLocalResponse(thisl);
526 //___________________________________________
527 void AliMUONTriggerElectronics::RegionalResponse()
529 /// Compute the response for all regional cards.
530 AliMUONTriggerCrate* cr;
531 TIter next(fCrates->CreateCrateIterator());
533 while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) )
535 TObjArray *boards = cr->Boards();
537 AliMUONRegionalTriggerBoard *regb = (AliMUONRegionalTriggerBoard*)boards->At(0);
546 //___________________________________________
547 void AliMUONTriggerElectronics::GlobalResponse()
549 /// Compute the global response
551 UShort_t regional[16];
553 AliMUONTriggerCrate* cr;
556 if ( !fCrates->NumberOfCrates() >= 16 )
558 AliFatal(Form("Something is wrong : too many crates %d",
559 fCrates->NumberOfCrates()));
562 // send regional responses to the global trigger in right order
563 // do not used iterator order
565 for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side
567 for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side.
569 cr = fCrates->Crate(iSide, iReg);
571 AliMUONTriggerBoard* rb =
572 static_cast<AliMUONTriggerBoard*>(cr->Boards()->At(0));
573 regional[irb] = rb->GetResponse();
578 fGlobalTriggerBoard->SetRegionalResponse(regional);
579 fGlobalTriggerBoard->Response();
582 //_______________________________________________________________________
583 void AliMUONTriggerElectronics::Digits2Trigger(const AliMUONVDigitStore& digitStore,
584 AliMUONVTriggerStore& triggerStore)
586 /// Main method to go from digits to trigger decision
587 AliMUONRegionalTrigger pRegTrig;
589 triggerStore.Clear();
591 // RUN THE FULL BEE CHAIN
598 AliMUONTriggerCrate* cr;
599 AliMUONLocalTrigger localTrigger;
601 // stored in right order
602 // do not used iterator order
604 for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side
606 for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side.
608 cr = fCrates->Crate(iSide, iReg);
609 TObjArray *boards = cr->Boards();
611 UInt_t regInpLpt = 0;
612 UInt_t regInpHpt = 0;
614 AliMUONRegionalTriggerBoard *regBoard = (AliMUONRegionalTriggerBoard*)boards->At(0);
616 for (Int_t j = 1; j < boards->GetEntries(); j++)
618 TObject *o = boards->At(j);
622 AliMUONLocalTriggerBoard *board = (AliMUONLocalTriggerBoard*)o;
627 // pcrochet 181206: MOOD needs ALL boards
628 // if (board->Triggered())
631 Int_t icirc = board->GetNumber();
632 if (icirc != 0) { // pcrochet 181206: MOOD needs ALL boards
634 localTrigger.SetLoCircuit(icirc);
635 localTrigger.SetLoStripX(board->GetStripX11());
636 localTrigger.SetLoDev(board->GetDev());
637 localTrigger.SetLoSdev(board->GetSdev());
638 localTrigger.SetLoTrigY(board->GetTrigY());
639 localTrigger.SetLoStripY(board->GetStripY11());
642 UShort_t response = board->GetResponse();
643 localTrigger.SetLoHpt((response & 12) >> 2);
644 localTrigger.SetLoLpt(response & 3);
646 // calculates regional inputs from local for the moment
647 UInt_t hPt = (response >> 2) & 0x3;
648 UInt_t lPt = response & 0x3;
650 regInpHpt |= hPt << (30 - (j-1)*2);
651 regInpLpt |= lPt << (30 - (j-1)*2);
654 rrr.Set(6,&response);
657 localTrigger.SetX1Pattern(board->GetXY(0,0));
658 localTrigger.SetX2Pattern(board->GetXY(0,1));
659 localTrigger.SetX3Pattern(board->GetXY(0,2));
660 localTrigger.SetX4Pattern(board->GetXY(0,3));
662 localTrigger.SetY1Pattern(board->GetXY(1,0));
663 localTrigger.SetY2Pattern(board->GetXY(1,1));
664 localTrigger.SetY3Pattern(board->GetXY(1,2));
665 localTrigger.SetY4Pattern(board->GetXY(1,3));
667 // ADD A NEW LOCAL TRIGGER
668 triggerStore.Add(localTrigger);
673 pRegTrig.SetId(iReg + 8*iSide);
674 pRegTrig.SetLocalOutput(regInpLpt, 0);
675 pRegTrig.SetLocalOutput(regInpHpt, 1);
676 pRegTrig.SetOutput(regBoard->GetResponse());
678 triggerStore.Add(pRegTrig);
682 // GLOBAL TRIGGER INFORMATION
683 UShort_t global = fGlobalTriggerBoard->GetResponse();
684 UInt_t *globalInput = fGlobalTriggerBoard->GetGlobalInput();
686 AliMUONGlobalTrigger globalTrigger;
688 globalTrigger.SetFromGlobalResponse(global);
689 globalTrigger.SetFromGlobalInput(globalInput);
690 // ADD A LOCAL TRIGGER IN THE LIST
691 triggerStore.SetGlobal(globalTrigger);
693 // NOW RESET ELECTRONICS