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()
75 fMakeTriggerDigits(kFALSE),
76 fRawStreamTracker(new AliMUONRawStreamTracker()),
77 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
88 // Standard Constructor
90 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
91 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
92 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
94 SetMakeTriggerDigits();
98 //__________________________________________________________________________
99 AliMUONDigitMaker::~AliMUONDigitMaker()
102 /// and time processing measure
104 delete fRawStreamTracker;
105 delete fRawStreamTrigger;
107 AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
108 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
109 AliDebug(1, Form(" Execution time for MUON tracker (mapping calls part) "
111 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
112 AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
113 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
117 //____________________________________________________________________
118 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
119 AliMUONVDigitStore* digitStore,
120 AliMUONVTriggerStore* triggerStore)
122 /// Main method to creates digit
126 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
127 rawReader,digitStore,triggerStore));
129 fDigitStore = digitStore;
130 fTriggerStore = triggerStore;
132 if (!fDigitStore && !fTriggerStore)
134 AliError("No digit or trigger store given. Nothing to do...");
140 fDigitStore->Clear(); // insure we start with an empty container
141 ReadTrackerDDL(rawReader);
144 if ( fTriggerStore || fMakeTriggerDigits )
146 if ( fTriggerStore ) fTriggerStore->Clear();
147 if ( fMakeTriggerDigits && !fDigitStore )
149 AliError("Asking for trigger digits but digitStore is null");
153 ReadTriggerDDL(rawReader);
160 //____________________________________________________________________
161 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
163 /// Reading tracker DDL
164 /// filling the fDigitStore container, which must not be null
168 fTrackerTimer.Start(kFALSE);
176 fRawStreamTracker->SetReader(rawReader);
177 fRawStreamTracker->First();
179 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
181 // getting DE from buspatch
182 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
184 const AliMpVSegmentation* seg
185 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
188 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
191 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
195 AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
196 detElemId, manuId, channelId));
200 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
201 AliMUONVDigitStore::kDeny);
204 AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
205 detElemId, manuId, channelId));
209 digit->SetPadXY(pad.GetIndices().GetFirst(),
210 pad.GetIndices().GetSecond());
212 digit->SetADC(charge);
216 fTrackerTimer.Stop();
221 //____________________________________________________________________
222 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
224 /// reading tracker DDL
225 /// filling the fTriggerStore container, which must not be null
229 AliMUONDDLTrigger* ddlTrigger = 0x0;
230 AliMUONDarcHeader* darcHeader = 0x0;
231 AliMUONRegHeader* regHeader = 0x0;
232 AliMUONLocalStruct* localStruct = 0x0;
236 fTriggerTimer.Start(kFALSE);
238 fRawStreamTrigger->SetReader(rawReader);
240 while (fRawStreamTrigger->NextDDL())
242 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
243 darcHeader = ddlTrigger->GetDarcHeader();
245 // fill global trigger information
248 if (darcHeader->GetGlobalFlag())
250 AliMUONGlobalTrigger globalTrigger;
251 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
252 fTriggerStore->SetGlobal(globalTrigger);
256 Int_t nReg = darcHeader->GetRegHeaderEntries();
258 for(Int_t iReg = 0; iReg < nReg ;iReg++)
263 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
264 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
267 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
270 regHeader = darcHeader->GetRegHeaderEntry(iReg);
272 Int_t nLocal = regHeader->GetLocalEntries();
273 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
276 localStruct = regHeader->GetLocalEntry(iLocal);
281 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
283 if ( !loCircuit ) continue; // empty slot
285 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
288 if( !localBoard->IsNotified())
293 // fill local trigger
294 AliMUONLocalTrigger localTrigger;
295 localTrigger.SetLocalStruct(loCircuit, *localStruct);
296 fTriggerStore->Add(localTrigger);
299 if ( fMakeTriggerDigits )
301 //FIXEME should find something better than a TArray
302 TArrayS xyPattern[2];
304 localStruct->GetXPattern(xyPattern[0]);
305 localStruct->GetYPattern(xyPattern[1]);
307 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
314 fTriggerTimer.Stop();
320 //____________________________________________________________________
321 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
323 AliMUONVDigitStore& digitStore) const
325 /// make digits for trigger from pattern, and add them to digitStore
329 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
333 // loop over x1-4 and y1-4
334 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
336 for (Int_t iCath = 0; iCath < 2; ++iCath)
338 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
339 if (!pattern) continue;
342 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
344 const AliMpVSegmentation* seg
345 = AliMpSegmentation::Instance()
346 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
348 // loop over the 16 bits of pattern
349 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
351 if ((pattern >> ibitxy) & 0x1)
353 // not quite sure about this
355 if (iCath && localBoard->GetSwitch(6)) offset = -8;
357 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
361 AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
362 detElemId, nBoard, ibitxy));
366 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
367 b = pad.GetLocation(0).GetSecond();
369 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
372 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
376 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
377 detElemId,nBoard,ibitxy,iCath));
381 Int_t padX = pad.GetIndices().GetFirst();
382 Int_t padY = pad.GetIndices().GetSecond();
385 digit->SetPadXY(padX,padY);
386 digit->SetCharge(1.);