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(AliMpIntPair(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.GetIndices().GetFirst(),
285 pad.GetIndices().GetSecond());
287 digit->SetADC(charge);
291 if ( fRawStreamTracker->IsErrorMessage() )
299 //____________________________________________________________________
301 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
303 /// reading tracker DDL
304 /// filling the fTriggerStore container, which must not be null
308 AliMUONDDLTrigger* ddlTrigger = 0x0;
309 AliMUONDarcHeader* darcHeader = 0x0;
310 AliMUONRegHeader* regHeader = 0x0;
311 AliMUONLocalStruct* localStruct = 0x0;
315 AliCodeTimerAuto("");
317 if (UsingFastTriggerDecoder()) return ReadTriggerDDLFast(rawReader);
319 fRawStreamTrigger->SetReader(rawReader);
321 while (fRawStreamTrigger->NextDDL())
323 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
324 darcHeader = ddlTrigger->GetDarcHeader();
326 // fill global trigger information
329 if (darcHeader->GetGlobalFlag())
331 AliMUONGlobalTrigger globalTrigger;
332 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
333 fTriggerStore->SetGlobal(globalTrigger);
337 Int_t nReg = darcHeader->GetRegHeaderEntries();
339 for(Int_t iReg = 0; iReg < nReg ;iReg++)
344 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
345 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
348 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
351 regHeader = darcHeader->GetRegHeaderEntry(iReg);
353 Int_t nLocal = regHeader->GetLocalEntries();
354 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
357 localStruct = regHeader->GetLocalEntry(iLocal);
362 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
364 if ( !loCircuit ) continue; // empty slot
366 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
369 if( !localBoard->IsNotified())
374 // fill local trigger
375 AliMUONLocalTrigger localTrigger;
376 localTrigger.SetLocalStruct(loCircuit, *localStruct);
377 fTriggerStore->Add(localTrigger);
380 if ( fMakeTriggerDigits )
382 //FIXEME should find something better than a TArray
383 TArrayS xyPattern[2];
385 localStruct->GetXPattern(xyPattern[0]);
386 localStruct->GetYPattern(xyPattern[1]);
388 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
398 //____________________________________________________________________
400 AliMUONDigitMaker::ReadTriggerDDLFast(AliRawReader* rawReader)
402 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
403 /// filling the fTriggerStore container, which must not be null
405 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
406 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
407 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
411 fRawStreamTrigger->SetReader(rawReader);
412 AliMUONRawStreamTriggerHP* rawStreamTrigger =
413 dynamic_cast<AliMUONRawStreamTriggerHP*>(fRawStreamTrigger);
415 while (fRawStreamTrigger->NextDDL())
417 darcHeader = rawStreamTrigger->GetHeaders();
419 // fill global trigger information
422 if (darcHeader->GetGlobalFlag())
424 AliMUONGlobalTrigger globalTrigger;
425 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
426 fTriggerStore->SetGlobal(globalTrigger);
430 Int_t nReg = rawStreamTrigger->GetRegionalHeaderCount();
432 for(Int_t iReg = 0; iReg < nReg ;iReg++)
437 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
438 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
441 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
444 regHeader = rawStreamTrigger->GetRegionalHeader(iReg);
446 Int_t nLocal = regHeader->GetLocalStructCount();
447 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
450 localStruct = regHeader->GetLocalStruct(iLocal);
455 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
457 if ( !loCircuit ) continue; // empty slot
459 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
462 if( !localBoard->IsNotified())
467 // fill local trigger
468 AliMUONLocalTrigger localTrigger;
469 localTrigger.SetLoCircuit(loCircuit);
470 localTrigger.SetLoStripX((Int_t)localStruct->GetXPos());
471 localTrigger.SetLoStripY((Int_t)localStruct->GetYPos());
472 localTrigger.SetLoDev((Int_t)localStruct->GetXDev());
473 localTrigger.SetLoSdev((Int_t)localStruct->GetSXDev());
474 localTrigger.SetLoTrigY((Int_t)localStruct->GetTrigY());
475 localTrigger.SetLoLpt(localStruct->GetLpt());
476 localTrigger.SetLoHpt(localStruct->GetHpt());
477 localTrigger.SetX1Pattern(localStruct->GetX1());
478 localTrigger.SetX2Pattern(localStruct->GetX2());
479 localTrigger.SetX3Pattern(localStruct->GetX3());
480 localTrigger.SetX4Pattern(localStruct->GetX4());
481 localTrigger.SetY1Pattern(localStruct->GetY1());
482 localTrigger.SetY2Pattern(localStruct->GetY2());
483 localTrigger.SetY3Pattern(localStruct->GetY3());
484 localTrigger.SetY4Pattern(localStruct->GetY4());
485 fTriggerStore->Add(localTrigger);
488 if ( fMakeTriggerDigits )
490 //FIXEME should find something better than a TArray
491 TArrayS xyPattern[2];
493 localStruct->GetXPattern(xyPattern[0]);
494 localStruct->GetYPattern(xyPattern[1]);
496 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
506 //____________________________________________________________________
507 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
509 AliMUONVDigitStore& digitStore) const
511 /// make digits for trigger from pattern, and add them to digitStore
513 AliCodeTimerAuto("");
517 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
521 // loop over x1-4 and y1-4
522 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
524 for (Int_t iCath = 0; iCath < 2; ++iCath)
526 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
527 if (!pattern) continue;
530 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
532 const AliMpVSegmentation* seg
533 = AliMpSegmentation::Instance()
534 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
536 // loop over the 16 bits of pattern
537 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
539 if ((pattern >> ibitxy) & 0x1)
541 // not quite sure about this
543 if (iCath && localBoard->GetSwitch(6)) offset = -8;
545 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
549 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
550 detElemId, nBoard, ibitxy));
554 n = pad.GetLocation(0).GetFirst(); // always take first location so that digits are not inserted several times
555 b = pad.GetLocation(0).GetSecond();
557 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
560 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
564 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
565 detElemId,nBoard,ibitxy,iCath));
569 Int_t padX = pad.GetIndices().GetFirst();
570 Int_t padY = pad.GetIndices().GetSecond();
573 digit->SetPadXY(padX,padY);
574 digit->SetCharge(1.);
583 //____________________________________________________________________
584 Bool_t AliMUONDigitMaker::UsingFastTrackerDecoder() const
586 /// Returns kTRUE if the digit maker is using the high performance decoder for
587 /// tracker DDL stream decoding.
589 return (fRawStreamTracker->IsA() == AliMUONRawStreamTrackerHP::Class());
592 //____________________________________________________________________
593 Bool_t AliMUONDigitMaker::UsingFastTriggerDecoder() const
595 /// Returns kTRUE if the digit maker is using the high performance decoder for
596 /// trigger DDL stream decoding.
598 return (fRawStreamTrigger->IsA() == AliMUONRawStreamTriggerHP::Class());
601 //____________________________________________________________________
602 void AliMUONDigitMaker::SetFastTrackerDecoder(Bool_t useFastDecoder)
604 /// Set fast raw data decoder
606 delete fRawStreamTracker;
607 CreateRawStreamTracker(useFastDecoder);
610 //____________________________________________________________________
611 void AliMUONDigitMaker::SetFastTriggerDecoder(Bool_t useFastDecoder)
613 /// Set fast raw data decoder
615 delete fRawStreamTrigger;
616 CreateRawStreamTrigger(useFastDecoder);