Remove obsolete class AliTPCclusterLMI (Marian)
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitMaker.cxx
... / ...
CommitLineData
1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16////////////////////////////////////
17///
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)
22///
23/// Implemented non-constant buspatch numbers for tracking
24/// with correct DDL id (first guess)
25/// (Ch. Finck, dec 2005)
26///
27///
28/// Raw2Digits:
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)
34///
35////////////////////////////////////
36
37#include <fstream>
38#include <string>
39
40#include <TClonesArray.h>
41
42#include "AliRawReader.h"
43#include "AliRawDataHeader.h"
44#include "AliLog.h"
45#include "AliRun.h"
46
47#include "AliMpBusPatch.h"
48#include "AliMUON.h"
49#include "AliMUONDigitMaker.h"
50#include "AliMUONDigit.h"
51
52#include "AliMUONConstants.h"
53#include "AliMUONData.h"
54
55#include "AliMUONRawStreamTracker.h"
56#include "AliMUONDDLTracker.h"
57#include "AliMUONDspHeader.h"
58#include "AliMUONBlockHeader.h"
59#include "AliMUONBusStruct.h"
60
61#include "AliMUONRawStreamTrigger.h"
62#include "AliMUONDDLTrigger.h"
63#include "AliMUONDarcHeader.h"
64#include "AliMUONRegHeader.h"
65#include "AliMUONLocalStruct.h"
66
67#include "AliMUONLocalTrigger.h"
68#include "AliMUONGlobalTrigger.h"
69
70#include "AliMpSegFactory.h"
71#include "AliMpVSegmentation.h"
72#include "AliMpPad.h"
73#include "AliMpDEManager.h"
74
75ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
76//__________________________________________________________________________
77AliMUONDigitMaker::AliMUONDigitMaker(AliMUONData* data)
78 : TObject(),
79 fMUONData(data),
80 fSegFactory(new AliMpSegFactory()),
81 fBusPatchManager(new AliMpBusPatch()),
82 fScalerEvent(kFALSE),
83 fRawStreamTracker(new AliMUONRawStreamTracker()),
84 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
85 fDigit(new AliMUONDigit()),
86 fLocalTrigger(new AliMUONLocalTrigger()),
87 fGlobalTrigger(new AliMUONGlobalTrigger()),
88 fTrackerTimer(),
89 fTriggerTimer(),
90 fMappingTimer()
91{
92 //
93 // ctor with AliMUONData as argument
94 // for reconstruction
95 //
96
97 AliDebug(1,"");
98
99 // Standard Constructor
100
101 // bus patch
102 fBusPatchManager->ReadBusPatchFile();
103
104
105 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
106 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
107 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
108
109}
110
111//__________________________________________________________________________
112AliMUONDigitMaker::AliMUONDigitMaker()
113 : TObject(),
114 fMUONData(0),
115 fSegFactory(0),
116 fBusPatchManager(0),
117 fScalerEvent(kFALSE),
118 fRawStreamTracker(0),
119 fRawStreamTrigger(0),
120 fDigit(0),
121 fLocalTrigger(0),
122 fGlobalTrigger(0),
123 fTrackerTimer(),
124 fTriggerTimer(),
125 fMappingTimer()
126{
127 //
128 // Default Constructor
129 //
130 AliDebug(1,"");
131 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
132 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
133 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
134
135}
136
137//__________________________________________________________________________
138AliMUONDigitMaker::~AliMUONDigitMaker()
139{
140 //
141 // clean up
142 // and time processing measure
143 //
144 delete fSegFactory;
145
146 delete fRawStreamTracker;
147 delete fRawStreamTrigger;
148
149 delete fDigit;
150 delete fLocalTrigger;
151 delete fGlobalTrigger;
152
153 delete fBusPatchManager;
154
155 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
156 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
157 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
158 ": R:%.2fs C:%.2fs",
159 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
160 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
161 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
162
163 return;
164}
165
166//____________________________________________________________________
167Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader)
168{
169 // Main method to creates digit
170 // for tracker
171 // and trigger
172
173 // generate digits
174 ReadTrackerDDL(rawReader);
175
176 // generate trigger
177 ReadTriggerDDL(rawReader);
178
179 return kTRUE;
180
181}
182
183//____________________________________________________________________
184Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
185{
186
187 // reading tracker DDL
188 // filling the TClonesArray in MUONData
189 //
190 fTrackerTimer.Start(kFALSE);
191
192 // elex info
193 Int_t buspatchId;
194 UChar_t channelId;
195 UShort_t manuId;
196 Char_t parity;
197 UShort_t charge;
198 Int_t dataSize;
199
200 Int_t iChamber;
201
202 AliMUONDDLTracker* ddlTracker = 0x0;
203 AliMUONBlockHeader* blkHeader = 0x0;
204 AliMUONDspHeader* dspHeader = 0x0;
205 AliMUONBusStruct* busStruct = 0x0;
206
207
208 fRawStreamTracker->SetReader(rawReader);
209
210 while(fRawStreamTracker->NextDDL()) {
211
212 ddlTracker = fRawStreamTracker->GetDDLTracker();
213
214 Int_t nBlock = ddlTracker->GetBlkHeaderEntries();
215 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
216
217 blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock);
218
219 Int_t nDsp = blkHeader->GetDspHeaderEntries();
220
221 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){ //DSP loop
222
223 dspHeader = blkHeader->GetDspHeaderEntry(iDsp);
224
225 Int_t nBusPatch = dspHeader->GetBusPatchEntries();
226
227 for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {
228
229 busStruct = dspHeader->GetBusPatchEntry(iBusPatch);
230
231 dataSize = busStruct->GetLength();
232 buspatchId = busStruct->GetBusPatchId();
233
234 for (Int_t iData = 0; iData < dataSize; iData++) {
235
236 // digits info
237 parity = busStruct->GetParity(iData); // test later for parity
238 manuId = busStruct->GetManuId(iData);
239 channelId = busStruct->GetChannelId(iData);
240 charge = busStruct->GetCharge(iData);
241 // set charge
242 fDigit->SetSignal(charge);
243 fDigit->SetPhysicsSignal(charge);
244 fDigit->SetADC(charge);
245
246 // Get Back the hits at pads
247 Int_t error = GetMapping(buspatchId,manuId,channelId,fDigit);
248 if (error) {
249 AliWarning("Mapping Error\n");
250 continue;
251 }
252 // debugging
253 if (AliLog::GetGlobalDebugLevel() == 3) {
254 Int_t padX = fDigit->PadX();
255 Int_t padY = fDigit->PadY();
256 Int_t iCath = fDigit->Cathode();
257 Int_t idDE = fDigit->DetElemId();
258
259 AliDebug(1,Form("output IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n",
260 idDE, buspatchId, padX, padY, iCath));
261
262 AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d",
263 idDE, padX, padY, iCath, charge));
264 }
265
266 // fill digits
267 iChamber = fDigit->DetElemId()/100 - 1;
268 fMUONData->AddDigit(iChamber, *fDigit);
269
270 } // iData
271 } // iBusPatch
272 } // iDsp
273 } // iBlock
274 } // NextDDL
275
276 fTrackerTimer.Stop();
277
278 return kTRUE;
279}
280//____________________________________________________________________
281Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId,
282 UChar_t channelId, AliMUONDigit* digit )
283{
284 //
285 // mapping for tracker
286 //
287 fMappingTimer.Start(kFALSE);
288
289 // getting DE from buspatch
290 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
291 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
292
293 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
294 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
295
296 if (!pad.IsValid())
297 {
298 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
299 detElemId, busPatchId, manuId, channelId));
300 fMappingTimer.Stop();
301 return kTRUE;
302 } // return error
303
304 // Getting padX, padY and cathode number.
305 Int_t padX = pad.GetIndices().GetFirst();
306 Int_t padY = pad.GetIndices().GetSecond();
307 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
308
309 // storing into digits
310 digit->SetPadX(padX);
311 digit->SetPadY(padY);
312 digit->SetCathode(iCath);
313 digit->SetDetElemId(detElemId);
314 digit->SetElectronics(manuId,channelId);
315
316 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
317 detElemId, busPatchId, manuId, channelId, padX, padY));
318 StdoutToAliDebug(3,digit->Print(););
319
320 fMappingTimer.Stop();
321 return kFALSE;
322}
323
324//____________________________________________________________________
325Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
326{
327 // reading tracker DDL
328 // filling the TClonesArray in MUONData
329 //
330
331 AliMUONDDLTrigger* ddlTrigger = 0x0;
332 AliMUONDarcHeader* darcHeader = 0x0;
333 AliMUONRegHeader* regHeader = 0x0;
334 AliMUONLocalStruct* localStruct = 0x0;
335
336 Int_t loCircuit;
337
338 fTriggerTimer.Start(kFALSE);
339
340 fRawStreamTrigger->SetReader(rawReader);
341
342 while(fRawStreamTrigger->NextDDL()) {
343
344 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
345 darcHeader = ddlTrigger->GetDarcHeader();
346
347 // fill global trigger information
348 if (darcHeader->GetGlobalFlag()) {
349 fGlobalTrigger->SetGlobalPattern(darcHeader->GetGlobalOutput());
350 fMUONData->AddGlobalTrigger(*fGlobalTrigger);
351 }
352
353 Int_t nReg = darcHeader->GetRegHeaderEntries();
354
355 for(Int_t iReg = 0; iReg < nReg ;iReg++){ //reg loop
356
357 regHeader = darcHeader->GetRegHeaderEntry(iReg);
358
359 Int_t nLocal = regHeader->GetLocalEntries();
360
361 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {
362
363 localStruct = regHeader->GetLocalEntry(iLocal);
364
365 if (localStruct->GetTriggerY() == 0) {
366 loCircuit = localStruct->GetId()+ 16*regHeader->GetId()
367 + 128*fRawStreamTrigger->GetDDL();
368
369 // fill local trigger
370 fLocalTrigger->SetLocalStruct(loCircuit, *localStruct);
371
372 fMUONData->AddLocalTrigger(*fLocalTrigger);
373 } // if triggerY
374 } // iLocal
375 } // iReg
376 } // NextDDL
377
378 fTriggerTimer.Stop();
379
380 return kTRUE;
381
382}
383