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(Bool_t flag)
83 fSegFactory(new AliMpSegFactory()),
84 fBusPatchManager(new AliMpBusPatch()),
87 fRawStreamTracker(new AliMUONRawStreamTracker()),
88 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
89 fDigit(new AliMUONDigit()),
90 fLocalTrigger(new AliMUONLocalTrigger()),
91 fGlobalTrigger(new AliMUONGlobalTrigger()),
92 fCrateManager(new AliMUONTriggerCrateStore()),
98 // ctor with AliMUONData as argument
104 // Standard Constructor
107 fBusPatchManager->ReadBusPatchFile();
110 fCrateManager->ReadFromFile();
112 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
113 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
114 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
118 //__________________________________________________________________________
119 AliMUONDigitMaker::~AliMUONDigitMaker()
123 // and time processing measure
127 delete fRawStreamTracker;
128 delete fRawStreamTrigger;
131 delete fLocalTrigger;
132 delete fGlobalTrigger;
134 delete fCrateManager;
136 delete fBusPatchManager;
138 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
139 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
140 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
142 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
143 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
144 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
149 //____________________________________________________________________
150 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader)
152 // Main method to creates digit
157 ReadTrackerDDL(rawReader);
161 ReadTriggerDDL(rawReader);
167 //____________________________________________________________________
168 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
171 // reading tracker DDL
172 // filling the TClonesArray in MUONData
174 fTrackerTimer.Start(kFALSE);
186 AliMUONDDLTracker* ddlTracker = 0x0;
187 AliMUONBlockHeader* blkHeader = 0x0;
188 AliMUONDspHeader* dspHeader = 0x0;
189 AliMUONBusStruct* busStruct = 0x0;
192 fRawStreamTracker->SetReader(rawReader);
194 while(fRawStreamTracker->NextDDL()) {
196 ddlTracker = fRawStreamTracker->GetDDLTracker();
198 Int_t nBlock = ddlTracker->GetBlkHeaderEntries();
199 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
201 blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock);
203 Int_t nDsp = blkHeader->GetDspHeaderEntries();
205 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){ //DSP loop
207 dspHeader = blkHeader->GetDspHeaderEntry(iDsp);
209 Int_t nBusPatch = dspHeader->GetBusPatchEntries();
211 for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {
213 busStruct = dspHeader->GetBusPatchEntry(iBusPatch);
215 dataSize = busStruct->GetLength();
216 buspatchId = busStruct->GetBusPatchId();
218 for (Int_t iData = 0; iData < dataSize; iData++) {
221 parity = busStruct->GetParity(iData); // test later for parity
222 manuId = busStruct->GetManuId(iData);
223 channelId = busStruct->GetChannelId(iData);
224 charge = busStruct->GetCharge(iData);
226 fDigit->SetSignal(charge);
227 fDigit->SetPhysicsSignal(charge);
228 fDigit->SetADC(charge);
230 // Get Back the hits at pads
231 Int_t error = GetMapping(buspatchId,manuId,channelId,fDigit);
233 AliWarning("Mapping Error\n");
237 if (AliLog::GetGlobalDebugLevel() == 3) {
238 Int_t padX = fDigit->PadX();
239 Int_t padY = fDigit->PadY();
240 Int_t iCath = fDigit->Cathode();
241 Int_t idDE = fDigit->DetElemId();
243 AliDebug(1,Form("output IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n",
244 idDE, buspatchId, padX, padY, iCath));
246 AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d",
247 idDE, padX, padY, iCath, charge));
251 iChamber = fDigit->DetElemId()/100 - 1;
254 fMUONData->AddDigit(iChamber, *fDigit);
256 fMUONData->AddSDigit(iChamber, *fDigit);
265 fTrackerTimer.Stop();
269 //____________________________________________________________________
270 Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId,
271 UChar_t channelId, AliMUONDigit* digit )
274 // mapping for tracker
276 fMappingTimer.Start(kFALSE);
278 // getting DE from buspatch
279 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
280 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
282 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
283 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
287 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
288 detElemId, busPatchId, manuId, channelId));
289 fMappingTimer.Stop();
293 // Getting padX, padY and cathode number.
294 Int_t padX = pad.GetIndices().GetFirst();
295 Int_t padY = pad.GetIndices().GetSecond();
296 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
298 // storing into digits
299 digit->SetPadX(padX);
300 digit->SetPadY(padY);
301 digit->SetCathode(iCath);
302 digit->SetDetElemId(detElemId);
303 digit->SetElectronics(manuId,channelId);
305 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
306 detElemId, busPatchId, manuId, channelId, padX, padY));
307 StdoutToAliDebug(3,digit->Print(););
309 fMappingTimer.Stop();
313 //____________________________________________________________________
314 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
316 // reading tracker DDL
317 // filling the TClonesArray in MUONData
320 AliMUONDDLTrigger* ddlTrigger = 0x0;
321 AliMUONDarcHeader* darcHeader = 0x0;
322 AliMUONRegHeader* regHeader = 0x0;
323 AliMUONLocalStruct* localStruct = 0x0;
327 fTriggerTimer.Start(kFALSE);
329 fRawStreamTrigger->SetReader(rawReader);
331 while(fRawStreamTrigger->NextDDL()) {
333 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
334 darcHeader = ddlTrigger->GetDarcHeader();
336 // fill global trigger information
337 if (darcHeader->GetGlobalFlag()) {
338 fGlobalTrigger->SetFromGlobalResponse(darcHeader->GetGlobalOutput());
339 fMUONData->AddGlobalTrigger(*fGlobalTrigger);
342 Int_t nReg = darcHeader->GetRegHeaderEntries();
344 for(Int_t iReg = 0; iReg < nReg ;iReg++){ //reg loop
347 AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg);
350 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
352 TObjArray *boards = crate->Boards();
355 regHeader = darcHeader->GetRegHeaderEntry(iReg);
357 Int_t nLocal = regHeader->GetLocalEntries();
359 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {
361 localStruct = regHeader->GetLocalEntry(iLocal);
363 // if card has triggered
364 if (localStruct->GetTriggerY() == 0) {
366 AliMUONLocalTriggerBoard* localBoard =
367 (AliMUONLocalTriggerBoard*)boards->At(localStruct->GetId()+1);
369 loCircuit = localBoard->GetNumber();
371 // fill local trigger
372 fLocalTrigger->SetLocalStruct(loCircuit, *localStruct);
374 fMUONData->AddLocalTrigger(*fLocalTrigger);
380 fTriggerTimer.Stop();
386 //____________________________________________________________________
387 void AliMUONDigitMaker::GetCrateName(Char_t* name, Int_t iDDL, Int_t iReg)
389 // set crate name from DDL & reg number
390 // method same as in RawWriter, not so nice
391 // should be put in AliMUONTriggerCrateStore
396 sprintf(name,"%d", iReg+1);
406 sprintf(name,"%d", iReg);
410 // crate Right for first DDL