Index: trunk/source/processes/electromagnetic/utils/src/G4VMultipleScattering.cc
===================================================================
--- trunk/source/processes/electromagnetic/utils/src/G4VMultipleScattering.cc	(revision 1228)
+++ trunk/source/processes/electromagnetic/utils/src/G4VMultipleScattering.cc	(revision 1315)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4VMultipleScattering.cc,v 1.77 2009/10/29 18:07:08 vnivanch Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// $Id: G4VMultipleScattering.cc,v 1.82 2010/04/12 11:45:03 vnivanch Exp $
+// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
 //
 // -------------------------------------------------------------------
@@ -95,5 +95,5 @@
   firstParticle(0),
   stepLimit(fUseSafety),
-  skin(3.0),
+  skin(1.0),
   facrange(0.04),
   facgeom(2.5),
@@ -144,5 +144,5 @@
   G4VEmFluctuationModel* fm = 0;
   modelManager->AddEmModel(order, p, fm, region);
-  if(p) p->SetParticleChange(pParticleChange);
+  if(p) { p->SetParticleChange(pParticleChange); }
 }
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -170,68 +170,4 @@
 {
   return modelManager->GetModel(idx, ver);
-}
-
-//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
-
-void G4VMultipleScattering::BuildPhysicsTable(const G4ParticleDefinition& part)
-{
-  G4String num = part.GetParticleName();
-  if(1 < verboseLevel) {
-    G4cout << "### G4VMultipleScattering::BuildPhysicsTable() for "
-           << GetProcessName()
-           << " and particle " << num
-           << G4endl;
-  }
-
-  if (buildLambdaTable && firstParticle == &part) {
-
-    const G4ProductionCutsTable* theCoupleTable=
-          G4ProductionCutsTable::GetProductionCutsTable();
-    size_t numOfCouples = theCoupleTable->GetTableSize();
-
-    G4bool splineFlag = (G4LossTableManager::Instance())->SplineFlag();
-
-    G4PhysicsLogVector* aVector = 0;
-    G4PhysicsLogVector* bVector = 0;
-
-    for (size_t i=0; i<numOfCouples; ++i) {
-
-      if (theLambdaTable->GetFlag(i)) {
-        // create physics vector and fill it
-        const G4MaterialCutsCouple* couple = 
-	  theCoupleTable->GetMaterialCutsCouple(i);
-	if(!bVector) {
-	  aVector = static_cast<G4PhysicsLogVector*>(PhysicsVector(couple));
-	  bVector = aVector;
-	} else {
-	  aVector = new G4PhysicsLogVector(*bVector);
-	}       
-	//G4PhysicsVector* aVector = PhysicsVector(couple);
-	aVector->SetSpline(splineFlag);
-        modelManager->FillLambdaVector(aVector, couple, false);
-	if(splineFlag) aVector->FillSecondDerivatives();
-        G4PhysicsTableHelper::SetPhysicsVector(theLambdaTable, i, aVector);
-      }
-    }
-
-    if(1 < verboseLevel) {
-      G4cout << "Lambda table is built for "
-             << num
-             << G4endl;
-    }
-  }
-  if(verboseLevel>0 && ( num == "e-" || num == "mu+" ||  
-                         num == "proton" || num == "pi-" || 
-			 num == "GenericIon")) {
-    PrintInfoDefinition();
-    if(2 < verboseLevel && theLambdaTable) G4cout << *theLambdaTable << G4endl;
-  }
-
-  if(1 < verboseLevel) {
-    G4cout << "### G4VMultipleScattering::BuildPhysicsTable() done for "
-           << GetProcessName()
-           << " and particle " << num
-           << G4endl;
-  }
 }
 
@@ -260,4 +196,6 @@
   }
 
+  (G4LossTableManager::Instance())->PreparePhysicsTable(&part, this);
+
   if(1 < verboseLevel) {
     G4cout << "### G4VMultipleScattering::PrepearPhysicsTable() for "
@@ -267,6 +205,4 @@
            << G4endl;
   }
-
-  (G4LossTableManager::Instance())->EmConfigurator()->AddModels();
 
   if(firstParticle == &part) {
@@ -307,4 +243,70 @@
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 
+void G4VMultipleScattering::BuildPhysicsTable(const G4ParticleDefinition& part)
+{
+  G4String num = part.GetParticleName();
+  if(1 < verboseLevel) {
+    G4cout << "### G4VMultipleScattering::BuildPhysicsTable() for "
+           << GetProcessName()
+           << " and particle " << num
+           << G4endl;
+  }
+
+  (G4LossTableManager::Instance())->BuildPhysicsTable(firstParticle);
+
+  if (buildLambdaTable && firstParticle == &part) {
+
+    const G4ProductionCutsTable* theCoupleTable=
+          G4ProductionCutsTable::GetProductionCutsTable();
+    size_t numOfCouples = theCoupleTable->GetTableSize();
+
+    G4bool splineFlag = (G4LossTableManager::Instance())->SplineFlag();
+
+    G4PhysicsLogVector* aVector = 0;
+    G4PhysicsLogVector* bVector = 0;
+
+    for (size_t i=0; i<numOfCouples; ++i) {
+
+      if (theLambdaTable->GetFlag(i)) {
+        // create physics vector and fill it
+        const G4MaterialCutsCouple* couple = 
+	  theCoupleTable->GetMaterialCutsCouple(i);
+	if(!bVector) {
+	  aVector = static_cast<G4PhysicsLogVector*>(PhysicsVector(couple));
+	  bVector = aVector;
+	} else {
+	  aVector = new G4PhysicsLogVector(*bVector);
+	}       
+	//G4PhysicsVector* aVector = PhysicsVector(couple);
+	aVector->SetSpline(splineFlag);
+        modelManager->FillLambdaVector(aVector, couple, false);
+	if(splineFlag) aVector->FillSecondDerivatives();
+        G4PhysicsTableHelper::SetPhysicsVector(theLambdaTable, i, aVector);
+      }
+    }
+
+    if(1 < verboseLevel) {
+      G4cout << "Lambda table is built for "
+             << num
+             << G4endl;
+    }
+  }
+  if(verboseLevel>0 && ( num == "e-" || num == "mu+" ||  
+                         num == "proton" || num == "pi-" || 
+			 num == "GenericIon")) {
+    PrintInfoDefinition();
+    if(2 < verboseLevel && theLambdaTable) G4cout << *theLambdaTable << G4endl;
+  }
+
+  if(1 < verboseLevel) {
+    G4cout << "### G4VMultipleScattering::BuildPhysicsTable() done for "
+           << GetProcessName()
+           << " and particle " << num
+           << G4endl;
+  }
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
+
 void G4VMultipleScattering::PrintInfoDefinition()
 {
@@ -362,4 +364,38 @@
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 
+G4double 
+G4VMultipleScattering::PostStepGetPhysicalInteractionLength(
+              const G4Track&, G4double, G4ForceCondition* condition)
+{
+  *condition = Forced;
+  return DBL_MAX;
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
+
+G4VParticleChange* 
+G4VMultipleScattering::AlongStepDoIt(const G4Track& track, const G4Step& step)
+{
+  if(currentModel->IsActive(track.GetKineticEnergy())) {
+    fParticleChange.ProposeTrueStepLength(currentModel->ComputeTrueStepLength(step.GetStepLength()));
+  }
+  return &fParticleChange;
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
+
+G4VParticleChange* 
+G4VMultipleScattering::PostStepDoIt(const G4Track& track, const G4Step& step)
+{
+  fParticleChange.Initialize(track);
+  if(currentModel->IsActive(track.GetKineticEnergy())) {
+    currentModel->SampleScattering(track.GetDynamicParticle(),
+				   step.GetPostStepPoint()->GetSafety());
+  }
+  return &fParticleChange;
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
+
 G4double G4VMultipleScattering::GetContinuousStepLimit(
                                        const G4Track& track,
@@ -371,4 +407,16 @@
   return AlongStepGetPhysicalInteractionLength(track,previousStepSize,currentMinimalStep,
 					       currentSafety, selection);
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
+
+G4double G4VMultipleScattering::ContinuousStepLimit(
+                                       const G4Track& track,
+                                       G4double previousStepSize,
+                                       G4double currentMinimalStep,
+                                       G4double& currentSafety)
+{
+  return GetContinuousStepLimit(track,previousStepSize,currentMinimalStep,
+				currentSafety);
 }
 
