Index: trunk/examples/advanced/underground_physics/src/DMXAnalysisManager.cc
===================================================================
--- trunk/examples/advanced/underground_physics/src/DMXAnalysisManager.cc	(revision 1230)
+++ trunk/examples/advanced/underground_physics/src/DMXAnalysisManager.cc	(revision 1337)
@@ -35,4 +35,7 @@
 // 17 June 2002 Alex Howard    Successfully Modified to AIDA 2.2
 // 17 November 2002 Alex Howard Migrated to AIDA 3.0 and added fitting
+// 22 October 2009 Luciano Pandola Changed variables names for ntuple2
+//                                 (avoid problem with columns) and some 
+//                                 clean-up (e.g. remove ntuple4)
 //
 // -------------------------------------------------------------------
@@ -46,24 +49,16 @@
 
 DMXAnalysisManager::DMXAnalysisManager() :
-  af(0), tree(0), hf(0), tpf(0),
-   ntuple1(0), ntuple2(0), ntuple3(0), ntuple4(0),
+  af(0), tf(0),tree(0), hf(0), tpf(0),
+   ntuple1(0), ntuple2(0), ntuple3(0), 
   hEsourcep(0), hEdepp(0), hEdepRecoil(0), hNumPhLow(0), hNumPhHigh(0),
   hAvPhArrival(0), hPhArrival(0), hPMTHits(0), h1stPMTHit(0),hGammaEdep(0), 
   hNeutronEdep(0), hElectronEdep(0), hPositronEdep(0), hOtherEdep(0) 
   //,funFact(0),fitFact(0),exponFun(0),gaussFun(0),e_fitter(0),fitResult(0)
-{
-  // tree is created and booked inside book()
-  ;
-}
+{;}
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 
 DMXAnalysisManager::~DMXAnalysisManager() 
-{ 
-  delete tpf;
-  delete hf;
-  delete tree;
-  delete af;
- }
+{;}
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -92,5 +87,5 @@
   G4bool readOnly   = false;
 
-  AIDA::ITreeFactory     * tf = af->createTreeFactory();
+  tf = af->createTreeFactory();
 
   tree = tf->create(histogramfile, "hbook", readOnly, fileExists);
@@ -109,12 +104,8 @@
 			     "double energy" );
 
-  //  assert(ntuple1);
-
   // ---- secondary ntuple ------   
 
   ntuple2 = tpf->create( "2", "Scintillation Hits Info", 
-				 "float Event,e_prim,tot_e,s_hits,xe_time,num_ph,avphtime,1stpart,1stparte,gamma,neutron,posi,elec,other,seed1,seed2" );
-
-  //assert(ntuple2);
+			 "float Event,e_prim,tot_e,s_hits,xe_time,num_ph,avphtime,firstpart,firstparte,gamma,neutron,posi,elec,other,seed1,seed2" );
 
   // ---- tertiary ntuple ------   
@@ -122,13 +113,4 @@
   ntuple3 = tpf->create( "3", "PMT Hits Info", 
 				"float event, hits, xpos, ypos, zpos" );
-
-  //assert(ntuple3);
-
-  // ---- extra ntuple ------   
-  ntuple4 = tpf->create( "4", "Particles energy type", 
-			     "float energy, NameIdx" );
-
-  //assert(ntuple4);
-
 
   // Creating an 1-dimensional histogram in the root directory of the tree
@@ -165,6 +147,4 @@
 
   hOtherEdep    = hf->createHistogram1D("95","Other Ener Deposit/keV", 1000,0.,1000.);
-  
-  delete tf;
 
  //  // Creating the plotter factory
@@ -204,4 +184,5 @@
 
 //   G4cout << " Created e_fitter " << G4endl;
+  return;
 
 }
@@ -210,6 +191,5 @@
 
 void DMXAnalysisManager::Init()
-{
-}
+{;}
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -227,4 +207,11 @@
   // close (will again commit)
   tree->close();
+
+  
+  delete tpf;
+  delete hf;
+  delete tree;
+  delete tf;
+  delete af;
 
   // extra delete as objects are created in book() method rather than during
@@ -339,9 +326,7 @@
   hAvPhArrival->fill(aveTimePmtHits/ns);
 
-  // AIDA::ITuple * ntuple = dynamic_cast<AIDA::ITuple *> ( tree->find("2") );
-
  // Fill the ntuple
   ntuple2->fill( ntuple2->findColumn( "Event"   ), (G4float) event_id          );
-  ntuple2->fill( ntuple2->findColumn( "e_prim"  ), (G4float) energy_pri/keV    );
+  ntuple2->fill( ntuple2->findColumn( "e_prim"  ), (G4float) (energy_pri/keV)    );
   ntuple2->fill( ntuple2->findColumn( "tot_e"   ), (G4float) totEnergy         );
   ntuple2->fill( ntuple2->findColumn( "s_hits"  ), (G4float) S_hits            );
@@ -349,6 +334,6 @@
   ntuple2->fill( ntuple2->findColumn( "num_ph"  ), (G4float) P_hits            );
   ntuple2->fill( ntuple2->findColumn( "avphtime"), (G4float) aveTimePmtHits    );
-  ntuple2->fill( ntuple2->findColumn( "1stpart" ), (G4float) firstparticleIndex);
-  ntuple2->fill( ntuple2->findColumn( "1stparte"), (G4float) firstParticleE    );
+  ntuple2->fill( ntuple2->findColumn( "firstpart" ), (G4float) firstparticleIndex);
+  ntuple2->fill( ntuple2->findColumn( "firstparte"), (G4float) firstParticleE    );
   ntuple2->fill( ntuple2->findColumn( "gamma"   ), (G4float) gamma_ev          );
   ntuple2->fill( ntuple2->findColumn( "neutron" ), (G4float) neutron_ev        );
@@ -361,5 +346,4 @@
   //Values of attributes are prepared; store them to the nTuple:
   ntuple2->addRow();
-
 }
 
@@ -375,6 +359,5 @@
   }
 
-  //AIDA::ITuple * ntuple = dynamic_cast<AIDA::ITuple *> ( tree->find("3") );
-  // Fill the secondaries ntuple
+  // Fill the ntuple
   ntuple3->fill( ntuple3->findColumn( "event" ), (G4float) event );
   ntuple3->fill( ntuple3->findColumn( "hits"  ), (G4float) i     );
@@ -384,5 +367,5 @@
 
   // NEW: Values of attributes are prepared; store them to the nTuple:
-  ntuple3->addRow(); // check for returning true ...
+  ntuple3->addRow(); 
 
 }
@@ -391,10 +374,9 @@
 {
 
-  // AIDA::ITuple * ntuple1 = dynamic_cast<AIDA::ITuple *> ( tree->find("1") );
   // Fill energy ntple:
   ntuple1->fill( ntuple1->findColumn( "energy" ), energy );
 
   // NEW: Values of attributes are prepared; store them to the nTuple:
-  ntuple1->addRow(); // check for returning true ...
+  ntuple1->addRow(); 
 
 }
Index: trunk/examples/advanced/underground_physics/src/DMXMinEkineCuts.cc
===================================================================
--- trunk/examples/advanced/underground_physics/src/DMXMinEkineCuts.cc	(revision 1230)
+++ trunk/examples/advanced/underground_physics/src/DMXMinEkineCuts.cc	(revision 1337)
@@ -26,5 +26,5 @@
 //
 // $Id: DMXMinEkineCuts.cc,v 1.6 2006/06/29 16:26:39 gunter Exp $
-// GEANT4 tag $Name: geant4-09-03-cand-01 $
+// GEANT4 tag $Name: geant4-09-04-beta-01 $
 //
 // 
Index: trunk/examples/advanced/underground_physics/src/DMXPhysicsList.cc
===================================================================
--- trunk/examples/advanced/underground_physics/src/DMXPhysicsList.cc	(revision 1230)
+++ trunk/examples/advanced/underground_physics/src/DMXPhysicsList.cc	(revision 1337)
@@ -46,4 +46,7 @@
 //          and redefined particles to allow non-static creation
 //          i.e. changed construction to G4MesonConstructor, G4BaryonConstructor
+// 
+// 23-10-09 LP - migrated EM physics from the LowEnergy processes (not supported) to 
+//          the new G4Livermore model implementation. Results unchanged.
 //
 // --------------------------------------------------------------
@@ -214,16 +217,28 @@
 // Electromagnetic Processes ////////////////////////////////////////////////
 // all charged particles
-#include "G4MultipleScattering.hh"
 
 // gamma
-#include "G4LowEnergyRayleigh.hh" 
-#include "G4LowEnergyPhotoElectric.hh"
-#include "G4LowEnergyCompton.hh"  
-#include "G4LowEnergyGammaConversion.hh" 
+#include "G4PhotoElectricEffect.hh"
+#include "G4LivermorePhotoElectricModel.hh"
+
+#include "G4ComptonScattering.hh"
+#include "G4LivermoreComptonModel.hh"
+
+#include "G4GammaConversion.hh"
+#include "G4LivermoreGammaConversionModel.hh"
+
+#include "G4RayleighScattering.hh" 
+#include "G4LivermoreRayleighModel.hh"
 
 
 // e-
-#include "G4LowEnergyIonisation.hh" 
-#include "G4LowEnergyBremsstrahlung.hh" 
+#include "G4eMultipleScattering.hh"
+
+#include "G4eIonisation.hh"
+#include "G4LivermoreIonisationModel.hh"
+
+#include "G4eBremsstrahlung.hh"
+#include "G4LivermoreBremsstrahlungModel.hh"
+
 
 // e+
@@ -246,5 +261,9 @@
 
 //OTHERS:
-#include "G4hIonisation.hh" // standard hadron ionisation
+#include "G4hIonisation.hh" 
+#include "G4hMultipleScattering.hh"
+#include "G4hBremsstrahlung.hh"
+#include "G4ionIonisation.hh"
+#include "G4IonParametrisedLossModel.hh"
 
 //em process options to allow msc step-limitation to be switched off
@@ -252,32 +271,11 @@
 
 void DMXPhysicsList::ConstructEM() {
-
-// processes:
-
-  G4LowEnergyPhotoElectric* lowePhot = new G4LowEnergyPhotoElectric();
-  G4LowEnergyIonisation* loweIon  = new G4LowEnergyIonisation();
-  G4LowEnergyBremsstrahlung* loweBrem = new G4LowEnergyBremsstrahlung();
-
-  // note LowEIon uses proton as basis for its data-base, therefore
-  // cannot specify different LowEnergyIonisation models for different
-  // particles, but can change model globally for Ion, Alpha and Proton.
-
-
-  //fluorescence apply specific cut for fluorescence from photons, electrons
-  //and bremsstrahlung photons:
-  G4double fluorcut = 250*eV;
-  lowePhot->SetCutForLowEnSecPhotons(fluorcut);
-  loweIon->SetCutForLowEnSecPhotons(fluorcut);
-  loweBrem->SetCutForLowEnSecPhotons(fluorcut);
   
-  // setting tables explicitly for electronic stopping power
-  //  ahadronLowEIon->SetElectronicStoppingPowerModel
-  //  (G4GenericIon::GenericIonDefinition(), "ICRU_R49p") ;
-  //  ahadronLowEIon->SetElectronicStoppingPowerModel
-  //  (G4Proton::ProtonDefinition(), "ICRU_R49p") ;
-
-  // Switch off the Barkas and Bloch corrections
-  //  ahadronLowEIon->SetBarkasOff();
-
+  //set a finer grid of the physic tables in order to improve precision
+  //former LowEnergy models have 200 bins up to 100 GeV
+  G4EmProcessOptions opt;
+  opt.SetMaxEnergy(100*GeV);
+  opt.SetDEDXBinning(200);
+  opt.SetLambdaBinning(200);
 
   theParticleIterator->reset();
@@ -292,8 +290,20 @@
       {
 	//gamma
-	pmanager->AddDiscreteProcess(new G4LowEnergyRayleigh());
-	pmanager->AddDiscreteProcess(lowePhot);
-	pmanager->AddDiscreteProcess(new G4LowEnergyCompton());
-	pmanager->AddDiscreteProcess(new G4LowEnergyGammaConversion());
+	G4RayleighScattering* theRayleigh = new G4RayleighScattering();
+	theRayleigh->SetModel(new G4LivermoreRayleighModel());  //not strictly necessary
+	pmanager->AddDiscreteProcess(theRayleigh);
+
+	G4PhotoElectricEffect* thePhotoElectricEffect = new G4PhotoElectricEffect();
+	thePhotoElectricEffect->SetModel(new G4LivermorePhotoElectricModel());
+	pmanager->AddDiscreteProcess(thePhotoElectricEffect);
+	
+	G4ComptonScattering* theComptonScattering = new G4ComptonScattering();
+	theComptonScattering->SetModel(new G4LivermoreComptonModel());
+	pmanager->AddDiscreteProcess(theComptonScattering);
+	
+	G4GammaConversion* theGammaConversion = new G4GammaConversion();
+	theGammaConversion->SetModel(new G4LivermoreGammaConversionModel());
+	pmanager->AddDiscreteProcess(theGammaConversion);
+
       } 
     else if (particleName == "e-") 
@@ -301,17 +311,36 @@
 	//electron
 	// process ordering: AddProcess(name, at rest, along step, post step)
-	// -1 = not implemented, then ordering
-        G4MultipleScattering* aMultipleScattering = new G4MultipleScattering();
-	pmanager->AddProcess(aMultipleScattering,     -1, 1, 1);
-	pmanager->AddProcess(loweIon,                 -1, 2, 2);
-	pmanager->AddProcess(loweBrem,                -1,-1, 3);
+	// Multiple scattering
+	G4eMultipleScattering* msc = new G4eMultipleScattering();
+	msc->SetStepLimitType(fUseDistanceToBoundary);
+	pmanager->AddProcess(msc,-1, 1, 1);
+
+	// Ionisation
+	G4eIonisation* eIonisation = new G4eIonisation();
+	eIonisation->SetEmModel(new G4LivermoreIonisationModel());
+	eIonisation->SetStepFunction(0.2, 100*um); //improved precision in tracking  
+	pmanager->AddProcess(eIonisation,-1, 2, 2);
+	
+	// Bremsstrahlung
+	G4eBremsstrahlung* eBremsstrahlung = new G4eBremsstrahlung();
+	eBremsstrahlung->SetEmModel(new G4LivermoreBremsstrahlungModel());
+	pmanager->AddProcess(eBremsstrahlung, -1,-3, 3);
       } 
     else if (particleName == "e+") 
       {
-	//positron
-        G4MultipleScattering* aMultipleScattering = new G4MultipleScattering();
-	pmanager->AddProcess(aMultipleScattering,     -1, 1, 1);
-	pmanager->AddProcess(new G4eIonisation(),     -1, 2, 2);
+	//positron	
+	G4eMultipleScattering* msc = new G4eMultipleScattering();
+	msc->SetStepLimitType(fUseDistanceToBoundary);
+	pmanager->AddProcess(msc,-1, 1, 1);
+	
+	// Ionisation
+	G4eIonisation* eIonisation = new G4eIonisation();
+	eIonisation->SetStepFunction(0.2, 100*um); //     
+	pmanager->AddProcess(eIonisation,                 -1, 2, 2);
+
+	//Bremsstrahlung (use default, no low-energy available)
 	pmanager->AddProcess(new G4eBremsstrahlung(), -1,-1, 3);
+
+	//Annihilation
 	pmanager->AddProcess(new G4eplusAnnihilation(),0,-1, 4);      
       } 
@@ -320,6 +349,5 @@
       {
 	//muon  
-        G4MultipleScattering* aMultipleScattering = new G4MultipleScattering();
-	pmanager->AddProcess(aMultipleScattering,           -1, 1, 1);
+	pmanager->AddProcess(new G4eMultipleScattering,           -1, 1, 1);
 	pmanager->AddProcess(new G4MuIonisation(),          -1, 2, 2);
 	pmanager->AddProcess(new G4MuBremsstrahlung(),      -1,-1, 3);
@@ -328,28 +356,48 @@
 	  pmanager->AddProcess(new G4MuonMinusCaptureAtRest(), 0,-1,-1);
       } 
-    else if (particleName == "proton"     ||
-	     particleName == "alpha"      ||
+    else if (particleName == "proton" || 
+	     particleName == "pi+" || 
+	     particleName == "pi-")
+      {
+	//multiple scattering
+	pmanager->AddProcess(new G4hMultipleScattering, -1, 1, 1);
+      
+	//ionisation
+	G4hIonisation* hIonisation = new G4hIonisation();
+	hIonisation->SetStepFunction(0.2, 50*um);
+	pmanager->AddProcess(hIonisation,                     -1, 2, 2);      
+	
+	//bremmstrahlung
+	pmanager->AddProcess(new G4hBremsstrahlung,     -1,-3, 3);
+      }
+    else if(particleName == "alpha"      ||
 	     particleName == "deuteron"   ||
 	     particleName == "triton"     ||
-	     particleName == "He3"        ||
-	     particleName == "GenericIon" || 
-	     (particleType == "nucleus" && charge != 0)) 
+	     particleName == "He3")
+      {
+	//multiple scattering
+	pmanager->AddProcess(new G4hMultipleScattering,-1,1,1);
+	
+	//ionisation
+	G4ionIonisation* ionIoni = new G4ionIonisation();
+	ionIoni->SetStepFunction(0.1, 20*um);
+	pmanager->AddProcess(ionIoni,                   -1, 2, 2);
+      }
+    else if (particleName == "GenericIon")
       {
 	// OBJECT may be dynamically created as either a GenericIon or nucleus
 	// G4Nucleus exists and therefore has particle type nucleus
 	// genericIon:
-        G4MultipleScattering* aMultipleScattering = new G4MultipleScattering();
-	//hIonisation G4hLowEnergyIonisation* ahadronLowEIon = new G4hLowEnergyIonisation();
-        G4hIonisation* ahadronIon = new G4hIonisation();
-	pmanager->AddProcess(aMultipleScattering,-1,1,1);
-	//hIonisation	pmanager->AddProcess(ahadronLowEIon,-1,2,2); 
-	pmanager->AddProcess(ahadronIon,-1,2,2); 
-        // ahadronLowEIon->SetNuclearStoppingOff() ;
-	//        ahadronLowEIon->SetNuclearStoppingPowerModel("ICRU_R49") ;
-	//        ahadronLowEIon->SetNuclearStoppingOn() ;
-  
-        //fluorescence switch off for hadrons (for now) PIXE:
-	//hIonisation        ahadronLowEIon->SetFluorescence(false);
+	
+	//multiple scattering
+	pmanager->AddProcess(new G4hMultipleScattering,-1,1,1);
+
+	//ionisation
+	G4ionIonisation* ionIoni = new G4ionIonisation();
+	ionIoni->SetEmModel(new G4IonParametrisedLossModel());
+	ionIoni->SetStepFunction(0.1, 20*um);
+	pmanager->AddProcess(ionIoni,                   -1, 2, 2);
       } 
+
     else if ((!particle->IsShortLived()) &&
 	     (charge != 0.0) && 
@@ -357,11 +405,12 @@
       {
 	//all others charged particles except geantino
-        G4MultipleScattering* aMultipleScattering = new G4MultipleScattering();
-	//hIonisation        G4hLowEnergyIonisation* ahadronLowEIon = new G4hLowEnergyIonisation();
+        G4hMultipleScattering* aMultipleScattering = new G4hMultipleScattering();
         G4hIonisation* ahadronIon = new G4hIonisation();
+	
+	//multiple scattering
 	pmanager->AddProcess(aMultipleScattering,-1,1,1);
-	//hIonisation	pmanager->AddProcess(ahadronLowEIon,       -1,2,2);      
+
+	//ionisation
 	pmanager->AddProcess(ahadronIon,       -1,2,2);      
-	//      pmanager->AddProcess(new G4hIonisation(),       -1,2,2);      
       }
     
@@ -369,6 +418,4 @@
 
   // turn off msc step-limitation - especially as electron cut 1nm
-  G4EmProcessOptions opt;
-  //  opt.SetMscStepLimitation(false);
   opt.SetMscStepLimitation(fMinimal);
 
Index: trunk/examples/advanced/underground_physics/src/DMXRunAction.cc
===================================================================
--- trunk/examples/advanced/underground_physics/src/DMXRunAction.cc	(revision 1230)
+++ trunk/examples/advanced/underground_physics/src/DMXRunAction.cc	(revision 1337)
@@ -39,4 +39,5 @@
 // History:
 // 17 Jan 2002 Alex Howard Added Analysis
+// 23 Oct 2009 Luciano Pandola Removed un-necessary calls from EndOfRun()
 //
 // RunAction program
@@ -104,12 +105,4 @@
 void DMXRunAction::EndOfRunAction(const G4Run*)
 {
-
-#ifdef G4ANALYSIS_USE
-  DMXAnalysisManager* analysis = DMXAnalysisManager::getInstance();
-  //analysis->PlotHistos(interactplot);
-  //analysis->PulseTimeFit();
-  analysis->Finish();
-#endif
-
   if (G4VVisManager::GetConcreteInstance()) {
      G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
