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()),
94 fRawStreamTracker = new AliMUONRawStreamTrackerHP();
96 fRawStreamTracker = new AliMUONRawStreamTracker();
98 // Standard Constructor
99 if (enableErrorLogger) {
100 fRawStreamTracker->EnabbleErrorLogger();
101 fRawStreamTrigger->EnabbleErrorLogger();
104 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
105 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
106 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
108 SetMakeTriggerDigits();
112 //__________________________________________________________________________
113 AliMUONDigitMaker::~AliMUONDigitMaker()
116 /// and time processing measure
118 delete fRawStreamTracker;
119 delete fRawStreamTrigger;
121 AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
122 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
123 AliDebug(1, Form(" Execution time for MUON tracker (mapping calls part) "
125 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
126 AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
127 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
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 AliError("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 AliError("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 fTrackerTimer.Start(kFALSE);
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,
202 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
205 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
209 AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
210 detElemId, manuId, channelId));
214 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
215 AliMUONVDigitStore::kDeny);
218 AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
219 detElemId, manuId, channelId));
223 digit->SetPadXY(pad.GetIndices().GetFirst(),
224 pad.GetIndices().GetSecond());
226 digit->SetADC(charge);
230 fTrackerTimer.Stop();
235 //____________________________________________________________________
236 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
238 /// reading tracker DDL
239 /// filling the fTriggerStore container, which must not be null
243 AliMUONDDLTrigger* ddlTrigger = 0x0;
244 AliMUONDarcHeader* darcHeader = 0x0;
245 AliMUONRegHeader* regHeader = 0x0;
246 AliMUONLocalStruct* localStruct = 0x0;
250 fTriggerTimer.Start(kFALSE);
252 fRawStreamTrigger->SetReader(rawReader);
254 while (fRawStreamTrigger->NextDDL())
256 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
257 darcHeader = ddlTrigger->GetDarcHeader();
259 // fill global trigger information
262 if (darcHeader->GetGlobalFlag())
264 AliMUONGlobalTrigger globalTrigger;
265 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
266 fTriggerStore->SetGlobal(globalTrigger);
270 Int_t nReg = darcHeader->GetRegHeaderEntries();
272 for(Int_t iReg = 0; iReg < nReg ;iReg++)
277 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
278 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
281 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
284 regHeader = darcHeader->GetRegHeaderEntry(iReg);
286 Int_t nLocal = regHeader->GetLocalEntries();
287 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
290 localStruct = regHeader->GetLocalEntry(iLocal);
295 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
297 if ( !loCircuit ) continue; // empty slot
299 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
302 if( !localBoard->IsNotified())
307 // fill local trigger
308 AliMUONLocalTrigger localTrigger;
309 localTrigger.SetLocalStruct(loCircuit, *localStruct);
310 fTriggerStore->Add(localTrigger);
313 if ( fMakeTriggerDigits )
315 //FIXEME should find something better than a TArray
316 TArrayS xyPattern[2];
318 localStruct->GetXPattern(xyPattern[0]);
319 localStruct->GetYPattern(xyPattern[1]);
321 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
328 fTriggerTimer.Stop();
334 //____________________________________________________________________
335 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
337 AliMUONVDigitStore& digitStore) const
339 /// make digits for trigger from pattern, and add them to digitStore
343 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
347 // loop over x1-4 and y1-4
348 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
350 for (Int_t iCath = 0; iCath < 2; ++iCath)
352 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
353 if (!pattern) continue;
356 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
358 const AliMpVSegmentation* seg
359 = AliMpSegmentation::Instance()
360 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
362 // loop over the 16 bits of pattern
363 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
365 if ((pattern >> ibitxy) & 0x1)
367 // not quite sure about this
369 if (iCath && localBoard->GetSwitch(6)) offset = -8;
371 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
375 AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
376 detElemId, nBoard, ibitxy));
380 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
381 b = pad.GetLocation(0).GetSecond();
383 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
386 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
390 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
391 detElemId,nBoard,ibitxy,iCath));
395 Int_t padX = pad.GetIndices().GetFirst();
396 Int_t padY = pad.GetIndices().GetSecond();
399 digit->SetPadXY(padX,padY);
400 digit->SetCharge(1.);