src/BDSHelixStepper.cc

00001 /* BDSIM code.    Version 1.0
00002    Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    Last modified 18.10.2002
00004    Copyright (c) 2002 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 */
00006 #include "BDSGlobalConstants.hh" 
00007 //
00008 #include "BDSHelixStepper.hh"
00009 #include "G4ThreeVector.hh"
00010 #include "G4LineSection.hh"
00011 #include "G4TransportationManager.hh"
00012 
00013 extern G4double BDSLocalRadiusOfCurvature;
00014 
00015 BDSHelixStepper::BDSHelixStepper(G4Mag_EqRhs *EqRhs)
00016   : G4MagIntegratorStepper(EqRhs,6),  // integrate over 6 variables only !!
00017     itsBField(0.0), itsDist(0.0)
00018 {
00019   its_EqRhs = EqRhs;
00020 }
00021 
00022 
00023 void BDSHelixStepper::AdvanceHelix( const G4double  yIn[],
00024                                   G4double  h,
00025                                   G4double  yHelix[])
00026 {
00027   G4ThreeVector positionMove, endTangent;
00028 
00029   const G4double *pIn = yIn+3;
00030  
00031   G4ThreeVector v0= G4ThreeVector( pIn[0], pIn[1], pIn[2]);  
00032   
00033   G4ThreeVector GlobalPosition= G4ThreeVector( yIn[0], yIn[1], yIn[2]);  
00034 
00035   G4double InitMag=v0.mag();
00036 
00037   G4ThreeVector LocalR,LocalRp ;
00038 
00039   //G4Navigator* HelixNavigator=
00040   //  G4TransportationManager::GetTransportationManager()->
00041   //  GetNavigatorForTracking();
00042 
00043 
00044   LocalR=GlobalPosition;
00045   LocalRp=v0.unit();
00046 
00047   G4ThreeVector itsFinalPoint,itsFinalDir;
00048   
00049   G4ThreeVector yhat(0.,1.,0.);
00050 
00051   G4ThreeVector vhat=LocalRp;
00052   
00053   G4ThreeVector vnorm=vhat.cross(yhat);
00054    
00055   G4double R;
00056 
00057   if(BDSGlobalConstants::Instance()->GetSynchRescale())
00058     {
00059       G4double B[3];
00060       its_EqRhs->GetFieldValue(yIn, B);
00061       R=-(InitMag/GeV)/(0.299792458 * B[1]/tesla) *m;
00062     }
00063   else
00064     {
00065       R=-(InitMag/GeV)/(0.299792458 * itsBField/tesla) * m;
00066     }
00067 
00068  // include the sign of the charge of the particles
00069 
00070   if( its_EqRhs->FCof()<0) R*=-1.;
00071   else if (its_EqRhs->FCof()==0) R=DBL_MAX;
00072 
00073   // check that the approximations are valid, else do a linear step:
00074   if(fabs(R)<DBL_MAX) 
00075     { 
00076   
00077       G4double Theta   = h/R;
00078 
00079       G4double CosT_ov_2, SinT_ov_2, CosT, SinT;
00080       CosT_ov_2=cos(Theta/2);
00081       SinT_ov_2=sin(Theta/2);
00082 
00083       CosT=(CosT_ov_2*CosT_ov_2)- (SinT_ov_2*SinT_ov_2);
00084       SinT=2*CosT_ov_2*SinT_ov_2;
00085 
00086       BDSLocalRadiusOfCurvature=R;
00087 
00088       itsDist=fabs(R)*(1.-CosT_ov_2);
00089 
00090       G4ThreeVector dPos=R*(SinT*vhat + (1-CosT)*vnorm);
00091         
00092       itsFinalPoint=LocalR+dPos;
00093       itsFinalDir=CosT*vhat +SinT*vnorm;
00094 
00095 
00096     }
00097   else
00098     {
00099       itsFinalPoint=LocalR + h * LocalRp;
00100       itsFinalDir=LocalRp;
00101       itsDist=0.;
00102     }
00103 
00104 
00105   G4ThreeVector GlobalTangent;
00106   GlobalPosition=itsFinalPoint;
00107   GlobalTangent=itsFinalDir;
00108   GlobalTangent*=InitMag;
00109 
00110   yHelix[0] = GlobalPosition.x(); 
00111   yHelix[1] = GlobalPosition.y(); 
00112   yHelix[2] = GlobalPosition.z(); 
00113                                 
00114   yHelix[3] = GlobalTangent.x();
00115   yHelix[4] = GlobalTangent.y();
00116   yHelix[5] = GlobalTangent.z();
00117 }    
00118 
00119 
00120 void BDSHelixStepper::Stepper( const G4double yInput[],
00121                              const G4double[],
00122                              const G4double hstep,
00123                              G4double yOut[],
00124                              G4double yErr[]      )
00125 {  
00126   const G4int nvar = 6 ;
00127 
00128   for(G4int i=0;i<nvar;i++) yErr[i]=0;
00129   AdvanceHelix(yInput,hstep,yOut);
00130 }
00131 
00132 G4double BDSHelixStepper::DistChord()   const 
00133 {
00134 
00135   return itsDist;
00136   // This is a class method that gives distance of Mid 
00137   //  from the Chord between the Initial and Final points.
00138 }
00139 
00140 BDSHelixStepper::~BDSHelixStepper()
00141 {}

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7