//
//
// Logs:
//
//  $Log: LIV.h,v $
//  Revision 1.10  2003/12/15 16:17:26  cvs
//  more verbosity
//
//  Revision 1.9  2003/11/03 13:54:40  cvs
//  TLServer is now threaded, LData and LDataHeader have now right Draw and Paint methods, LIV is controlled and comments were added.
//
//  Revision 1.8  2003/08/30 11:28:52  cvs
//  simplified and checked LIV calculations
//
//  Revision 1.7  2003/08/28 14:41:18  cvs
//  corrected the bug in LData::Add(float,float,float,...). Description of bug: position index, that was obtained by simulation, was not shifted by -1 like was shifted the range of position in LDataHeader::SetDefaults.
//
//  Revision 1.6  2003/07/25 11:36:26  cvs
//  simulation of IV measurements is done with iv program
//  some minority fixes to LDisorder - corrected ft to match the recorded position
//
//  Revision 1.5  2003/07/15 15:20:00  cvs
//  started LIV development, including doc file.
//
//  Revision 1.2  2003/06/26 09:27:11  cvs
//  added log fields...
//
#ifndef _LIV___
#define _LIV___

#include "Config.h"

#include <TObject.h>
#include "Util.h"
#include "LData.h"
#include "LDataHeader.h"


class LIV: public TObject {
 public:
  Float_t fUo;  //bias at z=0  (V)
  Float_t fUn;  //bias at z=fN (V)
  Float_t fEo;  //interface field at z=0  (V/Ang.)
  Float_t fEn;  //interface field at z=fN (V/Ang.)
  Float_t fS;   //surface area (Ang.2)
  Float_t fI;   //bias current (Amperes - see AdjustBias() code)
  Float_t fe;   //epsilon (nounits)
  Float_t fe0;   //epsilon0 (e0/VAng).

  Float_t fvo;  //units of velocity (Ang./s)

 protected:
  LData* fdata;         //->data used to do calculation
  LDataHeader* fheader; //->new header created to use in new simulation

 private:
  Int_t fN;  //n of bins in z axis of fbias array
  Float_t fdz;  //width of bin in z axis
  Float_t fzmin;  //min value of z axis
  Float_t fzmax;  //max value of z axis
  Float_t* fz;  //position axis array 1..fN-1
  Float_t* fv;  //averaged velocity array 1..fN-1
  Float_t* fbias;  //bias array 0..fN
  Float_t* ffield;  //electric field array 0..fN
  Float_t* fcharge; //charge density array 1..fN-1
  
 public:
  //step 1  
  LIV(LData* data);
  //step 2
  void SetEo(const Float_t Eo){ffield[0]=Eo;}
  void SetEn(const Float_t En){ffield[fN]=En;}
  void SetUo(const Float_t Uo){fbias[0]=Uo;}
  void SetUn(const Float_t Un){fbias[fN]=Un;}
  void SetS(const Float_t S){fS=S;}
  void SetI(const Float_t I){fI=I;}
  void Sete(const Float_t e){fe=e;}
  //step 3
  Float_t AdjustBias();
  //step 4
  Float_t Getvo()const{return fvo;}
  Float_t Getto()const{return 1./fvo;}
  LDataHeader* GetHeader() const {return fheader;}
  TH1F* GetTOF();   
  //step 5
  virtual ~LIV();

 private:
  Float_t Chi2(const Float_t* a,const Float_t* b,const Int_t n)const;

  ClassDef(LIV,0)  //IV characteristics simulation 
};

#endif //_LIV___




