]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdigitsManager.cxx
Protection against division by 0 in Binaries().
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
index f5c28debaa2444352f24275ac679c610d53bdf6d..ab7a04e5879171012f13e4a51073546cad2e1b46 100644 (file)
 
 /*
 $Log$
+Revision 1.21  2003/02/04 17:26:00  cblume
+Include a reset of the digits arrays in order to process several events
+
+Revision 1.20  2002/10/22 15:53:08  alibrary
+Introducing Riostream.h
+
+Revision 1.19  2002/10/14 14:57:43  hristov
+Merging the VirtualMC branch to the main development branch (HEAD)
+
+Revision 1.16.6.2  2002/07/24 10:09:30  alibrary
+Updating VirtualMC
+
+Revision 1.16.6.1  2002/06/10 15:28:58  hristov
+Merged with v3-08-02
+
+Revision 1.18  2002/04/12 12:13:23  cblume
+Add Jiris changes
+
+Revision 1.17  2002/03/28 14:59:07  cblume
+Coding conventions
+
+Revision 1.18  2002/04/12 12:13:23  cblume
+Add Jiris changes
+
+Revision 1.17  2002/03/28 14:59:07  cblume
+Coding conventions
+
+Revision 1.16  2002/02/12 11:42:08  cblume
+Remove fTree from destructor
+
+Revision 1.15  2002/02/11 14:27:54  cblume
+Geometry and hit structure update
+
+Revision 1.14  2001/11/14 10:50:46  cblume
+Changes in digits IO. Add merging of summable digits
+
+Revision 1.13  2001/11/06 17:19:41  cblume
+Add detailed geometry and simple simulator
+
+Revision 1.12  2001/05/16 14:57:28  alibrary
+New files for folders and Stack
+
+Revision 1.11  2001/03/13 09:30:35  cblume
+Update of digitization. Moved digit branch definition to AliTRD
+
+Revision 1.10  2001/01/26 19:56:57  hristov
+Major upgrade of AliRoot code
+
 Revision 1.9  2000/11/02 09:25:53  cblume
 Change also the dictionary to AliTRDdataArray
 
@@ -59,7 +107,8 @@ Add new class AliTRDdigitsManager
 //  AliTRDdataArray objects.                                                 //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
-#include <iostream.h>
+
+#include <Riostream.h>
  
 #include <TROOT.h>
 #include <TTree.h>                                                              
@@ -72,6 +121,7 @@ Add new class AliTRDdigitsManager
 #include "AliTRDdataArrayI.h"
 #include "AliTRDdigit.h"
 #include "AliTRDgeometry.h"
+#include "AliTRD.h"
 
 ClassImp(AliTRDdigitsManager)
 
@@ -87,13 +137,17 @@ AliTRDdigitsManager::AliTRDdigitsManager():TObject()
   // Default constructor
   //
 
-  fIsRaw = kFALSE;
-
-  fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
+  fIsRaw   = kFALSE;
+  fEvent   = 0;
+  fDebug   = 0;
+  fSDigits = 0;
 
+  fFile    = NULL;
+  fFileCreated = kFALSE;
+  fTree    = NULL;
+  fDigits  = NULL;
   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
-                                               ,AliTRDgeometry::Ndet());
+    fDictionary[iDict] = NULL;
   }
 
 }
@@ -116,14 +170,22 @@ AliTRDdigitsManager::~AliTRDdigitsManager()
   // AliTRDdigitsManager destructor
   //
 
+  if (fFile && fFileCreated) {
+    fFile->Close();
+    delete fFile;
+    fFile = NULL;
+  }
+
   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;
   }
 
 }
@@ -135,15 +197,58 @@ void AliTRDdigitsManager::Copy(TObject &m)
   // Copy function
   //
 
-  ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
+  ((AliTRDdigitsManager &) m).fIsRaw   = fIsRaw;
+  ((AliTRDdigitsManager &) m).fEvent   = fEvent;
+  ((AliTRDdigitsManager &) m).fDebug   = fDebug;
+  ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
 
   TObject::Copy(m);
 
 }
 
+//_____________________________________________________________________________
+void AliTRDdigitsManager::CreateArrays()
+{
+  //
+  // Create the data arrays
+  //
+
+  fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
+
+  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
+    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
+                                               ,AliTRDgeometry::Ndet());
+  }
+
+}
+//_____________________________________________________________________________
+void AliTRDdigitsManager::ResetArrays()
+{
+  //
+  // Reset the data arrays
+  //
+
+  if (fDigits) {
+    delete fDigits;
+  }
+  fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
+
+  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
+    if (fDictionary[iDict]) {  
+      delete fDictionary[iDict];
+    }
+    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
+                                               ,AliTRDgeometry::Ndet());
+  }
+
+}
+
 //_____________________________________________________________________________
 void AliTRDdigitsManager::SetRaw()
 {
+  //
+  // Switch on the raw digits flag
+  //
 
   fIsRaw = kTRUE;
 
@@ -152,65 +257,146 @@ void AliTRDdigitsManager::SetRaw()
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdigitsManager::MakeBranch(char *file)
+Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
+                                       , Int_t det) const
+{
+  //
+  // Returns the amplitude of a digit
+  //
+
+  return ((Short_t) GetDigits(det)->GetData(row,col,time));
+
+}
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::Open(const Char_t *file)
+{
+  //
+  // Opens the file for the TRD digits
+  //
+
+  fFile = (TFile*) gROOT->GetListOfFiles()->FindObject(file);
+  if (!fFile) {
+    if (fDebug > 0) {
+      printf("<AliTRDdigitsManager::Open> ");
+      printf("Open the AliROOT-file %s.\n",file);
+    }
+    fFile = new TFile(file,"UPDATE");
+    fFileCreated = kTRUE;
+    if (!fFile) return kFALSE;
+  }
+  else {
+    if (fDebug > 0) {
+      printf("<AliTRDdigitsManager::Open> ");
+      printf("%s is already open.\n",file);
+    }
+  }
+
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::MakeTreeAndBranches(TFile *file, Int_t iEvent)
+{
+  //
+  // Creates tree for (s)digits in the specified file
+  //
+
+  fEvent = iEvent;
+  TDirectory *wd = gDirectory;
+  file->cd();
+  MakeBranch();
+  wd->cd();
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
+{
+  //
+  // Creates the tree and branches for the digits and the dictionary
+  //
+
+  // Create the TRD digits tree
+  TTree *tree;
+  Char_t treeName[12];
+  if (fSDigits) {
+    sprintf(treeName,"TreeS%d_TRD",fEvent);
+    tree = new TTree(treeName,"TRD SDigits");
+  }
+  else {
+    sprintf(treeName,"TreeD%d_TRD",fEvent);
+    tree = new TTree(treeName,"TRD Digits");
+  }
+
+  if (fDebug > 0) {
+    printf("<AliTRDdigitsManager::MakeBranch> ");
+    printf("Creating tree %s\n",treeName);
+  }
+
+  return MakeBranch(tree,file);
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree, const Char_t *file)
 {
   //
-  // Creates the branches for the digits and the dictionary in the digits tree
+  // Creates the tree and branches for the digits and the dictionary
   //
 
   Int_t buffersize = 64000;
 
   Bool_t status = kTRUE;
 
-  //TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("TRD.Digits.root");
+  AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD") ;
 
-  if (gAlice->TreeD()) {
+  if (tree) {
+    fTree = tree;
+  }
 
-    // Make the branch for the digits
-    if (fDigits) {
-      const AliTRDdataArray *kDigits = 
-           (AliTRDdataArray *) fDigits->At(0);
-      if (kDigits) {
-          gAlice->MakeBranchInTree(gAlice->TreeD(), 
-                                   "TRDdigits", kDigits->IsA()->GetName(),
-                                   &kDigits,buffersize, 1,file) ;
-        printf("AliTRDdigitsManager::MakeBranch -- ");
+  // Make the branch for the digits
+  if (fDigits) {
+    const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
+    if (kDigits) {
+      trd->MakeBranchInTree(fTree,"TRDdigits",kDigits->IsA()->GetName()
+                                 ,&kDigits,buffersize,99,file);
+      if (fDebug > 0) {
+        printf("<AliTRDdigitsManager::MakeBranch> ");
         printf("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) {
-            gAlice->MakeBranchInTree(gAlice->TreeD(), 
-                                     branchname,kDictionary->IsA()->GetName(),
-                                     &kDictionary,buffersize, 1,file) ;
-          printf("AliTRDdigitsManager::MakeBranch -- ");
+  // 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) {
+        trd->MakeBranchInTree(fTree,branchname,kDictionary->IsA()->GetName()
+                             ,&kDictionary,buffersize,99,file);
+        if (fDebug > 0) {
+          printf("<AliTRDdigitsManager::MakeBranch> ");
           printf("Making branch %s\n",branchname);
-           }
-        else {
-          status = kFALSE;
-           }
+       }
       }
       else {
         status = kFALSE;
       }
     }
-
-  }
-  else {
-    status = kFALSE;
+    else {
+      status = kFALSE;
+    }
   }
 
   return status;
@@ -218,7 +404,7 @@ Bool_t AliTRDdigitsManager::MakeBranch(char *file)
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdigitsManager::ReadDigits()
+Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
 {
   //
   // Reads the digit information from the input file
@@ -226,12 +412,52 @@ Bool_t AliTRDdigitsManager::ReadDigits()
 
   Bool_t status = kTRUE;
 
-  status = fDigits->LoadArray("TRDdigits");
+  if (tree) {
+
+    fTree = tree;
+
+  }
+  else {
+
+    // Get the digits tree
+    Char_t treeName[12];
+    if (fSDigits) {
+      sprintf(treeName,"TreeS%d_TRD",fEvent);
+    }
+    else {
+      sprintf(treeName,"TreeD%d_TRD",fEvent);
+    }
+    if (fFile) {
+      fTree = (TTree *) fFile->Get(treeName);
+    }
+    else {
+      fTree = (TTree *) gDirectory->Get(treeName);
+    }
+
+    if (!fTree) {
+      if (fDebug > 0) {
+        printf("<AliTRDdigitsManager::ReadDigits> ");
+        printf("Could not find tree %s.\n",treeName);
+      }
+      return kFALSE;
+    }
+
+  }
+
+  if (!fDigits) {
+    if (fDebug > 0) {
+      printf("<AliTRDdigitsManager::ReadDigits> ");
+      printf("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);
+    status = fDictionary[iDict]->LoadArray(branchname,fTree);
   }  
 
   if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
@@ -252,27 +478,26 @@ Bool_t AliTRDdigitsManager::WriteDigits()
   // Writes out the TRD-digits and the dictionaries
   //
 
-  // Create the branches
-  if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) { 
-    if (!MakeBranch()) return kFALSE;
-  }
-
   // Store the contents of the segment array in the tree
-  if (!fDigits->StoreArray("TRDdigits")) {
-    printf("AliTRDdigitsManager::WriteDigits -- ");
+  if (!fDigits->StoreArray("TRDdigits",fTree)) {
+    printf("<AliTRDdigitsManager::WriteDigits> ");
     printf("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)) {
-      printf("AliTRDdigitsManager::WriteDigits -- ");
+    if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
+      printf("<AliTRDdigitsManager::WriteDigits> ");
       printf("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;
 
 }