]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDclusterizer.cxx
Update with reading the survey data from EDMS tables
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizer.cxx
index b51dd38ee63abecd88a680a7e1fc8daf2dd153f6..4f493ba9ca17a0d878fb97edf0fa4a3f8489cf05 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-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.1  2000/02/28 18:57:58  cblume
-Add new TRD classes
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -32,49 +21,60 @@ Add new TRD classes
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include "AliRun.h"
+#include <TROOT.h>
+#include <TTree.h>
+#include <TFile.h>
+#include <TObjArray.h>
+
+#include "AliRunLoader.h"
+#include "AliLoader.h"
+#include "AliLog.h"
 
-#include "AliTRD.h"
 #include "AliTRDclusterizer.h"
+#include "AliTRDcluster.h"
+#include "AliTRDgeometry.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDCommonParam.h"
 
 ClassImp(AliTRDclusterizer)
 
 //_____________________________________________________________________________
-AliTRDclusterizer::AliTRDclusterizer():TNamed()
+AliTRDclusterizer::AliTRDclusterizer()
+  :TNamed()
+  ,fRunLoader(NULL)
+  ,fClusterTree(NULL)
+  ,fRecPoints(NULL)
 {
   //
   // AliTRDclusterizer default constructor
   //
 
-  fInputFile = NULL;
-  fEvent     = 0;
-
 }
 
 //_____________________________________________________________________________
 AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
-                  :TNamed(name, title)
+  :TNamed(name,title)
+  ,fRunLoader(NULL)
+  ,fClusterTree(NULL)
+  ,fRecPoints(NULL)
 {
   //
-  // AliTRDclusterizer default constructor
+  // AliTRDclusterizer constructor
   //
 
-  fInputFile = NULL;
-  fEvent     = 0;
-
-  Init();
-
 }
 
 //_____________________________________________________________________________
-AliTRDclusterizer::AliTRDclusterizer(AliTRDclusterizer &c)
+AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
+  :TNamed(c)
+  ,fRunLoader(NULL)
+  ,fClusterTree(NULL)
+  ,fRecPoints(NULL)
 {
   //
   // AliTRDclusterizer copy constructor
   //
 
-  c.Copy(*this);
-
 }
 
 //_____________________________________________________________________________
@@ -84,96 +84,243 @@ AliTRDclusterizer::~AliTRDclusterizer()
   // AliTRDclusterizer destructor
   //
 
-  if (fInputFile) {
-    fInputFile->Close();
-    delete fInputFile;
+  if (fRecPoints) {
+    fRecPoints->Delete();
+    delete fRecPoints;
   }
 
 }
 
 //_____________________________________________________________________________
-void AliTRDclusterizer::Copy(AliTRDclusterizer &c)
+AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
 {
   //
-  // Copy function
+  // Assignment operator
   //
 
-  c.fInputFile = NULL;
-  c.fEvent     = 0;  
+  if (this != &c) {
+    ((AliTRDclusterizer &) c).Copy(*this);
+  }
+  return *this;
 
 }
 
 //_____________________________________________________________________________
-void AliTRDclusterizer::Init()
+void AliTRDclusterizer::Copy(TObject &c) const
 {
   //
-  // Initializes the cluster finder
+  // Copy function
   //
 
+  ((AliTRDclusterizer &) c).fClusterTree = NULL;
+  ((AliTRDclusterizer &) c).fRecPoints   = NULL;  
+
 }
 
 //_____________________________________________________________________________
 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
+{
+  //
+  // Opens the AliROOT file. Output and input are in the same file
+  //
+
+  TString evfoldname = AliConfig::GetDefaultEventFolderName();
+  fRunLoader         = AliRunLoader::GetRunLoader(evfoldname);
+
+  if (!fRunLoader) {
+    fRunLoader = AliRunLoader::Open(name);
+  }
+
+  if (!fRunLoader) {
+    AliError(Form("Can not open session for file %s.",name));
+    return kFALSE;
+  }
+
+  OpenInput(nEvent);
+  OpenOutput();
+
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::OpenOutput()
+{
+  //
+  // Open the output file
+  //
+
+  TObjArray *ioArray = 0;
+
+  AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+  loader->MakeTree("R");
+
+  fClusterTree = loader->TreeR();
+  fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
+
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
+{
+  //
+  // Connect the output tree
+  //
+
+  TObjArray *ioArray = 0;
+
+  fClusterTree = clusterTree;
+  fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
+
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
 {
   //
   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
   //
 
-  // Connect the AliRoot file containing Geometry, Kine, and Hits
-  fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
-  if (!fInputFile) {
-    printf("AliTRDclusterizer::Open -- ");
-    printf("Open the ALIROOT-file %s.\n",name);
-    fInputFile = new TFile(name,"UPDATE");
+  // Import the Trees for the event nEvent in the file
+  fRunLoader->GetEvent(nEvent);
+  
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
+{
+  //
+  // Fills TRDcluster branch in the tree with the clusters 
+  // found in detector = det. For det=-1 writes the tree. 
+  //
+
+  if ((det <                      -1) || 
+      (det >= AliTRDgeometry::Ndet())) {
+    AliError(Form("Unexpected detector index %d.\n",det));
+    return kFALSE;
   }
-  else {
-    printf("AliTRDclusterizer::Open -- ");
-    printf("%s is already open.\n",name);
+  TBranch *branch = fClusterTree->GetBranch("TRDcluster");
+  if (!branch) {
+    TObjArray *ioArray = 0;
+    branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
   }
 
-  // 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");
+  if ((det >=                      0) && 
+      (det <  AliTRDgeometry::Ndet())) {
+
+    Int_t nRecPoints = RecPoints()->GetEntriesFast();
+    TObjArray *detRecPoints = new TObjArray(400);
+
+    for (Int_t i = 0; i < nRecPoints; i++) {
+      AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
+      if (det == c->GetDetector()) {
+        detRecPoints->AddLast(c);
+      }
+      else {
+        AliError("Attempt to write a cluster with unexpected detector index\n");
+      }
+    }
+
+    branch->SetAddress(&detRecPoints);
+    fClusterTree->Fill();
+
+    delete detRecPoints;
+
+    return kTRUE;
+
+  }
+
+  if (det == -1) {
+
+    AliInfo(Form("Writing the cluster tree %s for event %d."
+               ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
+
+    if (fRecPoints) {
+
+      branch->SetAddress(&fRecPoints);
+
+      AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
+      loader->WriteRecPoints("OVERWRITE");
+  
     }
     else {
-      printf("AliTRDclusterizer::Open -- ");
-      printf("Could not find AliRun object.\n");
+
+      AliError("Cluster tree does not exist. Cannot write clusters.\n");
       return kFALSE;
+
     }
-  //}
 
-  fEvent = nEvent;
+    return kTRUE;  
 
-  // Import the Trees for the event nEvent in the file
-  Int_t nparticles = gAlice->GetEvent(fEvent);
-  if (nparticles <= 0) {
-    printf("AliTRDclusterizer::Open -- ");
-    printf("No entries in the trees for event %d.\n",fEvent);
+  }
+
+  AliError(Form("Unexpected detector index %d.\n",det));
+  return kFALSE;  
+  
+}
+
+//_____________________________________________________________________________
+Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet
+                                              , Int_t col, Int_t row)
+{
+  //
+  // Calculates the local x position in the detector from the timebin, 
+  // depends on the drift velocity and t0
+  //
+  
+  AliTRDcalibDB     *calibration = AliTRDcalibDB::Instance();
+  if (!calibration) {
+    AliError("Cannot find calibration object");
+    return -1;
+  }
+  AliTRDCommonParam *parCom      = AliTRDCommonParam::Instance();
+  if (!parCom) {
+    AliError("Could not get common parameters\n");
     return kFALSE;
   }
 
-  return kTRUE;
+  Float_t vdrift            = calibration->GetVdrift(idet,col,row);  
+  Float_t t0                = calibration->GetT0(idet,col,row);
+  Float_t samplingFrequency = parCom->GetSamplingFrequency();
+
+  timebin -= t0;
+
+  return timebin / samplingFrequency * vdrift;
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDclusterizer::WriteCluster()
+void AliTRDclusterizer::ResetRecPoints() 
 {
   //
-  // Writes out the TRD-cluster
+  // Resets the list of rec points
   //
 
-  // 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 (fRecPoints) {
+    fRecPoints->Delete();
+  }
+
+}
 
-  return kTRUE;
+//_____________________________________________________________________________
+TObjArray *AliTRDclusterizer::RecPoints() 
+{
+  //
+  // Returns the list of rec points
+  //
+
+  if (!fRecPoints) {
+    fRecPoints = new TObjArray(400);
+  }
+  return fRecPoints;
 
 }