#ifndef _KDetector
#define _KDetector
// F(x_{#frac{1}{2}}) = #prod(x < x_{#frac{1}{2}}) = #frac{1}{2} //
// END_LATEX
#include "TMath.h"
#include "fizika.h"
#include "nrutil.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
#include "TArray.h"
#include "TArrayI.h"
#include "TArrayF.h"
#include "TArrayD.h"
#include "TString.h"
#include <string.h>
#include "TClonesArray.h"
#include "TObjArray.h"
#include "TRandom.h"
#include "TMath.h"
#include "TLine.h"
#include "TF3.h"
#include "KStruct.h"
#include "TH3S.h"
#include "KGeometry.h"
#include "KMaterial.h"
#include "KField.h"
#include "TVector3.h"
class KDetector : public KGeometry, public KMaterial {
private:
Double_t Deps;
TRandom *ran;
Double_t CalErr;
Int_t MaxIter;
Short_t Debug;
public:
Float_t Voltage;
Float_t Voltage2;
TArrayF Voltages;
TF3 *NeffF;
TH3F *NeffH;
KField *Ramo;
KField *Real;
Float_t B[3];
Float_t taue;
Float_t tauh;
Int_t BreakDown;
Float_t MTresh;
Float_t BDTresh;
Float_t enp[3];
Float_t exp[3];
Int_t diff;
Int_t average;
Float_t SStep;
TH1F *pos;
TH1F *neg;
TH1F *sum;
KDetector();
~KDetector();
void ResetRnd(Int_t seed) {delete ran; ran=new TRandom(seed);};
void SetDriftHisto(Float_t x,Int_t=200);
void SetCalculationParameters(Double_t x,Int_t y){CalErr=x; MaxIter=y;}
void Declaration(Int_t);
Double_t kappa(int ,int , int , int);
Double_t V(int ,int);
void CalField(Int_t);
inline void CalPhyField(){CalField(0);}
inline void CalRamoField(){CalField(1);}
void SetVoltage(Float_t x,Int_t calnow=1) {Voltage=x; if(calnow) CalPhyField(); };
void SetNeff(TF3 *neff,Int_t calnow=1) {NeffF=neff; if(calnow) CalPhyField(); };
void SetNeff(TH3F *neff,Int_t calnow=1) {NeffH=neff; if(calnow) CalPhyField(); };
void SetEntryPoint(Float_t x, Float_t y, Float_t z) {enp[0]=x; enp[1]=y; enp[2]=z;};
void SetExitPoint(Float_t x, Float_t y, Float_t z) {exp[0]=x; exp[1]=y; exp[2]=z;};
void MipIR(Int_t=20,Float_t=0);
void ShowMipIR(Int_t, Int_t=14, Int_t=1);
void GaussBeam(Int_t , Float_t , Float_t , Float_t , Float_t , Float_t);
void ShowGaussBeam(Int_t , Float_t , Float_t , Float_t , Int_t ,Int_t );
void Drift(Double_t, Double_t, Double_t, Float_t, KStruct *, Double_t = 0);
void CalM(KStruct *seg, Double_t *data, Int_t=-1);
TH2F *Draw(Char_t *, Float_t=1);
TH1F *Draw1D(Char_t *, Float_t ,Int_t ,Float_t );
void Save(Char_t *,Char_t *);
TFile *Read(Char_t *,Char_t *);
void SetDebug(Short_t x) {Debug=x;};
inline void SetPrecision(Double_t x){Deps=x;};
inline Double_t GetPrecision(){return Deps;};
ClassDef(KDetector,1)
};
#endif