Rewritten Task for Fragmentation Function, added to compilation of JetTasks module now
[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"
e3a2b9c9 55#include "AliMUONRawStreamTrackerHP.h"
481d8064 56#include "AliMUONRawStreamTriggerHP.h"
40e382ae 57#include "AliMUONRegHeader.h"
be63c782 58#include "AliMUONVTriggerStore.h"
59#include "AliMpDetElement.h"
d9b1ecb0 60#include "AliMpTriggerCrate.h"
61#include "AliMpLocalBoard.h"
40e382ae 62#include "AliMpCathodType.h"
63#include "AliMpDDLStore.h"
64#include "AliMpDEManager.h"
65#include "AliMpPad.h"
9265505b 66#include "AliMpSegmentation.h"
a3283a4c 67#include "AliMpVSegmentation.h"
be63c782 68#include "AliCodeTimer.h"
69#include "AliLog.h"
9265505b 70#include "AliRawReader.h"
7771752e 71#include <TArrayS.h>
9265505b 72
9265505b 73/// \cond CLASSIMP
a3283a4c 74ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
9265505b 75/// \endcond
76
a3283a4c 77//__________________________________________________________________________
b6f591ae 78AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
79TObject(),
80fScalerEvent(kFALSE),
81fMakeTriggerDigits(kFALSE),
82fRawStreamTracker(new AliMUONRawStreamTrackerHP),
83fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
84fDigitStore(0x0),
85fTriggerStore(0x0),
9074a9a9 86fLogger(new AliMUONLogger(10000)){
b6f591ae 87 /// ctor
88
89 if ( !a || !b ) AliFatal("no longer supported");
90
91 AliDebug(1,"");
92
93 // Standard Constructor
94 if (enableErrorLogger)
95 {
96 fRawStreamTracker->EnabbleErrorLogger();
97 fRawStreamTrigger->EnabbleErrorLogger();
98 }
99 else
100 {
101 fRawStreamTracker->DisableWarnings();
102 }
103
104 SetMakeTriggerDigits();
105
106}
107
108//__________________________________________________________________________
109AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
110TObject(),
9f5dcca3 111 fScalerEvent(kFALSE),
40e382ae 112 fMakeTriggerDigits(kFALSE),
b6f591ae 113 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
114 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
40e382ae 115 fDigitStore(0x0),
0145e89a 116 fTriggerStore(0x0),
117 fLogger(new AliMUONLogger(10000))
a3283a4c 118{
40e382ae 119 /// ctor
a3283a4c 120
121 AliDebug(1,"");
e3a2b9c9 122
a3283a4c 123 // Standard Constructor
b6f591ae 124 if (enableErrorLogger)
125 {
3c7f5307 126 fRawStreamTracker->EnabbleErrorLogger();
127 fRawStreamTrigger->EnabbleErrorLogger();
128 }
b6f591ae 129 else
130 {
131 fRawStreamTracker->DisableWarnings();
132 }
a3283a4c 133
40e382ae 134 SetMakeTriggerDigits();
a3283a4c 135
136}
137
138//__________________________________________________________________________
9f5dcca3 139AliMUONDigitMaker::~AliMUONDigitMaker()
a3283a4c 140{
9265505b 141 /// clean up
142 /// and time processing measure
143
a3283a4c 144 delete fRawStreamTracker;
145 delete fRawStreamTrigger;
0145e89a 146 delete fLogger;
a3283a4c 147}
148
149//____________________________________________________________________
be63c782 150void
151AliMUONDigitMaker::Print(Option_t*) const
152{
153 /// Printout
154
155 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
156 << " MakeTriggerDigits=" << fMakeTriggerDigits
157 << " ScalerEvent=" << fScalerEvent
158 << " DigitStore=" << fDigitStore
159 << " TriggerStore=" << fTriggerStore << endl;
160
161 if ( fLogger ) fLogger->Print();
162}
163
164//____________________________________________________________________
165Int_t
166AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
167 AliMUONVDigitStore* digitStore,
168 AliMUONVTriggerStore* triggerStore)
a3283a4c 169{
9265505b 170 /// Main method to creates digit
171 /// for tracker
172 /// and trigger
a3283a4c 173
40e382ae 174 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
175 rawReader,digitStore,triggerStore));
176
177 fDigitStore = digitStore;
178 fTriggerStore = triggerStore;
179
180 if (!fDigitStore && !fTriggerStore)
181 {
0145e89a 182 fLogger->Log("No digit or trigger store given. Nothing to do...");
be63c782 183 return kTriggerBAD & kTrackerBAD;
40e382ae 184 }
185
be63c782 186 Int_t tracker(kOK);
187 Int_t trigger(kOK);
188
40e382ae 189 if ( fDigitStore )
190 {
191 fDigitStore->Clear(); // insure we start with an empty container
be63c782 192 tracker = ReadTrackerDDL(rawReader);
40e382ae 193 }
194
195 if ( fTriggerStore || fMakeTriggerDigits )
196 {
197 if ( fTriggerStore ) fTriggerStore->Clear();
198 if ( fMakeTriggerDigits && !fDigitStore )
199 {
0145e89a 200 fLogger->Log("Asking for trigger digits but digitStore is null");
40e382ae 201 }
202 else
203 {
be63c782 204 trigger = ReadTriggerDDL(rawReader);
40e382ae 205 }
206 }
207
be63c782 208 return tracker | trigger;
a3283a4c 209}
210
211//____________________________________________________________________
be63c782 212Int_t
213AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
a3283a4c 214{
40e382ae 215 /// Reading tracker DDL
216 /// filling the fDigitStore container, which must not be null
a3283a4c 217
40e382ae 218 AliDebug(1,"");
219
99c136e1 220 AliCodeTimerAuto("",0);
a3283a4c 221
222 // elex info
223 Int_t buspatchId;
224 UChar_t channelId;
225 UShort_t manuId;
a3283a4c 226 UShort_t charge;
a3283a4c 227
a3283a4c 228 fRawStreamTracker->SetReader(rawReader);
1bc885f3 229 fRawStreamTracker->First();
230
b6f591ae 231 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
1bc885f3 232 {
40e382ae 233 // getting DE from buspatch
234 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
a3283a4c 235
be63c782 236 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
237
238 if (!de)
239 {
1130977f 240 fLogger->Log(Form("DE %04d does not exist !", detElemId));
be63c782 241 continue;
242 }
243
244 if (!de->IsConnectedChannel(manuId,channelId))
245 {
246 // non connected pad, do nothing (this is not an error !)
247 continue;
248 }
249
40e382ae 250 const AliMpVSegmentation* seg
251 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
252 manuId);
a3283a4c 253
0145e89a 254 if (!seg)
255 {
256 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
257 continue;
258 }
259
be63c782 260 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
1bc885f3 261
168e9c4d 262 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
be63c782 263
40e382ae 264 if (!pad.IsValid())
265 {
0145e89a 266 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
40e382ae 267 detElemId, manuId, channelId));
268 continue;
269 }
be63c782 270
40e382ae 271 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
272 AliMUONVDigitStore::kDeny);
be63c782 273
40e382ae 274 if (!digit)
275 {
0145e89a 276 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
40e382ae 277 detElemId, manuId, channelId));
278 continue;
279 }
280
168e9c4d 281 digit->SetPadXY(pad.GetIx(),pad.GetIy());
40e382ae 282
168e9c4d 283 digit->SetADC(charge);
9265505b 284
40e382ae 285 }
a3283a4c 286
be63c782 287 if ( fRawStreamTracker->IsErrorMessage() )
288 {
289 return kTrackerBAD;
290 }
291
292 return kOK;
a3283a4c 293}
294
295//____________________________________________________________________
be63c782 296Int_t
297AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
a3283a4c 298{
481d8064 299 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
300 /// filling the fTriggerStore container, which must not be null
301
302 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
303 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
304 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
305
306 Int_t loCircuit;
307
308 fRawStreamTrigger->SetReader(rawReader);
481d8064 309
310 while (fRawStreamTrigger->NextDDL())
311 {
818aff28 312 darcHeader = fRawStreamTrigger->GetHeaders();
481d8064 313
314 // fill global trigger information
315 if (fTriggerStore)
316 {
317 if (darcHeader->GetGlobalFlag())
318 {
319 AliMUONGlobalTrigger globalTrigger;
320 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
a90f8830 321 globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
481d8064 322 fTriggerStore->SetGlobal(globalTrigger);
323 }
324 }
325
818aff28 326 Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount();
481d8064 327
328 for(Int_t iReg = 0; iReg < nReg ;iReg++)
329 { //reg loop
330
331
332 // crate info
333 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
334 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
335
336 if (!crate)
337 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
338
339
818aff28 340 regHeader = fRawStreamTrigger->GetRegionalHeader(iReg);
481d8064 341
342 Int_t nLocal = regHeader->GetLocalStructCount();
343 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
344 {
345
346 localStruct = regHeader->GetLocalStruct(iLocal);
347
348 // if card exist
349 if (localStruct) {
350
351 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
352
353 if ( !loCircuit ) continue; // empty slot
354
1ffbeb9d 355 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
481d8064 356
357 // skip copy cards
358 if( !localBoard->IsNotified())
359 continue;
360
361 if (fTriggerStore)
362 {
363 // fill local trigger
364 AliMUONLocalTrigger localTrigger;
a026ce9e 365 localTrigger.SetLocalStruct(loCircuit, *localStruct);
481d8064 366 fTriggerStore->Add(localTrigger);
367 }
368
369 if ( fMakeTriggerDigits )
370 {
371 //FIXEME should find something better than a TArray
372 TArrayS xyPattern[2];
373
374 localStruct->GetXPattern(xyPattern[0]);
375 localStruct->GetYPattern(xyPattern[1]);
376
377 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
378 }
379 } // if triggerY
380 } // iLocal
381 } // iReg
382 } // NextDDL
383
384 return kOK;
385}
386
387//____________________________________________________________________
7771752e 388Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
57e2ad1a 389 const TArrayS* xyPattern,
40e382ae 390 AliMUONVDigitStore& digitStore) const
d2d759cf 391{
40e382ae 392 /// make digits for trigger from pattern, and add them to digitStore
d2d759cf 393
99c136e1 394 AliCodeTimerAuto("",0);
0145e89a 395
d9b1ecb0 396 Int_t detElemId;
397
398 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
399
8c0b5e70 400 Int_t n,b;
401
d2d759cf 402 // loop over x1-4 and y1-4
40e382ae 403 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
404 {
405 for (Int_t iCath = 0; iCath < 2; ++iCath)
406 {
7771752e 407 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
408 if (!pattern) continue;
40e382ae 409
7771752e 410 // get detElemId
d9b1ecb0 411 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
40e382ae 412
413 const AliMpVSegmentation* seg
414 = AliMpSegmentation::Instance()
415 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
416
417 // loop over the 16 bits of pattern
418 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
419 {
420 if ((pattern >> ibitxy) & 0x1)
421 {
422 // not quite sure about this
423 Int_t offset = 0;
dc5d3949 424 if (iCath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
40e382ae 425
168e9c4d 426 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
40e382ae 427
428 if (!pad.IsValid())
429 {
0145e89a 430 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
40e382ae 431 detElemId, nBoard, ibitxy));
432 continue;
433 }
8c0b5e70 434
168e9c4d 435 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
436 b = pad.GetLocalBoardChannel(0);
8c0b5e70 437
438 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
439 n,b,nBoard,ibitxy));
440
441 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
40e382ae 442
443 if (!digit)
444 {
8c0b5e70 445 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
446 detElemId,nBoard,ibitxy,iCath));
447 continue;
40e382ae 448 }
449
168e9c4d 450 Int_t padX = pad.GetIx();
451 Int_t padY = pad.GetIy();
40e382ae 452
453 // fill digit
454 digit->SetPadXY(padX,padY);
455 digit->SetCharge(1.);
456 }// xyPattern
457 }// ibitxy
7771752e 458 }// cath
459 } // ichamber
40e382ae 460
d2d759cf 461 return kTRUE;
481d8064 462}
d61f56df 463
54355f2c 464//______________________________________________________________________________
465Bool_t
466AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
467 AliMUONVDigitStore& digitStore) const
468{
469 //
470 /// make (S)Digit for trigger
471 //
472
473 digitStore.Clear();
474
475 AliMUONLocalTrigger* locTrg;
476 TIter next(triggerStore.CreateLocalIterator());
477
478 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
479 {
480 if (locTrg->IsNull()) continue;
481
482 TArrayS xyPattern[2];
483 locTrg->GetXPattern(xyPattern[0]);
484 locTrg->GetYPattern(xyPattern[1]);
485
486 Int_t nBoard = locTrg->LoCircuit();
487 TriggerDigits(nBoard, xyPattern, digitStore);
488 }
489 return kTRUE;
490}
9074a9a9 491
492//______________________________________________________________________________
493void
494AliMUONDigitMaker::SetTryRecover(Bool_t flag)
495{
496 /// Instruct the decoder to try to recover corrupted raw data.
497 /// Only use for specific cases for which you know it will work...
498 fRawStreamTracker->TryRecover(flag);
499}