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 ////////////////////////////////////
18 /// MUON Digit maker from rawdata in ALICE-MUON
19 /// Using new interface with AliMUONRawStreamTracker(Trigger)
20 /// (New interface of AliMUONRawReader class)
21 /// Class version 1 (further details could be found in Alice-note)
23 /// Implemented non-constant buspatch numbers for tracking
24 /// with correct DDL id (first guess)
25 /// (Ch. Finck, dec 2005)
29 /// Using real mapping for tracker
30 /// Indranil Das (Adapted for runloader: Ch. Finck) july 05
31 /// Add reader for scaler trigger events
32 /// Use memcpy instead of assignment elt by elt
33 /// (Ch. Finck, Jan 06)
35 ////////////////////////////////////
40 #include <TClonesArray.h>
43 #include "AliRawReader.h"
44 #include "AliRawDataHeader.h"
48 #include "AliMpBusPatch.h"
50 #include "AliMUONDigitMaker.h"
51 #include "AliMUONDigit.h"
53 #include "AliMUONConstants.h"
54 #include "AliMUONData.h"
56 #include "AliMUONRawStreamTracker.h"
57 #include "AliMUONDDLTracker.h"
58 #include "AliMUONDspHeader.h"
59 #include "AliMUONBlockHeader.h"
60 #include "AliMUONBusStruct.h"
62 #include "AliMUONRawStreamTrigger.h"
63 #include "AliMUONDDLTrigger.h"
64 #include "AliMUONDarcHeader.h"
65 #include "AliMUONRegHeader.h"
66 #include "AliMUONLocalStruct.h"
68 #include "AliMUONTriggerCrateStore.h"
69 #include "AliMUONTriggerCrate.h"
70 #include "AliMUONLocalTriggerBoard.h"
71 #include "AliMUONLocalTrigger.h"
72 #include "AliMUONGlobalTrigger.h"
73 #include "AliMUONTriggerCircuitNew.h"
74 #include "AliMpSegFactory.h"
75 #include "AliMpVSegmentation.h"
77 #include "AliMpDEManager.h"
79 ClassImp(AliMUONDigitMaker) // Class implementation in ROOT context
80 //__________________________________________________________________________
81 AliMUONDigitMaker::AliMUONDigitMaker(Bool_t flag)
84 fSegFactory(new AliMpSegFactory()),
85 fBusPatchManager(new AliMpBusPatch()),
88 fRawStreamTracker(new AliMUONRawStreamTracker()),
89 fRawStreamTrigger(new AliMUONRawStreamTrigger()),
90 fDigit(new AliMUONDigit()),
91 fLocalTrigger(new AliMUONLocalTrigger()),
92 fGlobalTrigger(new AliMUONGlobalTrigger()),
93 fCrateManager(new AliMUONTriggerCrateStore()),
99 // ctor with AliMUONData as argument
100 // for reconstruction
105 // Standard Constructor
108 fBusPatchManager->ReadBusPatchFile();
111 fCrateManager->ReadFromFile();
113 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
114 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
115 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
119 //__________________________________________________________________________
120 AliMUONDigitMaker::~AliMUONDigitMaker()
124 // and time processing measure
128 delete fRawStreamTracker;
129 delete fRawStreamTrigger;
132 delete fLocalTrigger;
133 delete fGlobalTrigger;
135 delete fCrateManager;
137 delete fBusPatchManager;
139 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
140 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
141 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
143 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
144 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
145 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
150 //____________________________________________________________________
151 Int_t AliMUONDigitMaker::Raw2Digits(AliRawReader* rawReader)
153 // Main method to creates digit
158 ReadTrackerDDL(rawReader);
161 ReadTriggerDDL(rawReader);
167 //____________________________________________________________________
168 Int_t AliMUONDigitMaker::ReadTrackerDDL(AliRawReader* rawReader)
171 // reading tracker DDL
172 // filling the TClonesArray in MUONData
174 fTrackerTimer.Start(kFALSE);
186 AliMUONDDLTracker* ddlTracker = 0x0;
187 AliMUONBlockHeader* blkHeader = 0x0;
188 AliMUONDspHeader* dspHeader = 0x0;
189 AliMUONBusStruct* busStruct = 0x0;
192 fRawStreamTracker->SetReader(rawReader);
194 while(fRawStreamTracker->NextDDL()) {
196 ddlTracker = fRawStreamTracker->GetDDLTracker();
198 Int_t nBlock = ddlTracker->GetBlkHeaderEntries();
199 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
201 blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock);
203 Int_t nDsp = blkHeader->GetDspHeaderEntries();
205 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){ //DSP loop
207 dspHeader = blkHeader->GetDspHeaderEntry(iDsp);
209 Int_t nBusPatch = dspHeader->GetBusPatchEntries();
211 for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {
213 busStruct = dspHeader->GetBusPatchEntry(iBusPatch);
215 dataSize = busStruct->GetLength();
216 buspatchId = busStruct->GetBusPatchId();
218 for (Int_t iData = 0; iData < dataSize; iData++) {
221 parity = busStruct->GetParity(iData); // test later for parity
222 manuId = busStruct->GetManuId(iData);
223 channelId = busStruct->GetChannelId(iData);
224 charge = busStruct->GetCharge(iData);
226 fDigit->SetSignal(charge);
227 fDigit->SetPhysicsSignal(charge);
228 fDigit->SetADC(charge);
230 // Get Back the hits at pads
231 Int_t error = GetMapping(buspatchId,manuId,channelId,fDigit);
233 AliWarning("Mapping Error\n");
237 if (AliLog::GetGlobalDebugLevel() == 3) {
238 Int_t padX = fDigit->PadX();
239 Int_t padY = fDigit->PadY();
240 Int_t iCath = fDigit->Cathode();
241 Int_t idDE = fDigit->DetElemId();
243 AliDebug(1,Form("output IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n",
244 idDE, buspatchId, padX, padY, iCath));
246 AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d",
247 idDE, padX, padY, iCath, charge));
251 iChamber = fDigit->DetElemId()/100 - 1;
254 fMUONData->AddDigit(iChamber, *fDigit);
256 fMUONData->AddSDigit(iChamber, *fDigit);
265 fTrackerTimer.Stop();
269 //____________________________________________________________________
270 Int_t AliMUONDigitMaker::GetMapping(Int_t busPatchId, UShort_t manuId,
271 UChar_t channelId, AliMUONDigit* digit )
274 // mapping for tracker
276 fMappingTimer.Start(kFALSE);
278 // getting DE from buspatch
279 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
280 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
282 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
283 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
287 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
288 detElemId, busPatchId, manuId, channelId));
289 fMappingTimer.Stop();
293 // Getting padX, padY and cathode number.
294 Int_t padX = pad.GetIndices().GetFirst();
295 Int_t padY = pad.GetIndices().GetSecond();
296 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
298 // storing into digits
299 digit->SetPadX(padX);
300 digit->SetPadY(padY);
301 digit->SetCathode(iCath);
302 digit->SetDetElemId(detElemId);
303 digit->SetElectronics(manuId,channelId);
305 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
306 detElemId, busPatchId, manuId, channelId, padX, padY));
307 StdoutToAliDebug(3,digit->Print(););
309 fMappingTimer.Stop();
313 //____________________________________________________________________
314 Int_t AliMUONDigitMaker::ReadTriggerDDL(AliRawReader* rawReader)
316 // reading tracker DDL
317 // filling the TClonesArray in MUONData
320 AliMUONDDLTrigger* ddlTrigger = 0x0;
321 AliMUONDarcHeader* darcHeader = 0x0;
322 AliMUONRegHeader* regHeader = 0x0;
323 AliMUONLocalStruct* localStruct = 0x0;
329 fTriggerTimer.Start(kFALSE);
331 fRawStreamTrigger->SetReader(rawReader);
333 while(fRawStreamTrigger->NextDDL()) {
335 ddlTrigger = fRawStreamTrigger->GetDDLTrigger();
336 darcHeader = ddlTrigger->GetDarcHeader();
338 // fill global trigger information in Digit Tree
340 if (darcHeader->GetGlobalFlag()) {
341 fGlobalTrigger->SetFromGlobalResponse(darcHeader->GetGlobalOutput());
342 fMUONData->AddGlobalTrigger(*fGlobalTrigger);
346 Int_t nReg = darcHeader->GetRegHeaderEntries();
348 for(Int_t iReg = 0; iReg < nReg ;iReg++){ //reg loop
351 AliMUONTriggerCrate* crate = fCrateManager->Crate(fRawStreamTrigger->GetDDL(), iReg);
354 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, fRawStreamTrigger->GetDDL()));
356 TObjArray *boards = crate->Boards();
359 regHeader = darcHeader->GetRegHeaderEntry(iReg);
361 Int_t nLocal = regHeader->GetLocalEntries();
362 for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) {
364 localStruct = regHeader->GetLocalEntry(iLocal);
366 // if card has triggered
367 if (localStruct->GetTriggerY() == 0) {
370 AliMUONLocalTriggerBoard* localBoard =
371 (AliMUONLocalTriggerBoard*)boards->At(localStruct->GetId()+1);
373 loCircuit = localBoard->GetNumber();
376 // fill local trigger
377 fLocalTrigger->SetLocalStruct(loCircuit, *localStruct);
379 fMUONData->AddLocalTrigger(*fLocalTrigger);
386 if( TriggerDigits(localBoard, localStruct, digitList) ) {
388 for (Int_t iEntry = 0; iEntry < digitList.GetEntries(); iEntry++) {
390 AliMUONDigit* digit = (AliMUONDigit*)digitList.At(iEntry);
392 // filling S container
393 Int_t iChamber = digit->DetElemId()/100 - 1;
394 fMUONData->AddSDigit(iChamber, *digit);
406 fTriggerTimer.Stop();
411 //____________________________________________________________________
412 void AliMUONDigitMaker::GetTriggerChamber(AliMUONLocalStruct* localStruct, Int_t& xyPattern,
413 Int_t& iChamber, Int_t& iCath, Int_t icase)
416 // get chamber & cathode number
419 xyPattern = localStruct->GetX1();
424 xyPattern = localStruct->GetX2();
429 xyPattern = localStruct->GetX3();
434 xyPattern = localStruct->GetX4();
439 xyPattern = localStruct->GetY1();
444 xyPattern = localStruct->GetY2();
449 xyPattern = localStruct->GetY3();
454 xyPattern = localStruct->GetY4();
460 //____________________________________________________________________
461 Int_t AliMUONDigitMaker::TriggerDigits(AliMUONLocalTriggerBoard* localBoard,
462 AliMUONLocalStruct* localStruct,
466 // make (S)Digit for trigger
474 // loop over x1-4 and y1-4
475 for (Int_t icase = 0; icase < 8; icase++) {
477 // get chamber, cathode and associated trigger response pattern
478 GetTriggerChamber(localStruct, xyPattern, iChamber, iCath, icase);
480 if (!xyPattern) continue;
483 AliMUONTriggerCircuitNew triggerCircuit;
484 detElemId = triggerCircuit.DetElemId(iChamber, localBoard->GetName());
485 nBoard = localBoard->GetNumber();
487 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentation(detElemId, iCath);
489 // loop over the 16 bits of pattern
490 for (Int_t ibitxy = 0; ibitxy < 16; ibitxy++) {
492 if ((xyPattern >> ibitxy) & 0x1) {
494 // not quite sure about this
496 if (iCath && localBoard->GetSwitch(6)) offset = -8;
498 AliMpPad pad = seg->PadByLocation(AliMpIntPair(nBoard,ibitxy+offset),kTRUE);
500 AliMUONDigit* digit = new AliMUONDigit();
501 if (!pad.IsValid()) {
502 AliWarning(Form("No pad for detElemId: %d, nboard %d, ibitxy: %d\n",
503 detElemId, nBoard, ibitxy));
507 Int_t padX = pad.GetIndices().GetFirst();
508 Int_t padY = pad.GetIndices().GetSecond();
511 digit->SetPadX(padX);
512 digit->SetPadY(padY);
513 digit->SetCathode(iCath);
514 digit->SetDetElemId(detElemId);
515 digit->SetElectronics(nBoard, ibitxy);
516 digitList.Add(digit);
524 //____________________________________________________________________
525 void AliMUONDigitMaker::GetCrateName(Char_t* name, Int_t iDDL, Int_t iReg)
527 // set crate name from DDL & reg number
528 // method same as in RawWriter, not so nice
529 // should be put in AliMUONTriggerCrateStore
534 sprintf(name,"%d", iReg+1);
544 sprintf(name,"%d", iReg);
548 // crate Right for first DDL