ROOT logo
#include "KImplant3D.h"
#include "KImplant2D.h"
#include "TMath.h"

ClassImp(KImplant3D)
//////////////////////////////////////////////////////////////////////////
//                                                                      //
// KImplant3D                                                             //
// A mesh generator for the non-equividistant bins                      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////


Double_t KImplant3D::ImplEdge(Double_t *x,Double_t *par)
{
  // par[0]= width in X 
  // par[1]= width in Y
  // par[2]= width in Z
  // par[3]= curvature in X;
  // par[4]= curvature in XZ;
  // par[5]= curvature in YZ;
  Double_t par2D[3];
  Double_t y;
  if(x[1]>par[2]) return -1;
  par2D[0]=par[2];  par2D[1]=par[0];  par2D[2]=par[4];
  Double_t ap=KImplant2D::ImplEdge(x[1],par2D);
  par2D[0]=par[2];  par2D[1]=par[1];  par2D[2]=par[5];
  Double_t bp=KImplant2D::ImplEdge(x[1],par2D);
  //  Double_t ap=par[0]*TMath::Power(1-TMath::Power(x[1]/par[2],par[4]), 1/par[4] );  
  //  Double_t bp=par[1]*TMath::Power(1-TMath::Power(x[1]/par[2],par[5]), 1/par[5] );     
  //  printf("ap=%f, bp=%f \n",ap,bp);
  
  
  if(x[0]>ap) return -2;
  
  if(ap!=0)
    {
      par2D[0]=ap;  par2D[1]=bp;  par2D[2]=par[3];
      y=KImplant2D::ImplEdge(x[0],par2D);
      //      y=bp*TMath::Power(1-TMath::Power(x[0]/ap,par[3]), 1/par[3] );  
    }
     else
       y=0;

  return y;
}

Double_t KImplant3D::Distance(Double_t *R,Double_t *par, Double_t *RR)
{
  // par[0]= width in X 
  // par[1]= width in Y
  // par[2]= width in Z
  // par[3]= curvature in XY;
  // par[4]= curvature in XZ;
  // par[5]= curvature in YZ;
  
  Double_t par2D[3];
  Double_t SS[3];  
  Double_t XX[3],ap,bp,dist,mindist=1e6;
  Int_t k;
  Double_t z=R[2]>par[2]?par[2]/2:0;
  while(z<=par[2])
    {
       par2D[0]=par[2];  par2D[1]=par[0];  par2D[2]=par[4];
       ap=KImplant2D::ImplEdge(z,par2D);
       par2D[0]=par[2];  par2D[1]=par[1];  par2D[2]=par[5];
       bp=KImplant2D::ImplEdge(z,par2D); 
 
       par2D[0]=ap;  par2D[1]=bp;  par2D[2]=par[3];
       KImplant2D::Distance(R,par2D,XX);      
       XX[2]=z;

       dist=0;
       for(k=0;k<3;k++) dist+=TMath::Power(R[k]-XX[k],2);
       dist=TMath::Sqrt(dist);

       if(dist<mindist) 
	 {
	     mindist=dist; 
	     for(k=0;k<3;k++) SS[k]=XX[k];
	 }
       else break;

        if(z<0.9*par[2]) z+=0.1; else 
	 z+=0.02;
    }

  //if((Float_t)R[0]<=(Float_t)SS[0] && (Float_t)R[2]<=(Float_t)SS[2] && (Float_t)R[1]<=(Float_t)SS[1]) mindist=-mindist;
    XX[0]=R[0];
    XX[1]=R[2];
    XX[2]=KImplant3D::ImplEdge(XX,par);
    if(XX[2]>0 && XX[2]>=R[1]) mindist=-mindist;
  
  if(RR!=NULL) for(k=0;k<3;k++) RR[k]=SS[k];
  return mindist;
}


Double_t KImplant3D::Conc(Double_t *x, Double_t Thresh)
{
  // x[0]  = coordinate x
  // x[1]  = coordinate y
  // x[2]  = coordinate z

  Double_t dist=Distance(x,Dim);
  if(dist<Thresh) return 0; else
  return fConc->Eval(dist);
}

KImplant3D::KImplant3D(Double_t *x, Double_t Sigma, Double_t Nimpl)
{
  // x[0]  = coordinate x
  // x[1]  = coordinate y 

  for(Int_t i=0;i<6;i++) Dim[i]=x[i];
  fConc=new TF1("fConc","TMath::Erfc((x-[0])/[1])*[2]+[3]",-20,20);
  fConc->SetParameter(3,0);
  fConc->SetParameter(2,Nimpl);
  fConc->SetParameter(1,Sigma);
  fConc->SetParameter(0,0);

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