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