1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONDigitMaker
20 /// MUON Digit maker from rawdata.
23 /// Using real mapping for tracker
24 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
26 /// Implemented non-constant buspatch numbers for tracking
27 /// with correct DDL id.
28 /// (Ch. Finck, dec 05)
30 /// Add reader for scaler trigger events
31 /// Use memcpy instead of assignment elt by elt
32 /// (Ch. Finck, Jan 06)
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)
39 /// Add (S)Digit maker tracker (for free)
40 /// and for trigger. Create trigger inverse mapping.
42 /// \author Ch. Finck, oct 06
43 //-----------------------------------------------------------------------------
45 #include "AliMUONDigitMaker.h"
47 #include "AliMUONDDLTrigger.h"
48 #include "AliMUONDarcHeader.h"
49 #include "AliMUONVDigit.h"
50 #include "AliMUONVDigitStore.h"
51 #include "AliMUONGlobalTrigger.h"
52 #include "AliMUONLocalStruct.h"
53 #include "AliMUONLocalTrigger.h"
54 #include "AliMUONLogger.h"
55 #include "AliMUONRawStreamTracker.h"
56 #include "AliMUONRawStreamTrackerHP.h"
57 #include "AliMUONRawStreamTrigger.h"
58 #include "AliMUONRawStreamTriggerHP.h"
59 #include "AliMUONRegHeader.h"
60 #include "AliMUONTriggerCircuit.h"
61 #include "AliMUONVTriggerStore.h"
62 #include "AliMpDetElement.h"
63 #include "AliMpTriggerCrate.h"
64 #include "AliMpLocalBoard.h"
65 #include "AliMpCathodType.h"
66 #include "AliMpDDLStore.h"
67 #include "AliMpDEManager.h"
69 #include "AliMpSegmentation.h"
70 #include "AliMpVSegmentation.h"
71 #include "AliCodeTimer.h"
73 #include "AliRawReader.h"
77 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
80 //__________________________________________________________________________
81 AliMUONDigitMaker::AliMUONDigitMaker(
82 Bool_t enableErrorLogger,
83 Bool_t useFastTrackerDecoder, Bool_t useFastTriggerDecoder
87 fMakeTriggerDigits(kFALSE),
88 fRawStreamTracker(NULL),
89 fRawStreamTrigger(NULL),
92 fLogger(new AliMUONLogger(10000))
98 CreateRawStreamTracker(useFastTrackerDecoder);
99 CreateRawStreamTrigger(useFastTriggerDecoder);
101 // Standard Constructor
102 if (enableErrorLogger) {
103 fRawStreamTracker->EnabbleErrorLogger();
104 fRawStreamTrigger->EnabbleErrorLogger();
107 SetMakeTriggerDigits();
111 //__________________________________________________________________________
112 AliMUONDigitMaker::~AliMUONDigitMaker()
115 /// and time processing measure
117 delete fRawStreamTracker;
118 delete fRawStreamTrigger;
122 //__________________________________________________________________________
123 void AliMUONDigitMaker::CreateRawStreamTracker(Bool_t useFastDecoder)
125 /// Create raw stream tracker according to the passed option
129 fRawStreamTracker = new AliMUONRawStreamTrackerHP();
132 AliInfo("Using non-high performance tracker decoder.");
133 fRawStreamTracker = new AliMUONRawStreamTracker();
137 //__________________________________________________________________________
138 void AliMUONDigitMaker::CreateRawStreamTrigger(Bool_t useFastDecoder)
140 /// Create raw stream trigger according to the passed option
144 fRawStreamTrigger = new AliMUONRawStreamTriggerHP();
147 AliInfo("Using non-high performance tracker decoder.");
148 fRawStreamTrigger = new AliMUONRawStreamTrigger();
152 //____________________________________________________________________
154 AliMUONDigitMaker::Print(Option_t*) const
158 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
159 << " MakeTriggerDigits=" << fMakeTriggerDigits
160 << " ScalerEvent=" << fScalerEvent
161 << " DigitStore=" << fDigitStore
162 << " TriggerStore=" << fTriggerStore << endl;
164 if ( fLogger ) fLogger->Print();
167 //____________________________________________________________________
169 AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
170 AliMUONVDigitStore* digitStore,
171 AliMUONVTriggerStore* triggerStore)
173 /// Main method to creates digit
177 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
178 rawReader,digitStore,triggerStore));
180 fDigitStore = digitStore;
181 fTriggerStore = triggerStore;
183 if (!fDigitStore && !fTriggerStore)
185 fLogger->Log("No digit or trigger store given. Nothing to do...");
186 return kTriggerBAD & kTrackerBAD;
194 fDigitStore->Clear(); // insure we start with an empty container
195 tracker = ReadTrackerDDL(rawReader);
198 if ( fTriggerStore || fMakeTriggerDigits )
200 if ( fTriggerStore ) fTriggerStore->Clear();
201 if ( fMakeTriggerDigits && !fDigitStore )
203 fLogger->Log("Asking for trigger digits but digitStore is null");
207 trigger = ReadTriggerDDL(rawReader);
211 return tracker | trigger;
214 //____________________________________________________________________
216 AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
218 /// Reading tracker DDL
219 /// filling the fDigitStore container, which must not be null
223 AliCodeTimerAuto("");
231 fRawStreamTracker->SetReader(rawReader);
232 fRawStreamTracker->First();
234 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
236 // getting DE from buspatch
237 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
239 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
243 fLogger->Log(Form("DE %04d does not exist !"));
247 if (!de->IsConnectedChannel(manuId,channelId))
249 // non connected pad, do nothing (this is not an error !)
253 const AliMpVSegmentation* seg
254 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
259 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
263 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
265 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
269 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
270 detElemId, manuId, channelId));
274 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
275 AliMUONVDigitStore::kDeny);
279 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
280 detElemId, manuId, channelId));
284 digit->SetPadXY(pad.GetIx(),pad.GetIy());
286 digit->SetADC(charge);
290 if ( fRawStreamTracker->IsErrorMessage() )
298 //____________________________________________________________________
300 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
302 /// reading tracker DDL
303 /// filling the fTriggerStore container, which must not be null
307 AliMUONDDLTrigger* ddlTrigger = 0x0;
308 AliMUONDarcHeader* darcHeader = 0x0;
309 AliMUONRegHeader* regHeader = 0x0;
310 AliMUONLocalStruct* localStruct = 0x0;
314 AliCodeTimerAuto("");
316 if (UsingFastTriggerDecoder()) return ReadTriggerDDLFast(rawReader);
318 fRawStreamTrigger->SetReader(rawReader);
320 while (fRawStreamTrigger->NextDDL())
322 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
323 darcHeader = ddlTrigger->GetDarcHeader();
325 // fill global trigger information
328 if (darcHeader->GetGlobalFlag())
330 AliMUONGlobalTrigger globalTrigger;
331 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
332 fTriggerStore->SetGlobal(globalTrigger);
336 Int_t nReg = darcHeader->GetRegHeaderEntries();
338 for(Int_t iReg = 0; iReg < nReg ;iReg++)
343 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
344 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
347 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
350 regHeader = darcHeader->GetRegHeaderEntry(iReg);
352 Int_t nLocal = regHeader->GetLocalEntries();
353 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
356 localStruct = regHeader->GetLocalEntry(iLocal);
361 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
363 if ( !loCircuit ) continue; // empty slot
365 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
368 if( !localBoard->IsNotified())
373 // fill local trigger
374 AliMUONLocalTrigger localTrigger;
375 localTrigger.SetLocalStruct(loCircuit, *localStruct);
376 fTriggerStore->Add(localTrigger);
379 if ( fMakeTriggerDigits )
381 //FIXEME should find something better than a TArray
382 TArrayS xyPattern[2];
384 localStruct->GetXPattern(xyPattern[0]);
385 localStruct->GetYPattern(xyPattern[1]);
387 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
397 //____________________________________________________________________
399 AliMUONDigitMaker::ReadTriggerDDLFast(AliRawReader* rawReader)
401 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
402 /// filling the fTriggerStore container, which must not be null
404 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
405 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
406 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
410 fRawStreamTrigger->SetReader(rawReader);
411 AliMUONRawStreamTriggerHP* rawStreamTrigger =
412 dynamic_cast<AliMUONRawStreamTriggerHP*>(fRawStreamTrigger);
414 while (fRawStreamTrigger->NextDDL())
416 darcHeader = rawStreamTrigger->GetHeaders();
418 // fill global trigger information
421 if (darcHeader->GetGlobalFlag())
423 AliMUONGlobalTrigger globalTrigger;
424 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
425 fTriggerStore->SetGlobal(globalTrigger);
429 Int_t nReg = rawStreamTrigger->GetRegionalHeaderCount();
431 for(Int_t iReg = 0; iReg < nReg ;iReg++)
436 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
437 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
440 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
443 regHeader = rawStreamTrigger->GetRegionalHeader(iReg);
445 Int_t nLocal = regHeader->GetLocalStructCount();
446 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
449 localStruct = regHeader->GetLocalStruct(iLocal);
454 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
456 if ( !loCircuit ) continue; // empty slot
458 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
461 if( !localBoard->IsNotified())
466 // fill local trigger
467 AliMUONLocalTrigger localTrigger;
468 localTrigger.SetLoCircuit(loCircuit);
469 localTrigger.SetLoStripX((Int_t)localStruct->GetXPos());
470 localTrigger.SetLoStripY((Int_t)localStruct->GetYPos());
471 localTrigger.SetLoDev((Int_t)localStruct->GetXDev());
472 localTrigger.SetLoSdev((Int_t)localStruct->GetSXDev());
473 localTrigger.SetLoTrigY((Int_t)localStruct->GetTrigY());
474 localTrigger.SetLoLpt(localStruct->GetLpt());
475 localTrigger.SetLoHpt(localStruct->GetHpt());
476 localTrigger.SetX1Pattern(localStruct->GetX1());
477 localTrigger.SetX2Pattern(localStruct->GetX2());
478 localTrigger.SetX3Pattern(localStruct->GetX3());
479 localTrigger.SetX4Pattern(localStruct->GetX4());
480 localTrigger.SetY1Pattern(localStruct->GetY1());
481 localTrigger.SetY2Pattern(localStruct->GetY2());
482 localTrigger.SetY3Pattern(localStruct->GetY3());
483 localTrigger.SetY4Pattern(localStruct->GetY4());
484 fTriggerStore->Add(localTrigger);
487 if ( fMakeTriggerDigits )
489 //FIXEME should find something better than a TArray
490 TArrayS xyPattern[2];
492 localStruct->GetXPattern(xyPattern[0]);
493 localStruct->GetYPattern(xyPattern[1]);
495 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
505 //____________________________________________________________________
506 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
508 AliMUONVDigitStore& digitStore) const
510 /// make digits for trigger from pattern, and add them to digitStore
512 AliCodeTimerAuto("");
516 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
520 // loop over x1-4 and y1-4
521 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
523 for (Int_t iCath = 0; iCath < 2; ++iCath)
525 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
526 if (!pattern) continue;
529 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
531 const AliMpVSegmentation* seg
532 = AliMpSegmentation::Instance()
533 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
535 // loop over the 16 bits of pattern
536 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
538 if ((pattern >> ibitxy) & 0x1)
540 // not quite sure about this
542 if (iCath && localBoard->GetSwitch(6)) offset = -8;
544 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
548 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
549 detElemId, nBoard, ibitxy));
553 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
554 b = pad.GetLocalBoardChannel(0);
556 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
559 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
563 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
564 detElemId,nBoard,ibitxy,iCath));
568 Int_t padX = pad.GetIx();
569 Int_t padY = pad.GetIy();
572 digit->SetPadXY(padX,padY);
573 digit->SetCharge(1.);
582 //______________________________________________________________________________
584 AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
585 AliMUONVDigitStore& digitStore) const
588 /// make (S)Digit for trigger
593 AliMUONLocalTrigger* locTrg;
594 TIter next(triggerStore.CreateLocalIterator());
596 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
598 if (locTrg->IsNull()) continue;
600 TArrayS xyPattern[2];
601 locTrg->GetXPattern(xyPattern[0]);
602 locTrg->GetYPattern(xyPattern[1]);
604 Int_t nBoard = locTrg->LoCircuit();
605 TriggerDigits(nBoard, xyPattern, digitStore);
610 //____________________________________________________________________
611 Bool_t AliMUONDigitMaker::UsingFastTrackerDecoder() const
613 /// Returns kTRUE if the digit maker is using the high performance decoder for
614 /// tracker DDL stream decoding.
616 return (fRawStreamTracker->IsA() == AliMUONRawStreamTrackerHP::Class());
619 //____________________________________________________________________
620 Bool_t AliMUONDigitMaker::UsingFastTriggerDecoder() const
622 /// Returns kTRUE if the digit maker is using the high performance decoder for
623 /// trigger DDL stream decoding.
625 return (fRawStreamTrigger->IsA() == AliMUONRawStreamTriggerHP::Class());
628 //____________________________________________________________________
629 void AliMUONDigitMaker::SetFastTrackerDecoder(Bool_t useFastDecoder)
631 /// Set fast raw data decoder
633 delete fRawStreamTracker;
634 CreateRawStreamTracker(useFastDecoder);
637 //____________________________________________________________________
638 void AliMUONDigitMaker::SetFastTriggerDecoder(Bool_t useFastDecoder)
640 /// Set fast raw data decoder
642 delete fRawStreamTrigger;
643 CreateRawStreamTrigger(useFastDecoder);