]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFClusterFinder.cxx
One more attempt to fix STRING_OVERFLOW defect reported by Coverity
[u/mrichter/AliRoot.git] / TOF / AliTOFClusterFinder.cxx
index 8386ae3284f4a7f54cf7aa2f1a82e0d7a118f291..1abc822690098bb7ef0f0f5dd6c635b714737a59 100644 (file)
@@ -133,13 +133,14 @@ Revision 0.01  2005/07/25 A. De Caro
 
 #include "AliTOFDeltaBCOffset.h"
 #include "AliTOFCTPLatency.h"
-#include "AliTOFT0Fill.h"
+#include "AliTOFRunParams.h"
 
 //extern TFile *gFile;
 
 ClassImp(AliTOFClusterFinder)
 
 AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
+  TTask("AliTOFClusterFinder",""),
   fRunLoader(0),
   fTOFLoader(0),
   fTreeD(0),
@@ -156,11 +157,19 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
 // Constructor
 //
 
+  TString validity = (TString)fTOFcalib->GetOfflineValidity();
+  if (validity.CompareTo("valid")==0) {
+    AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
+  } else {
+    AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
+  }
+
 }
 
 //______________________________________________________________________________
 
 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
+  TTask("AliTOFClusterFinder",""),
   fRunLoader(runLoader),
   fTOFLoader(runLoader->GetLoader("TOFLoader")),
   fTreeD(0),
@@ -177,11 +186,18 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *c
 // Constructor
 //
 
+  TString validity = (TString)fTOFcalib->GetOfflineValidity();
+  if (validity.CompareTo("valid")==0) {
+    AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
+  } else {
+    AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
+  }
+
 }
 
 //------------------------------------------------------------------------
 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
-  :TObject(source),
+  :TTask(source),
   fRunLoader(0),
   fTOFLoader(0),
   fTreeD(0),
@@ -205,7 +221,7 @@ AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &s
   if (this == &source)
     return *this;
 
-  TObject::operator=(source);  
+  TTask::operator=(source);  
   fDigits=source.fDigits;
   fRecPoints=source.fRecPoints;
   fVerbose=source.fVerbose;
@@ -237,6 +253,12 @@ AliTOFClusterFinder::~AliTOFClusterFinder()
       fRecPoints=0;
     }
 
+  if (fTofClusters || fNumberOfTofClusters) {
+    for (Int_t ii=0; ii<fNumberOfTofClusters; ii++)
+      if (fTofClusters[ii]) fTofClusters[ii]->Delete();
+    fNumberOfTofClusters=0;
+   }
+
 }
 //______________________________________________________________________________
 
@@ -287,8 +309,8 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
   AliDebug(2,Form("Number of TOF digits: %d",nDigits));
 
   Int_t ii;
-  Int_t dig[5]; //cluster detector indeces
-  Int_t  parTOF[7]; //The TOF signal parameters
+  Int_t dig[5]={-1,-1,-1,-1,-1}; //cluster detector indeces
+  Int_t parTOF[7]={0,0,0,0,0,0,0}; //The TOF signal parameters
   Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
   for (ii=0; ii<nDigits; ii++) {
     AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
@@ -386,8 +408,8 @@ void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree
   AliDebug(2,Form("Number of TOF digits: %d",nDigits));
 
   Int_t ii;
-  Int_t dig[5]; //cluster detector indeces
-  Int_t  parTOF[7]; //The TOF signal parameters
+  Int_t dig[5]={-1,-1,-1,-1,-1}; //cluster detector indeces
+  Int_t parTOF[7]={0,0,0,0,0,0,0}; //The TOF signal parameters
   Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
   for (ii=0; ii<nDigits; ii++) {
     AliTOFdigit *d = (AliTOFdigit*)digits->UncheckedAt(ii);
@@ -475,19 +497,32 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
   fTOFRawStream.Clear();
   fTOFRawStream.SetRawReader(rawReader);
 
-  if (fDecoderVersion)
+  if (fDecoderVersion == 1) {
     AliInfo("Using New Decoder");
+  }
+  else if (fDecoderVersion == 2) {
+    AliInfo("Using Enhanced Decoder");
+  }
+  else {
+    AliInfo("Using Old Decoder");
+  }
 
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
-    if (fDecoderVersion)
+    if (fDecoderVersion == 1) {
       fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
-    else fTOFRawStream.LoadRawData(indexDDL);
-
+    }
+    else if (fDecoderVersion == 2) {
+      fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
+    }
+    else  {
+      fTOFRawStream.LoadRawData(indexDDL);
+    }
+    
     clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
-
+    
     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
 
       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
@@ -537,7 +572,7 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
       parTOF[0] = tofRawDatum->GetTOF(); //TDC
       parTOF[1] = tofRawDatum->GetTOT(); // TOT
       parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
-      parTOF[3] = -1;//raw data: no track of undecalib sim time
+      parTOF[3] = 0;//raw data: no track of undecalib sim time
       parTOF[4] = tofRawDatum->GetTOF(); // RAW time
       parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
       parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
@@ -570,7 +605,7 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
 
   AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
 
-  CalibrateRecPoint();
+  CalibrateRecPoint(rawReader->GetTimestamp());
   FillRecPoint();
 
   clustersTree->Fill();
@@ -624,16 +659,29 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
   fTOFRawStream.Clear();
   fTOFRawStream.SetRawReader(rawReader);
 
-  if (fDecoderVersion)
+  if (fDecoderVersion == 1) {
     AliInfo("Using New Decoder");
+  }
+  else if (fDecoderVersion == 2) {
+    AliInfo("Using Enhanced Decoder");
+  }
+  else {
+    AliInfo("Using Old Decoder");
+  }
 
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
-    if (fDecoderVersion)
+    if (fDecoderVersion == 1) {
       fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
-    else fTOFRawStream.LoadRawData(indexDDL);
+    }
+    else if (fDecoderVersion == 2) {
+      fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
+    }
+    else {
+      fTOFRawStream.LoadRawData(indexDDL);
+    }
 
     clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
 
@@ -686,7 +734,7 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
       parTOF[0] = tofRawDatum->GetTOF(); // TDC
       parTOF[1] = tofRawDatum->GetTOT(); // TOT
       parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
-      parTOF[3] = -1; //raw data: no track of the undecalib sim time
+      parTOF[3] = 0; //raw data: no track of the undecalib sim time
       parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
       parTOF[5] = tofRawDatum->GetDeltaBC(); // deltaBC
       parTOF[6] = tofRawDatum->GetL0L1Latency(); // L0-L1 latency
@@ -719,7 +767,7 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
 
   AliDebug(1,Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
 
-  CalibrateRecPoint();
+  CalibrateRecPoint(rawReader->GetTimestamp());
   FillRecPoint();
 
   fTreeR->Fill();
@@ -778,16 +826,29 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
   fTOFRawStream.Clear();
   fTOFRawStream.SetRawReader(rawReader);
 
-  if (fDecoderVersion)
+  if (fDecoderVersion == 1) {
     AliInfo("Using New Decoder");
+  }
+  else if (fDecoderVersion == 2) {
+    AliInfo("Using Enhanced Decoder");
+  }
+  else {
+    AliInfo("Using Old Decoder");
+  }
 
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
-    if (fDecoderVersion)
+    if (fDecoderVersion == 1) {
       fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
-    else fTOFRawStream.LoadRawData(indexDDL);
+    }
+    else if (fDecoderVersion == 2) {
+      fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
+    }
+    else {
+      fTOFRawStream.LoadRawData(indexDDL);
+    }
 
     clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
 
@@ -807,7 +868,7 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
       digit[0] = fTOFRawStream.GetTofBin();
       digit[1] = fTOFRawStream.GetToTbin();
       digit[2] = fTOFRawStream.GetToTbin();
-      digit[3] = -1;
+      digit[3] = 0;
 
       Int_t tracknum[3]={-1,-1,-1};
 
@@ -868,16 +929,29 @@ void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
   fTOFRawStream.Clear();
   fTOFRawStream.SetRawReader(rawReader);
 
-  if (fDecoderVersion)
+  if (fDecoderVersion == 1) {
     AliInfo("Using New Decoder");
+  }
+  else if (fDecoderVersion == 2) {
+    AliInfo("Using Enhanced Decoder");
+  }
+  else {
+    AliInfo("Using Old Decoder");
+  }
 
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
-    if (fDecoderVersion)
+    if (fDecoderVersion == 1) {
       fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
-    else fTOFRawStream.LoadRawData(indexDDL);
+    }
+    else if (fDecoderVersion == 2) {
+      fTOFRawStream.LoadRawDataBuffersV2(indexDDL,fVerbose);
+    }
+    else {
+      fTOFRawStream.LoadRawData(indexDDL);
+    }
 
     clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
 
@@ -897,7 +971,7 @@ void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
       digit[0] = fTOFRawStream.GetTofBin();
       digit[1] = fTOFRawStream.GetToTbin();
       digit[2] = fTOFRawStream.GetToTbin();
-      digit[3] = -1;
+      digit[3] = 0;
 
       Int_t tracknum[3]={-1,-1,-1};
 
@@ -1019,7 +1093,13 @@ void AliTOFClusterFinder::FillRecPoint()
 }
 
 //_________________________________________________________________________
-void AliTOFClusterFinder::CalibrateRecPoint()
+
+/*
+ * OLD CALIBRATE REC POINTS FUNCTION
+ */
+
+#if 0
+void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
 {
   //
   // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
@@ -1045,16 +1125,16 @@ void AliTOFClusterFinder::CalibrateRecPoint()
   Int_t deltaBCOffset = deltaBCOffsetObj->GetDeltaBCOffset();
   AliTOFCTPLatency *ctpLatencyObj = fTOFcalib->GetCTPLatency();
   Float_t ctpLatency = ctpLatencyObj->GetCTPLatency();
-  AliTOFT0Fill *t0FillObj = fTOFcalib->GetT0Fill();
-  Float_t t0Fill = t0FillObj->GetT0Fill();
+  AliTOFRunParams *runParamsObj = fTOFcalib->GetRunParams();
+  Float_t t0 = runParamsObj->EvalT0(timestamp);
 
   TString validity = (TString)fTOFcalib->GetOfflineValidity();
   Int_t calibration = -1;
   if (validity.CompareTo("valid")==0) {
-    AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
+    //AliInfo(Form(" validity = %s - Using offline calibration parameters",validity.Data()));
     calibration = 1;
   } else {
-    AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
+    //AliInfo(Form(" validity = %s - Using online calibration parameters",validity.Data()));
     calibration = 0 ;
   }
 
@@ -1092,7 +1172,7 @@ void AliTOFClusterFinder::CalibrateRecPoint()
      } 
       AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
       AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %d , %d", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
-      tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());    
+      tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());
       tToT*=1.E-3; //ToT in ns
 
       /* check TOT limits and set new TOT in case */
@@ -1117,7 +1197,7 @@ void AliTOFClusterFinder::CalibrateRecPoint()
      *
      * the following corrections are performed in this way:
      *
-     *    time = timeRaw - deltaBC + L0L1Latency + CTPLatency - TDCLatencyWindow - T0Fill
+     *    time = timeRaw - deltaBC + L0L1Latency + CTPLatency - TDCLatencyWindow - T0
      *
      */
 
@@ -1125,18 +1205,18 @@ void AliTOFClusterFinder::CalibrateRecPoint()
     AliDebug(2, Form("applying further corrections (L0L1Latency): L0L1Latency=%d (BC bins)", fTofClusters[ii]->GetL0L1Latency()));
     AliDebug(2, Form("applying further corrections (CTPLatency): CTPLatency=%f (ps)", ctpLatency));
     AliDebug(2, Form("applying further corrections (TDCLatencyWindow): TDCLatencyWindow=%f (ps)", tdcLatencyWindow));
-    AliDebug(2, Form("applying further corrections (T0Fill): T0Fill=%f (ps)", t0Fill));
+    AliDebug(2, Form("applying further corrections (T0): T0=%f (ps)", t0));
 
-    /* deltaBC correction */
-    timeCorr -= (fTofClusters[ii]->GetDeltaBC() - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
+    /* deltaBC correction (inhibited for the time being) */
+    //    timeCorr -= (fTofClusters[ii]->GetDeltaBC() - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
     /* L0L1-latency correction */
     timeCorr += fTofClusters[ii]->GetL0L1Latency() * AliTOFGeometry::BunchCrossingBinWidth();
     /* CTP-latency correction (from OCDB) */
     timeCorr += ctpLatency;
     /* TDC latency-window correction (from OCDB) */
     timeCorr -= tdcLatencyWindow;
-    /* T0Fill correction (from OCDB) */
-    timeCorr -= t0Fill;
+    /* T0 correction (from OCDB) */
+    timeCorr -= t0;
 
     /*
      * end of furhter corrections
@@ -1147,6 +1227,51 @@ void AliTOFClusterFinder::CalibrateRecPoint()
   } // loop on clusters
 
 }
+#endif
+
+//_________________________________________________________________________
+
+void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
+{
+  //
+  // Copy the global array of AliTOFcluster, i.e. fTofClusters (sorted
+  // in Z) in the global TClonesArray of AliTOFcluster,
+  // i.e. fRecPoints.
+  //
+
+  Int_t detectorIndex[5];
+  Double_t time, tot, corr;
+  Int_t deltaBC, l0l1, tdcBin;
+  for (Int_t ii = 0; ii < fNumberOfTofClusters; ii++) {
+    for(Int_t jj = 0; jj < 5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
+
+    Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
+
+    /* check channel enabled */
+    if (!fTOFcalib->IsChannelEnabled(index)) fTofClusters[ii]->SetStatus(kFALSE);
+    
+    /* get cluster info */
+    time = fTofClusters[ii]->GetTDC() * AliTOFGeometry::TdcBinWidth(); /* ps */
+    tot = fTofClusters[ii]->GetToT() * AliTOFGeometry::ToTBinWidth() * 1.e-3; /* ns */
+    deltaBC = fTofClusters[ii]->GetDeltaBC();
+    l0l1 = fTofClusters[ii]->GetL0L1Latency();
+
+    /* get correction */
+    corr = fTOFcalib->GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp); /* ps */
+    AliDebug(2, Form("calibrate index %d: time=%f (ps) tot=%f (ns) deltaBC=%d l0l1=%d timestamp=%d corr=%f (ps)", index, time, tot, deltaBC, l0l1, timestamp, corr));
+
+    /* apply time correction */
+    time -= corr;
+
+    /* convert in TDC bins and set cluster */
+    //tdcBin = (Int_t)(time / AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
+    tdcBin = TMath::Nint(time / AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
+    fTofClusters[ii]->SetTDC(tdcBin);
+
+  } // loop on clusters
+
+}
+
 //______________________________________________________________________________
 
 void AliTOFClusterFinder::ResetRecpoint()