#include "LEMuSRMagneticField.hh"
#include "G4ios.hh"
#include <iomanip.h>


LEMuSRMagneticField::LEMuSRMagneticField(const G4ThreeVector FieldVector)
  :G4UniformMagField(FieldVector )
{
  BField=FieldVector;

}


LEMuSRMagneticField::~LEMuSRMagneticField()
{;}


void LEMuSRMagneticField::GetFieldValue (const G4double pos[4],
                                            G4double *field ) const 
{



  field[0]= 0.0;
  field[1]= 0.0;
  field[2]= 0.0;
  
  G4double  X,Y,Z,factor;

  X= pos[0];Y=pos[1];Z=pos[2]*mm;
  //  G4cout<<"\n"<<pos[0]<<" "<<pos[1]<<" "<<pos[2]<<G4endl;
  if(Z<20*cm&&Z>-20*cm)
    { //G4cout<<"true!";
      factor=exp((-Z*Z)/(10*cm*10*cm));
      field[0]= BField.x()*factor ;//TAO
      field[1]= BField.y()*factor ;
      field[2]= BField.z()*factor ;
      
      //G4cout<<"true!"<<field[0]/gauss<<"gauss"<<field[1]/gauss<< "gauss"<<field[2]/gauss<< "gauss"<<G4endl;getchar();
      //      getchar();
   
    }
  
}
