Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CascadParticle.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 // $Id$
27 //
28 // 20100112 M. Kelsey -- Remove G4CascadeMomentum, use G4LorentzVector directly
29 // 20100114 M. Kelsey -- Replace vector<G4Double> position with G4ThreeVector
30 // 20101012 M. Kelsey -- Check for negative d2 in getPathToTheNextZone()
31 // 20110806 M. Kelsey -- Add fill() function to replicate ctor/op=() action
32 // 20110922 M. Kelsey -- Follow G4InuclParticle::print(ostream&) migration,
33 // Add stream argument to print(), add operator<<().
34 // 20111017 M. Kelsey -- Add check for zero momentum in path calculation.
35 
36 #include "G4CascadParticle.hh"
37 #include "G4ios.hh"
38 #include <cmath>
39 
40 
41 // Default constructor produces non-functional object
42 
44  : verboseLevel(0), current_zone(-1), current_path(-1.), movingIn(false),
45  reflectionCounter(0), reflected(false), generation(-1) {
46  if (verboseLevel > 3) {
47  G4cout << " >>> G4CascadParticle::G4CascadParticle" << G4endl;
48  }
49 }
50 
51 // Analogue to operator=() to support filling vectors w/o temporaries
52 
54  const G4ThreeVector& pos, G4int izone,
55  G4double cpath, G4int gen) {
56  if (verboseLevel > 3) G4cout << " >>> G4CascadParticle::fill" << G4endl;
57 
58  theParticle = particle;
59  position = pos;
60  current_zone = izone;
61  current_path = cpath;
62  movingIn = true;
63  reflectionCounter = 0;
64  reflected = false;
65  generation = gen;
66 }
67 
68 
70  G4double rz_out) {
71  if (verboseLevel > 3) {
72  G4cout << " >>> G4CascadParticle::getPathToTheNextZone rz_in " << rz_in
73  << " rz_out " << rz_out << G4endl;
74  }
75 
76  const G4LorentzVector& mom = getMomentum();
77 
78  G4double path = -1.0;
79  G4double rp = mom.vect().dot(position);
80  G4double rr = position.mag2();
81  G4double pp = mom.vect().mag2();
82 
83  if (std::abs(pp) < 1e-9) { // Cut-off for "at rest" is 1 eV momentum
84  if (verboseLevel > 3) G4cout << " at rest; path length is zero" << G4endl;
85  return 0.;
86  }
87 
88  G4double ra = rr - rp * rp / pp;
89  pp = std::sqrt(pp);
90  G4double ds;
91  G4double d2;
92 
93  if (verboseLevel > 3) {
94  G4cout << " current_zone " << current_zone << " rr " << rr
95  << " rp " << rp << " pp " << pp << " ra " << ra << G4endl;
96  }
97 
98  if (current_zone == 0 || rp > 0.0) {
99  d2 = rz_out * rz_out - ra;
100  if (d2 > 0.0) {
101  ds = 1.0;
102  movingIn = false;
103  } else {
104  d2 = rz_in * rz_in - ra;
105  ds = -1.0;
106  movingIn = true;
107  }
108  } else {
109  d2 = rz_in * rz_in - ra;
110  if (d2 > 0.0) {
111  ds = -1.0;
112  movingIn = true;
113  } else {
114  d2 = rz_out * rz_out - ra;
115  ds = 1.0;
116  movingIn = false;
117  }
118  }
119 
120  if (verboseLevel > 3) G4cout << " ds " << ds << " d2 " << d2 << G4endl;
121 
122  if (d2 < 0.0 && d2 > -1e-6) d2 = 0.; // Account for round-off
123 
124  if (d2 > 0.0) path = ds * std::sqrt(d2) - rp / pp; // Avoid FPE failure
125 
126  return path;
127 }
128 
130  if (verboseLevel > 3) {
131  G4cout << " >>> G4CascadParticle::propagateAlongThePath" << G4endl;
132  }
133 
134  position += getMomentum().vect().unit()*path;
135 }
136 
137 
138 // Proper stream output (just calls print())
139 
140 std::ostream& operator<<(std::ostream& os, const G4CascadParticle& part) {
141  part.print(os);
142  return os;
143 }
144 
145 void G4CascadParticle::print(std::ostream& os) const {
146  os << theParticle << G4endl
147  << " zone " << current_zone << " current_path " << current_path
148  << " reflectionCounter " << reflectionCounter << G4endl
149  << " x " << position.x() << " y " << position.y()
150  << " z " << position.z() << G4endl;
151 }
152