]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDclusterizer.cxx
Moving place of smell-detector
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizer.cxx
index 2c1884810d3cbb4f3723d5d856f0d4dcecbe5c83..87af305108a4d6ecfe1caaf4c99cff3994025bdc 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-
-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
-
-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$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -71,10 +26,14 @@ Add new TRD classes
 #include <TFile.h>
 
 #include "AliRun.h"
-#include "AliTRD.h"
+#include "AliRunLoader.h"
+#include "AliLoader.h"
+
 #include "AliTRDclusterizer.h"
+#include "AliTRDcluster.h"
 #include "AliTRDrecPoint.h"
 #include "AliTRDgeometry.h"
+#include "AliTRDcalibDB.h"
 
 ClassImp(AliTRDclusterizer)
 
@@ -85,8 +44,9 @@ AliTRDclusterizer::AliTRDclusterizer():TNamed()
   // AliTRDclusterizer default constructor
   //
 
-  fInputFile = NULL;
-  fEvent     = 0;
+  fClusterTree = NULL;
+  fRecPoints   = 0;
+  fVerbose     = 0;
 
 }
 
@@ -98,15 +58,14 @@ AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
   // AliTRDclusterizer default constructor
   //
 
-  fInputFile = NULL;
-  fEvent     = 0;
-
-  Init();
+  fClusterTree = NULL;
+  fRecPoints   = 0;
+  fVerbose     = 0;
 
 }
 
 //_____________________________________________________________________________
-AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
+AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c):TNamed(c)
 {
   //
   // AliTRDclusterizer copy constructor
@@ -123,11 +82,10 @@ AliTRDclusterizer::~AliTRDclusterizer()
   // AliTRDclusterizer destructor
   //
 
-  if (fInputFile) {
-    fInputFile->Close();
-    delete fInputFile;
+  if (fRecPoints) {
+    fRecPoints->Delete();
+    delete fRecPoints;
   }
-
 }
 
 //_____________________________________________________________________________
@@ -143,69 +101,83 @@ AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
 }
 
 //_____________________________________________________________________________
-void AliTRDclusterizer::Copy(TObject &c)
+void AliTRDclusterizer::Copy(TObject &c) const
 {
   //
   // Copy function
   //
 
-  ((AliTRDclusterizer &) c).fInputFile = NULL;
-  ((AliTRDclusterizer &) c).fEvent     = 0;  
+  ((AliTRDclusterizer &) c).fClusterTree = NULL;
+  ((AliTRDclusterizer &) c).fRecPoints   = NULL;  
+  ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
 
 }
 
 //_____________________________________________________________________________
-void AliTRDclusterizer::Init()
+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)
+   {
+     Error("Open","Can not open session for file %s.",name);
+     return kFALSE;
+   }
+
+  OpenInput(nEvent);
+  OpenOutput();
+  return kTRUE;
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::OpenOutput()
 {
   //
-  // Initializes the cluster finder
+  // 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::Open(const Char_t *name, Int_t nEvent)
+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");
+  if (fRunLoader->GetAliRun() == 0x0) 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;
+      }
   }
-  else {
-    printf("AliTRDclusterizer::Open -- ");
-    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;
-    }
-  //}
-
-  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("No entries in the trees for event %d.\n",fEvent);
-    return kFALSE;
-  }
-
+  fRunLoader->GetEvent(nEvent);
+  
   return kTRUE;
 
 }
@@ -214,60 +186,135 @@ Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
 {
   //
-  // Fills TRDrecPoints branch in TRDrecPoints## tree with rec. point
+  // Fills TRDcluster branch in the tree with the cluster
   // found in detector = det. For det=-1 writes the tree. 
-  // For det=-2 recreates the tree.
-
-  Char_t treeName[14];
-  sprintf(treeName,"TRDrecPoints%d", fEvent);
+  //
 
-  if (det == -2) {
-    fInputFile->Delete(treeName);
-    TTree *tree = new TTree(treeName,"Tree with TRD rec. points");
-    tree->Write();
-    return kTRUE;
+  if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
+    printf("AliTRDclusterizer::WriteClusters -- ");
+    printf("Unexpected detector index %d.\n",det);
+    return kFALSE;
   }
 
-  TTree *tree=(TTree*)fInputFile->Get(treeName);
-  TBranch *branch=tree->GetBranch("TRDrecPoints");
-
-  if(!branch) {
+  TBranch *branch = fClusterTree->GetBranch("TRDcluster");
+  if (!branch) {
     TObjArray *ioArray = 0;
-    branch = tree->Branch("TRDrecPoints","TObjArray",&ioArray,32000,0);
+    branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
   }
 
   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
 
-    AliTRD *TRD = (AliTRD*) gAlice->GetDetector("TRD");
-    Int_t nRecPoints = TRD->RecPoints()->GetEntriesFast();
-    TObjArray *fDetRecPoints = new TObjArray(400);
-
-    for (Int_t i=0; i<nRecPoints; i++) {
-      AliTRDrecPoint *p=(AliTRDrecPoint*)TRD->RecPoints()->UncheckedAt(i);
-      if(det == p->GetDetector()) fDetRecPoints->AddLast(p);
-      else printf("attempt to write a RecPoint with unexpected detector index");
+    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 {
+        printf("AliTRDclusterizer::WriteClusters --");
+        printf("Attempt to write a cluster with unexpected detector index\n");
+      }
     }
 
-    branch->SetAddress(&fDetRecPoints);
-    tree->Fill();
+    branch->SetAddress(&detRecPoints);
+    fClusterTree->Fill();
+
+    delete detRecPoints;
+
     return kTRUE;
+
   }
 
   if (det == -1) {
 
-    printf("\rAliTRDclusterizer::WriteClusters -- ");
-    printf("Writing the cluster tree %-18s for event %d.\n"
-          ,tree->GetName(),fEvent);
-
-    tree->Write();     
+    Info("WriteClusters","Writing the cluster tree %s for event %d."
+        ,fClusterTree->GetName(),fRunLoader->GetEventNumber());
+    /*
+    fClusterTree->Write();
+    AliTRDgeometry *geo = fTRD->GetGeometry();
+    geo->SetName("TRDgeometry");
+    geo->Write();
+    */
+    AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+    loader->WriteRecPoints("OVERWRITE");
+  
     return kTRUE;  
+
   }
-  
-  printf("\rAliTRDclusterizer::WriteClusters -- ");
-  printf("Unexpected detector index %d.\n", det); 
+  /*
+  AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+  loader->WriteDigits("OVERWRITE");
+  */
+  printf("AliTRDclusterizer::WriteClusters -- ");
+  printf("Unexpected detector index %d.\n",det);
   return kFALSE;  
+  
+}
+
 
+//_____________________________________________________________________________
+AliTRDcluster* AliTRDclusterizer::AddCluster(Double_t *pos, Int_t timebin, Int_t det, Double_t amp
+                                  , Int_t *tracks, Double_t *sig, Int_t iType, Float_t center)
+{
+  //
+  // Add a cluster for the TRD
+  //
+
+  AliTRDcluster *c = new AliTRDcluster();
+
+  c->SetDetector(det);
+  c->AddTrackIndex(tracks);
+  c->SetQ(amp);
+  c->SetX(pos[2]);
+  c->SetY(pos[0]);
+  c->SetZ(pos[1]);
+  c->SetSigmaY2(sig[0]);   
+  c->SetSigmaZ2(sig[1]);
+  c->SetLocalTimeBin(timebin);
+  c->SetCenter(center);
+  switch (iType) {
+  case 0:
+    c->Set2pad();
+    break;
+  case 1:
+    c->Set3pad();
+    break;
+  case 2:
+    c->Set4pad();
+    break;
+  case 3:
+    c->Set5pad();
+    break;
+  case 4:
+    c->SetLarge();
+    break;
+  };
+
+  RecPoints()->Add(c);
+  return c;
 }
 
+//_____________________________________________________________________________
+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)
+    return -1;
+
+  Float_t vdrift = calibration->GetVdrift(idet, col, row);  
+  Float_t t0 = calibration->GetT0(idet, col, row);
+  Float_t samplingFrequency = calibration->GetSamplingFrequency();
 
+  timebin -= t0;
 
+  return timebin / samplingFrequency * vdrift;
+}