ROOT logo
#ifndef ALITOFTENDERSUPPLY_H
#define ALITOFTENDERSUPPLY_H

/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

////////////////////////////////////////////////////////////////////////
//                                                                    //
//  TOF tender, reapply pid on the fly                                //
//                                                                    //
////////////////////////////////////////////////////////////////////////

#include <AliTenderSupply.h>
#include <AliLog.h>
#include <AliESDpid.h>

class AliESDpid;
class AliTOFcalib;
class AliTOFT0maker;
class AliESDEevent;
class AliESDtrack;
class AliTOFTenderSupply: public AliTenderSupply {

public:
  AliTOFTenderSupply();
  AliTOFTenderSupply(const char *name, const AliTender *tender=NULL);

  virtual ~AliTOFTenderSupply(){;}

  virtual void              Init();
  virtual void              ProcessEvent();

  // TOF tender methods
  void SetIsMC(Bool_t flag=kFALSE){fIsMC=flag;}
  void SetCorrectExpTimes(Bool_t flag=kTRUE){fCorrectExpTimes=flag;}
  void SetT0DetectorAdjust(Bool_t flag=kFALSE){fT0DetectorAdjust=flag;}
  void SetDebugLevel(Int_t flag=0){fDebugLevel=flag;}
  void SetLHC10dPatch(Bool_t flag=kFALSE){ 
    if (flag == kTRUE) {
      AliInfo(" **** TOF Tender: special setting LHC10d patch is ON");
      AliInfo(" **** TOF Tender: this setting is valid only on LHC10d pass2");
    }
    fLHC10dPatch=flag;
    return;
  }
  void SetAutomaticSettings(Bool_t flag=kTRUE){fAutomaticSettings=flag;}
  void SetForceCorrectTRDBug(Bool_t flag=kTRUE){fForceCorrectTRDBug=flag;}
  void SetUserRecoPass(Int_t flag=0){fUserRecoPass=flag;}
  Int_t GetRecoPass(void){return fRecoPass;}
  void DetectRecoPass();

  /* theoretical expected time: related stuff for LHC10d patch */
  static Float_t GetBetaTh(Float_t m, Float_t p) {return TMath::Sqrt(1. / (1. + m * m / (p * p)));}; // get beta th
  static Float_t GetExpTimeTh(Float_t m, Float_t p, Float_t L) {return L / 2.99792457999999984e-02 / GetBetaTh(m, p);}; // get exp time th
  void RecomputeTExp(AliESDEvent *event) const;
  void RecomputeTExp(AliESDtrack *track) const;
  void FixTRDBug(AliESDEvent *event);
  void FixTRDBug(AliESDtrack *track);
  void InitGeom();
  void FindTRDFix(AliESDtrack *track,Double_t *corr);
  Double_t EstimateLengthInTRD1(AliESDtrack *track);
  Double_t EstimateLengthInTRD2(AliESDtrack *track);
  Double_t EstimateLengthOutTRD(AliESDtrack *track);
  void CorrectDeltaTimes(Double_t pT, Double_t length, Bool_t isTRDout, Double_t *corrections);
  Double_t CorrectExpectedProtonTime(Double_t pT,Double_t length, Bool_t isTRDout);
  Double_t CorrectExpectedKaonTime(Double_t pT,Double_t length, Bool_t isTRDout);
  Double_t CorrectExpectedPionTime(Double_t pT,Double_t length, Bool_t isTRDout);
  Int_t GetOCDBVersion(Int_t runNumber);
  void LoadTOFPIDParams(Int_t runNumber);

  /* to invent a T0 signal... */
  Double_t SampleT0Signal(Int_t side, Double_t zvertex, Double_t tracklets) const;
  void GetTrackletsForT0(AliESDEvent *event, Double_t *trkA, Double_t *trkC) const;

private:
  AliESDpid          *fESDpid;         //! ESD pid object

  
  Bool_t fTenderNoAction;    // flag for periods when tender action is not requested/not supported
  Bool_t fIsMC;              // flag for MC data: adds start Time
  Bool_t fCorrectExpTimes;   // flag to apply Expected Time correction 
  Bool_t fCorrectTRDBug;     // flag to fix wrong dE/dx inside TRD
  Bool_t fLHC10dPatch;       // flag to apply special patch for LHC10d (reconstructed with wrong geometry)
  Bool_t fT0DetectorAdjust;  // DATA: flag to apply offsets to T0 data (LHC10b, c, d, e)
                             // MC: add smearing to simulated data (LHC10b,c,d,e)
  Int_t  fDebugLevel;        // debug purposes 0= no output, 1 Info, 2 lot of info....
  Bool_t fAutomaticSettings; // enable/disable automatic (per run) settings
  Int_t  fRecoPass;          // reconstruction pass: the tender applies different recipes depending on the pass
  Int_t  fUserRecoPass;      // when reco pass is selected by user
  Bool_t fForceCorrectTRDBug; // force TRD bug correction (for some bad MC production...)
  Bool_t fT0Simulate;        // ignore existing T0 data (if any) and simulate them


  // variables for TOF calibrations and timeZero setup
  AliTOFPIDParams *fTOFPIDParams;   //! TOF PID Params - period depending (OADB loaded)
  AliTOFcalib     *fTOFCalib;       // recalibrate TOF signal with OCDB
  AliTOFT0maker   *fTOFT0maker;     // computation of TOF-T0
  Float_t fT0shift[4];              // T0 detector correction from OCDB
  Float_t fT0IntercalibrationShift; // extra-shift to adjust TOF/TO intercalibration issue in some period

  // variables to parametrize MC
  static Float_t fgT0Aresolution;   // T0 resolution A-Side (MC)
  static Float_t fgT0Cresolution;   // T0 resolution C-Side (MC)

  // variables to steer TRD bug fix
  Bool_t fGeomSet;                 // steer loading GRP entry
  Bool_t fIsEnteringInTRD;
  Bool_t fInTRD;
  Bool_t fIsComingOutTRD;
  Bool_t fOutTRD;
  Float_t fRhoTRDin;                // cm
  Float_t fRhoTRDout;               // cm
  Float_t fStep;                    // cm
  Double_t fMagField;               // magnetic field value [kGauss]
  ULong64_t fCDBkey;

  AliTOFTenderSupply(const AliTOFTenderSupply&c);
  AliTOFTenderSupply& operator= (const AliTOFTenderSupply&c);

  ClassDef(AliTOFTenderSupply, 12);
};


#endif 
 AliTOFTenderSupply.h:1
 AliTOFTenderSupply.h:2
 AliTOFTenderSupply.h:3
 AliTOFTenderSupply.h:4
 AliTOFTenderSupply.h:5
 AliTOFTenderSupply.h:6
 AliTOFTenderSupply.h:7
 AliTOFTenderSupply.h:8
 AliTOFTenderSupply.h:9
 AliTOFTenderSupply.h:10
 AliTOFTenderSupply.h:11
 AliTOFTenderSupply.h:12
 AliTOFTenderSupply.h:13
 AliTOFTenderSupply.h:14
 AliTOFTenderSupply.h:15
 AliTOFTenderSupply.h:16
 AliTOFTenderSupply.h:17
 AliTOFTenderSupply.h:18
 AliTOFTenderSupply.h:19
 AliTOFTenderSupply.h:20
 AliTOFTenderSupply.h:21
 AliTOFTenderSupply.h:22
 AliTOFTenderSupply.h:23
 AliTOFTenderSupply.h:24
 AliTOFTenderSupply.h:25
 AliTOFTenderSupply.h:26
 AliTOFTenderSupply.h:27
 AliTOFTenderSupply.h:28
 AliTOFTenderSupply.h:29
 AliTOFTenderSupply.h:30
 AliTOFTenderSupply.h:31
 AliTOFTenderSupply.h:32
 AliTOFTenderSupply.h:33
 AliTOFTenderSupply.h:34
 AliTOFTenderSupply.h:35
 AliTOFTenderSupply.h:36
 AliTOFTenderSupply.h:37
 AliTOFTenderSupply.h:38
 AliTOFTenderSupply.h:39
 AliTOFTenderSupply.h:40
 AliTOFTenderSupply.h:41
 AliTOFTenderSupply.h:42
 AliTOFTenderSupply.h:43
 AliTOFTenderSupply.h:44
 AliTOFTenderSupply.h:45
 AliTOFTenderSupply.h:46
 AliTOFTenderSupply.h:47
 AliTOFTenderSupply.h:48
 AliTOFTenderSupply.h:49
 AliTOFTenderSupply.h:50
 AliTOFTenderSupply.h:51
 AliTOFTenderSupply.h:52
 AliTOFTenderSupply.h:53
 AliTOFTenderSupply.h:54
 AliTOFTenderSupply.h:55
 AliTOFTenderSupply.h:56
 AliTOFTenderSupply.h:57
 AliTOFTenderSupply.h:58
 AliTOFTenderSupply.h:59
 AliTOFTenderSupply.h:60
 AliTOFTenderSupply.h:61
 AliTOFTenderSupply.h:62
 AliTOFTenderSupply.h:63
 AliTOFTenderSupply.h:64
 AliTOFTenderSupply.h:65
 AliTOFTenderSupply.h:66
 AliTOFTenderSupply.h:67
 AliTOFTenderSupply.h:68
 AliTOFTenderSupply.h:69
 AliTOFTenderSupply.h:70
 AliTOFTenderSupply.h:71
 AliTOFTenderSupply.h:72
 AliTOFTenderSupply.h:73
 AliTOFTenderSupply.h:74
 AliTOFTenderSupply.h:75
 AliTOFTenderSupply.h:76
 AliTOFTenderSupply.h:77
 AliTOFTenderSupply.h:78
 AliTOFTenderSupply.h:79
 AliTOFTenderSupply.h:80
 AliTOFTenderSupply.h:81
 AliTOFTenderSupply.h:82
 AliTOFTenderSupply.h:83
 AliTOFTenderSupply.h:84
 AliTOFTenderSupply.h:85
 AliTOFTenderSupply.h:86
 AliTOFTenderSupply.h:87
 AliTOFTenderSupply.h:88
 AliTOFTenderSupply.h:89
 AliTOFTenderSupply.h:90
 AliTOFTenderSupply.h:91
 AliTOFTenderSupply.h:92
 AliTOFTenderSupply.h:93
 AliTOFTenderSupply.h:94
 AliTOFTenderSupply.h:95
 AliTOFTenderSupply.h:96
 AliTOFTenderSupply.h:97
 AliTOFTenderSupply.h:98
 AliTOFTenderSupply.h:99
 AliTOFTenderSupply.h:100
 AliTOFTenderSupply.h:101
 AliTOFTenderSupply.h:102
 AliTOFTenderSupply.h:103
 AliTOFTenderSupply.h:104
 AliTOFTenderSupply.h:105
 AliTOFTenderSupply.h:106
 AliTOFTenderSupply.h:107
 AliTOFTenderSupply.h:108
 AliTOFTenderSupply.h:109
 AliTOFTenderSupply.h:110
 AliTOFTenderSupply.h:111
 AliTOFTenderSupply.h:112
 AliTOFTenderSupply.h:113
 AliTOFTenderSupply.h:114
 AliTOFTenderSupply.h:115
 AliTOFTenderSupply.h:116
 AliTOFTenderSupply.h:117
 AliTOFTenderSupply.h:118
 AliTOFTenderSupply.h:119
 AliTOFTenderSupply.h:120
 AliTOFTenderSupply.h:121
 AliTOFTenderSupply.h:122
 AliTOFTenderSupply.h:123
 AliTOFTenderSupply.h:124