Index: trunk/source/processes/hadronic/models/parton_string/diffraction/src/G4FTFModel.cc
===================================================================
--- trunk/source/processes/hadronic/models/parton_string/diffraction/src/G4FTFModel.cc	(revision 819)
+++ trunk/source/processes/hadronic/models/parton_string/diffraction/src/G4FTFModel.cc	(revision 962)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4FTFModel.cc,v 1.7 2007/04/24 10:32:59 gunter Exp $
-// GEANT4 tag $Name: geant4-09-01-patch-02 $
+// $Id: G4FTFModel.cc,v 1.13 2008/12/09 10:40:52 vuzhinsk Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
 //
 
@@ -38,4 +38,5 @@
 
 #include "G4FTFModel.hh"
+#include "G4FTFParameters.hh"                            // Uzhi 29.03.08
 #include "G4FTFParticipants.hh"
 #include "G4InteractionContent.hh"
@@ -43,13 +44,17 @@
 #include "G4ParticleDefinition.hh"
 #include "G4ios.hh"
+#include <utility>                                        // Uzhi 29.03.08
 
 // Class G4FTFModel 
 
-G4FTFModel::G4FTFModel():theExcitation(new G4DiffractiveExcitation()) // Uzhi
+G4FTFModel::G4FTFModel():theExcitation(new G4DiffractiveExcitation()),
+                         theElastic(new G4ElasticHNScattering()) // Uzhi 29.03.08
 {
 	G4VPartonStringModel::SetThisPointer(this);
-}
-
-G4FTFModel::G4FTFModel(G4double a, G4double b, G4double c):theExcitation(new G4DiffractiveExcitation())
+        theParameters=0;                                         // Uzhi 9.12.08
+}
+
+/*
+G4FTFModel::G4FTFModel(G4double , G4double , G4double ):theExcitation(new // Uzhi 9.12.08 G4DiffractiveExcitation())
 {
 	G4VPartonStringModel::SetThisPointer(this);
@@ -62,9 +67,16 @@
 	G4VPartonStringModel::SetThisPointer(this);
 }
-
+*/
 
 
 G4FTFModel::~G4FTFModel()
-{}
+{
+   if( theParameters != 0 ) delete theParameters;             // Uzhi 5.12.08
+// Because FTF model can be called for various particles
+// theParameters must be erased at the end of each call.
+// Thus the delete is olso in G4FTFModel::GetStrings() method
+   if( theExcitation != 0 ) delete theExcitation;             // Uzhi 5.12.08
+   if( theElastic    != 0 ) delete theElastic;                // Uzhi 5.12.08
+}
 
 
@@ -86,85 +98,91 @@
 }
 
+// ------------------------------------------------------------
 void G4FTFModel::Init(const G4Nucleus & aNucleus, const G4DynamicParticle & aProjectile)
 {
-	theParticipants.Init(aNucleus.GetN(),aNucleus.GetZ()); // Uzhi N-mass number Z-charge
- 
 	theProjectile = aProjectile;  
-}
-
+//G4cout<<"G4FTFModel::Init "<<aNucleus.GetN()<<" "<<aNucleus.GetZ()<<G4endl;
+	theParticipants.Init(aNucleus.GetN(),aNucleus.GetZ()); 
+// Uzhi N-mass number Z-charge ------------------------- Uzhi 29.03.08
+
+// --- cms energy
+
+        G4double s = sqr( theProjectile.GetMass() ) +
+                     sqr( G4Proton::Proton()->GetPDGMass() ) +
+                     2*theProjectile.GetTotalEnergy()*G4Proton::Proton()->GetPDGMass();
+/*
+G4cout << " primary Total E (GeV): " << theProjectile.GetTotalEnergy()/GeV << G4endl;
+G4cout << " primary Mass    (GeV): " << theProjectile.GetMass() /GeV << G4endl;
+G4cout << "cms std::sqrt(s) (GeV) = " << std::sqrt(s) / GeV << G4endl;
+*/
+
+      if( theParameters != 0 ) delete theParameters;                    // Uzhi 9.12.08
+      theParameters = new G4FTFParameters(theProjectile.GetDefinition(),
+                                          aNucleus.GetN(),aNucleus.GetZ(),
+                                          s);// ------------------------- Uzhi 19.04.08
+//theParameters->SetProbabilityOfElasticScatt(0.); // To turn on/off (1/0) elastic scattering
+}
+
+// ------------------------------------------------------------
 G4ExcitedStringVector * G4FTFModel::GetStrings()
 {
-	theParticipants.BuildInteractions(theProjectile);
-
+//G4cout<<"theParticipants.GetList"<<G4endl;
+	theParticipants.GetList(theProjectile,theParameters);
+//G4cout<<"ExciteParticipants()"<<G4endl;
 	if (! ExciteParticipants()) return NULL;;
-
+//G4cout<<"theStrings = BuildStrings()"<<G4endl;
 	G4ExcitedStringVector * theStrings = BuildStrings();
-
+//G4cout<<"Return to theStrings "<<G4endl;
+        if( theParameters != 0 )                              // Uzhi 9.12.08 
+        {                                                     // Uzhi 9.12.08
+          delete theParameters;                               // Uzhi 9.12.08
+          theParameters=0;                                    // Uzhi 9.12.08
+        }                                                     // Uzhi 9.12.08
 	return theStrings;
 }
 
+// ------------------------------------------------------------
 struct DeleteVSplitableHadron { void operator()(G4VSplitableHadron * aH){delete aH;} };
 
-G4ExcitedStringVector * G4FTFModel::BuildStrings()
-{	
-
-// Loop over all collisions; find all primaries, and all target ( targets may 
-//  be duplicate in the List ( to unique G4VSplitableHadrons)
-
-	G4ExcitedStringVector * strings;
-	strings = new G4ExcitedStringVector();
-	
-	std::vector<G4VSplitableHadron *> primaries;
-	std::vector<G4VSplitableHadron *> targets;
-	
-	theParticipants.StartLoop();    // restart a loop 
-	while ( theParticipants.Next() ) 
-	{
-	    const G4InteractionContent & interaction=theParticipants.GetInteraction();
-                 //  do not allow for duplicates ...
-	    if ( primaries.end() == std::find(primaries.begin(), primaries.end(), interaction.GetProjectile()) )
-	    	primaries.push_back(interaction.GetProjectile());
-		
-	    if ( targets.end() == std::find(targets.begin(), targets.end(),interaction.GetTarget()) ) 
-	    	targets.push_back(interaction.GetTarget());
-	}
-	    
-	
-//	G4cout << "BuildStrings prim/targ " << primaries.entries() << " , " <<
-//					     targets.entries() << G4endl;
-
-
-	unsigned int ahadron;
-	for ( ahadron=0; ahadron < primaries.size() ; ahadron++)
-	{
-	    G4bool isProjectile=true;
-	    strings->push_back(theExcitation->String(primaries[ahadron], isProjectile));
-	}
-	for ( ahadron=0; ahadron < targets.size() ; ahadron++)
-	{
-	    G4bool isProjectile=false;
-	    strings->push_back(theExcitation->String(targets[ahadron], isProjectile));
-	}
-
-	std::for_each(primaries.begin(), primaries.end(), DeleteVSplitableHadron());
-	primaries.clear();
-	std::for_each(targets.begin(), targets.end(), DeleteVSplitableHadron());
-	targets.clear();
-	
-	return strings;
-}
-
+// ------------------------------------------------------------
 G4bool G4FTFModel::ExciteParticipants()
 {
-	
+/*    // Uzhi 29.03.08                     For elastic Scatt.
+G4cout<<"  In ExciteParticipants() "<<theParticipants.theInteractions.size()<<G4endl;
+G4cout<<" test Params Tot "<<theParameters->GetTotalCrossSection()<<G4endl;
+G4cout<<" test Params Ela "<<theParameters->GetElasticCrossSection()<<G4endl;
+	
+G4int counter=0;
+*/   // Uzhi 29.03.08
+
+
+
 	while (theParticipants.Next())
 	{	   
 	   const G4InteractionContent & collision=theParticipants.GetInteraction();
-
-//G4cout << " soft colls : " << collision.GetNumberOfSoftCollisions() << G4endl; // Uzhi no match
+/*
+counter++;
+G4cout<<" Inter # "<<counter<<G4endl;
+*/
 	   G4VSplitableHadron * projectile=collision.GetProjectile();
 	   G4VSplitableHadron * target=collision.GetTarget();
 
-	   if ( ! theExcitation->ExciteParticipants(projectile, target) ) 
+//   // Uzhi 29.03.08
+           G4bool Successfull;
+           if(G4UniformRand()< theParameters->GetProbabilityOfElasticScatt())
+           {
+//G4cout<<"Elastic"<<G4endl;
+            Successfull=theElastic->ElasticScattering(projectile, target, theParameters);
+           }
+           else
+           {
+//G4cout<<"Inelastic"<<G4endl;
+            Successfull=theExcitation->ExciteParticipants(projectile, target, theParameters);
+           }
+//           if(!Successfull)
+// // Uzhi 29.03.08
+
+//	   if ( ! theExcitation->ExciteParticipants(projectile, target) ) 
+           if(!Successfull)
 	   {
 //           give up, clean up
@@ -176,8 +194,10 @@
 		    const G4InteractionContent & interaction=theParticipants.GetInteraction();
                 	 //  do not allow for duplicates ...
-		    if ( primaries.end() == std::find(primaries.begin(), primaries.end(), interaction.GetProjectile()) )
+		    if ( primaries.end() == std::find(primaries.begin(), primaries.end(),
+                                                      interaction.GetProjectile()) )
 	    		primaries.push_back(interaction.GetProjectile());
 
-		    if ( targets.end() == std::find(targets.begin(), targets.end(),interaction.GetTarget()) ) 
+		    if ( targets.end()   == std::find(targets.begin(), targets.end(),
+                                                      interaction.GetTarget()) ) 
 	    		targets.push_back(interaction.GetTarget());
 		}
@@ -188,7 +208,62 @@
 
 	   	return false;
-	   }
-
+	   }  // End of the loop Uzhi
+        }
+	return true;
+}
+// ------------------------------------------------------------
+G4ExcitedStringVector * G4FTFModel::BuildStrings()
+{	
+// Loop over all collisions; find all primaries, and all target ( targets may 
+//  be duplicate in the List ( to unique G4VSplitableHadrons)
+
+	G4ExcitedStringVector * strings;
+	strings = new G4ExcitedStringVector();
+	
+	std::vector<G4VSplitableHadron *> primaries;
+	std::vector<G4VSplitableHadron *> targets;
+	
+	theParticipants.StartLoop();    // restart a loop 
+	while ( theParticipants.Next() ) 
+	{
+	    const G4InteractionContent & interaction=theParticipants.GetInteraction();
+                 //  do not allow for duplicates ...
+	    if ( primaries.end() == std::find(primaries.begin(), primaries.end(),
+                                                interaction.GetProjectile()) )
+	    	primaries.push_back(interaction.GetProjectile());
+		
+	    if ( targets.end()   == std::find(targets.begin(), targets.end(),
+                                                interaction.GetTarget()) ) 
+	    	targets.push_back(interaction.GetTarget());
 	}
-	return true;
-}
+	    
+	
+//	G4cout << "BuildStrings prim/targ " << primaries.size() << " , " <<
+//					       targets.size() << G4endl;
+
+	unsigned int ahadron;
+// Only for hA-interactions Uzhi -------------------------------------
+	for ( ahadron=0; ahadron < primaries.size() ; ahadron++)
+	{
+//G4ThreeVector aPosition=primaries[ahadron]->GetPosition();
+//G4cout<<"Proj Build "<<aPosition<<" "<<primaries[ahadron]->GetTimeOfCreation()<<G4endl;
+	    G4bool isProjectile=true;
+	    strings->push_back(theExcitation->String(primaries[ahadron], isProjectile));
+	}
+
+	for ( ahadron=0; ahadron < targets.size() ; ahadron++)
+	{
+//G4ThreeVector aPosition=targets[ahadron]->GetPosition();
+//G4cout<<"Targ Build "<<aPosition<<" "<<targets[ahadron]->GetTimeOfCreation()<<G4endl;
+	    G4bool isProjectile=false;
+	    strings->push_back(theExcitation->String(targets[ahadron], isProjectile));
+	}
+
+	std::for_each(primaries.begin(), primaries.end(), DeleteVSplitableHadron());
+	primaries.clear();
+	std::for_each(targets.begin(), targets.end(), DeleteVSplitableHadron());
+	targets.clear();
+	
+	return strings;
+}
+// ------------------------------------------------------------
