Geant4  10.00.p02
G4ReactionProduct.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 // J.L. Chuma, TRIUMF, 31-Oct-1996
27 // last modified: 19-Dec-1996
28 // Modified by J.L.Chuma, 05-May-97
29 // M. Kelsey 29-Aug-2011 -- Use G4Allocator for better memory management
30 
31 #include "G4ReactionProduct.hh"
32 
34 
35 
37  theParticleDefinition(NULL),
38  formationTime(0.0),
39  hasInitialStateParton(false),
40  mass(0.0),
41  totalEnergy(0.0),
42  kineticEnergy(0.0),
43  timeOfFlight(0.0),
44  side(0),
45  NewlyAdded(false),
46  MayBeKilled(true)
47  {
48  SetMomentum( 0.0, 0.0, 0.0 );
49  SetPositionInNucleus( 0.0, 0.0, 0.0 );
50  }
51 
53  G4ParticleDefinition *aParticleDefinition )
54  {
55  SetMomentum( 0.0, 0.0, 0.0 );
56  SetPositionInNucleus( 0.0, 0.0, 0.0 );
57  formationTime = 0.0;
58  hasInitialStateParton = false;
59  theParticleDefinition = aParticleDefinition;
60  mass = aParticleDefinition->GetPDGMass();
61  totalEnergy = mass;
62  kineticEnergy = 0.0;
63  (aParticleDefinition->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0;
64  side = 0;
65  NewlyAdded = false;
66  MayBeKilled = true;
67  }
68 
70  const G4ReactionProduct &right )
71  {
76  momentum = right.momentum;
77  mass = right.mass;
78  totalEnergy = right.totalEnergy;
80  timeOfFlight = right.timeOfFlight;
81  side = right.side;
82  NewlyAdded = right.NewlyAdded;
83  MayBeKilled = right.MayBeKilled;
84  }
85 
87  const G4ReactionProduct &right )
88  {
89  if( this != &right ) {
94  momentum = right.momentum;
95  mass = right.mass;
96  totalEnergy = right.totalEnergy;
98  timeOfFlight = right.timeOfFlight;
99  side = right.side;
100  NewlyAdded = right.NewlyAdded;
101  MayBeKilled = right.MayBeKilled;
102  }
103  return *this;
104  }
105 
107  const G4DynamicParticle &right )
108  {
110  SetPositionInNucleus( 0.0, 0.0, 0.0 );
111  formationTime = 0.0;
112  hasInitialStateParton = false;
113  momentum = right.GetMomentum();
114  mass = right.GetDefinition()->GetPDGMass();
115  totalEnergy = right.GetTotalEnergy();
117  (right.GetDefinition()->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0;
118  side = 0;
119  NewlyAdded = false;
120  MayBeKilled = true;
121  return *this;
122  }
123 
125  const G4HadProjectile &right )
126  {
128  SetPositionInNucleus( 0.0, 0.0, 0.0 );
129  formationTime = 0.0;
130  hasInitialStateParton = false;
131  momentum = right.Get4Momentum().vect();
132  mass = right.GetDefinition()->GetPDGMass();
133  totalEnergy = right.Get4Momentum().e();
135  (right.GetDefinition()->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0;
136  side = 0;
137  NewlyAdded = false;
138  MayBeKilled = true;
139  return *this;
140  }
141 
143  G4ParticleDefinition *aParticleDefinition )
144  { G4double aKineticEnergy = GetKineticEnergy();
145  G4double pp = GetMomentum().mag();
146  G4ThreeVector aMomentum = GetMomentum();
147  SetDefinition( aParticleDefinition );
148  SetKineticEnergy( aKineticEnergy );
149  if( pp > DBL_MIN )
150  SetMomentum( aMomentum * (std::sqrt(aKineticEnergy*aKineticEnergy +
151  2*aKineticEnergy*GetMass())/pp) );
152  }
153 
155  G4ParticleDefinition *aParticleDefinition )
156  {
157  theParticleDefinition = aParticleDefinition;
158  mass = aParticleDefinition->GetPDGMass();
159  totalEnergy = mass;
160  kineticEnergy = 0.0;
161  (aParticleDefinition->GetPDGEncoding()<0) ?
162  timeOfFlight=-1.0 : timeOfFlight=1.0;
163  }
164 
166  const G4double x, const G4double y, const G4double z )
167  {
168  momentum.setX( x );
169  momentum.setY( y );
170  momentum.setZ( z );
171  }
172 
174  const G4double x, const G4double y )
175  {
176  momentum.setX( x );
177  momentum.setY( y );
178  }
179 
181  {
182  momentum.setZ( z );
183  }
184 
186  {
187  SetMomentum( 0.0, 0.0, 0.0 );
188  totalEnergy = 0.0;
189  kineticEnergy = 0.0;
190  mass = 0.0;
191  timeOfFlight = 0.0;
192  side = 0;
193  NewlyAdded = false;
194  SetPositionInNucleus( 0.0, 0.0, 0.0 );
195  formationTime = 0.0;
196  hasInitialStateParton = false;
197  }
198 
200  const G4ReactionProduct &p1, const G4ReactionProduct &p2 )
201  {
202  G4ThreeVector p1M = p1.momentum;
203  G4ThreeVector p2M = p2.momentum;
204  G4double p1x = p1M.x(); G4double p1y = p1M.y(); G4double p1z = p1M.z();
205  G4double p2x = p2M.x(); G4double p2y = p2M.y(); G4double p2z = p2M.z();
206  G4double a = ( (p1x*p2x+p1y*p2y+p1z*p2z)/(p2.totalEnergy+p2.mass) -
207  p1.totalEnergy ) / p2.mass;
208  G4double x = p1x+a*p2x;
209  G4double y = p1y+a*p2y;
210  G4double z = p1z+a*p2z;
211  G4double p = std::sqrt(x*x+y*y+z*z);
212  SetMass( p1.mass );
213  SetTotalEnergy( std::sqrt( (p1.mass+p)*(p1.mass+p) - 2.*p1.mass*p ) );
214  //SetTotalEnergy( std::sqrt( p1.mass*p1.mass + x*x + y*y + z*z ) );
215  SetMomentum( x, y, z );
216  }
217 
219  const G4ReactionProduct& p ) const
220  {
221  G4ThreeVector tM = momentum;
222  G4ThreeVector pM = p.momentum;
223  G4double tx = tM.x(); G4double ty = tM.y(); G4double tz = tM.z();
224  G4double px = pM.x(); G4double py = pM.y(); G4double pz = pM.z();
225  G4double a = std::sqrt( ( px*px + py*py + pz*pz ) * ( tx*tx + ty*ty + tz*tz ) );
226  if( a == 0.0 ) {
227  return 0.0;
228  } else {
229  a = ( tx*px + ty*py + tz*pz ) / a;
230  if( std::fabs(a) > 1.0 ) { a<0.0 ? a=-1.0 : a=1.0; }
231  return std::acos( a );
232  }
233  }
234 
236  const G4ReactionProduct& p1, const G4ReactionProduct& p2 )
237  {
238  G4double totEnergy = p1.totalEnergy + p2.totalEnergy;
239  G4double x = p1.momentum.x() + p2.momentum.x();
240  G4double y = p1.momentum.y() + p2.momentum.y();
241  G4double z = p1.momentum.z() + p2.momentum.z();
242  G4double newMass = totEnergy*totEnergy - ( x*x + y*y + z*z );
243  if( newMass < 0.0 )
244  newMass = -1. * std::sqrt( -newMass );
245  else
246  newMass = std::sqrt( newMass );
247  G4ReactionProduct result;
248  result.SetMass( newMass );
249  result.SetMomentum( x, y, z );
250  result.SetTotalEnergy( totEnergy );
251  result.SetPositionInNucleus( 0.0, 0.0, 0.0 );
252  result.SetFormationTime(0.0);
253  result.HasInitialStateParton(false);
254  return result;
255  }
256 
258  const G4ReactionProduct& p1, const G4ReactionProduct& p2 )
259  {
260  G4double totEnergy = p1.totalEnergy - p2.totalEnergy;
261  G4double x = p1.momentum.x() - p2.momentum.x();
262  G4double y = p1.momentum.y() - p2.momentum.y();
263  G4double z = p1.momentum.z() - p2.momentum.z();
264  G4double newMass = totEnergy*totEnergy - ( x*x + y*y + z*z );
265  if( newMass < 0.0 )
266  newMass = -1. * std::sqrt( -newMass );
267  else
268  newMass = std::sqrt( newMass );
269  G4ReactionProduct result;
270  result.SetMass( newMass );
271  result.SetMomentum( x, y, z );
272  result.SetTotalEnergy( totEnergy );
273  result.SetPositionInNucleus( 0.0, 0.0, 0.0 );
274  result.SetFormationTime(0.0);
275  result.HasInitialStateParton(false);
276  return result;
277  }
278  /* end of code */
279 
void SetPositionInNucleus(G4double x, G4double y, G4double z)
void HasInitialStateParton(G4bool aFlag)
void Lorentz(const G4ReactionProduct &p1, const G4ReactionProduct &p2)
G4double GetKineticEnergy() const
CLHEP::Hep3Vector G4ThreeVector
G4double GetTotalEnergy() const
G4double z
Definition: TRTMaterials.hh:39
void SetKineticEnergy(const G4double en)
void SetMomentum(const G4double x, const G4double y, const G4double z)
G4ThreadLocal G4Allocator< G4ReactionProduct > * aRPAllocator
G4ParticleDefinition * GetDefinition() const
G4double a
Definition: TRTMaterials.hh:39
#define G4ThreadLocal
Definition: tls.hh:52
void SetDefinitionAndUpdateE(G4ParticleDefinition *aParticleDefinition)
G4double Angle(const G4ReactionProduct &p) const
G4ReactionProduct & operator=(const G4ReactionProduct &right)
void SetMass(const G4double mas)
G4ParticleDefinition * theParticleDefinition
const G4ParticleDefinition * GetDefinition() const
G4ThreeVector momentum
G4double GetKineticEnergy() const
void SetTotalEnergy(const G4double en)
const G4LorentzVector & Get4Momentum() const
G4double GetKineticEnergy() const
G4double GetPDGMass() const
G4ReactionProduct operator-(const G4ReactionProduct &p1, const G4ReactionProduct &p2)
#define DBL_MIN
Definition: templates.hh:75
void SetDefinition(G4ParticleDefinition *aParticleDefinition)
G4ThreeVector GetMomentum() const
void SetFormationTime(G4double aTime)
double G4double
Definition: G4Types.hh:76
G4ThreeVector positionInNucleus
G4double GetMass() const
G4ThreeVector GetMomentum() const
G4ReactionProduct operator+(const G4ReactionProduct &p1, const G4ReactionProduct &p2)