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 **************************************************************************/
16 /// \class AliMUONDigitMaker
17 /// MUON Digit maker from rawdata.
20 /// Using real mapping for tracker
21 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
23 /// Implemented non-constant buspatch numbers for tracking
24 /// with correct DDL id.
25 /// (Ch. Finck, dec 05)
27 /// Add reader for scaler trigger events
28 /// Use memcpy instead of assignment elt by elt
29 /// (Ch. Finck, Jan 06)
31 /// Using new interface with AliMUONRawStreamTracker(Trigger)
32 /// (New interface of AliMUONRawReader class)
33 /// (further details could be found in Alice-note)
34 /// (Ch. Finck, March 06)
36 /// Add (S)Digit maker tracker (for free)
37 /// and for trigger. Create trigger inverse mapping.
39 /// \author Ch. Finck, oct 06
41 #include "AliMUONDigitMaker.h"
44 #include "AliMUONDDLTrigger.h"
45 #include "AliMUONDarcHeader.h"
46 #include "AliMUONVDigit.h"
47 #include "AliMUONVDigitStore.h"
48 #include "AliMUONGlobalTrigger.h"
49 #include "AliMUONLocalStruct.h"
50 #include "AliMUONLocalTrigger.h"
51 #include "AliMUONRawStreamTracker.h"
52 #include "AliMUONRawStreamTrigger.h"
53 #include "AliMUONRegHeader.h"
54 #include "AliMUONTriggerCircuit.h"
55 #include "AliMpTriggerCrate.h"
56 #include "AliMpLocalBoard.h"
57 #include "AliMUONVTriggerStore.h"
58 #include "AliMpCathodType.h"
59 #include "AliMpDDLStore.h"
60 #include "AliMpDEManager.h"
62 #include "AliMpSegmentation.h"
63 #include "AliMpVSegmentation.h"
64 #include "AliRawReader.h"
68 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
71 //__________________________________________________________________________
72 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger)
75 fMakeTriggerDigits(kFALSE),
76 fRawStreamTracker(new AliMUONRawStreamTracker()),
77 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
88 // Standard Constructor
89 if (enableErrorLogger) {
90 fRawStreamTracker->EnabbleErrorLogger();
91 fRawStreamTrigger->EnabbleErrorLogger();
94 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
95 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
96 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
98 SetMakeTriggerDigits();
102 //__________________________________________________________________________
103 AliMUONDigitMaker::~AliMUONDigitMaker()
106 /// and time processing measure
108 delete fRawStreamTracker;
109 delete fRawStreamTrigger;
111 AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
112 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
113 AliDebug(1, Form(" Execution time for MUON tracker (mapping calls part) "
115 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
116 AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
117 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
121 //____________________________________________________________________
122 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
123 AliMUONVDigitStore* digitStore,
124 AliMUONVTriggerStore* triggerStore)
126 /// Main method to creates digit
130 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
131 rawReader,digitStore,triggerStore));
133 fDigitStore = digitStore;
134 fTriggerStore = triggerStore;
136 if (!fDigitStore && !fTriggerStore)
138 AliError("No digit or trigger store given. Nothing to do...");
144 fDigitStore->Clear(); // insure we start with an empty container
145 ReadTrackerDDL(rawReader);
148 if ( fTriggerStore || fMakeTriggerDigits )
150 if ( fTriggerStore ) fTriggerStore->Clear();
151 if ( fMakeTriggerDigits && !fDigitStore )
153 AliError("Asking for trigger digits but digitStore is null");
157 ReadTriggerDDL(rawReader);
164 //____________________________________________________________________
165 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
167 /// Reading tracker DDL
168 /// filling the fDigitStore container, which must not be null
172 fTrackerTimer.Start(kFALSE);
180 fRawStreamTracker->SetReader(rawReader);
181 fRawStreamTracker->First();
183 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
185 // getting DE from buspatch
186 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
188 const AliMpVSegmentation* seg
189 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
192 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
195 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
199 AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
200 detElemId, manuId, channelId));
204 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
205 AliMUONVDigitStore::kDeny);
208 AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
209 detElemId, manuId, channelId));
213 digit->SetPadXY(pad.GetIndices().GetFirst(),
214 pad.GetIndices().GetSecond());
216 digit->SetADC(charge);
220 fTrackerTimer.Stop();
225 //____________________________________________________________________
226 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
228 /// reading tracker DDL
229 /// filling the fTriggerStore container, which must not be null
233 AliMUONDDLTrigger* ddlTrigger = 0x0;
234 AliMUONDarcHeader* darcHeader = 0x0;
235 AliMUONRegHeader* regHeader = 0x0;
236 AliMUONLocalStruct* localStruct = 0x0;
240 fTriggerTimer.Start(kFALSE);
242 fRawStreamTrigger->SetReader(rawReader);
244 while (fRawStreamTrigger->NextDDL())
246 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
247 darcHeader = ddlTrigger->GetDarcHeader();
249 // fill global trigger information
252 if (darcHeader->GetGlobalFlag())
254 AliMUONGlobalTrigger globalTrigger;
255 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
256 fTriggerStore->SetGlobal(globalTrigger);
260 Int_t nReg = darcHeader->GetRegHeaderEntries();
262 for(Int_t iReg = 0; iReg < nReg ;iReg++)
267 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
268 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
271 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
274 regHeader = darcHeader->GetRegHeaderEntry(iReg);
276 Int_t nLocal = regHeader->GetLocalEntries();
277 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
280 localStruct = regHeader->GetLocalEntry(iLocal);
285 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
287 if ( !loCircuit ) continue; // empty slot
289 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
292 if( !localBoard->IsNotified())
297 // fill local trigger
298 AliMUONLocalTrigger localTrigger;
299 localTrigger.SetLocalStruct(loCircuit, *localStruct);
300 fTriggerStore->Add(localTrigger);
303 if ( fMakeTriggerDigits )
305 //FIXEME should find something better than a TArray
306 TArrayS xyPattern[2];
308 localStruct->GetXPattern(xyPattern[0]);
309 localStruct->GetYPattern(xyPattern[1]);
311 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
318 fTriggerTimer.Stop();
324 //____________________________________________________________________
325 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
327 AliMUONVDigitStore& digitStore) const
329 /// make digits for trigger from pattern, and add them to digitStore
333 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
337 // loop over x1-4 and y1-4
338 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
340 for (Int_t iCath = 0; iCath < 2; ++iCath)
342 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
343 if (!pattern) continue;
346 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
348 const AliMpVSegmentation* seg
349 = AliMpSegmentation::Instance()
350 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
352 // loop over the 16 bits of pattern
353 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
355 if ((pattern >> ibitxy) & 0x1)
357 // not quite sure about this
359 if (iCath && localBoard->GetSwitch(6)) offset = -8;
361 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
365 AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
366 detElemId, nBoard, ibitxy));
370 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
371 b = pad.GetLocation(0).GetSecond();
373 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
376 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
380 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
381 detElemId,nBoard,ibitxy,iCath));
385 Int_t padX = pad.GetIndices().GetFirst();
386 Int_t padY = pad.GetIndices().GetSecond();
389 digit->SetPadXY(padX,padY);
390 digit->SetCharge(1.);