diff --git a/Benchmarks/physics/hEx.root b/Benchmarks/physics/hEx.root
new file mode 100644
index 0000000000000000000000000000000000000000..9cf31cd23a08c6073c28e5e5ca5771b465f0f445
Binary files /dev/null and b/Benchmarks/physics/hEx.root differ
diff --git a/Benchmarks/physics/physics.cxx b/Benchmarks/physics/physics.cxx
index 6ac896ef3ad6fe9024802586d5db1c9e7a5f0e23..feae0da77b57589985fac93780315983805def27 100644
--- a/Benchmarks/physics/physics.cxx
+++ b/Benchmarks/physics/physics.cxx
@@ -1,11 +1,11 @@
 
 void EnergyLoss();
 void Reaction();
-TCanvas* c = new TCanvas("PhysicsBench","Physics Benchmark ",1000,500);
+TCanvas* c = new TCanvas("PhysicsBench","Physics Benchmark ",1500,500);
 
 ////////////////////////////////////////////////////////////////////////////////
 void physics(){
-  c->Divide(2,1);
+  c->Divide(3,1);
   EnergyLoss();
   Reaction();
 }
@@ -31,23 +31,51 @@ void EnergyLoss(){
 }
 ////////////////////////////////////////////////////////////////////////////////
 void Reaction() {
+  unsigned int cycles = 10000;
+  // test Random Ex generation
+    NPL::Reaction r2;
+    r2.ReadConfigurationFile("test.reaction");
+    TH1F* h2 = new TH1F("hE2","hE2",1000,-1,1);
+    double E4,T4,E3,T3,Ex,E;  
+    r2.ShootRandomExcitationEnergy();
+    clock_t begin = clock(); 
+    for (unsigned int i = 0 ; i < cycles ; i++){
+      r2.ShootRandomExcitationEnergy();
+      Ex = r2.GetExcitation4();
+      r2.SetThetaCM(i*deg*180./cycles);
+      r2.KineRelativistic(T3,E3,T4,E4);
+      E = r2.ReconstructRelativistic(E3,T3)-Ex;
+      h2->Fill(E/eV);
+    } 
+    clock_t end = clock();
+    double time = end-begin;
+    time = time/CLOCKS_PER_SEC;
+    cout << " ***** Reaction performance : " << cycles/time/1000. << " cycles per ms *****" << endl; 
+    c->cd(3);
+    h2->Draw("");
+    h2->GetXaxis()->SetTitle("Excitation error on Generated/Reconstructed cycle (eV)");
+
+  // On fly declaration
+  cout << " Reaction declaration without input file / no Ex distribution" << endl;
   NPL::Reaction r("28Si(d,p)29Si@280");
-  double E4,T4,E3,T3;
   TH1F* h = new TH1F("hE","hE",1000,-1,1);
-  clock_t begin = clock(); 
-  for (unsigned int i = 0 ; i < 10000 ; i++){
-    r.SetThetaCM(i*deg*180./10000);
+  begin = clock(); 
+  for (unsigned int i = 0 ; i < cycles ; i++){
+    r.SetExcitation4(0);
+    Ex = r2.GetExcitation4();
+    r.SetThetaCM(i*deg*180./cycles);
     r.KineRelativistic(T3,E3,T4,E4);
-    double E = r.ReconstructRelativistic(E3,T3);
+    E = r.ReconstructRelativistic(E3,T3);
     h->Fill(E/eV);
   } 
-  clock_t end = clock();
-  double time = end-begin;
+  end = clock();
+  time = end-begin;
   time = time/CLOCKS_PER_SEC;
-  cout << " ***** Reaction performance : 10000 cycle done in " << time*1000 << "ms *****" << endl; 
-
+  cout << " ***** Reaction performance :" << cycles/time/1000. << " cycles per ms *****" << endl; 
   c->cd(2);
   h->Draw("");
   h->GetXaxis()->SetTitle("Excitation error on Generated/Reconstructed cycle (eV)");
+
+
 }
 
diff --git a/Examples/Example1/Analysis.cxx b/Examples/Example1/Analysis.cxx
index b2690b0818df161750fe820eb0cdc5cb68f9c3df..fa8554aebb8d4a91f48286322f34a9f005aa5fbf 100644
--- a/Examples/Example1/Analysis.cxx
+++ b/Examples/Example1/Analysis.cxx
@@ -6,9 +6,9 @@
  *****************************************************************************/
 
 /*****************************************************************************
- * Original Author: Adrien MATTA  contact address: a.matta@surrey.ac.uk      *
+ * Original Author: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
  *                                                                           *
- * Creation Date  : march 2025                                               *
+ * Creation Date  : march 2015                                               *
  * Last update    :                                                          *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
@@ -30,15 +30,17 @@ using namespace std;
 ////////////////////////////////////////////////////////////////////////////////
 Analysis::Analysis(){
 }
+
 ////////////////////////////////////////////////////////////////////////////////
 Analysis::~Analysis(){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Analysis::Init(){
-  M2= (TMust2Physics*) m_DetectorManager->GetDetector("M2Telescope");
-  SSSD= (TSSSDPhysics*) m_DetectorManager->GetDetector("SSSD");
-  Initial=new TInitialConditions();
+  M2 = (TMust2Physics*) m_DetectorManager->GetDetector("M2Telescope");
+  SSSD = (TSSSDPhysics*) m_DetectorManager->GetDetector("SSSD");
+  Initial = new TInitialConditions();
+  ReactionConditions = new TReactionConditions(); 
   InitOutputBranch();
   InitInputBranch();
   Rand = TRandom3();
@@ -57,31 +59,50 @@ void Analysis::Init(){
   E_M2 = 0;
   Si_X_M2 = 0;
   Si_Y_M2 = 0;
-  ZTarget = 0;
   TargetThickness = m_DetectorManager->GetTargetThickness();
   //	Energy loss table: the G4Table are generated by the simulation
-  He3CD2 = EnergyLoss("Example/He3_CD2.G4table","G4Table",100 );
-  He3Al = EnergyLoss("Example/He3_Al.G4table","G4Table",10);
-  He3Si = EnergyLoss("Example/He3_Si.G4table","G4Table",10);
-  //Li11CD2 = EnergyLoss("ExampleLi11_CD2.G4table","G4Table",100);
+  He3CD2  = EnergyLoss("Example/He3_CD2.G4table","G4Table",100 );
+  He3Al   = EnergyLoss("Example/He3_Al.G4table","G4Table",10);
+  He3Si   = EnergyLoss("Example/He3_Si.G4table","G4Table",10);
+  Li11CD2 = EnergyLoss("Example/Li11_CD2.G4table","G4Table",100);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Analysis::TreatEvent(){
   // Reinitiate calculated variable
   ReInitValue();
+  // Get the Original condition for the record
+  OriginalELab = ReactionConditions->GetKineticEnergy(0);
+  OriginalThetaLab = ReactionConditions->GetTheta(0);
+  OriginalBeamEnergy = ReactionConditions->GetBeamEnergy();
   // Get the Init information on beam position and energy
   // and apply by hand the experimental resolution
   // This is because the beam diagnosis are not simulated
   // PPAC position resolution on target is assumed to be 1mm
-  double XTarget = Rand.Gaus(Initial->GetIncidentPositionX(),1);
-  double YTarget = Rand.Gaus(Initial->GetIncidentPositionY(),1);
+  double XTarget = Initial->GetIncidentPositionX();
+  double YTarget = Initial->GetIncidentPositionY();
+  double ZTarget = Initial->GetIncidentPositionZ();
+  
+  // Get the beam direction and position at entrance of the world
   TVector3 BeamDirection = Initial->GetBeamDirection();
-  // Beam energy is measured using F3 and F2 plastic TOF
-  double BeamEnergy = Rand.Gaus(Initial->GetIncidentInitialKineticEnergy(),4.5);
-  //BeamEnergy = Li11CD2.Slow(BeamEnergy,TargetThickness/2.,0);
-
+  TVector3 BeamPosition(XTarget,YTarget,ZTarget);
+ 
+  // Get the Beam position on Target 
+  BeamPosition+=abs(ZTarget)*BeamDirection;
+  
+  // Randomize beam position on target to simulate PPAC response
+  BeamPosition.SetX(Rand.Gaus(BeamPosition.X(),1));
+  BeamPosition.SetY(Rand.Gaus(BeamPosition.Y(),1));
+  BeamPosition.SetZ(0);
+  XTarget = BeamPosition.X();
+  YTarget = BeamPosition.Y();
+  ZTarget = 0;
+  
+  // Beam energy is measured using F3 and F2 plastic TOF with 4.5 MeV Resolution
+  BeamEnergy = Rand.Gaus(Initial->GetIncidentInitialKineticEnergy(),4.5);
+  BeamEnergy = Li11CD2.Slow(BeamEnergy,TargetThickness*0.5,0);
   He10Reaction->SetBeamEnergy(BeamEnergy);
+  
   //////////////////////////// LOOP on MUST2 + SSSD Hit //////////////////
   for(unsigned int countSSSD = 0 ; countSSSD < SSSD->Energy.size() ; countSSSD++){
     for(unsigned int countMust2 = 0 ; countMust2 < M2->Si_E.size() ; countMust2++){
@@ -127,7 +148,7 @@ void Analysis::TreatEvent(){
         /************************************************/
 
         // Part 2 : Impact Energy
-        Energy = ELab = 0;
+        Energy = ELab = E_M2 = 0;
         Si_E_M2 = M2->Si_E[countMust2];
         CsI_E_M2= M2->CsI_E[countMust2];
         E_SSSD = SSSD->Energy[countSSSD];
@@ -135,7 +156,6 @@ void Analysis::TreatEvent(){
         // if CsI
         if(CsI_E_M2>0 ){
           // The energy in CsI is calculate form dE/dx Table because 
-          // 20um resolution is poor
           Energy = 
             He3Si.EvaluateEnergyFromDeltaE(Si_E_M2,300*micrometer,
                 ThetaM2Surface, 0.01*MeV, 
@@ -149,11 +169,11 @@ void Analysis::TreatEvent(){
         E_M2 += Si_E_M2;
 
         // Evaluate energy using the thickness 
-        ELab = He3Al.EvaluateInitialEnergy( Energy ,2*0.4*micrometer , ThetaM2Surface); 
-        ELab = He3Si.EvaluateInitialEnergy( ELab ,20*micrometer , ThetaM2Surface);
-        ELab = He3Al.EvaluateInitialEnergy( ELab ,0.4*micrometer , ThetaM2Surface);
+        ELab = He3Al.EvaluateInitialEnergy( Energy , 2*0.4*micrometer , ThetaM2Surface); 
+        ELab = He3Si.EvaluateInitialEnergy( ELab   , 20*micrometer    , ThetaM2Surface);
+        ELab = He3Al.EvaluateInitialEnergy( ELab   , 0.4*micrometer   , ThetaM2Surface);
         // Target Correction
-        ELab   = He3CD2.EvaluateInitialEnergy( ELab ,TargetThickness/2., ThetaNormalTarget);
+        ELab = He3CD2.EvaluateInitialEnergy( ELab ,TargetThickness*0.5, ThetaNormalTarget);
         /************************************************/
 
         /************************************************/
@@ -183,6 +203,10 @@ void Analysis::InitOutputBranch() {
   RootOutput::getInstance()->GetTree()->Branch("ELab",&ELab,"ELab/D");
   RootOutput::getInstance()->GetTree()->Branch("ThetaLab",&ThetaLab,"ThetaLab/D");
   RootOutput::getInstance()->GetTree()->Branch("ThetaCM",&ThetaCM,"ThetaCM/D");
+  RootOutput::getInstance()->GetTree()->Branch("BeamEnergy",&BeamEnergy,"BeamEnergy/D"); 
+  RootOutput::getInstance()->GetTree()->Branch("OriginalELab",&OriginalELab,"OriginalELab/D");
+  RootOutput::getInstance()->GetTree()->Branch("OriginalThetaLab",&OriginalThetaLab,"OriginalThetaLab/D");
+  RootOutput::getInstance()->GetTree()->Branch("OriginalBeamEnergy",&OriginalBeamEnergy,"OriginalBeamEnergy/D");
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -190,6 +214,9 @@ void Analysis::InitInputBranch(){
   RootInput:: getInstance()->GetChain()->SetBranchStatus("InitialConditions",true );
   RootInput:: getInstance()->GetChain()->SetBranchStatus("fIC_*",true );
   RootInput:: getInstance()->GetChain()->SetBranchAddress("InitialConditions",&Initial);
+  RootInput:: getInstance()->GetChain()->SetBranchStatus("ReactionConditions",true );
+  RootInput:: getInstance()->GetChain()->SetBranchStatus("fRC_*",true );
+  RootInput:: getInstance()->GetChain()->SetBranchAddress("ReactionConditions",&ReactionConditions);
 }
 
 ////////////////////////////////////////////////////////////////////////////////     
@@ -197,7 +224,11 @@ void Analysis::ReInitValue(){
   Ex = -1000 ;
   ELab = -1000;
   ThetaLab = -1000;
+  BeamEnergy = -1000;
   ThetaCM = -1000;
+  OriginalELab = -1000;
+  OriginalThetaLab = -1000;
+  
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/Examples/Example1/Analysis.h b/Examples/Example1/Analysis.h
index 2f1deee862ad3df92be19fe20824d8cc1d2e247e..908a9f782c1812208524ef2cab6eae4dde6b4de7 100644
--- a/Examples/Example1/Analysis.h
+++ b/Examples/Example1/Analysis.h
@@ -8,9 +8,9 @@
  *****************************************************************************/
 
 /*****************************************************************************
- * Original Author: Adrien MATTA  contact address: a.matta@surrey.ac.uk      *
+ * Original Author: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
  *                                                                           *
- * Creation Date  : march 2025                                               *
+ * Creation Date  : march 2015                                               *
  * Last update    :                                                          *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
@@ -21,13 +21,16 @@
  *                                                                           *
  *                                                                           *
  *****************************************************************************/
-#include"NPVAnalysis.h"
+#include "NPVAnalysis.h"
 #include "TMust2Physics.h"
 #include "TSSSDPhysics.h"
 #include "TInitialConditions.h"
+#include "TReactionConditions.h"
 #include "NPEnergyLoss.h"
 #include "NPReaction.h"
 #include "TRandom3.h"
+
+#include"NPDetectorManager.h"
 class Analysis: public NPL::VAnalysis{
   public:
     Analysis();
@@ -47,6 +50,10 @@ class Analysis: public NPL::VAnalysis{
     double ELab;
     double ThetaLab;
     double ThetaCM;
+    double BeamEnergy;
+    double OriginalELab;
+    double OriginalThetaLab;
+    double OriginalBeamEnergy;
     NPL::Reaction* He10Reaction;
 
     // intermediate variable
@@ -64,7 +71,6 @@ class Analysis: public NPL::VAnalysis{
     double E_M2 ;
     double Si_X_M2;
     double Si_Y_M2;
-    double ZTarget;
     double TargetThickness;
 
     NPL::EnergyLoss He3CD2  ;
@@ -75,5 +81,6 @@ class Analysis: public NPL::VAnalysis{
     TMust2Physics* M2;
     TSSSDPhysics* SSSD;
     TInitialConditions* Initial;
+    TReactionConditions* ReactionConditions;
 };
 #endif
diff --git a/Examples/Example1/ShowResults.C b/Examples/Example1/ShowResults.C
index 9168863302ea8510128edcb2b9a27ed53e3affe8..3a279292678101949dcbcc2813d5f7aafac7fde0 100644
--- a/Examples/Example1/ShowResults.C
+++ b/Examples/Example1/ShowResults.C
@@ -3,7 +3,6 @@
 TCutG* ETOF=NULL;
 TCutG* EDE=NULL;
 TChain* chain=NULL ;
-TCanvas* c1 = NULL;
 
 ////////////////////////////////////////////////////////////////////////////////
 void LoadCuts(){
@@ -25,23 +24,25 @@ void ShowResults(){
     LoadChain();
     LoadCuts();
     
-    c1 = new TCanvas("Example1","Example1",0,0,600,600);
+    TCanvas* c1 = new TCanvas("Detected","Detected",0,0,600,600);
     c1->Divide(2,2);
     
     // Light Particle ID //
     // E-DE
     c1->cd(1);
     chain->Draw("SSSD.Energy:MUST2.Si_E>>hIDE(1000,0,35,1000,0,5)","MUST2.CsI_E<0 && MUST2.TelescopeNumber<5","colz");
+
     EDE->Draw("same");
     
     // E-TOF
     c1->cd(2);
-    chain->Draw("-MUST2.Si_T:SSSD.Energy+MUST2.Si_E>>hIDT(1000,0,35,1000,-15,0)","MUST2.CsI_E<0 && MUST2.TelescopeNumber<5","colz");
+    chain->Draw("-MUST2.Si_T:SSSD.Energy+MUST2.Si_E>>hIDT(1000,0,35,1000,-30,0)","MUST2.CsI_E<0 && MUST2.TelescopeNumber<5","colz");
+
+
     ETOF->Draw("same");
     
     // Kinematical Line //
     c1->cd(3);
-    //chain->Draw("ELab:ThetaLab>>hKine(500,0,45,400,0,40)","MUST2.CsI_E<0 && MUST2.TelescopeNumber<5 && EDE && ETOF","colz");
     chain->Draw("ELab:ThetaLab>>h(1000,0,90,1000,0,30)","MUST2.CsI_E<0 && MUST2.TelescopeNumber<5 && EDE && ETOF","colz");
     
     NPL::Reaction r("11Li(d,3He)10He@553");
@@ -72,4 +73,25 @@ void ShowResults(){
     f->SetLineColor(kOrange-3);
     f->SetNpx(1000);
     
+    TCanvas* c2 = new TCanvas("Simulated","Simulated",600,0,600,600);
+    c2->Divide(2,2);
+    
+    c2->cd(1);
+    chain->Draw("OriginalELab:OriginalThetaLab>>hS(1000,0,90,1000,0,30)","","col");
+    Kine->Draw("c");
+    c2->cd(2);
+    chain->Draw("OriginalELab:ELab>>hS2(1000,0,30,1000,0,30)","ELab>0","col");
+    TLine* lE = new TLine(0,0,30,30);
+    lE->Draw();
+    c2->cd(3);
+    chain->Draw("OriginalThetaLab:ThetaLab>>hS3(1000,0,90,1000,0,90)","ThetaLab>0","col");
+    TLine* lT = new TLine(0,0,90,90);
+    lT->Draw();
+    c2->cd(4);
+    chain->Draw("OriginalBeamEnergy:BeamEnergy>>hS4(1000,500,600,1000,500,600)","BeamEnergy>0","col");
+    TLine* lB = new TLine(500,500,600,600);
+    lB->Draw();
+    
+
+
 }
diff --git a/Examples/Example1/cuts/ETOF.root b/Examples/Example1/cuts/ETOF.root
index 462bead6ba3db3a5e7e68426a892a94f0aa23d75..067d548e7c6f2d4adc224047d2a23700cc380032 100644
Binary files a/Examples/Example1/cuts/ETOF.root and b/Examples/Example1/cuts/ETOF.root differ
diff --git a/Inputs/DetectorConfiguration/Example1.detector b/Inputs/DetectorConfiguration/Example1.detector
index 08299c1880580afc4b54374671e184f7cf21c07c..e67ae572d0e1b77285c08345d01c6aaa5e07f11f 100644
--- a/Inputs/DetectorConfiguration/Example1.detector
+++ b/Inputs/DetectorConfiguration/Example1.detector
@@ -1,9 +1,9 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Target
- THICKNESS= 18 micrometer
- RADIUS=  30 mm
- MATERIAL= CD2
- ANGLE= 0 deg
+ Thickness= 18 micrometer
+ Radius=  30 mm
+ Material= CD2
+ Angle= 0 deg
  X= 0 mm
  Y= 0 mm 
  Z= 0 mm
diff --git a/Inputs/EventGenerator/11Li.beam b/Inputs/EventGenerator/11Li.beam
index 361a7b898c8924347fa6e013af88ea4032d4bbee..cd92cf20ee125da3baa228a1304b6f3f139cea6a 100644
--- a/Inputs/EventGenerator/11Li.beam
+++ b/Inputs/EventGenerator/11Li.beam
@@ -2,7 +2,7 @@
 %%%%%%%%% Reaction file for 11Li(d,3He)10He reaction %%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Beam
-  Particle= 11Li
+  Particle= 10He
   Energy= 553
  SigmaEnergy= 20
  SigmaThetaX= 0.6138
diff --git a/Inputs/EventGenerator/Example1.reaction b/Inputs/EventGenerator/Example1.reaction
index 1b69a917b0a96e05b4c804ebb4f4362a8f2b75a9..24c22817ff15ddffa0fe5384736a43bcdcb0f49e 100644
--- a/Inputs/EventGenerator/Example1.reaction
+++ b/Inputs/EventGenerator/Example1.reaction
@@ -30,9 +30,12 @@ TwoBodyReaction
  ShootHeavy= 1
   
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%ParticleDecay 10He
-% Daughter= 8He n n
-% ExcitationEnergy= 0 0 0 MeV
-% shoot= 1 1 1
-    
+Decay 10He
+ Daughter= 8He n n
+ ExcitationEnergy= 0 0 0 MeV
+ Threshold= 0 MeV
+ BranchingRatio= 0.5
+ LifeTime= 0 ns
+ Shoot= 1 1 1
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/Inputs/EventGenerator/alpha.source b/Inputs/EventGenerator/alpha.source
index ea19e4bc82f69f9e898e26f1beadd9a70658a35b..b01a3a158a752d5b5f14d9fe656ae699f063b5ae 100644
--- a/Inputs/EventGenerator/alpha.source
+++ b/Inputs/EventGenerator/alpha.source
@@ -4,13 +4,13 @@
 %      Energy are given in MeV , Position in mm      % 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Isotropic
- EnergyLow= 5.5 MeV
- EnergyHigh= 5.5 MeV
+ EnergyLow= 3.5 MeV
+ EnergyHigh= 3.5 MeV
  HalfOpenAngleMin= 0 deg
- HalfOpenAngleMax= 90 deg
+ HalfOpenAngleMax= 180 deg
  x0= 0 mm
  y0= 0 mm
- z0= -110 mm
+ z0= 0 mm
  Particle= alpha
  ExcitationEnergy= 0 MeV
 
diff --git a/NPLib/CMakeLists.txt b/NPLib/CMakeLists.txt
index 6aba8713fe3d72bf28656b43a4aafe54c9890c8a..fd1349561149b0825b5b7e34a68e96a77b049519 100644
--- a/NPLib/CMakeLists.txt
+++ b/NPLib/CMakeLists.txt
@@ -2,7 +2,6 @@ cmake_minimum_required (VERSION 2.8)
 include(CheckCXXCompilerFlag)
 project(NPLib CXX)
 set(CMAKE_BUILD_TYPE Release)
-
 # Setting the policy to match Cmake version
 cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
 
@@ -19,6 +18,23 @@ set(NPLIB_VERSION_DETA 45)
 configure_file(Core/NPLibVersion.h.in Core/NPLibVersion.h @ONLY)
 set(DETLIST ${ETLIST})
 
+#activate Multithreading (on by default)
+if(NOT DEFINED NPMULTITHREADING) 
+  set(NPMULTITHREADING 1)
+  else()
+  set(NPMULTITHREADING ${NPMULTITHREADING})
+endif()
+
+if(NPMULTITHREADING)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNPMULTITHREADING=1")
+ message("Building application with MultiThreading Support")
+ else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNPMULTITHREADING=0")
+ message("Building application with no MutilThreading Support")
+endif()
+
+
+
 string(COMPARE EQUAL "${DETLIST}" "" rdet)
 if(rdet)
     message("Building all detectors")
diff --git a/NPLib/CanvasList.txt b/NPLib/CanvasList.txt
index 69f992086f52fb955120c45fd5545f9f8bdd89e0..144fbf0679ff712747b29bca6dbbd1fab9a27b7b 100644
--- a/NPLib/CanvasList.txt
+++ b/NPLib/CanvasList.txt
@@ -13,4 +13,13 @@ Canvas
  Histo= MM@Telescope_STRX_RAW_MULT MM@Telescope_STRY_RAW_MULT
  
 
+Canvas
+  Path= test
+  Divide= 2 2 
+  Histo= h1 h2
+
+Canvas
+  Path= pipo
+  Divide= 2 2 
+  Histo= h2 h1
 
diff --git a/NPLib/Core/NPCalibrationManager.cxx b/NPLib/Core/NPCalibrationManager.cxx
index 4503a7268a341b7e9d82c43cdc5b88f93ae13a9f..0b03b3a59af944a176c544e73a60a2c439ec7daf 100644
--- a/NPLib/Core/NPCalibrationManager.cxx
+++ b/NPLib/Core/NPCalibrationManager.cxx
@@ -33,7 +33,7 @@
 //////////////////////////////////////////////////////////////////
 CalibrationManager* CalibrationManager::instance = 0;
 
-CalibrationManager* CalibrationManager::getInstance(const string& configFileName){
+CalibrationManager* CalibrationManager::getInstance(const std::string& configFileName){
   // A new instance of CalibrationManager is created if it does not exist:
   if (instance == 0) {
     instance = new CalibrationManager(configFileName);
@@ -44,28 +44,28 @@ CalibrationManager* CalibrationManager::getInstance(const string& configFileName
 }
 
 //////////////////////////////////////////////////////////////////
-CalibrationManager::CalibrationManager(string configFileName){
+CalibrationManager::CalibrationManager(std::string configFileName){
   // Read configuration file Buffer
-  string lineBuffer, dataBuffer;
+  std::string lineBuffer, dataBuffer;
 
   // Open file
-  ifstream inputConfigFile;
+  std::ifstream inputConfigFile;
   inputConfigFile.open(configFileName.c_str());
 
   if(!NPOptionManager::getInstance()->IsDefault("Calibration")){
-    cout << endl;
-    cout << "/////////// Calibration Information ///////////" << endl;
-    cout << "Getting list of calibration files" << endl;
+    std::cout << std::endl;
+    std::cout << "/////////// Calibration Information ///////////" << std::endl;
+    std::cout << "Getting list of calibration files" << std::endl;
   }
  
   if (!inputConfigFile) {
       if(!NPOptionManager::getInstance()->IsDefault("Calibration"))
-        cout << "Calibration Path file: " << configFileName << " not found" << endl; 
+        std::cout << "Calibration Path file: " << configFileName << " not found" << std::endl; 
     return;
   }
 
   else { 
-    cout << "Reading list of files from: " << configFileName << endl; 
+    std::cout << "Reading list of files from: " << configFileName << std::endl; 
     while (!inputConfigFile.eof()) {
       getline(inputConfigFile, lineBuffer);
 
@@ -81,13 +81,13 @@ CalibrationManager::CalibrationManager(string configFileName){
 
           else if (!inputConfigFile.eof()) {
             AddFile(dataBuffer);
-            cout << "Adding file " << dataBuffer << " to Calibration" << endl;
+            std::cout << "Adding file " << dataBuffer << " to Calibration" << std::endl;
           }
         }
       }
     }
   }
-  cout << "/////////////////////////////////" << endl;
+  std::cout << "/////////////////////////////////" << std::endl;
 }
 
 //////////////////////////////////////////////////////////////////
@@ -95,8 +95,8 @@ CalibrationManager::~CalibrationManager()
 {}
 
 //////////////////////////////////////////////////////////////////
-bool CalibrationManager::AddParameter(string DetectorName , string ParameterName , string Token ){
-  string ParameterPath = DetectorName + "/" + ParameterName ;
+bool CalibrationManager::AddParameter(std::string DetectorName , std::string ParameterName , std::string Token ){
+  std::string ParameterPath = DetectorName + "/" + ParameterName ;
   fToken[Token] = ParameterPath ;
   return true;
 }
@@ -107,16 +107,16 @@ void CalibrationManager::ClearCalibration(){
 }
 
 /////////////////////////////////////////////////////////////////
-vector<double> CalibrationManager::GetCorrection(const string& ParameterPath) const {
-  vector<double> Coeff ;
-  map< string , vector<double> >::const_iterator it ;
+std::vector<double> CalibrationManager::GetCorrection(const std::string& ParameterPath) const {
+  std::vector<double> Coeff ;
+  std::map< std::string , std::vector<double> >::const_iterator it ;
   it = fCalibrationCoeff.find(ParameterPath)  ;
 
   if(it == fCalibrationCoeff.end() )
   {
-    /* cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << endl ;
-       cout << " ERROR: PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE  " << endl ;
-       cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << endl ;*/
+    /* std::cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << std::endl ;
+       std::cout << " ERROR: PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE  " << std::endl ;
+       std::cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << std::endl ;*/
 
     return Coeff ;
   }
@@ -129,9 +129,9 @@ vector<double> CalibrationManager::GetCorrection(const string& ParameterPath) co
 
 //////////////////////////////////////////////////////////////////
 void CalibrationManager::LoadParameterFromFile(){
-  ifstream CalibFile    ;
-  string    DataBuffer   ;
-  string   LineBuffer ;
+  std::ifstream  CalibFile;
+  std::string    DataBuffer;
+  std::string    LineBuffer;
 
   // Get pointer to the TAsciifile CalibrationFile in RootOuput
   TAsciiFile* AcsiiCalibration = RootOutput::getInstance()->GetAsciiFileCalibration();
@@ -140,17 +140,17 @@ void CalibrationManager::LoadParameterFromFile(){
   unsigned int sizeF = fFileList.size();
   for(unsigned int i = 0 ; i < sizeF ; i++){
     CalibFile.open( fFileList[i].c_str() );
-    map<string,string>::iterator it ;
+    std::map<std::string,std::string>::iterator it ;
 
     if(!CalibFile){
-      ostringstream message;
+      std::ostringstream message;
       message << "file " << fFileList[i] << " is missing " ;
       NPL::SendWarning ("NPL::CalibrationManager" , message.str());
     }
 
     else {
       // Append the Calibration File to the RootOuput for Back-up
-      string comment = "%%% From File " + fFileList[i] + "%%%";
+      std::string comment = "%%% From File " + fFileList[i] + "%%%";
       AcsiiCalibration->AppendLine(comment.c_str());
       AcsiiCalibration->Append(fFileList[i].c_str());
 
@@ -158,8 +158,8 @@ void CalibrationManager::LoadParameterFromFile(){
         // Read the file Line by line
         getline(CalibFile, LineBuffer);
 
-        // Create a istringstream to manipulate the line easely
-        istringstream theLine (LineBuffer,istringstream::in);
+        // Create a istd::stringstream to manipulate the line easely
+        std::istringstream theLine (LineBuffer,std::istringstream::in);
         theLine >> DataBuffer ;
 
         // Comment support, comment symbole is %
@@ -170,16 +170,16 @@ void CalibrationManager::LoadParameterFromFile(){
         it=fToken.find(DataBuffer);
         //   if the word is find, values are read
         if( it!=fToken.end() ){ 
-          vector<double> Coeff ;
+          std::vector<double> Coeff ;
           while( theLine >> DataBuffer ){
             Coeff.push_back( atof(DataBuffer.c_str()) ) ;
           }
 
           //   Check this parameter is not already define
           if( fCalibrationCoeff.find(it->second) != fCalibrationCoeff.end() ) 
-            cout << "WARNING: Parameter " << it->second << " Already found. It will be overwritten. " << endl;
+            std::cout << "WARNING: Parameter " << it->second << " Already found. It will be overwritten. " << std::endl;
 
-          //   Add the list of Coeff to the Coeff map using Parameter Path as index
+          //   Add the list of Coeff to the Coeff std::map using Parameter Path as index
           fCalibrationCoeff[ it->second ] = Coeff ;
         }
       }
@@ -189,9 +189,9 @@ void CalibrationManager::LoadParameterFromFile(){
 }
 
 //////////////////////////////////////////////////////////////////
-double CalibrationManager::ApplyCalibration(const string& ParameterPath , const double& RawValue) const {
-  map< string , vector<double> >::const_iterator it ;
-  static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end();
+double CalibrationManager::ApplyCalibration(const std::string& ParameterPath , const double& RawValue) const {
+  std::map< std::string , std::vector<double> >::const_iterator it ;
+  static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end();
 
   //   Find the good parameter in the Map
   // Using Find method of stl is the fastest way
@@ -199,11 +199,11 @@ double CalibrationManager::ApplyCalibration(const string& ParameterPath , const
   // If the find methods return the end iterator it's mean the parameter was not found
   if(it == ite ){
 //by Shuya 170222
-//cout << ParameterPath << "!" << endl;
+//std::cout << ParameterPath << "!" << std::endl;
     return RawValue ;
   }
 
-  // The vector size give the degree of calibration
+  // The std::vector size give the degree of calibration
   // We just apply the coeff it->second and returned the calibrated value
   double CalibratedValue = 0 ;
   unsigned int mysize = it->second.size(); 
@@ -215,9 +215,9 @@ double CalibrationManager::ApplyCalibration(const string& ParameterPath , const
 
 }
 //////////////////////////////////////////////////////////////////
-double CalibrationManager::ApplyCalibrationDebug(const string& ParameterPath , const double& RawValue) const{
-  map< string , vector<double> >::const_iterator it ;
-  static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end();
+double CalibrationManager::ApplyCalibrationDebug(const std::string& ParameterPath , const double& RawValue) const{
+  std::map< std::string , std::vector<double> >::const_iterator it ;
+  static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end();
 
   //   Find the good parameter in the Map
   // Using Find method of stl is the fastest way
@@ -225,30 +225,30 @@ double CalibrationManager::ApplyCalibrationDebug(const string& ParameterPath , c
 
   // If the find methods return the end iterator it's mean the parameter was not found
   if(it == ite ){
-           cout << " PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE  " << endl ;
+           std::cout << " PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE  " << std::endl ;
     return RawValue ;
   }
 
   // Else we take the second part of the element (first is index, ie: parameter path)
-  // Second is the vector of Coeff
-  cout << it->first << " :  raw = " << RawValue << " coeff = "  ;
-  vector<double> Coeff = it->second  ;
+  // Second is the std::vector of Coeff
+  std::cout << it->first << " :  raw = " << RawValue << " coeff = "  ;
+  std::vector<double> Coeff = it->second  ;
 
-  // The vector size give the degree of calibration
+  // The std::vector size give the degree of calibration
   // We just apply the coeff and returned the calibrated value
 
   double CalibratedValue = 0 ;
   for(unsigned int i = 0 ; i < Coeff.size() ; i++){
-    cout << Coeff[i] << " " ;
+    std::cout << Coeff[i] << " " ;
     CalibratedValue += Coeff[i]*pow(RawValue, (double)i);
   }
-  cout << "results = " << CalibratedValue << endl ;
+  std::cout << "results = " << CalibratedValue << std::endl ;
   return CalibratedValue ;
 }
 ////////////////////////////////////////////////////////////////////////////////
-double CalibrationManager::ApplyResistivePositionCalibration(const string& ParameterPath , const double& DeltaRawValue) const{
-  map< string , vector<double> >::const_iterator it ;
-  static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end();
+double CalibrationManager::ApplyResistivePositionCalibration(const std::string& ParameterPath , const double& DeltaRawValue) const{
+  std::map< std::string , std::vector<double> >::const_iterator it ;
+  static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end();
 
   //   Find the good parameter in the Map
   // Using Find method of stl is the fastest way
@@ -259,21 +259,19 @@ double CalibrationManager::ApplyResistivePositionCalibration(const string& Param
     return DeltaRawValue ;
   }
 
-  vector<double> Coeff = it->second  ;
-
   // Check that the number of coeff is ok
   if(it->second.size()!=2) 
     return DeltaRawValue ; 
 
-  double CalibratedValue = (DeltaRawValue-Coeff[0])/(Coeff[1]);
+  double CalibratedValue = (DeltaRawValue-it->second[0])/(it->second[1]);
 
   return CalibratedValue ;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-double CalibrationManager::ApplyResistivePositionCalibrationDebug(const string& ParameterPath , const double& DeltaRawValue) const {
-  map< string , vector<double> >::const_iterator it ;
-  static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end();
+double CalibrationManager::ApplyResistivePositionCalibrationDebug(const std::string& ParameterPath , const double& DeltaRawValue) const {
+  std::map< std::string , std::vector<double> >::const_iterator it ;
+  static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end();
 
   //   Find the good parameter in the Map
   // Using Find method of stl is the fastest way
@@ -281,30 +279,30 @@ double CalibrationManager::ApplyResistivePositionCalibrationDebug(const string&
 	
   // If the find methods return the end iterator it's mean the parameter was not found
   if(it == ite ){
-      cout << " PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE  " << endl ;
+      std::cout << " PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE  " << std::endl ;
     return DeltaRawValue ;
   }
 
-	vector<double> Coeff = it->second  ;
+	std::vector<double> Coeff = it->second  ;
 	
   // Check that the number of coeff is ok
   if(Coeff.size()!=2){
-      cout << " NUMBER OF COEFF " << Coeff.size() << " IS DIFFERENT THAN TWO " << endl ;
+      std::cout << " NUMBER OF COEFF " << Coeff.size() << " IS DIFFERENT THAN TWO " << std::endl ;
     return DeltaRawValue ; 
   }
 
   double CalibratedValue = (DeltaRawValue-Coeff[0])/(Coeff[1]);
-  cout << it->first << " :  raw = " << DeltaRawValue << " coeff = "  ;
-  cout << Coeff[0] << " " << Coeff[1] << endl ;
-  cout << "results = " << CalibratedValue << endl ;
+  std::cout << it->first << " :  raw = " << DeltaRawValue << " coeff = "  ;
+  std::cout << Coeff[0] << " " << Coeff[1] << std::endl ;
+  std::cout << "results = " << CalibratedValue << std::endl ;
 
   return CalibratedValue ;
 }
 
 //////////////////////////////////////////////////////////////////
-bool CalibrationManager::ApplyThreshold(const string& ParameterPath, const double& RawValue) const{
-  map< string , vector<double> >::const_iterator it ;
-  static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end();
+bool CalibrationManager::ApplyThreshold(const std::string& ParameterPath, const double& RawValue) const{
+  std::map< std::string , std::vector<double> >::const_iterator it ;
+  static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end();
   
   //   Find the good parameter in the Map
   // Using Find method of stl is the fastest way
@@ -315,20 +313,16 @@ bool CalibrationManager::ApplyThreshold(const string& ParameterPath, const doubl
     return false;
   }
 
-  // Else we take the second part of the element (first is index, ie: parameter path)
-  // Second is the vector of Coeff
-  vector<double> Coeff = it->second  ;
-
-  // The vector size give the degree of calibration
+  // The std::vector size give the degree of calibration
   // We just apply the coeff and returned the calibrated value
 
-  double ThresholdValue = 0 ;
+  double ThresholdValue ;
 
-  if(Coeff.size()==2){ // CATS style
-    ThresholdValue = Coeff[0] + 3*Coeff[1];
+  if(it->second.size()==2){ // CATS style
+    ThresholdValue = it->second[0] + 3*it->second[1];
   }
   else{ // Standard Threshold
-    ThresholdValue = Coeff[0];
+    ThresholdValue = it->second[0];
   }
 
 
@@ -339,14 +333,14 @@ bool CalibrationManager::ApplyThreshold(const string& ParameterPath, const doubl
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////
-double CalibrationManager::GetPedestal(const string& ParameterPath) const{
+double CalibrationManager::GetPedestal(const std::string& ParameterPath) const{
   return GetValue(ParameterPath,0);
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////
-double CalibrationManager::GetValue(const string& ParameterPath,const unsigned int& order) const{
-  map< string , vector<double> >::const_iterator it ;
-  static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end();
+double CalibrationManager::GetValue(const std::string& ParameterPath,const unsigned int& order) const{
+  std::map< std::string , std::vector<double> >::const_iterator it ;
+  static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end();
 
   //   Find the good parameter in the Map
   // Using Find method of stl is the fastest way
@@ -357,7 +351,7 @@ double CalibrationManager::GetValue(const string& ParameterPath,const unsigned i
     return 0;
   }
 
-  // The vector size give the degree of calibration
+  // The std::vector size give the degree of calibration
   double Value = 0 ;
   if(it->second.size()>order){
      Value = it->second[order];
diff --git a/NPLib/Core/NPCalibrationManager.h b/NPLib/Core/NPCalibrationManager.h
index e99e008fad1fc5f7c0364babe4f05bb3634445ed..2bf88eaad0fb1418bae8659e3db2ee736b7912fb 100644
--- a/NPLib/Core/NPCalibrationManager.h
+++ b/NPLib/Core/NPCalibrationManager.h
@@ -28,44 +28,43 @@
 #include<vector>
 #include<map>
 
-using namespace std ;
 
 class CalibrationManager{
 
   protected:   //   Constructor and Destructor are protected because the class is a singleton
-    CalibrationManager(string configFileName);
+    CalibrationManager(std::string configFileName);
     ~CalibrationManager();
 
   public: // Accessor
     //   return a pointer to the calibration manager instance.
     //   if the instance does not exist it is created.
-    static CalibrationManager* getInstance(const string& configFileName="XXX");
+    static CalibrationManager* getInstance(const std::string& configFileName="XXX");
 
   private: // the instance
     //   Hold a pointer on itself
     static CalibrationManager* instance ;
 
   public:   //   File Management
-    inline void AddFile(string Path) { fFileList.push_back(Path) ;} ;
+    inline void AddFile(std::string Path) { fFileList.push_back(Path) ;} ;
 
 
   public:   // Calibration Parameter Related
 
     // call like : myCalibrationManager->AddParameter( "MUST2" ,"Telescope5_Si_X38_E", "T5_Si_X38_E" )
     // return false if the token is not found in the file list
-    bool AddParameter(string DetectorName , string ParameterName , string Token)    ;      
+    bool AddParameter(std::string DetectorName , std::string ParameterName , std::string Token)    ;      
 
     // call like : myCalibrationManager->ApplyCalibration( "MUST2/Telescope5_Si_X38_E" , RawEnergy )
     // return the Calibrated value
-    double ApplyCalibration (const string& ParameterPath , const double& RawValue) const ;
-    double ApplyResistivePositionCalibration (const string& ParameterPath , const double& RawValue) const ;
+    double ApplyCalibration (const std::string& ParameterPath , const double& RawValue) const ;
+    double ApplyResistivePositionCalibration (const std::string& ParameterPath , const double& RawValue) const ;
     // Same but with debug information outputs
-    double ApplyCalibrationDebug (const string& ParameterPath , const double& RawValue) const ;
-    double ApplyResistivePositionCalibrationDebug (const string& ParameterPath , const double& RawValue) const ;
+    double ApplyCalibrationDebug (const std::string& ParameterPath , const double& RawValue) const ;
+    double ApplyResistivePositionCalibrationDebug (const std::string& ParameterPath , const double& RawValue) const ;
 
-    bool ApplyThreshold (const string& ParameterPath, const double& RawValue) const ;
-    double GetPedestal  (const string& ParameterPath) const ;
-    double GetValue     (const string& ParameterPath,const unsigned int& order) const ;
+    bool ApplyThreshold (const std::string& ParameterPath, const double& RawValue) const ;
+    double GetPedestal  (const std::string& ParameterPath) const ;
+    double GetValue     (const std::string& ParameterPath,const unsigned int& order) const ;
 
   public:   //   To be called after initialisation
     //   Loop over the file list and catch the file used for calibration
@@ -74,18 +73,18 @@ class CalibrationManager{
   public: //Clear calibration if we have some calibration files to read 
     void ClearCalibration();
 
-  public: //Get correction coefficient vector
-    vector<double> GetCorrection (const string& ParameterPath) const ;
+  public: //Get correction coefficient std::vector
+    std::vector<double> GetCorrection (const std::string& ParameterPath) const ;
 
   private:
-    //   This map hold a vector of the calibration coefficient. Index is the Parameter path, like "MUST2/Telescope5_Si_X38_E"
+    //   This std::map hold a std::vector of the calibration coefficient. Index is the Parameter path, like "MUST2/Telescope5_Si_X38_E"
 
-    map< string , vector<double> >   fCalibrationCoeff ;  
+    std::map< std::string , std::vector<double> >   fCalibrationCoeff ;  
     //   Hold the path of all the registered file of coeff
-    vector<string>   fFileList   ;
+    std::vector<std::string>   fFileList   ;
 
     //   Hold The list of Token. Index is the Token, value the parameter path.
-    map< string , string >   fToken      ;
+    std::map< std::string , std::string >   fToken      ;
 
 };
 
diff --git a/NPLib/Core/NPCore.cxx b/NPLib/Core/NPCore.cxx
index 082c0794b5cc95f1c2d80569b5c0b6fdcbfd5e0a..04fda36c45f4739c38638f7ccaea90110643bef9 100644
--- a/NPLib/Core/NPCore.cxx
+++ b/NPLib/Core/NPCore.cxx
@@ -21,6 +21,7 @@
  *****************************************************************************/
 #include "NPCore.h"
 #include<iostream>
+#include<string>
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::SendWarning(std::string Class, std::string Warning){
   std::cerr << "\033[5;34m";
@@ -44,3 +45,23 @@ void NPL::SendErrorAndExit(std::string Class , std::string Error){
   std::cerr << std::endl;
   exit(1); 
 }
+////////////////////////////////////////////////////////////////////////////////
+namespace NPL{
+  static std::string itoa_array[10000];
+
+  class itoa_proxy{
+    public:
+      itoa_proxy(){
+      char buffer[]="10000";
+        for(int i = 0 ; i < 10000 ; i++){
+          sprintf(buffer,"%d",i);
+          itoa_array[i] = buffer;
+        }
+      }
+  };
+  static itoa_proxy itoa_p ;
+}
+
+std::string NPL::itoa(const int& i){
+  return NPL::itoa_array[i];
+}
diff --git a/NPLib/Core/NPCore.h b/NPLib/Core/NPCore.h
index 181dd18d0d34ff6a52300cac4a101fe18f20a90a..9f14ffadd2b65bd0d096f8b1241805930713dc1e 100644
--- a/NPLib/Core/NPCore.h
+++ b/NPLib/Core/NPCore.h
@@ -24,6 +24,7 @@
 
 #include<string>
 namespace NPL{
+  std::string itoa(const int&); 
   void SendWarning(std::string Class, std::string Warning);
   void SendInformation(std::string Class, std::string Information);
   void SendErrorAndExit(std::string Class,std::string Error);
diff --git a/NPLib/Core/NPDetectorFactory.cxx b/NPLib/Core/NPDetectorFactory.cxx
index 5abf466a07396d29ac87d620b4ac1197f404a380..5c42b5f7848ff577a9472f06d3bab52fc776dd75 100644
--- a/NPLib/Core/NPDetectorFactory.cxx
+++ b/NPLib/Core/NPDetectorFactory.cxx
@@ -57,19 +57,19 @@ void NPL::DetectorFactory::ReadClassList(std::string FileList){
     std::ifstream InFile(FileList.c_str());
 
     if(!InFile.is_open()){
-      string error = "Detector Class List file " +FileList +" Not found";
+      std::string error = "Detector Class List file " +FileList +" Not found";
       NPL::SendErrorAndExit("NPL::NPL::DetectorFactory",error);
       exit(1);
     }
 
-    string Token, LibName;
+    std::string Token, LibName;
     while(InFile >> Token >> LibName)
       m_TokenLib[Token] = LibName; 
 }
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorFactory::CreateClassList(std::string FileList){
-  ofstream outFile(FileList.c_str());
-  std::map<string,string>::iterator it;
+  std::ofstream outFile(FileList.c_str());
+  std::map<std::string,std::string>::iterator it;
 
   for(it = m_TokenLib.begin();it!=m_TokenLib.end();it++){
     outFile << it->first << " " << it->second << std::endl;
diff --git a/NPLib/Core/NPDetectorManager.cxx b/NPLib/Core/NPDetectorManager.cxx
index e07f8b5427605ecaddd8720f581b8c36f06ba415..8be0afde85d0a554cef29e474dd6a6ec1a195e2c 100644
--- a/NPLib/Core/NPDetectorManager.cxx
+++ b/NPLib/Core/NPDetectorManager.cxx
@@ -45,6 +45,8 @@ using namespace NPUNITS;
 #include"TCanvas.h"
 #include "TROOT.h"
 ///////////////////////////////////////////////////////////////////////////////
+//double NPL::DetectorManager::GetTargetThickness    () {return  m_TargetThickness;}
+
 //   Default Constructor
 NPL::DetectorManager::DetectorManager(){
   m_BuildPhysicalPtr = &NPL::VDetector::BuildPhysicalEvent;
@@ -58,15 +60,39 @@ NPL::DetectorManager::DetectorManager(){
     if(NPOptionManager::getInstance()->GetCheckHistoOption())
       m_CheckSpectra = &NPL::VDetector::CheckSpectra ;
   }
-  m_WindowsThickness=0;
-  m_WindowsMaterial="";
+  m_CryoTarget=false;
+  m_TargetThickness    = 0   ;
+  m_TargetAngle        = 0   ;
+  m_TargetRadius       = 0   ;
+  m_TargetDensity      = 0   ;
+  m_TargetDensity = 0 ;
+  m_FrontDeformation = 0 ;
+  m_FrontThickness = 0 ;
+  m_FrontRadius = 0 ;
+  m_FrontMaterial = "" ;
+  m_BackDeformation = 0 ;
+  m_BackRadius = 0 ;
+  m_BackThickness = 0 ;
+  m_BackMaterial = "" ;
+  m_FrameRadius = 0 ;
+  m_FrameThickness = 0;
+  m_FrontCone = 0 ;
+  m_BackCone = 0 ;
+  m_FrameMaterial = "" ;
+  m_ShieldInnerRadius = 0 ;
+  m_ShieldOuterRadius = 0 ;
+  m_ShieldBottomLength = 0 ;
+  m_ShieldTopLength = 0 ;
+  m_ShieldFrontRadius = 0 ; 
+  m_ShieldBackRadius = 0 ;
+  m_ShieldMaterial = "" ;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 //   Default Desstructor
 NPL::DetectorManager::~DetectorManager(){
-#if __cplusplus > 199711L
+#if __cplusplus > 199711L && NPMULTITHREADING
   StopThread();
 #endif
   if(m_SpectraServer)
@@ -75,69 +101,103 @@ NPL::DetectorManager::~DetectorManager(){
 
 ///////////////////////////////////////////////////////////////////////////////
 //   Read stream at ConfigFile and pick-up Token declaration of Detector
-void NPL::DetectorManager::ReadConfigurationFile(string Path)   {
-  cout << "\033[1;36m" ;
+void NPL::DetectorManager::ReadConfigurationFile(std::string Path)   {
+  std::cout << "\033[1;36m" ;
 
   // Instantiate the Calibration Manager
   // All The detector will then add to it their parameter (see AddDetector)
   CalibrationManager::getInstance(NPOptionManager::getInstance()->GetCalibrationFile());
 
   // Access the DetectorFactory and ask it to load the Class List
-  string classlist = getenv("NPTOOL");
+  std::string classlist = getenv("NPTOOL");
   classlist += "/NPLib/ClassList.txt";
   NPL::DetectorFactory* theFactory = NPL::DetectorFactory::getInstance();
   theFactory->ReadClassList(classlist);
 
-  set<string> check;
+  std::set<std::string> check;
   NPL::InputParser parser(Path);
 
   ////////////////////////////////////////////
   //////////// Search for Target /////////////
   ////////////////////////////////////////////
-  vector<NPL::InputBlock*>  starget = parser.GetAllBlocksWithToken("Target");
-  vector<NPL::InputBlock*>  ctarget = parser.GetAllBlocksWithToken("CryoTarget");
+  std::vector<NPL::InputBlock*>  starget = parser.GetAllBlocksWithToken("Target");
+  std::vector<NPL::InputBlock*>  ctarget = parser.GetAllBlocksWithToken("CryogenicTarget");
 
   if(starget.size()==1){
     if(NPOptionManager::getInstance()->GetVerboseLevel()){
-    cout << "////       TARGET      ////" << endl;
-    cout << "//// Solid Target found " << endl;
+      std::cout << "////       TARGET      ////" << std::endl;
+      std::cout << "//// Solid Target found " << std::endl;
     }
-    vector<string> token = {"Thickness","Radius","Material","Angle","X","Y","Z"};
+    std::vector<std::string> token = {"Thickness","Radius","Material","Angle","X","Y","Z"};
     if(starget[0]->HasTokenList(token)){
-      m_TargetThickness= starget[0]->GetDouble("Thickness","micrometer");
-      m_TargetAngle=starget[0]->GetDouble("Angle","deg");
-      m_TargetMaterial=starget[0]->GetString("Material");
-      m_TargetX=starget[0]->GetDouble("X","mm");
-      m_TargetY=starget[0]->GetDouble("Y","mm");
-      m_TargetZ=starget[0]->GetDouble("Z","mm");
+      m_TargetThickness = starget[0]->GetDouble("Thickness","micrometer");
+      m_TargetAngle = starget[0]->GetDouble("Angle","deg");
+      m_TargetMaterial = starget[0]->GetString("Material");
+      m_TargetX = starget[0]->GetDouble("X","mm");
+      m_TargetY = starget[0]->GetDouble("Y","mm");
+      m_TargetZ = starget[0]->GetDouble("Z","mm");
     }
     else{
-      cout << "ERROR: Target token list incomplete, check your input file" << endl;
+      std::cout << "ERROR: Target token list incomplete, check your input file" << std::endl;
       exit(1);
     }
   }
   else if(ctarget.size()==1){
     if(NPOptionManager::getInstance()->GetVerboseLevel())
-      cout << "//// Cryogenic Target found " << endl;
-    
-    vector<string> token = {"Thickness","Radius","Material","Density","WindowsThickness","WindowsMaterial","Angle","X","Y","Z"};
-    if(ctarget[0]->HasTokenList(token)){
-      m_TargetThickness= ctarget[0]->GetDouble("Thickness","micrometer");
-      m_TargetAngle=ctarget[0]->GetDouble("Angle","deg");
-      m_TargetMaterial=ctarget[0]->GetString("Material");
-      m_WindowsThickness=ctarget[0]->GetDouble("WindowsThickness","micrometer");
-      m_WindowsMaterial=ctarget[0]->GetString("WindowsMaterial");
-      m_TargetX=ctarget[0]->GetDouble("X","mm");
-      m_TargetY=ctarget[0]->GetDouble("Y","mm");
-      m_TargetZ =ctarget[0]->GetDouble("Z","mm");
+    std::cout<< "//// Cryogenic Target found " << std::endl;
+    m_CryoTarget = true;
+    std::vector<std::string> CoreToken   = {"NominalThickness","Material","Density","Radius","Angle","X","Y","Z"};
+    std::vector<std::string> FrontToken  = {"FrontDeformation","FrontThickness","FrontRadius","FrontMaterial"};
+    std::vector<std::string> BackToken   = {"BackDeformation","BackThickness","BackRadius","BackMaterial"};
+    std::vector<std::string> FrameToken  = {"FrameRadius","FrameThickness","FrontCone","BackCone","FrameMaterial"};
+    std::vector<std::string> ShieldToken = {"ShieldInnerRadius","ShieldOuterRadius""ShieldBottomLength","ShieldTopLength","ShieldFrontRadius","ShieldBackRadius","ShieldMaterial"};
+
+    if(ctarget[0]->HasTokenList(CoreToken)){
+       // Target 
+      m_TargetThickness = ctarget[0]->GetDouble("NominalThickness","micrometer");
+      m_TargetAngle = ctarget[0]->GetDouble("Angle","deg");
+      m_TargetMaterial = ctarget[0]->GetString("Material");
+      m_TargetDensity = ctarget[0]->GetDouble("Density","g/cm3");
+      m_TargetRadius = ctarget[0]->GetDouble("Radius","mm");
+      m_TargetX = ctarget[0]->GetDouble("X","mm");
+      m_TargetY = ctarget[0]->GetDouble("Y","mm");
+      m_TargetZ = ctarget[0]->GetDouble("Z","mm");
+      m_TargetDensity = ctarget[0]->GetDouble("Density","g/cm3"); 
+      m_TargetRadius = ctarget[0]->GetDouble("Radius","mm");
+
+      // Front Window
+      m_FrontDeformation = ctarget[0]->GetDouble("FrontDeformation","mm");
+      m_FrontThickness = ctarget[0]->GetDouble("FrontThickness","micrometer");
+      m_FrontRadius = ctarget[0]->GetDouble("FrontRadius","mm");
+      m_FrontMaterial = ctarget[0]->GetString("FrontMaterial");
+
+      // Back Window
+      m_BackDeformation = ctarget[0]->GetDouble("BackDeformation","mm");
+      m_BackRadius = ctarget[0]->GetDouble("BackRadius","mm");
+      m_BackThickness = ctarget[0]->GetDouble("BackThickness","micrometer");
+      m_BackMaterial = ctarget[0]->GetString("BackMaterial");
+
+      // Cell Frame
+      m_FrameRadius = ctarget[0]->GetDouble("FrameRadius","mm");
+      m_FrameThickness = ctarget[0]->GetDouble("FrameThickness","mm");
+      m_FrontCone = ctarget[0]->GetDouble("FrontCone","deg");
+      m_BackCone = ctarget[0]->GetDouble("BackCone","deg");
+      m_FrameMaterial = ctarget[0]->GetString("FrameMaterial");
+      // Heat Shield
+      m_ShieldInnerRadius = ctarget[0]->GetDouble("ShieldInnerRadius","mm");
+      m_ShieldOuterRadius = ctarget[0]->GetDouble("ShieldOuterRadius","mm");
+      m_ShieldBottomLength = ctarget[0]->GetDouble("ShieldBottomLength","mm");
+      m_ShieldTopLength = ctarget[0]->GetDouble("ShieldTopLength","mm");
+      m_ShieldFrontRadius = ctarget[0]->GetDouble("ShieldFrontRadius","mm"); 
+      m_ShieldBackRadius = ctarget[0]->GetDouble("ShieldBackRadius","mm");
+      m_ShieldMaterial = ctarget[0]->GetString("ShieldMaterial");
     }
     else{
-      cout << "ERROR: Target token list incomplete, check your input file" << endl;
-      exit(1);
+      std::cout<< "ERROR: CryogenicTarget token list incomplete, check your input file" << std::endl;
     }
   }
   else{
-    cout << "ERROR: One and only one target shall be declared in your detector file" << endl;
+    std::cout << "ERROR: One and only one target shall be declared in your detector file" << std::endl;
   }
 
   ////////////////////////////////////////////
@@ -147,31 +207,27 @@ void NPL::DetectorManager::ReadConfigurationFile(string Path)   {
   std::vector<std::string> token = parser.GetAllBlocksToken();
   // Look for detectors among them
   for(unsigned int i = 0 ; i < token.size() ; i++){
-  VDetector* detector = theFactory->Construct(token[i]);
-  if(detector!=NULL && check.find(token[i])==check.end()){
-    if(NPOptionManager::getInstance()->GetVerboseLevel()){
-      cout << "/////////////////////////////////////////" << endl;
-      cout << "//// Adding Detector " << token[i] << endl; 
+    VDetector* detector = theFactory->Construct(token[i]);
+    if(detector!=NULL && check.find(token[i])==check.end()){
+      if(NPOptionManager::getInstance()->GetVerboseLevel()){
+        std::cout << "/////////////////////////////////////////" << std::endl;
+        std::cout << "//// Adding Detector " << token[i] << std::endl; 
+      }
+      detector->ReadConfiguration(parser);
+      if(NPOptionManager::getInstance()->GetVerboseLevel())
+        std::cout << "/////////////////////////////////////////" << std::endl;
+
+      // Add array to the VDetector Vector
+      AddDetector(token[i], detector);
+      check.insert(token[i]);
     }
-    detector->ReadConfiguration(parser);
-    if(NPOptionManager::getInstance()->GetVerboseLevel())
-      cout << "/////////////////////////////////////////" << endl;
-    
-    // Add array to the VDetector Vector
-    AddDetector(token[i], detector);
-    check.insert(token[i]);
-  }
-  else if(detector!=NULL)
-    delete detector;
+    else if(detector!=NULL)
+      delete detector;
   }
   // Now That the detector lib are loaded, we can instantiate the root input
-  string runToReadfileName = NPOptionManager::getInstance()->GetRunToReadFile();
+  std::string runToReadfileName = NPOptionManager::getInstance()->GetRunToReadFile();
   RootInput::getInstance(runToReadfileName);
 
-  // Now that the detector are all added, they can initialise their Branch to the Root I/O
-  //InitializeRootInput();
-  //InitializeRootOutput();
-
   // If Requiered, they can also instiantiate their control histogramm
   if(NPOptionManager::getInstance()->GetGenerateHistoOption())
     InitSpectra();
@@ -180,7 +236,7 @@ void NPL::DetectorManager::ReadConfigurationFile(string Path)   {
   CalibrationManager::getInstance()->LoadParameterFromFile();
 
   // Start the thread if multithreading supported
-#if __cplusplus > 199711L
+#if __cplusplus > 199711L && NPMULTITHREADING
   InitThreadPool();
 #endif
 
@@ -189,32 +245,21 @@ void NPL::DetectorManager::ReadConfigurationFile(string Path)   {
 
 ///////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorManager::BuildPhysicalEvent(){
-#if __cplusplus > 199711L
-  // add new job
-//cout << "TEST0a" << endl;
-  map<string,VDetector*>::iterator it;
-  unsigned int i = 0;
-  for (it = m_Detector.begin(); it != m_Detector.end(); ++it) {
-//cout << "TEST0" << endl;
-    m_Ready[i++]=true;
-  }
-//cout << "TEST1" << endl;
-  { // aquire the sub thread lock
-    std::unique_lock<std::mutex> lk(m_ThreadMtx);
-  }
-  m_CV.notify_all();
+#if __cplusplus > 199711L && NPMULTITHREADING
+    // add new job
+    m_Ready.flip();
+    std::this_thread::yield();
 
-//cout << "TEST2" << endl;
   while(!IsDone()){
-//cout << "TEST2a" << endl;
-     //this_thread::yield();
-  }
-//cout << "TEST2b" << endl;
+    std::this_thread::yield();
+    }
 
 #else 
-//cout << "TEST3" << endl;
-  map<string,VDetector*>::iterator it;
-  for (it = m_Detector.begin(); it != m_Detector.end(); ++it) {
+  static std::map<std::string,VDetector*>::iterator it;
+  static std::map<std::string,VDetector*>::iterator begin=m_Detector.begin();
+  static std::map<std::string,VDetector*>::iterator end= m_Detector.end();
+
+  for (it =begin; it != end; ++it) {
     (it->second->*m_ClearEventPhysicsPtr)();
     (it->second->*m_BuildPhysicalPtr)();
     if(m_FillSpectra){
@@ -224,21 +269,7 @@ void NPL::DetectorManager::BuildPhysicalEvent(){
     }
   }
 #endif
-}
-
-///////////////////////////////////////////////////////////////////////////////
-void NPL::DetectorManager::BuildSimplePhysicalEvent(){
-  ClearEventPhysics();
-  map<string,VDetector*>::iterator it;
-
-  for (it = m_Detector.begin(); it != m_Detector.end(); ++it) {
-    it->second->BuildSimplePhysicalEvent();
-    if(NPOptionManager::getInstance()->GetGenerateHistoOption()){
-      it->second->FillSpectra();
-      if(NPOptionManager::getInstance()->GetCheckHistoOption())
-        it->second->CheckSpectra();
-    }
-  }
+  return;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -247,7 +278,7 @@ void NPL::DetectorManager::InitializeRootInput(){
   if( NPOptionManager::getInstance()->GetDisableAllBranchOption() )
     RootInput::getInstance()->GetChain()->SetBranchStatus ( "*" , false ) ;
 
-  map<string,VDetector*>::iterator it;
+  std::map<std::string,VDetector*>::iterator it;
 
   if(NPOptionManager::getInstance()->GetInputPhysicalTreeOption())
     for (it = m_Detector.begin(); it != m_Detector.end(); ++it) 
@@ -260,7 +291,7 @@ void NPL::DetectorManager::InitializeRootInput(){
 
 ///////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorManager::InitializeRootOutput(){
-  map<string,VDetector*>::iterator it;
+  std::map<std::string,VDetector*>::iterator it;
 
   if(!NPOptionManager::getInstance()->GetInputPhysicalTreeOption())
     for (it = m_Detector.begin(); it != m_Detector.end(); ++it) 
@@ -268,26 +299,26 @@ void NPL::DetectorManager::InitializeRootOutput(){
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-void NPL::DetectorManager::AddDetector(string DetectorName , VDetector* newDetector){
+void NPL::DetectorManager::AddDetector(std::string DetectorName , VDetector* newDetector){
   m_Detector[DetectorName] = newDetector;
   newDetector->AddParameterToCalibrationManager();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-NPL::VDetector* NPL::DetectorManager::GetDetector(string name){
-  map<string,VDetector*>::iterator it;
+NPL::VDetector* NPL::DetectorManager::GetDetector(std::string name){
+  std::map<std::string,VDetector*>::iterator it;
   it = m_Detector.find(name);
   if ( it!=m_Detector.end() ) return it->second;
   else{
-    cout << endl;
-    cout << "**********************************       Error       **********************************" << endl;
-    cout << " No Detector " << name << " found in the Detector Manager" << endl;
-		cout << " Available Detectors: " << endl;
-		for(map<string,VDetector*>::iterator i = m_Detector.begin(); i != m_Detector.end(); ++i) {
-			cout << "\t" << i->first << endl;
-		}
-    cout << "***************************************************************************************" << endl;
-    cout << endl;
+    std::cout << std::endl;
+    std::cout << "**********************************       Error       **********************************" << std::endl;
+    std::cout << " No Detector " << name << " found in the Detector Manager" << std::endl;
+    std::cout << " Available Detectors: " << std::endl;
+    for(std::map<std::string,VDetector*>::iterator i = m_Detector.begin(); i != m_Detector.end(); ++i) {
+      std::cout << "\t" << i->first << std::endl;
+    }
+    std::cout << "***************************************************************************************" << std::endl;
+    std::cout << std::endl;
     exit(1);
   }
 
@@ -295,14 +326,14 @@ NPL::VDetector* NPL::DetectorManager::GetDetector(string name){
 
 ///////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorManager::ClearEventPhysics(){
-  map<string,VDetector*>::iterator it;
+  std::map<std::string,VDetector*>::iterator it;
   for (it = m_Detector.begin(); it != m_Detector.end(); ++it) 
     (it->second->*m_ClearEventPhysicsPtr)();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorManager::ClearEventData(){
-  map<string,VDetector*>::iterator it;
+  std::map<std::string,VDetector*>::iterator it;
   for (it = m_Detector.begin(); it != m_Detector.end(); ++it)
     (it->second->*m_ClearEventDataPtr)();
 }
@@ -311,30 +342,30 @@ void NPL::DetectorManager::ClearEventData(){
 void NPL::DetectorManager::InitSpectra(){
   bool batch = false;
   if(gROOT){
-     batch = gROOT->IsBatch();
-     gROOT->ProcessLine("gROOT->SetBatch()");
+    batch = gROOT->IsBatch();
+    gROOT->ProcessLine("gROOT->SetBatch()");
   }
-  map<string,VDetector*>::iterator it;
+  std::map<std::string,VDetector*>::iterator it;
   for (it = m_Detector.begin(); it != m_Detector.end(); ++it) 
     it->second->InitSpectra();
 
   if(gROOT&&!batch)
-   gROOT->ProcessLine("gROOT->SetBatch(kFALSE)");
+    gROOT->ProcessLine("gROOT->SetBatch(kFALSE)");
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorManager::WriteSpectra(){
-  std::cout << endl << "\r \033[1;36m *** Writing Spectra: this may take a while ***\033[0m"<<flush;
-  map<string,VDetector*>::iterator it;
+  std::cout << std::endl << "\r \033[1;36m *** Writing Spectra: this may take a while ***\033[0m"<<std::flush;
+  std::map<std::string,VDetector*>::iterator it;
   for (it = m_Detector.begin(); it != m_Detector.end(); ++it) 
     it->second->WriteSpectra();
-  std::cout << "\r                                                  " << flush; 
+  std::cout << "\r                                                  " << std::flush; 
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-vector< map< string, TH1* > > NPL::DetectorManager::GetSpectra(){
-  vector< map< string, TH1* > > myVector;
-  map<string,VDetector*>::iterator it;
+std::vector< std::map< std::string, TH1* > > NPL::DetectorManager::GetSpectra(){
+  std::vector< std::map< std::string, TH1* > > myVector;
+  std::map<std::string,VDetector*>::iterator it;
   // loop on detectors
   for (it = m_Detector.begin(); it != m_Detector.end(); ++it) {
     myVector.push_back(it->second->GetSpectra());
@@ -344,26 +375,27 @@ vector< map< string, TH1* > > NPL::DetectorManager::GetSpectra(){
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-vector<string> NPL::DetectorManager::GetDetectorList(){
-  map<string,VDetector*>::iterator it;
-  vector<string> DetectorList;
+std::vector<std::string> NPL::DetectorManager::GetDetectorList(){
+  std::map<std::string,VDetector*>::iterator it;
+  std::vector<std::string> DetectorList;
   for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { 
     DetectorList.push_back(it->first);
   }
 
   return DetectorList;
 }
-#if __cplusplus > 199711L 
+#if __cplusplus > 199711L && NPMULTITHREADING
+
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorManager::InitThreadPool(){
   StopThread();
   m_ThreadPool.clear();
   m_Ready.clear();
-  map<string,VDetector*>::iterator it;
+  std::map<std::string,VDetector*>::iterator it;
 
   unsigned int i = 0;
   for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { 
-    m_ThreadPool.push_back( thread( &NPL::DetectorManager::StartThread,this,it->second,i++) );
+    m_ThreadPool.push_back( std::thread( &NPL::DetectorManager::StartThread,this,it->second,i++) );
     m_Ready.push_back(false);
   }
 
@@ -372,60 +404,52 @@ void NPL::DetectorManager::InitThreadPool(){
     th.detach();
   }
 
-  cout << "\033[1;33m**** Detector Manager : Started " << i << " Threads ****\033[0m" << endl ;
+  std::cout << "\033[1;33m**** Detector Manager : Started " << i << " Threads ****\033[0m" << std::endl ;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorManager::StartThread(NPL::VDetector* det,unsigned int id){ 
-  this_thread::sleep_for(chrono::milliseconds(1));
-  vector<bool>::iterator it = m_Ready.begin()+id;
+  // Let the main thread start 
+  std::this_thread::sleep_for(std::chrono::milliseconds(100));
   while(true){
-    { // Aquire the lock
-////cout << "WWWW" << endl;
-      std::unique_lock<std::mutex> lk(m_ThreadMtx);    
-      // wait for work to be given
-      while(!m_Ready[id]){
-        m_CV.wait(lk);
-      }
-
+    // Do the job if possible
+    if(m_Ready[id]){
       // Do the job
       (det->*m_ClearEventPhysicsPtr)();
       (det->*m_BuildPhysicalPtr)();
       if(m_FillSpectra){
         (det->*m_FillSpectra)();
-        if(m_CheckSpectra)
+       if(m_CheckSpectra)
           (det->*m_CheckSpectra)();
       }
-      
-      // Reset Ready flag
-      m_Ready[id]=false;
-      // Quite if stopped
-      if(m_stop)
-        return;
-
-    } // Realease the lock
-
+     m_Ready[id].flip();
+     std::this_thread::yield();
+   }
+   else{
+    std::this_thread::yield();
+   }
+
+    // Return if stopped
+    if(m_stop){
+      return;
+      }
   }   
 }
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::DetectorManager::StopThread(){
   // make sure the last thread are schedule before stopping;
-  this_thread::yield();
+  std::this_thread::yield();
   m_stop=true;
-  m_CV.notify_all();
+  std::this_thread::yield();
 }
 ////////////////////////////////////////////////////////////////////////////////
 bool NPL::DetectorManager::IsDone(){
-int ijk=0;
-//cout << m_Ready.size() << " !" << endl;
-  for(vector<bool>::iterator it =  m_Ready.begin() ; it!=m_Ready.end() ; it++){
+  static std::vector<bool>::iterator it;
+  static std::vector<bool>::iterator begin = m_Ready.begin(); 
+  static std::vector<bool>::iterator end = m_Ready.end();
+  for( it = begin ; it!=end ; it++){
     if((*it))
-{
-ijk++;
-//cout << *it << endl;
-//cout << ijk << endl;
       return false;
-}
   }
   return true;
 }
@@ -434,12 +458,12 @@ ijk++;
 void NPL::DetectorManager::SetSpectraServer(){
   m_SpectraServer = NPL::SpectraServer::getInstance();
 
-  map<string,VDetector*>::iterator it;
+  std::map<std::string,VDetector*>::iterator it;
   for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ 
-    vector<TCanvas*> canvas = it->second->GetCanvas();
+    std::vector<TCanvas*> canvas = it->second->GetCanvas();
     size_t mysize = canvas.size();
     for (size_t i = 0 ; i < mysize ; i++){} 
-      //m_SpectraServer->AddCanvas(canvas[i]);
+    //m_SpectraServer->AddCanvas(canvas[i]);
   }
 
   // Avoid warning on gcc
@@ -452,8 +476,8 @@ void NPL::DetectorManager::StopSpectraServer(){
   if(m_SpectraServer)
     m_SpectraServer->Destroy();
   else
-    cout <<"WARNING: requesting to stop spectra server, which is not started" << endl; 
-  
+    std::cout <<"WARNING: requesting to stop spectra server, which is not started" << std::endl; 
+
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -461,7 +485,41 @@ void NPL::DetectorManager::CheckSpectraServer(){
   if(m_SpectraServer)
     m_SpectraServer->CheckRequest();
   else
-    cout <<"WARNING: requesting to check spectra server, which is not started" << endl; 
+    std::cout <<"WARNING: requesting to check spectra server, which is not started" << std::endl; 
 
 }
+////////////////////////////////////////////////////////////////////////////////
+bool NPL::DetectorManager::IsCryogenic() const {return  m_CryoTarget;};
+double NPL::DetectorManager::GetTargetThickness() const {return m_TargetThickness;};
+double NPL::DetectorManager::GetNominalTargetThickness() const {return  m_TargetThickness;};
+double NPL::DetectorManager::GetTargetDensity() const {return  m_TargetDensity;};
+double NPL::DetectorManager::GetFrontDeformation() const {return  m_FrontDeformation;};
+double NPL::DetectorManager::GetFrontThickness() const {return  m_FrontThickness;};
+double NPL::DetectorManager::GetFrontRadius() const {return  m_FrontRadius;};
+std::string NPL::DetectorManager::GetFrontMaterial() const {return  m_FrontMaterial;};
+double NPL::DetectorManager::GetBackDeformation() const {return  m_BackDeformation;};
+double NPL::DetectorManager::GetBackRadius() const {return  m_BackRadius;};
+double NPL::DetectorManager::GetBackThickness() const {return  m_BackThickness;};
+std::string NPL::DetectorManager::GetBackMaterial() const {return  m_BackMaterial;};
+double NPL::DetectorManager::GetFrameRadius() const {return  m_FrameRadius;};
+double NPL::DetectorManager::GetFrameThickness() const {return  m_FrameThickness;};
+double NPL::DetectorManager::GetFrontCone() const {return  m_FrontCone;};
+double NPL::DetectorManager::GetBackCone() const {return  m_BackCone;};
+std::string NPL::DetectorManager::GetFrameMaterial() const {return  m_FrameMaterial;};
+double NPL::DetectorManager::GetShieldInnerRadius() const {return  m_ShieldInnerRadius;};
+double NPL::DetectorManager::GetShieldOuterRadius() const {return  m_ShieldOuterRadius;};
+double NPL::DetectorManager::GetShieldBottomLength() const {return  m_ShieldBottomLength;};
+double NPL::DetectorManager::GetShieldTopLength() const {return  m_ShieldTopLength;};
+double NPL::DetectorManager::GetShieldFrontRadius() const {return  m_ShieldFrontRadius;}; 
+double NPL::DetectorManager::GetShieldBackRadius() const {return  m_ShieldBackRadius;};
+std::string NPL::DetectorManager::GetShieldMaterial() const {return  m_ShieldMaterial;};
+std::string NPL::DetectorManager::GetTargetMaterial() const {return m_TargetMaterial;};
+double NPL::DetectorManager::GetWindowsThickness() const {return m_WindowsThickness;};
+std::string NPL::DetectorManager::GetWindowsMaterial() const {return m_WindowsMaterial;};
+double NPL::DetectorManager::GetTargetRadius() const {return m_TargetRadius;};
+double NPL::DetectorManager::GetTargetAngle() const {return m_TargetAngle;};
+double NPL::DetectorManager::GetTargetX() const {return m_TargetX;};
+double NPL::DetectorManager::GetTargetY() const {return m_TargetY;};
+double NPL::DetectorManager::GetTargetZ() const {return m_TargetZ;}; 
+
 
diff --git a/NPLib/Core/NPDetectorManager.h b/NPLib/Core/NPDetectorManager.h
index ae7485e0cc4523937cf6d9ed1bba548d2419ac44..8b66d362841e42df9df5fe7c87d25c00083d7c11 100644
--- a/NPLib/Core/NPDetectorManager.h
+++ b/NPLib/Core/NPDetectorManager.h
@@ -29,17 +29,17 @@
 //   STL
 #include <string>
 #include <map>
- 
+#include <vector>
+#include <iostream>
 #if __cplusplus > 199711L 
 #include <thread>
 #include <mutex>
 #include <condition_variable>
 #endif
 
-using namespace std ;
 
 typedef void(NPL::VDetector::*VDetector_FuncPtr)(void);
-// This class manage a map of virtual detector
+// This class manage a std::map of virtual detector
 namespace NPL{
   class DetectorManager{
     public:
@@ -47,19 +47,18 @@ namespace NPL{
       ~DetectorManager();
 
     public:
-      void        ReadConfigurationFile(string Path);
+      void        ReadConfigurationFile(std::string Path);
       void        BuildPhysicalEvent();
-      void        BuildSimplePhysicalEvent();
       void        InitializeRootInput();
       void        InitializeRootOutput();
-      void        AddDetector(string,VDetector*);
-      VDetector*  GetDetector(string);
+      void        AddDetector(std::string,VDetector*);
+      VDetector*  GetDetector(std::string);
       void        ClearEventPhysics();
       void        ClearEventData();
       void        InitSpectra();
       void        WriteSpectra();
-      vector< map< string, TH1* > > GetSpectra();  
-      vector<string> GetDetectorList();
+      std::vector< std::map< std::string, TH1* > > GetSpectra();  
+      std::vector<std::string> GetDetectorList();
 
     public: // for online spectra server
       void SetSpectraServer();
@@ -69,9 +68,9 @@ namespace NPL{
       NPL::SpectraServer* m_SpectraServer;
 
     private:   
-      // The map containning all detectors
+      // The std::map containning all detectors
       // Using a Map one can access to any detector using its name
-      map<string,VDetector*> m_Detector;
+      std::map<std::string,VDetector*> m_Detector;
 
     private: // Function pointer to accelerate the code execution
       VDetector_FuncPtr m_BuildPhysicalPtr;
@@ -80,51 +79,90 @@ namespace NPL{
       VDetector_FuncPtr m_FillSpectra;
       VDetector_FuncPtr m_CheckSpectra;
       
-    #if __cplusplus > 199711L 
+    #if __cplusplus > 199711L && NPMULTITHREADING 
     private: // Thread Pool defined if C++11 is available
-      vector<std::thread> m_ThreadPool;
-      vector<bool> m_Ready;
+      std::vector<std::thread> m_ThreadPool;
+      std::vector<bool> m_Ready;
       bool m_stop;
-      std::mutex m_ThreadMtx;
-      std::condition_variable m_CV;
 
     public: // Init the Thread Pool
       void StopThread();
       void StartThread(NPL::VDetector*,unsigned int);
       void InitThreadPool(); 
       bool IsDone();
-   
-       #endif
+
+#endif
 
     private: // Target property
       double m_TargetThickness;
       double m_TargetAngle;
       double m_TargetRadius;
-      string m_TargetMaterial;
+      std::string m_TargetMaterial;
       double m_TargetX;
       double m_TargetY;
       double m_TargetZ;
-  
-      // Additional info for cryogenic target
-      double m_WindowsThickness;
-      string m_WindowsMaterial;
-  
 
-      // Special treatment for the target for the moment
-      // If necessary we should change it to treat it as 
-      // a full "detector"
+      // Additional info for cryogenic target
+      bool        m_CryoTarget;
+      double      m_TargetDensity;
+      double      m_FrontDeformation;
+      double      m_FrontThickness;
+      double      m_FrontRadius;
+      std::string m_FrontMaterial;
+      double      m_BackDeformation;
+      double      m_BackRadius;
+      double      m_BackThickness;
+      std::string m_BackMaterial;
+      double      m_FrameRadius;
+      double      m_FrameThickness;
+      double      m_FrontCone;
+      double      m_BackCone;
+      std::string m_FrameMaterial;
+      double      m_ShieldInnerRadius;
+      double      m_ShieldOuterRadius;
+      double      m_ShieldBottomLength;
+      double      m_ShieldTopLength;
+      double      m_ShieldFrontRadius; 
+      double      m_ShieldBackRadius;
+      std::string m_ShieldMaterial;
+      double      m_WindowsThickness;
+      std::string m_WindowsMaterial;
+ 
+    public: // those are define in cxx, otherwise the return value depend on context !?
+      bool IsCryogenic() const; // {return  m_CryoTarget;};
+      double GetTargetThickness() const;//{return m_TargetThickness;};
+      double GetNominalTargetThickness() const; // {return  m_TargetThickness;};
+      double GetTargetDensity() const; // {return  m_TargetDensity;};
+      double GetFrontDeformation() const; // {return  m_FrontDeformation;};
+      double GetFrontThickness() const; // {return  m_FrontThickness;};
+      double GetFrontRadius() const; // {return  m_FrontRadius;};
+      std::string GetFrontMaterial() const; // {return  m_FrontMaterial;};
+      double GetBackDeformation() const; // {return  m_BackDeformation;};
+      double GetBackRadius() const; // {return  m_BackRadius;};
+      double GetBackThickness() const; // {return  m_BackThickness;};
+      std::string GetBackMaterial() const; // {return  m_BackMaterial;};
+      double GetFrameRadius() const; // {return  m_FrameRadius;};
+      double GetFrameThickness() const; // {return  m_FrameThickness;};
+      double GetFrontCone() const; // {return  m_FrontCone;};
+      double GetBackCone() const; // {return  m_BackCone;};
+      std::string GetFrameMaterial() const; // {return  m_FrameMaterial;};
+      double GetShieldInnerRadius() const; // {return  m_ShieldInnerRadius;};
+      double GetShieldOuterRadius() const; // {return  m_ShieldOuterRadius;};
+      double GetShieldBottomLength() const; // {return  m_ShieldBottomLength;};
+      double GetShieldTopLength() const; // {return  m_ShieldTopLength;};
+      double GetShieldFrontRadius() const; // {return  m_ShieldFrontRadius;}; 
+      double GetShieldBackRadius() const; // {return  m_ShieldBackRadius;};
+      std::string GetShieldMaterial() const; // {return  m_ShieldMaterial;};
+      std::string GetTargetMaterial() const; // {return m_TargetMaterial;};
+      double GetWindowsThickness() const; // {return m_WindowsThickness;};
+      std::string GetWindowsMaterial() const; // {return m_WindowsMaterial;};
+      double GetTargetRadius() const; // {return m_TargetRadius;};
+      double GetTargetAngle() const; // {return m_TargetAngle;};
+      double GetTargetX() const; // {return m_TargetX;};
+      double GetTargetY() const; // {return m_TargetY;};
+      double GetTargetZ() const; // {return m_TargetZ;}; 
 
-    public:
-      double GetTargetThickness()       {return m_TargetThickness;}
-      string GetTargetMaterial()        {return m_TargetMaterial;}
-      double GetWindowsThickness(){return m_WindowsThickness;}
-      string GetWindowsMaterial() {return m_WindowsMaterial;}
-      double GetTargetRadius()          {return m_TargetRadius;}
-      double GetTargetAngle()           {return m_TargetAngle;}
-      double GetTargetX()               {return m_TargetX;}
-      double GetTargetY()               {return m_TargetY;}
-      double GetTargetZ()               {return m_TargetZ;} 
-    };
+  };
 }
 
 #endif 
diff --git a/NPLib/Core/NPInputParser.cxx b/NPLib/Core/NPInputParser.cxx
index 577983975a9a8249375ecabbd9f3ded97dcc1502..142397e899708e9b67b28972882d9ff3c381d7b4 100644
--- a/NPLib/Core/NPInputParser.cxx
+++ b/NPLib/Core/NPInputParser.cxx
@@ -143,7 +143,7 @@ double NPL::InputBlock::GetDouble(std::string Token,std::string default_unit){
   }
 
   if(verbose)
-    cout << " " << Token << " (" <<default_unit << "): " << val/ApplyUnit(1,default_unit) << endl; 
+    std::cout << " " << Token << " (" <<default_unit << "): " << val/ApplyUnit(1,default_unit) <<std::endl; 
 
   return val;        
 }
@@ -155,7 +155,7 @@ int NPL::InputBlock::GetInt(std::string Token){
   iss >> val ;
 
   if(verbose)
-    cout << " " << Token << ": " << val << endl;
+    std::cout << " " << Token << ": " << val <<std::endl;
 
 
   return val;        
@@ -164,7 +164,7 @@ int NPL::InputBlock::GetInt(std::string Token){
 std::string NPL::InputBlock::GetString(std::string Token){
   int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
   if(verbose)
-    cout << " " << Token << ": " << GetValue(Token) << endl; 
+    std::cout << " " << Token << ": " << GetValue(Token) << std::endl; 
 
   return GetValue(Token);
 }
@@ -190,10 +190,10 @@ TVector3 NPL::InputBlock::GetTVector3(std::string Token,std::string  default_uni
   }
 
   if(verbose)
-    cout << " " << Token << " (" <<default_unit << "): (" 
+    std::cout << " " << Token << " (" <<default_unit << "): (" 
       << x/ApplyUnit(1,default_unit) << " ; " 
       << y/ApplyUnit(1,default_unit) << " ; " 
-      << z/ApplyUnit(1,default_unit) << ")" << endl; 
+      << z/ApplyUnit(1,default_unit) << ")" << std::endl; 
 
 
   return TVector3(x,y,z);        
@@ -211,10 +211,10 @@ std::vector<std::string> NPL::InputBlock::GetVectorString(std::string Token){
 
 
   if(verbose){
-    cout << " " << Token << ": ";
+    std::cout << " " << Token << ": ";
     for(unsigned int i = 0 ; i < val.size() ; i++)
-      cout << val[i] << " " ;
-    cout << endl; 
+      std::cout << val[i] << " " ;
+    std::cout << std::endl; 
   }
   return val;        
 }
@@ -247,10 +247,10 @@ std::vector<double> NPL::InputBlock::GetVectorDouble(std::string Token,std::stri
   }
 
   if(verbose){
-    cout << " " << Token << " (" << default_unit << "): ";
+    std::cout << " " << Token << " (" << default_unit << "): ";
     for(unsigned int i = 0 ; i < val.size() ; i++)
-      cout << val[i]/ApplyUnit(1,default_unit) << " " ;
-    cout << endl; 
+      std::cout << val[i]/ApplyUnit(1,default_unit) << " " ;
+    std::cout << std::endl; 
   }
 
   return val;        
@@ -267,10 +267,10 @@ std::vector<int> NPL::InputBlock::GetVectorInt(std::string Token){
     val.push_back(buffer);
 
   if(verbose){
-    cout << " " << Token << ": ";
+    std::cout << " " << Token << ": ";
     for(unsigned int i = 0 ; i < val.size() ; i++)
-      cout << val[i] << " " ;
-    cout << endl; 
+      std::cout << val[i] << " " ;
+    std::cout << std::endl; 
   }
 
 
@@ -331,6 +331,18 @@ std::vector<std::string> NPL::InputParser::GetAllBlocksToken(){
 
   return token;
 }
+////////////////////////////////////////////////////////////////////////////////
+std::vector<std::string> NPL::InputParser::GetAllBlocksValues(std::string token){
+  std::vector<std::string> value;
+  std::vector<NPL::InputBlock*> blocks = GetAllBlocksWithToken(token);
+  unsigned int size = blocks.size();
+  for(unsigned int i = 0 ; i < size ; i++){
+    value.push_back(blocks[i]->GetMainValue());
+  }
+
+  return value;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::InputParser::TreatAliases(){
 
@@ -351,7 +363,7 @@ void NPL::InputParser::TreatAliases(){
     int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
 
     if(verbose)
-      std::cout << "Using Alias : @" << alias[i]->GetMainValue() << endl;
+      std::cout << "Using Alias : @" << alias[i]->GetMainValue() << std::endl;
     
     std::string name="@";
     name += alias[i]->GetMainValue(); 
@@ -398,7 +410,7 @@ void NPL::InputParser::TreatAliases(){
               m_Block[b] = newBlock;
             }
             else{
-              vector<NPL::InputBlock*>::iterator it = m_Block.begin();
+              std::vector<NPL::InputBlock*>::iterator it = m_Block.begin();
               m_Block.insert(it+b+a,newBlock);
             }
           }
diff --git a/NPLib/Core/NPInputParser.h b/NPLib/Core/NPInputParser.h
index cb808f59138af230b54f8567e7a54d28e8148d65..0791fe5c74a8c47f83b8bfd0390d79066d4dbc61 100644
--- a/NPLib/Core/NPInputParser.h
+++ b/NPLib/Core/NPInputParser.h
@@ -110,7 +110,7 @@ namespace NPL{
       void Clear();
       std::vector<InputBlock*> GetAllBlocksWithToken(std::string Token);
       std::vector<InputBlock*> GetAllBlocksWithTokenAndValue(std::string Token,std::string Value);
-
+      std::vector<std::string> GetAllBlocksValues(std::string);
       std::vector<std::string> GetAllBlocksToken();
 
 
diff --git a/NPLib/Core/NPOptionManager.cxx b/NPLib/Core/NPOptionManager.cxx
index eb522e198b87a011e66548e37a0e93749954f144..7f299c009373b6dbf07397722074694aa954e379 100644
--- a/NPLib/Core/NPOptionManager.cxx
+++ b/NPLib/Core/NPOptionManager.cxx
@@ -37,7 +37,7 @@ NPOptionManager* NPOptionManager::getInstance(int argc, char** argv){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-NPOptionManager* NPOptionManager::getInstance(string arg){
+NPOptionManager* NPOptionManager::getInstance(std::string arg){
 
   if (instance == 0) instance = new NPOptionManager(arg);
 
@@ -45,6 +45,10 @@ NPOptionManager* NPOptionManager::getInstance(string arg){
 
 }
 void NPOptionManager::ReadTheInputArgument(int argc, char** argv){
+  if(argc==1)
+    DisplayHelp();
+
+
   // Default Setting
   fDefaultReactionFileName    = "defaultReaction.reaction";
   fDefaultDetectorFileName    = "defaultDetector.detector";
@@ -90,7 +94,7 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){
 
 
   for (int i = 0; i < argc; i++) {
-    string argument = argv[i];
+    std::string argument = argv[i];
     if (argument == "-H" || argument == "-h" || argument == "--help") DisplayHelp();
 
     else if (argument == "--event-generator" && argc >= i + 1)    fReactionFileName    = argv[++i] ;
@@ -111,6 +115,8 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){
 
     else if (argument == "-R" && argc >= i + 1)                   fRunToReadFileName   = argv[++i] ;
 
+    else if (argument == "-T" && argc >= i + 2)                   CreateRunToTreatFile(argv[++i],argv[++i]);
+
     else if (argument == "--cal" && argc >= i + 1)                fCalibrationFileName = argv[++i] ;
 
     else if (argument == "-C" && argc >= i + 1)                   fCalibrationFileName = argv[++i] ;
@@ -160,18 +166,34 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){
   if(argc!=0)
     DisplayVersion();
 }
+////////////////////////////////////////////////////////////////////////////////
+void NPOptionManager::CreateRunToTreatFile(std::string file, std::string tree){
+  
+  std::ofstream run(".RunToTreat.txt");
+  if(!run.is_open())
+    exit(1);
+
+  run << "TTreeName" << std::endl;
+  run << " " << tree << std::endl;
+  run << "RootFileName" << std::endl;
+  run << " " << file << std::endl << std::endl;
+  run.close();
+  fRunToReadFileName=".RunToTreat.txt";
+  }
+
+
 ////////////////////////////////////////////////////////////////////////////////
 void NPOptionManager::DisplayVersion(){
   if(fVerboseLevel>0){
-    string line;
+    std::string line;
     line.resize(80,'*');
-    cout << line << endl;
-    cout << "***********************************  NPTool  ***********************************"<< endl;
-    cout << line << endl;
-    cout << " NPLib version: nplib-"<< NPL::version_major <<"-" << NPL::version_minor << "-" << NPL::version_deta <<endl;
-    cout << " Copyright: NPTool Collaboration "<<endl;
-    cout << " GitHub: http://github.com/adrien-matta/nptool"<<endl; ;
-    cout << line << endl;
+    std::cout << line << std::endl;
+    std::cout << "***********************************  NPTool  ***********************************"<< std::endl;
+    std::cout << line << std::endl;
+    std::cout << " NPLib version: nplib-"<< NPL::version_major <<"-" << NPL::version_minor << "-" << NPL::version_deta <<std::endl;
+    std::cout << " Copyright: NPTool Collaboration "<<std::endl;
+    std::cout << " GitHub: http://github.com/adrien-matta/nptool"<<std::endl; ;
+    std::cout << line << std::endl;
 
   }
 }
@@ -180,11 +202,11 @@ NPOptionManager::NPOptionManager(int argc, char** argv){
   ReadTheInputArgument(argc,argv);
 }
 ////////////////////////////////////////////////////////////////////////////////
-NPOptionManager::NPOptionManager(string arg){  
-  vector<char *> args;
-  istringstream iss(arg);
+NPOptionManager::NPOptionManager(std::string arg){  
+  std::vector<char *> args;
+  std::stringstream iss(arg);
 
-  string token;
+  std::string token;
   while(iss >> token) {
     char *arg = new char[token.size() + 1];
     copy(token.begin(), token.end(), arg);
@@ -211,11 +233,11 @@ void NPOptionManager::CheckEventGenerator(){
   bool checkFile = true;
 
   // NPTool path
-  string GlobalPath = getenv("NPTOOL");
-  string StandardPath = GlobalPath + "/Inputs/EventGenerator/" + fReactionFileName;
+  std::string GlobalPath = getenv("NPTOOL");
+  std::string StandardPath = GlobalPath + "/Inputs/EventGenerator/" + fReactionFileName;
 
   // ifstream to configfile
-  ifstream ConfigFile;
+  std::ifstream ConfigFile;
 
   // test if config file is in local path
   ConfigFile.open(fReactionFileName.c_str());
@@ -241,11 +263,11 @@ void NPOptionManager::CheckDetectorConfiguration(){
   bool checkFile = true;
 
   // NPTool path
-  string GlobalPath = getenv("NPTOOL");
-  string StandardPath = GlobalPath + "/Inputs/DetectorConfiguration/" + fDetectorFileName;
+  std::string GlobalPath = getenv("NPTOOL");
+  std::string StandardPath = GlobalPath + "/Inputs/DetectorConfiguration/" + fDetectorFileName;
 
   // ifstream to configfile
-  ifstream ConfigFile;
+  std::ifstream ConfigFile;
 
   // test if config file is in local path
   ConfigFile.open(fDetectorFileName.c_str());
@@ -273,7 +295,7 @@ void NPOptionManager::CheckG4Macro(){
     return ;
 
   // ifstream to configfile
-  ifstream MacroFile( fG4MacroPath );
+  std::ifstream MacroFile( fG4MacroPath );
 
   if (!MacroFile.is_open()) {
     SendErrorAndExit("G4MacroPath");
@@ -288,7 +310,7 @@ void NPOptionManager::CheckG4Macro(){
 bool NPOptionManager::IsDefault(const char* type) const{
   bool result = false;
 
-  string stype = type;
+  std::string stype = type;
   if (stype == "EventGenerator") {
     if (fReactionFileName == fDefaultReactionFileName) result = true;
   }
@@ -312,7 +334,7 @@ bool NPOptionManager::IsDefault(const char* type) const{
   }
  
   else {
-    cout << "NPOptionManager::IsDefault() unkwown keyword" << endl;
+    std::cout << "NPOptionManager::IsDefault() unkwown keyword" << std::endl;
   }
 
   return result;
@@ -322,21 +344,21 @@ bool NPOptionManager::IsDefault(const char* type) const{
 ////////////////////////////////////////////////////////////////////////////////
 // This method tests if the input files are the default ones
 void NPOptionManager::SendErrorAndExit(const char* type) const{
-  string stype = type;
+  std::string stype = type;
   if (stype == "EventGenerator") {
-    cout << endl;
-    cout << "**********************************       Error       **********************************" << endl;
-    cout << "* No event generator file found in $NPTool/Inputs/EventGenerator or local directories *" << endl;
-    cout << "***************************************************************************************" << endl;
-    cout << endl;
+    std::cout << std::endl;
+    std::cout << "**********************************       Error       **********************************" << std::endl;
+    std::cout << "* No event generator file found in $NPTool/Inputs/EventGenerator or local directories *" << std::endl;
+    std::cout << "***************************************************************************************" << std::endl;
+    std::cout << std::endl;
     exit(1);
   }
   else if (stype == "DetectorConfiguration") {
-    cout << endl;
-    cout << "***********************************       Error       ***********************************" << endl;
-    cout << "* No detector geometry file found in $NPTool/Inputs/DetectorConfiguration or local directories *" << endl;
-    cout << "*****************************************************************************************" << endl;
-    cout << endl;
+    std::cout << std::endl;
+    std::cout << "***********************************       Error       ***********************************" << std::endl;
+    std::cout << "* No detector geometry file found in $NPTool/Inputs/DetectorConfiguration or local directories *" << std::endl;
+    std::cout << "*****************************************************************************************" << std::endl;
+    std::cout << std::endl;
     exit(1);
   }
   else if (stype == "Calibration") {
@@ -344,16 +366,16 @@ void NPOptionManager::SendErrorAndExit(const char* type) const{
   else if (stype == "RunToTreat") {
   }
   else if (stype == "G4MacroPath") {
-    cout << endl;
-    cout << "***********************************       Error       ***********************************" << endl;
-    cout << "*                  No Geant4 macro file found in the provided path                      *" << endl;
-    cout << "*****************************************************************************************" << endl;
-    cout << endl;
+    std::cout << std::endl;
+    std::cout << "***********************************       Error       ***********************************" << std::endl;
+    std::cout << "*                  No Geant4 macro file found in the provided path                      *" << std::endl;
+    std::cout << "*****************************************************************************************" << std::endl;
+    std::cout << std::endl;
     exit(1);
   }
 
   else {
-    cout << "NPOptionManager::SendErrorAndExit() unkwown keyword" << endl;
+    std::cout << "NPOptionManager::SendErrorAndExit() unkwown keyword" << std::endl;
   }
 }
 
@@ -361,34 +383,36 @@ void NPOptionManager::SendErrorAndExit(const char* type) const{
 ////////////////////////////////////////////////////////////////////////////////
 void NPOptionManager::DisplayHelp(){
   DisplayVersion();
-  cout << endl << "----NPOptionManager Help----" << endl << endl ;
-  cout << "List of Option " << endl ;
-  cout << "\t--help -H -h\t\t\tDisplay this help message" << endl ;
-  cout << "\t--detector -D <arg>\t\tSet arg as the detector configuration file" << endl ;
-  cout << "\t--event-generator -E <arg>\tSet arg as the event generator file" << endl ;
-  cout << "\t--output -O <arg>\t\tSet arg as the Output File Name (output tree)" << endl ;
-  cout << "\t--tree-name <arg>\t\tSet arg as the Output Tree Name " << endl ;
-  cout << "\t--verbose -V <arg>\t\tSet the verbose level, 0 for nothing, 1 for normal printout."<<endl;
-	cout  << "\t\t\t\t\tError and warning are not affected" << endl ;
-  cout << endl << "NPAnalysis only:"<<endl;
-  cout << "\t--run -R <arg>\t\t\tSet arg as the run to read file list" << endl  ;
-  cout << "\t--cal -C <arg>\t\t\tSet arg as the calibration file list" << endl ;
-  cout << "\t--disable-branch\t\tDisable of branch of Input tree except the one of the detector (faster)" << endl  ;
-  cout << "\t--generate-histo -GH\t\tInstantiate the T*Spectra class of each detector" << endl ;
-  cout << "\t--check-histo -CH\t\tCheck if the Histogram looks ok and change there color if not" << endl ;
-  cout << "\t--input-physical -IP\t\tConsider the Input file is containing Physics Class." << endl  ;
-  cout << "\t-L <arg>\t\t\tLimit the number of events to be analysed to arg" << endl ;
-  cout << "\t-F <arg>\t\t\tSet the first event to analyse to arg (analysis goes from F -> L+F)" << endl ;
-  cout << "\t--last-sim\t\t\tIgnore the list of Run to treat if any and analysed the last simulated file" << endl ;
-  cout << "\t--last-phy\t\t\tIgnore the list of Run to treat if any and analysed the last Physics file" << endl ;
-  cout << "\t--last-res\t\t\tIgnore the list of Run to treat if any and analysed the last Result file" << endl ;
-  cout << "\t--last-any\t\t\tIgnore the list of Run to treat if any and analysed the last generated root file" << endl ;
-  cout << "\t--online  \t\t\tStart the spectra server" << endl ;
-  cout << endl << "NPSimulation only:"<<endl;
-  cout << "\t-M <arg>\t\t\tExecute Geant4 macro <arg> at startup" << endl ;
-  cout << "\t-B <arg>\t\t\tExecute in batch mode (no ui) with Geant4 macro <arg> at startup" << endl ;
-
-  cout << endl << endl ;
+  std::cout << std::endl << "----NPOptionManager Help----" << std::endl << std::endl ;
+  std::cout << "List of Option " << std::endl ;
+  std::cout << "\t--help -H -h\t\t\tDisplay this help message" << std::endl ;
+  std::cout << "\t--detector -D <arg>\t\tSet arg as the detector configuration file" << std::endl ;
+  std::cout << "\t--event-generator -E <arg>\tSet arg as the event generator file" << std::endl ;
+  std::cout << "\t--output -O <arg>\t\tSet arg as the Output File Name (output tree)" << std::endl ;
+  std::cout << "\t--tree-name <arg>\t\tSet arg as the Output Tree Name " << std::endl ;
+  std::cout << "\t--verbose -V <arg>\t\tSet the verbose level, 0 for nothing, 1 for normal printout."<<std::endl;
+	std::cout  << "\t\t\t\t\tError and warning are not affected" << std::endl ;
+  std::cout << std::endl << "NPAnalysis only:"<<std::endl;
+  std::cout << "\t--run -R <arg>\t\t\tSet arg as the run to read file list" << std::endl  ;
+  std::cout << "\t-T <name> <file>\t\tTree <name> from root file <file>" << std::endl  ;
+
+  std::cout << "\t--cal -C <arg>\t\t\tSet arg as the calibration file list" << std::endl ;
+  std::cout << "\t--disable-branch\t\tDisable of branch of Input tree except the one of the detector (faster)" << std::endl  ;
+  std::cout << "\t--generate-histo -GH\t\tInstantiate the T*Spectra class of each detector" << std::endl ;
+  std::cout << "\t--check-histo -CH\t\tCheck if the Histogram looks ok and change there color if not" << std::endl ;
+  std::cout << "\t--input-physical -IP\t\tConsider the Input file is containing Physics Class." << std::endl  ;
+  std::cout << "\t-L <arg>\t\t\tLimit the number of events to be analysed to arg" << std::endl ;
+  std::cout << "\t-F <arg>\t\t\tSet the first event to analyse to arg (analysis goes from F -> L+F)" << std::endl ;
+  std::cout << "\t--last-sim\t\t\tIgnore the list of Run to treat if any and analysed the last simulated file" << std::endl ;
+  std::cout << "\t--last-phy\t\t\tIgnore the list of Run to treat if any and analysed the last Physics file" << std::endl ;
+  std::cout << "\t--last-res\t\t\tIgnore the list of Run to treat if any and analysed the last Result file" << std::endl ;
+  std::cout << "\t--last-any\t\t\tIgnore the list of Run to treat if any and analysed the last generated root file" << std::endl ;
+  std::cout << "\t--online  \t\t\tStart the spectra server" << std::endl ;
+  std::cout << std::endl << "NPSimulation only:"<<std::endl;
+  std::cout << "\t-M <arg>\t\t\tExecute Geant4 macro <arg> at startup" << std::endl ;
+  std::cout << "\t-B <arg>\t\t\tExecute in batch mode (no ui) with Geant4 macro <arg> at startup" << std::endl ;
+
+  std::cout << std::endl << std::endl ;
 
   // exit current program
   exit(0);
@@ -403,8 +427,8 @@ void NPOptionManager::Destroy(){
   }
 }
 ////////////////////////////////////////////////////////////////////////////////
-string NPOptionManager::GetLastFile(){
-  string path = getenv("NPTOOL");
+std::string NPOptionManager::GetLastFile(){
+  std::string path = getenv("NPTOOL");
   if(fLastSimFile)
     return (path+"/.last_sim_file");
 
diff --git a/NPLib/Core/NPOptionManager.h b/NPLib/Core/NPOptionManager.h
index eaece873a6d061ccc5ac2b20214bc8350a5a2d1e..88fe77f63d89942ce2319cc5b4a6a1c878e73103 100644
--- a/NPLib/Core/NPOptionManager.h
+++ b/NPLib/Core/NPOptionManager.h
@@ -26,7 +26,6 @@
 // C++ headers
 #include <iostream>
 #include <string>
-using namespace std;
 
 class NPOptionManager{
    public:
@@ -38,7 +37,7 @@ class NPOptionManager{
       static NPOptionManager* getInstance(int argc = 0, char** argv = NULL);
   
       // Added for compatibility with pROOF 
-      static NPOptionManager* getInstance(string arg);
+      static NPOptionManager* getInstance(std::string arg);
 
       // The analysis class instance can be deleted by calling the Destroy
       // method (NOTE: The class destructor is protected, and can thus not be
@@ -48,7 +47,7 @@ class NPOptionManager{
    protected:
       // Constructor (protected)
       NPOptionManager(int argc, char** argv);
-      NPOptionManager(string arg);
+      NPOptionManager(std::string arg);
 
       // Destructor (protected)
       ~NPOptionManager() {};
@@ -60,7 +59,7 @@ class NPOptionManager{
   private:
     // Read the input argument
     void ReadTheInputArgument(int argc = 0, char** argv = NULL);
-  
+      
    private:
       // The static instance of the NPOptionManager class:
       static NPOptionManager* instance;
@@ -72,7 +71,7 @@ class NPOptionManager{
       void CheckEventGenerator();
       void CheckDetectorConfiguration();
       void CheckG4Macro();
-
+      void CreateRunToTreatFile(std::string file, std::string tree );
    public:
       bool IsDefault(const char* type) const;
       void SendErrorAndExit(const char* type) const;
@@ -80,21 +79,21 @@ class NPOptionManager{
    public:
       // Getters
       // default values
-      string GetDefaultReactionFile()     {return fDefaultReactionFileName;}
-      string GetDefaultDetectorFile()     {return fDefaultDetectorFileName;}
-      string GetDefaultRunToReadFile()    {return fDefaultRunToReadFileName;}
-      string GetDefaultCalibrationFile()  {return fDefaultCalibrationFileName;}
-      string GetDefaultOutputFile()       {return fDefaultOutputFileName;}
-      string GetDefaultG4MacroPath()      {return fDefaultG4MacroPath;}
+      std::string GetDefaultReactionFile()     {return fDefaultReactionFileName;}
+      std::string GetDefaultDetectorFile()     {return fDefaultDetectorFileName;}
+      std::string GetDefaultRunToReadFile()    {return fDefaultRunToReadFileName;}
+      std::string GetDefaultCalibrationFile()  {return fDefaultCalibrationFileName;}
+      std::string GetDefaultOutputFile()       {return fDefaultOutputFileName;}
+      std::string GetDefaultG4MacroPath()      {return fDefaultG4MacroPath;}
 
       // assigned values
-      string GetReactionFile()             {return fReactionFileName;}
-      string GetDetectorFile()             {return fDetectorFileName;}
-      string GetRunToReadFile()            {return fRunToReadFileName;}
-      string GetCalibrationFile()          {return fCalibrationFileName;}
-      string GetOutputFile()               {return fOutputFileName;}
-      string GetOutputTreeName()           {return fOutputTreeName;}
-      string GetG4MacroPath()              {return fG4MacroPath;}     
+      std::string GetReactionFile()             {return fReactionFileName;}
+      std::string GetDetectorFile()             {return fDetectorFileName;}
+      std::string GetRunToReadFile()            {return fRunToReadFileName;}
+      std::string GetCalibrationFile()          {return fCalibrationFileName;}
+      std::string GetOutputFile()               {return fOutputFileName;}
+      std::string GetOutputTreeName()           {return fOutputTreeName;}
+      std::string GetG4MacroPath()              {return fG4MacroPath;}     
 
       bool   GetDisableAllBranchOption()   {return fDisableAllBranchOption;}
       bool   GetInputPhysicalTreeOption()  {return fInputPhysicalTreeOption;}
@@ -106,32 +105,32 @@ class NPOptionManager{
       int    GetVerboseLevel()             {return fVerboseLevel;}
       int    GetNumberOfEntryToAnalyse()   {return fNumberOfEntryToAnalyse;} 
       int    GetFirstEntryToAnalyse()      {return fFirstEntryToAnalyse;} 
-      string GetSharedLibExtension()       {return fSharedLibExtension;}     
-      string GetLastFile();                 
+      std::string GetSharedLibExtension()       {return fSharedLibExtension;}     
+      std::string GetLastFile();                 
       
       // Setters
-      void SetReactionFile(string name)       {fReactionFileName = name;CheckEventGenerator();}
-      void SetDetectorFile(string name)       {fDetectorFileName = name;CheckDetectorConfiguration();}
-      void SetRunToReadFile(string name)      {fRunToReadFileName = name;}
-      void SetVerboseLevel(int VerboseLevel)  {fVerboseLevel = VerboseLevel;}
+      void SetReactionFile(const std::string& name)  {fReactionFileName = name;CheckEventGenerator();}
+      void SetDetectorFile(const std::string& name)  {fDetectorFileName = name;CheckDetectorConfiguration();}
+      void SetRunToReadFile(const std::string& name) {fRunToReadFileName = name;}
+      void SetVerboseLevel(int VerboseLevel)         {fVerboseLevel = VerboseLevel;}
   
    private:
       // default values
-      string fDefaultReactionFileName;
-      string fDefaultDetectorFileName;
-      string fDefaultRunToReadFileName;
-      string fDefaultCalibrationFileName;
-      string fDefaultOutputFileName;
-      string fDefaultOutputTreeName;
-      string fDefaultG4MacroPath;
+      std::string fDefaultReactionFileName;
+      std::string fDefaultDetectorFileName;
+      std::string fDefaultRunToReadFileName;
+      std::string fDefaultCalibrationFileName;
+      std::string fDefaultOutputFileName;
+      std::string fDefaultOutputTreeName;
+      std::string fDefaultG4MacroPath;
 
       // assigned values
-      string fReactionFileName;
-      string fDetectorFileName;
-      string fRunToReadFileName;
-      string fCalibrationFileName;
-      string fOutputFileName;
-      string fOutputTreeName;
+      std::string fReactionFileName;
+      std::string fDetectorFileName;
+      std::string fRunToReadFileName;
+      std::string fCalibrationFileName;
+      std::string fOutputFileName;
+      std::string fOutputTreeName;
       bool   fDisableAllBranchOption;
       bool   fInputPhysicalTreeOption;
       bool   fGenerateHistoOption;
@@ -145,8 +144,8 @@ class NPOptionManager{
       int    fVerboseLevel; // 0 for not talk, 1 for talking
       int    fNumberOfEntryToAnalyse; // use to limit the number of analysed in NPA
       int    fFirstEntryToAnalyse; // use to set the first event analysed in NPA (total: fFirstEntryToAnalyse -> fFirstEntryToAnalyse + fNumberOfEntryToAnalyse)
-      string fSharedLibExtension; // lib extension is platform dependent
-      string fG4MacroPath; // Path to a geant4 macro to execute at start of nps
+      std::string fSharedLibExtension; // lib extension is platform dependent
+      std::string fG4MacroPath; // Path to a geant4 macro to execute at start of nps
       bool fG4BatchMode; // Execute geant4 in batch mode, running the given macro
 };
 
diff --git a/NPLib/Core/NPSpectraServer.cxx b/NPLib/Core/NPSpectraServer.cxx
index ce23eff8e2e71f39dd3cdd690670b354dbd36f99..940c81391e3e9a89275834f49709762c7bf7bbaa 100644
--- a/NPLib/Core/NPSpectraServer.cxx
+++ b/NPLib/Core/NPSpectraServer.cxx
@@ -66,7 +66,7 @@ void NPL::SpectraServer::CheckRequest(){
   if(m_Server && m_Monitor){
     TSocket* s ;
     m_Monitor->ResetInterrupt();
-    if((s=m_Monitor->Select(100))!=(TSocket*)-1){
+    if((s=m_Monitor->Select(1))!=(TSocket*)-1){
       HandleSocket(s);
       }
   }
@@ -103,47 +103,43 @@ void NPL::SpectraServer::HandleSocket(TSocket* s){
 
     // send requested object back
     static TMessage answer(kMESS_OBJECT);
+    answer.SetCompressionLevel(1);
     answer.Reset();
-    
+    TObject* h =NULL;
    if (!strcmp(request, "RequestSpectra")){
+     std::cout << "Prepare" << std::endl;
       answer.WriteObject(m_Spectra);
+      std::cout << "Compress" << std::endl;
+      answer.Compress();
+      std::cout << "Send " << std::endl;
       s->Send(answer);
-      m_Delta[s].Clear();
+      std::cout << "done" << std::endl;
     }
-    
-    else if (!strcmp(request, "RequestDelta")){
-      answer.WriteObject(&m_Delta[s]);
-      s->Send(answer);
-      m_Delta[s].Clear();
+  
+    else if (h=m_Spectra->FindObject(request)){
+     answer.WriteObject(h);
+     s->Send(answer);
     }
-    
+
     else if (!strcmp(request, "RequestClear")){
      // TO DO 
     }
-    else // answer nothing
+    else{ // answer nothing
+      std::cout << "Fail to respond to request : " << request << std::endl; 
       s->Send(answer);
+    }
   }
 }
 ////////////////////////////////////////////////////////////////////////////////
-void NPL::SpectraServer::FillSpectra(std::string name,double valx){
+void NPL::SpectraServer::FillSpectra(const std::string& name,const double& valx){
   // Fill the local histo
   ((TH1*) m_Spectra->FindObject(name.c_str()))->Fill(valx);
-  
-  // Fill the Delta for each Socket
-  std::map<TSocket*,NPL::DeltaSpectra >::iterator it;
-  for(it = m_Delta.begin(); it!=m_Delta.end() ; it++){
-    it->second.Fill(name,valx);
-  }
 }
 ////////////////////////////////////////////////////////////////////////////////
-void NPL::SpectraServer::FillSpectra(std::string name,double valx,double valy){
+void NPL::SpectraServer::FillSpectra(const std::string& name,const double& valx,const double& valy){
   // Fill the local histo
   ((TH2*) m_Spectra->FindObject(name.c_str()))->Fill(valx,valy);
   
-  std::map<TSocket*,NPL::DeltaSpectra >::iterator it;
-  for(it = m_Delta.begin(); it!=m_Delta.end() ; it++){
-    it->second.Fill(name,valx,valy);  
-  }
 }
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::SpectraServer::AddSpectra(TH1* h){
diff --git a/NPLib/Core/NPSpectraServer.h b/NPLib/Core/NPSpectraServer.h
index 168a3ac4b7a39301d8a701540557beb0ea193e84..7c13d4526d319de2922e5052f9ed5f02951ef65c 100644
--- a/NPLib/Core/NPSpectraServer.h
+++ b/NPLib/Core/NPSpectraServer.h
@@ -49,16 +49,14 @@ namespace NPL{
     public:
       void HandleSocket(TSocket* s);
       void AddSpectra(TH1* h);
-      //void AddSpectra(TH2* h);
-      void FillSpectra(std::string name,double valx);
-      void FillSpectra(std::string name,double valx, double valy);
+      void FillSpectra(const std::string& name,const double& valx);
+      void FillSpectra(const std::string& name,const double& valx, const double& valy);
       void CheckRequest();
 
     private:
       bool m_stop;
       TServerSocket* m_Server;     
       TMonitor* m_Monitor;     
-      std::map<TSocket*,NPL::DeltaSpectra > m_Delta;
       TList* m_Sockets;
       TList* m_Spectra;
   };
diff --git a/NPLib/Core/NPVAnalysis.cxx b/NPLib/Core/NPVAnalysis.cxx
index 21a27ab7dfa0bacf593ab7f81ad16d289835da29..da0821e5d3d05794bdff40e07bbf44cfc44792b1 100644
--- a/NPLib/Core/NPVAnalysis.cxx
+++ b/NPLib/Core/NPVAnalysis.cxx
@@ -27,7 +27,3 @@ NPL::VAnalysis::VAnalysis(){
 ////////////////////////////////////////////////////////////////////////////////
 NPL::VAnalysis::~VAnalysis(){
 }
-////////////////////////////////////////////////////////////////////////////////
-void NPL::VAnalysis::SetDetectorManager(NPL::DetectorManager* det){
-  m_DetectorManager = det;
-}
diff --git a/NPLib/Core/NPVAnalysis.h b/NPLib/Core/NPVAnalysis.h
index dfba201490f1e8568f07bd4f976dbdca4da1914d..b7a0b753e1e065df33de822b65e0d959cbf623d2 100644
--- a/NPLib/Core/NPVAnalysis.h
+++ b/NPLib/Core/NPVAnalysis.h
@@ -10,7 +10,7 @@
 /*****************************************************************************
  * Original Author: Adrien MATTA  contact address: a.matta@surrey.ac.uk      *
  *                                                                           *
- * Creation Date  : march 2025                                               *
+ * Creation Date  : march 2015                                               *
  * Last update    :                                                          *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
@@ -33,9 +33,8 @@ namespace NPL{
       virtual void TreatEvent(){};
       virtual void Init(){};
       virtual void End(){};
-      
-      void SetDetectorManager(NPL::DetectorManager*);
-
+      void SetDetectorManager(NPL::DetectorManager* det ) {m_DetectorManager=det;}
+    
     protected:
       NPL::DetectorManager* m_DetectorManager;
   };
diff --git a/NPLib/Core/NPVDetector.cxx b/NPLib/Core/NPVDetector.cxx
index ea559d62525be351185bf1e7d99c925e47f5465b..b30be66c33cb731f7d6e9ac65221777b493be1a4 100644
--- a/NPLib/Core/NPVDetector.cxx
+++ b/NPLib/Core/NPVDetector.cxx
@@ -24,37 +24,14 @@
  *****************************************************************************/
 #include "NPVDetector.h"
 #include "NPOptionManager.h"
-using namespace NPL ;
 
-ClassImp(VDetector);
+ClassImp(NPL::VDetector);
 
 // Constructor
-VDetector::VDetector(){
+NPL::VDetector::VDetector(){
 }
 
 
 // Destructor
-VDetector::~VDetector(){
+NPL::VDetector::~VDetector(){
 }
-
-////////////////////////////////////////////////////////////////////////////////
-namespace NPL{
-  static string itoa_array[10000];
-
-  class itoa_proxy{
-    public:
-      itoa_proxy(){
-      char buffer[]="10000";
-        for(int i = 0 ; i < 10000 ; i++){
-          sprintf(buffer,"%d",i);
-          itoa_array[i] = buffer;
-        }
-      }
-  };
-  static itoa_proxy itoa_p ;
-}
-
-std::string NPL::itoa(const int& i){
-  return NPL::itoa_array[i];
-}
-
diff --git a/NPLib/Core/NPVDetector.h b/NPLib/Core/NPVDetector.h
index 81ddd7018fdaaffbd4011e56712680cc62cabcb8..415950273338a0e5287bb25ec139a3a1b5ca38f3 100644
--- a/NPLib/Core/NPVDetector.h
+++ b/NPLib/Core/NPVDetector.h
@@ -36,9 +36,9 @@
 
 // NPL
 #include "NPInputParser.h"
+#include "NPCore.h"
 
 namespace NPL {
-  std::string itoa(const int&); 
 
   class VDetector{
     public:
diff --git a/NPLib/Core/NPVSpectra.h b/NPLib/Core/NPVSpectra.h
index 36b3339cf7b7a06b809a36e6ea2a0b1840782d86..c9e26adb56d5eb31c73ecf4c052b33c6c3d417c9 100644
--- a/NPLib/Core/NPVSpectra.h
+++ b/NPLib/Core/NPVSpectra.h
@@ -30,7 +30,6 @@
 #include <map>
 #include <vector>
 #include <string>
-using namespace std;
 
 class VSpectra {
   public:
@@ -39,10 +38,10 @@ class VSpectra {
     virtual ~VSpectra(){};
 
   public:
-    // Instantiate and register histo to maps
-    TH1* AddHisto1D(string name, string title, Int_t nbinsx, Double_t xlow, Double_t xup, string family);
-    TH1* AddHisto2D(string name, string title, Int_t nbinsx, Double_t xlow, Double_t xup, 
-        Int_t nbinsy, Double_t ylow, Double_t yup, string family);
+    // Instantiate and register histo to std::maps
+    TH1* AddHisto1D(std::string name, std::string title, Int_t nbinsx, Double_t xlow, Double_t xup, std::string family);
+    TH1* AddHisto2D(std::string name, std::string title, Int_t nbinsx, Double_t xlow, Double_t xup, 
+        Int_t nbinsy, Double_t ylow, Double_t yup, std::string family);
 
   public:
     // Initialization methods
@@ -58,32 +57,32 @@ class VSpectra {
     virtual void CheckSpectra(){};
 
   public:
-    // get map histo which will be used for GSpectra in GUser
-    map< string, TH1* > GetMapHisto() const {return fMapHisto;}
-    TH1* GetSpectra(const string& family, const string& name);    
-    TH1* GetSpectra(const string& FamilyAndName);    
+    // get std::map histo which will be used for GSpectra in GUser
+    std::map< std::string, TH1* > GetMapHisto() const {return fMapHisto;}
+    TH1* GetSpectra(const std::string& family, const std::string& name);    
+    TH1* GetSpectra(const std::string& FamilyAndName);    
     // TEMP FIX
-//    TH1* GetHisto(const string& family, const string& name){return GetSpectra(family,name);};    
-//    TH1* GetHisto(const string& FamilyAndName){return GetSpectra(FamilyAndName);};    
+//    TH1* GetHisto(const std::string& family, const std::string& name){return GetSpectra(family,name);};    
+//    TH1* GetHisto(const std::string& FamilyAndName){return GetSpectra(FamilyAndName);};    
 
-    void FillSpectra(const string& family, const string& name, double val);
-    void FillSpectra(const string& family, const string& name, double x, double y);
-    void FillSpectra(const string& familyAndname, double val);
-    void FillSpectra(const string& familyAndname, double x, double y);
+    void FillSpectra(const std::string& family, const std::string& name, double val);
+    void FillSpectra(const std::string& family, const std::string& name, double x, double y);
+    void FillSpectra(const std::string& familyAndname, double val);
+    void FillSpectra(const std::string& familyAndname, double x, double y);
 
 
-    void WriteSpectra(string filename = "VOID");      
+    void WriteSpectra(std::string filename = "VOID");      
      
   protected:
-    // map holding histo pointers and their family names
-    map< string, TH1* > fMapHisto;
+    // std::map holding histo pointers and their family names
+    std::map< std::string, TH1* > fMapHisto;
     
   private: // Name of the Detector
-   string m_name;
+   std::string m_name;
 
   public:
-   inline void SetName(string name) {m_name=name;}
-   inline string GetName() {return m_name;}
+   inline void SetName(std::string name) {m_name=name;}
+   inline std::string GetName() {return m_name;}
 };
 
 #endif
diff --git a/NPLib/Core/RootInput.cxx b/NPLib/Core/RootInput.cxx
index e6393c049a0df1f022e2218ebfe9b6ec0bf63259..bfbb7929572c6198b4e3265b2578435bf4a2bf7b 100644
--- a/NPLib/Core/RootInput.cxx
+++ b/NPLib/Core/RootInput.cxx
@@ -30,10 +30,11 @@
 #include "RootInput.h"
 #include "TAsciiFile.h"
 #include "NPOptionManager.h"
+#include "NPInputParser.h"
 
 RootInput* RootInput::instance = 0;
 ////////////////////////////////////////////////////////////////////////////////
-RootInput* RootInput::getInstance(string configFileName){
+RootInput* RootInput::getInstance(std::string configFileName){
   // A new instance of RootInput is created if it does not exist:
   if (instance == 0) {
     instance = new RootInput(configFileName);
@@ -52,8 +53,8 @@ void RootInput::Destroy(){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-RootInput::RootInput(string configFileName){
-  string lastfile= NPOptionManager::getInstance()->GetLastFile();
+RootInput::RootInput(std::string configFileName){
+  std::string lastfile= NPOptionManager::getInstance()->GetLastFile();
   if(lastfile!="VOID"){
     configFileName = lastfile;
   }
@@ -63,40 +64,36 @@ RootInput::RootInput(string configFileName){
   bool CheckRootFileName = false;
 
   // Read configuration file Buffer
-  string lineBuffer, dataBuffer;
+  std::string lineBuffer, dataBuffer;
 
   // Open file
-  cout << endl;
-  cout << "/////////// ROOT Input files ///////////" << endl;
-  cout << "Initializing input TChain" << endl;
+  std::cout << std::endl;
+  std::cout << "/////////// ROOT Input files ///////////" << std::endl;
+  std::cout << "Initializing input TChain using: " << configFileName << std::endl;
 
-  ifstream inputConfigFile;
+  std::ifstream inputConfigFile;
   inputConfigFile.open(configFileName.c_str());
-
   pRootFile  = NULL;
-  pRootChain = new TChain();
-
   if (!inputConfigFile.is_open()) {
-    cout << "\033[1;31mWarning : Run to Read file: " << configFileName << " not found\033[0m" << endl; 
+    std::cout << "\033[1;31mWarning : Run to Read file: " << configFileName << " not found\033[0m" << std::endl; 
     //exit(1);
   }
 
   else {
     while (!inputConfigFile.eof()) {
       getline(inputConfigFile, lineBuffer);
-
       // search for token giving the TTree name
       if (lineBuffer.compare(0, 9, "TTreeName") == 0) {
         inputConfigFile >> dataBuffer;
         // initialize pRootChain
-        pRootChain->SetName(dataBuffer.c_str());
+        pRootChain = new TChain(dataBuffer.c_str());
         CheckTreeName = true ;
         // If the tree come from a simulation, the InteractionCoordinates
         // and InitialConditions lib are loaded
         if(dataBuffer=="SimulatedTree"){
-          string path = getenv("NPTOOL");
+          std::string path = getenv("NPTOOL");
           path+="/NPLib/lib/";
-          string libName="libNPInteractionCoordinates"+NPOptionManager::getInstance()->GetSharedLibExtension();
+          std::string libName="libNPInteractionCoordinates"+NPOptionManager::getInstance()->GetSharedLibExtension();
           libName=path+libName;
           dlopen(libName.c_str(),RTLD_NOW);
           libName="libNPInitialConditions"+NPOptionManager::getInstance()->GetSharedLibExtension();
@@ -119,16 +116,16 @@ RootInput::RootInput(string configFileName){
 
           else if (!inputConfigFile.eof()) {
             pRootChain->Add(dataBuffer.c_str());
-            cout << "Adding file " << dataBuffer << " to TChain" << endl;
+            std::cout << "Adding file " << dataBuffer << " to TChain" << std::endl;
 
             // Test if the file is a regex or a single file
             double counts;
-            string command = "ls " + dataBuffer + " > .ls_return";
+            std::string command = "ls " + dataBuffer + " > .ls_return";
             counts= system(command.c_str());
-            ifstream return_ls(".ls_return");
+            std::ifstream return_ls(".ls_return");
             
-            string files;
-            string firstfile;
+            std::string files;
+            std::string firstfile;
             while(return_ls >> files){
               if(counts == 0)
                 firstfile = files;
@@ -142,43 +139,43 @@ RootInput::RootInput(string configFileName){
       }
     }
     if( pRootChain->GetEntries() ==0){
-      cout << "\033[1;31m**** ERROR: No entries to analyse ****\033[0m" << endl; 
+      std::cout << "\033[1;31m**** ERROR: No entries to analyse ****\033[0m" << std::endl; 
       exit(1);
     }
     else{
-      cout << "\033[1;32mROOTInput:  " << pRootChain->GetEntries() << " entries loaded in the input chain\033[0m" << endl ;
+      std::cout << "\033[1;32mROOTInput:  " << pRootChain->GetEntries() << " entries loaded in the input chain\033[0m" << std::endl ;
     }
 
   }
 
   if (!CheckRootFileName || !CheckTreeName) 
-    cout << "\033[1;33mWARNING: Token not found for InputTree Declaration : Input Tree may not be instantiate properly\033[0m" << endl;
+    std::cout << "\033[1;33mWARNING: Token not found for InputTree Declaration : Input Tree may not be instantiate properly\033[0m" << std::endl;
 
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void RootInput::AddFriendChain(string RunToAdd){
+void RootInput::AddFriendChain(std::string RunToAdd){
   NumberOfFriend++;
-  ostringstream suffix_buffer;
+  std::ostringstream suffix_buffer;
   suffix_buffer << "_" << NumberOfFriend ; 
-  string suffix = suffix_buffer.str();
+  std::string suffix = suffix_buffer.str();
   bool CheckTreeName     = false;
   bool CheckRootFileName = false;
 
   // Read configuration file Buffer
-  string lineBuffer, dataBuffer;
+  std::string lineBuffer, dataBuffer;
 
   // Open file
-  ifstream inputConfigFile;
+  std::ifstream inputConfigFile;
   inputConfigFile.open(RunToAdd.c_str());
 
   TChain* localChain = new TChain();
-
-  cout << "/////////////////////////////////" << endl;
-  cout << "Adding friend to current TChain" << endl;
+  
+  std::cout << "/////////////////////////////////" << std::endl;
+  std::cout << "Adding friend to current TChain" << std::endl;
 
   if (!inputConfigFile) {
-    cout << "Run to Add file :" << RunToAdd << " not found " << endl; 
+    std::cout << "Run to Add file :" << RunToAdd << " not found " << std::endl; 
     return;
   }
 
@@ -210,7 +207,7 @@ void RootInput::AddFriendChain(string RunToAdd){
 
           else if (!inputConfigFile.eof()) {
             localChain->Add(dataBuffer.c_str());
-            cout << "Adding file " << dataBuffer << " to TChain" << endl;
+            std::cout << "Adding file " << dataBuffer << " to TChain" << std::endl;
           }
         }
       }
@@ -218,38 +215,38 @@ void RootInput::AddFriendChain(string RunToAdd){
   }
 
   if (!CheckRootFileName || !CheckTreeName) 
-    cout << "WARNING: Token not found for InputTree Declaration : Input Tree has not be Added to the current Chain" << endl;
+    std::cout << "WARNING: Token not found for InputTree Declaration : Input Tree has not be Added to the current Chain" << std::endl;
 
   else
     pRootChain->AddFriend( localChain->GetName() );
 
-  cout << "/////////////////////////////////" << endl;
+  std::cout << "/////////////////////////////////" << std::endl;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-string RootInput::DumpAsciiFile(const char* type, const char* folder){
-  string name="fail";
+std::string RootInput::DumpAsciiFile(const char* type, const char* folder){
+  std::string name="fail";
 
-  string sfolder = folder;
+  std::string sfolder = folder;
   // create folder if not existing
   // first test if folder exist
   struct stat dirInfo;
   int res = stat(folder, &dirInfo);
   if (res != 0) {   // if folder does not exist, create it
-    string cmd = "mkdir " + sfolder;
-    if (system(cmd.c_str()) != 0) cout << "RootInput::DumpAsciiFile() problem creating directory" << endl;
+    std::string cmd = "mkdir " + sfolder;
+    if (system(cmd.c_str()) != 0) std::cout << "RootInput::DumpAsciiFile() problem creating directory" << std::endl;
   }
 
-  string stype = type;
+  std::string stype = type;
   if (stype == "EventGenerator") {
     TAsciiFile *aFile = (TAsciiFile*)pRootFile->Get(stype.c_str());
 
     if(aFile)
     {
       // build file name
-      string title = aFile->GetTitle();
+      std::string title = aFile->GetTitle();
       size_t pos = title.rfind("/");
-      if (pos != string::npos) name = sfolder + title.substr(pos);
+      if (pos != std::string::npos) name = sfolder + title.substr(pos);
       else name = sfolder + "/" + title;
       aFile->WriteToFile(name.c_str());
     }
@@ -260,9 +257,9 @@ string RootInput::DumpAsciiFile(const char* type, const char* folder){
     if(aFile)
     {
       // build file name
-      string title = aFile->GetTitle();
+      std::string title = aFile->GetTitle();
       size_t pos = title.rfind("/");
-      if (pos != string::npos) name = sfolder + title.substr(pos);
+      if (pos != std::string::npos) name = sfolder + title.substr(pos);
       else name = sfolder + "/" + title;
       aFile->WriteToFile(name.c_str());
     }
@@ -273,9 +270,9 @@ string RootInput::DumpAsciiFile(const char* type, const char* folder){
     if(aFile)
     {
       // build file name
-      string title = aFile->GetTitle();
+      std::string title = aFile->GetTitle();
       size_t pos = title.rfind("/");
-      if (pos != string::npos) name = sfolder + title.substr(pos);
+      if (pos != std::string::npos) name = sfolder + title.substr(pos);
       else name = sfolder + "/" + title;
       aFile->WriteToFile(name.c_str());
     }
@@ -284,7 +281,7 @@ string RootInput::DumpAsciiFile(const char* type, const char* folder){
   else if (stype == "RunToTreat") {
   }
   else {
-    cout << "RootInput::DumpAsciiFile() unkwown keyword" << endl;
+    std::cout << "RootInput::DumpAsciiFile() unkwown keyword" << std::endl;
   }
 
   return name;
@@ -296,17 +293,17 @@ RootInput::~RootInput(){
   struct stat dirInfo;
   int res = stat("./.tmp", &dirInfo);
   if (res == 0) {   // if does exist, delete it
-    if (system("rm -rf ./.tmp") != 0) cout << "RootInput::~RootInput() problem deleting ./.tmp directory" << endl; 
+    if (system("rm -rf ./.tmp") != 0) std::cout << "RootInput::~RootInput() problem deleting ./.tmp directory" << std::endl; 
   }
-  cout << endl << "Root Input summary" << endl;
-  cout << "  - Number of bites read: " << pRootFile->GetBytesRead() << endl;
-  cout << "  - Number of transactions: " << pRootFile->GetReadCalls() << endl;
+  std::cout << std::endl << "Root Input summary" << std::endl;
+  std::cout << "  - Number of bites read: " << pRootFile->GetBytesRead() << std::endl;
+  std::cout << "  - Number of transactions: " << pRootFile->GetReadCalls() << std::endl;
   // Close the Root file
   pRootFile->Close();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-TChain* MakeFriendTrees(string RunToRead1,string RunToRead2){
+TChain* MakeFriendTrees(std::string RunToRead1,std::string RunToRead2){
   RootInput:: getInstance(RunToRead1)	;
   RootInput:: getInstance()->AddFriendChain(RunToRead2);
   return RootInput:: getInstance()->GetChain();
diff --git a/NPLib/Core/RootInput.h b/NPLib/Core/RootInput.h
index 7408ba4025fb3c638c0ad5340ff3647bfad578c6..b9cb0c6d9687f09c2b62458c24289b11b3d9c583 100644
--- a/NPLib/Core/RootInput.h
+++ b/NPLib/Core/RootInput.h
@@ -30,7 +30,6 @@
 #include "TFile.h"
 #include "TChain.h"
 
-using namespace std;
 
 
 class RootInput
@@ -41,7 +40,7 @@ public:
    // the user to get a pointer to the existing instance or to create it if
    // it does not yet exist:
    // (see the constructor for an explanation of the arguments)
-   static RootInput* getInstance(string configFileName = "configFile");
+   static RootInput* getInstance(std::string configFileName = "configFile");
 
    // The analysis class instance can be deleted by calling the Destroy
    // method (NOTE: The class destructor is protected, and can thus not be
@@ -50,7 +49,7 @@ public:
 
 protected:
    // Constructor (protected)
-   RootInput(string configFileName);
+   RootInput(std::string configFileName);
 
    // Destructor (protected)
    virtual ~RootInput();
@@ -64,7 +63,7 @@ private:
    static RootInput* instance;
 
 public:
-   string DumpAsciiFile(const char* type, const char* folder = "./.tmp");
+   std::string DumpAsciiFile(const char* type, const char* folder = "./.tmp");
 
 public:
    // Return the private chain and file
@@ -73,7 +72,7 @@ public:
    void     SetChain(TChain* c)  {pRootChain = c;} 
 
    // Add a Friend chain to the input chain
-   void     AddFriendChain(string RunToAdd);
+   void     AddFriendChain(std::string RunToAdd);
 
 private:
    TChain   *pRootChain;
@@ -83,6 +82,6 @@ private:
 };
 
 // A convenient function related to Root Input, coded Here so it can be called within ROOT CINT
-TChain* MakeFriendTrees(string,string);
+TChain* MakeFriendTrees(std::string,std::string);
 
 #endif // ROOTINPUT_HH
diff --git a/NPLib/Core/RootOutput.cxx b/NPLib/Core/RootOutput.cxx
index 6a4ea51986fa49371db932fba15dbfc09f57fe66..27d60c5d924318cf3f248a75b57c12bf42e886fb 100644
--- a/NPLib/Core/RootOutput.cxx
+++ b/NPLib/Core/RootOutput.cxx
@@ -31,10 +31,10 @@ using namespace std;
 
 RootOutput* RootOutput::instance = 0;
 ////////////////////////////////////////////////////////////////////////////////
-RootOutput* RootOutput::getInstance(TString fileNameBase, TString treeNameBase){
+RootOutput* RootOutput::getInstance(std::string fileNameBase, std::string treeNameBase){
   // A new instance of RootOutput is created if it does not exist:
   if (instance == 0) {
-    instance = new RootOutput(fileNameBase, treeNameBase);
+    instance = new RootOutput(fileNameBase.c_str(), treeNameBase.c_str());
   }
 
   // The instance of RootOutput is returned:
@@ -50,19 +50,19 @@ void RootOutput::Destroy(){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-RootOutput::RootOutput(TString fileNameBase, TString treeNameBase){
+RootOutput::RootOutput(std::string fileNameBase, std::string treeNameBase){
   TDirectory* currentPath= gDirectory;
 
   // The file extension is added to the file name:
-  TString GlobalPath = getenv("NPTOOL");
+  std::string GlobalPath = getenv("NPTOOL");
 
   // The ROOT file is created
   if(!NPOptionManager::getInstance()->GetPROOF()){
-    TString fileName = GlobalPath + "/Outputs/";
-    if (fileNameBase.Contains("root")) fileName += fileNameBase;
+    std::string fileName = GlobalPath + "/Outputs/";
+    if (fileNameBase.find("root")!=std::string::npos) fileName += fileNameBase;
     else fileName += fileNameBase + ".root";
 
-    pRootFile = new TFile(fileName, "RECREATE");
+    pRootFile = new TFile(fileName.c_str(), "RECREATE");
 
     if(treeNameBase=="SimulatedTree"){
       string path = getenv("NPTOOL");
@@ -118,7 +118,7 @@ RootOutput::RootOutput(TString fileNameBase, TString treeNameBase){
     pRootFile = 0 ;
   }
 
-  pRootTree = new TTree(treeNameBase, "Data created / analysed with the NPTool package");
+  pRootTree = new TTree(treeNameBase.c_str(), "Data created / analysed with the NPTool package");
   pRootList = new TList();
 
   // Init TAsciiFile objects
@@ -134,35 +134,35 @@ void RootOutput::InitAsciiFiles(){
 
   // Event generator
   // Get file name from NPOptionManager
-  TString fileNameEG = OptionManager->GetReactionFile();
+  std::string fileNameEG = OptionManager->GetReactionFile();
   pEventGenerator = new TAsciiFile();
-  pEventGenerator->SetNameTitle("EventGenerator", fileNameEG.Data());
-  pEventGenerator->Append(fileNameEG.Data());
+  pEventGenerator->SetNameTitle("EventGenerator", fileNameEG.c_str());
+  pEventGenerator->Append(fileNameEG.c_str());
   pEventGenerator->Write(0,TAsciiFile::kOverwrite);
   
   // Detector configuration 
   // Get file name from NPOptionManager
-  TString fileNameDC = OptionManager->GetDetectorFile();
+  std::string fileNameDC = OptionManager->GetDetectorFile();
   pDetectorConfiguration = new TAsciiFile();
-  pDetectorConfiguration->SetNameTitle("DetectorConfiguration", fileNameDC.Data());
-  pDetectorConfiguration->Append(fileNameDC.Data());
+  pDetectorConfiguration->SetNameTitle("DetectorConfiguration", fileNameDC.c_str());
+  pDetectorConfiguration->Append(fileNameDC.c_str());
   pDetectorConfiguration->Write(0,TAsciiFile::kOverwrite);
 
   // Run to treat file
   // Get file name from NPOptionManager
   pRunToTreatFile = new TAsciiFile();
   if (!OptionManager->IsDefault("RunToTreat")) {
-    TString fileNameRT = OptionManager->GetRunToReadFile();
-    pRunToTreatFile->SetNameTitle("RunToTreat", fileNameRT.Data());
-    pRunToTreatFile->Append(fileNameRT.Data());
+    std::string fileNameRT = OptionManager->GetRunToReadFile();
+    pRunToTreatFile->SetNameTitle("RunToTreat", fileNameRT.c_str());
+    pRunToTreatFile->Append(fileNameRT.c_str());
     pRunToTreatFile->Write(0,TAsciiFile::kOverwrite);
   }
 
   // Calibration files
   pCalibrationFile = new TAsciiFile();
   if (!OptionManager->IsDefault("Calibration")) {
-    TString fileNameCal = OptionManager->GetCalibrationFile();
-    pCalibrationFile->SetNameTitle("Calibration", fileNameCal.Data());
+    std::string fileNameCal = OptionManager->GetCalibrationFile();
+    pCalibrationFile->SetNameTitle("Calibration", fileNameCal.c_str());
     pCalibrationFile->Write(0,TAsciiFile::kOverwrite);
   }
 
@@ -197,7 +197,6 @@ RootOutput::~RootOutput(){
     cout << endl << "Root Output summary" << endl;
     cout << "  - Number of entries in the Tree: " << pRootTree->GetEntries() << endl;
     cout << "  - Number of bites written to file: " << pRootTree->Write(0, TObject::kOverwrite) << endl;
-     
     pRootFile->Flush();
     pRootFile->Purge(1);
 
@@ -227,14 +226,14 @@ RootOutput::~RootOutput(){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-TFile* RootOutput::InitFile(TString fileNameBase){
+TFile* RootOutput::InitFile(std::string fileNameBase){
 
   if(NPOptionManager::getInstance()->GetPROOF()){
-    TString GlobalPath = getenv("NPTOOL");
-    TString fileName = GlobalPath + "/Outputs/Analysis/";
-    if (fileNameBase.Contains("root")) fileName += fileNameBase;
+    std::string GlobalPath = getenv("NPTOOL");
+    std::string fileName = GlobalPath + "/Outputs/Analysis/";
+    if (fileNameBase.find("root")!=std::string::npos) fileName += fileNameBase;
     else fileName += fileNameBase + ".root";
-    pRootFile = new TFile(fileName, "RECREATE");
+    pRootFile = new TFile(fileName.c_str(), "RECREATE");
     pRootFile->Flush();
     return pRootFile;
   }
diff --git a/NPLib/Core/RootOutput.h b/NPLib/Core/RootOutput.h
index 25fca941286f49ce5ada6bb4bee848d0419f7d01..2ac1db6018403851367dd5f29259c46c369bbc9f 100644
--- a/NPLib/Core/RootOutput.h
+++ b/NPLib/Core/RootOutput.h
@@ -28,11 +28,10 @@
 #include "TAsciiFile.h"
 
 // ROOT headers
-#include "TString.h"
 #include "TFile.h"
 #include "TTree.h"
 #include "TList.h"
-
+#include <string>
 
 class RootOutput{
 public:
@@ -41,8 +40,8 @@ public:
   // the user to get a pointer to the existing instance or to create it if
   // it does not yet exist:
   // (see the constructor for an explanation of the arguments)
-  static RootOutput* getInstance(TString fileNameBase = "Simulation",
-                                 TString treeNameBase = "SimulatedTree");
+  static RootOutput* getInstance(std::string fileNameBase = "Simulation",
+                                 std::string treeNameBase = "SimulatedTree");
   
   // The analysis class instance can be deleted by calling the Destroy
   // method (NOTE: The class destructor is protected, and can thus not be
@@ -51,7 +50,7 @@ public:
   
 protected:
   // Constructor (protected)
-  RootOutput(TString fileNameBase, TString treeNameBase);
+  RootOutput(std::string fileNameBase, std::string treeNameBase);
   
   // Destructor (protected)
   virtual ~RootOutput();
@@ -76,7 +75,7 @@ public:
   TAsciiFile* GetAsciiFileCalibration()           {return pCalibrationFile;}
   TAsciiFile* GetAsciiFileRunToTreat()            {return pRunToTreatFile;}
   TAsciiFile* GetAsciiFileAnalysisConfig()        {return pAnalysisConfigFile;}
-  TFile*      InitFile(TString fileNameBase); // use only for proof environment
+  TFile*      InitFile(std::string fileNameBase); // use only for proof environment
   
 private:
   TFile      *pRootFile;
diff --git a/NPLib/Core/TAsciiFile.h b/NPLib/Core/TAsciiFile.h
index 249ab7b66e9f9819a4877a45aa28517f8d37b93e..e1ac5e248db9d62821f1168be0a824d0a76d01f3 100644
--- a/NPLib/Core/TAsciiFile.h
+++ b/NPLib/Core/TAsciiFile.h
@@ -28,12 +28,11 @@
 // C++ headers
 #include <vector>
 #include <string>
-using namespace std;
 
 
 class TAsciiFile : public TNamed {
  private :
-   vector<string>   fLines;
+   std::vector<std::string>   fLines;
 
  protected :
    void ReadFile(const char* inputAsciiFile);
diff --git a/NPLib/Detectors/CATS/TCATSData.cxx b/NPLib/Detectors/CATS/TCATSData.cxx
index d3cc32c309f68fb8f4aa4be57eed5b19ff2862c5..35d95af297c3bb2c699a43a1b01c22ffed68c86f 100644
--- a/NPLib/Detectors/CATS/TCATSData.cxx
+++ b/NPLib/Detectors/CATS/TCATSData.cxx
@@ -25,22 +25,13 @@
 
 
 ClassImp(TCATSData)
-
-TCATSData::TCATSData()
-{
-   // Default constructor
-
-   Clear();
+////////////////////////////////////////////////////////////////////////////////
+TCATSData::TCATSData(){
 }
-
-
-
-TCATSData::~TCATSData()
-{
+////////////////////////////////////////////////////////////////////////////////
+TCATSData::~TCATSData(){
 }
-
-
-
+////////////////////////////////////////////////////////////////////////////////
 void TCATSData::Clear()
 {
    // X
@@ -55,9 +46,7 @@ void TCATSData::Clear()
    fCATS_DetQ.clear();
    fCATS_Charge.clear();
 }
-
-
-
+////////////////////////////////////////////////////////////////////////////////
 void TCATSData::Dump() const
 {
    cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event XXXXXXXXXXXXXXXXX" << endl;
diff --git a/NPLib/Detectors/CATS/TCATSData.h b/NPLib/Detectors/CATS/TCATSData.h
index 4b166849a0afe6465e86cd155769ab7c5a8b0b24..69dcc497462be7996fee8fdf436a491ed831455b 100644
--- a/NPLib/Detectors/CATS/TCATSData.h
+++ b/NPLib/Detectors/CATS/TCATSData.h
@@ -73,18 +73,18 @@ class TCATSData : public TObject {
     /////////////////////           GETTERS           ////////////////////////
     // X
     inline UShort_t	GetCATSMultX()		              const {return fCATS_DetX.size();}
-    inline UShort_t	GetCATSDetX(const Int_t& i)	    const {return fCATS_DetX.at(i);}
-    inline UShort_t	GetCATSStripX(const Int_t& i)   const {return fCATS_StripX.at(i);}
-    inline UShort_t	GetCATSChargeX(const Int_t& i)	const {return fCATS_ChargeX.at(i);}
+    inline UShort_t	GetCATSDetX(const Int_t& i)	    const {return fCATS_DetX[i];}
+    inline UShort_t	GetCATSStripX(const Int_t& i)   const {return fCATS_StripX[i];}
+    inline UShort_t	GetCATSChargeX(const Int_t& i)	const {return fCATS_ChargeX[i];}
     // Y
     inline UShort_t	GetCATSMultY()		              const {return fCATS_DetY.size();}
-    inline UShort_t	GetCATSDetY(const Int_t& i)	    const {return fCATS_DetY.at(i);}
-    inline UShort_t	GetCATSStripY(const Int_t& i)   const {return fCATS_StripY.at(i);}
-    inline UShort_t	GetCATSChargeY(const Int_t& i)	const {return fCATS_ChargeY.at(i);}
+    inline UShort_t	GetCATSDetY(const Int_t& i)	    const {return fCATS_DetY[i];}
+    inline UShort_t	GetCATSStripY(const Int_t& i)   const {return fCATS_StripY[i];}
+    inline UShort_t	GetCATSChargeY(const Int_t& i)	const {return fCATS_ChargeY[i];}
     //Q fil
     inline UShort_t	GetCATSMultQ()                 const {return fCATS_DetQ.size();}
-    inline UShort_t	GetCATSDetQ(const Int_t& i)    const {return fCATS_DetQ.at(i);}
-    inline UShort_t	GetCATSCharge(const Int_t& i)  const {return fCATS_Charge.at(i);}
+    inline UShort_t	GetCATSDetQ(const Int_t& i)    const {return fCATS_DetQ[i];}
+    inline UShort_t	GetCATSCharge(const Int_t& i)  const {return fCATS_Charge[i];}
 
     ClassDef(TCATSData,2)  // CATSData structure
 };
diff --git a/NPLib/Detectors/CATS/TCATSPhysics.cxx b/NPLib/Detectors/CATS/TCATSPhysics.cxx
index 7cfc5aa9ed6bf9e24b269668bfdd66663fe3d4de..0b7af5eeef211ed5bfd8682c1f31c12efda808e7 100644
--- a/NPLib/Detectors/CATS/TCATSPhysics.cxx
+++ b/NPLib/Detectors/CATS/TCATSPhysics.cxx
@@ -49,6 +49,7 @@ ClassImp(TCATSPhysics)
     m_EventPhysics 			= this			    ;
     m_NumberOfCATS      = 0             ;
     m_Spectra           = NULL          ;
+    m_Zproj             = 0             ;
   }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -108,7 +109,11 @@ void TCATSPhysics::BuildSimplePhysicalEvent(){
 
 //////////////////////////////////////////////////////////////////////////////		
 void TCATSPhysics::BuildPhysicalEvent(){
+
+
+
   PreTreat();
+
   // Look how many CATS were fired
   // use a set to identify which detector has been hit
   set<int> DetectorHitX; // X only
@@ -164,7 +169,7 @@ void TCATSPhysics::BuildPhysicalEvent(){
       if(NX == DetMaxX[j] ){
         Buffer_X_Q[j][StrX-1]= CATS_X_Q;
         QsumX[j]+= CATS_X_Q;	
-        if(CATS_X_Q > Buffer_X_Q[j][StripMaxX[j] -1]){ 
+        if(CATS_X_Q > Buffer_X_Q[j][StripMaxX[j]-1]){ 
           StripMaxX[j] = StrX ; 
           ChargeMaxX[j]= CATS_X_Q; 
         }
@@ -185,7 +190,7 @@ void TCATSPhysics::BuildPhysicalEvent(){
       if(NY == DetMaxY[j] ){
         Buffer_Y_Q[j][StrY-1]= CATS_Y_Q;
         QsumY[j]+= CATS_Y_Q;	
-        if(CATS_Y_Q > Buffer_Y_Q[j][StripMaxY[j] -1]){ 
+        if(CATS_Y_Q > Buffer_Y_Q[j][StripMaxY[j]-1]){ 
           StripMaxY[j] = StrY ; 
           ChargeMaxY[j]= CATS_Y_Q; 
         }
@@ -198,9 +203,9 @@ void TCATSPhysics::BuildPhysicalEvent(){
 
   for(unsigned int i  = 0 ; i < NumberOfCATSHit ; i++ ){       
     // Return the position in strip unit
-     // Convention: the collected charge is atrributed to the center of the strip
-     // (histogram convention) so that a reconstructed position for a single strip
-     // goes from strip index -0.5 to strip index +0.5
+    // Convention: the collected charge is atrributed to the center of the strip
+    // (histogram convention) so that a reconstructed position for a single strip
+    // goes from strip index -0.5 to strip index +0.5
     double PosX =  ReconstructionFunctionX[DetMaxX[i]-1](Buffer_X_Q[i],StripMaxX[i]);
     double PosY =  ReconstructionFunctionY[DetMaxY[i]-1](Buffer_Y_Q[i],StripMaxY[i]);
     StripNumberX.push_back(PosX);
@@ -208,8 +213,8 @@ void TCATSPhysics::BuildPhysicalEvent(){
 
     // a shift - -1 is made to have PosX in between -0.5 and 27.5
     // for the following calculation of the position in the lab.
-    PosX = PosX -1;
-    PosY = PosY -1;
+    PosX = PosX;
+    PosY = PosY;
 
     // sx and sy are the X and Y strip number between which the PosX and PosY are
     int sx0 = (int) PosX;
@@ -227,6 +232,9 @@ void TCATSPhysics::BuildPhysicalEvent(){
 
       PositionX.push_back(px0+(px1-px0)*(PosX-sx0));  
       PositionY.push_back(py0+(py1-py0)*(PosY-sy0));  
+      //PositionX.push_back(2.54*(PosX-14));  
+      //PositionY.push_back(2.54*(PosY-14));  
+
       PositionZ.push_back(StripPositionZ[DetMaxX[i]-1]);
     }
 
@@ -235,14 +243,23 @@ void TCATSPhysics::BuildPhysicalEvent(){
   // At least two CATS need to gave back position in order to reconstruct on Target 
   if(PositionX.size()>1){
     if(DetMaxX[0]<DetMaxX[1]){
-      double t = -PositionZ[1]/(PositionZ[1]-PositionZ[0]);
+
+      // cout << "Test  " << m_Zproj << endl ;
+      // cout << "Test2  " <<  PositionZ[0]<< endl ;
+      // cout << "Test3  " <<  PositionZ[1]<< endl ;
+      double t = (m_Zproj-PositionZ[1])/(PositionZ[1]-PositionZ[0]);
+      // cout << "t  " << t << endl ;
+      // cout << "X1  " << PositionX[0] << endl ;
+      // cout << "X2  " << PositionX[1] << endl ;
       PositionOnTargetX= PositionX[1] + (PositionX[1]-PositionX[0])*t;
       PositionOnTargetY= PositionY[1] + (PositionY[1]-PositionY[0])*t; 
+
+      //cout << "X3  " << PositionOnTargetX << endl ;
       BeamDirection = GetBeamDirection();
     }
 
     else{
-      double t = -PositionZ[0]/(PositionZ[0]-PositionZ[1]);
+      double t = (m_Zproj-PositionZ[1])/(PositionZ[0]-PositionZ[1]);
       PositionOnTargetX= PositionX[0] + (PositionX[0]-PositionX[1])*t;
       PositionOnTargetY= PositionY[0] + (PositionY[0]-PositionY[1])*t; 
       BeamDirection = GetBeamDirection();
@@ -418,7 +435,7 @@ void TCATSPhysics::Clear(){
 }
 
 ////////////////////////////////////////////////////////////////////////////
-bool TCATSPhysics :: IsValidChannel(const string DetectorType, const int Detector , const int channel) {
+bool TCATSPhysics :: IsValidChannel(const string& DetectorType, const int& Detector , const int& channel) {
   if(DetectorType == "X")
     return *(m_XChannelStatus[Detector-1].begin()+channel-1);
 
@@ -564,6 +581,12 @@ void TCATSPhysics::ReadAnalysisConfig(){
         SetReconstructionMethod(CATSNumber,XorY,DataBuffer);
       }
 
+      else if (whatToDo == "ZPROJ") {
+        AnalysisConfigFile >> DataBuffer;
+        cout << whatToDo << "  " << DataBuffer << endl ;
+        m_Zproj = atoi(DataBuffer.c_str());
+      }
+
       else {ReadingStatus = false;}
 
     }
@@ -844,7 +867,7 @@ namespace CATS_LOCAL{
 
 
   ////////////////////////////////////////////////////////////////////////
-  double fCATS_X_Q(const TCATSData* m_EventData , const int i){
+  double fCATS_X_Q(const TCATSData* m_EventData , const int& i){
     static string name; 
     name = "CATS/D" ;
     name+= NPL::itoa( m_EventData->GetCATSDetX(i) ) ;
@@ -852,10 +875,11 @@ namespace CATS_LOCAL{
     name+= NPL::itoa( m_EventData->GetCATSStripX(i) ) ;
     name+= "_Q";
     return CalibrationManager::getInstance()->ApplyCalibration( name,   
-        m_EventData->GetCATSChargeX(i) + gRandom->Rndm() - fCATS_Ped_X(m_EventData, i) );
+        m_EventData->GetCATSChargeX(i) + gRandom->Rndm() );
+    //m_EventData->GetCATSChargeX(i) + gRandom->Rndm() - fCATS_Ped_X(m_EventData, i) );
   }
   ////////////////////////////////////////////////////////////////////////
-  double fCATS_Y_Q(const TCATSData* m_EventData , const int i){
+  double fCATS_Y_Q(const TCATSData* m_EventData , const int& i){
     static string name; 
     name = "CATS/D" ;
     name+= NPL::itoa( m_EventData->GetCATSDetY(i) ) ;
@@ -863,10 +887,11 @@ namespace CATS_LOCAL{
     name+= NPL::itoa( m_EventData->GetCATSStripY(i) ) ;
     name+= "_Q";
     return CalibrationManager::getInstance()->ApplyCalibration( name ,   
-        m_EventData->GetCATSChargeY(i) + gRandom->Rndm() - fCATS_Ped_Y(m_EventData, i) );
+        m_EventData->GetCATSChargeY(i) + gRandom->Rndm() );
+    //m_EventData->GetCATSChargeY(i) + gRandom->Rndm() - fCATS_Ped_Y(m_EventData, i) );
   }
   ////////////////////////////////////////////////////////////////////////
-  bool fCATS_Threshold_X(const TCATSData* m_EventData , const int i){
+  bool fCATS_Threshold_X(const TCATSData* m_EventData , const int& i){
     static string name; 
     name = "CATS/D" ;
     name+= NPL::itoa( m_EventData->GetCATSDetX(i) ) ;
@@ -876,7 +901,7 @@ namespace CATS_LOCAL{
         m_EventData->GetCATSChargeX(i));
   }
   ////////////////////////////////////////////////////////////////////////
-  bool fCATS_Threshold_Y(const TCATSData* m_EventData , const int i){
+  bool fCATS_Threshold_Y(const TCATSData* m_EventData , const int& i){
     static string name; 
     name ="CATS/D" ;
     name+= NPL::itoa( m_EventData->GetCATSDetY(i) ) ;
@@ -886,7 +911,7 @@ namespace CATS_LOCAL{
         m_EventData->GetCATSChargeY(i));
   }
   ////////////////////////////////////////////////////////////////////////
-  double fCATS_Ped_X(const TCATSData* m_EventData, const int i){
+  double fCATS_Ped_X(const TCATSData* m_EventData, const int& i){
     static string name; 
     name =  "CATS/D" ;
     name+= NPL::itoa( m_EventData->GetCATSDetX(i) ) ;
@@ -895,7 +920,7 @@ namespace CATS_LOCAL{
     return CalibrationManager::getInstance()->GetPedestal(name);
   }
   ////////////////////////////////////////////////////////////////////////
-  double fCATS_Ped_Y(const TCATSData* m_EventData, const int i){
+  double fCATS_Ped_Y(const TCATSData* m_EventData, const int& i){
     static string name; 
     name = "CATS/D" ;
     name+= NPL::itoa( m_EventData->GetCATSDetY(i) ) ;
@@ -916,14 +941,14 @@ NPL::VDetector* TCATSPhysics::Construct(){
 //            Registering the construct method to the factory                 //
 ////////////////////////////////////////////////////////////////////////////////
 extern "C"{
-class proxy_cats{
-  public:
-    proxy_cats(){
-      NPL::DetectorFactory::getInstance()->AddToken("CATSDetector","CATS");
-      NPL::DetectorFactory::getInstance()->AddDetector("CATSDetector",TCATSPhysics::Construct);
-    }
-};
+  class proxy_cats{
+    public:
+      proxy_cats(){
+        NPL::DetectorFactory::getInstance()->AddToken("CATSDetector","CATS");
+        NPL::DetectorFactory::getInstance()->AddDetector("CATSDetector",TCATSPhysics::Construct);
+      }
+  };
 
-proxy_cats p;
+  proxy_cats p;
 }
 
diff --git a/NPLib/Detectors/CATS/TCATSPhysics.h b/NPLib/Detectors/CATS/TCATSPhysics.h
index 64fd27f7c909b0489f51e7004b4aa302e30deddf..ee9730b1b5792411594c7792c9b6556a75ca520c 100644
--- a/NPLib/Detectors/CATS/TCATSPhysics.h
+++ b/NPLib/Detectors/CATS/TCATSPhysics.h
@@ -84,6 +84,7 @@ class TCATSPhysics : public TObject, public NPL::VDetector
     vector<double>	 QsumY;
     double           PositionOnTargetX;
     double           PositionOnTargetY;
+    double           m_Zproj;;
 
     TVector3         BeamDirection;//!
 
@@ -167,10 +168,10 @@ class TCATSPhysics : public TObject, public NPL::VDetector
     void  Clear(const Option_t*) {};  
 
     // Give and external TCATSData object to TCATSPhysics, needed for online analysis
-    void SetRawDataPointer(TCATSData* rawDataPointer) {m_EventData = rawDataPointer;}
+    void SetRawDataPointer(void* rawDataPointer) {m_EventData = (TCATSData*)rawDataPointer;}
 
     //   Return false if the channel is disabled by user
-    bool IsValidChannel(const string DetectorType, const int Detector , const int channel);
+    bool IsValidChannel(const string& DetectorType, const int& Detector , const int& channel);
     void InitializeStandardParameter();
     void AddParameterToCalibrationManager();
     void ReadAnalysisConfig();
@@ -212,12 +213,12 @@ namespace CATS_LOCAL{
   //   tranform an integer to a string
   string itoa(int value);
 
-  double fCATS_X_Q(const TCATSData* Data, const int i);
-  double fCATS_Y_Q(const TCATSData* Data, const int i);
-  bool fCATS_Threshold_X(const TCATSData* Data, const int i);
-  bool fCATS_Threshold_Y(const TCATSData* Data, const int i);
-  double fCATS_Ped_X(const TCATSData* m_EventData, const int i);
-  double fCATS_Ped_Y(const TCATSData* m_EventData, const int i);
+  double fCATS_X_Q(const TCATSData* Data, const int& i);
+  double fCATS_Y_Q(const TCATSData* Data, const int& i);
+  bool fCATS_Threshold_X(const TCATSData* Data, const int& i);
+  bool fCATS_Threshold_Y(const TCATSData* Data, const int& i);
+  double fCATS_Ped_X(const TCATSData* m_EventData, const int& i);
+  double fCATS_Ped_Y(const TCATSData* m_EventData, const int& i);
 }
 
 #endif
diff --git a/NPLib/Detectors/MDM/MDMTrace.cpp b/NPLib/Detectors/MDM/MDMTrace.cpp
index c375887cc87c20e040b259b70d69cbb78ed55da4..1ddee65846811f4039d382d12cb8412c789f4520 100644
--- a/NPLib/Detectors/MDM/MDMTrace.cpp
+++ b/NPLib/Detectors/MDM/MDMTrace.cpp
@@ -42,7 +42,8 @@ MDMTrace::Rayin::Rayin(const string& filename, bool check):
     cerr << "Creating link \"rayin.dat\" to the file \"" << filename << "\"...\n";
     stringstream sstr;
     sstr << "ln -fs " <<filename << " rayin.dat";
-    system(sstr.str().c_str());
+    int ret;
+    ret = system(sstr.str().c_str());
   }
 }
 
@@ -50,7 +51,8 @@ MDMTrace::Rayin::~Rayin()
 {
   if(isOwner) {
     cerr << "Removing link \"rayin.dat\"...\n";
-    system("rm -f rayin.dat");
+    int ret;
+    ret = system("rm -f rayin.dat");
   }
 }
 
diff --git a/NPLib/Detectors/MDM/TMDMPhysics.cxx b/NPLib/Detectors/MDM/TMDMPhysics.cxx
index b495ef65087aad6c9820a89b4be8206ec2835504..a2e8de7686437f15cf5ba381dad396f170aba68c 100644
--- a/NPLib/Detectors/MDM/TMDMPhysics.cxx
+++ b/NPLib/Detectors/MDM/TMDMPhysics.cxx
@@ -546,7 +546,7 @@ proxy_MDM p_MDM;
 
 
 #ifdef HAVE_MINUIT2
-#pragma message "Compiling TMDMPhysics with Minuit2 support"
+//#pragma message "Compiling TMDMPhysics with Minuit2 support"
 
 // Define real routines using minuit2
 //
diff --git a/NPLib/Detectors/MUST2/TMust2Physics.cxx b/NPLib/Detectors/MUST2/TMust2Physics.cxx
index 8466864423ec2a06227af41cc302a594f73c27b2..7c5f7d735f685f378ddb4ca5662658a6d62a9f26 100644
--- a/NPLib/Detectors/MUST2/TMust2Physics.cxx
+++ b/NPLib/Detectors/MUST2/TMust2Physics.cxx
@@ -76,7 +76,7 @@ ClassImp(TMust2Physics)
 
     for(int i = 0 ; i < 16 ; ++i){
       m_SiLi_MatchingX[0]=112;
-      m_SiLi_MatchingY[0]=112;
+      m_SiLi_MatchingY[1]=112;
 
       m_SiLi_MatchingX[1]=112;
       m_SiLi_MatchingY[1]=80;
@@ -128,52 +128,52 @@ ClassImp(TMust2Physics)
     m_CsI_MatchingX.resize(16,0);
     m_CsI_MatchingY.resize(16,0);
     for(int i = 0 ; i < 16 ; ++i){
-      m_CsI_MatchingX[0]=80;
-      m_CsI_MatchingY[0]=48;
+      m_CsI_MatchingX[0]=112;
+      m_CsI_MatchingY[0]=112;
 
       m_CsI_MatchingX[1]=112;
-      m_CsI_MatchingY[1]=48;
+      m_CsI_MatchingY[1]=80;
 
-      m_CsI_MatchingX[2]=80;
-      m_CsI_MatchingY[2]=16;
+      m_CsI_MatchingX[2]=112;
+      m_CsI_MatchingY[2]=48;
 
       m_CsI_MatchingX[3]=112;
       m_CsI_MatchingY[3]=16;
       //
-      m_CsI_MatchingX[4]=48;
-      m_CsI_MatchingY[4]=80;
+      m_CsI_MatchingX[4]=80;
+      m_CsI_MatchingY[4]=16;
 
-      m_CsI_MatchingX[5]=16;
-      m_CsI_MatchingY[5]=80;
+      m_CsI_MatchingX[5]=80;
+      m_CsI_MatchingY[5]=48;
 
-      m_CsI_MatchingX[6]=48;
-      m_CsI_MatchingY[6]=112;
+      m_CsI_MatchingX[6]=80;
+      m_CsI_MatchingY[6]=80;
 
-      m_CsI_MatchingX[7]=16;
+      m_CsI_MatchingX[7]=80;
       m_CsI_MatchingY[7]=112;
       //
       m_CsI_MatchingX[8]=48;
       m_CsI_MatchingY[8]=48;
 
-      m_CsI_MatchingX[9]=16;
+      m_CsI_MatchingX[9]=48;
       m_CsI_MatchingY[9]=48;
 
       m_CsI_MatchingX[10]=48;
-      m_CsI_MatchingY[10]=16;
+      m_CsI_MatchingY[10]=80;
 
-      m_CsI_MatchingX[11]=16;
-      m_CsI_MatchingY[11]=16;
+      m_CsI_MatchingX[11]=48;
+      m_CsI_MatchingY[11]=112;
       //
-      m_CsI_MatchingX[12]=80;
-      m_CsI_MatchingY[12]=80;
+      m_CsI_MatchingX[12]=16;
+      m_CsI_MatchingY[12]=16;
 
-      m_CsI_MatchingX[13]=112;
-      m_CsI_MatchingY[13]=80;
+      m_CsI_MatchingX[13]=16;
+      m_CsI_MatchingY[13]=48;
 
-      m_CsI_MatchingX[14]=80;
-      m_CsI_MatchingY[14]=112;
+      m_CsI_MatchingX[14]=16;
+      m_CsI_MatchingY[14]=80;
 
-      m_CsI_MatchingX[15]=112;
+      m_CsI_MatchingX[15]=16;
       m_CsI_MatchingY[15]=112;
     }
 
@@ -191,7 +191,9 @@ void TMust2Physics::BuildSimplePhysicalEvent(){
 ///////////////////////////////////////////////////////////////////////////
 
 void TMust2Physics::BuildPhysicalEvent(){
+
   PreTreat();
+
   bool check_SILI = false ;
   bool check_CSI  = false ;
 
@@ -203,8 +205,9 @@ void TMust2Physics::BuildPhysicalEvent(){
   m_SiLiTMult = m_PreTreatedData->GetMMSiLiTMult();
   m_CsIEMult = m_PreTreatedData->GetMMCsIEMult();
   m_CsITMult = m_PreTreatedData->GetMMCsITMult();
-  if( CheckEvent() == 1 ){
+  if( 1 /*CheckEvent() == 1*/ ){
     vector< TVector2 > couple = Match_X_Y() ;
+
     EventMultiplicity = couple.size();
     for(unsigned int i = 0 ; i < couple.size() ; ++i){
       check_SILI = false ;
@@ -324,7 +327,7 @@ void TMust2Physics::PreTreat(){
   m_SiLiTMult = m_EventData->GetMMSiLiTMult();
   m_CsIEMult = m_EventData->GetMMCsIEMult();
   m_CsITMult = m_EventData->GetMMCsITMult();
-  //   X
+ //   X
   //   E
   for(unsigned int i = 0 ; i < m_StripXEMult ; ++i){
     if( m_EventData->GetMMStripXEEnergy(i)>m_Si_X_E_RAW_Threshold && IsValidChannel(0, m_EventData->GetMMStripXEDetectorNbr(i), m_EventData->GetMMStripXEStripNbr(i)) ){
@@ -421,14 +424,15 @@ bool TMust2Physics :: ResolvePseudoEvent(){
 vector < TVector2 > TMust2Physics :: Match_X_Y(){
   vector < TVector2 > ArrayOfGoodCouple ;
   m_StripXEMult = m_PreTreatedData->GetMMStripXEMult();
-  m_StripYEMult = m_PreTreatedData->GetMMStripXEMult();
-
+  m_StripYEMult = m_PreTreatedData->GetMMStripYEMult();
+  
   // Prevent code from treating very high multiplicity Event
   // Those event are not physical anyway and that improve speed.
-  if( m_StripXEMult > m_MaximumStripMultiplicityAllowed || m_StripYEMult > m_MaximumStripMultiplicityAllowed )
+  if( m_StripXEMult > m_MaximumStripMultiplicityAllowed || m_StripYEMult > m_MaximumStripMultiplicityAllowed ){
     return ArrayOfGoodCouple;
+    }
 
-  for(unsigned int i = 0 ; i < m_StripXEMult ; ++i){
+  for(unsigned int i = 0 ; i < m_StripXEMult ; i++){
     for(unsigned int j = 0 ; j < m_StripYEMult ; j++){
       //   if same detector check energy
       if ( m_PreTreatedData->GetMMStripXEDetectorNbr(i) == m_PreTreatedData->GetMMStripYEDetectorNbr(j) ){
@@ -449,7 +453,7 @@ vector < TVector2 > TMust2Physics :: Match_X_Y(){
           }
 
           // Special Option, if the event is between two SiLi pad , it is rejected.
-          if(m_Ignore_not_matching_SiLi){
+          else if(m_Ignore_not_matching_SiLi){
             bool check_validity=false;
             for (unsigned int hh = 0 ; hh<16 ; ++hh ){
               if( Match_Si_SiLi(m_PreTreatedData->GetMMStripXEStripNbr(i), m_PreTreatedData->GetMMStripYEStripNbr(j) , hh+1) )
@@ -461,7 +465,9 @@ vector < TVector2 > TMust2Physics :: Match_X_Y(){
           }
 
           // Regular case, keep the event
-          else ArrayOfGoodCouple . push_back ( TVector2(i,j) ) ;
+          else {
+            ArrayOfGoodCouple . push_back ( TVector2(i,j) ) ;
+            }
         }
       }
     }
@@ -850,7 +856,7 @@ void TMust2Physics::ReadConfiguration(NPL::InputParser parser){
   InitializeStandardParameter();
   ReadAnalysisConfig();
 }
-///////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
 void TMust2Physics::InitSpectra(){
   m_Spectra = new TMust2Spectra(m_NumberOfTelescope);
 }
@@ -968,18 +974,13 @@ void TMust2Physics::AddTelescope( TVector3 C_X1_Y1,
 
   m_NumberOfTelescope++;
 
-  //   Geometry Parameter
-  double Face = 97.3; //mm
-  double NumberOfStrip = 128;
-  double StripPitch = Face/NumberOfStrip ; //mm
-
   //   Vector U on Telescope Face (paralelle to Y Strip) (NB: remember that Y strip are allong X axis)
   TVector3 U = C_X128_Y1 - C_X1_Y1 ;
-  double Ushift = (U.Mag()-Face)/2.;
+  double Ushift = (U.Mag()-98)/2.;
   U = U.Unit();
   //   Vector V on Telescope Face (parallele to X Strip)
   TVector3 V = C_X1_Y128 - C_X1_Y1 ;
-  double Vshift = (V.Mag() -Face)/2. ;
+  double Vshift = (V.Mag() -98)/2. ;
   V = V.Unit() ;
 
   //   Position Vector of Strip Center
@@ -987,6 +988,10 @@ void TMust2Physics::AddTelescope( TVector3 C_X1_Y1,
   //   Position Vector of X=1 Y=1 Strip
   TVector3 Strip_1_1;
 
+  //   Geometry Parameter
+  double Face = 98; //mm
+  double NumberOfStrip = 128;
+  double StripPitch = Face/NumberOfStrip ; //mm
   //   Buffer object to fill Position Array
   vector<double> lineX ; vector<double> lineY ; vector<double> lineZ ;
 
@@ -1095,7 +1100,7 @@ void TMust2Physics::AddTelescope(   double theta,
   U.Rotate( beta_w * Pi/180. , W ) ;
   V.Rotate( beta_w * Pi/180. , W ) ;
 
-  double Face = 97.3                     ; //mm
+  double Face = 98                     ; //mm
   double NumberOfStrip = 128             ;
   double StripPitch = Face/NumberOfStrip   ; //mm
 
@@ -1144,7 +1149,9 @@ TVector3 TMust2Physics::GetPositionOfInteraction(const int i) const{
   TVector3 Position = TVector3 (   GetStripPositionX( TelescopeNumber[i] , Si_X[i] , Si_Y[i] )    ,
       GetStripPositionY( TelescopeNumber[i] , Si_X[i] , Si_Y[i] )      ,
       GetStripPositionZ( TelescopeNumber[i] , Si_X[i] , Si_Y[i] )      ) ;
+
   return(Position) ;
+
 }
 
 TVector3 TMust2Physics::GetTelescopeNormal( const int i) const{
diff --git a/NPLib/Detectors/MUST2/TMust2Spectra.cxx b/NPLib/Detectors/MUST2/TMust2Spectra.cxx
index 0f29265db6591da7676a0b3bcd7e31bda9909086..aa5a33bf65be58d01a2856b75566b79511ed61fd 100644
--- a/NPLib/Detectors/MUST2/TMust2Spectra.cxx
+++ b/NPLib/Detectors/MUST2/TMust2Spectra.cxx
@@ -146,11 +146,11 @@ void TMust2Spectra::InitPreTreatedSpectra()
 
     // STRX_T_CAL
     name = "MM"+NPL::itoa(i+1)+"_STRX_T_CAL";
-    AddHisto2D(name, name, fStripX, 1, fStripX+1, 500, 0, 500, "MUST2/CAL/STRXT");
+    AddHisto2D(name, name, fStripX, 1, fStripX+1, 1000, 0, 1000, "MUST2/CAL/STRXT");
 
     // STRY_T_CAL
     name = "MM"+NPL::itoa(i+1)+"_STRY_T_CAL";
-    AddHisto2D(name, name, fStripY, 1, fStripY+1, 500, 0, 500, "MUST2/CAL/STRYT");
+    AddHisto2D(name, name, fStripY, 1, fStripY+1, 1000, 0, 1000, "MUST2/CAL/STRYT");
 
     // SILI_E_CAL
     name = "MM"+NPL::itoa(i+1)+"_SILI_E_CAL";
diff --git a/NPLib/Detectors/ModularLeaf/TModularLeafPhysics.h b/NPLib/Detectors/ModularLeaf/TModularLeafPhysics.h
index 3bcddfac2611567cd1a2d45e4b5a07fe73077153..83cf334201e0771947b678ae72a5ccdb9130c358 100644
--- a/NPLib/Detectors/ModularLeaf/TModularLeafPhysics.h
+++ b/NPLib/Detectors/ModularLeaf/TModularLeafPhysics.h
@@ -90,7 +90,11 @@ class TModularLeafPhysics : public TObject, public NPL::VDetector{
       //TModularLeafData*         EventData ;//!
       TModularLeafPhysics*      EventPhysics ;//!
 
-      public: // Static constructor to be passed to the Detector Factory
+
+   public:
+      inline short GetRawValue(std::string label){return m_RawData[label];};
+      inline double GetCalibratedValue(std::string label){return m_CalibratedData[label];};
+   public: // Static constructor to be passed to the Detector Factory
      static NPL::VDetector* Construct();
      ClassDef(TModularLeafPhysics,1)  // ModularLeafPhysics structure
 };
diff --git a/NPLib/Detectors/Plastic/TPlasticData.h b/NPLib/Detectors/Plastic/TPlasticData.h
index 7de7f9c816d4947ccad99779ac804d7831678d82..ff9b235cea1a2e6001cc44b83468d62cd01e6a01 100644
--- a/NPLib/Detectors/Plastic/TPlasticData.h
+++ b/NPLib/Detectors/Plastic/TPlasticData.h
@@ -51,17 +51,14 @@ class TPlasticData : public TObject {
    
    //Mult
    // E
-   inline double   GetEnergyMult() const { return fPlastic_Energy.size() ;}
-   // (T)
-   inline double   GetTimeMult()   const { return fPlastic_Time.size() ;}
-   // (N)
-   inline int      GetPlasticNumberMult() const { return fPlastic_Number.size() ;}
+   inline double   GetMult() const { return fPlastic_Energy.size() ;}
    
    /////////////////////           SETTERS           ////////////////////////
    // (E)
-   inline void   SetEnergy(const double& E)     { fPlastic_Energy.push_back(E) ;}
-   inline void   SetTime(const double&  T)      { fPlastic_Time.push_back(T) ;}
-   inline void   SetPlasticNumber(const int& N) { fPlastic_Number.push_back(N) ;}
+   inline void SetEnergyAndTime(const int& N, const double& E, const double& T)
+    { fPlastic_Energy.push_back(E);
+      fPlastic_Time.push_back(T) ;
+      fPlastic_Number.push_back(N); }
    //
    ClassDef(TPlasticData,1)  // PlasticData structure
 };
diff --git a/NPLib/Detectors/Plastic/TPlasticPhysics.cxx b/NPLib/Detectors/Plastic/TPlasticPhysics.cxx
index dd6894114e730a324c3c4e0334bdafb1cd613f89..26fb3d7119dd4b4d55ebc11b9553d4d3f87d481e 100644
--- a/NPLib/Detectors/Plastic/TPlasticPhysics.cxx
+++ b/NPLib/Detectors/Plastic/TPlasticPhysics.cxx
@@ -139,14 +139,11 @@ void TPlasticPhysics::ReadConfiguration(NPL::InputParser parser) {
 }
 
 ///////////////////////////////////////////////////////////////////////////
-void TPlasticPhysics::AddParameterToCalibrationManager()
-{
+void TPlasticPhysics::AddParameterToCalibrationManager(){
   CalibrationManager* Cal = CalibrationManager::getInstance();
 
-  for(int i = 0 ; i < NumberOfDetector ; i++)
-  {
-    for( int j = 0 ; j < 16 ; j++)
-    {
+  for(int i = 0 ; i < NumberOfDetector ; i++){
+    for( int j = 0 ; j < 16 ; j++){
       Cal->AddParameter("Plastic", "Detector"+ NPL::itoa(i+1)+"_E","Plastic_Detector"+ NPL::itoa(i+1)+"_E")   ;
       Cal->AddParameter("Plastic", "Detector"+ NPL::itoa(i+1)+"_T","Plastic_Detector"+ NPL::itoa(i+1)+"_T")   ;   
     }
@@ -155,16 +152,14 @@ void TPlasticPhysics::AddParameterToCalibrationManager()
 }
 
 ///////////////////////////////////////////////////////////////////////////
-void TPlasticPhysics::InitializeRootInputRaw() 
-{
-  TChain* inputChain = RootInput::getInstance()->GetChain()     ;
-  inputChain->SetBranchStatus ( "Plastic"       , true )        ;
-  inputChain->SetBranchStatus ( "fPlastic_*"    , true )        ;
-  inputChain->SetBranchAddress( "Plastic"       , &EventData )  ;
+void TPlasticPhysics::InitializeRootInputRaw() {
+  TChain* inputChain = RootInput::getInstance()->GetChain();
+  inputChain->SetBranchStatus ( "Plastic"   , true );
+  inputChain->SetBranchStatus ( "fPlastic_*", true );
+  inputChain->SetBranchAddress( "Plastic"   , &EventData );
 }
 ///////////////////////////////////////////////////////////////////////////
-void TPlasticPhysics::InitializeRootInputPhysics()
-{
+void TPlasticPhysics::InitializeRootInputPhysics(){
   TChain* inputChain = RootInput::getInstance()->GetChain();
   inputChain->SetBranchStatus ( "Plastic", true );
   inputChain->SetBranchStatus ( "DetectorNumber", true );
@@ -173,31 +168,27 @@ void TPlasticPhysics::InitializeRootInputPhysics()
   inputChain->SetBranchAddress( "Plastic", &EventPhysics );
 }
 ///////////////////////////////////////////////////////////////////////////
-void TPlasticPhysics::InitializeRootOutput()
-{
-  TTree* outputTree = RootOutput::getInstance()->GetTree()            ;
+void TPlasticPhysics::InitializeRootOutput(){
+  TTree* outputTree = RootOutput::getInstance()->GetTree();
   outputTree->Branch( "Plastic" , "TPlasticPhysics" , &EventPhysics ) ;
 }
 
 ///////////////////////////////////////////////////////////////////////////
-void TPlasticPhysics::BuildPhysicalEvent()
-{
-  BuildSimplePhysicalEvent()   ;
+void TPlasticPhysics::BuildPhysicalEvent(){
+  BuildSimplePhysicalEvent();
 }
 
 ///////////////////////////////////////////////////////////////////////////
-void TPlasticPhysics::BuildSimplePhysicalEvent()
-{
-  for(unsigned int i = 0 ; i < EventData->GetEnergyMult() ; i++)
-  {
-    DetectorNumber.push_back( EventData->GetPlasticNumber(i) )   ;
+void TPlasticPhysics::BuildSimplePhysicalEvent(){
+  unsigned int size =  EventData->GetMult();
+  for(unsigned int i = 0 ; i < size ; i++){
+    DetectorNumber.push_back(EventData->GetPlasticNumber(i));
     static string str;
-    str = "Plastic/Detector" + NPL::itoa( EventData->GetPlasticNumber(i) ) +"_E";
-    Energy.push_back(CalibrationManager::getInstance()->ApplyCalibration(str ,EventData->GetEnergy(i) ) );
-    str = "Plastic/Detector" + NPL::itoa( EventData->GetPlasticNumber(i) ) +"_T";
-    Time.push_back(CalibrationManager::getInstance()->ApplyCalibration(str ,EventData->GetTime(i) ) );
-  }
-
+    str = "Plastic/Detector" + NPL::itoa(EventData->GetPlasticNumber(i)) +"_E";
+    Energy.push_back(CalibrationManager::getInstance()->ApplyCalibration(str ,EventData->GetEnergy(i)));
+    str = "Plastic/Detector" + NPL::itoa(EventData->GetPlasticNumber(i)) +"_T";
+    Time.push_back(CalibrationManager::getInstance()->ApplyCalibration(str ,EventData->GetTime(i)));
+  } 
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/NPLib/Online/NPOnlineGUI.cxx b/NPLib/Online/NPOnlineGUI.cxx
index cbf86f7061c4961ec8d367b1348cb5fe9fa01f41..77ea3c58f2fd9c8f24128a7b173fcbbfaf73140a 100644
--- a/NPLib/Online/NPOnlineGUI.cxx
+++ b/NPLib/Online/NPOnlineGUI.cxx
@@ -46,18 +46,20 @@
 #include "TGComboBox.h"
 #include "TASImage.h"
 #include "TH2.h"
+#include "NPCore.h"
 ClassImp(NPL::OnlineGUI);
 ////////////////////////////////////////////////////////////////////////////////
-void NPL::ExecuteMacro(string name){
+void NPL::ExecuteMacro(const std::string& name){
   static DIR *dir;
   static struct dirent *ent;
-  static string path; 
+  static std::string path; 
   path = "./online_macros/";
-  name += ".C";
+  static std::string filename;
+  filename = name+".cxx";
   if ((dir = opendir (path.c_str())) != NULL) {
     while ((ent = readdir (dir)) != NULL) {
-      if(ent->d_name==name)
-        gROOT->ProcessLine(Form(".x online_macros/%s",name.c_str()));
+      if(ent->d_name==filename)
+        gROOT->ProcessLine(Form(".x online_macros/%s",filename.c_str()));
     }
     closedir (dir);
   }
@@ -159,8 +161,8 @@ void NPL::OnlineGUI::ResetCurrent(){
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::OnlineGUI::Eloging(){
 
-  vector<std::string> attributes;
-  vector<std::string> val;
+  std::vector<std::string> attributes;
+  std::vector<std::string> val;
 
   std::map<std::string,TGTextEntry*>::iterator it ;
   for(it = m_ElogAttributes.begin(); it != m_ElogAttributes.end() ; it++){
@@ -243,9 +245,9 @@ void NPL::OnlineGUI::ApplyRangeCurrent(){
 }
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::OnlineGUI::FitCurrent(){
-  static string gauss_formula = "([0]*[3]/([2]*sqrt(2*3.14159265359)))*exp(-0.5*(x-[1])*(x-[1])/([2]*[2]))";
+  static std::string gauss_formula = "([0]*[3]/([2]*sqrt(2*3.14159265359)))*exp(-0.5*(x-[1])*(x-[1])/([2]*[2]))";
 
-  static string full_formula = gauss_formula +"+[P0]+[P1]*x";
+  static std::string full_formula = gauss_formula +"+[P0]+[P1]*x";
   TList* list = gPad->GetListOfPrimitives();
     int Hsize = list->GetSize();
     for(int h = 0 ; h < Hsize ; h++){
@@ -314,8 +316,8 @@ void NPL::OnlineGUI::MakeGui(){
   m_ButtonBar->SetLayoutBroken(kTRUE);
   m_Main->AddFrame(m_ButtonBar,new TGLayoutHints(kLHintsLeft|kLHintsTop));
 
-  string NPLPath = gSystem->Getenv("NPTOOL");  
-  string path_quit = NPLPath+"/NPLib/Core/icons/power.xpm";
+  std::string NPLPath = gSystem->Getenv("NPTOOL");  
+  std::string path_quit = NPLPath+"/NPLib/Core/icons/power.xpm";
   m_Quit = new TGPictureButton(m_ButtonBar,gClient->GetPicture(path_quit.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame);
   m_Quit->SetBackgroundColor(m_BgColor);
   m_Quit->SetToolTipText("Quit");
@@ -323,9 +325,9 @@ void NPL::OnlineGUI::MakeGui(){
   m_ButtonBar->AddFrame(m_Quit, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
   m_Quit->MoveResize(10,5,32,32);
 
-  string path_connect = NPLPath+"/NPLib/Core/icons/plugin.xpm";
+  std::string path_connect = NPLPath+"/NPLib/Core/icons/plugin.xpm";
   m_Connect = new TGPictureButton(m_ButtonBar,gClient->GetPicture(path_connect.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame);
-  string path_connected = NPLPath+"/NPLib/Core/icons/brightness.xpm"; 
+  std::string path_connected = NPLPath+"/NPLib/Core/icons/brightness.xpm"; 
   m_Connect->SetDisabledPicture(gClient->GetPicture(path_connected.c_str()));
   m_Connect->SetBackgroundColor(m_BgColor);
   m_Connect->SetForegroundColor(m_BgColor);
@@ -334,7 +336,7 @@ void NPL::OnlineGUI::MakeGui(){
   m_ButtonBar->AddFrame(m_Connect, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
   m_Connect->MoveResize(52,5,32,32);
 
-  string path_update = NPLPath+"/NPLib/Core/icons/download.xpm";
+  std::string path_update = NPLPath+"/NPLib/Core/icons/download.xpm";
   m_Update = new TGPictureButton(m_ButtonBar,gClient->GetPicture(path_update.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame);
   m_Update->SetBackgroundColor(m_BgColor);
   m_Update->SetForegroundColor(m_BgColor);
@@ -342,7 +344,7 @@ void NPL::OnlineGUI::MakeGui(){
   m_ButtonBar->AddFrame(m_Update, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
   m_Update->MoveResize(400,5,32,32);
 
-  string path_clock= NPLPath+"/NPLib/Core/icons/clock.xpm";
+  std::string path_clock= NPLPath+"/NPLib/Core/icons/clock.xpm";
   m_Clock = new TGPictureButton(m_ButtonBar,gClient->GetPicture(path_clock.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame);
   m_Clock->SetBackgroundColor(m_BgColor);
   m_Clock->SetForegroundColor(m_BgColor);
@@ -588,7 +590,7 @@ void NPL::OnlineGUI::MakeGui(){
   m_Right->AddFrame(m_SaveAsBar, new TGLayoutHints(kLHintsTop|kLHintsExpandX));
 
   // SaveAs button
-  string path_print= NPLPath + "/NPLib/Core/icons/print.xpm";
+  std::string path_print= NPLPath + "/NPLib/Core/icons/print.xpm";
   m_SaveAs= new TGPictureButton(m_SaveAsBar,gClient->GetPicture(path_print.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame);
   m_SaveAs->SetBackgroundColor(m_FgColor);
   m_SaveAs->SetToolTipText("SaveAs");
@@ -619,15 +621,15 @@ void NPL::OnlineGUI::MakeGui(){
   m_Right->AddFrame(m_SaveAsLine, new TGLayoutHints(kLHintsExpandX,2,2,2,2));  
 
   // Elog button
-  string path_elog= NPLPath +  "/NPLib/Core/icons/booklet.xpm";
+  std::string path_elog= NPLPath +  "/NPLib/Core/icons/booklet.xpm";
   m_Eloging= new TGPictureButton(m_Right,gClient->GetPicture(path_elog.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame);
   m_Eloging->SetBackgroundColor(m_FgColor);
   m_Eloging->SetToolTipText("Elog");
   m_Right->AddFrame(m_Eloging, new TGLayoutHints(kLHintsTop|kLHintsLeft,10,10,10,10));
 
   // Elog attributes menu
-  std::map<std::string , vector <std::string> > attributes  = m_Elog.GetAttributesValues();
-  std::map<std::string , vector <std::string> >::iterator it;
+  std::map<std::string , std::vector <std::string> > attributes  = m_Elog.GetAttributesValues();
+  std::map<std::string , std::vector <std::string> >::iterator it;
   for(it = attributes.begin() ; it != attributes.end() ; it++){
     TGVerticalFrame* attframe= new TGVerticalFrame(m_Right,10000,80);
     attframe->SetBackgroundColor(m_FgColor);
@@ -665,7 +667,7 @@ void NPL::OnlineGUI::MakeGui(){
 
 
   // Center //
-  m_EmbeddedCanvas = new TRootEmbeddedCanvas("Display",m_Center,700,490,!kSunkenFrame);  
+  m_EmbeddedCanvas = new TRootEmbeddedCanvas("Display",m_Center,10000,10000,!kSunkenFrame);  
   m_EmbeddedCanvas->SetAutoFit(true);
   m_Center->AddFrame(m_EmbeddedCanvas,new TGLayoutHints(kLHintsLeft | kLHintsBottom | kLHintsExpandX | kLHintsExpandY));
   TCanvas* c = NULL;
@@ -732,19 +734,36 @@ NPL::OnlineGUI::~OnlineGUI(){
 
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::OnlineGUI::Connect(){
-  m_Client->SetAddressAndPort((string) m_Address->GetDisplayText().Data(),(int) m_Port->GetNumber());
+  m_Client->SetAddressAndPort((std::string) m_Address->GetDisplayText().Data(),(int) m_Port->GetNumber());
   m_Client->Connect();
   m_CanvasListTree->LoadCanvasList(m_Client->GetSpectra());
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::OnlineGUI::Update(){
-  if(m_Client->Update()){
-    // Do some stuff with the histo
-  }
+    TCanvas* c = m_EmbeddedCanvas->GetCanvas();
+    int current = gPad->GetNumber();
+    TList* first = c->GetListOfPrimitives();
+    int size= first->GetSize();
+    for(unsigned int i =  0 ; i < size ;i++){
+      if(first->At(i)->InheritsFrom(TPad::Class())){
+      dynamic_cast<TPad*>(first->At(i))->cd();
+      TList* list = gPad->GetListOfPrimitives();
+      int Hsize = list->GetSize();
+      for(int h = 0 ; h < Hsize ; h++){
+        TObject* obj = list->At(h);
+        if(obj->InheritsFrom(TH1::Class())){
+          m_Client->Update(obj->GetName());
+          obj->Paint();
+          ExecuteMacro(obj->GetName());
+          gPad->Update();
+        }
+      }
+     }
+    }
+    c->cd(current);
+    c->Update();
 
-  else
-    m_Connect->SetState(kButtonUp);  
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -771,9 +790,9 @@ void NPL::OnlineGUI::AutoUpdate(){
 ////////////////////////////////////////////////////////////////////////////////
 
 NPL::CanvasList::CanvasList(TGMainFrame* main, TGCanvas* parent,TRootEmbeddedCanvas* canvas,TList* Spectra){
-  string NPLPath = gSystem->Getenv("NPTOOL");  
-  string path_icon = NPLPath+"/NPLib/Core/icons/polaroid.xpm";
-  string path_icon_folder = NPLPath+"/NPLib/Core/icons/folder.xpm";
+  std::string NPLPath = gSystem->Getenv("NPTOOL");  
+  std::string path_icon = NPLPath+"/NPLib/Core/icons/polaroid.xpm";
+  std::string path_icon_folder = NPLPath+"/NPLib/Core/icons/folder.xpm";
 
   m_popen = gClient->GetPicture(path_icon.c_str());
   m_pclose = gClient->GetPicture(path_icon.c_str());
@@ -786,7 +805,7 @@ NPL::CanvasList::CanvasList(TGMainFrame* main, TGCanvas* parent,TRootEmbeddedCan
   m_ListTree->Connect("DoubleClicked(TGListTreeItem*,Int_t)","NPL::CanvasList",this,"OnDoubleClick(TGListTreeItem*,Int_t)");
   m_Main = main;
   m_EmbeddedCanvas = canvas;
-  //LoadCanvasList(Spectra);
+  m_OldCurrent     = "_void_";
 }
 ////////////////////////////////////////////////////////////////////////////////
 NPL::CanvasList::~CanvasList(){
@@ -801,8 +820,8 @@ void NPL::CanvasList::OnDoubleClick(TGListTreeItem* item, Int_t btn){
     m_EmbeddedCanvas->GetContainer()->Resize(0,0);
     m_EmbeddedCanvas->GetContainer()->Resize(size);
     c->SetHighLightColor(kAzure+7); // color of active pad
+    c->Draw();
     c->Update();
-    ExecuteMacro(c->GetName());
     c->cd(1);
   }
 }
@@ -812,12 +831,20 @@ void NPL::CanvasList::AddItem(TCanvas* c,TGListTreeItem* parent){
   item->SetPictures(m_popen, m_pclose);
   if(parent)
     parent->SetPictures(m_pfolder,m_pfolder);
-  string path = c->GetName();
   m_Canvas[c->GetName()]=c;
 }
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::CanvasList::Clear(){
+  m_OldCurrent=m_EmbeddedCanvas->GetCanvas()->GetName();
+  
+  std::map<std::string,TCanvas*>::iterator it ;
+  // delete all old canvas
+  for(it=m_Canvas.begin(); it!=m_Canvas.end();it++){
+    delete it->second;
+    }
   m_Canvas.clear();
+
+  // Clear the list tree
   TGListTreeItem* item =  m_ListTree->GetFirstItem() ;
   while(item){
     m_ListTree->DeleteItem(item);
@@ -839,7 +866,7 @@ void NPL::CanvasList::SetStatusText(const char* txt, int pi){
 }
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::CanvasList::EventInfo(int event,int px,int py,TObject* selected){
-    const char *text0, *text1, *text3;
+  const char *text0, *text1, *text3;
   char text2[50];
   text0 = selected->GetTitle();
   SetStatusText(text0,0);
@@ -857,33 +884,41 @@ void NPL::CanvasList::EventInfo(int event,int px,int py,TObject* selected){
 void NPL::CanvasList::LoadCanvasList(TList* Spectra){
   if(!Spectra)
     return;
+  Clear();
   NPL::InputParser parser("CanvasList.txt",false);
-  vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Canvas");
-  vector<std::string> token = {"Path","Divide","Histo"};
+  std::vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Canvas");
+  std::vector<std::string> token = {"Path","Divide","Histo"};
   gROOT->ProcessLine("gROOT->SetBatch(kTRUE)");
   for(unsigned int i = 0 ; i < blocks.size() ; i++){
     if(blocks[i]->HasTokenList(token)){
-      vector<std::string> path = blocks[i]->GetVectorString("Path");
-      vector<int> divide = blocks[i]->GetVectorInt("Divide");
-      vector<std::string> histo = blocks[i]->GetVectorString("Histo");
-      string name = path[path.size()-1];
+      std::vector<std::string> path = blocks[i]->GetVectorString("Path");
+      std::vector<int> divide = blocks[i]->GetVectorInt("Divide");
+      std::vector<std::string> histo = blocks[i]->GetVectorString("Histo");
+      std::string name = path[path.size()-1];
       TCanvas* c = new TCanvas(name.c_str(), 5000,5000,0);
       c->Divide(divide[0],divide[1]);
 
-
       unsigned int size = histo.size();
       for(unsigned int h = 0 ; h < size ; h++){
         c->cd(h+1);
+        std::string padname=name+"_"+NPL::itoa(h);
+        gPad->SetName(padname.c_str());
         TH1* hist = (TH1*) Spectra->FindObject(histo[h].c_str());
         if(hist){
           hist->UseCurrentStyle();
           hist->Draw("colz");
+          ExecuteMacro(hist->GetName());
         }
       }
+      if(m_EmbeddedCanvas && m_OldCurrent == c->GetName()){
+        m_EmbeddedCanvas->AdoptCanvas(c);
+      }
+
+
       TGListTreeItem*  item  =  NULL;
       TGListTreeItem*  pitem =  NULL;
 
-      string item_path="";
+      std::string item_path="";
       for(unsigned int j = 0 ; j < path.size()-1 ; j++){
         item_path+="/"+path[j];
         item = m_ListTree->FindItemByPathname(item_path.c_str());
diff --git a/NPLib/Online/NPOnlineGUI.h b/NPLib/Online/NPOnlineGUI.h
index d47f2eadd9404db1baaa3b22ae6ec63d4cb11ed8..1451eda228d5cb39fbe3341f7eeff8fc85ed16c9 100644
--- a/NPLib/Online/NPOnlineGUI.h
+++ b/NPLib/Online/NPOnlineGUI.h
@@ -41,10 +41,9 @@
 #include "NPSpectraClient.h"
 #include "NPElog.h"
 #include<map>
-using namespace std;
 
 namespace NPL{
-   void ExecuteMacro(string name);
+   void ExecuteMacro(const std::string& name);
   
   class CanvasList {
     RQ_OBJECT("CanvasList")
@@ -52,15 +51,16 @@ namespace NPL{
       TGMainFrame* m_Main;
       TGListTree* m_ListTree;
       TRootEmbeddedCanvas* m_EmbeddedCanvas; 
+      std::string          m_OldCurrent;
       TGTab* m_Tab;
-      map<string,TCanvas*> m_Canvas;
+      std::map<std::string,TCanvas*> m_Canvas;
       const TGPicture* m_popen;     
       const TGPicture* m_pclose;   
       const TGPicture* m_pfolder;   
 
       Pixel_t m_BgColor;
       Pixel_t m_FgColor;
-      vector<TGStatusBar*> m_StatusBar;
+      std::vector<TGStatusBar*> m_StatusBar;
 
     public:
       CanvasList(TGMainFrame* main, TGCanvas* parent, TRootEmbeddedCanvas* canvas, TList*);
diff --git a/NPLib/Online/NPSpectraClient.cxx b/NPLib/Online/NPSpectraClient.cxx
index 63860db504fc927cb85d31ee4eb04b833e0ed963..473b99a189622441fe9c5f92cdd209d29d18b584 100644
--- a/NPLib/Online/NPSpectraClient.cxx
+++ b/NPLib/Online/NPSpectraClient.cxx
@@ -24,11 +24,11 @@
 #include<iostream>
 #include<sstream>
 #include"NPCore.h"
+#include"TH2.h"
 ////////////////////////////////////////////////////////////////////////////////
 NPL::SpectraClient::SpectraClient(){
   m_Sock =NULL;
   m_Spectra=NULL; 
-  m_Delta = NULL;
   m_Address = "localhost";
   m_Port = 9092;
 }
@@ -36,7 +36,6 @@ NPL::SpectraClient::SpectraClient(){
 NPL::SpectraClient::SpectraClient(std::string address, int port){
   m_Sock =NULL;
   m_Spectra=NULL; 
-  m_Delta = NULL;
   m_Address = address;
   m_Port = port;
 }
@@ -52,8 +51,6 @@ NPL::SpectraClient::~SpectraClient(){
     delete m_Spectra;
     m_Spectra=NULL;
   }
-  if(m_Delta)
-    delete m_Delta;
 }
 ////////////////////////////////////////////////////////////////////////////////
 bool NPL::SpectraClient::Connect(){
@@ -112,7 +109,8 @@ bool NPL::SpectraClient::Sync(){
       delete m_Spectra;
       m_Spectra = NULL;
     }
-    
+   
+    //message->Uncompress();
     m_Spectra = (TList*) message->ReadObject(message->GetClass());
     if(m_Spectra){
       NPL::SendInformation("NPL::SpectraClient","Successful sync of spectra list");
@@ -126,14 +124,14 @@ bool NPL::SpectraClient::Sync(){
   }
 
   else{
-    NPL::SendInformation("NPL::SpectraClient","Server return empty sepctra list");
+    NPL::SendInformation("NPL::SpectraClient","Server returned an empty message");
     return false;
   }
 
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-bool NPL::SpectraClient::Update(){
+bool NPL::SpectraClient::Update(std::string name){
   if(!m_Sock || !(m_Sock->IsValid())){
     if(m_Sock){
       m_Sock->Close("force");
@@ -146,7 +144,7 @@ bool NPL::SpectraClient::Update(){
   }
 
   TMessage* message=NULL;
-  m_Sock->Send("RequestDelta");
+  m_Sock->Send(name.c_str());
 
   if(m_Sock->Recv(message)<=0){
     if(m_Sock){
@@ -161,16 +159,12 @@ bool NPL::SpectraClient::Update(){
   }
 
   if(message){
-    if(m_Delta)
-      delete m_Delta;
-     
-    m_Delta = (NPL::DeltaSpectra*) message->ReadObject(message->GetClass());
-   
-    if(m_Delta && m_Spectra){
-      m_Delta->UpdateLocalSpectra(m_Spectra);
-      }
-    else
-      NPL::SendWarning("NPL::SpectraClient","Local Spectra or received Delta are NULL");
+    // Get the current spectra
+    TH1* h = (TH1*) m_Spectra->FindObject(name.c_str());
+    // Get the new one
+    TH1* n = (TH1*) message->ReadObject(message->GetClass());
+    UpdateTH1(h,n); 
+    delete n;  
     return true;
   }
   
@@ -184,4 +178,22 @@ bool NPL::SpectraClient::Update(){
 TList* NPL::SpectraClient::GetSpectra(){
   return m_Spectra;
 }
+////////////////////////////////////////////////////////////////////////////////
+void NPL::SpectraClient::UpdateTH1(TH1* Old , TH1* New){
+  // Save the Ranges on the different axis
+  double minX = Old->GetXaxis()->GetBinLowEdge(Old->GetXaxis()->GetFirst());
+  double maxX = Old->GetXaxis()->GetBinUpEdge(Old->GetXaxis()->GetLast());
+  double minY = Old->GetYaxis()->GetBinLowEdge(Old->GetYaxis()->GetFirst());
+  double maxY = Old->GetYaxis()->GetBinUpEdge(Old->GetYaxis()->GetLast());
+
+  // Put new stuff in old object
+  New->Copy(*Old) ;    
+  // Reset the axis range
+  Old->SetAxisRange(minX,maxX);
+  if(Old->GetDimension()==2)
+    Old->SetAxisRange(minY,maxY,"Y");
+   
+  // Refresh style
+  Old->UseCurrentStyle();      
+ }
 
diff --git a/NPLib/Online/NPSpectraClient.h b/NPLib/Online/NPSpectraClient.h
index e80dd5c7dfe020f5be1b7d4d3a58b757d105dca5..fb67e65df181429b301dd7d45e7ccee05ac62126 100644
--- a/NPLib/Online/NPSpectraClient.h
+++ b/NPLib/Online/NPSpectraClient.h
@@ -27,8 +27,7 @@
 #include "TMessage.h"
 #include "TList.h"
 #include "TH1.h"
-// NPTOOL
-#include "NPDeltaSpectra.h"
+#include "string"
 
 namespace NPL{
   class SpectraClient{
@@ -42,9 +41,9 @@ namespace NPL{
       bool Connect();
       // Get the full copy of Spectrum (erase local one first)
       bool Sync();
-      // Get the Delta since last update
-      bool Update();
-
+      // Update a single spectra
+      bool Update(std::string name);
+      void UpdateTH1(TH1* Old, TH1* New );
     private: // The sochet use for connection
       TSocket* m_Sock;
       std::string m_Address;
@@ -52,7 +51,6 @@ namespace NPL{
 
     private: // The spectrum list
       TList* m_Spectra; 
-      NPL::DeltaSpectra* m_Delta;
     public: // GUI Interface
       TList* GetSpectra();
  
diff --git a/NPLib/Physics/CMakeLists.txt b/NPLib/Physics/CMakeLists.txt
index 06d6713640464d23bb452541b91deaa5921414f8..4d2d6d776ed17546b2eb551c083e93e6b2cf32c3 100644
--- a/NPLib/Physics/CMakeLists.txt
+++ b/NPLib/Physics/CMakeLists.txt
@@ -1,9 +1,14 @@
 add_custom_command(OUTPUT NPReactionDict.cxx COMMAND ../scripts/build_dict.sh NPReaction.h NPReactionDict.cxx NPReaction.rootmap libNPPhysics.so NPPhysicsLinkDef.h DEPENDS NPReaction.h) 
+
 add_custom_command(OUTPUT NPEnergyLossDict.cxx COMMAND ../scripts/build_dict.sh NPEnergyLoss.h NPEnergyLossDict.cxx NPEnergyLoss.rootmap libNPPhysics.so NPPhysicsLinkDef.h DEPENDS NPEnergyLoss.h) 
+
 add_custom_command(OUTPUT TInitialConditionsDict.cxx COMMAND ../scripts/build_dict.sh TInitialConditions.h TInitialConditionsDict.cxx TInitialConditions.rootmap libNPInitialConditions.so DEPENDS TInitialConditions.h)
+
 add_custom_command(OUTPUT TInteractionCoordinatesDict.cxx COMMAND ../scripts/build_dict.sh TInteractionCoordinates.h TInteractionCoordinatesDict.cxx TInteractionCoordinates.rootmap libNPInteractionCoordinates.so DEPENDS TInteractionCoordinates.h)
 
-add_library(NPPhysics SHARED NPBeam.cxx NPEnergyLoss.cxx NPFunction.cxx NPNucleus.cxx NPReaction.cxx NPReactionDict.cxx NPEnergyLossDict.cxx )
+add_custom_command(OUTPUT TReactionConditionsDict.cxx COMMAND ../scripts/build_dict.sh TReactionConditions.h TReactionConditionsDict.cxx TReactionConditions.rootmap libNPReactionConditions.so DEPENDS TReactionConditions.h)
+
+add_library(NPPhysics SHARED NPDecay.cxx NPBeam.cxx NPEnergyLoss.cxx NPFunction.cxx NPNucleus.cxx NPReaction.cxx NPReactionDict.cxx NPEnergyLossDict.cxx )
 target_link_libraries(NPPhysics ${ROOT_LIBRARIES} Physics NPCore) 
 
 add_library(NPInitialConditions  SHARED  TInitialConditions.cxx TInitialConditionsDict.cxx )
@@ -12,4 +17,8 @@ target_link_libraries(NPInitialConditions  ${ROOT_LIBRARIES} )
 add_library(NPInteractionCoordinates SHARED TInteractionCoordinates.cxx TInteractionCoordinatesDict.cxx)
 target_link_libraries(NPInteractionCoordinates ${ROOT_LIBRARIES} ) 
 
-install(FILES NPBeam.h NPEnergyLoss.h NPFunction.h NPNucleus.h NPReaction.h TInitialConditions.h TInteractionCoordinates.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+add_library(NPReactionConditions SHARED TReactionConditions.cxx TReactionConditionsDict.cxx)
+target_link_libraries(NPReactionConditions ${ROOT_LIBRARIES} ) 
+
+
+install(FILES NPDecay.h NPBeam.h NPEnergyLoss.h NPFunction.h NPNucleus.h NPReaction.h TInitialConditions.h TInteractionCoordinates.h TReactionConditions.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
diff --git a/NPLib/Physics/NPBeam.cxx b/NPLib/Physics/NPBeam.cxx
index 454f4f894dd7f3ac32ce35fdc92e11d85354c002..d9487db7aaf14d5c7e0b7b9dcd77498aecf55d93 100644
--- a/NPLib/Physics/NPBeam.cxx
+++ b/NPLib/Physics/NPBeam.cxx
@@ -66,6 +66,8 @@ Beam::Beam(){
   fEffectiveTargetThickness = 0 ;
   fTargetAngle = 0 ;
   fTargetZ = 0 ;
+  fZEmission=-1*NPUNITS::m;
+  fZProfile=0;
   fVerboseLevel = NPOptionManager::getInstance()->GetVerboseLevel();
 
   // case of user given distribution
@@ -98,6 +100,8 @@ Beam::Beam(string isotope){
   fEffectiveTargetThickness = 0 ;
   fTargetAngle = 0 ;
   fTargetZ = 0 ;
+  fZEmission=-1*NPUNITS::m;
+  fZProfile=0;
   fVerboseLevel = NPOptionManager::getInstance()->GetVerboseLevel();
 
   // case of user given distribution
@@ -141,6 +145,12 @@ void Beam::ReadConfigurationFile(NPL::InputParser parser){
       if(blocks[i]->HasToken("ExcitationEnergy"))
         fExcitationEnergy = blocks[i]->GetDouble("ExcitationEnergy","MeV");
 
+      if(blocks[i]->HasToken("ZEmission"))
+        fZEmission = blocks[i]->GetDouble("ZEmission","mm");
+
+      if(blocks[i]->HasToken("ZProfile"))
+        fZProfile = blocks[i]->GetDouble("ZProfile","mm");
+
       // Energy analytic
       if(blocks[i]->HasTokenList(energyA)){
         fEnergy = blocks[i]->GetDouble("Energy","MeV");
@@ -175,7 +185,7 @@ void Beam::ReadConfigurationFile(NPL::InputParser parser){
         SetXThetaXHist( Read2DProfile(XThetaX[0], XThetaX[1]));
         vector<string> YPhiY= blocks[i]->GetVectorString("YPhiYProfilePath");
         SetYPhiYHist( Read2DProfile(YPhiY[0], YPhiY[1]));
-
+        
       }
 
       else{
@@ -195,28 +205,46 @@ void Beam::ReadConfigurationFile(NPL::InputParser parser){
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 void Beam::GenerateRandomEvent(double& E, double& X, double& Y, double& Z, double& ThetaX, double& PhiY ){
-  X = Y = 1000000*cm;
-
-  if(fSigmaEnergy!=-1)
-    E = gRandom->Gaus(fEnergy,fSigmaEnergy);
+  double X0,Y0;
+  X0 = Y0 = 1*km;
+
+  // ENERGY //
+  // Gaussian energy distribution 
+  if(fSigmaEnergy!=-1){
+    E=-1;
+    while(E<0)
+      E = gRandom->Gaus(fEnergy,fSigmaEnergy);
+  }
+  // User Profile
   else
     E = fEnergyHist->GetRandom();
-
+  
+  // POSITION/DIRECTION AT Z PROFILE//
+  // Gaussian Distribution
   if(fSigmaX!=-1){
-    // Shoot within the target unless target size is null (no limit)
-    while(sqrt(X*X+Y*Y)>fEffectiveTargetSize || fEffectiveTargetSize == 0){
-      NPL::RandomGaussian2D(fMeanX, fMeanThetaX, fSigmaX, fSigmaThetaX, X, ThetaX);
-      NPL::RandomGaussian2D(fMeanY, fMeanPhiY, fSigmaY, fSigmaPhiY, Y, PhiY);
-    }
+      NPL::RandomGaussian2D(fMeanX, fMeanThetaX, fSigmaX, fSigmaThetaX, X0, ThetaX);
+      NPL::RandomGaussian2D(fMeanY, fMeanPhiY, fSigmaY, fSigmaPhiY, Y0, PhiY);
   }
 
+  // Profile
   else{
-    while(sqrt(X*X+Y*Y)>fEffectiveTargetSize || fEffectiveTargetSize == 0){
       fXThetaXHist->GetRandom2(X,ThetaX);
       fYPhiYHist->GetRandom2(Y,PhiY);
-    }
   }
-  Z = fTargetZ + fEffectiveTargetThickness*(gRandom->Uniform()-0.5);
+  // Direction
+  double Xdir = sin(ThetaX); // cos(90-x) = sin(x)
+  double Ydir = sin(PhiY); 
+  double Zdir = sqrt(1-Xdir*Xdir-Ydir*Ydir); // alpha^2 + beta^2 + gamma^2 = 1
+  // Stretch factor to extend unitary vector from ZEmission to ZProfile
+  double S = fZProfile-fZEmission ;
+  TVector3 BeamDir(Xdir*S/Zdir,Ydir*S/Zdir,S);
+ 
+  Xdir = BeamDir.X();
+  Ydir = BeamDir.Y();
+  // POSITION/DIRECTION AT Z EMISSION// 
+  X = X0 - Xdir;
+  Y = Y0 - Ydir;
+  Z = fZEmission;
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
diff --git a/NPLib/Physics/NPBeam.h b/NPLib/Physics/NPBeam.h
index 7ddc9f081487e2eca5299a47073cdc2d3768116a..79134f25beb3a5e5072f29eaa512a1410e59eb21 100644
--- a/NPLib/Physics/NPBeam.h
+++ b/NPLib/Physics/NPBeam.h
@@ -68,7 +68,8 @@ namespace NPL{
     double fMeanPhiY;
     double fSigmaThetaX;
     double fSigmaPhiY;
-    
+    double fZEmission;
+    double fZProfile;
     // case of user given distribution
     TH1F* fEnergyHist;
     TH2F* fXThetaXHist;
diff --git a/NPLib/Physics/NPDecay.cxx b/NPLib/Physics/NPDecay.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..68a6eb6dbed984cecc7421e6ed593c3898fa5644
--- /dev/null
+++ b/NPLib/Physics/NPDecay.cxx
@@ -0,0 +1,438 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2016    this file is part of the NPTool Project        *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ *                                                                           *
+ * Original Author : Adrien Matta  contact: matta@lpccaen.in2p3.fr           *
+ *                                                                           *
+ * Creation Date   : Octobre 2017                                            *
+ * Last update     :                                                         *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *   This Class hold data for all decay scheme of a given nuclei             *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+#include "NPDecay.h"
+#include <iostream>
+#include "NPOptionManager.h"
+#include "NPFunction.h"
+#include "NPCore.h"
+#include "TF1.h"
+#include "TRandom.h"
+////////////////////////////////////////////////////////////////////////////////
+//////////////////////////// Single Decay //////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+
+NPL::SingleDecay::SingleDecay(std::string mother, double threshold, std::vector<std::string> daughter,std::vector<double> Ex, TH1F* CrossSection){
+
+  m_MotherName = mother;
+  m_DaughterName = daughter;
+  // Checking if there is a mixt of Gamma and particle
+  bool hasGamma=false;
+  bool hasOther=false;
+  unsigned int sizeD = daughter.size();
+  for(unsigned int d = 0 ; d < sizeD ; d++){
+    if(daughter[d]=="Gamma"|| daughter[d]=="gamma")
+      hasGamma=true;
+    else if (daughter[d]!=m_MotherName)
+      hasOther=true;
+  }
+
+  // If the same channel contain both, issue an error and exit
+  if(hasOther&&hasGamma){
+    NPL::SendErrorAndExit("NPL::SingleDecay","Cannot have particle/gamma mixt decay channel");
+  }
+  else if (hasGamma)
+    m_GammaOnly=true;
+  else
+    m_GammaOnly=false;
+
+  m_ExcitationEnergies = Ex;
+  m_CrossSectionHist = CrossSection;
+  m_Mother = NPL::Nucleus(m_MotherName);
+  m_MotherMass = m_Mother.Mass();
+  m_Threshold = threshold;
+  unsigned int size = m_DaughterName.size();
+  for(unsigned int i = 0 ; i < size ; i++){
+    m_Daughter.push_back(NPL::Nucleus(m_DaughterName[i])) ;
+    
+    m_Daughter[i].SetExcitationEnergy(Ex[i]);
+    if (m_DaughterName[i]=="Gamma" || m_DaughterName[i]=="gamma")
+      m_DaughterMasses.push_back(0);
+    else
+      m_DaughterMasses.push_back(m_Daughter[i].Mass()/GeV);
+
+  }
+
+}
+////////////////////////////////////////////////////////////////////////////////
+bool NPL::SingleDecay::GenerateEvent(double MEx, double MEK, double MPX, double MPY, double MPZ, std::vector<double>& DEK, std::vector<double>& DPx, std::vector<double>& DPy, std::vector<double>& DPz){
+  // Clear the output object
+  DPx.clear();
+  DPy.clear();
+  DPz.clear();
+  DEK.clear();
+  if(MEx < m_Threshold)
+    return false;
+
+  double Effective_Mass= m_MotherMass+MEx;
+  double NucleiEnergy= MEK+Effective_Mass;
+
+  double NucleiMomentum=
+    sqrt(NucleiEnergy*NucleiEnergy 
+        - Effective_Mass*Effective_Mass);
+  TVector3 Momentum(MPX,MPY,MPZ);
+  Momentum = Momentum.Unit();
+
+  if(m_CrossSectionHist){
+    TLorentzVector NucleiLV( NucleiMomentum*Momentum.X(),
+        NucleiMomentum*Momentum.Y(),
+        NucleiMomentum*Momentum.Z(),
+        NucleiEnergy);
+    // Shoot the angle in Center of Mass (CM) frame
+    double ThetaCM = m_CrossSectionHist->GetRandom()* deg;
+    double phi     = gRandom->Uniform()*2.*pi;
+
+    // Build daughter particule CM LV
+    // Pre compute variable for the decay
+    double m1 = m_DaughterMasses[0]*GeV;
+    double m2 = m_DaughterMasses[1]*GeV;
+    if(Effective_Mass<(m1+m2))
+      return false;
+
+    else {
+      double Energy = ( 1./(2.*Effective_Mass) )*(Effective_Mass*Effective_Mass + m1*m1 - m2*m2);
+      double Momentum1 = sqrt(Energy*Energy - m1*m1);
+
+      TVector3 FirstDaughterMomentum = Momentum1 * TVector3( sin(ThetaCM) * cos(phi),
+          sin(ThetaCM) * sin(phi),
+          cos(ThetaCM));
+
+      TLorentzVector FirstDaughterLV(FirstDaughterMomentum,Energy);
+
+      FirstDaughterLV.Boost( NucleiLV.BoostVector() );
+      TLorentzVector SecondDaughterLV = NucleiLV - FirstDaughterLV;
+
+      DEK.push_back(FirstDaughterLV.E()-m1);
+      DPx.push_back(FirstDaughterLV.X());
+      DPy.push_back(FirstDaughterLV.Y());
+      DPz.push_back(FirstDaughterLV.Z());
+
+      DEK.push_back(SecondDaughterLV.E()-m2);
+      DPx.push_back(SecondDaughterLV.X());
+      DPy.push_back(SecondDaughterLV.Y());
+      DPz.push_back(SecondDaughterLV.Z());
+      return true;
+    }
+  }
+
+  // Case of a TGenPhaseSpace
+  else if (!m_GammaOnly){
+    // TGenPhaseSpace require to input Energy and Momentum in GeV
+    TLorentzVector NucleiLV( NucleiMomentum*Momentum.x()/GeV,
+        NucleiMomentum*Momentum.y()/GeV,
+        NucleiMomentum*Momentum.z()/GeV,
+        NucleiEnergy/GeV);
+
+    if( !m_TGenPhaseSpace.SetDecay(NucleiLV, m_Daughter.size(), &m_DaughterMasses[0]) )
+      return false;
+
+    else{
+      // FIXME : weight has to be returned for normalisation
+      double weight = m_TGenPhaseSpace.Generate();
+
+      TLorentzVector* DaughterLV ;
+      double KineticEnergy;
+
+      for (unsigned int i = 0 ;  i < m_Daughter.size(); i++) {
+        DaughterLV = m_TGenPhaseSpace.GetDecay(i);
+        DEK.push_back(GeV*DaughterLV->E()-GeV*m_DaughterMasses[i]);
+        DPx.push_back(GeV*DaughterLV->X());
+        DPy.push_back(GeV*DaughterLV->Y());
+        DPz.push_back(GeV*DaughterLV->Z());
+      }
+      return true;
+    }
+  }
+
+  // Case of a Gamma Cascade
+  else{
+    TLorentzVector NucleiLV( NucleiMomentum*Momentum.X(),
+        NucleiMomentum*Momentum.Y(),
+        NucleiMomentum*Momentum.Z(),
+        NucleiEnergy);
+
+    TLorentzVector TotalGamma(0,0,0,0);
+    unsigned int pos;
+
+    unsigned int sizeM = m_DaughterMasses.size();
+    for (unsigned int i = 0; i < sizeM; i++) {
+      // One of the Gamma
+      if(m_DaughterName[i]=="gamma"|| m_DaughterName[i]=="Gamma"){
+         // Shoot flat in cos(theta) and Phi to have isotropic emission
+        double cos_theta = -1+2*gRandom->Uniform();
+        double theta     = acos(cos_theta);
+        double phi       = gRandom->Uniform()*2.*pi;
+        double gammaEnergy = m_ExcitationEnergies[i];
+        TLorentzVector GammaLV( gammaEnergy*cos(phi)*sin(theta),
+          gammaEnergy*sin(phi)*sin(theta),
+          gammaEnergy*cos(theta),
+          gammaEnergy);
+        
+       GammaLV.Boost(NucleiLV.BoostVector());
+        TotalGamma+=GammaLV; 
+        DEK.push_back(GammaLV.E());
+        DPx.push_back(GammaLV.X());
+        DPy.push_back(GammaLV.Y());
+        DPz.push_back(GammaLV.Z());
+
+        }
+     else{
+        pos = i;
+        DEK.push_back(0);
+        DPx.push_back(0);
+        DPy.push_back(0);
+        DPz.push_back(0);
+       }
+    }
+
+    // The original nuclei get what is left
+   NucleiLV -= TotalGamma;
+   DEK[pos]=NucleiLV.E()-m_MotherMass;
+   DPx[pos]=NucleiLV.X();
+   DPy[pos]=NucleiLV.Y();
+   DPz[pos]=NucleiLV.Z();
+  }
+}
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////// Decay ///////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+NPL::Decay::Decay(std::string MotherName,std::string path){
+  ReadConfiguration(MotherName,path);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+NPL::Decay::Decay(std::string MotherName, NPL::InputParser parser){
+  ReadConfiguration(MotherName,parser);     
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void NPL::Decay::ReadConfiguration(std::string MotherName,std::string path){
+  NPL::InputParser parser(path);
+  ReadConfiguration(MotherName,parser);
+}
+////////////////////////////////////////////////////////////////////////////////
+bool NPL::Decay::AnyAboveThreshold(double MEx){
+  unsigned int size = m_SingleDecay.size();
+  for(unsigned int i = 0 ; i < size ; i++){
+    if(MEx >=  m_SingleDecay[i].GetThreshold())
+      return true;
+  }
+  return false;
+}
+////////////////////////////////////////////////////////////////////////////////
+void NPL::Decay::ReadConfiguration(std::string MotherName, NPL::InputParser parser){
+  vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithTokenAndValue("Decay",MotherName);
+  m_BRTotal=0;
+  m_MotherName=MotherName;
+
+  if(NPOptionManager::getInstance()->GetVerboseLevel())
+    std::cout << "//// " << blocks.size() << " decay path found for " << MotherName << std::endl; 
+
+  std::vector<std::string> token = 
+  {"Daughter","Threshold","ExcitationEnergy","Shoot","LifeTime","BranchingRatio"};
+  std::vector<std::string> CStoken = 
+  {"DifferentialCrossSection"};
+
+  unsigned int size = blocks.size();
+  for(unsigned int i = 0 ; i < size ; i++){
+    if(blocks[i]->HasTokenList(token)){
+      if(NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "//// "<< MotherName << " Decay " << i+1 <<  endl;
+
+      std::vector<std::string> Daughter = blocks[i]->GetVectorString("Daughter");
+
+      double Threshold = blocks[i]->GetDouble("Threshold","MeV");   
+      std::vector<double> Ex = blocks[i]->GetVectorDouble("ExcitationEnergy","MeV");
+      double BR = blocks[i]->GetDouble("BranchingRatio","void");
+      m_BranchingRatio.push_back(BR);
+      m_BRTotal+= BR;
+      double LT = blocks[i]->GetDouble("LifeTime","ns");
+      m_Shoot = blocks[i]->GetVectorInt("Shoot");
+
+      TH1F* h = NULL; 
+      std::vector<std::string> cs ;
+
+
+      if(blocks[i]->HasTokenList(CStoken)){
+        if(Ex.size()!=2){
+          std::cout << "ERROR : Differential cross section is only used for two body decay" << std::endl;
+          exit(1);
+        }
+        cs = blocks[i]->GetVectorString("DifferentialCrossSection");
+      }
+
+      // Load the Cross section  
+      if(cs.size()==2){
+        h = NPL::Read1DProfile(cs[0],cs[1]);
+        TF1* sinus = new TF1("sinus","1/sin(x*3.141592653589793/180.)",0,180);
+        h->Divide(sinus,1);
+        delete sinus;
+      }
+      else if (cs.size()!=0){
+        std::cout << "ERROR : You should provide 2 arguments for the cross section : path and name" << std::endl;
+        exit(1);
+      }
+
+      m_SingleDecay.push_back(SingleDecay(m_MotherName,Threshold,Daughter,Ex,h));
+    }
+
+    else{
+      cout << "ERROR: check your input file formatting" << endl;
+      exit(1);
+    }
+
+  }
+  // Shift the Branching ratio for faster shooting during event generation
+  for (unsigned int i = 1; i < m_BranchingRatio.size(); i++) {
+    m_BranchingRatio[i] = m_BranchingRatio[i-1]+m_BranchingRatio[i];
+  } 
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+bool NPL::Decay::GenerateEvent(double MEx,double MEK,double MPx,double MPy,double MPz, 
+    std::vector<NPL::Nucleus>& Daughter, std::vector<double>& Ex,
+    std::vector<double>& DEK,
+    std::vector<double>& DPx,std::vector<double>& DPy,std::vector<double>& DPz){
+  // Choose one of the Decay
+  // if the decay is not allowed, then try again
+  // FIXME: does take into account case where the decay is never possible
+  bool worked = false;
+  // Limit the number of attempt
+  unsigned int count =0;
+  while (!worked){
+    if(count++ > 1000)
+      break;
+    double rand = m_BRTotal*gRandom->Uniform();
+    unsigned int size = m_BranchingRatio.size();
+    unsigned int ChoosenDecay = 0;
+    for (unsigned int i = 1; i < size; i++) {
+      if(rand > m_BranchingRatio[i-1] && rand< m_BranchingRatio[i])
+        ChoosenDecay = i;
+    }
+
+    // Generate the event
+    worked = m_SingleDecay[ChoosenDecay].GenerateEvent(MEx,MEK,MPx,MPy,MPz,DEK,DPx,DPy,DPz);
+    if(worked){
+      Daughter = m_SingleDecay[ChoosenDecay].GetDaughter();
+      Ex = m_SingleDecay[ChoosenDecay].GetExcitationEnergies();  
+    }
+  }
+
+  return worked;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////// Decay Store ////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+NPL::DecayStore::DecayStore(std::string path){
+  ReadConfiguration(path);  
+}
+////////////////////////////////////////////////////////////////////////////////
+NPL::DecayStore::DecayStore(NPL::InputParser parser){
+  ReadConfiguration(parser);  
+}
+////////////////////////////////////////////////////////////////////////////////
+void NPL::DecayStore::ReadConfiguration(std::string path){
+  NPL::InputParser parser(path);  
+  ReadConfiguration(parser);
+}  
+////////////////////////////////////////////////////////////////////////////////
+void NPL::DecayStore::ReadConfiguration(NPL::InputParser parser){
+  // Get all the Nucleus concern by a decay
+  std::vector<std::string> nuclei = parser.GetAllBlocksValues("Decay");
+  m_Store.clear();
+  unsigned int size = nuclei.size();
+  for(unsigned int i = 0 ; i < size ; i++){
+    if(m_Store.find(nuclei[i])==m_Store.end()){
+      m_Store[nuclei[i]] = Decay(nuclei[i],parser);
+    } 
+  }
+}
+////////////////////////////////////////////////////////////////////////////////
+void NPL::DecayStore::GenerateEvent(std::string MotherName, double MEx,
+    double MEK,double MPx,double MPy,double MPz,
+    std::vector<NPL::Nucleus>& Daughter, std::vector<double>& Ex,
+    std::vector<double>& DEK,
+    std::vector<double>& DPx,std::vector<double>& DPy,std::vector<double>& DPz){
+
+  if(m_Store.find(MotherName)!=m_Store.end())
+    m_Store[MotherName].GenerateEvent(MEx,MEK,MPx,MPy,MPz,Daughter,Ex,DEK,DPx,DPy,DPz);  
+  else
+    cout << "Warning: Decay for " << MotherName << " requested but not found" << endl;
+}
+////////////////////////////////////////////////////////////////////////////////
+bool NPL::DecayStore::AnyAboveThreshold(std::string MotherName, double MEx){
+  if(m_Store.find(MotherName)!=m_Store.end())
+    m_Store[MotherName].AnyAboveThreshold(MEx);
+  else
+    return false;
+}
+////////////////////////////////////////////////////////////////////////////////
+std::set<std::string> NPL::DecayStore::GetAllMotherName(){
+  std::map<std::string,NPL::Decay>::iterator it;
+  std::set<std::string> result;
+  for(it = m_Store.begin(); it != m_Store.end() ; it++)
+    result.insert(it->first);   
+
+  return result; 
+} 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/NPLib/Physics/NPDecay.h b/NPLib/Physics/NPDecay.h
new file mode 100644
index 0000000000000000000000000000000000000000..9478a22d94d48c4eaa299468a2855e174e1145df
--- /dev/null
+++ b/NPLib/Physics/NPDecay.h
@@ -0,0 +1,133 @@
+#ifndef NPDECAY_H
+#define NPDECAY_H
+/*****************************************************************************
+ * Copyright (C) 2009-2016    this file is part of the NPTool Project        *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ *                                                                           *
+ * Original Author : Adrien Matta  contact: matta@lpccaen.in2p3.fr           *
+ *                                                                           *
+ * Creation Date   : Octobre 2017                                            *
+ * Last update     :                                                         *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *   This Class hold data for all decay scheme of a given nuclei             *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+// C++ header
+#include <string>
+#include <vector>
+#include <set>
+
+// NPL Header
+#include "NPInputParser.h"
+#include "NPNucleus.h"
+
+// Root
+#include "TH1D.h"
+#include "TGenPhaseSpace.h"
+namespace NPL{
+  // A given decay Path
+  class SingleDecay{
+    public: 
+        SingleDecay(){};
+        SingleDecay(std::string mother,double threshold, std::vector<std::string> daughter, 
+        std::vector<double> Ex, TH1F* CrossSection);
+        ~SingleDecay(){};
+    
+    private:
+        std::string m_MotherName; 
+        NPL::Nucleus m_Mother;
+        double m_MotherMass;
+        std::vector<std::string> m_DaughterName;
+        std::vector<NPL::Nucleus> m_Daughter;
+        bool m_GammaOnly;
+        std::vector<double> m_DaughterMasses;
+        std::vector<double> m_ExcitationEnergies;
+        double m_Threshold;
+        TH1F* m_CrossSectionHist; 
+        TGenPhaseSpace m_TGenPhaseSpace; 
+ 
+   public:
+        // Given Energy and Momentum direction of Mother,
+        // Send back Momemtum and Energy of Daugther
+        // Return false if the decay is not allowed
+        // true other wise
+        bool GenerateEvent(double MEx,double MEK,double MPx, double MPy,double MPz,
+        std::vector<double>& DEK,
+        std::vector<double>& DPx,std::vector<double>& DPy,std::vector<double>& DPz);
+   
+   public:// Getter
+        inline std::vector<std::string> GetDaughterName() {return m_DaughterName;};
+        inline std::vector<double> GetExcitationEnergies() {return m_ExcitationEnergies;};
+        inline std::vector<NPL::Nucleus> GetDaughter() {return m_Daughter;};
+        inline NPL::Nucleus GetMother() {return m_Mother;};
+        inline double GetThreshold(){return m_Threshold;};
+    };
+  
+  // All decay Path for a given nuclei, with Branching Ratio
+  class Decay{
+    public:
+      Decay(){};
+      Decay(std::string MotherName,std::string path);
+      Decay(std::string MotherName,NPL::InputParser parser);
+      ~Decay(){};
+
+    public:
+      void ReadConfiguration(std::string MotherName, std::string path);
+      void ReadConfiguration(std::string MotherName, NPL::InputParser parser);
+      bool GenerateEvent(double MEx,double MEK,double MPx,double MPy,double MPz, 
+      std::vector<NPL::Nucleus>& Daughter, std::vector<double>& Ex,
+      std::vector<double>& DEK,
+      std::vector<double>& DPx,std::vector<double>& DPy,std::vector<double>& DPz);
+      bool AnyAboveThreshold(double MEx);
+
+
+     private:
+      std::string m_MotherName;  
+      std::vector<int> m_Shoot;
+      std::vector<NPL::SingleDecay> m_SingleDecay;
+      std::vector<double> m_BranchingRatio;
+      double m_BRTotal;
+    }; 
+ 
+  // All decay read from files
+  class DecayStore{
+    public:
+      DecayStore(){};
+      DecayStore(std::string path);
+      DecayStore(NPL::InputParser parser);
+      ~DecayStore(){};
+    
+     public:
+      void ReadConfiguration(std::string path);
+      void ReadConfiguration(NPL::InputParser parser);
+      std::set<std::string> GetAllMotherName();  
+
+    private:
+      std::map<std::string, NPL::Decay> m_Store;
+  
+    public:
+      void GenerateEvent(std::string MotherName, double MEx,
+        double MEK,double MPx,double MPy,double MPz,
+        std::vector<NPL::Nucleus>& Daughter, std::vector<double>& Ex,
+        std::vector<double>& DEK,
+        std::vector<double>& DPx,std::vector<double>& DPy,std::vector<double>& DPz);
+      bool AnyAboveThreshold(std::string MotherName, double MEx);
+    };
+  }
+#endif
diff --git a/NPLib/Physics/NPFunction.cxx b/NPLib/Physics/NPFunction.cxx
index 71602f164667e633ce7966235034c47924788d89..abdc65f5d030cbba4538f99540224b02a0e4c29b 100644
--- a/NPLib/Physics/NPFunction.cxx
+++ b/NPLib/Physics/NPFunction.cxx
@@ -21,6 +21,7 @@
  *****************************************************************************/
 
 #include "NPFunction.h"
+#include "NPSystemOfUnits.h"
 #include<sstream>
 using namespace NPL;
 
@@ -28,409 +29,428 @@ using namespace NPL;
 #include "TDirectory.h"
 namespace NPL{
 
-// Check the type of Filename (root or ASCII) and extract build/extract a 1D histogramm
-TH1F* Read1DProfile(string filename,string HistName) 
-{  
-  ifstream ASCII;
-  TFile ROOT;
-  TH1F* h;
-  
-  // test whether file format is ASCII or ROOT
-  bool type = OpenASCIIorROOTFile(filename, ASCII , ROOT);
-
-  // ASCII File case
-  if (type) {
-    string LineBuffer;
-    
-    // storing vector
-    vector <double> x, w;
-    
-    // variable buffer
-    double xb, wb;
-    
-    // read the file
-    Double_t xmin =  200;
-    Double_t xmax = -200;
-    int mysize = 0;
-    while (getline(ASCII, LineBuffer)) {
-       stringstream iss(LineBuffer);
-       if (!(iss >> xb >> wb)) {continue;}   // skip comment lines 
-       // fill vectors
-       x.push_back(xb);
-       w.push_back(wb);
-//       cout << xb << "\t" << wb << endl;
-       // compute xmin / xmax / size of x array
-       if (xb > xmax) xmax = xb;
-       if (xb < xmin) xmin = xb;
-       mysize++;
-    }
-    Double_t dx = (xmax - xmin) / (mysize);
-//    cout << xmin << "\t" << xmax << "\t" << mysize << "\t" << dx << endl;
-
-    // fill histo
-    h = new TH1F(HistName.c_str(), HistName.c_str(), mysize, xmin, xmax+dx);
-    for (unsigned int i = 0; i < mysize; i++) {
-      int bin = h->FindBin(x[i]);
-      h->SetBinContent(bin,w[i]);
-//      cout << i << "\t" << x[i] << "\t" << bin << "\t" << w[i] << "\t" << h->GetBinContent(bin) << endl;
-    }
-  }
-  
-  // ROOT File case
-  else{
-    h = (TH1F*) gDirectory->FindObjectAny(HistName.c_str());
-    if(!h){
-      cout << "Error: Histogram " << HistName << " not found in file " << filename << endl;
-      exit(1);
-    }
-  }
-  
-  return h;
-}
+  // Check the type of Filename (root or ASCII) and extract build/extract a 1D histogramm
+  TH1F* Read1DProfile(string filename,string HistName) {  
+    ifstream ASCII;
+    TFile ROOT;
+    TH1F* h;
 
-//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-// Check the type of Filename (root or ASCII) and extract build/extract a 2D histogramm
-TH2F* Read2DProfile(string filename,string HistName){
-  
-  ifstream ASCII;
-  TFile ROOT;
-  TH2F* h;
-  
-  bool type = OpenASCIIorROOTFile(filename, ASCII , ROOT);
-  
-  
-  // ASCII File case
-  if(type){
-    string LineBuffer;
-    
-    // storing vector
-    vector <double> x,y,w;
-    
-    // variable buffer
-    double xb,yb,wb;
-    
-    // Read the file
-    while(!ASCII.eof()){
-      getline(ASCII,LineBuffer);
-      stringstream LineStream(LineBuffer);
-      // ignore comment line
-      if (LineBuffer.compare(0,1,"%")!=0){
-        LineStream >> xb >> yb >> wb ;
+    // test whether file format is ASCII or ROOT
+    bool type = OpenASCIIorROOTFile(filename, ASCII , ROOT);
+
+    // ASCII File case
+    if (type) {
+      string LineBuffer;
+
+      // storing vector
+      vector <double> x, w;
+
+      // variable buffer
+      double xb, wb;
+
+      // read the file
+      Double_t xmin =  200;
+      Double_t xmax = -200;
+      int mysize = 0;
+      while (getline(ASCII, LineBuffer)) {
+        stringstream iss(LineBuffer);
+        if (!(iss >> xb >> wb)) {continue;}   // skip comment lines 
+        // fill vectors
         x.push_back(xb);
-        y.push_back(yb);
         w.push_back(wb);
+        //       cout << xb << "\t" << wb << endl;
+        // compute xmin / xmax / size of x array
+        if (xb > xmax) xmax = xb;
+        if (xb < xmin) xmin = xb;
+        mysize++;
+      }
+      Double_t dx = (xmax - xmin) / (mysize);
+      //    cout << xmin << "\t" << xmax << "\t" << mysize << "\t" << dx << endl;
+
+      // fill histo
+      h = new TH1F(HistName.c_str(), HistName.c_str(), mysize, xmin, xmax+dx);
+      for (unsigned int i = 0; i < mysize; i++) {
+        int bin = h->FindBin(x[i]);
+        h->SetBinContent(bin,w[i]);
+        //      cout << i << "\t" << x[i] << "\t" << bin << "\t" << w[i] << "\t" << h->GetBinContent(bin) << endl;
       }
     }
-    
-    // Look for the step size, min and max of the distribution
-    double xmin = 0;
-    double xmax = 0;
-    unsigned int xsize = x.size();
-    
-    double ymin = 0;
-    double ymax = 0;
-    unsigned int ysize = y.size();
-    
-    if(xsize > 0){
-      xmin = x[0] ;
-      xmax = x[0] ;
-    }
-    
-    if(ysize > 0){
-      ymin = y[0] ;
-      ymax = y[0] ;
-    }
-    
-    for(unsigned int i = 0 ; i < xsize ; i++){
-      if(x[i] > xmax) xmax = x[i] ;
-      if(x[i] < xmin) xmin = x[i] ;
-    }
-    
-    for(unsigned int i = 0 ; i < ysize ; i++){
-      if(y[i] > ymax) ymax = y[i] ;
-      if(y[i] < ymin) ymin = y[i] ;
-    }
-    
-    h = new TH2F(HistName.c_str(),HistName.c_str(),xsize,xmin,xmax,ysize,ymin,ymax);
-    
-    for(unsigned int i = 0 ; i < xsize ; i++){
-      int bin = h->FindBin(x[i],y[i]);
-      h->SetBinContent(bin,w[i]);
+
+    // ROOT File case
+    else{
+      h = (TH1F*) gDirectory->FindObjectAny(HistName.c_str());
+      if(!h){
+        cout << "Error: Histogram " << HistName << " not found in file " << filename << endl;
+        exit(1);
+      }
     }
+
+    return h;
   }
-  
-  // ROOT File case
-  else{
-    h = (TH2F*) gDirectory->FindObjectAny(HistName.c_str());
-    if(!h){
-      cout << "Error: Histogramm " << HistName << " not found in file " << filename << endl;
-      exit(1);
+
+  //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+  // Check the type of Filename (root or ASCII) and extract build/extract a 2D histogramm
+  TH2F* Read2DProfile(string filename,string HistName){
+
+    ifstream ASCII;
+    TFile ROOT;
+    TH2F* h;
+
+    bool type = OpenASCIIorROOTFile(filename, ASCII , ROOT);
+
+
+    // ASCII File case
+    if(type){
+      string LineBuffer;
+
+      // storing vector
+      vector <double> x,y,w;
+
+      // variable buffer
+      double xb,yb,wb;
+
+      // Read the file
+      while(!ASCII.eof()){
+        getline(ASCII,LineBuffer);
+        stringstream LineStream(LineBuffer);
+        // ignore comment line
+        if (LineBuffer.compare(0,1,"%")!=0){
+          LineStream >> xb >> yb >> wb ;
+          x.push_back(xb);
+          y.push_back(yb);
+          w.push_back(wb);
+        }
+      }
+
+      // Look for the step size, min and max of the distribution
+      double xmin = 0;
+      double xmax = 0;
+      unsigned int xsize = x.size();
+
+      double ymin = 0;
+      double ymax = 0;
+      unsigned int ysize = y.size();
+
+      if(xsize > 0){
+        xmin = x[0] ;
+        xmax = x[0] ;
+      }
+
+      if(ysize > 0){
+        ymin = y[0] ;
+        ymax = y[0] ;
+      }
+
+      for(unsigned int i = 0 ; i < xsize ; i++){
+        if(x[i] > xmax) xmax = x[i] ;
+        if(x[i] < xmin) xmin = x[i] ;
+      }
+
+      for(unsigned int i = 0 ; i < ysize ; i++){
+        if(y[i] > ymax) ymax = y[i] ;
+        if(y[i] < ymin) ymin = y[i] ;
+      }
+
+      h = new TH2F(HistName.c_str(),HistName.c_str(),xsize,xmin,xmax,ysize,ymin,ymax);
+
+      for(unsigned int i = 0 ; i < xsize ; i++){
+        int bin = h->FindBin(x[i],y[i]);
+        h->SetBinContent(bin,w[i]);
+      }
     }
-  }
-  return h;
-}
 
-// Open a file at Filename after checking the type of file it is
-// true for a ASCII file
-// False for a Root file
-bool OpenASCIIorROOTFile(string filename, ifstream &ASCII , TFile &ROOT){
-  
-  // look for .root extension
-  size_t pos = filename.find(".root");
-  
-  string GlobalPath = getenv("NPTOOL");
-  string StandardPath = GlobalPath + "/Inputs/CrossSection/" + filename;
-
-  // extension not found, file is assume to be a ASCII file
-  if(pos > filename.size()) {
-    ASCII.open(filename.c_str());
-    
-    if(!ASCII.is_open()){
-      ASCII.open(StandardPath.c_str());
-      if(!ASCII.is_open()){
-        cout << "Error, file " << filename << " not found " << endl ;
+    // ROOT File case
+    else{
+      h = (TH2F*) gDirectory->FindObjectAny(HistName.c_str());
+      if(!h){
+        cout << "Error: Histogramm " << HistName << " not found in file " << filename << endl;
         exit(1);
       }
     }
-    
-    return true;
+    return h;
   }
-  
-  else {
-    if(ROOT.Open(filename.c_str(),"READ")){
-      return false;
+
+  // Open a file at Filename after checking the type of file it is
+  // true for a ASCII file
+  // False for a Root file
+  bool OpenASCIIorROOTFile(string filename, ifstream &ASCII , TFile &ROOT){
+
+    // look for .root extension
+    size_t pos = filename.find(".root");
+
+    string GlobalPath = getenv("NPTOOL");
+    string StandardPath = GlobalPath + "/Inputs/CrossSection/" + filename;
+
+    // extension not found, file is assume to be a ASCII file
+    if(pos > filename.size()) {
+      ASCII.open(filename.c_str());
+
+      if(!ASCII.is_open()){
+        ASCII.open(StandardPath.c_str());
+        if(!ASCII.is_open()){
+          cout << "Error, file " << filename << " not found " << endl ;
+          exit(1);
+        }
+      }
+
+      return true;
     }
-  
-    else{
-      
-      if(ROOT.Open(StandardPath.c_str(),"READ")){
+
+    else {
+      if(ROOT.Open(filename.c_str(),"READ")){
         return false;
       }
+
       else{
-        cout << "Error, file " << StandardPath << " not found " << endl ;
-        exit(1);
+
+        if(ROOT.Open(StandardPath.c_str(),"READ")){
+          return false;
+        }
+        else{
+          cout << "Error, file " << StandardPath << " not found " << endl ;
+          exit(1);
+        }
       }
+
     }
-    
-  }
-  
-}
 
-//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-void RandomGaussian2D(double MeanX, double MeanY, double SigmaX, double SigmaY, double &X, double &Y, double NumberOfSigma)
-{
-  if (SigmaX != 0 && SigmaY!=0) {
-    X = 2 * NumberOfSigma*SigmaX;
-    while (X > NumberOfSigma*SigmaX) X = gRandom->Gaus(MeanX, SigmaX);
-    
-    double a = NumberOfSigma * SigmaX/2;
-    double b = NumberOfSigma * SigmaY/2;
-    double SigmaYPrim = b * sqrt(1 - X*X / (a*a));
-    
-    SigmaYPrim = 2*SigmaYPrim / NumberOfSigma;
-    Y = gRandom->Gaus(MeanY, SigmaYPrim);
-  }
-  
-  else if(SigmaX == 0 && SigmaY!=0) {
-    X = MeanX;
-    Y = gRandom->Gaus(MeanY, SigmaY);
   }
-  
-  else if(SigmaX != 0 && SigmaY==0) {
-    Y = MeanY;
-    X = gRandom->Gaus(MeanX, SigmaX);
-  }
-  
-  else {
-    X = MeanX;
-    Y = MeanY;
+
+  //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+  void RandomGaussian2D(double MeanX, double MeanY, double SigmaX, double SigmaY, double &X, double &Y){
+    if (SigmaX != 0 && SigmaY!=0) {
+      X = gRandom->Gaus(MeanX, SigmaX);
+
+      double a = SigmaX/2.;
+      double b = SigmaY/2.;
+      double SigmaYPrim = b * sqrt(1 - X*X / (a*a));
+      Y = gRandom->Gaus(MeanY, SigmaY);
+    }
+
+    else if(SigmaX == 0 && SigmaY!=0) {
+      X = MeanX;
+      Y = gRandom->Gaus(MeanY, SigmaY);
+    }
+
+    else if(SigmaX != 0 && SigmaY==0) {
+      Y = MeanY;
+      X = gRandom->Gaus(MeanX, SigmaX);
+    }
+
+    else {
+      X = MeanX;
+      Y = MeanY;
+    }
   }
-}
+  //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+  TVector3 HyperbolicProfileCrossing(TVector3 origin,TVector3 direction, double offset, double b, double R){
+  // Check that origin is within range:
+  if(sqrt(origin.X()*origin.X()+origin.Y()*origin.Y())>R)
+    return TVector3(-1000,-1000,-1000);
+
+  direction=direction.Unit();
 
+  // Find crossing point by dichotomy
+  TVector3 Pos= origin;
+  double diff = 1e10;
+  double step = 1*NPUNITS::mm;
+  double r = 0;
+  int count =0;
 
-//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-string ChangeNameToG4Standard(string OriginalName){
-  string NumberOfMass ;
-  string Nucleid;
-  
-  for (unsigned int i = 0; i < OriginalName.length(); i++) {
-    ostringstream character;
-    character << OriginalName[i];
-    if      (character.str()=="0") NumberOfMass+="0";
-    else if (character.str()=="1") NumberOfMass+="1";
-    else if (character.str()=="2") NumberOfMass+="2";
-    else if (character.str()=="3") NumberOfMass+="3";
-    else if (character.str()=="4") NumberOfMass+="4";
-    else if (character.str()=="5") NumberOfMass+="5";
-    else if (character.str()=="6") NumberOfMass+="6";
-    else if (character.str()=="7") NumberOfMass+="7";
-    else if (character.str()=="8") NumberOfMass+="8";
-    else if (character.str()=="9") NumberOfMass+="9";
+  while(abs(diff)>1e-6){
+    // safety check
+    if(count++>1000){
+      cout << " WARNING: Hyperbolic Profile failed to converge in 1000 trial " << endl;
+      return TVector3(-1000,-1000,-1000);
+      }
     
-    else if (character.str()=="A") Nucleid+="A";
-    else if (character.str()=="B") Nucleid+="B";
-    else if (character.str()=="C") Nucleid+="C";
-    else if (character.str()=="D") Nucleid+="D";
-    else if (character.str()=="E") Nucleid+="E";
-    else if (character.str()=="F") Nucleid+="F";
-    else if (character.str()=="G") Nucleid+="G";
-    else if (character.str()=="H") Nucleid+="H";
-    else if (character.str()=="I") Nucleid+="I";
-    else if (character.str()=="J") Nucleid+="J";
-    else if (character.str()=="K") Nucleid+="K";
-    else if (character.str()=="L") Nucleid+="L";
-    else if (character.str()=="M") Nucleid+="M";
-    else if (character.str()=="N") Nucleid+="N";
-    else if (character.str()=="O") Nucleid+="O";
-    else if (character.str()=="P") Nucleid+="P";
-    else if (character.str()=="Q") Nucleid+="Q";
-    else if (character.str()=="R") Nucleid+="R";
-    else if (character.str()=="S") Nucleid+="S";
-    else if (character.str()=="T") Nucleid+="T";
-    else if (character.str()=="U") Nucleid+="U";
-    else if (character.str()=="V") Nucleid+="V";
-    else if (character.str()=="W") Nucleid+="W";
-    else if (character.str()=="X") Nucleid+="X";
-    else if (character.str()=="Y") Nucleid+="Y";
-    else if (character.str()=="Z") Nucleid+="Z";
+    Pos+= step*direction;
+    // The surface is generated by rotation, so the Perp (R in cyl coord.)
+    // is enough to find the Z of the surface at this Position
+    diff= Pos.Z()-HyperbolicProfile(Pos.Perp(),offset,b,R);
     
-    else if (character.str()=="a") Nucleid+="a";
-    else if (character.str()=="b") Nucleid+="b";
-    else if (character.str()=="c") Nucleid+="c";
-    else if (character.str()=="d") Nucleid+="d";
-    else if (character.str()=="e") Nucleid+="e";
-    else if (character.str()=="f") Nucleid+="f";
-    else if (character.str()=="g") Nucleid+="g";
-    else if (character.str()=="h") Nucleid+="h";
-    else if (character.str()=="i") Nucleid+="i";
-    else if (character.str()=="j") Nucleid+="j";
-    else if (character.str()=="k") Nucleid+="k";
-    else if (character.str()=="l") Nucleid+="l";
-    else if (character.str()=="m") Nucleid+="m";
-    else if (character.str()=="n") Nucleid+="n";
-    else if (character.str()=="o") Nucleid+="o";
-    else if (character.str()=="p") Nucleid+="p";
-    else if (character.str()=="q") Nucleid+="q";
-    else if (character.str()=="r") Nucleid+="r";
-    else if (character.str()=="s") Nucleid+="s";
-    else if (character.str()=="t") Nucleid+="t";
-    else if (character.str()=="u") Nucleid+="u";
-    else if (character.str()=="v") Nucleid+="v";
-    else if (character.str()=="w") Nucleid+="w";
-    else if (character.str()=="x") Nucleid+="x";
-    else if (character.str()=="y") Nucleid+="y";
-    else if (character.str()=="z") Nucleid+="z";
+    if(diff>0){
+      Pos-=step*direction;
+      step/=10;
+      }
+   }
+   return Pos; 
+    }
+
+
+  //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+  string ChangeNameToG4Standard(string OriginalName){
+    string NumberOfMass ;
+    string Nucleid;
+
+    for (unsigned int i = 0; i < OriginalName.length(); i++) {
+      ostringstream character;
+      character << OriginalName[i];
+      if      (character.str()=="0") NumberOfMass+="0";
+      else if (character.str()=="1") NumberOfMass+="1";
+      else if (character.str()=="2") NumberOfMass+="2";
+      else if (character.str()=="3") NumberOfMass+="3";
+      else if (character.str()=="4") NumberOfMass+="4";
+      else if (character.str()=="5") NumberOfMass+="5";
+      else if (character.str()=="6") NumberOfMass+="6";
+      else if (character.str()=="7") NumberOfMass+="7";
+      else if (character.str()=="8") NumberOfMass+="8";
+      else if (character.str()=="9") NumberOfMass+="9";
+
+      else if (character.str()=="A") Nucleid+="A";
+      else if (character.str()=="B") Nucleid+="B";
+      else if (character.str()=="C") Nucleid+="C";
+      else if (character.str()=="D") Nucleid+="D";
+      else if (character.str()=="E") Nucleid+="E";
+      else if (character.str()=="F") Nucleid+="F";
+      else if (character.str()=="G") Nucleid+="G";
+      else if (character.str()=="H") Nucleid+="H";
+      else if (character.str()=="I") Nucleid+="I";
+      else if (character.str()=="J") Nucleid+="J";
+      else if (character.str()=="K") Nucleid+="K";
+      else if (character.str()=="L") Nucleid+="L";
+      else if (character.str()=="M") Nucleid+="M";
+      else if (character.str()=="N") Nucleid+="N";
+      else if (character.str()=="O") Nucleid+="O";
+      else if (character.str()=="P") Nucleid+="P";
+      else if (character.str()=="Q") Nucleid+="Q";
+      else if (character.str()=="R") Nucleid+="R";
+      else if (character.str()=="S") Nucleid+="S";
+      else if (character.str()=="T") Nucleid+="T";
+      else if (character.str()=="U") Nucleid+="U";
+      else if (character.str()=="V") Nucleid+="V";
+      else if (character.str()=="W") Nucleid+="W";
+      else if (character.str()=="X") Nucleid+="X";
+      else if (character.str()=="Y") Nucleid+="Y";
+      else if (character.str()=="Z") Nucleid+="Z";
+
+      else if (character.str()=="a") Nucleid+="a";
+      else if (character.str()=="b") Nucleid+="b";
+      else if (character.str()=="c") Nucleid+="c";
+      else if (character.str()=="d") Nucleid+="d";
+      else if (character.str()=="e") Nucleid+="e";
+      else if (character.str()=="f") Nucleid+="f";
+      else if (character.str()=="g") Nucleid+="g";
+      else if (character.str()=="h") Nucleid+="h";
+      else if (character.str()=="i") Nucleid+="i";
+      else if (character.str()=="j") Nucleid+="j";
+      else if (character.str()=="k") Nucleid+="k";
+      else if (character.str()=="l") Nucleid+="l";
+      else if (character.str()=="m") Nucleid+="m";
+      else if (character.str()=="n") Nucleid+="n";
+      else if (character.str()=="o") Nucleid+="o";
+      else if (character.str()=="p") Nucleid+="p";
+      else if (character.str()=="q") Nucleid+="q";
+      else if (character.str()=="r") Nucleid+="r";
+      else if (character.str()=="s") Nucleid+="s";
+      else if (character.str()=="t") Nucleid+="t";
+      else if (character.str()=="u") Nucleid+="u";
+      else if (character.str()=="v") Nucleid+="v";
+      else if (character.str()=="w") Nucleid+="w";
+      else if (character.str()=="x") Nucleid+="x";
+      else if (character.str()=="y") Nucleid+="y";
+      else if (character.str()=="z") Nucleid+="z";
+    }
+
+    // Special case for light particles
+    string FinalName=Nucleid+NumberOfMass;
+    if      (FinalName=="H1")       FinalName="proton";
+    else if (FinalName=="H2")       FinalName="deuteron";
+    else if (FinalName=="H3")       FinalName="triton";
+    else if (FinalName=="He4")      FinalName="alpha";
+    else if (FinalName=="p")        FinalName="proton";
+    else if (FinalName=="d")        FinalName="deuteron";
+    else if (FinalName=="t")        FinalName="triton";
+    else if (FinalName=="a")        FinalName="alpha";
+    else if (FinalName=="n")        FinalName="neutron";
+    return(FinalName);
   }
-  
-  // Special case for light particles
-  string FinalName=Nucleid+NumberOfMass;
-  if      (FinalName=="H1")       FinalName="proton";
-  else if (FinalName=="H2")       FinalName="deuteron";
-  else if (FinalName=="H3")       FinalName="triton";
-  else if (FinalName=="He4")      FinalName="alpha";
-  else if (FinalName=="p")        FinalName="proton";
-  else if (FinalName=="d")        FinalName="deuteron";
-  else if (FinalName=="t")        FinalName="triton";
-  else if (FinalName=="a")        FinalName="alpha";
-  else if (FinalName=="proton")   FinalName="proton";
-  else if (FinalName=="deuteron") FinalName="deuteron";
-  else if (FinalName=="triton")   FinalName="triton";
-  else if (FinalName=="alpha")    FinalName="alpha";
-  else if (FinalName=="n")        FinalName="neutron";
-  else if (FinalName=="neutron")  FinalName="neutron";
-  return(FinalName);
-}
 
-//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-string ChangeNameFromG4Standard(string OriginalName){
-  string NumberOfMass ;
-  string Nucleid;
-  
-  for (unsigned int i = 0; i < OriginalName.length(); i++) {
-    ostringstream character;
-    character << OriginalName[i];
-    if      (character.str()=="0") NumberOfMass+="0";
-    else if (character.str()=="1") NumberOfMass+="1";
-    else if (character.str()=="2") NumberOfMass+="2";
-    else if (character.str()=="3") NumberOfMass+="3";
-    else if (character.str()=="4") NumberOfMass+="4";
-    else if (character.str()=="5") NumberOfMass+="5";
-    else if (character.str()=="6") NumberOfMass+="6";
-    else if (character.str()=="7") NumberOfMass+="7";
-    else if (character.str()=="8") NumberOfMass+="8";
-    else if (character.str()=="9") NumberOfMass+="9";
-    
-    else if (character.str()=="A") Nucleid+="A";
-    else if (character.str()=="B") Nucleid+="B";
-    else if (character.str()=="C") Nucleid+="C";
-    else if (character.str()=="D") Nucleid+="D";
-    else if (character.str()=="E") Nucleid+="E";
-    else if (character.str()=="F") Nucleid+="F";
-    else if (character.str()=="G") Nucleid+="G";
-    else if (character.str()=="H") Nucleid+="H";
-    else if (character.str()=="I") Nucleid+="I";
-    else if (character.str()=="J") Nucleid+="J";
-    else if (character.str()=="K") Nucleid+="K";
-    else if (character.str()=="L") Nucleid+="L";
-    else if (character.str()=="M") Nucleid+="M";
-    else if (character.str()=="N") Nucleid+="N";
-    else if (character.str()=="O") Nucleid+="O";
-    else if (character.str()=="P") Nucleid+="P";
-    else if (character.str()=="Q") Nucleid+="Q";
-    else if (character.str()=="R") Nucleid+="R";
-    else if (character.str()=="S") Nucleid+="S";
-    else if (character.str()=="T") Nucleid+="T";
-    else if (character.str()=="U") Nucleid+="U";
-    else if (character.str()=="V") Nucleid+="V";
-    else if (character.str()=="W") Nucleid+="W";
-    else if (character.str()=="X") Nucleid+="X";
-    else if (character.str()=="Y") Nucleid+="Y";
-    else if (character.str()=="Z") Nucleid+="Z";
-    
-    else if (character.str()=="a") Nucleid+="a";
-    else if (character.str()=="b") Nucleid+="b";
-    else if (character.str()=="c") Nucleid+="c";
-    else if (character.str()=="d") Nucleid+="d";
-    else if (character.str()=="e") Nucleid+="e";
-    else if (character.str()=="f") Nucleid+="f";
-    else if (character.str()=="g") Nucleid+="g";
-    else if (character.str()=="h") Nucleid+="h";
-    else if (character.str()=="i") Nucleid+="i";
-    else if (character.str()=="j") Nucleid+="j";
-    else if (character.str()=="k") Nucleid+="k";
-    else if (character.str()=="l") Nucleid+="l";
-    else if (character.str()=="m") Nucleid+="m";
-    else if (character.str()=="n") Nucleid+="n";
-    else if (character.str()=="o") Nucleid+="o";
-    else if (character.str()=="p") Nucleid+="p";
-    else if (character.str()=="q") Nucleid+="q";
-    else if (character.str()=="r") Nucleid+="r";
-    else if (character.str()=="s") Nucleid+="s";
-    else if (character.str()=="t") Nucleid+="t";
-    else if (character.str()=="u") Nucleid+="u";
-    else if (character.str()=="v") Nucleid+="v";
-    else if (character.str()=="w") Nucleid+="w";
-    else if (character.str()=="x") Nucleid+="x";
-    else if (character.str()=="y") Nucleid+="y";
-    else if (character.str()=="z") Nucleid+="z";
+  //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+  string ChangeNameFromG4Standard(string OriginalName){
+    string NumberOfMass ;
+    string Nucleid;
+
+    for (unsigned int i = 0; i < OriginalName.length(); i++) {
+      ostringstream character;
+      character << OriginalName[i];
+      if      (character.str()=="0") NumberOfMass+="0";
+      else if (character.str()=="1") NumberOfMass+="1";
+      else if (character.str()=="2") NumberOfMass+="2";
+      else if (character.str()=="3") NumberOfMass+="3";
+      else if (character.str()=="4") NumberOfMass+="4";
+      else if (character.str()=="5") NumberOfMass+="5";
+      else if (character.str()=="6") NumberOfMass+="6";
+      else if (character.str()=="7") NumberOfMass+="7";
+      else if (character.str()=="8") NumberOfMass+="8";
+      else if (character.str()=="9") NumberOfMass+="9";
+
+      else if (character.str()=="A") Nucleid+="A";
+      else if (character.str()=="B") Nucleid+="B";
+      else if (character.str()=="C") Nucleid+="C";
+      else if (character.str()=="D") Nucleid+="D";
+      else if (character.str()=="E") Nucleid+="E";
+      else if (character.str()=="F") Nucleid+="F";
+      else if (character.str()=="G") Nucleid+="G";
+      else if (character.str()=="H") Nucleid+="H";
+      else if (character.str()=="I") Nucleid+="I";
+      else if (character.str()=="J") Nucleid+="J";
+      else if (character.str()=="K") Nucleid+="K";
+      else if (character.str()=="L") Nucleid+="L";
+      else if (character.str()=="M") Nucleid+="M";
+      else if (character.str()=="N") Nucleid+="N";
+      else if (character.str()=="O") Nucleid+="O";
+      else if (character.str()=="P") Nucleid+="P";
+      else if (character.str()=="Q") Nucleid+="Q";
+      else if (character.str()=="R") Nucleid+="R";
+      else if (character.str()=="S") Nucleid+="S";
+      else if (character.str()=="T") Nucleid+="T";
+      else if (character.str()=="U") Nucleid+="U";
+      else if (character.str()=="V") Nucleid+="V";
+      else if (character.str()=="W") Nucleid+="W";
+      else if (character.str()=="X") Nucleid+="X";
+      else if (character.str()=="Y") Nucleid+="Y";
+      else if (character.str()=="Z") Nucleid+="Z";
+
+      else if (character.str()=="a") Nucleid+="a";
+      else if (character.str()=="b") Nucleid+="b";
+      else if (character.str()=="c") Nucleid+="c";
+      else if (character.str()=="d") Nucleid+="d";
+      else if (character.str()=="e") Nucleid+="e";
+      else if (character.str()=="f") Nucleid+="f";
+      else if (character.str()=="g") Nucleid+="g";
+      else if (character.str()=="h") Nucleid+="h";
+      else if (character.str()=="i") Nucleid+="i";
+      else if (character.str()=="j") Nucleid+="j";
+      else if (character.str()=="k") Nucleid+="k";
+      else if (character.str()=="l") Nucleid+="l";
+      else if (character.str()=="m") Nucleid+="m";
+      else if (character.str()=="n") Nucleid+="n";
+      else if (character.str()=="o") Nucleid+="o";
+      else if (character.str()=="p") Nucleid+="p";
+      else if (character.str()=="q") Nucleid+="q";
+      else if (character.str()=="r") Nucleid+="r";
+      else if (character.str()=="s") Nucleid+="s";
+      else if (character.str()=="t") Nucleid+="t";
+      else if (character.str()=="u") Nucleid+="u";
+      else if (character.str()=="v") Nucleid+="v";
+      else if (character.str()=="w") Nucleid+="w";
+      else if (character.str()=="x") Nucleid+="x";
+      else if (character.str()=="y") Nucleid+="y";
+      else if (character.str()=="z") Nucleid+="z";
+    }
+
+    // Special case for light particles
+    string FinalName=NumberOfMass+Nucleid;
+    if      (FinalName=="H1")       FinalName="proton";
+    else if (FinalName=="H2")       FinalName="deuteron";
+    else if (FinalName=="H3")       FinalName="triton";
+    else if (FinalName=="He4")      FinalName="alpha";
+    else if (FinalName=="p")        FinalName="proton";
+    else if (FinalName=="d")        FinalName="deuteron";
+    else if (FinalName=="t")        FinalName="triton";
+    else if (FinalName=="a")        FinalName="alpha";
+    else if (FinalName=="n")        FinalName="neutron";
+    return(FinalName);
   }
-  
-  // Special case for light particles
-  string FinalName=NumberOfMass+Nucleid;
-  if      (FinalName=="H1")       FinalName="proton";
-  else if (FinalName=="H2")       FinalName="deuteron";
-  else if (FinalName=="H3")       FinalName="triton";
-  else if (FinalName=="He4")      FinalName="alpha";
-  else if (FinalName=="p")        FinalName="proton";
-  else if (FinalName=="d")        FinalName="deuteron";
-  else if (FinalName=="t")        FinalName="triton";
-  else if (FinalName=="a")        FinalName="alpha";
-  else if (FinalName=="proton")   FinalName="proton";
-  else if (FinalName=="deuteron") FinalName="deuteron";
-  else if (FinalName=="triton")   FinalName="triton";
-  else if (FinalName=="alpha")    FinalName="alpha";
-  else if (FinalName=="n")        FinalName="neutron";
-  else if (FinalName=="neutron")  FinalName="neutron";
-  return(FinalName);
-}
 }
diff --git a/NPLib/Physics/NPFunction.h b/NPLib/Physics/NPFunction.h
index a9fc43fde32def47b053120998a9a99173fc8f48..b6373860d8c04d2559877846e4b025ac0fbc1099 100644
--- a/NPLib/Physics/NPFunction.h
+++ b/NPLib/Physics/NPFunction.h
@@ -39,6 +39,7 @@ using namespace std;
 #include "TFile.h"
 #include "TRandom.h"
 #include "TRandom2.h"
+#include "TVector3.h"
 
 namespace NPL{
 
@@ -54,11 +55,17 @@ namespace NPL{
   // False for a Root file
   bool OpenASCIIorROOTFile(string filename, ifstream &ASCII , TFile &ROOT);
   
-  void RandomGaussian2D(double MeanX, double MeanY, double SigmaX, double SigmaY, double &X, double &Y, double NumberOfSigma= 10000);
+  void RandomGaussian2D(double MeanX, double MeanY, double SigmaX, double SigmaY, double &X, double &Y);
   
   // Change nucleus name from G4 standard to Physics standard (11Li vs Li11)
   string ChangeNameToG4Standard(string name);
   string ChangeNameFromG4Standard(string name);
+
+  // Hyperbolic shape generator for cryogenic target deformation
+  inline double HyperbolicProfile(double x, double offset, double b, double R) {return (offset+b+1)- cosh(x/(R/acosh(b+1)));}
+  // Crossing point between a TVector3 direction and an Hyperbolic Profile
+  TVector3 HyperbolicProfileCrossing(TVector3 origin,TVector3 direction, double offset, double b, double R);
+
 }
 
 #endif
diff --git a/NPLib/Physics/NPNucleus.cxx b/NPLib/Physics/NPNucleus.cxx
index b8e740f86e0e396dcffab160b40e7f10bf2c554c..52b092588e45a21050eb0aeef1babd430a495360 100644
--- a/NPLib/Physics/NPNucleus.cxx
+++ b/NPLib/Physics/NPNucleus.cxx
@@ -12,7 +12,7 @@
  * Last update    : may 2012 morfouac@ipno.in2p3.fr                          *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
- *  This class manage a nucleus, data are read in the nubtab03.asc file      *
+ *  This class manage a nucleus, data are read in the nubtab12.asc file      *
  *                                                                           *
  *---------------------------------------------------------------------------*
  * Comment:                                                                  *
@@ -24,16 +24,7 @@
 // NPTOOL headers
 #include "NPNucleus.h"
 using namespace NPL;
-//#include "Constant.h"
 
-// Use CLHEP System of unit and Physical Constant
-//#include "CLHEP/Units/GlobalSystemOfUnits.h"
-//#include "CLHEP/Units/PhysicalConstants.h"
-#include "NPGlobalSystemOfUnits.h"
-#include "NPPhysicalConstants.h"
-#ifdef NP_SYSTEM_OF_UNITS_H
-using namespace NPUNITS;
-#endif
 
 // C++ headers
 #include <iostream>
@@ -54,6 +45,7 @@ Nucleus::Nucleus(){
   fCharge= 0;
   fAtomicWeight= 0;
   fMassExcess= 0;
+  fExcitationEnergy=0;
   fSpinParity= "";
   fSpin= 0;
   fParity= "";
@@ -66,15 +58,19 @@ Nucleus::Nucleus(string isotope){
 }
 
 void Nucleus::SetUp(string isotope){
-  //----------- Constructor Using nubtab03.asc by name----------
+  //----------- Constructor Using nubtab12.asc by name----------
   // open the file to read and check if it is open
-
-  // Replace the p,d,t,a by there standard name:
+  fExcitationEnergy=0; 
+  // Replace the n,p,d,t,a by there standard name:
   if(isotope=="p") isotope="1H";
 	else if(isotope=="n") isotope="1n";
   else if(isotope=="d") isotope="2H";
   else if(isotope=="t") isotope="3H";
   else if(isotope=="a") isotope="4He";
+  else if(isotope=="n") isotope="1n";
+  else if(isotope=="neutron") isotope="1n";
+  else if(isotope=="g") isotope="gamma";
+  else if(isotope=="gamma") isotope="gamma";
 	else if(isotope=="4n"){ // tetraneutron @Eres = 0
 		string line = "004 0000   4n      32285.268   0.0005                       219.4    ys 0.6    1/2+          00 02PaDGt   B-=100";
 		Extract(line.data());
@@ -83,7 +79,7 @@ void Nucleus::SetUp(string isotope){
 	
   ifstream inFile;
   string Path = getenv("NPTOOL") ;
-  string FileName = Path + "/NPLib/Physics/nubtab03.asc";
+  string FileName = Path + "/NPLib/Physics/nubtab12.asc";
   inFile.open(FileName.c_str());
 
   // reading the file
@@ -109,7 +105,7 @@ void Nucleus::SetUp(string isotope){
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 
 Nucleus::Nucleus(int Z, int A)
 {
-  //----------- Constructor Using nubtab03.asc by Z and A----------
+  //----------- Constructor Using nubtab12.asc by Z and A----------
 
 	if(Z==0 && A==4){
 		SetUp("4n");
@@ -118,7 +114,7 @@ Nucleus::Nucleus(int Z, int A)
   // open the file to read and check if it is open
   ifstream inFile;
   string Path = getenv("NPTOOL") ;
-  string FileName = Path + "/NPLib/Physics/nubtab03.asc";
+  string FileName = Path + "/NPLib/Physics/nubtab12.asc";
   inFile.open(FileName.c_str());
 
   // reading the file
@@ -219,9 +215,6 @@ void Nucleus::Extract(string line){
   fSpinParity = s_spinparity.data();
   size_t found_p = s_spinparity.find("+");
   size_t found_m = s_spinparity.find("-");
-  //   size_t found_( = s_jpi.find("(");
-  //   size_t found_) = s_jpi.find(")");
-  //   size_t found_# = s_jpi.find("#");
   // parity
   if (found_p != string::npos) fParity = "+";
   if (found_m != string::npos) fParity = "-";
diff --git a/NPLib/Physics/NPNucleus.h b/NPLib/Physics/NPNucleus.h
index 18bf35d0ef4bfc00ecf01047aa65309474899946..58373c56b48923109d4f57a26e8acbe14c2f0bc6 100644
--- a/NPLib/Physics/NPNucleus.h
+++ b/NPLib/Physics/NPNucleus.h
@@ -28,14 +28,20 @@
 // NPTOOL headers
 #include "NPGlobalSystemOfUnits.h"
 #include "NPPhysicalConstants.h"
+
 #ifdef NP_SYSTEM_OF_UNITS_H
 using namespace NPUNITS;
 #endif
 
+#ifdef HEP_PHYSICAL_CONSTANTS_H
+using namespace CLHEP;
+#endif
+
 // C++ headers
 #include <string>
 using namespace std;
 
+#include <iostream>
 namespace NPL {
   class Nucleus {
     
@@ -50,16 +56,16 @@ namespace NPL {
     
   private :
     //intrinsic properties
-    string      fName;         // Nucleus name
-    string	    fNucleusName;
-    int         fCharge;       // Nucleus charge
-    int         fAtomicWeight; // Nucleus atomic weight
-    double      fMassExcess;   // Nucleus mass excess in keV
-    string      fSpinParity;   // Nucleus spin and parity
-    double      fSpin;         // Nucleus spin
-    string      fParity;       // Nucleus parity
-    double      fLifeTime;     // life time
-
+    string fName;         // Nucleus name
+    string fNucleusName;
+    int    fCharge;       // Nucleus charge
+    int    fAtomicWeight; // Nucleus atomic weight
+    double fMassExcess;   // Nucleus mass excess in keV
+    string fSpinParity;   // Nucleus spin and parity
+    double fSpin;         // Nucleus spin
+    string fParity;       // Nucleus parity
+    double fLifeTime;     // life time
+    double fExcitationEnergy; // Excitation Energy
     //kinematic properties
     double fKineticEnergy;
     double fBeta;
@@ -102,18 +108,19 @@ namespace NPL {
     double			GetBeta()			    const		{return fBeta;}
     double			GetGamma()			  const		{return fGamma;}
     double			GetVelocity()	   	const		{return fVelocity;}
-    TLorentzVector	GetEnergyImpulsion() const				{return fEnergyImpulsion;}
-    void				SetName(const char* name)				{fName = name;}
-    void				SetZ(int charge)						{fCharge = charge;}
-    void				SetA(int mass)							{fAtomicWeight = mass;}
-    void				SetMassExcess(double massexcess)		{fMassExcess = massexcess;}
+    TLorentzVector	GetEnergyImpulsion() const {return fEnergyImpulsion;}
+    double      GetExcitationEnergy() const {return fExcitationEnergy;}
+    void				SetName(const char* name)	{fName = name;}
+    void				SetZ(int charge)					{fCharge = charge;}
+    void				SetA(int mass)						{fAtomicWeight = mass;}
+    void				SetMassExcess(double massexcess) {fMassExcess = massexcess;}
     void				SetSpinParity(const char* spinparity)	{fSpinParity = spinparity;}
-    void				SetSpin(double spin)					{fSpin = spin;}
-    void				SetParity(const char* parity)			{fParity = parity;}
+    void				SetSpin(double spin) {fSpin = spin;}
+    void				SetParity(const char* parity)	{fParity = parity;}
     void        SetLifeTime(double LifeTime) {fLifeTime=LifeTime;}
-    void				SetKineticEnergy(double energy)			{fKineticEnergy = energy; EnergyToBrho(); EnergyToTof(); EnergyToBeta(); BetaToGamma();BetaToVelocity();}
-    void				SetBrho(double brho)					{fBrho = brho; BrhoToEnergy(); BrhoToTof(); EnergyToBeta(); BetaToGamma();BetaToVelocity();}
-    void				SetTimeOfFlight(double tof)				{fTimeOfFlight = tof; TofToEnergy(); TofToBrho(); EnergyToBeta(); BetaToGamma();BetaToVelocity();}
+    void				SetKineticEnergy(double energy)	{fKineticEnergy = energy; EnergyToBrho(); EnergyToTof(); EnergyToBeta(); BetaToGamma();BetaToVelocity();}
+    void				SetBrho(double brho) {fBrho = brho; BrhoToEnergy(); BrhoToTof(); EnergyToBeta(); BetaToGamma();BetaToVelocity();}
+    void				SetTimeOfFlight(double tof) {fTimeOfFlight = tof; TofToEnergy(); TofToBrho(); EnergyToBeta(); BetaToGamma();BetaToVelocity();}
     void				SetEnergyImpulsion(TLorentzVector P) 	{fEnergyImpulsion = P;
       fKineticEnergy = P.E() - Mass();
       EnergyToBrho();
@@ -121,12 +128,13 @@ namespace NPL {
       EnergyToBeta();
       BetaToGamma();
       BetaToVelocity();}
+    void SetExcitationEnergy(double Ex) {fExcitationEnergy=Ex;}
     void				SetBeta(double beta)					{fBeta = beta; BetaToGamma(); BetaToEnergy(); EnergyToTof(); EnergyToBrho();BetaToVelocity();}
       double GetEnergyCM(double EnergyLab, double ThetaLab, double PhiLab, double relativisticboost);
       double GetThetaCM(double EnergyLab, double ThetaLab, double PhiLab, double relativisticboost);
     
     // Nuclear mass in MeV
-    double      Mass() const {return (fAtomicWeight*amu_c2 + fMassExcess/1000. - fCharge*electron_mass_c2);}
+    double      Mass() const {return (fAtomicWeight*amu_c2 + fMassExcess/1000. - fCharge*electron_mass_c2+fExcitationEnergy);}
       double GetBindingEnergy() const {return (fCharge*proton_mass_c2 + (fAtomicWeight-fCharge)*neutron_mass_c2 + fCharge*electron_mass_c2 - fAtomicWeight*amu_c2 - fMassExcess/1000);}
     void        Print() const   ;
   };
diff --git a/NPLib/Physics/NPPhysicsLinkDef.h b/NPLib/Physics/NPPhysicsLinkDef.h
index 7f7bb77816c1424f53d2fb4cd94b851cbd8b9975..4b4ace982dd68c055180e2d0a7e3b23a36145313 100644
--- a/NPLib/Physics/NPPhysicsLinkDef.h
+++ b/NPLib/Physics/NPPhysicsLinkDef.h
@@ -3,4 +3,5 @@
 #pragma link C++ defined_in "./NPBeam.h";
 #pragma link C++ defined_in "./NPNucleus.h";
 #pragma link C++ defined_in "./NPEnergyLoss.h";
+#pragma link C++ defined_in "./NPDecay.h";  
 #endif
diff --git a/NPLib/Physics/NPReaction.cxx b/NPLib/Physics/NPReaction.cxx
index 3af75e2aa6442491dd6e337aa49983efba1d3c86..08c7786698bc3ab31e12953803f84ef9f21a4555 100644
--- a/NPLib/Physics/NPReaction.cxx
+++ b/NPLib/Physics/NPReaction.cxx
@@ -217,8 +217,20 @@ double Reaction::ShootRandomThetaCM(){
     theta = EnergyLabToThetaCM(energylab, thetalab); //transform to theta CM
     SetThetaCM( theta );
   }
-  else
-    SetThetaCM( theta=fCrossSectionHist->GetRandom()*deg );
+  else{
+    // When root perform a Spline interpolation to shoot random number out of 
+    // the distribution, it can over shoot and output a number larger that 180
+    // this lead to an additional signal at 0-4 deg Lab, especially when using a 
+    // flat distribution.
+    // This fix it.
+    theta=181;
+    if(theta/deg>180)
+      theta=fCrossSectionHist->GetRandom();
+
+    SetThetaCM( theta*deg );
+    }
+   
+    
   return theta;
 }
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -234,14 +246,12 @@ void Reaction::KineRelativistic(double& ThetaLab3, double& KineticEnergyLab3,
   // 2-body relativistic kinematics: direct + inverse
   // EnergieLab3,4 : lab energy in MeV of the 2 ejectiles
   // ThetaLab3,4   : angles in rad
-
   // case of inverse kinematics
   double theta = fThetaCM;
   if (m1 > m2) theta = M_PI - fThetaCM;
-
   fEnergyImpulsionCM_3	= TLorentzVector(pCM_3*sin(theta),0,pCM_3*cos(theta),ECM_3);
   fEnergyImpulsionCM_4	= fTotalEnergyImpulsionCM - fEnergyImpulsionCM_3;
-
+  
   fEnergyImpulsionLab_3 = fEnergyImpulsionCM_3;
   fEnergyImpulsionLab_3.Boost(0,0,BetaCM);
   fEnergyImpulsionLab_4 = fEnergyImpulsionCM_4;
@@ -259,10 +269,10 @@ void Reaction::KineRelativistic(double& ThetaLab3, double& KineticEnergyLab3,
   // Kinetic Energy in the lab frame
   KineticEnergyLab3 = fEnergyImpulsionLab_3.E() - m3;
   KineticEnergyLab4 = fEnergyImpulsionLab_4.E() - m4;
-
+  
   // test for total energy conversion
-  if (fabs(fTotalEnergyImpulsionLab.E() - (fEnergyImpulsionLab_3.E()+fEnergyImpulsionLab_4.E())) > 1e-6)
-    cout << "Problem for energy conservation" << endl;
+  //if (fabs(fTotalEnergyImpulsionLab.E() - (fEnergyImpulsionLab_3.E()+fEnergyImpulsionLab_4.E())) > 1e-6)
+  //  cout << "Problem for energy conservation" << endl;
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -720,3 +730,16 @@ void Reaction::SetCSAngle(double CSHalfOpenAngleMin,double CSHalfOpenAngleMax){
         fCrossSectionHist->SetBinContent(i,0);
   }
 }
+
+///////////////////////////////////////////////////////////////////////////////
+// Check whenever the reaction is allowed at the given energy
+bool Reaction::IsAllowed(double Energy){
+  double AvailableEnergy = Energy + fNuclei1.Mass() + fNuclei2.Mass();
+  double RequiredEnergy  = fNuclei3.Mass() + fNuclei4.Mass();
+
+  if(AvailableEnergy>RequiredEnergy)
+    return true;
+  else
+    return false; 
+  }
+      
diff --git a/NPLib/Physics/NPReaction.h b/NPLib/Physics/NPReaction.h
index 7890663af2dff479a8e3069e045d562494bdaba8..91663ecce5e2f684eadd7099adc2eb557bf9e5ab 100644
--- a/NPLib/Physics/NPReaction.h
+++ b/NPLib/Physics/NPReaction.h
@@ -215,6 +215,9 @@ namespace NPL{
       // This uses the fExcitation4 and fQValue both set previously
       double EnergyLabFromThetaLab(double ThetaLab); 
 
+      // Check whenever the reaction is allowed at the given energy
+      bool IsAllowed(double Energy);
+      
       void SetNuclei3(double EnergyLab, double ThetaLab);
 
       TGraph* GetKinematicLine3(double AngleStep_CM=1);
diff --git a/NPLib/Physics/TReactionConditions.cxx b/NPLib/Physics/TReactionConditions.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..a7232682aff34cd76289d147e1da34d7cf18b588
--- /dev/null
+++ b/NPLib/Physics/TReactionConditions.cxx
@@ -0,0 +1,112 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2016    this file is part of the NPTool Project        *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Pierre Morfouace  contact address: morfouace@ganil.fr    *
+ *                                                                           *
+ * Creation Date  : 17/07/18                                                 *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription: This class records all the information concerning the beam    *
+ *             rwaction generators, e.g. vertex of interaction, angles of    *
+ *             emitted particles...                                          *
+ *             This class derives from TObject (ROOT) and its aim is to be   *
+ *             stored in the output TTree of the G4 simulation               *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+
+#include <iostream>
+using namespace std;
+
+#include "TReactionConditions.h"
+
+ClassImp(TReactionConditions)
+////////////////////////////////////////////////////////////////////////////////
+TReactionConditions::TReactionConditions(){
+}
+////////////////////////////////////////////////////////////////////////////////
+TReactionConditions::~TReactionConditions(){
+}
+////////////////////////////////////////////////////////////////////////////////
+void TReactionConditions::Clear(){
+    // Beam beam parameter
+    fRC_Beam_Particle_Name.clear();
+    fRC_Beam_Emittance_ThetaX = -1;
+    fRC_Beam_Emittance_PhiY = -1;
+    fRC_Beam_Emittance_Theta = -1;
+    fRC_Beam_Emittance_Phi = -1;
+    fRC_Beam_Reaction_Energy = -1;
+
+    fRC_Vertex_Position_X = -1;
+    fRC_Vertex_Position_Y = -1;
+    fRC_Vertex_Position_Z = -1;
+    
+    fRC_ThetaCM = -1;
+    
+    // emmitted particles
+    fRC_Particle_Name.clear();
+    fRC_Theta.clear();
+    fRC_Kinetic_Energy.clear();
+    fRC_Momentum_Direction_X.clear();
+    fRC_Momentum_Direction_Y.clear();
+    fRC_Momentum_Direction_Z.clear();
+    
+}
+////////////////////////////////////////////////////////////////////////////////
+void TReactionConditions::Dump() const{
+    cout << "--------- Initial Condition Dump ---------" << endl ;
+    
+    // Beam beam parameter
+    cout << "\t ---- Beam Beam ---- " << endl;
+    cout << "\t Particle Name:  " << fRC_Beam_Particle_Name << endl;
+    cout << "\t Reaction Energy: " << fRC_Beam_Reaction_Energy << endl;
+    cout << "\t Theta_X: " << fRC_Beam_Emittance_ThetaX << endl;
+    cout << "\t Phi_Y: " << fRC_Beam_Emittance_PhiY << endl;
+    cout << "\t Theta: " << fRC_Beam_Emittance_Theta << endl;
+    cout << "\t Phi: " << fRC_Beam_Emittance_Phi << endl;
+    
+    
+    // Beam status at the initial interaction point
+    cout << "\t ---- Interaction Point ---- " << endl;
+    cout << "\t Energy: " << fRC_Beam_Reaction_Energy << endl;
+    cout << "\t ThetaCM: " << fRC_ThetaCM << endl;
+    cout << "\t Position: ( "
+    << fRC_Vertex_Position_X << " ; "
+    << fRC_Vertex_Position_Y << " ; "
+    << fRC_Vertex_Position_Z << ")" << endl;
+    
+    // emmitted particle
+    unsigned int size = fRC_Particle_Name.size();
+    for(unsigned int i = 0 ; i < size; i ++){
+        cout << "\t ---- Particle " << i << " ---- " << endl;
+        cout << "\t Particle Name" <<   fRC_Particle_Name[i] << endl;
+        cout << "\t Energy" <<   fRC_Kinetic_Energy[i] << endl;
+        cout << "\t Momentum Direction: ( "
+        << fRC_Momentum_Direction_X[i] << " ; "
+        << fRC_Momentum_Direction_Y[i] << " ; "
+        << fRC_Momentum_Direction_Z[i] << ")" << endl;
+    }
+
+    
+   
+}
+////////////////////////////////////////////////////////////////////////////////
+TVector3 TReactionConditions::GetBeamDirection() const{
+    return TVector3( sin(fRC_Beam_Emittance_Theta*deg)*cos(fRC_Beam_Emittance_Phi*deg),
+                    sin(fRC_Beam_Emittance_Theta*deg)*sin(fRC_Beam_Emittance_Phi*deg),
+                    cos(fRC_Beam_Emittance_Theta*deg));
+}
+////////////////////////////////////////////////////////////////////////////////
+TVector3 TReactionConditions::GetParticleDirection (const int &i) const {
+    return TVector3(  fRC_Momentum_Direction_X[i],
+                    fRC_Momentum_Direction_Y[i],
+                    fRC_Momentum_Direction_Z[i]);
+}
+
diff --git a/NPLib/Physics/TReactionConditions.h b/NPLib/Physics/TReactionConditions.h
new file mode 100644
index 0000000000000000000000000000000000000000..2a6769cce08f98cce779071ebe50851f66adf6a8
--- /dev/null
+++ b/NPLib/Physics/TReactionConditions.h
@@ -0,0 +1,142 @@
+#ifndef TREACTIONCONDITIONS_H
+#define TREACTIONCONDITIONS_H
+/*****************************************************************************
+ * Copyright (C) 2009-2016    this file is part of the NPTool Project        *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Pierre Morfouace  contact address: morfouace@ganil.fr    *
+ *                                                                           *
+ * Creation Date  : 17/07/18                                                 *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription: This class records all the information concerning the beam    *
+ *             rwaction generators, e.g. vertex of interaction, angles of    *
+ *             emitted particles...                                          *
+ *             This class derives from TObject (ROOT) and its aim is to be   *
+ *             stored in the output TTree of the G4 simulation               *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+
+
+
+// STL Header
+#include <vector>
+#include <string>
+#include <cmath>
+using namespace std ;
+
+// Root Header
+#include "TObject.h"
+#include "TVector3.h"
+
+// NPTOOL headers
+#include "NPGlobalSystemOfUnits.h"
+#include "NPPhysicalConstants.h"
+#ifdef NP_SYSTEM_OF_UNITS_H
+using namespace NPUNITS;
+#endif
+
+class TReactionConditions : public TObject{
+private:
+    
+    // Beam beam parameter
+    string fRC_Beam_Particle_Name;
+    double fRC_Beam_Emittance_ThetaX;
+    double fRC_Beam_Emittance_PhiY;
+    double fRC_Beam_Emittance_Theta;
+    double fRC_Beam_Emittance_Phi;
+    double fRC_Beam_Reaction_Energy;
+    double fRC_Vertex_Position_X;
+    double fRC_Vertex_Position_Y;
+    double fRC_Vertex_Position_Z;
+    
+    double fRC_ThetaCM;
+    // emmitted particles
+    vector<string> fRC_Particle_Name;
+    vector<double> fRC_Theta;
+    vector<double> fRC_Kinetic_Energy;
+    vector<double> fRC_Momentum_Direction_X;
+    vector<double> fRC_Momentum_Direction_Y;
+    vector<double> fRC_Momentum_Direction_Z;
+
+    
+public:
+    TReactionConditions();
+    virtual ~TReactionConditions();
+    
+    void  Clear();
+    void  Clear(const Option_t*) {};
+    void  Dump() const;
+    
+    /////////////////////           SETTERS           ////////////////////////
+    // Beam parameter
+    void SetBeamParticleName   (const string &Beam_Particle_Name)   {fRC_Beam_Particle_Name = Beam_Particle_Name;}//!
+    void SetBeamReactionEnergy  (const double &Beam_Reaction_Energy) {fRC_Beam_Reaction_Energy  = Beam_Reaction_Energy;}//!
+    void SetBeamEmittanceTheta (const double &Beam_Emittance_Theta) {fRC_Beam_Emittance_Theta = Beam_Emittance_Theta;}//!
+    void SetBeamEmittancePhi   (const double &Beam_Emittance_Phi)   {fRC_Beam_Emittance_Phi   = Beam_Emittance_Phi;}//!
+    void SetBeamEmittanceThetaX (const double &Beam_Emittance_ThetaX) {fRC_Beam_Emittance_ThetaX = Beam_Emittance_ThetaX;}//!
+    void SetBeamEmittancePhiY   (const double &Beam_Emittance_PhiY)   {fRC_Beam_Emittance_PhiY   = Beam_Emittance_PhiY;}//!
+    // Beam status at the initial interaction point
+    void SetVertexPositionX     (const double &Vertex_Position_X)      {fRC_Vertex_Position_X     = Vertex_Position_X;}//!
+    void SetVertexPositionY     (const double &Vertex_Position_Y)      {fRC_Vertex_Position_Y     = Vertex_Position_Y;}//!
+    void SetVertexPositionZ     (const double &Vertex_Position_Z)      {fRC_Vertex_Position_Z     = Vertex_Position_Z;}//!
+
+    void SetThetaCM            (const double &ThetaCM)               {fRC_ThetaCM = ThetaCM;}//!
+    
+    // emmitted particles
+    void SetParticleName       (const string &Particle_Name)         {fRC_Particle_Name.push_back(Particle_Name);}//!
+    void SetTheta              (const double &Angle)                 {fRC_Theta.push_back(Angle);}//!
+    void SetKineticEnergy      (const double &Kinetic_Energy)        {fRC_Kinetic_Energy.push_back(Kinetic_Energy);}//!
+    void SetMomentumDirectionX (const double &Momentum_Direction_X)  {fRC_Momentum_Direction_X.push_back(Momentum_Direction_X);}//!
+    void SetMomentumDirectionY (const double &Momentum_Direction_Y)  {fRC_Momentum_Direction_Y.push_back(Momentum_Direction_Y);}//!
+    void SetMomentumDirectionZ (const double &Momentum_Direction_Z)  {fRC_Momentum_Direction_Z.push_back(Momentum_Direction_Z);}//!
+    
+    /////////////////////           GETTERS           ////////////////////////
+    // Beam parameter
+    string GetBeamParticleName    () const  {return fRC_Beam_Particle_Name   ;}//!
+    double GetBeamEnergy          () const  {return fRC_Beam_Reaction_Energy  ;}//!
+    double GetBeamEmittanceTheta  () const  {return fRC_Beam_Emittance_Theta ;}//!
+    double GetBeamEmittancePhi    () const  {return fRC_Beam_Emittance_Phi   ;}//!
+    double GetBeamEmittanceThetaX () const  {return fRC_Beam_Emittance_ThetaX ;}//!
+    double GetBeamEmittancePhiY   () const  {return fRC_Beam_Emittance_PhiY   ;}//!
+    
+    // Beam status at the initial Beam point
+    double GetVertexPositionX     () const {return fRC_Vertex_Position_X     ;}//!
+    double GetVertexPositionY     () const {return fRC_Vertex_Position_Y     ;}//!
+    double GetVertexPositionZ     () const {return fRC_Vertex_Position_Z     ;}//!
+
+    double GetThetaCM             () const {return fRC_ThetaCM;}//!
+    
+    // emmitted particles
+    int GetParticleMultiplicity()                const {return fRC_Kinetic_Energy.size();}//!
+    string GetParticleName        (const int &i) const {return fRC_Particle_Name[i];}//!
+    double GetTheta               (const int &i) const {return fRC_Theta[i];}//!
+    double GetKineticEnergy       (const int &i) const {return fRC_Kinetic_Energy[i];}//!
+    double GetMomentumDirectionX  (const int &i) const {return fRC_Momentum_Direction_X[i];}//!
+    double GetMomentumDirectionY  (const int &i) const {return fRC_Momentum_Direction_Y[i];}//!
+    double GetMomentumDirectionZ  (const int &i) const {return fRC_Momentum_Direction_Z[i];}//!
+
+    TVector3 GetBeamDirection         () const ;//!
+    TVector3 GetParticleDirection     (const int &i) const ;//!
+    
+    double GetThetaLab_WorldFrame (const int &i) const {
+        return (GetParticleDirection(i).Angle(TVector3(0,0,1)))/deg;
+    } //!
+    
+    double GetThetaLab_BeamFrame (const int &i) const{
+        return (GetParticleDirection(i).Angle(GetBeamDirection()))/deg;
+    } //!
+    
+    unsigned int GetEmittedMult() const {return fRC_Particle_Name.size();} //!
+    
+    ClassDef(TReactionConditions, 1) // TReactionConditions structure
+};
+
+#endif
diff --git a/NPLib/Physics/nubtab12.asc b/NPLib/Physics/nubtab12.asc
index 86e7023a03acef84f7cf1f02a056afcda3a6d4ae..b16be589f1a75ebbdda755400aa8487cc2c3cebe 100644
--- a/NPLib/Physics/nubtab12.asc
+++ b/NPLib/Physics/nubtab12.asc
@@ -1,3 +1,4 @@
+000 0000   gamma   0.0         0.0000                        stbl              0+           06          1932 IS=0.000000 00
 001 0000   1n      8071.3171   0.0005                       613.9    s 0.6    1/2+          06          1932 B-=100
 001 0010   1H       7288.9705   0.0001                       stbl              1/2+          06 11Be53d  1920 IS=99.9885 70
 002 0010   2H      13135.7217   0.0001                       stbl              1+            03          1932 IS=0.0115 70
@@ -5508,4 +5509,4 @@
 293 1180   293Ei  198930#     730#                      RN     1#    ms        1/2+#         00 02Ni10i       A ?
 294 1170   294Eh  196040#     690#                           290     ms 230                  10 10Og01td 2010 A=100
 294 1180   294Ei  199270#     660#                             1.4   ms 0.7    0+            05 06Og05td 2006 A=100
-295 1180   295Ei  201430#     640#                            10#    ms                         04Og05td      A ?
\ No newline at end of file
+295 1180   295Ei  201430#     640#                            10#    ms                         04Og05td      A ?
diff --git a/NPLib/Utility/CMakeLists.txt b/NPLib/Utility/CMakeLists.txt
index 4e62770d5cee3a69992f8afe4c1e80459931e18f..6f3b543c7358748b39433842d45d038e538288de 100644
--- a/NPLib/Utility/CMakeLists.txt
+++ b/NPLib/Utility/CMakeLists.txt
@@ -4,5 +4,8 @@ add_executable(npanalysis npanalysis.cxx)
 target_link_libraries(npanalysis ${ROOT_LIBRARIES} -lThread -lGraf -lHist -lMatrix NPCore) 
 add_executable(nponline nponline.cxx)
 target_link_libraries(nponline ${ROOT_LIBRARIES} NPCore NPOnline) 
+add_executable(npspectra_test npspectra_test.cxx)
+target_link_libraries(npspectra_test ${ROOT_LIBRARIES} NPCore NPOnline) 
+
 install(PROGRAMS nptool-installer npanalysis nponline DESTINATION ${CMAKE_BINARY_OUTPUT_DIRECTORY})
 install(SCRIPT ../scripts/post_install.cmake ${DETLIST})
diff --git a/NPLib/Utility/npanalysis.cxx b/NPLib/Utility/npanalysis.cxx
index 3863a46d53d44cf0973215ed2f9291a5dcdc8f71..9ad671f30a3b2cc5009d85c6833332e9d0945aa2 100644
--- a/NPLib/Utility/npanalysis.cxx
+++ b/NPLib/Utility/npanalysis.cxx
@@ -12,40 +12,42 @@
 #include<dlfcn.h>
 #include<stdlib.h>
 #include<unistd.h>
+#include<sys/time.h>
 
 // Root
 #include"TKey.h"
 #include"TEnv.h" 
 #include"TROOT.h"
 void ProgressDisplay(clock_t&,clock_t&,unsigned long&, unsigned long&, unsigned long&, double&, unsigned long&, int&, int&);
+void ProgressDisplay(struct timeval& begin, struct timeval& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree);
 ////////////////////////////////////////////////////////////////////////////////
 int main(int argc , char** argv){
   // command line parsing
   NPOptionManager* myOptionManager = NPOptionManager::getInstance(argc,argv);
-  string inputfilename = myOptionManager->GetRunToReadFile();
+  std::string inputfilename = myOptionManager->GetRunToReadFile();
   // if input files are not given, use those from TAsciiFile
   if (myOptionManager->IsDefault("DetectorConfiguration")) {
-    string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("DetectorConfiguration");
+    std::string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("DetectorConfiguration");
     if(name!="fail"){
       myOptionManager->SetDetectorFile(name);
-     cout << "\033[1;33mInfo: No Detector file given, using Input tree one \033[0m"<<endl;;
+     std::cout << "\033[1;33mInfo: No Detector file given, using Input tree one \033[0m" << std::endl;;
     }  
   }
 
   if (myOptionManager->IsDefault("EventGenerator")) {
-    string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("EventGenerator");
+    std::string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("EventGenerator");
     if(name!="fail"){
     myOptionManager->SetReactionFile(name);
-    cout << "\033[1;33mInfo: No Event file given, using Input tree one \033[0m"<<endl;;
+    std::cout << "\033[1;33mInfo: No Event file given, using Input tree one \033[0m" << std::endl;;
     }
   }
 
   // get input files from NPOptionManager
-  string detectorfileName    = myOptionManager->GetDetectorFile();
-  string OutputfileName      = myOptionManager->GetOutputFile();
+  std::string detectorfileName    = myOptionManager->GetDetectorFile();
+  std::string OutputfileName      = myOptionManager->GetOutputFile();
 
   // Instantiate RootOutput
-  string TreeName="NPTool_Tree";
+  std::string TreeName="NPTool_Tree";
 
   // User decided of the name
   if(!myOptionManager->IsDefault("TreeName")){
@@ -53,7 +55,7 @@ int main(int argc , char** argv){
   }
 
   // Case of a Physics tree produced
-  else if(!myOptionManager->GetInputPhysicalTreeOption()){ //
+  else if(!myOptionManager->GetInputPhysicalTreeOption()){ 
     TreeName="PhysicsTree";
     if(myOptionManager->IsDefault("OutputFileName"))
       OutputfileName="PhysicsTree";
@@ -76,14 +78,14 @@ int main(int argc , char** argv){
   myDetector->InitializeRootOutput();
   // Attempt to load an analysis
   NPL::VAnalysis* UserAnalysis = NULL;
-  string libName = "./libNPAnalysis" + myOptionManager->GetSharedLibExtension();
+  std::string libName = "./libNPAnalysis" + myOptionManager->GetSharedLibExtension();
   dlopen(libName.c_str(),RTLD_NOW | RTLD_GLOBAL);
   char* error = dlerror();
   if(error==NULL){
     UserAnalysis = NPL::AnalysisFactory::getInstance()->Construct(); 
     UserAnalysis->SetDetectorManager(myDetector);
     UserAnalysis->Init();
-  }
+  } 
   else{
     std::string str_error=error;
     if(str_error.find("image not found")!=std::string::npos ||str_error.find("No such file or directory")!=std::string::npos )
@@ -119,6 +121,8 @@ int main(int argc , char** argv){
   unsigned long displayed=0;
   clock_t end;
   clock_t begin = clock();
+  struct timeval tv_end;
+  struct timeval tv_begin; gettimeofday(&tv_begin,NULL);
   unsigned long new_nentries = 0 ;
   int current_tree = 0 ;
   int total_tree = Chain->GetNtrees();
@@ -136,7 +140,8 @@ int main(int argc , char** argv){
         tree->Fill();
 
         current_tree = Chain->GetTreeNumber()+1;
-        ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
+        //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
+        ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
         if(myOptionManager->GetOnline() && i%10000==0){
           myDetector->CheckSpectraServer();
 
@@ -161,7 +166,7 @@ int main(int argc , char** argv){
     }
 
     else{
-      cout << "\033[1;31m ERROR: You are requesting to rebuild a Physics Tree without any User Analysis, nothing to be done\033[0m" <<endl;
+      std::cout << "\033[1;31m ERROR: You are requesting to rebuild a Physics Tree without any User Analysis, nothing to be done\033[0m" << std::endl;
       // Quit without error
       exit(0);
     }
@@ -171,22 +176,17 @@ int main(int argc , char** argv){
     if(!IsPhysics){ 
       for (unsigned long i = first_entry ; i < nentries + first_entry; i++) { 
         // Get the raw Data
-	//cout << "!" << endl;
         Chain -> GetEntry(i);
-	//cout << "!!" << endl;
         // Build the current event
         myDetector->BuildPhysicalEvent();
-	//cout << "!!!" << endl;
         // User Analysis
         UserAnalysis->TreatEvent();
-	//cout << "!!!!" << endl;
         // Fill the tree      
         tree->Fill();
       
-	//cout << "!!!!!" << endl;
         current_tree = Chain->GetTreeNumber()+1;
-        ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
-        
+        //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
+        ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
         if(myOptionManager->GetOnline() && i%10000==0){
           myDetector->CheckSpectraServer();
           bool first = true;
@@ -219,7 +219,8 @@ int main(int argc , char** argv){
         tree->Fill();
 
         current_tree = Chain->GetTreeNumber()+1;
-        ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
+        //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
+        ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
         if(myOptionManager->GetOnline() && i%10000==0){
           myDetector->CheckSpectraServer();
 
@@ -245,11 +246,14 @@ int main(int argc , char** argv){
     UserAnalysis->End();
   }
 
-#if __cplusplus > 199711L
+#if __cplusplus > 199711L && NPMULTITHREADING
   myDetector->StopThread();
 #endif
+
   current_tree = Chain->GetTreeNumber()+1;
-  ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
+  //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
+
+  ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree);
 
   if(myOptionManager->GetOnline()){
     myDetector->CheckSpectraServer(); 
@@ -261,10 +265,48 @@ int main(int argc , char** argv){
 
   RootOutput::Destroy();
   RootInput::Destroy();
-
-return 0;
+  return 0;
 }
+////////////////////////////////////////////////////////////////////////////////
+void ProgressDisplay(struct timeval& begin, struct timeval& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree){
+  gettimeofday(&end,NULL);
+  long double elapsed= end.tv_sec-begin.tv_sec+(end.tv_usec-begin.tv_usec)*1e-6;
+  if(elapsed>1||treated>=total ){
+    displayed++;
+    double event_rate = inter/elapsed;
+    mean_rate += (event_rate-mean_rate)/(displayed);
+    double percent = 100*treated/total;
+    double remain = (total-treated)/mean_rate;
+
+    char* timer;
+    double check;
+    int minutes = remain/60.;
+    int seconds = remain -60*minutes;
+    if(remain>60)
+      check=asprintf(&timer,"%dmin%ds",minutes,seconds);
+    else
+      check=asprintf(&timer,"%ds",(int)(remain));
+    
+    static char star[10];
+    if(displayed%2==0 || treated==total)
+      sprintf(star,"*******");
+    else
+      sprintf(star,"-------");
 
+    if(treated!=total)
+      printf("\r \033[1;31m %s Progress: \033[1;36m%.1f%% \033[1;31m| Rate: %.1fk evt/s | Remain: %s | Tree: %d/%d %s   \033[0m         ", star,percent,mean_rate/1000.,timer, current_tree,total_tree,star);
+
+    else{
+      printf("\r \033[1;32m %s Progress: %.1f%% | Rate: %.1fk evt/s | Remain: %s | Tree: %d/%d %s   \033[0m         ", star,percent,mean_rate/1000.,timer, current_tree, total_tree,star);
+    }
+    fflush(stdout);
+    inter=0;
+    gettimeofday(&begin,NULL);
+  }
+
+  treated++;
+  inter++;
+}
 ////////////////////////////////////////////////////////////////////////////////
 void ProgressDisplay(clock_t& begin, clock_t& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree){
   end = clock();
diff --git a/NPLib/Utility/npspectra_test.cxx b/NPLib/Utility/npspectra_test.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..4995b6b52240b93b7ad673d568c8638552747c33
--- /dev/null
+++ b/NPLib/Utility/npspectra_test.cxx
@@ -0,0 +1,53 @@
+#include"TApplication.h"
+#include "TH1D.h"
+#include "TH2D.h"
+#include "TError.h"
+#include "TRandom.h"
+#include"NPSpectraServer.h"
+#include<cstdlib>
+#include<iostream>
+
+int main(int argc , char** argv){
+  // Root will not issue any BS warning message
+  gErrorIgnoreLevel = 10000;
+
+  NPL::SpectraServer* server = NPL::SpectraServer::getInstance();
+
+  // Create two test spectrum
+  TH1D* h1 = new TH1D("h1","h1",1000,-10,10);
+  TH2D* h2 = new TH2D("h2","h2",500,-10,10,500,-10,10);
+  // Add them to the server
+  server->AddSpectra(h1);
+  server->AddSpectra(h2);
+
+
+  // Load test
+  for(unsigned int i = 0 ; i < 100 ; i++){
+  TH1D* hh1 = new TH1D(Form("hh1D%i",i),"hh1D",1000,-10,10);
+  TH2D* hh2 = new TH2D(Form("hh2D%i",i),"hh2D",1000,-10,10,1000,-10,10);
+  // Add them to the server
+  server->AddSpectra(hh1);
+  server->AddSpectra(hh2);
+  }
+
+   while(true){
+    h1->Reset();
+    h2->Reset();
+    double meanX = gRandom->Uniform(-5,5);
+    double meanY = gRandom->Uniform(-5,5);
+    for(unsigned int i=0 ; i< 1000 ; i++){
+    // Random value for the fill
+    double x = gRandom->Gaus(meanX,1); 
+    double y = gRandom->Gaus(meanY,1); 
+
+    // Fill them
+    server->FillSpectra("h1",x);
+    server->FillSpectra("h2",x,y);
+    }
+    
+    server->CheckRequest(); 
+    }
+
+  return 0;
+}
+
diff --git a/NPLib/ressources/CMake/NPTool_CMake_Preamble.cmake b/NPLib/ressources/CMake/NPTool_CMake_Preamble.cmake
index 3589e9dd88e0d6c59829194896709c40e98c47db..53b09109cfd198639c7c4ea6d8512494c93e2c1a 100644
--- a/NPLib/ressources/CMake/NPTool_CMake_Preamble.cmake
+++ b/NPLib/ressources/CMake/NPTool_CMake_Preamble.cmake
@@ -10,6 +10,8 @@ include("${NPLIB}/ressources/CMake/Root.cmake")
 # Setting the policy to match Cmake version
 cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
 
+
+
 # This suppress the Up-to-Date message of file installed for cmake 3.1 and above
 set(CMAKE_INSTALL_MESSAGE LAZY) 
 
diff --git a/NPLib/scripts/Style_nponline.C b/NPLib/scripts/Style_nponline.C
index 8f5ac365611e969a108a9e62cd10cac9514b9b27..aeb7eb4a4debd4eefc56f4ac033c5693e3407732 100644
--- a/NPLib/scripts/Style_nponline.C
+++ b/NPLib/scripts/Style_nponline.C
@@ -81,7 +81,7 @@ style->SetFrameFillColor(kGray+3);
 
   style->SetTitlePS("nptool");
 
-  const UInt_t Number = 2;
+/*  const UInt_t Number = 2;
   Double_t Red[Number]    = { 0,0   };
   Double_t Green[Number]  = { 0,0.8 };
   Double_t Blue[Number]   = { 0,1.00 };
@@ -89,5 +89,7 @@ style->SetFrameFillColor(kGray+3);
   Double_t Length[Number] = { 0,1.00 };
   Int_t nb=255;
   TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
-  style->SetNumberContours(99);
+*/
+ style->SetNumberContours(99);
+ style->SetPalette();
 }
diff --git a/NPLib/scripts/Style_nptool.C b/NPLib/scripts/Style_nptool.C
index 6026c490c028391d99680b2427621c72944dc2ed..60c8f49926f3e4e2d0831939d74a16a88076b15b 100644
--- a/NPLib/scripts/Style_nptool.C
+++ b/NPLib/scripts/Style_nptool.C
@@ -80,13 +80,15 @@ void Style_nptool(){
   style->SetFuncWidth(2);
 
   // Create the color gradiant 
-  const UInt_t Number = 2;
-  Double_t Red[Number]    = { 0,0   };
-  Double_t Green[Number]  = { 0,0.8 };
-  Double_t Blue[Number]   = { 0,1.00 };
+//  const UInt_t Number = 2;
+//  Double_t Red[Number]    = { 0,0   };
+//  Double_t Green[Number]  = { 0,0.8 };
+//  Double_t Blue[Number]   = { 0,1.00 };
 
-  Double_t Length[Number] = { 0,1.00 };
-  Int_t nb=255;
-  TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
+//  Double_t Length[Number] = { 0,1.00 };
+//  Int_t nb=255;
+//  TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
   style->SetNumberContours(99);
+  style->SetPalette(0);
+
 }
diff --git a/NPSimulation/Core/CMakeLists.txt b/NPSimulation/Core/CMakeLists.txt
index 95ea8b3b40920a973c8d796a90499c67357cdfad..9ac5b1c90e0411c232b9467b4109251034a54b07 100644
--- a/NPSimulation/Core/CMakeLists.txt
+++ b/NPSimulation/Core/CMakeLists.txt
@@ -1,2 +1,2 @@
 add_library(NPSCore SHARED $<TARGET_OBJECTS:NPSEventGenerator> EventAction.cc PrimaryGeneratorAction.cc Target.cc Chamber.cc PrimaryGeneratorActionMessenger.cc NPSVDetector.cc DetectorConstruction.cc MaterialManager.cc DetectorMessenger.cc MyMagneticField.cc  SteppingVerbose.cc NPSDetectorFactory.cc RunAction.cc Particle.cc ParticleStack.cc)
-target_link_libraries(NPSCore ${ROOT_LIBRARIES} ${Geant4_LIBRARIES} ${NPLib_LIBRARIES} NPSScorers NPInitialConditions NPInteractionCoordinates )
+target_link_libraries(NPSCore ${ROOT_LIBRARIES} ${Geant4_LIBRARIES} ${NPLib_LIBRARIES} NPSScorers NPSProcess NPInitialConditions NPInteractionCoordinates )
diff --git a/NPSimulation/Core/DetectorConstruction.cc b/NPSimulation/Core/DetectorConstruction.cc
index a5f9cb379cd9dcf47e9fda11e2becad57f88ec85..69aeb655f62b9a9a355240960dcd1f6bea771506 100644
--- a/NPSimulation/Core/DetectorConstruction.cc
+++ b/NPSimulation/Core/DetectorConstruction.cc
@@ -56,11 +56,10 @@
 #include "NPSDetectorFactory.hh"
 #include "MaterialManager.hh"
 #include "DetectorMessenger.hh"
-
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 DetectorConstruction::DetectorConstruction():  world_log(0), world_phys(0){
-  m_Target   = 0;
-  m_Chamber  = 0 ;
+  m_Target   = NULL;
+  m_Chamber  = NULL ;
   m_Messenger =  new DetectorMessenger(this);
   m_ReadSensitivePtr = &NPS::VDetector::ReadSensitive;
 }
@@ -74,8 +73,6 @@ G4VPhysicalVolume* DetectorConstruction::Construct(){
   return ReadConfigurationFile();
 }
 
-
-
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 void DetectorConstruction::AddDetector(NPS::VDetector* NewDetector){
   // Add new detector to vector
@@ -92,7 +89,6 @@ void DetectorConstruction::AddDetector(NPS::VDetector* NewDetector){
 }
 
 
-
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 G4VPhysicalVolume* DetectorConstruction::ReadConfigurationFile(){
   
@@ -110,7 +106,7 @@ G4VPhysicalVolume* DetectorConstruction::ReadConfigurationFile(){
   world_log = new G4LogicalVolume(world_box, Vacuum, "world_log", 0, 0, 0);
   world_phys = new G4PVPlacement(0, G4ThreeVector(), world_log, "world", 0, false, 0);
 
-  G4VisAttributes* VisAtt = new G4VisAttributes(G4VisAttributes::Invisible);
+    G4VisAttributes* VisAtt = new G4VisAttributes(G4VisAttributes::Invisible);
   world_log->SetVisAttributes(VisAtt);
 
   //------------------------------------------------------------------
@@ -152,7 +148,7 @@ G4VPhysicalVolume* DetectorConstruction::ReadConfigurationFile(){
     AddDetector(m_Target);
   }
   else{
-     blocks = parser.GetAllBlocksWithToken("CryoTarget");
+     blocks = parser.GetAllBlocksWithToken("CryogenicTarget");
      if(blocks.size()==1){
       m_Target = new Target();
       m_Target->ReadConfiguration(parser);
diff --git a/NPSimulation/Core/EventAction.cc b/NPSimulation/Core/EventAction.cc
index e3a0805c43b37fc9642847bbd0934b59d5f653f4..bb88725eab7c91346a8b9823fab8906ac7d9bdd4 100644
--- a/NPSimulation/Core/EventAction.cc
+++ b/NPSimulation/Core/EventAction.cc
@@ -26,7 +26,6 @@
 #include "G4RunManager.hh"
 #include "G4Trajectory.hh"
 #include "G4TrajectoryContainer.hh"
-
 // NPTool headers
 #include "EventAction.hh"
 #include "DetectorConstruction.hh"
@@ -34,7 +33,6 @@
 #include "ParticleStack.hh"
 
 #include<iostream>
-using namespace std;
 
 EventAction* EventAction::m_EventAction=0;
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
diff --git a/NPSimulation/Core/EventAction.hh b/NPSimulation/Core/EventAction.hh
index 8067f47e1b16f75ac2add1e8c1d072501732d152..914b38accf69b7835ec77ff89074a68da6b0fe9a 100644
--- a/NPSimulation/Core/EventAction.hh
+++ b/NPSimulation/Core/EventAction.hh
@@ -32,7 +32,6 @@
 
 // STL
 #include<time.h>
-
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 class EventAction : public G4UserEventAction{
   public:
diff --git a/NPSimulation/Core/MaterialManager.cc b/NPSimulation/Core/MaterialManager.cc
index 06c59632b53d8df98d3771372bdb1547f6dac286..703c3dff5ca917b69167357f44713735d433b8fd 100644
--- a/NPSimulation/Core/MaterialManager.cc
+++ b/NPSimulation/Core/MaterialManager.cc
@@ -32,6 +32,7 @@
 #include "G4VisAttributes.hh"
 #include "G4NistManager.hh"
 #include "G4MaterialPropertiesTable.hh"
+#include "G4ParticleTable.hh"
 // STL
 #include <iostream>
 #include <string>
@@ -848,6 +849,8 @@ G4Material* MaterialManager::GetGasFromLibrary(string Name, double Pressure, dou
 //   Generate a DEDX file table using the material used in the geometry
 void MaterialManager::WriteDEDXTable(G4ParticleDefinition* Particle ,G4double Emin,G4double Emax){
     map<string,G4Material*>::iterator it;
+    if(Particle->GetPDGCharge()==0)
+      return;
     for(it = m_Material.begin() ; it != m_Material.end() ; it++){
         //   Opening hte output file
         G4String GlobalPath = getenv("NPTOOL");
@@ -875,7 +878,7 @@ void MaterialManager::WriteDEDXTable(G4ParticleDefinition* Particle ,G4double Em
         for (G4double E=Emin; E < Emax; E+=step){
             dedx = emCalculator.ComputeTotalDEDX(E, Particle, it->second)/(MeV/micrometer);
             if(before){
-                if(abs(before-dedx)/abs(before)<0.01) step*=10; 
+                if(abs(before-dedx)/abs(before)<0.01) step*=2; 
             }
             
             before = dedx;
@@ -886,6 +889,15 @@ void MaterialManager::WriteDEDXTable(G4ParticleDefinition* Particle ,G4double Em
     }
 }
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+//   Generate a DEDX file table using the material used in the geometry
+void MaterialManager::WriteDEDXTable(std::set<string> Particle ,G4double Emin,G4double Emax){
+  std::set<string>::iterator it;
+  for(it=Particle.begin(); it!=Particle.end() ; it++){
+     G4ParticleDefinition* p = G4ParticleTable::GetParticleTable()->FindParticle((*it));
+     WriteDEDXTable(p,Emin,Emax);
+    }
+}
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 void MaterialManager::CreateSampleVolumes(G4LogicalVolume* world_log){
     
     // Crate a micrometer big cube for each material
diff --git a/NPSimulation/Core/MaterialManager.hh b/NPSimulation/Core/MaterialManager.hh
index 15df2022212de5ce2f92314a8f180eb89c94c8c8..977f988a8186dadc5fe5b837ef839f1d6a2847a5 100644
--- a/NPSimulation/Core/MaterialManager.hh
+++ b/NPSimulation/Core/MaterialManager.hh
@@ -30,6 +30,7 @@
 #include "G4LogicalVolume.hh"
 // STL
 #include<map>
+#include<set>
 using namespace std;
 
 class MaterialManager{
@@ -90,5 +91,10 @@ public:
   // Write the DEDx table for all material instantiate in the MaterialManager
   // for a given particle
   void WriteDEDXTable(G4ParticleDefinition* Particle ,G4double Emin,G4double Emax);
+
+  // Write the DEDx table for all material instantiate in the MaterialManager
+  // for a list of particle name
+  void WriteDEDXTable(std::set<string> Particle ,G4double Emin,G4double Emax);
+
 };
 #endif
diff --git a/NPSimulation/Core/ParticleStack.cc b/NPSimulation/Core/ParticleStack.cc
index 236eab375ff5d25d7c3c03017806295546578e9f..c8d6641f9c7a01c458b11adbac240899c8dea4d7 100644
--- a/NPSimulation/Core/ParticleStack.cc
+++ b/NPSimulation/Core/ParticleStack.cc
@@ -106,18 +106,19 @@ void ParticleStack::AddBeamParticleToStack(Particle& particle){
     m_ParticleStack.push_back(particle);
     // Incident beam parameter
     m_InitialConditions-> SetIncidentParticleName   (particle.GetParticleDefinition()->GetParticleName());
-    m_InitialConditions-> SetIncidentFinalKineticEnergy  (particle. GetParticleKineticEnergy());
+    //m_InitialConditions-> SetIncidentInitialKineticEnergy  (particle. GetParticleThetaCM());
+    m_InitialConditions-> SetIncidentInitialKineticEnergy  (particle. GetParticleKineticEnergy());
     
     G4ThreeVector U(1,0,0);
     G4ThreeVector V(0,1,0);
     
     m_InitialConditions-> SetIncidentEmittanceThetaX (particle.GetParticleMomentumDirection().angle(U)/deg);
     m_InitialConditions-> SetIncidentEmittancePhiY   (particle.GetParticleMomentumDirection().angle(V)/deg);
-    m_InitialConditions-> SetIncidentEmittanceTheta (particle.GetParticleMomentumDirection().theta()/deg);
-    m_InitialConditions-> SetIncidentEmittancePhi  (particle.GetParticleMomentumDirection().phi()/deg);
+    m_InitialConditions-> SetIncidentEmittanceTheta  (particle.GetParticleMomentumDirection().theta()/deg);
+    m_InitialConditions-> SetIncidentEmittancePhi    (particle.GetParticleMomentumDirection().phi()/deg);
     
     // Beam status at the initial interaction point
-    m_InitialConditions-> SetIncidentInitialKineticEnergy (particle. GetParticleThetaCM());
+    m_InitialConditions-> SetIncidentFinalKineticEnergy (particle. GetParticleKineticEnergy());
     m_InitialConditions-> SetIncidentPositionX     (particle. GetParticlePosition().x());
     m_InitialConditions-> SetIncidentPositionY     (particle. GetParticlePosition().y());
     m_InitialConditions-> SetIncidentPositionZ     (particle. GetParticlePosition().z());
diff --git a/NPSimulation/Core/PrimaryGeneratorAction.cc b/NPSimulation/Core/PrimaryGeneratorAction.cc
index 361a95fe196c7878b9b5bd53098263659423f761..4c761b3c19d9231c4edb6e5bfe57f828385323e9 100644
--- a/NPSimulation/Core/PrimaryGeneratorAction.cc
+++ b/NPSimulation/Core/PrimaryGeneratorAction.cc
@@ -51,7 +51,8 @@
 PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* det): m_detector(det){
   m_Messenger = new PrimaryGeneratorActionMessenger(this);
   m_GenerateEvent = &NPS::VEventGenerator::GenerateEvent;
-}
+  m_Target=NULL;
+  }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 PrimaryGeneratorAction::~PrimaryGeneratorAction(){
@@ -111,7 +112,7 @@ void PrimaryGeneratorAction::ReadEventGeneratorFile(string Path){
     myEventGenerator->SetTarget(m_detector->GetTarget());
     m_EventGenerator.push_back(myEventGenerator);
   }
-  blocks.clear();
+/*  blocks.clear();
   blocks = parser.GetAllBlocksWithToken("TwoBodyReaction");
   if (blocks.size()>0) {
     NPS::VEventGenerator* myEventGenerator = new EventGeneratorTwoBodyReaction();
@@ -138,6 +139,10 @@ void PrimaryGeneratorAction::ReadEventGeneratorFile(string Path){
     myEventGenerator->SetTarget(m_detector->GetTarget());
     m_EventGenerator.push_back(myEventGenerator);
   }
+*/
+  m_Target=m_detector->GetTarget();
+  m_Target->SetReactionRegion();
+
 }
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 void PrimaryGeneratorAction::ClearEventGenerator(){
@@ -152,7 +157,7 @@ void PrimaryGeneratorAction::ClearEventGenerator(){
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 void PrimaryGeneratorAction::SetTarget(){
   for (unsigned int i = 0 ; i < m_EventGenerator.size(); i++) {
-    m_EventGenerator[i]->SetTarget(m_detector->GetTarget());
+    m_EventGenerator[i]->SetTarget(m_Target);
   }
 }
 
diff --git a/NPSimulation/Core/PrimaryGeneratorAction.hh b/NPSimulation/Core/PrimaryGeneratorAction.hh
index 7a52d1b5a36468447c4367770e1a3f19b4361069..3a09784f4d160335f149712cf8e4d5b0b9201462 100644
--- a/NPSimulation/Core/PrimaryGeneratorAction.hh
+++ b/NPSimulation/Core/PrimaryGeneratorAction.hh
@@ -62,7 +62,7 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction{
     DetectorConstruction* m_detector;
     vector<NPS::VEventGenerator*> m_EventGenerator;
     PrimaryGeneratorActionMessenger* m_Messenger;
-    
+    Target* m_Target;   
 };
 
 #endif
diff --git a/NPSimulation/Core/PrimaryGeneratorActionMessenger.hh b/NPSimulation/Core/PrimaryGeneratorActionMessenger.hh
index 37c9d314f582f0ae34cf9e6746b60c900095d513..0b9e6af09b15118d854ad7de361659260fa1c8a8 100644
--- a/NPSimulation/Core/PrimaryGeneratorActionMessenger.hh
+++ b/NPSimulation/Core/PrimaryGeneratorActionMessenger.hh
@@ -14,7 +14,7 @@
  * Last update    :                                                          *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
- *  This class describe the PrimaryGeneratorAction Messenger                               *
+ *  This class describe the PrimaryGeneratorAction Messenger                 *
  *                                                                           *
  *---------------------------------------------------------------------------*
  * Comment:                                                                  *
diff --git a/NPSimulation/Core/RunAction.cc b/NPSimulation/Core/RunAction.cc
index ddea8c3ca4256ceb7be23fdca308a6e7fb0ca8af..b68b214be5df5c80ea725876fe72080255aaaddb 100644
--- a/NPSimulation/Core/RunAction.cc
+++ b/NPSimulation/Core/RunAction.cc
@@ -24,9 +24,13 @@
 #include "PrimaryGeneratorAction.hh"
 #include "EventAction.hh"
 #include "ParticleStack.hh"
+#include "MaterialManager.hh"
 // G4
 #include "G4Run.hh"
 #include "G4RunManager.hh"
+#include "G4Event.hh"
+#include "G4VTrajectory.hh"
+
 // NPL
 #include "RootOutput.h"
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -53,10 +57,21 @@ void RunAction::BeginOfRunAction(const G4Run* aRun){
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-void RunAction::EndOfRunAction(const G4Run*){
+void RunAction::EndOfRunAction(const G4Run* aRun){
     // Pass a line for nicer presentation when chainning event generator
     cout << endl;
-    
     // Force the tree to be saved at the end of the run
     RootOutput::getInstance()->GetTree()->AutoSave("Overwrite SaveSelf");
+    // Write DEDX Tables
+    std::set<string> Particles;
+    const std::vector<const G4Event*>* events = aRun->GetEventVector();
+    unsigned int sizeE = events->size();
+    for(unsigned int e = 0 ; e < sizeE ; e++){
+      TrajectoryVector* traj = (*events)[e]->GetTrajectoryContainer()->GetVector();
+      unsigned int size = traj->size();
+      for(unsigned int i = 0 ; i < size ; i++)
+        Particles.insert( (*traj)[i]->GetParticleName());
+    }
+    
+    MaterialManager::getInstance()->WriteDEDXTable(Particles,0,10*GeV); 
 }
diff --git a/NPSimulation/Core/RunAction.hh b/NPSimulation/Core/RunAction.hh
index 546a55cd559e0cef90d849db0780d76f85884b9c..b63768bd0b65f8bf6d9038bbff515cd46d1cad05 100644
--- a/NPSimulation/Core/RunAction.hh
+++ b/NPSimulation/Core/RunAction.hh
@@ -25,6 +25,8 @@
 // G4 headers
 #include "G4UserRunAction.hh"
 #include "globals.hh"
+#include <set>
+#include <string>
 
 class G4Run;
 
@@ -35,9 +37,10 @@ class RunAction : public G4UserRunAction{
 
     virtual void BeginOfRunAction(const G4Run*);
     virtual void EndOfRunAction(const G4Run*);
+
   private:
     int m_RunNumber;
-    
+    std::set<std::string> m_Particle;
 };
 
 
diff --git a/NPSimulation/Core/Target.cc b/NPSimulation/Core/Target.cc
index 6107342125ac5b41f9aef8f9de94fd376fbb0ea2..35b795c4cf2b32fbb062baccca64d86ad97ab402 100644
--- a/NPSimulation/Core/Target.cc
+++ b/NPSimulation/Core/Target.cc
@@ -45,13 +45,17 @@
 #include "G4EmCalculator.hh"
 #include "G4ParticleDefinition.hh"
 #include "G4ParticleTable.hh"
+#include "G4UserLimits.hh"
 #include "Randomize.hh"
+#include "BeamReaction.hh"
+#include "G4FastSimulationManager.hh"
+#include "G4SubtractionSolid.hh"
 using namespace CLHEP ;
 
 // NPS
-#include"Target.hh"
-#include"MaterialManager.hh"
-
+#include "Target.hh"
+#include "MaterialManager.hh"
+#include "Decay.hh"
 // NPL
 #include "NPOptionManager.h"
 #include "NPInputParser.h"
@@ -66,11 +70,37 @@ Target::Target(){
   m_TargetThickness    = 0   ;
   m_TargetAngle        = 0   ;
   m_TargetRadius       = 0   ;
-  m_WindowsThickness   = 0   ;
   m_TargetDensity      = 0   ;
   m_TargetNbLayers     = 5;   // Number of steps by default
   // Set the global pointer
   TargetInstance = this;
+  m_ReactionRegion=NULL;
+
+  m_TargetDensity = 0 ;
+  m_FrontDeformation = 0 ;
+  m_FrontThickness = 0 ;
+  m_FrontRadius = 0 ;
+  m_FrontMaterial = 0 ;
+  m_BackDeformation = 0 ;
+  m_BackRadius = 0 ;
+  m_BackThickness = 0 ;
+  m_BackMaterial = 0 ;
+  m_FrameRadius = 0 ;
+  m_FrameThickness = 0;
+  m_FrontCone = 0 ;
+  m_BackCone = 0 ;
+  m_FrameMaterial = 0 ;
+  m_ShieldInnerRadius = 0 ;
+  m_ShieldOuterRadius = 0 ;
+  m_ShieldBottomLength = 0 ;
+  m_ShieldTopLength = 0 ;
+  m_ShieldFrontRadius = 0 ; 
+  m_ShieldBackRadius = 0 ;
+  m_ShieldMaterial = 0 ;
+
+
+
+
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -87,7 +117,7 @@ G4Material* Target::GetMaterialFromLibrary(G4String MaterialName){
 // Called in DetecorConstruction::ReadDetextorConfiguration Method
 void Target::ReadConfiguration(NPL::InputParser parser){
   vector<NPL::InputBlock*>  starget = parser.GetAllBlocksWithToken("Target");
-  vector<NPL::InputBlock*>  ctarget = parser.GetAllBlocksWithToken("CryoTarget");
+  vector<NPL::InputBlock*>  ctarget = parser.GetAllBlocksWithToken("CryogenicTarget");
 
   if(starget.size()==1){
     cout << "////       TARGET      ////" << endl;
@@ -113,26 +143,63 @@ void Target::ReadConfiguration(NPL::InputParser parser){
   }
   else if(ctarget.size()==1){
     m_TargetType=false;
-    cout << " Cryo Target found " << endl;
-    vector<string> token = {"Thickness","Radius","Material","Density","WindowsThickness","WindowsMaterial","Angle","X","Y","Z"};
-    if(ctarget[0]->HasTokenList(token)){
-      m_TargetThickness= ctarget[0]->GetDouble("Thickness","micrometer");
-      m_TargetAngle=ctarget[0]->GetDouble("Angle","deg");
-      m_TargetMaterial= MaterialManager::getInstance()->GetMaterialFromLibrary(ctarget[0]->GetString("Material"),ctarget[0]->GetDouble("Density","g/cm3"));
-      m_WindowsThickness= ctarget[0]->GetDouble("WindowsThickness","micrometer");
-      m_WindowsMaterial= GetMaterialFromLibrary(ctarget[0]->GetString("WindowsMaterial"));
-      m_TargetRadius=ctarget[0]->GetDouble("Radius","mm");
-      
-      m_TargetX=ctarget[0]->GetDouble("X","mm");
-      m_TargetY=ctarget[0]->GetDouble("Y","mm");
-      m_TargetZ =ctarget[0]->GetDouble("Z","mm");
+    cout << "//// Cryogenic Target found " << endl;
+
+    vector<string> CoreToken   = {"NominalThickness","Material","Density","Radius","Angle","X","Y","Z"};
+    vector<string> FrontToken  = {"FrontDeformation","FrontThickness","FrontRadius","FrontMaterial"};
+    vector<string> BackToken   = {"BackDeformation","BackThickness","BackRadius","BackMaterial"};
+    vector<string> FrameToken  = {"FrameRadius","FrameThickness","FrontCone","BackCone","FrameMaterial"};
+    vector<string> ShieldToken = {"ShieldInnerRadius","ShieldOuterRadius""ShieldBottomLength","ShieldTopLength","ShieldFrontRadius","ShieldBackRadius","ShieldMaterial"};
+
+
+
+
+    if(ctarget[0]->HasTokenList(CoreToken)){
+      MaterialManager* Mat =  MaterialManager::getInstance();
+      // Target 
+      m_TargetThickness = ctarget[0]->GetDouble("NominalThickness","micrometer");
+      m_TargetAngle = ctarget[0]->GetDouble("Angle","deg");
+      m_TargetMaterial = Mat->GetMaterialFromLibrary(ctarget[0]->GetString("Material"),ctarget[0]->GetDouble("Density","g/cm3"));
+      m_TargetRadius = ctarget[0]->GetDouble("Radius","mm");
+      m_TargetX = ctarget[0]->GetDouble("X","mm");
+      m_TargetY = ctarget[0]->GetDouble("Y","mm");
+      m_TargetZ = ctarget[0]->GetDouble("Z","mm");
+      m_TargetDensity = ctarget[0]->GetDouble("Density","g/cm3"); 
+      m_TargetRadius = ctarget[0]->GetDouble("Radius","mm");
+
+      // Front Window
+      m_FrontDeformation = ctarget[0]->GetDouble("FrontDeformation","mm");
+      m_FrontThickness = ctarget[0]->GetDouble("FrontThickness","micrometer");
+      m_FrontRadius = ctarget[0]->GetDouble("FrontRadius","mm");
+      m_FrontMaterial = Mat->GetMaterialFromLibrary(ctarget[0]->GetString("FrontMaterial"));
+
+      // Back Window
+      m_BackDeformation = ctarget[0]->GetDouble("BackDeformation","mm");
+      m_BackRadius = ctarget[0]->GetDouble("BackRadius","mm");
+      m_BackThickness = ctarget[0]->GetDouble("BackThickness","micrometer");
+      m_BackMaterial = Mat->GetMaterialFromLibrary( ctarget[0]->GetString("BackMaterial"));
+
+      // Cell Frame
+      m_FrameRadius = ctarget[0]->GetDouble("FrameRadius","mm");
+      m_FrameThickness = ctarget[0]->GetDouble("FrameThickness","mm");
+      m_FrontCone = ctarget[0]->GetDouble("FrontCone","deg");
+      m_BackCone = ctarget[0]->GetDouble("BackCone","deg");
+      m_FrameMaterial = Mat->GetMaterialFromLibrary(ctarget[0]->GetString("FrameMaterial"));
+      // Heat Shield
+      m_ShieldInnerRadius = ctarget[0]->GetDouble("ShieldInnerRadius","mm");
+      m_ShieldOuterRadius = ctarget[0]->GetDouble("ShieldOuterRadius","mm");
+      m_ShieldBottomLength = ctarget[0]->GetDouble("ShieldBottomLength","mm");
+      m_ShieldTopLength = ctarget[0]->GetDouble("ShieldTopLength","mm");
+      m_ShieldFrontRadius = ctarget[0]->GetDouble("ShieldFrontRadius","mm"); 
+      m_ShieldBackRadius = ctarget[0]->GetDouble("ShieldBackRadius","mm");
+      m_ShieldMaterial = Mat->GetMaterialFromLibrary(ctarget[0]->GetString("ShieldMaterial"));
     }
     else{
       cout << "ERROR: Target token list incomplete, check your input file" << endl;
       exit(1);
     }
-    
-    if(ctarget[0]->HasToken("NBLAYERS"))
+
+    if(ctarget[0]->HasToken("360AYERS"))
       m_TargetNbLayers = ctarget[0]->GetInt("NBLAYERS");
 
   }
@@ -170,68 +237,217 @@ void Target::ConstructDetector(G4LogicalVolume* world){
   }
 
   else {   // case of cryogenic target
-    if (m_TargetThickness > 0) {
-      m_TargetSolid = 
-        new G4Tubs("solidTarget", 0, m_TargetRadius, 
-            0.5*m_TargetThickness+m_WindowsThickness, 0*deg, 360*deg);
+    // X-Z target profile
+    unsigned int size = 100;
+    std::vector<double> OuterRadius;
+    std::vector<double> InnerRadius;
+    std::vector<double> Z;
+
+    // Front Bulge
+    if(m_FrontDeformation!=0){
+      double step = m_FrontRadius/size;
+      for(unsigned int i = 0 ; i < size ; i++){
+        OuterRadius.push_back(i*step);
+        Z.push_back(FrontProfile(i*step,m_TargetThickness*0.5,m_FrontDeformation,m_FrontRadius));
+      } 
+    }
 
-     m_TargetLogic = 
-        new G4LogicalVolume(m_TargetSolid, 
-                            GetMaterialFromLibrary("Vacuum")
-                            , "logicTarget");
+    // Nominal Part
+    OuterRadius.push_back(m_FrontRadius);
+    Z.push_back(0.5*m_TargetThickness);
 
-      m_TargetLogic->SetVisAttributes(G4VisAttributes::Invisible);
-      G4Tubs* solidTarget = 
-            new G4Tubs("solidTarget", 0, m_TargetRadius, 
-            0.5*m_TargetThickness, 0*deg, 360*deg);
+    OuterRadius.push_back(m_TargetRadius);
+    Z.push_back(0.5*m_TargetThickness);
 
-      G4LogicalVolume* logicTarget = 
-        new G4LogicalVolume(solidTarget, m_TargetMaterial, "logicTarget");
+    OuterRadius.push_back(m_TargetRadius);
+    Z.push_back(-0.5*m_TargetThickness);
 
-      new G4PVPlacement(0, G4ThreeVector(0, 0, 0), 
-          logicTarget, "Target", m_TargetLogic, false, 0);
+    OuterRadius.push_back(m_BackRadius);
+    Z.push_back(-0.5*m_TargetThickness);
 
-       new G4PVPlacement(0, G4ThreeVector(m_TargetX, m_TargetY, m_TargetZ), 
-          m_TargetLogic, "Target", world, false, 0);
 
-      G4VisAttributes* TargetVisAtt = new G4VisAttributes(G4Colour(0., 0., 1.));
-      logicTarget->SetVisAttributes(TargetVisAtt);
+    // Back Bulge
+    if(m_FrontDeformation!=0){
+      double step = m_BackRadius/size;
+      for(int i = size-1 ; i>=0 ; i--){
+        OuterRadius.push_back(i*step);
+        Z.push_back(BackProfile(i*step,m_TargetThickness*0.5,m_BackDeformation,m_BackRadius));
+      } 
     }
 
 
-    if (m_WindowsThickness > 0) {
-      G4ThreeVector TargetPos = G4ThreeVector(m_TargetX, m_TargetY, m_TargetZ);
+    InnerRadius.resize(Z.size(),0);
+
+    m_CryoTargetSolid = 
+      new G4Polycone("solidTarget", 0, 360*deg,Z.size(),&Z[0],&InnerRadius[0],&OuterRadius[0]);
+
+    m_TargetLogic = 
+      new G4LogicalVolume(m_CryoTargetSolid, 
+          m_TargetMaterial,
+          "logicTarget");
 
-      G4Tubs* solidWindowsF =
-        new G4Tubs("solidTargetWindowsF", 0, m_TargetRadius, 
-            0.5*m_WindowsThickness, 0*deg, 360*deg);
-      G4LogicalVolume* logicWindowsF = 
-        new G4LogicalVolume(solidWindowsF, m_WindowsMaterial, 
-            "logicTargetWindowsF");
+    new G4PVPlacement(0, G4ThreeVector(0, 0, 0), 
+        m_TargetLogic, "Target", world, false, 0);
 
-      G4Tubs* solidWindowsB =
-        new G4Tubs("solidTargetWindowsB", 0, m_TargetRadius, 
-            0.5*m_WindowsThickness, 0*deg, 360*deg);
-      G4LogicalVolume* logicWindowsB = 
-        new G4LogicalVolume(solidWindowsB, m_WindowsMaterial, 
-            "logicTargetWindowsB");
+    G4VisAttributes* TargetVisAtt = new G4VisAttributes(G4Colour(0., 0., 1.));
+    m_TargetLogic->SetVisAttributes(TargetVisAtt);
 
-      new G4PVPlacement(0,
-          TargetPos 
-          +G4ThreeVector(0., 0., 0.5*(m_TargetThickness + m_WindowsThickness)) ,
-          logicWindowsF,"Target Window Front",m_TargetLogic,false, 0);
 
-      new G4PVPlacement(   0,
-          TargetPos + G4ThreeVector(0., 0., -0.5*(m_TargetThickness + m_WindowsThickness)),
-          logicWindowsB,"Target Window Back",m_TargetLogic,false, 0);
+    // Front Window 
+    OuterRadius.clear();
+    InnerRadius.clear();
+    Z.clear();
 
-      G4VisAttributes* WindowsVisAtt = new G4VisAttributes(G4Colour(0.5, 1., 0.5));
-      logicWindowsF->SetVisAttributes(WindowsVisAtt);
-      logicWindowsB->SetVisAttributes(WindowsVisAtt);
+    // Front Bulge
+    if(m_FrontDeformation!=0){
+      double step = m_FrontRadius/size;
+      for(unsigned int i = 0 ; i < size ; i++){
+        InnerRadius.push_back(i*step);
+        OuterRadius.push_back(i*step+m_FrontThickness);
+        Z.push_back(FrontProfile(i*step+m_FrontThickness,m_FrontThickness+m_TargetThickness*0.5,m_FrontDeformation,m_FrontRadius));
+      } 
     }
-  }
 
+    G4Polycone* FrontSolid = 
+      new G4Polycone("solidFront", 0, 360*deg,Z.size(),&Z[0],&InnerRadius[0],&OuterRadius[0]);
+
+    G4LogicalVolume* FrontLogic = 
+      new G4LogicalVolume(FrontSolid, 
+          m_FrontMaterial,
+          "logicFront");
+
+    new G4PVPlacement(0, G4ThreeVector(0, 0, 0), 
+        FrontLogic, "Target", world, false, 0);
+    G4VisAttributes* WindowsVisAtt = new G4VisAttributes(G4Colour(0.5, 0.5, 0.5,0.5));
+    FrontLogic->SetVisAttributes(WindowsVisAtt);
+
+
+    // Back Window 
+    OuterRadius.clear();
+    InnerRadius.clear();
+    Z.clear();
+
+    // Back Bulge
+    if(m_BackDeformation!=0){
+      double step = m_BackRadius/size;
+      for(unsigned int i = 0 ; i < size ; i++){
+        InnerRadius.push_back(i*step);
+        OuterRadius.push_back(i*step+m_BackThickness);
+        Z.push_back(BackProfile(i*step+m_BackThickness,m_BackThickness+m_TargetThickness*0.5,m_BackDeformation,m_BackRadius));
+      } 
+    }
+
+    G4Polycone* BackSolid = 
+      new G4Polycone("solidBack", 0, 360*deg,Z.size(),&Z[0],&InnerRadius[0],&OuterRadius[0]);
+
+    G4LogicalVolume* BackLogic = 
+      new G4LogicalVolume(BackSolid, 
+          m_BackMaterial,
+          "logicBack");
+
+    new G4PVPlacement(0, G4ThreeVector(0, 0, 0), 
+        BackLogic, "Target", world, false, 0);
+
+    BackLogic->SetVisAttributes(WindowsVisAtt);
+
+    // Frame
+    OuterRadius.clear();
+    InnerRadius.clear();
+    Z.clear();
+    double FrontInner = 0.5*(m_FrameThickness-m_TargetThickness) / tan(0.5*M_PI-m_FrontCone);
+    double BackInner  = 0.5*(m_FrameThickness-m_TargetThickness) / tan(0.5*M_PI-m_BackCone);
+
+    Z.push_back(m_FrameThickness*0.5); InnerRadius.push_back(FrontInner+m_FrontRadius); OuterRadius.push_back(m_FrameRadius);
+    Z.push_back(m_TargetThickness*0.5); InnerRadius.push_back(m_FrontRadius); OuterRadius.push_back(m_FrameRadius);
+    Z.push_back(m_TargetThickness*0.5); InnerRadius.push_back(m_TargetRadius); OuterRadius.push_back(m_FrameRadius);
+    Z.push_back(-m_TargetThickness*0.5); InnerRadius.push_back(m_TargetRadius); OuterRadius.push_back(m_FrameRadius);
+    Z.push_back(-m_TargetThickness*0.5); InnerRadius.push_back(m_BackRadius); OuterRadius.push_back(m_FrameRadius);
+    Z.push_back(-m_FrameThickness*0.5); InnerRadius.push_back(BackInner+m_BackRadius); OuterRadius.push_back(m_FrameRadius);
+
+    G4Polycone* FrameSolid = 
+      new G4Polycone("solidFrame", 0, 360*deg,Z.size(),&Z[0],&InnerRadius[0],&OuterRadius[0]);
+
+    G4LogicalVolume* FrameLogic = 
+      new G4LogicalVolume(FrameSolid, 
+          m_FrameMaterial,
+          "logicFrame");
+
+    new G4PVPlacement(0, G4ThreeVector(0, 0, 0), 
+        FrameLogic, "FrameTarget", world, false, 0);
+    G4VisAttributes* FrameVisAtt = new G4VisAttributes(G4Colour(0.3, 0.4, 0.4,1));
+    FrameLogic->SetVisAttributes(FrameVisAtt);
+
+   G4RotationMatrix* Rotation=new G4RotationMatrix();
+    Rotation->rotateX(90*deg);
+
+
+    // Heat Shield
+    G4Tubs* ShieldMain = 
+      new G4Tubs("HeatShieldMain",
+          m_ShieldInnerRadius,m_ShieldOuterRadius,
+          m_ShieldBottomLength+m_ShieldTopLength,
+          0,360);
+
+    G4Tubs* ShieldBack = 
+      new G4Tubs("HeatShieldBack",
+          0,m_ShieldBackRadius,
+          m_ShieldInnerRadius,
+          0,360);
+
+    G4Tubs* ShieldFront = 
+      new G4Tubs("HeatShieldFront",
+          0,m_ShieldFrontRadius,
+          m_ShieldInnerRadius,
+          0,360);
+
+    G4RotationMatrix Rot ;  Rot.rotateX(90*deg);    
+     
+    G4Transform3D transformBack(Rot, G4ThreeVector(0,m_ShieldInnerRadius,-m_ShieldTopLength));
+
+    G4SubtractionSolid* subtraction =
+      new G4SubtractionSolid("Shield-Back", ShieldMain, ShieldBack,transformBack);
+
+    G4Transform3D transformFront(Rot, G4ThreeVector(0,-m_ShieldInnerRadius,-m_ShieldTopLength));
+
+    G4SubtractionSolid* ShieldSolid =
+      new G4SubtractionSolid("Shield-Front", subtraction, ShieldFront,transformFront);
+
+    G4LogicalVolume* ShieldLogic = 
+      new G4LogicalVolume(ShieldSolid, 
+          m_ShieldMaterial,
+          "logicShield");
+
+       new G4PVPlacement(Rotation, G4ThreeVector(0,m_ShieldTopLength, 0), 
+        ShieldLogic, "ShieldTarget", world, false, 0);
+    G4VisAttributes* ShieldVisAtt = new G4VisAttributes(G4Colour(0.7, 0.9, 0.9,0.5));
+    ShieldLogic->SetVisAttributes(ShieldVisAtt);
+
+
+  }
 }
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+void Target::SetReactionRegion(){
+  if(!m_ReactionRegion){
+    m_ReactionRegion= new G4Region("NPSimulationProcess");
+    m_ReactionRegion->AddRootLogicalVolume(m_TargetLogic);
+    m_ReactionRegion->SetUserLimits(new G4UserLimits(m_TargetThickness/10.)); 
+  }
+
+  G4FastSimulationManager* mng = m_ReactionRegion->GetFastSimulationManager();
+
+  unsigned int size = m_ReactionModel.size();
+  for(unsigned int i = 0 ; i < size ; i++)
+    mng->RemoveFastSimulationModel(m_ReactionModel[i]);
+
+  m_ReactionModel.clear();
+  G4VFastSimulationModel* fsm;
+  fsm = new NPS::BeamReaction("BeamReaction",m_ReactionRegion);
+  ((NPS::BeamReaction*) fsm)->SetStepSize(m_TargetThickness/10.);
+  m_ReactionModel.push_back(fsm); 
+  fsm = new NPS::Decay("Decay",m_ReactionRegion);
+  m_ReactionModel.push_back(fsm); 
+
+} 
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 // Add Detector branch to the EventTree.
@@ -283,10 +499,10 @@ G4double Target::SlowDownBeam(G4ParticleDefinition* Beam,
 
   else{
     //   Windows
-    if(m_WindowsThickness!=0)
+    if(m_FrontThickness!=0)
       for (G4int i = 0; i < m_TargetNbLayers; i++){
-        dedx = emCalculator.ComputeTotalDEDX(IncidentEnergy, Beam, m_WindowsMaterial);
-        de   = dedx  * m_WindowsThickness / (cos(IncidentTheta)* m_TargetNbLayers);
+        dedx = emCalculator.ComputeTotalDEDX(IncidentEnergy, Beam, m_FrontMaterial);
+        de   = dedx  * m_FrontThickness / (cos(IncidentTheta)* m_TargetNbLayers);
         IncidentEnergy -= de;
         if(IncidentEnergy<0){
           IncidentEnergy = 0;
diff --git a/NPSimulation/Core/Target.hh b/NPSimulation/Core/Target.hh
index 833243887047c596dc17dc4e0c70219bf8826f97..8dee4b73c73ad951ab8e9932404287d6b8212d13 100644
--- a/NPSimulation/Core/Target.hh
+++ b/NPSimulation/Core/Target.hh
@@ -37,11 +37,13 @@
 #include "G4Event.hh"
 #include "G4Material.hh"
 #include "G4Tubs.hh"
+#include "G4Polycone.hh"
 #include "G4LogicalVolume.hh"
-
+#include "G4VFastSimulationModel.hh"
 // NPTool headers
 #include "NPSVDetector.hh"
 #include "NPInputParser.h"
+#include "NPFunction.h"
 using namespace std;
 using namespace CLHEP;
 
@@ -112,15 +114,47 @@ private:
   G4int       m_TargetNbLayers;
   
   // For Cryo Target
+  // this fonction generate a deformed target window shape
+//  inline double FrontProfile(double x, double offset, double b, double R) {return (offset+b+1)- cosh(x/(R/acosh(b+1)));}
+//  inline double BackProfile(double x, double offset, double b, double R)  {return   cosh(x/(R/acosh(b+1)))-(offset+b+1);}
+  inline double FrontProfile(double x, double offset, double b, double R) {return NPL::HyperbolicProfile(x,offset,b,R);}
+  inline double BackProfile(double x, double offset, double b, double R)  {return -NPL::HyperbolicProfile(x,offset,b,R);}
+
+
   G4double    m_TargetDensity;
-  G4double    m_WindowsThickness;
-  G4Material* m_WindowsMaterial;
-  
+  double      m_FrontDeformation;
+  double      m_FrontThickness;
+  double      m_FrontRadius;
+  G4Material* m_FrontMaterial;
+  double      m_BackDeformation;
+  double      m_BackRadius;
+  double      m_BackThickness;
+  G4Material* m_BackMaterial;
+  double      m_FrameRadius;
+  double      m_FrameThickness;
+  double      m_FrontCone;
+  double      m_BackCone;
+  G4Material* m_FrameMaterial;
+  double      m_ShieldInnerRadius;
+  double      m_ShieldOuterRadius;
+  double      m_ShieldBottomLength;
+  double      m_ShieldTopLength;
+  double      m_ShieldFrontRadius; 
+  double      m_ShieldBackRadius;
+  G4Material* m_ShieldMaterial;
+  G4Polycone*  m_CryoTargetSolid; 
   // Positioning
   G4double    m_TargetX;
   G4double    m_TargetY;
   G4double    m_TargetZ;
 
+public: // Region were reaction can occure
+  void SetReactionRegion();  
+ 
+private:
+  // Region were reaction can occure:
+  G4Region* m_ReactionRegion;
+  vector<G4VFastSimulationModel*> m_ReactionModel;
   // Pointer to the last target generated (0 if none)
   private:
     static Target*  TargetInstance ;
diff --git a/NPSimulation/Detectors/Chio/Chio.cc b/NPSimulation/Detectors/Chio/Chio.cc
index a02d0cdee388aa7bf2cb7180891552ee83eccdc0..4d6f446f893258209ff32d737562bcf3e30b8575 100644
--- a/NPSimulation/Detectors/Chio/Chio.cc
+++ b/NPSimulation/Detectors/Chio/Chio.cc
@@ -148,12 +148,13 @@ G4LogicalVolume* Chio::BuildDetector(){
     G4Material* Fe= MaterialManager::getInstance()->GetMaterialFromLibrary("Fe");
     G4Material* Al= MaterialManager::getInstance()->GetMaterialFromLibrary("Al");
 
-    G4Material* CF4= MaterialManager::getInstance()->GetGasFromLibrary("CF4",0.0693276*bar,273.15*kelvin);
+    //G4Material* CF4= MaterialManager::getInstance()->GetGasFromLibrary("CF4",0.0693276*bar,273.15*kelvin);
+    G4Material* CF4= MaterialManager::getInstance()->GetGasFromLibrary("iC4H10",8.*bar/1000.,273.15*kelvin);
+
     G4Material* Mylar= MaterialManager::getInstance()->GetMaterialFromLibrary("Mylar");
 
     G4MaterialPropertiesTable* MPT = new G4MaterialPropertiesTable();      
     MPT->AddConstProperty("DE_PAIRENERGY",30*eV);
-    MPT->AddConstProperty("DE_YIELD",1e-2);
     //  MPT->AddConstProperty("DE_AMPLIFICATION",1e4);
     MPT->AddConstProperty("DE_ABSLENGTH",1*pc);
     MPT->AddConstProperty("DE_DRIFTSPEED",11*cm/microsecond);
@@ -181,7 +182,7 @@ G4LogicalVolume* Chio::BuildDetector(){
         logicGas,
         "ChioGas",m_SquareDetector,false,0);
 
-    new G4PVPlacement(G4Transform3D(*Rot,G4ThreeVector(-2.5*cm,0,0)),
+    new G4PVPlacement(G4Transform3D(*Rot,G4ThreeVector(2.5*cm,0,0)),
         logicGrid,
         "ChioGrid",logicGas,false,0);
 
diff --git a/NPSimulation/Detectors/Plastic/Plastic.cc b/NPSimulation/Detectors/Plastic/Plastic.cc
index ec9b2c7d063fb9e9c10fd00abdc46eae5f6f300e..1eeb8c92be4cc0f59a1da55e15a5732586d07ff2 100644
--- a/NPSimulation/Detectors/Plastic/Plastic.cc
+++ b/NPSimulation/Detectors/Plastic/Plastic.cc
@@ -404,22 +404,25 @@ void Plastic::ReadSensitive(const G4Event* event){
   G4int sizeN = DetectorNumberHitMap->entries()    ;
   G4int sizeE = EnergyHitMap->entries()          ;
   G4int sizeT = TimeHitMap->entries()          ;
+  vector<double> energy;
+    vector<double> time;
+    vector<int>    det;
+
+
 
   // Loop on Plastic Number
   for (G4int l = 0 ; l < sizeN ; l++) {
     G4int N     =      *(DetectorNumber_itr->second)    ;
     G4int NTrackID  =   DetectorNumber_itr->first - N  ;
-
-
-    if (N > 0) {
-      m_Event->SetPlasticNumber(N) ;
+      if (N > 0) {
+      det.push_back(N);
       //  Energy
       Energy_itr = EnergyHitMap->GetMap()->begin();
       for (G4int h = 0 ; h < sizeE ; h++) {
         G4int ETrackID  =   Energy_itr->first  - N      ;
         G4double E     = *(Energy_itr->second)         ;
         if (ETrackID == NTrackID) {
-          m_Event->SetEnergy(RandGauss::shoot(E, E*ResoEnergy/100./2.35))    ;
+          energy.push_back(RandGauss::shoot(E, E*ResoEnergy/100./2.35))    ;
         }
         Energy_itr++;
       }
@@ -431,7 +434,7 @@ void Plastic::ReadSensitive(const G4Event* event){
         G4int TTrackID  =   Time_itr->first   - N    ;
         G4double T     = *(Time_itr->second)      ;
         if (TTrackID == NTrackID) {
-          m_Event->SetTime(RandGauss::shoot(T, ResoTime)) ;
+          time.push_back(RandGauss::shoot(T, ResoTime)) ;
         }
         Time_itr++;
       }
@@ -481,9 +484,13 @@ void Plastic::ReadSensitive(const G4Event* event){
       }
 
     }
-
     DetectorNumber_itr++;
   }
+ unsigned int size=energy.size();
+ for(unsigned int i = 0 ; i < size ; i++){
+   m_Event->SetEnergyAndTime(det[i],energy[i],time[i]);
+   }
+
 
   // clear map for next event
   TimeHitMap->clear()   ;
diff --git a/NPSimulation/Detectors/TRex/TRex.cc b/NPSimulation/Detectors/TRex/TRex.cc
index 5908162cf760b6dcf4fb71b7462b19698ba0003b..f8c0376c0a0a0ffaae3b1d31804af06b5920b676 100644
--- a/NPSimulation/Detectors/TRex/TRex.cc
+++ b/NPSimulation/Detectors/TRex/TRex.cc
@@ -134,7 +134,7 @@ G4LogicalVolume* TRex::BuildChamber(){
       cout << "TRex geometry is based on Munich Group Simulation exported in GDML"<< endl;
       string basepath = getenv("NPTOOL");
       string path=basepath+"/NPSimulation/Detectors/TRex/TRex_Miniball.gdml";
-      m_gdmlparser.Read(path);
+      m_gdmlparser.Read(path,false);
     }
     m_Chamber= m_gdmlparser.GetVolume("chamber_log");
   }
diff --git a/NPSimulation/EventGenerator/EventGeneratorBeam.cc b/NPSimulation/EventGenerator/EventGeneratorBeam.cc
index c6b67dc1f74bc6c516f6ab2e6516f7d81168f5ea..748fa663713a2de716f2c4edf0685262abf71866 100644
--- a/NPSimulation/EventGenerator/EventGeneratorBeam.cc
+++ b/NPSimulation/EventGenerator/EventGeneratorBeam.cc
@@ -55,9 +55,8 @@ EventGeneratorBeam::~EventGeneratorBeam(){
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 void   EventGeneratorBeam::SetTarget(Target* Target){
-  if(Target!=0){
+  if(Target!=0)
     m_Target = Target;
-  }
   
   // Set the target parameter for the internal event generator of m_Beam
   m_Beam->SetTargetSize(m_Target->GetTargetRadius());
@@ -75,12 +74,12 @@ void EventGeneratorBeam::GenerateEvent(G4Event* anEvent){
 
   if( anEvent->GetEventID()==0){
     // Define the particle to be shoot
-    if(m_Beam->GetZ()==0 &&  m_Beam->GetA()==1){
+    if(m_Beam->GetZ()==0 &&  m_Beam->GetA()==1)
       m_particle = G4ParticleTable::GetParticleTable()->FindParticle("neutron");
-    }
    
     else
-      m_particle = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIon(m_Beam->GetZ(), m_Beam->GetA() ,m_Beam->GetExcitationEnergy());
+      m_particle = 
+        G4ParticleTable::GetParticleTable()->GetIonTable()->GetIon(m_Beam->GetZ(), m_Beam->GetA() ,m_Beam->GetExcitationEnergy());
 
   }
   
@@ -89,28 +88,23 @@ void EventGeneratorBeam::GenerateEvent(G4Event* anEvent){
   ///// of interaction in target and Energy Loss of the beam within /////
   ///// the target.                                                 /////
   ///////////////////////////////////////////////////////////////////////
-  G4ThreeVector InterCoord;
+  //G4ThreeVector InterCoord;
   
-  G4double Beam_theta, Beam_phi, FinalBeamEnergy, InitialBeamEnergy, x0, y0, z0, Beam_thetaX, Beam_phiY;
+  double InitialBeamEnergy, x0, y0, z0, Beam_thetaX, Beam_phiY;
 
   m_Beam->GenerateRandomEvent(InitialBeamEnergy, x0, y0, z0, Beam_thetaX, Beam_phiY);
   //Set the direction cosines: alpha=90-Beam_thetaX, beta=90-Beam_phiY
-  G4double Xdir = sin(Beam_thetaX); // cos(90-x) = sin(x)
-  G4double Ydir = sin(Beam_phiY); 
-  G4double Zdir = sqrt(1-Xdir*Xdir-Ydir*Ydir); // alpha^2 + beta^2 + gamma^2 = 1
+  double Xdir = sin(Beam_thetaX); // cos(90-x) = sin(x)
+  double Ydir = sin(Beam_phiY); 
+  double Zdir = sqrt(1-Xdir*Xdir-Ydir*Ydir); // alpha^2 + beta^2 + gamma^2 = 1
   G4ThreeVector BeamDir(Xdir,Ydir,Zdir);
   G4ThreeVector BeamPos(x0,y0,z0);
-  Beam_theta = BeamDir.theta()    ;
-  Beam_phi   = BeamDir.phi()      ; Beam_phi *= 1;
-  FinalBeamEnergy = m_Target->SlowDownBeam(m_particle, InitialBeamEnergy,z0-m_Beam->GetTargetZ(),Beam_theta);
-  if(FinalBeamEnergy<0 || FinalBeamEnergy!=FinalBeamEnergy)
-    FinalBeamEnergy=0;
   ///////////////////////////////////////////////////////
   ///// Add the Beam particle to the particle Stack /////
   ///////////////////////////////////////////////////////
   Particle BeamParticle( m_particle,
                         InitialBeamEnergy,
-                        FinalBeamEnergy,
+                        InitialBeamEnergy,
                         BeamDir.unit(),
                         BeamPos,
                         1);
diff --git a/NPSimulation/EventGenerator/EventGeneratorGammaDecay.cc b/NPSimulation/EventGenerator/EventGeneratorGammaDecay.cc
index d7d7471ce6c8352707168fc2d483e16e6a9e7901..af815fab7e4fc5eded5ac4fa081b5e88b1e457fa 100644
--- a/NPSimulation/EventGenerator/EventGeneratorGammaDecay.cc
+++ b/NPSimulation/EventGenerator/EventGeneratorGammaDecay.cc
@@ -89,7 +89,8 @@ void EventGeneratorGammaDecay::ReadConfiguration(NPL::InputParser parser){
     else
       AddCascade(E, BranchingRatio);
   }
-PrepareCascade();
+  
+  PrepareCascade();
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
diff --git a/NPSimulation/Process/BeamReaction.cc b/NPSimulation/Process/BeamReaction.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5798ec4daa09f26e2649db1f8d8f2f713a56f85b
--- /dev/null
+++ b/NPSimulation/Process/BeamReaction.cc
@@ -0,0 +1,302 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2016   this file is part of the NPTool Project         *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
+ *                                                                           *
+ * Creation Date  : Octobre 2017                                             *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ * Use to kill the beam track and replace it with the reaction product       *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+
+#include <iostream>
+#include <string>
+#include "NPFunction.h"
+#include "RootOutput.h"
+#include "BeamReaction.hh"
+#include "NPOptionManager.h"
+#include "NPInputParser.h"
+#include "G4VPhysicalVolume.hh"
+#include "G4Electron.hh"
+#include "G4Gamma.hh"
+#include "G4SystemOfUnits.hh"
+////////////////////////////////////////////////////////////////////////////////
+NPS::BeamReaction::BeamReaction(G4String modelName,G4Region* envelope) :
+  G4VFastSimulationModel(modelName, envelope) {
+    ReadConfiguration();
+    m_PreviousEnergy=0 ;
+    m_PreviousLength=0 ;
+    m_active = true;
+    m_ReactionConditions = new TReactionConditions();
+    AttachReactionConditions();
+    if(!RootOutput::getInstance()->GetTree()->FindBranch("ReactionConditions"))
+      RootOutput::getInstance()->GetTree()->Branch("ReactionConditions","TReactionConditions",&m_ReactionConditions);
+  }
+
+
+////////////////////////////////////////////////////////////////////////////////
+NPS::BeamReaction::BeamReaction(G4String modelName) :
+  G4VFastSimulationModel(modelName) {
+  }
+
+////////////////////////////////////////////////////////////////////////////////
+NPS::BeamReaction::~BeamReaction() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void NPS::BeamReaction::AttachReactionConditions(){
+    // Reasssigned the branch address
+    if(RootOutput::getInstance()->GetTree()->FindBranch("ReactionConditions"))
+        RootOutput::getInstance()->GetTree()->SetBranchAddress("ReactionConditions",&m_ReactionConditions);
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+void NPS::BeamReaction::ReadConfiguration(){
+  NPL::InputParser input(NPOptionManager::getInstance()->GetReactionFile());
+  m_Reaction.ReadConfigurationFile(input);
+  m_BeamName=NPL::ChangeNameToG4Standard(m_Reaction.GetNucleus1().GetName());
+  if(m_Reaction.GetNucleus3().GetName()!=""){
+    m_active = true;
+  }
+  else{
+    m_active = false;
+
+  }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+G4bool NPS::BeamReaction::IsApplicable( const G4ParticleDefinition& particleType) {
+  if(!m_active)
+    return false;
+
+  static std::string particleName;
+  particleName = particleType.GetParticleName();
+  if (particleName.find(m_BeamName)!=std::string::npos) {
+    return true;
+  }
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+G4bool NPS::BeamReaction::ModelTrigger(const G4FastTrack& fastTrack) {
+  //static bool shoot = false;
+  static double rand = 0;
+  const G4Track* PrimaryTrack = fastTrack.GetPrimaryTrack();   
+  G4ThreeVector V = PrimaryTrack->GetMomentum().unit();
+  G4ThreeVector P = fastTrack.GetPrimaryTrackLocalPosition();
+  G4VSolid* solid = 
+    fastTrack.GetPrimaryTrack()->GetVolume()->GetLogicalVolume()->GetSolid();
+  double in = solid->DistanceToOut(P,V);
+  double out = solid->DistanceToOut(P,-V);
+  double ratio  = in / (out+in) ; 
+  
+  if(out == 0){// first step of current event
+      rand = G4RandFlat::shoot();
+      m_PreviousLength = m_StepSize ;
+      m_PreviousEnergy = PrimaryTrack->GetKineticEnergy() ;
+    }
+
+  else if(in==0){// last step
+    return true;
+    }
+
+  // If the condition is met, the event is generated 
+  if(ratio<rand){ 
+    // Reset the static for next event
+    //  shoot = false;
+    if(m_Reaction.IsAllowed(PrimaryTrack->GetKineticEnergy())){
+      return true;
+      
+      }
+    else{
+      return false;
+      }
+  }
+
+  // Record the situation of the current step
+  // so it can be used in the next one
+  if(!PrimaryTrack->GetStep()->IsLastStepInVolume()){
+    m_PreviousLength = PrimaryTrack->GetStep()->GetStepLength(); 
+    m_PreviousEnergy = PrimaryTrack->GetKineticEnergy();
+  }
+
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void NPS::BeamReaction::DoIt(const G4FastTrack& fastTrack,G4FastStep& fastStep) {
+    
+    m_ReactionConditions->Clear();
+    
+    // Get the track info
+    const G4Track* PrimaryTrack = fastTrack.GetPrimaryTrack();
+    G4ThreeVector pdirection = PrimaryTrack->GetMomentum().unit();
+    G4ThreeVector localdir = fastTrack.GetPrimaryTrackLocalDirection();
+    
+    G4ThreeVector worldPosition = PrimaryTrack->GetPosition();
+    G4ThreeVector localPosition = fastTrack.GetPrimaryTrackLocalPosition();
+    
+    double energy = PrimaryTrack->GetKineticEnergy();
+    double time = PrimaryTrack->GetGlobalTime();
+    
+    // Randomize within the step
+    // Assume energy loss is linear within the step
+    // Assume no scattering
+    double rand =  G4RandFlat::shoot();
+    double length = rand*(m_PreviousLength);
+    energy += (1-rand)*(m_PreviousEnergy-energy);
+    G4ThreeVector ldir = pdirection;
+    ldir*=length;
+    localPosition = localPosition - ldir;
+    // Set the end of the step conditions
+    fastStep.SetPrimaryTrackFinalKineticEnergyAndDirection(0,pdirection);
+    fastStep.SetPrimaryTrackFinalPosition(worldPosition);
+    fastStep.SetTotalEnergyDeposited(0);
+    fastStep.SetPrimaryTrackFinalTime (time);
+    fastStep.KillPrimaryTrack();
+    fastStep.SetPrimaryTrackPathLength(0.0);
+    
+    //////////////////////////////////////////////////
+    //////Define the kind of particle to shoot////////
+    //////////////////////////////////////////////////
+    
+    // Nucleus 3
+    int LightZ = m_Reaction.GetNucleus3().GetZ() ;
+    int LightA = m_Reaction.GetNucleus3().GetA() ;
+    static G4IonTable* IonTable = G4ParticleTable::GetParticleTable()->GetIonTable();
+    
+    G4ParticleDefinition* LightName
+    = IonTable->GetIon(LightZ, LightA, m_Reaction.GetExcitation3()*MeV);
+    
+    // Nucleus 4
+    G4int HeavyZ = m_Reaction.GetNucleus4().GetZ() ;
+    G4int HeavyA = m_Reaction.GetNucleus4().GetA() ;
+    
+    // Generate the excitation energy if a distribution is given
+    m_Reaction.ShootRandomExcitationEnergy();
+    
+    // Use to clean up the IonTable in case of the Ex changing at every event
+    G4ParticleDefinition* HeavyName
+    = IonTable->GetIon(HeavyZ, HeavyA, m_Reaction.GetExcitation4()*MeV);
+    // Set the Energy of the reaction
+    m_Reaction.SetBeamEnergy(energy);
+    
+    double Beam_theta = pdirection.theta();
+    double Beam_phi = pdirection.phi();
+    
+    ///////////////////////////
+    ///// Beam Parameters /////
+    ///////////////////////////
+    m_ReactionConditions->SetBeamParticleName(PrimaryTrack->GetParticleDefinition()->GetParticleName());
+
+    m_ReactionConditions->SetBeamReactionEnergy(energy);
+    m_ReactionConditions->SetVertexPositionX(localPosition.x());
+    m_ReactionConditions->SetVertexPositionY(localPosition.y());
+    m_ReactionConditions->SetVertexPositionZ(localPosition.z());
+    
+    G4ThreeVector U(1,0,0);
+    G4ThreeVector V(0,1,0);
+    
+    m_ReactionConditions->SetBeamEmittanceTheta(PrimaryTrack->GetMomentumDirection().theta()/deg);
+    m_ReactionConditions->SetBeamEmittancePhi(PrimaryTrack->GetMomentumDirection().phi()/deg);
+    m_ReactionConditions->SetBeamEmittanceThetaX(PrimaryTrack->GetMomentumDirection().angle(U)/deg);
+    m_ReactionConditions->SetBeamEmittancePhiY(PrimaryTrack->GetMomentumDirection().angle(V)/deg);
+    
+    //////////////////////////////////////////////////////////
+    ///// Build rotation matrix to go from the incident //////
+    ///// beam frame to the "world" frame               //////
+    //////////////////////////////////////////////////////////
+    G4ThreeVector col1(cos(Beam_theta) * cos(Beam_phi),
+                       cos(Beam_theta) * sin(Beam_phi),
+                       -sin(Beam_theta));
+    G4ThreeVector col2(-sin(Beam_phi),
+                       cos(Beam_phi),
+                       0);
+    G4ThreeVector col3(sin(Beam_theta) * cos(Beam_phi),
+                       sin(Beam_theta) * sin(Beam_phi),
+                       cos(Beam_theta));
+    G4RotationMatrix BeamToWorld(col1, col2, col3);
+    
+    /////////////////////////////////////////////////////////////////
+    ///// Angles for emitted particles following Cross Section //////
+    ///// Angles are in the beam frame                         //////
+    /////////////////////////////////////////////////////////////////
+    
+    // Angles
+    // Shoot and Set a Random ThetaCM
+    m_Reaction.ShootRandomThetaCM();
+    double phi     = RandFlat::shoot() * 2. * pi;
+    
+    //////////////////////////////////////////////////
+    /////  Momentum and angles from  kinematics  /////
+    /////  Angles are in the beam frame          /////
+    //////////////////////////////////////////////////
+    // Variable where to store results
+    double Theta3, Energy3, Theta4, Energy4;
+    
+    // Compute Kinematic using previously defined ThetaCM
+    m_Reaction.KineRelativistic(Theta3, Energy3, Theta4, Energy4);
+    // Momentum in beam frame for light particle
+    G4ThreeVector momentum_kine3_beam(sin(Theta3) * cos(phi),
+                                      sin(Theta3) * sin(phi),
+                                      cos(Theta3));
+    // Momentum in World frame
+    G4ThreeVector momentum_kine3_world = BeamToWorld * momentum_kine3_beam;
+    
+    
+    // Momentum in beam frame for heavy particle
+    G4ThreeVector momentum_kine4_beam(sin(Theta4) * cos(phi+pi),
+                                      sin(Theta4) * sin(phi+pi),
+                                      cos(Theta4));
+    // Momentum in World frame
+    G4ThreeVector momentum_kine4_world = BeamToWorld * momentum_kine4_beam;
+    
+    
+    // Emitt secondary
+    G4DynamicParticle particle3(LightName,momentum_kine3_world,Energy3);
+    fastStep.CreateSecondaryTrack(particle3, localPosition, time);
+    
+    G4DynamicParticle particle4(HeavyName,momentum_kine4_world,Energy4);
+    fastStep.CreateSecondaryTrack(particle4, localPosition, time);
+    
+    // Reinit for next event
+    m_PreviousEnergy=0 ;
+    m_PreviousLength=0 ;
+    
+    ///////////////////////////////////////
+    ///// Emitted particle Parameters /////
+    ///////////////////////////////////////
+    // Names 3 and 4//
+    m_ReactionConditions->SetParticleName(LightName->GetParticleName());
+    m_ReactionConditions->SetParticleName(HeavyName->GetParticleName());
+    // Angle 3 and 4 //
+    m_ReactionConditions->SetTheta(Theta3/deg);
+    m_ReactionConditions->SetTheta(Theta4/deg);
+    // Energy 3 and 4 //
+    m_ReactionConditions->SetKineticEnergy(Energy3);
+    m_ReactionConditions->SetKineticEnergy(Energy4);
+    // ThetaCM //
+    m_ReactionConditions->SetThetaCM(m_Reaction.GetThetaCM()/deg);
+    // Momuntum X 3 and 4 //
+    m_ReactionConditions->SetMomentumDirectionX(momentum_kine3_world.x());
+    m_ReactionConditions->SetMomentumDirectionX(momentum_kine4_world.x());
+    // Momuntum Y 3 and 4 //
+    m_ReactionConditions->SetMomentumDirectionY(momentum_kine3_world.y());
+    m_ReactionConditions->SetMomentumDirectionY(momentum_kine4_world.y());
+    // Momuntum Z 3 and 4 //
+    m_ReactionConditions->SetMomentumDirectionZ(momentum_kine3_world.z());
+    m_ReactionConditions->SetMomentumDirectionZ(momentum_kine4_world.z());
+}
diff --git a/NPSimulation/Process/BeamReaction.hh b/NPSimulation/Process/BeamReaction.hh
new file mode 100644
index 0000000000000000000000000000000000000000..cb81602f18eb28cde9f4fcbd6af5d146f307e288
--- /dev/null
+++ b/NPSimulation/Process/BeamReaction.hh
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2016   this file is part of the NPTool Project         *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
+ *                                                                           *
+ * Creation Date  : Octobre 2017                                             *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ * Use to kill the beam track and replace it with the reaction product       *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+
+#ifndef BeamReaction_h
+#define BeamReaction_h
+
+#include "G4VFastSimulationModel.hh"
+#include "PhysicsList.hh"
+#include "NPReaction.h"
+#include "TReactionConditions.h"
+class G4VPhysicalVolume;
+namespace NPS{
+  class BeamReaction : public G4VFastSimulationModel{
+    public:
+      BeamReaction (G4String, G4Region*);
+      BeamReaction (G4String);
+      ~BeamReaction ();
+
+    public:
+      void ReadConfiguration();
+      G4bool IsApplicable(const G4ParticleDefinition&);
+      G4bool ModelTrigger(const G4FastTrack &);
+      void DoIt(const G4FastTrack&, G4FastStep&);
+ 
+    private:
+      NPL::Reaction m_Reaction;
+      string m_BeamName;
+      double m_PreviousEnergy;
+      double m_PreviousLength;
+      bool   m_active;// is the process active
+      double m_StepSize;
+   
+   private:
+     TReactionConditions* m_ReactionConditions;
+ 
+   public:
+    void AttachReactionConditions();
+    void SetStepSize(double step){m_StepSize=step;};
+  };
+}
+
+
+#endif 
diff --git a/NPSimulation/Process/CMakeLists.txt b/NPSimulation/Process/CMakeLists.txt
index c5e28e4e2f7c60cba71dbd956e9d1550ef8fcd9d..8eeaa7c33b1b4340c1310f6da12e229c50e85bf5 100644
--- a/NPSimulation/Process/CMakeLists.txt
+++ b/NPSimulation/Process/CMakeLists.txt
@@ -1,2 +1,2 @@
-add_library(NPSProcess SHARED  FastDriftElectron.cc NPIonIonInelasticPhysic.cc PhysicsList.cc G4DriftElectron.cc G4IonizationWithDE.cc G4DriftElectronPhysics.cc G4DEAbsorption.cc G4DEAmplification.cc G4DETransport.cc )
-target_link_libraries(NPSProcess ${ROOT_LIBRARIES} ${Geant4_LIBRARIES} ${NPLib_LIBRARIES} -lNPInitialConditions -lNPInteractionCoordinates)
+add_library(NPSProcess SHARED Decay.cc BeamReaction.cc FastDriftElectron.cc NPIonIonInelasticPhysic.cc PhysicsList.cc G4DriftElectron.cc G4IonizationWithDE.cc G4DriftElectronPhysics.cc G4DEAbsorption.cc G4DEAmplification.cc G4DETransport.cc )
+target_link_libraries(NPSProcess ${ROOT_LIBRARIES} ${Geant4_LIBRARIES} ${NPLib_LIBRARIES} -lNPInitialConditions -lNPInteractionCoordinates -lNPReactionConditions)
diff --git a/NPSimulation/Process/Decay.cc b/NPSimulation/Process/Decay.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bfd7ee212ffc083712e4f466a68c5292ae593e67
--- /dev/null
+++ b/NPSimulation/Process/Decay.cc
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2016   this file is part of the NPTool Project         *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
+ *                                                                           *
+ * Creation Date  : Octobre 2017                                             *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ * Use to kill the beam track and replace it with the reaction product       *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+
+#include <iostream>
+#include <string>
+#include <set>
+#include "NPFunction.h"
+#include "Decay.hh"
+#include "NPOptionManager.h"
+#include "NPInputParser.h"
+#include "G4VPhysicalVolume.hh"
+#include "G4Electron.hh"
+#include "G4Gamma.hh"
+#include "G4SystemOfUnits.hh"
+#include "G4ParticleTable.hh"
+#include "G4IonTable.hh"
+
+
+using namespace NPS;
+////////////////////////////////////////////////////////////////////////////////
+Decay::Decay(G4String modelName,G4Region* envelope) :
+  G4VFastSimulationModel(modelName, envelope) {
+    ReadConfiguration();
+    m_PreviousEnergy=0 ;
+    m_PreviousLength=0 ;
+  }
+
+
+////////////////////////////////////////////////////////////////////////////////
+Decay::Decay(G4String modelName) :
+  G4VFastSimulationModel(modelName) {
+  }
+
+////////////////////////////////////////////////////////////////////////////////
+Decay::~Decay() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Decay::ReadConfiguration(){
+  NPL::InputParser input(NPOptionManager::getInstance()->GetReactionFile());
+  m_Decay.ReadConfiguration(input);
+  std::set<std::string> Mother = m_Decay.GetAllMotherName();
+  std::set<std::string>::iterator it ;
+  for(it = Mother.begin() ; it != Mother.end() ; it++)
+    m_MotherName.insert(NPL::ChangeNameToG4Standard(*it));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+G4bool Decay::IsApplicable( const G4ParticleDefinition& particleType) {
+  m_CurrentName = particleType.GetParticleName();
+  // Extract Ex from name
+  if(m_CurrentName.find("[")!=std::string::npos)
+    m_ExcitationEnergy = atof(m_CurrentName.substr(m_CurrentName.find("[")+1,m_CurrentName.find("]")-1).c_str())*keV;
+  else
+    m_ExcitationEnergy=0;
+
+
+  // Strip name from excitation energy
+  m_CurrentName = m_CurrentName.substr(0,m_CurrentName.find("["));
+  // If the decay exist
+   if (m_MotherName.find(m_CurrentName)!=m_MotherName.end()) {
+    return true;
+  }
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+G4bool Decay::ModelTrigger(const G4FastTrack& ) {
+  //FIXME: Solve the issue of long lived decay
+  // Check that a decay is possible:
+  return m_Decay.AnyAboveThreshold(NPL::ChangeNameFromG4Standard(m_CurrentName),m_ExcitationEnergy);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Decay::DoIt(const G4FastTrack& fastTrack,G4FastStep& fastStep){
+  // Get the track info
+  const G4Track* PrimaryTrack = fastTrack.GetPrimaryTrack();
+  G4ThreeVector pdirection = PrimaryTrack->GetMomentum().unit();
+  G4ThreeVector localdir = fastTrack.GetPrimaryTrackLocalDirection();
+
+  G4ThreeVector worldPosition = PrimaryTrack->GetPosition();
+  G4ThreeVector localPosition = fastTrack.GetPrimaryTrackLocalPosition();
+
+  double energy = PrimaryTrack->GetKineticEnergy();
+  double time = PrimaryTrack->GetGlobalTime();
+
+  // Randomize within the step
+  // Assume energy loss is linear within the step
+  // Assume no scattering
+  double rand =  G4RandFlat::shoot(); 
+  double length = rand*(m_PreviousLength); 
+  energy += (1-rand)*(m_PreviousEnergy-energy); 
+  G4ThreeVector ldir = pdirection;
+  ldir*=length;
+  localPosition = localPosition - ldir; 
+  //////////////////////////////////////////////////
+  //////Define the kind of particle to shoot////////
+  //////////////////////////////////////////////////
+  std::vector<NPL::Nucleus> Daughter;
+  std::vector<double> Ex;
+  std::vector<double> DEK;
+  std::vector<double> DPx;
+  std::vector<double> DPy;
+  std::vector<double> DPz;
+
+  m_Decay.GenerateEvent(NPL::ChangeNameFromG4Standard(m_CurrentName),m_ExcitationEnergy,energy,
+      pdirection.x(),pdirection.y(),pdirection.z(),
+      Daughter, Ex,DEK,DPx,DPy,DPz);
+
+ 
+  G4ParticleDefinition* DaughterDef; 
+  unsigned int size = Daughter.size();
+  if(size == 0)
+    return;
+  for(unsigned int i = 0 ; i < size ; i++){
+    // Get the decaying particle
+    int DaughterZ = Daughter[i].GetZ();
+    int DaughterA = Daughter[i].GetA();
+    DaughterDef=NULL;
+
+    // neutral particle
+    if(DaughterZ==0){
+      if(DaughterA==1)
+        DaughterDef=G4ParticleTable::GetParticleTable()->FindParticle("neutron");
+     
+      else if(DaughterA==0){
+        DaughterDef=G4ParticleTable::GetParticleTable()->FindParticle("gamma");
+        }
+
+    }
+    // proton
+    else if (DaughterZ==1 && DaughterA==1 )
+      DaughterDef=G4ParticleTable::GetParticleTable()->FindParticle("proton");
+    // the rest
+    else
+      DaughterDef=G4ParticleTable::GetParticleTable()->GetIonTable()->GetIon(DaughterZ, DaughterA, Ex[i]);
+
+    // Set the momentum direction
+    G4ThreeVector Momentum (DPx[i],DPy[i],DPz[i]);
+    Momentum=Momentum.unit();
+      
+    G4DynamicParticle DynamicDaughter(DaughterDef,Momentum,DEK[i]);
+    fastStep.CreateSecondaryTrack(DynamicDaughter, localPosition, time);
+  }
+  if(size){
+    // Set the end of the step conditions
+    fastStep.SetPrimaryTrackFinalKineticEnergyAndDirection(0,pdirection);
+    fastStep.SetPrimaryTrackFinalPosition(worldPosition);  
+    fastStep.SetTotalEnergyDeposited(0);
+    fastStep.SetPrimaryTrackFinalTime (time);
+    fastStep.KillPrimaryTrack();
+    fastStep.SetPrimaryTrackPathLength(0.0);
+    }
+}
diff --git a/NPSimulation/Process/Decay.hh b/NPSimulation/Process/Decay.hh
new file mode 100644
index 0000000000000000000000000000000000000000..ae6190811e2b287151770ef2e3ed6a7fd7381203
--- /dev/null
+++ b/NPSimulation/Process/Decay.hh
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2016   this file is part of the NPTool Project         *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
+ *                                                                           *
+ * Creation Date  : Octobre 2017                                             *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ * Use to kill the beam track and replace it with the reaction product       *
+ *                                                                           *
+*                                                                           *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+
+#ifndef Decay_h
+#define Decay_h
+
+#include "G4VFastSimulationModel.hh"
+#include "PhysicsList.hh"
+#include "NPDecay.h"
+class G4VPhysicalVolume;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace NPS{
+
+class Decay : public G4VFastSimulationModel{
+  public:
+    Decay (G4String, G4Region*);
+    Decay (G4String);
+    ~Decay();
+
+  public:
+    void ReadConfiguration();
+    virtual G4bool IsApplicable(const G4ParticleDefinition&);
+    virtual G4bool ModelTrigger(const G4FastTrack &);
+    virtual void DoIt(const G4FastTrack&, G4FastStep&);
+
+  private:
+    NPL::DecayStore m_Decay;
+    std::set<std::string>  m_MotherName;
+    std::string m_CurrentName;
+    double m_ExcitationEnergy;
+    double m_PreviousEnergy;
+    double m_PreviousLength;
+
+};
+}
+
+#endif 
diff --git a/NPSimulation/Process/G4DEAmplification.cc b/NPSimulation/Process/G4DEAmplification.cc
index 8e8b3e272e50f841873ba81d9c2944666840d9ff..22b273de0d92fde66ecd74128d1456e389a60e4e 100644
--- a/NPSimulation/Process/G4DEAmplification.cc
+++ b/NPSimulation/Process/G4DEAmplification.cc
@@ -98,19 +98,11 @@ G4DEAmplification::~G4DEAmplification(){}
 G4DEAmplification::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
 {
 
-//  if(aTrack.GetCreatorProcess()->GetProcessName()=="DEAmplification" )
-//    return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
-
   // Get the primary track
   aParticleChange.Initialize(aTrack);
 
   const G4Material* aMaterial = aTrack.GetMaterial();
 
-  G4StepPoint* pPreStepPoint  = aStep.GetPreStepPoint();
-
-  G4ThreeVector x0 = pPreStepPoint->GetPosition();
-  G4ThreeVector p0 = aStep.GetDeltaPosition().unit();
-  G4double      t0 = pPreStepPoint->GetGlobalTime();
 
   // Get the material table
   G4MaterialPropertiesTable* aMaterialPropertiesTable =
@@ -118,41 +110,50 @@ G4DEAmplification::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
   if (!aMaterialPropertiesTable){ // Does the table exist
     return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
   }
-  
-  if(!aMaterialPropertiesTable->ConstPropertyExists("DE_AMPLIFICATION") ||
-     !aMaterialPropertiesTable->ConstPropertyExists("DE_YIELD"))
+
+  if(!aMaterialPropertiesTable->ConstPropertyExists("DE_AMPLIFICATION"))
     return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
-  
+
+
+  G4StepPoint* pPreStepPoint  = aStep.GetPreStepPoint();
+
+  G4ThreeVector x0 = pPreStepPoint->GetPosition();
+  G4ThreeVector p0 = aStep.GetDeltaPosition().unit();
+  G4double      t0 = pPreStepPoint->GetGlobalTime();
+
   G4double pair_energy = pPreStepPoint->GetKineticEnergy();
 
   G4double amplification = aMaterialPropertiesTable->GetConstProperty("DE_AMPLIFICATION");
-  G4double Yield = aMaterialPropertiesTable->GetConstProperty("DE_YIELD");
 
-  G4int number_electron = amplification*Yield;
-    //if no electron leave
-  if(number_electron<1){
+
+  double OriginalW = aTrack.GetWeight();
+  // Number of Physical electron to be created
+  G4int number_electron = amplification*OriginalW;
+  //Number of tracked electron effectively created instead
+  G4int tracked_electron = 10;
+
+  //if no electron leave
+  if(tracked_electron<1){
     aParticleChange.SetNumberOfSecondaries(0);
     return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
   }
 
-  aParticleChange.SetNumberOfSecondaries(number_electron);
+  static G4ParticleDefinition* DEDef = G4DriftElectron::DriftElectron();
+  G4TouchableHandle handle = pPreStepPoint->GetTouchableHandle();
+  G4int ParentID = aTrack.GetTrackID();
+
+   aParticleChange.SetNumberOfSecondaries(tracked_electron);
+  aParticleChange.SetSecondaryWeightByProcess(true);
   // Create the secondary tracks
-  for(G4int i = 0 ; i < number_electron ; i++){
-    // Random direction at creation
-    G4double cost = 1-2*G4UniformRand();
-    G4double theta = acos(cost);
-    G4double phi = twopi*G4UniformRand();
-    G4ThreeVector p;
-    p.setRThetaPhi(1,theta,phi); 
-
-    G4DynamicParticle* particle = new G4DynamicParticle(G4DriftElectron::DriftElectron(),p, pair_energy);
+  for(G4int i = 0 ; i < tracked_electron ; i++){
+     G4DynamicParticle* particle = new G4DynamicParticle(DEDef,p0, pair_energy);
+     // The secondary track follow the original one
      G4Track* aSecondaryTrack = new G4Track(particle,t0,x0);
 
-    aSecondaryTrack->SetTouchableHandle(
-        aStep.GetPreStepPoint()->GetTouchableHandle());
     aSecondaryTrack->SetCreatorProcess(this);
-    aSecondaryTrack->SetParentID(aTrack.GetTrackID());
-    aSecondaryTrack->SetTouchableHandle(aStep.GetPreStepPoint()->GetTouchableHandle());
+    aSecondaryTrack->SetParentID(ParentID);
+    aSecondaryTrack->SetTouchableHandle(handle);
+    aSecondaryTrack->SetWeight(number_electron/tracked_electron);
     aParticleChange.AddSecondary(aSecondaryTrack);
   }
   // to kill the primary track to avoid it being re-amplified
@@ -183,10 +184,10 @@ G4double G4DEAmplification::GetMeanLifeTime(const G4Track& aTrack,
     G4ForceCondition* condition)
 {
   if(aTrack.GetCreatorProcess()->GetProcessName()=="DEAmplification" ){
-   *condition = NotForced;
+    *condition = NotForced;
     return DBL_MAX;
   }
-    
+
   *condition = StronglyForced;
   return DBL_MAX;
 }
diff --git a/NPSimulation/Process/G4DETransport.cc b/NPSimulation/Process/G4DETransport.cc
index aa7a75fbcc7b230761583c9672dc93b44866a29e..f37b3995d7f919140a20bb80f560c9b8f43181f0 100644
--- a/NPSimulation/Process/G4DETransport.cc
+++ b/NPSimulation/Process/G4DETransport.cc
@@ -128,7 +128,6 @@ G4DETransport::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
   
 
   if(!aMaterialPropertiesTable->ConstPropertyExists("DE_PAIRENERGY") ||
-     !aMaterialPropertiesTable->ConstPropertyExists("DE_YIELD") ||
      !aMaterialPropertiesTable->ConstPropertyExists("DE_TRANSVERSALSPREAD") ||
      !aMaterialPropertiesTable->ConstPropertyExists("DE_LONGITUDINALSPREAD") ||
      !aMaterialPropertiesTable->ConstPropertyExists("DE_DRIFTSPEED") )
diff --git a/NPSimulation/Process/G4IonizationWithDE.cc b/NPSimulation/Process/G4IonizationWithDE.cc
index b4a2abe6cd2b0c4edbfb4ad66606c9835ae2275b..94dae397adfcebc5f04b1ade056942297a759085 100644
--- a/NPSimulation/Process/G4IonizationWithDE.cc
+++ b/NPSimulation/Process/G4IonizationWithDE.cc
@@ -117,7 +117,6 @@ void G4IonizationWithDE::BuildPhysicsTable(const G4ParticleDefinition&)
 //
   G4VParticleChange*
 G4IonizationWithDE::AtRestDoIt(const G4Track& aTrack, const G4Step& aStep)
-
   // This routine simply calls the equivalent PostStepDoIt since all the
   // necessary information resides in aStep.GetTotalEnergyDeposit()
 
@@ -140,15 +139,6 @@ G4IonizationWithDE::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
   aParticleChange.Initialize(aTrack);
 
   const G4Material* aMaterial = aTrack.GetMaterial();
-
-  G4StepPoint* pPreStepPoint  = aStep.GetPreStepPoint();
-
-  G4ThreeVector x0 = pPreStepPoint->GetPosition();
-  G4ThreeVector p0 = aStep.GetDeltaPosition().unit();
-  G4double      t0 = pPreStepPoint->GetGlobalTime();
-
-  G4double TotalEnergyDeposit = aStep.GetTotalEnergyDeposit();
-
   // Get the material table
   G4MaterialPropertiesTable* aMaterialPropertiesTable =
     aMaterial->GetMaterialPropertiesTable();
@@ -157,59 +147,85 @@ G4IonizationWithDE::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
   
 
   if(!aMaterialPropertiesTable->ConstPropertyExists("DE_PAIRENERGY") ||
-     !aMaterialPropertiesTable->ConstPropertyExists("DE_YIELD") ||
      !aMaterialPropertiesTable->ConstPropertyExists("DE_TRANSVERSALSPREAD") ||
      !aMaterialPropertiesTable->ConstPropertyExists("DE_LONGITUDINALSPREAD") ||
      !aMaterialPropertiesTable->ConstPropertyExists("DE_DRIFTSPEED") )
     return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
  
 
+  G4StepPoint* pPreStepPoint  = aStep.GetPreStepPoint();
+  const G4TouchableHandle& handle = pPreStepPoint->GetTouchableHandle();
+
+  G4ThreeVector x0 = pPreStepPoint->GetPosition();
+  G4ThreeVector p0 = aStep.GetDeltaPosition().unit();
+  G4double      t0 = pPreStepPoint->GetGlobalTime();
+
+  G4double TotalEnergyDeposit = aStep.GetTotalEnergyDeposit();
+
+  
   G4double v_drift=
     aMaterialPropertiesTable->GetConstProperty("DE_DRIFTSPEED");
   G4double pair_energy=
     aMaterialPropertiesTable->GetConstProperty("DE_PAIRENERGY");
-  G4double IonizationWithDEYield = 0;
-  IonizationWithDEYield=
-    aMaterialPropertiesTable->GetConstProperty("DE_YIELD");
 
-  G4int number_electron = IonizationWithDEYield*TotalEnergyDeposit/pair_energy;
+  // Physical number of electron produced
+  G4int number_electron = TotalEnergyDeposit/pair_energy;
   number_electron = G4Poisson(number_electron);
-    //if no electron leave
-  if(number_electron<1){
+
+  // Tracked electron produced
+  // 100 per mm per step to have a good statistical accuracy
+  
+  G4int tracked_electron = (aStep.GetStepLength()/mm)*5;
+
+  //if no electron leave
+  if(tracked_electron<1){
     aParticleChange.SetNumberOfSecondaries(0);
     return G4VRestDiscreteProcess::PostStepDoIt(aTrack, aStep);
   }
 
-  aParticleChange.SetNumberOfSecondaries(number_electron);
+  aParticleChange.SetNumberOfSecondaries(tracked_electron);
+  aParticleChange.SetSecondaryWeightByProcess(true);
 
-  // Create the secondary tracks
-  for(G4int i = 0 ; i < number_electron ; i++){
   // Electron follow the field direction
   // The field direction is taken from the field manager
-  G4double* fieldArr = new G4double[6];
-  G4double  Point[4]={x0.x(),x0.y(),x0.z(),t0};
-  G4FieldManager* fMng = pPreStepPoint->GetTouchableHandle()->GetVolume()->GetLogicalVolume()->
-    GetFieldManager();
+  //Everything common to all created DE:
+  static G4double  fieldArr[6];
+  static G4double  Point[4];
+  Point[0] = x0.x();
+  Point[1] = x0.y();
+  Point[2] = x0.z();
+  Point[3] = t0;
+
+  G4FieldManager* fMng = handle->GetVolume()->GetLogicalVolume()->GetFieldManager();
 
   G4ElectroMagneticField* field = (G4ElectroMagneticField*)fMng->GetDetectorField();
-  field->GetFieldValue(Point,fieldArr) ;
+  field->GetFieldValue(Point,&fieldArr[0]) ;
 
   // Electron move opposite to the field direction, hance the minus sign
   G4ThreeVector p(-fieldArr[3],-fieldArr[4],-fieldArr[5]);
   // Normalised the drift direction
   p = p.unit();
 
-    // Random Position along the step with matching time
+  G4ThreeVector delta = aStep.GetDeltaPosition();
+  G4double     deltaT = aStep.GetDeltaTime();
+  static G4ParticleDefinition* DEDefinition = G4DriftElectron::DriftElectron();
+  G4double velocity = v_drift/c_light;
+  G4int parentID = aTrack.GetTrackID();
+  
+  // Create the secondary tracks
+  for(G4int i = 0 ; i < tracked_electron ; i++){ // always create 100 electron, but with weight
+      // Random Position along the step with matching time
     G4double rand = G4UniformRand();
-    G4ThreeVector pos = x0 + rand * aStep.GetDeltaPosition();
-    G4double time = t0+ rand* aStep.GetDeltaTime(); 
-
-    G4DynamicParticle* particle = new G4DynamicParticle(G4DriftElectron::DriftElectron(),p, pair_energy);
-     G4Track* aSecondaryTrack = new G4Track(particle,time,pos);
-    aSecondaryTrack->SetVelocity(v_drift/c_light);
-
-    aSecondaryTrack->SetParentID(aTrack.GetTrackID());
-    aSecondaryTrack->SetTouchableHandle(aStep.GetPreStepPoint()->GetTouchableHandle());
+    G4ThreeVector pos = x0 + rand * delta;
+    G4double time = t0 + rand* deltaT; 
+
+    G4DynamicParticle* particle = new G4DynamicParticle(DEDefinition,p, pair_energy);
+    G4Track* aSecondaryTrack = new G4Track(particle,time,pos);
+    aSecondaryTrack->SetVelocity(velocity);
+    aSecondaryTrack->SetParentID(parentID);
+    aSecondaryTrack->SetTouchableHandle(handle);
+    // Set the weight, ie, how many electron the track represents 
+    aSecondaryTrack->SetWeight(number_electron/tracked_electron);
     aParticleChange.AddSecondary(aSecondaryTrack);
   }
 
diff --git a/NPSimulation/Process/PhysicsList.cc b/NPSimulation/Process/PhysicsList.cc
index cf08ee4881d969ba626ae8c5bbe1c2e33d2e191d..130db3d84b4b31121cf52e526d8da512c84adda0 100644
--- a/NPSimulation/Process/PhysicsList.cc
+++ b/NPSimulation/Process/PhysicsList.cc
@@ -27,7 +27,7 @@
 // Local physic directly implemented from the Hadronthrapy example
 // Physic dedicated to the ion-ion inelastic processes
 #include "NPIonIonInelasticPhysic.hh"
-
+#include "Decay.hh"
 // G4
 #include "G4SystemOfUnits.hh"
 #include "G4RunManager.hh"
@@ -37,6 +37,7 @@
 #include "G4UnitsTable.hh"
 #include "G4ProcessManager.hh"
 #include "G4FastSimulationManagerProcess.hh"
+#include "G4StepLimiter.hh"
 /////////////////////////////////////////////////////////////////////////////
 PhysicsList::PhysicsList() : G4VUserPhysicsList(){
     m_EmList = "Option4";
@@ -283,7 +284,7 @@ void PhysicsList::ConstructProcess(){
     em_option.SetAuger(true);
     
     AddParametrisation();
-    
+
     return;
 }
 /////////////////////////////////////////////////////////////////////////////
@@ -291,9 +292,8 @@ void PhysicsList::AddStepMax(){
 }
 /////////////////////////////////////////////////////////////////////////////
 void PhysicsList::AddParametrisation(){
-/*
-	G4FastSimulationManagerProcess* drift =
-			new G4FastSimulationManagerProcess("DriftElectron");
+  G4FastSimulationManagerProcess* BeamReaction =
+			new G4FastSimulationManagerProcess("NPSimulationProcess");
 
 // For 10.3 and higher
 #ifndef theParticleIterator  
@@ -304,10 +304,12 @@ void PhysicsList::AddParametrisation(){
 	while ((*theParticleIterator)()){
 		  G4ParticleDefinition* particle = theParticleIterator->value();
       G4ProcessManager* pmanager = particle->GetProcessManager();
-
-      if(particle->GetParticleName()=="e-")
-        pmanager->AddDiscreteProcess(drift);
-  }*/
+      std::string name = particle->GetParticleName();
+      pmanager->AddDiscreteProcess(BeamReaction);
+      // Add a Step limiter to the beam particle. 
+      // This will be used to limit the step of the beam in the target
+      pmanager->AddProcess(new G4StepLimiter,-1,-1,5);
+  }
 }
 
 
diff --git a/NPSimulation/Process/PhysicsList.hh b/NPSimulation/Process/PhysicsList.hh
index c171bc6271a3f9eb9897f189f1f4c42b9edcb0fb..66ceaa685f2f212011a250413130a2cfd56076a1 100644
--- a/NPSimulation/Process/PhysicsList.hh
+++ b/NPSimulation/Process/PhysicsList.hh
@@ -84,7 +84,7 @@ class PhysicsList: public G4VUserPhysicsList{
     void AddParametrisation();
     void AddPackage(const G4String& name);
     void BiasCrossSectionByFactor(double factor);
-  
+
   private:
     std::map<std::string,G4VPhysicsConstructor*>  m_PhysList;
     G4EmConfigurator em_config;
@@ -96,7 +96,7 @@ class PhysicsList: public G4VUserPhysicsList{
     G4VPhysicsConstructor* emPhysicsList;
     G4VPhysicsConstructor* decay_List;
     G4VPhysicsConstructor* radioactiveDecay_List;
-    
+ 			  
   private: // Physics option
     std::string m_EmList;
     double m_IonBinaryCascadePhysics;
diff --git a/NPSimulation/Scorers/DriftElectronScorers.cc b/NPSimulation/Scorers/DriftElectronScorers.cc
index 2f66eaeece89e23770406a042565ed8307199fdf..a09a905c9e0a7256789c2272ce65231795d5197e 100644
--- a/NPSimulation/Scorers/DriftElectronScorers.cc
+++ b/NPSimulation/Scorers/DriftElectronScorers.cc
@@ -57,7 +57,7 @@ G4bool PS_DECathode::ProcessHits(G4Step* aStep, G4TouchableHistory*){
   G4String PID = aStep->GetTrack()->GetDefinition()->GetParticleName();
 
     if(PID=="driftelectron"){
-        Infos[0] = 1;
+        Infos[0] = aStep->GetTrack()->GetWeight();
     }
 
     // Check if the particle has interact before, if yes, add up the number of electron.
@@ -143,7 +143,7 @@ G4bool PS_DEDigitizer::ProcessHits(G4Step* aStep, G4TouchableHistory*){
   G4String PID = aStep->GetTrack()->GetDefinition()->GetParticleName();
 
     if(PID=="driftelectron"){
-        Infos[0] = 1;
+        Infos[0] = aStep->GetTrack()->GetWeight();
     }
 
     // Check if the particle has interact before, if yes, add up the number of electron.
diff --git a/NPSimulation/Scorers/ObsoleteGeneralScorers.cc b/NPSimulation/Scorers/ObsoleteGeneralScorers.cc
index 558119d59bbd821dd22ed7ac4e72b83f97a8e87d..6bfbc2d8c0ebbf3573b668732397d567565b20fb 100644
--- a/NPSimulation/Scorers/ObsoleteGeneralScorers.cc
+++ b/NPSimulation/Scorers/ObsoleteGeneralScorers.cc
@@ -200,10 +200,10 @@ G4bool PSTOF::ProcessHits(G4Step* aStep, G4TouchableHistory*)
     int DetNumber = PickUpDetectorNumber(aStep, m_VolumeName);
     
     G4double TOF  = aStep->GetPreStepPoint()->GetGlobalTime();
-    G4double de = aStep->GetTotalEnergyDeposit();
+   // G4double de = aStep->GetTotalEnergyDeposit();
     G4int  index = aStep->GetTrack()->GetTrackID();
-    if(de < TriggerThreshold)
-        return FALSE;
+  //  if(de < TriggerThreshold)
+   //     return FALSE;
     EvtMap->set(index+DetNumber, TOF);
     return TRUE;
 }
diff --git a/NPSimulation/Simulation.cc b/NPSimulation/Simulation.cc
index df6c6886f7565858cd0f9720f3f284a441484d53..b15420bc908d392d02336750a1a3d417ed9d7c72 100644
--- a/NPSimulation/Simulation.cc
+++ b/NPSimulation/Simulation.cc
@@ -74,7 +74,7 @@ int main(int argc, char** argv){
     PhysicsList* physicsList   = new PhysicsList();
     runManager->SetUserInitialization(physicsList);
     PrimaryGeneratorAction* primary = new PrimaryGeneratorAction(detector);
-    
+
     // Initialize Geant4 kernel
     runManager->Initialize();
     
diff --git a/Projects/MUGAST/Analysis.cxx b/Projects/MUGAST/Analysis.cxx
index 57e731e6e5993b353b4d94417bdb5d0659461256..e9d626c18ae89bc024c861772c51d00368874606 100644
--- a/Projects/MUGAST/Analysis.cxx
+++ b/Projects/MUGAST/Analysis.cxx
@@ -47,18 +47,16 @@ void Analysis::Init() {
   // get reaction information
   myReaction.ReadConfigurationFile(NPOptionManager::getInstance()->GetReactionFile());
   OriginalBeamEnergy = myReaction.GetBeamEnergy();
-
   // target thickness
   TargetThickness = m_DetectorManager->GetTargetThickness();
   string TargetMaterial = m_DetectorManager->GetTargetMaterial();
   // Cryo target case
-  WindowsThickness = m_DetectorManager->GetWindowsThickness(); 
-  string WindowsMaterial = m_DetectorManager->GetWindowsMaterial();
+  WindowsThickness = 0;//m_DetectorManager->GetWindowsThickness(); 
+  string WindowsMaterial = "";//m_DetectorManager->GetWindowsMaterial();
 
-  // energy losses
+ // energy losses
   string light=NPL::ChangeNameToG4Standard(myReaction.GetNucleus3().GetName());
   string beam=NPL::ChangeNameToG4Standard(myReaction.GetNucleus1().GetName());
-
   LightTarget = NPL::EnergyLoss(light+"_"+TargetMaterial+".G4table","G4Table",100 );
   LightAl = NPL::EnergyLoss(light+"_Al.G4table","G4Table",100);
   LightSi = NPL::EnergyLoss(light+"_Si.G4table","G4Table",100);
diff --git a/Projects/MUGAST/ShowResults.C b/Projects/MUGAST/ShowResults.C
index 41ca7ece32729879f3f02fbce3663a6ce1767457..15bbb392d6d5d8e7e89d891a12b6c2b7c49dec2d 100644
--- a/Projects/MUGAST/ShowResults.C
+++ b/Projects/MUGAST/ShowResults.C
@@ -52,8 +52,7 @@ using namespace std;
 #include "NPReaction.h"
 using namespace NPL;
 
-void ShowResults()
-{
+void ShowResults(){
    // get tree   
    TFile *f = new TFile("../../Outputs/Analysis/PhysicsTree.root");
    TTree *t = (TTree*) f->Get("PhysicsTree");
@@ -63,27 +62,47 @@ void ShowResults()
    TCanvas *c1 = new TCanvas("c1", "kinematic information", 600, 600);
    c1->Draw();
    // kinematic line
-   TH2F *hk = new TH2F("hk", "hk", 90, 90, 180, 200, 0, 12);
+   TH2F *hk = new TH2F("hk", "hk", 180, 0, 180, 200, 0, 60);
    hk->GetXaxis()->SetTitle("#Theta_{lab} (deg)");
    hk->GetYaxis()->SetTitle("E_{p} (MeV)");
-   t->Draw("ELab:ThetaLab>>hk");
-   // inset
-   TPad *pad = new TPad("pad1", "excitation energy", 0.45, 0.45, 0.87, 0.87);
-   pad->Draw();
-   pad->cd();
-   // excitation energy
-   TH1F *hx = new TH1F("hx", "hx", 150, 5, 8);
-   hx->SetXTitle("E_{X} (MeV)");
-   hx->SetYTitle("counts / (20 keV)");
-   t->Draw("Ex>>hx");
+   cout << "counts " << t->Draw("ELab:ThetaLab>>hk","Ex>0&&Ex<6","colz") << endl;
+   NPL::Reaction* reaction = new NPL::Reaction();
+   reaction->ReadConfigurationFile("28Mg.reaction");
+   reaction->GetKinematicLine3()->Draw("c");
+
+  new TCanvas();
+  TH1F *hCM = new TH1F("hCM", "hCM", 36, 0, 180); 
+  t->Draw("ThetaCM>>hCM","Ex>0&&Ex<6","",2900);
+  for(int i = 0 ; i < hCM->GetNbinsX();i++){
+    if(hCM->GetBinCenter(i)==37.5 || hCM->GetBinCenter(i)==97.5|| hCM->GetBinCenter(i)==167.5|| hCM->GetBinCenter(i)==42.5){
+      hCM->SetBinContent(i,0);
+      
+      }
+    
+    }
+ gPad->SetLogy();
+
+  TFile* file= new TFile("effMUGAST.root");
+  TH1* hOmega = (TH1*)file->FindObjectAny("hDetecThetaCM");
+  hOmega->Rebin(5);
+  hCM->Sumw2();
+  hCM->Divide(hOmega);
+  TGraph* g= new TGraph("22.jjj");
+  g->Draw("c");
+   hCM->Scale(g->Eval(32.5)/hCM->GetBinContent(hCM->FindBin(32.5)));
+  TGraph* g2= new TGraph("22.l2");
+  g2->Draw("c");
+  TGraph* g3= new TGraph("22.l3");
+  g3->Draw("c");
+
+
 }
 
 
-void CountingRates(Double_t ibeam = 1e5, Double_t ubt = 30)
-{
+void CountingRates(Double_t ibeam = 1e5, Double_t ubt = 30){
    // load event generator file
    NPL::Reaction* reaction = new NPL::Reaction();
-   reaction->ReadConfigurationFile("30Pdp.reaction");
+   reaction->ReadConfigurationFile("28Mg.reaction");
 //   reaction->ReadConfigurationFile("11Be_d3He.reaction");
    // get angular distribution
    TH1F *dsig = reaction->GetCrossSectionHist();
diff --git a/Projects/TRex_Miniball/Analysis.cxx b/Projects/TRex_Miniball/Analysis.cxx
index 8bd30237c82fed822b2dcc135d0458255f865263..fbe9c96f2dbf88d67870ca7500f1a29366f5fb95 100644
--- a/Projects/TRex_Miniball/Analysis.cxx
+++ b/Projects/TRex_Miniball/Analysis.cxx
@@ -42,12 +42,12 @@ void Analysis::Init(){
   myReaction->ReadConfigurationFile(NPOptionManager::getInstance()->GetReactionFile());
 
   string ligth,heavy;
-  if(myReaction->GetNucleus3()->GetZ()==1 && myReaction->GetNucleus3()->GetA()==1)
+  if(myReaction->GetNucleus3().GetZ()==1 && myReaction->GetNucleus3().GetA()==1)
     ligth = "proton";
   else
     ligth = "deuteron";
 
-  heavy = "N17";
+  heavy = "Ga80";
 
 
   Sharc = (TSharcPhysics*)  m_DetectorManager -> GetDetector("Sharc");
diff --git a/Projects/TRex_Miniball/Reaction/17Ndp.reaction b/Projects/TRex_Miniball/Reaction/17Ndp.reaction
index f1fbd52ea4d0693e056d9e1c71651c5fad902e71..9287cda0c85d7ba896ecf69a7ce486a310004ddf 100644
--- a/Projects/TRex_Miniball/Reaction/17Ndp.reaction
+++ b/Projects/TRex_Miniball/Reaction/17Ndp.reaction
@@ -1,30 +1,30 @@
 %%%%%%%%%%%%%%%%%%%%%% IS591 at ISOLDE %%%%%%%%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Beam
-  Particle= 17N 
-  ExcitationEnergy= 0
-  Energy= 93
-  SigmaEnergy= 0.448
-  SigmaThetaX= 0.01 
-  SigmaPhiY= 0.01
-  SigmaX= 0.5
-  SigmaY= 0.5
-  MeanThetaX= 0
-  MeanPhiY= 0
-  MeanX= 0
-  MeanY= 0
-  %EnergyProfilePath=
-  %XThetaXProfilePath=
-  %YPhiYProfilePath=
+ Particle= 17N 
+ ExcitationEnergy= 0
+ Energy= 93
+ SigmaEnergy= 0.448
+ SigmaThetaX= 0.01 
+ SigmaPhiY= 0.01
+ SigmaX= 0.5
+ SigmaY= 0.5
+ MeanThetaX= 0
+ MeanPhiY= 0
+ MeanX= 0
+ MeanY= 0
+ %EnergyProfilePath=
+ %XThetaXProfilePath=
+ %YPhiYProfilePath=
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TwoBodyReaction
-	Beam= 17N
-	Target= 2H
-	Light= 1H
-	Heavy= 18N
-	ExcitationEnergyLight= 0.0
-	ExcitationEnergyHeavy= 0.0
-  CrossSectionPath= 18Ngs.txt CSR
-	ShootLight= 1
-	ShootHeavy= 1
+ Beam= 17N
+ Target= 2H
+ Light= 1H
+ Heavy= 18N
+ ExcitationEnergyLight= 0.0
+ ExcitationEnergyHeavy= 0.0
+ CrossSectionPath= flat.txt CSR
+ ShootLight= 1
+ ShootHeavy= 1
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/Projects/TRex_Miniball/TRex_Miniball.detector b/Projects/TRex_Miniball/TRex_Miniball.detector
index 210bb5c22c38f25706688592b59a375800706db3..93a045dc1200517105ffee3222a17ba9680ee337 100644
--- a/Projects/TRex_Miniball/TRex_Miniball.detector
+++ b/Projects/TRex_Miniball/TRex_Miniball.detector
@@ -1,135 +1,131 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-GeneralTarget
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Target
-	THICKNESS= 5
-	RADIUS=	5
-	MATERIAL= CD2
-	ANGLE= 0
-	X= 0
-	Y= 0
-	Z= 0
+ THICKNESS= 9 micrometer
+ RADIUS= 5 mm
+ MATERIAL= CD2
+ ANGLE= 0 deg 
+ X= 0 mm 
+ Y= 0 mm
+ Z= 0 mm
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TRex
-	Chamber= 1
-  X= 0
-	Y= 29
-	Z= 33
-	Shape= Square
+ Chamber= 1
+ X= 0 mm
+ Y= 29 mm 
+ Z= 33 mm
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TRex
-	X= 0
-	Y= -29
-	Z= 33
-	Shape= Square
+ X= 0 mm 
+ Y= -29 mm 
+ Z= 33 mm
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TRex
-	X= 29
-	Y= 0
-	Z= 33
-	Shape= Square
+ X= 29 mm
+ Y= 0 mm 
+ Z= 33 mm
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TRex
-	X= -29
-	Y= 0
-	Z= 33
-	Shape= Square
+ X= -29 mm 
+ Y= 0 mm
+ Z= 33 mm
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TRex
-	X= 0
-	Y= 29
-	Z= -33
-	Shape= Square
+ X= 0 mm 
+ Y= 29 mm
+ Z= -33 mm
+Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TRex
-	X= 0
-	Y= -29
-	Z= -33
-	Shape= Square
+ X= 0 mm
+ Y= -29 mm
+ Z= -33 mm
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TRex
-	X= 29
-	Y= 0
-	Z= -33
-	Shape= Square
+ X= 29 mm
+ Y= 0 mm
+ Z= -33 mm
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 TRex
-	X= -29
-	Y= 0
-	Z= -33
-	Shape= Square
+ X= -29 mm
+ Y= 0 mm
+ Z= -33 mm
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-Sharc
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-  %Upstream CD
-  SharcQQQ
-    Z= -70
-    R= 0
-    Phi= 2
-    ThicknessDector= 500
-  SharcQQQ
-    Z= -70
-    R= 0
-    Phi= 92
-    ThicknessDector= 500
-  SharcQQQ
-    Z= -70
-    R= 0
-    Phi= 182
-    ThicknessDector= 500
-  SharcQQQ
-    Z= -70
-    R= 0
-    Phi= 272
-    ThicknessDector= 500
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-Miniball
-	R= 110
-	THETA= 110
-	PHI= 320
-	Shape= Square
+%Upstream CD
+Sharc QQQ
+ Z= -70 mm
+ R= 0 mm
+ Phi= 2 deg
+ ThicknessDetector= 500
+Sharc QQQ
+ Z= -70 mm
+ R= 0 mm
+ Phi= 92 deg
+ ThicknessDetector= 500
+Sharc QQQ
+ Z= -70 mm
+ R= 0 mm
+ Phi= 182 deg
+ ThicknessDetector= 500
+Sharc QQQ
+ Z= -70 mm
+ R= 0 mm
+ Phi= 272 deg
+ ThicknessDetector= 500
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Miniball
-	R= 110
-	THETA= 110 
-	PHI= 220
-	Shape= Square
+ R= 110 mm
+ THETA= 110 deg
+ PHI= 320 deg
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Miniball
-	R= 110
-	THETA= 67 
-	PHI= 320
-	Shape= Square
+ R= 110 mm
+ THETA= 110 deg
+ PHI= 220 deg
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Miniball
-	R= 110
-	THETA= 67
-	PHI= 220
-	Shape= Square
+ R= 110 mm
+ THETA= 67 deg
+ PHI= 320 deg
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Miniball
-	R= 110
-	THETA= 67
-	PHI= 40
-	Shape= Square
+ R= 110 mm
+ THETA= 67 deg
+ PHI= 220 deg
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Miniball
-	R= 110
-	THETA= 67
-	PHI= 140
-	Shape= Square
+ R= 110 mm
+ THETA= 67 deg
+ PHI= 40 deg
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Miniball
-	R= 110
-	THETA= 110 
-	PHI= 40
-	Shape= Square
+ R= 110 mm 
+ THETA= 67 deg
+ PHI= 140 deg
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Miniball
-	R= 110
-	THETA= 125 
-	PHI= 140
-	Shape= Square
+ R= 110 mm
+ THETA= 110 deg 
+ PHI= 40 deg
+ Shape= Square
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+Miniball 
+ R= 110 mm 
+ THETA= 125 deg 
+ PHI= 140 deg 
+ Shape= Square
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
diff --git a/Projects/e748/Analysis.cxx b/Projects/e748/Analysis.cxx
index a66d024f8f42a54f16bfe368c0f97b21132ede4e..376c1dd901c721db230647806bffb4ec1d9645ff 100644
--- a/Projects/e748/Analysis.cxx
+++ b/Projects/e748/Analysis.cxx
@@ -36,11 +36,9 @@ Analysis::~Analysis(){
 
 ////////////////////////////////////////////////////////////////////////////////
 void Analysis::Init(){
-  M2= (TMust2Physics*) m_DetectorManager->GetDetector("M2Telescope");
-  CATS= ( TCATSPhysics*) m_DetectorManager->GetDetector("CATSDetector");
-  
-  //Initial=new TInitialConditions();
-
+  M2 = (TMust2Physics*) m_DetectorManager->GetDetector("M2Telescope");
+  CATS = (TCATSPhysics*) m_DetectorManager->GetDetector("CATSDetector");
+  ModularLeaf = (TModularLeafPhysics*) m_DetectorManager->GetDetector("ModularLeaf");
   InitOutputBranch();
   InitInputBranch();
   /* Rand = TRandom3(); */
@@ -62,17 +60,29 @@ void Analysis::Init(){
   TimeCorr=0;
   TargetThickness = m_DetectorManager->GetTargetThickness();
   //	Energy loss table: the G4Table are generated by the simulation
-  He3CD2 = EnergyLoss("Example/He3_CD2.G4table","G4Table",101 );
+  He3CD2 = EnergyLoss("Example/He3_CD2.G4table","G4Table",10 );
   He3Al = EnergyLoss("Example/He3_Al.G4table","G4Table",10);
   He3Si = EnergyLoss("Example/He3_Si.G4table","G4Table",10);
-  //Li11CD2 = EnergyLoss("ExampleLi11_CD2.G4table","G4Table",100);
+  BeamCD2 = EnergyLoss("Be12_CD2.G4table","G4Table",10);
+  BeamMylar = EnergyLoss("Be12_Mylar.G4table","G4Table",10);
+  BeamIsobutane = EnergyLoss("Be12_iC4H10.G4table","G4Table",10); 
+
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Analysis::TreatEvent(){
   // Reinitiate calculated variable
   ReInitValue();
-  // Get the Init information on beam position and energy
+
+  // Calculate Run Number
+  static string filename ;
+  filename = RootInput::getInstance()->GetChain()->GetFile()->GetName();
+  size_t minor_pos = filename.rfind("_");
+  run_minor = atoi(filename.substr(minor_pos+1,1).c_str());
+  filename = filename.substr(0,minor_pos);
+  size_t major_pos = filename.rfind("_");
+  run_major = atoi(filename.substr(major_pos+1,4).c_str());
+   // Get the Init information on beam position and energy
   // and apply by hand the experimental resolution
   // This is because the beam diagnosis are not simulated
   // PPAC position resolution on target is assumed to be 1mm
@@ -82,9 +92,6 @@ void Analysis::TreatEvent(){
   TVector3 BeamDirection = CATS->GetBeamDirection();
   // Beam energy is measured using F3 and F2 plastic TOF
   //double BeamEnergy= myReaction-> GetBeamEnergy()* MeV;
-  double BeamEnergy= 30*12* MeV;
-  //BeamEnergy = Li11CD2.Slow(BeamEnergy,TargetThickness/2.,0);
-  myReaction->SetBeamEnergy(BeamEnergy);
   //////////////////////////// LOOP on MUST2 Hit //////////////////
      for(unsigned int countMust2 = 0 ; countMust2 < M2->Si_E.size() ; countMust2++){ 
     /*   //Part 0 : Get the usefull Data */
@@ -95,37 +102,70 @@ void Analysis::TreatEvent(){
       Si_X_M2 = X ;
       Si_Y_M2 = Y ;
 
-    /*   // Forward Telescope Only */
- 	//      if(TelescopeNumber<6){
-    /*   // All Telescopes */
       if(TelescopeNumber<9){
- 	//      if(TelescopeNumber<6){
         DetectorNumber = TelescopeNumber ;
   
-    /*     // Part 1 : Impact Angle */
+        /* // Part 1 : Impact Angle */
         ThetaM2Surface = 0;
         ThetaNormalTarget = 0;
         if(XTarget>-1000 && YTarget>-1000){
           TVector3 BeamImpact(XTarget,YTarget,0);
-          //TVector3 BeamImpact(0,0,0);
-          
           TVector3 HitDirection = M2 -> GetPositionOfInteraction(countMust2) - BeamImpact ;
           ThetaLab = HitDirection.Angle( BeamDirection );
 
-
-
           ThetaM2Surface = HitDirection.Angle(- M2 -> GetTelescopeNormal(countMust2) );
           ThetaNormalTarget = HitDirection.Angle( TVector3(0,0,1) ) ;
           X_M2 = M2 -> GetPositionOfInteraction(countMust2).X() ;
           Y_M2 = M2 -> GetPositionOfInteraction(countMust2).Y() ;
           Z_M2 = M2 -> GetPositionOfInteraction(countMust2).Z() ;
-          static double BeamSpeed = 74.2;// mm per nano
-          static double ZCats1    = 1458; //mm
-          BeamLength = ZCats1/(1-sin(BeamDirection.Angle(TVector3(0,0,1))));
-          ParticleLength = HitDirection.Mag();
-          TimeCorr=BeamLength/BeamSpeed ; 
-           
+          
+          // Beam Energy from Cav Time of Flight //
+          
+          // Beam speed from Beam Energy
+
+       //   double BeamSpeed =  10.8727 + ModularLeaf->GetCalibratedValue("T_CATS1_CAV")*0.276825; // mm/ns
+          //double BeamSpeed =  5.17952 + ModularLeaf->GetCalibratedValue("T_CATS1_CAV")*0.305315; // mm/ns
+           double BeamSpeed =  11.0476 + ModularLeaf->GetCalibratedValue("T_CATS1_CAV")*0.278917; // mm/ns
 
+          // Beam Energy before CATS1
+          static double c2 = 299.792458*299.792458;// mm/ns 
+          double gamma = 1./sqrt(1-BeamSpeed*BeamSpeed/c2);
+          BeamEnergy= 11200.962140*(gamma-1);
+          double BeamAngle= BeamDirection.Angle(TVector3(0,0,1));
+          
+          // Beam Energy and speed after CATS1
+          double BeamEnergyC1 = BeamMylar.Slow(BeamEnergy,1.2*micrometer,BeamAngle); 
+          BeamEnergyC1 = BeamIsobutane.Slow(BeamEnergyC1,cm/3.,BeamAngle);
+          BeamEnergyC1 = BeamMylar.Slow(BeamEnergyC1,0.9*micrometer,BeamAngle); 
+          BeamEnergyC1 = BeamIsobutane.Slow(BeamEnergyC1,cm/3,BeamAngle);
+          BeamEnergyC1 = BeamMylar.Slow(BeamEnergyC1,0.9*micrometer,BeamAngle); 
+          BeamEnergyC1 = BeamIsobutane.Slow(BeamEnergyC1,cm/3.,BeamAngle);
+          BeamEnergyC1 = BeamMylar.Slow(BeamEnergyC1,1.2*micrometer,BeamAngle); 
+          
+          double gammaC1 = (BeamEnergyC1+11200.962140) / 11200.962140 ;
+          double BeamSpeedC1 = sqrt(c2*(1-1/(gammaC1*gammaC1)));
+          TVector3 C1toC2 =  TVector3(CATS->PositionX[1],CATS->PositionY[1],CATS->PositionZ[1]) 
+                          -  TVector3(CATS->PositionX[0],CATS->PositionY[0],CATS->PositionZ[0]) ;
+          TimeCorr = C1toC2.Mag()/BeamSpeedC1;
+          
+          // Beam Energy and speed after CATS2
+          double BeamEnergyC2 = BeamMylar.Slow(BeamEnergyC1,1.2*micrometer,BeamAngle); 
+          BeamEnergyC2 = BeamIsobutane.Slow(BeamEnergyC2,cm/3.,BeamAngle);
+          BeamEnergyC2 = BeamMylar.Slow(BeamEnergyC2,0.9*micrometer,BeamAngle); 
+          BeamEnergyC2 = BeamIsobutane.Slow(BeamEnergyC2,cm/3,BeamAngle);
+          BeamEnergyC2 = BeamMylar.Slow(BeamEnergyC2,0.9*micrometer,BeamAngle); 
+          BeamEnergyC2 = BeamIsobutane.Slow(BeamEnergyC2,cm/3.,BeamAngle);
+          BeamEnergyC2 = BeamMylar.Slow(BeamEnergyC2,1.2*micrometer,BeamAngle); 
+          
+          double gammaC2 = (BeamEnergyC2+11200.962140) / 11200.962140; 
+          double BeamSpeedC2 = sqrt(c2*(1-1/(gammaC2*gammaC2)));
+          TVector3 C2toTarget =  BeamImpact-TVector3(CATS->PositionX[1],CATS->PositionY[1],CATS->PositionZ[1]);
+          TimeCorr += C2toTarget.Mag()/BeamSpeedC2;
+
+          // slow down beam inside the target
+          BeamEnergy = BeamCD2.Slow(BeamEnergyC2,TargetThickness*0.5,BeamDirection.Angle(TVector3(0,0,1))); 
+          myReaction->SetBeamEnergy(BeamEnergy);   
+          
           }
         
 
@@ -135,8 +175,7 @@ void Analysis::TreatEvent(){
           ThetaNormalTarget = -1000  ;
         }
 
-
-/*         // Part 2 : Impact Energy */
+/*      // Part 2 : Impact Energy */
         Energy = ELab = E_M2 = 0;
         Si_E_M2 = M2->Si_E[countMust2];
         CsI_E_M2= M2->CsI_E[countMust2];
@@ -194,8 +233,13 @@ void Analysis::InitOutputBranch() {
   RootOutput::getInstance()->GetTree()->Branch("TimeCorr",&TimeCorr,"TimeCorr/D"); 
   RootOutput::getInstance()->GetTree()->Branch("BeamLength",&BeamLength,"BeamLength/D"); 
   RootOutput::getInstance()->GetTree()->Branch("ParticleLength",&ParticleLength,"ParticleLength/D"); 
+  RootOutput::getInstance()->GetTree()->Branch("BeamEnergy",&BeamEnergy,"BeamEnergy/D"); 
+
 
   RootOutput::getInstance()->GetTree()->Branch("GATCONF",&vGATCONF,"GATCONF/s");
+  RootOutput::getInstance()->GetTree()->Branch("RunMajor",&run_major,"RunMajor/I");
+  RootOutput::getInstance()->GetTree()->Branch("RunMinor",&run_minor,"RunMinor/I");
+
 /*  RootOutput::getInstance()->GetTree()->Branch("ADC_CHIO_V15",&vADC_CHIO_V15,"ADC_CHIO_V15/s");
   RootOutput::getInstance()->GetTree()->Branch("ADC_VOIE_29",&vADC_VOIE_29,"ADC_VOIE_29/s");
   RootOutput::getInstance()->GetTree()->Branch("CHIO",&vCHIO,"CHIO/s");
@@ -276,6 +320,9 @@ void Analysis::ReInitValue(){
   TimeCorr=-1000;
   BeamLength=-1000;
   ParticleLength=-1000;
+  run_minor=-1000;
+  run_major=-1000;
+  BeamEnergy=-1000;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/Projects/e748/Analysis.h b/Projects/e748/Analysis.h
index c614c7ae4ce79b8ba8ee573c5ee273d4305e32d5..6bac47cdcb550985ba913f5ed81119a7689000a6 100644
--- a/Projects/e748/Analysis.h
+++ b/Projects/e748/Analysis.h
@@ -24,7 +24,8 @@
 #include"NPVAnalysis.h"
 #include "TMust2Physics.h"
 #include "TCATSPhysics.h"
- #include "TInitialConditions.h"
+#include "TModularLeafPhysics.h"
+#include "TInitialConditions.h"
 #include "NPEnergyLoss.h"
 #include "NPReaction.h"
 #include "TRandom3.h"
@@ -70,13 +71,21 @@ class Analysis: public NPL::VAnalysis{
     double TargetThickness;
     double OriginalThetaLab;
     double OriginalELab;
+    double BeamEnergy;
+    int run_major;
+    int run_minor;
     NPL::EnergyLoss He3CD2  ;
     NPL::EnergyLoss He3Al   ;
     NPL::EnergyLoss He3Si   ;
-    NPL::EnergyLoss Li11CD2 ;
+    NPL::EnergyLoss BeamCD2 ;
+    NPL::EnergyLoss BeamMylar ;
+    NPL::EnergyLoss BeamIsobutane ;
+
+
 
     TMust2Physics* M2;
    TCATSPhysics* CATS;
+   TModularLeafPhysics* ModularLeaf;
    TInitialConditions* Initial;
     //other variables 
    Short_t         vADC_CHIO_V15;
diff --git a/Projects/e748/Calibration/Energy/ExtractRawHisto_E.C b/Projects/e748/Calibration/Energy/ExtractRawHisto_E.C
index 29d419a57ea364a41dc422ea959b4d7dd03326e1..839018e011adacaf55aecd51fb21c77dbb090082 100644
--- a/Projects/e748/Calibration/Energy/ExtractRawHisto_E.C
+++ b/Projects/e748/Calibration/Energy/ExtractRawHisto_E.C
@@ -19,11 +19,11 @@
 #include "/home/muvi/e748/nptool/NPLib/Detectors/MUST2/TMust2Data.h"
 #include "/home/muvi/e748/nptool/NPLib/include/RootInput.h"
 
-#define NBTELESCOPE	8	
+#define NBTELESCOPE	4	
 #define	NBSTRIPS	128
 #define NBSILI     16
 
-void ExtractMust2Histos(const char* fname = "run_0019")
+void ExtractMust2Histos(const char* fname = "run_1031")
 {
 	
 	RootInput* Input = RootInput::getInstance("RunToTreat.txt");
diff --git a/Projects/e748/configs/ConfigMust2.dat b/Projects/e748/configs/ConfigMust2.dat
index 247888b9066a495290646e88bdb2f6ae7c65bd4c..97ac0c84fa8b1939aaffe20273ef57a681982097 100644
--- a/Projects/e748/configs/ConfigMust2.dat
+++ b/Projects/e748/configs/ConfigMust2.dat
@@ -69,6 +69,6 @@ ConfigMust2
   SI_X_E_RAW_THRESHOLD 8270
   SI_Y_E_RAW_THRESHOLD 8120
   CSI_E_RAW_THRESHOLD 8250
-  CSI_SIZE 40
-  TAKE_T_Y
-  TAKE_E_Y
+  CSI_SIZE 34
+  TAKE_T_X
+  TAKE_E_X
diff --git a/Projects/e748/e748.detector b/Projects/e748/e748.detector
index 302a7fe4f7ac6751f3ca066a0e30103a20055f31..90336a06ac1a2a26bb9f421b822cd4081433e7eb 100644
--- a/Projects/e748/e748.detector
+++ b/Projects/e748/e748.detector
@@ -100,18 +100,24 @@ M2Telescope
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CATSDetector
- X1_Y1= -35.86  -34.76  -1457 mm
- X28_Y1= 35.26  -34.76  -1457 mm
- X1_Y28= -35.86  36.36  -1457 mm
- X28_Y28= 35.26 36.36  -1457 mm
+ X1_Y1= -35.86  -35.26  -1457 mm
+ X28_Y1= 35.26  -35.26  -1457 mm
+ X1_Y28= -35.86  35.86  -1457 mm
+ X28_Y28= 35.26  35.86  -1457 mm
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CATSDetector
- X1_Y1= 34.86  -35.36   -949 mm
- X28_Y1= -36.26  -35.36  -949 mm
- X1_Y28= 34.66  35.76  -949 mm
- X28_Y28= -36.26 35.76  -949 mm
+ X1_Y1= 34.86    -35.86   -949 mm
+ X28_Y1= -36.26  -35.86   -949 mm
+ X1_Y28= 34.86    35.26   -949 mm
+ X28_Y28= -36.26  35.26   -949 mm
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+
+
+ModularLeaf
+ DefaultValue= -1000
+ Leafs= QPlast QCaviar CHIO T_CATS1_CAV T_CATS1_2 T_MUVI_CATS1 T_PL_CATS2 EXL_HF T_PL_CHIO T_PL_CATS1
+
 Chio_dig 
  Pos=       -30.  -30.   600. mm
 
@@ -125,21 +131,18 @@ Chio_an
 
 %% warning all parameters need to be there for routine to exit
 %Plastic
-  THETA= 0 deg
-  PHI= 0 deg
-  R= 0 mm
-  Thickness= 20 mm
-  Shape= Square
-  Height= 30 mm
-  Width= 30 mm
-  Scintillator= BC400
-  LeadThickness= 0 mm
-
+%  THETA= 0 deg
+ % PHI= 0 deg
+ % R= 0 mm
+ % Thickness= 20 mm
+  %Shape= Square
+  %Height= 30 mm
+  %Width= 30 mm
+  %Scintillator= BC400
+  %LeadThickness= 0 mm
+  %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-EXL
-  POS= -20 30 -20 cm
+%EXL
+ % POS= -20 30 -20 cm
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-ModularLeaf
- DefaultValue= -1000
- Leafs= T_CATS1_CAV T_CATS1_2 T_MUVI_CATS1 T_PL_CATS2 EXL_HF T_PL_CHIO T_PL_CATS1
 
diff --git a/Projects/macros/GeometricalEfficiency.C b/Projects/macros/GeometricalEfficiency.C
index 99ba200fc583cb1b1dbf12b851e083302ced89d6..9655b7afddfbe9ddacc42377bb0394f7a002d5d7 100644
--- a/Projects/macros/GeometricalEfficiency.C
+++ b/Projects/macros/GeometricalEfficiency.C
@@ -48,8 +48,7 @@
 using namespace std;
 
 
-void GeometricalEfficiency(const char * fname = "46Ar_pd_gs"){
-    gROOT->SetStyle("pierre_style");
+void GeometricalEfficiency(const char * fname = "myResult"){
     // Open output ROOT file from NPTool simulation run
     TString path = gSystem->Getenv("NPTOOL");
     path += "/Outputs/Simulation/";
@@ -78,6 +77,7 @@ void GeometricalEfficiency(const char * fname = "46Ar_pd_gs"){
     int nentries = tree->GetEntries();
     for (int i = 0; i < nentries; i++) {
         tree->GetEntry(i);
+
         // Fill histos
         hEmittTheta->Fill(initCond->GetThetaLab_WorldFrame(0));
         hEmittThetaCM->Fill(initCond->GetThetaCM(0));
@@ -113,13 +113,13 @@ void GeometricalEfficiency(const char * fname = "46Ar_pd_gs"){
     c4->SetRightMargin(0.03);
     TH1F* SolidACM = new TH1F(*hDetecThetaCM);
     SolidACM->Sumw2();
-    TF1* C = new TF1("C",Form("1./(2*%f*sin(x*%f/180.)*1*%f/180)",M_PI,M_PI,M_PI),0,90);
+    TF1* C = new TF1("C",Form("1./(2*%f*sin(x*%f/180.)*1*%f/180)",M_PI,M_PI,M_PI),0,180);
     SolidACM->Divide(hEmittThetaCM);
     SolidACM->Divide(C,1);
     SolidACM->Draw();
     SolidACM->GetXaxis()->SetTitle("#theta_{CM} (deg)");
     SolidACM->GetYaxis()->SetTitle("d#Omega (sr) ");
-    TF1* f = new TF1("f",Form("2 * %f * sin(x*%f/180.) *1*%f/180.",M_PI,M_PI,M_PI),0,90);
+    TF1* f = new TF1("f",Form("2 * %f * sin(x*%f/180.) *1*%f/180.",M_PI,M_PI,M_PI),0,180);
     f->Draw("SAME");
     c4->Update();
     
diff --git a/nptool.sh b/nptool.sh
index 3b15a1257798c0506e243a58c04682f4ca783cae..bb3fdb8ce66136b428d27ec856d37873504290a2 100755
--- a/nptool.sh
+++ b/nptool.sh
@@ -37,15 +37,15 @@ NPARCH=$(uname)
 # mac os x case
 if [ "${NPARCH}" = "Darwin" ] ; 
 then
-  ${CMD} DYLD_LIBRARY_PATH${SEP}$DYLD_LIBRARY_PATH:$NPTOOL/NPLib/lib
-  ${CMD} DYLD_LIBRARY_PATH${SEP}$DYLD_LIBRARY_PATH:$NPTOOL/NPSimulation/lib
+  ${CMD} DYLD_LIBRARY_PATH${SEP}$NPTOOL/NPLib/lib:$DYLD_LIBRARY_PATH
+  ${CMD} DYLD_LIBRARY_PATH${SEP}$NPTOOL/NPSimulation/lib:$DYLD_LIBRARY_PATH
 else 
-  ${CMD} LD_LIBRARY_PATH${SEP}$LD_LIBRARY_PATH:$NPTOOL/NPLib/lib
-  ${CMD} LD_LIBRARY_PATH${SEP}$LD_LIBRARY_PATH:$NPTOOL/NPSimulation/lib
+  ${CMD} LD_LIBRARY_PATH${SEP}$NPTOOL/NPLib/lib:$LD_LIBRARY_PATH
+  ${CMD} LD_LIBRARY_PATH${SEP}$NPTOOL/NPSimulation/lib:$LD_LIBRARY_PATH
 fi
 
-${CMD} PATH=$PATH:$NPTOOL/NPLib/bin
-${CMD} PATH=$PATH:$NPTOOL/NPSimulation/bin
+${CMD} PATH=$NPTOOL/NPLib/bin:$PATH
+${CMD} PATH=$NPTOOL/NPSimulation/bin:$PATH
 
 alias npt='cd $NPTOOL'  
 alias npl='cd $NPTOOL/NPLib'