]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFClusterFinder.cxx
TOF raw data format: updated version
[u/mrichter/AliRoot.git] / TOF / AliTOFClusterFinder.cxx
index 9de88e6ae8b3233cd2bf7b81498c450123065951..db8db279b10338117941513627ef417d14195f10 100644 (file)
@@ -50,24 +50,27 @@ Revision 0.01  2005/07/25 A. De Caro
 //                                                            //
 ////////////////////////////////////////////////////////////////
 
-#include <Riostream.h>
-#include <TTree.h>
-#include <TObjArray.h>
-#include <TClonesArray.h>
-#include <TFile.h>
+#include "TClonesArray.h"
+#include "TFile.h"
+#include "TTree.h"
 
+#include "AliDAQ.h"
+#include "AliLoader.h"
 #include "AliLog.h"
+#include "AliRawReader.h"
 #include "AliRunLoader.h"
-#include "AliLoader.h"
 
-#include "AliTOFdigit.h"
+#include "AliTOFcalib.h"
+#include "AliTOFCal.h"
+#include "AliTOFChannel.h"
+#include "AliTOFClusterFinder.h"
 #include "AliTOFcluster.h"
-#include "AliTOFGeometry.h"
-#include "AliTOFGeometryV4.h"
+#include "AliTOFdigit.h"
 #include "AliTOFGeometryV5.h"
+#include "AliTOFGeometry.h"
 #include "AliTOFRawStream.h"
 
-#include "AliTOFClusterFinder.h"
+extern TFile *gFile;
 
 ClassImp(AliTOFClusterFinder)
 
@@ -86,6 +89,7 @@ AliTOFClusterFinder::AliTOFClusterFinder():
 
   fTOFGeometry = new AliTOFGeometryV5();
   AliInfo("V5 TOF Geometry is taken as the default");
+
 }
 //______________________________________________________________________________
 
@@ -107,6 +111,28 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader):
   in->cd();
   fTOFGeometry = (AliTOFGeometry*)in->Get("TOFgeometry");
 
+}
+
+//------------------------------------------------------------------------
+AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
+  :TObject()
+{
+  // copy constructor
+  this->fDigits=source.fDigits;
+  this->fRecPoints=source.fRecPoints;
+  this->fTOFGeometry=source.fTOFGeometry;
+
+}
+
+//------------------------------------------------------------------------
+AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
+{
+  // ass. op.
+  this->fDigits=source.fDigits;
+  this->fRecPoints=source.fRecPoints;
+  this->fTOFGeometry=source.fTOFGeometry;
+  return *this;
+
 }
 //______________________________________________________________________________
 
@@ -178,8 +204,8 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
   Int_t dig[5];
   Float_t g[3];
   Double_t h[5];
-  Float_t ToT;
-  Double_t TdcND;
+  Float_t tToT;
+  Double_t tTdcND;
   for (ii=0; ii<nDigits; ii++) {
     AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
     dig[0]=d->GetSector();
@@ -188,6 +214,8 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
     dig[3]=d->GetPadz();
     dig[4]=d->GetPadx();
 
+    //AliInfo(Form(" %2i  %1i  %2i  %1i  %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
+
     for (jj=0; jj<3; jj++) g[jj] = 0.;
     fTOFGeometry->GetPos(dig,g);
 
@@ -196,16 +224,17 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
     h[2] = g[2];
     h[3] = d->GetTdc();
     h[4] = d->GetAdc();
-    ToT = d->GetToT();
-    TdcND = d->GetTdcND();
+    tToT = d->GetToT();
+    tTdcND = d->GetTdcND();
 
-    AliTOFcluster *tofCluster = new AliTOFcluster(h,d->GetTracks(),dig,ii,ToT, TdcND);
+    AliTOFcluster *tofCluster = new AliTOFcluster(h,d->GetTracks(),dig,ii,tToT, tTdcND);
     InsertCluster(tofCluster);
 
   }
 
   AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
 
+  CalibrateRecPoint();
   FillRecPoint();
 
   fTreeR->Fill();
@@ -224,7 +253,8 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
   // Converts RAW data to recpoints for TOF
   //
 
-  const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
+  //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
+  const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
 
   ResetRecpoint();
 
@@ -237,21 +267,33 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
   Int_t detectorIndex[5];
   Float_t position[3];
   Double_t cylindricalPosition[5];
+  Float_t tToT;
+  Double_t tTdcND;
 
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
     AliTOFRawStream tofInput(rawReader);
-    rawReader->Select(5, indexDDL, indexDDL);
+    rawReader->Select("TOF", indexDDL, indexDDL);
 
     while(tofInput.Next()) {
 
+      for (ii=0; ii<5; ii++) detectorIndex[ii] = -1;
+
       detectorIndex[0] = tofInput.GetSector();
       detectorIndex[1] = tofInput.GetPlate();
       detectorIndex[2] = tofInput.GetStrip();
       detectorIndex[3] = tofInput.GetPadZ();
       detectorIndex[4] = tofInput.GetPadX();
       
+      //AliInfo(Form("  %2i  %1i  %2i  %1i  %2i ",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
+
+      if (detectorIndex[0]==-1 ||
+         detectorIndex[1]==-1 ||
+         detectorIndex[2]==-1 ||
+         detectorIndex[3]==-1 ||
+         detectorIndex[4]==-1) continue;
+
       for (ii=0; ii<3; ii++) position[ii] =  0.;
 
       fTOFGeometry->GetPos(detectorIndex, position);
@@ -260,9 +302,12 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
       cylindricalPosition[1] = TMath::ATan2(position[1], position[0]);
       cylindricalPosition[2] = position[2];
       cylindricalPosition[3] = tofInput.GetTofBin();
-      cylindricalPosition[4] = tofInput.GetADCbin();
-
+      cylindricalPosition[4] = tofInput.GetToTbin();
+      tToT = tofInput.GetToTbin();
+      tTdcND = -1.;
       AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
+      tofCluster->SetToT(tToT);
+      tofCluster->SetTDCND(tTdcND);
       InsertCluster(tofCluster);
 
     } // while loop
@@ -271,9 +316,11 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
 
   AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
 
+  CalibrateRecPoint();
   FillRecPoint();
 
   clustersTree->Fill();
+
   ResetRecpoint();
 
 }
@@ -285,7 +332,8 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
   // Converts RAW data to recpoints for TOF
   //
 
-  const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
+  //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
+  const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
 
   fRunLoader->GetEvent(iEvent);
 
@@ -304,24 +352,36 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
   Int_t ii = 0;
   Int_t indexDDL = 0;
 
-  Int_t detectorIndex[5];
+  Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
   Float_t position[3];
   Double_t cylindricalPosition[5];
+  Float_t tToT;
+  Double_t tTdcND;
 
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
     AliTOFRawStream tofInput(rawReader);
-    rawReader->Select(5, indexDDL, indexDDL);
+    rawReader->Select("TOF", indexDDL, indexDDL);
 
     while(tofInput.Next()) {
 
+      for (ii=0; ii<5; ii++) detectorIndex[ii] = -1;
+
       detectorIndex[0] = (Int_t)tofInput.GetSector();
       detectorIndex[1] = (Int_t)tofInput.GetPlate();
       detectorIndex[2] = (Int_t)tofInput.GetStrip();
       detectorIndex[3] = (Int_t)tofInput.GetPadZ();
       detectorIndex[4] = (Int_t)tofInput.GetPadX();
 
+      if (detectorIndex[0]==-1 ||
+         detectorIndex[1]==-1 ||
+         detectorIndex[2]==-1 ||
+         detectorIndex[3]==-1 ||
+         detectorIndex[4]==-1) continue;
+
+      //AliInfo(Form("  %2i  %1i  %2i  %1i  %2i ",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
+
       for (ii=0; ii<3; ii++) position[ii] =  0.;
 
       fTOFGeometry->GetPos(detectorIndex, position);
@@ -330,9 +390,13 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
       cylindricalPosition[1] = (Double_t)TMath::ATan2(position[1], position[0]);
       cylindricalPosition[2] = (Double_t)position[2];
       cylindricalPosition[3] = (Double_t)tofInput.GetTofBin();
-      cylindricalPosition[4] = (Double_t)tofInput.GetADCbin();
-
+      cylindricalPosition[4] = (Double_t)tofInput.GetToTbin();
+      tToT = tofInput.GetToTbin();
+      tTdcND = -1.;
+    
       AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex);
+      tofCluster->SetToT(tToT);
+      tofCluster->SetTDCND(tTdcND);
       InsertCluster(tofCluster);
 
     } // while loop
@@ -341,6 +405,7 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
 
   AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
 
+  CalibrateRecPoint();
   FillRecPoint();
 
   fTreeR->Fill();
@@ -365,20 +430,12 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
   fTreeD = fTOFLoader->TreeD();
   if (fTreeD)
     {
-    AliInfo("AliTOFClusterFinder: TreeD re-creation");
+    AliInfo("TreeD re-creation");
     fTreeD = 0x0;
     fTOFLoader->MakeTree("D");
     fTreeD = fTOFLoader->TreeD();
     }
 
-
-  fTreeR = fTOFLoader->TreeD();
-  if (fTreeD == 0x0)
-    {
-      fTOFLoader->MakeTree("D");
-      fTreeD = fTOFLoader->TreeD();
-    }
-
   TClonesArray dummy("AliTOFdigit",10000), *tofDigits=&dummy;
   Int_t bufsize = 32000;
   fTreeD->Branch("TOF", &tofDigits, bufsize);
@@ -390,27 +447,40 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
 
   AliDebug(2,Form(" Event number %2i ", iEvent));
 
+  Int_t ii = 0;
   Int_t indexDDL = 0;
 
   Int_t detectorIndex[5];
-  Float_t digit[2];
+  Float_t digit[4];
 
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
     AliTOFRawStream tofInput(rawReader);
-    rawReader->Select(5, indexDDL, indexDDL);
+    rawReader->Select("TOF", indexDDL, indexDDL);
 
     while(tofInput.Next()) {
 
+      for (ii=0; ii<5; ii++) detectorIndex[ii] = -1;
+
       detectorIndex[0] = tofInput.GetSector();
       detectorIndex[1] = tofInput.GetPlate();
       detectorIndex[2] = tofInput.GetStrip();
       detectorIndex[3] = tofInput.GetPadX();
       detectorIndex[4] = tofInput.GetPadZ();
       
+      //AliInfo(Form("  %2i  %1i  %2i  %1i  %2i ",detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
+
+      if (detectorIndex[0]==-1 ||
+         detectorIndex[1]==-1 ||
+         detectorIndex[2]==-1 ||
+         detectorIndex[3]==-1 ||
+         detectorIndex[4]==-1) continue;
+
       digit[0] = (Float_t)tofInput.GetTofBin();
-      digit[1] = (Float_t)tofInput.GetADCbin();
+      digit[1] = (Float_t)tofInput.GetToTbin();
+      digit[2] = (Float_t)tofInput.GetToTbin();
+      digit[3] = -1.;
 
       Int_t tracknum[3]={-1,-1,-1};
 
@@ -486,8 +556,8 @@ void AliTOFClusterFinder::FillRecPoint()
   Double_t cylindricalPosition[5];
   Int_t trackLabels[3];
   Int_t digitIndex = -1;
-  Float_t ToT;
-  Double_t TdcND;
+  Float_t tToT;
+  Double_t tTdcND;
 
   TClonesArray &lRecPoints = *fRecPoints;
   
@@ -501,16 +571,59 @@ void AliTOFClusterFinder::FillRecPoint()
     cylindricalPosition[2] = fTofClusters[ii]->GetZ();
     cylindricalPosition[3] = fTofClusters[ii]->GetTDC();
     cylindricalPosition[4] = fTofClusters[ii]->GetADC();
-    ToT = fTofClusters[ii]->GetToT();
-    TdcND = fTofClusters[ii]->GetTDCND();
+    tToT = fTofClusters[ii]->GetToT();
+    tTdcND = fTofClusters[ii]->GetTDCND();
 
-    new(lRecPoints[ii]) AliTOFcluster(cylindricalPosition, trackLabels, detectorIndex, digitIndex, ToT, TdcND);
+    new(lRecPoints[ii]) AliTOFcluster(cylindricalPosition, trackLabels, detectorIndex, digitIndex, tToT, tTdcND);
 
     //AliInfo(Form("%3i  %3i  %f %f %f %f %f  %2i %2i %2i %1i %2i",ii,digitIndex, cylindricalPosition[2],cylindricalPosition[0],cylindricalPosition[1],cylindricalPosition[3],cylindricalPosition[4],detectorIndex[0],detectorIndex[1],detectorIndex[2],detectorIndex[3],detectorIndex[4]));
 
   } // loop on clusters
 
 }
+
+//_________________________________________________________________________
+void AliTOFClusterFinder::CalibrateRecPoint()
+{
+  //
+  // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
+  // in Z) in the global TClonesArray of AliTOFcluster,
+  // i.e. fRecPoints.
+  //
+
+  Int_t ii, jj;
+
+  Int_t detectorIndex[5];
+  Int_t digitIndex = -1;
+  Float_t tToT;
+  Float_t tdcCorr;
+  AliInfo(" Calibrating TOF Clusters: ")
+  AliTOFcalib *calib = new AliTOFcalib(fTOFGeometry);
+  // calib->ReadParFromCDB("TOF/Calib",0); // original
+  calib->ReadParFromCDB("TOF/Calib",-1); // Use AliCDBManager's run number
+  AliTOFCal *calTOFArray = calib->GetTOFCalArray();  
+
+  for (ii=0; ii<fNumberOfTofClusters; ii++) {
+    digitIndex = fTofClusters[ii]->GetIndex();
+    for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
+
+    Int_t index = calib->GetIndex(detectorIndex);
+     
+    AliTOFChannel * calChannel = calTOFArray->GetChannel(index);
+    Float_t par[6];
+    for (Int_t j = 0; j<6; j++){
+      par[j]=calChannel->GetSlewPar(j);
+    }
+    tToT = fTofClusters[ii]->GetToT();
+    Float_t timeCorr=par[0]+par[1]*tToT+par[2]*tToT*tToT+par[3]*tToT*tToT*tToT+par[4]*tToT*tToT*tToT*tToT+par[5]*tToT*tToT*tToT*tToT*tToT;
+    tdcCorr=(fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()+32)*1.E-3-timeCorr;
+    tdcCorr=(tdcCorr*1E3-32)/AliTOFGeometry::TdcBinWidth();
+    fTofClusters[ii]->SetTDC(tdcCorr);
+
+  } // loop on clusters
+
+  delete calib;
+}
 //______________________________________________________________________________
 
 void AliTOFClusterFinder::ResetRecpoint()