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 TArrayI activeBoards(AliMUONConstants::NTriggerCircuit());
79 // for (Int_t iSide = 0; iSide < 2; iSide++) // right & left side
81 // UInt_t currMaskLpt = fCalibrationData->GlobalTriggerCrateConfig()->GetGlobalMask(iSide);
82 // UInt_t currMaskHpt = fCalibrationData->GlobalTriggerCrateConfig()->GetGlobalMask(2+iSide);
83 // for (Int_t iReg = 0; iReg < 8; iReg++) // 8 crates/regional boards for each side.
85 // Bool_t isActiveLpt = ( currMaskLpt >> (4*iReg) ) & 0xF;
86 // Bool_t isActiveHpt = ( currMaskHpt >> (4*iReg) ) & 0xF;
87 // if ( ! isActiveLpt && ! isActiveHpt ) continue;
88 // AliMUONTriggerCrate* cr = trigElectronics.GetCrateStore()->Crate(iSide, iReg);
89 // TObjArray *boards = cr->Boards();
91 // for ( Int_t iboard = 1; iboard < boards->GetEntries(); iboard++)
93 // TObject* currBoard = boards->At(iboard);
95 // if ( ! currBoard ) break;
96 // Int_t idx = static_cast<AliMUONLocalTriggerBoard*>(currBoard)->GetNumber()-1;
97 // if ( idx < 0 ) continue; // Some boards of crates 2 and 3 do not exist, but they are still in the board list
98 // activeBoards[idx] = 1;
99 // } // loop on boards in crate
100 // } // loop on regional
103 TArrayS xyPatternAll[2];
104 for(Int_t icath=0; icath<AliMpConstants::NofCathodes(); icath++){
105 xyPatternAll[icath].Set(AliMpConstants::NofTriggerChambers());
106 xyPatternAll[icath].Reset(0xFFFF);
109 // Create a store with all digits in trigger
110 for ( Int_t iboard=1; iboard<=AliMpConstants::NofLocalBoards(); iboard++ ) {
111 digitMaker.TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
113 // For each local board, fill all the strips and check the global output:
114 // if the board is masked at the global level, the output will be 0
115 digitStorePart.Clear();
116 digitMaker.TriggerDigits(iboard, xyPatternAll, digitStorePart, kFALSE);
117 triggerStorePart.Clear();
118 trigElectronics.Digits2Trigger(digitStorePart, triggerStorePart);
119 AliMUONGlobalTrigger* globalTrig = triggerStorePart.Global();
120 if ( globalTrig->GetGlobalResponse() > 0 ) activeBoards[iboard-1] = 1;
123 // Create trigger with electronics (it applies masks)
124 trigElectronics.Digits2Trigger(digitStore, triggerStore);
126 // Re-compute digits from triggerStore
127 // Since the masks were applied in the response,
128 // the new store do not contain masked channels
129 AliMUONDigitStoreV2R digitStoreMasked;
130 digitMaker.TriggerToDigitsStore(triggerStore, digitStoreMasked);
132 // Loop on non-masked digit store
133 // Search for digits in the masked one:
134 // if digit is not found, it means it was masked
135 TIter next(digitStore.CreateIterator());
136 AliMUONVDigit* dig = 0x0;
137 while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
138 Int_t cath = dig->Cathode();
139 Int_t detElemId = dig->DetElemId();
140 Int_t board = dig->ManuId();
141 Int_t strip = dig->ManuChannel();
142 AliMUONVDigit* currDigit = digitStoreMasked.FindObject(detElemId, board, strip, cath);
143 Int_t ich = detElemId/100-11;
144 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(cath));
145 AliMpPad pad = seg->PadByIndices(dig->PadX(), dig->PadY(), kTRUE);
146 Bool_t isMasked = ( currDigit ) ? kFALSE : kTRUE;
149 // Check if board is active
150 // For the non-bending plane the digit is created for the first board only
151 // The first board may be masked, but there may be some boards which are not.
152 // If so, the strip won't be masked, so we should keep it
153 Bool_t allBoardsMasked = kTRUE;
154 for (Int_t iloc=0; iloc<pad.GetNofLocations(); iloc++) {
155 Int_t currBoard = pad.GetLocalBoardId(iloc);
156 if ( activeBoards[currBoard-1] == 1 ) {
157 allBoardsMasked = kFALSE;
161 isMasked = allBoardsMasked;
164 if ( isMasked ) fMaskedDigitsStore->Add(*((AliMUONVDigit*)dig->Clone()), AliMUONVDigitStore::kDeny);
166 for (Int_t iloc=0; iloc<pad.GetNofLocations(); iloc++) {
167 Int_t currBoard = pad.GetLocalBoardId(iloc);
168 Int_t arrayIndex = GetArrayIndex(cath, ich, currBoard);
169 fTriggerStatusMap[arrayIndex] |= ( 0x1 << strip );
170 } // loop on locations (in bending plane we have to fill all copy boards)
174 // AliMUONTriggerCrateStore crates;
175 // crates.ReadFromFile(fCalibrationData);
177 // AliMUONRegionalTriggerConfig* regionalConfig = fCalibrationData->RegionalTriggerConfig();
178 // if ( ! regionalConfig ) AliFatal("no valid regional trigger configuration in CDB\n");
181 // AliMUONTriggerCrate* cr = 0x0;
182 // TIter next ( crates.CreateCrateIterator() );
183 // while ( ( cr = static_cast<AliMUONTriggerCrate*>(next()) ) ) {
184 // TObjArray *boards = cr->Boards();
186 // AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(cr->GetName());
188 // if ( ! crateConfig ) AliFatal(Form("Crate %s not present in configuration !!!\n", cr->GetName()));
190 // UShort_t regionalMask = crateConfig->GetMask();
193 // for (Int_t iboard = 1; iboard < boards->GetEntries(); iboard++ ) {
194 // Bool_t activeBoard = ( ( regionalMask >> ( iboard - 1) ) & 1 );
195 // AliMUONLocalTriggerBoard* board = (AliMUONLocalTriggerBoard*)boards->At(iboard);
196 // Int_t cardNumber = board->GetNumber();
197 // if ( cardNumber <= 0 ) continue; // interface board are not interested
198 // AliMUONVCalibParam* localBoardMask = fCalibrationData->LocalTriggerBoardMasks(cardNumber);
199 // for ( Int_t icath = 0; icath < 2; ++icath ) {
200 // for ( Int_t ich = 0; ich < 4; ++ich ) {
201 // Int_t planeIndex = icath * 4 + ich;
202 // Int_t localMask = ( activeBoard ) ? localBoardMask->ValueAsInt(planeIndex) : 0;
203 // Int_t arrayIndex = GetArrayIndex(icath, ich, cardNumber);
204 // fTriggerStatusMap[arrayIndex] = localMask;
205 // } // loop on chambers
206 // } // loop on planes
207 // } // loop on boards
208 // } // loop on crates
213 //_____________________________________________________________________________
214 Bool_t AliMUONTriggerUtilities::IsMasked(const AliMUONVDigit& digit) const
216 /// Check if pad is masked
217 return IsMasked(digit.DetElemId(), digit.Cathode(), digit.ManuId(), digit.ManuChannel());
221 //_____________________________________________________________________________
222 Bool_t AliMUONTriggerUtilities::IsMasked(const AliMpPad& pad, Int_t detElemId, Int_t cathode) const
224 /// Check if pad is masked
225 return IsMasked(detElemId, cathode, pad.GetLocalBoardId(0), pad.GetLocalBoardChannel(0));
229 //_____________________________________________________________________________
230 Bool_t AliMUONTriggerUtilities::IsMasked(Int_t detElemId, Int_t cathode, Int_t localCircuit, Int_t strip) const
232 /// Check if pad is masked
233 Int_t trigCh = detElemId/100 - 11;
235 // Int_t ibitxy = strip;
236 // AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(localCircuit);
237 // if ( cathode && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB) ) ibitxy += 8;
238 Int_t arrayIndex = GetArrayIndex(cathode, trigCh, localCircuit);
239 Bool_t isMasked = ( ( ( fTriggerStatusMap[arrayIndex] >> strip ) & 0x1 ) == 0 );
240 AliDebug(1,Form("detElemId %i cath %i board %i strip %i is active %i\n", detElemId, cathode, localCircuit, strip, ! isMasked));
244 //_____________________________________________________________________________
245 Bool_t AliMUONTriggerUtilities::IsMaskedBoard ( Int_t localCircuit, Int_t detElemId, Int_t cathode ) const
247 /// Check if board is masked
248 Int_t trigCh = detElemId/100-11;
249 Int_t arrayIndex = GetArrayIndex(cathode, trigCh, localCircuit);
250 return ( fTriggerStatusMap[arrayIndex] == 0 );
255 //_____________________________________________________________________________
256 Int_t AliMUONTriggerUtilities::GetArrayIndex(Int_t cathode, Int_t trigCh, Int_t localCircuit) const
258 /// Get index of array with trigger status map or efficiency
260 AliMUONConstants::NTriggerCircuit() * AliMUONConstants::NTriggerCh() * cathode +
261 AliMUONConstants::NTriggerCircuit() * trigCh + localCircuit-1;