Geant4  10.02
G4InuclParticle.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: G4InuclParticle.cc 71719 2013-06-21 00:01:54Z mkelsey $
27 //
28 // 20100409 M. Kelsey -- Drop unused string argument from ctors.
29 // 20110721 M. Kelsey -- Add model ID as optional ctor argument (so subclasses
30 // don't have to call SetModel()).
31 // 20110922 M. Kelsey -- Add stream argument to printParticle() => print()
32 // 20130620 M. Kelsey -- Address Coverity #37504, check self in op=()
33 // 20130806 M. Kelsey -- Per A. Dotti, move empty G4DynPart to file scope to
34 // address thread-collision problem.
35 // 20140310 M. Kelsey -- Fix constness in G4PD* passing
36 
37 #include <cmath>
38 
39 #include "G4InuclParticle.hh"
40 #include "G4ios.hh"
41 #include "G4SystemOfUnits.hh"
42 
43 // Internal constructor only usable by subclasses
45  const G4LorentzVector& mom,
47  : modelId(model) {
48  setDefinition(pd);
49  setMomentum(mom);
50 }
51 
52 
53 // Assignment operator for use with std::sort()
55  if (this != &right) {
56  pDP = right.pDP;
57  modelId = right.modelId;
58  }
59 
60  return *this;
61 }
62 
63 
64 // Set particle definition allowing for null pointer to erase DynPart content
65 
66 namespace {
67  static const G4DynamicParticle empty; // To zero out everything
68 }
69 
71  if (pd) pDP.SetDefinition(pd);
72  else pDP = empty;
73 }
74 
75 
76 // WARNING! Bertini code doesn't do four-vectors; repair mass before use!
78  G4double mass = getMass();
79  if (std::fabs(mass-mom.m()) <= 1e-5)
80  pDP.Set4Momentum(mom*GeV/MeV); // From Bertini to G4 units
81  else
82  pDP.SetMomentum(mom.vect()*GeV/MeV); // Don't change current mass!
83 }
84 
85 
86 // Proper stream output (just calls print())
87 
88 std::ostream& operator<<(std::ostream& os, const G4InuclParticle& part) {
89  part.print(os);
90  return os;
91 }
92 
93 void G4InuclParticle::print(std::ostream& os) const {
95  os << " px " << mom.px() << " py " << mom.py() << " pz " << mom.pz()
96  << " pmod " << mom.rho() << " E " << mom.e()
97  << " creator model " << modelId;
98 }
99 
G4DynamicParticle pDP
static const double MeV
Definition: G4SIunits.hh:211
void SetMomentum(const G4ThreeVector &momentum)
G4LorentzVector getMomentum() const
std::ostream & operator<<(std::ostream &os, const G4InuclParticle &part)
void setDefinition(const G4ParticleDefinition *pd)
virtual void print(std::ostream &os) const
static const double GeV
Definition: G4SIunits.hh:214
void Set4Momentum(const G4LorentzVector &momentum)
G4InuclParticle & operator=(const G4InuclParticle &right)
void setMomentum(const G4LorentzVector &mom)
double G4double
Definition: G4Types.hh:76
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
G4double getMass() const
CLHEP::HepLorentzVector G4LorentzVector