| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4ExactHelixStepper.cc,v 1.9 2008/10/29 14:34:35 gcosmo Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | // Helix a-la-Explicity Euler: x_1 = x_0 + helix(h)
|
|---|
| 31 | // with helix(h) being a helix piece of length h
|
|---|
| 32 | // simplest approach for solving linear differential equations.
|
|---|
| 33 | // Take the current derivative and add it to the current position.
|
|---|
| 34 | //
|
|---|
| 35 | // As the field is assumed constant, an error is not calculated.
|
|---|
| 36 | //
|
|---|
| 37 | // Author: J. Apostolakis, 28 Jan 2005
|
|---|
| 38 | // Implementation adapted from ExplicitEuler of W.Wander
|
|---|
| 39 | // -------------------------------------------------------------------
|
|---|
| 40 |
|
|---|
| 41 | #include "G4ExactHelixStepper.hh"
|
|---|
| 42 | #include "G4ThreeVector.hh"
|
|---|
| 43 | #include "G4LineSection.hh"
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | G4ExactHelixStepper::G4ExactHelixStepper(G4Mag_EqRhs *EqRhs)
|
|---|
| 47 | : G4MagHelicalStepper(EqRhs),
|
|---|
| 48 | fBfieldValue(DBL_MAX, DBL_MAX, DBL_MAX), yInitialEHS(DBL_MAX), yFinalEHS(-DBL_MAX)
|
|---|
| 49 |
|
|---|
| 50 | {
|
|---|
| 51 | const G4int nvar = 6 ;
|
|---|
| 52 | G4int i;
|
|---|
| 53 | for(i=0;i<nvar;i++) {
|
|---|
| 54 | fYInSav[i]= DBL_MAX;
|
|---|
| 55 | }
|
|---|
| 56 | fPtrMagEqOfMot=EqRhs;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | G4ExactHelixStepper::~G4ExactHelixStepper() {}
|
|---|
| 60 |
|
|---|
| 61 | void
|
|---|
| 62 | G4ExactHelixStepper::Stepper( const G4double yInput[],
|
|---|
| 63 | const G4double*,
|
|---|
| 64 | G4double hstep,
|
|---|
| 65 | G4double yOut[],
|
|---|
| 66 | G4double yErr[] )
|
|---|
| 67 | {
|
|---|
| 68 | const G4int nvar = 6 ;
|
|---|
| 69 |
|
|---|
| 70 | G4int i;
|
|---|
| 71 | // G4double yTemp[7], yIn[7] ;
|
|---|
| 72 | G4ThreeVector Bfld_value;
|
|---|
| 73 |
|
|---|
| 74 | for(i=0;i<nvar;i++) {
|
|---|
| 75 | // yIn[i]= yInput[i];
|
|---|
| 76 | fYInSav[i]= yInput[i];
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | MagFieldEvaluate(yInput, Bfld_value) ;
|
|---|
| 80 |
|
|---|
| 81 | // DumbStepper(yIn, Bfld_value, hstep, yTemp);
|
|---|
| 82 | AdvanceHelix(yInput, Bfld_value, hstep, yOut);
|
|---|
| 83 |
|
|---|
| 84 | // We are assuming a constant field: helix is exact.
|
|---|
| 85 | for(i=0;i<nvar;i++) {
|
|---|
| 86 | yErr[i] = 0.0 ;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | yInitialEHS = G4ThreeVector( yInput[0], yInput[1], yInput[2]);
|
|---|
| 90 | yFinalEHS = G4ThreeVector( yOut[0], yOut[1], yOut[2]);
|
|---|
| 91 | fBfieldValue=Bfld_value;
|
|---|
| 92 |
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | void
|
|---|
| 96 | G4ExactHelixStepper::DumbStepper( const G4double yIn[],
|
|---|
| 97 | G4ThreeVector Bfld,
|
|---|
| 98 | G4double h,
|
|---|
| 99 | G4double yOut[])
|
|---|
| 100 | {
|
|---|
| 101 | // Assuming a constant field: solution is a helix
|
|---|
| 102 | AdvanceHelix(yIn, Bfld, h, yOut);
|
|---|
| 103 |
|
|---|
| 104 | G4Exception("G4ExactHelixStepper::DumbStepper should not be called.",
|
|---|
| 105 | "EHS:NoDumbStepper", FatalException, "Stepper must do all the work." );
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | // ---------------------------------------------------------------------------
|
|---|
| 110 |
|
|---|
| 111 | G4double G4ExactHelixStepper::DistChord() const
|
|---|
| 112 | {
|
|---|
| 113 | // Implementation : must check whether h/R > pi !!
|
|---|
| 114 | // If( h/R < pi) DistChord=h/2*std::tan(Ang_curve/4)
|
|---|
| 115 | // Else DistChord=R_helix
|
|---|
| 116 | //
|
|---|
| 117 | G4double distChord;
|
|---|
| 118 | G4double Ang_curve=GetAngCurve();
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 | if(Ang_curve<=pi){
|
|---|
| 122 | distChord=GetRadHelix()*(1-std::cos(0.5*Ang_curve));
|
|---|
| 123 | }
|
|---|
| 124 | else
|
|---|
| 125 | if(Ang_curve<twopi){
|
|---|
| 126 | distChord=GetRadHelix()*(1+std::cos(0.5*(twopi-Ang_curve)));
|
|---|
| 127 | }
|
|---|
| 128 | else{
|
|---|
| 129 | distChord=2.*GetRadHelix();
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 | return distChord;
|
|---|
| 135 |
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | G4int
|
|---|
| 139 | G4ExactHelixStepper::IntegratorOrder() const
|
|---|
| 140 | {
|
|---|
| 141 | return 1;
|
|---|
| 142 | }
|
|---|