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