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 ////////////////////////////////////
18 /// MUON Digit maker from rawdata in ALICE-MUON
19 /// Using new interface with AliMUONRawStreamTracker(Trigger)
20 /// (New interface of AliMUONRawReader class)
21 /// Class version 1 (further details could be found in Alice-note)
23 /// Implemented non-constant buspatch numbers for tracking
24 /// with correct DDL id (first guess)
25 /// (Ch. Finck, dec 2005)
29 /// Using real mapping for tracker
30 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
31 /// Add reader for scaler trigger events
32 /// Use memcpy instead of assignment elt by elt
33 /// (Ch. Finck, Jan 06)
35 ////////////////////////////////////
40 #include <TClonesArray.h>
42 #include "AliRawReader.h"
43 #include "AliRawDataHeader.h"
47 #include "AliMpBusPatch.h"
49 #include "AliMUONDigitMaker.h"
50 #include "AliMUONDigit.h"
52 #include "AliMUONConstants.h"
53 #include "AliMUONData.h"
55 #include "AliMUONRawStreamTracker.h"
56 #include "AliMUONDDLTracker.h"
57 #include "AliMUONDspHeader.h"
58 #include "AliMUONBlockHeader.h"
59 #include "AliMUONBusStruct.h"
61 #include "AliMUONRawStreamTrigger.h"
62 #include "AliMUONDDLTrigger.h"
63 #include "AliMUONDarcHeader.h"
64 #include "AliMUONRegHeader.h"
65 #include "AliMUONLocalStruct.h"
67 #include "AliMUONTriggerCrateStore.h"
68 #include "AliMUONTriggerCrate.h"
69 #include "AliMUONLocalTriggerBoard.h"
70 #include "AliMUONLocalTrigger.h"
71 #include "AliMUONGlobalTrigger.h"
73 #include "AliMpSegFactory.h"
74 #include "AliMpVSegmentation.h"
76 #include "AliMpDEManager.h"
78 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
79 //__________________________________________________________________________
80 AliMUONDigitMaker::AliMUONDigitMaker()
83 fSegFactory(new AliMpSegFactory()),
84 fBusPatchManager(new AliMpBusPatch()),
86 fRawStreamTracker(new AliMUONRawStreamTracker()),
87 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
88 fDigit(new AliMUONDigit()),
89 fLocalTrigger(new AliMUONLocalTrigger()),
90 fGlobalTrigger(new AliMUONGlobalTrigger()),
91 fCrateManager(new AliMUONTriggerCrateStore()),
97 // ctor with AliMUONData as argument
103 // Standard Constructor
106 fBusPatchManager->ReadBusPatchFile();
109 fCrateManager->ReadFromFile();
111 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
112 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
113 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
117 //__________________________________________________________________________
118 AliMUONDigitMaker::~AliMUONDigitMaker()
122 // and time processing measure
126 delete fRawStreamTracker;
127 delete fRawStreamTrigger;
130 delete fLocalTrigger;
131 delete fGlobalTrigger;
133 delete fCrateManager;
135 delete fBusPatchManager;
137 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
138 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
139 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
141 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
142 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
143 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
148 //____________________________________________________________________
149 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader)
151 // Main method to creates digit
156 ReadTrackerDDL(rawReader);
159 ReadTriggerDDL(rawReader);
165 //____________________________________________________________________
166 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
169 // reading tracker DDL
170 // filling the TClonesArray in MUONData
172 fTrackerTimer.Start(kFALSE);
184 AliMUONDDLTracker* ddlTracker = 0x0;
185 AliMUONBlockHeader* blkHeader = 0x0;
186 AliMUONDspHeader* dspHeader = 0x0;
187 AliMUONBusStruct* busStruct = 0x0;
190 fRawStreamTracker->SetReader(rawReader);
192 while(fRawStreamTracker->NextDDL()) {
194 ddlTracker = fRawStreamTracker->GetDDLTracker();
196 Int_t nBlock = ddlTracker->GetBlkHeaderEntries();
197 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
199 blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock);
201 Int_t nDsp = blkHeader->GetDspHeaderEntries();
203 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){ //DSP loop
205 dspHeader = blkHeader->GetDspHeaderEntry(iDsp);
207 Int_t nBusPatch = dspHeader->GetBusPatchEntries();
209 for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {
211 busStruct = dspHeader->GetBusPatchEntry(iBusPatch);
213 dataSize = busStruct->GetLength();
214 buspatchId = busStruct->GetBusPatchId();
216 for (Int_t iData = 0; iData < dataSize; iData++) {
219 parity = busStruct->GetParity(iData); // test later for parity
220 manuId = busStruct->GetManuId(iData);
221 channelId = busStruct->GetChannelId(iData);
222 charge = busStruct->GetCharge(iData);
224 fDigit->SetSignal(charge);
225 fDigit->SetPhysicsSignal(charge);
226 fDigit->SetADC(charge);
228 // Get Back the hits at pads
229 Int_t error = GetMapping(buspatchId,manuId,channelId,fDigit);
231 AliWarning("Mapping Error\n");
235 if (AliLog::GetGlobalDebugLevel() == 3) {
236 Int_t padX = fDigit->PadX();
237 Int_t padY = fDigit->PadY();
238 Int_t iCath = fDigit->Cathode();
239 Int_t idDE = fDigit->DetElemId();
241 AliDebug(1,Form("output IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n",
242 idDE, buspatchId, padX, padY, iCath));
244 AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d",
245 idDE, padX, padY, iCath, charge));
249 iChamber = fDigit->DetElemId()/100 - 1;
250 fMUONData->AddDigit(iChamber, *fDigit);
258 fTrackerTimer.Stop();
262 //____________________________________________________________________
263 Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId,
264 UChar_t channelId, AliMUONDigit* digit )
267 // mapping for tracker
269 fMappingTimer.Start(kFALSE);
271 // getting DE from buspatch
272 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
273 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
275 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
276 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
280 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
281 detElemId, busPatchId, manuId, channelId));
282 fMappingTimer.Stop();
286 // Getting padX, padY and cathode number.
287 Int_t padX = pad.GetIndices().GetFirst();
288 Int_t padY = pad.GetIndices().GetSecond();
289 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
291 // storing into digits
292 digit->SetPadX(padX);
293 digit->SetPadY(padY);
294 digit->SetCathode(iCath);
295 digit->SetDetElemId(detElemId);
296 digit->SetElectronics(manuId,channelId);
298 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
299 detElemId, busPatchId, manuId, channelId, padX, padY));
300 StdoutToAliDebug(3,digit->Print(););
302 fMappingTimer.Stop();
306 //____________________________________________________________________
307 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
309 // reading tracker DDL
310 // filling the TClonesArray in MUONData
313 AliMUONDDLTrigger* ddlTrigger = 0x0;
314 AliMUONDarcHeader* darcHeader = 0x0;
315 AliMUONRegHeader* regHeader = 0x0;
316 AliMUONLocalStruct* localStruct = 0x0;
320 fTriggerTimer.Start(kFALSE);
322 fRawStreamTrigger->SetReader(rawReader);
324 while(fRawStreamTrigger->NextDDL()) {
326 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
327 darcHeader = ddlTrigger->GetDarcHeader();
329 // fill global trigger information
330 if (darcHeader->GetGlobalFlag()) {
331 fGlobalTrigger->SetGlobalPattern(darcHeader->GetGlobalOutput());
332 fMUONData->AddGlobalTrigger(*fGlobalTrigger);
335 Int_t nReg = darcHeader->GetRegHeaderEntries();
337 for(Int_t iReg = 0; iReg < nReg ;iReg++){ //reg loop
340 AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg);
343 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
345 TObjArray *boards = crate->Boards();
348 regHeader = darcHeader->GetRegHeaderEntry(iReg);
350 Int_t nLocal = regHeader->GetLocalEntries();
352 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {
354 localStruct = regHeader->GetLocalEntry(iLocal);
356 // if card has triggered
357 if (localStruct->GetTriggerY() == 0) {
359 AliMUONLocalTriggerBoard* localBoard =
360 (AliMUONLocalTriggerBoard*)boards->At(localStruct->GetId()+1);
362 loCircuit = localBoard->GetNumber();
364 // fill local trigger
365 fLocalTrigger->SetLocalStruct(loCircuit, *localStruct);
367 fMUONData->AddLocalTrigger(*fLocalTrigger);
373 fTriggerTimer.Stop();
379 //____________________________________________________________________
380 void AliMUONDigitMaker::GetCrateName(Char_t* name, Int_t iDDL, Int_t iReg)
382 // set crate name from DDL & reg number
383 // method same as in RawWriter, not so nice
384 // should be put in AliMUONTriggerCrateStore
389 sprintf(name,"%d", iReg+1);
399 sprintf(name,"%d", iReg);
403 // crate Right for first DDL