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 **************************************************************************/
17 #include "AliMUONTriggerUtilities.h"
23 #include "AliMUONCalibrationData.h"
24 //#include "AliMUONTriggerCrateStore.h"
25 //#include "AliMUONTriggerCrate.h"
26 //#include "AliMUONGlobalCrateConfig.h"
27 //#include "AliMUONVCalibParam.h"
28 //#include "AliMUONRegionalTriggerConfig.h"
29 #include "AliMUONGlobalTrigger.h"
30 #include "AliMUONLocalTriggerBoard.h"
31 #include "AliMUONVDigit.h"
32 #include "AliMUONConstants.h"
33 #include "AliMUONTriggerElectronics.h"
34 #include "AliMUONDigitStoreV2R.h"
35 #include "AliMUONDigitMaker.h"
36 #include "AliMUONTriggerStoreV1.h"
38 #include "AliMpDDLStore.h"
40 //#include "AliMpLocalBoard.h"
41 #include "AliMpConstants.h"
42 #include "AliMpVSegmentation.h"
43 #include "AliMpSegmentation.h"
46 ClassImp(AliMUONTriggerUtilities)
50 //_____________________________________________________________________________
51 AliMUONTriggerUtilities::AliMUONTriggerUtilities(AliMUONCalibrationData* calibData):
53 fCalibrationData(calibData),
54 fTriggerStatusMap(2*AliMUONConstants::NTriggerCh()*AliMUONConstants::NTriggerCircuit()),
55 fMaskedDigitsStore(new AliMUONDigitStoreV2R())
61 //_____________________________________________________________________________
62 AliMUONTriggerUtilities::~AliMUONTriggerUtilities()
64 /// Destructor. Note we're the owner of some pointers.
65 delete fMaskedDigitsStore;
69 //_____________________________________________________________________________
70 Bool_t AliMUONTriggerUtilities::Init()
72 /// Build trigger status map from masks
73 AliMUONTriggerElectronics trigElectronics(fCalibrationData);
74 AliMUONDigitMaker digitMaker(kFALSE);
75 AliMUONDigitStoreV2R digitStore, digitStorePart;
76 AliMUONTriggerStoreV1 triggerStore, triggerStorePart;
78 // // In the trigger logic, when the regional input is masked in the
79 TArrayI activeBoards(AliMUONConstants::NTriggerCircuit());
80 // for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side
82 // UInt_t currMaskLpt = fCalibrationData->GlobalTriggerCrateConfig()->GetGlobalMask(iSide);
83 // UInt_t currMaskHpt = fCalibrationData->GlobalTriggerCrateConfig()->GetGlobalMask(2+iSide);
84 // for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side.
86 // Bool_t isActiveLpt = ( currMaskLpt >> (4*iReg) ) & 0xF;
87 // Bool_t isActiveHpt = ( currMaskHpt >> (4*iReg) ) & 0xF;
88 // if ( ! isActiveLpt && ! isActiveHpt ) continue;
89 // AliMUONTriggerCrate* cr = trigElectronics.GetCrateStore()->Crate(iSide, iReg);
90 // TObjArray *boards = cr->Boards();
92 // for ( Int_t iboard = 1; iboard < boards->GetEntries(); iboard++)
94 // TObject* currBoard = boards->At(iboard);
96 // if ( ! currBoard ) break;
97 // Int_t idx = static_cast<AliMUONLocalTriggerBoard*>(currBoard)->GetNumber()-1;
98 // if ( idx < 0 ) continue; // Some boards of crates 2 and 3 do not exist, but they are still in the board list
99 // activeBoards[idx] = 1;
100 // } // loop on boards in crate
101 // } // loop on regional
104 TArrayS xyPatternAll[2];
105 for(Int_t icath=0; icath<AliMpConstants::NofCathodes(); icath++){
106 xyPatternAll[icath].Set(AliMpConstants::NofTriggerChambers());
107 xyPatternAll[icath].Reset(0xFFFF);
110 // Create a store with all digits in trigger
111 for ( Int_t iboard=1; iboard<=AliMpConstants::NofLocalBoards(); iboard++ ) {
112 digitMaker.TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
114 // For each local board, fill all the strips and check the global output:
115 // if the board is masked at the global level, the output will be 0
116 digitStorePart.Clear();
117 digitMaker.TriggerDigits(iboard, xyPatternAll, digitStorePart, kFALSE);
118 triggerStorePart.Clear();
119 trigElectronics.Digits2Trigger(digitStorePart, triggerStorePart);
120 AliMUONGlobalTrigger* globalTrig = triggerStorePart.Global();
121 if ( globalTrig->GetGlobalResponse() > 0 ) activeBoards[iboard-1] = 1;
124 // Create trigger with electronics (it applies masks)
125 trigElectronics.Digits2Trigger(digitStore, triggerStore);
127 // Re-compute digits from triggerStore
128 // Since the masks were applied in the response,
129 // the new store do not contain masked channels
130 AliMUONDigitStoreV2R digitStoreMasked;
131 digitMaker.TriggerToDigitsStore(triggerStore, digitStoreMasked);
133 // Loop on non-masked digit store
134 // Search for digits in the masked one:
135 // if digit is not found, it means it was masked
136 TIter next(digitStore.CreateIterator());
137 AliMUONVDigit* dig = 0x0;
138 while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
139 Int_t cath = dig->Cathode();
140 Int_t detElemId = dig->DetElemId();
141 Int_t board = dig->ManuId();
142 Int_t strip = dig->ManuChannel();
143 AliMUONVDigit* currDigit = 0x0;
144 if ( activeBoards[board-1] == 1 ) currDigit = digitStoreMasked.FindObject(detElemId, board, strip, cath);
145 Bool_t isMasked = ( currDigit ) ? kFALSE : kTRUE;
146 if ( isMasked ) fMaskedDigitsStore->Add(*((AliMUONVDigit*)dig->Clone()), AliMUONVDigitStore::kDeny);
148 Int_t ich = detElemId/100-11;
149 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(cath));
150 AliMpPad pad = seg->PadByIndices(dig->PadX(), dig->PadY(), kTRUE);
151 for (Int_t iloc=0; iloc<pad.GetNofLocations(); iloc++) {
152 Int_t currBoard = pad.GetLocalBoardId(iloc);
153 Int_t arrayIndex = GetArrayIndex(cath, ich, currBoard);
154 fTriggerStatusMap[arrayIndex] |= ( 0x1 << strip );
155 } // loop on locations (in bending plane we have to fill all copy boards)
159 // AliMUONTriggerCrateStore crates;
160 // crates.ReadFromFile(fCalibrationData);
162 // AliMUONRegionalTriggerConfig* regionalConfig = fCalibrationData->RegionalTriggerConfig();
163 // if ( ! regionalConfig ) AliFatal("no valid regional trigger configuration in CDB\n");
166 // AliMUONTriggerCrate* cr = 0x0;
167 // TIter next ( crates.CreateCrateIterator() );
168 // while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) ) {
169 // TObjArray *boards = cr->Boards();
171 // AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(cr->GetName());
173 // if ( ! crateConfig ) AliFatal(Form("Crate %s not present in configuration !!!\n", cr->GetName()));
175 // UShort_t regionalMask = crateConfig->GetMask();
178 // for (Int_t iboard = 1; iboard < boards->GetEntries(); iboard++ ) {
179 // Bool_t activeBoard = ( ( regionalMask >> ( iboard - 1) ) & 1 );
180 // AliMUONLocalTriggerBoard* board = (AliMUONLocalTriggerBoard*)boards->At(iboard);
181 // Int_t cardNumber = board->GetNumber();
182 // if ( cardNumber <= 0 ) continue; // interface board are not interested
183 // AliMUONVCalibParam* localBoardMask = fCalibrationData->LocalTriggerBoardMasks(cardNumber);
184 // for ( Int_t icath = 0; icath < 2; ++icath ) {
185 // for ( Int_t ich = 0; ich < 4; ++ich ) {
186 // Int_t planeIndex = icath * 4 + ich;
187 // Int_t localMask = ( activeBoard ) ? localBoardMask->ValueAsInt(planeIndex) : 0;
188 // Int_t arrayIndex = GetArrayIndex(icath, ich, cardNumber);
189 // fTriggerStatusMap[arrayIndex] = localMask;
190 // } // loop on chambers
191 // } // loop on planes
192 // } // loop on boards
193 // } // loop on crates
198 //_____________________________________________________________________________
199 Bool_t AliMUONTriggerUtilities::IsMasked(const AliMUONVDigit& digit) const
201 /// Check if pad is masked
202 return IsMasked(digit.DetElemId(), digit.Cathode(), digit.ManuId(), digit.ManuChannel());
206 //_____________________________________________________________________________
207 Bool_t AliMUONTriggerUtilities::IsMasked(const AliMpPad& pad, Int_t detElemId, Int_t cathode) const
209 /// Check if pad is masked
210 return IsMasked(detElemId, cathode, pad.GetLocalBoardId(0), pad.GetLocalBoardChannel(0));
214 //_____________________________________________________________________________
215 Bool_t AliMUONTriggerUtilities::IsMasked(Int_t detElemId, Int_t cathode, Int_t localCircuit, Int_t strip) const
217 /// Check if pad is masked
218 Int_t trigCh = detElemId/100 - 11;
220 // Int_t ibitxy = strip;
221 // AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(localCircuit);
222 // if ( cathode && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB) ) ibitxy += 8;
223 Int_t arrayIndex = GetArrayIndex(cathode, trigCh, localCircuit);
224 Bool_t isMasked = ( ( ( fTriggerStatusMap[arrayIndex] >> strip ) & 0x1 ) == 0 );
225 AliDebug(1,Form("detElemId %i cath %i board %i strip %i is active %i\n", detElemId, cathode, localCircuit, strip, ! isMasked));
229 //_____________________________________________________________________________
230 Bool_t AliMUONTriggerUtilities::IsMaskedBoard ( Int_t localCircuit, Int_t detElemId, Int_t cathode ) const
232 /// Check if board is masked
233 Int_t trigCh = detElemId/100-11;
234 Int_t arrayIndex = GetArrayIndex(cathode, trigCh, localCircuit);
235 return ( fTriggerStatusMap[arrayIndex] == 0 );
240 //_____________________________________________________________________________
241 Int_t AliMUONTriggerUtilities::GetArrayIndex(Int_t cathode, Int_t trigCh, Int_t localCircuit) const
243 /// Get index of array with trigger status map or efficiency
245 AliMUONConstants::NTriggerCircuit() * AliMUONConstants::NTriggerCh() * cathode +
246 AliMUONConstants::NTriggerCircuit() * trigCh + localCircuit-1;