Geant4  10.00.p01
G4InuclNuclei.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: G4InuclNuclei.cc 71719 2013-06-21 00:01:54Z mkelsey $
27 //
28 // 20100301 M. Kelsey -- Add function to create unphysical nuclei for use
29 // as temporary final-state fragments.
30 // 20100319 M. Kelsey -- Add information message to makeNuclearFragment().
31 // Use new GetBindingEnergy() function instead of bindingEnergy().
32 // 20100622 M. Kelsey -- Use local "bindingEnergy()" function to call through.
33 // 20100627 M. Kelsey -- Test for non-physical fragments and abort job.
34 // 20100630 M. Kelsey -- Use excitation energy in G4Ions
35 // 20100714 M. Kelsey -- Use G4DynamicParticle::theDynamicalMass to deal with
36 // excitation energy without instantianting "infinite" G4PartDefns.
37 // 20100719 M. Kelsey -- Change excitation energy without altering momentum
38 // 20100906 M. Kelsey -- Add fill() functions to rewrite contents
39 // 20100910 M. Kelsey -- Add clearExitonConfiguration() to fill() functions
40 // 20100914 M. Kelsey -- Make printout symmetric with G4InuclElemPart,
41 // migrate to integer A and Z
42 // 20100924 M. Kelsey -- Add constructor to copy G4Fragment input, and output
43 // functions to create G4Fragment
44 // 20110214 M. Kelsey -- Replace integer "model" with enum
45 // 20110308 M. Kelsey -- Follow new G4Fragment interface for hole types
46 // 20110427 M. Kelsey -- Remove PDG-code warning
47 // 20110721 M. Kelsey -- Follow base-class ctor change to pass model directly
48 // 20110829 M. Kelsey -- Add constructor to copy G4V3DNucleus input
49 // 20110919 M. Kelsey -- Special case: Allow fill(A=0,Z=0) to make dummy
50 // 20110922 M. Kelsey -- Add stream argument to printParticle() => print()
51 // 20121009 M. Kelsey -- Add report of excitons if non-empty
52 // 20130314 M. Kelsey -- Use G4IonList typedef for fragment map, encapsulate
53 // it in a static function with mutexes.
54 // 20130620 M. Kelsey -- Address Coverity #37503, check self in op=()
55 
56 #include "G4InuclNuclei.hh"
57 #include "G4AutoLock.hh"
58 #include "G4Fragment.hh"
59 #include "G4HadronicException.hh"
61 #include "G4IonTable.hh"
62 #include "G4Ions.hh"
63 #include "G4NucleiProperties.hh"
64 #include "G4Nucleon.hh"
65 #include "G4ParticleDefinition.hh"
66 #include "G4ParticleTable.hh"
67 #include "G4SystemOfUnits.hh"
68 #include "G4Threading.hh"
69 #include "G4V3DNucleus.hh"
70 
71 #include <assert.h>
72 #include <sstream>
73 #include <map>
74 
75 using namespace G4InuclSpecialFunctions;
76 
77 
78 // Convert contents from (via constructor) and to G4Fragment
79 
82  : G4InuclParticle() {
83  copy(aFragment, model);
84 }
85 
86 void G4InuclNuclei::copy(const G4Fragment& aFragment, Model model) {
87  fill(aFragment.GetMomentum()/GeV, aFragment.GetA_asInt(),
88  aFragment.GetZ_asInt(), aFragment.GetExcitationEnergy(), model);
89 
90  // Exciton configuration must be set by hand
92 
94  aFragment.GetNumberOfParticles() - aFragment.GetNumberOfCharged();
95 
97 
100 }
101 
102 
103 // FIXME: Should we have a local buffer and return by const-reference instead?
105  G4Fragment frag(getA(), getZ(), getMomentum()*GeV); // From Bertini units
106 
107  // Note: exciton configuration has to be set piece by piece
111 
115 
116  return frag;
117 }
118 
119 G4InuclNuclei::operator G4Fragment() const {
120  return makeG4Fragment();
121 }
122 
123 
124 // Convert contents from (via constructor) G4V3DNucleus
125 
128  : G4InuclParticle() {
129  copy(a3DNucleus, model);
130 }
131 
132 void G4InuclNuclei::copy(G4V3DNucleus* a3DNucleus, Model model) {
133  if (!a3DNucleus) return; // Null pointer means no action
134 
135  fill(0., a3DNucleus->GetMassNumber(), a3DNucleus->GetCharge(), 0., model);
136 
137  // Convert every hit nucleon into an exciton hole
138  if (a3DNucleus->StartLoop()) {
139  G4Nucleon* nucl = 0;
140  while ((nucl = a3DNucleus->GetNextNucleon())) {
141  if (nucl->AreYouHit()) { // Found previously interacted nucleon
142  if (nucl->GetParticleType() == G4Proton::Definition())
144 
145  if (nucl->GetParticleType() == G4Neutron::Definition())
147  }
148  }
149  }
150 }
151 
152 
153 // Overwrite data structure (avoids creating/copying temporaries)
154 
156  G4double exc, G4InuclParticle::Model model) {
158  setMomentum(mom);
159  setExitationEnergy(exc);
161  setModel(model);
162 }
163 
165  G4InuclParticle::Model model) {
167  setKineticEnergy(ekin);
168  setExitationEnergy(exc);
170  setModel(model);
171 }
172 
174  setDefinition(0);
177 }
178 
179 
180 // Change excitation energy while keeping momentum vector constant
181 
183  G4double ekin = getKineticEnergy(); // Current kinetic energy
184 
185  G4double emass = getNucleiMass() + e*MeV/GeV; // From Bertini to G4 units
186 
187  // Directly compute new kinetic energy from old
188  G4double ekin_new = std::sqrt(emass*emass + ekin*(2.*getMass()+ekin)) - emass;
189 
190  setMass(emass); // Momentum is computed from mass and Ekin
191  setKineticEnergy(ekin_new);
192 }
193 
194 
195 // Convert nuclear configuration to standard GEANT4 pointer
196 
197 // WARNING: Opposite conventions! G4InuclNuclei uses (A,Z) everywhere, while
198 // G4ParticleTable::GetIon() uses (Z,A)!
199 
201  // SPECIAL CASE: (0,0) means create dummy without definition
202  if (0 == a && 0 == z) return 0;
203 
205  G4ParticleDefinition *pd = pTable->GetIonTable()->GetIon(z, a, 0);
206 
207  // SPECIAL CASE: Non-physical nuclear fragment, for final-state return
208  if (!pd) pd = makeNuclearFragment(a,z);
209 
210  return pd; // This could return a null pointer if above fails
211 }
212 
213 
214 // Shared buffer of nuclear fragments created below, to avoid memory leaks
215 
216 namespace {
217  static std::map<G4int,G4ParticleDefinition*> fragmentList;
218  G4Mutex fragListMutex = G4MUTEX_INITIALIZER;
219 }
220 
221 // Creates a non-physical pseudo-nucleus, for return as final-state fragment
222 // from G4IntraNuclearCascader
223 
226  if (a<=0 || z<0 || a<z) {
227  G4cerr << " >>> G4InuclNuclei::makeNuclearFragment() called with"
228  << " impossible arguments A=" << a << " Z=" << z << G4endl;
229  throw G4HadronicException(__FILE__, __LINE__,
230  "G4InuclNuclei impossible A/Z arguments");
231  }
232 
234 
235  // Use local lookup table (see above) to maintain singletons
236  // NOTE: G4ParticleDefinitions don't need to be explicitly deleted
237  // (see comments in G4IonTable.cc::~G4IonTable)
238 
239  G4AutoLock fragListLock(&fragListMutex);
240  if (fragmentList.find(code) != fragmentList.end()) return fragmentList[code];
241  fragListLock.unlock();
242 
243  // Name string follows format in G4IonTable.cc::GetIonName(Z,A,E)
244  std::stringstream zstr, astr;
245  zstr << z;
246  astr << a;
247 
248  G4String name = "Z" + zstr.str() + "A" + astr.str();
249 
250  G4double mass = getNucleiMass(a,z) *GeV/MeV; // From Bertini to GEANT4 units
251 
252  // Arguments for constructor are as follows
253  // name mass width charge
254  // 2*spin parity C-conjugation
255  // 2*Isospin 2*Isospin3 G-parity
256  // type lepton number baryon number PDG encoding
257  // stable lifetime decay table
258  // shortlived subType anti_encoding Excitation-energy
259 
260  G4Ions* fragPD = new G4Ions(name, mass, 0., z*eplus,
261  0, +1, 0,
262  0, 0, 0,
263  "nucleus", 0, a, code,
264  true, 0., 0,
265  true, "generic", 0, 0.);
266  fragPD->SetAntiPDGEncoding(0);
267 
268  fragListLock.lock(); // Protect before saving new fragment
269  return (fragmentList[code] = fragPD); // Store in table for next lookup
270 }
271 
273  // Simple minded mass calculation use constants in CLHEP (all in MeV)
275 
276  return mass*MeV/GeV; // Convert from GEANT4 to Bertini units
277 }
278 
279 // Assignment operator for use with std::sort()
281  if (this != &right) {
284  }
285  return *this;
286 }
287 
288 // Dump particle properties for diagnostics
289 
290 void G4InuclNuclei::print(std::ostream& os) const {
292  os << G4endl << " Nucleus: " << getDefinition()->GetParticleName()
293  << " A " << getA() << " Z " << getZ() << " mass " << getMass()
294  << " Eex (MeV) " << getExitationEnergy();
295 
297  os << G4endl << " " << theExitonConfiguration;
298 }
void fill(G4int a, G4int z, G4double exc=0., Model model=DefaultModel)
static const double MeV
Definition: G4SIunits.hh:193
static G4double GetNuclearMass(const G4double A, const G4double Z)
G4int getZ() const
virtual G4int GetCharge()=0
void SetAntiPDGEncoding(G4int aEncoding)
G4LorentzVector getMomentum() const
virtual G4bool StartLoop()=0
G4double z
Definition: TRTMaterials.hh:39
G4InuclNuclei & operator=(const G4InuclNuclei &right)
G4String name
Definition: TRTMaterials.hh:40
G4ParticleDefinition * GetIon(G4int Z, G4int A, G4int lvl=0)
Definition: G4IonTable.cc:449
virtual G4int GetMassNumber()=0
void SetNumberOfHoles(G4int valueTot, G4int valueP=0)
Definition: G4Fragment.hh:355
static G4int GetNucleusEncoding(G4int Z, G4int A, G4double E=0.0, G4int lvl=0)
Definition: G4IonTable.cc:854
G4int GetNumberOfParticles() const
Definition: G4Fragment.hh:325
G4double a
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:158
const G4String & GetParticleName() const
G4double getKineticEnergy() const
static G4Proton * Definition()
Definition: G4Proton.cc:49
void setExitationEnergy(G4double e)
G4int GetNumberOfHoles() const
Definition: G4Fragment.hh:345
void SetNumberOfExcitedParticle(G4int valueTot, G4int valueP)
Definition: G4Fragment.hh:336
G4IonTable * GetIonTable() const
G4int GetA_asInt() const
Definition: G4Fragment.hh:238
virtual void print(std::ostream &os) const
G4int getA() const
Definition: G4Ions.hh:51
const G4LorentzVector & GetMomentum() const
Definition: G4Fragment.hh:271
G4bool AreYouHit() const
Definition: G4Nucleon.hh:97
G4double getNucleiMass() const
void copy(const G4Fragment &aFragment, Model model=DefaultModel)
G4double getExitationEnergy() const
static const double GeV
Definition: G4SIunits.hh:196
virtual void print(std::ostream &os) const
void setDefinition(G4ParticleDefinition *pd)
G4int G4Mutex
Definition: G4Threading.hh:156
static G4ParticleTable * GetParticleTable()
G4Fragment makeG4Fragment() const
void clearExitonConfiguration()
static G4Neutron * Definition()
Definition: G4Neutron.cc:54
G4int GetZ_asInt() const
Definition: G4Fragment.hh:243
G4InuclParticle & operator=(const G4InuclParticle &right)
void setMass(G4double mass)
void setModel(Model model)
#define G4endl
Definition: G4ios.hh:61
G4ParticleDefinition * GetParticleType() const
Definition: G4Nucleon.hh:84
G4int GetNumberOfChargedHoles() const
Definition: G4Fragment.hh:350
virtual G4Nucleon * GetNextNucleon()=0
void setKineticEnergy(G4double ekin)
static G4ParticleDefinition * makeDefinition(G4int a, G4int z)
void setMomentum(const G4LorentzVector &mom)
double G4double
Definition: G4Types.hh:76
G4ExitonConfiguration theExitonConfiguration
static const double eplus
Definition: G4SIunits.hh:178
static G4ParticleDefinition * makeNuclearFragment(G4int a, G4int z)
G4ParticleDefinition * getDefinition() const
G4int GetNumberOfCharged() const
Definition: G4Fragment.hh:330
G4double GetExcitationEnergy() const
Definition: G4Fragment.hh:255
G4GLOB_DLL std::ostream G4cerr
G4double getMass() const
CLHEP::HepLorentzVector G4LorentzVector