]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdigitsManager.cxx
running local for SP and LYZEP and new histograms for QC
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
index 7c759249e7db8bbef5cfb516de8278ae3361ef5e..f80989b0473fd183cbc24e1365ca461acf1b7be4 100644 (file)
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
 //  Manages the digits and the track dictionary in the form of               //
-//  AliTRDdataArray objects.                                                 //
+//  TObjArray objects                                                        //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <Riostream.h>
+#include <Riostream.h> 
 #include <TROOT.h>
 #include <TTree.h>                                                              
 #include <TFile.h>
-
 #include "AliRun.h"
 #include "AliLog.h"
-
 #include "AliTRDdigitsManager.h"
-#include "AliTRDsegmentArray.h"
-#include "AliTRDdataArrayI.h"
+#include "AliTRDarrayDictionary.h"
+#include "AliTRDarrayADC.h"
+#include "AliTRDarraySignal.h"
 #include "AliTRDdigit.h"
 #include "AliTRDgeometry.h"
-
 #include "AliTRDSignalIndex.h"
 
 ClassImp(AliTRDdigitsManager)
@@ -51,20 +48,22 @@ AliTRDdigitsManager::AliTRDdigitsManager()
   :TObject()
   ,fEvent(0)
   ,fTree(0)
-  ,fDigits(0)
-  ,fIsRaw(0)
-  ,fSDigits(0)
+  ,fDigits(0) 
+  ,fHasSDigits(0)
   ,fSignalIndexes(NULL)
+  ,fUseDictionaries(kTRUE)
+  ,fTreeD(0)
+  ,fBranch(0)
 {
   //
   // Default constructor
   //
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    fDictionary[iDict] = NULL;
-  }
+  for (Int_t iDict = 0; iDict < kNDict; iDict++) 
+    {
+      fDict[iDict] = NULL;
+    }
   
-  //fSignalIndexes = new TList();
   fSignalIndexes = new TObjArray(AliTRDgeometry::Ndet());
   
 }
@@ -74,10 +73,12 @@ AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
   :TObject(m)
   ,fEvent(m.fEvent)
   ,fTree(0)
-  ,fDigits(0)
-  ,fIsRaw(m.fIsRaw)
-  ,fSDigits(m.fSDigits)
+  ,fDigits(0) 
+  ,fHasSDigits(m.fHasSDigits)
   ,fSignalIndexes(NULL)
+  ,fUseDictionaries(kTRUE)
+  ,fTreeD(m.fTree)
+  ,fBranch(m.fBranch)
 {
   //
   // AliTRDdigitsManager copy constructor
@@ -92,22 +93,27 @@ AliTRDdigitsManager::~AliTRDdigitsManager()
   // AliTRDdigitsManager destructor
   //
 
-  if (fDigits) {
-    fDigits->Delete();
-    delete fDigits;
-    fDigits = NULL;
-  }
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    fDictionary[iDict]->Delete();
-    delete fDictionary[iDict];
-    fDictionary[iDict] = NULL;
-  }
+  if (fDigits) 
+    {
+      fDigits->Delete();
+      delete fDigits;
+      fDigits = NULL;
+    }
+
+  for (Int_t iDict = 0; iDict < kNDict; iDict++) 
+    {
+      fDict[iDict]->Delete();
+      delete fDict[iDict];
+      fDict[iDict] = NULL;
+    }
 
-  delete fSignalIndexes;
-  fSignalIndexes = NULL;
-//   for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
-//     delete fSignalIndexes[i];
+  if (fSignalIndexes) 
+    {
+      fSignalIndexes->Delete();
+      delete fSignalIndexes;
+      fSignalIndexes = NULL;
+    }
 
 }
 
@@ -118,7 +124,11 @@ AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m
   // Assignment operator
   //
 
-  if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
+  if (this != &m) 
+    {
+      ((AliTRDdigitsManager &) m).Copy(*this);
+    }
+
   return *this;
 
 }
@@ -130,11 +140,16 @@ void AliTRDdigitsManager::Copy(TObject &m) const
   // Copy function
   //
 
-  ((AliTRDdigitsManager &) m).fIsRaw   = fIsRaw;
-  ((AliTRDdigitsManager &) m).fEvent   = fEvent;
-  ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
-  
-  ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
+  ((AliTRDdigitsManager &) m).fEvent           = fEvent;
+  ((AliTRDdigitsManager &) m).fHasSDigits      = fHasSDigits;
+  ((AliTRDdigitsManager &) m).fDigits          = fDigits;
+  for(Int_t i=0; i<kNDict; i++)
+    {
+      ((AliTRDdigitsManager &) m).fDict[i]  = fDict[i];
+    }
+  ((AliTRDdigitsManager &) m).fSignalIndexes   = fSignalIndexes;
+  ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
+
   TObject::Copy(m);
 
 }
@@ -146,18 +161,68 @@ void AliTRDdigitsManager::CreateArrays()
   // Create the data arrays
   //
 
-  fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
+  if (fHasSDigits) 
+    {
+      if(fDigits)                                        
+       {                                                   
+         fDigits->Delete();                                
+         delete fDigits;                                   
+       }                                                    
+      fDigits = new TObjArray(AliTRDgeometry::Ndet());
+      for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
+       {
+         AliTRDarraySignal *chamber= new AliTRDarraySignal();
+         chamber->SetNdet(index);
+         fDigits->AddAt(chamber,index);
+       } 
+    }
+  else 
+    {
+      if(fDigits)                                          
+       {                                                    
+         fDigits->Delete();                                
+         delete fDigits;                                   
+       }                                                   
+      fDigits = new TObjArray(AliTRDgeometry::Ndet());    
+      for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
+       {
+         AliTRDarrayADC *chamber= new AliTRDarrayADC();                                                 
+         chamber->SetNdet(index);
+         fDigits->AddAt(chamber,index);
+       }       
+    }
+
+  if (fUseDictionaries) 
+    {
+      for(Int_t iDict = 0; iDict < kNDict; iDict++)
+       if(fDict[iDict])                                           
+         {
+           fDict[iDict]->Delete();                                
+           delete fDict[iDict];                                    
+         }
+      for(Int_t iDict = 0; iDict < kNDict; iDict++)
+       {
+         fDict[iDict] = new TObjArray(AliTRDgeometry::Ndet());    
+       }
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
-                                               ,AliTRDgeometry::Ndet());
-  }
+      for (Int_t iDict = 0; iDict < kNDict; iDict++)
+       {
+         for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
+           {
+             AliTRDarrayDictionary *dictio= new AliTRDarrayDictionary();
+             dictio->SetNdet(index);
+             fDict[iDict]->AddAt(dictio,index);
+           } 
+       }
+    }
 
-  for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
+  for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) 
     {
       fSignalIndexes->AddLast(new AliTRDSignalIndex());
-    }
+    } 
+
 }
+
 //_____________________________________________________________________________
 void AliTRDdigitsManager::ResetArrays()
 {
@@ -165,108 +230,187 @@ void AliTRDdigitsManager::ResetArrays()
   // Reset the data arrays
   //
 
-  if (fDigits) {
-    delete fDigits;
-  }
-  fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
+  if (fDigits) 
+    {
+      fDigits->Delete();
+      delete fDigits;
+    }
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    if (fDictionary[iDict]) {  
-      delete fDictionary[iDict];
+  for (Int_t iDict = 0; iDict < kNDict; iDict++)          
+    {                                                        
+      if (fDict[iDict])                                
+       {                                                    
+         fDict[iDict]->Delete();                      
+         delete fDict[iDict];                        
+       }
     }
-    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
-                                               ,AliTRDgeometry::Ndet());
-  }
 
-  for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
+  if (fHasSDigits)
+    {
+      fDigits = new TObjArray(AliTRDgeometry::Ndet());     
+      for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
+       {
+         AliTRDarraySignal *chamber= new AliTRDarraySignal();
+         chamber->SetNdet(index);
+         fDigits->AddAt(chamber,index);
+       } 
+    }
+  else 
+    {
+      fDigits = new TObjArray(AliTRDgeometry::Ndet());      
+      for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
+       {
+         AliTRDarrayADC *chamber= new AliTRDarrayADC();
+         chamber->SetNdet(index);
+         fDigits->AddAt(chamber,index);
+       }
+    }
+  
+  if (fUseDictionaries) 
     {
-      AliTRDSignalIndex *idx = (AliTRDSignalIndex *)fSignalIndexes->At(i);
-      idx->Reset();
+      for(Int_t iDict = 0; iDict < kNDict; iDict++)
+       {
+         fDict[iDict] = new TObjArray(AliTRDgeometry::Ndet());  
+       }
+      for (Int_t iDict = 0; iDict < kNDict; iDict++)
+       {
+         for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
+           {
+             AliTRDarrayDictionary *dictio= new AliTRDarrayDictionary();   
+             dictio->SetNdet(index);                                       
+             fDict[iDict]->AddAt(dictio,index);                            
+           }
+       }
     }
+
+  for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) 
+    {
+      AliTRDSignalIndex *idx = (AliTRDSignalIndex *) fSignalIndexes->At(i);
+      if (idx) idx->Reset();
+    }
+
 }
 
 //_____________________________________________________________________________
-void AliTRDdigitsManager::SetRaw()
+Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
 {
   //
-  // Switch on the raw digits flag
+  // Returns the amplitude of a digit
   //
 
-  fIsRaw = kTRUE;
-  if (fDigits)
-    fDigits->SetBit(AliTRDdigit::RawDigit());
+  if (!GetDigits(det)) 
+    {
+      return 0;
+    }
   
+  return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataB(row,col,time));
+
 }
 
 //_____________________________________________________________________________
-Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
-                                       , Int_t det) const
+UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
 {
   //
-  // Returns the amplitude of a digit
+  // Returns the pad status for the requested pad
   //
+       
+  if (!GetDigits(det)) 
+    {
+      return 0;
+    }
 
-  if (!GetDigits(det)) return 0;
-  return ((Short_t) GetDigits(det)->GetData(row,col,time));
-
-}
+  return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
  
+}
+
 //_____________________________________________________________________________
-Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
+Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)  
 {
   //
   // Creates the tree and branches for the digits and the dictionary
   //
 
-  Int_t buffersize = 64000;
-
-  Bool_t status = kTRUE;
+  Int_t  buffersize = 64000;
+  Bool_t status     = kTRUE;
 
-  if (tree) {
-    fTree = tree;
-  }
+  if (tree) 
+    {
+      fTree = tree;
+    }
 
   // Make the branch for the digits
-  if (fDigits) {
-    const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
-    if (kDigits) {
-      if (!fTree) return kFALSE;
-      TBranch* branch = fTree->GetBranch("TRDdigits");
-      if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName(),
-                                 &kDigits,buffersize,99);
-      AliDebug(1,"Making branch TRDdigits\n");
-    }
-    else {
+  if (fDigits) 
+    {
+      if(fHasSDigits)
+       {
+         const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0); 
+         if (kDigits) 
+           {
+             if (!fTree) return kFALSE;
+             AliDebug(1,"Making branch for SDigits!\n");
+             TBranch* branch = fTree->GetBranch("TRDdigits");
+             if (!branch) fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
+             AliDebug(1,"Making branch TRDdigits\n");
+           }
+         else 
+           {
+             status = kFALSE;
+           }
+       }
+
+      if(!fHasSDigits)
+       {
+         const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
+         if (kDigits) 
+           {
+             if (!fTree) return kFALSE;
+             AliDebug(1,"Making branch for Digits!\n");
+             TBranch* branch = fTree->GetBranch("TRDdigits");
+             if (!branch) fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
+             AliDebug(1,"Making branch TRDdigits\n");        
+           }
+         else 
+           {
+             status = kFALSE;
+           }
+       }
+
+    }    
+  else
+    {
       status = kFALSE;
     }
-  }
-  else {
-    status = kFALSE;
-  }
-
-  // Make the branches for the dictionaries
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    Char_t branchname[15];
-    sprintf(branchname,"TRDdictionary%d",iDict);
-    if (fDictionary[iDict]) {
-      const AliTRDdataArray *kDictionary = 
-              (AliTRDdataArray *) fDictionary[iDict]->At(0);
-      if (kDictionary) {
-       if (!fTree) return kFALSE;
-       TBranch* branch = fTree->GetBranch(branchname);
-       if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName(),
-                                  &kDictionary,buffersize,99);
-        AliDebug(1,Form("Making branch %s\n",branchname));
-      }
-      else {
-        status = kFALSE;
-      }
-    }
-    else {
-      status = kFALSE;
+  
+  if (fUseDictionaries) 
+    {
+      // Make the branches for the dictionaries
+      for (Int_t iDict = 0; iDict < kNDict; iDict++) 
+       {
+         Char_t branchname[15];
+         sprintf(branchname,"TRDdictionary%d",iDict); 
+         if (fDict[iDict]) 
+           {
+             const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
+             if (kDictionary) 
+               {
+                 if (!fTree) return kFALSE;
+                 AliDebug(2,"Making branch for dictionary!\n");
+                 TBranch* branch = fTree->GetBranch(branchname);
+                 if (!branch) fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
+                 AliDebug(1,Form("Making branch %s\n",branchname));
+               }
+             else 
+               {
+                 status = kFALSE;
+               }
+           }
+         else 
+           {
+             status = kFALSE;
+           }
+       }
     }
-  }
-
+  
   return status;
 
 }
@@ -280,31 +424,34 @@ Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
 
   Bool_t status = kTRUE;
 
-  if (tree) {
-
-    fTree = tree;
-
-  }
-
-  if (!fDigits) {
-    AliDebug(1,"Create the data arrays.\n");
-    CreateArrays();
-  }
+  if (tree) 
+    {
+      fTree = tree;
+    }
 
-  status = fDigits->LoadArray("TRDdigits",fTree);
+  if (!fDigits) 
+    {
+      AliDebug(1,"Create the data arrays.\n");
+      CreateArrays();
+    }
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    Char_t branchname[15];
-    sprintf(branchname,"TRDdictionary%d",iDict);
-    status = fDictionary[iDict]->LoadArray(branchname,fTree);
-  }  
+  status = LoadArray(fDigits,"TRDdigits",fTree);
 
-  if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
-    fIsRaw = kTRUE;
-  }
-  else {
-    fIsRaw = kFALSE;
-  }
+  if (fUseDictionaries) 
+    {
+      for (Int_t iDict = 0; iDict < kNDict; iDict++) 
+       {
+         Char_t branchname[15];
+         sprintf(branchname,"TRDdictionary%d",iDict);
+         status = LoadArrayDict(fDict[iDict],branchname,fTree);
+         if (status == kFALSE) 
+           {
+             fUseDictionaries = kFALSE;
+             AliWarning("Unable to load dict arrays. Will not use them.\n");
+             break;
+           }
+       }  
+    }
 
   return kTRUE;
 
@@ -317,36 +464,46 @@ Bool_t AliTRDdigitsManager::WriteDigits()
   // Writes out the TRD-digits and the dictionaries
   //
 
-  // Store the contents of the segment array in the tree
-  if (!fDigits->StoreArray("TRDdigits",fTree)) {
-    AliError("Error while storing digits in branch TRDdigits\n");
-    return kFALSE;
-  }
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    Char_t branchname[15];
-    sprintf(branchname,"TRDdictionary%d",iDict);
-    if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
-      AliError(Form("Error while storing dictionary in branch %s\n",branchname));
+  // Store the contents of the detector array in the tree
+
+  if (!StoreArray(fDigits,"TRDdigits",fTree))
+    {
+      AliError("Error while storing digits in branch TRDdigits\n");
       return kFALSE;
     }
-  }
 
+  if (fUseDictionaries) 
+    {
+      for (Int_t iDict = 0; iDict < kNDict; iDict++)
+       {
+         Char_t branchname[15];
+         sprintf(branchname,"TRDdictionary%d",iDict);
+         if (!StoreArrayDict(fDict[iDict],branchname,fTree)) 
+           {
+             AliError(Form("Error while storing dictionary in branch %s\n",branchname));
+             return kFALSE;
+           }
+       }
+    }
+  
   // Write the new tree to the output file
-  fTree->AutoSave();  // Modification by Jiri
+  fTree->AutoSave();
 
   return kTRUE;
 
 }
 
 //_____________________________________________________________________________
-AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
-                                         , Int_t time, Int_t det) const
+AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
+                                         , Int_t col
+                                         , Int_t time
+                                         , Int_t det) const
 {
   // 
   // Creates a single digit object 
   //
 
-  Int_t digits[4];
+  Int_t digits[4]; 
   Int_t amp[1];
 
   digits[0] = det;
@@ -354,66 +511,116 @@ AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
   digits[2] = col;
   digits[3] = time;
 
-  amp[0]    = GetDigits(det)->GetData(row,col,time);
+  amp[0]    = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
   
-  return (new AliTRDdigit(fIsRaw,digits,amp));
+  return (new AliTRDdigit(digits,amp));
 
 }
 
 //_____________________________________________________________________________
 Int_t AliTRDdigitsManager::GetTrack(Int_t track
-                                  , Int_t row, Int_t col, Int_t time
+                                  , Int_t row
+                                  , Int_t col
+                                  , Int_t time
                                   , Int_t det) const
 {
   // 
   // Returns the MC-track numbers from the dictionary.
   //
 
-  if ((track < 0) || (track >= kNDict)) {
-    AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)"
-                 ,track,kNDict,this));
-    return -1;
-  }
+  if ((track < 0) || (track >= kNDict)) 
+    {
+      AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
+      return -1;
+    }
+
+  if (fUseDictionaries == kFALSE) 
+    {
+      return -1;
+    }
 
-  // Array contains index+1 to allow data compression
-  return (GetDictionary(det,track)->GetData(row,col,time) - 1);
+  // Array contains index+1 to allow data compression--->Changed
+  return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
 
 }
 
-//_____________________________________________________________________________
-AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
+//________________________________________________________________________________
+AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
 {
   //
   // Returns the digits array for one detector
   //
 
-  if (!fDigits) return 0x0;
-  return (AliTRDdataArrayI *) fDigits->At(det);
+  if (!fDigits)   
+    {
+      return 0x0;
+    }
+
+  if (!fHasSDigits)
+    {
+      return (AliTRDarrayADC *) fDigits->At(det); 
+    }
+  else
+    {
+      AliDebug(2,"ERROR IN DATA TYPE!!!!");
+      return 0x0;
+    }
+
+}
+
+//_____________________________________________________________________________
+AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
+{
+  //
+  // Returns the sdigits array for one detector
+  //
+
+  if (!fDigits)   
+    {
+      //      AliDebug(1,"NO FDIGITS!");       
+      return 0x0;
+    }
+
+  if (fHasSDigits)
+    {
+      return (AliTRDarraySignal *) fDigits->At(det);
+    }
+  else
+    {
+      AliDebug(2,"ERROR IN DATA TYPE!!!!");
+      return 0x0;
+    }
 
 }
 
 //_____________________________________________________________________________
-AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
+AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
+                                                        , Int_t i) const
 {
   //
   // Returns the dictionary for one detector
   //
 
-  return (AliTRDdataArrayI *) fDictionary[i]->At(det);
+  if (fUseDictionaries == kFALSE)
+    {
+      return 0x0;
+    }
 
+  return (AliTRDarrayDictionary *) fDict[i]->At(det);
+  
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
+Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *digit) const
 {
   // 
   // Returns the MC-track numbers from the dictionary for a given digit
   //
 
-  Int_t row  = Digit->GetRow();
-  Int_t col  = Digit->GetCol();
-  Int_t time = Digit->GetTime();
-  Int_t det  = Digit->GetDetector();
+  Int_t row  = digit->GetRow();
+  Int_t col  = digit->GetCol();
+  Int_t time = digit->GetTime();
+  Int_t det  = digit->GetDetector();
 
   return GetTrack(track,row,col,time,det);
 
@@ -426,18 +633,30 @@ AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
   // Returns indexes of active pads
   //
 
-  return (AliTRDSignalIndex*)fSignalIndexes->At(det);
+  return (AliTRDSignalIndex *) fSignalIndexes->At(det);
 
 }
 
 //_____________________________________________________________________________
 void AliTRDdigitsManager::RemoveDigits(Int_t det) 
 {
-  // 
-  // Clear memory
-  //
+   // 
+   // Clear memory at det for Digits
+   //
 
-  fDigits->ClearSegment(det);
+  if (fDigits->At(det))
+    {
+      if (fHasSDigits) 
+        {
+          AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(det);
+          delete arr;
+       }
+      else 
+        {
+          AliTRDarrayADC    *arr = (AliTRDarrayADC *)    fDigits->RemoveAt(det);
+          delete arr;
+       }
+    }
 
 }
 
@@ -448,9 +667,19 @@ void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
   // Clear memory
   //
 
-  for (Int_t i = 0; i < kNDict; i++) {
-    fDictionary[i]->ClearSegment(det);
-  }
+  if (fUseDictionaries == kFALSE) 
+    {
+      return;
+    }
+
+  for (Int_t i = 0; i < kNDict; i++) 
+    {
+      if (fDict[i]->At(det))
+       {
+         AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(det);
+          delete arr;
+       }
+    }
 
 }
 
@@ -460,9 +689,10 @@ void AliTRDdigitsManager::ClearIndexes(Int_t det)
   // 
   // Clear memory
   //
-  fSignalIndexes->At(det)->Clear();  
-}
 
+  ((AliTRDSignalIndex *) fSignalIndexes->At(det))->ClearAll();  
+
+}
 
 //_____________________________________________________________________________
 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
@@ -471,54 +701,272 @@ Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
   // Build the list of indices
   //
 
-  Int_t nRows = 0;
-  Int_t nCols = 0;
+  Int_t nRows  = 0;
+  Int_t nCols  = 0;
   Int_t nTbins = 0;
 
-  AliTRDgeometry    geom;
-  AliTRDdataArrayI *digits = GetDigits(det);
+  AliTRDgeometry  geom;
+  AliTRDarrayADC *digits = 0x0;
+
+  if (fHasSDigits) 
+    {
+      return kFALSE;
+    }
+  else 
+    {
+      digits = (AliTRDarrayADC *) GetDigits(det);
+    }
+
   //digits should be expanded by now!!!
   if (digits->GetNtime() > 0) 
-    {
-      digits->Expand();
-      nRows = digits->GetNrow();
-      nCols = digits->GetNcol();
+    {      
+      digits->Expand(); 
+      nRows  = digits->GetNrow();
+      nCols  = digits->GetNcol();
       nTbins = digits->GetNtime();
-
-      //AliInfo(Form("rows %d cols %d tbins %d", nRows, nCols, nTbins));
-
-      AliTRDSignalIndex* indexes = GetIndexes(det);
+      
+      AliTRDSignalIndex *indexes = GetIndexes(det);
       indexes->SetSM(geom.GetSector(det));
-      indexes->SetChamber(geom.GetChamber(det));
-      indexes->SetPlane(geom.GetPlane(det));
+      indexes->SetStack(geom.GetStack(det));
+      indexes->SetLayer(geom.GetLayer(det));
       indexes->SetDetNumber(det);
+
       if (indexes->IsAllocated() == kFALSE)
        {
-         indexes->Allocate(nRows, nCols, nTbins);
-         //AliInfo(Form("Allocating 0x%x %d", indexes->GetArray(), indexes->GetArray()->GetSize()));
+         indexes->Allocate(nRows,nCols,nTbins);
        }
-      for (Int_t ir = 0; ir < nRows; ir++)
+
+      for (Int_t ir = 0; ir < nRows; ir++) 
        {
-         for (Int_t ic = 0; ic < nCols; ic++)
+         for (Int_t ic = 0; ic < nCols; ic++) 
            {
              for (Int_t it = 0; it < nTbins; it++)
                {         
-                 //AliInfo(Form("row %d col %d tbin %d", ir, ic, it));
-                 
-                 Int_t isig = digits->GetDataUnchecked(ir, ic, it);
-                 if (isig > 0)
+                 Int_t isig = digits->GetDataB(ir,ic,it);
+                 if (isig > 0) 
                    {
-                     //AliInfo(Form("row %d col %d tbin %d", ir, ic, it));
-                     indexes->AddIndexTBin(ir, ic, it);            
+                     indexes->AddIndexRC(ir,ic);           
                    }
-               } //tbins
-           } //cols
+               } // tbins
+           } // cols
        } // rows
+
     } // if GetNtime
-  else
+  else 
     {
       return kFALSE;
     }
+  
   return kTRUE;
 
 }
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::LoadArray(TObjArray *object
+                                    , const Char_t *branchname
+                                    , TTree *tree)
+{
+  //
+  // Loads all detectors of the array from the branch <branchname> of
+  // the digits tree <tree>
+  // Adapted from code of the class AliTRDsegmentArray
+  //
+
+  fTreeD = tree;
+
+  if (!fTreeD) 
+    {
+      AliError("Digits tree is not defined\n");
+      return kFALSE;
+    }
+
+  // Get the branch
+  fBranch = fTreeD->GetBranch(branchname);
+  if (!fBranch) 
+    {
+      AliError(Form("Branch %s is not defined\n",branchname));
+      return kFALSE;
+    }
+
+  // Loop through all detectors and read them from the tree
+  Bool_t status = kTRUE;
+  for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) 
+    {
+      if(fHasSDigits)
+       {
+         AliTRDarraySignal *dataArray = (AliTRDarraySignal *) object->At(iDet);
+         if (!dataArray) 
+           {
+             status = kFALSE;
+             break;    
+           }
+
+         fBranch->SetAddress(&dataArray);
+         fBranch->GetEntry(iDet);
+       }
+      else
+       {
+         AliTRDarrayADC *dataArray = (AliTRDarrayADC *) object->At(iDet);
+         if (!dataArray) 
+           {
+             status = kFALSE;
+             break;    
+           }
+         fBranch->SetAddress(&dataArray);
+         fBranch->GetEntry(iDet);
+       }
+    }
+
+  return status;
+
+}
+
+//________________________________________________________________________________________________
+Bool_t AliTRDdigitsManager::LoadArrayDict(TObjArray *object
+                                        , const Char_t *branchname
+                                        , TTree *tree)
+{
+  //
+  // Loads all detectors of the array from the branch <branchname> of
+  // the dictionary tree <tree>
+  // Adapted from code of the class AliTRDsegmentArray
+  //
+
+  fTreeD = tree;
+
+  if (!fTreeD) 
+    {
+      AliError("Digits tree is not defined\n");
+      return kFALSE;
+    }
+
+  // Get the branch
+  fBranch = fTreeD->GetBranch(branchname);
+  if (!fBranch) 
+    {
+      AliError(Form("Branch %s is not defined\n",branchname));
+      return kFALSE;
+    }
+
+  // Loop through all detectors and read them from the tree
+  Bool_t status = kTRUE;
+  for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) 
+    {
+      AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) object->At(iDet);
+      if (!dataArray) 
+       {
+         status = kFALSE;
+         break;    
+       }
+      fBranch->SetAddress(&dataArray);
+      fBranch->GetEntry(iDet);
+    }
+
+  return status;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::StoreArray(TObjArray *array1
+                                     , const Char_t *branchname
+                                     , TTree *tree)
+{
+  //
+  // Stores all the detectors of the array in the branch <branchname> of 
+  // the digits tree <tree>
+  // Adapted from code of the class AliTRDsegmentArray
+  //
+
+  fTree = tree;
+
+  if (!fTree) 
+    {
+      AliError("Digits tree is not defined\n");
+      return kFALSE;
+    }
+
+  // Get the branch
+  fBranch = fTree->GetBranch(branchname);
+  if (!fBranch) 
+    {
+      AliError(Form("Branch %s is not defined\n",branchname));
+      return kFALSE;
+    }
+
+  // Loop through all detectors and fill them into the tree
+  Bool_t status = kTRUE;
+  for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) 
+    {
+      if (fHasSDigits)
+       {
+         const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) array1->At(iDet);
+         if (!kDataArray) 
+           {
+             status = kFALSE;
+             break;
+           }
+         fBranch->SetAddress(&kDataArray);
+         fBranch->Fill();
+       }
+      else
+       {
+         const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) array1->At(iDet); 
+         if (!kDataArray) 
+           {
+             status = kFALSE;
+             break;
+           }
+         fBranch->SetAddress(&kDataArray);
+         fBranch->Fill();
+       }
+    }
+
+  return status;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::StoreArrayDict(TObjArray *array3
+                                         , const Char_t *branchname
+                                         , TTree *tree)
+{
+  //
+  // Stores all the dictionary arrays of the detectors of the array in the branch <branchname> of 
+  // the dictionary tree <tree>
+  // Adapted from code of the class AliTRDsegmentArray
+  //
+
+  //  AliDebug(1,"Storing Arrays of Dictionary");
+  fTree = tree;
+
+  if (!fTree) 
+    {
+      AliError("Digits tree is not defined\n");
+      return kFALSE;
+    }
+
+  // Get the branch
+  fBranch = fTree->GetBranch(branchname);
+  if (!fBranch) 
+    {
+      AliError(Form("Branch %s is not defined\n",branchname));
+      return kFALSE;
+    }
+
+  // Loop through all detectors and fill them into the tree
+  Bool_t status = kTRUE;
+  for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) 
+    {
+      const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) array3->At(iDet);
+      if (!kDataArray) 
+       {
+         status = kFALSE;
+         break;
+       }
+      fBranch->SetAddress(&kDataArray);
+      fBranch->Fill();
+    }
+
+  return status;
+
+}