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 | // $Id: G4StokesVector.cc,v 1.3 2006/11/17 11:59:03 vnivanch Exp $ |
---|
27 | // GEANT4 tag $Name: $ |
---|
28 | // |
---|
29 | // GEANT4 Class file |
---|
30 | // |
---|
31 | // |
---|
32 | // File name: G4StokesVector |
---|
33 | // |
---|
34 | // Author: Andreas Schaelicke |
---|
35 | // |
---|
36 | // Creation date: 01.05.2005 |
---|
37 | // |
---|
38 | // Modifications: |
---|
39 | // |
---|
40 | // Class Description: |
---|
41 | // |
---|
42 | // Provides Stokesvector representation employed in polarized |
---|
43 | // processes. |
---|
44 | // |
---|
45 | #include "G4StokesVector.hh" |
---|
46 | #include "G4PolarizationHelper.hh" |
---|
47 | #include "Randomize.hh" |
---|
48 | |
---|
49 | const G4StokesVector G4StokesVector::ZERO=G4ThreeVector(0.,0.,0.); |
---|
50 | const G4StokesVector G4StokesVector::P1=G4ThreeVector(1.,0.,0.); |
---|
51 | const G4StokesVector G4StokesVector::P2=G4ThreeVector(0.,1.,0.); |
---|
52 | const G4StokesVector G4StokesVector::P3=G4ThreeVector(0.,0.,1.); |
---|
53 | const G4StokesVector G4StokesVector::M1=G4ThreeVector(-1.,0.,0.); |
---|
54 | const G4StokesVector G4StokesVector::M2=G4ThreeVector(0.,-1.,0.); |
---|
55 | const G4StokesVector G4StokesVector::M3=G4ThreeVector(0.,0.,-1.); |
---|
56 | |
---|
57 | G4StokesVector::G4StokesVector() |
---|
58 | : G4ThreeVector(),isPhoton(false) |
---|
59 | { |
---|
60 | } |
---|
61 | |
---|
62 | G4StokesVector::G4StokesVector(const G4ThreeVector & v) |
---|
63 | : G4ThreeVector(v),isPhoton(false) |
---|
64 | { |
---|
65 | } |
---|
66 | |
---|
67 | G4StokesVector::~G4StokesVector() |
---|
68 | { |
---|
69 | } |
---|
70 | |
---|
71 | void G4StokesVector::RotateAz(G4ThreeVector nInteractionFrame, |
---|
72 | G4ThreeVector particleDirection) |
---|
73 | { |
---|
74 | G4ThreeVector yParticleFrame = |
---|
75 | G4PolarizationHelper::GetParticleFrameY(particleDirection); |
---|
76 | |
---|
77 | |
---|
78 | G4double cosphi=yParticleFrame*nInteractionFrame; |
---|
79 | if (cosphi>(1.+1.e-8) || cosphi<(-1.-1.e-8)) { |
---|
80 | G4cout<<" warning G4StokesVector::RotateAz cosphi>1 or cosphi<-1\n" |
---|
81 | <<" cosphi="<<cosphi<<"\n" |
---|
82 | <<" zAxis="<<particleDirection<<" ("<<particleDirection.mag()<<")\n" |
---|
83 | <<" yAxis="<<yParticleFrame<<" ("<<yParticleFrame.mag()<<")\n" |
---|
84 | <<" nAxis="<<nInteractionFrame<<" (" |
---|
85 | <<nInteractionFrame.mag()<<")"<<G4endl; |
---|
86 | } |
---|
87 | if (cosphi>1.) cosphi=1.; |
---|
88 | else if (cosphi<-1.) cosphi=-1.; |
---|
89 | |
---|
90 | // G4cout<<" cosphi="<<cosphi<<"\n" |
---|
91 | // <<" zAxis="<<particleDirection<<" ("<<particleDirection.mag()<<")\n" |
---|
92 | // <<" yAxis="<<yParticleFrame<<" ("<<yParticleFrame.mag()<<","<<(yParticleFrame*particleDirection)<<")\n" |
---|
93 | // <<" nAxis="<<nInteractionFrame<<" (" |
---|
94 | // <<nInteractionFrame.mag()<<")"<<G4endl; |
---|
95 | |
---|
96 | // G4double hel=sgn(cross(yParticleFrame*nInteractionFrame)*zInteractionFrame); |
---|
97 | // Why not particleDirection instead of zInteractionFrame ???!!! |
---|
98 | // -> is the same, since SYSIN is called with p1, and p2 as first parameter! |
---|
99 | G4double hel=(cross(yParticleFrame*nInteractionFrame)*particleDirection)>0?1.:-1.; |
---|
100 | |
---|
101 | G4double sinphi=hel*std::sqrt(1.-cosphi*cosphi); |
---|
102 | // G4cout<<" sin2 + cos2 -1 = "<<(sinphi*sinphi+cosphi*cosphi-1)<<"\n"; |
---|
103 | |
---|
104 | RotateAz(cosphi,sinphi); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | void G4StokesVector::InvRotateAz(G4ThreeVector nInteractionFrame, |
---|
109 | G4ThreeVector particleDirection) |
---|
110 | { |
---|
111 | // note if incomming particle is on z-axis, |
---|
112 | // we might encounter some nummerical problems, since |
---|
113 | // nInteratonFrame and yParticleFrame are actually (almost) the same momentum |
---|
114 | // and the normalization is only good to 10^-12 ! |
---|
115 | |
---|
116 | G4ThreeVector yParticleFrame = |
---|
117 | G4PolarizationHelper::GetParticleFrameY(particleDirection); |
---|
118 | G4double cosphi=yParticleFrame*nInteractionFrame; |
---|
119 | |
---|
120 | if (cosphi>1.+1.e-8 || cosphi<-1.-1.e-8) { |
---|
121 | G4cout<<" warning G4StokesVector::RotateAz cosphi>1 or cosphi<-1\n"; |
---|
122 | } |
---|
123 | if (cosphi>1) cosphi=1.; |
---|
124 | else if (cosphi<-1)cosphi=-1.; |
---|
125 | |
---|
126 | // check sign once more! |
---|
127 | G4double hel=(cross(yParticleFrame*nInteractionFrame)*particleDirection)>0?1.:-1.; |
---|
128 | G4double sinphi=hel*std::sqrt(std::fabs(1.-cosphi*cosphi)); |
---|
129 | RotateAz(cosphi,-sinphi); |
---|
130 | } |
---|
131 | |
---|
132 | void G4StokesVector::RotateAz(G4double cosphi, G4double sinphi) |
---|
133 | { |
---|
134 | if (!isPhoton) { |
---|
135 | G4double xsi1= cosphi*p1() + sinphi*p2(); |
---|
136 | G4double xsi2= -sinphi*p1() + cosphi*p2(); |
---|
137 | setX(xsi1); |
---|
138 | setY(xsi2); |
---|
139 | return; |
---|
140 | } |
---|
141 | |
---|
142 | G4double sin2phi=2.*cosphi*sinphi; |
---|
143 | G4double cos2phi=cosphi*cosphi-sinphi*sinphi; |
---|
144 | |
---|
145 | G4double xsi1= cos2phi*p1() + sin2phi*p2(); |
---|
146 | G4double xsi2= -sin2phi*p1() + cos2phi*p2(); |
---|
147 | setX(xsi1); |
---|
148 | setY(xsi2); |
---|
149 | } |
---|
150 | |
---|
151 | G4double G4StokesVector::GetBeta() |
---|
152 | { |
---|
153 | G4double beta=getPhi(); |
---|
154 | if (isPhoton) |
---|
155 | return 0.5*beta; |
---|
156 | return beta; |
---|
157 | } |
---|
158 | |
---|
159 | void G4StokesVector::DiceUniform() |
---|
160 | { |
---|
161 | G4double costheta=2.*G4UniformRand()-1.; |
---|
162 | G4double sintheta=std::sqrt(1.-costheta*costheta); |
---|
163 | G4double phi =2.*pi*G4UniformRand(); |
---|
164 | setX(std::sin(phi)*sintheta); |
---|
165 | setY(std::cos(phi)*sintheta); |
---|
166 | setZ(costheta); |
---|
167 | } |
---|
168 | |
---|
169 | void G4StokesVector::DiceP1() |
---|
170 | { |
---|
171 | if (G4UniformRand()>0.5) setX(1.); |
---|
172 | else setX(-1.); |
---|
173 | setY(0.); |
---|
174 | setZ(0.); |
---|
175 | } |
---|
176 | |
---|
177 | void G4StokesVector::DiceP2() |
---|
178 | { |
---|
179 | setX(0.); |
---|
180 | if (G4UniformRand()>0.5) setY(1.); |
---|
181 | else setY(-1.); |
---|
182 | setZ(0.); |
---|
183 | } |
---|
184 | |
---|
185 | void G4StokesVector::DiceP3() |
---|
186 | { |
---|
187 | setX(0.); |
---|
188 | setY(0.); |
---|
189 | if (G4UniformRand()>0.5) setZ(1.); |
---|
190 | else setZ(-1.); |
---|
191 | } |
---|
192 | |
---|
193 | void G4StokesVector::FlipP3() |
---|
194 | { |
---|
195 | setZ(-z()); |
---|
196 | } |
---|
197 | |
---|
198 | G4ThreeVector G4StokesVector::PolError(const G4StokesVector & sum2, long n) |
---|
199 | { |
---|
200 | // delta x = sqrt[ ( <x^2> - <x>^2 )/(n-1) ] |
---|
201 | G4StokesVector mean=(1./n)*(*this); |
---|
202 | return G4StokesVector((1./(n-1.)*((1./n)*sum2 - mean.PolSqr()))).PolSqrt(); |
---|
203 | } |
---|
204 | |
---|
205 | G4ThreeVector G4StokesVector::PolDiv(const G4StokesVector & b) |
---|
206 | {return G4ThreeVector(b.x()!=0. ? x()/b.x() : 11111., |
---|
207 | b.y()!=0. ? y()/b.y() : 11111., |
---|
208 | b.z()!=0. ? z()/b.z() : 11111.);} |
---|