]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdigitsManager.cxx
BlockFilter component added; minor corrections
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
index 5d1e88fc69833c74a654c0b6015cc2962e2f2709..199855e62ac465fcac0ff7af914f626e252c954c 100644 (file)
@@ -29,6 +29,7 @@
 #include <TFile.h>
 
 #include "AliRun.h"
+#include "AliLog.h"
 
 #include "AliTRDdigitsManager.h"
 #include "AliTRDsegmentArray.h"
@@ -36,6 +37,8 @@
 #include "AliTRDdigit.h"
 #include "AliTRDgeometry.h"
 
+#include "AliTRDSignalIndex.h"
+
 ClassImp(AliTRDdigitsManager)
 
 //_____________________________________________________________________________
@@ -44,35 +47,44 @@ ClassImp(AliTRDdigitsManager)
   const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
 
 //_____________________________________________________________________________
-AliTRDdigitsManager::AliTRDdigitsManager():TObject()
+AliTRDdigitsManager::AliTRDdigitsManager()
+  :TObject()
+  ,fEvent(0)
+  ,fTree(0)
+  ,fDigits(0)
+  ,fIsRaw(0)
+  ,fSDigits(0)
+  ,fSignalIndexes(NULL)
+  ,fUseDictionaries(kTRUE)
 {
   //
   // Default constructor
   //
 
-  fIsRaw   = kFALSE;
-  fEvent   = 0;
-  fDebug   = 0;
-  fSDigits = 0;
-
-  fTree    = NULL;
-  fDigits  = NULL;
   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
     fDictionary[iDict] = NULL;
   }
-
+  
+  //fSignalIndexes = new TList();
+  fSignalIndexes = new TObjArray(AliTRDgeometry::Ndet());
+  
 }
 
 //_____________________________________________________________________________
 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
-:TObject(m)
+  :TObject(m)
+  ,fEvent(m.fEvent)
+  ,fTree(0)
+  ,fDigits(0)
+  ,fIsRaw(m.fIsRaw)
+  ,fSDigits(m.fSDigits)
+  ,fSignalIndexes(NULL)
+  ,fUseDictionaries(kTRUE)
 {
   //
   // AliTRDdigitsManager copy constructor
   //
 
-  ((AliTRDdigitsManager &) m).Copy(*this);
-
 }
 
 //_____________________________________________________________________________
@@ -94,10 +106,28 @@ AliTRDdigitsManager::~AliTRDdigitsManager()
     fDictionary[iDict] = NULL;
   }
 
+  if (fSignalIndexes) {
+    fSignalIndexes->Delete();
+    delete fSignalIndexes;
+  }
+  fSignalIndexes = NULL;
+
+}
+
+//_____________________________________________________________________________
+AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
+{
+  //
+  // Assignment operator
+  //
+
+  if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
+  return *this;
+
 }
 
 //_____________________________________________________________________________
-void AliTRDdigitsManager::Copy(TObject &m)
+void AliTRDdigitsManager::Copy(TObject &m) const
 {
   //
   // Copy function
@@ -105,8 +135,10 @@ void AliTRDdigitsManager::Copy(TObject &m)
 
   ((AliTRDdigitsManager &) m).fIsRaw   = fIsRaw;
   ((AliTRDdigitsManager &) m).fEvent   = fEvent;
-  ((AliTRDdigitsManager &) m).fDebug   = fDebug;
   ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
+  
+  ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
+  ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
 
   TObject::Copy(m);
 
@@ -121,11 +153,18 @@ void AliTRDdigitsManager::CreateArrays()
 
   fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
-                                               ,AliTRDgeometry::Ndet());
-  }
+  if (fUseDictionaries)
+    {
+      for (Int_t iDict = 0; iDict < kNDict; iDict++) {
+       fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
+                                                   ,AliTRDgeometry::Ndet());
+      }
+    }
 
+  for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
+    {
+      fSignalIndexes->AddLast(new AliTRDSignalIndex());
+    }
 }
 //_____________________________________________________________________________
 void AliTRDdigitsManager::ResetArrays()
@@ -135,18 +174,28 @@ void AliTRDdigitsManager::ResetArrays()
   //
 
   if (fDigits) {
+    fDigits->Delete();
     delete fDigits;
   }
   fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    if (fDictionary[iDict]) {  
-      delete fDictionary[iDict];
+  if (fUseDictionaries)
+    {
+      for (Int_t iDict = 0; iDict < kNDict; iDict++) {
+       if (fDictionary[iDict]) { 
+         fDictionary[iDict]->Delete();
+         delete fDictionary[iDict];
+       }
+       fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
+                                                   ,AliTRDgeometry::Ndet());
+      }
     }
-    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
-                                               ,AliTRDgeometry::Ndet());
-  }
 
+  for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
+    {
+      AliTRDSignalIndex *idx = (AliTRDSignalIndex *)fSignalIndexes->At(i);
+      if (idx) idx->Reset();
+    }
 }
 
 //_____________________________________________________________________________
@@ -157,8 +206,8 @@ void AliTRDdigitsManager::SetRaw()
   //
 
   fIsRaw = kTRUE;
-
-  fDigits->SetBit(AliTRDdigit::RawDigit());
+  if (fDigits)
+    fDigits->SetBit(AliTRDdigit::RawDigit());
   
 }
 
@@ -170,6 +219,7 @@ Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
   // Returns the amplitude of a digit
   //
 
+  if (!GetDigits(det)) return 0;
   return ((Short_t) GetDigits(det)->GetData(row,col,time));
 
 }
@@ -197,10 +247,7 @@ Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
       TBranch* branch = fTree->GetBranch("TRDdigits");
       if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName(),
                                  &kDigits,buffersize,99);
-      if (fDebug > 0) {
-        printf("<AliTRDdigitsManager::MakeBranch> ");
-        printf("Making branch TRDdigits\n");
-      }
+      AliDebug(1,"Making branch TRDdigits\n");
     }
     else {
       status = kFALSE;
@@ -210,31 +257,31 @@ Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
     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(),
+  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 (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);
-        if (fDebug > 0) {
-          printf("<AliTRDdigitsManager::MakeBranch> ");
-          printf("Making branch %s\n",branchname);
+           AliDebug(1,Form("Making branch %s\n",branchname));
+         }
+         else {
+           status = kFALSE;
+         }
+       }
+       else {
+         status = kFALSE;
        }
       }
-      else {
-        status = kFALSE;
-      }
-    }
-    else {
-      status = kFALSE;
     }
-  }
 
   return status;
 
@@ -256,20 +303,26 @@ Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
   }
 
   if (!fDigits) {
-    if (fDebug > 0) {
-      printf("<AliTRDdigitsManager::ReadDigits> ");
-      printf("Create the data arrays.\n");
-    }
+    AliDebug(1,"Create the data arrays.\n");
     CreateArrays();
   }
 
   status = fDigits->LoadArray("TRDdigits",fTree);
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    Char_t branchname[15];
-    sprintf(branchname,"TRDdictionary%d",iDict);
-    status = fDictionary[iDict]->LoadArray(branchname,fTree);
-  }  
+  if (fUseDictionaries)
+    {
+      for (Int_t iDict = 0; iDict < kNDict; iDict++) {
+       Char_t branchname[15];
+       sprintf(branchname,"TRDdictionary%d",iDict);
+       status = fDictionary[iDict]->LoadArray(branchname,fTree);
+       if (status == kFALSE)
+         {
+           fUseDictionaries = kFALSE;
+           AliWarning("Unable to load dict arrays. Will not use them.\n");
+           break;
+         }
+      }  
+    }
 
   if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
     fIsRaw = kTRUE;
@@ -291,22 +344,23 @@ Bool_t AliTRDdigitsManager::WriteDigits()
 
   // Store the contents of the segment array in the tree
   if (!fDigits->StoreArray("TRDdigits",fTree)) {
-    printf("<AliTRDdigitsManager::WriteDigits> ");
-    printf("Error while storing digits in branch TRDdigits\n");
+    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)) {
-      printf("<AliTRDdigitsManager::WriteDigits> ");
-      printf("Error while storing dictionary in branch %s\n",branchname);
-      return kFALSE;
+
+  if (fUseDictionaries)
+    {
+      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));
+         return kFALSE;
+       }
+      }
     }
-  }
 
   // Write the new tree to the output file
-  //fTree->Write();
   fTree->AutoSave();  // Modification by Jiri
 
   return kTRUE;
@@ -345,12 +399,15 @@ Int_t AliTRDdigitsManager::GetTrack(Int_t track
   //
 
   if ((track < 0) || (track >= kNDict)) {
-    TObject::Error("GetTracks"
-                  ,"track %d out of bounds (size: %d, this: 0x%08x)"
-                  ,track,kNDict,this);
+    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);
 
@@ -363,6 +420,7 @@ AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
   // Returns the digits array for one detector
   //
 
+  if (!fDigits) return 0x0;
   return (AliTRDdataArrayI *) fDigits->At(det);
 
 }
@@ -373,6 +431,10 @@ AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
   //
   // Returns the dictionary for one detector
   //
+  if (fUseDictionaries == kFALSE)
+    {
+      return NULL;
+    }
 
   return (AliTRDdataArrayI *) fDictionary[i]->At(det);
 
@@ -395,13 +457,109 @@ Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
 }
 
 //_____________________________________________________________________________
-AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
+AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det) 
 {
+  // 
+  // Returns indexes of active pads
   //
-  // Assignment operator
+
+  return (AliTRDSignalIndex*)fSignalIndexes->At(det);
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::RemoveDigits(Int_t det) 
+{
+  // 
+  // Clear memory
   //
 
-  if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
-  return *this;
+  fDigits->ClearSegment(det);
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::RemoveDictionaries(Int_t det) 
+{
+  // 
+  // Clear memory
+  //
+  if (fUseDictionaries == kFALSE)
+    {
+      return;
+    }
+
+  for (Int_t i = 0; i < kNDict; i++) {
+    fDictionary[i]->ClearSegment(det);
+  }
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::ClearIndexes(Int_t det) 
+{
+  // 
+  // Clear memory
+  //
+  fSignalIndexes->At(det)->Clear();  
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
+{
+  //
+  // Build the list of indices
+  //
+
+  Int_t nRows = 0;
+  Int_t nCols = 0;
+  Int_t nTbins = 0;
+
+  AliTRDgeometry    geom;
+  AliTRDdataArrayI *digits = GetDigits(det);
+  //digits should be expanded by now!!!
+  if (digits->GetNtime() > 0) 
+    {
+      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);
+      indexes->SetSM(geom.GetSector(det));
+      indexes->SetChamber(geom.GetChamber(det));
+      indexes->SetPlane(geom.GetPlane(det));
+      indexes->SetDetNumber(det);
+      if (indexes->IsAllocated() == kFALSE)
+       {
+         indexes->Allocate(nRows, nCols, nTbins);
+         //AliInfo(Form("Allocating 0x%x %d", indexes->GetArray(), indexes->GetArray()->GetSize()));
+       }
+      for (Int_t ir = 0; ir < nRows; ir++)
+       {
+         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)
+                   {
+                     //AliInfo(Form("row %d col %d tbin %d", ir, ic, it));
+                     indexes->AddIndexTBin(ir, ic, it);            
+                   }
+               } //tbins
+           } //cols
+       } // rows
+    } // if GetNtime
+  else
+    {
+      return kFALSE;
+    }
+  return kTRUE;
 
 }