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 Raw Data reader in ALICE-MUON
19 // Class version 3 (further details could be found in Alice-note)
21 // Implemented non-constant buspatch numbers for tracking
22 // with correct DDL id (first guess)
23 // (Ch. Finck, dec 2005)
27 // Using real mapping for tracker
28 // Indranil Das (Adapted for runloader: Ch. Finck) july 05
29 // Add reader for scaler trigger events
30 // Use memcpy instead of assignment elt by elt
31 // (Ch. Finck, Jan 06)
33 ////////////////////////////////////
38 #include <TClonesArray.h>
40 #include "AliBitPacking.h"
41 #include "AliRawReader.h"
45 #include "AliMpBusPatch.h"
48 #include "AliMUONRawReader.h"
49 #include "AliMUONDigit.h"
51 #include "AliMUONConstants.h"
52 #include "AliMUONData.h"
54 #include "AliMUONSubEventTracker.h"
55 #include "AliMUONScalerEventTrigger.h"
56 #include "AliMUONSubEventTrigger.h"
57 #include "AliMUONDDLTracker.h"
58 #include "AliMUONDDLTrigger.h"
60 #include "AliMUONLocalTrigger.h"
61 #include "AliMUONGlobalTrigger.h"
63 #include "AliMUONGeometrySegmentation.h"
64 #include "AliMUONGeometryModule.h"
65 #include "AliMUONGeometryStore.h"
66 #include "AliMpSegFactory.h"
67 #include "AliMpPlaneType.h"
68 #include "AliMpVSegmentation.h"
69 #include "AliMpHelper.h"
71 #include "AliMpDEManager.h"
73 ClassImp(AliMUONRawReader) // Class implementation in ROOT context
74 //__________________________________________________________________________
75 AliMUONRawReader::AliMUONRawReader(AliMUONData* data)
81 // Standard Constructor
83 // initialize segmentation factory
84 fSegFactory = new AliMpSegFactory();
86 // initialize container
90 fDDLTracker = new AliMUONDDLTracker();
91 fDDLTrigger = new AliMUONDDLTrigger();
93 fBusPatchManager = new AliMpBusPatch();
94 fBusPatchManager->ReadBusPatchFile();
96 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
97 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
98 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
101 //__________________________________________________________________________
102 AliMUONRawReader::AliMUONRawReader()
111 // Default Constructor
113 fTrackerTimer.Start(kTRUE); fTrackerTimer.Stop();
114 fTriggerTimer.Start(kTRUE); fTriggerTimer.Stop();
115 fMappingTimer.Start(kTRUE); fMappingTimer.Stop();
118 //_______________________________________________________________________
119 AliMUONRawReader::AliMUONRawReader (const AliMUONRawReader& rhs)
122 // Protected copy constructor
124 AliFatal("Not implemented.");
127 //_______________________________________________________________________
129 AliMUONRawReader::operator=(const AliMUONRawReader& rhs)
131 // Protected assignement operator
133 if (this == &rhs) return *this;
135 AliFatal("Not implemented.");
140 //__________________________________________________________________________
141 AliMUONRawReader::~AliMUONRawReader()
148 delete fBusPatchManager;
150 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
151 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
152 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
154 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
155 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
156 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
160 //____________________________________________________________________
161 Int_t AliMUONRawReader::Raw2Digits(AliRawReader* rawReader)
165 ReadTrackerDDL(rawReader);
168 ReadTriggerDDL(rawReader);
174 //____________________________________________________________________
175 Int_t AliMUONRawReader::ReadTrackerDDL(AliRawReader* rawReader)
177 // reading tracker DDL
178 // filling the TClonesArray in MUONData
180 fTrackerTimer.Start(kFALSE);
182 AliMUONSubEventTracker* subEventTracker = new AliMUONSubEventTracker();
183 AliMUONDigit* digit = new AliMUONDigit();
186 //Read Header Size of DDL,Block,DSP and BusPatch (put k before constant imb'cile)
188 Int_t kDDLHeaderSize = fDDLTracker->GetHeaderSize();
189 Int_t kBlockHeaderSize = fDDLTracker->GetBlkHeaderLength();
190 Int_t kDspHeaderSize = fDDLTracker->GetDspHeaderLength();
191 Int_t kBusPatchHeaderSize = subEventTracker->GetHeaderLength();
193 Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize;
196 Int_t iBusPerDSP[5];//number of bus patches per DSP
197 Int_t iDspMax; //number max of DSP per block
199 // minimum data size (only header's)
201 Int_t blankBlockSize;
204 for(Int_t iDDL = 0; iDDL < 20; iDDL++) { // DDL loop
206 AliDebug(3, Form("Chamber %d\n", iDDL/2 +1 ));
209 fBusPatchManager->GetDspInfo(iDDL/2, iDspMax, iBusPerDSP);
211 // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most and each of DSP has at most 5 buspatches.
212 // This information is used to calculate the size of headers (DDL,Block and DSP) which has no interesting data.
213 blankDDLSize = kDDLHeaderSize + 2*kBlockHeaderSize + 2*iDspMax*kDspHeaderSize;
214 blankBlockSize = kBlockHeaderSize + iDspMax*kDspHeaderSize;
216 for (Int_t i = 0; i < iDspMax; i++) {
217 blankDDLSize += 2*iBusPerDSP[i]*kBusPatchHeaderSize;
218 blankBlockSize += iBusPerDSP[i]*kBusPatchHeaderSize;
221 rawReader->Select(0X9, iDDL, iDDL); //Select the DDL file to be read
223 rawReader->ReadHeader();
225 totalDDLSize = (rawReader->GetDataSize() + sizeof(AliRawDataHeader))/4; // 4 is multiplied to convert byte 2 words
227 if(totalDDLSize > blankDDLSize) { // Compare the DDL header with an empty DDL header size to read the file
229 Int_t totalDataWord = rawReader->GetDataSize(); // in bytes
230 UInt_t *buffer = new UInt_t[totalDataWord/4];
232 rawReader->ReadNext((UChar_t*)buffer, totalDataWord);
246 for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){ // loop over 2 blocks
247 totalBlockSize = buffer[index];
249 if(totalBlockSize > blankBlockSize) { // compare block header
250 index += kBlockHeaderSize;
252 for(Int_t iDsp = 0; iDsp < iDspMax ;iDsp++){ //DSP loop
254 totalDspSize = buffer[index];
257 blankDspSize = kDspHeaderSize + iBusPerDSP[iDsp]*kBusPatchHeaderSize; // no data just header
259 if(totalDspSize > blankDspSize) { // Compare DSP Header
260 index += kDspHeaderSize;
262 for(Int_t iBusPatch = 0; iBusPatch < iBusPerDSP[iDsp]; iBusPatch++) {
264 //copy buffer into header structure
265 memcpy(subEventTracker->GetBusPatchHeader(), &buffer[index], kBusPatchHeaderSize*4);
267 totalBusPatchSize = subEventTracker->GetTotalLength();
268 buspatchId = subEventTracker->GetBusPatchId();
269 indexBusPatch = index;
272 if(totalBusPatchSize > kBusPatchHeaderSize) { //Check Buspatch header, not empty events
274 index += kBusPatchHeaderSize;
275 dataSize = subEventTracker->GetLength();
277 if(dataSize>0) { // check data present
279 //copy buffer into data structure
280 memcpy(subEventTracker->GetData(), &buffer[index], dataSize*4);
283 for(Int_t iData = 0; iData < dataSize; iData++) {
286 parity = subEventTracker->GetParity(iData); // test later for parity
287 manuId = subEventTracker->GetManuId(iData);
288 channelId = subEventTracker->GetChannelId(iData);
289 charge = subEventTracker->GetCharge(iData);
291 digit->SetSignal(charge);
292 digit->SetPhysicsSignal(charge);
293 digit->SetADC(charge);
294 Int_t error = GetMapping(buspatchId,manuId,channelId,digit); // Get Back the hits at pads
298 if (AliLog::GetGlobalDebugLevel() == 3) {
299 Int_t padX = digit->PadX();
300 Int_t padY = digit->PadY();
301 Int_t iCath = digit->Cathode();
302 Int_t detElemId = digit->DetElemId();
304 AliDebug(1,Form("output detElemId %d busPatchid %d PadX %d PadY %d iCath %d \n",
305 detElemId, buspatchId, padX, padY, iCath));
307 AliDebug(3,Form("detElemId %d Padx %d Pady %d, Cath %d, charge %d",detElemId, padX, padY, iCath, charge));
311 fMUONData->AddDigit(iDDL/2, *digit);
315 } // testing buspatch
317 index = indexBusPatch + totalBusPatchSize;
323 index = indexDsp + totalDspSize;
329 index = totalBlockSize;
334 } //loop checking the header size of DDL
340 delete subEventTracker;
343 fTrackerTimer.Stop();
348 //____________________________________________________________________
349 Int_t AliMUONRawReader::GetMapping(Int_t busPatchId, UShort_t manuId,
350 UChar_t channelId, AliMUONDigit* digit )
353 // mapping for tracker
355 fMappingTimer.Start(kFALSE);
357 // getting DE from buspatch
358 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
359 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
361 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
362 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
366 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
367 detElemId, busPatchId, manuId, channelId));
368 fMappingTimer.Stop();
372 // Getting padX, padY and cathode number.
373 Int_t padX = pad.GetIndices().GetFirst();
374 Int_t padY = pad.GetIndices().GetSecond();
375 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
377 // storing into digits
378 digit->SetPadX(padX);
379 digit->SetPadY(padY);
380 digit->SetCathode(iCath);
381 digit->SetDetElemId(detElemId);
382 digit->SetElectronics(manuId,channelId);
384 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
385 detElemId, busPatchId, manuId, channelId, padX, padY));
386 StdoutToAliDebug(3,digit->Print(););
388 fMappingTimer.Stop();
392 //____________________________________________________________________
393 Int_t AliMUONRawReader::ReadTriggerDDL(AliRawReader* rawReader)
396 // reading DDL for trigger
398 fTriggerTimer.Start(kFALSE);
400 AliMUONSubEventTrigger* subEventTrigger = new AliMUONSubEventTrigger();
401 AliMUONScalerEventTrigger* scalerEvent = 0x0;
403 AliMUONGlobalTrigger* globalTrigger = 0x0;
404 AliMUONLocalTrigger* localTrigger = new AliMUONLocalTrigger();
407 //Int_t kDDLHeaderSize = fDDLTrigger->GetHeaderSize();
408 // we dont need this, as size of ddl data is same for triger and no trigger
410 Int_t kDDLEnhanceHeaderSize = fDDLTrigger->GetHeaderLength();
411 Int_t kRegHeaderSize = subEventTrigger->GetRegHeaderLength() ;
413 Int_t loCircuit, loStripX, loDev, loStripY, loLpt, loHpt;
416 UShort_t x1Pattern, x2Pattern, x3Pattern, x4Pattern;
417 UShort_t y1Pattern, y2Pattern, y3Pattern, y4Pattern;
419 // loop over the two ddl's
420 for(Int_t iDDL = 0; iDDL < 2; iDDL++) { //DDL loop
422 rawReader->Select(0XA,iDDL,iDDL); //Select the DDL file to be read
424 rawReader->ReadHeader();
426 Int_t totalDataWord = rawReader->GetDataSize(); // in bytes
427 UInt_t *buffer = new UInt_t[totalDataWord/4];
429 rawReader->ReadNext((UChar_t*)buffer, totalDataWord);
432 fDDLTrigger->SetDDLWord(buffer[index++]);
434 if(fDDLTrigger->GetEventType() == 2) {
435 fScalerEvent = kTRUE;
436 scalerEvent = new AliMUONScalerEventTrigger();
438 fScalerEvent = kFALSE;
441 // 6 DARC scaler words
442 memcpy(scalerEvent->GetDarcScalers(), &buffer[index], scalerEvent->GetDarcScalerLength()*4);
443 index += scalerEvent->GetDarcScalerLength();
446 // 4 words of global board input + Global board output
447 memcpy(fDDLTrigger->GetGlobalInput(), &buffer[index], (kDDLEnhanceHeaderSize-1)*4);
448 index += kDDLEnhanceHeaderSize - 1; // kind tricky cos scaler info in-between Darc header
451 // 10 Global scaler words
452 memcpy(scalerEvent->GetGlobalScalers(), &buffer[index], scalerEvent->GetGlobalScalerLength()*4);
453 index += scalerEvent->GetGlobalScalerLength();
456 // fill global trigger information
457 globalTrigger = GetGlobalTriggerPattern(fDDLTrigger->GetGlobalOuput());
458 fMUONData->AddGlobalTrigger(*globalTrigger);
461 for (Int_t iReg = 0; iReg < 8; iReg++) { //loop over regeonal card
463 memcpy(subEventTrigger->GetRegHeader(), &buffer[index], kRegHeaderSize*4);
464 index += kRegHeaderSize;
466 // 11 regional scaler word
468 memcpy(scalerEvent->GetRegScalers(), &buffer[index], scalerEvent->GetRegScalerLength()*4);
469 index += scalerEvent->GetRegScalerLength();
472 // 16 local cards per regional board
473 for (Int_t iLoc = 0; iLoc < 16; iLoc++) { //loop over local card
475 Int_t iLocIndex = index;
477 // 5 word trigger information
478 for(Int_t iData = 0; iData < 5 ;iData++ ){
479 subEventTrigger->SetLocalData(buffer[index++],5*iLoc+iData); //read local data
482 if(buffer[iLocIndex] > 0) {
484 loCircuit = (Int_t)subEventTrigger->GetLocalId(iLoc)+ 16*iReg + 128*iDDL;
485 loStripX = (Int_t)subEventTrigger->GetXPos(iLoc);
486 loStripY = (Int_t)subEventTrigger->GetYPos(iLoc);
487 loDev = (Int_t)subEventTrigger->GetXDev(iLoc);
489 // fill local trigger
490 localTrigger->SetLoCircuit(loCircuit);
491 localTrigger->SetLoStripX(loStripX );
492 localTrigger->SetLoStripY(loStripY);
493 localTrigger->SetLoDev(loDev);
495 loDecision = subEventTrigger->GetLocalDec(iLoc);
496 loLpt = loDecision & 0x3;
497 loHpt = (loDecision >> 2) & 0x3;
499 // fill local trigger
500 localTrigger->SetLoLpt(loLpt);
501 localTrigger->SetLoHpt(loHpt);
503 //getting pattern from subvent
504 x1Pattern = subEventTrigger->GetX1(iLoc);
505 x2Pattern = subEventTrigger->GetX2(iLoc);
506 x3Pattern = subEventTrigger->GetX3(iLoc);
507 x4Pattern = subEventTrigger->GetX4(iLoc);
509 y1Pattern = subEventTrigger->GetY1(iLoc);
510 y2Pattern = subEventTrigger->GetY2(iLoc);
511 y3Pattern = subEventTrigger->GetY3(iLoc);
512 y4Pattern = subEventTrigger->GetY4(iLoc);
514 // fill local trigger
515 localTrigger->SetX1Pattern(x1Pattern);
516 localTrigger->SetX2Pattern(x2Pattern);
517 localTrigger->SetX3Pattern(x3Pattern);
518 localTrigger->SetX4Pattern(x4Pattern);
520 localTrigger->SetY1Pattern(y1Pattern);
521 localTrigger->SetY2Pattern(y2Pattern);
522 localTrigger->SetY3Pattern(y3Pattern);
523 localTrigger->SetY4Pattern(y4Pattern);
524 fMUONData->AddLocalTrigger(*localTrigger);
528 // 45 regional scaler word
530 memcpy(scalerEvent->GetLocalScalers(), &buffer[index], scalerEvent->GetLocalScalerLength()*4);
531 index += scalerEvent->GetLocalScalerLength();
536 } // regional card loop
541 delete subEventTrigger;
542 delete globalTrigger;
547 fTriggerTimer.Stop();
551 //____________________________________________________________________
552 AliMUONGlobalTrigger* AliMUONRawReader::GetGlobalTriggerPattern(Int_t gloTrigPat) const
554 // global trigger pattern calculation
556 Int_t globalSinglePlus[3]; // tot num of single plus
557 Int_t globalSingleMinus[3]; // tot num of single minus
558 Int_t globalSingleUndef[3]; // tot num of single undefined
559 Int_t globalPairUnlike[3]; // tot num of unlike-sign pairs
560 Int_t globalPairLike[3]; // tot num of like-sign pairs
563 for (Int_t i = 0; i < 3; i++) {
565 globalSinglePlus[i] = (gloTrigPat >> i) & 0x1;
566 globalSingleMinus[i] = (gloTrigPat >> (i+3)) & 0x1;
567 globalSingleUndef[i] = (gloTrigPat >> (i+6)) & 0x1;
568 globalPairUnlike[i] = (gloTrigPat >> (i+9)) & 0x1;
569 globalPairLike[i] = (gloTrigPat >> (i+12)) & 0x1;
572 return (new AliMUONGlobalTrigger(globalSinglePlus, globalSingleMinus,
573 globalSingleUndef, globalPairUnlike,