Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Fragment.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//---------------------------------------------------------------------
29//
30// Geant4 class G4Fragment
31//
32// Hadronic Process: Nuclear De-excitations
33// by V. Lara (May 1998)
34//
35// Modifications:
36// 03.05.2010 V.Ivanchenko General cleanup; moved obsolete methods from
37// inline to source
38// 25.09.2010 M. Kelsey -- Change "setprecision" to "setwidth" in printout,
39// add null pointer check.
40
41#include "G4Fragment.hh"
43#include "G4Gamma.hh"
44#include "G4Electron.hh"
45#include "G4ios.hh"
46#include <iomanip>
47
48G4int G4Fragment::errCount = 0;
49
50// Default constructor
52 theA(0),
53 theZ(0),
54 theExcitationEnergy(0.0),
55 theGroundStateMass(0.0),
56 theMomentum(G4LorentzVector(0,0,0,0)),
57 theAngularMomentum(G4ThreeVector(0,0,0)),
58 numberOfParticles(0),
59 numberOfCharged(0),
60 numberOfHoles(0),
61 numberOfChargedHoles(0),
62 numberOfShellElectrons(0),
63 theParticleDefinition(0),
64 theCreationTime(0.0),
65 isStable(true)
66{}
67
68// Copy Constructor
70{
71 theA = right.theA;
72 theZ = right.theZ;
73 theExcitationEnergy = right.theExcitationEnergy;
74 theGroundStateMass = right.theGroundStateMass;
75 theMomentum = right.theMomentum;
76 theAngularMomentum = right.theAngularMomentum;
77 numberOfParticles = right.numberOfParticles;
78 numberOfCharged = right.numberOfCharged;
79 numberOfHoles = right.numberOfHoles;
80 numberOfChargedHoles = right.numberOfChargedHoles;
81 numberOfShellElectrons = right.numberOfShellElectrons;
82 theParticleDefinition = right.theParticleDefinition;
83 theCreationTime = right.theCreationTime;
84 isStable = right.isStable;
85}
86
88{}
89
91 theA(A),
92 theZ(Z),
93 theMomentum(aMomentum),
94 theAngularMomentum(G4ThreeVector(0,0,0)),
95 numberOfParticles(0),
96 numberOfCharged(0),
97 numberOfHoles(0),
98 numberOfChargedHoles(0),
99 numberOfShellElectrons(0),
100 theParticleDefinition(0),
101 theCreationTime(0.0),
102 isStable(true)
103{
104 theExcitationEnergy = 0.0;
105 theGroundStateMass = 0.0;
106 if(theA > 0) {
107 CalculateGroundStateMass();
108 CalculateExcitationEnergy();
109
110 // default flag of stability for excited fragments is false
111 // it may be overwritten by SetStable(G4bool val) method
112 if(theExcitationEnergy > 0.0) { isStable = false; }
113 }
114}
115
116// This constructor is for initialize photons or electrons
118 G4ParticleDefinition * aParticleDefinition) :
119 theA(0),
120 theZ(0),
121 theMomentum(aMomentum),
122 theAngularMomentum(G4ThreeVector(0,0,0)),
123 numberOfParticles(0),
124 numberOfCharged(0),
125 numberOfHoles(0),
126 numberOfChargedHoles(0),
127 numberOfShellElectrons(0),
128 theParticleDefinition(aParticleDefinition),
129 theCreationTime(0.0),
130 isStable(true)
131{
132 theExcitationEnergy = 0.0;
133 if(aParticleDefinition != G4Gamma::Gamma() &&
134 aParticleDefinition != G4Electron::Electron()) {
135 G4String text = "G4Fragment::G4Fragment constructor for gamma used for "
136 + aParticleDefinition->GetParticleName();
137 throw G4HadronicException(__FILE__, __LINE__, text);
138 }
139 theGroundStateMass = aParticleDefinition->GetPDGMass();
140}
141
143{
144 if (this != &right) {
145 theA = right.theA;
146 theZ = right.theZ;
147 theExcitationEnergy = right.theExcitationEnergy;
148 theGroundStateMass = right.theGroundStateMass;
149 theMomentum = right.theMomentum;
150 theAngularMomentum = right.theAngularMomentum;
151 numberOfParticles = right.numberOfParticles;
152 numberOfCharged = right.numberOfCharged;
153 numberOfHoles = right.numberOfHoles;
154 numberOfChargedHoles = right.numberOfChargedHoles;
155 numberOfShellElectrons = right.numberOfShellElectrons;
156 theParticleDefinition = right.theParticleDefinition;
157 theCreationTime = right.theCreationTime;
158 isStable = right.isStable;
159 }
160 return *this;
161}
162
164{
165 return (this == (G4Fragment *) &right);
166}
167
169{
170 return (this != (G4Fragment *) &right);
171}
172
173std::ostream& operator << (std::ostream &out, const G4Fragment *theFragment)
174{
175 if (!theFragment) {
176 out << "Fragment: null pointer ";
177 return out;
178 }
179
180 std::ios::fmtflags old_floatfield = out.flags();
181 out.setf(std::ios::floatfield);
182
183 out << "Fragment: A = " << std::setw(3) << theFragment->theA
184 << ", Z = " << std::setw(3) << theFragment->theZ ;
185 out.setf(std::ios::scientific,std::ios::floatfield);
186
187 // Store user's precision setting and reset to (3) here: back-compatibility
188 std::streamsize floatPrec = out.precision();
189
190 out << std::setprecision(3)
191 << ", U = " << theFragment->GetExcitationEnergy()/CLHEP::MeV
192 << " MeV IsStable= " << theFragment->IsStable() << G4endl
193 << " P = ("
194 << theFragment->theMomentum.x()/CLHEP::MeV << ","
195 << theFragment->theMomentum.y()/CLHEP::MeV << ","
196 << theFragment->theMomentum.z()/CLHEP::MeV
197 << ") MeV E = "
198 << theFragment->theMomentum.t()/CLHEP::MeV << " MeV"
199 << G4endl;
200
201 // What about Angular momentum???
202
203 if (theFragment->GetNumberOfExcitons() != 0) {
204 out << " "
205 << "#Particles= " << theFragment->numberOfParticles
206 << ", #Charged= " << theFragment->numberOfCharged
207 << ", #Holes= " << theFragment->numberOfHoles
208 << ", #ChargedHoles= " << theFragment->numberOfChargedHoles
209 << G4endl;
210 }
211 out.setf(old_floatfield,std::ios::floatfield);
212 out.precision(floatPrec);
213
214 return out;
215}
216
217std::ostream& operator << (std::ostream &out, const G4Fragment &theFragment)
218{
219 out << &theFragment;
220 return out;
221}
222
223void G4Fragment::ExcitationEnergyWarning()
224{
225 if (theExcitationEnergy < -10 * CLHEP::eV) {
226 ++errCount;
227 if ( errCount <= 1 ) {
228 G4cout << "G4Fragment::CalculateExcitationEnergy(): WARNING "<<G4endl;
229 G4cout << *this << G4endl;
230 if( errCount == 10 ) {
231 G4String text = "G4Fragment::G4Fragment Excitation Energy < 0.0 10 times!";
232 throw G4HadronicException(__FILE__, __LINE__, text);
233 }
234 }
235 }
236 theExcitationEnergy = 0.0;
237}
238
239void G4Fragment::NumberOfExitationWarning(const G4String& value)
240{
241 G4cout << "G4Fragment::"<< value << " ERROR "
242 << G4endl;
243 G4cout << this << G4endl;
244 G4String text = "G4Fragment::G4Fragment wrong exciton number ";
245 throw G4HadronicException(__FILE__, __LINE__, text);
246}
std::ostream & operator<<(std::ostream &out, const G4Fragment *theFragment)
Definition: G4Fragment.cc:173
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
static G4Electron * Electron()
Definition: G4Electron.cc:94
G4double GetExcitationEnergy() const
Definition: G4Fragment.hh:235
G4bool operator!=(const G4Fragment &right) const
Definition: G4Fragment.cc:168
G4bool IsStable() const
Definition: G4Fragment.hh:388
G4int GetNumberOfExcitons() const
Definition: G4Fragment.hh:300
G4Fragment & operator=(const G4Fragment &right)
Definition: G4Fragment.cc:142
G4bool operator==(const G4Fragment &right) const
Definition: G4Fragment.cc:163
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
const G4String & GetParticleName() const