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 AliMUONDigitMaker
20 /// MUON Digit maker from rawdata.
23 /// Using real mapping for tracker
24 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
26 /// Implemented non-constant buspatch numbers for tracking
27 /// with correct DDL id.
28 /// (Ch. Finck, dec 05)
30 /// Add reader for scaler trigger events
31 /// Use memcpy instead of assignment elt by elt
32 /// (Ch. Finck, Jan 06)
34 /// Using new interface with AliMUONRawStreamTracker(Trigger)
35 /// (New interface of AliMUONRawReader class)
36 /// (further details could be found in Alice-note)
37 /// (Ch. Finck, March 06)
39 /// Add (S)Digit maker tracker (for free)
40 /// and for trigger. Create trigger inverse mapping.
42 /// \author Ch. Finck, oct 06
43 //-----------------------------------------------------------------------------
45 #include "AliMUONDigitMaker.h"
47 #include "AliCodeTimer.h"
49 #include "AliMUONDDLTrigger.h"
50 #include "AliMUONDarcHeader.h"
51 #include "AliMUONVDigit.h"
52 #include "AliMUONVDigitStore.h"
53 #include "AliMUONGlobalTrigger.h"
54 #include "AliMUONLocalStruct.h"
55 #include "AliMUONLocalTrigger.h"
56 #include "AliMUONLogger.h"
57 #include "AliMUONRawStreamTracker.h"
58 #include "AliMUONRawStreamTrackerHP.h"
59 #include "AliMUONRawStreamTrigger.h"
60 #include "AliMUONRegHeader.h"
61 #include "AliMUONTriggerCircuit.h"
62 #include "AliMpTriggerCrate.h"
63 #include "AliMpLocalBoard.h"
64 #include "AliMUONVTriggerStore.h"
65 #include "AliMpCathodType.h"
66 #include "AliMpDDLStore.h"
67 #include "AliMpDEManager.h"
69 #include "AliMpSegmentation.h"
70 #include "AliMpVSegmentation.h"
71 #include "AliRawReader.h"
75 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
78 //__________________________________________________________________________
79 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t useFastDecoder)
82 fMakeTriggerDigits(kFALSE),
83 fRawStreamTracker(NULL),
84 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
87 fLogger(new AliMUONLogger(10000))
93 CreateRawStreamTracker(useFastDecoder);
95 // Standard Constructor
96 if (enableErrorLogger) {
97 fRawStreamTracker->EnabbleErrorLogger();
98 fRawStreamTrigger->EnabbleErrorLogger();
101 SetMakeTriggerDigits();
105 //__________________________________________________________________________
106 AliMUONDigitMaker::~AliMUONDigitMaker()
109 /// and time processing measure
111 delete fRawStreamTracker;
112 delete fRawStreamTrigger;
117 //__________________________________________________________________________
118 void AliMUONDigitMaker::CreateRawStreamTracker(Bool_t useFastDecoder)
120 /// Create raw stream tracker according to the passed option
124 AliInfo("Using fast decoder.");
125 fRawStreamTracker = new AliMUONRawStreamTrackerHP();
128 fRawStreamTracker = new AliMUONRawStreamTracker();
131 //____________________________________________________________________
132 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
133 AliMUONVDigitStore* digitStore,
134 AliMUONVTriggerStore* triggerStore)
136 /// Main method to creates digit
140 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
141 rawReader,digitStore,triggerStore));
143 fDigitStore = digitStore;
144 fTriggerStore = triggerStore;
146 if (!fDigitStore && !fTriggerStore)
148 fLogger->Log("No digit or trigger store given. Nothing to do...");
154 fDigitStore->Clear(); // insure we start with an empty container
155 ReadTrackerDDL(rawReader);
158 if ( fTriggerStore || fMakeTriggerDigits )
160 if ( fTriggerStore ) fTriggerStore->Clear();
161 if ( fMakeTriggerDigits && !fDigitStore )
163 fLogger->Log("Asking for trigger digits but digitStore is null");
167 ReadTriggerDDL(rawReader);
174 //____________________________________________________________________
175 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
177 /// Reading tracker DDL
178 /// filling the fDigitStore container, which must not be null
182 AliCodeTimerAuto("");
190 fRawStreamTracker->SetReader(rawReader);
191 fRawStreamTracker->First();
193 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
195 // getting DE from buspatch
196 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
198 const AliMpVSegmentation* seg
199 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
204 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
208 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
211 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
215 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
216 detElemId, manuId, channelId));
220 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
221 AliMUONVDigitStore::kDeny);
224 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
225 detElemId, manuId, channelId));
229 digit->SetPadXY(pad.GetIndices().GetFirst(),
230 pad.GetIndices().GetSecond());
232 digit->SetADC(charge);
239 //____________________________________________________________________
240 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
242 /// reading tracker DDL
243 /// filling the fTriggerStore container, which must not be null
247 AliMUONDDLTrigger* ddlTrigger = 0x0;
248 AliMUONDarcHeader* darcHeader = 0x0;
249 AliMUONRegHeader* regHeader = 0x0;
250 AliMUONLocalStruct* localStruct = 0x0;
254 AliCodeTimerAuto("");
256 fRawStreamTrigger->SetReader(rawReader);
258 while (fRawStreamTrigger->NextDDL())
260 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
261 darcHeader = ddlTrigger->GetDarcHeader();
263 // fill global trigger information
266 if (darcHeader->GetGlobalFlag())
268 AliMUONGlobalTrigger globalTrigger;
269 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
270 fTriggerStore->SetGlobal(globalTrigger);
274 Int_t nReg = darcHeader->GetRegHeaderEntries();
276 for(Int_t iReg = 0; iReg < nReg ;iReg++)
281 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
282 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
285 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
288 regHeader = darcHeader->GetRegHeaderEntry(iReg);
290 Int_t nLocal = regHeader->GetLocalEntries();
291 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
294 localStruct = regHeader->GetLocalEntry(iLocal);
299 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
301 if ( !loCircuit ) continue; // empty slot
303 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
306 if( !localBoard->IsNotified())
311 // fill local trigger
312 AliMUONLocalTrigger localTrigger;
313 localTrigger.SetLocalStruct(loCircuit, *localStruct);
314 fTriggerStore->Add(localTrigger);
317 if ( fMakeTriggerDigits )
319 //FIXEME should find something better than a TArray
320 TArrayS xyPattern[2];
322 localStruct->GetXPattern(xyPattern[0]);
323 localStruct->GetYPattern(xyPattern[1]);
325 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
336 //____________________________________________________________________
337 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
339 AliMUONVDigitStore& digitStore) const
341 /// make digits for trigger from pattern, and add them to digitStore
343 AliCodeTimerAuto("");
347 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
351 // loop over x1-4 and y1-4
352 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
354 for (Int_t iCath = 0; iCath < 2; ++iCath)
356 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
357 if (!pattern) continue;
360 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
362 const AliMpVSegmentation* seg
363 = AliMpSegmentation::Instance()
364 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
366 // loop over the 16 bits of pattern
367 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
369 if ((pattern >> ibitxy) & 0x1)
371 // not quite sure about this
373 if (iCath && localBoard->GetSwitch(6)) offset = -8;
375 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
379 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
380 detElemId, nBoard, ibitxy));
384 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
385 b = pad.GetLocation(0).GetSecond();
387 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
390 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
394 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
395 detElemId,nBoard,ibitxy,iCath));
399 Int_t padX = pad.GetIndices().GetFirst();
400 Int_t padY = pad.GetIndices().GetSecond();
403 digit->SetPadXY(padX,padY);
404 digit->SetCharge(1.);
413 //____________________________________________________________________
414 void AliMUONDigitMaker::SetFastDecoder(Bool_t useFastDecoder)
416 /// Set fast raw data decoder
418 delete fRawStreamTracker;
419 CreateRawStreamTracker(useFastDecoder);