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 "AliMUONRawStreamTrackerHP.h"
56 #include "AliMUONRawStreamTriggerHP.h"
57 #include "AliMUONRegHeader.h"
58 #include "AliMUONVTriggerStore.h"
59 #include "AliMpDetElement.h"
60 #include "AliMpTriggerCrate.h"
61 #include "AliMpLocalBoard.h"
62 #include "AliMpCathodType.h"
63 #include "AliMpDDLStore.h"
64 #include "AliMpDEManager.h"
66 #include "AliMpSegmentation.h"
67 #include "AliMpVSegmentation.h"
68 #include "AliCodeTimer.h"
70 #include "AliRawReader.h"
74 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
77 //__________________________________________________________________________
78 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
81 fMakeTriggerDigits(kFALSE),
82 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
83 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
86 fLogger(new AliMUONLogger(10000))
90 if ( !a || !b ) AliFatal("no longer supported");
94 // Standard Constructor
95 if (enableErrorLogger)
97 fRawStreamTracker->EnabbleErrorLogger();
98 fRawStreamTrigger->EnabbleErrorLogger();
102 fRawStreamTracker->DisableWarnings();
105 SetMakeTriggerDigits();
109 //__________________________________________________________________________
110 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
112 fScalerEvent(kFALSE),
113 fMakeTriggerDigits(kFALSE),
114 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
115 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
118 fLogger(new AliMUONLogger(10000))
124 // Standard Constructor
125 if (enableErrorLogger)
127 fRawStreamTracker->EnabbleErrorLogger();
128 fRawStreamTrigger->EnabbleErrorLogger();
132 fRawStreamTracker->DisableWarnings();
135 SetMakeTriggerDigits();
139 //__________________________________________________________________________
140 AliMUONDigitMaker::~AliMUONDigitMaker()
143 /// and time processing measure
145 delete fRawStreamTracker;
146 delete fRawStreamTrigger;
150 //____________________________________________________________________
152 AliMUONDigitMaker::Print(Option_t*) const
156 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
157 << " MakeTriggerDigits=" << fMakeTriggerDigits
158 << " ScalerEvent=" << fScalerEvent
159 << " DigitStore=" << fDigitStore
160 << " TriggerStore=" << fTriggerStore << endl;
162 if ( fLogger ) fLogger->Print();
165 //____________________________________________________________________
167 AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
168 AliMUONVDigitStore* digitStore,
169 AliMUONVTriggerStore* triggerStore)
171 /// Main method to creates digit
175 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
176 rawReader,digitStore,triggerStore));
178 fDigitStore = digitStore;
179 fTriggerStore = triggerStore;
181 if (!fDigitStore && !fTriggerStore)
183 fLogger->Log("No digit or trigger store given. Nothing to do...");
184 return kTriggerBAD & kTrackerBAD;
192 fDigitStore->Clear(); // insure we start with an empty container
193 tracker = ReadTrackerDDL(rawReader);
196 if ( fTriggerStore || fMakeTriggerDigits )
198 if ( fTriggerStore ) fTriggerStore->Clear();
199 if ( fMakeTriggerDigits && !fDigitStore )
201 fLogger->Log("Asking for trigger digits but digitStore is null");
205 trigger = ReadTriggerDDL(rawReader);
209 return tracker | trigger;
212 //____________________________________________________________________
214 AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
216 /// Reading tracker DDL
217 /// filling the fDigitStore container, which must not be null
221 AliCodeTimerAuto("",0);
229 fRawStreamTracker->SetReader(rawReader);
230 fRawStreamTracker->First();
232 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
234 // getting DE from buspatch
235 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
237 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
241 fLogger->Log(Form("DE %04d does not exist !"));
245 if (!de->IsConnectedChannel(manuId,channelId))
247 // non connected pad, do nothing (this is not an error !)
251 const AliMpVSegmentation* seg
252 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
257 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
261 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
263 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
267 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
268 detElemId, manuId, channelId));
272 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
273 AliMUONVDigitStore::kDeny);
277 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
278 detElemId, manuId, channelId));
282 digit->SetPadXY(pad.GetIx(),pad.GetIy());
284 digit->SetADC(charge);
288 if ( fRawStreamTracker->IsErrorMessage() )
296 //____________________________________________________________________
298 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
300 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
301 /// filling the fTriggerStore container, which must not be null
303 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
304 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
305 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
309 fRawStreamTrigger->SetReader(rawReader);
311 while (fRawStreamTrigger->NextDDL())
313 darcHeader = fRawStreamTrigger->GetHeaders();
315 // fill global trigger information
318 if (darcHeader->GetGlobalFlag())
320 AliMUONGlobalTrigger globalTrigger;
321 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
322 globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
323 fTriggerStore->SetGlobal(globalTrigger);
327 Int_t nReg = fRawStreamTrigger->GetRegionalHeaderCount();
329 for(Int_t iReg = 0; iReg < nReg ;iReg++)
334 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
335 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
338 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
341 regHeader = fRawStreamTrigger->GetRegionalHeader(iReg);
343 Int_t nLocal = regHeader->GetLocalStructCount();
344 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
347 localStruct = regHeader->GetLocalStruct(iLocal);
352 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
354 if ( !loCircuit ) continue; // empty slot
356 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
359 if( !localBoard->IsNotified())
364 // fill local trigger
365 AliMUONLocalTrigger localTrigger;
366 localTrigger.SetLocalStruct(loCircuit, *localStruct);
367 fTriggerStore->Add(localTrigger);
370 if ( fMakeTriggerDigits )
372 //FIXEME should find something better than a TArray
373 TArrayS xyPattern[2];
375 localStruct->GetXPattern(xyPattern[0]);
376 localStruct->GetYPattern(xyPattern[1]);
378 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
388 //____________________________________________________________________
389 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
391 AliMUONVDigitStore& digitStore) const
393 /// make digits for trigger from pattern, and add them to digitStore
395 AliCodeTimerAuto("",0);
399 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
403 // loop over x1-4 and y1-4
404 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
406 for (Int_t iCath = 0; iCath < 2; ++iCath)
408 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
409 if (!pattern) continue;
412 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
414 const AliMpVSegmentation* seg
415 = AliMpSegmentation::Instance()
416 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
418 // loop over the 16 bits of pattern
419 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
421 if ((pattern >> ibitxy) & 0x1)
423 // not quite sure about this
425 if (iCath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
427 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
431 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
432 detElemId, nBoard, ibitxy));
436 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
437 b = pad.GetLocalBoardChannel(0);
439 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
442 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
446 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
447 detElemId,nBoard,ibitxy,iCath));
451 Int_t padX = pad.GetIx();
452 Int_t padY = pad.GetIy();
455 digit->SetPadXY(padX,padY);
456 digit->SetCharge(1.);
465 //______________________________________________________________________________
467 AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
468 AliMUONVDigitStore& digitStore) const
471 /// make (S)Digit for trigger
476 AliMUONLocalTrigger* locTrg;
477 TIter next(triggerStore.CreateLocalIterator());
479 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
481 if (locTrg->IsNull()) continue;
483 TArrayS xyPattern[2];
484 locTrg->GetXPattern(xyPattern[0]);
485 locTrg->GetYPattern(xyPattern[1]);
487 Int_t nBoard = locTrg->LoCircuit();
488 TriggerDigits(nBoard, xyPattern, digitStore);