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 **************************************************************************/
16 /// \class AliMUONDigitMaker
17 /// MUON Digit maker from rawdata.
20 /// Using real mapping for tracker
21 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
23 /// Implemented non-constant buspatch numbers for tracking
24 /// with correct DDL id.
25 /// (Ch. Finck, dec 05)
27 /// Add reader for scaler trigger events
28 /// Use memcpy instead of assignment elt by elt
29 /// (Ch. Finck, Jan 06)
31 /// Using new interface with AliMUONRawStreamTracker(Trigger)
32 /// (New interface of AliMUONRawReader class)
33 /// (further details could be found in Alice-note)
34 /// (Ch. Finck, March 06)
36 /// Add (S)Digit maker tracker (for free)
37 /// and for trigger. Create trigger inverse mapping.
39 /// \author Ch. Finck, oct 06
41 #include "AliMUONDigitMaker.h"
44 #include "AliMUONDDLTrigger.h"
45 #include "AliMUONDarcHeader.h"
46 #include "AliMUONVDigit.h"
47 #include "AliMUONVDigitStore.h"
48 #include "AliMUONGlobalTrigger.h"
49 #include "AliMUONLocalStruct.h"
50 #include "AliMUONLocalTrigger.h"
51 #include "AliMUONLocalTriggerBoard.h"
52 #include "AliMUONRawStreamTracker.h"
53 #include "AliMUONRawStreamTrigger.h"
54 #include "AliMUONRegHeader.h"
55 #include "AliMUONTriggerCircuit.h"
56 #include "AliMUONTriggerCrate.h"
57 #include "AliMUONTriggerCrateStore.h"
58 #include "AliMUONVTriggerStore.h"
59 #include "AliMpCathodType.h"
60 #include "AliMpDDLStore.h"
61 #include "AliMpDEManager.h"
63 #include "AliMpSegmentation.h"
64 #include "AliMpVSegmentation.h"
65 #include "AliRawReader.h"
69 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
72 //__________________________________________________________________________
73 AliMUONDigitMaker::AliMUONDigitMaker()
76 fMakeTriggerDigits(kFALSE),
77 fRawStreamTracker(new AliMUONRawStreamTracker()),
78 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
90 // Standard Constructor
92 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
93 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
94 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
96 SetMakeTriggerDigits();
100 //__________________________________________________________________________
101 AliMUONDigitMaker::~AliMUONDigitMaker()
104 /// and time processing measure
106 delete fRawStreamTracker;
107 delete fRawStreamTrigger;
109 AliDebug(1, Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
110 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
111 AliDebug(1, Form(" Execution time for MUON tracker (mapping calls part) "
113 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
114 AliDebug(1, Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
115 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
119 //____________________________________________________________________
120 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader,
121 AliMUONVDigitStore* digitStore,
122 AliMUONVTriggerStore* triggerStore)
124 /// Main method to creates digit
128 AliDebug(1,Form("rawReader=%p digitStore=%p triggerStore=%p",
129 rawReader,digitStore,triggerStore));
131 fDigitStore = digitStore;
132 fTriggerStore = triggerStore;
134 if (!fDigitStore && !fTriggerStore)
136 AliError("No digit or trigger store given. Nothing to do...");
142 fDigitStore->Clear(); // insure we start with an empty container
143 ReadTrackerDDL(rawReader);
146 if ( fTriggerStore || fMakeTriggerDigits )
148 if ( fTriggerStore ) fTriggerStore->Clear();
149 if ( fMakeTriggerDigits && !fDigitStore )
151 AliError("Asking for trigger digits but digitStore is null");
155 ReadTriggerDDL(rawReader);
162 //____________________________________________________________________
163 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
165 /// Reading tracker DDL
166 /// filling the fDigitStore container, which must not be null
170 fTrackerTimer.Start(kFALSE);
178 fRawStreamTracker->SetReader(rawReader);
179 fRawStreamTracker->First();
181 while ( fRawStreamTracker->Next(buspatchId,manuId,channelId,charge) )
183 // getting DE from buspatch
184 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
186 const AliMpVSegmentation* seg
187 = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,
190 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,
193 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kFALSE);
197 AliError(Form("No pad for detElemId: %d, manuId: %d, channelId: %d",
198 detElemId, manuId, channelId));
202 AliMUONVDigit* digit = fDigitStore->Add(detElemId,manuId,channelId,cathodeType,
203 AliMUONVDigitStore::kDeny);
206 AliError(Form("Digit DE %04d Manu %04d Channel %02d could not be added",
207 detElemId, manuId, channelId));
211 digit->SetPadXY(pad.GetIndices().GetFirst(),
212 pad.GetIndices().GetSecond());
214 digit->SetADC(charge);
218 fTrackerTimer.Stop();
223 //____________________________________________________________________
224 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
226 /// reading tracker DDL
227 /// filling the fTriggerStore container, which must not be null
231 AliMUONDDLTrigger* ddlTrigger = 0x0;
232 AliMUONDarcHeader* darcHeader = 0x0;
233 AliMUONRegHeader* regHeader = 0x0;
234 AliMUONLocalStruct* localStruct = 0x0;
238 fTriggerTimer.Start(kFALSE);
240 fRawStreamTrigger->SetReader(rawReader);
242 while (fRawStreamTrigger->NextDDL())
244 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
245 darcHeader = ddlTrigger->GetDarcHeader();
247 // fill global trigger information
250 if (darcHeader->GetGlobalFlag())
252 AliMUONGlobalTrigger globalTrigger;
253 globalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
254 fTriggerStore->SetGlobal(globalTrigger);
258 Int_t nReg = darcHeader->GetRegHeaderEntries();
260 for(Int_t iReg = 0; iReg < nReg ;iReg++)
264 if (!fCrateManager) AliFatal("Crate Store not defined");
265 AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg);
268 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
270 TObjArray *boards = crate->Boards();
272 regHeader = darcHeader->GetRegHeaderEntry(iReg);
274 Int_t nLocal = regHeader->GetLocalEntries();
275 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++)
278 localStruct = regHeader->GetLocalEntry(iLocal);
283 AliMUONLocalTriggerBoard* localBoard =
284 (AliMUONLocalTriggerBoard*)boards->At(localStruct->GetId()+1);
287 if( !(loCircuit = localBoard->GetNumber()) )
292 // fill local trigger
293 AliMUONLocalTrigger localTrigger;
294 localTrigger.SetLocalStruct(loCircuit, *localStruct);
295 fTriggerStore->Add(localTrigger);
298 if ( fMakeTriggerDigits )
300 //FIXEME should find something better than a TArray
301 TArrayS xyPattern[2];
305 xyPattern[0].AddAt(localStruct->GetX1(),0);
306 xyPattern[0].AddAt(localStruct->GetX2(),1);
307 xyPattern[0].AddAt(localStruct->GetX3(),2);
308 xyPattern[0].AddAt(localStruct->GetX4(),3);
310 xyPattern[1].AddAt(localStruct->GetY1(),0);
311 xyPattern[1].AddAt(localStruct->GetY2(),1);
312 xyPattern[1].AddAt(localStruct->GetY3(),2);
313 xyPattern[1].AddAt(localStruct->GetY4(),3);
315 TriggerDigits(loCircuit, xyPattern, *fDigitStore);
322 fTriggerTimer.Stop();
328 //____________________________________________________________________
329 Int_t AliMUONDigitMaker::TriggerDigits(Int_t nBoard,
331 AliMUONVDigitStore& digitStore) const
333 /// make digits for trigger from pattern, and add them to digitStore
335 // loop over x1-4 and y1-4
336 for (Int_t iChamber = 0; iChamber < 4; ++iChamber)
338 for (Int_t iCath = 0; iCath < 2; ++iCath)
340 Int_t pattern = (Int_t)xyPattern[iCath].At(iChamber);
341 if (!pattern) continue;
344 AliMUONTriggerCircuit triggerCircuit;
345 AliMUONLocalTriggerBoard* localBoard = fCrateManager->LocalBoard(nBoard);
346 Int_t detElemId = triggerCircuit.DetElemId(iChamber+10, localBoard->GetName());//FIXME +/-10 (should be ok with new mapping)
348 const AliMpVSegmentation* seg
349 = AliMpSegmentation::Instance()
350 ->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
352 // loop over the 16 bits of pattern
353 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
355 if ((pattern >> ibitxy) & 0x1)
357 // not quite sure about this
359 if (iCath && localBoard->GetSwitch(6)) offset = -8;
361 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
365 AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
366 detElemId, nBoard, ibitxy));
370 AliMUONVDigit* digit = digitStore.Add(detElemId,nBoard,ibitxy,iCath,AliMUONVDigitStore::kDeny);
374 AliError(Form("Could not add digit DE %04d LocalBoard %03d ibitxy %02d cath %d",
375 detElemId,nBoard,ibitxy,iCath));
379 Int_t padX = pad.GetIndices().GetFirst();
380 Int_t padY = pad.GetIndices().GetSecond();
383 digit->SetPadXY(padX,padY);
384 digit->SetCharge(1.);
392 //____________________________________________________________________
394 AliMUONDigitMaker::GetCrateName(Char_t* name, Int_t iDDL, Int_t iReg) const
396 /// set crate name from DDL & reg number
397 /// method same as in RawWriter, not so nice
398 /// should be put in AliMUONTriggerCrateStore
403 sprintf(name,"%d", iReg+1);
413 sprintf(name,"%d", iReg);
417 // crate Right for first DDL