]> 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 2bceb93fb68c6f814a9ef9d8e1daf98c64b442d6..1abc822690098bb7ef0f0f5dd6c635b714737a59 100644 (file)
@@ -309,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);
@@ -408,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);
@@ -497,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);
@@ -559,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
@@ -646,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();
 
@@ -708,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
@@ -800,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();
 
@@ -829,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};
 
@@ -890,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();
 
@@ -919,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};
 
@@ -1041,6 +1093,12 @@ void AliTOFClusterFinder::FillRecPoint()
 }
 
 //_________________________________________________________________________
+
+/*
+ * OLD CALIBRATE REC POINTS FUNCTION
+ */
+
+#if 0
 void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
 {
   //
@@ -1114,7 +1172,7 @@ void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
      } 
       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 */
@@ -1169,6 +1227,51 @@ void AliTOFClusterFinder::CalibrateRecPoint(UInt_t timestamp)
   } // 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()