]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFSDigit.cxx
o fix for coverity bug 19907
[u/mrichter/AliRoot.git] / TOF / AliTOFSDigit.cxx
index 665d351dd3ca12b2a5ba1ca11a442cf7731f5635..25a797ca32cc32955db9a689b2cd89b83fc97315 100644 (file)
@@ -1,18 +1,3 @@
-//_________________________________________________________________________
-//  TOF digit: member variables 
-//  fSector  : TOF sector
-//  fPlate   : TOF plate
-//  fStrip   : strips number
-//  fPadx    : pad number along x
-//  fPadz    : pad number along z
-//  fTdc     : TArrayF of TDC values
-//  fAdc     : TArrayF of ADC values
-//              
-//  Getters, setters and member functions  defined here
-//
-//*-- Authors: F. Pierella, A. Seganti, D. Vicinanza
-
 /**************************************************************************
  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  *                                                                        *
  * provided "as is" without express or implied warranty.                  * 
  **************************************************************************/
 
-#include <iostream.h>
+/* $Id$ */
 
-#include "TArrayF.h"
-#include "TArrayI.h"
+//_________________________________________________________________________//
+//                                                                         //
+//  TOF sdigit: member variables                                           //
+//  fSector  : TOF sector                                                  //
+//  fPlate   : TOF plate                                                   //
+//  fStrip   : strips number                                               //
+//  fPadx    : pad number along x                                          //
+//  fPadz    : pad number along z                                          //
+//  fTdc     : TArrayI of TDC values                                       //
+//  fAdc     : TArrayI of ADC values                                       //
+//                                                                         //
+//  Getters, setters and member functions  defined here                    //
+//                                                                         //
+// -- Authors: F. Pierella, A. Seganti, D. Vicinanza                       //
+//_________________________________________________________________________//
 
-#include "AliTOF.h"
+#include "AliLog.h"
+
+#include "AliTOFGeometry.h"
 #include "AliTOFSDigit.h"
-#include "AliTOFConstants.h"
-#include "AliRun.h"
-#include "AliMC.h"
 
 ClassImp(AliTOFSDigit)
 
 ////////////////////////////////////////////////////////////////////////
-AliTOFSDigit::AliTOFSDigit()
+AliTOFSDigit::AliTOFSDigit():
+  fSector(-1),
+  fPlate(-1),
+  fStrip(-1),
+  fPadx(-1),
+  fPadz(-1),
+  fNDigits(0),
+  fTdc(0x0),
+  fAdc(0x0),
+  fTracks(0x0)
 {
-//
-// default ctor
-//
-  fNDigits = 0;
-  fTdc = 0;
-  fAdc = 0;
-  fTracks = 0;
+  //
+  // default ctor
+  //
 }
 
 ////////////////////////////////////////////////////////////////////////
-AliTOFSDigit::AliTOFSDigit(Int_t tracknum, Int_t *vol,Float_t *digit)
+AliTOFSDigit::AliTOFSDigit(Int_t tracknum, Int_t * const vol,Int_t * const digit):
+  TObject(),
+  fSector(-1),
+  fPlate(-1),
+  fStrip(-1),
+  fPadx(-1),
+  fPadz(-1),
+  fNDigits(0),
+  fTdc(0x0),
+  fAdc(0x0),
+  fTracks(0x0)
 {
-//
-// Constructor of digit object
-//
+  //
+  // Constructor of digit object
+  //
+
   fSector = vol[0];
   fPlate  = vol[1];
   fStrip  = vol[2];
   fPadx   = vol[3];
   fPadz   = vol[4];
   fNDigits = 1;
-  fTdc = new TArrayF(fNDigits);
+  fTdc = new TArrayI(fNDigits);
   (*fTdc)[0] = digit[0];
-  fAdc = new TArrayF(fNDigits);
+  fAdc = new TArrayI(fNDigits);
   (*fAdc)[0] = digit[1];
   fTracks = new TArrayI(kMAXDIGITS*fNDigits);
   (*fTracks)[0] = tracknum;
@@ -77,95 +90,138 @@ AliTOFSDigit::AliTOFSDigit(Int_t tracknum, Int_t *vol,Float_t *digit)
 }
 
 ////////////////////////////////////////////////////////////////////////
-AliTOFSDigit::AliTOFSDigit(const AliTOFSDigit & digit)
+AliTOFSDigit::AliTOFSDigit(const AliTOFSDigit & digit):
+  TObject(digit),
+  fSector(digit.fSector),
+  fPlate(digit.fPlate),
+  fStrip(digit.fStrip),
+  fPadx(digit.fPadx),
+  fPadz(digit.fPadz),
+  fNDigits(digit.fNDigits),
+  fTdc(0x0),
+  fAdc(0x0),
+  fTracks(0x0)
 {
   // 
   // copy ctor for AliTOFSDigit object
   //
+  fTdc = new TArrayI(*digit.fTdc);  
+  fAdc = new TArrayI(*digit.fAdc);
+  fTracks = new TArrayI(*digit.fTracks);
+}
+
+////////////////////////////////////////////////////////////////////////
+AliTOFSDigit& AliTOFSDigit::operator=(const AliTOFSDigit & digit)
+{
+  // 
+  // copy ctor for AliTOFSDigit object
+  //
+
+  if (this == &digit)
+    return *this;
+
+  TObject::operator=(digit);
   fSector = digit.fSector;
   fPlate  = digit.fPlate;
   fStrip  = digit.fStrip;
   fPadx   = digit.fPadx;
   fPadz   = digit.fPadz;
   fNDigits = digit.fNDigits;
-  fTdc = new TArrayF(*digit.fTdc);  
-  fAdc = new TArrayF(*digit.fAdc);
-  fTracks = new TArrayI(*digit.fTracks);
+  fTdc = digit.fTdc;
+  fAdc = digit.fAdc;
+  fTracks = digit.fTracks;
+  return *this;
+
 }
 
 ////////////////////////////////////////////////////////////////////////
 AliTOFSDigit::AliTOFSDigit(Int_t sector, Int_t plate, Int_t strip, Int_t padx,
-Int_t padz, Float_t tdc, Float_t adc)
+                          Int_t padz, Int_t tdc, Int_t adc):
+  fSector(sector),
+  fPlate(plate),
+  fStrip(strip),
+  fPadx(padx),
+  fPadz(padz),
+  fNDigits(1),
+  fTdc(0x0),
+  fAdc(0x0),
+  fTracks(0x0)
 {
-//
-// Constructor for sdigit
-//
-  fSector = sector;
-  fPlate  = plate;
-  fStrip  = strip;
-  fPadx   = padx;
-  fPadz   = padz;  
-  fNDigits = 1;
-  fTdc = new TArrayF(fNDigits);
+  //
+  // Constructor for sdigit
+  //
+  fTdc = new TArrayI(fNDigits);
   (*fTdc)[0] = tdc;   
-  fAdc = new TArrayF(fNDigits);
-  (*fAdc)[0] = tdc;   
-// no tracks were specified, set them to -1
+  fAdc = new TArrayI(fNDigits);
+  (*fAdc)[0] = adc;   
+  // no tracks were specified, set them to -1
   fTracks = new TArrayI(kMAXDIGITS*fNDigits);
   for (Int_t i = 0; i <kMAXDIGITS*fNDigits; i++) {
     (*fTracks)[i] = -1;
   }
 }
-   
+
 ////////////////////////////////////////////////////////////////////////
 void AliTOFSDigit::GetLocation(Int_t *Loc) const
 {
-//
-// Get the coordinates of the digit
-// in terms of Sector - Plate - Strip - Pad
-//
-
-   Loc[0]=fSector;
-   Loc[1]=fPlate;
-   Loc[2]=fStrip;
-   Loc[3]=fPadx;
-   Loc[4]=fPadz;
+  //
+  // Get the coordinates of the digit
+  // in terms of Sector - Plate - Strip - Pad
+  //
+  
+  Loc[0]=fSector;
+  Loc[1]=fPlate;
+  Loc[2]=fStrip;
+  Loc[3]=fPadx;
+  Loc[4]=fPadz;
 }
 
 ////////////////////////////////////////////////////////////////////////
-void AliTOFSDigit::Update(Int_t tdc, Int_t adc, Int_t track)
+void AliTOFSDigit::Update(Float_t tdcbin, Int_t tdc, Int_t adc, Int_t track)
 {
-//
-// Add charge and track
-//
-
+  //
+  // Add charge and track
+  //
+  
   Int_t sameTime = -1;
-
+  Float_t tdcwindow = AliTOFGeometry::DeadTime()/tdcbin;
   for (Int_t i = 0; i < fNDigits; i++) {
-    if (TMath::Abs(tdc-fTdc->At(i)) < AliTOFConstants::fgkTimeDiff) {
+    if (TMath::Abs(tdc-fTdc->At(i)) < tdcwindow) {
       sameTime = i;
       break;
     }
   }
+  
+  if (sameTime >= 0) { // another time measurement happens during the
+                      // dead time of the hit pad => it corresponds
+                      // to the same time measurement
+    (*fAdc)[sameTime] += adc;
 
-  if (sameTime >= 0) {
-    (*fAdc)[sameTime] += static_cast<Float_t>(adc);
-// update track - find the first -1  value and replace it by the
-// track number
-    for (Int_t iTrack=0; iTrack<kMAXDIGITS; iTrack++) {
-      if ((*fTracks)[sameTime*kMAXDIGITS+iTrack] == -1) {
-       (*fTracks)[sameTime*kMAXDIGITS+iTrack] = track;
-       break;
-      }
-// write warning about many tracks going to this pad
-      if (iTrack == kMAXDIGITS) {
-       cerr<<"WARNING: AliTOFSDigit::Update  Many hits in the padhit"<<endl;
-       cerr<<"         ";
-//     PrintPad();
+    // update track index array in case the current digit track index
+    // is different from -1
+    if (track!=-1) {
+
+      //Find the first -1 value of the track index array and replace
+      //it by the current digit track index
+      for (Int_t iTrack=0; iTrack<kMAXDIGITS; iTrack++) {
+       if (track==(*fTracks)[sameTime*kMAXDIGITS+iTrack]) break;
+       if ((*fTracks)[sameTime*kMAXDIGITS+iTrack] == -1) {
+         (*fTracks)[sameTime*kMAXDIGITS+iTrack] = track;
+         break;
+       }
+       // write warning about many tracks going to this pad at same time
+       if (iTrack == kMAXDIGITS-1) {
+         AliDebug(1,Form("Update: Many different tracks in the same TOF pad"
+                         " (%2d %1d %2d %1d %2d)\n",
+                         fSector,fPlate,fStrip,fPadz,fPadx));
+         //ToAliWarning(PrintPad());
+       }
       }
     }
-  } else {
-// add new time slot
+
+  } else { // they are two different time measurements
+
+    // add new time slot
     fNDigits++;
     fTdc->Set(fNDigits);
     (*fTdc)[fNDigits-1] = tdc;
@@ -173,18 +229,53 @@ void AliTOFSDigit::Update(Int_t tdc, Int_t adc, Int_t track)
     (*fAdc)[fNDigits-1] = adc;
     fTracks->Set(fNDigits*kMAXDIGITS);
     (*fTracks)[(fNDigits-1)*kMAXDIGITS] = track;
-    for (Int_t i = 1; i <kMAXDIGITS; i++) {
+    for (Int_t i = 1; i <kMAXDIGITS; i++)
       (*fTracks)[(fNDigits-1)*kMAXDIGITS+i] = -1;
-    }
+
   }
+  
+}
+
+////////////////////////////////////////////////////////////////////////
+void AliTOFSDigit::Update(AliTOFSDigit * const sdig)
+{
+
+  //
+  // Perform the sum with sdig
+  //
+
+  Float_t tdcbin = AliTOFGeometry::TdcBinWidth();// [ps] hardwired for the time being
+
+  Int_t track = -1;
+  Int_t adc = -1;
+  Int_t tdc = -1;
+
+  // start loop on all sdig locations
+  Int_t nlocations = sdig->GetNDigits();
+  for (Int_t j = 0; j < nlocations; j++) {
+    tdc = (Int_t)sdig->GetTdc(j);
+    adc = (Int_t)sdig->GetAdc(j);
+
+    // getting here only the first track number
+    //Int_t track = GetTrack(j,0);
+
+    // getting here all the track numbers
+    for (Int_t iTrack = 0; iTrack<kMAXDIGITS; iTrack++) {
+      track = sdig->GetTrack(j,iTrack);
+      Update(tdcbin, tdc, adc, track);
+    } // end loop on tracks
+
+  } // end loop on sdig locations
+
 
 }
+
 ////////////////////////////////////////////////////////////////////////
 AliTOFSDigit::~AliTOFSDigit()
 {
-//
-// dtor
-//
+  //
+  // dtor
+  //
   delete fTdc;
   delete fAdc;
   delete fTracks;
@@ -194,79 +285,33 @@ AliTOFSDigit::~AliTOFSDigit()
 
 Int_t AliTOFSDigit::GetTotPad() const
 {
-//
-// Get the "total" index of the pad inside a Sector
-// starting from the digits data.
-//
-
-  AliTOF* tof;
-  
-  if(gAlice){
-     tof =(AliTOF*) gAlice->GetDetector("TOF");
-  }else{
-     printf("AliTOFSDigit::GetTotPad - No AliRun object present, exiting");
-     return 0;
-  }
+  //
+  // Get the "total" index of the pad inside a Sector
+  // starting from the digits data.
+  //
   
-  Int_t pad = fPadx+tof->GetNpadX()*(fPadz-1);
+  Int_t pad = AliTOFGeometry::NpadZ()*fPadx + fPadz;
   Int_t before=0;
-
+  
   switch(fPlate){ 
-  case 1: before = 0;
-          break;
-  case 2: before = tof->GetNStripC();
-          break;
-  case 3: before = tof->GetNStripB() + tof->GetNStripC();
-          break;
-  case 4: before = tof->GetNStripA() + tof->GetNStripB() + tof->GetNStripC();
-          break;
-  case 5: before = tof->GetNStripA() + 2*tof->GetNStripB() + tof->GetNStripC();
-          break;
+  case 0:
+    //before = 0;
+    break;
+  case 1:
+    before = AliTOFGeometry::NStripC();
+    break;
+  case 2:
+    before = AliTOFGeometry::NStripB() +   AliTOFGeometry::NStripC();
+    break;
+  case 3:
+    before = AliTOFGeometry::NStripA() +   AliTOFGeometry::NStripB() + AliTOFGeometry::NStripC();
+    break;
+  case 4:
+    before = AliTOFGeometry::NStripA() + 2*AliTOFGeometry::NStripB() + AliTOFGeometry::NStripC();
+    break;
   }
   
-  Int_t strip = fStrip+before;
-  Int_t padTot = tof->GetPadXStr()*(strip-1)+pad;
+  Int_t strip = fStrip + before;
+  Int_t padTot = AliTOFGeometry::NpadXStrip()*strip + pad;
   return padTot;
 }
-
-////////////////////////////////////////////////////////////////////////
-//void AliTOFSDigit::AddTrack(Int_t track)
-//{
-//
-// Add a new and different track to the digit -- but to which digit??
-// do not implemet this function
-//
-////////////////////////////////////////////////////////////////////////
-
-// Overloading of Streaming, Sum and Comparison operators
-
-////////////////////////////////////////////////////////////////////////
-/*
-Bool_t AliTOFSDigit::operator==(AliTOFSDigit const &digit) const
-{
-//
-// Overloading of Comparison operator
-//   
- if (fSector==digit.fSector &&
-     fPlate==digit.fPlate &&
-     fStrip==digit.fStrip &&
-     fPadx==digit.fPadx &&
-     fPadz==digit.fPadz &&
-     fTdc==digit.fTdc &&
-     fAdc==digit.fAdc) return kTRUE;
-     else return kFALSE;
-}
-*/
-////////////////////////////////////////////////////////////////////////
-/*
-ostream& operator << (ostream& out, const AliTOFSDigit &digit)
-{
-//
-// Output streamer: output of the digit data
-//
-out << "Sector " << digit.fSector << ", Plate " << digit.fPlate << ", Strip " << digit.fStrip << endl;
-out << "Padx" << digit.fPadx << ", Padz " << digit.fPadz << endl;
-out << "TDC " << digit.fTdc->At(0) << ", ADC "<< digit.fAdc->At(0) << endl;
-return out;
-}
-*/