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 "AliMUONRawStreamTrigger.h"
57 #include "AliMUONRegHeader.h"
58 #include "AliMUONTriggerCircuit.h"
59 #include "AliMpTriggerCrate.h"
60 #include "AliMpLocalBoard.h"
61 #include "AliMUONVTriggerStore.h"
62 #include "AliMpCathodType.h"
63 #include "AliMpDDLStore.h"
64 #include "AliMpDEManager.h"
66 #include "AliMpSegmentation.h"
67 #include "AliMpVSegmentation.h"
68 #include "AliRawReader.h"
72 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
75 //__________________________________________________________________________
76 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger)
79 fMakeTriggerDigits(kFALSE),
80 fRawStreamTracker(new AliMUONRawStreamTracker()),
81 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
92 // Standard Constructor
93 if (enableErrorLogger) {
94 fRawStreamTracker->EnabbleErrorLogger();
95 fRawStreamTrigger->EnabbleErrorLogger();
98 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
99 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
100 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
102 SetMakeTriggerDigits();
106 //__________________________________________________________________________
107 AliMUONDigitMaker::~AliMUONDigitMaker()
110 /// and time processing measure
112 delete fRawStreamTracker;
113 delete fRawStreamTrigger;
115 AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
116 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
117 AliDebug(1, Form(" Execution time for MUON tracker (mapping calls part) "
119 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
120 AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
121 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
125 //____________________________________________________________________
126 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
127 AliMUONVDigitStore* digitStore,
128 AliMUONVTriggerStore* triggerStore)
130 /// Main method to creates digit
134 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
135 rawReader,digitStore,triggerStore));
137 fDigitStore = digitStore;
138 fTriggerStore = triggerStore;
140 if (!fDigitStore && !fTriggerStore)
142 AliError("No digit or trigger store given. Nothing to do...");
148 fDigitStore->Clear(); // insure we start with an empty container
149 ReadTrackerDDL(rawReader);
152 if ( fTriggerStore || fMakeTriggerDigits )
154 if ( fTriggerStore ) fTriggerStore->Clear();
155 if ( fMakeTriggerDigits && !fDigitStore )
157 AliError("Asking for trigger digits but digitStore is null");
161 ReadTriggerDDL(rawReader);
168 //____________________________________________________________________
169 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
171 /// Reading tracker DDL
172 /// filling the fDigitStore container, which must not be null
176 fTrackerTimer.Start(kFALSE);
184 fRawStreamTracker->SetReader(rawReader);
185 fRawStreamTracker->First();
187 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
189 // getting DE from buspatch
190 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
192 const AliMpVSegmentation* seg
193 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
196 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
199 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
203 AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
204 detElemId, manuId, channelId));
208 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
209 AliMUONVDigitStore::kDeny);
212 AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
213 detElemId, manuId, channelId));
217 digit->SetPadXY(pad.GetIndices().GetFirst(),
218 pad.GetIndices().GetSecond());
220 digit->SetADC(charge);
224 fTrackerTimer.Stop();
229 //____________________________________________________________________
230 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
232 /// reading tracker DDL
233 /// filling the fTriggerStore container, which must not be null
237 AliMUONDDLTrigger* ddlTrigger = 0x0;
238 AliMUONDarcHeader* darcHeader = 0x0;
239 AliMUONRegHeader* regHeader = 0x0;
240 AliMUONLocalStruct* localStruct = 0x0;
244 fTriggerTimer.Start(kFALSE);
246 fRawStreamTrigger->SetReader(rawReader);
248 while (fRawStreamTrigger->NextDDL())
250 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
251 darcHeader = ddlTrigger->GetDarcHeader();
253 // fill global trigger information
256 if (darcHeader->GetGlobalFlag())
258 AliMUONGlobalTrigger globalTrigger;
259 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
260 fTriggerStore->SetGlobal(globalTrigger);
264 Int_t nReg = darcHeader->GetRegHeaderEntries();
266 for(Int_t iReg = 0; iReg < nReg ;iReg++)
271 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
272 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
275 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
278 regHeader = darcHeader->GetRegHeaderEntry(iReg);
280 Int_t nLocal = regHeader->GetLocalEntries();
281 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
284 localStruct = regHeader->GetLocalEntry(iLocal);
289 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
291 if ( !loCircuit ) continue; // empty slot
293 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
296 if( !localBoard->IsNotified())
301 // fill local trigger
302 AliMUONLocalTrigger localTrigger;
303 localTrigger.SetLocalStruct(loCircuit, *localStruct);
304 fTriggerStore->Add(localTrigger);
307 if ( fMakeTriggerDigits )
309 //FIXEME should find something better than a TArray
310 TArrayS xyPattern[2];
312 localStruct->GetXPattern(xyPattern[0]);
313 localStruct->GetYPattern(xyPattern[1]);
315 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
322 fTriggerTimer.Stop();
328 //____________________________________________________________________
329 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
331 AliMUONVDigitStore& digitStore) const
333 /// make digits for trigger from pattern, and add them to digitStore
337 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
341 // loop over x1-4 and y1-4
342 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
344 for (Int_t iCath = 0; iCath < 2; ++iCath)
346 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
347 if (!pattern) continue;
350 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
352 const AliMpVSegmentation* seg
353 = AliMpSegmentation::Instance()
354 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
356 // loop over the 16 bits of pattern
357 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
359 if ((pattern >> ibitxy) & 0x1)
361 // not quite sure about this
363 if (iCath && localBoard->GetSwitch(6)) offset = -8;
365 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
369 AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
370 detElemId, nBoard, ibitxy));
374 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
375 b = pad.GetLocation(0).GetSecond();
377 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
380 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
384 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
385 detElemId,nBoard,ibitxy,iCath));
389 Int_t padX = pad.GetIndices().GetFirst();
390 Int_t padY = pad.GetIndices().GetSecond();
393 digit->SetPadXY(padX,padY);
394 digit->SetCharge(1.);