Index: trunk/source/processes/electromagnetic/lowenergy/src/G4CrossSectionExcitationMillerGreenPartial.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4CrossSectionExcitationMillerGreenPartial.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4CrossSectionExcitationMillerGreenPartial.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4CrossSectionExcitationMillerGreenPartial.cc,v 1.2 2008/07/14 20:47:34 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4CrossSectionExcitationMillerGreenPartial.cc,v 1.3 2009/01/20 07:40:53 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 
 #include "G4CrossSectionExcitationMillerGreenPartial.hh"
@@ -115,4 +115,8 @@
   tCorrected = k * kineticEnergyCorrection[particleTypeIndex];
 
+  // SI - added protection 
+  if (tCorrected < waterExcitation.ExcitationEnergy(excitationLevel)) return 0;
+  //
+  
   G4int z = 10;
 
@@ -158,5 +162,7 @@
   // ELECTRON CORRECTION
  
-  if ( particle == instance->GetIon("alpha++"))
+  if ( particle == instance->GetIon("alpha++")||
+       particle == G4Proton::ProtonDefinition())
+       
   {  while (i > 0)
      {
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4CrossSectionIonisationBornPartial.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4CrossSectionIonisationBornPartial.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4CrossSectionIonisationBornPartial.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4CrossSectionIonisationBornPartial.cc,v 1.4 2008/07/14 20:47:34 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4CrossSectionIonisationBornPartial.cc,v 1.5 2009/01/20 07:40:53 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 
 #include "G4CrossSectionIonisationBornPartial.hh"
@@ -33,5 +33,5 @@
 G4CrossSectionIonisationBornPartial::G4CrossSectionIonisationBornPartial()
 {
-  lowEnergyLimitDefault = 25 * eV;
+  lowEnergyLimitDefault = 12.61 * eV;
   highEnergyLimitDefault = 30 * keV;
 
@@ -52,5 +52,5 @@
     tableFile[electron] = fileElectron;
 
-    lowEnergyLimit[electron] = 25. * eV;
+    lowEnergyLimit[electron] = 12.61 * eV;
     highEnergyLimit[electron] = 30. * keV;
 
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateChargeDecrease.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateChargeDecrease.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateChargeDecrease.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4FinalStateChargeDecrease.cc,v 1.3 2008/07/14 20:47:34 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4FinalStateChargeDecrease.cc,v 1.4 2009/01/20 07:50:28 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 
 #include "G4FinalStateChargeDecrease.hh"
@@ -70,7 +70,11 @@
   }
   
+  //SI - Added protection against total energy deposit
+  product.DoNotDepositEnergy();
+  //
   product.KillPrimaryParticle();
+
   product.AddEnergyDeposit(waterBindingEnergy);
-  
+
   G4DynamicParticle* aSecondary = new G4DynamicParticle(OutgoingParticleDefinition(definition, finalStateIndex), 
 							track.GetDynamicParticle()->GetMomentumDirection(), 
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateChargeIncrease.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateChargeIncrease.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateChargeIncrease.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4FinalStateChargeIncrease.cc,v 1.3 2008/07/14 20:47:34 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4FinalStateChargeIncrease.cc,v 1.4 2009/01/20 07:50:28 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 
 #include "G4FinalStateChargeIncrease.hh"
@@ -48,6 +48,10 @@
   product.Clear();
 
+  //SI - Added protection against total energy deposit
+  product.DoNotDepositEnergy();
+  //
   product.KillPrimaryParticle();
   product.AddEnergyDeposit(0.);
+
   G4ParticleDefinition* definition = track.GetDefinition();
  
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateProduct.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateProduct.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4FinalStateProduct.cc	(revision 1005)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4FinalStateProduct.cc,v 1.5 2007/11/09 20:11:04 pia Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4FinalStateProduct.cc,v 1.6 2009/01/20 07:50:28 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 // 
 // Contact Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
@@ -53,5 +53,5 @@
 #include "G4ThreeVector.hh"
 
-G4FinalStateProduct::G4FinalStateProduct() : killStatus(false), isModified(false), localEnergyDeposit(0.), modifiedEnergy(0)
+G4FinalStateProduct::G4FinalStateProduct() : killStatus(false), doNotDepositStatus(false), isModified(false), localEnergyDeposit(0.), modifiedEnergy(0)
 {
   // empty
@@ -68,4 +68,5 @@
   // Reset object status
   killStatus = false;
+  doNotDepositStatus = false;
   isModified = false;
   localEnergyDeposit = 0.;
@@ -98,6 +99,12 @@
 }
   
+void G4FinalStateProduct::DoNotDepositEnergy()
+{
+  doNotDepositStatus = true;
+}
+
 void G4FinalStateProduct::KillPrimaryParticle()
 {
+  
   // ---- MGP ---- To be added: Handle local energy deposit here
   killStatus = true;
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4IonParametrisedLossModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4IonParametrisedLossModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4IonParametrisedLossModel.cc	(revision 1005)
@@ -37,5 +37,5 @@
 // First implementation: 10. 11. 2008
 //
-// Modifications:
+// Modifications: 03. 02. 2009 - Bug fix iterators (AL)
 //
 //
@@ -107,5 +107,5 @@
   dedxCacheMaterial = 0;
   dedxCacheEnergyCut = 0;
-  dedxCacheIter = lossTableList.begin();
+  dedxCacheIter = lossTableList.end();
   dedxCacheTransitionEnergy = 0.0;  
   dedxCacheTransitionFactor = 0.0;
@@ -166,5 +166,5 @@
   dedxCacheMaterial = 0;
   dedxCacheEnergyCut = 0;
-  dedxCacheIter = lossTableList.begin();
+  dedxCacheIter = lossTableList.end();
   dedxCacheTransitionEnergy = 0.0;  
   dedxCacheTransitionFactor = 0.0;
@@ -342,5 +342,5 @@
   LossTableList::iterator iter = dedxCacheIter;
 
-  if(iter != lossTableList.begin()) {
+  if(iter != lossTableList.end()) {
 
      G4double transitionEnergy = dedxCacheTransitionEnergy;
@@ -672,5 +672,5 @@
 
      // If any table is applicable, the transition factor is computed:
-     if(iter != lossTableList.begin()) {
+     if(iter != lossTableList.end()) {
 
         // Retrieving the transition energy from the parameterisation table
@@ -777,5 +777,5 @@
   // If parameterization for ions is available the electronic energy loss
   // is overwritten
-  if(iter != lossTableList.begin()) {
+  if(iter != lossTableList.end()) {
 
      // The energy loss is calculated using the ComputeDEDXPerVolume function
@@ -854,5 +854,5 @@
   G4double transitionEnergy = dedxCacheTransitionEnergy;
 
-  if(iter != lossTableList.begin() && transitionEnergy < kineticEnergy) {
+  if(iter != lossTableList.end() && transitionEnergy < kineticEnergy) {
      chargeSquareRatio *= corrections -> EffectiveChargeCorrection(particle,
                                                                 material,
@@ -862,5 +862,5 @@
      eloss *= chargeSquareRatioCorr;
   }
-  else if (iter == lossTableList.begin()) {
+  else if (iter == lossTableList.end()) {
 
      chargeSquareRatio *= corrections -> EffectiveChargeCorrection(particle,
@@ -875,5 +875,5 @@
   // overwrite the energy loss (i.e. when the effective charge approach is
   // used)
-  if(iter == lossTableList.begin()) {
+  if(iter == lossTableList.end()) {
 
      G4double scaledKineticEnergy = kineticEnergy * dedxCacheGenIonMassRatio;
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreComptonModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreComptonModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreComptonModel.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4LivermoreComptonModel.cc,v 1.1 2008/10/30 14:17:46 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4LivermoreComptonModel.cc,v 1.2 2009/01/21 10:58:13 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 
@@ -38,5 +38,5 @@
 G4LivermoreComptonModel::G4LivermoreComptonModel(const G4ParticleDefinition*,
                                              const G4String& nam)
-:G4VEmModel(nam),isInitialised(false)
+:G4VEmModel(nam),isInitialised(false),meanFreePathTable(0),scatterFunctionData(0),crossSectionHandler(0)
 {
   lowEnergyLimit = 250 * eV; // SI - Could be 10 eV ?
@@ -45,5 +45,5 @@
   SetHighEnergyLimit(highEnergyLimit);
 
-  verboseLevel= 0;
+  verboseLevel=0 ;
   // Verbosity scale:
   // 0 = nothing 
@@ -65,7 +65,9 @@
 G4LivermoreComptonModel::~G4LivermoreComptonModel()
 {  
-  delete meanFreePathTable;
-  delete crossSectionHandler;
-  delete scatterFunctionData;
+
+  if (meanFreePathTable)   delete meanFreePathTable;
+  if (crossSectionHandler) delete crossSectionHandler;
+  if (scatterFunctionData) delete scatterFunctionData;
+
 }
 
@@ -75,9 +77,14 @@
                                        const G4DataVector& cuts)
 {
+
   if (verboseLevel > 3)
     G4cout << "Calling G4LivermoreComptonModel::Initialise()" << G4endl;
 
-  InitialiseElementSelectors(particle,cuts);
-
+  if (crossSectionHandler)
+  {
+    crossSectionHandler->Clear();
+    delete crossSectionHandler;
+  }
+  
   // Energy limits
   
@@ -118,4 +125,6 @@
   if (verboseLevel > 2) 
     G4cout << "Loaded cross section files for Livermore Compton model" << G4endl;
+
+  InitialiseElementSelectors(particle,cuts);
 
   G4cout << "Livermore Compton model is initialized " << G4endl
@@ -135,4 +144,5 @@
     
   isInitialised = true;
+
 }
 
@@ -145,9 +155,12 @@
                                              G4double, G4double)
 {
+
   if (verboseLevel > 3)
     G4cout << "Calling ComputeCrossSectionPerAtom() of G4LivermoreComptonModel" << G4endl;
 
   G4double cs = crossSectionHandler->FindValue(G4int(Z), GammaEnergy);
+  
   return cs;
+
 }
 
@@ -160,4 +173,5 @@
 					      G4double)
 {
+
   // The scattered gamma energy is sampled according to Klein - Nishina formula.
   // then accepted or rejected depending on the Scattering Function multiplied
@@ -184,5 +198,4 @@
       fParticleChange->SetProposedKineticEnergy(0.);
       fParticleChange->ProposeLocalEnergyDeposit(photonEnergy0);
-      // SI - IS THE FOLLOWING RETURN NECESSARY ?
       return ;
   }
@@ -335,4 +348,5 @@
   G4DynamicParticle* dp = new G4DynamicParticle (G4Electron::Electron(),eDirection,eKineticEnergy) ;
   fvect->push_back(dp);
+
 }
 
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreGammaConversionModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreGammaConversionModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreGammaConversionModel.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4LivermoreGammaConversionModel.cc,v 1.1 2008/10/30 14:16:35 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4LivermoreGammaConversionModel.cc,v 1.2 2009/01/21 10:58:13 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 
@@ -38,5 +38,5 @@
 G4LivermoreGammaConversionModel::G4LivermoreGammaConversionModel(const G4ParticleDefinition*,
                                              const G4String& nam)
-:G4VEmModel(nam),smallEnergy(2.*MeV),isInitialised(false)
+:G4VEmModel(nam),smallEnergy(2.*MeV),isInitialised(false),crossSectionHandler(0),meanFreePathTable(0)
 {
   lowEnergyLimit = 1.022000 * MeV;
@@ -63,6 +63,6 @@
 G4LivermoreGammaConversionModel::~G4LivermoreGammaConversionModel()
 {  
-  delete meanFreePathTable;
-  delete crossSectionHandler;
+  if (meanFreePathTable) delete meanFreePathTable;
+  if (crossSectionHandler) delete crossSectionHandler;
 }
 
@@ -75,5 +75,9 @@
     G4cout << "Calling G4LivermoreGammaConversionModel::Initialise()" << G4endl;
 
-  InitialiseElementSelectors(particle,cuts);
+  if (crossSectionHandler)
+  {
+    crossSectionHandler->Clear();
+    delete crossSectionHandler;
+  }
 
   // Energy limits
@@ -107,4 +111,6 @@
   if (verboseLevel > 2) 
     G4cout << "Loaded cross section files for PenelopeGammaConversion" << G4endl;
+
+  InitialiseElementSelectors(particle,cuts);
 
   G4cout << "Livermore Gamma Conversion model is initialized " << G4endl
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePhotoElectricModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePhotoElectricModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePhotoElectricModel.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4LivermorePhotoElectricModel.cc,v 1.1 2008/10/30 14:16:35 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4LivermorePhotoElectricModel.cc,v 1.2 2009/01/21 10:58:13 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 
@@ -38,5 +38,5 @@
 G4LivermorePhotoElectricModel::G4LivermorePhotoElectricModel(const G4ParticleDefinition*,
                                              const G4String& nam)
-:G4VEmModel(nam),isInitialised(false)
+:G4VEmModel(nam),isInitialised(false),meanFreePathTable(0),crossSectionHandler(0),shellCrossSectionHandler(0),ElectronAngularGenerator(0)
 {
   lowEnergyLimit = 250 * eV; // SI - Could be 10 eV ?
@@ -64,8 +64,8 @@
 G4LivermorePhotoElectricModel::~G4LivermorePhotoElectricModel()
 {  
-  delete meanFreePathTable;
-  delete crossSectionHandler;
-  delete shellCrossSectionHandler;
-  delete ElectronAngularGenerator;
+  if (meanFreePathTable) delete meanFreePathTable;
+  if (crossSectionHandler) delete crossSectionHandler;
+  if (shellCrossSectionHandler) delete shellCrossSectionHandler;
+  if (ElectronAngularGenerator) delete ElectronAngularGenerator;
 }
 
@@ -78,6 +78,16 @@
     G4cout << "Calling G4LivermorePhotoElectricModel::Initialise()" << G4endl;
 
-  InitialiseElementSelectors(particle,cuts);
-
+  if (crossSectionHandler)
+  {
+    crossSectionHandler->Clear();
+    delete crossSectionHandler;
+  }
+  
+  if (shellCrossSectionHandler)
+  {
+    shellCrossSectionHandler->Clear();
+    delete shellCrossSectionHandler;
+  }
+  
   // Energy limits
   
@@ -122,4 +132,6 @@
     G4cout << "Loaded cross section files for Livermore PhotoElectric model" << G4endl;
 
+  InitialiseElementSelectors(particle,cuts);
+
   G4cout << "Livermore PhotoElectric model is initialized " << G4endl
          << "Energy range: "
@@ -177,5 +189,4 @@
       fParticleChange->SetProposedKineticEnergy(0.);
       fParticleChange->ProposeLocalEnergyDeposit(photonEnergy);
-      // SI - IS THE FOLLOWING RETURN NECESSARY ?
       return ;
     }
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePolarizedComptonModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePolarizedComptonModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePolarizedComptonModel.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4LivermorePolarizedComptonModel.cc,v 1.1 2008/10/30 14:16:35 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4LivermorePolarizedComptonModel.cc,v 1.2 2009/01/21 10:58:13 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 
@@ -38,5 +38,5 @@
 G4LivermorePolarizedComptonModel::G4LivermorePolarizedComptonModel(const G4ParticleDefinition*,
                                              const G4String& nam)
-:G4VEmModel(nam),isInitialised(false)
+:G4VEmModel(nam),isInitialised(false),meanFreePathTable(0),scatterFunctionData(0),crossSectionHandler(0)
 {
   lowEnergyLimit = 250 * eV; // SI - Could be 10 eV ?
@@ -65,7 +65,7 @@
 G4LivermorePolarizedComptonModel::~G4LivermorePolarizedComptonModel()
 {  
-  delete meanFreePathTable;
-  delete crossSectionHandler;
-  delete scatterFunctionData;
+  if (meanFreePathTable)   delete meanFreePathTable;
+  if (crossSectionHandler) delete crossSectionHandler;
+  if (scatterFunctionData) delete scatterFunctionData;
 }
 
@@ -78,5 +78,9 @@
     G4cout << "Calling G4LivermorePolarizedComptonModel::Initialise()" << G4endl;
 
-  InitialiseElementSelectors(particle,cuts);
+  if (crossSectionHandler)
+  {
+    crossSectionHandler->Clear();
+    delete crossSectionHandler;
+  }
 
   // Energy limits
@@ -119,4 +123,6 @@
   if (verboseLevel > 2) 
     G4cout << "Loaded cross section files for Livermore Polarized Compton model" << G4endl;
+
+  InitialiseElementSelectors(particle,cuts);
 
   G4cout << "Livermore Polarized Compton model is initialized " << G4endl
@@ -203,5 +209,4 @@
       fParticleChange->SetProposedKineticEnergy(0.);
       fParticleChange->ProposeLocalEnergyDeposit(gammaEnergy0);
-      // SI - IS THE FOLLOWING RETURN NECESSARY ?
       return;
     }
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePolarizedRayleighModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePolarizedRayleighModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4LivermorePolarizedRayleighModel.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4LivermorePolarizedRayleighModel.cc,v 1.1 2008/10/30 14:16:35 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4LivermorePolarizedRayleighModel.cc,v 1.2 2009/01/21 10:58:13 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 
@@ -38,5 +38,5 @@
 G4LivermorePolarizedRayleighModel::G4LivermorePolarizedRayleighModel(const G4ParticleDefinition*,
                                              const G4String& nam)
-:G4VEmModel(nam),isInitialised(false)
+:G4VEmModel(nam),isInitialised(false),crossSectionHandler(0),formFactorData(0)
 {
   lowEnergyLimit = 250 * eV; // SI - Could be 10 eV ?
@@ -65,6 +65,6 @@
 G4LivermorePolarizedRayleighModel::~G4LivermorePolarizedRayleighModel()
 {  
-  delete crossSectionHandler;
-  delete formFactorData;
+  if (crossSectionHandler) delete crossSectionHandler;
+  if (formFactorData) delete formFactorData;
 }
 
@@ -84,6 +84,10 @@
     G4cout << "Calling G4LivermorePolarizedRayleighModel::Initialise()" << G4endl;
 
-  InitialiseElementSelectors(particle,cuts);
-
+  if (crossSectionHandler)
+  {
+    crossSectionHandler->Clear();
+    delete crossSectionHandler;
+  }
+  
   // Energy limits
   
@@ -116,4 +120,6 @@
   if (verboseLevel > 2) 
     G4cout << "Loaded cross section files for Livermore Polarized Rayleigh model" << G4endl;
+
+  InitialiseElementSelectors(particle,cuts);
 
   G4cout << "Livermore Polarized Rayleigh model is initialized " << G4endl
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreRayleighModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreRayleighModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4LivermoreRayleighModel.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4LivermoreRayleighModel.cc,v 1.1 2008/10/30 14:16:35 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4LivermoreRayleighModel.cc,v 1.2 2009/01/21 10:58:13 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 
@@ -38,5 +38,5 @@
 G4LivermoreRayleighModel::G4LivermoreRayleighModel(const G4ParticleDefinition*,
                                              const G4String& nam)
-:G4VEmModel(nam),isInitialised(false)
+:G4VEmModel(nam),isInitialised(false),meanFreePathTable(0),formFactorData(0),crossSectionHandler(0)
 {
   lowEnergyLimit = 250 * eV; // SI - Could be 10 eV ?
@@ -65,7 +65,7 @@
 G4LivermoreRayleighModel::~G4LivermoreRayleighModel()
 {  
-  delete meanFreePathTable;
-  delete crossSectionHandler;
-  delete formFactorData;
+  if (meanFreePathTable) delete meanFreePathTable;
+  if (crossSectionHandler) delete crossSectionHandler;
+  if (formFactorData) delete formFactorData;
 }
 
@@ -78,6 +78,10 @@
     G4cout << "Calling G4LivermoreRayleighModel::Initialise()" << G4endl;
 
-  InitialiseElementSelectors(particle,cuts);
-
+  if (crossSectionHandler)
+  {
+    crossSectionHandler->Clear();
+    delete crossSectionHandler;
+  }
+  
   // Energy limits
   
@@ -115,4 +119,6 @@
   if (verboseLevel > 2) 
     G4cout << "Loaded cross section files for Livermore Rayleigh model" << G4endl;
+
+  InitialiseElementSelectors(particle,cuts);
 
   G4cout << "Livermore Rayleigh model is initialized " << G4endl
@@ -166,5 +172,4 @@
       fParticleChange->SetProposedKineticEnergy(0.);
       fParticleChange->ProposeLocalEnergyDeposit(photonEnergy0);
-      // SI - IS THE FOLLOWING RETURN NECESSARY ?
       return ;
   }
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopeBremsstrahlungContinuous.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopeBremsstrahlungContinuous.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopeBremsstrahlungContinuous.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4PenelopeBremsstrahlungContinuous.cc,v 1.10 2008/12/09 15:08:13 pandola Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4PenelopeBremsstrahlungContinuous.cc,v 1.11 2008/12/15 09:23:06 pandola Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 // 
 // --------------------------------------------------------------
@@ -97,6 +97,5 @@
  G4String dirFile = pathString + "/penelope/" + name;
  std::ifstream file(dirFile);
- std::filebuf* lsdp = file.rdbuf();
- if (!(lsdp->is_open()))
+ if (!file.is_open())
      {
       G4String excep = "G4PenelopeBremsstrahlungContinuous - data file " + name + " not found!";
@@ -112,14 +111,15 @@
      for (size_t j=0;j<NumberofKPoints;j++){
        file >> a1;
-       ReducedCS[i][j]=a1*cm2; //coversion present in Penelope source
+       ReducedCS[i][j]=a1*cm2; 
      }
      //3) read the total cross section, in cm2
      file >> a1;
-     TotalCS[i]=a1*cm2; //conversion present in Penelope source
+     TotalCS[i]=a1*cm2; 
      // Check closing item
      file >> a1;
      if (a1 != ((G4double) -1))
        {
-	 G4String excep = "G4PenelopeBremsstrahlungContinuous - Check the bremms data file " + name;
+	 G4String excep = "G4PenelopeBremsstrahlungContinuous - Check the bremms data file " 
+	   + name;
 	 G4Exception(excep);
        }
@@ -229,5 +229,6 @@
   
   //Global x-section factor
-  G4double Fact=Zmat*Zmat*(energy+electron_mass_c2)*(energy+electron_mass_c2)/(energy*(energy+2.0*electron_mass_c2));
+  G4double Fact=Zmat*Zmat*(energy+electron_mass_c2)*(energy+electron_mass_c2)/
+    (energy*(energy+2.0*electron_mass_c2));
   Fact *= PositronCorrection(energy);
 
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopeIonisationModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopeIonisationModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopeIonisationModel.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4PenelopeIonisationModel.cc,v 1.2 2008/12/05 09:15:43 pandola Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4PenelopeIonisationModel.cc,v 1.3 2008/12/15 09:23:06 pandola Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 // Author: Luciano Pandola
@@ -517,7 +517,5 @@
     //Penelope subtracted the fluorescence, but one has to match the databases
     eKineticEnergy = energySecondary+ioniEnergy-bindingEnergy;
-    
-  //VERIFICA QUI LA STORIA DEL LOCAL ENERGY DEPOSIT!
-
+  
   G4double localEnergyDeposit = ionEnergy; 
   G4double energyInFluorescence = 0.0*eV;
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopePhotoElectric.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopePhotoElectric.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopePhotoElectric.cc	(revision 1005)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4PenelopePhotoElectric.cc,v 1.12 2006/06/29 19:40:51 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4PenelopePhotoElectric.cc,v 1.13 2009/01/08 09:42:54 pandola Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 // Author: L. Pandola
@@ -37,4 +37,9 @@
 // 31 May 2005  L. Pandola  Added Sauter formula for the sampling of 
 //                          the electron direction
+// 08 Jan 2009  L. Pandola  Check shell index to avoid mismatch between 
+//                          the Penelope cross section database and the 
+//                          G4AtomicTransitionManager database. It suppresses 
+//                          a warning from G4AtomicTransitionManager only. 
+//                          Results are unchanged.
 // --------------------------------------------------------------
 
@@ -146,4 +151,15 @@
   // Retrieve the corresponding identifier and binding energy of the selected shell
   const G4AtomicTransitionManager* transitionManager = G4AtomicTransitionManager::Instance();
+
+  //The number of shell cross section possibly reported in the Penelope database 
+  //might be different from the number of shells in the G4AtomicTransitionManager
+  //(namely, Penelope may contain more shell, especially for very light elements).
+  //In order to avoid a warning message from the G4AtomicTransitionManager, I 
+  //add this protection. Results are anyway changed, because when G4AtomicTransitionManager
+  //has a shellID>maxID, it sets the shellID to the last valid shell. 
+  size_t numberOfShells = (size_t) transitionManager->NumberOfShells(Z);
+  if (shellIndex >= numberOfShells)
+    shellIndex = numberOfShells-1;
+
   const G4AtomicShell* shell = transitionManager->Shell(Z,shellIndex);
   G4double bindingEnergy = shell->BindingEnergy();
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopePhotoElectricModel.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopePhotoElectricModel.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4PenelopePhotoElectricModel.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4PenelopePhotoElectricModel.cc,v 1.2 2008/12/04 14:09:36 pandola Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4PenelopePhotoElectricModel.cc,v 1.3 2009/01/08 09:42:54 pandola Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 // Author: Luciano Pandola
@@ -31,5 +31,10 @@
 // History:
 // --------
-// 08 Oct 2008   L Pandola    Migration from process to model 
+// 08 Oct 2008   L Pandola  Migration from process to model 
+// 08 Jan 2009  L. Pandola  Check shell index to avoid mismatch between 
+//                          the Penelope cross section database and the 
+//                          G4AtomicTransitionManager database. It suppresses 
+//                          a warning from G4AtomicTransitionManager only. 
+//                          Results are unchanged.
 //
 
@@ -227,4 +232,15 @@
   // Retrieve the corresponding identifier and binding energy of the selected shell
   const G4AtomicTransitionManager* transitionManager = G4AtomicTransitionManager::Instance();
+
+  //The number of shell cross section possibly reported in the Penelope database 
+  //might be different from the number of shells in the G4AtomicTransitionManager
+  //(namely, Penelope may contain more shell, especially for very light elements).
+  //In order to avoid a warning message from the G4AtomicTransitionManager, I 
+  //add this protection. Results are anyway changed, because when G4AtomicTransitionManager
+  //has a shellID>maxID, it sets the shellID to the last valid shell. 
+  size_t numberOfShells = (size_t) transitionManager->NumberOfShells(Z);
+  if (shellIndex >= numberOfShells)
+    shellIndex = numberOfShells-1;
+
   const G4AtomicShell* shell = transitionManager->Shell(Z,shellIndex);
   G4double bindingEnergy = shell->BindingEnergy();
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4eIonisationCrossSectionHandler.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4eIonisationCrossSectionHandler.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4eIonisationCrossSectionHandler.cc	(revision 1005)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4eIonisationCrossSectionHandler.cc,v 1.11 2006/06/29 19:42:00 gunter Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4eIonisationCrossSectionHandler.cc,v 1.12 2009/01/29 08:13:34 pandola Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 // -------------------------------------------------------------------
@@ -42,4 +42,6 @@
 // 19 Jul 2002   VI          Create composite data set for material
 // 21 Jan 2003  V.Ivanchenko Cut per region
+// 28 Jan 2009  L.Pandola    Added public method to make a easier migration of 
+//                           G4LowEnergyIonisation to G4LivermoreIonisationModel
 //
 // -------------------------------------------------------------------
@@ -98,9 +100,10 @@
     G4int nElements = material->GetNumberOfElements();
 
-    if(verbose > 0) {
-      G4cout << "eIonisation CS for " << m << "th material "
-             << material->GetName()
-             << "  eEl= " << nElements << G4endl;
-    }
+    if(verbose > 0) 
+      {
+	G4cout << "eIonisation CS for " << m << "th material "
+	       << material->GetName()
+	       << "  eEl= " << nElements << G4endl;
+      }
 
     G4double tcut  = (*energyCuts)[m];
@@ -129,5 +132,6 @@
             value += cross * p * density;
 
-            if(verbose>0 && m == 0 && e>=1. && e<=0.) {
+	    if(verbose>0 && m == 0 && e>=1. && e<=0.) 
+	    {
               G4cout << "G4eIonCrossSH: e(MeV)= " << e/MeV
                      << " n= " << n
@@ -139,5 +143,5 @@
                      << " Z= " << Z
                      << G4endl;
-	    }
+	      }
 
 	  }
@@ -155,3 +159,18 @@
 }
 
-
+G4double G4eIonisationCrossSectionHandler::GetCrossSectionAboveThresholdForElement(G4double energy,
+										   G4double cutEnergy,
+										   G4int Z)
+{
+  G4int nShells = NumberOfComponents(Z);
+  G4double value = 0.;
+  if(energy > cutEnergy) 
+    {
+      for (G4int n=0; n<nShells; n++) {
+	G4double cross = FindValue(Z, energy, n);
+	G4double p = theParam->Probability(Z, cutEnergy, energy, energy, n);
+	value += cross * p;
+      }
+    }
+  return value;
+}
Index: trunk/source/processes/electromagnetic/lowenergy/src/G4hLowEnergyLoss.cc
===================================================================
--- trunk/source/processes/electromagnetic/lowenergy/src/G4hLowEnergyLoss.cc	(revision 991)
+++ trunk/source/processes/electromagnetic/lowenergy/src/G4hLowEnergyLoss.cc	(revision 1005)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4hLowEnergyLoss.cc,v 1.27 2008/06/20 19:54:03 sincerti Exp $
-// GEANT4 tag $Name: geant4-09-02 $
+// $Id: G4hLowEnergyLoss.cc,v 1.28 2009/02/20 10:49:54 sincerti Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 // -----------------------------------------------------------
@@ -145,5 +145,6 @@
 G4double G4hLowEnergyLoss::HighestKineticEnergy= 100.*GeV;
 G4int    G4hLowEnergyLoss::TotBin = 360;
-G4double G4hLowEnergyLoss::RTable,G4hLowEnergyLoss::LOGRTable;
+G4double G4hLowEnergyLoss::RTable =1.1;
+G4double G4hLowEnergyLoss::LOGRTable = 1.1;
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -772,5 +773,4 @@
     theRangeTable = theRangepbarTable ;
   }
- 
   G4double R2 = RTable*RTable ;
   G4double R1 = RTable+1.;
@@ -1062,5 +1062,6 @@
 {
   G4double LowEdgeRange,A,B,C,discr,KineticEnergy ;
-  G4double Tbin = LowestKineticEnergy/RTable ;
+  G4double Tbin = 0;
+  if (RTable !=0.) Tbin = LowestKineticEnergy/RTable ;
   G4double rangebin = 0.0 ;
   G4int binnumber = -1 ;
