Index: trunk/source/processes/hadronic/models/util/include/G4Fragment.hh
===================================================================
--- trunk/source/processes/hadronic/models/util/include/G4Fragment.hh	(revision 1228)
+++ trunk/source/processes/hadronic/models/util/include/G4Fragment.hh	(revision 1315)
@@ -24,8 +24,21 @@
 // ********************************************************************
 //
-//
-//
-// Hadronic Process: Nuclear De-excitations
+// $Id: G4Fragment.hh,v 1.11 2010/05/19 10:23:00 vnivanch Exp $
+// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
+//
+//---------------------------------------------------------------------
+//
+// Geant4 header G4Fragment
+//
 // by V. Lara (May 1998)
+//
+// Modifications:
+// 03.05.2010 V.Ivanchenko General cleanup of inline functions: objects 
+//            are accessed by reference; remove double return 
+//            tolerance of excitation energy at modent it is computed;
+//            safe computation of excitation for exotic fragments
+// 18.05.2010 V.Ivanchenko added member theGroundStateMass and inline
+//            method which allowing to compute this value once and use 
+//            many times
 
 #ifndef G4Fragment_h
@@ -38,5 +51,5 @@
 #include "globals.hh"
 #include "G4LorentzVector.hh"
-#include "G4ParticleMomentum.hh"
+//#include "G4ParticleMomentum.hh"
 #include "G4ThreeVector.hh"
 #include "G4NucleiProperties.hh"
@@ -61,5 +74,5 @@
   // ============= CONSTRUCTORS ==================
 
-  // Default constructor
+  // Default constructor - obsolete
   G4Fragment();
 
@@ -70,11 +83,9 @@
   G4Fragment(const G4Fragment &right);
 
-  // Several constructors
-
-  // A,Z and 4-momentum
-  G4Fragment(const G4int A, const G4int Z, const G4LorentzVector aMomentum);
+  // A,Z and 4-momentum - main constructor for fragment
+  G4Fragment(const G4int A, const G4int Z, const G4LorentzVector& aMomentum);
 
   // 4-momentum and pointer to G4particleDefinition (for gammas)
-  G4Fragment(const G4LorentzVector aMomentum, G4ParticleDefinition * aParticleDefinition);
+  G4Fragment(const G4LorentzVector& aMomentum, G4ParticleDefinition * aParticleDefinition);
 
   // ============= OPERATORS ==================
@@ -89,65 +100,74 @@
   // ============= METHODS ==================
 
-  inline G4double GetA(void) const;
-  void SetA(const G4double value);
-  
-  G4double GetZ(void) const;
-  void SetZ(const G4double value);
-  
-  G4double GetExcitationEnergy(void) const;
+  inline G4double GetA() const;
+  inline void SetA(const G4double value);
+  
+  inline G4double GetZ() const;
+  inline void SetZ(const G4double value);
+
+  inline G4int GetZ_asInt() const;
+  inline G4int GetA_asInt() const;
+  inline void SetZandA_asInt(G4int Znew, G4int Anew);
+  
+  inline G4double GetExcitationEnergy() const;
   void SetExcitationEnergy(const G4double value);
   
-  const G4LorentzVector GetMomentum(void) const;
-  void SetMomentum(const G4LorentzVector value);
-  
-  const G4ThreeVector GetAngularMomentum(void) const;
-  void SetAngularMomentum(const G4ThreeVector value);
-  
-  G4int GetNumberOfExcitons(void) const;
-  //  void SetNumberOfExcitons(const G4int value);
-  
-  G4int GetNumberOfHoles(void) const;
-  void SetNumberOfHoles(const G4int value);
-  
-  G4int GetNumberOfCharged(void) const;
+  inline const G4LorentzVector& GetMomentum() const;
+  inline void SetMomentum(const G4LorentzVector& value);
+  
+  inline const G4ThreeVector& GetAngularMomentum() const;
+  inline void SetAngularMomentum(const G4ThreeVector& value);
+  
+  inline G4int GetNumberOfExcitons() const;
+  
+  inline G4int GetNumberOfHoles() const;
+  inline void SetNumberOfHoles(const G4int value);
+  
+  inline G4int GetNumberOfCharged() const;
   void SetNumberOfCharged(const G4int value);
 
-  G4int GetNumberOfParticles(void) const;
-  void SetNumberOfParticles(const G4int value);
-
-  inline G4ParticleDefinition * GetParticleDefinition(void) const;
-  void SetParticleDefinition(G4ParticleDefinition * aParticleDefinition);
-
-  G4double GetCreationTime(void) const;
-  void SetCreationTime(const G4double time);
-
-
-// Some utility methods
-
-  inline G4double GetGroundStateMass(void) const;
-  
-  inline G4double GetBindingEnergy(void) const;
+  inline G4int GetNumberOfParticles() const;
+  inline void SetNumberOfParticles(const G4int value);
+
+  inline G4ParticleDefinition * GetParticleDefinition() const;
+  inline void SetParticleDefinition(G4ParticleDefinition * aParticleDefinition);
+
+  inline G4double GetCreationTime() const;
+  inline void SetCreationTime(const G4double time);
+
+  inline G4double GetGroundStateMass() const;
+   
+  inline G4double GetBindingEnergy() const;
+
+  // computation of mass for any Z and A
+  inline G4double ComputeGroundStateMass(const G4int Z, const G4int A) const;
 
 #ifdef PRECOMPOUND_TEST 
-  G4String GetCreatorModel() const { return theCreatorModel; }
-  void SetCreatorModel(const G4String & aModel) 
-  { theCreatorModel = aModel; }
+  G4String GetCreatorModel() const;
+  void SetCreatorModel(const G4String & aModel); 
 #endif
 
 private:
 
-  G4double CalculateExcitationEnergy(const G4LorentzVector value) const;
+  void ExcitationEnegryWarning();
+
+  inline void CalculateGroundStateMass();
+
+  inline void CalculateExcitationEnergy();
 
   G4ThreeVector IsotropicRandom3Vector(const G4double Magnitude = 1.0) const;
   
-
   // ============= DATA MEMBERS ==================
 
-  G4double theA;
-  
-  G4double theZ;
+  static G4int errCount;
+
+  G4int theA;
+  
+  G4int theZ;
   
   G4double theExcitationEnergy;
 
+  G4double theGroundStateMass;
+
   G4LorentzVector theMomentum;
   
@@ -159,5 +179,4 @@
   
   G4int numberOfCharged;
-
 
   // Gamma evaporation requeriments
@@ -173,23 +192,46 @@
 
 // Class G4Fragment 
+inline void G4Fragment::CalculateGroundStateMass() 
+{
+  theGroundStateMass = G4NucleiProperties::GetNuclearMass(theA, theZ);
+}
 
 inline G4double G4Fragment::GetA() const
 {
+  return G4double(theA);
+}
+
+inline void G4Fragment::SetA(const G4double value)
+{
+  theA = G4lrint(value);
+  CalculateGroundStateMass();
+}
+
+inline G4double G4Fragment::GetZ()  const
+{
+  return G4double(theZ);
+}
+
+inline void G4Fragment::SetZ(const G4double value)
+{
+  theZ = G4lrint(value);
+  CalculateGroundStateMass();
+}
+
+inline G4int G4Fragment::GetA_asInt() const
+{
   return theA;
 }
 
-inline void G4Fragment::SetA(const G4double value)
-{
-  theA = value;
-}
-
-inline G4double G4Fragment::GetZ()  const
+inline G4int G4Fragment::GetZ_asInt()  const
 {
   return theZ;
 }
 
-inline void G4Fragment::SetZ(const G4double value)
-{
-  theZ = value;
+inline void G4Fragment::SetZandA_asInt(G4int Znew, G4int Anew)
+{
+  theZ = Znew;
+  theA = Anew;
+  CalculateGroundStateMass();
 }
 
@@ -200,31 +242,19 @@
   // HPW Apr 1999 @@@@@@@ 
   
-  if(std::abs(theExcitationEnergy)<10*eV) return 0; 
+  //VI  if(std::abs(theExcitationEnergy)<10*eV) return 0; 
   return theExcitationEnergy;
 }
 
-inline void G4Fragment::SetExcitationEnergy(const G4double )
-{
-  //   theExcitationEnergy = value;
-  G4cout << "Warning: G4Fragment::SetExcitationEnergy() is a dummy method. Please, avoid to use it." << G4endl;
-}
-
-inline const G4LorentzVector G4Fragment::GetMomentum()  const
+inline const G4LorentzVector& G4Fragment::GetMomentum()  const
 {
   return theMomentum;
 }
 
-inline void G4Fragment::SetMomentum(const G4LorentzVector value)
-{
-  theMomentum = value;
-  theExcitationEnergy = CalculateExcitationEnergy(value);
-}
-
-inline const G4ThreeVector G4Fragment::GetAngularMomentum()  const
+inline const G4ThreeVector& G4Fragment::GetAngularMomentum()  const
 {
   return theAngularMomentum;
 }
 
-inline void G4Fragment::SetAngularMomentum(const G4ThreeVector value)
+inline void G4Fragment::SetAngularMomentum(const G4ThreeVector& value)
 {
   theAngularMomentum = value;
@@ -258,9 +288,9 @@
 inline void G4Fragment::SetNumberOfCharged(const G4int value)
 {
-  if (value <= numberOfParticles) numberOfCharged = value;
+  if (value <= numberOfParticles) { numberOfCharged = value; }
   else 
   {
-  G4String text = "G4Fragment::SetNumberOfCharged: Number of charged particles can't be greater than number of particles";
-	  throw G4HadronicException(__FILE__, __LINE__, text);
+    G4String text = "G4Fragment::SetNumberOfCharged: Number of charged particles can't be greater than number of particles";
+    throw G4HadronicException(__FILE__, __LINE__, text);
   }
 }
@@ -271,5 +301,4 @@
 }
 
-
 inline G4ParticleDefinition * G4Fragment::GetParticleDefinition(void) const
 {
@@ -282,6 +311,5 @@
 }
 
-
-inline G4double G4Fragment::GetCreationTime(void) const 
+inline G4double G4Fragment::GetCreationTime() const 
 {
   return theCreationTime;
@@ -293,17 +321,32 @@
 }
 
-inline G4double G4Fragment::GetGroundStateMass(void) const
-{
-	if (theA == 0) return 0.0; // photon
-	else return G4ParticleTable::GetParticleTable()->
-		    GetIonTable()->GetIonMass(G4lrint(theZ),G4lrint(theA));
+inline G4double G4Fragment::GetGroundStateMass() const
+{
+  return theGroundStateMass; 
+}
+
+inline G4double 
+G4Fragment::ComputeGroundStateMass(const G4int Z, const G4int A) const
+{
+  return G4NucleiProperties::GetNuclearMass(A, Z); 
+}
+
+inline void G4Fragment::CalculateExcitationEnergy()
+{
+  theExcitationEnergy = theMomentum.mag() - theGroundStateMass;
+  if(theExcitationEnergy < 0.0) { ExcitationEnegryWarning(); }
 }
 	
-inline G4double G4Fragment::GetBindingEnergy(void) const
-{
-	return -GetGroundStateMass()+(theA-theZ)*G4Neutron::Neutron()->GetPDGMass()
-										 + theZ*G4Proton::Proton()->GetPDGMass();
-}
-
+inline G4double G4Fragment::GetBindingEnergy() const
+{
+  return (theA-theZ)*CLHEP::neutron_mass_c2 + theZ*CLHEP::proton_mass_c2 
+    - theGroundStateMass;
+}
+
+inline void G4Fragment::SetMomentum(const G4LorentzVector& value)
+{
+  theMomentum = value;
+  CalculateExcitationEnergy();
+}
 
 #endif
