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)
79 // 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()
150 delete fBusPatchManager;
152 AliInfo(Form("Execution time for MUON tracker : R:%.2fs C:%.2fs",
153 fTrackerTimer.RealTime(),fTrackerTimer.CpuTime()));
154 AliInfo(Form(" Execution time for MUON tracker (mapping calls part) "
156 fMappingTimer.RealTime(),fMappingTimer.CpuTime()));
157 AliInfo(Form("Execution time for MUON trigger : R:%.2fs C:%.2fs",
158 fTriggerTimer.RealTime(),fTriggerTimer.CpuTime()));
162 //____________________________________________________________________
163 Int_t AliMUONRawReader::Raw2Digits(AliRawReader* rawReader)
167 ReadTrackerDDL(rawReader);
170 ReadTriggerDDL(rawReader);
176 //____________________________________________________________________
177 Int_t AliMUONRawReader::ReadTrackerDDL(AliRawReader* rawReader)
179 // reading tracker DDL
180 // filling the TClonesArray in MUONData
182 fTrackerTimer.Start(kFALSE);
184 AliMUONSubEventTracker* subEventTracker = new AliMUONSubEventTracker();
185 AliMUONDigit* digit = new AliMUONDigit();
188 //Read Header Size of DDL,Block,DSP and BusPatch (put k before constant imb'cile)
190 Int_t kDDLHeaderSize = fDDLTracker->GetHeaderSize();
191 Int_t kBlockHeaderSize = fDDLTracker->GetBlkHeaderLength();
192 Int_t kDspHeaderSize = fDDLTracker->GetDspHeaderLength();
193 Int_t kBusPatchHeaderSize = subEventTracker->GetHeaderLength();
195 Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize;
198 Int_t iBusPerDSP[5];//number of bus patches per DSP
199 Int_t iDspMax; //number max of DSP per block
201 // minimum data size (only header's)
203 Int_t blankBlockSize;
206 for(Int_t iDDL = 0; iDDL < 20; iDDL++) { // DDL loop
208 AliDebug(3, Form("Chamber %d\n", iDDL/2 +1 ));
211 fBusPatchManager->GetDspInfo(iDDL/2, iDspMax, iBusPerDSP);
213 // 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.
214 // This information is used to calculate the size of headers (DDL,Block and DSP) which has no interesting data.
215 blankDDLSize = kDDLHeaderSize + 2*kBlockHeaderSize + 2*iDspMax*kDspHeaderSize;
216 blankBlockSize = kBlockHeaderSize + iDspMax*kDspHeaderSize;
218 for (Int_t i = 0; i < iDspMax; i++) {
219 blankDDLSize += 2*iBusPerDSP[i]*kBusPatchHeaderSize;
220 blankBlockSize += iBusPerDSP[i]*kBusPatchHeaderSize;
223 rawReader->Select(0X9, iDDL, iDDL); //Select the DDL file to be read
225 rawReader->ReadHeader();
227 totalDDLSize = (rawReader->GetDataSize() + sizeof(AliRawDataHeader))/4; // 4 is multiplied to convert byte 2 words
229 if(totalDDLSize > blankDDLSize) { // Compare the DDL header with an empty DDL header size to read the file
231 Int_t totalDataWord = rawReader->GetDataSize(); // in bytes
232 UInt_t *buffer = new UInt_t[totalDataWord/4];
234 rawReader->ReadNext((UChar_t*)buffer, totalDataWord);
248 for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){ // loop over 2 blocks
249 totalBlockSize = buffer[index];
251 if(totalBlockSize > blankBlockSize) { // compare block header
252 index += kBlockHeaderSize;
254 for(Int_t iDsp = 0; iDsp < iDspMax ;iDsp++){ //DSP loop
256 totalDspSize = buffer[index];
259 blankDspSize = kDspHeaderSize + iBusPerDSP[iDsp]*kBusPatchHeaderSize; // no data just header
261 if(totalDspSize > blankDspSize) { // Compare DSP Header
262 index += kDspHeaderSize;
264 for(Int_t iBusPatch = 0; iBusPatch < iBusPerDSP[iDsp]; iBusPatch++) {
266 //copy buffer into header structure
267 memcpy(subEventTracker->GetBusPatchHeader(), &buffer[index], kBusPatchHeaderSize*4);
269 totalBusPatchSize = subEventTracker->GetTotalLength();
270 buspatchId = subEventTracker->GetBusPatchId();
271 indexBusPatch = index;
274 if(totalBusPatchSize > kBusPatchHeaderSize) { //Check Buspatch header, not empty events
276 index += kBusPatchHeaderSize;
277 dataSize = subEventTracker->GetLength();
278 Int_t bufSize = subEventTracker->GetBufSize();
280 if(dataSize>0) { // check data present
281 if (dataSize > bufSize) subEventTracker->SetAlloc(dataSize);
283 //copy buffer into data structure
284 memcpy(subEventTracker->GetData(), &buffer[index], dataSize*4);
287 for(Int_t iData = 0; iData < dataSize; iData++) {
290 parity = subEventTracker->GetParity(iData); // test later for parity
291 manuId = subEventTracker->GetManuId(iData);
292 channelId = subEventTracker->GetChannelId(iData);
293 charge = subEventTracker->GetCharge(iData);
296 digit->SetSignal(charge);
297 digit->SetPhysicsSignal(charge);
298 digit->SetADC(charge);
299 Int_t error = GetMapping(buspatchId,manuId,channelId,digit); // Get Back the hits at pads
303 if (AliLog::GetGlobalDebugLevel() == 3) {
304 Int_t padX = digit->PadX();
305 Int_t padY = digit->PadY();
306 Int_t iCath = digit->Cathode();
307 Int_t detElemId = digit->DetElemId();
309 AliDebug(1,Form("output detElemId %d busPatchid %d PadX %d PadY %d iCath %d \n",
310 detElemId, buspatchId, padX, padY, iCath));
312 AliDebug(3,Form("detElemId %d Padx %d Pady %d, Cath %d, charge %d",detElemId, padX, padY, iCath, charge));
316 fMUONData->AddDigit(iDDL/2, *digit);
320 } // testing buspatch
322 index = indexBusPatch + totalBusPatchSize;
328 index = indexDsp + totalDspSize;
334 index = totalBlockSize;
339 } //loop checking the header size of DDL
345 delete subEventTracker;
348 fTrackerTimer.Stop();
353 //____________________________________________________________________
354 Int_t AliMUONRawReader::GetMapping(Int_t busPatchId, UShort_t manuId,
355 UChar_t channelId, AliMUONDigit* digit )
358 // mapping for tracker
360 fMappingTimer.Start(kFALSE);
362 // getting DE from buspatch
363 Int_t detElemId = fBusPatchManager->GetDEfromBus(busPatchId);
364 AliDebug(3,Form("detElemId: %d busPatchId %d\n", detElemId, busPatchId));
366 AliMpVSegmentation* seg = fSegFactory->CreateMpSegmentationByElectronics(detElemId, manuId);
367 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,channelId),kTRUE);
371 AliWarning(Form("No pad for detElemId: %d, busPatchId %d, manuId: %d, channelId: %d\n",
372 detElemId, busPatchId, manuId, channelId));
373 fMappingTimer.Stop();
377 // Getting padX, padY and cathode number.
378 Int_t padX = pad.GetIndices().GetFirst();
379 Int_t padY = pad.GetIndices().GetSecond();
380 Int_t iCath = AliMpDEManager::GetCathod(detElemId,seg->PlaneType());
382 // storing into digits
383 digit->SetPadX(padX);
384 digit->SetPadY(padY);
385 digit->SetCathode(iCath);
386 digit->SetDetElemId(detElemId);
387 digit->SetElectronics(manuId,channelId);
389 AliDebug(3,Form("detElemId: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
390 detElemId, busPatchId, manuId, channelId, padX, padY));
391 StdoutToAliDebug(3,digit->Print(););
393 fMappingTimer.Stop();
397 //____________________________________________________________________
398 Int_t AliMUONRawReader::ReadTriggerDDL(AliRawReader* rawReader)
401 // reading DDL for trigger
403 fTriggerTimer.Start(kFALSE);
405 AliMUONSubEventTrigger* subEventTrigger = new AliMUONSubEventTrigger();
406 AliMUONScalerEventTrigger* scalerEvent = 0x0;
408 AliMUONGlobalTrigger* globalTrigger = 0x0;
409 AliMUONLocalTrigger* localTrigger = new AliMUONLocalTrigger();
412 //Int_t kDDLHeaderSize = fDDLTrigger->GetHeaderSize();
413 // we dont need this, as size of ddl data is same for triger and no trigger
415 Int_t kDDLEnhanceHeaderSize = fDDLTrigger->GetHeaderLength();
416 Int_t kRegHeaderSize = subEventTrigger->GetRegHeaderLength() ;
418 Int_t loCircuit, loStripX, loDev, loStripY, loLpt, loHpt;
421 UShort_t x1Pattern, x2Pattern, x3Pattern, x4Pattern;
422 UShort_t y1Pattern, y2Pattern, y3Pattern, y4Pattern;
424 // loop over the two ddl's
425 for(Int_t iDDL = 0; iDDL < 2; iDDL++) { //DDL loop
428 rawReader->Select(0XA,iDDL,iDDL); //Select the DDL file to be read
430 rawReader->ReadHeader();
432 Int_t totalDataWord = rawReader->GetDataSize(); // in bytes
433 UInt_t *buffer = new UInt_t[totalDataWord/4];
435 rawReader->ReadNext((UChar_t*)buffer, totalDataWord);
438 fDDLTrigger->SetDDLWord(buffer[index++]);
440 if(fDDLTrigger->GetEventType() == 2) {
441 fScalerEvent = kTRUE;
442 scalerEvent = new AliMUONScalerEventTrigger();
444 fScalerEvent = kFALSE;
447 // 6 DARC scaler words
448 memcpy(scalerEvent->GetDarcScalers(), &buffer[index], scalerEvent->GetDarcScalerLength()*4);
449 index += scalerEvent->GetDarcScalerLength();
452 // 4 words of global board input + Global board output
453 memcpy(fDDLTrigger->GetGlobalInput(), &buffer[index], (kDDLEnhanceHeaderSize-1)*4);
454 index += kDDLEnhanceHeaderSize - 1; // kind tricky cos scaler info in-between Darc header
457 // 10 Global scaler words
458 memcpy(scalerEvent->GetGlobalScalers(), &buffer[index], scalerEvent->GetGlobalScalerLength()*4);
459 index += scalerEvent->GetGlobalScalerLength();
462 // fill global trigger information
463 globalTrigger = GetGlobalTriggerPattern(fDDLTrigger->GetGlobalOuput());
464 fMUONData->AddGlobalTrigger(*globalTrigger);
467 for (Int_t iReg = 0; iReg < 8; iReg++) { //loop over regeonal card
469 memcpy(subEventTrigger->GetRegHeader(), &buffer[index], kRegHeaderSize*4);
470 index += kRegHeaderSize;
472 // 11 regional scaler word
474 memcpy(scalerEvent->GetRegScalers(), &buffer[index], scalerEvent->GetRegScalerLength()*4);
475 index += scalerEvent->GetRegScalerLength();
478 // 16 local cards per regional board
479 for (Int_t iLoc = 0; iLoc < 16; iLoc++) { //loop over local card
481 Int_t iLocIndex = index;
483 // 5 word trigger information
484 for(Int_t iData = 0; iData < 5 ;iData++ ){
485 subEventTrigger->SetLocalData(buffer[index++],5*iLoc+iData); //read local data
488 if(buffer[iLocIndex] > 0) {
490 loCircuit = (Int_t)subEventTrigger->GetLocalId(iLoc)+ 16*iReg + 128*iDDL;
491 loStripX = (Int_t)subEventTrigger->GetXPos(iLoc);
492 loStripY = (Int_t)subEventTrigger->GetYPos(iLoc);
493 loDev = (Int_t)subEventTrigger->GetXDev(iLoc);
495 // fill local trigger
496 localTrigger->SetLoCircuit(loCircuit);
497 localTrigger->SetLoStripX(loStripX );
498 localTrigger->SetLoStripY(loStripY);
499 localTrigger->SetLoDev(loDev);
501 loDecision = subEventTrigger->GetLocalDec(iLoc);
502 loLpt = loDecision & 0x3;
503 loHpt = (loDecision >> 2) & 0x3;
505 // fill local trigger
506 localTrigger->SetLoLpt(loLpt);
507 localTrigger->SetLoHpt(loHpt);
509 //getting pattern from subvent
510 x1Pattern = subEventTrigger->GetX1(iLoc);
511 x2Pattern = subEventTrigger->GetX2(iLoc);
512 x3Pattern = subEventTrigger->GetX3(iLoc);
513 x4Pattern = subEventTrigger->GetX4(iLoc);
515 y1Pattern = subEventTrigger->GetY1(iLoc);
516 y2Pattern = subEventTrigger->GetY2(iLoc);
517 y3Pattern = subEventTrigger->GetY3(iLoc);
518 y4Pattern = subEventTrigger->GetY4(iLoc);
520 // fill local trigger
521 localTrigger->SetX1Pattern(x1Pattern);
522 localTrigger->SetX2Pattern(x2Pattern);
523 localTrigger->SetX3Pattern(x3Pattern);
524 localTrigger->SetX4Pattern(x4Pattern);
526 localTrigger->SetY1Pattern(y1Pattern);
527 localTrigger->SetY2Pattern(y2Pattern);
528 localTrigger->SetY3Pattern(y3Pattern);
529 localTrigger->SetY4Pattern(y4Pattern);
530 fMUONData->AddLocalTrigger(*localTrigger);
534 // 45 regional scaler word
536 memcpy(scalerEvent->GetLocalScalers(), &buffer[index], scalerEvent->GetLocalScalerLength()*4);
537 index += scalerEvent->GetLocalScalerLength();
542 } // regional card loop
547 delete subEventTrigger;
548 delete globalTrigger;
553 fTriggerTimer.Stop();
557 //____________________________________________________________________
558 AliMUONGlobalTrigger* AliMUONRawReader::GetGlobalTriggerPattern(Int_t gloTrigPat) const
560 // global trigger pattern calculation
562 Int_t globalSinglePlus[3]; // tot num of single plus
563 Int_t globalSingleMinus[3]; // tot num of single minus
564 Int_t globalSingleUndef[3]; // tot num of single undefined
565 Int_t globalPairUnlike[3]; // tot num of unlike-sign pairs
566 Int_t globalPairLike[3]; // tot num of like-sign pairs
569 for (Int_t i = 0; i < 3; i++) {
571 globalSinglePlus[i] = (gloTrigPat >> i) & 0x1;
572 globalSingleMinus[i] = (gloTrigPat >> (i+3)) & 0x1;
573 globalSingleUndef[i] = (gloTrigPat >> (i+6)) & 0x1;
574 globalPairUnlike[i] = (gloTrigPat >> (i+9)) & 0x1;
575 globalPairLike[i] = (gloTrigPat >> (i+12)) & 0x1;
578 return (new AliMUONGlobalTrigger(globalSinglePlus, globalSingleMinus,
579 globalSingleUndef, globalPairUnlike,