- Adding comment lines to class description needed for Root documentation
[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
9265505b 16/// \class AliMUONDigitMaker
8c51a32f 17/// MUON Digit maker from rawdata.
a3283a4c 18///
19/// Raw2Digits:
20/// Using real mapping for tracker
21/// Indranil Das (Adapted for runloader: Ch. Finck) july 05
8c51a32f 22///
23/// Implemented non-constant buspatch numbers for tracking
24/// with correct DDL id.
25/// (Ch. Finck, dec 05)
26///
a3283a4c 27/// Add reader for scaler trigger events
28/// Use memcpy instead of assignment elt by elt
29/// (Ch. Finck, Jan 06)
8c51a32f 30///
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)
35///
36/// Add (S)Digit maker tracker (for free)
37/// and for trigger. Create trigger inverse mapping.
78649106 38///
39/// \author Ch. Finck, oct 06
a3283a4c 40
a3283a4c 41#include "AliMUONDigitMaker.h"
a3283a4c 42
40e382ae 43#include "AliLog.h"
a3283a4c 44#include "AliMUONDDLTrigger.h"
45#include "AliMUONDarcHeader.h"
40e382ae 46#include "AliMUONVDigit.h"
47#include "AliMUONVDigitStore.h"
48#include "AliMUONGlobalTrigger.h"
a3283a4c 49#include "AliMUONLocalStruct.h"
a3283a4c 50#include "AliMUONLocalTrigger.h"
40e382ae 51#include "AliMUONRawStreamTracker.h"
52#include "AliMUONRawStreamTrigger.h"
53#include "AliMUONRegHeader.h"
e1a10d41 54#include "AliMUONTriggerCircuit.h"
d9b1ecb0 55#include "AliMpTriggerCrate.h"
56#include "AliMpLocalBoard.h"
40e382ae 57#include "AliMUONVTriggerStore.h"
58#include "AliMpCathodType.h"
59#include "AliMpDDLStore.h"
60#include "AliMpDEManager.h"
61#include "AliMpPad.h"
9265505b 62#include "AliMpSegmentation.h"
a3283a4c 63#include "AliMpVSegmentation.h"
9265505b 64#include "AliRawReader.h"
7771752e 65#include <TArrayS.h>
9265505b 66
9265505b 67/// \cond CLASSIMP
a3283a4c 68ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
9265505b 69/// \endcond
70
a3283a4c 71//__________________________________________________________________________
3c7f5307 72AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger)
a3283a4c 73 : TObject(),
9f5dcca3 74 fScalerEvent(kFALSE),
40e382ae 75 fMakeTriggerDigits(kFALSE),
9f5dcca3 76 fRawStreamTracker(new AliMUONRawStreamTracker()),
77 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
9f5dcca3 78 fTrackerTimer(),
79 fTriggerTimer(),
40e382ae 80 fMappingTimer(),
81 fDigitStore(0x0),
82 fTriggerStore(0x0)
a3283a4c 83{
40e382ae 84 /// ctor
a3283a4c 85
86 AliDebug(1,"");
87
88 // Standard Constructor
3c7f5307 89 if (enableErrorLogger) {
90 fRawStreamTracker->EnabbleErrorLogger();
91 fRawStreamTrigger->EnabbleErrorLogger();
92 }
a3283a4c 93
a3283a4c 94 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
95 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
96 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
40e382ae 97
98 SetMakeTriggerDigits();
a3283a4c 99
100}
101
102//__________________________________________________________________________
9f5dcca3 103AliMUONDigitMaker::~AliMUONDigitMaker()
a3283a4c 104{
9265505b 105 /// clean up
106 /// and time processing measure
107
a3283a4c 108 delete fRawStreamTracker;
109 delete fRawStreamTrigger;
110
a7b01aa5 111 AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
a3283a4c 112 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
a7b01aa5 113 AliDebug(1, Form(" Execution time for MUON tracker (mapping calls part) "
a3283a4c 114 ": R:%.2fs C:%.2fs",
115 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
a7b01aa5 116 AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
a3283a4c 117 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
118
a3283a4c 119}
120
121//____________________________________________________________________
40e382ae 122Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
123 AliMUONVDigitStore* digitStore,
124 AliMUONVTriggerStore* triggerStore)
a3283a4c 125{
9265505b 126 /// Main method to creates digit
127 /// for tracker
128 /// and trigger
a3283a4c 129
40e382ae 130 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
131 rawReader,digitStore,triggerStore));
132
133 fDigitStore = digitStore;
134 fTriggerStore = triggerStore;
135
136 if (!fDigitStore && !fTriggerStore)
137 {
138 AliError("No digit or trigger store given. Nothing to do...");
139 return kFALSE;
140 }
141
142 if ( fDigitStore )
143 {
144 fDigitStore->Clear(); // insure we start with an empty container
145 ReadTrackerDDL(rawReader);
146 }
147
148 if ( fTriggerStore || fMakeTriggerDigits )
149 {
150 if ( fTriggerStore ) fTriggerStore->Clear();
151 if ( fMakeTriggerDigits && !fDigitStore )
152 {
153 AliError("Asking for trigger digits but digitStore is null");
154 }
155 else
156 {
e604ac4c 157 ReadTriggerDDL(rawReader);
40e382ae 158 }
159 }
160
a3283a4c 161 return kTRUE;
a3283a4c 162}
163
164//____________________________________________________________________
165Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
166{
40e382ae 167 /// Reading tracker DDL
168 /// filling the fDigitStore container, which must not be null
a3283a4c 169
40e382ae 170 AliDebug(1,"");
171
a3283a4c 172 fTrackerTimer.Start(kFALSE);
173
174 // elex info
175 Int_t buspatchId;
176 UChar_t channelId;
177 UShort_t manuId;
a3283a4c 178 UShort_t charge;
a3283a4c 179
a3283a4c 180 fRawStreamTracker->SetReader(rawReader);
1bc885f3 181 fRawStreamTracker->First();
182
183 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
184 {
40e382ae 185 // getting DE from buspatch
186 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
a3283a4c 187
40e382ae 188 const AliMpVSegmentation* seg
189 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
190 manuId);
a3283a4c 191
40e382ae 192 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
193 seg->PlaneType());
1bc885f3 194
40e382ae 195 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
196
197 if (!pad.IsValid())
198 {
199 AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
200 detElemId, manuId, channelId));
201 continue;
202 }
203
204 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
205 AliMUONVDigitStore::kDeny);
206 if (!digit)
207 {
208 AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
209 detElemId, manuId, channelId));
210 continue;
211 }
212
213 digit->SetPadXY(pad.GetIndices().GetFirst(),
214 pad.GetIndices().GetSecond());
215
216 digit->SetADC(charge);
9265505b 217
40e382ae 218 }
a3283a4c 219
40e382ae 220 fTrackerTimer.Stop();
a3283a4c 221
40e382ae 222 return kTRUE;
a3283a4c 223}
224
225//____________________________________________________________________
226Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
227{
9265505b 228 /// reading tracker DDL
40e382ae 229 /// filling the fTriggerStore container, which must not be null
a3283a4c 230
40e382ae 231 AliDebug(1,"");
232
a3283a4c 233 AliMUONDDLTrigger* ddlTrigger = 0x0;
234 AliMUONDarcHeader* darcHeader = 0x0;
235 AliMUONRegHeader* regHeader = 0x0;
236 AliMUONLocalStruct* localStruct = 0x0;
237
238 Int_t loCircuit;
d2d759cf 239
a3283a4c 240 fTriggerTimer.Start(kFALSE);
241
242 fRawStreamTrigger->SetReader(rawReader);
243
40e382ae 244 while (fRawStreamTrigger->NextDDL())
245 {
a3283a4c 246 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
247 darcHeader = ddlTrigger->GetDarcHeader();
40e382ae 248
249 // fill global trigger information
250 if (fTriggerStore)
251 {
252 if (darcHeader->GetGlobalFlag())
253 {
254 AliMUONGlobalTrigger globalTrigger;
255 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
256 fTriggerStore->SetGlobal(globalTrigger);
d2d759cf 257 }
a3283a4c 258 }
40e382ae 259
a3283a4c 260 Int_t nReg = darcHeader->GetRegHeaderEntries();
40e382ae 261
262 for(Int_t iReg = 0; iReg < nReg ;iReg++)
263 { //reg loop
264
d9b1ecb0 265
266 // crate info
267 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
268 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
40e382ae 269
d53fb0de 270 if (!crate)
40e382ae 271 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
d9b1ecb0 272
40e382ae 273
a3283a4c 274 regHeader = darcHeader->GetRegHeaderEntry(iReg);
40e382ae 275
a3283a4c 276 Int_t nLocal = regHeader->GetLocalEntries();
40e382ae 277 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
278 {
279
280 localStruct = regHeader->GetLocalEntry(iLocal);
281
282 // if card exist
283 if (localStruct) {
284
d9b1ecb0 285 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
286
287 if ( !loCircuit ) continue; // empty slot
288
289 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
290
291 // skip copy cards
292 if( !localBoard->IsNotified())
293 continue;
40e382ae 294
295 if (fTriggerStore)
296 {
297 // fill local trigger
298 AliMUONLocalTrigger localTrigger;
299 localTrigger.SetLocalStruct(loCircuit, *localStruct);
300 fTriggerStore->Add(localTrigger);
301 }
302
303 if ( fMakeTriggerDigits )
304 {
305 //FIXEME should find something better than a TArray
306 TArrayS xyPattern[2];
40e382ae 307
d9b1ecb0 308 localStruct->GetXPattern(xyPattern[0]);
309 localStruct->GetYPattern(xyPattern[1]);
40e382ae 310
311 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
312 }
313 } // if triggerY
a3283a4c 314 } // iLocal
315 } // iReg
316 } // NextDDL
40e382ae 317
a3283a4c 318 fTriggerTimer.Stop();
319
320 return kTRUE;
321
322}
7771752e 323
d2d759cf 324//____________________________________________________________________
7771752e 325Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
40e382ae 326 TArrayS* xyPattern,
327 AliMUONVDigitStore& digitStore) const
d2d759cf 328{
40e382ae 329 /// make digits for trigger from pattern, and add them to digitStore
d2d759cf 330
d9b1ecb0 331 Int_t detElemId;
332
333 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
334
8c0b5e70 335 Int_t n,b;
336
d2d759cf 337 // loop over x1-4 and y1-4
40e382ae 338 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
339 {
340 for (Int_t iCath = 0; iCath < 2; ++iCath)
341 {
7771752e 342 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
343 if (!pattern) continue;
40e382ae 344
7771752e 345 // get detElemId
d9b1ecb0 346 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
40e382ae 347
348 const AliMpVSegmentation* seg
349 = AliMpSegmentation::Instance()
350 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
351
352 // loop over the 16 bits of pattern
353 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
354 {
355 if ((pattern >> ibitxy) & 0x1)
356 {
357 // not quite sure about this
358 Int_t offset = 0;
359 if (iCath && localBoard->GetSwitch(6)) offset = -8;
360
361 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
362
363 if (!pad.IsValid())
364 {
365 AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
366 detElemId, nBoard, ibitxy));
367 continue;
368 }
8c0b5e70 369
370 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
371 b = pad.GetLocation(0).GetSecond();
372
373 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
374 n,b,nBoard,ibitxy));
375
376 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
40e382ae 377
378 if (!digit)
379 {
8c0b5e70 380 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
381 detElemId,nBoard,ibitxy,iCath));
382 continue;
40e382ae 383 }
384
385 Int_t padX = pad.GetIndices().GetFirst();
386 Int_t padY = pad.GetIndices().GetSecond();
387
388 // fill digit
389 digit->SetPadXY(padX,padY);
390 digit->SetCharge(1.);
391 }// xyPattern
392 }// ibitxy
7771752e 393 }// cath
394 } // ichamber
40e382ae 395
d2d759cf 396 return kTRUE;
397}