]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDclusterizer.cxx
Split DAQ DA into two tasks
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizer.cxx
index 58fcab22928da107e9319d728d21da2e87d009cf..4f493ba9ca17a0d878fb97edf0fa4a3f8489cf05 100644 (file)
 #include <TROOT.h>
 #include <TTree.h>
 #include <TFile.h>
+#include <TObjArray.h>
 
-#include "AliRun.h"
 #include "AliRunLoader.h"
 #include "AliLoader.h"
+#include "AliLog.h"
 
-#include "AliTRD.h"
 #include "AliTRDclusterizer.h"
 #include "AliTRDcluster.h"
-#include "AliTRDrecPoint.h"
 #include "AliTRDgeometry.h"
-#include "AliTRDparameter.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDCommonParam.h"
 
 ClassImp(AliTRDclusterizer)
 
 //_____________________________________________________________________________
-AliTRDclusterizer::AliTRDclusterizer():TNamed()
+AliTRDclusterizer::AliTRDclusterizer()
+  :TNamed()
+  ,fRunLoader(NULL)
+  ,fClusterTree(NULL)
+  ,fRecPoints(NULL)
 {
   //
   // AliTRDclusterizer default constructor
   //
 
-  fClusterTree = NULL;
-  fTRD         = 0;
-  fEvent       = 0;
-  fVerbose     = 0;
-  fPar         = 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
   //
 
-  fClusterTree = NULL;
-  fEvent       = 0;
-  fVerbose     = 0;
-  fPar         = 0;
-
 }
 
 //_____________________________________________________________________________
 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
+  :TNamed(c)
+  ,fRunLoader(NULL)
+  ,fClusterTree(NULL)
+  ,fRecPoints(NULL)
 {
   //
   // AliTRDclusterizer copy constructor
   //
 
-  ((AliTRDclusterizer &) c).Copy(*this);
-
 }
 
 //_____________________________________________________________________________
@@ -86,6 +84,11 @@ AliTRDclusterizer::~AliTRDclusterizer()
   // AliTRDclusterizer destructor
   //
 
+  if (fRecPoints) {
+    fRecPoints->Delete();
+    delete fRecPoints;
+  }
+
 }
 
 //_____________________________________________________________________________
@@ -95,22 +98,22 @@ AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
   // Assignment operator
   //
 
-  if (this != &c) ((AliTRDclusterizer &) c).Copy(*this);
+  if (this != &c) {
+    ((AliTRDclusterizer &) c).Copy(*this);
+  }
   return *this;
 
 }
 
 //_____________________________________________________________________________
-void AliTRDclusterizer::Copy(TObject &c)
+void AliTRDclusterizer::Copy(TObject &c) const
 {
   //
   // Copy function
   //
 
   ((AliTRDclusterizer &) c).fClusterTree = NULL;
-  ((AliTRDclusterizer &) c).fEvent       = 0;  
-  ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
-  ((AliTRDclusterizer &) c).fPar         = 0;
+  ((AliTRDclusterizer &) c).fRecPoints   = NULL;  
 
 }
 
@@ -120,18 +123,25 @@ Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
   //
   // Opens the AliROOT file. Output and input are in the same file
   //
-  fRunLoader = AliRunLoader::Open(name);
-  if (!fRunLoader)
-   {
-     Error("Open","Can not open session for file %s.",name);
-     return kFALSE;
-   }
+
+  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()
@@ -144,9 +154,25 @@ Bool_t AliTRDclusterizer::OpenOutput()
 
   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;
 
@@ -159,33 +185,9 @@ 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
-  fRunLoader->LoadgAlice();
-  gAlice = fRunLoader->GetAliRun();
-
-  if (!(gAlice)) {
-    fRunLoader->LoadgAlice();
-    gAlice = fRunLoader->GetAliRun();
-      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
-  fRunLoader->GetEvent(fEvent);
+  fRunLoader->GetEvent(nEvent);
   
-  // 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;
 
 }
@@ -198,70 +200,127 @@ Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
   // found in detector = det. For det=-1 writes the tree. 
   //
 
-  if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
-    printf("AliTRDclusterizer::WriteClusters -- ");
-    printf("Unexpected detector index %d.\n",det);
+  if ((det <                      -1) || 
+      (det >= AliTRDgeometry::Ndet())) {
+    AliError(Form("Unexpected detector index %d.\n",det));
     return kFALSE;
   }
  
-
   TBranch *branch = fClusterTree->GetBranch("TRDcluster");
   if (!branch) {
     TObjArray *ioArray = 0;
     branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
   }
 
-  if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
+  if ((det >=                      0) && 
+      (det <  AliTRDgeometry::Ndet())) {
 
-    Int_t nRecPoints = fTRD->RecPoints()->GetEntriesFast();
+    Int_t nRecPoints = RecPoints()->GetEntriesFast();
     TObjArray *detRecPoints = new TObjArray(400);
 
     for (Int_t i = 0; i < nRecPoints; i++) {
-      AliTRDcluster *c = (AliTRDcluster *) fTRD->RecPoints()->UncheckedAt(i);
+      AliTRDcluster *c = (AliTRDcluster *) 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");
+        AliError("Attempt to write a cluster with unexpected detector index\n");
       }
     }
 
     branch->SetAddress(&detRecPoints);
     fClusterTree->Fill();
 
+    delete detRecPoints;
+
     return kTRUE;
 
   }
 
   if (det == -1) {
 
-    printf("AliTRDclusterizer::WriteClusters -- ");
-    printf("Writing the cluster tree %-18s for event %d.\n"
-         ,fClusterTree->GetName(),fEvent);
-    /*
-    fClusterTree->Write();
-    AliTRDgeometry *geo = fTRD->GetGeometry();
-    geo->SetName("TRDgeometry");
-    geo->Write();
-    fPar->Write();
-    */
-    AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
-    loader->WriteRecPoints("OVERWRITE");
+    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 {
+
+      AliError("Cluster tree does not exist. Cannot write clusters.\n");
+      return kFALSE;
+
+    }
+
     return kTRUE;  
 
   }
-  /*
-  AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
-  loader->WriteDigits("OVERWRITE");
-  */
-  printf("AliTRDclusterizer::WriteClusters -- ");
-  printf("Unexpected detector index %d.\n",det);
+
+  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;
+  }
+
+  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;
+
+}
+
+//_____________________________________________________________________________
+void AliTRDclusterizer::ResetRecPoints() 
+{
+  //
+  // Resets the list of rec points
+  //
+
+  if (fRecPoints) {
+    fRecPoints->Delete();
+  }
+
+}
+
+//_____________________________________________________________________________
+TObjArray *AliTRDclusterizer::RecPoints() 
+{
+  //
+  // Returns the list of rec points
+  //
+
+  if (!fRecPoints) {
+    fRecPoints = new TObjArray(400);
+  }
+  return fRecPoints;
+
+}