]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
updates to TOF-T0 algorithm
authorrpreghen <rpreghen@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 1 Sep 2010 15:01:44 +0000 (15:01 +0000)
committerrpreghen <rpreghen@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 1 Sep 2010 15:01:44 +0000 (15:01 +0000)
TOF/AliTOFT0maker.cxx
TOF/AliTOFT0maker.h
TOF/AliTOFT0v1.cxx
TOF/AliTOFT0v1.h

index 5dc950667004defff4c4a827f9de023e37caf734..1e51f96957ad395e174f59c679aef40ca9a0fc77 100644 (file)
@@ -64,11 +64,14 @@ AliTOFT0maker::AliTOFT0maker():
   fExternalPIDFlag(kFALSE),
   fTOFcalib(NULL),
   fNoTOFT0(0),
   fExternalPIDFlag(kFALSE),
   fTOFcalib(NULL),
   fNoTOFT0(0),
+  fNmomBins(0),
   fTimeResolution(100),
   fT0sigma(1000),
   fHmapChannel(0),
   fKmask(0),
   fTimeResolution(100),
   fT0sigma(1000),
   fHmapChannel(0),
   fKmask(0),
-  fT0width(150.)
+  fT0width(150.),
+  fT0spreadExt(-1.),
+  fT0fillExt(0)
 {
   // ctr
   fCalculated[0] = 0;
 {
   // ctr
   fCalculated[0] = 0;
@@ -76,38 +79,15 @@ AliTOFT0maker::AliTOFT0maker():
   fCalculated[2] = 0;
   fCalculated[3] = 0;
 
   fCalculated[2] = 0;
   fCalculated[3] = 0;
 
-  fT0TOF = new AliTOFT0v1();
   if(AliPID::ParticleMass(0) == 0) new AliPID();
 
   fPIDesd = new AliESDpid();
 
   if(AliPID::ParticleMass(0) == 0) new AliPID();
 
   fPIDesd = new AliESDpid();
 
-  fPtCutMin[0] = 0.3;
-  fPtCutMin[1] = 0.5;
-  fPtCutMin[2] = 0.6;
-  fPtCutMin[3] = 0.7;
-  fPtCutMin[4] = 0.8;
-  fPtCutMin[5] = 0.9;
-  fPtCutMin[6] = 1;
-  fPtCutMin[7] = 1.2;
-  fPtCutMin[8] = 1.5;
-  fPtCutMin[9] = 2;
-
-  fPtCutMax[0] = 0.5;
-  fPtCutMax[1] = 0.6;
-  fPtCutMax[2] = 0.7;
-  fPtCutMax[3] = 0.8;
-  fPtCutMax[4] = 0.9;
-  fPtCutMax[5] = 1;
-  fPtCutMax[6] = 1.2;
-  fPtCutMax[7] = 1.5;
-  fPtCutMax[8] = 2;
-  fPtCutMax[9] = 3;
-
-  /* init arrays */
-  for (Int_t i = 0; i < 10; i++) {
-    fT0pt[i] = 0.;
-    fT0ptSigma[i] = 0.;
-  }
+  fNmomBins = fPIDesd->GetTOFResponse().GetNmomBins();
+  SetTOFResponse();
+
+  fT0TOF = new AliTOFT0v1(fPIDesd);
+
 }
 //____________________________________________________________________________ 
 AliTOFT0maker::AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib):
 }
 //____________________________________________________________________________ 
 AliTOFT0maker::AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib):
@@ -117,11 +97,14 @@ AliTOFT0maker::AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib):
     fExternalPIDFlag(kTRUE),
     fTOFcalib(tofCalib),
     fNoTOFT0(0),
     fExternalPIDFlag(kTRUE),
     fTOFcalib(tofCalib),
     fNoTOFT0(0),
+    fNmomBins(0),
     fTimeResolution(100),
     fT0sigma(1000),
     fHmapChannel(0),
     fKmask(0),
     fTimeResolution(100),
     fT0sigma(1000),
     fHmapChannel(0),
     fKmask(0),
-    fT0width(150.)
+    fT0width(150.),
+    fT0spreadExt(-1.),
+    fT0fillExt(0)
 {
   // ctr
   fCalculated[0] = 0;
 {
   // ctr
   fCalculated[0] = 0;
@@ -129,7 +112,6 @@ AliTOFT0maker::AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib):
   fCalculated[2] = 0;
   fCalculated[3] = 0;
 
   fCalculated[2] = 0;
   fCalculated[3] = 0;
 
-  fT0TOF = new AliTOFT0v1();
   if(AliPID::ParticleMass(0) == 0) new AliPID();
 
   if(!fPIDesd){
   if(AliPID::ParticleMass(0) == 0) new AliPID();
 
   if(!fPIDesd){
@@ -137,71 +119,13 @@ AliTOFT0maker::AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib):
     fExternalPIDFlag = kFALSE;
   }
 
     fExternalPIDFlag = kFALSE;
   }
 
-  fPtCutMin[0] = 0.3;
-  fPtCutMin[1] = 0.5;
-  fPtCutMin[2] = 0.6;
-  fPtCutMin[3] = 0.7;
-  fPtCutMin[4] = 0.8;
-  fPtCutMin[5] = 0.9;
-  fPtCutMin[6] = 1;
-  fPtCutMin[7] = 1.2;
-  fPtCutMin[8] = 1.5;
-  fPtCutMin[9] = 2;
-
-  fPtCutMax[0] = 0.5;
-  fPtCutMax[1] = 0.6;
-  fPtCutMax[2] = 0.7;
-  fPtCutMax[3] = 0.8;
-  fPtCutMax[4] = 0.9;
-  fPtCutMax[5] = 1;
-  fPtCutMax[6] = 1.2;
-  fPtCutMax[7] = 1.5;
-  fPtCutMax[8] = 2;
-  fPtCutMax[9] = 3;
-
-  /* init arrays */
-  for (Int_t i = 0; i < 10; i++) {
-    fT0pt[i] = 0.;
-    fT0ptSigma[i] = 0.;
-  }
-}
-
-/* copy-constructor and operator= suppressed
-
-
-//____________________________________________________________________________ 
-AliTOFT0maker::AliTOFT0maker(const AliTOFT0maker & t) :
-  TObject(t),
-  fT0TOF(t.fT0TOF),
-  fPIDESD(t.fPIDESD),
-  fNoTOFT0(t.fNoTOFT0),
-  fTimeResolution(t.fTimeResolution),
-  fT0sigma(t.fT0sigma),
-  fHmapChannel(t.fHmapChannel),
-  fKmask(t.fKmask)
-  {
-  // copy ctr
-}
-
-//____________________________________________________________________________ 
-AliTOFT0maker& AliTOFT0maker::operator=(const AliTOFT0maker &t)
-{
-  //
-  // assign. operator
-  //
-
-  if (this == &t)
-    return *this;
+  fNmomBins = fPIDesd->GetTOFResponse().GetNmomBins();
+  SetTOFResponse();
 
 
-  TObject::operator=(t);
-  fTimeResolution = t.fTimeResolution;
-  fT0sigma = t.fT0sigma;
+  fT0TOF = new AliTOFT0v1(fPIDesd);
 
 
-  return *this;
 }
 
 }
 
-*/
-
 //____________________________________________________________________________ 
 AliTOFT0maker::~AliTOFT0maker()
 {
 //____________________________________________________________________________ 
 AliTOFT0maker::~AliTOFT0maker()
 {
@@ -216,34 +140,46 @@ Double_t* AliTOFT0maker::ComputeT0TOF(AliESDEvent *esd,Double_t t0time,Double_t
   // Remake TOF PID probabilities
   //
 
   // Remake TOF PID probabilities
   //
 
-  Double_t t0tof[4];
+  Double_t t0tof[6];
 
   if(fKmask) ApplyMask(esd);
 
 
   if(fKmask) ApplyMask(esd);
 
+  Double_t t0fill = 0.;
+
+  fPIDesd->GetTOFResponse().ResetT0info();
+
   /* get T0 spread from TOFcalib if available otherwise use default value */
   if (fTOFcalib && esd) {
     AliTOFRunParams *runParams = fTOFcalib->GetRunParams();
     if (runParams && runParams->GetTimestamp(0) != 0) {
       Float_t t0spread = runParams->EvalT0Spread(esd->GetTimeStamp());
   /* get T0 spread from TOFcalib if available otherwise use default value */
   if (fTOFcalib && esd) {
     AliTOFRunParams *runParams = fTOFcalib->GetRunParams();
     if (runParams && runParams->GetTimestamp(0) != 0) {
       Float_t t0spread = runParams->EvalT0Spread(esd->GetTimeStamp());
-      SetT0FillWidth(t0spread);
+      if(fT0spreadExt > 0) SetT0FillWidth(fT0spreadExt);
+      else{
+       SetT0FillWidth(t0spread);
+       t0fill = fT0fillExt;
+      }
+    }
+    else{
+      SetT0FillWidth(fT0spreadExt);
+      t0fill = fT0fillExt;
     }
   }
 
   fT0TOF->Init(esd);
   AliTOFT0v1* t0maker= fT0TOF;
     }
   }
 
   fT0TOF->Init(esd);
   AliTOFT0v1* t0maker= fT0TOF;
-  t0maker->SetTimeResolution(fTimeResolution*1e-12);
 
   t0maker->DefineT0("all",1.5,3.0);
   t0tof[0] = t0maker->GetResult(0);
   t0tof[1] = t0maker->GetResult(1);
   t0tof[2] = t0maker->GetResult(2);
   t0tof[3] = t0maker->GetResult(3);
 
   t0maker->DefineT0("all",1.5,3.0);
   t0tof[0] = t0maker->GetResult(0);
   t0tof[1] = t0maker->GetResult(1);
   t0tof[2] = t0maker->GetResult(2);
   t0tof[3] = t0maker->GetResult(3);
+  t0tof[4] = t0maker->GetResult(4);
+  t0tof[5] = t0maker->GetResult(5);
 
   Float_t lT0Current=0.;
   fT0sigma=1000;
 
 //   Int_t nrun = esd->GetRunNumber();
 
   Float_t lT0Current=0.;
   fT0sigma=1000;
 
 //   Int_t nrun = esd->GetRunNumber();
-  Double_t t0fill = 0.;
 
   t0time += t0fill;
 
 
   t0time += t0fill;
 
@@ -260,6 +196,10 @@ Double_t* AliTOFT0maker::ComputeT0TOF(AliESDEvent *esd,Double_t t0time,Double_t
   fCalculated[6]=sigmaFill; // sigma t0 fill
   fCalculated[7] = t0tof[3];  // n TOF tracks used for T0
 
   fCalculated[6]=sigmaFill; // sigma t0 fill
   fCalculated[7] = t0tof[3];  // n TOF tracks used for T0
 
+  //statistics
+  fCalculated[8] = t0tof[4]; // real time in s
+  fCalculated[9] = t0tof[5]; // cpu time in s
+
   if(fCalculated[1] < sigmaFill && TMath::Abs(fCalculated[0] - t0fill) < 500 && fCalculated[1] < fTimeResolution*1.2){
     fT0sigma=fCalculated[1];
     lT0Current=fCalculated[0];
   if(fCalculated[1] < sigmaFill && TMath::Abs(fCalculated[0] - t0fill) < 500 && fCalculated[1] < fTimeResolution*1.2){
     fT0sigma=fCalculated[1];
     lT0Current=fCalculated[0];
@@ -305,48 +245,67 @@ Double_t* AliTOFT0maker::ComputeT0TOF(AliESDEvent *esd,Double_t t0time,Double_t
   }
 
   // T0 pt bin
   }
 
   // T0 pt bin
-  for(Int_t i=0;i<10;i++){
-   t0maker->DefineT0("all",fPtCutMin[i],fPtCutMax[i]);
-    t0tof[0] = t0maker->GetResult(0);
-    t0tof[1] = t0maker->GetResult(1);
-    t0tof[2] = t0maker->GetResult(2);
-    t0tof[3] = t0maker->GetResult(3);
-    fT0pt[i] =-1000*t0tof[0]; // best t0
-    fT0ptSigma[i] =1000*t0tof[1]; // sigma best t0
-
-    if(fT0ptSigma[i] < sigmaFill  && fT0ptSigma[i] < fTimeResolution * 1.2 && TMath::Abs(fT0pt[i] - t0fill) < 500){
-      // Ok T0
+  if(fCalculated[7] < 100){
+    for(Int_t i=0;i<fNmomBins;i++){
+      t0maker->DefineT0("all",fPIDesd->GetTOFResponse().GetMinMom(i),fPIDesd->GetTOFResponse().GetMaxMom(i));
+      t0tof[0] = t0maker->GetResult(0);
+      t0tof[1] = t0maker->GetResult(1);
+      t0tof[2] = t0maker->GetResult(2);
+      t0tof[3] = t0maker->GetResult(3);
+
+      Float_t t0bin =-1000*t0tof[0]; // best t0
+      Float_t t0binRes =1000*t0tof[1]; // sigma best t0
+      
+      if(t0binRes < sigmaFill  && t0binRes < fTimeResolution * 1.2 && TMath::Abs(t0bin - t0fill) < 500){
+       // Ok T0
+       if(t0sigma < 1000){
+         Double_t w1 = 1./t0sigma/t0sigma;
+         Double_t w2 = 1./t0binRes/t0binRes;
+         
+         Double_t wtot = w1+w2;
+         
+         t0bin = (w1*t0time + w2*t0bin) / wtot;
+         t0binRes = TMath::Sqrt(1./wtot);
+       }
+      }
+      else{
+       t0bin = t0fill;
+       t0binRes = sigmaFill;
+       if(t0sigma < 1000){
+         t0bin = t0time;
+          t0binRes= t0sigma;     
+       }
+      }
+      fPIDesd->GetTOFResponse().SetT0bin(i,t0bin);
+      fPIDesd->GetTOFResponse().SetT0binRes(i,t0binRes);
     }
     }
-    else{
-      fT0pt[i] = t0fill;
-      fT0ptSigma[i] = sigmaFill;
+  }
+  else{
+    for(Int_t i=0;i<fNmomBins;i++){
+      fPIDesd->GetTOFResponse().SetT0bin(i,lT0Current);
+      fPIDesd->GetTOFResponse().SetT0binRes(i,fT0sigma);
     }
   }
     }
   }
-  //----
-  SetTOFResponse();
 
   return fCalculated;
 }
 //____________________________________________________________________________ 
 Double_t  *AliTOFT0maker::GetT0p(Float_t p){// [0]=to -- [1] = sigma T0
 
   return fCalculated;
 }
 //____________________________________________________________________________ 
 Double_t  *AliTOFT0maker::GetT0p(Float_t p){// [0]=to -- [1] = sigma T0
-  Int_t i=0;
-  while(p > fPtCutMin[i] && i < 10) i++;
-  if(i > 0) i--;
+  Int_t i=fPIDesd->GetTOFResponse().GetMomBin(p);
   
   
-  fT0cur[0] = fT0pt[i];
-  fT0cur[1] = fT0ptSigma[i];
+  fT0cur[0] = fPIDesd->GetTOFResponse().GetT0bin(i);
+  fT0cur[1] = fPIDesd->GetTOFResponse().GetT0binRes(i);
+
   return fT0cur;
 }
 //____________________________________________________________________________ 
 void AliTOFT0maker::SetTOFResponse(){
   return fT0cur;
 }
 //____________________________________________________________________________ 
 void AliTOFT0maker::SetTOFResponse(){
-    fPIDesd->GetTOFResponse().SetTimeResolution(TMath::Sqrt(fT0sigma*fT0sigma + fTimeResolution*fTimeResolution));
+  fPIDesd->GetTOFResponse().SetTimeResolution(fTimeResolution);
 }
 //____________________________________________________________________________ 
 Float_t AliTOFT0maker::GetExpectedSigma(Float_t mom, Float_t tof, Float_t mass){
 }
 //____________________________________________________________________________ 
 Float_t AliTOFT0maker::GetExpectedSigma(Float_t mom, Float_t tof, Float_t mass){
-  Double_t *sigmaT0 = GetT0p(mom);
-  fPIDesd->GetTOFResponse().SetTimeResolution(TMath::Sqrt(sigmaT0[1]*sigmaT0[1] + fTimeResolution*fTimeResolution));
   Float_t sigma = fPIDesd->GetTOFResponse().GetExpectedSigma(mom,tof,mass);
   Float_t sigma = fPIDesd->GetTOFResponse().GetExpectedSigma(mom,tof,mass);
-  fPIDesd->GetTOFResponse().SetTimeResolution(TMath::Sqrt(fT0sigma*fT0sigma + fTimeResolution*fTimeResolution));
 
   return sigma;
 }
 
   return sigma;
 }
index cc8b701ddd619adc5b3494be780f7f8da8e4be0d..e415a0192512c111a1d4f76f4566f959f8db54f4 100644 (file)
@@ -28,13 +28,13 @@ public:
   AliTOFT0maker() ; // default constructor
   AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib); // overloaded constructor
   virtual ~AliTOFT0maker() ; // dtor
   AliTOFT0maker() ; // default constructor
   AliTOFT0maker(AliESDpid *externalPID, AliTOFcalib *tofCalib); // overloaded constructor
   virtual ~AliTOFT0maker() ; // dtor
+  
   // return (fCalculated[0]=event time -- fCalculated[1]=sigma event time in ps -- fCalculated[2]=mean event time for each fill -- fCalculated[3]=number of tracks at the TOF level) if you can subtruct the event time; return NULL if there is no event time
   Double_t *ComputeT0TOF(AliESDEvent *esd,Double_t t0time=0.,Double_t t0sigma=1000.); // t0time and t0sigma in ps
   void ApplyT0TOF(AliESDEvent *esd);
   Float_t GetExpectedSigma(Float_t mom, Float_t tof, Float_t mass);
   Double_t  *GetT0p(Float_t p);
   // return (fCalculated[0]=event time -- fCalculated[1]=sigma event time in ps -- fCalculated[2]=mean event time for each fill -- fCalculated[3]=number of tracks at the TOF level) if you can subtruct the event time; return NULL if there is no event time
   Double_t *ComputeT0TOF(AliESDEvent *esd,Double_t t0time=0.,Double_t t0sigma=1000.); // t0time and t0sigma in ps
   void ApplyT0TOF(AliESDEvent *esd);
   Float_t GetExpectedSigma(Float_t mom, Float_t tof, Float_t mass);
   Double_t  *GetT0p(Float_t p);
-
+  
   void      SetTimeResolution(Double_t timeresolution){fTimeResolution=timeresolution;};// TOF timeresolution in [ps]
   Double_t  GetTimeResolution() const {return fTimeResolution;} // Get TOF Time Resolution
   void SetT0FillWidth(Float_t width){fT0width = width;}; // in ps
   void      SetTimeResolution(Double_t timeresolution){fTimeResolution=timeresolution;};// TOF timeresolution in [ps]
   Double_t  GetTimeResolution() const {return fTimeResolution;} // Get TOF Time Resolution
   void SetT0FillWidth(Float_t width){fT0width = width;}; // in ps
@@ -44,15 +44,17 @@ public:
   
   void SetNoTOFT0(Bool_t status=kTRUE){fNoTOFT0=status;}; // disable the TOF T0 info
   void SetMaskOffChannel(Bool_t status=kTRUE){fKmask=status;}; // switch for the map off channel
   
   void SetNoTOFT0(Bool_t status=kTRUE){fNoTOFT0=status;}; // disable the TOF T0 info
   void SetMaskOffChannel(Bool_t status=kTRUE){fKmask=status;}; // switch for the map off channel
-
+  
   Float_t  TuneForMC(AliESDEvent *esd); // set enabled channeld, add a smeared t0, add a TOF smearing, return true(smeared) T0 event
   Float_t  TuneForMC(AliESDEvent *esd); // set enabled channeld, add a smeared t0, add a TOF smearing, return true(smeared) T0 event
-
-
+  
+  void SetT0spread(Float_t t0spread){fT0spreadExt=t0spread;};
+  void SetT0fill(Float_t t0fill){fT0fillExt=t0fill;};
+  
  private:
  private:
-
+  
   AliTOFT0maker(const AliTOFT0maker &);
   AliTOFT0maker & operator=(const AliTOFT0maker &);
   AliTOFT0maker(const AliTOFT0maker &);
   AliTOFT0maker & operator=(const AliTOFT0maker &);
-
+  
   void SetTOFResponse();
 
   AliTOFT0v1 *fT0TOF; // T0-TOF
   void SetTOFResponse();
 
   AliTOFT0v1 *fT0TOF; // T0-TOF
@@ -60,15 +62,14 @@ public:
   Bool_t fExternalPIDFlag; // external PID flag
   AliTOFcalib *fTOFcalib; // TOF calibration
 
   Bool_t fExternalPIDFlag; // external PID flag
   AliTOFcalib *fTOFcalib; // TOF calibration
 
-  Double_t fT0pt[10],fT0ptSigma[10]; // T0 and T0sigma in p-bins
-
   Bool_t fNoTOFT0;   // swithc to avoid T0-TOF is used
 
   Bool_t fNoTOFT0;   // swithc to avoid T0-TOF is used
 
-  Float_t fPtCutMin[10]; // min values for p bins
-  Float_t fPtCutMax[10]; // max values for p bins
+  Int_t fNmomBins;
+
+  Double_t fCalculated[10]; // contains the parameters with the event time
+
   Double_t fT0cur[2]; // current T0 and T0 sigma
  
   Double_t fT0cur[2]; // current T0 and T0 sigma
  
-  Double_t fCalculated[8]; // contains the parameters with the event time
   Double_t fTimeResolution;  // global time resolution used to calculate T0
   
   Float_t fT0sigma; // T0 resolution
   Double_t fTimeResolution;  // global time resolution used to calculate T0
   
   Float_t fT0sigma; // T0 resolution
@@ -78,8 +79,11 @@ public:
   
   Float_t fT0width; // T0 FILL width
 
   
   Float_t fT0width; // T0 FILL width
 
+  Float_t fT0spreadExt;
+  Float_t fT0fillExt; // t0spread if set 
+
   ClassDef(AliTOFT0maker,2);  // Calculate the time zero using TOF detector */
   
 };
 
   ClassDef(AliTOFT0maker,2);  // Calculate the time zero using TOF detector */
   
 };
 
-#endif // ALITOFT0MAKERANA_H
+#endif // ALITOFT0MAKER_H
index f4bfeac5d89c8e0736195f9311da77fb7dcd01fb..651d36d9646bd2c26269d9ca2066c25a84fc06fa 100644 (file)
 #include "AliESDtrack.h"
 #include "AliESDEvent.h"
 #include "AliTOFT0v1.h"
 #include "AliESDtrack.h"
 #include "AliESDEvent.h"
 #include "AliTOFT0v1.h"
+#include "TBenchmark.h"
+#include "AliPID.h"
+#include "AliESDpid.h"
 
 ClassImp(AliTOFT0v1)
            
 //____________________________________________________________________________ 
 
 ClassImp(AliTOFT0v1)
            
 //____________________________________________________________________________ 
-AliTOFT0v1::AliTOFT0v1():
+AliTOFT0v1::AliTOFT0v1(AliESDpid *extPID):
   TObject(),
   fLowerMomBound(0.5),
   fUpperMomBound(3),  
   TObject(),
   fLowerMomBound(0.5),
   fUpperMomBound(3),  
-  fTimeResolution(0.80e-10), 
   fTimeCorr(0.), 
   fTimeCorr(0.), 
-  fEvent(0x0)
-//   fCalib(0x0)
+  fEvent(0x0),
+  fPIDesd(extPID)
 {
   //
   // default constructor
   //
 {
   //
   // default constructor
   //
+  if(AliPID::ParticleMass(0) == 0) new AliPID();
+
+  if(!fPIDesd){
+    fPIDesd = new AliESDpid();
+  }
 
   Init(NULL);
     
 }
 
 
   Init(NULL);
     
 }
 
-           
 //____________________________________________________________________________ 
 //____________________________________________________________________________ 
-AliTOFT0v1::AliTOFT0v1(AliESDEvent* event): 
+AliTOFT0v1::AliTOFT0v1(AliESDEvent* event,AliESDpid *extPID): 
   TObject(),
   fLowerMomBound(0.5),
   fUpperMomBound(3.0),  
   TObject(),
   fLowerMomBound(0.5),
   fUpperMomBound(3.0),  
-  fTimeResolution(0.80e-10), 
   fTimeCorr(0.), 
   fTimeCorr(0.), 
-  fEvent(event)
-//   fCalib(0x0)
+  fEvent(event),
+  fPIDesd(extPID)
 {
   //
   // real constructor
   //
 {
   //
   // real constructor
   //
-  
-  Init(event);
-
-}
+  if(AliPID::ParticleMass(0) == 0) new AliPID();
 
 
-/* copy-constructor and operator= suppresed 
+  if(!fPIDesd){
+    fPIDesd = new AliESDpid();
+  }
 
 
-//____________________________________________________________________________ 
-AliTOFT0v1::AliTOFT0v1(const AliTOFT0v1 & tzero):
-  TObject(),
-  fLowerMomBound(tzero.fLowerMomBound),
-  fUpperMomBound(tzero.fUpperMomBound),  
-  fTimeResolution(tzero.fTimeResolution), 
-  fTimeCorr(tzero.fTimeCorr), 
-  fEvent(tzero.fEvent)
-//   fCalib(tzero.fCalib)
-{
-  //
-  // copy constructor
-  //
-    
-  fT0SigmaT0def[0]=tzero.fT0SigmaT0def[0];
-  fT0SigmaT0def[1]=tzero.fT0SigmaT0def[1];
-  fT0SigmaT0def[2]=tzero.fT0SigmaT0def[2];
-  fT0SigmaT0def[3]=tzero.fT0SigmaT0def[3];
+  Init(event);
 
 }
 
 }
-
 //____________________________________________________________________________ 
 AliTOFT0v1& AliTOFT0v1::operator=(const AliTOFT0v1 &tzero)
 {
 //____________________________________________________________________________ 
 AliTOFT0v1& AliTOFT0v1::operator=(const AliTOFT0v1 &tzero)
 {
@@ -133,10 +119,8 @@ AliTOFT0v1& AliTOFT0v1::operator=(const AliTOFT0v1 &tzero)
   
   fLowerMomBound=tzero.fLowerMomBound;
   fUpperMomBound=tzero.fUpperMomBound;  
   
   fLowerMomBound=tzero.fLowerMomBound;
   fUpperMomBound=tzero.fUpperMomBound;  
-  fTimeResolution=tzero.fTimeResolution; 
   fTimeCorr=tzero.fTimeCorr; 
   fEvent=tzero.fEvent;
   fTimeCorr=tzero.fTimeCorr; 
   fEvent=tzero.fEvent;
-//   fCalib=tzero.fCalib;
   fT0SigmaT0def[0]=tzero.fT0SigmaT0def[0];
   fT0SigmaT0def[1]=tzero.fT0SigmaT0def[1];
   fT0SigmaT0def[2]=tzero.fT0SigmaT0def[2];
   fT0SigmaT0def[0]=tzero.fT0SigmaT0def[0];
   fT0SigmaT0def[1]=tzero.fT0SigmaT0def[1];
   fT0SigmaT0def[2]=tzero.fT0SigmaT0def[2];
@@ -145,12 +129,10 @@ AliTOFT0v1& AliTOFT0v1::operator=(const AliTOFT0v1 &tzero)
   return *this;
 }
 
   return *this;
 }
 
-*/
 //____________________________________________________________________________ 
 AliTOFT0v1::~AliTOFT0v1()
 {
   // dtor
 //____________________________________________________________________________ 
 AliTOFT0v1::~AliTOFT0v1()
 {
   // dtor
-//   fCalib=NULL;
   fEvent=NULL;
 
 }
   fEvent=NULL;
 
 }
@@ -172,25 +154,21 @@ AliTOFT0v1::Init(AliESDEvent *event)
 
 }
 
 
 }
 
-//____________________________________________________________________________ 
-void AliTOFT0v1::SetTimeResolution(Double_t timeresolution){
-  // Set the TOF time resolution
-  fTimeResolution=timeresolution;
-}
-//____________________________________________________________________________
 //____________________________________________________________________________
 Double_t * AliTOFT0v1::DefineT0(Option_t *option) 
 { 
   // Caluclate the Event Time using the ESD TOF time
 
 //____________________________________________________________________________
 Double_t * AliTOFT0v1::DefineT0(Option_t *option) 
 { 
   // Caluclate the Event Time using the ESD TOF time
 
+  TBenchmark *bench=new TBenchmark();
+  bench->Start("t0computation");
+
   fT0SigmaT0def[0]=0.;
   fT0SigmaT0def[1]=0.600;
   fT0SigmaT0def[2]=0.;
   fT0SigmaT0def[3]=0.;
   fT0SigmaT0def[0]=0.;
   fT0SigmaT0def[1]=0.600;
   fT0SigmaT0def[2]=0.;
   fT0SigmaT0def[3]=0.;
-
- Float_t timeresolutioninns=fTimeResolution*(1.e+9); // convert in [ns]
   
   
-  const Int_t nmaxtracksinset=10;
+  const Int_t nmaxtracksinsetMax=10;
+  Int_t nmaxtracksinset=10;
 //   if(strstr(option,"all")){
 //     cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl;
 //     cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl;
 //   if(strstr(option,"all")){
 //     cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl;
 //     cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl;
@@ -233,16 +211,17 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
     
     time*=1.E-3; // tof given in nanoseconds      
     if (!(mom<=fUpperMomBound && mom>=fLowerMomBound))continue;
     
     time*=1.E-3; // tof given in nanoseconds      
     if (!(mom<=fUpperMomBound && mom>=fLowerMomBound))continue;
-   
+
     if (!AcceptTrack(t)) continue;
 
     if (!AcceptTrack(t)) continue;
 
-    if(t->GetIntegratedLength() < 350)continue; //skip decays
+    if(t->GetP() < fLowerMomBound || t->GetIntegratedLength() < 350 || t->GetTOFsignalToT() < 0.000000001)continue; //skip decays
     if(time <= mintime) mintime=time;
     tracks[ngoodtrk]=t;
     ngoodtrk++;
   }
   
     if(time <= mintime) mintime=time;
     tracks[ngoodtrk]=t;
     ngoodtrk++;
   }
   
-  
+  if(ngoodtrk>22) nmaxtracksinset = 6;
+
 //    cout << " N. of ESD tracks                    : " << ntrk << endl;
 //    cout << " N. of preselected tracks            : " << ngoodtrk << endl;
 //    cout << " Minimum tof time in set (in ns)                 : " << mintime << endl;
 //    cout << " N. of ESD tracks                    : " << ntrk << endl;
 //    cout << " N. of preselected tracks            : " << ngoodtrk << endl;
 //    cout << " Minimum tof time in set (in ns)                 : " << mintime << endl;
@@ -304,27 +283,27 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
        
        // Analyse it
        
        
        // Analyse it
        
-       Int_t   assparticle[nmaxtracksinset];
-       Float_t exptof[nmaxtracksinset][3];
-       Float_t timeofflight[nmaxtracksinset];
-       Float_t momentum[nmaxtracksinset];
-       Float_t timezero[nmaxtracksinset];
-       Float_t weightedtimezero[nmaxtracksinset];
-       Float_t beta[nmaxtracksinset];
-       Float_t texp[nmaxtracksinset];
-       Float_t dtexp[nmaxtracksinset];
-       Float_t sqMomError[nmaxtracksinset];
-       Float_t sqTrackError[nmaxtracksinset];
+       Int_t   assparticle[nmaxtracksinsetMax];
+       Float_t exptof[nmaxtracksinsetMax][3];
+       Float_t timeofflight[nmaxtracksinsetMax];
+       Float_t momentum[nmaxtracksinsetMax];
+       Float_t timezero[nmaxtracksinsetMax];
+       Float_t weightedtimezero[nmaxtracksinsetMax];
+       Float_t beta[nmaxtracksinsetMax];
+       Float_t texp[nmaxtracksinsetMax];
+       Float_t dtexp[nmaxtracksinsetMax];
+       Float_t sqMomError[nmaxtracksinsetMax];
+       Float_t sqTrackError[nmaxtracksinsetMax];
        Float_t massarray[3]={0.13957,0.493677,0.9382723};
        Float_t massarray[3]={0.13957,0.493677,0.9382723};
-       Float_t tracktoflen[nmaxtracksinset];
-       Float_t besttimezero[nmaxtracksinset];
-       Float_t besttexp[nmaxtracksinset];
-       Float_t besttimeofflight[nmaxtracksinset];
-       Float_t bestmomentum[nmaxtracksinset];
-       Float_t bestchisquare[nmaxtracksinset];
-       Float_t bestweightedtimezero[nmaxtracksinset];
-       Float_t bestsqTrackError[nmaxtracksinset];
-       Int_t imass[nmaxtracksinset];
+       Float_t tracktoflen[nmaxtracksinsetMax];
+       Float_t besttimezero[nmaxtracksinsetMax];
+       Float_t besttexp[nmaxtracksinsetMax];
+       Float_t besttimeofflight[nmaxtracksinsetMax];
+       Float_t bestmomentum[nmaxtracksinsetMax];
+       Float_t bestchisquare[nmaxtracksinsetMax];
+       Float_t bestweightedtimezero[nmaxtracksinsetMax];
+       Float_t bestsqTrackError[nmaxtracksinsetMax];
+       Int_t imass[nmaxtracksinsetMax];
        
        for (Int_t j=0; j<ntracksinset; j++) {
          assparticle[j] = 3;
        
        for (Int_t j=0; j<ntracksinset; j++) {
          assparticle[j] = 3;
@@ -373,7 +352,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
          beta[itz]=momentum[itz]/sqrt(massarray[0]*massarray[0]
                                       +momentum[itz]*momentum[itz]);
          sqMomError[itz]= ((1.-beta[itz]*beta[itz])*0.01)*((1.-beta[itz]*beta[itz])*0.01)*(tracktoflen[itz]/(0.299792*beta[itz]))*(tracktoflen[itz]/(0.299792*beta[itz])); 
          beta[itz]=momentum[itz]/sqrt(massarray[0]*massarray[0]
                                       +momentum[itz]*momentum[itz]);
          sqMomError[itz]= ((1.-beta[itz]*beta[itz])*0.01)*((1.-beta[itz]*beta[itz])*0.01)*(tracktoflen[itz]/(0.299792*beta[itz]))*(tracktoflen[itz]/(0.299792*beta[itz])); 
-         sqTrackError[itz]=(timeresolutioninns*timeresolutioninns+sqMomError[itz]); //in ns
+         sqTrackError[itz]=sqMomError[itz]; //in ns
          timezero[itz]=exptof[itz][0]-timeofflight[itz];// in ns
          weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
          sumAllweightspi+=1./sqTrackError[itz];
          timezero[itz]=exptof[itz][0]-timeofflight[itz];// in ns
          weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
          sumAllweightspi+=1./sqTrackError[itz];
@@ -403,10 +382,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
          Float_t eMeanTzero=0.;
          
          for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
          Float_t eMeanTzero=0.;
          
          for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
-           sqTrackError[itz]=
-             (timeresolutioninns*
-              timeresolutioninns
-              +dtexp[itz]*dtexp[itz]*1E-6); //in ns2
+           sqTrackError[itz]=dtexp[itz]*dtexp[itz]*1E-6; //in ns2
            
            timezero[itz]=texp[itz]-timeofflight[itz];// in ns                    
            
            
            timezero[itz]=texp[itz]-timeofflight[itz];// in ns                    
            
@@ -452,7 +428,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
          
        }
        
          
        }
        
-       Double_t chi2cut[nmaxtracksinset];
+       Double_t chi2cut[nmaxtracksinsetMax];
        chi2cut[0] = 0;
        chi2cut[1] = 6.6; // corresponding to a C.L. of 0.01
        for (Int_t j=2; j<ntracksinset; j++) {
        chi2cut[0] = 0;
        chi2cut[1] = 6.6; // corresponding to a C.L. of 0.01
        for (Int_t j=2; j<ntracksinset; j++) {
@@ -465,7 +441,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
        
        Bool_t kRedoT0 = kFALSE;
         ntracksinsetmyCut = ntracksinsetmy;
        
        Bool_t kRedoT0 = kFALSE;
         ntracksinsetmyCut = ntracksinsetmy;
-       Bool_t usetrack[nmaxtracksinset];
+       Bool_t usetrack[nmaxtracksinsetMax];
        for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
          usetrack[icsq] = kTRUE;
          if((bestchisquare[icsq] > chisquarebest*0.5 && ntracksinsetmy > 2) || (bestchisquare[icsq] > chi2singlecut)){
        for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
          usetrack[icsq] = kTRUE;
          if((bestchisquare[icsq] > chisquarebest*0.5 && ntracksinsetmy > 2) || (bestchisquare[icsq] > chi2singlecut)){
@@ -493,10 +469,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
            
            for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
              if(! usetrack[itz]) continue;
            
            for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
              if(! usetrack[itz]) continue;
-             sqTrackError[itz]=
-               (timeresolutioninns*
-                timeresolutioninns
-                +dtexp[itz]*dtexp[itz]*1E-6); //in ns2
+             sqTrackError[itz]=dtexp[itz]*dtexp[itz]*1E-6; //in ns2
              
              timezero[itz]=texp[itz]-timeofflight[itz];// in ns                          
              
              
              timezero[itz]=texp[itz]-timeofflight[itz];// in ns                          
              
@@ -587,6 +560,8 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
            sumWt0bestallSel += 1./eT0best/eT0best;
            ngoodsetsSel++;
            ngoodtrktrulyused+=ntracksinsetmyCut;           
            sumWt0bestallSel += 1./eT0best/eT0best;
            ngoodsetsSel++;
            ngoodtrktrulyused+=ntracksinsetmyCut;           
+
+           //      printf("t0 of a set = %f +/- %f\n",t0best,eT0best);
          }
          else{
            //      printf("conflevel = %f -- ngoodsetsSel = %i -- ntrackset = %i\n",confLevel,ngoodsetsSel,ntracksinsetmy);
          }
          else{
            //      printf("conflevel = %f -- ngoodsetsSel = %i -- ntrackset = %i\n",confLevel,ngoodsetsSel,ntracksinsetmy);
@@ -615,12 +590,9 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
       
       t0def=t0bestallSel;
       deltat0def=eT0bestallSel;
       
       t0def=t0bestallSel;
       deltat0def=eT0bestallSel;
-      if ((TMath::Abs(t0bestallSel) < 0.001)&&(TMath::Abs(eT0bestallSel)<0.001)){
-       t0def=-999; deltat0def=0.600;
-      }
       
       fT0SigmaT0def[0]=t0def;
       
       fT0SigmaT0def[0]=t0def;
-      fT0SigmaT0def[1]=TMath::Sqrt(deltat0def*deltat0def*ngoodtrktrulyused/(ngoodtrktrulyused-1));
+      fT0SigmaT0def[1]=TMath::Sqrt(deltat0def*deltat0def);//*ngoodtrktrulyused/(ngoodtrktrulyused-1));
       fT0SigmaT0def[2]=ngoodtrkt0;
       fT0SigmaT0def[3]=ngoodtrktrulyused;
     }
       fT0SigmaT0def[2]=ngoodtrkt0;
       fT0SigmaT0def[3]=ngoodtrktrulyused;
     }
@@ -630,23 +602,35 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option)
   //     cout << "AliTOFT0v1:" << endl ;
   //}
   
   //     cout << "AliTOFT0v1:" << endl ;
   //}
   
-  if(fT0SigmaT0def[1] < 0.01) fT0SigmaT0def[1] = 0.6;
+  if(fT0SigmaT0def[1] < 0.00001) fT0SigmaT0def[1] = 0.6;
+
+  bench->Stop("t0computation");
+
+  fT0SigmaT0def[4]=bench->GetRealTime("t0computation");
+  fT0SigmaT0def[5]=bench->GetCpuTime("t0computation");
+
+//   bench->Print("t0computation");
+//   printf("%f %f\n",fT0SigmaT0def[4],fT0SigmaT0def[5]);
+
+  bench->Reset();
 
   return fT0SigmaT0def;
   }
 //__________________________________________________________________
 Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut) 
 { 
 
   return fT0SigmaT0def;
   }
 //__________________________________________________________________
 Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut) 
 { 
+  TBenchmark *bench=new TBenchmark();
+  bench->Start("t0computation");
+
   // Caluclate the Event Time using the ESD TOF time
 
   fT0SigmaT0def[0]=0.;
   fT0SigmaT0def[1]=0.600;
   fT0SigmaT0def[2]=0.;
   fT0SigmaT0def[3]=0.;
   // Caluclate the Event Time using the ESD TOF time
 
   fT0SigmaT0def[0]=0.;
   fT0SigmaT0def[1]=0.600;
   fT0SigmaT0def[2]=0.;
   fT0SigmaT0def[3]=0.;
-
- Float_t timeresolutioninns=fTimeResolution*(1.e+9); // convert in [ns]
   
   
-  const Int_t nmaxtracksinset=10;
+  const Int_t nmaxtracksinsetMax=10;
+  Int_t nmaxtracksinset=10;
 //   if(strstr(option,"all")){
 //     cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl;
 //     cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl;
 //   if(strstr(option,"all")){
 //     cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl;
 //     cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl;
@@ -690,7 +674,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
     
     time*=1.E-3; // tof given in nanoseconds      
     if (!(mom<=fUpperMomBound && mom>=fLowerMomBound))continue;
     
     time*=1.E-3; // tof given in nanoseconds      
     if (!(mom<=fUpperMomBound && mom>=fLowerMomBound))continue;
-   
+
     if (!AcceptTrack(t)) continue;
 
     if(t->GetIntegratedLength() < 350)continue; //skip decays
     if (!AcceptTrack(t)) continue;
 
     if(t->GetIntegratedLength() < 350)continue; //skip decays
@@ -700,10 +684,12 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
     ngoodtrk++;
   }
   
     ngoodtrk++;
   }
   
+  if(ngoodtrk>22) nmaxtracksinset = 6;
+
   
   
-//    cout << " N. of ESD tracks                    : " << ntrk << endl;
-//    cout << " N. of preselected tracks            : " << ngoodtrk << endl;
-//    cout << " Minimum tof time in set (in ns)                 : " << mintime << endl;
+//     cout << " N. of ESD tracks                    : " << ntrk << endl;
+//     cout << " N. of preselected tracks            : " << ngoodtrk << endl;
+//     cout << " Minimum tof time in set (in ns)                 : " << mintime << endl;
   
   AliESDtrack **gtracks=new AliESDtrack*[ngoodtrk];
   
   
   AliESDtrack **gtracks=new AliESDtrack*[ngoodtrk];
   
@@ -717,11 +703,14 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
     }
   }
   
     }
   }
   
+//     cout << " N. of preselected tracks t0         : " << ngoodtrkt0 << endl;
 
   Int_t nseteq = (ngoodtrkt0-1)/nmaxtracksinset + 1;
   Int_t nmaxtracksinsetCurrent=ngoodtrkt0/nseteq;
   if(nmaxtracksinsetCurrent*nseteq < ngoodtrkt0) nmaxtracksinsetCurrent++;
 
 
   Int_t nseteq = (ngoodtrkt0-1)/nmaxtracksinset + 1;
   Int_t nmaxtracksinsetCurrent=ngoodtrkt0/nseteq;
   if(nmaxtracksinsetCurrent*nseteq < ngoodtrkt0) nmaxtracksinsetCurrent++;
 
+//   cout << " N. of sets                        : " << nseteq << endl;
+
   if(ngoodtrkt0<2){
 //     cout << "less than 2 tracks, skip event " << endl;
     t0def=-999;
   if(ngoodtrkt0<2){
 //     cout << "less than 2 tracks, skip event " << endl;
     t0def=-999;
@@ -743,7 +732,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
     
     if(nset>=1){
       for (Int_t i=0; i< nset; i++) {   
     
     if(nset>=1){
       for (Int_t i=0; i< nset; i++) {   
-       
+       //      printf("Set %i of %i\n",i+1,nset);
        Float_t t0best=999.;
        Float_t eT0best=999.;
        Float_t chisquarebest=99999.;
        Float_t t0best=999.;
        Float_t eT0best=999.;
        Float_t chisquarebest=99999.;
@@ -762,27 +751,27 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
        
        // Analyse it
        
        
        // Analyse it
        
-       Int_t   assparticle[nmaxtracksinset];
-       Float_t exptof[nmaxtracksinset][3];
-       Float_t timeofflight[nmaxtracksinset];
-       Float_t momentum[nmaxtracksinset];
-       Float_t timezero[nmaxtracksinset];
-       Float_t weightedtimezero[nmaxtracksinset];
-       Float_t beta[nmaxtracksinset];
-       Float_t texp[nmaxtracksinset];
-       Float_t dtexp[nmaxtracksinset];
-       Float_t sqMomError[nmaxtracksinset];
-       Float_t sqTrackError[nmaxtracksinset];
+       Int_t   assparticle[nmaxtracksinsetMax];
+       Float_t exptof[nmaxtracksinsetMax][3];
+       Float_t timeofflight[nmaxtracksinsetMax];
+       Float_t momentum[nmaxtracksinsetMax];
+       Float_t timezero[nmaxtracksinsetMax];
+       Float_t weightedtimezero[nmaxtracksinsetMax];
+       Float_t beta[nmaxtracksinsetMax];
+       Float_t texp[nmaxtracksinsetMax];
+       Float_t dtexp[nmaxtracksinsetMax];
+       Float_t sqMomError[nmaxtracksinsetMax];
+       Float_t sqTrackError[nmaxtracksinsetMax];
        Float_t massarray[3]={0.13957,0.493677,0.9382723};
        Float_t massarray[3]={0.13957,0.493677,0.9382723};
-       Float_t tracktoflen[nmaxtracksinset];
-       Float_t besttimezero[nmaxtracksinset];
-       Float_t besttexp[nmaxtracksinset];
-       Float_t besttimeofflight[nmaxtracksinset];
-       Float_t bestmomentum[nmaxtracksinset];
-       Float_t bestchisquare[nmaxtracksinset];
-       Float_t bestweightedtimezero[nmaxtracksinset];
-       Float_t bestsqTrackError[nmaxtracksinset];
-       Int_t imass[nmaxtracksinset];
+       Float_t tracktoflen[nmaxtracksinsetMax];
+       Float_t besttimezero[nmaxtracksinsetMax];
+       Float_t besttexp[nmaxtracksinsetMax];
+       Float_t besttimeofflight[nmaxtracksinsetMax];
+       Float_t bestmomentum[nmaxtracksinsetMax];
+       Float_t bestchisquare[nmaxtracksinsetMax];
+       Float_t bestweightedtimezero[nmaxtracksinsetMax];
+       Float_t bestsqTrackError[nmaxtracksinsetMax];
+       Int_t imass[nmaxtracksinsetMax];
        
        for (Int_t j=0; j<ntracksinset; j++) {
          assparticle[j] = 3;
        
        for (Int_t j=0; j<ntracksinset; j++) {
          assparticle[j] = 3;
@@ -831,7 +820,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
          beta[itz]=momentum[itz]/sqrt(massarray[0]*massarray[0]
                                       +momentum[itz]*momentum[itz]);
          sqMomError[itz]= ((1.-beta[itz]*beta[itz])*0.01)*((1.-beta[itz]*beta[itz])*0.01)*(tracktoflen[itz]/(0.299792*beta[itz]))*(tracktoflen[itz]/(0.299792*beta[itz])); 
          beta[itz]=momentum[itz]/sqrt(massarray[0]*massarray[0]
                                       +momentum[itz]*momentum[itz]);
          sqMomError[itz]= ((1.-beta[itz]*beta[itz])*0.01)*((1.-beta[itz]*beta[itz])*0.01)*(tracktoflen[itz]/(0.299792*beta[itz]))*(tracktoflen[itz]/(0.299792*beta[itz])); 
-         sqTrackError[itz]=(timeresolutioninns*timeresolutioninns+sqMomError[itz]); //in ns
+         sqTrackError[itz]=sqMomError[itz]; //in ns
          timezero[itz]=exptof[itz][0]-timeofflight[itz];// in ns
          weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
          sumAllweightspi+=1./sqTrackError[itz];
          timezero[itz]=exptof[itz][0]-timeofflight[itz];// in ns
          weightedtimezero[itz]=timezero[itz]/sqTrackError[itz];
          sumAllweightspi+=1./sqTrackError[itz];
@@ -861,10 +850,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
          Float_t eMeanTzero=0.;
          
          for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
          Float_t eMeanTzero=0.;
          
          for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
-           sqTrackError[itz]=
-             (timeresolutioninns*
-              timeresolutioninns
-              +dtexp[itz]*dtexp[itz]*1E-6); //in ns2
+           sqTrackError[itz]=dtexp[itz]*dtexp[itz]*1E-6; //in ns2
            
            timezero[itz]=texp[itz]-timeofflight[itz];// in ns                    
            
            
            timezero[itz]=texp[itz]-timeofflight[itz];// in ns                    
            
@@ -882,7 +868,6 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
          Float_t chisquare=0.;         
          for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
            chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
          Float_t chisquare=0.;         
          for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
            chisquare+=(timezero[icsq]-meantzero)*(timezero[icsq]-meantzero)/sqTrackError[icsq];
-           
          } // end loop for (Int_t icsq=0; icsq<15;icsq++) 
          
          if(chisquare<=chisquarebest){
          } // end loop for (Int_t icsq=0; icsq<15;icsq++) 
          
          if(chisquare<=chisquarebest){
@@ -907,10 +892,9 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
            t0best=meantzero;
            eT0best=eMeanTzero;
          } // close if(dummychisquare<=chisquare)
            t0best=meantzero;
            eT0best=eMeanTzero;
          } // close if(dummychisquare<=chisquare)
-         
        }
        
        }
        
-       Double_t chi2cut[nmaxtracksinset];
+       Double_t chi2cut[nmaxtracksinsetMax];
        chi2cut[0] = 0;
        chi2cut[1] = 6.6; // corresponding to a C.L. of 0.01
        for (Int_t j=2; j<ntracksinset; j++) {
        chi2cut[0] = 0;
        chi2cut[1] = 6.6; // corresponding to a C.L. of 0.01
        for (Int_t j=2; j<ntracksinset; j++) {
@@ -919,11 +903,11 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
        
        Double_t chi2singlecut = chi2cut[ntracksinsetmy-1]/ntracksinsetmy + TMath::Abs(chisquarebest-chi2cut[ntracksinsetmy-1])/ntracksinsetmy;
        
        
        Double_t chi2singlecut = chi2cut[ntracksinsetmy-1]/ntracksinsetmy + TMath::Abs(chisquarebest-chi2cut[ntracksinsetmy-1])/ntracksinsetmy;
        
-//     printf("tracks removed with a chi2 > %f (chi2total = %f w.r.t. the limit of %f)\n",chi2singlecut,chisquarebest,chi2cut[ntracksinsetmy-1]);
+       //      printf("tracks removed with a chi2 > %f (chi2total = %f w.r.t. the limit of %f)\n",chi2singlecut,chisquarebest,chi2cut[ntracksinsetmy-1]);
        
        Bool_t kRedoT0 = kFALSE;
         ntracksinsetmyCut = ntracksinsetmy;
        
        Bool_t kRedoT0 = kFALSE;
         ntracksinsetmyCut = ntracksinsetmy;
-       Bool_t usetrack[nmaxtracksinset];
+       Bool_t usetrack[nmaxtracksinsetMax];
        for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
          usetrack[icsq] = kTRUE;
          if((bestchisquare[icsq] > chisquarebest*0.5 && ntracksinsetmy > 2) || (bestchisquare[icsq] > chi2singlecut)){
        for (Int_t icsq=0; icsq<ntracksinsetmy;icsq++) {
          usetrack[icsq] = kTRUE;
          if((bestchisquare[icsq] > chisquarebest*0.5 && ntracksinsetmy > 2) || (bestchisquare[icsq] > chi2singlecut)){
@@ -934,7 +918,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
        } // end loop for (Int_t icsq=0; icsq<15;icsq++) 
        
        //      printf("ntrackinsetmy = %i - %i\n",ntracksinsetmy,ntracksinsetmyCut);
        } // end loop for (Int_t icsq=0; icsq<15;icsq++) 
        
        //      printf("ntrackinsetmy = %i - %i\n",ntracksinsetmy,ntracksinsetmyCut);
-       
+
        // Loop on mass hypotheses Redo
        if(kRedoT0 && ntracksinsetmyCut > 1){
          //      printf("Redo T0\n");
        // Loop on mass hypotheses Redo
        if(kRedoT0 && ntracksinsetmyCut > 1){
          //      printf("Redo T0\n");
@@ -951,10 +935,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
            
            for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
              if(! usetrack[itz]) continue;
            
            for (Int_t itz=0; itz<ntracksinsetmy;itz++) {
              if(! usetrack[itz]) continue;
-             sqTrackError[itz]=
-               (timeresolutioninns*
-                timeresolutioninns
-                +dtexp[itz]*dtexp[itz]*1E-6); //in ns2
+             sqTrackError[itz]=dtexp[itz]*dtexp[itz]*1E-6; //in ns2
              
              timezero[itz]=texp[itz]-timeofflight[itz];// in ns                          
              
              
              timezero[itz]=texp[itz]-timeofflight[itz];// in ns                          
              
@@ -1007,6 +988,7 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
        Float_t confLevel=999;
        
        // Sets with decent chisquares
        Float_t confLevel=999;
        
        // Sets with decent chisquares
+       //      printf("Chi2best of the set = %f \n",chisquarebest);
        
        if(chisquarebest<999.){
          Double_t dblechisquare=(Double_t)chisquarebest;
        
        if(chisquarebest<999.){
          Double_t dblechisquare=(Double_t)chisquarebest;
@@ -1034,6 +1016,8 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
 //              << " is used = " << usetrack[icsq] << endl;
          }
          
 //              << " is used = " << usetrack[icsq] << endl;
          }
          
+         //      printf("%i) CL(Chi2) = %f < 0.01\n",ngoodsetsSel,confLevel);
+
          // Pick up only those with C.L. >1%
          //      if(confLevel>0.01 && ngoodsetsSel<200){
          if(confLevel>0.01 && ngoodsetsSel<200){
          // Pick up only those with C.L. >1%
          //      if(confLevel>0.01 && ngoodsetsSel<200){
          if(confLevel>0.01 && ngoodsetsSel<200){
@@ -1044,7 +1028,8 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
            t0bestallSel += t0best/eT0best/eT0best;
            sumWt0bestallSel += 1./eT0best/eT0best;
            ngoodsetsSel++;
            t0bestallSel += t0best/eT0best/eT0best;
            sumWt0bestallSel += 1./eT0best/eT0best;
            ngoodsetsSel++;
-           ngoodtrktrulyused+=ntracksinsetmyCut;           
+           ngoodtrktrulyused+=ntracksinsetmyCut;
+           //      printf("T0 set = %f +/- %f\n",t0best,eT0best);
          }
          else{
            //      printf("conflevel = %f -- ngoodsetsSel = %i -- ntrackset = %i\n",confLevel,ngoodsetsSel,ntracksinsetmy);
          }
          else{
            //      printf("conflevel = %f -- ngoodsetsSel = %i -- ntrackset = %i\n",confLevel,ngoodsetsSel,ntracksinsetmy);
@@ -1062,10 +1047,12 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
          eMeanTzeroPi=sqrt(1./sumAllweightspi); // it is given in [ns]
        }      
        
          eMeanTzeroPi=sqrt(1./sumAllweightspi); // it is given in [ns]
        }      
        
+       //      printf("t0bestallSel = %f -- eT0bestallSel = %f\n",t0bestallSel,sumWt0bestallSel);
+
        if(sumWt0bestallSel>0){
          t0bestallSel  = t0bestallSel/sumWt0bestallSel;
          eT0bestallSel = sqrt(1./sumWt0bestallSel);
        if(sumWt0bestallSel>0){
          t0bestallSel  = t0bestallSel/sumWt0bestallSel;
          eT0bestallSel = sqrt(1./sumWt0bestallSel);
-         
+         //      printf("Final) t0bestallSel = %f -- eT0bestallSel = %f\n",t0bestallSel,eT0bestallSel);          
        }// end of if(sumWt0bestallSel>0){
        
 //     cout << "T0 all " << t0bestallSel << " +/- " << eT0bestallSel << "Number of tracks used: "<<ngoodtrktrulyused<<endl;
        }// end of if(sumWt0bestallSel>0){
        
 //     cout << "T0 all " << t0bestallSel << " +/- " << eT0bestallSel << "Number of tracks used: "<<ngoodtrktrulyused<<endl;
@@ -1073,12 +1060,9 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
       
       t0def=t0bestallSel;
       deltat0def=eT0bestallSel;
       
       t0def=t0bestallSel;
       deltat0def=eT0bestallSel;
-      if ((TMath::Abs(t0bestallSel) < 0.001)&&(TMath::Abs(eT0bestallSel)<0.001)){
-       t0def=-999; deltat0def=0.600;
-      }
       
       fT0SigmaT0def[0]=t0def;
       
       fT0SigmaT0def[0]=t0def;
-      fT0SigmaT0def[1]=TMath::Sqrt(deltat0def*deltat0def*ngoodtrktrulyused/(ngoodtrktrulyused-1));
+      fT0SigmaT0def[1]=TMath::Sqrt(deltat0def*deltat0def);//*ngoodtrktrulyused/(ngoodtrktrulyused-1));
       fT0SigmaT0def[2]=ngoodtrkt0;
       fT0SigmaT0def[3]=ngoodtrktrulyused;
     }
       fT0SigmaT0def[2]=ngoodtrkt0;
       fT0SigmaT0def[3]=ngoodtrktrulyused;
     }
@@ -1088,7 +1072,17 @@ Double_t * AliTOFT0v1::DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut
   //     cout << "AliTOFT0v1:" << endl ;
   //}
 
   //     cout << "AliTOFT0v1:" << endl ;
   //}
 
-  if(fT0SigmaT0def[1] < 0.01) fT0SigmaT0def[1] = 0.6;
+  if(fT0SigmaT0def[1] < 0.00001) fT0SigmaT0def[1] = 0.6;
+
+  bench->Stop("t0computation");
+
+  fT0SigmaT0def[4]=bench->GetRealTime("t0computation");
+  fT0SigmaT0def[5]=bench->GetCpuTime("t0computation");
+
+//   bench->Print("t0computation");
+//   printf("(%4.1f < p < %4.1f GeV/c) T0-TOF =%9.1f +/- %5.1f ps (n_track = %i)\n\n",pMinCut,pMaxCut,-fT0SigmaT0def[0]*1000,fT0SigmaT0def[1]*1000,Int_t(fT0SigmaT0def[3]));
+
+  bench->Reset();
 
   return fT0SigmaT0def;
   }
 
   return fT0SigmaT0def;
   }
@@ -1102,11 +1096,8 @@ Float_t AliTOFT0v1::GetMomError(Int_t index, Float_t mom, Float_t texp) const
   };
 
   Double_t mass=kMasses[index+2];
   };
 
   Double_t mass=kMasses[index+2];
-  Double_t dpp=0.02;      //mean relative pt resolution;
-  //  if(mom > 1) dpp = 0.02*mom;
-  Double_t sigma=dpp*texp*1E3/(1.+ mom*mom/(mass*mass));
 
 
-  sigma =TMath::Sqrt(sigma*sigma);
+  Float_t sigma = fPIDesd->GetTOFResponse().GetExpectedSigma(mom,texp,mass);
 
   return sigma;
 }
 
   return sigma;
 }
index b0a05bfd1bdc8af233259800bce5ff90128b0d24..e823a0902066a54a01120277e60ba8b279afeb28 100644 (file)
 
 class AliESDtrack;
 class AliESDEvent;
 
 class AliESDtrack;
 class AliESDEvent;
+class AliESDpid;
 
 class AliTOFT0v1: public TObject {
 public:
   
 
 class AliTOFT0v1: public TObject {
 public:
   
-  AliTOFT0v1(; // default constructor
-  AliTOFT0v1(AliESDEvent *event); // overloaded constructor
+  AliTOFT0v1(AliESDpid *extPID=NULL); // default constructor
+  AliTOFT0v1(AliESDEvent *event,AliESDpid *extPID=NULL); // overloaded constructor
   virtual ~AliTOFT0v1() ; // dtor
  
   Double_t* DefineT0(Option_t *option); 
   Double_t* DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut=1.5); 
   virtual ~AliTOFT0v1() ; // dtor
  
   Double_t* DefineT0(Option_t *option); 
   Double_t* DefineT0(Option_t *option,Float_t pMinCut,Float_t pMaxCut=1.5); 
-  
-  void      SetTimeResolution(Double_t timeresolution);// timeresolution in [s] e.g. for 120 ps -> 1.2e-10
-  
-  Double_t GetTimeResolution() const {return fTimeResolution;}
-  
+    
   void          SetMomBounds(Float_t pLow, Float_t pUp) { fLowerMomBound=pLow; fUpperMomBound=pUp;} // momenta are expressed in [GeV/c]
   void          SetTimeCorr(Float_t timecorr) {fTimeCorr=timecorr;} //in ns!!!
   Float_t       GetMomError(Int_t index, Float_t mom, Float_t texp) const;
   void          SetMomBounds(Float_t pLow, Float_t pUp) { fLowerMomBound=pLow; fUpperMomBound=pUp;} // momenta are expressed in [GeV/c]
   void          SetTimeCorr(Float_t timecorr) {fTimeCorr=timecorr;} //in ns!!!
   Float_t       GetMomError(Int_t index, Float_t mom, Float_t texp) const;
-  Double_t GetResult(Int_t i){if(i < 4) return fT0SigmaT0def[i]; else return -1.;};
+  Double_t GetResult(Int_t i){if(i < 6) return fT0SigmaT0def[i]; else return -1.;};
 /*   void  Print(Option_t* option) const ; */
 
 /*   void  Print(Option_t* option) const ; */
 
+  void   SetTimeResolution(Float_t /* timeres */){}; // obsolete
+
   void Init(AliESDEvent *event); // init
 
  private:
   void Init(AliESDEvent *event); // init
 
  private:
@@ -48,12 +47,13 @@ public:
 
   Float_t fLowerMomBound;   // momentum lower bound for selected primary tracks   
   Float_t fUpperMomBound;   // momentum upper bound for selected primary tracks 
 
   Float_t fLowerMomBound;   // momentum lower bound for selected primary tracks   
   Float_t fUpperMomBound;   // momentum upper bound for selected primary tracks 
-  Double_t fTimeResolution;  // global time resolution used to calculate T0
   Float_t fTimeCorr;  // global time resolution used to calculate T0
   AliESDEvent* fEvent;      //evento per il quale si vuole calcolare il T0
   Float_t fTimeCorr;  // global time resolution used to calculate T0
   AliESDEvent* fEvent;      //evento per il quale si vuole calcolare il T0
-  Double_t fT0SigmaT0def[4]; // array with the event information ([0]=event time -- [1] = sigma -- [2] = tracks on the TOF -- [3] = tracks used for the event time)
+  Double_t fT0SigmaT0def[6]; // array with the event information ([0]=event time -- [1] = sigma -- [2] = tracks on the TOF -- [3] = tracks used for the event time)
   
   
-  ClassDef(AliTOFT0v1,2);  // Calculate the time zero using TOF detector */
+  AliESDpid *fPIDesd; // class with the detector response
+
+  ClassDef(AliTOFT0v1,3);  // Calculate the time zero using TOF detector */
   
 };
 
   
 };