]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONRawData.cxx
Updated for replacement of AliMpReader with AliMpSectorReader
[u/mrichter/AliRoot.git] / MUON / AliMUONRawData.cxx
index d024f21591a0e73b19a75d51dc84fa90c8feef4c..ba7ef6d5805a9b52c7a442aa617c1fe09a1d8bf6 100644 (file)
 
 ////////////////////////////////////
 //
-// MUON Raw Data generator in ALICE-MUON
-//
-// This class version 1 (further details could be found in Alice-note coming soon right in our direction)
+// MUON Raw Data generator and reader in ALICE-MUON
+// This class version 1 (further details could be found in Alice-note)
+// Digits2Raw:
 // Generates raw data for MUON tracker and finally for trigger
 // * a simple mapping is used (see below)
 // * the bus patch id is calculated with an absolute number 0 - 999
 // * one DDL per 1/2 chamber is created for both cathode.
 // For trigger there is no mapping (mapping could be found in AliMUONTriggerCircuit)
-// don't need for digits2raw but needed in raw2Reco
-// the position are given per local card
+// Ch. Finck july 04
+// Raw2Digits:
+// Using still dummy mapping (inverse) for tracker
+// Indranil Das (Adapted for runloader: Ch. Finck) july 05
 ////////////////////////////////////
 
 #include <TClonesArray.h>
 #include "AliMUONRawData.h"
 #include "AliMUONDigit.h"
-#include "AliMUONTriggerDecision.h"
+
+#include "AliMUON.h"
+#include "AliMUONChamber.h"
 #include "AliMUONConstants.h"
 #include "AliMUONData.h"
-#include "AliRun.h" 
-#include "AliRunLoader.h"
 #include "AliLoader.h"
 #include "AliBitPacking.h" 
+#include "AliRawReader.h"
+
+#include "AliMUONSubEventTrigger.h"
 #include "AliMUONDDLTracker.h"
 #include "AliMUONDDLTrigger.h"
 
-#include "AliMUON.h"
 #include "AliMUONLocalTrigger.h"
 #include "AliMUONGlobalTrigger.h"
-#include "AliMUONTriggerCircuit.h"
 
-const Int_t AliMUONRawData::fgkDefaultPrintLevel = 0;
+#include "AliMUONGeometrySegmentation.h"
+#include "AliLog.h"
+#include "AliRun.h"
+
 
-ClassImp(AliMUONRawData) // Class implementation in ROOT context
 
+ClassImp(AliMUONRawData) // Class implementation in ROOT context
 //__________________________________________________________________________
-AliMUONRawData::AliMUONRawData(AliLoader* loader)
-  : TObject(),
-    fDebug(0)
+  AliMUONRawData::AliMUONRawData(AliLoader* loader)
+  : TObject()
 {
   // Standard Constructor
  
-  fPrintLevel = fgkDefaultPrintLevel;
-
   // initialize loader's
   fLoader = loader;
 
   // initialize container
   fMUONData  = new AliMUONData(fLoader,"MUON","MUON");
 
-  // trigger decision, temp solution, local & global has to move to Digits Tree
-//   fTrigDec = new AliMUONTriggerDecision(fLoader);
-//   fTrigData = fTrigDec->GetMUONData();
-
   // initialize array
   fSubEventArray[0] = new TClonesArray("AliMUONSubEventTracker",1000);
   fSubEventArray[1] = new TClonesArray("AliMUONSubEventTracker",1000);
 
-  // initialize array
-  fSubEventTrigArray[0] = new TClonesArray("AliMUONSubEventTrigger",1000);
-  fSubEventTrigArray[1] = new TClonesArray("AliMUONSubEventTrigger",1000);
 
   // ddl pointer
   fDDLTracker = new AliMUONDDLTracker();
-  fDDLTrigger= new  AliMUONDDLTrigger();
+  fDDLTrigger = new AliMUONDDLTrigger();
 }
 
 //__________________________________________________________________________
 AliMUONRawData::AliMUONRawData()
   : TObject(),
     fMUONData(0),
-    fPrintLevel(fgkDefaultPrintLevel),
-    fDebug(0),
-    fLoader(0)
+    fLoader(0),
+    fFile1(0x0),
+    fFile2(0x0),
+    fDDLTracker(0),
+    fDDLTrigger(0)
+
 {
   // Default Constructor
 }
@@ -98,7 +97,7 @@ AliMUONRawData::AliMUONRawData (const AliMUONRawData& rhs)
 {
 // Protected copy constructor
 
-  Fatal("AliMUONRawData", "Not implemented.");
+  AliFatal("Not implemented.");
 }
 
 //_______________________________________________________________________
@@ -109,7 +108,7 @@ AliMUONRawData::operator=(const AliMUONRawData& rhs)
 
   if (this == &rhs) return *this;
 
-  Fatal("operator=", "Not implemented.");
+  AliFatal("Not implemented.");
     
   return *this;  
 }
@@ -124,11 +123,6 @@ AliMUONRawData::~AliMUONRawData(void)
   if (fSubEventArray[1])
     fSubEventArray[1]->Delete();
 
-  if (fSubEventTrigArray[0])
-    fSubEventTrigArray[0]->Delete();
-  if (fSubEventTrigArray[1])
-    fSubEventTrigArray[1]->Delete();
-
   if (fDDLTracker)
     delete fDDLTracker;
   if (fDDLTrigger)
@@ -137,11 +131,11 @@ AliMUONRawData::~AliMUONRawData(void)
   return;
 }
 //____________________________________________________________________
-Int_t AliMUONRawData::WriteRawData()
+Int_t AliMUONRawData::Digits2Raw()
 {
  // convert digits of the current event to raw data
 
-  Int_t DDLId;
+  Int_t idDDL;
   Char_t name[20];
 
   fLoader->LoadDigits("READ");
@@ -154,12 +148,12 @@ Int_t AliMUONRawData::WriteRawData()
   for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++) {
  
     // open files
-    DDLId = ich * 2  + 0x900;
-    sprintf(name, "MUON_%d.ddl",DDLId);
+    idDDL = ich * 2  + 0x900;
+    sprintf(name, "MUON_%d.ddl",idDDL);
     fFile1 = fopen(name,"w");
 
-    DDLId = (ich * 2) + 1 + 0x900;
-    sprintf(name, "MUON_%d.ddl",DDLId);
+    idDDL = (ich * 2) + 1 + 0x900;
+    sprintf(name, "MUON_%d.ddl",idDDL);
     fFile2 = fopen(name,"w");
 
     WriteTrackerDDL(ich);
@@ -173,12 +167,12 @@ Int_t AliMUONRawData::WriteRawData()
   // trigger chambers
  
   // open files
-  DDLId = 0xA00;
-  sprintf(name, "MUTR_%d.ddl",DDLId);
+  idDDL = 0xA00;
+  sprintf(name, "MUTR_%d.ddl",idDDL);
   fFile1 = fopen(name,"w");
 
-  DDLId = 0xA00 + 1;
-  sprintf(name, "MUTR_%d.ddl",DDLId);
+  idDDL = 0xA00 + 1;
+  sprintf(name, "MUTR_%d.ddl",idDDL);
   fFile2 = fopen(name,"w");
 
   WriteTriggerDDL();
@@ -229,22 +223,33 @@ Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
   Int_t index;
   Int_t indexDsp;
   Int_t indexBlk;
-
+  Int_t padX;
+  Int_t padY;
+  Int_t cathode = 0;
+  Int_t detElemId;
   Int_t nDigits;
   const AliMUONDigit* digit;
 
-   if (fPrintLevel == 1)
-      printf("WriteDDL chamber %d\n", iCh+1);
+//   AliMUON *pMUON;
+//   AliMUONChamber* iChamber = 0x0;
+//   AliMUONGeometrySegmentation* segmentation2[2];
 
-  for (Int_t iCath = 0; iCath < 2; iCath++) {
+//   pMUON = (AliMUON*) gAlice->GetModule("MUON");
+//   iChamber =  &(pMUON->Chamber(iCh));
+
+//   segmentation2[0]=iChamber->SegmentationModel2(1); // cathode 0
+//   segmentation2[1]=iChamber->SegmentationModel2(2); // cathode 1
+
+   AliDebug(1, Form("WriteDDL chamber %d\n", iCh+1));
+
+   //  for (Int_t iCath = 0; iCath < 2; iCath++) {
 
     fMUONData->ResetDigits();
-    fMUONData->GetCathode(iCath);
+    fMUONData->GetDigits();
     muonDigits = fMUONData->Digits(iCh);
 
     nDigits = muonDigits->GetEntriesFast();
-    if (fPrintLevel == 2)
-      printf("ndigits = %d\n",nDigits);
+    AliDebug(2,Form("ndigits = %d\n",nDigits));
 
     // open DDL file, on per 1/2 chamber
  
@@ -252,9 +257,32 @@ Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
 
       digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
 
-      // mapping
-      GetDummyMapping(iCh, iCath, digit, busPatchId, manuId, channelId, charge);
+      padX = digit->PadX();
+      padY = digit->PadY();
+      charge = digit->Signal();
+      charge &= 0xFFF;
+      cathode = digit->Cathode();
+      detElemId = digit->DetElemId();
 
+      // mapping
+//       if (detElemId == 0) {
+//     AliWarning("\ndetElemId = 0, old segmentation !\n");
+       GetDummyMapping(iCh, cathode, digit, busPatchId, manuId, channelId);
+//       } else {
+//       // mapping (not far from real one)
+//     AliMUONSegmentManuIndex* connect = segmentation2[iCath]->GetMpConnection(detElemId, padX, padY);
+//     if (connect != 0x0) {
+//       busPatchId = connect->GetBusPatchId(); 
+//       manuId     = connect->GetManuId();
+//       channelId  = connect->GetManuChannelId();
+//       AliDebug(3,Form("busPatchId %d, manuId: %d, channelId: %d\n", busPatchId, manuId, channelId));
+//     } else {
+//       busPatchId = 0; 
+//       manuId     = 0;
+//       channelId  = 0;
+//     }
+
+//       }
       //packing word
       AliBitPacking::PackWord((UInt_t)parity,word,29,31);
       AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
@@ -274,7 +302,7 @@ Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
       }
       delete subEvent;
     }
-  }
+    //   }
   fSubEventArray[0]->Sort();
   fSubEventArray[1]->Sort();
 
@@ -296,7 +324,7 @@ Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
     }
     fSubEventArray[iDDL]->Compress();
 
-    if (fPrintLevel == 3) {
+    if (AliLog::GetGlobalDebugLevel() == 3) {
       nEntries = fSubEventArray[iDDL]->GetEntriesFast();
       for (Int_t i = 0; i < nEntries; i++) {
        AliMUONSubEventTracker* temp =  (AliMUONSubEventTracker*)fSubEventArray[iDDL]->At(i);
@@ -310,10 +338,11 @@ Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
       printf("\n");
     }
   
-  }
+   }
   
   Int_t iBusPatch;
   Int_t iEntries;
+  Int_t length;
 
   for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
  
@@ -331,18 +360,20 @@ Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
     for (Int_t iBlock = 0; iBlock < 2; iBlock++) {
 
       // block header
-      fDDLTracker->SetTotalBlkLength(0xFFFFFFFF);
-      memcpy(&buffer[index],fDDLTracker->GetBlkHeader(),32);
+      //    fDDLTracker->SetTotalBlkLength(0xFFFFFFFF);
+      length = fDDLTracker->GetBlkHeaderLength();
+      memcpy(&buffer[index],fDDLTracker->GetBlkHeader(),length*4);
       indexBlk = index;
-      index += 8
+      index += length
 
       for (Int_t iDsp = 0; iDsp < 5; iDsp++) {
 
        // DSP header
-       fDDLTracker->SetTotalDspLength(0xEEEEEEEE);
-       memcpy(&buffer[index],fDDLTracker->GetDspHeader(),32);
+       //      fDDLTracker->SetTotalDspLength(0xEEEEEEEE);
+       length = fDDLTracker->GetDspHeaderLength();
+       memcpy(&buffer[index],fDDLTracker->GetDspHeader(),length*4);
        indexDsp = index;
-       index += 8
+       index += length
 
        for (Int_t i = 0; i < 5; i++) {
 
@@ -356,8 +387,9 @@ Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
 
          if (busPatchId == iBusPatch) {
            // add bus patch structure
-           memcpy(&buffer[index],temp->GetAddress(),16);
-           index+= 4;
+           length = temp->GetHeaderLength();
+           memcpy(&buffer[index],temp->GetAddress(),length*4);
+           index += length;
            for (Int_t j = 0; j < temp->GetLength(); j++) 
              buffer[index++] =  temp->GetData(j);
            if (iEntries < nEntries-1)
@@ -369,25 +401,25 @@ Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
            buffer[index++] = 0xdeadbeef; // trigger word
          }
        } // bus patch
-       buffer[indexDsp] = index - indexDsp;
-       buffer[indexDsp+1] = index - indexDsp -8;
+       buffer[indexDsp] = index - indexDsp; // dsp length
+       buffer[indexDsp+1] = index - indexDsp - fDDLTracker->GetDspHeaderLength();
        if ((index - indexDsp) % 2 == 0)
          buffer[indexDsp+7] = 0;
        else
          buffer[indexDsp+7] = 1;
       } // dsp
-      buffer[indexBlk] = index - indexBlk;
-      buffer[indexBlk+1] = index - indexBlk -8;
+      buffer[indexBlk] = index - indexBlk; // block length
+      buffer[indexBlk+1] = index - indexBlk - fDDLTracker->GetBlkHeaderLength();
     }
     if (iDDL == 0) {
       // write DDL 1
-      header.fSize = index + headerSize;// total length in word
+      header.fSize = (index + headerSize) * 4;// total length in bytes
       fwrite((char*)(&header),headerSize*4,1,fFile1);
       fwrite(buffer,sizeof(int),index,fFile1);
     } 
     if (iDDL == 1) {
       // write DDL 2
-      header.fSize = index + headerSize;// total length in word
+      header.fSize = (index + headerSize) * 4;// total length in bytes
       fwrite((char*)(&header),headerSize*4,1,fFile2);
       fwrite(buffer,sizeof(int),index,fFile2);
     }
@@ -412,7 +444,7 @@ Int_t AliMUONRawData::WriteTriggerDDL()
  // DDL header
   AliRawDataHeader header = fDDLTrigger->GetHeader();
   Int_t headerSize = fDDLTrigger->GetHeaderSize();
-
+  Int_t length;
   TClonesArray* localTrigger;
   TClonesArray* globalTrigger;
   AliMUONGlobalTrigger* gloTrg;
@@ -433,10 +465,11 @@ Int_t AliMUONRawData::WriteTriggerDDL()
   Int_t index;
   Int_t iEntries = 0;
   Int_t iLocCard, locCard;
-  Char_t locDec, trigY, posY, devX, posX;
+  Char_t locDec, trigY, posY, devX, posX,regOut;
   Int_t version = 1; // software version
-  Int_t eventType =1; // trigger type: 1 for physics ?
+  Int_t eventType = 1; // trigger type: 1 for physics ?
   Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
+  Int_t globalFlag = 1; // set to 2 if global info present in DDL else set to 1
 
   Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
   // stored the local card id that's fired
@@ -446,25 +479,35 @@ Int_t AliMUONRawData::WriteTriggerDDL()
   }
 
   if (!nEntries)
-    Error("AliMUONRawData::WriteTriggerDDL","No Trigger information available");
+    AliError("No Trigger information available");
 
-  buffer = new Int_t [680]; // [16(local)*5 words + 4 words]*8(reg) + 7 words = 679
+  buffer = new Int_t [672]; // [16(local)*5 words + 3 words]*8(reg) + 8 words = 672
 
   for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
     
     index = 0; 
 
     // DDL enhanced header
-    word =0;
-    AliBitPacking::PackWord((UInt_t)iDDL+1,word,30,31); //see AliMUONDDLTrigger.h for details
-    AliBitPacking::PackWord((UInt_t)version,word,22,29);
-    AliBitPacking::PackWord((UInt_t)serialNb,word,18,21);
-    AliBitPacking::PackWord((UInt_t)eventType,word,14,17);
-
+    word = 0;
+    AliBitPacking::PackWord((UInt_t)iDDL+1,word,28,31); //see AliMUONDDLTrigger.h for details
+    AliBitPacking::PackWord((UInt_t)serialNb,word,24,27);
+    AliBitPacking::PackWord((UInt_t)version,word,16,23);
+    AliBitPacking::PackWord((UInt_t)eventType,word,12,15);
+
+    if (iDDL == 0) // suppose global info in DDL one
+      globalFlag = 2;
+    else 
+      globalFlag = 1;
+    AliBitPacking::PackWord((UInt_t)globalFlag,word,8,11);
     fDDLTrigger->SetDDLWord(word);
-    fDDLTrigger->SetGlobalOutput(gloTrigPat);
-    memcpy(&buffer[index],fDDLTrigger->GetEnhancedHeader(),24);
-    index += 6; 
+
+    if (iDDL == 0)
+      fDDLTrigger->SetGlobalOutput(gloTrigPat);// no global input for the moment....
+    else 
+      fDDLTrigger->SetGlobalOutput(0);
+    length = fDDLTrigger->GetHeaderLength(); 
+    memcpy(&buffer[index],fDDLTrigger->GetEnhancedHeader(),length*4);
+    index += length; 
 
     for (Int_t iReg = 0; iReg < 8; iReg++) {
 
@@ -472,12 +515,18 @@ Int_t AliMUONRawData::WriteTriggerDDL()
 
       // Regional card header
       word = 0;
-      AliBitPacking::PackWord((UInt_t)serialNb,word,27,31); //see  AliMUONSubEventTrigger.h for details
-      AliBitPacking::PackWord((UInt_t)iReg,word,22,26);
-      AliBitPacking::PackWord((UInt_t)version,word,14,21);
+      regOut  = 0;
+      AliBitPacking::PackWord((UInt_t)serialNb,word,24,28); //see  AliMUONSubEventTrigger.h for details
+      AliBitPacking::PackWord((UInt_t)version,word,16,23);
+      AliBitPacking::PackWord((UInt_t)iReg,word,12,15);
+      AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // whenever regional output will be implemented
+
       subEvent->SetRegWord(word);
       memcpy(&buffer[index++],subEvent->GetAddress(),4);
 
+      buffer[index++] = 0;// 2 words of regional input
+      buffer[index++] = 0;
+
       for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
 
        iLocCard = iLoc + iReg*16 + iDDL*128;
@@ -490,9 +539,8 @@ Int_t AliMUONRawData::WriteTriggerDDL()
          posY = locTrg->LoStripY();
          posX = locTrg->LoStripX();
          devX = locTrg->LoDev();
-         if (fPrintLevel == 4) 
-           printf("loctrg %d, posX %d, posY %d, devX %d\n", 
-                  locTrg-> LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev());
+         AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n", 
+                         locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
        } else { //no trigger (see PRR chpt 3.4)
          locCard = -1;
          locDec = 0;
@@ -529,26 +577,24 @@ Int_t AliMUONRawData::WriteTriggerDDL()
 
        }
       } // local card 
-      buffer[index++] = 0;// 2 words of regional input
-      buffer[index++] = 0;
-      buffer[index++] = 0;// regional output
 
       delete subEvent; 
 
     } // Regional card
     
     buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word
+    buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word for 64 bits transfer purpose
 
     
     if (iDDL == 0) {
       // write DDL 1
-      header.fSize = index + headerSize;// total length in word
+      header.fSize = (index + headerSize) * 4;// total length in bytes
       fwrite((char*)(&header),headerSize*4,1,fFile1);
       fwrite(buffer,sizeof(int),index,fFile1);
     } 
     if (iDDL == 1) {
       // write DDL 2
-      header.fSize = index + headerSize;// total length in word
+      header.fSize = (index + headerSize) * 4;// total length in bytes
       fwrite((char*)(&header),headerSize*4,1,fFile2);
       fwrite(buffer,sizeof(int),index,fFile2);
     }
@@ -559,8 +605,9 @@ Int_t AliMUONRawData::WriteTriggerDDL()
 }
 //____________________________________________________________________
 void AliMUONRawData::GetDummyMapping(Int_t iCh, Int_t iCath, const AliMUONDigit* digit,
-                                    Int_t &busPatchId, UShort_t &manuId, UChar_t &channelId, UShort_t &charge)
+                                    Int_t &busPatchId, UShort_t &manuId, UChar_t &channelId)
 {
+// Dummy mapping for tracker
 
   Int_t offsetX = 0; // offet row
   Int_t offsetY = 0; // offset columns
@@ -609,37 +656,20 @@ void AliMUONRawData::GetDummyMapping(Int_t iCh, Int_t iCath, const AliMUONDigit*
       channelId = (id % chPerBus) % 64; //start at zero 
       channelId &= 0x3F; // 6 bits
 
-//       id =  (TMath::Abs(digit->PadX()) * offsetX + digit->PadY() + offsetY +
-//          offsetCath * iCath);
-//       busPatchId = id/50;
-
-//       Int_t inBusId = id - (maxChannel/50 * busPatchId);// id channel in buspatch
-//       Int_t manuPerBus = (maxChannel/(50*64)); // number of manus per buspatch
-
-//       // 64 manu cards for one buspatch
-//       manuId = inBusId/manuPerBus;
-//       manuId &= 0x7FF; // 11 bits 
+     
+      AliDebug(2,Form("id: %d, busPatchId %d, manuId: %d, channelId: %d, maxchannel: %d, chPerBus %d\n",
+                     id, busPatchId, manuId, channelId, maxChannel, chPerBus));
 
-//       // channel id
-//       channelId = (inBusId % manuPerBus);
-//       channelId &= 0x3F; // 6 bits
-
-      if (fPrintLevel == 2)
-       printf("id: %d, busPatchId %d, manuId: %d, channelId: %d, maxchannel: %d, chPerBus %d\n",
-              id, busPatchId, manuId, channelId, maxChannel, chPerBus);
-      // charge
-      charge = digit->Signal();
-      charge &= 0xFFF;
-
-      if (fPrintLevel == 2)
-       printf("id: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d, charge %d\n",
-              id, busPatchId, manuId, channelId, digit->PadX(), digit->PadY(), digit->Signal());
+      AliDebug(2,Form("id: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d, charge %d\n",
+                     id, busPatchId, manuId, channelId, digit->PadX(), digit->PadY(), digit->Signal()));
 
 }
 
 //____________________________________________________________________
-Int_t AliMUONRawData::GetGlobalTriggerPattern(AliMUONGlobalTrigger* gloTrg)
+Int_t AliMUONRawData::GetGlobalTriggerPattern(const AliMUONGlobalTrigger* gloTrg)
 {
+  // global trigger pattern calculation
+
   Int_t gloTrigPat = 0;
 
   if (gloTrg->SinglePlusLpt())  gloTrigPat|= 0x1;
@@ -664,3 +694,374 @@ Int_t AliMUONRawData::GetGlobalTriggerPattern(AliMUONGlobalTrigger* gloTrg)
 
   return gloTrigPat;
 }
+
+//____________________________________________________________________
+Int_t AliMUONRawData::Raw2Digits(AliRawReader* rawReader)
+{
+
+  // generate digits
+  ReadTrackerDDL(rawReader);
+
+  // generate trigger
+  ReadTriggerDDL(rawReader);
+
+  return kTRUE;
+
+}
+
+//____________________________________________________________________
+Int_t AliMUONRawData::ReadTrackerDDL(AliRawReader* rawReader)
+{
+
+  AliMUONSubEventTracker* subEventTracker = new AliMUONSubEventTracker();
+  AliMUONDigit* digit = new AliMUONDigit();
+
+
+  //Read Header Size of DDL,Block,DSP and BusPatch.
+
+  Int_t ddlHeaderSize      = fDDLTracker->GetHeaderSize();
+  Int_t blockHeaderSize    = fDDLTracker->GetBlkHeaderLength();
+  Int_t dspHeaderSize      = fDDLTracker->GetDspHeaderLength();
+  Int_t buspatchHeaderSize = subEventTracker->GetHeaderLength();
+
+//   Each DDL is made with 2 Blocks each of which consists of 5 DSP and each of DSP has at most 5 buspatches.
+//   This information is used to calculate the size of headers (DDL,Block and DSP) which has no interesting data. 
+
+  const Int_t blankDDLSize   = ddlHeaderSize + 2*blockHeaderSize + 2*5*dspHeaderSize + 2*5*5*buspatchHeaderSize;
+  const Int_t blankBlockSize = blockHeaderSize + 5*dspHeaderSize + 5*5*buspatchHeaderSize;
+  const Int_t blankDspSize   = dspHeaderSize + 5*buspatchHeaderSize;
+
+  Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize; 
+
+
+  for(Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++){                // loops over tracking chambers
+
+    UShort_t  charge; 
+    Int_t padX, padY,iCath;
+
+    for(Int_t iDDL = 0; iDDL < 2; iDDL++){                                         // DDL loop
+
+      //rawReader = new AliRawReaderFile(iEvent);
+      rawReader->Select(0X9,(2*iCh)+iDDL,(2*iCh)+iDDL);  //Select the DDL file to be read  
+
+      rawReader->ReadHeader();
+
+      totalDDLSize = (rawReader->GetDataSize()+sizeof(AliRawDataHeader))/4; // 4 is multipiled to convert byte 2 word
+
+      if(totalDDLSize>blankDDLSize){      // Compare the DDL header with an empty DDL header size to read the file
+
+
+       Int_t totalDataWord = rawReader->GetDataSize()/4 ;
+       UInt_t *buffer = new UInt_t[totalDataWord];
+       for(Int_t i=0;i<totalDataWord;i++){
+         UInt_t& temp = buffer[i]; 
+          rawReader->ReadNextInt(temp);      // takes the whole result into buffer variable for future analysis
+       }
+
+       Char_t parity;
+       Int_t buspatchId;
+       UChar_t channelId;
+       UShort_t  manuId;//,charge; 
+       Int_t id;//,padX, padY,iCath;
+       Int_t indexDsp, indexBusPatch, index = 0;
+
+
+       for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){  // loop over 2 blocks
+         totalBlockSize = buffer[index];
+         
+         if(totalBlockSize > blankBlockSize){        // compare block header
+           index += blockHeaderSize;
+
+           for(Int_t iDsp = 0; iDsp < 5 ;iDsp++){   //DSP loop
+             totalDspSize = buffer[index];
+             indexDsp = index;
+
+             if(totalDspSize > blankDspSize){       // Compare DSP Header
+               index += dspHeaderSize;
+               
+               for(Int_t iBusPatch = 0; iBusPatch < 5 ; iBusPatch++){  
+                 totalBusPatchSize = buffer[index];
+                 indexBusPatch = index;
+                 buspatchId = buffer[index+2];
+
+                 if(totalBusPatchSize > buspatchHeaderSize){    //Check Buspatch header
+                   index += buspatchHeaderSize;
+                   dataSize = totalBusPatchSize - buspatchHeaderSize;
+
+                   if(dataSize>0) {
+
+                     for(Int_t iData = 0; iData < dataSize ;iData++) {
+
+                       subEventTracker->SetData(buffer[index++],iData);   //Set to extract data
+                       parity = subEventTracker->GetParity(iData);
+                       manuId = subEventTracker->GetManuId(iData);
+                       channelId = subEventTracker->GetChannelId(iData);
+                       charge = subEventTracker->GetCharge(iData);
+                       digit->AddSignal(charge); // set charge
+
+                       GetInvDummyMapping(iCh,buspatchId,manuId,channelId,digit); // Get Back the hits at pads
+                       padX = digit->PadX();
+                       padY = digit->PadY();
+                       iCath = digit->Cathode();  
+                       id = digit->DetElemId();
+
+                       // fill digits
+                       fMUONData->AddDigit(iCh, *digit);
+
+                     } // data loop
+                   } // dataSize test
+                 } // testing buspatch
+
+                 index = indexBusPatch + totalBusPatchSize;
+
+               }  //buspatch loop
+               
+               
+             }  // dsp test
+
+             index = indexDsp + totalDspSize;
+             
+           }  // dsp loop
+
+         }   //block test
+
+         index = totalBlockSize;
+
+       }  //block loop
+
+       delete []buffer;
+      } //loop checking the header size of DDL
+
+      //delete rawReader;
+    } // DDL loop
+
+  } // Chamber loop
+
+  delete subEventTracker;
+  delete digit;
+
+  return kTRUE;
+}
+
+//____________________________________________________________________
+void AliMUONRawData:: GetInvDummyMapping(Int_t iCh, Int_t buspatchId, UShort_t manuId, 
+                                        UChar_t channelId, AliMUONDigit* digit )
+{
+  Int_t offsetX = 0; // offet row
+  Int_t offsetY = 0; // offset columns
+  Int_t offsetCath = 0; //offset from one cathod to the other
+  Int_t maxChannel = 0; // maximum nb of channel in 1/2 chamber
+  //Int_t id;
+  Bool_t flag;
+  switch (iCh+1) {
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+    offsetX = 512;
+    offsetY = 256;
+    offsetCath = 65536;
+    maxChannel = (offsetY * offsetX + 2* offsetY + offsetCath);
+    break;
+  case 5:
+  case 6:
+  case 7:
+  case 8:
+  case 9:
+  case 10:
+    offsetX = 1024;
+    offsetY = 0;
+    offsetCath = 65536;
+    maxChannel = (256 * offsetX + offsetX + offsetCath);
+    break;
+  }
+  // dummy mapping
+  // manu Id directly from a matrix 8*8, same segmentation for B and NB
+  // 50 buspatches for 1/2 chamber
+  
+  if(buspatchId >= 50*(2*iCh + 1)){          // condn to find the sign of padX
+    buspatchId = buspatchId - 50*(2*iCh + 1);
+    flag = kTRUE;
+  }
+  else{
+    buspatchId = buspatchId - 50*2*iCh;
+    flag = kFALSE;
+  }
+  
+  Int_t chPerBus = maxChannel/50;
+  
+  Int_t id = buspatchId*chPerBus + 64*manuId + channelId;
+  Int_t iCath, padX,padY;
+  if(id >= (offsetY + offsetCath))           // find cathode plane
+    iCath = 1;
+  else
+    iCath = 0;
+  
+  if(iCh<4)
+    padX = TMath::Nint((Float_t)(id - offsetY - offsetCath*iCath)/offsetX);
+  else
+    padX = (id - offsetY - offsetCath*iCath)/offsetX;
+  
+  padY = id - (padX*offsetX + offsetY + offsetCath*iCath);
+  
+  if(flag)                                 //Detect the sign of padX
+    padX = -padX;
+  else
+    padX = padX;
+  
+  digit->SetPadX(padX);
+  digit->SetPadY(padY);
+  digit->SetCathode(iCath);
+  digit->SetDetElemId(id);
+
+  return;
+}
+
+//____________________________________________________________________
+Int_t AliMUONRawData::ReadTriggerDDL(AliRawReader* rawReader)
+{
+  AliMUONSubEventTrigger* subEventTrigger = new AliMUONSubEventTrigger();
+  AliMUONGlobalTrigger* globalTrigger = 0x0;
+  AliMUONLocalTrigger* localTrigger = new  AliMUONLocalTrigger();
+
+
+  //Int_t ddlHeaderSize = fDDLTrigger->GetHeaderSize();    // we dont need this, as size of ddl data is same for triger and no trigger
+
+  Int_t ddlEnhanceHeaderSize = fDDLTrigger->GetHeaderLength(); 
+  Int_t regHeaderLength      = subEventTrigger->GetRegHeaderLength() ;
+
+  Int_t loCircuit, loStripX, loDev, loStripY, loLpt, loHpt;
+  Char_t loDecision; 
+
+  UShort_t X1Pattern, X2Pattern, X3Pattern, X4Pattern;
+  UShort_t Y1Pattern, Y2Pattern, Y3Pattern, Y4Pattern;
+
+
+  for(Int_t iDDL = 0; iDDL < 2; iDDL++){                        //DDL loop
+
+    rawReader->Select(0XA,iDDL,iDDL);  //Select the DDL file to be read  
+
+    rawReader->ReadHeader();
+
+    Int_t totalDataWord = rawReader->GetDataSize()/4 ;
+    UInt_t *buffer = new UInt_t[totalDataWord];
+    for(Int_t i=0;i<totalDataWord;i++){
+      UInt_t& temp = buffer[i]; 
+      rawReader->ReadNextInt(temp);      // takes the whole result into buffer variable for future analysis
+    }
+
+    // rawReader->ReadNext((UChar_t*)buffer, totalDataWord);     // method is protected ????
+  
+    Int_t index = 0;
+
+    // fill DDL header informations
+    memcpy(fDDLTrigger->GetEnhancedHeader(), &buffer[index], ddlEnhanceHeaderSize*4); 
+
+    // fill global trigger information
+    globalTrigger = GetGlobalTriggerPattern(fDDLTrigger->GetGlobalOuput());
+    fMUONData->AddGlobalTrigger(*globalTrigger);
+
+    index += ddlEnhanceHeaderSize;
+
+    for (Int_t iReg = 0; iReg < 8; iReg++) {           //loop over regeonal card
+
+
+      subEventTrigger->SetRegWord(buffer[index]);      //read regional data 
+
+      index += regHeaderLength;
+
+      for (Int_t iLoc = 0; iLoc < 16; iLoc++) {         //loop over local card
+         
+       Int_t iLocIndex = index;
+
+       for(Int_t iData = 0; iData < 5 ;iData++ ){
+         subEventTrigger->SetLocalData(buffer[index++],5*iLoc+iData);   //read local data
+       }
+
+       if(buffer[iLocIndex] > 0) {
+
+         loCircuit = (Int_t)subEventTrigger->GetLocalId(iLoc)+ 16*iReg + 128*iDDL; 
+         loStripX =  (Int_t)subEventTrigger->GetXPos(iLoc);
+         loStripY = (Int_t)subEventTrigger->GetYPos(iLoc);
+         loDev = (Int_t)subEventTrigger->GetXDev(iLoc);
+           
+         // fill local trigger
+         localTrigger->SetLoCircuit(loCircuit);
+         localTrigger->SetLoStripX(loStripX );
+         localTrigger->SetLoStripY(loStripY);
+         localTrigger->SetLoDev(loDev);
+
+         loDecision = subEventTrigger->GetLocalDec(iLoc);
+         loLpt =  loDecision       & 0x3;
+         loHpt = (loDecision >> 2) & 0x3; 
+           
+         // fill local trigger
+         localTrigger->SetLoLpt(loLpt);
+         localTrigger->SetLoHpt(loHpt);
+
+
+         X1Pattern = subEventTrigger->GetX1(iLoc);
+         X2Pattern = subEventTrigger->GetX2(iLoc);
+         X3Pattern = subEventTrigger->GetX3(iLoc);
+         X4Pattern = subEventTrigger->GetX4(iLoc);
+           
+         Y1Pattern = subEventTrigger->GetY1(iLoc);
+         Y2Pattern = subEventTrigger->GetY2(iLoc);
+         Y3Pattern = subEventTrigger->GetY3(iLoc);
+         Y4Pattern = subEventTrigger->GetY4(iLoc);
+
+         // fill local trigger
+         localTrigger->SetX1Pattern(X1Pattern);
+         localTrigger->SetX2Pattern(X2Pattern);
+         localTrigger->SetX3Pattern(X3Pattern);
+         localTrigger->SetX4Pattern(X4Pattern);
+
+         localTrigger->SetY1Pattern(Y1Pattern);
+         localTrigger->SetY2Pattern(Y2Pattern);
+         localTrigger->SetY3Pattern(Y3Pattern);
+         localTrigger->SetY4Pattern(Y4Pattern);
+         fMUONData->AddLocalTrigger(*localTrigger);
+
+       }
+         
+      } // local card loop
+       
+    } // regeinal card loop
+      
+    delete [] buffer;
+    //delete rawReader;
+  } // DDL loop
+
+
+  delete subEventTrigger;
+  delete globalTrigger;
+  delete localTrigger;
+
+  return kTRUE;
+
+}
+//____________________________________________________________________
+AliMUONGlobalTrigger* AliMUONRawData::GetGlobalTriggerPattern(Int_t gloTrigPat)
+{
+  // global trigger pattern calculation
+
+  Int_t globalSinglePlus[3];  // tot num of single plus
+  Int_t globalSingleMinus[3]; // tot num of single minus
+  Int_t globalSingleUndef[3]; // tot num of single undefined
+  Int_t globalPairUnlike[3];  // tot num of unlike-sign pairs
+  Int_t globalPairLike[3];    // tot num of like-sign pairs
+
+
+  for (Int_t i = 0; i < 3; i++) {
+    globalSinglePlus[i]  = gloTrigPat & (0x1 << i);
+    globalSingleMinus[i] = gloTrigPat & (0x1 << i+3);
+    globalSingleUndef[i] = gloTrigPat & (0x1 << i+6);
+    globalPairUnlike[i]  = gloTrigPat & (0x1 << i+9);
+    globalPairLike[i]    = gloTrigPat & (0x1 << i+12);
+  }
+
+  return (new AliMUONGlobalTrigger(globalSinglePlus, globalSingleMinus,
+                                                      globalSingleUndef, globalPairUnlike, 
+                                                       globalPairLike));  
+
+}