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 "AliMUONTriggerCircuit.h"
59 #include "AliMUONVTriggerStore.h"
60 #include "AliMpDetElement.h"
61 #include "AliMpTriggerCrate.h"
62 #include "AliMpLocalBoard.h"
63 #include "AliMpCathodType.h"
64 #include "AliMpDDLStore.h"
65 #include "AliMpDEManager.h"
67 #include "AliMpSegmentation.h"
68 #include "AliMpVSegmentation.h"
69 #include "AliCodeTimer.h"
71 #include "AliRawReader.h"
75 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
78 //__________________________________________________________________________
79 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger, Bool_t a, Bool_t b) :
82 fMakeTriggerDigits(kFALSE),
83 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
84 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
87 fLogger(new AliMUONLogger(10000))
91 if ( !a || !b ) AliFatal("no longer supported");
95 // Standard Constructor
96 if (enableErrorLogger)
98 fRawStreamTracker->EnabbleErrorLogger();
99 fRawStreamTrigger->EnabbleErrorLogger();
103 fRawStreamTracker->DisableWarnings();
106 SetMakeTriggerDigits();
110 //__________________________________________________________________________
111 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t enableErrorLogger) :
113 fScalerEvent(kFALSE),
114 fMakeTriggerDigits(kFALSE),
115 fRawStreamTracker(new AliMUONRawStreamTrackerHP),
116 fRawStreamTrigger(new AliMUONRawStreamTriggerHP),
119 fLogger(new AliMUONLogger(10000))
125 // Standard Constructor
126 if (enableErrorLogger)
128 fRawStreamTracker->EnabbleErrorLogger();
129 fRawStreamTrigger->EnabbleErrorLogger();
133 fRawStreamTracker->DisableWarnings();
136 SetMakeTriggerDigits();
140 //__________________________________________________________________________
141 AliMUONDigitMaker::~AliMUONDigitMaker()
144 /// and time processing measure
146 delete fRawStreamTracker;
147 delete fRawStreamTrigger;
151 //____________________________________________________________________
153 AliMUONDigitMaker::Print(Option_t*) const
157 cout << "RawStreamerTracker class=" << fRawStreamTracker->ClassName()
158 << " MakeTriggerDigits=" << fMakeTriggerDigits
159 << " ScalerEvent=" << fScalerEvent
160 << " DigitStore=" << fDigitStore
161 << " TriggerStore=" << fTriggerStore << endl;
163 if ( fLogger ) fLogger->Print();
166 //____________________________________________________________________
168 AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
169 AliMUONVDigitStore* digitStore,
170 AliMUONVTriggerStore* triggerStore)
172 /// Main method to creates digit
176 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
177 rawReader,digitStore,triggerStore));
179 fDigitStore = digitStore;
180 fTriggerStore = triggerStore;
182 if (!fDigitStore && !fTriggerStore)
184 fLogger->Log("No digit or trigger store given. Nothing to do...");
185 return kTriggerBAD & kTrackerBAD;
193 fDigitStore->Clear(); // insure we start with an empty container
194 tracker = ReadTrackerDDL(rawReader);
197 if ( fTriggerStore || fMakeTriggerDigits )
199 if ( fTriggerStore ) fTriggerStore->Clear();
200 if ( fMakeTriggerDigits && !fDigitStore )
202 fLogger->Log("Asking for trigger digits but digitStore is null");
206 trigger = ReadTriggerDDL(rawReader);
210 return tracker | trigger;
213 //____________________________________________________________________
215 AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
217 /// Reading tracker DDL
218 /// filling the fDigitStore container, which must not be null
222 AliCodeTimerAuto("");
230 fRawStreamTracker->SetReader(rawReader);
231 fRawStreamTracker->First();
233 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge,kTRUE) )
235 // getting DE from buspatch
236 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
238 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
242 fLogger->Log(Form("DE %04d does not exist !"));
246 if (!de->IsConnectedChannel(manuId,channelId))
248 // non connected pad, do nothing (this is not an error !)
252 const AliMpVSegmentation* seg
253 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
258 fLogger->Log(Form("(DE,MANUID)=(%04d,%04d) is not valid",detElemId,manuId));
262 AliMp::CathodType cathodeType = de->GetCathodType(seg->PlaneType());
264 AliMpPad pad = seg->PadByLocation(manuId,channelId,kFALSE);
268 fLogger->Log(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
269 detElemId, manuId, channelId));
273 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
274 AliMUONVDigitStore::kDeny);
278 fLogger->Log(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
279 detElemId, manuId, channelId));
283 digit->SetPadXY(pad.GetIx(),pad.GetIy());
285 digit->SetADC(charge);
289 if ( fRawStreamTracker->IsErrorMessage() )
297 //____________________________________________________________________
299 AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
301 /// reading tracker DDL like ReadTriggerDDL but with fast decoder interface.
302 /// filling the fTriggerStore container, which must not be null
304 const AliMUONRawStreamTriggerHP::AliHeader* darcHeader = 0x0;
305 const AliMUONRawStreamTriggerHP::AliRegionalHeader* regHeader = 0x0;
306 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStruct = 0x0;
310 fRawStreamTrigger->SetReader(rawReader);
311 AliMUONRawStreamTriggerHP* rawStreamTrigger =
312 dynamic_cast<AliMUONRawStreamTriggerHP*>(fRawStreamTrigger);
314 while (fRawStreamTrigger->NextDDL())
316 darcHeader = rawStreamTrigger->GetHeaders();
318 // fill global trigger information
321 if (darcHeader->GetGlobalFlag())
323 AliMUONGlobalTrigger globalTrigger;
324 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
325 globalTrigger.SetFromGlobalInput(darcHeader->GetGlobalHeader()->fInput);
326 fTriggerStore->SetGlobal(globalTrigger);
330 Int_t nReg = rawStreamTrigger->GetRegionalHeaderCount();
332 for(Int_t iReg = 0; iReg < nReg ;iReg++)
337 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
338 GetTriggerCrate(fRawStreamTrigger->GetDDL(), iReg);
341 fLogger->Log(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
344 regHeader = rawStreamTrigger->GetRegionalHeader(iReg);
346 Int_t nLocal = regHeader->GetLocalStructCount();
347 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
350 localStruct = regHeader->GetLocalStruct(iLocal);
355 loCircuit = crate->GetLocalBoardId(localStruct->GetId());
357 if ( !loCircuit ) continue; // empty slot
359 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, kTRUE);
362 if( !localBoard->IsNotified())
367 // fill local trigger
368 AliMUONLocalTrigger localTrigger;
369 localTrigger.SetLoCircuit(loCircuit);
370 localTrigger.SetLoStripX((Int_t)localStruct->GetXPos());
371 localTrigger.SetLoStripY((Int_t)localStruct->GetYPos());
372 localTrigger.SetLoDev((Int_t)localStruct->GetXDev());
373 localTrigger.SetLoSdev((Int_t)localStruct->GetSXDev());
374 localTrigger.SetLoTrigY((Int_t)localStruct->GetTrigY());
375 localTrigger.SetLoLpt(localStruct->GetLpt());
376 localTrigger.SetLoHpt(localStruct->GetHpt());
377 localTrigger.SetX1Pattern(localStruct->GetX1());
378 localTrigger.SetX2Pattern(localStruct->GetX2());
379 localTrigger.SetX3Pattern(localStruct->GetX3());
380 localTrigger.SetX4Pattern(localStruct->GetX4());
381 localTrigger.SetY1Pattern(localStruct->GetY1());
382 localTrigger.SetY2Pattern(localStruct->GetY2());
383 localTrigger.SetY3Pattern(localStruct->GetY3());
384 localTrigger.SetY4Pattern(localStruct->GetY4());
385 fTriggerStore->Add(localTrigger);
388 if ( fMakeTriggerDigits )
390 //FIXEME should find something better than a TArray
391 TArrayS xyPattern[2];
393 localStruct->GetXPattern(xyPattern[0]);
394 localStruct->GetYPattern(xyPattern[1]);
396 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
406 //____________________________________________________________________
407 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
409 AliMUONVDigitStore& digitStore) const
411 /// make digits for trigger from pattern, and add them to digitStore
413 AliCodeTimerAuto("");
417 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(nBoard);
421 // loop over x1-4 and y1-4
422 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
424 for (Int_t iCath = 0; iCath < 2; ++iCath)
426 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
427 if (!pattern) continue;
430 detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(nBoard, iChamber);
432 const AliMpVSegmentation* seg
433 = AliMpSegmentation::Instance()
434 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
436 // loop over the 16 bits of pattern
437 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
439 if ((pattern >> ibitxy) & 0x1)
441 // not quite sure about this
443 if (iCath && localBoard->GetSwitch(6)) offset = -8;
445 AliMpPad pad = seg->PadByLocation(nBoard,ibitxy+offset,kTRUE);
449 fLogger->Log(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
450 detElemId, nBoard, ibitxy));
454 n = pad.GetLocalBoardId(0); // always take first location so that digits are not inserted several times
455 b = pad.GetLocalBoardChannel(0);
457 AliDebug(1,Form("Using localBoard %d ixy %d instead of %d,%d",
460 AliMUONVDigit* digit = digitStore.Add(detElemId,n,b,iCath,AliMUONVDigitStore::kDeny);
464 AliDebug(1, Form("Digit DE %04d LocalBoard %03d ibitxy %02d cath %d already in store",
465 detElemId,nBoard,ibitxy,iCath));
469 Int_t padX = pad.GetIx();
470 Int_t padY = pad.GetIy();
473 digit->SetPadXY(padX,padY);
474 digit->SetCharge(1.);
483 //______________________________________________________________________________
485 AliMUONDigitMaker::TriggerToDigitsStore(const AliMUONVTriggerStore& triggerStore,
486 AliMUONVDigitStore& digitStore) const
489 /// make (S)Digit for trigger
494 AliMUONLocalTrigger* locTrg;
495 TIter next(triggerStore.CreateLocalIterator());
497 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
499 if (locTrg->IsNull()) continue;
501 TArrayS xyPattern[2];
502 locTrg->GetXPattern(xyPattern[0]);
503 locTrg->GetYPattern(xyPattern[1]);
505 Int_t nBoard = locTrg->LoCircuit();
506 TriggerDigits(nBoard, xyPattern, digitStore);