Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4StokesVector.cc
Go to the documentation of this file.
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// Geant4 Class file
27//
28// File name: G4StokesVector
29//
30// Author: Andreas Schaelicke
31//
32// Class Description:
33// Provides Stokes vector representation employed in polarized processes.
34
35#include "G4StokesVector.hh"
36
38#include "Randomize.hh"
39
41 G4StokesVector(G4ThreeVector(0., 0., 0.));
43 G4StokesVector(G4ThreeVector(1., 0., 0.));
45 G4StokesVector(G4ThreeVector(0., 1., 0.));
47 G4StokesVector(G4ThreeVector(0., 0., 1.));
49 G4StokesVector(G4ThreeVector(-1., 0., 0.));
51 G4StokesVector(G4ThreeVector(0., -1., 0.));
53 G4StokesVector(G4ThreeVector(0., 0., -1.));
54
57 , fIsPhoton(false)
58{}
59
61 : G4ThreeVector(v)
62 , fIsPhoton(false)
63{}
64
65G4bool G4StokesVector::IsZero() const { return *this == ZERO; }
66
68 G4ThreeVector particleDirection)
69{
70 G4ThreeVector yParticleFrame =
72
73 G4double cosphi = yParticleFrame * nInteractionFrame;
74 if(cosphi > (1. + 1.e-8) || cosphi < (-1. - 1.e-8))
75 {
77 ed << " warning G4StokesVector::RotateAz cosphi>1 or cosphi<-1\n"
78 << " cosphi=" << cosphi << "\n"
79 << " zAxis=" << particleDirection << " (" << particleDirection.mag()
80 << ")\n"
81 << " yAxis=" << yParticleFrame << " (" << yParticleFrame.mag() << ")\n"
82 << " nAxis=" << nInteractionFrame << " (" << nInteractionFrame.mag()
83 << ")\n";
84 G4Exception("G4StokesVector::RotateAz", "pol030", JustWarning, ed);
85 }
86 if(cosphi > 1.)
87 cosphi = 1.;
88 else if(cosphi < -1.)
89 cosphi = -1.;
90
91 G4double hel =
92 (yParticleFrame.cross(nInteractionFrame) * particleDirection) > 0. ? 1.
93 : -1.;
94
95 G4double sinphi = hel * std::sqrt(1. - cosphi * cosphi);
96
97 RotateAz(cosphi, sinphi);
98}
99
101 G4ThreeVector particleDirection)
102{
103 // note if incoming particle is on z-axis,
104 // we might encounter some nummerical problems, since
105 // nInteratonFrame and yParticleFrame are actually (almost) the same momentum
106 // and the normalization is only good to 10^-12 !
107
108 G4ThreeVector yParticleFrame =
110 G4double cosphi = yParticleFrame * nInteractionFrame;
111
112 if(cosphi > 1. + 1.e-8 || cosphi < -1. - 1.e-8)
113 {
115 ed << " warning G4StokesVector::RotateAz cosphi>1 or cosphi<-1\n";
116 G4Exception("G4StokesVector::InvRotateAz", "pol030", JustWarning, ed);
117 }
118 if(cosphi > 1.)
119 cosphi = 1.;
120 else if(cosphi < -1.)
121 cosphi = -1.;
122
123 // check sign once more!
124 G4double hel =
125 (yParticleFrame.cross(nInteractionFrame) * particleDirection) > 0. ? 1.
126 : -1.;
127 G4double sinphi = hel * std::sqrt(std::fabs(1. - cosphi * cosphi));
128 RotateAz(cosphi, -sinphi);
129}
130
132{
133 if(!fIsPhoton)
134 {
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
152{
153 G4double bet = getPhi();
154 if(fIsPhoton)
155 {
156 bet *= 0.5;
157 }
158 return bet;
159}
160
162{
163 G4double costheta = 2. * G4UniformRand() - 1.;
164 G4double sintheta = std::sqrt(1. - costheta * costheta);
165 G4double aphi = 2. * CLHEP::pi * G4UniformRand();
166 setX(std::sin(aphi) * sintheta);
167 setY(std::cos(aphi) * sintheta);
168 setZ(costheta);
169}
170
172{
173 if(G4UniformRand() > 0.5)
174 setX(1.);
175 else
176 setX(-1.);
177 setY(0.);
178 setZ(0.);
179}
180
182{
183 setX(0.);
184 if(G4UniformRand() > 0.5)
185 setY(1.);
186 else
187 setY(-1.);
188 setZ(0.);
189}
190
192{
193 setX(0.);
194 setY(0.);
195 if(G4UniformRand() > 0.5)
196 setZ(1.);
197 else
198 setZ(-1.);
199}
200
202
204{
205 // delta x = sqrt[ ( <x^2> - <x>^2 )/(n-1) ]
206 G4ThreeVector mean = (1. / n) * G4ThreeVector(*this);
207 G4ThreeVector polsqr = G4StokesVector(mean).PolSqr();
208 G4ThreeVector result =
209 G4StokesVector((1. / (n - 1.) * ((1. / n) * sum2 - polsqr))).PolSqrt();
210 return result;
211}
212
214{
215 return G4ThreeVector(b.x() != 0. ? x() / b.x() : 11111.,
216 b.y() != 0. ? y() / b.y() : 11111.,
217 b.z() != 0. ? z() / b.z() : 11111.);
218}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
#define G4UniformRand()
Definition Randomize.hh:52
double z() const
double x() const
void setY(double)
double y() const
Hep3Vector cross(const Hep3Vector &) const
void setZ(double)
double mag() const
double getPhi() const
void setX(double)
static G4ThreeVector GetParticleFrameY(const G4ThreeVector &)
static const G4StokesVector P3
G4double p1() const
static const G4StokesVector M2
G4bool IsZero() const
G4ThreeVector PolDiv(const G4StokesVector &)
static const G4StokesVector ZERO
void InvRotateAz(G4ThreeVector nInteractionFrame, G4ThreeVector particleDirection)
static const G4StokesVector P2
G4double p2() const
static const G4StokesVector M3
void RotateAz(G4ThreeVector nInteractionFrame, G4ThreeVector particleDirection)
static const G4StokesVector M1
G4ThreeVector PolError(const G4StokesVector &sum2, long n)
static const G4StokesVector P1