Message: Re: setPhi() method for G4ThreeVector Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: setPhi() method for G4ThreeVector 

Forum: Event and Track Management
Re: Question setPhi() method for G4ThreeVector
Date: 23 Mar, 2012
From: Michael H. Kelsey <Michael H. Kelsey>

On Thu, 22 Mar 2012 20:05:02 GMT, Santos wrote:
> Hi all,
> This is a little piece of my program
>   G4ThreeVector momDir(0.,0.,1.);
>   momDir.setPhi(60.*deg);
>   momDir.setTheta(45.*deg);
>   G4cout<<"momDir.phi() "<<momDir.phi() <<G4endl;
>   G4cout<<"momDir.theta() "<<momDir.theta() <<G4endl;
>   G4cout<<"momDir "<<momDir<<G4endl;
> This is the output:
> momDir.phi() 0 momDir.theta() 0.785398 momDir (0.707107,0,0.707107)
> Now, momDir.phi() is 0 no matter what value I assign. This page:
> describes the setPhi() method, and G4ThreeVector is just GEANT reusing
> Hep3Vector.
> Could you, please, tell me what is wrong. By the way, I am using
> geant4.9.4.p02

The Phi angle is measured from the +X axis, in the XY plane. You have X=Y=0. at the time you call setPhi(), so there is no component in the XY plane, and the phi value is indeterminate, and hence stays zero.

If you swap the order of operations,


you'll get the result you want. Alternatively, if the code above is actually what you're doing (and not a simplified test case), you could set the whole vector in one shot:

  G4ThreeVector momDir;

-- Michael Kelsey

 Add Message Add Message
to: "Re: setPhi() method for G4ThreeVector"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]