Geant4  10.02
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  theCreatorModel(-1),
46  NewlyAdded(false),
47  MayBeKilled(true)
48  {
49  SetMomentum( 0.0, 0.0, 0.0 );
50  SetPositionInNucleus( 0.0, 0.0, 0.0 );
51  }
52 
54  const G4ParticleDefinition *aParticleDefinition )
55  {
56  SetMomentum( 0.0, 0.0, 0.0 );
57  SetPositionInNucleus( 0.0, 0.0, 0.0 );
58  formationTime = 0.0;
59  hasInitialStateParton = false;
60  theParticleDefinition = aParticleDefinition;
61  mass = aParticleDefinition->GetPDGMass();
62  totalEnergy = mass;
63  kineticEnergy = 0.0;
64  (aParticleDefinition->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0;
65  side = 0;
66  theCreatorModel = -1;
67  NewlyAdded = false;
68  MayBeKilled = true;
69  }
70 
72  const G4ReactionProduct &right )
73  {
78  momentum = right.momentum;
79  mass = right.mass;
80  totalEnergy = right.totalEnergy;
82  timeOfFlight = right.timeOfFlight;
83  side = right.side;
85  NewlyAdded = right.NewlyAdded;
86  MayBeKilled = right.MayBeKilled;
87  }
88 
90  const G4ReactionProduct &right )
91  {
92  if( this != &right ) {
97  momentum = right.momentum;
98  mass = right.mass;
99  totalEnergy = right.totalEnergy;
101  timeOfFlight = right.timeOfFlight;
102  side = right.side;
104  NewlyAdded = right.NewlyAdded;
105  MayBeKilled = right.MayBeKilled;
106  }
107  return *this;
108  }
109 
111  const G4DynamicParticle &right )
112  {
114  SetPositionInNucleus( 0.0, 0.0, 0.0 );
115  formationTime = 0.0;
116  hasInitialStateParton = false;
117  momentum = right.GetMomentum();
118  mass = right.GetDefinition()->GetPDGMass();
119  totalEnergy = right.GetTotalEnergy();
121  (right.GetDefinition()->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0;
122  side = 0;
123  theCreatorModel = -1;
124  NewlyAdded = false;
125  MayBeKilled = true;
126  return *this;
127  }
128 
130  const G4HadProjectile &right )
131  {
133  SetPositionInNucleus( 0.0, 0.0, 0.0 );
134  formationTime = 0.0;
135  hasInitialStateParton = false;
136  momentum = right.Get4Momentum().vect();
137  mass = right.GetDefinition()->GetPDGMass();
138  totalEnergy = right.Get4Momentum().e();
140  (right.GetDefinition()->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0;
141  side = 0;
142  theCreatorModel = -1;
143  NewlyAdded = false;
144  MayBeKilled = true;
145  return *this;
146  }
147 
149  const G4ParticleDefinition *aParticleDefinition )
150  { G4double aKineticEnergy = GetKineticEnergy();
151  G4double pp = GetMomentum().mag();
152  G4ThreeVector aMomentum = GetMomentum();
153  SetDefinition( aParticleDefinition );
154  SetKineticEnergy( aKineticEnergy );
155  if( pp > DBL_MIN )
156  SetMomentum( aMomentum * (std::sqrt(aKineticEnergy*aKineticEnergy +
157  2*aKineticEnergy*GetMass())/pp) );
158  }
159 
161  const G4ParticleDefinition *aParticleDefinition )
162  {
163  theParticleDefinition = aParticleDefinition;
164  mass = aParticleDefinition->GetPDGMass();
165  totalEnergy = mass;
166  kineticEnergy = 0.0;
167  (aParticleDefinition->GetPDGEncoding()<0) ?
168  timeOfFlight=-1.0 : timeOfFlight=1.0;
169  }
170 
172  const G4double x, const G4double y, const G4double z )
173  {
174  momentum.setX( x );
175  momentum.setY( y );
176  momentum.setZ( z );
177  }
178 
180  const G4double x, const G4double y )
181  {
182  momentum.setX( x );
183  momentum.setY( y );
184  }
185 
187  {
188  momentum.setZ( z );
189  }
190 
192  {
193  SetMomentum( 0.0, 0.0, 0.0 );
194  totalEnergy = 0.0;
195  kineticEnergy = 0.0;
196  mass = 0.0;
197  timeOfFlight = 0.0;
198  side = 0;
199  theCreatorModel = -1;
200  NewlyAdded = false;
201  SetPositionInNucleus( 0.0, 0.0, 0.0 );
202  formationTime = 0.0;
203  hasInitialStateParton = false;
204  }
205 
207  const G4ReactionProduct &p1, const G4ReactionProduct &p2 )
208  {
209  G4ThreeVector p1M = p1.momentum;
210  G4ThreeVector p2M = p2.momentum;
211  G4double p1x = p1M.x(); G4double p1y = p1M.y(); G4double p1z = p1M.z();
212  G4double p2x = p2M.x(); G4double p2y = p2M.y(); G4double p2z = p2M.z();
213  G4double a = ( (p1x*p2x+p1y*p2y+p1z*p2z)/(p2.totalEnergy+p2.mass) -
214  p1.totalEnergy ) / p2.mass;
215  G4double x = p1x+a*p2x;
216  G4double y = p1y+a*p2y;
217  G4double z = p1z+a*p2z;
218  G4double p = std::sqrt(x*x+y*y+z*z);
219  SetMass( p1.mass );
220  SetTotalEnergy( std::sqrt( (p1.mass+p)*(p1.mass+p) - 2.*p1.mass*p ) );
221  //SetTotalEnergy( std::sqrt( p1.mass*p1.mass + x*x + y*y + z*z ) );
222  SetMomentum( x, y, z );
223  }
224 
226  const G4ReactionProduct& p ) const
227  {
228  G4ThreeVector tM = momentum;
229  G4ThreeVector pM = p.momentum;
230  G4double tx = tM.x(); G4double ty = tM.y(); G4double tz = tM.z();
231  G4double px = pM.x(); G4double py = pM.y(); G4double pz = pM.z();
232  G4double a = std::sqrt( ( px*px + py*py + pz*pz ) * ( tx*tx + ty*ty + tz*tz ) );
233  if( a == 0.0 ) {
234  return 0.0;
235  } else {
236  a = ( tx*px + ty*py + tz*pz ) / a;
237  if( std::fabs(a) > 1.0 ) { a<0.0 ? a=-1.0 : a=1.0; }
238  return std::acos( a );
239  }
240  }
241 
243  const G4ReactionProduct& p1, const G4ReactionProduct& p2 )
244  {
245  G4double totEnergy = p1.totalEnergy + p2.totalEnergy;
246  G4double x = p1.momentum.x() + p2.momentum.x();
247  G4double y = p1.momentum.y() + p2.momentum.y();
248  G4double z = p1.momentum.z() + p2.momentum.z();
249  G4double newMass = totEnergy*totEnergy - ( x*x + y*y + z*z );
250  if( newMass < 0.0 )
251  newMass = -1. * std::sqrt( -newMass );
252  else
253  newMass = std::sqrt( newMass );
254  G4ReactionProduct result;
255  result.SetMass( newMass );
256  result.SetMomentum( x, y, z );
257  result.SetTotalEnergy( totEnergy );
258  result.SetPositionInNucleus( 0.0, 0.0, 0.0 );
259  result.SetFormationTime(0.0);
260  result.HasInitialStateParton(false);
261  return result;
262  }
263 
265  const G4ReactionProduct& p1, const G4ReactionProduct& p2 )
266  {
267  G4double totEnergy = p1.totalEnergy - p2.totalEnergy;
268  G4double x = p1.momentum.x() - p2.momentum.x();
269  G4double y = p1.momentum.y() - p2.momentum.y();
270  G4double z = p1.momentum.z() - p2.momentum.z();
271  G4double newMass = totEnergy*totEnergy - ( x*x + y*y + z*z );
272  if( newMass < 0.0 )
273  newMass = -1. * std::sqrt( -newMass );
274  else
275  newMass = std::sqrt( newMass );
276  G4ReactionProduct result;
277  result.SetMass( newMass );
278  result.SetMomentum( x, y, z );
279  result.SetTotalEnergy( totEnergy );
280  result.SetPositionInNucleus( 0.0, 0.0, 0.0 );
281  result.SetFormationTime(0.0);
282  result.HasInitialStateParton(false);
283  return result;
284  }
285  /* end of code */
286 
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:89
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
G4double Angle(const G4ReactionProduct &p) const
G4ReactionProduct & operator=(const G4ReactionProduct &right)
void SetMass(const G4double mas)
const G4ParticleDefinition * GetDefinition() const
G4ThreeVector momentum
G4double GetKineticEnergy() const
void SetTotalEnergy(const G4double en)
void SetDefinitionAndUpdateE(const G4ParticleDefinition *aParticleDefinition)
const G4LorentzVector & Get4Momentum() const
G4double GetKineticEnergy() const
const G4ParticleDefinition * theParticleDefinition
G4double GetPDGMass() const
G4ReactionProduct operator-(const G4ReactionProduct &p1, const G4ReactionProduct &p2)
const G4double x[NPOINTSGL]
#define DBL_MIN
Definition: templates.hh:75
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)