38   ThetaInBeamSystem= 0.0;
    39   PhiInBeamSystem  = 0.0;
    40   BeamDirectionAtVertexTheta=0.0;
    41   BeamDirectionAtVertexPhi=0.0;
    42   ThetaInLabSystem = 0.0;
    70   const G4double PI=3.14159265358979323846;
    73   G4double Theta0 = ThetaInBeamSystem;
    74   G4double Phi0   = PhiInBeamSystem;
    76   G4double alpha = BeamDirectionAtVertexPhi;      
    77   G4double beta  = BeamDirectionAtVertexTheta;    
    80   G4double px = sin(Theta0)*cos(Phi0);
    81   G4double py = sin(Theta0)*sin(Phi0);
    82   G4double pz = cos(Theta0);
    84   G4double sa = sin(alpha);
    85   G4double ca = cos(alpha);
    86   G4double sb = sin(beta);
    87   G4double cb = cos(beta);
    88   G4double sg = sin(gamma);
    89   G4double cg = cos(gamma);
    91   G4double px_1 = px*(ca*cb*cg-sa*sg)+py*(-ca*cb*sg-sa*cg)+pz*(ca*sb);
    92   G4double py_1 = px*(sa*cb*cg+ca*sg)+py*(-sa*cb*sg+ca*cg)+pz*(sa*sb);
    93   G4double pz_1 = px*(-sb*cg) + py*(sb*sg) + pz*(cb);
    95   G4double pxy_1 = sqrt(px_1*px_1 + py_1*py_1);
    96   G4double sithe1 = pxy_1;
    97   G4double cothe1 = pz_1;
    99   G4double theta_1 = atan2(sithe1,cothe1);
   101   ThetaInLabSystem = theta_1;
   106     G4double siphi1 = py_1/pxy_1;
   107     G4double cophi1 = px_1/pxy_1;
   108     phi_1 = atan2(siphi1,cophi1);
   111       phi_1 = 2.*PI + phi_1;
   119   PhiInLabSystem = phi_1;
   130   G4cout << 
"Beam direction in the Lab frame:" << G4endl
   131          << 
"  theta=" << BeamDirectionAtVertexTheta << 
", phi=" << BeamDirectionAtVertexPhi << G4endl;
   132   G4cout << 
"Particle direction in the beam system:" << G4endl
   133          << 
"  theta=" << ThetaInBeamSystem << 
", phi=" << PhiInBeamSystem << G4endl;
   134   G4cout << 
"Particle direction in the Lab system:" << G4endl
   135          << 
"  theta=" << ThetaInLabSystem << 
", phi=" << PhiInLabSystem << G4endl;