// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // $Id: G4RKG3_Stepper.cc,v 1.17 2010/07/23 14:13:49 tnikitin Exp $ // GEANT4 tag $Name: field-V09-03-03 $ // // ------------------------------------------------------------------- #include "G4RKG3_Stepper.hh" #include "G4LineSection.hh" #include "G4Mag_EqRhs.hh" G4RKG3_Stepper::G4RKG3_Stepper(G4Mag_EqRhs *EqRhs) : G4MagIntegratorStepper(EqRhs,6), hStep(0.), fPtrMagEqOfMot(EqRhs) { } G4RKG3_Stepper::~G4RKG3_Stepper() { } void G4RKG3_Stepper::Stepper( const G4double yInput[8], const G4double dydx[6], G4double Step, G4double yOut[8], G4double yErr[]) { G4double B[3]; G4int nvar = 6 ; G4int i; G4double by15 = 1. / 15. ; // was 0.066666666 ; G4double yTemp[8], dydxTemp[6], yIn[8] ; // Saving yInput because yInput and yOut can be aliases for same array for(i=0;iEvaluateRhsGivenB(yTemp,B,dydxTemp) ; StepNoErr(yTemp,dydxTemp,h,yOut,B); // Store midpoint, chord calculation fyMidPoint = G4ThreeVector( yTemp[0], yTemp[1], yTemp[2]); // Do a full Step h *= 2 ; StepNoErr(yIn,dydx,h,yTemp,B); for(i=0;iEvaluateRhsReturnB(tIn,dydx,B1) ; // Correction for momentum not a velocity // Need the protection !!! must be not zero mom=std::sqrt(tIn[3]*tIn[3]+tIn[4]*tIn[4]+tIn[5]*tIn[5]); inverse_mom=1./mom; for(i=0;i<3;i++) { K1[i] = Step * dydx[i+3]*inverse_mom; tTemp[i] = tIn[i] + Step*(c1*tIn[i+3]*inverse_mom + c2*K1[i]) ; tTemp[i+3] = tIn[i+3] + c1*K1[i]*mom ; } GetEquationOfMotion()->EvaluateRhsReturnB(tTemp,yderiv,B) ; for(i=0;i<3;i++) { K2[i] = Step * yderiv[i+3]*inverse_mom; tTemp[i+3] = tIn[i+3] + c1*K2[i]*mom ; } // Given B, calculate yderiv ! GetEquationOfMotion()->EvaluateRhsGivenB(tTemp,B,yderiv) ; for(i=0;i<3;i++) { K3[i] = Step * yderiv[i+3]*inverse_mom; tTemp[i] = tIn[i] + Step*(tIn[i+3]*inverse_mom + c1*K3[i]) ; tTemp[i+3] = tIn[i+3] + K3[i]*mom ; } // Calculates y-deriv(atives) & returns B too! GetEquationOfMotion()->EvaluateRhsReturnB(tTemp,yderiv,B) ; for(i=0;i<3;i++) // Output trajectory vector { K4[i] = Step * yderiv[i+3]*inverse_mom; tOut[i] = tIn[i] + Step*(tIn[i+3]*inverse_mom+ (K1[i] + K2[i] + K3[i])*c3) ; tOut[i+3] = tIn[i+3] + mom*(K1[i] + 2*K2[i] + 2*K3[i] +K4[i])*c3 ; } tOut[6] = tIn[6]; tOut[7] = tIn[7]; // NormaliseTangentVector( tOut ); } // --------------------------------------------------------------------------- G4double G4RKG3_Stepper::DistChord() const { // Soon: must check whether h/R > 2 pi !! // Method below is good only for < 2 pi G4double distChord,distLine; if (fyInitial != fyFinal) { distLine= G4LineSection::Distline(fyMidPoint,fyInitial,fyFinal ); distChord = distLine; }else{ distChord = (fyMidPoint-fyInitial).mag(); } return distChord; }