Problem 1589 - Spin Tracking using G4Mag_SpinEqRhs sets Track polarization to 0
Summary: Spin Tracking using G4Mag_SpinEqRhs sets Track polarization to 0
Status: RESOLVED INVALID
Alias: None
Product: Geant4
Classification: Unclassified
Component: geometry/magneticfield (show other problems)
Version: other
Hardware: All All
: P5 trivial
Assignee: gum
URL:
Depends on:
Blocks:
 
Reported: 2014-03-11 18:14 CET by Chris Rogers
Modified: 2014-05-21 00:13 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description Chris Rogers 2014-03-11 18:14:44 CET
I have a line like

>        _equation = new G4Mag_SpinEqRhs(_miceMagneticField);
>        int n_vars = 9;
>        _stepper = new G4ClassicalRK4(_equation, n_vars);
>        _chordFinder =  new G4ChordFinder(_miceMagneticField, 0.1*mm, _stepper);
>        fieldMgr->SetChordFinder(_chordFinder);


in my code. When I run tracking, I look in my UserSteppingAction at the track polarization

> void MAUSSteppingAction::UserSteppingAction(const G4Step * aStep) {
>    std::cerr << "SteppingAction::UserSteppingAction " 
>              << aStep->GetTrack()->GetPolarization() << std::endl;
> }

and see that the track polarization is always 0, even when it is set to be initially non-zero in the PrimaryGeneratorAction.

I repeat the test, but with 

>       _equation = new G4EqEMFieldWithSpin(_miceElectroMagneticField);
>       int n_vars = 12;
>        _stepper = new G4ClassicalRK4(_equation, n_vars);
>        _chordFinder =  new G4ChordFinder(_miceMagneticField, 0.1*mm, _stepper);
>        fieldMgr->SetChordFinder(_chordFinder);

and now the non-zero polarization has gone away - i.e. the polarization is apparently propagated correctly.

I believe the polarization should be propagated correctly in both cases.
Comment 1 Chris Rogers 2014-03-11 18:18:36 CET
Apologies, I should add that I am using G4.9.6.p02
Comment 2 John Apostolakis 2014-05-19 18:24:16 CEST
Dear Chris,

Thank you for reporting this.

The examples for the propagation in field are potentially not clear enough, but the correct value for the number of variables required is 12.

To be certain, you can refer to the "G4FieldTrack" class and its method DumpToArray which turns the information from data members of a class into variables which will be integrated by the stepper.  You can see that the polarization (called spin) resides in elements 9-11, so the size must be at least 12:

   valArr[9]=fSpin.x();
   valArr[10]=fSpin.y();
   valArr[11]=fSpin.z();

Here is a link to the relevant lines of code in release 10.0. 

http://www-geant4.kek.jp/lxr/source/geometry/magneticfield/include/G4FieldTrack.icc?v=10.0#L213

( This code has been stable for an extended period of time. )

Best regards,
John
Comment 3 gum 2014-05-21 00:13:21 CEST
There is a chapter specifically for 'spin tracking' in the Application Developer's Guide:

http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/ForApplicationDeveloper/html/ch04s03.html#sect.EMField.Spin

In it, you'll find:

In order to track the spin of a particle in a magnetic field, you need to code the following:

   1.

      in your DetectorConstruction

      #include "G4Mag_SpinEqRhs.hh"

        G4Mag_EqRhs* fEquation = new G4Mag_SpinEqRhs(magField);

        G4MagIntegratorStepper* pStepper = new G4ClassicalRK4(fEquation,12);
                                                             notice the 12 
          
The 'notice the 12' is in bold letters.