]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDclusterizer.cxx
Added method FillFromParticles()
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizer.cxx
index f13669d953faaa9ded0499fa81d456986fc897a3..d185bb79c88b4b33d1547f8c258dc624a5ad0a37 100644 (file)
 
 /*
 $Log$
+Revision 1.10  2001/11/14 10:50:45  cblume
+Changes in digits IO. Add merging of summable digits
+
+Revision 1.9  2001/10/21 18:30:02  hristov
+Several pointers were set to zero in the default constructors to avoid memory management problems
+
+Revision 1.8  2001/05/07 08:06:44  cblume
+Speedup of the code. Create only AliTRDcluster
+
+Revision 1.7  2001/03/30 14:40:14  cblume
+Update of the digitization parameter
+
+Revision 1.6  2000/11/01 14:53:20  cblume
+Merge with TRD-develop
+
+
+Revision 1.1.4.5  2000/10/15 23:40:01  cblume
+Remove AliTRDconst
+
+Revision 1.1.4.4  2000/10/06 16:49:46  cblume
+Made Getters const
+
+Revision 1.1.4.3  2000/10/04 16:34:58  cblume
+Replace include files by forward declarations
+
+Revision 1.1.4.2  2000/09/22 14:49:49  cblume
+Adapted to tracking code
+
+Revision 1.5  2000/10/02 21:28:19  fca
+Removal of useless dependecies via forward declarations
+
+Revision 1.4  2000/06/09 11:10:07  cblume
+Compiler warnings and coding conventions, next round
+
+Revision 1.3  2000/06/08 18:32:58  cblume
+Make code compliant to coding conventions
+
+Revision 1.2  2000/05/08 16:17:27  cblume
+Merge TRD-develop
+
+Revision 1.1.4.1  2000/05/08 15:08:03  cblume
+Remove the class AliTRDcluster
+
+Revision 1.4  2000/06/09 11:10:07  cblume
+Compiler warnings and coding conventions, next round
+
 Revision 1.3  2000/06/08 18:32:58  cblume
 Make code compliant to coding conventions
 
@@ -35,10 +81,16 @@ Add new TRD classes
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include "AliRun.h"
+#include <TROOT.h>
+#include <TTree.h>
+#include <TFile.h>
 
+#include "AliRun.h"
 #include "AliTRD.h"
 #include "AliTRDclusterizer.h"
+#include "AliTRDcluster.h"
+#include "AliTRDrecPoint.h"
+#include "AliTRDgeometry.h"
 
 ClassImp(AliTRDclusterizer)
 
@@ -49,8 +101,12 @@ AliTRDclusterizer::AliTRDclusterizer():TNamed()
   // AliTRDclusterizer default constructor
   //
 
-  fInputFile = NULL;
-  fEvent     = 0;
+  fInputFile   = NULL;
+  fOutputFile  = NULL;
+  fClusterTree = NULL;
+  fTRD         = 0;
+  fEvent       = 0;
+  fVerbose     = 0;
 
 }
 
@@ -62,10 +118,11 @@ AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
   // AliTRDclusterizer default constructor
   //
 
-  fInputFile = NULL;
-  fEvent     = 0;
-
-  Init();
+  fInputFile   = NULL;
+  fOutputFile  = NULL;
+  fClusterTree = NULL;
+  fEvent       = 0;
+  fVerbose     = 0;
 
 }
 
@@ -92,6 +149,15 @@ AliTRDclusterizer::~AliTRDclusterizer()
     delete fInputFile;
   }
 
+  if (fOutputFile) {
+    fOutputFile->Close();
+    delete fOutputFile;
+  }
+
+  if (fClusterTree) {
+    delete fClusterTree;
+  }
+
 }
 
 //_____________________________________________________________________________
@@ -113,22 +179,78 @@ void AliTRDclusterizer::Copy(TObject &c)
   // Copy function
   //
 
-  ((AliTRDclusterizer &) c).fInputFile = NULL;
-  ((AliTRDclusterizer &) c).fEvent     = 0;  
+  ((AliTRDclusterizer &) c).fInputFile   = NULL;
+  ((AliTRDclusterizer &) c).fOutputFile  = NULL;
+  ((AliTRDclusterizer &) c).fClusterTree = NULL;
+  ((AliTRDclusterizer &) c).fEvent       = 0;  
+  ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
 
 }
 
 //_____________________________________________________________________________
-void AliTRDclusterizer::Init()
+Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
 {
   //
-  // Initializes the cluster finder
+  // Opens the AliROOT file. Output and input are in the same file
   //
 
+  OpenInput(name,nEvent);
+  OpenOutput(name);
+
+  return kTRUE;
+
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
+Bool_t AliTRDclusterizer::Open(const Char_t *inname, const Char_t *outname
+                              , Int_t nEvent)
+{
+  //
+  // Opens the AliROOT file. Output and input are in different files
+  //
+
+  OpenInput(inname,nEvent);
+  OpenOutput(outname);
+
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::OpenOutput(const Char_t *name)
+{
+  //
+  // Open the output file
+  //
+
+  TDirectory *savedir = NULL;
+
+  if (!fInputFile) return kFALSE;
+
+  if (strcmp(name,fInputFile->GetName()) != 0) {
+    savedir = gDirectory;
+    printf("AliTRDclusterizer::OpenOutput -- ");
+    printf("Open the output file %s.\n",name);
+    fOutputFile = new TFile(name,"RECREATE");
+  }
+
+  // Create a tree for the cluster
+  Char_t treeName[12];
+  sprintf(treeName,"TreeR%d_TRD",fEvent);
+  fClusterTree = new TTree(treeName,"TRD cluster");
+  TObjArray *ioArray = 0;
+  fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
+
+  if (savedir) {
+    savedir->cd();
+  }
+
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::OpenInput(const Char_t *name, Int_t nEvent)
 {
   //
   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
@@ -137,58 +259,114 @@ Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
   // Connect the AliRoot file containing Geometry, Kine, and Hits
   fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
   if (!fInputFile) {
-    printf("AliTRDclusterizer::Open -- ");
+    printf("AliTRDclusterizer::OpenInput -- ");
     printf("Open the ALIROOT-file %s.\n",name);
     fInputFile = new TFile(name,"UPDATE");
   }
   else {
-    printf("AliTRDclusterizer::Open -- ");
+    printf("AliTRDclusterizer::OpenInput -- ");
     printf("%s is already open.\n",name);
   }
 
-  // Get AliRun object from file or create it if not on file
-  //if (!gAlice) {
-    gAlice = (AliRun*) fInputFile->Get("gAlice");
-    if (gAlice) {
-      printf("AliTRDclusterizer::Open -- ");
-      printf("AliRun object found on file.\n");
-    }
-    else {
-      printf("AliTRDclusterizer::Open -- ");
-      printf("Could not find AliRun object.\n");
-      return kFALSE;
-    }
-  //}
+  // Get AliRun object from file
+  gAlice = (AliRun *) fInputFile->Get("gAlice");
+  if (!(gAlice)) {
+    printf("AliTRDclusterizer::OpenInput -- ");
+    printf("Could not find AliRun object.\n");
+    return kFALSE;
+  }
 
   fEvent = nEvent;
 
   // Import the Trees for the event nEvent in the file
   Int_t nparticles = gAlice->GetEvent(fEvent);
   if (nparticles <= 0) {
-    printf("AliTRDclusterizer::Open -- ");
+    printf("AliTRDclusterizer::OpenInput -- ");
     printf("No entries in the trees for event %d.\n",fEvent);
     return kFALSE;
   }
 
+  // Get the TRD object
+  fTRD = (AliTRD*) gAlice->GetDetector("TRD"); 
+  if (!fTRD) {
+    printf("AliTRDclusterizer::OpenInput -- ");
+    printf("No TRD detector object found\n");
+    return kFALSE;
+  }
+
   return kTRUE;
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDclusterizer::WriteCluster()
+Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
 {
   //
-  // Writes out the TRD-cluster
+  // Fills TRDcluster branch in the tree with the clusters 
+  // found in detector = det. For det=-1 writes the tree. 
   //
 
-  // Write the new tree into the input file (use overwrite option)
-  Char_t treeName[7];
-  sprintf(treeName,"TreeR%d",fEvent);
-  printf("AliTRDclusterizer::WriteCluster -- ");
-  printf("Write the cluster tree %s for event %d.\n"
-        ,treeName,fEvent);
-  gAlice->TreeR()->Write(treeName,2);
+  if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
+    printf("AliTRDclusterizer::WriteClusters -- ");
+    printf("Unexpected detector index %d.\n",det);
+    return kFALSE;
+  }
+  TDirectory *savedir = gDirectory;
 
-  return kTRUE;
+  if (fOutputFile) {
+    fOutputFile->cd();
+  }
+
+  TBranch *branch = fClusterTree->GetBranch("TRDcluster");
+  if (!branch) {
+    TObjArray *ioArray = 0;
+    branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
+  }
+
+  if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
+
+    Int_t nRecPoints = fTRD->RecPoints()->GetEntriesFast();
+    TObjArray *detRecPoints = new TObjArray(400);
+
+    for (Int_t i = 0; i < nRecPoints; i++) {
+      AliTRDcluster *c = (AliTRDcluster *) fTRD->RecPoints()->UncheckedAt(i);
+      if (det == c->GetDetector()) {
+        detRecPoints->AddLast(c);
+      }
+      else {
+        printf("AliTRDclusterizer::WriteClusters --");
+        printf("Attempt to write a cluster with unexpected detector index\n");
+      }
+    }
+
+    branch->SetAddress(&detRecPoints);
+    fClusterTree->Fill();
+
+    return kTRUE;
+
+  }
+
+  if (det == -1) {
+
+    printf("AliTRDclusterizer::WriteClusters -- ");
+    printf("Writing the cluster tree %-18s for event %d.\n"
+         ,fClusterTree->GetName(),fEvent);
+
+    fClusterTree->Write();
+     
+    return kTRUE;  
+
+  }
+  
+  savedir->cd();
+
+  printf("AliTRDclusterizer::WriteClusters -- ");
+  printf("Unexpected detector index %d.\n",det);
+  return kFALSE;  
 
 }
+
+
+