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"
48 #include "AliMUONDDLTrigger.h"
49 #include "AliMUONDarcHeader.h"
50 #include "AliMUONVDigit.h"
51 #include "AliMUONVDigitStore.h"
52 #include "AliMUONGlobalTrigger.h"
53 #include "AliMUONLocalStruct.h"
54 #include "AliMUONLocalTrigger.h"
55 #include "AliMUONRawStreamTracker.h"
56 #include "AliMUONRawStreamTrackerHP.h"
57 #include "AliMUONRawStreamTrigger.h"
58 #include "AliMUONRegHeader.h"
59 #include "AliMUONTriggerCircuit.h"
60 #include "AliMpTriggerCrate.h"
61 #include "AliMpLocalBoard.h"
62 #include "AliMUONVTriggerStore.h"
63 #include "AliMpCathodType.h"
64 #include "AliMpDDLStore.h"
65 #include "AliMpDEManager.h"
67 #include "AliMpSegmentation.h"
68 #include "AliMpVSegmentation.h"
69 #include "AliRawReader.h"
73 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
76 //__________________________________________________________________________
77 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t useFastDecoder)
80 fMakeTriggerDigits(kFALSE),
81 fRawStreamTracker(NULL),
82 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
93 CreateRawStreamTracker(useFastDecoder);
95 // Standard Constructor
96 if (enableErrorLogger) {
97 fRawStreamTracker->EnabbleErrorLogger();
98 fRawStreamTrigger->EnabbleErrorLogger();
101 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
102 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
103 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
105 SetMakeTriggerDigits();
109 //__________________________________________________________________________
110 AliMUONDigitMaker::~AliMUONDigitMaker()
113 /// and time processing measure
115 delete fRawStreamTracker;
116 delete fRawStreamTrigger;
118 AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
119 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
120 AliDebug(1, Form(" Execution time for MUON tracker (mapping calls part) "
122 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
123 AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
124 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
128 //__________________________________________________________________________
129 void AliMUONDigitMaker::CreateRawStreamTracker(Bool_t useFastDecoder)
131 /// Create raw stream tracker according to the passed option
135 AliInfo("Using fast decoder.");
136 fRawStreamTracker = new AliMUONRawStreamTrackerHP();
139 fRawStreamTracker = new AliMUONRawStreamTracker();
142 //____________________________________________________________________
143 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
144 AliMUONVDigitStore* digitStore,
145 AliMUONVTriggerStore* triggerStore)
147 /// Main method to creates digit
151 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
152 rawReader,digitStore,triggerStore));
154 fDigitStore = digitStore;
155 fTriggerStore = triggerStore;
157 if (!fDigitStore && !fTriggerStore)
159 AliError("No digit or trigger store given. Nothing to do...");
165 fDigitStore->Clear(); // insure we start with an empty container
166 ReadTrackerDDL(rawReader);
169 if ( fTriggerStore || fMakeTriggerDigits )
171 if ( fTriggerStore ) fTriggerStore->Clear();
172 if ( fMakeTriggerDigits && !fDigitStore )
174 AliError("Asking for trigger digits but digitStore is null");
178 ReadTriggerDDL(rawReader);
185 //____________________________________________________________________
186 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
188 /// Reading tracker DDL
189 /// filling the fDigitStore container, which must not be null
193 fTrackerTimer.Start(kFALSE);
201 fRawStreamTracker->SetReader(rawReader);
202 fRawStreamTracker->First();
204 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
206 // getting DE from buspatch
207 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
209 const AliMpVSegmentation* seg
210 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
213 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
216 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
220 AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
221 detElemId, manuId, channelId));
225 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
226 AliMUONVDigitStore::kDeny);
229 AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
230 detElemId, manuId, channelId));
234 digit->SetPadXY(pad.GetIndices().GetFirst(),
235 pad.GetIndices().GetSecond());
237 digit->SetADC(charge);
241 fTrackerTimer.Stop();
246 //____________________________________________________________________
247 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
249 /// reading tracker DDL
250 /// filling the fTriggerStore container, which must not be null
254 AliMUONDDLTrigger* ddlTrigger = 0x0;
255 AliMUONDarcHeader* darcHeader = 0x0;
256 AliMUONRegHeader* regHeader = 0x0;
257 AliMUONLocalStruct* localStruct = 0x0;
261 fTriggerTimer.Start(kFALSE);
263 fRawStreamTrigger->SetReader(rawReader);
265 while (fRawStreamTrigger->NextDDL())
267 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
268 darcHeader = ddlTrigger->GetDarcHeader();
270 // fill global trigger information
273 if (darcHeader->GetGlobalFlag())
275 AliMUONGlobalTrigger globalTrigger;
276 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
277 fTriggerStore->SetGlobal(globalTrigger);
281 Int_t nReg = darcHeader->GetRegHeaderEntries();
283 for(Int_t iReg = 0; iReg < nReg ;iReg++)
288 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
289 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
292 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
295 regHeader = darcHeader->GetRegHeaderEntry(iReg);
297 Int_t nLocal = regHeader->GetLocalEntries();
298 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
301 localStruct = regHeader->GetLocalEntry(iLocal);
306 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
308 if ( !loCircuit ) continue; // empty slot
310 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
313 if( !localBoard->IsNotified())
318 // fill local trigger
319 AliMUONLocalTrigger localTrigger;
320 localTrigger.SetLocalStruct(loCircuit, *localStruct);
321 fTriggerStore->Add(localTrigger);
324 if ( fMakeTriggerDigits )
326 //FIXEME should find something better than a TArray
327 TArrayS xyPattern[2];
329 localStruct->GetXPattern(xyPattern[0]);
330 localStruct->GetYPattern(xyPattern[1]);
332 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
339 fTriggerTimer.Stop();
345 //____________________________________________________________________
346 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
348 AliMUONVDigitStore& digitStore) const
350 /// make digits for trigger from pattern, and add them to digitStore
354 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
358 // loop over x1-4 and y1-4
359 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
361 for (Int_t iCath = 0; iCath < 2; ++iCath)
363 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
364 if (!pattern) continue;
367 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
369 const AliMpVSegmentation* seg
370 = AliMpSegmentation::Instance()
371 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
373 // loop over the 16 bits of pattern
374 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
376 if ((pattern >> ibitxy) & 0x1)
378 // not quite sure about this
380 if (iCath && localBoard->GetSwitch(6)) offset = -8;
382 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
386 AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
387 detElemId, nBoard, ibitxy));
391 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
392 b = pad.GetLocation(0).GetSecond();
394 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
397 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
401 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
402 detElemId,nBoard,ibitxy,iCath));
406 Int_t padX = pad.GetIndices().GetFirst();
407 Int_t padY = pad.GetIndices().GetSecond();
410 digit->SetPadXY(padX,padY);
411 digit->SetCharge(1.);
420 //____________________________________________________________________
421 void AliMUONDigitMaker::SetFastDecoder(Bool_t useFastDecoder)
423 /// Set fast raw data decoder
425 delete fRawStreamTracker;
426 CreateRawStreamTracker(useFastDecoder);