diff --git a/NPLib/Detectors/Actar/CMakeLists.txt b/NPLib/Detectors/Actar/CMakeLists.txt
index 3a0cfd553e869df062a0a29ace253f1a7d772c64..2676dc9930a8fedc60c327e79f756444b9bb1a15 100644
--- a/NPLib/Detectors/Actar/CMakeLists.txt
+++ b/NPLib/Detectors/Actar/CMakeLists.txt
@@ -1,7 +1,10 @@
 add_custom_command(OUTPUT TActarPhysicsDict.cxx COMMAND ../../scripts/build_dict.sh TActarPhysics.h TActarPhysicsDict.cxx TActarPhysics.rootmap libNPActar.dylib DEPENDS TActarPhysics.h)
 add_custom_command(OUTPUT TActarDataDict.cxx COMMAND ../../scripts/build_dict.sh TActarData.h TActarDataDict.cxx TActarData.rootmap libNPActar.dylib DEPENDS TActarData.h)
 add_custom_command(OUTPUT MEventReducedDict.cxx COMMAND ../../scripts/build_dict.sh MEventReduced.h MEventReducedDict.cxx MEventReduced.rootmap libNPActar.dylib MTreeStructureLinkDef.h DEPENDS MEventReduced.h)
-add_library(NPActar SHARED TActarSpectra.cxx TActarData.cxx TActarPhysics.cxx TActarDataDict.cxx TActarPhysicsDict.cxx MEventReducedDict.cxx)
+add_custom_command(OUTPUT TActarPhysicsReaderDict.cxx COMMAND ../../scripts/build_dict.sh TActarPhysicsReader.h TActarPhysicsReaderDict.cxx TActarPhysicsReader.rootmap libNPActar.dylib DEPENDS TActarPhysicsReader.h)
+add_custom_command(OUTPUT TActarScatteringDict.cxx COMMAND ../../scripts/build_dict.sh TActarScattering.h TActarScatteringDict.cxx TActarScattering.rootmap libNPActar.dylib DEPENDS TActarScattering.h)
+
+add_library(NPActar SHARED TActarSpectra.cxx TActarData.cxx TActarPhysics.cxx TActarPhysicsReader.cxx TActarScatteringDict.cxx TActarScattering.cxx TActarDataDict.cxx TActarPhysicsDict.cxx TActarPhysicsReaderDict.cxx MEventReducedDict.cxx)
 target_link_libraries(NPActar ${ROOT_LIBRARIES} NPCore NPTrackReconstruction) 
-install(FILES TActarData.h TActarPhysics.h TActarSpectra.h MEventReduced.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+install(FILES TActarData.h TActarPhysics.h TActarSpectra.h MEventReduced.h TActarPhysicsReader.h TActarScattering.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
 
diff --git a/NPLib/Detectors/Actar/MTreeStructureLinkDef.h b/NPLib/Detectors/Actar/MTreeStructureLinkDef.h
index c9ec8b317d947c4bce19560139b89eaf73c89405..3b079dfa434cb48e437dbd25102a2a72c2560b27 100644
--- a/NPLib/Detectors/Actar/MTreeStructureLinkDef.h
+++ b/NPLib/Detectors/Actar/MTreeStructureLinkDef.h
@@ -8,5 +8,7 @@
 #pragma link C++ class ReducedData+;
 #pragma link C++ class MEventReduced+;
 
+#pragma link C++ class TActarPhysicsReader+;
+#pragma link C++ class TActarScattering+;
 
 #endif
diff --git a/NPLib/Detectors/Actar/TActarData.cxx b/NPLib/Detectors/Actar/TActarData.cxx
index 9c569553b800eca7c8769b9764dc9e57e21ecec6..1524dbb01c5644039a4865f956662bf1d2c7720f 100644
--- a/NPLib/Detectors/Actar/TActarData.cxx
+++ b/NPLib/Detectors/Actar/TActarData.cxx
@@ -51,6 +51,8 @@ void TActarData::Clear() {
     fActar_PadZ.clear();
     fActar_PadCharge.clear();
 
+    fActar_RebinningMap.clear();
+
     fSilicon_Energy.clear();
     fSilicon_Time.clear();
     fSilicon_DetectorNumber.clear();
@@ -79,3 +81,33 @@ void TActarData::Dump() const {
   }
 
 }
+//////////////////////////////////////////////////////////////////////
+void TActarData::RebinData(){
+    fActar_PadNumber.clear();
+    fActar_PadX.clear();
+    fActar_PadY.clear();
+    fActar_PadZ.clear();
+    fActar_PadCharge.clear();
+    fZ_trigger = 256;
+    int min_offset = 1000;
+    for(auto it = fActar_RebinningMap.begin(); it != fActar_RebinningMap.end(); ++it)
+    {
+      int x, y, z;
+      int rest_z;
+      z = it->first/1000000;
+      rest_z = it->first-z*1000000;
+      y = rest_z/1000;
+      x = rest_z-y*1000;
+      if((x > 1 && x < 126 && y == 39) || (x>1 && x < 126 && y == 68)) //58Ni experiment
+      {
+        int this_offset = fabs(z-256);
+        if(this_offset < min_offset){
+          fZ_trigger = z;
+          min_offset = this_offset;
+        }
+      }
+      //cout << "ID : " << it->first << " x = " << x << " y =  " << y << " z = " << z << " q = " << it->second <<  endl;
+      //if(it->second > 100)
+      fActar_PadNumber.push_back(x*128+y); fActar_PadX.push_back(x); fActar_PadY.push_back(y); fActar_PadZ.push_back(z); fActar_PadCharge.push_back(it->second);
+    }
+}
diff --git a/NPLib/Detectors/Actar/TActarData.h b/NPLib/Detectors/Actar/TActarData.h
index 5674c6aa4d6b929bc34c8542cba1c0049c847118..95b71843158ad6bfdb3ca26ec39d9024c7b1745b 100644
--- a/NPLib/Detectors/Actar/TActarData.h
+++ b/NPLib/Detectors/Actar/TActarData.h
@@ -24,6 +24,7 @@
 
 // STL
 #include <vector>
+#include <map>
 using namespace std;
 
 // ROOT
@@ -49,6 +50,9 @@ class TActarData : public TObject {
     vector<double> fCsI_Energy;
     vector<int> fCsI_CrystalNumber;
 
+    map<int, double> fActar_RebinningMap; //!
+    int fZ_trigger; //!
+
 
   //////////////////////////////////////////////////////////////
   // Constructor and destructor
@@ -64,6 +68,11 @@ class TActarData : public TObject {
     void Clear(const Option_t*) {};
     void Dump() const;
 
+  //////////////////////////////////////////////////////////////
+  // Methods to "rebin" the data in case of simulations
+
+  public:
+    void RebinData(); //!
 
   //////////////////////////////////////////////////////////////
   // Getters and Setters
@@ -89,10 +98,15 @@ class TActarData : public TObject {
         fActar_PadX.push_back(ColumnNbr);
     }
     // Time Z
-    inline void SetPadZ(const Double_t& Time)	{
+    inline void SetPadZ(const int& Time)	{
       fActar_PadZ.push_back(Time);
     };//!
 
+    // Rebinning (for simulation purpose)
+    inline void AddInRebinningMap(const int & ID, const double & charge){
+      fActar_RebinningMap[ID] += charge;
+    }
+
     //Silicon
     inline void SetSiliconEnergy(const Double_t& Energy){
       fSilicon_Energy.push_back(Energy);
@@ -122,11 +136,13 @@ class TActarData : public TObject {
     inline UShort_t GetPadX(const unsigned int &i) const
       {return fActar_PadX[i];}//!
     inline UShort_t GetPadY(const unsigned int &i) const
-    {return fActar_PadY[i];}//!
-    inline Double_t GetPadZ(const unsigned int &i) const
-    {return fActar_PadZ[i];}//!
+      {return fActar_PadY[i];}//!
+    inline int GetPadZ(const unsigned int &i) const
+      {return fActar_PadZ[i];}//!
     inline Double_t GetPadCharge(const unsigned int &i) const
       {return fActar_PadCharge[i];}//!
+    inline UShort_t GetZTrigger() const
+      {return fZ_trigger;}//!
    
 
 
diff --git a/NPLib/Detectors/Actar/TActarPhysics.cxx b/NPLib/Detectors/Actar/TActarPhysics.cxx
index 1d83d2156d6516e45da21d1929464c06467467e8..da9dbd291b5a7fa090a072a96ab6a1e9fa285dbe 100644
--- a/NPLib/Detectors/Actar/TActarPhysics.cxx
+++ b/NPLib/Detectors/Actar/TActarPhysics.cxx
@@ -9,7 +9,7 @@
  * Original Author: Pierre Morfouace  contact address: morfouace@ganil.fr    *
  *                                                                           *
  * Creation Date  : September 2017                                           *
- * Last update    :                                                          *
+ * Last update    : November 2024                                            *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
  *  This class hold Actar Treated  data                               *
@@ -63,15 +63,28 @@ TActarPhysics::TActarPhysics()
   fXBeamMax(128),
   fYBeamMin(60),
   fYBeamMax(67),
+  fAngleBeamMax(5),
+  fVertexDistanceMax(5),
   fNumberOfPadsX(128),
   fNumberOfPadsY(128),
   fPadSizeX(2),
   fPadSizeY(2),
+  fTimeSampling(80),
   fDriftVelocity(40),
   fPressure(100),
   fGas("iC4H10"),
+  fPercentRange(0.95),
+  fShortTrackMaxRange(40),
   m_NumberOfPadSilicon(20),
-  m_NumberOfDetectors(0) {
+  m_NumberOfDetectors(0),
+  fIsGoodEvent(true),
+  fScattering(false),
+  fIsSimulation(false),
+  fPixelStatusFilePath(""),
+  fPixelStatusLoaded(false)
+  {
+    m_randgen = new TRandom3(time(0));
+    //InitSpectra();
   }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -95,45 +108,131 @@ void TActarPhysics::AddDetector(double R, double Theta, double Phi, string shape
 void TActarPhysics::BuildSimplePhysicalEvent() {
   BuildPhysicalEvent();
 }
+///////////////////////////////////////////////////////////////////////////
+void TActarPhysics::BuildScatteringPhysicalEvent(){
+
+  if(fRecoRansac && PadX.size()>fHitThreshold){
+    m_Track =  m_Ransac->SimpleRansac(PadX, PadY, PadZ, PadCharge);
+  }
+  else {
+    fIsGoodEvent = false;
+    return ;
+  }
+
+  TrackMult = m_Track.size();
+  int voxels_in_all_clusters = 0;
+
+
+  for(auto & track : m_Track){
+    voxels_in_all_clusters+=track.size();
+    track.FastLinearFit();
+    TVector3 d = track.GetDir();
+    double Theta_X = d.Angle(TVector3(1, 0, 0))*180/M_PI;
+    ThetaX.push_back(Theta_X);
+    if(fabs(Theta_X) < fAngleBeamMax || fabs(180-Theta_X) < fAngleBeamMax){
+      BeamTrackMult++;
+      if(track.GetDir().X() < 0) track.Inverse();
+      m_BeamTrack.push_back(track);
+    }
+    else{
+      ScatteredTrackMult++;
+      m_ScatteredTrack.push_back(track);
+    }
+  }
+  if(m_ScatteredTrack.size() == 0){
+    fIsGoodEvent = false;
+    return ;
+  }
+
+  for(auto & bTrack : m_BeamTrack){
+    for(auto & sTrack : m_ScatteredTrack){
+      TVector3 vertex;
+      TVector3 delta;
+      double minDist = NPL::MinimumDistanceTwoLines(bTrack.GetP0(), bTrack.GetP0()+bTrack.GetDir(), sTrack.GetP0(), sTrack.GetP0()+sTrack.GetDir(), vertex, delta);
+      if(minDist < fVertexDistanceMax){
+        if(vertex.X() < 1 || vertex.X() > 255 || vertex.Y() < 110 || vertex.Y() > 146) { //Reject if vertex is out of box and beam zone
+          continue;
+        }
+        sTrack.SetShortTrackMaxLength(fShortTrackMaxRange);
+        sTrack.CalculateTrackLength(vertex, fPercentRange); //Do it first cause it also puts the track in the good direction
+        if(sTrack.GetFurthestPoint().X() < 3 || sTrack.GetFurthestPoint().X() > 253 || sTrack.GetFurthestPoint().Y() < 3 || sTrack.GetFurthestPoint().Y() > 253){ //Reject if scattered track go out of box
+          continue;
+        }
+        double Phi = TMath::ATan2(sTrack.GetDir().Z(),sTrack.GetDir().Y())>0?TMath::ATan2(sTrack.GetDir().Z(),sTrack.GetDir().Y())*180./M_PI:TMath::ATan2(sTrack.GetDir().Z(),sTrack.GetDir().Y())*180/M_PI+360;
+        if(fabs(Phi-90) < 10 || fabs(Phi-270) < 10){ //Reject if track is vertical
+          continue;
+        }
+
+        TActarScattering aScatteringEvent;
+        aScatteringEvent.Vertex = vertex;
+        aScatteringEvent.Phi = Phi;
+        aScatteringEvent.Range = sTrack.GetTrackLength();
+        aScatteringEvent.EndOfTrack = sTrack.GetFurthestPoint();
+        aScatteringEvent.Charge = sTrack.GetCharge();
+        aScatteringEvent.Theta = bTrack.GetDir().Angle(sTrack.GetDir())*180/M_PI;
+        aScatteringEvent.Voxels = sTrack.size();
+
+        VertexMult++;
+        //We shorten the track to measure an angle without the deviation
+        sTrack.FastLinearFitShort();
+        sTrack.CheckDirection(vertex);
+        double Phi_Short = TMath::ATan2(sTrack.GetDir().Z(),sTrack.GetDir().Y())>0?TMath::ATan2(sTrack.GetDir().Z(),sTrack.GetDir().Y())*180./M_PI:TMath::ATan2(sTrack.GetDir().Z(),sTrack.GetDir().Y())*180/M_PI+360;
+
+        aScatteringEvent.PhiShort = Phi_Short;
+        aScatteringEvent.ThetaShort = bTrack.GetDir().Angle(sTrack.GetDir())*180/M_PI;
+        Scattering.push_back(aScatteringEvent);
+
+      }
+    }
+  }
+  if(VertexMult < 1){
+    fIsGoodEvent = false;
+    return;
+  }
+
+}
 
 
 
 ///////////////////////////////////////////////////////////////////////////
 void TActarPhysics::BuildPhysicalEvent() {
-
+  if (NPOptionManager::getInstance()->IsReader() == true) {
+    m_EventReduced = &(**r_ReaderEventData);
+  }
   PreTreat();
 
-  //unsigned int mysize = m_PreTreatedData->GetPadMult();
-
-  /*for (unsigned int e = 0; e < mysize; e++) {
-    PadX.push_back(m_PreTreatedData->GetPadX(e));
-    PadY.push_back(m_PreTreatedData->GetPadY(e));
-    PadZ.push_back(m_PreTreatedData->GetPadZ(e));
-    PadCharge.push_back(m_PreTreatedData->GetPadCharge(e));
-    }*/
-  if(fRecoRansac && PadX.size()>fHitThreshold){
-    //m_Ransac->Init(PadX, PadY, PadZ, PadCharge);
-    m_Ransac->Init(PadX, PadY, PadZ, PadCharge);
-    m_Track = m_Ransac->SimpleRansac();
+  //If scattering mode is activated, then we use the dedicated method to process the data
+  if(fScattering) {
+    BuildScatteringPhysicalEvent();
+    return ;
+  }
+  
+  if(fRecoRansac){
+    m_Track = m_Ransac->SimpleRansac(PadX, PadY, PadZ, PadCharge);
   }
 
-  else if(fRecoCluster){
-    if(PadX.size()>fHitThreshold){
-      m_Cluster->Init(PadX, PadY, PadZ, PadCharge);
-      m_Cluster->FindTracks();
-    }
 
-    if(BeamPadX.size()>fHitThreshold){
-      m_Cluster->Init(BeamPadX, BeamPadY, BeamPadZ, BeamPadCharge);
-      m_Cluster->FindTracks();
-    }
+  //////  NEED TO BE CORRECTED CAUSE TYPE of PADX, PADY changed //////
 
-    m_Track = m_Cluster->GetTracks();
+  // else if(fRecoCluster){
+  //   if(PadX.size()>fHitThreshold){
+  //     m_Cluster->Init(PadX, PadY, PadZ, PadCharge);
+  //     m_Cluster->FindTracks();
+  //   }
 
-    m_Cluster->Clear();
-  }
+  //   if(BeamPadX.size()>fHitThreshold){
+  //     m_Cluster->Init(BeamPadX, BeamPadY, BeamPadZ, BeamPadCharge);
+  //     m_Cluster->FindTracks();
+  //   }
 
-  TrackMult = m_Track.size();
+  //   m_Track = m_Cluster->GetTracks();
+
+  //   m_Cluster->Clear();
+  // }
+
+  TrackMult = m_Track.size();  
+  
+  //cout << "End of Physical event building" << endl;
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -142,11 +241,14 @@ void TActarPhysics::PreTreat() {
   // Might test for disabled channels for more complex detector
 
   // clear pre-treated object
-  ClearPreTreatedData();
+  //ClearPreTreatedData();
 
-  CleanPads();
+  //CleanPads();
 
   // instantiate CalibrationManager
+
+  //cout << "Start pre-treating" << endl;
+
   static CalibrationManager* Cal = CalibrationManager::getInstance();
 
 
@@ -157,35 +259,52 @@ void TActarPhysics::PreTreat() {
     int ag=(m_EventReduced->CoboAsad[it].globalchannelid - (co<<11)-(as<<9))>>7;
     int ch=m_EventReduced->CoboAsad[it].globalchannelid - (co<<11)-(as<<9)-(ag<<7);
     int where=co*NumberOfASAD*NumberOfAGET*NumberOfChannel + as*NumberOfAGET*NumberOfChannel + ag*NumberOfChannel + ch;
-    if(co!=31){
+    if(co<16){
       unsigned int vector_size = m_EventReduced->CoboAsad[it].peakheight.size();
-      //cout << vector_size << endl;
-      for(unsigned int hh=0; hh<vector_size; hh++){
-        if(m_EventReduced->CoboAsad[it].peakheight[hh]>fQ_Threshold && m_EventReduced->CoboAsad[it].peaktime[hh]>fT_Threshold){
-          if(GoodHit(TABLE[4][where],TABLE[5][where])){
-            //if(Hit[TABLE[4][where]][TABLE[5][where]]<2){
-            if(fRecoCluster){
-              if(IsBeamZone(TABLE[4][where],TABLE[5][where])){
-                BeamPadCharge.push_back(m_EventReduced->CoboAsad[it].peakheight[hh]);
-                BeamPadX.push_back(TABLE[4][where]);
-                BeamPadY.push_back(TABLE[5][where]);
-                BeamPadZ.push_back(int(m_EventReduced->CoboAsad[it].peaktime[hh]*fDriftVelocity));
-              }
-              else{
-                PadCharge.push_back(m_EventReduced->CoboAsad[it].peakheight[hh]);
-                PadX.push_back(TABLE[4][where]);
-                PadY.push_back(TABLE[5][where]);
-                PadZ.push_back(int(m_EventReduced->CoboAsad[it].peaktime[hh]*fDriftVelocity));
-              }
 
-            }
-            else if(fRecoRansac){
-              PadCharge.push_back(m_EventReduced->CoboAsad[it].peakheight[hh]);
-              PadX.push_back(TABLE[4][where]);
-              PadY.push_back(TABLE[5][where]);
-              PadZ.push_back(int(m_EventReduced->CoboAsad[it].peaktime[hh]*fDriftVelocity));
-            }
-            //}
+      if(fIsSimulation){
+        m_EventData->Clear();
+
+        for(unsigned int hh=0; hh<vector_size; hh++){
+          int xx = TABLE[4][where], yy = TABLE[5][where], zz = static_cast<int>(m_EventReduced->CoboAsad[it].peaktime[hh]/fTimeSampling+128);
+          if(fPixelStatusLoaded && !PixelStatusTable[xx][yy]) continue; //remove the "bad" pixels given by the table
+          m_EventData->AddInRebinningMap(1000000*zz+1000*yy+xx, m_EventReduced->CoboAsad[it].peakheight[hh]); //In order to have 512 bin of 80ns in Z
+        }
+        m_EventData->RebinData();
+        for(unsigned int i = 0; i < m_EventData->GetPadMult(); i++){
+          int xx = m_EventData->GetPadX(i), yy = m_EventData->GetPadY(i), zz = m_EventData->GetPadZ(i);
+          if(fPixelStatusLoaded && !PixelStatusTable[xx][yy]) continue; //remove the "bad" pixels given by the table
+
+          static string name_pixel;
+          name_pixel = "Actar/X" ;
+          name_pixel+= NPL::itoa(xx);
+          name_pixel+= "_Y" ;
+          name_pixel+= NPL::itoa(yy);
+          name_pixel+= "_Q";
+          double CalCharge = CalibrationManager::getInstance()->ApplyCalibration(name_pixel, m_EventData->GetPadCharge(i));
+          if(CalCharge>fQ_Threshold){
+            double new_zz = (256+zz-m_EventData->GetZTrigger()); //To shift the z according to the trigger time (as in experimental data)
+            PadCharge.push_back(CalCharge);
+            PadX.push_back((double)xx*fPadSizeX);
+            PadY.push_back((double)yy*fPadSizeY);
+            PadZ.push_back((double)new_zz*fTimeSampling*fDriftVelocity);
+          }
+        }
+      }
+      else{
+        for(unsigned int hh=0; hh<vector_size; hh++){
+          static string name_pixel;
+          name_pixel = "Actar/X" ;
+          name_pixel+= NPL::itoa(TABLE[4][where]);
+          name_pixel+= "_Y" ;
+          name_pixel+= NPL::itoa(TABLE[5][where]);
+          name_pixel+= "_Q";
+          double CalCharge = CalibrationManager::getInstance()->ApplyCalibration(name_pixel, m_EventReduced->CoboAsad[it].peakheight[hh]);
+          if(CalCharge>fQ_Threshold && m_EventReduced->CoboAsad[it].peaktime[hh]>fT_Threshold){
+            PadCharge.push_back(CalCharge);
+            PadX.push_back((double)TABLE[4][where]*fPadSizeX);
+            PadY.push_back((double)TABLE[5][where]*fPadSizeY);
+            PadZ.push_back((double)(m_EventReduced->CoboAsad[it].peaktime[hh]*fTimeSampling*fDriftVelocity)); 
           }
         }
       }
@@ -216,6 +335,7 @@ void TActarPhysics::PreTreat() {
       }
     }
   }
+  //cout << "End of pre-treatment" << endl;
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -249,7 +369,6 @@ bool TActarPhysics::GoodHit(int iX, int iY)
 void TActarPhysics::CleanPads()
 {
   unsigned int mysize = m_EventReduced->CoboAsad.size();
-
   for(unsigned int it=0; it<mysize; it++){
     int co=m_EventReduced->CoboAsad[it].globalchannelid>>11;
     int as=(m_EventReduced->CoboAsad[it].globalchannelid - (co<<11))>>9;
@@ -257,8 +376,7 @@ void TActarPhysics::CleanPads()
     int ch=m_EventReduced->CoboAsad[it].globalchannelid - (co<<11)-(as<<9)-(ag<<7);
     int where=co*NumberOfASAD*NumberOfAGET*NumberOfChannel + as*NumberOfAGET*NumberOfChannel + ag*NumberOfChannel + ch;
 
-
-    if(co!=31){
+    if(co<16){
       unsigned int vector_size = m_EventReduced->CoboAsad[it].peakheight.size();
       for(unsigned int hh=0; hh < vector_size; hh++){
         if(m_EventReduced->CoboAsad[it].peakheight[hh]>fQ_Threshold && m_EventReduced->CoboAsad[it].peaktime[hh]>fT_Threshold){
@@ -276,44 +394,6 @@ void TActarPhysics::CleanPads()
 
 ///////////////////////////////////////////////////////////////////////////
 void TActarPhysics::ReadAnalysisConfig() {
-  // VXI ACTION FILE //
-  string VXI_FileName = "./configs/ACTION_Si_config.dat";
-  ifstream VXIConfigFile;
-  VXIConfigFile.open(VXI_FileName.c_str());
-  if(!VXIConfigFile.is_open()){
-    cout << "No VXI ACTION FILE ./configs/ACTION_Si_config.dat found!" << endl;
-    return;
-  }
-  else{
-    cout << "/// Using VXI ACTION FILE: " << VXI_FileName << " ///" << endl;
-    string token;
-    int vxi_param, si_nbr;
-    for(int i=0; i<20; i++){
-      VXIConfigFile >> token >> vxi_param >> si_nbr;
-      Si_map[vxi_param] = si_nbr+1;
-    }
-  }
-  VXIConfigFile.close();
-
-  // Lookup table //
-  bool ReadingLookupTable = false;
-  string LT_FileName = "./configs/LT.dat";
-  ifstream LTConfigFile;
-  LTConfigFile.open(LT_FileName.c_str());
-  if(!LTConfigFile.is_open()){
-    cout << "No Lookup Table in ./configs/LT.dat found!" << endl;
-    return;
-  }
-  else{
-    cout << "/// Using LookupTable from: " << LT_FileName << " ///" << endl;
-    for(int i=0;i<NumberOfCobo*NumberOfASAD*NumberOfAGET*NumberOfChannel;i++){
-      LTConfigFile >> TABLE[0][i] >> TABLE[1][i] >> TABLE[2][i] >> TABLE[3][i] >> TABLE[4][i] >> TABLE[5][i];
-    }
-    ReadingLookupTable = true;
-  }
-  LTConfigFile.close();
-
-
   bool ReadingStatus = false;
 
   // ACTAR config file //
@@ -420,6 +500,13 @@ void TActarPhysics::ReadAnalysisConfig() {
         cout << "/// Pad Size Y= " << fPadSizeY << " ///" << endl;
       }
 
+      else if(whatToDo.compare(0,13,"TimeSampling=")==0){
+        AnalysisConfigFile >> DataBuffer;
+        fTimeSampling = atof(DataBuffer.c_str());
+        //check_sizeY=true;
+        cout << "/// Time sampling= " << fTimeSampling << " ///" << endl;
+      }
+
       else if(whatToDo.compare(0,9,"XBeamMin=")==0){
         AnalysisConfigFile >> DataBuffer;
         fXBeamMin = atof(DataBuffer.c_str());
@@ -444,6 +531,30 @@ void TActarPhysics::ReadAnalysisConfig() {
         cout << "/// Y Beam Max= " << fYBeamMax << " ///" << endl;
       }
 
+      else if(whatToDo.compare(0,13,"AngleBeamMax=")==0){
+        AnalysisConfigFile >> DataBuffer;
+        fAngleBeamMax = atof(DataBuffer.c_str());
+        cout << "/// Angle Beam Max= " << fAngleBeamMax << " ///" << endl;
+      }
+
+      else if(whatToDo.compare(0,18,"VertexDistanceMax=")==0){
+        AnalysisConfigFile >> DataBuffer;
+        fVertexDistanceMax = atof(DataBuffer.c_str());
+        cout << "/// Vertex Distance Max= " << fVertexDistanceMax << " ///" << endl;
+      }
+
+      else if(whatToDo.compare(0,13,"PercentRange=")==0){
+        AnalysisConfigFile >> DataBuffer;
+        fPercentRange = atof(DataBuffer.c_str());
+        cout << "/// Percentage Range= " << fPercentRange << " ///" << endl;
+      }
+
+      else if(whatToDo.compare(0,20,"ShortTrackMaxLength=")==0){
+        AnalysisConfigFile >> DataBuffer;
+        fShortTrackMaxRange = atof(DataBuffer.c_str());
+        cout << "/// Short Track Max Range= " << fShortTrackMaxRange << " ///" << endl;
+      }
+
       else if(whatToDo.compare(0,19,"NumberOfPadSilicon=")==0){
         AnalysisConfigFile >> DataBuffer;
         m_NumberOfPadSilicon = atof(DataBuffer.c_str());
@@ -472,14 +583,92 @@ void TActarPhysics::ReadAnalysisConfig() {
         cout << "/// Gas Type= " << fGas << " ///" << endl;
       }
 
+      else if(whatToDo.compare(0,11,"Scattering=")==0){
+        AnalysisConfigFile >> DataBuffer;
+        if(atoi(DataBuffer.c_str()) == 1) {
+          fScattering = true;
+          cout << "/// Scattering mode activated ///" << endl;
+        }
+      }
+
+      else if(whatToDo.compare(0,11,"Simulation=")==0){
+        AnalysisConfigFile >> DataBuffer;
+        if(atoi(DataBuffer.c_str()) == 1) {
+          fIsSimulation = true;
+          cout << "/// Assuming analysis of simulated data ///" << endl;
+        }
+      }
+
+      else if(whatToDo.compare(0,12,"PixelStatus=")==0){
+        AnalysisConfigFile >> DataBuffer;
+          fPixelStatusFilePath = DataBuffer.c_str();
+          cout << "/// Pixel Status file path : " << fPixelStatusFilePath << " ///" << endl;
+          ifstream pixel_status(fPixelStatusFilePath);
+          if(!pixel_status.is_open()) cerr << "Error opening the pixel status file ..." << endl;
+          else{
+            int xx, yy, vv;
+            while(pixel_status >> xx >> yy >> vv){
+              PixelStatusTable[xx][yy] = vv>0;
+            }
+            cout << "Pixel status loaded ! " << endl;
+            fPixelStatusLoaded = true;
+            pixel_status.close();
+          }
+      }
+
+    
       else {
         ReadingStatus = false;
       }
     }
+      // VXI ACTION FILE //
+  string VXI_FileName = "./configs/ACTION_Si_config.dat";
+  ifstream VXIConfigFile;
+  VXIConfigFile.open(VXI_FileName.c_str());
+  if(!VXIConfigFile.is_open()){
+    cout << "No VXI ACTION FILE ./configs/ACTION_Si_config.dat found!" << endl;
+    //return; //I commented that because I don't use VXI file for my analysis
+  }
+  else{
+    cout << "/// Using VXI ACTION FILE: " << VXI_FileName << " ///" << endl;
+    string token;
+    int vxi_param, si_nbr;
+    for(int i=0; i<20; i++){
+      VXIConfigFile >> token >> vxi_param >> si_nbr;
+      Si_map[vxi_param] = si_nbr+1;
+    }
+  }
+  VXIConfigFile.close();
+
+  // Lookup table //
+  bool ReadingLookupTable = false;
+  string LT_FileName; 
+  if(IsSimulation()) {LT_FileName = "./configs/LT_SIMU.dat";}
+  else {LT_FileName = "./configs/LT.dat";}
+  ifstream LTConfigFile;
+  LTConfigFile.open(LT_FileName.c_str());
+  if(!LTConfigFile.is_open()){
+    cout << "No Lookup Table in ./configs/LT.dat found!" << endl;
+    return;
+  }
+  else{
+    cout << "/// Using LookupTable from: " << LT_FileName << " ///" << endl;
+    for(int i=0;i<NumberOfCobo*NumberOfASAD*NumberOfAGET*NumberOfChannel;i++){
+      LTConfigFile >> TABLE[0][i] >> TABLE[1][i] >> TABLE[2][i] >> TABLE[3][i] >> TABLE[4][i] >> TABLE[5][i];
+      //cout << i << "\t" << TABLE[0][i] << "\t" << TABLE[1][i] << "\t" << TABLE[2][i] << "\t" << TABLE[3][i] << "\t" << TABLE[4][i] << "\t" << TABLE[5][i] << endl;
+    }
+    ReadingLookupTable = true;
+  }
+  LTConfigFile.close();
   }
 
   if(fRecoRansac){
-    m_Ransac = new NPL::Ransac(fNumberOfPadsX,fNumberOfPadsY,fRecoVisu);
+    m_Ransac = new NPL::RansacACTAR();
+    SetRansacParameter("./configs/RansacConfig_data.dat");
+    TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
+    asciiConfig->AppendLine("%%% ConfigRANSACActar.dat %%%");
+    asciiConfig->Append("./configs/RansacConfig_data.dat");
+    asciiConfig->AppendLine("");
   }
   else if(fRecoCluster){
     m_Cluster = new NPL::Cluster(fNumberOfPadsX,fNumberOfPadsY,fRecoVisu);
@@ -511,15 +700,23 @@ void TActarPhysics::Clear() {
   PadY.clear();
   PadZ.clear();
   PadCharge.clear();
+
   m_Track.clear();
+  m_BeamTrack.clear();
+  m_ScatteredTrack.clear();
+
   Si_Number.clear();
   Si_E.clear();
 
-  for(int i=0; i<fNumberOfPadsX; i++){
-    for(int j=0; j<fNumberOfPadsY; j++){
-      Hit[i][j] = 0;
-    }
-  }
+  ThetaX.clear();
+
+  Scattering.clear();
+
+  TrackMult = 0;
+  BeamTrackMult = 0;
+  ScatteredTrackMult = 0;
+  VertexMult = 0;
+  fIsGoodEvent = true;
 }
 
 
@@ -556,14 +753,19 @@ void TActarPhysics::ReadConfiguration(NPL::InputParser parser) {
       exit(1);
     }
   }
+
+  ReadAnalysisConfig();
 }
 
 ///////////////////////////////////////////////////////////////////////////
 void TActarPhysics::InitSpectra() {
-  m_Spectra = new TActarSpectra(m_NumberOfDetectors);
-}
-
+  m_Spectra = new TActarSpectra(1);
+} 
 
+///////////////////////////////////////////////////////////////////////////
+void TActarPhysics::SetTreeReader(TTreeReader* TreeReader) {
+  TActarPhysicsReader::r_SetTreeReader(TreeReader, fIsSimulation);
+}
 
 ///////////////////////////////////////////////////////////////////////////
 void TActarPhysics::FillSpectra() {
@@ -620,15 +822,24 @@ void TActarPhysics::WriteSpectra() {
 
 
 ///////////////////////////////////////////////////////////////////////////
+// void TActarPhysics::AddParameterToCalibrationManager() {
+//   CalibrationManager* Cal = CalibrationManager::getInstance();
+//   for (int i = 0; i < m_NumberOfDetectors; ++i) {
+//     Cal->AddParameter("Actar", "D"+ NPL::itoa(i+1)+"_CHARGE","Actar_D"+ NPL::itoa(i+1)+"_CHARGE");
+//     Cal->AddParameter("Actar", "D"+ NPL::itoa(i+1)+"_TIME","Actar_D"+ NPL::itoa(i+1)+"_TIME");
+//   }
+
+//   for(int i=0; i<m_NumberOfPadSilicon; i++){
+//     Cal->AddParameter("ActarSi","D"+NPL::itoa(i)+"_E","ActarSi_D"+NPL::itoa(i)+"_E");
+//   }
+// }
+
 void TActarPhysics::AddParameterToCalibrationManager() {
   CalibrationManager* Cal = CalibrationManager::getInstance();
-  for (int i = 0; i < m_NumberOfDetectors; ++i) {
-    Cal->AddParameter("Actar", "D"+ NPL::itoa(i+1)+"_CHARGE","Actar_D"+ NPL::itoa(i+1)+"_CHARGE");
-    Cal->AddParameter("Actar", "D"+ NPL::itoa(i+1)+"_TIME","Actar_D"+ NPL::itoa(i+1)+"_TIME");
-  }
-
-  for(int i=0; i<m_NumberOfPadSilicon; i++){
-    Cal->AddParameter("ActarSi","D"+NPL::itoa(i)+"_E","ActarSi_D"+NPL::itoa(i)+"_E");
+  for (int X = 0; X < fNumberOfPadsX; ++X) {
+    for (int Y = 0; Y < fNumberOfPadsX; ++Y) {
+      Cal->AddParameter("ACTAR", "X"+ NPL::itoa(X)+"_Y"+NPL::itoa(Y)+"_Q","ACTAR_X"+ NPL::itoa(X)+"_Y"+NPL::itoa(Y)+"_Q");
+    }
   }
 }
 
@@ -644,10 +855,18 @@ void TActarPhysics::AddParameterToCalibrationManager() {
 ///////////////////////////////////////////////////////////////////////////
 void TActarPhysics::InitializeRootInputRaw() {
   TChain* inputChain = RootInput::getInstance()->GetChain();
-  inputChain->SetBranchStatus("data",  true );
-  inputChain->SetBranchStatus("ACTAR_TTree",  true );
-  inputChain->SetBranchAddress("data", &m_EventReduced );
 
+  // Option to use the npreader anaysis
+  if (NPOptionManager::getInstance()->IsReader() == true) {
+    TTreeReader* inputTreeReader = RootInput::getInstance()->GetTreeReader();
+    inputTreeReader->SetTree(inputChain);
+  }
+  // Option to use the standard npanalysis
+  else{
+    inputChain->SetBranchStatus("data",  true );
+    //inputChain->SetBranchStatus("ACTAR_TTree",  true );
+    inputChain->SetBranchAddress("data", &m_EventReduced );
+  }
   fInputTreeName = inputChain->GetTree()->GetName();
 }
 
@@ -656,7 +875,15 @@ void TActarPhysics::InitializeRootInputRaw() {
 ///////////////////////////////////////////////////////////////////////////
 void TActarPhysics::InitializeRootInputPhysics() {
   TChain* inputChain = RootInput::getInstance()->GetChain();
-  inputChain->SetBranchAddress("Actar", &m_EventPhysics);
+  // Option to use the nptreereader anaysis
+  if (NPOptionManager::getInstance()->IsReader() == true) {
+    TTreeReader* inputTreeReader = RootInput::getInstance()->GetTreeReader();
+    inputTreeReader->SetTree(inputChain);
+  }
+  // Option to use the standard npanalysis
+  else{
+    inputChain->SetBranchAddress("Actar", &m_EventPhysics);
+  }
 }
 
 
@@ -676,6 +903,10 @@ NPL::VDetector* TActarPhysics::Construct() {
   return (NPL::VDetector*) new TActarPhysics();
 }
 
+NPL::VTreeReader* TActarPhysics::ConstructReader() {
+  return (NPL::VTreeReader*)new TActarPhysicsReader(); 
+}
+
 
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -687,6 +918,8 @@ extern "C"{
       proxy_Actar(){
         NPL::DetectorFactory::getInstance()->AddToken("Actar","Actar");
         NPL::DetectorFactory::getInstance()->AddDetector("Actar",TActarPhysics::Construct);
+        NPL::DetectorFactory::getInstance()->AddDetectorReader("Actar", TActarPhysics::ConstructReader);
+
       }
   };
 
diff --git a/NPLib/Detectors/Actar/TActarPhysics.h b/NPLib/Detectors/Actar/TActarPhysics.h
index 505fbd367072f302b70fb3829fc2b077f910041a..93c84328515922d3ee357a695f223e34bb17744c 100644
--- a/NPLib/Detectors/Actar/TActarPhysics.h
+++ b/NPLib/Detectors/Actar/TActarPhysics.h
@@ -11,10 +11,10 @@
  * Original Author: Pierre Morfouace  contact address: morfouace@ganil.fr    *
  *                                                                           *
  * Creation Date  : September 2017                                           *
- * Last update    :                                                          *
+ * Last update    : November 2024                                            *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
- *  This class hold Actar Treated data                                *
+ *  This class hold Actar Treated data                                       *
  *                                                                           *
  *---------------------------------------------------------------------------*
  * Comment:                                                                  *
@@ -40,10 +40,16 @@ using namespace std;
 #include "TActarSpectra.h"
 #include "NPCalibrationManager.h"
 #include "NPVDetector.h"
+#include "NPVTreeReader.h"
 #include "NPInputParser.h"
 #include "NPTrack.h"
 #include "NPRansac.h"
 #include "NPCluster.h"
+#include "NPRansacACTAR.h"
+#include "NPTrackingUtility.h"
+#include "NPEnergyLoss.h"
+#include "TActarPhysicsReader.h"
+#include "TActarScattering.h"
 
 #define NumberOfCobo 16
 #define NumberOfASAD 4
@@ -52,12 +58,14 @@ using namespace std;
 
 class TActarSpectra;
 
-class TActarPhysics : public TObject, public NPL::VDetector {
+class TActarPhysics : public TObject, public NPL::VDetector, public TActarPhysicsReader {
     //////////////////////////////////////////////////////////////
     // constructor and destructor
 public:
     TActarPhysics();
-    ~TActarPhysics() {};
+    ~TActarPhysics() {
+        delete m_randgen;
+    };
 
 
     //////////////////////////////////////////////////////////////
@@ -71,17 +79,23 @@ public:
     // data obtained after BuildPhysicalEvent() and stored in
     // output ROOT file
 public:
-    vector<int> PadX;
-    vector<int> PadY;
-    vector<double> PadZ;
+    vector<double> PadX;
+    vector<double> PadY; 
+    vector<double> PadZ; 
     vector<double> PadCharge;
-    vector<int> BeamPadX;
-    vector<int> BeamPadY;
-    vector<double> BeamPadZ;
-    vector<double> BeamPadCharge;
-    vector<double> Si_E;
-    vector<int> Si_Number;
+    vector<int> BeamPadX; //!
+    vector<int> BeamPadY; //!
+    vector<double> BeamPadZ; //!
+    vector<double> BeamPadCharge; //!
+    vector<double> Si_E; //!
+    vector<int> Si_Number; //!
+    vector<double> ThetaX;
+    vector<TActarScattering> Scattering;
     int TrackMult;
+    int BeamTrackMult;
+    int ScatteredTrackMult;
+    int VertexMult;
+
 
     /// A usefull method to bundle all operation to add a detector
     void AddDetector(TVector3 POS, string shape);
@@ -89,7 +103,7 @@ public:
 
 public:
     int GetTrackMult() {return m_Track.size();}
-    vector<NPL::Track> GetTracks() {return m_Track;}
+    vector<LinearCluster3D> GetTracks() {return m_Track;}
 
 
     //////////////////////////////////////////////////////////////
@@ -109,6 +123,10 @@ public:
     // treatment
     void BuildSimplePhysicalEvent();
 
+    // build a scattering event
+    // treatment
+    void BuildScatteringPhysicalEvent();
+
     // same as above but for online analysis
     void BuildOnlinePhysicalEvent()  {BuildPhysicalEvent();};
 
@@ -147,6 +165,8 @@ public:
     // write spectra to ROOT output file
     void WriteSpectra();
 
+    void SetTreeReader(TTreeReader* TreeReader);
+
 
     //////////////////////////////////////////////////////////////
     // specific methods to Actar array
@@ -176,9 +196,12 @@ private:
     MEventReduced*      m_EventReduced;     //!
     TActarData*         m_PreTreatedData;   //!
     TActarPhysics*      m_EventPhysics;     //!
-    NPL::Ransac*        m_Ransac;           //!
+    NPL::RansacACTAR*        m_Ransac;      //!
     NPL::Cluster*       m_Cluster;          //!
-    vector<NPL::Track>  m_Track;            //!
+    vector<LinearCluster3D>  m_Track;       //!
+    vector<LinearCluster3D>  m_BeamTrack;       //!
+    vector<LinearCluster3D>  m_ScatteredTrack;  //!
+    TRandom3* m_randgen;                    //!
 
     // getters for raw and pre-treated data object
 public:
@@ -193,6 +216,9 @@ public:
     double GetPRessure() {return fPressure;}
     string GetGasName() {return fGas;}
 
+    bool IsGoodEvent() {return fIsGoodEvent;}
+    bool IsSimulation() {return fIsSimulation;}
+
     // parameters used in the analysis
 private:
     // thresholds
@@ -205,8 +231,11 @@ private:
     int fXBeamMin;          //!
     int fYBeamMax;          //!
     int fYBeamMin;          //!
+    double fAngleBeamMax;   //!
+    double fVertexDistanceMax; //!
     double fPadSizeX;       //!
     double fPadSizeY;       //!
+    double fTimeSampling;   //!
     double fDriftVelocity;  //!
     double fPressure;       //!
     string fGas;            //!
@@ -215,9 +244,19 @@ private:
     bool fRecoVisu;         //!
     map<int, int> Si_map;   //!
     string fInputTreeName;  //!
+    double fPercentRange;   //!
+    double fShortTrackMaxRange; //!
+
+    bool fIsGoodEvent; //!
+    bool fIsSimulation; //!
+    bool fScattering; //!
+
+    string fPixelStatusFilePath; //!
+    bool fPixelStatusLoaded; //!
 
     int TABLE[6][NumberOfCobo*NumberOfASAD*NumberOfAGET*NumberOfChannel]; //!
     int Hit[128][128];  //!
+    bool PixelStatusTable[128][128]; //!
 
 
     // number of detectors
@@ -233,7 +272,8 @@ private:
 public:
     void SetRansacParameter(string filename);
     void SetClusterParameter(string filename);
-    NPL::Ransac* GetRansacObject() {return m_Ransac;}
+    //NPL::Ransac* GetRansacObject() {return m_Ransac;}
+    NPL::RansacACTAR* GetRansacObject() {return m_Ransac;}
     bool GetRansacStatus() {return fRecoRansac;}
     NPL::Cluster* GetClusterObject() {return m_Cluster;}
     bool GetClusterStatus() {return fRecoCluster;}
@@ -247,6 +287,7 @@ public:
     // Static constructor to be passed to the Detector Factory
 public:
     static NPL::VDetector* Construct();
+    static NPL::VTreeReader* ConstructReader();
 
     ClassDef(TActarPhysics,1)  // ActarPhysics structure
 };
diff --git a/NPLib/Detectors/Actar/TActarPhysicsReader.cxx b/NPLib/Detectors/Actar/TActarPhysicsReader.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..a3aca597702bc38ba558fc0041c88ed6096df8f2
--- /dev/null
+++ b/NPLib/Detectors/Actar/TActarPhysicsReader.cxx
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * 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: Damien THISSE  contact address: damien.thisse@cea.fr     *
+ *                                                                           *
+ * Creation Date  : 5th November 2024                                        *
+ * Last update    : 5th November 2024                                        *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *                                                                           *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+#include "TActarPhysicsReader.h"
+#include "NPDetectorFactory.h"
+///////////////////////////////////////////////////////////////////////////
+
+ClassImp(TActarPhysicsReader)
+
+TActarPhysicsReader::TActarPhysicsReader()
+{
+};
+
+void TActarPhysicsReader::r_SetTreeReader(TTreeReader* TreeReader, bool is_simulation){
+    r_ReaderEventData = new TTreeReaderValue<MEventReduced>(*TreeReader, "data");
+    if (is_simulation)
+    {
+        r_ReaderReactionCondition = new TTreeReaderValue<TReactionConditions>(*TreeReader, "ReactionConditions");
+    }
+    
+}; 
\ No newline at end of file
diff --git a/NPLib/Detectors/Actar/TActarPhysicsReader.h b/NPLib/Detectors/Actar/TActarPhysicsReader.h
new file mode 100644
index 0000000000000000000000000000000000000000..60d8904ceefd01eb3ed917f1d687bbac5ced464f
--- /dev/null
+++ b/NPLib/Detectors/Actar/TActarPhysicsReader.h
@@ -0,0 +1,62 @@
+#ifndef TACTARPHYSICSREADER_H
+#define TACTARPHYSICSREADER_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: Hugo Jacob  contact address: hjacob@ijclab.in2p3.fr      *
+ *                                                                           *
+ * Creation Date  : 2023                                                     *
+ * Last update    : 2023
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  TTreader class for Actar Physics                                         *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+// STL
+#include <map>
+#include <vector>
+// NPL
+#include "MEventReduced.h"
+#include "TActarData.h"
+#include "TTreeReader.h"
+#include "TTreeReaderValue.h"
+#include "TTreeReaderArray.h"
+#include "RootInput.h"
+#include "RootOutput.h"
+#include "TTree.h"
+#include "NPVTreeReader.h"
+#include "TReactionConditions.h"
+
+
+using namespace std;
+
+class TActarPhysicsReader : public NPL::VTreeReader {
+public:
+  TActarPhysicsReader();
+  ~TActarPhysicsReader(){};
+  
+public:
+  void r_SetTreeReader(TTreeReader* TreeReader, bool is_simulation);
+private:
+  TTreeReader *dummy = new TTreeReader();
+public:
+  TTreeReaderValue<MEventReduced>* r_ReaderEventData = new TTreeReaderValue<MEventReduced>(*dummy,"");
+  TTreeReaderValue<TReactionConditions>* r_ReaderReactionCondition= new TTreeReaderValue<TReactionConditions>(*dummy,"");
+
+public:
+  ClassDef(TActarPhysicsReader,0);
+
+};
+
+
+#endif
diff --git a/NPLib/Detectors/Actar/TActarScattering.cxx b/NPLib/Detectors/Actar/TActarScattering.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..aa58856edbcb038e758536b8f1b85406c457aff8
--- /dev/null
+++ b/NPLib/Detectors/Actar/TActarScattering.cxx
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2017   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: Damien Thisse  contact address: damien.thisse@cea.fr     *
+ *                                                                           *
+ * Creation Date  : November 2024                                            *
+ * Last update    : November 2024                                            *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold Actar Scattring events properties                        *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+#include "TActarScattering.h"
+
+ClassImp(TActarScattering)
+
+TActarScattering::TActarScattering():
+Theta(0),
+Phi(0),
+Range(0),
+Charge(0),
+PhiShort(0),
+ThetaShort(0),
+Voxels(0),
+Energy(0)
+{}
\ No newline at end of file
diff --git a/NPLib/Detectors/Actar/TActarScattering.h b/NPLib/Detectors/Actar/TActarScattering.h
new file mode 100644
index 0000000000000000000000000000000000000000..c43a96b8effab928124b0dc5683bbccccc5ec189
--- /dev/null
+++ b/NPLib/Detectors/Actar/TActarScattering.h
@@ -0,0 +1,64 @@
+#ifndef TActarSCATTERING_H
+#define TActarSCATTERING_H
+/*****************************************************************************
+ * Copyright (C) 2009-2017   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: Damien Thisse  contact address: damien.thisse@cea.fr     *
+ *                                                                           *
+ * Creation Date  : November 2024                                            *
+ * Last update    : November 2024                                            *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold Actar Scattring events properties                        *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+// C++ headers
+
+using namespace std;
+
+// ROOT headers
+#include "TObject.h"
+#include "TVector3.h"
+
+class TActarScattering : public TObject {
+
+public:
+    TActarScattering();
+    ~TActarScattering() {};
+
+    //////////////////////////////////////////////////////////////
+    // Inherited from TObject and overriden to avoid warnings
+public:
+    void Clear() {};
+    void Clear(const Option_t*) {};
+
+    //////////////////////////////////////////////////////////////
+    // data obtained after reconstruction of an event
+
+    double Theta;
+    double Phi;
+    double Range;
+    double Charge;
+    double Energy;
+    TVector3 Vertex;
+    TVector3 EndOfTrack;
+    double ThetaShort;
+    double PhiShort;
+
+    int Voxels;
+
+public:
+    ClassDef(TActarScattering, 1) //ActarScattering structure
+};
+
+
+#endif
\ No newline at end of file
diff --git a/NPLib/Detectors/PISTA/CMakeLists.txt b/NPLib/Detectors/PISTA/CMakeLists.txt
index d4edf2bbb788f01b8bb9f96628c6eb89abf50ebd..41848764389a46d338eae0aa8d60b5e782d863c2 100644
--- a/NPLib/Detectors/PISTA/CMakeLists.txt
+++ b/NPLib/Detectors/PISTA/CMakeLists.txt
@@ -12,8 +12,14 @@ add_custom_command(OUTPUT TICPhysicsDict.cxx COMMAND ../../scripts/build_dict.sh
 
 add_custom_command(OUTPUT TVamosReconstructionDict.cxx COMMAND ../../scripts/build_dict.sh TVamosReconstruction.h TVamosReconstructionDict.cxx TVamosReconstruction.rootmap libNPPISTA.dylib DEPENDS TVamosReconstruction.h)
 
-add_library(NPPISTA SHARED TPISTASpectra.cxx TPISTAData.cxx TPISTAPhysics.cxx TPISTADataDict.cxx TPISTAPhysicsDict.cxx TFPMWData.cxx TFPMWDataDict.cxx TFPMWPhysics.cxx TFPMWPhysicsDict.cxx TICData.cxx TICDataDict.cxx TICPhysics.cxx TICPhysicsDict.cxx TVamosReconstruction.cxx TVamosReconstructionDict.cxx)
+add_custom_command(OUTPUT TTimeDataDict.cxx COMMAND ../../scripts/build_dict.sh TTimeData.h TTimeDataDict.cxx TTimeData.rootmap libNPPISTA.dylib DEPENDS TTimeData.h)
+
+add_library(NPPISTA SHARED TPISTASpectra.cxx TPISTAData.cxx TPISTAPhysics.cxx
+    TPISTADataDict.cxx TPISTAPhysicsDict.cxx TFPMWData.cxx TFPMWDataDict.cxx
+    TFPMWPhysics.cxx TFPMWPhysicsDict.cxx TICData.cxx TICDataDict.cxx
+    TICPhysics.cxx TICPhysicsDict.cxx TVamosReconstruction.cxx TVamosReconstructionDict.cxx TTimeData.cxx TTimeDataDict.cxx)
 
 target_link_libraries(NPPISTA ${ROOT_LIBRARIES} NPCore) 
-install(FILES TPISTAData.h TPISTAPhysics.h TPISTASpectra.h TFPMWData.h TFPMWPhysics.h TICData.h TICPhysics.h TVamosReconstruction.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+
+install(FILES TPISTAData.h TPISTAPhysics.h TPISTASpectra.h TFPMWData.h TFPMWPhysics.h TICData.h TICPhysics.h TVamosReconstruction.h TTimeData.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
 
diff --git a/NPLib/Detectors/PISTA/TICData.cxx b/NPLib/Detectors/PISTA/TICData.cxx
index 52a8670d53b6128f1c59ac84a6f83cabb8d7bba3..6d34fa00d3f52d2ca45472b05195c267cced7abe 100644
--- a/NPLib/Detectors/PISTA/TICData.cxx
+++ b/NPLib/Detectors/PISTA/TICData.cxx
@@ -46,6 +46,7 @@ TICData::~TICData() {
 void TICData::Clear() {
   fIC_Section.clear();
   fIC_Charge.clear();
+  fIC_TS.clear();
 }
 
 
diff --git a/NPLib/Detectors/PISTA/TICData.h b/NPLib/Detectors/PISTA/TICData.h
index 542d76a8b17316d2e902eba40a252ae0f2fe2e73..5073e68d46c84402def36158b831bad65dc59ee0 100644
--- a/NPLib/Detectors/PISTA/TICData.h
+++ b/NPLib/Detectors/PISTA/TICData.h
@@ -36,6 +36,7 @@ class TICData : public TObject {
   private: 
     vector<int> fIC_Section;
     vector<double> fIC_Charge;
+    vector<long> fIC_TS;
 
 
 
@@ -64,6 +65,7 @@ class TICData : public TObject {
     // X setters
     inline void SetIC_Charge(double Charge){fIC_Charge.push_back(Charge);};//!
     inline void SetIC_Section(int sec){fIC_Section.push_back(sec);};//!
+    inline void SetIC_TS(long TS){fIC_TS.push_back(TS);};//!
 
 
     //////////////////////    GETTERS    ////////////////////////
@@ -73,7 +75,9 @@ class TICData : public TObject {
       {return fIC_Section[i];}//!
     inline Double_t GetIC_Charge(const unsigned int &i) const 
       {return fIC_Charge[i];}//!      
-   
+    inline long GetIC_TS(const unsigned int &i) const 
+      {return fIC_TS[i];}//!      
+     
     //////////////////////////////////////////////////////////////
   // Required for ROOT dictionnary
   ClassDef(TICData,1)  // ICData structure
diff --git a/NPLib/Detectors/PISTA/TICPhysics.cxx b/NPLib/Detectors/PISTA/TICPhysics.cxx
index a4097a504c20469497aeb45bd921963ec5a7c612..c905cf16a25a1716af8a7b21396c65017eebfacb 100644
--- a/NPLib/Detectors/PISTA/TICPhysics.cxx
+++ b/NPLib/Detectors/PISTA/TICPhysics.cxx
@@ -96,7 +96,7 @@ void TICPhysics::BuildPhysicalEvent() {
     fIC_raw[i] = m_PreTreatedData->GetIC_Charge(i);
     fIC[i] = gain*m_PreTreatedData->GetIC_Charge(i);
     fIC_Init[i] = GainInit * m_PreTreatedData->GetIC_Charge(i);
-
+    fIC_TS.push_back(m_PreTreatedData->GetIC_TS(i));
   }
 
 
@@ -168,9 +168,11 @@ void TICPhysics::PreTreat() {
     //cout << section << " " << gain << endl;
     //double charge = gain*m_EventData->GetIC_Charge(i);
     double charge = m_EventData->GetIC_Charge(i);
+    long TS = m_EventData->GetIC_TS(i);
 
     m_PreTreatedData->SetIC_Charge(charge);
     m_PreTreatedData->SetIC_Section(segment);
+    m_PreTreatedData->SetIC_TS(TS);
   }
 }
 
@@ -319,6 +321,8 @@ void TICPhysics::Clear() {
     fIC_raw[i] = 0;
     fIC_Init[i] = 0;
   }
+
+  fIC_TS.clear();
 }
 
 
diff --git a/NPLib/Detectors/PISTA/TICPhysics.h b/NPLib/Detectors/PISTA/TICPhysics.h
index 5866e24a46b10c703802b025643742b7c4fbba1a..c02c89ab1ccfbd4a6c7ef8fee2935fb7f8f7405b 100644
--- a/NPLib/Detectors/PISTA/TICPhysics.h
+++ b/NPLib/Detectors/PISTA/TICPhysics.h
@@ -66,6 +66,9 @@ class TICPhysics : public TObject, public NPL::VDetector {
     double Etot;
     double EtotInit;
     double Chio_Z;
+    
+    vector<long> fIC_TS;
+
     double fIC[11];
     double fIC_raw[11]; 
     double fIC_Init[11];//! 
diff --git a/NPLib/Detectors/PISTA/TTimeData.cxx b/NPLib/Detectors/PISTA/TTimeData.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..cb8713f660e51856e867ed046a518bcc9d047484
--- /dev/null
+++ b/NPLib/Detectors/PISTA/TTimeData.cxx
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2020   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: Théodore Efremov contact address: theodore.efremov@cea.fr*
+ *                                                                           *
+ * Creation Date  : Nov 2024                                                 *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold Time Raw data                                            *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+#include "TTimeData.h"
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+using namespace std; 
+
+ClassImp(TTimeData)
+
+
+//////////////////////////////////////////////////////////////////////
+TTimeData::TTimeData() {
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+TTimeData::~TTimeData() {
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+void TTimeData::Clear() {
+  fTS_MWPC13.clear();
+  fTS_MWPC14.clear();
+  fTS_MWPC23.clear();
+  fTS_MWPC24.clear();
+
+  fTime_MWPC13.clear();
+  fTime_MWPC14.clear();
+  fTime_MWPC23.clear();
+  fTime_MWPC24.clear();
+
+  fSection_MWPC3.clear();
+  fSection_MWPC4.clear();
+
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+void TTimeData::Dump() const {
+  // This method is very useful for debuging and worth the dev.
+  cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TTimeData::Dump()] XXXXXXXXXXXXXXXXX" << endl;
+
+  size_t mysize = fTime_MWPC13.size();
+  cout << "MWPC_Mult: " << mysize << endl;
+  for(unsigned int i=0; i<mysize; i++){
+    cout << "Time 13 mult " << i+1 << " / T= " << fTime_MWPC13[i] << endl;
+    cout << "Time 14 mult " << i+1 << " / T= " << fTime_MWPC14[i] << endl;
+    cout << "Time 23 mult " << i+1 << " / T= " << fTime_MWPC23[i] << endl;
+    cout << "Time 24 mult " << i+1 << " / T= " << fTime_MWPC24[i] << endl;
+  }
+}
diff --git a/NPLib/Detectors/PISTA/TTimeData.h b/NPLib/Detectors/PISTA/TTimeData.h
new file mode 100644
index 0000000000000000000000000000000000000000..d56982141903c3cad350f77b0d3193f5f893f3dd
--- /dev/null
+++ b/NPLib/Detectors/PISTA/TTimeData.h
@@ -0,0 +1,129 @@
+#ifndef __TIMEDATA__
+#define __TIMEDATA__
+/*****************************************************************************
+ * Copyright (C) 2009-2020   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: Théodore Efremov  contact address: theodore.efremov@cea.fr                        *
+ *                                                                           *
+ * Creation Date  : Oct 2023                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold Time Raw data                                    *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// STL
+#include <vector>
+using namespace std;
+
+// ROOT
+#include "TObject.h"
+
+class TTimeData : public TObject {
+    //////////////////////////////////////////////////////////////
+    // data members are hold into vectors in order 
+    // to allow multiplicity treatment
+    private: 
+        vector<long> fTS_MWPC13;
+        vector<long> fTS_MWPC14;
+        vector<long> fTS_MWPC23;
+        vector<long> fTS_MWPC24;
+
+        vector<float> fTime_MWPC13;
+        vector<float> fTime_MWPC14;
+        vector<float> fTime_MWPC23;
+        vector<float> fTime_MWPC24;
+
+        vector<short> fSection_MWPC3;
+        vector<short> fSection_MWPC4;
+
+
+
+        //////////////////////////////////////////////////////////////
+        // Constructor and destructor
+    public: 
+        TTimeData();
+        ~TTimeData();
+
+
+        //////////////////////////////////////////////////////////////
+        // Inherited from TObject and overriden to avoid warnings
+    public:
+        void Clear();
+        void Clear(const Option_t*) {};
+        void Dump() const;
+
+
+        //////////////////////////////////////////////////////////////
+        // Getters and Setters
+        // Prefer inline declaration to avoid unnecessary called of 
+        // frequently used methods
+        // add //! to avoid ROOT creating dictionnary for the methods
+    public:
+        //////////////////////    SETTERS    ////////////////////////
+        // X setters
+        inline void SetTS_MWPC13(long time ){fTS_MWPC13.push_back(time);};//!
+        inline void SetTS_MWPC14(long time ){fTS_MWPC14.push_back(time);};//!
+        inline void SetTS_MWPC23(long time ){fTS_MWPC23.push_back(time);};//!
+        inline void SetTS_MWPC24(long time ){fTS_MWPC24.push_back(time);};//!
+
+        inline void SetTime_MWPC13(float time ){fTime_MWPC13.push_back(time);};//!
+        inline void SetTime_MWPC14(float time ){fTime_MWPC14.push_back(time);};//!
+        inline void SetTime_MWPC23(float time ){fTime_MWPC23.push_back(time);};//!
+        inline void SetTime_MWPC24(float time ){fTime_MWPC24.push_back(time);};//!
+
+        inline void SetSection_MWPC3(short section ){fSection_MWPC3.push_back(section);};//!
+        inline void SetSection_MWPC4(short section ){fSection_MWPC4.push_back(section);};//!
+
+
+
+
+        //////////////////////    GETTERS    ////////////////////////
+        inline long GetTS_MWPC13(const unsigned int &i) const
+        {return fTS_MWPC13.at(i) ;}//!
+        inline long GetTS_MWPC14(const unsigned int &i) const
+        {return fTS_MWPC14.at(i) ;}//!
+        inline long GetTS_MWPC23(const unsigned int &i) const
+        {return fTS_MWPC23.at(i) ;}//!
+        inline long GetTS_MWPC24(const unsigned int &i) const
+        {return fTS_MWPC24.at(i) ;}//!
+
+        inline float GetTime_MWPC13(const unsigned int &i) const
+        {return fTime_MWPC13.at(i) ;}//!
+        inline float GetTime_MWPC14(const unsigned int &i) const
+        {return fTime_MWPC14.at(i) ;}//!
+        inline float GetTime_MWPC23(const unsigned int &i) const
+        {return fTime_MWPC23.at(i) ;}//!
+        inline float GetTime_MWPC24(const unsigned int &i) const
+        {return fTime_MWPC24.at(i) ;}//!
+        
+        inline short GetSection_MWPC3(const unsigned int &i) const
+        {return fSection_MWPC3.at(i) ;}//!
+        inline short GetSection_MWPC4(const unsigned int &i) const
+        {return fSection_MWPC4.at(i) ;}//!
+          
+        inline Int_t GetMWPC13Mult() const
+        {return static_cast<int>(fTime_MWPC13.size());}         
+        inline Int_t GetMWPC14Mult() const
+        {return static_cast<int>(fTime_MWPC14.size());}        
+        inline Int_t GetMWPC23Mult() const
+        {return static_cast<int>(fTime_MWPC23.size());}        
+        inline Int_t GetMWPC24Mult() const
+        {return static_cast<int>(fTime_MWPC24.size());}
+
+        //////////////////////////////////////////////////////////////
+        // Required for ROOT dictionnary
+        ClassDef(TTimeData,2)  // TimeData structure
+};
+
+#endif
diff --git a/NPLib/Physics/NPReaction.cxx b/NPLib/Physics/NPReaction.cxx
index 6f890404c9fc15904a6392a296bfb55d3b1d29b6..70f0206a18977458ea78d3ab9b19720b27a215f4 100644
--- a/NPLib/Physics/NPReaction.cxx
+++ b/NPLib/Physics/NPReaction.cxx
@@ -639,10 +639,10 @@ void Reaction::initializePrecomputeVariable() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////
-void Reaction::SetParticle3(double EnergyLab, double ThetaLab) {
+void Reaction::SetParticle3(double EnergyLab, double ThetaLab, double PhiLab) {
   double p3 = sqrt(pow(EnergyLab, 2) + 2 * m3 * EnergyLab);
 
-  fEnergyImpulsionLab_3 = TLorentzVector(p3 * sin(ThetaLab), 0, p3 * cos(ThetaLab), EnergyLab + m3);
+  fEnergyImpulsionLab_3 = TLorentzVector(p3 * sin(ThetaLab) * cos(PhiLab), p3 * sin(ThetaLab) * sin(PhiLab), p3 * cos(ThetaLab), EnergyLab + m3);
   fEnergyImpulsionLab_4 = fTotalEnergyImpulsionLab - fEnergyImpulsionLab_3;
 
   fParticle3.SetEnergyImpulsion(fEnergyImpulsionLab_3);
diff --git a/NPLib/Physics/NPReaction.h b/NPLib/Physics/NPReaction.h
index 52037c6d0e4a14d28b8359d4b1b982be482688e5..fa43b2c6a3046a13d08c9d3554deaa5953965ce3 100644
--- a/NPLib/Physics/NPReaction.h
+++ b/NPLib/Physics/NPReaction.h
@@ -262,7 +262,7 @@ namespace NPL {
     // Check whenever the reaction is allowed at the given energy
     bool IsAllowed(double Energy);
 
-    void SetParticle3(double EnergyLab, double ThetaLab);
+    void SetParticle3(double EnergyLab, double ThetaLab, double PhiLab = 0);
 
     void SetParticle1(Beam p) { fParticle1 = p; };
     void SetParticle2(Particle p) { fParticle2 = p; };
diff --git a/NPLib/TrackReconstruction/CMakeLists.txt b/NPLib/TrackReconstruction/CMakeLists.txt
index f87460b714ed6f34e3c79f695bfb55b12b81fae2..b0f97855471a30e9a277e5454a82d414526f73c3 100644
--- a/NPLib/TrackReconstruction/CMakeLists.txt
+++ b/NPLib/TrackReconstruction/CMakeLists.txt
@@ -16,7 +16,7 @@ else()
 endif()      
 
 
-add_library(NPTrackReconstruction SHARED NPTrackingUtility.cxx NPLinearRansac3D.cxx NPRansac.cxx NPCluster.cxx NPTrack.cxx Tracking.cxx NPLinearRansac3DDict.cxx NPRansacDict.cxx NPClusterDict.cxx TrackingDict.cxx NPDCReconstruction.cxx NPDCReconstructionMT.cxx)
+add_library(NPTrackReconstruction SHARED NPTrackingUtility.cxx NPLinearRansac3D.cxx NPRansac.cxx NPCluster.cxx NPTrack.cxx Tracking.cxx NPRansacACTAR.cxx NPLinearRansac3DDict.cxx NPRansacDict.cxx NPClusterDict.cxx TrackingDict.cxx NPDCReconstruction.cxx NPDCReconstructionMT.cxx)
 
 if(Minuit2_FOUND)
 target_link_libraries(NPTrackReconstruction ${ROOT_LIBRARIES} -lMinuit2 NPCore)
@@ -24,4 +24,4 @@ else()
 target_link_libraries(NPTrackReconstruction ${ROOT_LIBRARIES} NPCore)
 endif()
 
-install(FILES NPLinearRansac3D.h NPRansac.h NPCluster.h NPTrack.h Tracking.h NPTrackingUtility.h NPDCReconstruction.h NPDCReconstructionMT.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+install(FILES NPLinearRansac3D.h NPRansac.h NPCluster.h NPTrack.h NPRansacACTAR.h Tracking.h NPTrackingUtility.h NPDCReconstruction.h NPDCReconstructionMT.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
diff --git a/NPLib/TrackReconstruction/NPLinearRansac3D.cxx b/NPLib/TrackReconstruction/NPLinearRansac3D.cxx
index 8ef0839a43c82fd5b263a9b10b5351f813b596d1..6b2c17eaa6a38ceed4c138368a892f124bf0c1cb 100644
--- a/NPLib/TrackReconstruction/NPLinearRansac3D.cxx
+++ b/NPLib/TrackReconstruction/NPLinearRansac3D.cxx
@@ -17,8 +17,14 @@
  *****************************************************************************/
 
 #include "NPLinearRansac3D.h"
+#include<iostream>
 using namespace std;
 using namespace NPL;
+
+
+ClassImp(LinearCluster3D);
+
+ClassImp(LinearRansac3D);
 ////////////////////////////////////////////////////////////////////////////////
 void LinearCluster3D::LinearFit() {
 
@@ -36,6 +42,7 @@ void LinearCluster3D::LinearFit() {
   double meanZ = 0;
   double w;
 
+
   for (unsigned int i = 0; i < sizeI; i++) {
     TVector3 Pi((*m_X)[m_index[i]], (*m_Y)[m_index[i]], (*m_Z)[m_index[i]]);
     for (unsigned int j = i + 1; j < sizeI; j++) {
@@ -69,11 +76,200 @@ void LinearCluster3D::LinearFit() {
 
   m_P0 = TVector3(meanX, meanY, meanZ);
   m_Dir = (TVector3(meanDX, meanDY, meanDZ)).Unit();
+  m_isFitted = true;
   // Cluster dir is arbitrary. we choose to always have positive Z dir
   if (m_Dir.Z() < 0)
     m_Dir = -m_Dir;
 };
 
+void LinearCluster3D::FastLinearFit() {
+
+double xx=0, yy=0, zz=0, xx2=0, yy2=0, zz2=0, xy=0, xz=0, yz=0, qq=0;
+unsigned int sizeI = m_index.size();
+	for(unsigned int i = 0; i < sizeI; i++){
+		xx+=(*m_X)[m_index[i]];
+		yy+=(*m_Y)[m_index[i]];
+		zz+=(*m_Z)[m_index[i]];
+		xx2+=(*m_X)[m_index[i]]*(*m_X)[m_index[i]];
+		yy2+=(*m_Y)[m_index[i]]*(*m_Y)[m_index[i]];
+		zz2+=(*m_Z)[m_index[i]]*(*m_Z)[m_index[i]];
+		xy+=(*m_X)[m_index[i]]*(*m_Y)[m_index[i]];
+		xz+=(*m_X)[m_index[i]]*(*m_Z)[m_index[i]];
+		yz+=(*m_Y)[m_index[i]]*(*m_Z)[m_index[i]];
+		qq+=1;
+	}
+
+  double Xm = xx/qq, Ym = yy/qq, Zm = zz/qq;
+  double Sxx = -Xm*Xm+xx2/qq, Syy = -Ym*Ym+yy2/qq, Szz = -Zm*Zm+zz2/qq;
+  double Sxy = -Xm*Ym+xy/qq, Sxz = -Xm*Zm+xz/qq, Syz = -Ym*Zm+yz/qq;
+  double theta = 0.5*atan(2*Sxy/(Sxx-Syy));
+
+  double ct = cos(theta), st = sin(theta), ct2 = ct*ct, st2 = st*st, cst = cos(theta)*sin(theta);
+  double K11 = (Syy+Szz)*ct2+(Sxx+Szz)*st2-2*Sxy*cst;
+  double K22 = (Syy+Szz)*st2+(Sxx+Szz)*ct2+2*Sxy*cst;
+  //double K12 = -Sxy*(ct2-st2)+(Sxx-Syy)*cst; //=0 by construction
+  double K10 = Sxz*ct+Syz*st;
+  double K01 = -Sxz*st+Syz*ct;
+  double K00 = Sxx+Syy;
+
+  double C2 = -K00-K11-K22;
+  double C1 = K00*K11+K00*K22+K11*K22-K01*K01-K10*K10;
+  double C0 = K01*K01*K11+K10*K10*K22-K00*K11*K22;
+
+  double p = C1-C2*C2/3, q = 2*C2*C2*C2/27-C1*C2/3+C0;
+  double R = q*q/4+p*p*p/27;
+  double dm2 = 0;
+  if(R>0)
+  {
+    dm2 = -C2/3+pow(-q/2+sqrt(R), 1./3.)+pow(-q/2-sqrt(R), 1./3.);
+  }
+  else
+  {
+    double rho = sqrt(-p*p*p/27), phi = acos(-q/(2*rho));  double R = q*q/4+p*p*p/27;
+
+    double sqrt3rho = pow(rho, 1./3.);
+    double d1 = -C2/3+2*sqrt3rho*cos(phi/3);
+    double d2 = -C2/3+2*sqrt3rho*cos((phi+2*M_PI)/3);
+    double d3 = -C2/3+2*sqrt3rho*cos((phi+4*M_PI)/3);
+    dm2 = std::min(std::min(d1, d2), d3);
+  }
+  double a = -K10*ct/(K11-dm2)+K01*st/(K22-dm2);
+  double b = -K10*st/(K11-dm2)-K01*ct/(K22-dm2);
+
+  double denom = 1./(1+a*a+b*b);
+  double u = ((1+b*b)*Xm-a*b*Ym+a*Zm)*denom;
+  double v = (-a*b*Xm+(1+a*a)*Ym+b*Zm)*denom;
+  double w = (a*Xm+b*Ym+(a*a+b*b)*Zm)*denom;
+
+  m_P0 = TVector3(Xm, Ym, Zm);
+  m_Dir = (TVector3(Xm-u, Ym-v, Zm-w)).Unit();
+}
+
+void LinearCluster3D::FastLinearFitShort() {
+
+double xx=0, yy=0, zz=0, xx2=0, yy2=0, zz2=0, xy=0, xz=0, yz=0, qq=0;
+unsigned int sizeI = m_index_short.size();
+	for(unsigned int i = 0; i < sizeI; i++){
+		xx+=(*m_X)[m_index_short[i]];
+		yy+=(*m_Y)[m_index_short[i]];
+		zz+=(*m_Z)[m_index_short[i]];
+		xx2+=(*m_X)[m_index_short[i]]*(*m_X)[m_index_short[i]];
+		yy2+=(*m_Y)[m_index_short[i]]*(*m_Y)[m_index_short[i]];
+		zz2+=(*m_Z)[m_index_short[i]]*(*m_Z)[m_index_short[i]];
+		xy+=(*m_X)[m_index_short[i]]*(*m_Y)[m_index_short[i]];
+		xz+=(*m_X)[m_index_short[i]]*(*m_Z)[m_index_short[i]];
+		yz+=(*m_Y)[m_index_short[i]]*(*m_Z)[m_index_short[i]];
+		qq+=1;
+	}
+
+  double Xm = xx/qq, Ym = yy/qq, Zm = zz/qq;
+  double Sxx = -Xm*Xm+xx2/qq, Syy = -Ym*Ym+yy2/qq, Szz = -Zm*Zm+zz2/qq;
+  double Sxy = -Xm*Ym+xy/qq, Sxz = -Xm*Zm+xz/qq, Syz = -Ym*Zm+yz/qq;
+  double theta = 0.5*atan(2*Sxy/(Sxx-Syy));
+
+  double ct = cos(theta), st = sin(theta), ct2 = ct*ct, st2 = st*st, cst = cos(theta)*sin(theta);
+  double K11 = (Syy+Szz)*ct2+(Sxx+Szz)*st2-2*Sxy*cst;
+  double K22 = (Syy+Szz)*st2+(Sxx+Szz)*ct2+2*Sxy*cst;
+  //double K12 = -Sxy*(ct2-st2)+(Sxx-Syy)*cst; //=0 by construction
+  double K10 = Sxz*ct+Syz*st;
+  double K01 = -Sxz*st+Syz*ct;
+  double K00 = Sxx+Syy;
+
+  double C2 = -K00-K11-K22;
+  double C1 = K00*K11+K00*K22+K11*K22-K01*K01-K10*K10;
+  double C0 = K01*K01*K11+K10*K10*K22-K00*K11*K22;
+
+  double p = C1-C2*C2/3, q = 2*C2*C2*C2/27-C1*C2/3+C0;
+  double R = q*q/4+p*p*p/27;
+  double dm2 = 0;
+  if(R>0)
+  {
+    dm2 = -C2/3+pow(-q/2+sqrt(R), 1./3.)+pow(-q/2-sqrt(R), 1./3.);
+  }
+  else
+  {
+    double rho = sqrt(-p*p*p/27), phi = acos(-q/(2*rho));  double R = q*q/4+p*p*p/27;
+
+    double sqrt3rho = pow(rho, 1./3.);
+    double d1 = -C2/3+2*sqrt3rho*cos(phi/3);
+    double d2 = -C2/3+2*sqrt3rho*cos((phi+2*M_PI)/3);
+    double d3 = -C2/3+2*sqrt3rho*cos((phi+4*M_PI)/3);
+    dm2 = std::min(std::min(d1, d2), d3);
+  }
+  double a = -K10*ct/(K11-dm2)+K01*st/(K22-dm2);
+  double b = -K10*st/(K11-dm2)-K01*ct/(K22-dm2);
+
+  double denom = 1./(1+a*a+b*b);
+  double u = ((1+b*b)*Xm-a*b*Ym+a*Zm)*denom;
+  double v = (-a*b*Xm+(1+a*a)*Ym+b*Zm)*denom;
+  double w = (a*Xm+b*Ym+(a*a+b*b)*Zm)*denom;
+
+  m_P0 = TVector3(Xm, Ym, Zm);
+  m_Dir = (TVector3(Xm-u, Ym-v, Zm-w)).Unit();
+}
+
+void LinearCluster3D::CheckDirection(const TVector3 & vertex){
+    if(m_FurthestPoint == TVector3(0, 0, 0)){
+      double max_distance = 0;
+      for(int i = 0; i < m_index.size(); i++)
+      {
+        TVector3 aPoint((*m_X)[m_index[i]], (*m_Y)[m_index[i]], (*m_Z)[m_index[i]]);
+        double distance = (aPoint-vertex).Mag();
+        if(distance > max_distance){
+          max_distance = distance;
+          m_FurthestPoint = aPoint;
+        }
+      }
+    }
+    if((m_FurthestPoint-vertex).X()*m_Dir.X() < 0) this->Inverse();
+}
+
+void LinearCluster3D::CalculateTrackLength(const TVector3 & vertex, const double & percentRange){
+  TH1D* Hrange = new TH1D("Range", "range", 256, 0, 512);
+  TH1D* Hrangecumule = new TH1D("RangeCumulated", "rangecumule", 256, 0, 512);
+
+  double total_charge = 0;
+  double cumulated_charge = 0;
+  double max_distance = 0;
+
+
+  for(int i = 0; i < m_index.size(); i++)
+  {
+    TVector3 aPoint((*m_X)[m_index[i]], (*m_Y)[m_index[i]], (*m_Z)[m_index[i]]);
+    double distance = (aPoint-vertex).Mag();
+    total_charge+=(*m_Q)[m_index[i]];
+    Hrange->Fill(distance, (*m_Q)[m_index[i]]);
+    if(distance > max_distance){
+      max_distance = distance;
+      m_FurthestPoint = aPoint;
+    }
+    if(distance < m_ShortTrackMaxLength){
+      m_index_short.push_back(m_index[i]);
+    }
+  }
+  m_Charge = total_charge;
+  //Inverse the track if it is not going in the good direction
+  if((m_FurthestPoint-vertex).X()*m_Dir.X() < 0) this->Inverse();
+
+  for(int bin = 1; bin < Hrange->GetNbinsX(); bin++)
+  {
+    cumulated_charge+=Hrange->GetBinContent(bin);
+    Hrangecumule->SetBinContent(bin, cumulated_charge/total_charge);
+  }
+  Int_t nbin = 1;
+  while(Hrangecumule->GetBinContent(nbin) < percentRange && nbin < Hrangecumule->GetNbinsX()-1)
+  {
+    nbin++;
+  }
+  Double_t delta, deltabinap, deltabinav;
+  delta = Hrangecumule->GetBinContent(nbin)-Hrangecumule->GetBinContent(nbin-1);
+  deltabinap = Hrangecumule->GetBinContent(nbin)-percentRange;
+  deltabinav = percentRange-Hrangecumule->GetBinContent(nbin-1);
+  m_TrackLength = deltabinap*Hrangecumule->GetBinCenter(nbin-1)/delta+deltabinav*Hrangecumule->GetBinCenter(nbin)/delta;
+  delete Hrange;
+  delete Hrangecumule;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 vector<LinearCluster3D> LinearRansac3D::TreatEvent(vector<double>& X, vector<double>& Y, vector<double>& Z) {
   cluster_id.clear();
@@ -92,7 +288,7 @@ vector<LinearCluster3D> LinearRansac3D::TreatEvent(vector<double>& X, vector<dou
   m_iteration_d = 0;
   m_iteration = 0;
 
-  while (m_iteration++ < m_max_iteration && m_assigned.size() < sizeX) {
+  while (m_iteration++ < m_max_iteration/* && m_assigned.size() < sizeX*/) {
     LinearCluster3D cluster(&X, &Y, &Z);
     // take 2 distant point randomly that has not been match before
     d = 0;
@@ -123,7 +319,7 @@ vector<LinearCluster3D> LinearRansac3D::TreatEvent(vector<double>& X, vector<dou
     }
 
   } // while
-
+	
   // loop over the cluster starting with the biggest
   unsigned int current_cluster = 0;
   unsigned int index;
diff --git a/NPLib/TrackReconstruction/NPLinearRansac3D.h b/NPLib/TrackReconstruction/NPLinearRansac3D.h
index b824e6e21a93cb6d3f27a874165dc8b06217a402..cdbf0b08b9e1952256069dfc4ca0283ddcfd0cab 100644
--- a/NPLib/TrackReconstruction/NPLinearRansac3D.h
+++ b/NPLib/TrackReconstruction/NPLinearRansac3D.h
@@ -24,15 +24,25 @@
 //root
 #include "TVector3.h"
 #include "TRandom2.h"
+#include "TH1.h"
 // nptool
 #include "NPTrackingUtility.h"
 namespace NPL{
   /////////////////////////////////
   class LinearCluster3D{
     public:
-      LinearCluster3D(){};
+      LinearCluster3D(){
+        m_isFitted = false;
+        m_FurthestPoint = TVector3(0, 0, 0);
+      };
+
       LinearCluster3D(std::vector<double>* X, std::vector<double>* Y, std::vector<double>* Z){
-        m_X=X; m_Y=Y; m_Z=Z;
+        m_X=X; m_Y=Y; m_Z=Z; m_isFitted = false;
+        m_FurthestPoint = TVector3(0, 0, 0);
+      }
+      LinearCluster3D(std::vector<double>* X, std::vector<double>* Y, std::vector<double>* Z, std::vector<double>* Q){
+        m_X=X; m_Y=Y; m_Z=Z; m_Q=Q; m_isFitted = false;
+        m_FurthestPoint = TVector3(0, 0, 0);
       }
       ~LinearCluster3D(){};
 
@@ -40,22 +50,48 @@ namespace NPL{
       void AddIndex(const unsigned int& i) {m_index.push_back(i);};
       unsigned int size() const {return m_index.size();};
       unsigned int GetIndex (const unsigned int& i) const {return m_index[i];};
+      void SetShortTrackMaxLength(const double & l) {m_ShortTrackMaxLength = l;}
 
+      //Inverse the direction
+      void Inverse() {m_Dir = -m_Dir;}; //!
       // Fit the cluster
-      void LinearFit();
+      void LinearFit(); //!
+      void FastLinearFit(); //!
+      void FastLinearFitShort(); //!
+
+      //Calculate the track length from the interaction vertex, and for a given percent of charge deposited along the way
+      //It also inverses the track if needed, and regroups the points below a certain distance from the vertex to refit it without the deviation
+      void CalculateTrackLength(const TVector3 & vertex, const double & percentRange = 0.95); //!
+      void CheckDirection(const TVector3 & vertex);
 
     private:
       std::vector<double>* m_X;//!
       std::vector<double>* m_Y;//!
       std::vector<double>* m_Z;//!
+      std::vector<double>* m_Q;//!
+
       std::vector<unsigned int> m_index;//!
-      TVector3 m_P0;// a point on the line
-      TVector3 m_Dir;// direction of the line
+      std::vector<unsigned int> m_index_short;//!
+      TVector3 m_P0; // a point on the line
+      TVector3 m_Dir; // direction of the line
+
+      double m_TrackLength; //!
+      double m_Charge; //!
+      // check if the track has been fitted with the "LinearFit" function
+      bool m_isFitted; //!
+      //Furthest point compared to vertex
+      TVector3 m_FurthestPoint; //!
+      double m_ShortTrackMaxLength; //!
+
 
     public:
       std::vector<unsigned int> GetIndex() const {return m_index;};
       TVector3 GetP0()const {return m_P0;};
       TVector3 GetDir()const {return m_Dir;};
+      double GetTrackLength()const {return m_TrackLength;}
+      bool IsFitted() const {return m_isFitted;}
+      TVector3 GetFurthestPoint()const {return m_FurthestPoint;}
+      double GetCharge()const {return m_Charge;}
 
     public: //operator
       // reversed logic so the cluster are ordered from largest to smallest
@@ -69,6 +105,8 @@ namespace NPL{
       friend bool operator<(const LinearCluster3D& A, const LinearCluster3D& B){
         return (A.size()>B.size());
       } 
+      ClassDef(LinearCluster3D, 0);
+
   };
   /////////////////////////////////
   class LinearRansac3D{
@@ -109,6 +147,8 @@ namespace NPL{
 
     public:
       std::vector<LinearCluster3D> TreatEvent(std::vector<double>& X, std::vector<double>&Y, std::vector<double>&Z);
+
+    ClassDef(LinearRansac3D, 0);
   };
 
 
diff --git a/NPLib/TrackReconstruction/NPRansacACTAR.cxx b/NPLib/TrackReconstruction/NPRansacACTAR.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..d8a9d035f5be393b7d49c2a8413584c793c1b62d
--- /dev/null
+++ b/NPLib/TrackReconstruction/NPRansacACTAR.cxx
@@ -0,0 +1,184 @@
+/*****************************************************************************
+ * 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 :  Damien THISSE contact address: damien.thisse@cea.fr    *
+ *                                                                           *
+ * Creation Date   : October 2024                                            *
+ * Last update     : October 2024                                            *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class deal with finding all the track event by event                *
+ *****************************************************************************/
+
+#include "NPRansacACTAR.h"
+#include "NPLinearRansac3D.h"
+
+using namespace NPL;
+using namespace std;
+
+/////////////////////////////////////////////////
+RansacACTAR::RansacACTAR()
+{
+    fRANSACMaxIteration = 1000;
+    fRANSACThreshold = 16;//100;
+    fRANSACPointThreshold = 0.05;//0.07;
+    fRANSACChargeThreshold = 0.05;//0.07;
+    fRANSACDistance = 7;//7;
+    fMAXBarycenterDistance = 10;
+    fAngleMax = 2;//degree
+    
+    fNumberOfPadsX = 128;
+    fNumberOfPadsY = 128;
+
+    Rand = new TRandom3();
+}
+
+vector<LinearCluster3D> RansacACTAR::SimpleRansac(vector<double> & vX, vector<double> & vY, vector<double> & vZ, vector<double> & vQ){
+    fTotalCharge = 0;
+    fOriginalCloudSize = vX.size();
+    vector<int> index;
+    vector<LinearCluster3D> all_clusters;
+
+    for(int QQ = 0; QQ < vQ.size(); QQ++){
+        fTotalCharge+= vQ.at(QQ);
+        index.push_back(QQ);
+    }
+    double RemainingCharge = fTotalCharge;
+    int loop_counter = 0;
+    // cout << "Total charge is " << fTotalCharge << " ---> Threshold to end RANSAC is thus " <<  fTotalCharge*fRANSACChargeThreshold << endl;
+    // cout << "Total voxels is " << index.size() << " ---> Threshold to end RANSAC is thus " <<  fOriginalCloudSize*fRANSACPointThreshold << endl;
+    do{
+        loop_counter++;
+        //cout << "Loop " << loop_counter << ": remaining charge is " << RemainingCharge << "; number of points remaining : " << index.size() << endl;
+        LinearCluster3D foundCluster(&vX, &vY, &vZ, &vQ);
+        int highest_inliers = 0;
+        vector<int> index_to_remove;
+
+        for(int i = 0; i < fRANSACMaxIteration; i++){
+            LinearCluster3D aCluster(&vX, &vY, &vZ, &vQ);
+            vector<int> pos_index;
+            UInt_t rand1 = Rand->Integer(index.size());
+            UInt_t rand2;
+            do{
+                rand2 = Rand->Integer(index.size());
+            } while(rand2 == rand1);
+
+            TVector3 pt1(vX[index[rand1]], vY[index[rand1]], vZ[index[rand1]]);
+            TVector3 pt2(vX[index[rand2]], vY[index[rand2]], vZ[index[rand2]]);
+            
+            for(int j = 0; j < index.size(); j++){
+                TVector3 pt(vX[index[j]], vY[index[j]], vZ[index[j]]);
+                if(MinimumDistancePointLine(pt1, pt2, pt) < fRANSACDistance){
+                    aCluster.AddIndex(index[j]);
+                    pos_index.push_back(j);
+
+                }
+            }
+            if(aCluster.size() > highest_inliers){
+                foundCluster = aCluster;
+                highest_inliers = aCluster.size();
+                index_to_remove = pos_index;
+            }
+        }
+
+        if(highest_inliers > fRANSACThreshold){
+           all_clusters.push_back(foundCluster);
+           for(int i = index_to_remove.size()-1; i >-1; i--){
+                RemainingCharge-= vQ.at(index[index_to_remove[i]]);
+                index.erase(index.begin()+index_to_remove.at(i));
+           }
+        //    RemainingCharge = 0;
+        //    for(int QQ = 0; QQ < index.size(); QQ++){
+        //         RemainingCharge+= vQ.at(index.at(QQ));
+        //     }
+        }
+        else break;
+
+    } while(RemainingCharge > fTotalCharge*fRANSACChargeThreshold && index.size() > fOriginalCloudSize*fRANSACPointThreshold);
+
+    return all_clusters;
+}
+
+void RansacACTAR::ReadParameterValue(string filename)
+{
+    bool ReadingStatus = false;
+    
+    ifstream RansacParamFile;
+    RansacParamFile.open(filename.c_str());
+    
+    if(!RansacParamFile.is_open()){
+        cout << "No Paramter File found for Ransac parameters" << endl;
+        cout << "Using the default parameter:" << endl;
+        cout << "RANSAC MaxIteration= " << fRANSACMaxIteration << endl;
+        cout << "RANSAC Threshold=" << fRANSACThreshold << endl;
+        cout << "RANSAC ChargeThreshold= " << fRANSACChargeThreshold << endl;
+        cout << "RANSAC Distance= " << fRANSACDistance << endl;
+        cout << "RANSAC PointThreshold= " << fRANSACPointThreshold << endl;
+        cout << "MAX Barycenter Distance= " << fMAXBarycenterDistance << endl;
+        cout << "Angle Max to merge tracks= " << fAngleMax << endl;
+    }
+    else{
+        string LineBuffer, whatToDo, DataBuffer;
+        while(!RansacParamFile.eof()){
+            getline(RansacParamFile,LineBuffer);
+            string name = "ConfigRansac";
+            if(LineBuffer.compare(0, name.length(), name) == 0){
+                cout << endl;
+                cout << "**** ConfigRansac found" << endl;
+                ReadingStatus = true;
+            }
+            while(ReadingStatus){
+                whatToDo="";
+                RansacParamFile >> whatToDo;
+                // Search for comment symbol (%)
+                if (whatToDo.compare(0, 1, "%") == 0) {
+                    RansacParamFile.ignore(numeric_limits<streamsize>::max(), '\n' );
+                }
+                else if (whatToDo.compare(0,19,"RANSACMaxIteration=") == 0) {
+                    RansacParamFile >> DataBuffer;
+                    fRANSACMaxIteration = atoi(DataBuffer.c_str());
+                    cout << "/// RANSAC MaxIteration= " << " " << fRANSACMaxIteration << " ///" << endl;
+                }
+                else if (whatToDo.compare(0,15,"RANSACDistance=") == 0) {
+                    RansacParamFile >> DataBuffer;
+                    fRANSACDistance = atoi(DataBuffer.c_str());
+                    cout << "/// RANSAC Distance= " << " " << fRANSACDistance << " ///" << endl;
+                }
+                else if (whatToDo.compare(0,22,"RANSACChargeThreshold=") == 0) {
+                    RansacParamFile >> DataBuffer;
+                    fRANSACChargeThreshold = atof(DataBuffer.c_str());
+                    cout << "/// RANSAC ChargeThreshold= " << " " << fRANSACChargeThreshold << " ///" << endl;
+                }
+                else if (whatToDo.compare(0,21,"RANSACPointThreshold=") == 0) {
+                    RansacParamFile >> DataBuffer;
+                    fRANSACPointThreshold = atof(DataBuffer.c_str());
+                    cout << "/// RANSAC PointThreshold= " << " " << fRANSACPointThreshold << " ///" << endl;
+                }
+                else if (whatToDo.compare(0,16,"RANSACThreshold=") == 0) {
+                    RansacParamFile >> DataBuffer;
+                    fRANSACThreshold = atoi(DataBuffer.c_str());
+                    cout << "/// RANSAC Threshold= " << " " << fRANSACThreshold << " ///" << endl;
+                }
+                else if (whatToDo.compare(0,22,"MAXBarycenterDistance=") == 0) {
+                    RansacParamFile >> DataBuffer;
+                    fMAXBarycenterDistance = atoi(DataBuffer.c_str());
+                    cout << "/// Max Barycenter Distance= " << " " << fMAXBarycenterDistance << " ///" << endl;
+                }
+                else if (whatToDo.compare(0,16,"AngleMaxToMerge=") == 0) {
+                    RansacParamFile >> DataBuffer;
+                    fAngleMax = atoi(DataBuffer.c_str());
+                    cout << "/// Angle Max to merge tracks= " << " " << fAngleMax << " ///" << endl;
+                }
+                else{
+                    ReadingStatus = false;
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/NPLib/TrackReconstruction/NPRansacACTAR.h b/NPLib/TrackReconstruction/NPRansacACTAR.h
new file mode 100644
index 0000000000000000000000000000000000000000..e7def0bccadce2b27884b245d7cac10d10c3b639
--- /dev/null
+++ b/NPLib/TrackReconstruction/NPRansacACTAR.h
@@ -0,0 +1,79 @@
+#ifndef __RANSACACTAR__
+#define __RANSACACTAR__
+/*****************************************************************************
+ * 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 :  Damien THISSE contact address: damien.thisse@cea.fr    *
+ *                                                                           *
+ * Creation Date   : October 2024                                            *
+ * Last update     : October 2024                                            *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class deal with finding all the track event by event                *
+ *****************************************************************************/
+
+//C++ Header
+#include <stdio.h>
+#include <vector>
+#include <sstream>
+#include <iostream>
+#include <fstream>
+#include <cmath>
+#include <stdlib.h>
+#include <limits>
+#include <string>
+#include <algorithm>
+
+//NPL
+#include "NPTrack.h"
+#include "NPLinearRansac3D.h"
+
+using namespace NPL;
+
+// ROOT Headers
+#include <TH2F.h>
+#include <TMath.h>
+#include <TVector3.h>
+#include <TRandom3.h>
+#include <TVector.h>
+
+using namespace std;
+
+namespace NPL{
+    
+    class RansacACTAR
+    {
+    public:
+        RansacACTAR();
+        ~RansacACTAR() {};
+        
+    public:
+        void ReadParameterValue(string filename);
+        vector<NPL::LinearCluster3D> SimpleRansac(vector<double> & vX, vector<double> & vY, vector<double> & vZ, vector<double> & vQ);
+        
+    private:
+        TRandom3* Rand;
+        
+    private:
+        float fRANSACThreshold;
+        float fRANSACPointThreshold;
+        float fRANSACChargeThreshold;
+        float fRANSACDistance;
+        float fRANSACMaxIteration;
+        float fMAXBarycenterDistance;
+        float fAngleMax;
+        int fNumberOfTracksMax;
+        int fOriginalCloudSize;
+        double fTotalCharge;
+        int fNumberOfPadsX;
+        int fNumberOfPadsY;
+        
+    };
+}
+#endif
diff --git a/NPSimulation/Detectors/Actar/Actar.cc b/NPSimulation/Detectors/Actar/Actar.cc
index 15ee6ccbaf7e63335db490c69ead96e0e547fafe..d5374006eee66af72f07730fc85971bad4b48301 100644
--- a/NPSimulation/Detectors/Actar/Actar.cc
+++ b/NPSimulation/Detectors/Actar/Actar.cc
@@ -269,7 +269,7 @@ G4LogicalVolume* Actar::BuildDetector() {
     MPT->AddConstProperty("DE_YIELD", 3e-1, true);
     // MPT->AddConstProperty("DE_AMPLIFICATION",2,true);
     MPT->AddConstProperty("DE_ABSLENGTH", 1 * pc, true);
-    MPT->AddConstProperty("DE_DRIFTSPEED", 0.8 * cm / microsecond, true);
+    MPT->AddConstProperty("DE_DRIFTSPEED", 1.28 * cm / microsecond, true);
     MPT->AddConstProperty("DE_TRANSVERSALSPREAD", 2e-5 * mm2 / ns, true);
     MPT->AddConstProperty("DE_LONGITUDINALSPREAD", 4e-6 * mm2 / ns, true);
     DriftGasMaterial->SetMaterialPropertiesTable(MPT);
@@ -349,7 +349,7 @@ G4LogicalVolume* Actar::BuildDetector() {
      logicWindows,
      "ActarEntranceWindows",m_SquareDetector,false,0);*/
 
-    G4ElectricField* field = new G4UniformElectricField(G4ThreeVector(0.0, -400 * volt / cm, 0.0));
+    G4ElectricField* field = new G4UniformElectricField(G4ThreeVector(0.0, -70 * volt / cm, 0.0));
     // Create an equation of motion for this field
     G4EqMagElectricField* Equation = new G4EqMagElectricField(field);
     G4MagIntegratorStepper* Stepper = new G4ClassicalRK4(Equation, 8);
diff --git a/NPSimulation/Detectors/PISTA/PISTA.cc b/NPSimulation/Detectors/PISTA/PISTA.cc
index 462352433a3b06907ccf06ca0755d23f3dcb879d..f7ebec47fb36d9d4b1be5a229764f7222313a1d4 100644
--- a/NPSimulation/Detectors/PISTA/PISTA.cc
+++ b/NPSimulation/Detectors/PISTA/PISTA.cc
@@ -64,26 +64,26 @@ namespace PISTA_NS{
   const double E_ResoEnergy  = 0.018*MeV ;
 
   // Trapezoid dimension PISTA1
-  //const double TrapezoidBaseLarge = 72.3*mm;
-  //const double TrapezoidBaseSmall = 41.0*mm;
-  //const double TrapezoidHeight = 57.7*mm;
-  //const double TrapezoidLength = 1*cm;
-  //const double FirstStageThickness = 300*um;
-  //const double SecondStageThickness = 1.5*mm;
-  //const double DistanceBetweenSi = 4*mm;
-  //const double FirstStageNbrOfStrips = 91;
-  //const double SecondStageNbrOfStrips = 57;
+  double TrapezoidBaseLarge = 72.3*mm;
+  double TrapezoidBaseSmall = 41.0*mm;
+  double TrapezoidHeight = 57.7*mm;
+  double TrapezoidLength = 1*cm;
+  double FirstStageThickness = 300*um;
+  double SecondStageThickness = 1.5*mm;
+  double DistanceBetweenSi = 4*mm;
+  double FirstStageNbrOfStrips = 91;
+  double SecondStageNbrOfStrips = 57;
 
   // Trapezoid dimension PISTA2
-  const double TrapezoidBaseLarge = 53*mm;
-  const double TrapezoidBaseSmall = 34.0*mm;
-  const double TrapezoidHeight = 27*mm;
-  const double TrapezoidLength = 1*cm;
-  const double FirstStageThickness = 0.3*mm;
-  const double SecondStageThickness = 1.5*mm;
-  const double DistanceBetweenSi = 3*mm;
-  const double FirstStageNbrOfStrips = 49;
-  const double SecondStageNbrOfStrips = 45;
+  //double TrapezoidBaseLarge = 53*mm;
+  //double TrapezoidBaseSmall = 34.0*mm;
+  //double TrapezoidHeight = 27*mm;
+  //double TrapezoidLength = 1*cm;
+  //double FirstStageThickness = 0.3*mm;
+  //double SecondStageThickness = 1.5*mm;
+  //double DistanceBetweenSi = 3*mm;
+  //double FirstStageNbrOfStrips = 49;
+  //double SecondStageNbrOfStrips = 45;
 }
 using namespace PISTA_NS;
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -95,6 +95,7 @@ PISTA::PISTA(){
   m_FirstStageScorer = 0;
   m_SecondStageScorer = 0;
   m_TrapezoidDetector = 0;
+  m_version = 1;
 }
 
 PISTA::~PISTA(){
@@ -111,6 +112,29 @@ void PISTA::AddDetector(G4ThreeVector A, G4ThreeVector B, G4ThreeVector C, G4Thr
   m_R.push_back(0);
   m_Theta.push_back(0);
   m_Phi.push_back(0);
+
+  if(m_version==1){
+    TrapezoidBaseLarge = 72.3*mm;
+    TrapezoidBaseSmall = 41.0*mm;
+    TrapezoidHeight = 57.7*mm;
+    TrapezoidLength = 1*cm;
+    FirstStageThickness = 300*um;
+    SecondStageThickness = 1.5*mm;
+    DistanceBetweenSi = 4*mm;
+    FirstStageNbrOfStrips = 91;
+    SecondStageNbrOfStrips = 57;
+  }
+  else if(m_version==2){
+    TrapezoidBaseLarge = 53*mm;
+    TrapezoidBaseSmall = 34.0*mm;
+    TrapezoidHeight = 27*mm;
+    TrapezoidLength = 1*cm;
+    FirstStageThickness = 0.3*mm;
+    SecondStageThickness = 1.5*mm;
+    DistanceBetweenSi = 3*mm;
+    FirstStageNbrOfStrips = 49;
+    SecondStageNbrOfStrips = 45;
+  }
 }
 
 
@@ -225,6 +249,7 @@ void PISTA::ReadConfiguration(NPL::InputParser parser){
       if(NPOptionManager::getInstance()->GetVerboseLevel())
         cout << endl << "////  PISTA " << i+1 <<  endl;
 
+      m_version = blocks[i]->GetInt("VERSION");
       G4ThreeVector A = NPS::ConvertVector(blocks[i]->GetTVector3("POS_A","mm"));
       G4ThreeVector B = NPS::ConvertVector(blocks[i]->GetTVector3("POS_B","mm"));
       G4ThreeVector C = NPS::ConvertVector(blocks[i]->GetTVector3("POS_C","mm"));
@@ -277,7 +302,7 @@ void PISTA::ConstructDetector(G4LogicalVolume* world){
       w = w.unit();
 
       center = (m_A[i] + m_B[i] + m_C[i] + m_D[i])/4;
-    
+
       Rot = new G4RotationMatrix(u,v,w);
       Det_pos = w * TrapezoidLength * 0.5 + center; 
     }
@@ -343,9 +368,9 @@ void PISTA::ReadSensitive(const G4Event* ){
       m_Event->SetPISTA_DE_StripTime(Time);
     }
   }
-  
+
   unsigned int sizeDEBack = FirstStageScorer->GetLengthMult();
-   for(unsigned int i = 0 ; i < sizeDEBack ; i++){
+  for(unsigned int i = 0 ; i < sizeDEBack ; i++){
     double EnergyBack = RandGauss::shoot(FirstStageScorer->GetEnergyLength(i), DE_ResoEnergy);   
     if(EnergyBack>EnergyThreshold){
       double Time = RandGauss::shoot(FirstStageScorer->GetTimeLength(i), ResoTime);
@@ -356,18 +381,18 @@ void PISTA::ReadSensitive(const G4Event* ){
 
     }
   }
-  
+
   /*for(unsigned int i = 0 ; i < sizeDEFront ; i++){
     double EnergyFront = RandGauss::shoot(FirstStageScorer->GetEnergyWidth(i), DE_ResoEnergy);   
     double EnergyBack  = RandGauss::shoot(FirstStageScorer->GetEnergyLength(i), DE_ResoEnergy);   
     if(EnergyFront>EnergyThreshold){
-      double Time = RandGauss::shoot(FirstStageScorer->GetTimeLength(i), ResoTime);
-      int DetNbr  = FirstStageScorer->GetDetectorWidth(i);
-      int StripFront = 92-FirstStageScorer->GetStripWidth(i);
-      m_Event->SetPISTA_DE(DetNbr, StripFront, EnergyFront, EnergyBack, Time, Time);
-      m_Event->SetPISTA_DE_BackDetector(DetNbr);
+    double Time = RandGauss::shoot(FirstStageScorer->GetTimeLength(i), ResoTime);
+    int DetNbr  = FirstStageScorer->GetDetectorWidth(i);
+    int StripFront = 92-FirstStageScorer->GetStripWidth(i);
+    m_Event->SetPISTA_DE(DetNbr, StripFront, EnergyFront, EnergyBack, Time, Time);
+    m_Event->SetPISTA_DE_BackDetector(DetNbr);
     }
-  }*/
+    }*/
   FirstStageScorer->clear();
 
   ///////////
@@ -387,7 +412,7 @@ void PISTA::ReadSensitive(const G4Event* ){
       m_Event->SetPISTA_E_StripTime(Time);
     }
   }
-  
+
   unsigned int sizeEBack = SecondStageScorer->GetWidthMult();
   for(unsigned int i = 0 ; i < sizeEBack ; i++){
     double EnergyBack = RandGauss::shoot(SecondStageScorer->GetEnergyWidth(i), E_ResoEnergy);   
@@ -399,20 +424,20 @@ void PISTA::ReadSensitive(const G4Event* ){
       m_Event->SetPISTA_E_BackTime(Time);
     }
   }
-  
+
 
 
   /*for(unsigned int i = 0 ; i < sizeEFront ; i++){
     double EnergyFront = RandGauss::shoot(SecondStageScorer->GetEnergyLength(i), E_ResoEnergy);   
     double EnergyBack  = RandGauss::shoot(SecondStageScorer->GetEnergyWidth(i), E_ResoEnergy);   
     if(EnergyFront>EnergyThreshold){
-      double Time = RandGauss::shoot(SecondStageScorer->GetTimeLength(i), ResoTime);
-      int DetNbr  = SecondStageScorer->GetDetectorLength(i);
-      int StripFront = SecondStageScorer->GetStripLength(i);
-      m_Event->SetPISTA_E(DetNbr, StripFront, EnergyFront, EnergyBack, Time, Time);
-      m_Event->SetPISTA_E_BackDetector(DetNbr);
+    double Time = RandGauss::shoot(SecondStageScorer->GetTimeLength(i), ResoTime);
+    int DetNbr  = SecondStageScorer->GetDetectorLength(i);
+    int StripFront = SecondStageScorer->GetStripLength(i);
+    m_Event->SetPISTA_E(DetNbr, StripFront, EnergyFront, EnergyBack, Time, Time);
+    m_Event->SetPISTA_E_BackDetector(DetNbr);
     }
-  }*/
+    }*/
   SecondStageScorer->clear();
 
 
diff --git a/NPSimulation/Detectors/PISTA/PISTA.hh b/NPSimulation/Detectors/PISTA/PISTA.hh
index 90548dec841c28b11394d4fafd6fbadcf2ac61a9..4ac6371879228364ade3a01f41da02a296fb327c 100644
--- a/NPSimulation/Detectors/PISTA/PISTA.hh
+++ b/NPSimulation/Detectors/PISTA/PISTA.hh
@@ -98,6 +98,7 @@ class PISTA : public NPS::VDetector{
     ////////////////////////////////////////////////////
   private: // Geometry
     // Detector Coordinate 
+    int m_version;
     vector<bool> m_DefinitionType;
     vector<G4ThreeVector>  m_A; 
     vector<G4ThreeVector>  m_B; 
diff --git a/NPSimulation/Detectors/Vamos/Vamos.cc b/NPSimulation/Detectors/Vamos/Vamos.cc
index 586262abd8747e0fac9e112f58ac40796e2648f7..67c2386f5cc03fbf1a8a8715e572ef1fd15c7c80 100644
--- a/NPSimulation/Detectors/Vamos/Vamos.cc
+++ b/NPSimulation/Detectors/Vamos/Vamos.cc
@@ -59,42 +59,52 @@ using namespace CLHEP;
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 namespace Vamos_NS {
 
-    // Energy,time and position Resolution
-    const G4double EnergyThreshold = -10 * MeV;
-    const G4double ResoTime        = 4.5 * ns;
-    const G4double ResoEnergy      = 0.0001 * MeV;
-    const G4double ResoDriftTime   = 0.0001 * ns;
-    const G4double ResoPosX        = 0.0001 * mm;
-
-    // Drift features
-    const G4double      DriftSpeed = 1 * cm / microsecond;
-    const G4ThreeVector DriftDir   = G4ThreeVector(0, 1, 0);
-
-    // Geometry
-    const G4double E_DCWidth     = 600 * mm;  // Entrance_DriftChamber
-    const G4double E_DCLength    = 150 * mm;
-    const G4double E_DCThickness = 60 * mm;
-
-    const G4double MagnetWidth     = 1000 * mm;
-    const G4double MagnetLenght    = 150 * mm;
-    const G4double MagnetThickness = 200 * mm;
-    const G4double DipolThickness  = 600 * mm;
-
-    const G4double ChamberWidth     = 1000 * mm;
-    const G4double ChamberLength    = 150 * mm;
-    const G4double ChamberThickness = 120 * mm;
-
-    // Mother Volume of Vamos
-    const G4double Phi                  = 0 * deg;
-    const G4double VamosVolumeWidth     = 4500 * mm;
-    const G4double VamosVolumeLength    = 1000 * mm;
-    const G4double VamosVolumeThickness = 5000 * mm;
-
-    // SubVolume of detection
-    const G4double DetectionVolumeThickness = 1300 * mm;
-    const G4double DetectionVolumeWidth     = 1000 * mm;
-    const G4double DetectionVolumeLength    = 1000 * mm;
-    const G4double Det_Theta                = 45 * deg;
+  // Energy,time and position Resolution
+  const G4double EnergyThreshold = -10 * MeV;
+  const G4double ResoTime        = 4.5 * ns;
+  const G4double ResoEnergy      = 0.0001 * MeV;
+  const G4double ResoDriftTime   = 0.0001 * ns;
+  const G4double ResoPosX        = 0.0001 * mm;
+
+  // Drift features
+  const G4double      DriftSpeed = 1 * cm / microsecond;
+  const G4ThreeVector DriftDir   = G4ThreeVector(0, 1, 0);
+
+  // Geometry
+  const G4double E_DCWidth     = 600 * mm;  // Entrance_DriftChamber
+  const G4double E_DCLength    = 150 * mm;
+  const G4double E_DCThickness = 60 * mm;
+
+  const G4double MagnetWidth     = 1000 * mm;
+  const G4double MagnetLenght    = 150 * mm;
+  const G4double MagnetThickness = 200 * mm;
+  const G4double DipolThickness  = 600 * mm;
+
+  const G4double ChamberWidth     = 1000 * mm;
+  const G4double ChamberLength    = 150 * mm;
+  const G4double ChamberThickness = 120 * mm;
+
+  // Mother Volume of Vamos
+  const G4double Phi                  = 0 * deg;
+  const G4double VamosVolumeWidth     = 4500 * mm;
+  const G4double VamosVolumeLength    = 1000 * mm;
+  const G4double VamosVolumeThickness = 5000 * mm;
+
+  // SubVolume of detection
+  const G4double DetectionVolumeThickness = 1300 * mm;
+  const G4double DetectionVolumeWidth     = 1000 * mm;
+  const G4double DetectionVolumeLength    = 1000 * mm;
+  const G4double Det_Theta                = 45 * deg;
+
+  // TMW1-2
+  const G4double TMW1_Width     = 40 * mm;
+  const G4double TMW1_Length    = 61 * mm;
+  const G4double TMW1_Thickness = 5 * mm;
+
+  const G4double TMW2_Width     = 65 * mm;
+  const G4double TMW2_Length    = 93 * mm;
+  const G4double TMW2_Thickness = 5 * mm;
+
 
 } 
 
@@ -105,28 +115,31 @@ namespace Vamos_NS {
 // Vamos Specific Method
 Vamos::Vamos() {
 
-    m_Event             = new TVamosData();
-    m_CalorimeterScorer = 0;
-    m_DCScorer          = 0;
-    m_Quad1             = 0;
-    m_Quad2             = 0;
-    m_Dipol             = 0;
-    m_BeamCatcher       = 0;
-    m_MWPPAC            = 0;
-    m_DC3               = 0;
-    m_DC4               = 0;
-    m_DC1               = 0;
-    m_DC2               = 0;
-
-    ICcounter = 0;
-
-    // RGB Color + Transparency
-    m_VisQuad        = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0));
-    m_VisVolumeVamos = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0, 0.1));
-    m_VisDC          = new G4VisAttributes(G4Colour(0.0, 1.0, 0.0, 0.2));
-    m_VisCatcher     = new G4VisAttributes(G4Colour(0.0, 0.0, 1.0));
-    m_VisGasC4H10    = new G4VisAttributes(G4Colour(0.0, 1.0, 0.0, 0.2));
-    m_VisGasCF4      = new G4VisAttributes(G4Colour(0.0, 0.0, 1.0, 0.2));
+  m_Event             = new TVamosData();
+  m_CalorimeterScorer = 0;
+  m_DCScorer          = 0;
+  m_TMW1Scorer        = 0;
+  m_Quad1             = 0;
+  m_Quad2             = 0;
+  m_Dipol             = 0;
+  m_BeamCatcher       = 0;
+  m_TMW1              = 0;
+  m_TMW2              = 0;
+  m_MWPPAC            = 0;
+  m_DC3               = 0;
+  m_DC4               = 0;
+  m_DC1               = 0;
+  m_DC2               = 0;
+
+  ICcounter = 0;
+
+  // RGB Color + Transparency
+  m_VisQuad        = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0));
+  m_VisVolumeVamos = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0, 0.1));
+  m_VisDC          = new G4VisAttributes(G4Colour(0.0, 1.0, 0.0, 0.2));
+  m_VisCatcher     = new G4VisAttributes(G4Colour(0.0, 0.0, 1.0));
+  m_VisGasC4H10    = new G4VisAttributes(G4Colour(0.0, 1.0, 0.0, 0.2));
+  m_VisGasCF4      = new G4VisAttributes(G4Colour(0.0, 0.0, 1.0, 0.2));
 }
 
 Vamos::~Vamos() {}
@@ -135,200 +148,250 @@ Vamos::~Vamos() {}
 
 using namespace Vamos_NS;
 
+/////////////////////////////////////////////////////////////////////
 void Vamos::AddVamos(G4double R, double Theta) {
-    m_R     = R;
-    m_Theta = Theta;
+  m_R     = R;
+  m_Theta = Theta;
 }
 
+/////////////////////////////////////////////////////////////////////
 void Vamos::AddBeamCatcher(string Material, G4double Width, double Length,
-        double Thickness, G4ThreeVector Pos) {
-    CatcherMaterial  = Material;
-    CatcherWidth     = Width;
-    CatcherLength    = Length;
-    CatcherThickness = Thickness;
-    R_Catcher        = Pos[2];
-    Pos[2]           = -DetectionVolumeThickness * 0.5 + CatcherThickness * 0.5;
-    m_PosCatcher     = Pos;
+    double Thickness, G4ThreeVector Pos) {
+  CatcherMaterial  = Material;
+  CatcherWidth     = Width;
+  CatcherLength    = Length;
+  CatcherThickness = Thickness;
+  R_Catcher        = Pos[2];
+  Pos[2]           = -DetectionVolumeThickness * 0.5 + CatcherThickness * 0.5;
+  m_PosCatcher     = Pos;
 }
 
 // To add DriftChambers and the MWPPAC
+/////////////////////////////////////////////////////////////////////
 void Vamos::AddDetector(G4double Z, string Gas, double Pressure,
-        double Temperature) {
-    m_Z.push_back(Z);
-    m_Gas.push_back(Gas);
-    m_Pressure.push_back(Pressure);
-    m_Temperature.push_back(Temperature);
+    double Temperature) {
+  m_Z.push_back(Z);
+  m_Gas.push_back(Gas);
+  m_Pressure.push_back(Pressure);
+  m_Temperature.push_back(Temperature);
 }
 
+/////////////////////////////////////////////////////////////////////
 void Vamos::AddIC(G4double Z, double Thickness, string Gas, double Pressure,
-        double Temperature) {
-    m_ZIC.push_back(Z);
-    m_ThicknessIC.push_back(Thickness);
-    m_GasIC.push_back(Gas);
-    m_PressureIC.push_back(Pressure);
-    m_TemperatureIC.push_back(Temperature);
+    double Temperature) {
+  m_ZIC.push_back(Z);
+  m_ThicknessIC.push_back(Thickness);
+  m_GasIC.push_back(Gas);
+  m_PressureIC.push_back(Pressure);
+  m_TemperatureIC.push_back(Temperature);
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
 // The two entry DriftChambers 
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildDC1() {
-    if (!m_DC1) {
-        G4Box* box = new G4Box("Vamos_DC1", E_DCWidth * 0.5, E_DCLength * 0.5,
-                E_DCThickness * 0.5);
-
-        G4Material* DetectorMaterial
-            = MaterialManager::getInstance()->GetGasFromLibrary(
-                    m_Gas[0], m_Pressure[0], m_Temperature[0]);
-
-        m_DC1 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_DC1", 0, 0,
-                0);
-        m_DC1->SetVisAttributes(m_VisGasC4H10);
-        m_DC1->SetSensitiveDetector(m_DCScorer);
-    }
-    return m_DC1;
+  if (!m_DC1) {
+    G4Box* box = new G4Box("Vamos_DC1", E_DCWidth * 0.5, E_DCLength * 0.5,
+        E_DCThickness * 0.5);
+
+    G4Material* DetectorMaterial
+      = MaterialManager::getInstance()->GetGasFromLibrary(
+          m_Gas[0], m_Pressure[0], m_Temperature[0]);
+
+    m_DC1 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_DC1", 0, 0,
+        0);
+    m_DC1->SetVisAttributes(m_VisGasC4H10);
+    m_DC1->SetSensitiveDetector(m_DCScorer);
+  }
+  return m_DC1;
 }
 
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildDC2() {
-    if (!m_DC2) {
-        G4Box* box = new G4Box("Vamos_DC2", E_DCWidth * 0.5, E_DCLength * 0.5,
-                E_DCThickness * 0.5);
-
-        G4Material* DetectorMaterial
-            = MaterialManager::getInstance()->GetGasFromLibrary(
-                    m_Gas[1], m_Pressure[1], m_Temperature[1]);
-
-        m_DC2 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_DC2", 0, 0,
-                0);
-        m_DC2->SetVisAttributes(m_VisGasC4H10);
-        m_DC2->SetSensitiveDetector(m_DCScorer);
-    }
-    return m_DC2;
+  if (!m_DC2) {
+    G4Box* box = new G4Box("Vamos_DC2", E_DCWidth * 0.5, E_DCLength * 0.5,
+        E_DCThickness * 0.5);
+
+    G4Material* DetectorMaterial
+      = MaterialManager::getInstance()->GetGasFromLibrary(
+          m_Gas[1], m_Pressure[1], m_Temperature[1]);
+
+    m_DC2 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_DC2", 0, 0,
+        0);
+    m_DC2->SetVisAttributes(m_VisGasC4H10);
+    m_DC2->SetSensitiveDetector(m_DCScorer);
+  }
+  return m_DC2;
 }
 
 // Quadruples and Dipole just to make the visualisation nice
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildQuad1() {
-    if (!m_Quad1) {
-        G4Box* box = new G4Box("Vamos_Box", Vamos_NS::MagnetWidth * 0.5,
-                Vamos_NS::MagnetLenght * 0.5,
-                Vamos_NS::MagnetThickness * 0.5);
-
-        G4Material* VamosMaterial
-            = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
-        m_Quad1 = new G4LogicalVolume(box, VamosMaterial, "logic_Quad1", 0, 0, 0);
-        m_Quad1->SetVisAttributes(m_VisQuad);
-    }
-    return m_Quad1;
+  if (!m_Quad1) {
+    G4Box* box = new G4Box("Vamos_Box", Vamos_NS::MagnetWidth * 0.5,
+        Vamos_NS::MagnetLenght * 0.5,
+        Vamos_NS::MagnetThickness * 0.5);
+
+    G4Material* VamosMaterial
+      = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
+    m_Quad1 = new G4LogicalVolume(box, VamosMaterial, "logic_Quad1", 0, 0, 0);
+    m_Quad1->SetVisAttributes(m_VisQuad);
+  }
+  return m_Quad1;
 }
 
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildQuad2() {
-    if (!m_Quad2) {
-        G4Box* box = new G4Box("Vamos_Quad2", Vamos_NS::MagnetWidth * 0.5,
-                Vamos_NS::MagnetLenght * 0.5,
-                Vamos_NS::MagnetThickness * 0.5);
-
-        G4Material* VamosMaterial
-            = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
-        m_Quad1 = new G4LogicalVolume(box, VamosMaterial, "logic_Quad1", 0, 0, 0);
-        m_Quad1->SetVisAttributes(m_VisQuad);
-    }
-    return m_Quad1;
+  if (!m_Quad2) {
+    G4Box* box = new G4Box("Vamos_Quad2", Vamos_NS::MagnetWidth * 0.5,
+        Vamos_NS::MagnetLenght * 0.5,
+        Vamos_NS::MagnetThickness * 0.5);
+
+    G4Material* VamosMaterial
+      = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
+    m_Quad1 = new G4LogicalVolume(box, VamosMaterial, "logic_Quad1", 0, 0, 0);
+    m_Quad1->SetVisAttributes(m_VisQuad);
+  }
+  return m_Quad1;
 }
 
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildDipol() {
-    if (!m_Dipol) {
-        G4Box* box = new G4Box("Vamos_Dipol", Vamos_NS::MagnetWidth * 0.5,
-                Vamos_NS::MagnetLenght * 0.5,
-                Vamos_NS::DipolThickness * 0.5);
-
-        G4Material* VamosMaterial
-            = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
-        m_Dipol = new G4LogicalVolume(box, VamosMaterial, "logic_Dipol", 0, 0, 0);
-        m_Dipol->SetVisAttributes(m_VisQuad);
-    }
-    return m_Dipol;
+  if (!m_Dipol) {
+    G4Box* box = new G4Box("Vamos_Dipol", Vamos_NS::MagnetWidth * 0.5,
+        Vamos_NS::MagnetLenght * 0.5,
+        Vamos_NS::DipolThickness * 0.5);
+
+    G4Material* VamosMaterial
+      = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
+    m_Dipol = new G4LogicalVolume(box, VamosMaterial, "logic_Dipol", 0, 0, 0);
+    m_Dipol->SetVisAttributes(m_VisQuad);
+  }
+  return m_Dipol;
 }
 
 // Detection at the end of Vamos
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildBeamCatcher() {
-    if (!m_BeamCatcher) {
-        G4Box* box = new G4Box("Vamos_Catcher", CatcherWidth * 0.5,
-                CatcherLength * 0.5, CatcherThickness * 0.5);
-
-        G4Material* Material
-            = MaterialManager::getInstance()->GetMaterialFromLibrary(
-                    CatcherMaterial);
-        m_BeamCatcher
-            = new G4LogicalVolume(box, Material, "logic_Vamos_Catcher", 0, 0, 0);
-        m_BeamCatcher->SetVisAttributes(m_VisCatcher);
-        m_BeamCatcher->SetSensitiveDetector(m_CalorimeterScorer);
-    }
-    return m_BeamCatcher;
+  if (!m_BeamCatcher) {
+    G4Box* box = new G4Box("Vamos_Catcher", CatcherWidth * 0.5,
+        CatcherLength * 0.5, CatcherThickness * 0.5);
+
+    G4Material* Material
+      = MaterialManager::getInstance()->GetMaterialFromLibrary(
+          CatcherMaterial);
+    m_BeamCatcher
+      = new G4LogicalVolume(box, Material, "logic_Vamos_Catcher", 0, 0, 0);
+    m_BeamCatcher->SetVisAttributes(m_VisCatcher);
+    m_BeamCatcher->SetSensitiveDetector(m_CalorimeterScorer);
+  }
+  return m_BeamCatcher;
 }
 
+/////////////////////////////////////////////////////////////////////
+G4LogicalVolume* Vamos::BuildTMW1() {
+  if (!m_TMW1) {
+    G4Box* box = new G4Box("Vamos_TMW1", TMW1_Width * 0.5,
+        TMW1_Length * 0.5, TMW1_Thickness * 0.5);
+
+    G4Material* DetectorMaterial
+      = MaterialManager::getInstance()->GetGasFromLibrary(
+          m_Gas_TMW1, m_Pressure_TMW1, 295 * kelvin);
+    m_TMW1 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_TMW1",
+        0, 0, 0);
+    m_TMW1->SetVisAttributes(m_VisGasC4H10);
+
+    m_TMW1->SetSensitiveDetector(m_TMW1Scorer);
+  }
+  return m_TMW1;
+
+}
+
+/////////////////////////////////////////////////////////////////////
+G4LogicalVolume* Vamos::BuildTMW2() {
+  if (!m_TMW2) {
+    G4Box* box = new G4Box("Vamos_TMW2", TMW2_Width * 0.5,
+        TMW2_Length * 0.5, TMW2_Thickness * 0.5);
+
+    G4Material* DetectorMaterial
+      = MaterialManager::getInstance()->GetGasFromLibrary(
+          m_Gas_TMW2, m_Pressure_TMW2, 295 * kelvin);
+    m_TMW2 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_TMW2",
+        0, 0, 0);
+    m_TMW2->SetVisAttributes(m_VisGasC4H10);
+  }
+  return m_TMW2;
+
+}
+
+
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildMWPPAC() {
-    if (!m_MWPPAC) {
-        G4Box* box = new G4Box("Vamos_MWPPAC", ChamberWidth * 0.5,
-                ChamberLength * 0.5, ChamberThickness * 0.5);
-
-        G4Material* DetectorMaterial
-            = MaterialManager::getInstance()->GetGasFromLibrary(
-                    m_Gas[2], m_Pressure[2], m_Temperature[2]);
-        m_MWPPAC = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_MWPPAC",
-                0, 0, 0);
-        m_MWPPAC->SetVisAttributes(m_VisGasC4H10);
-    }
-    return m_MWPPAC;
+  if (!m_MWPPAC) {
+    G4Box* box = new G4Box("Vamos_MWPPAC", ChamberWidth * 0.5,
+        ChamberLength * 0.5, ChamberThickness * 0.5);
+
+    G4Material* DetectorMaterial
+      = MaterialManager::getInstance()->GetGasFromLibrary(
+          m_Gas[0], m_Pressure[0], m_Temperature[0]);
+    m_MWPPAC = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_MWPPAC",
+        0, 0, 0);
+    m_MWPPAC->SetVisAttributes(m_VisGasC4H10);
+  }
+  return m_MWPPAC;
 }
 
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildDC3() {
-    if (!m_DC3) {
-        G4Box* box = new G4Box("Vamos_DC3", ChamberWidth * 0.5, ChamberLength * 0.5,
-                ChamberThickness * 0.5);
-
-        G4Material* DetectorMaterial
-            = MaterialManager::getInstance()->GetGasFromLibrary(
-                    m_Gas[3], m_Pressure[3], m_Temperature[3]);
-
-        m_DC3 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_DC3", 0, 0,
-                0);
-        m_DC3->SetVisAttributes(m_VisGasC4H10);
-        m_DC3->SetSensitiveDetector(m_DCScorer);
-    }
-    return m_DC3;
+  if (!m_DC3) {
+    G4Box* box = new G4Box("Vamos_DC3", ChamberWidth * 0.5, ChamberLength * 0.5,
+        ChamberThickness * 0.5);
+
+    G4Material* DetectorMaterial
+      = MaterialManager::getInstance()->GetGasFromLibrary(
+          m_Gas[3], m_Pressure[3], m_Temperature[3]);
+
+    m_DC3 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_DC3", 0, 0,
+        0);
+    m_DC3->SetVisAttributes(m_VisGasC4H10);
+    m_DC3->SetSensitiveDetector(m_DCScorer);
+  }
+  return m_DC3;
 }
 
+/////////////////////////////////////////////////////////////////////
 G4LogicalVolume* Vamos::BuildDC4() {
-    if (!m_DC4) {
-        G4Box* box = new G4Box("Vamos_DC4", ChamberWidth * 0.5, ChamberLength * 0.5,
-                ChamberThickness * 0.5);
-
-        G4Material* DetectorMaterial
-            = MaterialManager::getInstance()->GetGasFromLibrary(
-                    m_Gas[4], m_Pressure[4], m_Temperature[4]);
-
-        m_DC4 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_DC4", 0, 0,
-                0);
-        m_DC4->SetVisAttributes(m_VisGasC4H10);
-        m_DC4->SetSensitiveDetector(m_DCScorer);
-    }
-    return m_DC4;
+  if (!m_DC4) {
+    G4Box* box = new G4Box("Vamos_DC4", ChamberWidth * 0.5, ChamberLength * 0.5,
+        ChamberThickness * 0.5);
+
+    G4Material* DetectorMaterial
+      = MaterialManager::getInstance()->GetGasFromLibrary(
+          m_Gas[4], m_Pressure[4], m_Temperature[4]);
+
+    m_DC4 = new G4LogicalVolume(box, DetectorMaterial, "logic_Vamos_DC4", 0, 0,
+        0);
+    m_DC4->SetVisAttributes(m_VisGasC4H10);
+    m_DC4->SetSensitiveDetector(m_DCScorer);
+  }
+  return m_DC4;
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 // In anticipation of use a macro
 void Vamos::ClearGeometry(){
 
-    m_Z.clear();
-    m_Gas.clear();
-    m_Pressure.clear();
-    m_Temperature.clear();
+  m_Z.clear();
+  m_Gas.clear();
+  m_Pressure.clear();
+  m_Temperature.clear();
 
-    m_ZIC.clear();
-    m_ThicknessIC.clear();
-    m_PressureIC.clear();
-    m_TemperatureIC.clear();
-    m_GasIC.clear();
+  m_ZIC.clear();
+  m_ThicknessIC.clear();
+  m_PressureIC.clear();
+  m_TemperatureIC.clear();
+  m_GasIC.clear();
 
 }   
 
@@ -338,202 +401,237 @@ void Vamos::ClearGeometry(){
 // Read stream at Configfile to pick-up parameters of detector (Position,...)
 // Called in DetecorConstruction::ReadDetectorConfiguration Method
 
+/////////////////////////////////////////////////////////////////////
 void Vamos::ReadConfiguration(NPL::InputParser parser) {
 
-    vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Vamos");
-    if (NPOptionManager::getInstance()->GetVerboseLevel())
-        cout << "//// " << blocks.size() << " detectors found " << endl;
-
-    vector<string> TokenBeamCatcher
-        = {"Material", "Width", "Length", "Thickness", "Pos"};
-    vector<string> sphe        = {"R", "Theta"};
-    vector<string> TokenMWPPAC = {"Z", "Gas", "Pressure", "Temperature"};
-    vector<string> TokenDC     = {"Z", "Gas", "Pressure", "Temperature"};
-    vector<string> TokenIC = {"Z", "Thickness", "Gas", "Pressure", "Temperature"};
-
-    for (unsigned int i = 0; i < blocks.size(); i++) {
-        if (blocks[i]->HasTokenList(sphe)) {
-            if (NPOptionManager::getInstance()->GetVerboseLevel())
-                cout << endl << "////  Vamos " << i + 1 << endl;
-            G4double R     = blocks[i]->GetDouble("R", "mm");
-            G4double Theta = blocks[i]->GetDouble("Theta", "deg");
-            AddVamos(R, Theta);
-        }
-
-        else if (blocks[i]->GetMainValue() == "BeamCatcher"
-                && blocks[i]->HasTokenList(TokenBeamCatcher)) {
-            if (NPOptionManager::getInstance()->GetVerboseLevel())
-                cout << endl << "//// BeamCatcher" << i + 1 << endl;
-            string        Material  = blocks[i]->GetString("Material");
-            G4double      Width     = blocks[i]->GetDouble("Width", "mm");
-            G4double      Length    = blocks[i]->GetDouble("Length", "mm");
-            G4double      Thickness = blocks[i]->GetDouble("Thickness", "mm");
-            G4ThreeVector Pos
-                = NPS::ConvertVector(blocks[i]->GetTVector3("Pos", "mm"));
-            AddBeamCatcher(Material, Width, Length, Thickness, Pos);
-        }
-
-        else if (blocks[i]->GetMainValue() == "MWPPAC"
-                && blocks[i]->HasTokenList(TokenMWPPAC)) {
-            if (NPOptionManager::getInstance()->GetVerboseLevel())
-                cout << endl << "//// MWPPAC" << i + 1 << endl;
-            G4double Z           = blocks[i]->GetDouble("Z", "mm");
-            string   Gas         = blocks[i]->GetString("Gas");
-            G4double Pressure    = blocks[i]->GetDouble("Pressure", "bar");
-            G4double Temperature = blocks[i]->GetDouble("Temperature", "kelvin");
-            AddDetector(Z, Gas, Pressure, Temperature);
-        }
-
-        else if (blocks[i]->GetMainValue() == "DC"
-                && blocks[i]->HasTokenList(TokenDC)) {
-            if (NPOptionManager::getInstance()->GetVerboseLevel())
-                cout << endl << "//// DC" << i + 1 << endl;
-            G4double Z           = blocks[i]->GetDouble("Z", "mm");
-            string   Gas         = blocks[i]->GetString("Gas");
-            G4double Pressure    = blocks[i]->GetDouble("Pressure", "bar");
-            G4double Temperature = blocks[i]->GetDouble("Temperature", "kelvin");
-            AddDetector(Z, Gas, Pressure, Temperature);
-        }
-
-        else if (blocks[i]->GetMainValue() == "IC"
-                && blocks[i]->HasTokenList(TokenIC)) {
-            if (NPOptionManager::getInstance()->GetVerboseLevel())
-                cout << endl << "//// IC" << ICcounter+1 << endl;
-            G4double Z           = blocks[i]->GetDouble("Z", "mm");
-            G4double Thickness   = blocks[i]->GetDouble("Thickness", "mm");
-            string   Gas         = blocks[i]->GetString("Gas");
-            G4double Pressure    = blocks[i]->GetDouble("Pressure", "bar");
-            G4double Temperature = blocks[i]->GetDouble("Temperature", "kelvin");
-            AddIC(Z, Thickness, Gas, Pressure, Temperature);
-            ICcounter++;
-        }
-
-        else {
-            cout << "ERROR: check your input file formatting " << endl;
-            exit(1);
-        }
+  vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Vamos");
+  if (NPOptionManager::getInstance()->GetVerboseLevel())
+    cout << "//// " << blocks.size() << " detectors found " << endl;
+
+  vector<string> TokenBeamCatcher
+    = {"Material", "Width", "Length", "Thickness", "Pos"};
+  vector<string> sphe        = {"R", "Theta"};
+  vector<string> TokenMWPPAC = {"Z", "Gas", "Pressure", "Temperature"};
+  vector<string> TokenTMW = {"Z", "Gas", "Pressure"};
+  vector<string> TokenDC     = {"Z", "Gas", "Pressure", "Temperature"};
+  vector<string> TokenIC = {"Z", "Thickness", "Gas", "Pressure", "Temperature"};
+
+  for (unsigned int i = 0; i < blocks.size(); i++) {
+    if (blocks[i]->HasTokenList(sphe)) {
+      if (NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "////  Vamos " << i + 1 << endl;
+      G4double R     = blocks[i]->GetDouble("R", "mm");
+      G4double Theta = blocks[i]->GetDouble("Theta", "deg");
+      AddVamos(R, Theta);
+    }
 
+    else if (blocks[i]->GetMainValue() == "BeamCatcher"
+        && blocks[i]->HasTokenList(TokenBeamCatcher)) {
+      if (NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "//// BeamCatcher" << i + 1 << endl;
+      string        Material  = blocks[i]->GetString("Material");
+      G4double      Width     = blocks[i]->GetDouble("Width", "mm");
+      G4double      Length    = blocks[i]->GetDouble("Length", "mm");
+      G4double      Thickness = blocks[i]->GetDouble("Thickness", "mm");
+      G4ThreeVector Pos
+        = NPS::ConvertVector(blocks[i]->GetTVector3("Pos", "mm"));
+      AddBeamCatcher(Material, Width, Length, Thickness, Pos);
     }
-}
 
-// Construct detector and inialise sensitive part.
-// Called After DetecorConstruction::AddDetector Method
-void Vamos::ConstructDetector(G4LogicalVolume* world) {
+    else if (blocks[i]->GetMainValue() == "MWPPAC"
+        && blocks[i]->HasTokenList(TokenMWPPAC)) {
+      if (NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "//// MWPPAC" << i + 1 << endl;
+      G4double Z           = blocks[i]->GetDouble("Z", "mm");
+      string   Gas         = blocks[i]->GetString("Gas");
+      G4double Pressure    = blocks[i]->GetDouble("Pressure", "bar");
+      G4double Temperature = blocks[i]->GetDouble("Temperature", "kelvin");
+      AddDetector(Z, Gas, Pressure, Temperature);
+    }
 
-    // Mother Volume of Vamos
-    G4double R  = m_R + VamosVolumeThickness * 0.5;
+    else if (blocks[i]->GetMainValue() == "TMW1"
+        && blocks[i]->HasTokenList(TokenTMW)) {
+      if (NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "//// TMW1"  << endl;
+      m_Z_TMW1           = blocks[i]->GetDouble("Z", "mm");
+      m_Gas_TMW1         = blocks[i]->GetString("Gas");
+      m_Pressure_TMW1    = blocks[i]->GetDouble("Pressure", "bar");
+      //AddDetector(Z, Gas, Pressure, Temperature);
+    }
 
-    G4double X = R * sin(m_Theta) * cos(Phi);
-    G4double Y = R * sin(m_Theta) * sin(Phi);
-    G4double Z = R * cos(m_Theta);
-    G4ThreeVector Det_pos = G4ThreeVector(X, Y, Z);
+    else if (blocks[i]->GetMainValue() == "TMW2"
+        && blocks[i]->HasTokenList(TokenTMW)) {
+      if (NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "//// TMW2"  << endl;
+      m_Z_TMW2           = blocks[i]->GetDouble("Z", "mm");
+      m_Gas_TMW2         = blocks[i]->GetString("Gas");
+      m_Pressure_TMW2    = blocks[i]->GetDouble("Pressure", "bar");
+      //AddDetector(Z, Gas, Pressure, Temperature);
+    }
 
-    G4RotationMatrix* Rot1 = new G4RotationMatrix();
-    Rot1->rotateY(m_Theta);
 
-    G4Box* MotherSolid
-        = new G4Box("MotherVolume", VamosVolumeWidth * 0.5,
-                VamosVolumeLength * 0.5, VamosVolumeThickness * 0.5);
 
-    G4Material* VolumeMaterial
-        = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
-    G4LogicalVolume* MotherVolume = new G4LogicalVolume(
-            MotherSolid, VolumeMaterial, "MotherVolume", 0, 0, 0);
+    else if (blocks[i]->GetMainValue() == "DC"
+        && blocks[i]->HasTokenList(TokenDC)) {
+      if (NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "//// DC" << i + 1 << endl;
+      G4double Z           = blocks[i]->GetDouble("Z", "mm");
+      string   Gas         = blocks[i]->GetString("Gas");
+      G4double Pressure    = blocks[i]->GetDouble("Pressure", "bar");
+      G4double Temperature = blocks[i]->GetDouble("Temperature", "kelvin");
+      AddDetector(Z, Gas, Pressure, Temperature);
+    }
 
-    new G4PVPlacement(G4Transform3D(*Rot1, Det_pos), MotherVolume, "MotherVolume",
-            world, false, 0);
-    MotherVolume->SetVisAttributes(m_VisVolumeVamos);
+    else if (blocks[i]->GetMainValue() == "IC"
+        && blocks[i]->HasTokenList(TokenIC)) {
+      if (NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "//// IC" << ICcounter+1 << endl;
+      G4double Z           = blocks[i]->GetDouble("Z", "mm");
+      G4double Thickness   = blocks[i]->GetDouble("Thickness", "mm");
+      string   Gas         = blocks[i]->GetString("Gas");
+      G4double Pressure    = blocks[i]->GetDouble("Pressure", "bar");
+      G4double Temperature = blocks[i]->GetDouble("Temperature", "kelvin");
+      AddIC(Z, Thickness, Gas, Pressure, Temperature);
+      ICcounter++;
+    }
 
-    // SubVolume of Detection at the end of Vamos
-    // The position of the subvolume is defined by the position of the BeamCatcher
-    G4double R2
-        = R_Catcher - CatcherThickness * 0.5 + DetectionVolumeThickness * 0.5;
+    else {
+      cout << "ERROR: check your input file formatting " << endl;
+      exit(1);
+    }
 
-    G4double      X2 = R2 * sin(Det_Theta) * cos(0);
-    G4double      Z2 = R2 * cos(Det_Theta);
-    G4ThreeVector Det_pos2 = G4ThreeVector(X2, 0, Z2);
+  }
+}
 
-    G4RotationMatrix* Rot2 = new G4RotationMatrix();
-    Rot2->rotateY(Det_Theta);
+// Construct detector and inialise sensitive part.
+// Called After DetecorConstruction::AddDetector Method
+void Vamos::ConstructDetector(G4LogicalVolume* world) {
 
-    G4Box* MotherDetectorSolid
-        = new G4Box("MotherDetector", DetectionVolumeWidth * 0.5,
-                DetectionVolumeLength * 0.5, DetectionVolumeThickness * 0.5);
+  // Mother Volume of Vamos
+  G4double R  = m_R + VamosVolumeThickness * 0.5;
 
-    G4LogicalVolume* MotherDetector = new G4LogicalVolume(
-            MotherDetectorSolid, VolumeMaterial, "MotherDetector", 0, 0, 0);
+  G4double X = R * sin(m_Theta) * cos(Phi);
+  G4double Y = R * sin(m_Theta) * sin(Phi);
+  G4double Z = R * cos(m_Theta);
+  G4ThreeVector Det_pos = G4ThreeVector(X, Y, Z);
 
-    new G4PVPlacement(G4Transform3D(*Rot2, Det_pos2), MotherDetector,
-            "MotherDetector", MotherVolume, false, 0);
-    MotherDetector->SetVisAttributes(m_VisVolumeVamos);
+  G4RotationMatrix* Rot1 = new G4RotationMatrix();
+  Rot1->rotateY(m_Theta);
 
+  G4Box* MotherSolid
+    = new G4Box("MotherVolume", VamosVolumeWidth * 0.5,
+        VamosVolumeLength * 0.5, VamosVolumeThickness * 0.5);
 
-    // Position the entry DCs and the magnets in the MotherVolume
-    new G4PVPlacement(0, G4ThreeVector(0, 0, -VamosVolumeThickness * 0.5 + m_Z[0]),
-            BuildDC1(), "Entrance_DC1", MotherVolume, false, 1);
+  G4Material* VolumeMaterial
+    = MaterialManager::getInstance()->GetMaterialFromLibrary("Vacuum");
+  G4LogicalVolume* MotherVolume = new G4LogicalVolume(
+      MotherSolid, VolumeMaterial, "MotherVolume", 0, 0, 0);
 
-    new G4PVPlacement(0, G4ThreeVector(0, 0, -VamosVolumeThickness * 0.5 + m_Z[1]),
-            BuildDC2(), "Entrance_DC2", MotherVolume, false, 2);
+  new G4PVPlacement(G4Transform3D(*Rot1, Det_pos), MotherVolume, "MotherVolume",
+      world, false, 0);
+  MotherVolume->SetVisAttributes(m_VisVolumeVamos);
 
-    new G4PVPlacement(
-            0,
-            G4ThreeVector(0, 0, (-VamosVolumeThickness + MagnetThickness) * 0.5 + 400),
-            BuildQuad1(), "Vamos", MotherVolume, false, 0);
+  // SubVolume of Detection at the end of Vamos
+  // The position of the subvolume is defined by the position of the BeamCatcher
+  G4double R2
+    = R_Catcher - CatcherThickness * 0.5 + DetectionVolumeThickness * 0.5;
 
-    new G4PVPlacement(
-            0,
-            G4ThreeVector(0, 0,
-                (-VamosVolumeThickness + MagnetThickness) * 0.5 + 700 * mm),
-            BuildQuad2(), "Vamos", MotherVolume, false, 0);
+  G4double      X2 = R2 * sin(Det_Theta) * cos(0);
+  G4double      Z2 = R2 * cos(Det_Theta);
+  G4ThreeVector Det_pos2 = G4ThreeVector(X2, 0, Z2);
 
-    new G4PVPlacement(
-            0,
-            G4ThreeVector(0, 0,
-                (-VamosVolumeThickness + MagnetThickness) * 0.5 + 1500 * mm),
-            BuildDipol(), "Vamos", MotherVolume, false, 0);
+  G4RotationMatrix* Rot2 = new G4RotationMatrix();
+  Rot2->rotateY(Det_Theta);
 
-    // Position the system of detection at the end of Vamos in the sub Volume
-    new G4PVPlacement(0, m_PosCatcher, BuildBeamCatcher(), "BeamCatcher",
-            MotherDetector, false, 3);
+  G4Box* MotherDetectorSolid
+    = new G4Box("MotherDetector", DetectionVolumeWidth * 0.5,
+        DetectionVolumeLength * 0.5, DetectionVolumeThickness * 0.5);
 
-    new G4PVPlacement(
-            0,
-            G4ThreeVector(0, 0,
-                -DetectionVolumeThickness * 0.5
-                + (m_Z[2] - R_Catcher + CatcherThickness * 0.5)),
-            BuildMWPPAC(), "MWPPAC", MotherDetector, false, 4);
+  G4LogicalVolume* MotherDetector = new G4LogicalVolume(
+      MotherDetectorSolid, VolumeMaterial, "MotherDetector", 0, 0, 0);
 
-    new G4PVPlacement(
-            0,
-            G4ThreeVector(0, 0,
-                -DetectionVolumeThickness * 0.5
-                + (m_Z[3] - R_Catcher + CatcherThickness * 0.5)),
-            BuildDC3(), "DC", MotherDetector, false, 5);
+  new G4PVPlacement(G4Transform3D(*Rot2, Det_pos2), MotherDetector,
+      "MotherDetector", MotherVolume, false, 0);
+  MotherDetector->SetVisAttributes(m_VisVolumeVamos);
+
+
+  // Position the entry DCs and the magnets in the MotherVolume
+  /*new G4PVPlacement(0, G4ThreeVector(0, 0, -VamosVolumeThickness * 0.5 + m_Z[0]),
+    BuildDC1(), "Entrance_DC1", MotherVolume, false, 1);
+
+    new G4PVPlacement(0, G4ThreeVector(0, 0, -VamosVolumeThickness * 0.5 + m_Z[1]),
+    BuildDC2(), "Entrance_DC2", MotherVolume, false, 2);*/
+
+  new G4PVPlacement(
+      0,
+      G4ThreeVector(0, 0, (-VamosVolumeThickness + MagnetThickness) * 0.5 + 400),
+      BuildQuad1(), "Vamos", MotherVolume, false, 0);
+
+  new G4PVPlacement(
+      0,
+      G4ThreeVector(0, 0,
+        (-VamosVolumeThickness + MagnetThickness) * 0.5 + 700 * mm),
+      BuildQuad2(), "Vamos", MotherVolume, false, 0);
+
+  new G4PVPlacement(
+      0,
+      G4ThreeVector(0, 0,
+        (-VamosVolumeThickness + MagnetThickness) * 0.5 + 1500 * mm),
+      BuildDipol(), "Vamos", MotherVolume, false, 0);
+
+  // Position the system of detection at the end of Vamos in the sub Volume
+  /*new G4PVPlacement(0, m_PosCatcher, BuildBeamCatcher(), "BeamCatcher",
+    MotherDetector, false, 3);*/
+
+  new G4PVPlacement(
+      0,
+      G4ThreeVector(0, 0, -VamosVolumeThickness * 0.5 + TMW1_Thickness * 0.5),
+      BuildTMW1(), "TMW1", MotherVolume, false, 0);
+
+  new G4PVPlacement(
+      0,
+      G4ThreeVector(0, 0, -VamosVolumeThickness * 0.5 + TMW2_Thickness * 0.5 + m_Z_TMW2),
+      BuildTMW2(), "TMW2", MotherVolume, false, 0);
+
+
+/*  new G4PVPlacement(
+      0,
+      G4ThreeVector(0, 0,
+        -DetectionVolumeThickness * 0.5
+        + (m_Z[0] - R_Catcher + CatcherThickness * 0.5)),
+      BuildMWPPAC(), "MWPPAC", MotherDetector, false, 1);
+*/
+  /*    new G4PVPlacement(
+        0,
+        G4ThreeVector(0, 0,
+        -DetectionVolumeThickness * 0.5
+        + (m_Z[3] - R_Catcher + CatcherThickness * 0.5)),
+        BuildDC3(), "DC", MotherDetector, false, 5);
 
-    new G4PVPlacement(
-            0,
-            G4ThreeVector(0, 0,
-                -DetectionVolumeThickness * 0.5
-                + (m_Z[4] - R_Catcher + CatcherThickness * 0.5)),
-            BuildDC4(), "DC", MotherDetector, false, 6);
-
-    // Construct and position the Ionisations Chambers
-    for (int i = 0; i < ICcounter; i++) {
-        G4Box* box = new G4Box("Vamos_IC", ChamberWidth * 0.5, ChamberLength * 0.5,
-                m_ThicknessIC[i] * 0.5);
-        G4Material* GasIC = MaterialManager::getInstance()->GetGasFromLibrary(
-                m_GasIC[i], m_PressureIC[i], m_TemperatureIC[i]);
-        G4LogicalVolume* IC
-            = new G4LogicalVolume(box, GasIC, "logic_Vamos_IC", 0, 0, 0);
-        IC->SetVisAttributes(m_VisGasCF4);
-        IC->SetSensitiveDetector(m_CalorimeterScorer);
         new G4PVPlacement(
-                0,
-                G4ThreeVector(0, 0,
-                    -DetectionVolumeThickness * 0.5
-                    + (m_ZIC[i] - R_Catcher + CatcherThickness * 0.5)),
-                IC, "IC", MotherDetector, false, i + 7);
-    }
+        0,
+        G4ThreeVector(0, 0,
+        -DetectionVolumeThickness * 0.5
+        + (m_Z[4] - R_Catcher + CatcherThickness * 0.5)),
+        BuildDC4(), "DC", MotherDetector, false, 6);*/
+
+  // Construct and position the Ionisations Chambers
+  /*for (int i = 0; i < ICcounter; i++) {
+    G4Box* box = new G4Box("Vamos_IC", ChamberWidth * 0.5, ChamberLength * 0.5,
+    m_ThicknessIC[i] * 0.5);
+    G4Material* GasIC = MaterialManager::getInstance()->GetGasFromLibrary(
+    m_GasIC[i], m_PressureIC[i], m_TemperatureIC[i]);
+    G4LogicalVolume* IC
+    = new G4LogicalVolume(box, GasIC, "logic_Vamos_IC", 0, 0, 0);
+    IC->SetVisAttributes(m_VisGasCF4);
+    IC->SetSensitiveDetector(m_CalorimeterScorer);
+    new G4PVPlacement(
+    0,
+    G4ThreeVector(0, 0,
+    -DetectionVolumeThickness * 0.5
+    + (m_ZIC[i] - R_Catcher + CatcherThickness * 0.5)),
+    IC, "IC", MotherDetector, false, i + 7);
+    }*/
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -541,12 +639,12 @@ void Vamos::ConstructDetector(G4LogicalVolume* world) {
 // Called After DetecorConstruction::AddDetector Method
 
 void Vamos::InitializeRootOutput() {
-    RootOutput* pAnalysis = RootOutput::getInstance();
-    TTree*      pTree     = pAnalysis->GetTree();
-    if (!pTree->FindBranch("Vamos")) {
-        pTree->Branch("Vamos", "TVamosData", &m_Event);
-    }
-    pTree->SetBranchAddress("Vamos", &m_Event);
+  RootOutput* pAnalysis = RootOutput::getInstance();
+  TTree*      pTree     = pAnalysis->GetTree();
+  if (!pTree->FindBranch("Vamos")) {
+    pTree->Branch("Vamos", "TVamosData", &m_Event);
+  }
+  pTree->SetBranchAddress("Vamos", &m_Event);
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -554,67 +652,71 @@ void Vamos::InitializeRootOutput() {
 // Called at in the EventAction::EndOfEventAvtion
 void Vamos::ReadSensitive(const G4Event*) {
 
-    m_Event->Clear();
-
-    ///////////
-    // Calorimeter scorer
-    CalorimeterScorers::PS_Calorimeter* Scorer
-        = (CalorimeterScorers::PS_Calorimeter*)m_CalorimeterScorer->GetPrimitive(
-                0);
-    unsigned int size = Scorer->GetMult();
-    for (unsigned int i = 0; i < size; i++) {
-        vector<unsigned int> level = Scorer->GetLevel(i);
-        G4double             Energy
-            = RandGauss::shoot(Scorer->GetEnergy(i), Vamos_NS::ResoEnergy);
-        if (Energy > Vamos_NS::EnergyThreshold) {
-            G4double Time = RandGauss::shoot(Scorer->GetTime(i), Vamos_NS::ResoTime);
-            int      DetectorNbr = level[0];
-            m_Event->SetEnergy(DetectorNbr, Energy);
-            m_Event->SetTime(DetectorNbr, Time);
-        }
-    }
-    ///////////
-    // DriftChamber  scorer
-    DriftChamberScorers::PS_DriftChamber* Scorer2
-        = (DriftChamberScorers::PS_DriftChamber*)m_DCScorer->GetPrimitive(0);
-    unsigned int size2 = Scorer2->GetMult();
-    for (unsigned int i = 0; i < size2; i++) {
-        vector<unsigned int> level     = Scorer2->GetLevel(i);
-        G4double               DriftTime 
-            = RandGauss::shoot(Scorer2->GetDriftTime(i)/Scorer2->GetCounter(i), Vamos_NS::ResoDriftTime);
-        G4double               X         
-            = RandGauss::shoot(Scorer2->GetX(i)/Scorer2->GetCounter(i), ResoPosX);
-        int DetectorNbr = level[0];
-        m_Event->SetDrift(DetectorNbr, DriftTime, X);
+  m_Event->Clear();
+
+  ///////////
+  // Calorimeter scorer
+  CalorimeterScorers::PS_Calorimeter* Scorer
+    = (CalorimeterScorers::PS_Calorimeter*)m_CalorimeterScorer->GetPrimitive(0);
+  unsigned int size = Scorer->GetMult();
+  for (unsigned int i = 0; i < size; i++) {
+    vector<unsigned int> level = Scorer->GetLevel(i);
+    G4double             Energy
+      = RandGauss::shoot(Scorer->GetEnergy(i), Vamos_NS::ResoEnergy);
+    if (Energy > Vamos_NS::EnergyThreshold) {
+      G4double Time = RandGauss::shoot(Scorer->GetTime(i), Vamos_NS::ResoTime);
+      int      DetectorNbr = level[0];
+      m_Event->SetEnergy(DetectorNbr, Energy);
+      m_Event->SetTime(DetectorNbr, Time);
     }
+  }
+  ///////////
+  // DriftChamber  scorer
+  DriftChamberScorers::PS_DriftChamber* Scorer2
+    = (DriftChamberScorers::PS_DriftChamber*)m_DCScorer->GetPrimitive(0);
+  unsigned int size2 = Scorer2->GetMult();
+  for (unsigned int i = 0; i < size2; i++) {
+    vector<unsigned int> level     = Scorer2->GetLevel(i);
+    G4double               DriftTime 
+      = RandGauss::shoot(Scorer2->GetDriftTime(i)/Scorer2->GetCounter(i), Vamos_NS::ResoDriftTime);
+    G4double               X         
+      = RandGauss::shoot(Scorer2->GetX(i)/Scorer2->GetCounter(i), ResoPosX);
+    int DetectorNbr = level[0];
+    m_Event->SetDrift(DetectorNbr, DriftTime, X);
+  }
 
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 ////////////////////////////////////////////////////////////////
 void Vamos::InitializeScorers() {
-    // This check is necessary in case the geometry is reloaded
-    bool already_exist  = false;
-    m_DCScorer          = CheckScorer("DCScorer", already_exist);
-    m_CalorimeterScorer = CheckScorer("VamosScorer", already_exist);
-    if (already_exist)
-        return;
-
-    // Otherwise the scorer is initialised
-    vector<int> level;
-    level.push_back(0);
-
-    G4VPrimitiveScorer* Calorimeter
-        = new CalorimeterScorers::PS_Calorimeter("Calorimeter", level, 0);
-    m_CalorimeterScorer->RegisterPrimitive(Calorimeter);
-
-    G4VPrimitiveScorer* Drift = new DriftChamberScorers::PS_DriftChamber(
-            "Drift", level, DriftDir, DriftSpeed, 0);
-    m_DCScorer->RegisterPrimitive(Drift);
-
-    // and register it to the multifunctionnal detector
-    G4SDManager::GetSDMpointer()->AddNewDetector(m_DCScorer);
-    G4SDManager::GetSDMpointer()->AddNewDetector(m_CalorimeterScorer);
+  // This check is necessary in case the geometry is reloaded
+  bool already_exist  = false;
+  m_DCScorer          = CheckScorer("DCScorer", already_exist);
+  m_CalorimeterScorer = CheckScorer("VamosScorer", already_exist);
+  m_TMW1Scorer = CheckScorer("TMW1Scorer", already_exist);
+  if (already_exist)
+    return;
+
+  // Otherwise the scorer is initialised
+  vector<int> level;
+  level.push_back(0);
+
+  G4VPrimitiveScorer* Calorimeter
+    = new CalorimeterScorers::PS_Calorimeter("Calorimeter", level, 0);
+  m_CalorimeterScorer->RegisterPrimitive(Calorimeter);
+
+  G4VPrimitiveScorer* Drift = new DriftChamberScorers::PS_DriftChamber(
+      "Drift", level, DriftDir, DriftSpeed, 0);
+  m_DCScorer->RegisterPrimitive(Drift);
+
+  G4VPrimitiveScorer* InteractionTMW1 = new InteractionScorers::PS_Interactions("InteractionTMW1",ms_InterCoord,0);
+  m_TMW1Scorer->RegisterPrimitive(InteractionTMW1);
+
+  // and register it to the multifunctionnal detector
+  G4SDManager::GetSDMpointer()->AddNewDetector(m_DCScorer);
+  G4SDManager::GetSDMpointer()->AddNewDetector(m_CalorimeterScorer);
+  G4SDManager::GetSDMpointer()->AddNewDetector(m_TMW1Scorer);
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -628,13 +730,13 @@ NPS::VDetector* Vamos::Construct() { return (NPS::VDetector*)new Vamos(); }
 //            Registering the construct method to the factory //
 ////////////////////////////////////////////////////////////////////////////////
 extern "C" {
-    class proxy_nps_Vamos {
-        public:
-            proxy_nps_Vamos() {
-                NPS::DetectorFactory::getInstance()->AddToken("Vamos", "Vamos");
-                NPS::DetectorFactory::getInstance()->AddDetector("Vamos", Vamos::Construct);
-            }
-    };
-
-    proxy_nps_Vamos p_nps_Vamos;
+  class proxy_nps_Vamos {
+    public:
+      proxy_nps_Vamos() {
+        NPS::DetectorFactory::getInstance()->AddToken("Vamos", "Vamos");
+        NPS::DetectorFactory::getInstance()->AddDetector("Vamos", Vamos::Construct);
+      }
+  };
+
+  proxy_nps_Vamos p_nps_Vamos;
 }
diff --git a/NPSimulation/Detectors/Vamos/Vamos.hh b/NPSimulation/Detectors/Vamos/Vamos.hh
index d4e6b3dc0372b2e92ccef1261623cb02a75cc9fc..b33f39dfc66fd70a185331d33590d4620deb546e 100644
--- a/NPSimulation/Detectors/Vamos/Vamos.hh
+++ b/NPSimulation/Detectors/Vamos/Vamos.hh
@@ -39,134 +39,147 @@ using namespace std;
 #include "NPInputParser.h"
 
 class Vamos : public NPS::VDetector{
+  ////////////////////////////////////////////////////
+  /////// Default Constructor and Destructor /////////
+  ////////////////////////////////////////////////////
+  public:
+    Vamos() ;
+    virtual ~Vamos() ;
+
+    ////////////////////////////////////////////////////
+    /////// Specific Function of this Class ///////////
+    ////////////////////////////////////////////////////
+  public:  
+
+    void AddVamos(G4double R,double Theta);  
+    void AddBeamCatcher(string Material, G4double Width, double Length, double Thickness, G4ThreeVector Pos);
+    void AddDetector(G4double Z, string Gas, double Pressure, double Temperature);       
+    void AddIC(G4double Z,  double Thickness, string Gas, double Pressure, double Temperature);
+
+    G4LogicalVolume* BuildDC1();
+    G4LogicalVolume* BuildDC2();
+
+    G4LogicalVolume* BuildQuad1();
+    G4LogicalVolume* BuildQuad2();
+    G4LogicalVolume* BuildDipol();
+
+    G4LogicalVolume* BuildBeamCatcher();
+    G4LogicalVolume* BuildMWPPAC();
+    G4LogicalVolume* BuildDC3();
+    G4LogicalVolume* BuildDC4();
+    G4LogicalVolume* BuildIC(); 
+    G4LogicalVolume* BuildTMW1(); 
+    G4LogicalVolume* BuildTMW2(); 
+
+  private:
+
+    G4LogicalVolume* m_DC1;
+    G4LogicalVolume* m_DC2;
+
+    G4LogicalVolume* m_Quad1;
+    G4LogicalVolume* m_Quad2;
+    G4LogicalVolume* m_Dipol;    
+
+    G4LogicalVolume* m_BeamCatcher;
+    G4LogicalVolume* m_MWPPAC;
+    G4LogicalVolume* m_DC3;
+    G4LogicalVolume* m_DC4;
+    G4LogicalVolume* m_IC;
+    G4LogicalVolume* m_TMW1;
+    G4LogicalVolume* m_TMW2;
+
+    G4double ICcounter;
+
     ////////////////////////////////////////////////////
-    /////// Default Constructor and Destructor /////////
+    //////  Inherite from NPS::VDetector class /////////
     ////////////////////////////////////////////////////
-    public:
-        Vamos() ;
-        virtual ~Vamos() ;
+  public:
+    // Read stream at Configfile to pick-up parameters of detector (Position,...)
+
+    void ClearGeometry();
+
+    // Called in DetecorConstruction::ReadDetextorConfiguration Method
+    void ReadConfiguration(NPL::InputParser) ;
 
-        ////////////////////////////////////////////////////
-        /////// Specific Function of this Class ///////////
-        ////////////////////////////////////////////////////
-    public:  
+    // Construct detector and inialise sensitive part.
+    // Called After DetecorConstruction::AddDetector Method
+    void ConstructDetector(G4LogicalVolume* world) ;
 
-        void AddVamos(G4double R,double Theta);  
-        void AddBeamCatcher(string Material, G4double Width, double Length, double Thickness, G4ThreeVector Pos);
-        void AddDetector(G4double Z, string Gas, double Pressure, double Temperature);       
-        void AddIC(G4double Z,  double Thickness, string Gas, double Pressure, double Temperature);
+    // Add Detector branch to the EventTree.
+    // Called After DetecorConstruction::AddDetector Method
+    void InitializeRootOutput() ;
 
-        G4LogicalVolume* BuildDC1();
-        G4LogicalVolume* BuildDC2();
+    // Read sensitive part and fill the Root tree.
+    // Called at in the EventAction::EndOfEventAvtion
+    void ReadSensitive(const G4Event* event) ;
 
-        G4LogicalVolume* BuildQuad1();
-        G4LogicalVolume* BuildQuad2();
-        G4LogicalVolume* BuildDipol();
-
-        G4LogicalVolume* BuildBeamCatcher();
-        G4LogicalVolume* BuildMWPPAC();
-        G4LogicalVolume* BuildDC3();
-        G4LogicalVolume* BuildDC4();
-        G4LogicalVolume* BuildIC(); 
-
-    private:
-
-        G4LogicalVolume* m_DC1;
-        G4LogicalVolume* m_DC2;
-
-        G4LogicalVolume* m_Quad1;
-        G4LogicalVolume* m_Quad2;
-        G4LogicalVolume* m_Dipol;    
-
-        G4LogicalVolume* m_BeamCatcher;
-        G4LogicalVolume* m_MWPPAC;
-        G4LogicalVolume* m_DC3;
-        G4LogicalVolume* m_DC4;
-        G4LogicalVolume* m_IC;
-
-        G4double ICcounter;
-
-        ////////////////////////////////////////////////////
-        //////  Inherite from NPS::VDetector class /////////
-        ////////////////////////////////////////////////////
-    public:
-        // Read stream at Configfile to pick-up parameters of detector (Position,...)
-
-        void ClearGeometry();
-
-        // Called in DetecorConstruction::ReadDetextorConfiguration Method
-        void ReadConfiguration(NPL::InputParser) ;
-
-        // Construct detector and inialise sensitive part.
-        // Called After DetecorConstruction::AddDetector Method
-        void ConstructDetector(G4LogicalVolume* world) ;
-
-        // Add Detector branch to the EventTree.
-        // Called After DetecorConstruction::AddDetector Method
-        void InitializeRootOutput() ;
-
-        // Read sensitive part and fill the Root tree.
-        // Called at in the EventAction::EndOfEventAvtion
-        void ReadSensitive(const G4Event* event) ;
-
-    public: 
-        // Scorer
-        // Initialize all Scorer used by Vamos
-        void InitializeScorers() ;
-
-        // Associated Scorer
-        G4MultiFunctionalDetector* m_CalorimeterScorer ;
-        G4MultiFunctionalDetector* m_DCScorer ;
-
-        ////////////////////////////////////////////////////
-        ///////////Event class to store Data////////////////
-        ////////////////////////////////////////////////////
-
-    private:
-        TVamosData* m_Event ;
-
-        ////////////////////////////////////////////////////
-        ///////////////Private intern Data//////////////////
-        ////////////////////////////////////////////////////
-
-    private: 
-
-        // Geometry
-
-        G4double R_Catcher        = 0;
-        G4double CatcherWidth     = 0;
-        G4double CatcherLength    = 0;
-        G4double CatcherThickness = 0;
-        G4double       m_R        = 0; // distance Target- Entrance of the Mother Volume
-        G4double       m_Theta    = 0; 
-        // Detector Coordinate  
-
-        string CatcherMaterial;
-
-        G4ThreeVector m_PosCatcher; 
-        vector<G4double> m_Z ;
-        vector<string> m_Gas;
-        vector<G4double> m_Pressure;
-        vector<G4double> m_Temperature;
+  public: 
+    // Scorer
+    // Initialize all Scorer used by Vamos
+    void InitializeScorers() ;
 
-        vector<G4double> m_ZIC;
-        vector<G4double> m_ThicknessIC;
-        vector<G4double> m_PressureIC;
-        vector<G4double> m_TemperatureIC;
-        vector<string> m_GasIC;
+    // Associated Scorer
+    G4MultiFunctionalDetector* m_CalorimeterScorer ;
+    G4MultiFunctionalDetector* m_DCScorer ;
+    G4MultiFunctionalDetector* m_TMW1Scorer ;
 
-        //   Shape type
+    ////////////////////////////////////////////////////
+    ///////////Event class to store Data////////////////
+    ////////////////////////////////////////////////////
+
+  private:
+    TVamosData* m_Event ;
 
-        // Visualisation Attribute
-        G4VisAttributes* m_VisQuad;
-        G4VisAttributes* m_VisDC;
-        G4VisAttributes* m_VisVolumeVamos;
-        G4VisAttributes* m_VisCatcher;
-        G4VisAttributes* m_VisGasC4H10;
-        G4VisAttributes* m_VisGasCF4;
+    ////////////////////////////////////////////////////
+    ///////////////Private intern Data//////////////////
+    ////////////////////////////////////////////////////
 
-    public:
-        static NPS::VDetector* Construct();
+  private: 
+
+    // Geometry
+
+    G4double R_Catcher        = 0;
+    G4double CatcherWidth     = 0;
+    G4double CatcherLength    = 0;
+    G4double CatcherThickness = 0;
+    G4double       m_R        = 0; // distance Target- Entrance of the Mother Volume
+    G4double       m_Theta    = 0; 
+    // Detector Coordinate  
+
+    string CatcherMaterial;
+
+    G4ThreeVector m_PosCatcher; 
+    vector<G4double> m_Z ;
+    vector<string> m_Gas;
+    vector<G4double> m_Pressure;
+    vector<G4double> m_Temperature;
+
+    vector<G4double> m_ZIC;
+    vector<G4double> m_ThicknessIC;
+    vector<G4double> m_PressureIC;
+    vector<G4double> m_TemperatureIC;
+    vector<string> m_GasIC;
+
+    // TMW1-2
+    double m_Z_TMW1;
+    double m_Z_TMW2;
+    string m_Gas_TMW1;
+    string m_Gas_TMW2;
+    double m_Pressure_TMW1;
+    double m_Pressure_TMW2;
+
+    //   Shape type
+
+    // Visualisation Attribute
+    G4VisAttributes* m_VisQuad;
+    G4VisAttributes* m_VisDC;
+    G4VisAttributes* m_VisVolumeVamos;
+    G4VisAttributes* m_VisCatcher;
+    G4VisAttributes* m_VisGasC4H10;
+    G4VisAttributes* m_VisGasCF4;
+
+  public:
+    static NPS::VDetector* Construct();
 };
 
 #endif
diff --git a/NPSimulation/EventGenerator/EventGeneratorGEFReader.cc b/NPSimulation/EventGenerator/EventGeneratorGEFReader.cc
index 8b72743c198db8020b7662e2fbe338a450423d91..c4e64349249c92cc71176129623eaa79360ce272 100644
--- a/NPSimulation/EventGenerator/EventGeneratorGEFReader.cc
+++ b/NPSimulation/EventGenerator/EventGeneratorGEFReader.cc
@@ -160,7 +160,7 @@ void EventGeneratorGEFReader::ReadConfiguration(NPL::InputParser parser){
       {
         it->m_FissioningSystemName=blocks[i]->GetString("FissioningSystem");
         m_FissioningSystem=new NPL::Particle(it->m_FissioningSystemName);
-      	m_FissioningSystem->SetKineticEnergy(0,0,0);
+        m_FissioningSystem->SetKineticEnergy(0,0,0);
       }
       if(blocks[i]->HasToken("SigmaX"))
         it->m_SigmaX=blocks[i]->GetDouble("SigmaX","mm");
@@ -198,8 +198,10 @@ void EventGeneratorGEFReader::GetBoostFromTwoBodyReaction(double Ex){
   m_TwoBodyReaction->KineRelativistic(Theta3,E3,Theta4,E4);
 
   double Phi4 = RandFlat::shoot() * 2 * pi;
+  double Phi3 = Phi4 - pi;
   m_FissioningSystem->SetKineticEnergy(E4,Theta4,Phi4);
 
+  m_TwoBodyReaction->SetParticle3(E3,Theta3,Phi3);
 }
 
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -229,6 +231,7 @@ void EventGeneratorGEFReader::GenerateEvent(G4Event*){
     NPL::Particle *Proton=new NPL::Particle("1H");
     NPL::Particle *Gamma=new NPL::Particle("gamma");
     NPL::Particle *Fragment;
+    NPL::Particle *Ejectile;
     TVector3 FissioningSystemBoost;
     int it=0;
 
@@ -264,12 +267,13 @@ void EventGeneratorGEFReader::GenerateEvent(G4Event*){
           double Ex  = DataLine.at(25); // Excitation energy at fission
           if(m_isTwoBody){
             GetBoostFromTwoBodyReaction(Ex);
+            Ejectile = m_TwoBodyReaction->GetParticle3();
           }
           FissioningSystemBoost = m_FissioningSystem->GetEnergyImpulsion().BoostVector();
-          
+
           int Z_CN = DataLine.at(1);
           int A_CN = DataLine.at(2);
-        
+
           m_FissionConditions->SetZ_CN(Z_CN);
           m_FissionConditions->SetA_CN(A_CN);
           m_FissionConditions->SetEx_CN(Ex);
@@ -371,29 +375,29 @@ void EventGeneratorGEFReader::GenerateEvent(G4Event*){
         else if(DataLine.size()>0 && DataLine.at(0)==0
             && (AllowedParticles.size()==0 || std::find(AllowedParticles.begin(), AllowedParticles.end(), "neutron") != AllowedParticles.end()))
           for(int it=0;it<(DataLine.size()-1)/3;it++)
-	  {// Promt fission neutron treatment
+          {// Promt fission neutron treatment
 
-          	double ELabn      = DataLine.at(1+3*it);
-          	double cos_thetan = DataLine.at(2+3*it);
-          	double Phin       = DataLine.at(3+3*it) *M_PI/180.;
+            double ELabn      = DataLine.at(1+3*it);
+            double cos_thetan = DataLine.at(2+3*it);
+            double Phin       = DataLine.at(3+3*it) *M_PI/180.;
 
-          	TVector3 NeutronLabAngle(0,0,1.);
-          	NeutronLabAngle.SetMagThetaPhi(1.,acos(cos_thetan),Phin);
-          	NeutronLabAngle.RotateUz(LightFragmentDirection);
-          	Neutron->SetKineticEnergy(ELabn,NeutronLabAngle.Theta(),NeutronLabAngle.Phi());
+            TVector3 NeutronLabAngle(0,0,1.);
+            NeutronLabAngle.SetMagThetaPhi(1.,acos(cos_thetan),Phin);
+            NeutronLabAngle.RotateUz(LightFragmentDirection);
+            Neutron->SetKineticEnergy(ELabn,NeutronLabAngle.Theta(),NeutronLabAngle.Phi());
 
-          	TLorentzVector ImpulsionNeutron = Neutron->GetEnergyImpulsion();
-          	ImpulsionNeutron.Boost(FissioningSystemBoost);
-          	ELabn      = ImpulsionNeutron.E()-Neutron->Mass();
-          	cos_thetan = ImpulsionNeutron.CosTheta();
-          	Phin       = NeutronLabAngle.Phi();
+            TLorentzVector ImpulsionNeutron = Neutron->GetEnergyImpulsion();
+            ImpulsionNeutron.Boost(FissioningSystemBoost);
+            ELabn      = ImpulsionNeutron.E()-Neutron->Mass();
+            cos_thetan = ImpulsionNeutron.CosTheta();
+            Phin       = NeutronLabAngle.Phi();
 
-          	ELab       .push_back(ELabn);
-          	CosThetaLab.push_back(cos_thetan);
-          	PhiLab     .push_back(Phin);
-          	vParticle  .push_back(G4ParticleTable::GetParticleTable()->FindParticle("neutron"));
+            ELab       .push_back(ELabn);
+            CosThetaLab.push_back(cos_thetan);
+            PhiLab     .push_back(Phin);
+            vParticle  .push_back(G4ParticleTable::GetParticleTable()->FindParticle("neutron"));
 
-          	fileParticleMultiplicity++;
+            fileParticleMultiplicity++;
 
           }
 
@@ -476,6 +480,19 @@ void EventGeneratorGEFReader::GenerateEvent(G4Event*){
         NPS::Particle particle(GeneratedParticle, theta,particle_energy,G4ThreeVector(Momentum.x(), Momentum.y(), Momentum.z()),G4ThreeVector(x0, y0, z0));
         m_ParticleStack->AddParticleToStack(particle);
       }
+    
+    if(m_isTwoBody){
+      G4double theta                          = Ejectile->GetImpulsion().Theta();
+      G4double phi                            = Ejectile->GetImpulsion().Phi();
+      G4double particle_energy                = Ejectile->GetEnergy();
+      G4ParticleDefinition* GeneratedParticle = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIon(Ejectile->GetZ(),Ejectile->GetA(),0.);
+
+      Momentum = ShootParticle(theta,phi,par.m_direction);
+      //cout << "particle_energy=" << particle_energy << endl;
+      NPS::Particle particle(GeneratedParticle, theta,particle_energy,G4ThreeVector(Momentum.x(), Momentum.y(), Momentum.z()),G4ThreeVector(x0, y0, z0));
+      m_ParticleStack->AddParticleToStack(particle);
+
+    }
   }
 }
 
diff --git a/Projects/AlPhaPha/2024/Analysis.cxx b/Projects/AlPhaPha/2024/Analysis.cxx
index 05e7c4642647ced08b06801e21f162ee7b7d91b0..8e25260c22852da47032736e0de72b7adadde15c 100644
--- a/Projects/AlPhaPha/2024/Analysis.cxx
+++ b/Projects/AlPhaPha/2024/Analysis.cxx
@@ -1,4 +1,4 @@
-/*****************************************************************************
+/****************************************************************************
  * Copyright (C) 2009-2016    this file is part of the NPTool Project        *
  *                                                                           *
  * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
@@ -406,415 +406,473 @@ void Analysis::TwoAlphaAnalysis(){
 
 /////////////////////////////////////////////////////////////////////////////////
 void Analysis::VamosAnalysis(){
-  if(abs(FPMW->XtLin)<5 && abs(FPMW->YtLin)<5){
-    //XTarget = FPMW->Xt*cos(20*deg+FPMW->Theta_in)/cos(FPMW->Theta_in);
-    XTarget = FPMW->Xt*(cos(FPMW->Theta_in)/cos(20*deg+FPMW->Theta_in));
-    YTarget = FPMW->Yt;
-
-    XTargetLin = FPMW->XtLin*(cos(FPMW->Theta_in_Lin)/cos(20*deg+FPMW->Theta_in_Lin));
-    YTargetLin = FPMW->YtLin;
-    ZTarget = 0;
+    if(abs(FPMW->XtLin)<5 && abs(FPMW->YtLin)<5){
+        //XTarget = FPMW->Xt*cos(20*deg+FPMW->Theta_in)/cos(FPMW->Theta_in);
+        XTarget = FPMW->Xt*(cos(FPMW->Theta_in)/cos(20*deg+FPMW->Theta_in));
+        YTarget = FPMW->Yt;
+
+        XTargetLin = FPMW->XtLin*(cos(FPMW->Theta_in_Lin)/cos(20*deg+FPMW->Theta_in_Lin));
+        YTargetLin = FPMW->YtLin;
+        ZTarget = 0;
+
+        FF_Theta = FPMW->Theta_in+m_Vamos_Angle*deg;
+        FF_Phi = FPMW->Phi_in;
+
+        Xmean_iter += XTarget;
+        Ymean_iter += YTarget;
+        Xmean_iterLin += XTargetLin;
+        Ymean_iterLin += YTargetLin;
+
+        iteration++;
+        if(iteration%100==0){
+            Xmean = Xmean_iter/iteration;
+            Ymean = Ymean_iter/iteration;
+
+            XmeanLin = Xmean_iterLin/iteration;
+            YmeanLin = Ymean_iterLin/iteration;
+
+            iteration = 0;
+            Xmean_iter = 0;
+            Ymean_iter = 0;
+
+
+            Xmean_iterLin = 0;
+            Ymean_iterLin = 0;
+        }
+    } //If some linearisation is done 
+    else{
+        XTargetLin = XmeanLin;
+        YTargetLin = YmeanLin;
+        XTarget = Xmean;
+        YTarget = Ymean;
+        ZTarget = 0;
+    }
 
-    FF_Theta = FPMW->Theta_in+m_Vamos_Angle*deg;
-    FF_Phi = FPMW->Phi_in;
+    XTarget += m_XTarget_offset;
+    YTarget += m_YTarget_offset;
+    ZTarget += m_ZTarget_offset;
 
-    Xmean_iter += XTarget;
-    Ymean_iter += YTarget;
-    Xmean_iterLin += XTargetLin;
-    Ymean_iterLin += YTargetLin;
+    XTargetLin += m_XTarget_offset;
+    YTargetLin += m_YTarget_offset +0.2;
 
-    iteration++;
-    if(iteration%100==0){
-      Xmean = Xmean_iter/iteration;
-      Ymean = Ymean_iter/iteration;
+    //cout << XTarget << endl;
 
-      XmeanLin = Xmean_iterLin/iteration;
-      YmeanLin = Ymean_iterLin/iteration;
 
-      iteration = 0;
-      Xmean_iter = 0;
-      Ymean_iter = 0;
+    PositionOnTarget = TVector3(XTarget,YTarget,ZTarget);
+    PositionOnTargetLin = TVector3(XTargetLin,YTargetLin,ZTarget);
 
+    if( MTOF_FP0_T0VM == 1 && MTOF_FP0_T1VM ==1 ){
 
-      Xmean_iterLin = 0;
-      Ymean_iterLin = 0;
-    }
-  } //If some linearisation is done 
-  else{
-    XTargetLin = XmeanLin;
-    YTargetLin = YmeanLin;
-    XTarget = Xmean;
-    YTarget = Ymean;
-    ZTarget = 0;
-  }
 
-  XTarget += m_XTarget_offset;
-  YTarget += m_YTarget_offset;
-  ZTarget += m_ZTarget_offset;
+        UShort_t FPMWPat = MTOF_FP0_T0VN[0]; //20 section
+        FPMW_Section = FPMWPat;
+        IC->SetFPMWSection(FPMW_Section);
+        IC->BuildSimplePhysicalEvent();
+        double Theta = -1000;
 
-  XTargetLin += m_XTarget_offset;
-  YTargetLin += m_YTarget_offset +0.2;
 
-  //cout << XTarget << endl;
+        if(FPMW->Xf!=-1000){
 
+            FF_DE   = IC->DE;
+            FF_Eres = IC->Eres;
 
-  PositionOnTarget = TVector3(XTarget,YTarget,ZTarget);
-  PositionOnTargetLin = TVector3(XTargetLin,YTargetLin,ZTarget);
+            Tracking->CalculateReconstruction(FPMW->Xf, 1000*FPMW->Thetaf, m_Brho_ref, FF_Brho, Theta, FF_Path);
+            // FF_Path is in cm !
+            //
+            FF_Y1  = FPMW->PositionY[0];
+            FF_Y3  = FPMW->PositionY[2];
 
-  if( MTOF_FP0_T0VM == 1 ){
+            //FF_IC_Y = FPMW->Yf + (1442.6+6774.4-7600)*tan(FPMW->Phif/1000);
+            FF_IC_Y = FPMW->Yf + (1442.6+6774.4-7600)*tan(FPMW->Phif/1000);
+            FF_IC_X = FPMW->Xf + (1442.6+6774.4-7600)*tan(FPMW->Thetaf/1000);
 
+            // T13 //
+            double path1 = FPMW->GetDetectorPositionZ(0)/10./cos(FPMW->Theta_in)/cos(FPMW->Phi_in);
+            double path2 = (FPMW->GetDetectorPositionZ(2)-7600)/10./cos(FPMW->Thetaf);
 
-    UShort_t FPMWPat = MTOF_FP0_T0VN[0];
-    FPMW_Section = FPMWPat;
-    IC->SetFPMWSection(FPMW_Section);
-    IC->BuildSimplePhysicalEvent();
-    double Theta = -1000;
-    if(FPMW->Xf!=-1000){
+            //Toff
+            vector<double> Toff13 , Toff14, Toff23, Toff24;
+            const char* Path13 = "macro/mwpc/Toff/output/Toff13.txt";
+            const char* Path14 = "macro/mwpc/Toff/output/Toff14.txt";
+            const char* Path23 = "macro/mwpc/Toff/output/Toff23.txt";
+            const char* Path24 = "macro/mwpc/Toff/output/Toff24.txt";
 
-      FF_DE   = IC->DE;
-      FF_Eres = IC->Eres;
+            Toff13 = TxtToVector(Path13);
+            Toff14 = TxtToVector(Path14);
+            Toff23 = TxtToVector(Path23);
+            Toff24 = TxtToVector(Path24);
 
-      Tracking->CalculateReconstruction(FPMW->Xf, 1000*FPMW->Thetaf, m_Brho_ref, FF_Brho, Theta, FF_Path);
-      // FF_Path is in cm ! 
+            double Toff[20] = {0, 588.0, 588.5, 587.95, 588.04, 587.72, 587.92, 587.9, 587.9, 588.66, 588.80, 588.67, 588.64, 588.75, 588.47, 588.65, 588.65, 588.67, 589.05, 590.3};
+            // To know time of electron drift in a section of the chio
+            for (int seg = 0 ; seg < IC->fIC_TS.size() ; seg++){
+                    FF_DriftTime.push_back(10* (IC->fIC_TS.at(seg) - Time->GetTS_MWPC13(0)) - ((Time->GetTime_MWPC13(0)+Toff13.at(FPMW_Section))));
+            }
 
-      FF_Y1  = FPMW->PositionY[0];
-      FF_Y3  = FPMW->PositionY[2];
 
-      FF_IC_Y = FPMW->Yf + (1442.6+6774.4-7600)*tan(FPMW->Phif/1000);
-      FF_IC_X = FPMW->Xf + (1442.6+6774.4-7600)*tan(FPMW->Thetaf/1000);
 
-      // T13 //
-      double path1 = FPMW->GetDetectorPositionZ(0)/10./cos(FPMW->Theta_in)/cos(FPMW->Phi_in);
-      double path2 = (FPMW->GetDetectorPositionZ(2)-7600)/10./cos(FPMW->Thetaf);
-      
-      //Online
+            FF_T13 = - MTOF_FP0_T0V[0] + Toff[FPMWPat];
+            //FF_T13 = -Time->GetTime_MWPC13(0) - Toff13[FPMW_Section-1] + 589;
+            FF_D13 = FF_Path - path1 + path2; 
+            FF_V13 = FF_D13/FF_T13;
+            FF_Beta13 = FF_V13/29.9792458;
+            FF_Gamma13 = 1./sqrt(1.0-FF_Beta13*FF_Beta13);
 
-      double Toff[20] = {0, 588.0, 588.5, 587.95, 588.04, 587.72, 587.92, 587.9, 587.9, 588.66, 588.80, 588.67, 588.64, 588.75, 588.47, 588.65, 588.65, 588.67, 589.05, 590.3};
 
+            FF_AoQ13 = (FF_Brho/(3.107*FF_Beta13*FF_Gamma13));
+            FF_M13 = IC->EtotInit/(931.5016*(FF_Gamma13-1.));
+            FF_Q13 = FF_M13/FF_AoQ13;
 
-      FF_T13 = - MTOF_FP0_T0V[0] + Toff[FPMWPat];
-      FF_D13 = FF_Path - path1 + path2; 
-      FF_V13 = FF_D13/FF_T13;
-      FF_Beta13 = FF_V13/29.9792458;
-      FF_Gamma13 = 1./sqrt(1.0-FF_Beta13*FF_Beta13);
-      
+            FF_Mass13 = int(FF_Q13+0.5)*FF_AoQ13;
 
-      FF_AoQ13 = (FF_Brho/(3.107*FF_Beta13*FF_Gamma13));
-      FF_M13 = IC->EtotInit/(931.5016*(FF_Gamma13-1.));
-      FF_Q13 = FF_M13/FF_AoQ13;
+            //FF_DriftTime[FPMW_Section] = 10*(fVAMOS_TS_sec[FPMW_Section]- MT)
+        }
+    }
+    else{
+        FPMW_Section = -1;
+    }
 
-      FF_Mass13 = int(FF_Q13+0.5)*FF_AoQ13;
+}
 
+vector<double> Analysis::TxtToVector(const char *Path){
+    string line;
+    vector<double> values;
+    ifstream file(Path); 
+
+    if (file.is_open()) {
+        while (std::getline(file, line)) {
+            try {
+                values.push_back(std::stod(line));
+            } catch (const std::invalid_argument& e) {
+                std::cerr << "Invalid number in line: " << line << '\n';
+            }
+        }
+        file.close();
+    } else {
+        std::cerr << "Error opening file.\n";
     }
-  }
-  else{
-    FPMW_Section = -1;
-  }
-}
 
+    return values;
+}
 
 ////////////////////////////////////////////////////////////////////////////////
 void Analysis::InitOutputBranch(){
-  RootOutput::getInstance()->GetTree()->Branch("BeamEnergy",&BeamEnergy,"BeamEnergy/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("XTarget",&XTarget,"XTarget/D");
-  RootOutput::getInstance()->GetTree()->Branch("XTargetLin",&XTargetLin,"XTargetLin/D");
-  RootOutput::getInstance()->GetTree()->Branch("YTarget",&YTarget,"YTarget/D");
-  RootOutput::getInstance()->GetTree()->Branch("YTargetLin",&YTargetLin,"YTargetLin/D");
-  RootOutput::getInstance()->GetTree()->Branch("ZTarget",&ZTarget,"ZTarget/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("Ex242Pu",&Ex242Pu,"Ex242Pu/D");
-  RootOutput::getInstance()->GetTree()->Branch("Ex240Pu",&Ex240Pu,"Ex240Pu/D");
-  RootOutput::getInstance()->GetTree()->Branch("Ex240PuLin",&Ex240PuLin,"Ex240PuLin/D");
-  RootOutput::getInstance()->GetTree()->Branch("Ex236U",&Ex236U,"Ex236U/D");
-  RootOutput::getInstance()->GetTree()->Branch("Ex238U",&Ex238U,"Ex238U/D");
-  
-  RootOutput::getInstance()->GetTree()->Branch("DeltaE",&DeltaE,"DeltaE/D");
-  RootOutput::getInstance()->GetTree()->Branch("DeltaEcorr",&DeltaEcorr,"DeltaEcorr/D");
-  RootOutput::getInstance()->GetTree()->Branch("Eres",&Eres,"Eres/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("Telescope",&Telescope,"Telescope/I");
-  RootOutput::getInstance()->GetTree()->Branch("PID",&PID,"PID/D");
-  
-  RootOutput::getInstance()->GetTree()->Branch("Elab",&Elab,"Elab/D");
-  RootOutput::getInstance()->GetTree()->Branch("ThetaLab",&ThetaLab,"ThetaLab/D");
-  
-  RootOutput::getInstance()->GetTree()->Branch("Beta_pista",&Beta_pista,"Beta_pista/D");
-  RootOutput::getInstance()->GetTree()->Branch("ThetaLabLin",&ThetaLabLin,"ThetaLabLin/D");
-  RootOutput::getInstance()->GetTree()->Branch("ThetaDetectorSurface",&ThetaDetectorSurface,"ThetaDetectorSurface/D");
-  RootOutput::getInstance()->GetTree()->Branch("PhiLab",&PhiLab,"PhiLab/D");
-  RootOutput::getInstance()->GetTree()->Branch("ThetaCM",&ThetaCM,"ThetaCM/D");
-  
-  RootOutput::getInstance()->GetTree()->Branch("Xcalc",&Xcalc,"Xcalc/D");
-  RootOutput::getInstance()->GetTree()->Branch("Ycalc",&Ycalc,"Ycalc/D");
-  RootOutput::getInstance()->GetTree()->Branch("Zcalc",&Zcalc,"Zcalc/D");
-  
-  RootOutput::getInstance()->GetTree()->Branch("strip_DE",&strip_DE,"strip_DE/I");
-  RootOutput::getInstance()->GetTree()->Branch("strip_E",&strip_E,"strip_E/I");
-  RootOutput::getInstance()->GetTree()->Branch("Time_E",&Time_E,"Time_E/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("Pista_Time_Target",&Pista_Time_Target,"Pista_Time_Target/D");
-  RootOutput::getInstance()->GetTree()->Branch("Vamos_Time_Target",&Vamos_Time_Target,"Vamos_Time_Target/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("FF_DE",&FF_DE,"FF_DE/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Eres",&FF_Eres,"FF_Eres/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Z",&FF_Z,"FF_Z/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Theta",&FF_Theta,"FF_Theta/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Phi",&FF_Phi,"FF_Phi/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Brho",&FF_Brho,"FF_Brho/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Path",&FF_Path,"FF_Path/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("FF_Y1",&FF_Y1,"FF_Y1/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Y3",&FF_Y3,"FF_Y3/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_IC_Y",&FF_IC_Y,"FF_IC_Y/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_IC_X",&FF_IC_X,"FF_IC_X/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_D13",&FF_D13,"FF_D13/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_T13",&FF_T13,"FF_T13/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_V13",&FF_V13,"FF_V13/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_AoQ13",&FF_AoQ13,"FF_AoQ13/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Beta13",&FF_Beta13,"FF_Beta13/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Gamma13",&FF_Gamma13,"FF_Gamma13/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Q13",&FF_Q13,"FF_Q13/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_M13",&FF_M13,"FF_M13/D");
-  RootOutput::getInstance()->GetTree()->Branch("FF_Mass13",&FF_Mass13,"FF_Mass13/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("FPMW_Section",&FPMW_Section,"FPMW_Section/I");
-
-  RootOutput::getInstance()->GetTree()->Branch("theta_lab_fission",&theta_lab_fission,"theta_lab_fission/D");
-  RootOutput::getInstance()->GetTree()->Branch("theta_cm_fission",&theta_cm_fission,"theta_cm_fission/D");
-  RootOutput::getInstance()->GetTree()->Branch("theta_240Pu",&theta_240Pu,"theta_240Pu/D");
-  RootOutput::getInstance()->GetTree()->Branch("phi_240Pu",&phi_240Pu,"phi_240Pu/D");
-  RootOutput::getInstance()->GetTree()->Branch("beta_240Pu",&beta_240Pu,"beta_240Pu/D");
-  RootOutput::getInstance()->GetTree()->Branch("gamma_240Pu",&gamma_240Pu,"gamma_240Pu/D");
-  RootOutput::getInstance()->GetTree()->Branch("gamma_lab_ff",&gamma_lab_ff,"gamma_lab_ff/D");
-  RootOutput::getInstance()->GetTree()->Branch("gamma_cm_ff",&gamma_cm_ff,"gamma_cm_ff/D");
-  RootOutput::getInstance()->GetTree()->Branch("beta_lab_ff",&beta_lab_ff,"beta_lab_ff/D");
-  RootOutput::getInstance()->GetTree()->Branch("beta_cm_ff",&beta_cm_ff,"beta_cm_ff/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("Elab1",&Elab1);
-  RootOutput::getInstance()->GetTree()->Branch("Elab2",&Elab2);
-  RootOutput::getInstance()->GetTree()->Branch("m_2alpha",&m_2alpha,"m_2alpha/I");
-
-  RootOutput::getInstance()->GetTree()->Branch("Exo_cosa",&Exo_cosa,"Exo_cosa/D");
-  RootOutput::getInstance()->GetTree()->Branch("Exo_E",&Exo_E,"Exo_E/D");
-  RootOutput::getInstance()->GetTree()->Branch("Exo_EDC_vamos",&Exo_EDC_vamos,"Exo_EDC_vamos/D");
-  RootOutput::getInstance()->GetTree()->Branch("Exo_EDC_pista",&Exo_EDC_pista,"Exo_EDC_pista/D");
-  RootOutput::getInstance()->GetTree()->Branch("Exo_Theta",&Exo_Theta,"Exo_Theta/D");
-  RootOutput::getInstance()->GetTree()->Branch("Exo_Phi",&Exo_Phi,"Exo_Phi/D");
-
-  RootOutput::getInstance()->GetTree()->Branch("VAMOS_TS_hour",&VAMOS_TS_hour,"VAMOS_TS_hour/D");
-  RootOutput::getInstance()->GetTree()->Branch("PISTA_TS_hour",&PISTA_TS_hour,"PISTA_TS_hour/D");
+    RootOutput::getInstance()->GetTree()->Branch("Time",&Time);
+
+    RootOutput::getInstance()->GetTree()->Branch("BeamEnergy",&BeamEnergy,"BeamEnergy/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("XTarget",&XTarget,"XTarget/D");
+    RootOutput::getInstance()->GetTree()->Branch("XTargetLin",&XTargetLin,"XTargetLin/D");
+    RootOutput::getInstance()->GetTree()->Branch("YTarget",&YTarget,"YTarget/D");
+    RootOutput::getInstance()->GetTree()->Branch("YTargetLin",&YTargetLin,"YTargetLin/D");
+    RootOutput::getInstance()->GetTree()->Branch("ZTarget",&ZTarget,"ZTarget/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("Ex242Pu",&Ex242Pu,"Ex242Pu/D");
+    RootOutput::getInstance()->GetTree()->Branch("Ex240Pu",&Ex240Pu,"Ex240Pu/D");
+    RootOutput::getInstance()->GetTree()->Branch("Ex240PuLin",&Ex240PuLin,"Ex240PuLin/D");
+    RootOutput::getInstance()->GetTree()->Branch("Ex236U",&Ex236U,"Ex236U/D");
+    RootOutput::getInstance()->GetTree()->Branch("Ex238U",&Ex238U,"Ex238U/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("DeltaE",&DeltaE,"DeltaE/D");
+    RootOutput::getInstance()->GetTree()->Branch("DeltaEcorr",&DeltaEcorr,"DeltaEcorr/D");
+    RootOutput::getInstance()->GetTree()->Branch("Eres",&Eres,"Eres/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("Telescope",&Telescope,"Telescope/I");
+    RootOutput::getInstance()->GetTree()->Branch("PID",&PID,"PID/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("Elab",&Elab,"Elab/D");
+    RootOutput::getInstance()->GetTree()->Branch("ThetaLab",&ThetaLab,"ThetaLab/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("Beta_pista",&Beta_pista,"Beta_pista/D");
+    RootOutput::getInstance()->GetTree()->Branch("ThetaLabLin",&ThetaLabLin,"ThetaLabLin/D");
+    RootOutput::getInstance()->GetTree()->Branch("ThetaDetectorSurface",&ThetaDetectorSurface,"ThetaDetectorSurface/D");
+    RootOutput::getInstance()->GetTree()->Branch("PhiLab",&PhiLab,"PhiLab/D");
+    RootOutput::getInstance()->GetTree()->Branch("ThetaCM",&ThetaCM,"ThetaCM/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("Xcalc",&Xcalc,"Xcalc/D");
+    RootOutput::getInstance()->GetTree()->Branch("Ycalc",&Ycalc,"Ycalc/D");
+    RootOutput::getInstance()->GetTree()->Branch("Zcalc",&Zcalc,"Zcalc/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("strip_DE",&strip_DE,"strip_DE/I");
+    RootOutput::getInstance()->GetTree()->Branch("strip_E",&strip_E,"strip_E/I");
+    RootOutput::getInstance()->GetTree()->Branch("Time_E",&Time_E,"Time_E/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("Pista_Time_Target",&Pista_Time_Target,"Pista_Time_Target/D");
+    RootOutput::getInstance()->GetTree()->Branch("Vamos_Time_Target",&Vamos_Time_Target,"Vamos_Time_Target/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("FF_DE",&FF_DE,"FF_DE/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Eres",&FF_Eres,"FF_Eres/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Z",&FF_Z,"FF_Z/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Theta",&FF_Theta,"FF_Theta/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Phi",&FF_Phi,"FF_Phi/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Brho",&FF_Brho,"FF_Brho/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Path",&FF_Path,"FF_Path/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("FF_DriftTime",&FF_DriftTime);
+    RootOutput::getInstance()->GetTree()->Branch("FF_Y1",&FF_Y1,"FF_Y1/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Y3",&FF_Y3,"FF_Y3/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_IC_Y",&FF_IC_Y,"FF_IC_Y/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_IC_X",&FF_IC_X,"FF_IC_X/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_D13",&FF_D13,"FF_D13/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_T13",&FF_T13,"FF_T13/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_V13",&FF_V13,"FF_V13/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_AoQ13",&FF_AoQ13,"FF_AoQ13/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Beta13",&FF_Beta13,"FF_Beta13/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Gamma13",&FF_Gamma13,"FF_Gamma13/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Q13",&FF_Q13,"FF_Q13/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_M13",&FF_M13,"FF_M13/D");
+    RootOutput::getInstance()->GetTree()->Branch("FF_Mass13",&FF_Mass13,"FF_Mass13/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("FPMW_Section",&FPMW_Section,"FPMW_Section/I");
+    RootOutput::getInstance()->GetTree()->Branch("MTOF_FP0_T0VM",&MTOF_FP0_T0VM,"MTOF_FP0_T0VM/I");
+    RootOutput::getInstance()->GetTree()->Branch("MTOF_FP0_T1VM",&MTOF_FP0_T1VM,"MTOF_FP0_T1VM/I");
+    RootOutput::getInstance()->GetTree()->Branch("MTOF_FP1_T0VM",&MTOF_FP1_T0VM,"MTOF_FP1_T0VM/I");
+    RootOutput::getInstance()->GetTree()->Branch("MTOF_FP1_T1VM",&MTOF_FP1_T1VM,"MTOF_FP1_T1VM/I");
+
+    RootOutput::getInstance()->GetTree()->Branch("MTOF_FP0_T0VN",&MTOF_FP0_T0VN,"MTOF_FP0_T0VN/I");
+    RootOutput::getInstance()->GetTree()->Branch("MTOF_FP0_T1VN",&MTOF_FP0_T1VN,"MTOF_FP0_T1VN/I");
+    RootOutput::getInstance()->GetTree()->Branch("MTOF_FP1_T0VN",&MTOF_FP1_T0VN,"MTOF_FP1_T0VN/I");
+    RootOutput::getInstance()->GetTree()->Branch("MTOF_FP1_T1VN",&MTOF_FP1_T1VN,"MTOF_FP1_T1VN/I");
+
+    RootOutput::getInstance()->GetTree()->Branch("theta_lab_fission",&theta_lab_fission,"theta_lab_fission/D");
+    RootOutput::getInstance()->GetTree()->Branch("theta_cm_fission",&theta_cm_fission,"theta_cm_fission/D");
+    RootOutput::getInstance()->GetTree()->Branch("theta_240Pu",&theta_240Pu,"theta_240Pu/D");
+    RootOutput::getInstance()->GetTree()->Branch("phi_240Pu",&phi_240Pu,"phi_240Pu/D");
+    RootOutput::getInstance()->GetTree()->Branch("beta_240Pu",&beta_240Pu,"beta_240Pu/D");
+    RootOutput::getInstance()->GetTree()->Branch("gamma_240Pu",&gamma_240Pu,"gamma_240Pu/D");
+    RootOutput::getInstance()->GetTree()->Branch("gamma_lab_ff",&gamma_lab_ff,"gamma_lab_ff/D");
+    RootOutput::getInstance()->GetTree()->Branch("gamma_cm_ff",&gamma_cm_ff,"gamma_cm_ff/D");
+    RootOutput::getInstance()->GetTree()->Branch("beta_lab_ff",&beta_lab_ff,"beta_lab_ff/D");
+    RootOutput::getInstance()->GetTree()->Branch("beta_cm_ff",&beta_cm_ff,"beta_cm_ff/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("Elab1",&Elab1);
+    RootOutput::getInstance()->GetTree()->Branch("Elab2",&Elab2);
+    RootOutput::getInstance()->GetTree()->Branch("m_2alpha",&m_2alpha,"m_2alpha/I");
+
+    RootOutput::getInstance()->GetTree()->Branch("Exo_cosa",&Exo_cosa,"Exo_cosa/D");
+    RootOutput::getInstance()->GetTree()->Branch("Exo_E",&Exo_E,"Exo_E/D");
+    RootOutput::getInstance()->GetTree()->Branch("Exo_EDC_vamos",&Exo_EDC_vamos,"Exo_EDC_vamos/D");
+    RootOutput::getInstance()->GetTree()->Branch("Exo_EDC_pista",&Exo_EDC_pista,"Exo_EDC_pista/D");
+    RootOutput::getInstance()->GetTree()->Branch("Exo_Theta",&Exo_Theta,"Exo_Theta/D");
+    RootOutput::getInstance()->GetTree()->Branch("Exo_Phi",&Exo_Phi,"Exo_Phi/D");
+
+    RootOutput::getInstance()->GetTree()->Branch("VAMOS_TS_hour",&VAMOS_TS_hour,"VAMOS_TS_hour/D");
+    RootOutput::getInstance()->GetTree()->Branch("PISTA_TS_hour",&PISTA_TS_hour,"PISTA_TS_hour/D");
+
 
 
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Analysis::InitInputBranch(){
-  RootInput::getInstance()->GetChain()->SetBranchStatus("T_TMW0_FPMW0",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("T_TMW0_FPMW0",&T13);
-
-  RootInput::getInstance()->GetChain()->SetBranchStatus("T_TMW0_FPMW1",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("T_TMW0_FPMW1",&T14);
-
-  RootInput::getInstance()->GetChain()->SetBranchStatus("T_TMW1_FPMW0",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("T_TMW1_FPMW0",&T23);
-
-  RootInput::getInstance()->GetChain()->SetBranchStatus("T_TMW1_FPMW1",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("T_TMW1_FPMW1",&T24);
-
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T0VN",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T0VN",&MTOF_FP0_T0VN);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T1VN",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T1VN",&MTOF_FP0_T1VN);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T0VN",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T0VN",&MTOF_FP1_T0VN);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T1VN",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T1VN",&MTOF_FP1_T1VN);
-
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T0V",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T0V",&MTOF_FP0_T0V);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T1V",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T1V",&MTOF_FP0_T1V);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T0V",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T0V",&MTOF_FP1_T0V);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T1V",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T1V",&MTOF_FP1_T1V);
-
-
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T0VM",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T0VM",&MTOF_FP0_T0VM);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T1VM",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T1VM",&MTOF_FP0_T1VM);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T0VM",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T0VM",&MTOF_FP1_T0VM);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T1VM",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T1VM",&MTOF_FP1_T1VM);
-
-  RootInput::getInstance()->GetChain()->SetBranchStatus("fVAMOS_TS_sec",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("fVAMOS_TS_sec",&fVAMOS_TS_sec);
-  RootInput::getInstance()->GetChain()->SetBranchStatus("fPISTA_TS_sec",true);
-  RootInput::getInstance()->GetChain()->SetBranchAddress("fPISTA_TS_sec",&fPISTA_TS_sec);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("Time",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("Time",&Time);
+
+    RootInput::getInstance()->GetChain()->SetBranchStatus("T_TMW0_FPMW0",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("T_TMW0_FPMW0",&T13);
+
+    RootInput::getInstance()->GetChain()->SetBranchStatus("T_TMW0_FPMW1",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("T_TMW0_FPMW1",&T14);
+
+    RootInput::getInstance()->GetChain()->SetBranchStatus("T_TMW1_FPMW0",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("T_TMW1_FPMW0",&T23);
+
+    RootInput::getInstance()->GetChain()->SetBranchStatus("T_TMW1_FPMW1",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("T_TMW1_FPMW1",&T24);
+
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T0VN",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T0VN",&MTOF_FP0_T0VN);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T1VN",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T1VN",&MTOF_FP0_T1VN);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T0VN",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T0VN",&MTOF_FP1_T0VN);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T1VN",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T1VN",&MTOF_FP1_T1VN);
+
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T0V",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T0V",&MTOF_FP0_T0V);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T1V",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T1V",&MTOF_FP0_T1V);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T0V",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T0V",&MTOF_FP1_T0V);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T1V",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T1V",&MTOF_FP1_T1V);
+
+
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T0VM",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T0VM",&MTOF_FP0_T0VM);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP0_T1VM",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP0_T1VM",&MTOF_FP0_T1VM);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T0VM",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T0VM",&MTOF_FP1_T0VM);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("MTOF_FP1_T1VM",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("MTOF_FP1_T1VM",&MTOF_FP1_T1VM);
+
+    RootInput::getInstance()->GetChain()->SetBranchStatus("fVAMOS_TS_sec",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("fVAMOS_TS_sec",&fVAMOS_TS_sec);
+    RootInput::getInstance()->GetChain()->SetBranchStatus("fPISTA_TS_sec",true);
+    RootInput::getInstance()->GetChain()->SetBranchAddress("fPISTA_TS_sec",&fPISTA_TS_sec);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Analysis::ReInitValue(){
-  BeamEnergy = -1000;
-  Ex242Pu = -1000;
-  Ex240Pu = -1000;
-  Ex240PuLin = -1000;
-  Ex236U = -1000;
-  Ex238U = -1000;
-  DeltaE = -1000;
-  DeltaEcorr = -1000;
-  Eres = -1000;
-  Elab = -1000;
-  ThetaLab = -1000;
-  Beta_pista = -1;
-  ThetaDetectorSurface = -1000;
-  PhiLab = -1000;
-  ThetaCM = -1000;
-  XTarget = -1000;
-  XTargetLin = -1000;
-  YTarget = -1000;
-  YTargetLin = -1000;
-  ZTarget = -1000;
-  Xcalc = -1000;
-  Ycalc = -1000;
-  Zcalc = -1000;
-  PID = -1000;
-  Telescope = -1;
-  strip_DE = -1;
-  strip_E = -1;
-  Time_E = -1000;
-  Pista_Time_Target = -1000;
-  Vamos_Time_Target = -1000;
-
-  Exo_cosa = -100;
-  Exo_E = -100;
-  Exo_EDC_vamos = -100;
-  Exo_EDC_pista = -100;
-  Exo_Theta = -100;
-  Exo_Phi = -100;
-
-  FF_Theta = -100;
-  FF_Phi = -100;
-  FF_Brho = -1;
-  FF_Path = -1;
-  FF_Y1 = -1000;
-  FF_Y3 = -1000;
-  FF_IC_X = -1000;
-  FF_IC_Y = -1000;
-  FF_D13 = -1;
-  FF_T13 = -1;
-  FF_V13 = -1;
-  FF_AoQ13 = -1;
-  FF_Beta13 = -1;
-  FF_Gamma13 = -1;
-  FF_Q13 = -1;
-  FF_M13 = -1;
-  FF_Mass13 = -1;
-  FPMW_Section = -1;
-
-  theta_lab_fission = -100;
-  theta_cm_fission = -100;
-  theta_240Pu = -100;
-  phi_240Pu = -100;
-  beta_240Pu = -100;
-  gamma_240Pu = -100;
-  gamma_lab_ff = -100;
-  gamma_cm_ff = -100;
-  beta_lab_ff = -100;
-  beta_cm_ff = -100;
-
-
-  m_2alpha = 0;
-  Elab1.clear();
-  Elab2.clear();
+    BeamEnergy = -1000;
+    Ex242Pu = -1000;
+    Ex240Pu = -1000;
+    Ex240PuLin = -1000;
+    Ex236U = -1000;
+    Ex238U = -1000;
+    DeltaE = -1000;
+    DeltaEcorr = -1000;
+    Eres = -1000;
+    Elab = -1000;
+    ThetaLab = -1000;
+    Beta_pista = -1;
+    ThetaDetectorSurface = -1000;
+    PhiLab = -1000;
+    ThetaCM = -1000;
+    XTarget = -1000;
+    XTargetLin = -1000;
+    YTarget = -1000;
+    YTargetLin = -1000;
+    ZTarget = -1000;
+    Xcalc = -1000;
+    Ycalc = -1000;
+    Zcalc = -1000;
+    PID = -1000;
+    Telescope = -1;
+    strip_DE = -1;
+    strip_E = -1;
+    Time_E = -1000;
+    Pista_Time_Target = -1000;
+    Vamos_Time_Target = -1000;
+
+    Exo_cosa = -100;
+    Exo_E = -100;
+    Exo_EDC_vamos = -100;
+    Exo_EDC_pista = -100;
+    Exo_Theta = -100;
+    Exo_Phi = -100;
+
+    FF_Theta = -100;
+    FF_Phi = -100;
+    FF_Brho = -1;
+    FF_Path = -1;
+    FF_Y1 = -1000;
+    FF_Y3 = -1000;
+    FF_IC_X = -1000;
+    FF_IC_Y = -1000;
+    FF_D13 = -1;
+    FF_T13 = -1;
+    FF_V13 = -1;
+    FF_AoQ13 = -1;
+    FF_Beta13 = -1;
+    FF_Gamma13 = -1;
+    FF_Q13 = -1;
+    FF_M13 = -1;
+    FF_Mass13 = -1;
+    FPMW_Section = -1;
+    FF_DriftTime.clear();
+
+    theta_lab_fission = -100;
+    theta_cm_fission = -100;
+    theta_240Pu = -100;
+    phi_240Pu = -100;
+    beta_240Pu = -100;
+    gamma_240Pu = -100;
+    gamma_lab_ff = -100;
+    gamma_cm_ff = -100;
+    beta_lab_ff = -100;
+    beta_cm_ff = -100;
+
+
+    m_2alpha = 0;
+    Elab1.clear();
+    Elab2.clear();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Analysis::ReadAnalysisConfig(){
-  bool ReadingStatus = false;
+    bool ReadingStatus = false;
 
-  string filename = "AnalysisConfig.dat";
+    string filename = "AnalysisConfig.dat";
 
-  // open analysis config file
-  ifstream AnalysisConfigFile;
-  AnalysisConfigFile.open(filename.c_str());
+    // open analysis config file
+    ifstream AnalysisConfigFile;
+    AnalysisConfigFile.open(filename.c_str());
 
-  if (!AnalysisConfigFile.is_open()) {
-    cout << " No AnalysisConfig.dat found: Default parameter loaded for Analayis " << filename << endl;
-    return;
-  }
-  cout << "**** Loading user parameter for Analysis from AnalysisConfig.dat " << endl;
-
-  // Save it in a TAsciiFile
-  TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
-  asciiConfig->AppendLine("%%% AnalysisConfig.dat %%%");
-  asciiConfig->Append(filename.c_str());
-  asciiConfig->AppendLine("");
-  // read analysis config file
-  string LineBuffer,DataBuffer,whatToDo;
-  while (!AnalysisConfigFile.eof()) {
-    // Pick-up next line
-    getline(AnalysisConfigFile, LineBuffer);
-
-    // search for "header"
-    string name = "AnalysisConfig";
-    if (LineBuffer.compare(0, name.length(), name) == 0) 
-      ReadingStatus = true;
-
-    // loop on tokens and data
-    while (ReadingStatus ) {
-      whatToDo="";
-      AnalysisConfigFile >> whatToDo;
-
-      // Search for comment symbol (%)
-      if (whatToDo.compare(0, 1, "%") == 0) {
-        AnalysisConfigFile.ignore(numeric_limits<streamsize>::max(), '\n' );
-      }
-
-      else if (whatToDo=="XTARGET_OFFSET") {
-        AnalysisConfigFile >> DataBuffer;
-        m_XTarget_offset = atof(DataBuffer.c_str());
-        cout << "**** " << whatToDo << " " << m_XTarget_offset << endl;
-      }
-      else if (whatToDo=="YTARGET_OFFSET") {
-        AnalysisConfigFile >> DataBuffer;
-        m_YTarget_offset = atof(DataBuffer.c_str());
-        cout << "**** " << whatToDo << " " << m_YTarget_offset << endl;
-      }
-      else if (whatToDo=="ZTARGET_OFFSET") {
-        AnalysisConfigFile >> DataBuffer;
-        m_ZTarget_offset = atof(DataBuffer.c_str());
-        cout << "**** " << whatToDo << " " << m_ZTarget_offset << endl;
-      }
-      else if (whatToDo=="BEAM_THETAX") {
-        AnalysisConfigFile >> DataBuffer;
-        m_Beam_ThetaX = atof(DataBuffer.c_str());
-        cout << "**** " << whatToDo << " " << m_Beam_ThetaX << endl;
-      }
-      else if (whatToDo=="BEAM_THETAY") {
-        AnalysisConfigFile >> DataBuffer;
-        m_Beam_ThetaY = atof(DataBuffer.c_str());
-        cout << "**** " << whatToDo << " " << m_Beam_ThetaY << endl;
-      }
-      else if (whatToDo=="BRHO_REF") {
-        AnalysisConfigFile >> DataBuffer;
-        m_Brho_ref = atof(DataBuffer.c_str());
-        cout << "**** " << whatToDo << " " << m_Brho_ref << endl;
-      }
-      else if (whatToDo=="VAMOS_ANGLE") {
-        AnalysisConfigFile >> DataBuffer;
-        m_Vamos_Angle = atof(DataBuffer.c_str());
-        cout << "**** " << whatToDo << " " << m_Vamos_Angle << endl;
-      }
-
-      else {
-        ReadingStatus = false;
-      }
+    if (!AnalysisConfigFile.is_open()) {
+        cout << " No AnalysisConfig.dat found: Default parameter loaded for Analayis " << filename << endl;
+        return;
+    }
+    cout << "**** Loading user parameter for Analysis from AnalysisConfig.dat " << endl;
+
+    // Save it in a TAsciiFile
+    TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
+    asciiConfig->AppendLine("%%% AnalysisConfig.dat %%%");
+    asciiConfig->Append(filename.c_str());
+    asciiConfig->AppendLine("");
+    // read analysis config file
+    string LineBuffer,DataBuffer,whatToDo;
+    while (!AnalysisConfigFile.eof()) {
+        // Pick-up next line
+        getline(AnalysisConfigFile, LineBuffer);
+
+        // search for "header"
+        string name = "AnalysisConfig";
+        if (LineBuffer.compare(0, name.length(), name) == 0) 
+            ReadingStatus = true;
+
+        // loop on tokens and data
+        while (ReadingStatus ) {
+            whatToDo="";
+            AnalysisConfigFile >> whatToDo;
+
+            // Search for comment symbol (%)
+            if (whatToDo.compare(0, 1, "%") == 0) {
+                AnalysisConfigFile.ignore(numeric_limits<streamsize>::max(), '\n' );
+            }
+
+            else if (whatToDo=="XTARGET_OFFSET") {
+                AnalysisConfigFile >> DataBuffer;
+                m_XTarget_offset = atof(DataBuffer.c_str());
+                cout << "**** " << whatToDo << " " << m_XTarget_offset << endl;
+            }
+            else if (whatToDo=="YTARGET_OFFSET") {
+                AnalysisConfigFile >> DataBuffer;
+                m_YTarget_offset = atof(DataBuffer.c_str());
+                cout << "**** " << whatToDo << " " << m_YTarget_offset << endl;
+            }
+            else if (whatToDo=="ZTARGET_OFFSET") {
+                AnalysisConfigFile >> DataBuffer;
+                m_ZTarget_offset = atof(DataBuffer.c_str());
+                cout << "**** " << whatToDo << " " << m_ZTarget_offset << endl;
+            }
+            else if (whatToDo=="BEAM_THETAX") {
+                AnalysisConfigFile >> DataBuffer;
+                m_Beam_ThetaX = atof(DataBuffer.c_str());
+                cout << "**** " << whatToDo << " " << m_Beam_ThetaX << endl;
+            }
+            else if (whatToDo=="BEAM_THETAY") {
+                AnalysisConfigFile >> DataBuffer;
+                m_Beam_ThetaY = atof(DataBuffer.c_str());
+                cout << "**** " << whatToDo << " " << m_Beam_ThetaY << endl;
+            }
+            else if (whatToDo=="BRHO_REF") {
+                AnalysisConfigFile >> DataBuffer;
+                m_Brho_ref = atof(DataBuffer.c_str());
+                cout << "**** " << whatToDo << " " << m_Brho_ref << endl;
+            }
+            else if (whatToDo=="VAMOS_ANGLE") {
+                AnalysisConfigFile >> DataBuffer;
+                m_Vamos_Angle = atof(DataBuffer.c_str());
+                cout << "**** " << whatToDo << " " << m_Vamos_Angle << endl;
+            }
+
+            else {
+                ReadingStatus = false;
+            }
+        }
     }
-  }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -826,20 +884,20 @@ void Analysis::End(){
 //            Construct Method to be pass to the DetectorFactory              //
 ////////////////////////////////////////////////////////////////////////////////
 NPL::VAnalysis* Analysis::Construct(){
-  return (NPL::VAnalysis*) new Analysis();
+    return (NPL::VAnalysis*) new Analysis();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //            Registering the construct method to the factory                 //
 ////////////////////////////////////////////////////////////////////////////////
 extern "C"{
-  class proxy{
-    public:
-      proxy(){
-        NPL::AnalysisFactory::getInstance()->SetConstructor(Analysis::Construct);
-      }
-  };
-
-  proxy p;
+    class proxy{
+        public:
+            proxy(){
+                NPL::AnalysisFactory::getInstance()->SetConstructor(Analysis::Construct);
+            }
+    };
+
+    proxy p;
 }
 
diff --git a/Projects/AlPhaPha/2024/Analysis.h b/Projects/AlPhaPha/2024/Analysis.h
index 78eaf1f0b587ff23c5b035c775cac70e715ed702..7a4bbb2823f7c0d31cb6734c7d5bfae2c74fa979 100644
--- a/Projects/AlPhaPha/2024/Analysis.h
+++ b/Projects/AlPhaPha/2024/Analysis.h
@@ -36,6 +36,8 @@
 #include "TRandom3.h"
 #include "TSpline.h"
 #include "TChain.h"
+#include "TTimeData.h"
+#include <vector>
 
 class Analysis: public NPL::VAnalysis{
   public:
@@ -68,6 +70,7 @@ class Analysis: public NPL::VAnalysis{
     double m_BeamEnergy;
     double m_Brho_ref;
     double m_Vamos_Angle;
+
   private:
     double BeamEnergy;
     double Xcalc;
@@ -139,7 +142,8 @@ class Analysis: public NPL::VAnalysis{
     double FF_M13;
     double FF_Mass13;
     double FF_Etot13;
-    
+    vector<double> FF_DriftTime;
+
     double Exo_cosa;
     double Exo_E;
     double Exo_EDC_vamos;
@@ -220,7 +224,9 @@ class Analysis: public NPL::VAnalysis{
     Float_t MTOF_FP1_T0V[92];
     Float_t MTOF_FP1_T1V[92];
 
+    vector<double> TxtToVector(const char* Path); 
   private:
+    TTimeData* Time ;
     TPISTAPhysics* PISTA;
     TFPMWPhysics* FPMW;
     TICPhysics* IC;
diff --git a/Projects/AlPhaPha/2024/ReadMe.md b/Projects/AlPhaPha/2024/ReadMe.md
index 9f8a2923086cba2d3742f3c0f31cca3b1ec98010..86105c1452fe9c5f8383b7add95aba72e7a50526 100644
--- a/Projects/AlPhaPha/2024/ReadMe.md
+++ b/Projects/AlPhaPha/2024/ReadMe.md
@@ -39,7 +39,7 @@ Don't forget to modify the input file .
 Your project.config must point to the root dir of your computer
 
 # Compatibility AlmaLinux
-Never import a detector class in a macro, if you do be sure to put a 
+Never import a detector class in a macro, if you do, be sure to put a 
 ```
 #ifdef 0
 #include DETECTOR.h
diff --git a/Projects/AlPhaPha/2024/SnakeFileGeneric b/Projects/AlPhaPha/2024/Snakefile
similarity index 86%
rename from Projects/AlPhaPha/2024/SnakeFileGeneric
rename to Projects/AlPhaPha/2024/Snakefile
index 9aa13a1addd4a8a37c982733dfafa63f266eb347..c2b42c1666d746178afc26f844ea7121daa18566 100644
--- a/Projects/AlPhaPha/2024/SnakeFileGeneric
+++ b/Projects/AlPhaPha/2024/Snakefile
@@ -3,7 +3,7 @@ import subprocess
 
 # Lire le répertoire d'entrée depuis les arguments de configuration
 #input_directory = config["folder"]
-input_directory = os.getcwd() + "/../DataMacro/output/run_241"
+input_directory = os.getcwd() + "/../DataMacro/output/run_247"
 origin = [] 
 # Iterate over files in input_directory
 for filename in os.listdir(input_directory):
@@ -12,14 +12,14 @@ for filename in os.listdir(input_directory):
     origin.append(filename)
 
 # Définir le répertoire de sortie pour les fichiers convertis
-phy_directory = os.getcwd() + "/../DataMacro/output/analysis"
+phy_directory = os.getcwd() + "/../DataMacro/output/analysis/run_247"
 #phy_directory = "./"
 
 # define target files directory
 analysedfile = []
 for inputfile in origin:
   #analysedfile.append("/home/morfouacep/Physics/NPTool/nptool/Projects/ana_e850/root/analysis/"+inputfile.replace("_raw_","_"))
-  analysedfile.append( os.getcwd() + "/../DataMacro/output/analysis/"+inputfile)
+  analysedfile.append( os.getcwd() + "/../DataMacro/output/analysis/run_247/"+inputfile)
 
 ## batch rules
 rule all:
diff --git a/Projects/AlPhaPha/2024/convert_snakemake_generic.sh b/Projects/AlPhaPha/2024/convert_snakemake_generic.sh
index 10a5f3daf85d317225f3078bab83ae442d3a1a48..7ead632c0d8a841894512a0d7f58ade995a08f5e 100755
--- a/Projects/AlPhaPha/2024/convert_snakemake_generic.sh
+++ b/Projects/AlPhaPha/2024/convert_snakemake_generic.sh
@@ -3,4 +3,4 @@ echo "- executing snakemake file for npanalysis..."
 snakemake --cores 30 --forceall --keep-incomplete --keep-going --rerun-incomplete
 echo "- snakemake executed successfully!"
 echo "- Merging file..."
-root -q '../DataMacro/Merger.C(16,"root/analysis","VamosCalib241","../DataMacro/output/analysis/run_raw_241_")'
+root -q '../DataMacro/Merger.C(30,"root/analysis","VamosCalib247","../DataMacro/output/analysis/run_247/run_raw_247_")'
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/ICCorr.C b/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/ICCorr.C
deleted file mode 100644
index 7497d41b1a9ae4f73cd95da1a2734861866bfc37..0000000000000000000000000000000000000000
--- a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/ICCorr.C
+++ /dev/null
@@ -1,223 +0,0 @@
-#include <TICPhysics.h>
-#include <TCanvas.h>
-#include <TChain.h>
-#include <TF1.h>
-#include <TFile.h>
-#include <TH2.h>
-#include <TSpline.h>
-#include <fstream>
-#include <vector>
-
-using namespace std;
-
-int GetNumberKey(TFile *infile ,const char* ClassName);
-//////////////////////////////////////////////////////////////////////////////////////////
-void ICCorr() {
-  //===========================================================================================================
-  //                           Loading var
-  //===========================================================================================================
-  TChain* chain = new TChain("PhysicsTree");
-  chain->Add("../../../root/analysis/VamosCalib241.root");
-
-  TICPhysics* IC = new TICPhysics() ;
-  double FF_IC_X, FF_IC_Y;
-
-  chain->SetBranchStatus("FF_IC_X", true);
-  chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
-  chain->SetBranchStatus("FF_IC_Y", true);
-  chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
-  chain->SetBranchStatus("IC", true);
-  chain->SetBranchAddress("IC", &IC); 
-
-
-  TFile* fHisto =  TFile::Open("Output/HistoP2P.root");
-  TFile* fSpline =  TFile::Open("Output/spline_P2P_2024.root");
-  TFile* fFit = TFile::Open("Output/FitIC.root");
-
-  //Defining output histo
-  TH2F* hDE_E = new TH2F("DE_E","DE_E",1000,100,1,1000,100,1);
-  TH2F* hDE_Ecorr1 = new TH2F("DE_Ecorr1","DE_Ecorr1",1000,100,1,1000,100,1);
-  TH2F* hDEBis_Ecorr_IC1 = new
-    TH2F("DEBis_Ecorr_IC1","DEBis_Ecorr_IC1",1000,0,20000,1000,0,25000);
-  TH2F* hDE_E_CorrAll = new
-    TH2F("hDE_E_CorrAll","hDE_E_CorrAll",1000,0,20000,1000,0,25000);
-
-
-  // Filling the input histo 
-  int NSegment = 5 ;
-  vector<TH2F*> hICseg_ICprev, hICX,hICY ,hICseg_ICprevX,hICseg_ICprevY, hICcorr;
-  for(int seg=0; seg<NSegment; seg++){
-    
-		if(seg==1){
-			hICX.push_back((TH2F*)fHisto->Get(Form("hChio_IC%d_X",seg)));
-			hICY.push_back((TH2F*)fHisto->Get(Form("hChio_IC%d_Y",seg)));
-			hICcorr.push_back(new TH2F(Form("hICorr%d_Y",seg),Form("hICorr%d_Y",seg),1000,-100,100,500,2000,9500));
-		}
-		else if (seg == 0){
-			hICX.push_back((TH2F*)fHisto->Get(Form("hIC%d_IC%d_X",seg+1,seg)));
-			hICY.push_back((TH2F*)fHisto->Get(Form("hIC%d_IC%d_Y",seg+1,seg)));
-			hICcorr.push_back(new TH2F(Form("hICorr%d_Y",seg),Form("hICorr%d_Y",seg),1000,-100,100,500,0,2));
-		}
-		else {
-			hICX.push_back((TH2F*)fHisto->Get(Form("hIC%d_IC%d_X",seg,seg-1)));
-			hICY.push_back((TH2F*)fHisto->Get(Form("hIC%d_IC%d_Y",seg,seg-1)));
-			hICcorr.push_back(new TH2F(Form("hICorr%d_Y",seg),Form("hICorr%d_Y",seg),1000,-100,100,500,0,2));
-		}
-	}
-
-	//===========================================================================================================
-	//                                            GETSPLINE
-	//===========================================================================================================
-	// Get number of spline
-	int SplineCount = 0 ;
-	TIter next(fSpline->GetListOfKeys());
-	TKey* key;
-
-	while ((key=(TKey*)next())){
-		if (std::string(key->GetClassName()) == "TSpline3"){
-			SplineCount ++;
-		}
-	}
-
-
-	vector<TSpline3*> spline_X(11), spline_Y(11);
-	for (int i = 0; i < SplineCount  ; i++) {
-		int seg = int((i-2)/2 +1 );
-
-		if (i < 2){
-			spline_X.at(0) = (TSpline3 *)fSpline->Get("fspline_IC1_IC0_X");
-			spline_Y.at(0) = (TSpline3 *)fSpline->Get("fspline_IC1_IC0_Y");
-		}
-
-		else if ( i>=2 && i<4){ 
-			spline_X.at(1) = (TSpline3 *)fSpline->Get("fsplineIC1_X");
-			spline_Y.at(1) = (TSpline3 *)fSpline->Get("fsplineIC1_Y");
-		}
-		else if (seg >=2 && (i%2 == 0) ) {
-			spline_X.at(seg) = (TSpline3 *)fSpline->Get(Form("fspline_IC%d_IC%d_X",seg,seg-1));
-		}
-		else if (seg >=2 && !(i%2 == 0) ) {	
-			spline_Y.at(seg) = (TSpline3 *)fSpline->Get(Form("fspline_IC%d_IC%d_Y",seg,seg-1));
-		}
-	} //End loop on histogram
-		//===========================================================================================================
-		//                                 get fit
-		//===========================================================================================================
-
-	int FitCount = GetNumberKey(fFit,"TF1"); 
-
-
-	vector<TF1*> Fit;
-	for (int i = 0; i < FitCount  ; i++) {
-		Fit.push_back((TF1*)fFit->Get(Form("Fit_Y_Expo_IC%d",i)));
-	} //End loop on Fit 
-
-
-	//===========================================================================================================
-	//                                        Event Loop
-	//===========================================================================================================
-	int Nentries = chain->GetEntries();
-
-	for (int e = 0; e < Nentries; e++) {
-		// Printing status
-		if (e % 100000 == 0){
-			cout <<  "Please wait, we are  " << e * 100. / Nentries << "% done ..\r" << flush;
-		}
-		chain->GetEntry(e);
-
-
-		vector<double> ICcorr_Y(5), ICcorr_X(11); // the [0] element of spline is the
-																							 // correction on the first
-																							 // segment of ic
-		for (int seg = 0; seg < ICcorr_Y.size()  ; seg++) {
-			if (seg == 1){ 
-				ICcorr_Y.at(seg) = IC->fIC_raw[1]*spline_Y.at(0)->Eval(0)/spline_Y.at(0)->Eval(FF_IC_Y);
-			}
-
-			if (seg == 0) {
-				double temp = ICcorr_Y.at(1) / IC->fIC_raw[0] * spline_Y.at(1)->Eval(0)/ spline_Y.at(1)->Eval(FF_IC_Y);
-				ICcorr_Y.at(seg) = ICcorr_Y.at(1) / temp;
-				//cout << ICcorr_Y.at(0) << "  " << IC->fIC_raw[0]<< endl;
-			}
-			else if (seg > 1) {
-				double temp =  IC->fIC_raw[seg]/ICcorr_Y.at(seg-1) * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
-				ICcorr_Y.at(seg) = ICcorr_Y.at(seg-1) * temp;
-			}
-			if (!(ICcorr_Y.at(seg)==ICcorr_Y.at(seg))) ICcorr_Y.at(seg) = 0;
-		} //End loop on histogram
-
-
-		for (int i = 0; i < ICcorr_Y.size()  ; i++) {
-			hICcorr.at(i)->Fill(FF_IC_Y,ICcorr_Y.at(i));
-		} //End loop on histogram
-
-		double DE = 0 ,E =0 ,DE_IC1_corrY =0, DE_ICALL_corrY=0, Ecorr=0;
-
-		for (int seg = 0 ;  seg < sizeof(IC->fIC_raw)/sizeof(IC->fIC_raw[0]) ; seg++ ){
-			if (seg >4){
-				E += IC->fIC_raw[seg] ;
-				//Ecorr += ICcorr_Y.at(seg) ;
-			}
-		}
-
-		double IC1corr = (IC->fIC_raw[1]*(1-0.000686068*FF_IC_Y))*(1-4.88238e-05*FF_IC_Y+7.40395e-06*FF_IC_Y*FF_IC_Y);
-		double DE_Bis = 0.5*(IC1corr+IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
-
-		DE = 0.5*(IC->fIC_raw[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
-		DE_IC1_corrY = 0.5*(ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
-		DE_ICALL_corrY = 0.5*(ICcorr_Y[0]+ICcorr_Y[1] +ICcorr_Y[2]+ICcorr_Y[3]);
-		double Ealt = E + IC->fIC_raw[4];
-
-		if (FF_IC_Y >-60 && FF_IC_Y <60){
-			hDEBis_Ecorr_IC1->Fill(E,DE_Bis);
-			hDE_E->Fill(E,DE);
-			hDE_Ecorr1->Fill(E,DE_IC1_corrY);
-			hDE_E_CorrAll->Fill(E,DE_ICALL_corrY);
-		}
-	} //endl loop event
-		//===========================================================================================================
-		//                                          Drawing histo
-		//===========================================================================================================
-
-	TCanvas* c1 = new TCanvas("c1","c1",10000,1000);
-	c1->Divide(11,2);
-	for (int i = 0 ; i<11 ;i++){
-		c1->cd(i+1);
-		hICcorr.at(i)->ProfileX()->Draw();
-
-		c1->cd(11+i+1);
-		hICY.at(i)->ProfileX()->Draw();
-	}
-
-	TCanvas* c2 = new TCanvas("c2","c2",1500,1000);
-	c2->Divide(4);
-	c2->cd(1);
-	gPad->SetLogz();
-	hDE_E->Draw();
-	c2->cd(2);
-	gPad->SetLogz();
-	hDE_Ecorr1->Draw();
-	c2->cd(3);
-	gPad->SetLogz();
-	hDEBis_Ecorr_IC1->Draw();
-	c2->cd(4);
-	gPad->SetLogz();
-	hDE_E_CorrAll->Draw();
-} // End spline chio XY
-
-
-int GetNumberKey(TFile *infile ,const char* ClassName){
-	// Get number of spline
-	int KeyCount = 0 ;
-	TIter next(infile->GetListOfKeys());
-	TKey* keyFit;
-
-	while ((keyFit=(TKey*)next())){
-		if (std::string(keyFit->GetClassName()) == ClassName){
-			KeyCount ++;
-		}
-	}
-
-	return KeyCount;
-
-}
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioP2P.C b/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioP2P.C
deleted file mode 100644
index 6cb779075b87e972ce33f67beab260de85760d68..0000000000000000000000000000000000000000
--- a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioP2P.C
+++ /dev/null
@@ -1,511 +0,0 @@
-//#ifdef TICPhysics
-#include <TICPhysics.h>
-//#endif
-#include <TCanvas.h>
-#include <TChain.h>
-#include <TF1.h>
-#include <TFile.h>
-#include <TH2.h>
-#include <TSpline.h>
-#include <fstream>
-#include <vector>
-#include <TCutG.h>
-
-using namespace std;
-
-TSpline3* MakeSpline(TH2F* hInput, Int_t NCallee, double XMin , double
-    XMax, double YMin, double YMax);
-
-vector<TH2F*>HistoFillerIC(int segment, vector<vector<TSpline3*>> Spline_All_ICprev);
-vector<vector<TH2F*>>HistoFillerICcorr(int segment, vector<vector<TSpline3*>> Spline_All_ICprev);
-
-void HistoDrawer(vector<TH2F*> h ,const char* CharName);
-
-//////////////////////////////////////////////////////////////////////////////////////////
-void SplineChioP2P() {
-
-  int NSegment = 5 ;
-  double XMin[4] , XMax[4], YMin[4] , YMax[4];
-  XMin[0] = -520 ;   XMax[0] = 380 ; YMin[0] = 2000 ; YMax[0] = 9500 ; 
-  XMin[1] = -60  ;   XMax[1] = 63  ; YMin[1] = 2000 ; YMax[1] = 9500 ; 
-  XMin[2] = -520 ;   XMax[2] = 380 ; YMin[2] = 0 ; YMax[2] = 2 ; 
-  XMin[3] = -60  ;   XMax[3] = 63  ; YMin[3] = 0 ; YMax[3] = 2 ; 
-
-  //Reinitialising the outfile
-  TFile *OutFile = new TFile("Output/HistoP2P.root","recreate");
-  OutFile->Close();
-  //Initialising with IC1
-  int NCallSpline = 0;
-  int seg = 1;
-
-  vector<vector<TSpline3*>> SplineAllIC(11);
-  vector<TSpline3*> SplineICurrent;
-
-  vector<vector<TH2F*>> hIC(NSegment);
-  hIC.at(1)= (HistoFillerIC(1,SplineAllIC));
-
-  SplineICurrent.push_back(MakeSpline(hIC[seg][0] , NCallSpline, XMin[0] , XMax[0], YMin[0], YMax[0]));
-  SplineICurrent.at(0)->SetName("fsplineIC1_X");
-  NCallSpline+=1;
-
-
-  SplineICurrent.push_back(MakeSpline(hIC[seg][1] , NCallSpline, XMin[1] , XMax[1], YMin[1], YMax[1]));
-  SplineICurrent.at(1)->SetName("fsplineIC1_Y");
-  NCallSpline+=1;
-
-  SplineAllIC.at(1)= (SplineICurrent); // 
-
-
-  for (int seg = 0 ; seg < NSegment ; seg++){
-    if(seg ==1) {
-    }
-
-    else{
-
-      //Load Histo 
-      hIC.at(seg) = (HistoFillerIC(seg,SplineAllIC));
-
-      //Reset spline holder
-      vector<TSpline3*> SplineICurrent; 
-
-      // X Spline
-      SplineICurrent.push_back(MakeSpline(hIC[seg][0] , NCallSpline, XMin[2] , XMax[2], YMin[2], YMax[2]));
-      if (seg == 0)  SplineICurrent.at(0)->SetName(Form("fspline_IC%d_IC%d_X",seg+1,seg));
-      else if (seg != 0) SplineICurrent.at(0)->SetName(Form("fspline_IC%d_IC%d_X",seg,seg-1));
-      NCallSpline+=1;
-
-      // Y Spline
-      SplineICurrent.push_back(MakeSpline(hIC[seg][1] , NCallSpline, XMin[3] , XMax[3], YMin[3], YMax[3]));
-      if (seg == 0)  SplineICurrent.at(1)->SetName(Form("fspline_IC%d_IC%d_Y",seg+1,seg));
-      else if (seg != 0)SplineICurrent.at(1)->SetName(Form("fspline_IC%d_IC%d_Y",seg,seg-1));
-      NCallSpline+=1;
-
-      //push vector into memory
-      SplineAllIC.at(seg)= SplineICurrent;
-    }
-  }
-  //write spline
-  TFile* fspline = new TFile("Output/spline_P2P_2024.root", "recreate");
-  for (int seg = 0 ; seg < NSegment ; seg++){
-    SplineAllIC.at(seg)[0]->Write();
-    SplineAllIC.at(seg)[1]->Write();
-  }
-  fspline->Close();
- 
- 
-  vector<vector<TH2F*>> hIC_Corrall(NSegment);
-  vector<TH1F*> hIC_Corr_profile(NSegment);
-  vector<TH2F*> hIC_Corr(NSegment);
-
-  hIC_Corrall = HistoFillerICcorr(NSegment,SplineAllIC);
-  hIC_Corr = hIC_Corrall.at(1);
-
-  TCanvas *c1 = new TCanvas("c1","c1");
-  c1->Divide(NSegment);
-  for (int i=0 ; i<NSegment ; i++){
-    hIC_Corr_profile.at(i) = (TH1F*)hIC_Corr.at(i)->ProfileX();  
-    c1->cd(i+1);
-    hIC_Corr_profile.at(i)->Draw();
-  }
-
-
-} // End spline chio XY
-
-///////////////////////////////////////////////////////////////////////////////////////////
-/**
- * This function fill the histograms of ICseg/ICcorrSeg-1 expect for IC1 where
- * it give IC1 and ICO where it give IC0/IC1corr
- */
-vector<TH2F*> HistoFillerIC(int segment, vector<vector<TSpline3*>> Spline_All_ICprev) {
-
-  // Input and setters
-  TChain* chain = new TChain("PhysicsTree");
-  chain->Add("../../../root/analysis/VamosCalib241.root");
-
-  TICPhysics* IC = new TICPhysics() ; 
-  double FF_IC_X, FF_IC_Y;
-
-  chain->SetBranchStatus("FF_IC_X", true);
-  chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
-  chain->SetBranchStatus("FF_IC_Y", true);
-  chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
-  chain->SetBranchStatus("IC", true);
-  chain->SetBranchAddress("IC", &IC);
-
-  // Get the number of previous spline to load
-  int NSpline = abs(segment-1);
-
-  //Filling all  previous vector spline
-  vector<TSpline3*> SplineIC_X(NSpline+1);
-  vector<TSpline3*> SplineIC_Y(NSpline+1);
-
-  //Fill all the previous spline , if the segment is 0 it'll fill spline 1 only 
-  for (int pseg = 1 ; pseg<=NSpline; pseg++){
-    if(!Spline_All_ICprev.at(pseg).empty()){
-      SplineIC_X.at(pseg) = Spline_All_ICprev.at(pseg).at(0);
-      SplineIC_Y.at(pseg) = Spline_All_ICprev.at(pseg).at(1);
-    }
-  }
-
-  // Histograms
-  TH2F *hIC_X , *hIC_Y;
-
-  if (segment == 1 ) { 
-    hIC_Y = new TH2F(Form("hChio_IC%d_Y",segment),
-        Form("hChio_IC%d_Y",segment), 1000, -160, 160, 500, 2000, 9500);
-    hIC_X = new TH2F(Form("hChio_IC%d_X",segment),
-        Form("hChio_IC%d_X",segment), 1000, -800, 800, 500, 2000, 9500);
-
-  }
-
-  else if (segment == 0){  
-    hIC_Y = new TH2F(Form("hChio_IC%d/IC%d_Y",segment+1,segment),
-        Form("hChio_IC%d/IC%d_Y",segment+1,segment), 1000, -160, 160, 500, 0, 2);
-    hIC_X = new TH2F(Form("hChio_IC%d/IC%d_X",segment+1,segment),
-        Form("hChio_IC%d/IC%d_X",segment+1,segment), 1000, -800, 800, 500, 0, 2);
-  }
-
-  else {
-    hIC_Y = new TH2F(Form("hChio_IC%d/IC%d_Y",segment,segment-1),
-        Form("hChio_IC%d/IC%d_Y",segment,segment-1), 1000, -160, 160, 500, 0, 2);
-    hIC_X = new TH2F(Form("hChio_IC%d/IC%d_X",segment,segment-1),
-        Form("hChio_IC%d/IC%d_X",segment,segment-1), 1000, -800, 800, 500, 0, 2);
-  }
-
-
-  //===========================================================================================================
-  //																	Beginning loop on entries
-  //===========================================================================================================
-
-   int Nentries = chain->GetEntries();
-  //int Nentries = 100000;
-  auto start = std::chrono::high_resolution_clock::now();
-  for (int e = 0; e < Nentries; e++) {
-
-    chain->GetEntry(e);
-
-    vector<double> IC_Spline_CorrX(NSpline + 1),IC_Spline_CorrY(NSpline+1);
-
-    //Get the corrected value for all previous spline
-    for (int pseg = 1 ; pseg<=NSpline ; pseg++){
-      //If the spline doesnt exist define default value
-      if(Spline_All_ICprev.at(pseg).empty()){
-        IC_Spline_CorrX.at(pseg)= IC->fIC_raw[pseg];
-        IC_Spline_CorrY.at(pseg)= IC->fIC_raw[pseg]; 
-      }
-
-      //If it exist correct the current line
-      else if (!Spline_All_ICprev.at(pseg).empty()){
-        if(pseg ==1){
-          IC_Spline_CorrX.at(pseg) = IC->fIC_raw[pseg] * SplineIC_X.at(pseg)->Eval(0) / SplineIC_X.at(pseg)->Eval(FF_IC_X); 
-          IC_Spline_CorrY.at(pseg) = IC->fIC_raw[pseg] * SplineIC_Y.at(pseg)->Eval(0) / SplineIC_Y.at(pseg)->Eval(FF_IC_Y); 
-        } //end ic 1
-        else { 
-          IC_Spline_CorrX.at(pseg) = IC->fIC_raw[pseg] * SplineIC_X.at(pseg)->Eval(0) / SplineIC_X.at(pseg)->Eval(FF_IC_X); 
-          IC_Spline_CorrY.at(pseg) = IC->fIC_raw[pseg] * SplineIC_Y.at(pseg)->Eval(0) / SplineIC_Y.at(pseg)->Eval(FF_IC_Y); 
-        } //end ic 2 to 10
-      } //End if non empty
-
-    } // End loop IC non 0
-
-    //===========================================================================================================
-    //                               Fill histo
-    //===========================================================================================================/
-
-    if (segment == 1){
-      hIC_Y->Fill(FF_IC_Y,IC->fIC_raw[segment]);
-      hIC_X->Fill(FF_IC_X,IC->fIC_raw[segment]);
-    }
-
-    else if (segment == 0){
-      hIC_Y->Fill(FF_IC_Y,IC_Spline_CorrY.at(1)/IC->fIC_raw[segment]);
-      hIC_X->Fill(FF_IC_X,IC_Spline_CorrX.at(1)/IC->fIC_raw[segment]);
-    }
-
-
-    else {
-      hIC_Y->Fill(FF_IC_Y,IC->fIC_raw[segment]/IC_Spline_CorrY.at(segment-1));
-      hIC_X->Fill(FF_IC_X,IC->fIC_raw[segment]/IC_Spline_CorrX.at(segment-1));    
-    }
-
-    // Estimate time left every `updateInterval` iterations
-    if (e % 100000  == 0 && e > 0) {
-      auto now = std::chrono::high_resolution_clock::now();
-      std::chrono::duration<double> elapsed = now - start;
-      double avgTimePerIteration = elapsed.count() / e;
-      double timeLeft = avgTimePerIteration * (Nentries - e);
-
-      std::cout << "Treating segment : " << segment 
-        << "  | Estimated time left: " << timeLeft << " seconds" << "\r" << flush;
-    }
-  } // end loop on entries
-
-  //===========================================================================================================
-  //                                       Output 
-  //===========================================================================================================
-  vector<TH2F*> hIC;
-  hIC.push_back(hIC_X);
-  hIC.push_back(hIC_Y);
-
-  TFile *OutFile = new TFile("Output/HistoP2P.root","UPDATE");
-  hIC_X->Write();
-  hIC_Y->Write();
-  OutFile->Close();
-
-  return hIC;
-} // End HistoFiller
-
-vector<vector<TH2F*>>HistoFillerICcorr(int segment, vector<vector<TSpline3*>> Spline_All_ICprev){
-
-  // Input and setters
-  TChain* chain = new TChain("PhysicsTree");
-  chain->Add("../../../root/analysis/VamosCalib241.root");
-
-  TICPhysics* IC = new TICPhysics() ; 
-  double FF_IC_X, FF_IC_Y;
-
-  chain->SetBranchStatus("FF_IC_X", true);
-  chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
-  chain->SetBranchStatus("FF_IC_Y", true);
-  chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
-  chain->SetBranchStatus("IC", true);
-  chain->SetBranchAddress("IC", &IC);
-
-  // Get the number of previous spline to load
-  segment = segment -1;
-  int NSpline = abs(segment);
-
-  //Filling all  previous vector spline
-  vector<TSpline3*> SplineIC_X(NSpline+1);
-  vector<TSpline3*> SplineIC_Y(NSpline+1);
-
-  //Fill all the previous spline , if the segment is 0 it'll fill spline 1 only 
-  for (int pseg = 0 ; pseg<=NSpline; pseg++){
-    if(!Spline_All_ICprev.at(pseg).empty()){
-      SplineIC_X.at(pseg) = Spline_All_ICprev.at(pseg).at(0);
-      SplineIC_Y.at(pseg) = Spline_All_ICprev.at(pseg).at(1);
-    }
-  }
-
-  // Histograms
-  vector<TH2F*> hIC_X(segment +1) , hIC_Y(segment+1);
-
-  for (int pseg = 0 ; pseg<=NSpline; pseg++){
-    if (pseg == 1 ) { 
-      hIC_Y.at(pseg) = new TH2F(Form("hChiocorr_IC%d_Y",pseg),
-          Form("hChiocorr_IC%d_Y",pseg), 1000, -160, 160, 500, 2000, 9500);
-      hIC_X.at(pseg) = new TH2F(Form("hChiocorr_IC%d_X",pseg),
-          Form("hChiocorr_IC%d_X",pseg), 1000, -800, 800, 500, 2000, 9500);
-
-    }
-
-    else if (pseg == 0){  
-      hIC_Y.at(pseg) = new TH2F(Form("hChiocorr_IC%d/IC%d_Y",pseg+1,pseg),
-          Form("hChiocorr_IC%d/IC%d_Y",pseg+1,pseg), 1000, -160, 160, 500, 0, 2);
-      hIC_X.at(pseg) = new TH2F(Form("hChiocorr_IC%d/IC%d_X",pseg+1,pseg),
-          Form("hChiocorr_IC%d/IC%d_X",pseg+1,pseg), 1000, -800, 800, 500, 0, 2);
-    }
-
-    else {
-      hIC_Y.at(pseg) = new TH2F(Form("hChiocorr_IC%d/IC%d_Y",pseg,pseg-1),
-          Form("hChiocorr_IC%d/IC%d_Y",pseg,pseg-1), 1000, -160, 160, 500, 0, 2);
-      hIC_X.at(pseg) = new TH2F(Form("hChiocorr_IC%d/IC%d_X",pseg,pseg-1),
-          Form("hChiocorr_IC%d/IC%d_X",pseg,pseg-1), 1000, -800, 800, 500, 0, 2);
-    }
-  }
-
-  //===========================================================================================================
-  //																	Beginning loop on entries
-  //===========================================================================================================
-
-   int Nentries = chain->GetEntries();
-  //int Nentries = 100000;
-  auto start = std::chrono::high_resolution_clock::now();
-  for (int e = 0; e < Nentries; e++) {
-
-    chain->GetEntry(e);
-
-    vector<double> IC_Spline_CorrX(NSpline + 1),IC_Spline_CorrY(NSpline+1);
-
-    //Get the corrected value for all previous spline
-    for (int pseg = 0 ; pseg<=NSpline ; pseg++){
-      //If the spline doesnt exist define default value
-      if(Spline_All_ICprev.at(pseg).empty()){
-        IC_Spline_CorrX.at(pseg)= IC->fIC_raw[pseg];
-        IC_Spline_CorrY.at(pseg)= IC->fIC_raw[pseg];
-      }
-
-      //If it exist correct the current line
-      else if (!Spline_All_ICprev.at(pseg).empty()){
-        if(pseg ==1){
-          IC_Spline_CorrX.at(pseg) = IC->fIC_raw[1] * SplineIC_X.at(pseg)->Eval(0) / SplineIC_X.at(pseg)->Eval(FF_IC_X); 
-          IC_Spline_CorrY.at(pseg) = IC->fIC_raw[1] * SplineIC_Y.at(pseg)->Eval(0) / SplineIC_Y.at(pseg)->Eval(FF_IC_Y); 
-        } //end ic 1
-        else if (pseg !=0) { 
-          IC_Spline_CorrX.at(pseg) = IC->fIC_raw[pseg] * SplineIC_X.at(pseg)->Eval(0) / SplineIC_X.at(pseg)->Eval(FF_IC_X); 
-          IC_Spline_CorrY.at(pseg) = IC->fIC_raw[pseg] * SplineIC_Y.at(pseg)->Eval(0) / SplineIC_Y.at(pseg)->Eval(FF_IC_Y); 
-        } //end ic 2 to 10
-      } //End if non empty
-    } // end loop
-    
-    //filling 0
-    if (!Spline_All_ICprev.at(0).empty()){
-      IC_Spline_CorrX.at(0) = IC->fIC_raw[0] / SplineIC_X.at(0)->Eval(0) * SplineIC_X.at(0)->Eval(FF_IC_X); 
-      IC_Spline_CorrY.at(0) = IC->fIC_raw[0] / SplineIC_Y.at(0)->Eval(0) * SplineIC_Y.at(0)->Eval(FF_IC_Y); 
-    }
-
-    for (int pseg = 0 ; pseg<=NSpline ; pseg++){
-      if (pseg == 1){
-        hIC_Y.at(pseg)->Fill(FF_IC_Y,IC_Spline_CorrY.at(1));
-        hIC_X.at(pseg)->Fill(FF_IC_X,IC_Spline_CorrY.at(1));
-      }
-
-      else if (pseg == 0){
-        hIC_Y.at(pseg)->Fill(FF_IC_Y,IC_Spline_CorrY.at(1)/IC_Spline_CorrY.at(pseg));
-        hIC_X.at(pseg)->Fill(FF_IC_X,IC_Spline_CorrY.at(1)/IC_Spline_CorrX.at(pseg));
-      }
-
-
-      else {
-        hIC_Y.at(pseg)->Fill(FF_IC_Y,IC_Spline_CorrY.at(pseg)/IC_Spline_CorrY.at(pseg-1));
-        hIC_X.at(pseg)->Fill(FF_IC_X,IC_Spline_CorrY.at(pseg)/IC_Spline_CorrX.at(pseg-1));    
-      }
-    }
-    //===========================================================================================================
-    //                               Fill histo
-    //===========================================================================================================/
-
-
-    // Estimate time left every `updateInterval` iterations
-    if (e % 100000  == 0 && e > 0) {
-      auto now = std::chrono::high_resolution_clock::now();
-      std::chrono::duration<double> elapsed = now - start;
-      double avgTimePerIteration = elapsed.count() / e;
-      double timeLeft = avgTimePerIteration * (Nentries - e);
-
-      std::cout << "Treating segment : " << segment 
-        << "  | Estimated time left: " << timeLeft << " seconds" << "\r" << flush;
-    }
-  } // end loop on entries
-
-  //===========================================================================================================
-  //                                       Output 
-  //===========================================================================================================
-  vector<vector<TH2F*>> hIC;
-  hIC.push_back(hIC_X);
-  hIC.push_back(hIC_Y);
-
-  return hIC;
-} // End HistoFiller
-
-
-/**
-  }
- *  Create the spline for one TH2F
- *
- *  Input :
- *     Pointer to a TH2F
- *
- *
- *  Output:
- *
- *     TSpline3 : the output spline
- *
- */
-
-TSpline3* MakeSpline(TH2F* hInput, Int_t NCallee, double XMin = 0 , double
-    XMax = 1000 , double YMin=0 , double YMax = 100) {
-
-  TSpline3* gspline;
-
-  TH1F* hProfile;
-  TH1F* pfx; // extended hProfile
-
-  TCanvas* canfit = new TCanvas(Form("CanSpline_%02d",NCallee),
-      Form("canfit_%02d",NCallee), 0, 0, 1000, 500);
-
-
-  //===========================================================================================================
-  //                                            Init profile
-  //===========================================================================================================
-
-  // Create the TProfile
-  hProfile = (TH1F*)hInput->ProfileX();
-  hProfile->SetLineWidth(2);
-  hProfile->SetDirectory(0);
-  canfit->cd();
-
-  hProfile->GetYaxis()->SetRangeUser(YMin, YMax);
-  hProfile->Draw();
-  //===========================================================================================================
-  //                                          First and last bin to get to 6k
-  //                                          event get promoted
-  //===========================================================================================================
-  int FirstBin, LastBin;
-  double Treshold = 1;
-  for (int bin =1 ; bin<hProfile->GetNbinsX(); bin++) {
-    FirstBin = bin;
-    if (hProfile->GetBinLowEdge(bin)> XMin) break;
-  }
-  for (int bin = hProfile->GetNbinsX(); bin>1 ; bin--) {
-    LastBin = bin;
-    if (hProfile->GetBinLowEdge(bin)< XMax) break;
-  }
-  //===========================================================================================================
-  //                                          Init Extended profile function
-  //===========================================================================================================
-  // Create the extended TProfile
-  pfx = new TH1F(
-      Form("pfx_%02d", Int_t(NCallee/2)), Form("pfx_%02d", Int_t(NCallee/2)), hProfile->GetNbinsX(), hProfile->GetBinLowEdge(1),
-      hProfile->GetBinLowEdge(hProfile->GetNbinsX()) + hProfile->GetBinWidth(hProfile->GetNbinsX()));
-  pfx->SetLineColor(8);
-  pfx->SetDirectory(0);
-  //===========================================================================================================
-  //                                           Fill extended profile
-  //===========================================================================================================
-
-  // fill the extended TProfile
-  float newval, lastval, lasterr;
-  for (int bin = 1; bin <= FirstBin; bin++) {
-    newval = 0;
-    pfx->SetBinContent(bin, newval);
-  }
-
-
-  for (int bin = FirstBin; bin <= LastBin; bin++) {
-    newval = hProfile->GetBinContent(bin);
-    if (newval != 0) {
-      pfx->SetBinContent(bin, newval);
-      pfx->SetBinError(bin, hProfile->GetBinError(bin));
-      lastval = newval;
-      lasterr = hProfile->GetBinError(bin);
-    }
-    else {
-      pfx->SetBinContent(bin, lastval);
-      pfx->SetBinError(bin, lasterr);
-    }
-  }
-  pfx->Draw("same");
-
-  gspline = new TSpline3(pfx);
-  gspline->SetName(Form("fspline_%d", NCallee + 1));
-
-  return gspline;
-
-} // end makespline
-
-void HistoDrawer(vector<TH2F*> h,const char* CharName){
-
-  int NHisto = static_cast<int>(h.size());
-
-  TCanvas* Can= new TCanvas(CharName,CharName,0,0,2000,1000);
-
-  Can->Divide(NHisto);
-
-  for ( int i=0 ; i < NHisto ; i+=1 ){
-    //All x are even and all y are odd
-    int CanvaNumber = (i) ;
-    Can->cd(CanvaNumber);
-    h[i]->Draw("colz");
-  }
-}
diff --git a/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/Cut/ReadMe.md b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/Cut/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..71d0df6fef1491bc83cb666eab4a766060bc0577
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/Cut/ReadMe.md
@@ -0,0 +1,3 @@
+# Fill your cut here
+
+Fill this directory with your cut
diff --git a/Projects/AlPhaPha/2024/macro/chio/FillCharge.cxx b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/FillCharge.cxx
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/chio/FillCharge.cxx
rename to Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/FillCharge.cxx
diff --git a/Projects/AlPhaPha/2024/macro/chio/FillSelectTree.C b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/FillSelectTree.C
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/chio/FillSelectTree.C
rename to Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/FillSelectTree.C
diff --git a/Projects/AlPhaPha/2024/macro/chio/FitCharge.C b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/FitCharge.C
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/chio/FitCharge.C
rename to Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/FitCharge.C
diff --git a/Projects/AlPhaPha/2024/macro/chio/Minimization.C b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/Minimization.C
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/chio/Minimization.C
rename to Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/Minimization.C
diff --git a/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/Output/ReadMe.md b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/Output/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..53145de146838959247a7d2b25df28daea120c04
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/Output/ReadMe.md
@@ -0,0 +1,3 @@
+# Output
+
+This directory is crucial for pathing of the macro
diff --git a/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/ReadMe.md b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..3e6f98ff227ed13a32aec8477ee7090fd282e46a
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/ReadMe.md
@@ -0,0 +1,7 @@
+# Requirement
+
+You need to fill Cut folder with the cut of each charge  
+
+You can do this simply by using the DECorr.C macro in the YCalibration folder  
+
+The name of the cut should be Z1->ZN and you should space them a little  
diff --git a/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/SplineChio.C b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/SplineChio.C
new file mode 100644
index 0000000000000000000000000000000000000000..eb7c1011f258abdd4000e661ba873e344470ab96
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/SplineChio.C
@@ -0,0 +1,776 @@
+#include "TICPhysics.h"
+#include <TChain.h>
+#include <TCutG.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TH2.h>
+#include <TSpline.h>
+#include <fstream>
+
+using namespace std;
+
+const int Ncuts=28;
+const int NSegment=11;
+const int Nrun=1;
+int RunNumber[Nrun]={241};
+
+void MakeSpline();
+void ApplySpline_perTCutG();
+void ApplySpline();
+vector<vector<TSpline3*>> LoadSpline(const char* PathToSpline);
+
+///////////////////////////////////////////////////////////////////////////
+void SplineChio()
+{
+    //===========================================================================================================
+    //                                      Loading Var
+    //===========================================================================================================
+    
+    //**********************Cut**************************************
+    TFile *fcut=new TFile("Cut/Cut_Z.root","open");
+    TCutG *cutZ[Ncuts];
+    for(int i=0;i<Ncuts;i++) cutZ[i]=(TCutG*)fcut->Get(Form("Z%i",i+1));
+
+    // ****************** Spline Y **********************************
+    TFile *fSplineIC = new TFile("../YCalibration/Output/spline_P2P_2024.root","open"); 
+
+
+    vector<vector<TSpline3*>> Spline = LoadSpline("../YCalibration/Output/spline_P2P_2024.root");
+    vector<TSpline3*> spline_X(11), spline_Y(11);
+    spline_X = Spline.at(0) ; spline_Y = Spline.at(1);
+
+    //**********************DE_E****************************************************
+    TChain *chain=new TChain("PhysicsTree");
+    
+    chain->Add("../../../root/analysis/VamosCalib241.root");
+    
+    TICPhysics* IC = new TICPhysics() ;
+    double FF_IC_X, FF_IC_Y, FF_V13;
+    double FF_DE, FF_Eres;
+    
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC); 
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+
+
+    TH2F *hChioDE_E_all = new TH2F("hChioDE_E","hChioDE_E",1000,1000,20000,500,1000,26000);
+    TH2F *hChioDE_E[Ncuts];
+    for(int i=0;i<Ncuts;i++) hChioDE_E[i]=new TH2F(Form("hChioDE_E_%d",i+1),Form("hChioDE_E_%d",i+1),2000,1000,20000,1250,1000,26000);
+
+    auto start = std::chrono::high_resolution_clock::now();
+    int Nentries=chain->GetEntries();
+    for(int e=0;e<Nentries;++e)
+    {
+        if (e % 100000  == 0 && e > 0 ) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+        }
+
+        chain->GetEntry(e);
+
+        vector<double> ICcorr_Y(NSegment), ICcorr_X(NSegment); // the [0] element of spline is the
+        vector<double> Temp_X(NSegment) , Temp_Y(NSegment);    // correction on the first
+                                                               // segment of ic
+        for (int seg = 1; seg < NSegment+1 ; seg++) {
+
+            if (seg == NSegment) seg = 0; //from 1to NSeg finishing with 0
+
+            if (spline_Y.at(seg)==0){
+                ICcorr_Y.at(seg) = IC->fIC_raw[seg]; 
+            }
+
+            else {
+                if (seg == 0) {
+                    Temp_Y.at(seg) = ICcorr_Y.at(1) / IC->fIC_raw[seg] * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(1) / Temp_Y.at(seg);
+                }
+
+                else if (seg == 1){ 
+                    ICcorr_Y.at(seg) = IC->fIC_raw[1]*spline_Y.at(1)->Eval(0)/spline_Y.at(1)->Eval(FF_IC_Y);
+                }
+
+                else if (seg > 1) {
+                    Temp_Y.at(seg) =  IC->fIC_raw[seg]/ICcorr_Y.at(seg-1) * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(seg-1) * Temp_Y.at(seg);
+                }
+
+                if (!(ICcorr_Y.at(seg)==ICcorr_Y.at(seg))) ICcorr_Y.at(seg) = 0;
+            } //end if non empty
+            if (seg == 0) break;
+        }//endloop seg
+
+
+       FF_DE = 0.5*( ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+       FF_Eres = 0 ;
+
+        for (int seg = 0 ;  seg < sizeof(IC->fIC_raw)/sizeof(IC->fIC_raw[0]) ; seg++ ){
+            if (seg >4){
+                FF_Eres += IC->fIC_raw[seg] ;
+                //Ecorr += ICcorr_Y.at(seg) ;
+            }
+        }
+
+
+       hChioDE_E_all->Fill(FF_Eres,FF_DE); 
+
+        //for(int i=0;i<Ncuts;i++) if(cutZ[i]->IsInside(Chio_E,FF_DE)) {hChioDE_E[i]->Fill(Chio_E,FF_DE); break;}
+        for(int i=0;i<Ncuts;i++) if(cutZ[i]->IsInside(FF_Eres,FF_DE)) {hChioDE_E[i]->Fill(FF_Eres,FF_DE); break;}
+    }
+
+
+    //**********************************Out***************************
+    TFile *outFile=new TFile("histo/SingleZ_ChioDE_E.root","recreate");
+    for(int i=0;i<Ncuts;i++) hChioDE_E[i]->Write();
+    outFile->Close();
+
+    TCanvas * can = new TCanvas(Form("ChioEbis_vs_ChioDE_run%04d_%04d",RunNumber[0],RunNumber[Nrun-1]),
+            Form("ChioEbis_vs_ChiodE_run%04d_%04d",RunNumber[0],RunNumber[Nrun-1]),
+            0,0,2000,1000);
+    can->cd(); gPad-> SetLogz();
+    hChioDE_E_all->Draw("colz");
+    for(int i = 0 ; i < Ncuts ; i++) cutZ[i]->Draw("same");
+}
+
+///////////////////////////////////////////////////////////////////////////
+void MakeSpline()
+{
+    TFile *inFile=new TFile("histo/SingleZ_ChioDE_E.root");
+
+    TSpline3 *gspline[Ncuts];  
+
+    TH2F* h2 [Ncuts];
+    TH1F* hProfile[Ncuts];
+    TH1F* pfx[Ncuts]; // extended hProfile 
+    TFile *fspline=new TFile("Output/spline_Chio_2024.root","recreate");
+
+    TCanvas * canfit = new TCanvas("canfit","canfit",0,0,2000,1500);
+
+    for(int i=0;i<Ncuts;i++)
+    {
+        // Get the 2D plot in TCutG
+        h2[i]=(TH2F*)inFile->Get(Form("hChioDE_E_%d",i+1));
+
+        // Create the TProfile
+        hProfile[i]=(TH1F*)h2[i]->ProfileX();
+        hProfile[i]->SetLineWidth(2);
+        hProfile[i]->SetDirectory(0);
+        canfit->cd();
+        if (i==0) {
+            hProfile[i]->GetYaxis()->SetRangeUser(5000,26000);
+            hProfile[i]->Draw();
+        }
+        else hProfile[i]->Draw("same");
+
+        // Get the range of the TProfile
+        int FirstBin, LastBin;
+        double parpol3[4];
+        for(int bin=1; bin<hProfile[i]->GetNbinsX(); bin++){
+            FirstBin = bin;
+            if (hProfile[i]->GetBinContent(bin)>6000) break;
+        }
+        double parpol1[2];
+        for(int bin=hProfile[i]->GetNbinsX(); bin>1 ; bin--){
+            LastBin = bin;
+            if (hProfile[i]->GetBinContent(bin)>6000) break;
+        }
+
+        // Create the extended TProfile
+        pfx[i] = new TH1F(Form("pfx_%02d",i+1),Form("pfx_%02d",i+1),hProfile[i]->GetNbinsX(),hProfile[i]->GetBinLowEdge(1),
+                hProfile[i]->GetBinLowEdge(hProfile[i]->GetNbinsX())+hProfile[i]->GetBinWidth(hProfile[i]->GetNbinsX()));
+        pfx[i]->SetLineColor(8);
+        pfx[i]->SetDirectory(0);
+
+        // find the function to extend the TProfile on the lower range
+        TF1 * fitpol3 = new TF1(Form("FitPol3_pfx_%02d",i+1),"pol3",hProfile[i]->GetBinLowEdge(FirstBin),hProfile[i]->GetBinLowEdge(FirstBin)+10000);
+        hProfile[i]->Fit(fitpol3,"R");
+        fitpol3->GetParameters(parpol3);
+
+        // find the function to extend the TProfile on the higher range
+        TF1 * fitpol1 = new TF1(Form("FitPol1_pfx_%02d",i+1),"pol1",hProfile[i]->GetBinLowEdge(LastBin)-10000,hProfile[i]->GetBinLowEdge(LastBin));
+        hProfile[i]->Fit(fitpol1,"R");
+        fitpol1->GetParameters(parpol1);
+
+        // fill the extended TProfile
+        float newval,lastval,lasterr;
+        for(int bin=1; bin<=FirstBin; bin++){
+            newval=0;
+            if(i < (Ncuts-4) && i!=0 && i!=1)
+                for(int par=0; par<4; par++) newval += parpol3[par]*pow(hProfile[i]->GetBinCenter(bin),par);
+            else if (i >= (Ncuts-4))
+                newval = hProfile[i]->GetBinContent(FirstBin);
+            else{
+                newval=0;
+                for(int par=0; par<2; par++) newval += parpol1[par]*pow(hProfile[i]->GetBinCenter(bin),par);
+                pfx[i]->SetBinContent(bin,newval);
+            }
+            pfx[i]->SetBinContent(bin,newval);
+        }
+        for(int bin=FirstBin; bin<=LastBin; bin++){
+            newval = hProfile[i]->GetBinContent(bin);
+            if (newval!=0){
+                pfx[i]->SetBinContent(bin,newval);
+                pfx[i]->SetBinError(bin,hProfile[i]->GetBinError(bin));
+                lastval = newval;
+                lasterr = hProfile[i]->GetBinError(bin);
+            }
+            else{
+                pfx[i]->SetBinContent(bin,lastval);
+                pfx[i]->SetBinError(bin,lasterr);
+            }
+        }
+        for(int bin=LastBin; bin<=hProfile[i]->GetNbinsX(); bin++){
+            newval=0;
+            for(int par=0; par<2; par++) newval += parpol1[par]*pow(hProfile[i]->GetBinCenter(bin),par);
+            pfx[i]->SetBinContent(bin,newval);
+        }
+        pfx[i]->Draw("same");
+
+        gspline[i]=new TSpline3(pfx[i]);
+        gspline[i]->SetName(Form("fspline_%d",i+1));
+        fspline->cd();
+        gspline[i]->Write();
+
+    }
+
+    fspline->Close();
+
+    TGraph * gr = new TGraph();
+    gr->SetName("DEvsZ");
+
+    TCanvas * can = new TCanvas("ChioEcorr_vs_Ebis_for_TSplines","ChioEcorr_vs_Ebis_for_TSplines",0,0,2500,2000);
+    can->cd();
+    ofstream ofile_par;
+    string filename_par = "Output/mean_spline_par.dat";
+    ofile_par.open(filename_par.c_str());
+    cout << "Float_t FF_DEcorr[" << Ncuts << "] = { " << endl; 
+    ofile_par << "Float_t FF_DEcorr[" << Ncuts << "] = { " << endl; 
+    for(int i=0;i<Ncuts;i++){
+        can->cd();
+        if(i==0) h2[i]->Draw("col");
+        else     h2[i]->Draw("col,same");
+        cout << h2[i]->GetMean(2) << ", " << endl;
+        ofile_par << h2[i]->GetMean(2) << ", " << endl;
+        //gr->SetPoint(i,sqrt(h2[i]->GetMean(2)),i+31);
+        gr->SetPoint(i,gspline[i]->Eval(8500),i+31);
+        //hProfile[i]->Draw("same");
+        pfx[i]->Draw("same");
+        gspline[i]->SetLineColor(kBlue);
+        gspline[i]->SetLineWidth(3);
+        gspline[i]->Draw("lsame");
+    }
+
+    TCanvas * cangr = new TCanvas("ToGetRoughCal","ToGetRoughCal",200,0,1200,1000);
+    cangr->cd();
+    gr->SetMarkerStyle(20);
+    gr->Draw("AP");
+    gr->Fit("pol2");
+}
+
+
+///////////////////////////////////////////////////////////////////////////
+void ApplySpline_perTCutG()
+{
+
+    // *************************Cut***************************
+    TFile *fcut=new TFile("Cut/Cut_Z.root");
+    TCutG *cutZ[Ncuts];
+
+    // ******************* TSpline DE*************************
+    TFile *fspline=new TFile("Output/spline_Chio_2024.root","read");
+    TSpline3 *gspline[Ncuts];  
+
+    for(int i=0;i<Ncuts;i++){ 
+        cutZ[i]=(TCutG*)fcut->Get(Form("Z%i",i+1));
+        gspline[i] = (TSpline3*)fspline->FindObjectAny(Form("fspline_%d",i+1));
+    }
+
+    // ****************** Spline Y **********************************
+    TFile *fSplineIC = new TFile("../YCalibration/Output/spline_P2P_2024.root","open"); 
+
+
+    vector<vector<TSpline3*>> Spline = LoadSpline("../YCalibration/Output/spline_P2P_2024.root");
+    vector<TSpline3*> spline_X(11), spline_Y(11);
+    spline_X = Spline.at(0) ; spline_Y = Spline.at(1);
+
+    //**********************DE_E****************************************************
+    TChain *chain=new TChain("PhysicsTree");
+    
+    chain->Add("../../../root/analysis/VamosCalib241.root");
+    
+    TICPhysics* IC = new TICPhysics() ;
+    double FF_IC_X, FF_IC_Y, FF_V13;
+    double FF_DE, FF_Eres;
+    
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC); 
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+
+    // variable after applying TSpline
+    double FF_DEcorr;
+    double FF_DEcorr0[Ncuts] = { 
+        7375.73, 
+        7982.83, 
+        8419.21, 
+        8801.52, 
+        9227.89, 
+        9667.77, 
+        10163.1, 
+        10680.5, 
+        11222.2, 
+        11758.3, 
+        12287.6, 
+        12802.2, 
+        13324.2, 
+        13828.4, 
+        14325.2, 
+        14773.7, 
+        15207.3, 
+        15674.6, 
+        16098.9, 
+        16548.5, 
+        16926.9, 
+        17384.1, 
+        17778.3, 
+        18196.6, 
+        18597.6, 
+        19043.9, 
+        19437.8, 
+        19889.4,}; 
+        // 20301.1, 
+        //20709.7, 
+        //21112.6, 
+        //21544, 
+        //21953.4, 
+        //22361.8};
+
+
+    TH2F *hChioDE_E_all  = new TH2F("hChioDE_E_all","hChioDE_E_all",1000,1000,41000,500,1000,26000);
+    TH2F *hChioDE_E      = new TH2F("hChioDE_E","hChioDE_E",1000,1000,41000,500,1000,26000);
+    TH2F *hChioDE_E_corr = new TH2F("hChioDE_E_corr","hChioDE_E_corr",1000,1000,41000,500,1000,26000);
+
+    int Nentries=chain->GetEntries();
+    auto start = std::chrono::high_resolution_clock::now();
+    
+    for(int e=0;e<Nentries;++e){
+        if (e % 100000  == 0 && e > 0 ) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+        }
+
+        chain->GetEntry(e);
+
+
+
+        vector<double> ICcorr_Y(NSegment), ICcorr_X(NSegment); // the [0] element of spline is the
+        vector<double> Temp_X(NSegment) , Temp_Y(NSegment);    // correction on the first
+                                                               // segment of ic
+        for (int seg = 1; seg < NSegment+1 ; seg++) {
+
+            if (seg == NSegment) seg = 0; //from 1to NSeg finishing with 0
+
+            if (spline_Y.at(seg)==0){
+                ICcorr_Y.at(seg) = IC->fIC_raw[seg]; 
+            }
+
+            else {
+                if (seg == 0) {
+                    Temp_Y.at(seg) = ICcorr_Y.at(1) / IC->fIC_raw[seg] * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(1) / Temp_Y.at(seg);
+                }
+
+                else if (seg == 1){ 
+                    ICcorr_Y.at(seg) = IC->fIC_raw[1]*spline_Y.at(1)->Eval(0)/spline_Y.at(1)->Eval(FF_IC_Y);
+                }
+
+                else if (seg > 1) {
+                    Temp_Y.at(seg) =  IC->fIC_raw[seg]/ICcorr_Y.at(seg-1) * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(seg-1) * Temp_Y.at(seg);
+                }
+
+                if (!(ICcorr_Y.at(seg)==ICcorr_Y.at(seg))) ICcorr_Y.at(seg) = 0;
+            } //end if non empty
+            if (seg == 0) break;
+        }//endloop seg
+
+
+        FF_DE = 0.5*( ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+        FF_Eres = 0 ;
+
+        for (int seg = 0 ;  seg < sizeof(IC->fIC_raw)/sizeof(IC->fIC_raw[0]) ; seg++ ){
+            if (seg >4){
+                FF_Eres += IC->fIC_raw[seg] ;
+                //Ecorr += ICcorr_Y.at(seg) ;
+            }
+        }
+
+        hChioDE_E_all->Fill(FF_Eres,FF_DE); 
+        for(int i=0;i<Ncuts;i++) if(cutZ[i]->IsInside(FF_Eres,FF_DE)) {
+            hChioDE_E->Fill(FF_Eres,FF_DE); 
+            FF_DEcorr = FF_DEcorr0[i] * FF_DE / gspline[i]->Eval(FF_Eres); 
+            hChioDE_E_corr->Fill(FF_Eres,FF_DEcorr); 
+            break;
+        }
+    }
+
+TCanvas * can = new TCanvas(Form("ChioEbis_vs_ChioDE_run%04d_%04d",RunNumber[0],RunNumber[Nrun-1]),
+        Form("ChioEbis_vs_ChiodE_run%04d_%04d",RunNumber[0],RunNumber[Nrun-1]),
+        0,0,2000,1000);
+can->Divide(1,3);
+can->cd(1); gPad-> SetLogz(); hChioDE_E_all->Draw("colz");
+can->cd(2); gPad-> SetLogz(); hChioDE_E->Draw("colz");
+can->cd(3); gPad-> SetLogz(); hChioDE_E_corr->Draw("colz");
+
+}
+
+///////////////////////////////////////////////////////////////////////////
+void ApplySpline()
+{
+    // *************************Cut***************************
+    TFile *fcut=new TFile("Cut/Cut_Z.root");
+    TCutG *cutZ[Ncuts];
+
+    // ******************* TSpline DE*************************
+    TFile *fspline=new TFile("Output/spline_Chio_2024.root","read");
+    TSpline3 *gspline[Ncuts];  
+
+    for(int i=0;i<Ncuts;i++){ 
+        cutZ[i]=(TCutG*)fcut->Get(Form("Z%i",i+1));
+        gspline[i] = (TSpline3*)fspline->FindObjectAny(Form("fspline_%d",i+1));
+    }
+
+    // ****************** Spline Y **********************************
+    TFile *fSplineIC = new TFile("../YCalibration/Output/spline_P2P_2024.root","open"); 
+
+
+    vector<vector<TSpline3*>> Spline = LoadSpline("../YCalibration/Output/spline_P2P_2024.root");
+    vector<TSpline3*> spline_X(11), spline_Y(11);
+    spline_X = Spline.at(0) ; spline_Y = Spline.at(1);
+
+    //**********************DE_E****************************************************
+    TChain *chain=new TChain("PhysicsTree");
+    
+    chain->Add("../../../root/analysis/VamosCalib241.root");
+    
+    TICPhysics* IC = new TICPhysics() ;
+    double FF_IC_X, FF_IC_Y, FF_V13;
+    double FF_DE, FF_Eres;
+    
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC); 
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+
+
+    // variable after applying TSpline
+    double FF_DEcorr=0;
+    double Zrough=0;
+    double Zabitbetter=0;
+
+    double FF_DEcorr0[Ncuts];
+    for(int index=0; index<Ncuts; index++){  
+        FF_DEcorr0[index] = gspline[index]->Eval(8500);
+    }
+    /*double FF_DEcorr0[Ncuts] = { 
+      7375.73, 
+      7982.83, 
+      8419.21, 
+      8801.52, 
+      9227.89, 
+      9667.77, 
+      10163.1, 
+      10680.5, 
+      11222.2, 
+      11758.3, 
+      12287.6, 
+      12802.2, 
+      13324.2, 
+      13828.4, 
+      14325.2, 
+      14773.7, 
+      15207.3, 
+      15674.6, 
+      16098.9, 
+      16548.5, 
+      16926.9, 
+      17384.1, 
+      17778.3, 
+      18196.6, 
+      18597.6, 
+      19043.9, 
+      19437.8, 
+      19889.4, 
+      20301.1, 
+      20709.7, 
+      21112.6, 
+      21544, 
+      21953.4, 
+      22361.8};*/
+
+    // histos
+    TH2F *hChioDE_E_all  = new TH2F("hChioDE_E_all","hChioDE_E_all",1000,1000,41000,500,1000,26000);
+    TH2F *hChioDE_E_corr = new TH2F("hChioDE_E_corr","hChioDE_E_corr",1000,1000,41000,500,1000,26000);
+    TH1F *hChioDE_corr   = new TH1F("hChioDE_corr","hChioDE_corr",2500,1000,26000);
+    TH2F *hChioZ_E_rough = new TH2F("hChioZ_E_rough","hChioZ_E_rough",1000,1000,41000,500,25,65); 
+    TH1F *hChioZ_rough = new TH1F("hChioZ_rough","hChioZ_rough",2500,25,65); 
+    TH1F *hChioZ_abitbetter = new TH1F("hChioZ_abitbetter","hChioZ_abitbetter",2500,25,65); 
+
+    int Nentries=1e6;//chain->GetEntries();
+    auto start = std::chrono::high_resolution_clock::now();
+
+    double FF_Eres_prev = 0;
+    for(int e=0;e<Nentries;e++)
+    {
+        if (e % 100000  == 0 && e > 0 ) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+        }
+
+        FF_DEcorr = -100;
+        chain->GetEntry(e);
+
+        //===========================================================================================================
+        //                           Splined Y
+        //===========================================================================================================
+        vector<double> ICcorr_Y(NSegment), ICcorr_X(NSegment); // the [0] element of spline is the
+        vector<double> Temp_X(NSegment) , Temp_Y(NSegment);    // correction on the first
+                                                               // segment of ic
+        for (int seg = 1; seg < NSegment+1 ; seg++) {
+
+            if (seg == NSegment) seg = 0; //from 1to NSeg finishing with 0
+
+            if (spline_Y.at(seg)==0){
+                ICcorr_Y.at(seg) = IC->fIC_raw[seg]; 
+            }
+
+            else {
+                if (seg == 0) {
+                    Temp_Y.at(seg) = ICcorr_Y.at(1) / IC->fIC_raw[seg] * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(1) / Temp_Y.at(seg);
+                }
+
+                else if (seg == 1){ 
+                    ICcorr_Y.at(seg) = IC->fIC_raw[1]*spline_Y.at(1)->Eval(0)/spline_Y.at(1)->Eval(FF_IC_Y);
+                }
+
+                else if (seg > 1) {
+                    Temp_Y.at(seg) =  IC->fIC_raw[seg]/ICcorr_Y.at(seg-1) * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(seg-1) * Temp_Y.at(seg);
+                }
+
+                if (!(ICcorr_Y.at(seg)==ICcorr_Y.at(seg))) ICcorr_Y.at(seg) = 0;
+            } //end if non empty
+            if (seg == 0) break;
+        }//endloop seg
+
+
+        FF_DE = 0.5*( ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+        FF_Eres = 0 ;
+
+        for (int seg = 0 ;  seg < sizeof(IC->fIC_raw)/sizeof(IC->fIC_raw[0]) ; seg++ ){
+            if (seg >4){
+                FF_Eres += IC->fIC_raw[seg] ;
+                //Ecorr += ICcorr_Y.at(seg) ;
+            }
+        }
+
+        //===========================================================================================================
+        //                              Spline DE
+        //===========================================================================================================&
+
+
+        if (FF_DE<3000) continue;
+        if(FF_Eres==FF_Eres_prev) continue;
+        FF_Eres_prev = FF_Eres;
+
+        hChioDE_E_all->Fill(FF_Eres,FF_DE);
+
+        float Eval_DEspline, DEspline0;
+        int   index=0;
+        for(int i=0; i<Ncuts; i++){
+            Eval_DEspline = gspline[i]->Eval(FF_Eres); 
+            if(FF_DE<Eval_DEspline) break;
+            index = i;
+        }
+
+        Eval_DEspline = gspline[index]->Eval(FF_Eres);
+        DEspline0 = FF_DEcorr0[index];
+        float dmin, dsup;
+        if( index < (Ncuts-1) && FF_DE > gspline[0]->Eval(FF_Eres)){
+            dmin = FF_DE-gspline[index]->Eval(FF_Eres);
+            dsup = gspline[index+1]->Eval(FF_Eres)-FF_DE;
+            if(dmin<0) cout << "negative value of dmin = " << dmin << ", for index = " << index << endl;
+            if(dsup<0) cout << "negative value of dsup = " << dsup << ", for index = " << index << endl;
+            //if(dsup<dmin) {
+            //  Eval_DEspline = gspline[index+1]->Eval(FF_Eres) ;
+            //  DEspline0 = FF_DEcorr0[index] ;
+            //}
+            Eval_DEspline = dsup*gspline[index]->Eval(FF_Eres)/(dmin+dsup) + dmin*gspline[index+1]->Eval(FF_Eres)/(dmin+dsup) ;
+            DEspline0 = dsup*FF_DEcorr0[index]/(dmin+dsup) + dmin*FF_DEcorr0[index+1]/(dmin+dsup) ;
+
+            FF_DEcorr = DEspline0 * FF_DE / Eval_DEspline ;
+            hChioDE_E_corr->Fill(FF_Eres,FF_DEcorr);
+            //if(FF_DEcorr>15120 && FF_DEcorr<15130) {
+            //  cout << e << " " << index << " " << FF_Eres << " " << FF_DEcorr << endl;
+            //}
+        }
+
+        // should be pol2 !!!
+        //Zrough = -110.165 + 3.34475*sqrt(FF_DEcorr) - 0.0271123*FF_DEcorr + 8.60752e-05 * pow(sqrt(FF_DEcorr),3);
+        Zrough = 16.8521 + 0.0017328*FF_DEcorr + 1.70774e-8*pow(FF_DEcorr,2);
+        Zabitbetter = -127.117 + 3.83463*sqrt(FF_DEcorr) - 0.0317448 *FF_DEcorr + 0.000100428 * pow(sqrt(FF_DEcorr),3);
+        hChioZ_E_rough->Fill(FF_Eres,Zrough);
+
+        if(3000<FF_Eres && FF_Eres<25000){ 
+            hChioDE_corr->Fill(FF_DEcorr);
+            hChioZ_rough->Fill(Zrough);
+            hChioZ_abitbetter->Fill(Zabitbetter);
+        }
+    }
+
+    TCanvas * can = new TCanvas(Form("ChioEbis_vs_ChioDE_run%04d_%04d",RunNumber[0],RunNumber[Nrun-1]),
+            Form("ChioEbis_vs_ChiodE_run%04d_%04d",RunNumber[0],RunNumber[Nrun-1]),
+            0,0,2000,2000);
+    can->Divide(1,3);
+    can->cd(1); gPad-> SetLogz(); hChioDE_E_all->Draw("colz");
+    for(int i = 0 ; i < Ncuts ; i++) cutZ[i]->Draw("same");
+    can->cd(2); gPad-> SetLogz(); hChioDE_E_corr->Draw("colz");
+    can->cd(3); gPad-> SetLogz(); hChioZ_E_rough->Draw("colz");
+
+    TCanvas * can1D = new TCanvas(Form("DE_and_Z_ifE_8000to25000_run%04d_%04d",RunNumber[0],RunNumber[Nrun-1]),
+            Form("DE_and_Z_ifE_8000to25000_run%04d_%04d",RunNumber[0],RunNumber[Nrun-1]),
+            0, 0, 2000,2000);
+    can1D->Divide(1,3);
+    can1D->cd(1);  hChioDE_corr->Draw(); 
+    can1D->cd(2);  hChioZ_rough->Draw();
+    can1D->cd(3);  hChioZ_abitbetter->Draw();
+
+    TFile * fsave = new TFile(Form("Output/DEvsE_corr_run%04d_%04d.root",RunNumber[0],RunNumber[Nrun-1]),"recreate");  
+    can->Write();
+    hChioDE_E_all->Write();
+    hChioDE_E_corr->Write();
+    hChioZ_E_rough->Write();
+    can1D->Write();
+    hChioDE_corr->Write();
+    hChioZ_rough->Write();
+    hChioZ_abitbetter->Write();
+    fsave->Close();
+}
+
+///////////////////////////////////////////////////////////////////////////
+void Fit_DE_E_corr()
+{
+
+    TFile * f = new TFile(Form("Output/DEvsE_corr_run%04d_%04d.root",RunNumber[0],RunNumber[Nrun-1]),"read");
+    f->ls();
+    TH1F * h1DEcorr = (TH1F*)f->Get("hChioDE_corr");
+    h1DEcorr->SetDirectory(0);
+    f->Close();
+
+    TCanvas * canfit = new TCanvas("DEcorrforfit","Decorrforfit",0,0,3000,1000);
+    canfit->Divide(2,1);
+    canfit->cd(1);   h1DEcorr->Draw();
+
+    float InitMean[34] = {
+        7.55521e+03,     7.82392e+03,    8.04283e+03,     8.36164e+03,   
+        8.68128e+03,     9.06218e+03,    9.44613e+03,     9.82352e+03,   
+        1.02433e+04,     1.06666e+04,    1.11215e+04,     1.15371e+04,   
+        1.20246e+04,     1.24492e+04,    1.29190e+04,     1.34056e+04,   
+        1.38367e+04,     1.42968e+04,    1.46816e+04,     1.51614e+04,   
+        1.55115e+04,     1.58873e+04,    1.63049e+04,     1.66187e+04,   
+        1.69730e+04,     1.73969e+04,    1.76965e+04,     1.80730e+04,   
+        1.85234e+04,     1.88849e+04,    1.92127e+04,     1.96378e+04,   
+        1.99820e+04,     2.02914e+04
+    };
+
+    float InitSigma[34] = {
+        6.97215e+01,    7.76394e+01,    7.84506e+01,    8.23239e+01, 
+        9.25943e+01,    1.06154e+02,    1.03566e+02,    1.02429e+02, 
+        1.10066e+02,    1.15032e+02,    1.20449e+02,    1.15397e+02, 
+        1.30322e+02,    1.29513e+02,    1.45757e+02,    1.53552e+02, 
+        1.48061e+02,    1.49866e+02,    1.60311e+02,    1.56691e+02, 
+        1.55461e+02,    1.78093e+02,    1.66829e+02,    1.67863e+02, 
+        1.75509e+02,    1.75189e+02,    1.70589e+02,    1.76178e+02, 
+        1.65192e+02,    1.87470e+02,    1.78153e+02,    1.58322e+02, 
+        1.53678e+02,    1.97134e+02
+    };
+
+    char name[1000];
+    TString totname;
+    for(int i=0; i<34;i++){
+        sprintf(name,"%i",i*3);
+        totname += "gaus(" + TString(name) + ")+";
+    }  
+    totname.Remove(totname.Last('+'));
+    TF1 * gtot = new TF1("MultiGaussianFit",totname,InitMean[0]-2*InitSigma[0],InitMean[33]+2*InitSigma[33]);
+
+    for(int i=0; i<34;i++){
+        gtot->SetParameter(i*3+1,InitMean[i]); 
+        gtot->SetParameter(i*3+2,InitSigma[i]); 
+    }  
+    h1DEcorr->Fit(gtot,"R+");
+
+    TGraph * gr = new TGraph();
+    gr->SetName("DEfit_vs_Z");
+    gr->SetMarkerStyle(20);
+    for(int i=0; i<33; i++){
+        gr->SetPoint(i,sqrt(gtot->GetParameter(i*3+1)),i+32); 
+    }
+
+    canfit->cd(2); gr->Draw("AP");
+
+}
+
+
+vector<vector<TSpline3*>> LoadSpline(const char* PathToSpline){
+    TFile *fSplineIC = new TFile(PathToSpline,"open"); 
+    // Get number of spline
+    int SplineCount = 0 ;
+    TIter next(fSplineIC->GetListOfKeys());
+    TKey* key;
+
+    while ((key=(TKey*)next())){
+        if (std::string(key->GetClassName()) == "TSpline3"){
+            SplineCount ++;
+        }
+    }
+
+    vector<vector<TSpline3*>> Spline;
+    vector<TSpline3*> spline_X(11), spline_Y(11);
+    for (int i = 0; i < SplineCount  ; i++) {
+        int seg = int((i-2)/2 +1 );
+        if (i < 2){
+            spline_X.at(0) = (TSpline3 *)fSplineIC->Get("fspline_IC0_X");
+            spline_Y.at(0) = (TSpline3 *)fSplineIC->Get("fspline_IC0_Y");
+        }
+
+        else if ( i>=2 && i<4){ 
+            spline_X.at(1) = (TSpline3 *)fSplineIC->Get("fspline_IC1_X");
+            spline_Y.at(1) = (TSpline3 *)fSplineIC->Get("fspline_IC1_Y");
+        }
+        else if (seg >=2 && (i%2 == 0) ) {
+            spline_X.at(seg) = (TSpline3 *)fSplineIC->Get(Form("fspline_IC%d_X",seg));
+        }
+        else if (seg >=2 && !(i%2 == 0) ) {	
+            spline_Y.at(seg) = (TSpline3 *)fSplineIC->Get(Form("fspline_IC%d_Y",seg));
+        }
+    } //End loop on histogram
+
+    Spline.push_back(spline_X);
+    Spline.push_back(spline_Y);
+
+    return Spline;
+}
diff --git a/Projects/AlPhaPha/2024/macro/chio/charge.cal b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/charge.cal
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/chio/charge.cal
rename to Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/charge.cal
diff --git a/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/histo/ReadMe.md b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/histo/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..ad679641bc5f7248cfd099b9876816d918264951
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/DE_E_Spline/histo/ReadMe.md
@@ -0,0 +1,4 @@
+# Histo Holder
+
+this directory exist to hold some histogram generated by the macro
+
diff --git a/Projects/AlPhaPha/2024/macro/chio/XYCalibration/VerifCorrelation.C b/Projects/AlPhaPha/2024/macro/chio/XYCalibration/VerifCorrelation.C
new file mode 100644
index 0000000000000000000000000000000000000000..c386bbdcb379fd8c03b08ebfcb3c739389d12f48
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/XYCalibration/VerifCorrelation.C
@@ -0,0 +1,101 @@
+#include "TICPhysics.h"
+#include "TTimeData.h"
+#include <TChain.h>
+#include <TH2.h>
+#include <TH3.h>
+
+vector<double> TxtToVector(const char *Path);
+
+void VerifCorrelation(){
+
+    //===========================================================================================================
+    //                           Loading var
+    //===========================================================================================================
+    TChain* chain = new TChain("PhysicsTree");
+    chain->Add("../../../root/analysis/VamosCalib247.root");
+
+    TTimeData *Time = new TTimeData();
+    TICPhysics* IC = new TICPhysics() ;
+    double FF_IC_X, FF_IC_Y, FF_V13, FF_DriftTime;
+
+  
+    vector<double> Toff13 , Toff14, Toff23, Toff24;
+    const char* Path13 = "../../../mwpc/Toff/output/Toff13.txt";
+    const char* Path14 = "../../../mwpc/Toff/output/Toff14.txt";
+    const char* Path23 = "../../../mwpc/Toff/output/Toff23.txt";
+    const char* Path24 = "../../../mwpc/Toff/output/Toff24.txt";
+
+    Toff13 = TxtToVector(Path13);
+    Toff14 = TxtToVector(Path14);
+    Toff23 = TxtToVector(Path23);
+    Toff24 = TxtToVector(Path24);
+
+
+    chain->SetBranchStatus("FF_IC_X", true);
+    chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC);
+
+    chain->SetBranchStatus("Time", true);
+    chain->SetBranchAddress("Time", &Time);
+
+    
+    TH2F *ICXY = new TH2F("ICXY","ICXY",1000,-1000,1000,1000,-1000,1000);
+ 
+    int Nentries = chain->GetEntries();
+    //int Nentries = 1000000;
+    auto start = std::chrono::high_resolution_clock::now();
+
+    for (int e = 0; e < Nentries; e++) {
+        if (e % 100000  == 0 && e > 0 ) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+        }
+
+        chain->GetEntry(e);
+
+
+        if(Time->GetMWPC13Mult()==1 && IC->fIC_raw[8] >0){
+            UShort_t FPMW_Section = Time->GetSection_MWPC3(0);
+            FF_DriftTime = 10* (IC->fIC_TS.at(0) - Time->GetTS_MWPC13(0)) - ((Time->GetTime_MWPC13(0)+Toff13.at(FPMW_Section))) ;
+
+
+            double ICRatio =  IC->fIC_raw[0]/IC->fIC_raw[1];
+
+            if(IC->fIC_raw[8] >0 ) {
+                ICXY->Fill(FF_IC_X,FF_IC_Y,ICRatio);
+            }
+        }
+    }
+    TCanvas *c = new TCanvas("c","c");
+    ICXY->SetMinimum(0);
+    ICXY->Draw("surf");
+}
+
+vector<double> TxtToVector(const char *Path){
+    string line;
+    vector<double> values;
+    ifstream file(Path); 
+
+    if (file.is_open()) {
+        while (std::getline(file, line)) {
+            try {
+                values.push_back(std::stod(line));
+            } catch (const std::invalid_argument& e) {
+                std::cerr << "Invalid number in line: " << line << '\n';
+            }
+        }
+        file.close();
+    } else {
+        std::cerr << "Error opening file.\n";
+    }
+
+    return values;
+}
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C
new file mode 100644
index 0000000000000000000000000000000000000000..2b4463b219c2d96a623bbb7a2d64441778a3dfed
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/DECorr.C
@@ -0,0 +1,450 @@
+#include <TICPhysics.h>
+#include <TCanvas.h>
+#include <TChain.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TH2.h>
+#include <TSpline.h>
+#include <TCutG.h>
+#include <fstream>
+#include <vector>
+
+using namespace std;
+
+int GetNumberKey(TFile *infile ,const char* ClassName);
+
+TSpline3* MakeSpline(TH2F* hInput, Int_t NCallee, double XMin , double
+    XMax, double YMin, double YMax);
+//////////////////////////////////////////////////////////////////////////////////////////
+void DECorr(bool cut = false, bool spline = false) {
+    //===========================================================================================================
+    //                           Loading var
+    //===========================================================================================================
+    TChain* chain = new TChain("PhysicsTree");
+    chain->Add("../../../root/analysis/VamosCalib247.root");
+
+    TICPhysics* IC = new TICPhysics() ;
+    double FF_IC_X, FF_IC_Y, FF_V13;
+
+    chain->SetBranchStatus("FF_IC_X", true);
+    chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC); 
+    chain->SetBranchStatus("FF_V13", true);
+    chain->SetBranchAddress("FF_V13", &FF_V13); 
+
+    TCutG *CutZ;
+    TCutG *CutZbis;
+    TFile *fCut;
+    if (cut) {
+        fCut =  TFile::Open("Output/CutDeCorr.root");
+        CutZbis = (TCutG*)fCut->Get("CutZbis") ;
+        CutZ = (TCutG*)fCut->Get("CutZ") ;
+    }
+
+    TFile *fSpline, *fSplineIC; 
+    TSpline3 *splineDEcorr, *splineDEbis;
+    fSpline= new TFile("Output/splineDE.root","open");
+    splineDEcorr = (TSpline3*) fSpline->Get("SplineDe_0");
+    splineDEbis = (TSpline3*) fSpline->Get("SplineDebis");
+    
+    vector<TSpline3*> vsplineDE;
+    // Get number of spline
+    int SplineCountDe = 0 ;
+    TIter next1(fSpline->GetListOfKeys());
+    TKey* key1;
+
+    while ((key1=(TKey*)next1())){
+        if (std::string(key1->GetClassName()) == "TSpline3"){
+            SplineCountDe ++;
+        }
+    }
+
+
+    //Fill spline vector
+    for (int i =0 ; i<SplineCountDe ; i++){
+        vsplineDE.push_back((TSpline3*) fSpline->Get(Form("SplineDe_%d",i)));
+    }
+
+    //empty backup one
+    for (int i =0 ; i<SplineCountDe ; i++){
+        if (vsplineDE[i]==nullptr) vsplineDE.erase(vsplineDE.begin()+i);
+    }
+
+
+    fSplineIC = new TFile("Output/spline_P2P_2024.root","open"); 
+    // Get number of spline
+    int SplineCount = 0 ;
+    TIter next(fSplineIC->GetListOfKeys());
+    TKey* key;
+
+    while ((key=(TKey*)next())){
+        if (std::string(key->GetClassName()) == "TSpline3"){
+            SplineCount ++;
+        }
+    }
+
+
+    vector<TSpline3*> spline_X(11), spline_Y(11);
+    for (int i = 0; i < SplineCount  ; i++) {
+        int seg = int((i-2)/2 +1 );
+        if (i < 2){
+            spline_X.at(0) = (TSpline3 *)fSplineIC->Get("fspline_IC0_X");
+            spline_Y.at(0) = (TSpline3 *)fSplineIC->Get("fspline_IC0_Y");
+        }
+
+        else if ( i>=2 && i<4){ 
+            spline_X.at(1) = (TSpline3 *)fSplineIC->Get("fspline_IC1_X");
+            spline_Y.at(1) = (TSpline3 *)fSplineIC->Get("fspline_IC1_Y");
+        }
+        else if (seg >=2 && (i%2 == 0) ) {
+            spline_X.at(seg) = (TSpline3 *)fSplineIC->Get(Form("fspline_IC%d_X",seg));
+        }
+        else if (seg >=2 && !(i%2 == 0) ) {	
+            spline_Y.at(seg) = (TSpline3 *)fSplineIC->Get(Form("fspline_IC%d_Y",seg));
+        }
+    } //End loop on histogram
+
+    //Defining output histo
+    TH2F* hDE_E = new TH2F("DE_E","DE_E",1000,0,22000,1000,0,28000);
+    TH2F* hDE_E_splined = new TH2F("DE_E_splined","DE_E_splined",1000,0,22000,1000,0,28000);
+    TH2F* hDE_Ebis = new TH2F("DE_Ebis","DE_Ebis",1000,0,22000,1000,0,24000);
+
+
+    TH2F* hDE_Y = new TH2F("DE_Y","DE_Y",1000,-100,100,1000,0,22000);
+    TH2F* hDE_Y_splined = new TH2F("DE_Ysplined","DE_Ysplined",1000,-100,100,1000,0,22000);
+    TH2F* hDE_Y_splined_nocut = new TH2F("DE_Ysplined_nocut","DE_Ysplined_nocut",1000,-100,100,1000,0,22000);
+    TH2F* hIC_Y = new TH2F("IC_Y","IC_Y",1000,-100,100,1000,0,22000);
+    TH2F* hIC_Y_splined = new TH2F("IC_Ysplined","IC_Ysplined",1000,-100,100,1000,0,22000);
+
+
+    TH2F* hDE_Y_corr = new TH2F("DE_Ycorr","DE_Ycorr",1000,-100,100,1000,0,22000);
+    TH2F* hDE_Y_corr_nocut = new TH2F("DE_Ycorr_nocut","DE_Ycorr_nocut",1000,-100,100,1000,0,22000);
+
+    TH2F* hDE_Y_bis = new TH2F("DE_Ybis","DE_Ybis",1000,-100,100,1000,0,22000);
+    TH2F* hDEbis_Y_corr = new TH2F("DE_Ybiscorr","DE_Ybiscorr",1000,-100,100,1000,0,22000);
+
+    TH2F* hDE_E_corr = new TH2F("DE_Ecorr","DE_Ecorr",1000,0,22000,1000,0,28000);
+    TH2F* hDE_Ebis_corr = new TH2F("DE_Ebiscorr","DE_Ebiscorr",1000,0,22000,1000,0,24000);
+    TH2F* hDE_E_Recur = new TH2F("DE_E_Recur","DE_E_Recur",1000,0,22000,1000,0,28000);
+
+    TH2F* hDE_V = new TH2F("DE_V","DE_V",1000,0,5,1000,0,28000);
+
+    // Def Lim spline
+    double Ymin = -100 , Ymax =100;
+    //===========================================================================================================
+    //                                        Event Loop
+    //===========================================================================================================
+    int Nentries = chain->GetEntries();
+    //int Nentries = 10000000;
+    auto start = std::chrono::high_resolution_clock::now();
+    int NSegment = 5 ;
+
+    for (int e = 0; e < Nentries; e++) {
+        if (e % 100000  == 0 && e > 0 ) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+        }
+
+        chain->GetEntry(e);
+
+        vector<double> ICcorr_Y(NSegment), ICcorr_X(NSegment); // the [0] element of spline is the
+        vector<double> Temp_X(NSegment) , Temp_Y(NSegment);    // correction on the first
+                                                               // segment of ic
+        for (int seg = 1; seg < NSegment+1 ; seg++) {
+
+            if (seg == NSegment) seg = 0; //from 1to NSeg finishing with 0
+
+            if (spline_Y.at(seg)==0){
+                ICcorr_Y.at(seg) = IC->fIC_raw[seg]; 
+            }
+
+            else {
+                if (seg == 0) {
+                    Temp_Y.at(seg) = ICcorr_Y.at(1) / IC->fIC_raw[seg] * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(1) / Temp_Y.at(seg);
+                }
+
+                else if (seg == 1){ 
+                    ICcorr_Y.at(seg) = IC->fIC_raw[1]*spline_Y.at(1)->Eval(0)/spline_Y.at(1)->Eval(FF_IC_Y);
+                }
+
+                else if (seg > 1) {
+                    Temp_Y.at(seg) =  IC->fIC_raw[seg]/ICcorr_Y.at(seg-1) * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(seg-1) * Temp_Y.at(seg);
+                }
+
+                if (!(ICcorr_Y.at(seg)==ICcorr_Y.at(seg))) ICcorr_Y.at(seg) = 0;
+            } //end if non empty
+            if (seg == 0) break;
+        }//endloop seg
+
+
+        double DE = 0 , DE_splined=0 ,DE_corr=0, DE_Ybis=0, DE_Y_Recur=0;
+        double E =0, Ecorr=0; 
+        for (int seg = 0 ;  seg < sizeof(IC->fIC_raw)/sizeof(IC->fIC_raw[0]) ; seg++ ){
+            if (seg >4){
+                E += IC->fIC_raw[seg] ;
+                //Ecorr += ICcorr_Y.at(seg) ;
+            }
+        }
+
+
+
+        // ********************* DE setter *********************
+        double IC1corr = (IC->fIC_raw[1]*(1-0.000686068*FF_IC_Y))*(1-4.88238e-05*FF_IC_Y+7.40395e-06*FF_IC_Y*FF_IC_Y);
+        double DE_Bis = 0.5*(IC1corr+IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+
+        DE = 0.5*(IC->fIC_raw[0]+ IC->fIC_raw[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+        DE_splined = 0.5*(ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+        //DE_splined = 0.5*( ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+        
+
+        //************* Cut ******************
+        bool CutV = abs( FF_V13-3.94)<0.01;
+        bool CutVbis =  abs( FF_V13-3.94)<0.01;
+        
+        //bool CutV = true;
+        //bool CutVbis =  true;
+       
+        //***********Fill histo*************
+
+        if (FF_IC_Y >Ymin && FF_IC_Y <Ymax ){
+            
+            //*************Init DE_E***************** 
+            hDE_E->Fill(E,DE);
+            hDE_E_splined->Fill(E,DE_splined);
+            hDE_Ebis->Fill(E,DE_Bis);
+
+            hDE_V->Fill(FF_V13,DE);    
+
+            //******* Coor DE ************
+            if (spline== true  ){     
+                DE_corr = DE_splined * splineDEcorr->Eval(0) / splineDEcorr->Eval(FF_IC_Y);
+                hDE_E_corr->Fill(E,DE_corr);
+
+                DE_Ybis = DE_Bis * splineDEbis->Eval(0) / splineDEbis->Eval(FF_IC_Y);
+                hDE_Ebis_corr->Fill(E,DE_Ybis); 
+
+                DE_Y_Recur = DE_splined;
+
+                for (int i=0; i<vsplineDE.size() ; i++){
+                    DE_Y_Recur = DE_Y_Recur * vsplineDE.at(i)->Eval(0) / vsplineDE.at(i)->Eval(FF_IC_Y);
+                }
+                hDE_E_Recur->Fill(E,DE_Y_Recur);    
+            }   
+                
+            else {
+                DE_corr = DE_splined;
+                hDE_E_corr->Fill(E,DE_corr);
+
+                DE_Ybis = DE_Bis ;
+                hDE_Ebis_corr->Fill(E,DE_Ybis);  
+            }
+
+            bool CutCharge;
+            if (cut == true) {
+                CutCharge   =  CutZ->IsInside(FF_V13,DE);
+            }
+            //bool CutChargeBis =  CutZ->IsInside(E,DE_Y_Recur);
+            //bool CutVbis =  CutZbis->IsInside(E,DE_Bis);
+            // DE_Y in a cut
+            
+            hDE_Y_corr_nocut->Fill(FF_IC_Y,DE);
+            hDE_Y_splined_nocut->Fill(FF_IC_Y,DE_splined);
+            if (cut == true ) {
+                if (CutV && CutCharge){ 
+                    hDE_Y->Fill(FF_IC_Y,DE);
+                    hDE_Y_splined->Fill(FF_IC_Y,DE_splined); 
+                    hDE_Y_corr->Fill(FF_IC_Y,DE_corr);
+
+                    hIC_Y->Fill(FF_IC_Y,IC->fIC_raw[1]);
+                    hIC_Y_splined->Fill(FF_IC_Y,ICcorr_Y.at(1));
+                }
+            }//end cut
+            else {
+                hDE_Y->Fill(FF_IC_Y,DE);
+                hDE_Y_splined->Fill(FF_IC_Y,DE_splined); 
+                hDE_Y_corr->Fill(FF_IC_Y,DE_corr);
+
+                hIC_Y->Fill(FF_IC_Y,IC->fIC_raw[1]);
+                hIC_Y_splined->Fill(FF_IC_Y,ICcorr_Y.at(1));}
+
+            if (cut == true && CutVbis) {
+                hDE_Y_bis->Fill(FF_IC_Y,DE_Bis);
+                hDEbis_Y_corr->Fill(FF_IC_Y,DE_Ybis);
+            }
+            else{;}
+            //end cut
+        }//end cond Y
+    } //endl loop event
+
+    // making spline
+
+    TSpline3 *splineDE, *osplineDEbis;
+    if (spline == true){
+        splineDE = MakeSpline(hDE_Y_splined,0,Ymin,Ymax,0,23000); 
+        osplineDEbis = MakeSpline(hDE_Y_bis,1,Ymin,Ymax,0,23000); 
+        TFile *fSpline = new TFile("Output/splineDE.root","recreate");
+        splineDE->SetName("SplineDe_0");
+        splineDE->Write();
+        osplineDEbis->SetName("SplineDebis");
+        osplineDEbis->Write(); 
+        fSpline->Close();
+    }
+    //===========================================================================================================
+    //                                          Drawing histo
+    //===========================================================================================================
+
+    TCanvas* c = new TCanvas("c","c",1500,1000);
+    c->Divide(2,2);
+    c->cd(1);
+    gPad->SetLogz();
+    hDE_Y->ProfileX()->Draw();
+    c->cd(2);
+    gPad->SetLogz();
+    hDE_Y_splined->ProfileX()->Draw();
+    c->cd(3);
+    gPad->SetLogz();
+    hIC_Y->ProfileX()->Draw();
+    c->cd(4);
+    gPad->SetLogz();
+    hIC_Y_splined->ProfileX()->Draw();
+
+    TCanvas *c4 = new TCanvas("c4","c4",1500,1000);
+    c4->Divide(2);
+    c4->cd(1);
+    hDE_Y_splined_nocut->ProfileX()->Draw();
+    c4->cd(2);
+    hDE_Y_corr_nocut->ProfileX()->Draw();
+
+
+
+    TCanvas *c1 = new TCanvas("c1","c1",1500,1000);
+    hDE_V->Draw();
+
+    TCanvas* c2 = new TCanvas("c2","c2",1500,1000);
+    c2->Divide(2 + 3*spline);
+    c2->cd(1);
+    gPad->SetLogz();
+    hDE_E->Draw();
+    c2->cd(2);
+    gPad->SetLogz();
+    hDE_Ebis->Draw();
+    if (spline){
+        c2->cd(3);
+        gPad->SetLogz();
+        hDE_E_splined->Draw();
+        c2->cd(4);
+        gPad->SetLogz();
+        hDE_E_corr->Draw();   
+        c2->cd(5);
+        gPad->SetLogz();
+        hDE_Ebis_corr->Draw();
+    }
+} // End spline chio XY
+
+
+int GetNumberKey(TFile *infile ,const char* ClassName){
+    // Get number of spline
+    int KeyCount = 0 ;
+    TIter next(infile->GetListOfKeys());
+    TKey* keyFit;
+
+    while ((keyFit=(TKey*)next())){
+        if (std::string(keyFit->GetClassName()) == ClassName){
+            KeyCount ++;
+        }
+    }
+
+    return KeyCount;
+
+}
+
+TSpline3* MakeSpline(TH2F* hInput, Int_t NCallee, double XMin = 0 , double
+        XMax = 1000 , double YMin=0 , double YMax = 100) {
+
+    TSpline3* gspline;
+
+    TH1F* hProfile;
+    TH1F* pfx; // extended hProfile
+
+    TCanvas* canfit = new TCanvas(Form("CanSpline_%02d",NCallee),
+            Form("canfit_%02d",NCallee), 0, 0, 1000, 500);
+
+
+    //===========================================================================================================
+    //                                            Init profile
+    //===========================================================================================================
+
+    // Create the TProfile
+    hProfile = (TH1F*)hInput->ProfileX();
+    hProfile->SetLineWidth(2);
+    hProfile->SetDirectory(0);
+    canfit->cd();
+
+    hProfile->GetYaxis()->SetRangeUser(YMin, YMax);
+    hProfile->Draw();
+    //===========================================================================================================
+    //                                          First and last bin to get to 6k
+    //                                          event get promoted
+    //===========================================================================================================
+    int FirstBin, LastBin;
+    double Treshold = 0;
+    for (int bin =1 ; bin<hProfile->GetNbinsX(); bin++) {
+        FirstBin = bin;
+        if (hProfile->GetBinLowEdge(bin)> XMin) break;
+    }
+    for (int bin = hProfile->GetNbinsX(); bin>1 ; bin--) {
+        LastBin = bin;
+        if (hProfile->GetBinLowEdge(bin)< XMax) break;
+    }
+    //===========================================================================================================
+    //                                          Init Extended profile function
+    //===========================================================================================================
+    // Create the extended TProfile
+    pfx = new TH1F(
+            Form("pfx_%02d", Int_t(NCallee/2)), Form("pfx_%02d", Int_t(NCallee/2)), hProfile->GetNbinsX(), hProfile->GetBinLowEdge(1),
+            hProfile->GetBinLowEdge(hProfile->GetNbinsX()) + hProfile->GetBinWidth(hProfile->GetNbinsX()));
+    pfx->SetLineColor(8);
+    pfx->SetDirectory(0);
+    //===========================================================================================================
+    //                                           Fill extended profile
+    //===========================================================================================================
+
+    // fill the extended TProfile
+    float newval, lastval, lasterr;
+    for (int bin = 1; bin <= FirstBin; bin++) {
+        newval = 0;
+        pfx->SetBinContent(bin, newval);
+    }
+
+
+    for (int bin = FirstBin; bin <= LastBin; bin++) {
+        newval = hProfile->GetBinContent(bin);
+        if (newval != 0) {
+            pfx->SetBinContent(bin, newval);
+            pfx->SetBinError(bin, hProfile->GetBinError(bin));
+            lastval = newval;
+            lasterr = hProfile->GetBinError(bin);
+        }
+        else {
+            pfx->SetBinContent(bin, lastval);
+            pfx->SetBinError(bin, lasterr);
+        }
+    }
+    pfx->Draw("same");
+
+    gspline = new TSpline3(pfx);
+    gspline->SetName(Form("fspline_%d", NCallee + 1));
+
+    return gspline;
+
+} // end makespline
+
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/ICCorr.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/ICCorr.C
new file mode 100644
index 0000000000000000000000000000000000000000..e22d6395fb29995581f1f1151fd93777ed10f017
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/ICCorr.C
@@ -0,0 +1,244 @@
+#include <TICPhysics.h>
+#include <TCanvas.h>
+#include <TChain.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TH2.h>
+#include <TSpline.h>
+#include <fstream>
+#include <vector>
+
+using namespace std;
+
+int GetNumberKey(TFile *infile ,const char* ClassName);
+//////////////////////////////////////////////////////////////////////////////////////////
+void ICCorr() {
+    //===========================================================================================================
+    //                           Loading var
+    //===========================================================================================================
+    TChain* chain = new TChain("PhysicsTree");
+    chain->Add("../../../root/analysis/VamosCalib241.root");
+
+    TICPhysics* IC = new TICPhysics() ;
+    double FF_IC_X, FF_IC_Y;
+
+    chain->SetBranchStatus("FF_IC_X", true);
+    chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC); 
+
+
+    TFile* fHisto =  TFile::Open("Output/HistoP2P.root");
+    TFile* fSpline =  TFile::Open("Output/spline_P2P_2024.root");
+    //TFile* fSpline =  TFile::Open("Output/spline_ICALL_2024.root");
+    TFile* fFit = TFile::Open("Output/FitIC.root");
+
+    //Defining output histo
+    double NbinX = 500 , NbinY =100;
+    TH2F* hDE_E = new TH2F("DE_E","DE_E",NbinX,9000,16000,NbinY,11000,18000);
+    TH2F* hDE_Ecorr1 = new TH2F("DE_Ecorr1","DE_Ecorr1",NbinX,9000,16000,NbinY,11000,18000);
+    TH2F* hDEBis_Ecorr_IC1 = new
+        TH2F("DE_Ecorr_IC1","DE_Ecorr_IC1",NbinX,9000,16000,NbinY,11000,18000);
+    TH2F* hDE_E_CorrAll = new
+        TH2F("hDE_E_CorrAll","hDE_E_CorrAll",NbinX,9000,16000,NbinY,11000,18000);
+
+
+    // Filling the input histo 
+    int NSegment = 5 ;
+    vector<TH2F*> hICseg_ICprev, hICX,hICY ,hICseg_ICprevX,hICseg_ICprevY, hICcorr;
+    for(int seg=0; seg<NSegment; seg++){
+
+        if(seg==1){
+            hICX.push_back((TH2F*)fHisto->Get(Form("hChio_IC%d_X",seg)));
+            hICY.push_back((TH2F*)fHisto->Get(Form("hChio_IC%d_Y",seg)));
+            hICcorr.push_back(new TH2F(Form("hICorr%d_Y",seg),Form("hICorr%d_Y",seg),1000,-100,100,500,2000,9500));
+        }
+        else if (seg == 0){
+            hICX.push_back((TH2F*)fHisto->Get(Form("hChio_IC%d_IC%d_X",seg+1,seg)));
+            hICY.push_back((TH2F*)fHisto->Get(Form("hChio_IC%d_IC%d_Y",seg+1,seg)));
+            hICcorr.push_back(new TH2F(Form("hICorr%d_Y",seg),Form("hICorr%d_Y",seg),1000,-100,100,500,0,2));
+        }
+        else {
+            hICX.push_back((TH2F*)fHisto->Get(Form("hChio_IC%d_IC%d_X",seg,seg-1)));
+            hICY.push_back((TH2F*)fHisto->Get(Form("hChio_IC%d_IC%d_Y",seg,seg-1)));
+            hICcorr.push_back(new TH2F(Form("hICorr%d_Y",seg),Form("hICorr%d_Y",seg),1000,-100,100,500,0,2));
+        }
+    }
+
+    //===========================================================================================================
+    //                                            GETSPLINE
+    //===========================================================================================================
+    // Get number of spline
+    int SplineCount = 0 ;
+    TIter next(fSpline->GetListOfKeys());
+    TKey* key;
+
+    while ((key=(TKey*)next())){
+        if (std::string(key->GetClassName()) == "TSpline3"){
+            SplineCount ++;
+        }
+    }
+
+
+    vector<TSpline3*> spline_X(11), spline_Y(11);
+    for (int i = 0; i < SplineCount  ; i++) {
+        int seg = int((i-2)/2 +1 );
+
+        if (i < 2){
+            spline_X.at(0) = (TSpline3 *)fSpline->Get("fspline_IC0_X");
+            spline_Y.at(0) = (TSpline3 *)fSpline->Get("fspline_IC0_Y");
+        }
+
+        else if ( i>=2 && i<4){ 
+            spline_X.at(1) = (TSpline3 *)fSpline->Get("fspline_IC1_X");
+            spline_Y.at(1) = (TSpline3 *)fSpline->Get("fspline_IC1_Y");
+        }
+        else if (seg >=2 && (i%2 == 0) ) {
+            spline_X.at(seg) = (TSpline3 *)fSpline->Get(Form("fspline_IC%d_X",seg));
+        }
+        else if (seg >=2 && !(i%2 == 0) ) {	
+            spline_Y.at(seg) = (TSpline3 *)fSpline->Get(Form("fspline_IC%d_Y",seg));
+        }
+    } //End loop on histogram
+      //===========================================================================================================
+      //                                 get fit
+      //===========================================================================================================
+
+    int FitCount = GetNumberKey(fFit,"TF1"); 
+
+
+    vector<TF1*> Fit;
+    for (int i = 0; i < FitCount  ; i++) {
+        Fit.push_back((TF1*)fFit->Get(Form("Fit_Y_Expo_IC%d",i)));
+    } //End loop on Fit 
+
+
+    //===========================================================================================================
+    //                                        Event Loop
+    //===========================================================================================================
+    int Nentries = chain->GetEntries();
+    auto start = std::chrono::high_resolution_clock::now();
+    for (int e = 0; e < Nentries; e++) {
+
+        if (e % 100000  == 0 && e > 0) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "  ****** Estimated time left: " << int(timeLeft) << " seconds ******" << "\r" << flush;
+        }
+
+        chain->GetEntry(e);
+
+
+        vector<double> ICcorr_Y(NSegment), ICcorr_X(NSegment); // the [0] element of spline is the
+        vector<double> Temp_X(NSegment) , Temp_Y(NSegment);    // correction on the first
+                                                               // segment of ic
+        for (int seg = 1; seg < NSegment+1 ; seg++) {
+
+            if (seg == NSegment) seg = 0; //from 1to NSeg finishing with 0
+
+
+            if (spline_Y.at(seg)==0){
+                ICcorr_Y.at(seg) = IC->fIC_raw[seg]; 
+            }
+
+            else {
+                if (seg == 0) {
+                    Temp_Y.at(seg) = ICcorr_Y.at(1) / IC->fIC_raw[seg] * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(1) / Temp_Y.at(seg);
+                }
+
+                else if (seg == 1){ 
+                    ICcorr_Y.at(seg) = IC->fIC_raw[1]*spline_Y.at(1)->Eval(0)/spline_Y.at(1)->Eval(FF_IC_Y);
+                }
+
+                else if (seg > 1) {
+                    Temp_Y.at(seg) =  IC->fIC_raw[seg]/ICcorr_Y.at(seg-1) * spline_Y.at(seg)->Eval(0)/ spline_Y.at(seg)->Eval(FF_IC_Y);
+                    ICcorr_Y.at(seg) = ICcorr_Y.at(seg-1) * Temp_Y.at(seg);
+                }
+
+                if (!(ICcorr_Y.at(seg)==ICcorr_Y.at(seg))) ICcorr_Y.at(seg) = 0;
+            } //end if non empty
+            if (seg == 0) break;
+        }//endloop seg
+
+        for (int i = 0; i < ICcorr_Y.size()  ; i++) {
+            if (i ==1) hICcorr.at(i)->Fill(FF_IC_Y,ICcorr_Y.at(i));
+            else hICcorr.at(i)->Fill(FF_IC_Y,Temp_Y.at(i));
+        } //End loop on histogram
+
+        double DE = 0 ,E =0 ,DE_IC1_corrY =0, DE_ICALL_corrY=0, Ecorr=0;
+
+        for (int seg = 0 ;  seg < sizeof(IC->fIC_raw)/sizeof(IC->fIC_raw[0]) ; seg++ ){
+            if (seg >4){
+                E += IC->fIC_raw[seg] ;
+                //Ecorr += ICcorr_Y.at(seg) ;
+            }
+        }
+
+        double IC1corr = (IC->fIC_raw[1]*(1-0.000686068*FF_IC_Y))*(1-4.88238e-05*FF_IC_Y+7.40395e-06*FF_IC_Y*FF_IC_Y);
+        double DE_Bis = 0.5*(IC1corr+IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+
+        DE = 0.5*(IC->fIC_raw[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+        DE_IC1_corrY = 0.5*(ICcorr_Y[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+        DE_ICALL_corrY = 0.5*(ICcorr_Y[0]+ICcorr_Y[1] +ICcorr_Y[2]+ICcorr_Y[3])+ICcorr_Y[4];
+        double Ealt = E + IC->fIC_raw[4];
+
+        if (FF_IC_Y >-60 && FF_IC_Y <60){
+            hDE_E->Fill(E,DE);
+            hDE_Ecorr1->Fill(E,DE_Bis);
+            hDEBis_Ecorr_IC1->Fill(E,DE_IC1_corrY);
+            hDE_E_CorrAll->Fill(E,DE_ICALL_corrY);
+        }
+    } //endl loop event
+      //===========================================================================================================
+      //                                          Drawing histo
+      //===========================================================================================================
+
+    TCanvas* c1 = new TCanvas("c1","c1",10000,1000);
+    c1->Divide(NSegment,2);
+    for (int i = 0 ; i<NSegment ;i++){
+        c1->cd(i+1);
+        hICcorr.at(i)->ProfileX()->Draw();
+
+        c1->cd(NSegment+i+1);
+        hICY.at(i)->ProfileX()->Draw();
+    }
+
+
+    TCanvas* c2 = new TCanvas("c2","c2",1500,1000);
+    c2->Divide(2,2);
+    c2->cd(1);
+    //gPad->SetLogz();
+    hDE_E->Draw();
+    c2->cd(3);
+    //gPad->SetLogz();
+    hDE_Ecorr1->Draw();
+    c2->cd(4);
+    //gPad->SetLogz();
+    hDEBis_Ecorr_IC1->Draw();
+    c2->cd(2);
+    //gPad->SetLogz();
+    hDE_E_CorrAll->Draw();
+} // End spline chio XY
+
+
+int GetNumberKey(TFile *infile ,const char* ClassName){
+    // Get number of spline
+    int KeyCount = 0 ;
+    TIter next(infile->GetListOfKeys());
+    TKey* keyFit;
+
+    while ((keyFit=(TKey*)next())){
+        if (std::string(keyFit->GetClassName()) == ClassName){
+            KeyCount ++;
+        }
+    }
+
+    return KeyCount;
+
+}
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/IC_Dampen_Recombination.cxx b/Projects/AlPhaPha/2024/macro/chio/YCalibration/IC_Dampen_Recombination.cxx
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/chio/CalibrationChio/IC_Dampen_Recombination.cxx
rename to Projects/AlPhaPha/2024/macro/chio/YCalibration/IC_Dampen_Recombination.cxx
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/IC_Dampen_Recombination.h b/Projects/AlPhaPha/2024/macro/chio/YCalibration/IC_Dampen_Recombination.h
similarity index 86%
rename from Projects/AlPhaPha/2024/macro/chio/CalibrationChio/IC_Dampen_Recombination.h
rename to Projects/AlPhaPha/2024/macro/chio/YCalibration/IC_Dampen_Recombination.h
index 2a2b364371d6e9393a586008c6eb68f4ea314afa..e4c7d79537f4062f13f402a2740f9327b86f6b7d 100644
--- a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/IC_Dampen_Recombination.h
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/IC_Dampen_Recombination.h
@@ -1,5 +1,5 @@
 #include <TFile.h>
-#include <TICPhysics.h>
+//#include <TICPhysics.h>
 #include <TChain.h>
 #include <TF1.h>
 #include <TH2.h>
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/CutZ.cxx b/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/CutZ.cxx
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/chio/CalibrationChio/CutZ.cxx
rename to Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/CutZ.cxx
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/DECorrParra.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/DECorrParra.C
new file mode 100644
index 0000000000000000000000000000000000000000..2e1be5cf48583c06b4d9f86ea1968da75cd2c05e
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/DECorrParra.C
@@ -0,0 +1,253 @@
+//#include <TICPhysics.h>
+#include <TCanvas.h>
+#include <TChain.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TH2.h>
+#include <TSpline.h>
+#include <TCutG.h>
+#include <fstream>
+#include <vector>
+
+using namespace std;
+
+int GetNumberKey(TFile *infile ,const char* ClassName);
+
+TSpline3* MakeSpline(TH2F* hInput, Int_t NCallee, double XMin , double
+    XMax, double YMin, double YMax);
+//////////////////////////////////////////////////////////////////////////////////////////
+void DECorrParra(bool cut = false, bool spline = false) {
+  //===========================================================================================================
+  //                           Loading var
+  //===========================================================================================================
+  TChain* chain = new TChain("PhysicsTree");
+  chain->Add("../../../root/analysis/VamosCalib241.root");
+
+  TICPhysics* IC = new TICPhysics() ;
+  double FF_IC_X, FF_IC_Y;
+
+  chain->SetBranchStatus("FF_IC_X", true);
+  chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
+  chain->SetBranchStatus("FF_IC_Y", true);
+  chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+  chain->SetBranchStatus("IC", true);
+  chain->SetBranchAddress("IC", &IC); 
+
+ TCutG *CutZ;
+ TCutG *CutZbis;
+ TFile *fCut; 
+  if (cut) {
+    fCut =  TFile::Open("Output/CutDeCorr.root");
+    CutZbis = (TCutG*)fCut->Get("CutZbis") ;
+    CutZ = (TCutG*)fCut->Get("CutZbis") ;
+  }
+
+  TFile *fSpline; 
+  TSpline3 *splineDEcorr, *splineDEbis;
+  if(spline){
+    fSpline= new TFile("Output/splineDE.root","open");
+    splineDEcorr = (TSpline3*) fSpline->Get("SplineDe");
+    splineDEbis = (TSpline3*) fSpline->Get("SplineDebis");
+  }
+
+  //Defining output histo
+  TH2F* hDE_E = new TH2F("DE_E","DE_E",1000,100,1,1000,100,1);
+  TH2F* hDE_Ebis = new TH2F("DE_Ebis","DE_Ebis",1000,100,1,1000,100,1);
+  TH2F* hDE_Y = new TH2F("DE_Y","DE_Y",1000,-100,100,1000,0,22000);
+  TH2F* hDE_Y_bis = new TH2F("DE_Ybis","DE_Ybis",1000,-100,100,1000,0,22000);
+  TH2F* hDE_E_corr = new TH2F("DE_Ecorr","DE_Ecorr",1000,100,1,1000,0,22000);
+  TH2F* hDE_Ebis_corr = new TH2F("DE_Ebiscorr","DE_Ebiscorr",1000,100,1,1000,0,22000);
+
+
+  //===========================================================================================================
+  //                                        Event Loop
+  //===========================================================================================================
+  int Nentries = chain->GetEntries();
+  //int Nentries = 1000000;
+  auto start = std::chrono::high_resolution_clock::now();
+  for (int e = 0; e < Nentries; e++) {
+
+    if (e % 100000  == 0 && e > 0 ) {
+      auto now = std::chrono::high_resolution_clock::now();
+      std::chrono::duration<double> elapsed = now - start;
+      double avgTimePerIteration = elapsed.count() / e;
+      double timeLeft = avgTimePerIteration * (Nentries - e);
+
+      std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+    }
+
+    chain->GetEntry(e);
+
+
+    double DE = 0 ,E =0 ,DE_Ycorr=0, DE_Ybis=0;
+
+    for (int seg = 0 ;  seg < sizeof(IC->fIC_raw)/sizeof(IC->fIC_raw[0]) ; seg++ ){
+      if (seg >4){
+        E += IC->fIC_raw[seg] ;
+        //Ecorr += ICcorr_Y.at(seg) ;
+      }
+    }
+
+    double IC1corr = (IC->fIC_raw[1]*(1-0.000686068*FF_IC_Y))*(1-4.88238e-05*FF_IC_Y+7.40395e-06*FF_IC_Y*FF_IC_Y);
+    double DE_Bis = 0.5*(IC1corr+IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+
+    DE = 0.5*(IC->fIC_raw[1] +IC->fIC_raw[2]+IC->fIC_raw[3])+IC->fIC_raw[4];
+
+    if (FF_IC_Y >-100 && FF_IC_Y <100){
+      hDE_E->Fill(E,DE);
+      hDE_Ebis->Fill(E,DE_Bis);
+
+      if (spline== true){     
+        DE_Ycorr = DE * 13750 / splineDEcorr->Eval(FF_IC_Y);
+        hDE_E_corr->Fill(E,DE_Ycorr);
+
+        DE_Ybis = DE_Bis * 13750 / splineDEbis->Eval(FF_IC_Y);
+        hDE_Ebis_corr->Fill(E,DE_Ybis);  
+      }
+
+      if (cut == true && !(CutZ->IsInside(E,DE))) {;}
+      else {
+        hDE_Y->Fill(FF_IC_Y,DE);
+      }//end cut
+
+      if (cut == true && !(CutZbis->IsInside(E,DE_Bis))) {;}
+      else {
+        hDE_Y_bis->Fill(FF_IC_Y,DE_Bis);
+      }//end cut
+    }//end cond Y
+  } //endl loop event
+
+  // making spline
+
+  TSpline3 *splineDE, *osplineDEbis;
+  if (cut == true){
+    splineDE = MakeSpline(hDE_Y,0,-100,100,14300,15000); 
+    osplineDEbis = MakeSpline(hDE_Y_bis,1,-100,100,14300,15000); 
+    TFile *fSpline = new TFile("Output/splineDE.root","recreate");
+    splineDE->SetName("SplineDe");
+    splineDE->Write();
+    osplineDEbis->SetName("SplineDebis");
+    osplineDEbis->Write(); 
+    fSpline->Close();
+    fCut->cd();
+  }
+  //===========================================================================================================
+  //                                          Drawing histo
+  //===========================================================================================================
+
+  TCanvas* c2 = new TCanvas("c2","c2",1500,1000);
+  c2->Divide(2 + 2*spline);
+  c2->cd(1);
+  gPad->SetLogz();
+  hDE_E->Draw();
+  c2->cd(2);
+  gPad->SetLogz();
+  hDE_Ebis->Draw();
+  if (spline){
+    c2->cd(3);
+    gPad->SetLogz();
+    hDE_E_corr->Draw();
+    c2->cd(4);
+    gPad->SetLogz();
+    hDE_Ebis_corr->Draw();
+  }
+} // End spline chio XY
+
+
+int GetNumberKey(TFile *infile ,const char* ClassName){
+  // Get number of spline
+  int KeyCount = 0 ;
+  TIter next(infile->GetListOfKeys());
+  TKey* keyFit;
+
+  while ((keyFit=(TKey*)next())){
+    if (std::string(keyFit->GetClassName()) == ClassName){
+      KeyCount ++;
+    }
+  }
+
+  return KeyCount;
+
+}
+
+TSpline3* MakeSpline(TH2F* hInput, Int_t NCallee, double XMin = 0 , double
+    XMax = 1000 , double YMin=0 , double YMax = 100) {
+
+  TSpline3* gspline;
+
+  TH1F* hProfile;
+  TH1F* pfx; // extended hProfile
+
+  TCanvas* canfit = new TCanvas(Form("CanSpline_%02d",NCallee),
+      Form("canfit_%02d",NCallee), 0, 0, 1000, 500);
+
+
+  //===========================================================================================================
+  //                                            Init profile
+  //===========================================================================================================
+
+  // Create the TProfile
+  hProfile = (TH1F*)hInput->ProfileX();
+  hProfile->SetLineWidth(2);
+  hProfile->SetDirectory(0);
+  canfit->cd();
+
+  hProfile->GetYaxis()->SetRangeUser(YMin, YMax);
+  hProfile->Draw();
+  //===========================================================================================================
+  //                                          First and last bin to get to 6k
+  //                                          event get promoted
+  //===========================================================================================================
+  int FirstBin, LastBin;
+  double Treshold = 1;
+  for (int bin =1 ; bin<hProfile->GetNbinsX(); bin++) {
+    FirstBin = bin;
+    if (hProfile->GetBinLowEdge(bin)> XMin) break;
+  }
+  for (int bin = hProfile->GetNbinsX(); bin>1 ; bin--) {
+    LastBin = bin;
+    if (hProfile->GetBinLowEdge(bin)< XMax) break;
+  }
+  //===========================================================================================================
+  //                                          Init Extended profile function
+  //===========================================================================================================
+  // Create the extended TProfile
+  pfx = new TH1F(
+      Form("pfx_%02d", Int_t(NCallee/2)), Form("pfx_%02d", Int_t(NCallee/2)), hProfile->GetNbinsX(), hProfile->GetBinLowEdge(1),
+      hProfile->GetBinLowEdge(hProfile->GetNbinsX()) + hProfile->GetBinWidth(hProfile->GetNbinsX()));
+  pfx->SetLineColor(8);
+  pfx->SetDirectory(0);
+  //===========================================================================================================
+  //                                           Fill extended profile
+  //===========================================================================================================
+
+  // fill the extended TProfile
+  float newval, lastval, lasterr;
+  for (int bin = 1; bin <= FirstBin; bin++) {
+    newval = 0;
+    pfx->SetBinContent(bin, newval);
+  }
+
+
+  for (int bin = FirstBin; bin <= LastBin; bin++) {
+    newval = hProfile->GetBinContent(bin);
+    if (newval != 0) {
+      pfx->SetBinContent(bin, newval);
+      pfx->SetBinError(bin, hProfile->GetBinError(bin));
+      lastval = newval;
+      lasterr = hProfile->GetBinError(bin);
+    }
+    else {
+      pfx->SetBinContent(bin, lastval);
+      pfx->SetBinError(bin, lasterr);
+    }
+  }
+  pfx->Draw("same");
+
+  gspline = new TSpline3(pfx);
+  gspline->SetName(Form("fspline_%d", NCallee + 1));
+
+  return gspline;
+
+} // end makespline
+
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/PlotChio.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/PlotChio.C
new file mode 100644
index 0000000000000000000000000000000000000000..c3b8424dea658e413d07e00a2c918643bc954627
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/Legacy/PlotChio.C
@@ -0,0 +1,21 @@
+#include <TCanvas.h>
+#include <TFile.h>
+#include <TGraph.h>
+#include <TH2.h>
+#include <TTree.h>
+
+void PlotChio(){
+
+  TFile *f = new TFile("../../../root/analysis/VamosCalib241.root");
+  TTree *tree = (TTree*) f->Get("PhysicsTree");
+
+     
+  TCanvas *c1 = new TCanvas("c1","c1",1200,600);
+  
+  TH2F *h = new TH2F("h","h",1000,-800,800,1000,-160,160);
+  tree->Draw("FF_IC_Y:FF_IC_X>>h","","colz");
+  h->GetXaxis()->SetTitle("X");
+  h->GetYaxis()->SetTitle("Y");
+
+
+}
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/Output/ReadMe.md b/Projects/AlPhaPha/2024/macro/chio/YCalibration/Output/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..612bb5848913890a39168d1cdf4e806b3cf355fc
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/Output/ReadMe.md
@@ -0,0 +1,3 @@
+# Output
+
+Directory essential for pathing
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/PlotOnline.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/PlotOnline.C
new file mode 100644
index 0000000000000000000000000000000000000000..d301d3ccd30b950fa2f91f2c89aecc5d17b330a5
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/PlotOnline.C
@@ -0,0 +1,21 @@
+
+#include <TAxis.h>
+#include <TCanvas.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TSpline.h>
+
+void PlotOnline(){
+
+    TF1 *f1 = new TF1("Fonction Online", "(1-0.000686068*x)*(1-4.88238e-05*x+7.40395e-06*x*x)", -100, 100);
+
+
+    TFile *fSplineIC = new TFile("Output/spline_P2P_2024.root","open"); 
+    TSpline3 *spline_Y = (TSpline3 *)fSplineIC->Get("fspline_IC1_Y");
+
+    TCanvas *c = new TCanvas("c","c");
+    f1->Draw();
+    f1->SetTitle("Lucas correction");
+    f1->GetXaxis()->SetTitle("Y");
+    f1->GetYaxis()->SetTitle("De Correction");
+}
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/ReadMe.md b/Projects/AlPhaPha/2024/macro/chio/YCalibration/ReadMe.md
similarity index 66%
rename from Projects/AlPhaPha/2024/macro/chio/CalibrationChio/ReadMe.md
rename to Projects/AlPhaPha/2024/macro/chio/YCalibration/ReadMe.md
index 74440f95c2f9bd869b0585ed48bedfdc95d196f0..10a6324c37f70ab764edc66abd7e7821b75eab84 100644
--- a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/ReadMe.md
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/ReadMe.md
@@ -13,5 +13,13 @@ of the electron by the grid.
 
 ## The code
 
-SplineXY.C serve the purpose of creating this spline and storing int a .root
+SplineChioXY.C serve the purpose of creating this spline and storing int a .root
 file. 
+
+SplineChioAllXY.C make the spline for all section of the chio
+
+SplineChioP2P scale the i section from the i-1 one
+
+DECorr.C plot the DE_E with several correction compared
+
+IC_Dampen_recombi try a expo fit
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioAllXY.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioAllXY.C
similarity index 87%
rename from Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioAllXY.C
rename to Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioAllXY.C
index fe9f9cbbf07197a01ddb2cc2d0a612e49d7e6e16..c1e4e3769710416d68149f4d6df5bdbe346e6379 100644
--- a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioAllXY.C
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioAllXY.C
@@ -41,14 +41,12 @@ void SplineChioAllXY( bool Create = false , bool Cut = false) {
   
   int NSegment = 11 ;
   vector<TH2F*> hIC,hICX,hICY;
-  hIC.push_back((TH2F*)inFile->Get("hChio_IC1_X"));
-  hIC.push_back((TH2F*)inFile->Get("hChio_IC1_Y"));
 
   for(int seg=0; seg<NSegment; seg++){
-    hIC.push_back((TH2F*)inFile->Get(Form("hIC1_IC%d_X",seg)));
-    hIC.push_back((TH2F*)inFile->Get(Form("hIC1_IC%d_Y",seg)));
-    hICX.push_back((TH2F*)inFile->Get(Form("hIC1_IC%d_X",seg)));
-    hICY.push_back((TH2F*)inFile->Get(Form("hIC1_IC%d_Y",seg)));
+    hIC.push_back((TH2F*)inFile->Get(Form("hChio_IC%d_X",seg)));
+    hIC.push_back((TH2F*)inFile->Get(Form("hChio_IC%d_Y",seg)));
+    hICX.push_back((TH2F*)inFile->Get(Form("hChio_IC%d_X",seg)));
+    hICY.push_back((TH2F*)inFile->Get(Form("hChio_IC%d_Y",seg)));
   }
 
   HistoDrawer(hICX,"CanX");
@@ -60,32 +58,24 @@ void SplineChioAllXY( bool Create = false , bool Cut = false) {
   int NHist = static_cast<int>(hIC.size());
   double XMin[NHist] , XMax[NHist], YMin[NHist] , YMax[NHist];
   XMin[0] = -520 ;   XMax[0] = 380 ; YMin[0] = 2000 ; YMax[0] = 9500 ; 
-  XMin[1] = -60  ;   XMax[1] = 63  ; YMin[1] = 2000 ; YMax[1] = 9500 ; 
-  XMin[2] = -520 ;   XMax[2] = 380 ; YMin[2] = 0 ; YMax[2] = 2 ; 
-  XMin[3] = -60  ;   XMax[3] = 63  ; YMin[3] = 0 ; YMax[3] = 2 ; 
+  XMin[1] = -100  ;   XMax[1] = 103  ; YMin[1] = 0 ; YMax[1] = 20000 ; 
+  XMin[2] = -520 ;   XMax[2] = 380 ; YMin[2] = 2000 ; YMax[2] = 9500 ; 
+  XMin[3] = -100  ;   XMax[3] = 103  ; YMin[3] = 0 ; YMax[3] = 20000 ; 
 
 
 
   for (int i = 0; i < NHist; i++) {
     
     TSpline3 *spline;
-    if (i == 1){ 
-      spline = MakeSpline(hIC[i] , i, XMin[i] , XMax[i], YMin[i], YMax[i]);
-      spline->SetName("fsplineIC1_Y");
-    }
-    else if (i == 0){ 
-      spline = MakeSpline(hIC[i] , i, XMin[i] , XMax[i], YMin[i], YMax[i]);
-      spline->SetName("fsplineIC1_X");
-    }
-    else if (i>=2 && (i%2 == 0) && (i!=4) && false) {
+    if ( (i%2 == 0) && true) {
       spline = MakeSpline(hIC[i] , i, XMin[2] , XMax[2], YMin[2],
           YMax[2]);
-      spline->SetName(Form("fsplineIC1_IC%d_X",int((i-2)/2)));   
+      spline->SetName(Form("fspline_IC%d_X",int((i-2)/2)));   
     }
-    else if (i>=2 && !(i%2 == 0) && (i!=5)) {
+    else if ( !(i%2 == 0)) {
       spline = MakeSpline(hIC[i] , i, XMin[3] , XMax[3], YMin[3],
           YMax[3]);
-      spline->SetName(Form("fsplineIC1_IC%d_Y",int((i-2)/2)));   
+      spline->SetName(Form("fspline_IC%d_Y",int((i-2)/2)));   
     }
     spline->Write();
   } //End loop on histogram
@@ -103,7 +93,7 @@ void HistoFiller(bool cut) {
 
   // Input and setters
   TChain* chain = new TChain("PhysicsTree");
-  chain->Add("../../../root/analysis/VamosCalib241.root");
+  chain->Add("../../../root/analysis/VamosCalib247.root");
 
   TICPhysics* IC = new TICPhysics() ; 
   double FF_IC_X, FF_IC_Y;
@@ -117,8 +107,10 @@ void HistoFiller(bool cut) {
 
   //spline to correct IC1 as a baseline of IC0
   TFile* fSpline =  TFile::Open("Output/spline_ICALL_2024.root");
-  TSpline3* SplineIC1 = (TSpline3 *)fSpline->Get(Form("fsplineIC1_Y"));
-
+  TSpline3* SplineIC1;
+  if (fSpline && !fSpline->IsZombie()) {
+      SplineIC1 = (TSpline3 *)fSpline->Get(Form("fspline_IC1_Y"));
+  }
 
   //cut
   TFile *fcut = new TFile("Output/CutZ.root","open") ;
@@ -136,9 +128,9 @@ void HistoFiller(bool cut) {
         Form("hIC1_IC%d_Y",seg), 1000, -160, 160, 500, 0, 2);
 
     hChio_ICn_Y.at(seg) = new TH2F(Form("hChio_IC%d_Y",seg),
-        Form("hChio_IC%d_Y",seg), 1000, -160, 160, 500, 2000, 9500);
+        Form("hChio_IC%d_Y",seg), 1000, -160, 160, 500, 0, 20000);
     hChio_ICn_X.at(seg) = new TH2F(Form("hChio_IC%d_X",seg),
-        Form("hChio_IC%d_X",seg), 1000, -800, 800, 500, 2000, 9500);
+        Form("hChio_IC%d_X",seg), 1000, -800, 800, 500, 0, 20000);
 
   }
 
@@ -326,7 +318,7 @@ void HistoDrawer(vector<TH2F*> h,const char* CharName){
   for ( int i=0 ; i < NHisto ; i+=1 ){
     //All x are even and all y are odd
     int CanvaNumber = (i) ;
-    Can->cd(CanvaNumber);
+    Can->cd(CanvaNumber+1);
     h[i]->Draw("colz");
   }
 }
diff --git a/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioP2P.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioP2P.C
new file mode 100644
index 0000000000000000000000000000000000000000..2819b39f1c8a617e6f030459944c76a7ce656093
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioP2P.C
@@ -0,0 +1,515 @@
+#ifdef TICPhysics
+#include <TICPhysics.h>
+#endif
+#include <TCanvas.h>
+#include <TChain.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TH2.h>
+#include <TSpline.h>
+#include <fstream>
+#include <vector>
+#include <TCutG.h>
+
+using namespace std;
+
+TSpline3* MakeSpline(TH2F* hInput, Int_t NCallee, double XMin , double
+        XMax, double YMin, double YMax);
+
+vector<TH2F*>HistoFillerIC(int segment, vector<vector<TSpline3*>> Spline_All_ICprev);
+vector<vector<TH2F*>>HistoFillerICcorr(int segment, vector<vector<TSpline3*>> Spline_All_ICprev);
+
+void HistoDrawer(vector<TH2F*> h ,const char* CharName);
+
+//////////////////////////////////////////////////////////////////////////////////////////
+void SplineChioP2P() {
+
+    int NSegment = 5 ;
+    double XMin[4] , XMax[4], YMin[4] , YMax[4];
+    XMin[0] = -520 ;   XMax[0] = 380 ; YMin[0] = 2000 ; YMax[0] = 9500 ; 
+    XMin[1] = -100  ;   XMax[1] = 100  ; YMin[1] = 1000 ; YMax[1] = 10000 ; 
+    XMin[2] = -520 ;   XMax[2] = 380 ; YMin[2] = 0 ; YMax[2] = 2 ; 
+    XMin[3] = -100  ;   XMax[3] = 100  ; YMin[3] = 0 ; YMax[3] = 2 ; 
+
+    //Reinitialising the outfile
+    TFile *OutFile = new TFile("Output/HistoP2P.root","update");
+    OutFile->Close();
+    //Initialising with IC1
+    int NCallSpline = 0;
+    int seg = 1;
+
+    vector<vector<TSpline3*>> SplineAllIC(11);
+    vector<TSpline3*> SplineICurrent(2);
+
+    vector<vector<TH2F*>> hIC(NSegment);
+    hIC.at(1)= (HistoFillerIC(1,SplineAllIC));
+
+    SplineICurrent.at(0) = MakeSpline(hIC[seg][0] , NCallSpline, XMin[0] , XMax[0], YMin[0], YMax[0]);
+    SplineICurrent.at(0)->SetName("fspline_IC1_X");
+    NCallSpline+=1;
+
+    SplineICurrent.at(1) = MakeSpline(hIC[seg][1] , NCallSpline, XMin[1] , XMax[1], YMin[1], YMax[1]);
+    SplineICurrent.at(1)->SetName("fspline_IC1_Y");
+    NCallSpline+=1;
+
+    SplineAllIC.at(1)= (SplineICurrent); // 
+    ///SplineAllIC.erase(SplineAllIC.begin() + 1); 
+                                         ///activate this to not make the
+                                         //spline of IC1 
+
+
+    for (int seg = 0 ; seg < NSegment ; seg++){
+        if(seg ==1) {
+        }
+
+        else{
+
+            //Load Histo 
+            hIC.at(seg) = (HistoFillerIC(seg,SplineAllIC));
+
+            //Reset spline holder
+            vector<TSpline3*> SplineICurrent; 
+
+            // X Spline
+            SplineICurrent.push_back(MakeSpline(hIC[seg][0] , NCallSpline, XMin[2] , XMax[2], YMin[2], YMax[2]));
+            if (seg == 0)  SplineICurrent.at(0)->SetName(Form("fspline_IC%d_X",seg));
+            else if (seg != 0) SplineICurrent.at(0)->SetName(Form("fspline_IC%d_X",seg));
+            NCallSpline+=1;
+
+            // Y Spline
+            SplineICurrent.push_back(MakeSpline(hIC[seg][1] , NCallSpline, XMin[3] , XMax[3], YMin[3], YMax[3]));
+            if (seg == 0)  SplineICurrent.at(1)->SetName(Form("fspline_IC%d_Y",seg));
+            else if (seg != 0)SplineICurrent.at(1)->SetName(Form("fspline_IC%d_Y",seg));
+            NCallSpline+=1;
+
+            //push vector into memory
+            SplineAllIC.at(seg)= SplineICurrent;
+        }
+    }
+    //write spline
+    TFile* fspline = new TFile("Output/spline_P2P_2024.root", "recreate");
+    for (int seg = 0 ; seg < NSegment ; seg++){
+        if (!SplineAllIC.at(seg).empty()){
+            SplineAllIC.at(seg)[0]->Write();
+            SplineAllIC.at(seg)[1]->Write();
+        }
+    }
+    fspline->Close();
+
+
+    vector<vector<TH2F*>> hIC_Corrall(NSegment);
+    vector<TH1F*> hIC_Corr_profile(NSegment);
+    vector<TH2F*> hIC_Corr(NSegment);
+    hIC_Corrall = HistoFillerICcorr(NSegment,SplineAllIC);
+    hIC_Corr = hIC_Corrall.at(1);
+
+    TCanvas *c1 = new TCanvas("c1","c1");
+    c1->Divide(NSegment);
+    for (int i=0 ; i<NSegment ; i++){
+        hIC_Corr_profile.at(i) = (TH1F*)hIC_Corr.at(i)->ProfileX();  
+        c1->cd(i+1);
+        hIC_Corr_profile.at(i)->Draw();
+    }
+
+
+} // End spline chio XY
+
+///////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * This function fill the histograms of ICseg/ICcorrSeg-1 expect for IC1 where
+ * it give IC1 and ICO where it give IC0/IC1corr
+ */
+vector<TH2F*> HistoFillerIC(int segment, vector<vector<TSpline3*>> Spline_All_ICprev) {
+
+    // Input and setters
+    TChain* chain = new TChain("PhysicsTree");
+    chain->Add("../../../root/analysis/VamosCalib247.root");
+
+    TICPhysics* IC = new TICPhysics() ; 
+    double FF_IC_X, FF_IC_Y;
+
+    chain->SetBranchStatus("FF_IC_X", true);
+    chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC);
+
+    // Get the number of previous spline to load
+    int NSpline = abs(segment-1);
+
+    //Filling all  previous vector spline
+    vector<TSpline3*> SplineIC_X(NSpline+1);
+    vector<TSpline3*> SplineIC_Y(NSpline+1);
+
+    //Fill all the previous spline , if the segment is 0 it'll fill spline 1 only 
+    for (int pseg = 1 ; pseg<=NSpline; pseg++){
+        if(!Spline_All_ICprev.at(pseg).empty()){
+            SplineIC_X.at(pseg) = Spline_All_ICprev.at(pseg).at(0);
+            SplineIC_Y.at(pseg) = Spline_All_ICprev.at(pseg).at(1);
+        }
+    }
+
+    // Histograms
+    TH2F *hIC_X , *hIC_Y;
+
+    if (segment == 1 ) { 
+        hIC_Y = new TH2F(Form("hChio_IC%d_Y",segment),
+                Form("hChio_IC%d_Y",segment), 1000, -160, 160, 1000, 1000, 10000);
+        hIC_X = new TH2F(Form("hChio_IC%d_X",segment),
+                Form("hChio_IC%d_X",segment), 1000, -800, 800, 1000, 1000, 10000);
+
+    }
+
+    else if (segment == 0){  
+        hIC_Y = new TH2F(Form("hChio_IC%d_IC%d_Y",segment+1,segment),
+                Form("hChio_IC%d_IC%d_Y",segment+1,segment), 1000, -160, 160, 500, 0, 2);
+        hIC_X = new TH2F(Form("hChio_IC%d_IC%d_X",segment+1,segment),
+                Form("hChio_IC%d_IC%d_X",segment+1,segment), 1000, -800, 800, 500, 0, 2);
+    }
+
+    else {
+        hIC_Y = new TH2F(Form("hChio_IC%d_IC%d_Y",segment,segment-1),
+                Form("hChio_IC%d_IC%d_Y",segment,segment-1), 1000, -160, 160, 500, 0, 2);
+        hIC_X = new TH2F(Form("hChio_IC%d_IC%d_X",segment,segment-1),
+                Form("hChio_IC%d_IC%d_X",segment,segment-1), 1000, -800, 800, 500, 0, 2);
+    }
+
+
+    //===========================================================================================================
+    //																	Beginning loop on entries
+    //===========================================================================================================
+
+    //int Nentries = chain->GetEntries();
+    int Nentries = 1000000;
+    auto start = std::chrono::high_resolution_clock::now();
+    for (int e = 0; e < Nentries; e++) {
+
+        chain->GetEntry(e);
+
+        vector<double> IC_Spline_CorrX(NSpline + 1),IC_Spline_CorrY(NSpline+1);
+
+        //Get the corrected value for all previous spline
+        for (int pseg = 1 ; pseg<=NSpline ; pseg++){
+            //If the spline doesnt exist define default value
+            if(Spline_All_ICprev.at(pseg).empty()){
+                IC_Spline_CorrX.at(pseg)= IC->fIC_raw[pseg];
+                IC_Spline_CorrY.at(pseg)= IC->fIC_raw[pseg]; 
+            }
+
+            //If it exist correct the current line
+            else if (!Spline_All_ICprev.at(pseg).empty()){
+                if(pseg ==1){
+                    IC_Spline_CorrX.at(pseg) = IC->fIC_raw[pseg] * SplineIC_X.at(pseg)->Eval(0) / SplineIC_X.at(pseg)->Eval(FF_IC_X); 
+                    IC_Spline_CorrY.at(pseg) = IC->fIC_raw[pseg] * SplineIC_Y.at(pseg)->Eval(0) / SplineIC_Y.at(pseg)->Eval(FF_IC_Y); 
+                } //end ic 1
+                else { 
+                    IC_Spline_CorrX.at(pseg) = IC->fIC_raw[pseg] * SplineIC_X.at(pseg)->Eval(0) / SplineIC_X.at(pseg)->Eval(FF_IC_X); 
+                    IC_Spline_CorrY.at(pseg) = IC->fIC_raw[pseg] * SplineIC_Y.at(pseg)->Eval(0) / SplineIC_Y.at(pseg)->Eval(FF_IC_Y); 
+                } //end ic 2 to 10
+            } //End if non empty
+
+        } // End loop IC non 0
+
+        //===========================================================================================================
+        //                               Fill histo
+        //===========================================================================================================/
+
+        if (segment == 1){
+            hIC_Y->Fill(FF_IC_Y,IC->fIC_raw[segment]);
+            hIC_X->Fill(FF_IC_X,IC->fIC_raw[segment]);
+        }
+
+        else if (segment == 0){
+            hIC_Y->Fill(FF_IC_Y,IC_Spline_CorrY.at(1)/IC->fIC_raw[segment]);
+            hIC_X->Fill(FF_IC_X,IC_Spline_CorrX.at(1)/IC->fIC_raw[segment]);
+        }
+
+
+        else {
+            hIC_Y->Fill(FF_IC_Y,IC->fIC_raw[segment]/IC_Spline_CorrY.at(segment-1));
+            hIC_X->Fill(FF_IC_X,IC->fIC_raw[segment]/IC_Spline_CorrX.at(segment-1));    
+        }
+
+        // Estimate time left every `updateInterval` iterations
+        if (e % 100000  == 0 && e > 0) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "Treating segment : " << segment 
+                << "  | Estimated time left: " << int(timeLeft) << " seconds" << "\r" << flush;
+        }
+    } // end loop on entries
+
+    //===========================================================================================================
+    //                                       Output 
+    //===========================================================================================================
+    vector<TH2F*> hIC;
+    hIC.push_back(hIC_X);
+    hIC.push_back(hIC_Y);
+
+    TFile *OutFile = new TFile("Output/HistoP2P.root","UPDATE");
+    hIC_X->Write();
+    hIC_Y->Write();
+    OutFile->Close();
+
+    return hIC;
+} // End HistoFiller
+
+vector<vector<TH2F*>>HistoFillerICcorr(int segment, vector<vector<TSpline3*>> Spline_All_ICprev){
+
+    // Input and setters
+    TChain* chain = new TChain("PhysicsTree");
+    chain->Add("../../../root/analysis/VamosCalib247.root");
+
+    TICPhysics* IC = new TICPhysics() ; 
+    double FF_IC_X, FF_IC_Y;
+
+    chain->SetBranchStatus("FF_IC_X", true);
+    chain->SetBranchAddress("FF_IC_X", &FF_IC_X);
+    chain->SetBranchStatus("FF_IC_Y", true);
+    chain->SetBranchAddress("FF_IC_Y", &FF_IC_Y);
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC);
+
+    // Get the number of previous spline to load
+    segment = segment -1;
+    int NSpline = abs(segment);
+
+    //Filling all  previous vector spline
+    vector<TSpline3*> SplineIC_X(NSpline+1);
+    vector<TSpline3*> SplineIC_Y(NSpline+1);
+
+    //Fill all the previous spline , if the segment is 0 it'll fill spline 1 only 
+    for (int pseg = 0 ; pseg<=NSpline; pseg++){
+        if(!Spline_All_ICprev.at(pseg).empty()){
+            SplineIC_X.at(pseg) = Spline_All_ICprev.at(pseg).at(0);
+            SplineIC_Y.at(pseg) = Spline_All_ICprev.at(pseg).at(1);
+        }
+    }
+
+    // Histograms
+    vector<TH2F*> hIC_X(segment +1) , hIC_Y(segment+1);
+
+    for (int pseg = 0 ; pseg<=NSpline; pseg++){
+        if (pseg == 1 ) { 
+            hIC_Y.at(pseg) = new TH2F(Form("hChiocorr_IC%d_Y",pseg),
+                    Form("hChiocorr_IC%d_Y",pseg), 1000, -160, 160, 1000, 0, 20000);
+            hIC_X.at(pseg) = new TH2F(Form("hChiocorr_IC%d_X",pseg),
+                    Form("hChiocorr_IC%d_X",pseg), 1000, -800, 800, 1000, 0, 20000);
+
+        }
+
+        else if (pseg == 0){  
+            hIC_Y.at(pseg) = new TH2F(Form("hChiocorr_IC%d_IC%d_Y",pseg+1,pseg),
+                    Form("hChiocorr_IC%d_IC%d_Y",pseg+1,pseg), 1000, -160, 160, 500, 0, 2);
+            hIC_X.at(pseg) = new TH2F(Form("hChiocorr_IC%d_IC%d_X",pseg+1,pseg),
+                    Form("hChiocorr_IC%d_IC%d_X",pseg+1,pseg), 1000, -800, 800, 500, 0, 2);
+        }
+
+        else {
+            hIC_Y.at(pseg) = new TH2F(Form("hChiocorr_IC%d_IC%d_Y",pseg,pseg-1),
+                    Form("hChiocorr_IC%d_IC%d_Y",pseg,pseg-1), 1000, -160, 160, 500, 0, 2);
+            hIC_X.at(pseg) = new TH2F(Form("hChiocorr_IC%d_IC%d_X",pseg,pseg-1),
+                    Form("hChiocorr_IC%d_IC%d_X",pseg,pseg-1), 1000, -800, 800, 500, 0, 2);
+        }
+    }
+
+    //===========================================================================================================
+    //																	Beginning loop on entries
+    //===========================================================================================================
+
+    //int Nentries = chain->GetEntries();
+    int Nentries = 1000000;
+    auto start = std::chrono::high_resolution_clock::now();
+    for (int e = 0; e < Nentries; e++) {
+
+        chain->GetEntry(e);
+
+        vector<double> IC_Spline_CorrX(NSpline + 1),IC_Spline_CorrY(NSpline+1);
+
+        //Get the corrected value for all previous spline
+        for (int pseg = 0 ; pseg<=NSpline ; pseg++){
+            //If the spline doesnt exist define default value
+            if(Spline_All_ICprev.at(pseg).empty()){
+                IC_Spline_CorrX.at(pseg)= IC->fIC_raw[pseg];
+                IC_Spline_CorrY.at(pseg)= IC->fIC_raw[pseg];
+                //cout << pseg << endl;
+            }
+
+            //If it exist correct the current line
+            else if (!Spline_All_ICprev.at(pseg).empty()){
+                if(pseg ==1){
+                    IC_Spline_CorrX.at(pseg) = IC->fIC_raw[1] * SplineIC_X.at(pseg)->Eval(0) / SplineIC_X.at(pseg)->Eval(FF_IC_X); 
+                    IC_Spline_CorrY.at(pseg) = IC->fIC_raw[1] * SplineIC_Y.at(pseg)->Eval(0) / SplineIC_Y.at(pseg)->Eval(FF_IC_Y); 
+                } //end ic 1
+                else if (pseg !=0) { 
+                    IC_Spline_CorrX.at(pseg) = IC->fIC_raw[pseg] * SplineIC_X.at(pseg)->Eval(0) / SplineIC_X.at(pseg)->Eval(FF_IC_X); 
+                    IC_Spline_CorrY.at(pseg) = IC->fIC_raw[pseg] * SplineIC_Y.at(pseg)->Eval(0) / SplineIC_Y.at(pseg)->Eval(FF_IC_Y); 
+                } //end ic 2 to 10
+            } //End if non empty
+        } // end loop
+
+        //filling 0
+        if (!Spline_All_ICprev.at(0).empty()){
+            IC_Spline_CorrX.at(0) = IC->fIC_raw[0] / SplineIC_X.at(0)->Eval(0) * SplineIC_X.at(0)->Eval(FF_IC_X); 
+            IC_Spline_CorrY.at(0) = IC->fIC_raw[0] / SplineIC_Y.at(0)->Eval(0) * SplineIC_Y.at(0)->Eval(FF_IC_Y); 
+        }
+
+        for (int pseg = 0 ; pseg<=NSpline ; pseg++){
+            if (pseg == 1){
+                hIC_Y.at(pseg)->Fill(FF_IC_Y,IC_Spline_CorrY.at(1));
+                hIC_X.at(pseg)->Fill(FF_IC_X,IC_Spline_CorrY.at(1));
+            }
+
+            else if (pseg == 0){
+                hIC_Y.at(pseg)->Fill(FF_IC_Y,IC_Spline_CorrY.at(1)/IC_Spline_CorrY.at(pseg));
+                hIC_X.at(pseg)->Fill(FF_IC_X,IC_Spline_CorrY.at(1)/IC_Spline_CorrX.at(pseg));
+            }
+
+
+            else {
+                hIC_Y.at(pseg)->Fill(FF_IC_Y,IC_Spline_CorrY.at(pseg)/IC_Spline_CorrY.at(pseg-1));
+                hIC_X.at(pseg)->Fill(FF_IC_X,IC_Spline_CorrY.at(pseg)/IC_Spline_CorrX.at(pseg-1));    
+            }
+        }
+        //===========================================================================================================
+        //                               Fill histo
+        //===========================================================================================================/
+
+
+        // Estimate time left every `updateInterval` iterations
+        if (e % 100000  == 0 && e > 0) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "Treating segment : " << segment 
+                << "  | Estimated time left: " << timeLeft << " seconds" << "\r" << flush;
+        }
+    } // end loop on entries
+
+    //===========================================================================================================
+    //                                       Output 
+    //===========================================================================================================
+    vector<vector<TH2F*>> hIC;
+    hIC.push_back(hIC_X);
+    hIC.push_back(hIC_Y);
+
+    return hIC;
+} // End HistoFiller
+
+
+/**
+  }
+ *  Create the spline for one TH2F
+ *
+ *  Input :
+ *     Pointer to a TH2F
+ *
+ *
+ *  Output:
+ *
+ *     TSpline3 : the output spline
+ *
+ */
+
+TSpline3* MakeSpline(TH2F* hInput, Int_t NCallee, double XMin = 0 , double
+        XMax = 1000 , double YMin=0 , double YMax = 100) {
+
+    TSpline3* gspline;
+
+    TH1F* hProfile;
+    TH1F* pfx; // extended hProfile
+
+    TCanvas* canfit = new TCanvas(Form("CanSpline_%02d",NCallee),
+            Form("canfit_%02d",NCallee), 0, 0, 1000, 500);
+
+
+    //===========================================================================================================
+    //                                            Init profile
+    //===========================================================================================================
+
+    // Create the TProfile
+    hProfile = (TH1F*)hInput->ProfileX();
+    hProfile->SetLineWidth(2);
+    hProfile->SetDirectory(0);
+    canfit->cd();
+
+    hProfile->GetYaxis()->SetRangeUser(YMin, YMax);
+    hProfile->Draw();
+    //===========================================================================================================
+    //                                          First and last bin to get to 6k
+    //                                          event get promoted
+    //===========================================================================================================
+    int FirstBin, LastBin;
+    double Treshold = 1;
+    for (int bin =1 ; bin<hProfile->GetNbinsX(); bin++) {
+        FirstBin = bin;
+        if (hProfile->GetBinLowEdge(bin)> XMin) break;
+    }
+    for (int bin = hProfile->GetNbinsX(); bin>1 ; bin--) {
+        LastBin = bin;
+        if (hProfile->GetBinLowEdge(bin)< XMax) break;
+    }
+    //===========================================================================================================
+    //                                          Init Extended profile function
+    //===========================================================================================================
+    // Create the extended TProfile
+    pfx = new TH1F(
+            Form("pfx_%02d", Int_t(NCallee/2)), Form("pfx_%02d", Int_t(NCallee/2)), hProfile->GetNbinsX(), hProfile->GetBinLowEdge(1),
+            hProfile->GetBinLowEdge(hProfile->GetNbinsX()) + hProfile->GetBinWidth(hProfile->GetNbinsX()));
+    pfx->SetLineColor(8);
+    pfx->SetDirectory(0);
+    //===========================================================================================================
+    //                                           Fill extended profile
+    //===========================================================================================================
+
+    // fill the extended TProfile
+    float newval, lastval, lasterr;
+    for (int bin = 1; bin <= FirstBin; bin++) {
+        newval = 0;
+        pfx->SetBinContent(bin, newval);
+    }
+
+
+    for (int bin = FirstBin; bin <= LastBin; bin++) {
+        newval = hProfile->GetBinContent(bin);
+        if (newval != 0) {
+            pfx->SetBinContent(bin, newval);
+            pfx->SetBinError(bin, hProfile->GetBinError(bin));
+            lastval = newval;
+            lasterr = hProfile->GetBinError(bin);
+        }
+        else {
+            pfx->SetBinContent(bin, lastval);
+            pfx->SetBinError(bin, lasterr);
+        }
+    }
+    pfx->Draw("same");
+
+    gspline = new TSpline3(pfx);
+    gspline->SetName(Form("fspline_%d", NCallee + 1));
+
+    return gspline;
+
+} // end makespline
+
+void HistoDrawer(vector<TH2F*> h,const char* CharName){
+
+    int NHisto = static_cast<int>(h.size());
+
+    TCanvas* Can= new TCanvas(CharName,CharName,0,0,2000,1000);
+
+    Can->Divide(NHisto);
+
+    for ( int i=0 ; i < NHisto ; i+=1 ){
+        //All x are even and all y are odd
+        int CanvaNumber = (i) ;
+        Can->cd(CanvaNumber);
+        h[i]->Draw("colz");
+    }
+}
diff --git a/Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioXY.C b/Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioXY.C
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/chio/CalibrationChio/SplineChioXY.C
rename to Projects/AlPhaPha/2024/macro/chio/YCalibration/SplineChioXY.C
diff --git a/Projects/AlPhaPha/2024/macro/mwpc/HistoPosFiller.cxx b/Projects/AlPhaPha/2024/macro/mwpc/Linearisation/HistoPosFiller.cxx
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/mwpc/HistoPosFiller.cxx
rename to Projects/AlPhaPha/2024/macro/mwpc/Linearisation/HistoPosFiller.cxx
diff --git a/Projects/AlPhaPha/2024/macro/mwpc/LinearisationTransfo.cxx b/Projects/AlPhaPha/2024/macro/mwpc/Linearisation/LinearisationTransfo.cxx
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/mwpc/LinearisationTransfo.cxx
rename to Projects/AlPhaPha/2024/macro/mwpc/Linearisation/LinearisationTransfo.cxx
diff --git a/Projects/AlPhaPha/2024/macro/mwpc/LinearisationTxt.cxx b/Projects/AlPhaPha/2024/macro/mwpc/Linearisation/LinearisationTxt.cxx
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/mwpc/LinearisationTxt.cxx
rename to Projects/AlPhaPha/2024/macro/mwpc/Linearisation/LinearisationTxt.cxx
diff --git a/Projects/AlPhaPha/2024/macro/mwpc/ReadMe.md b/Projects/AlPhaPha/2024/macro/mwpc/Linearisation/ReadMe.md
similarity index 100%
rename from Projects/AlPhaPha/2024/macro/mwpc/ReadMe.md
rename to Projects/AlPhaPha/2024/macro/mwpc/Linearisation/ReadMe.md
diff --git a/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx b/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..67cdf48e7998a346a967d7822d3081dec826d17d
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/mwpc/Toff/ToffGenerator.cxx
@@ -0,0 +1,514 @@
+#include "TICPhysics.h"
+#include "TTimeData.h"
+#include <TCanvas.h>
+#include <TChain.h>
+#include <TF1.h>
+#include <TFile.h>
+#include <TH2.h>
+#include <TLatex.h>
+#include <iostream>
+using namespace std;
+
+vector<int> SortSection(UShort_t STargFocal[2]);
+vector<double> ToffCalc(vector<double> ToffP2P);
+
+void ToffGenerator(bool Create = true ){
+
+    //===========================================================================================================
+    //                                              Setters
+    //===========================================================================================================
+
+    TChain* chain = new TChain("PhysicsTree");
+    chain->Add("../../../root/analysis/VamosCalib247.root");
+
+
+    Int_t M13 , M14, M23, M24 ;// we will fetch multiplicity during
+                               // the getentry
+
+    UShort_t S13[20] , S14[20] , S23[20] , S24[20];
+
+    TTimeData *Time = new TTimeData();
+    TICPhysics *IC = new TICPhysics();
+
+    chain->SetBranchStatus("MTOF_FP0_T0VN", true);
+    chain->SetBranchAddress("MTOF_FP0_T0VN", &S13);
+
+    chain->SetBranchStatus("MTOF_FP0_T1VN", true);
+    chain->SetBranchAddress("MTOF_FP0_T1VN", &S14);
+
+    chain->SetBranchStatus("MTOF_FP1_T0VN", true);
+    chain->SetBranchAddress("MTOF_FP1_T0VN", &S23);
+
+    chain->SetBranchStatus("MTOF_FP1_T1VN", true);
+    chain->SetBranchAddress("MTOF_FP1_T1VN", &S24);
+
+    chain->SetBranchStatus("Time", true);
+    chain->SetBranchAddress("Time", &Time);
+
+    chain->SetBranchStatus("IC", true);
+    chain->SetBranchAddress("IC", &IC);
+    //===========================================================================================================
+    //                              Histograms
+    //===========================================================================================================
+
+    TH2F *hToff13;
+    TH2F *hToff14;
+    TH2F *hToff23;
+    TH2F *hToff24;
+
+    TH2F *hToffOnline13;
+    TH2F *hToffOnline14;
+    TH2F *hToffOnline23;
+    TH2F *hToffOnline24;
+
+
+    double xmin[4], xmax[4];
+    double ymin[4], ymax[4];
+    int binx = 20 , biny = 400;
+    
+    xmin[0] = 0 ; xmax[0] = 20 ; ymin[0] = -10 ; ymax[0] = 10 ;
+    xmin[1] = 0 ; xmax[1] = 20 ; ymin[1] = -10 ; ymax[1] = 10 ;
+    xmin[2] = 0 ; xmax[2] = 20 ; ymin[2] = -10 ; ymax[2] = 10 ;
+    xmin[3] = 0 ; xmax[3] = 20 ; ymin[3] = -10 ; ymax[3] = 10 ;
+
+    // Toff from aligning AoQ
+    double Toff[20] = {0, 588.0, 588.5, 587.95, 588.04, 587.72, 587.92, 587.9, 587.9, 588.66, 588.80, 588.67, 588.64, 588.75, 588.47, 588.65, 588.65, 588.67, 589.05, 590.3};
+
+    if (Create == true){
+
+        hToff13 = new TH2F("Toff13","Toff13",binx ,xmin[0] , xmax[0], biny, ymin[0], ymax[0]);
+        hToff14 = new TH2F("Toff14","Toff14",binx ,xmin[1] , xmax[1], biny, ymin[1], ymax[1]);
+        hToff23 = new TH2F("Toff23","Toff23",binx ,xmin[2] , xmax[2], biny, ymin[2], ymax[2]);
+        hToff24 = new TH2F("Toff24","Toff24",binx ,xmin[3] , xmax[3], biny, ymin[3], ymax[3]);
+
+        hToffOnline13 = new TH2F("ToffOnline13","ToffOnline13",binx ,xmin[0] , xmax[0], biny, ymin[0], ymax[0]);
+        hToffOnline14 = new TH2F("ToffOnline14","ToffOnline14",binx ,xmin[1] , xmax[1], biny, ymin[1], ymax[1]);
+        hToffOnline23 = new TH2F("ToffOnline23","ToffOnline23",binx ,xmin[2] , xmax[2], biny, ymin[2], ymax[2]);
+        hToffOnline24 = new TH2F("ToffOnline24","ToffOnline24",binx ,xmin[3] , xmax[3], biny, ymin[3], ymax[3]);
+
+
+        //===========================================================================================================
+        //                            Loop on entries
+        //===========================================================================================================
+        int Nentries = chain->GetEntries();
+        //int Nentries = 1000000;
+        auto start = std::chrono::high_resolution_clock::now();
+
+        for (int e = 0; e < Nentries; e++) {
+
+            chain->GetEntry(e);
+
+            if (e % 100000  == 0 && e > 0 ) {
+                auto now = std::chrono::high_resolution_clock::now();
+                std::chrono::duration<double> elapsed = now - start;
+                double avgTimePerIteration = elapsed.count() / e;
+                double timeLeft = avgTimePerIteration * (Nentries - e);
+
+                std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+            }
+
+            // Get Multiplicity
+            M13 = Time->GetMWPC13Mult();
+            M14 = Time->GetMWPC14Mult();
+            M23 = Time->GetMWPC23Mult();
+            M24 = Time->GetMWPC24Mult();
+            
+
+            if (M13 == 2 && (abs(S13[0]-S13[1]) == 1)){
+                vector<int> Pos = SortSection(S13);
+                hToff13->Fill(S13[0],  Time->GetTime_MWPC13(Pos[0])  - Time->GetTime_MWPC13(Pos[1])  );
+
+                hToffOnline13->Fill(S13[0], (Time->GetTime_MWPC13(Pos[0]) - Toff[S13[0]]) -( Time->GetTime_MWPC13(Pos[1]) -Toff[S13[1]]  )); 
+            }
+            if (M23 == 2 && (abs(S23[0]-S23[1]) == 1)){
+                vector<int> Pos = SortSection(S23);
+                hToff23->Fill(S23[0],Time->GetTime_MWPC23(Pos[0]) - Time->GetTime_MWPC23(Pos[1])); 
+                hToffOnline23->Fill(S23[0],(Time->GetTime_MWPC23(Pos[0]) - Toff[S23[0]]) -( Time->GetTime_MWPC23(Pos[1])  -Toff[S23[1]]  )   ); 
+            }
+
+            if (M14 == 2 && (abs(S14[0]-S14[1]) == 1)){
+                vector<int> Pos = SortSection(S14);
+                hToff14->Fill(S14[0],Time->GetTime_MWPC14(Pos[0]) - Time->GetTime_MWPC14(Pos[1])); 
+                hToffOnline14->Fill(S14[0],(Time->GetTime_MWPC14(Pos[0]) - Toff[S14[0]]) -( Time->GetTime_MWPC14(Pos[1])  -Toff[S14[1]]  )   ); 
+            }
+
+            if (M24 == 2 && (abs(S24[0]-S24[1]) == 1)){
+                vector<int> Pos = SortSection(S24);
+                hToff24->Fill(S24[0],Time->GetTime_MWPC24(Pos[0]) - Time->GetTime_MWPC24(Pos[1])); 
+                hToffOnline24->Fill(S24[0],(Time->GetTime_MWPC24(Pos[0]) - Toff[S24[0]]) -( Time->GetTime_MWPC24(Pos[1])  -Toff[S24[1]]  )   ); 
+            }
+        } // End loop event
+
+        TFile *out = new TFile("output/ToffHisto.root","recreate");
+        hToff13->Write();
+        hToff14->Write();
+        hToff23->Write();
+        hToff24->Write();
+        
+        hToffOnline13->Write();
+        hToffOnline14->Write();
+        hToffOnline23->Write();
+        hToffOnline24->Write();
+    }// end if create
+
+    else {
+
+        TFile *in = new TFile("output/ToffHisto.root","open");
+        hToff13 = (TH2F*)in->Get("Toff13");
+        hToff14 = (TH2F*)in->Get("Toff14");
+        hToff23 = (TH2F*)in->Get("Toff23");
+        hToff24 = (TH2F*)in->Get("Toff24");
+
+        hToffOnline13 = (TH2F*)in->Get("ToffOnline13");
+        hToffOnline14 = (TH2F*)in->Get("ToffOnline14");
+        hToffOnline23 = (TH2F*)in->Get("ToffOnline23");
+        hToffOnline24 = (TH2F*)in->Get("ToffOnline24");
+
+    }
+
+    int MinX = 2;
+    hToff13->SetMinimum(MinX);
+    hToff14->SetMinimum(MinX);
+    hToff23->SetMinimum(MinX);
+    hToff24->SetMinimum(MinX);
+    //===========================================================================================================
+    //                                       Proj fit
+    //===========================================================================================================
+    TCanvas* c13 = new TCanvas("c13", "Toff13", 1800, 1600);
+    c13->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here)
+
+    TCanvas* c14 = new TCanvas("c14", "Toff14", 1800, 1600);
+    c14->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here)
+
+    TCanvas* c23 = new TCanvas("c23", "Toff23", 1800, 1600);
+    c23->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here)
+
+    TCanvas* c24 = new TCanvas("c24", "Toff24", 1800, 1600);
+    c24->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here)
+
+    vector<double> P2PToff13(19), P2PToff14(19) , P2PToff23(19), P2PToff24(19);
+
+    // Loop through bins and draw each fit
+    for (int binX = 1; binX <= hToff13->GetNbinsX()-1; ++binX) {
+
+        c13->cd(binX); 
+
+        // Create a projection along the Y-axis for the current X-bin
+        TH1F* proj = (TH1F*)hToff13->ProjectionY(Form("proj_bin13%d", binX), binX, binX);
+        proj->SetMinimum(MinX);
+
+        // Fit the projection with a Gaussian
+        TF1* fit = new TF1(Form("fit_bin%d", binX), "gaus",-5,5);
+
+        // Select subpad and draw
+        proj->Fit(fit,"R"); // Suppress output with "Q"
+        proj->Draw();
+        fit->SetLineColor(kRed); // Optional: Differentiate fit line
+        fit->Draw("SAME");
+
+        // Retrieve fit parameters
+        double mean = fit->GetParameter(1);
+        double sigma = fit->GetParameter(2);
+        P2PToff13.at(binX-1) = mean;
+
+        // Add fit results to the subpad using TLatex
+        TLatex text;
+        text.SetNDC();
+        text.SetTextSize(0.05);
+        text.SetTextAlign(13); // Align at top-left corner
+        text.DrawLatex(0.15, 0.85, Form("#mu = %.2f", mean));
+        text.DrawLatex(0.15, 0.75, Form("#sigma = %.2f", sigma));
+
+
+        // Save the mean to the text file
+
+    }
+    // Display the canvas
+    c13->Update();
+
+    // Loop through bins and draw each fit
+    for (int binX = 1; binX <= hToff14->GetNbinsX()-1; ++binX) {
+
+        c14->cd(binX); 
+
+        // Create a projection along the Y-axis for the current X-bin
+        TH1F* proj = (TH1F*)hToff14->ProjectionY(Form("proj_bin14%d", binX), binX, binX);
+        proj->SetMinimum(MinX);
+
+        // Fit the projection with a Gaussian
+        TF1* fit = new TF1(Form("fit_bin%d", binX), "gaus");
+
+        // Select subpad and draw
+        proj->Fit(fit); // Suppress output with "Q"
+        proj->Draw();
+        fit->SetLineColor(kRed); // Optional: Differentiate fit line
+        fit->Draw("SAME");
+
+        // Retrieve fit parameters
+        double mean = fit->GetParameter(1);
+        double sigma = fit->GetParameter(2);
+        P2PToff14.at(binX-1) = mean;
+
+
+
+        // Add fit results to the subpad using TLatex
+        TLatex text;
+        text.SetNDC();
+        text.SetTextSize(0.05);
+        text.SetTextAlign(13); // Align at top-left corner
+        text.DrawLatex(0.15, 0.85, Form("#mu = %.2f", mean));
+        text.DrawLatex(0.15, 0.75, Form("#sigma = %.2f", sigma));
+
+
+        // Save the mean to the text file
+
+    }
+    // Display the canvas
+    c14->Update();
+
+
+    // Loop through bins and draw each fit
+    for (int binX = 1; binX <= hToff23->GetNbinsX()-1; ++binX) {
+
+        c23->cd(binX); 
+
+        // Create a projection along the Y-axis for the current X-bin
+        TH1F* proj = (TH1F*)hToff23->ProjectionY(Form("proj_bin23%d", binX), binX, binX);
+        proj->SetMinimum(MinX);
+
+        // Fit the projection with a Gaussian
+        TF1* fit = new TF1(Form("fit_bin%d", binX), "gaus");
+
+        // Select subpad and draw
+        proj->Fit(fit); // Suppress output with "Q"
+        proj->Draw();
+        fit->SetLineColor(kRed); // Optional: Differentiate fit line
+        fit->Draw("SAME");
+
+        // Retrieve fit parameters
+        double mean = fit->GetParameter(1);
+        double sigma = fit->GetParameter(2);
+        P2PToff23.at(binX-1) = mean;
+
+        // Add fit results to the subpad using TLatex
+        TLatex text;
+        text.SetNDC();
+        text.SetTextSize(0.05);
+        text.SetTextAlign(13); // Align at top-left corner
+        text.DrawLatex(0.15, 0.85, Form("#mu = %.2f", mean));
+        text.DrawLatex(0.15, 0.75, Form("#sigma = %.2f", sigma));
+
+
+        // Save the mean to the text file
+
+    }
+    // Display the canvas
+    c23->Update();
+
+    // Loop through bins and draw each fit
+    for (int binX = 1; binX <= hToff24->GetNbinsX()-1; ++binX) {
+
+        c24->cd(binX); 
+
+        // Create a projection along the Y-axis for the current X-bin
+        TH1F* proj = (TH1F*)hToff24->ProjectionY(Form("proj_bin24%d", binX), binX, binX);
+        proj->SetMinimum(MinX);
+
+        // Fit the projection with a Gaussian
+        TF1* fit = new TF1(Form("fit_bin%d", binX), "gaus");
+
+        // Select subpad and draw
+        proj->Fit(fit,"Q"); // Suppress output with "Q"
+        proj->Draw();
+        fit->SetLineColor(kRed); // Optional: Differentiate fit line
+        fit->Draw("SAME");
+
+        // Retrieve fit parameters
+        double mean = fit->GetParameter(1);
+        double sigma = fit->GetParameter(2);
+        P2PToff24.at(binX-1) = mean;
+
+        // Add fit results to the subpad using TLatex
+        TLatex text;
+        text.SetNDC();
+        text.SetTextSize(0.05);
+        text.SetTextAlign(13); // Align at top-left corner
+        text.DrawLatex(0.15, 0.85, Form("#mu = %.2f", mean));
+        text.DrawLatex(0.15, 0.75, Form("#sigma = %.2f", sigma));
+
+
+        // Save the mean to the text file
+
+    }
+    // Display the canvas
+    c24->Update();  
+
+    //===========================================================================================================
+    //                                          Saving correction
+    //===========================================================================================================
+
+
+    //First we get the absolute correction to use on each section
+    vector<double> Toff13, Toff14, Toff23, Toff24;
+    Toff13 = ToffCalc(P2PToff13);
+    Toff23 = ToffCalc(P2PToff23);
+    Toff14 = ToffCalc(P2PToff14);
+    Toff24 = ToffCalc(P2PToff24);
+
+    //Save it in a txt file
+    ofstream o13("output/Toff13.txt");
+    ofstream o23("output/Toff23.txt");
+    ofstream o14("output/Toff14.txt");
+    ofstream o24("output/Toff24.txt");
+
+    for (auto &elem : Toff13) o13 << elem << endl;
+    for (auto &elem : Toff14) o14 << elem << endl;
+    for (auto &elem : Toff23) o23 << elem << endl;
+    for (auto &elem : Toff24) o24 << elem << endl;
+
+
+    //===========================================================================================================
+    //                                       Testing correction
+    //===========================================================================================================
+
+
+    TH2F*  hCorrToff13 = new TH2F("CorrToff13","CorrToff13",binx ,xmin[0] , xmax[0], biny, ymin[0], ymax[0]);
+    TH2F*  hCorrToff14 = new TH2F("CorrToff14","CorrToff14",binx ,xmin[1] , xmax[1], biny, ymin[1], ymax[1]);
+    TH2F*  hCorrToff23 = new TH2F("CorrToff23","CorrToff23",binx ,xmin[2] , xmax[2], biny, ymin[2], ymax[2]);
+    TH2F*  hCorrToff24 = new TH2F("CorrToff24","CorrToff24",binx ,xmin[3] , xmax[3], biny, ymin[3], ymax[3]);
+
+
+    int Nentries = chain->GetEntries();
+    //int Nentries = 1000000;
+    auto start = std::chrono::high_resolution_clock::now();
+
+    for (int e = 0; e < Nentries; e++) {
+
+        chain->GetEntry(e);
+
+        if (e % 100000  == 0 && e > 0 ) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / e;
+            double timeLeft = avgTimePerIteration * (Nentries - e);
+
+            std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+        }
+
+        // Get Multiplicity
+        M13 = Time->GetMWPC13Mult();
+        M14 = Time->GetMWPC14Mult();
+        M23 = Time->GetMWPC23Mult();
+        M24 = Time->GetMWPC24Mult();
+
+
+
+        if (M13 == 2 && (abs(S13[0]-S13[1]) == 1)){
+
+            vector<int> Pos = SortSection(S13);
+            hCorrToff13->Fill(S13[0],(Time->GetTime_MWPC13(Pos[0]) - double(Time->GetTS_MWPC13(Pos[0]))+ Toff13.at(S13[0])) - (Time->GetTime_MWPC13(Pos[1]) - double(Time->GetTS_MWPC13(Pos[1]))+ Toff13.at(S13[1])));
+        }
+
+
+        if (M23 == 2 && (abs(S23[0]-S23[1]) == 1)){
+            vector<int> Pos = SortSection(S23);
+            hCorrToff23->Fill(S23[0],(Time->GetTime_MWPC23(Pos[0]) + Toff23.at(S23[0])) - (Time->GetTime_MWPC23(Pos[1]) + Toff23.at(S23[1])));
+        }
+
+
+        if (M14 == 2 && (abs(S14[0]-S14[1]) == 1)){
+            vector<int> Pos = SortSection(S14);
+            hCorrToff14->Fill(S14[0],(Time->GetTime_MWPC14(Pos[0]) + Toff14.at(S14[0])) - (Time->GetTime_MWPC14(Pos[1]) + Toff14.at(S14[1])));
+        }
+
+
+        if (M24 == 2 && (abs(S24[0]-S24[1]) == 1)){
+            vector<int> Pos = SortSection(S24);
+            hCorrToff24->Fill(S24[0],(Time->GetTime_MWPC24(Pos[0]) + Toff24.at(S24[0])) - (Time->GetTime_MWPC24(Pos[1]) + Toff24.at(S24[1])));
+        }
+
+
+    } // End loop event
+
+    //===========================================================================================================
+    //                                       Drawing canvas
+    //===========================================================================================================
+
+    TCanvas *c1 = new TCanvas("c1","c1");
+    c1->Divide(3);
+
+    c1->cd(1);
+    hToff13->Draw("colz");
+    c1->cd(2);
+    hCorrToff13->Draw("colz");
+    c1->cd(3);
+    hToffOnline13->Draw("colz");
+
+
+    TCanvas *c2 = new TCanvas("c2","c2");
+    c2->Divide(3);
+
+    c2->cd(1);
+    hToff23->Draw("colz");
+    c2->cd(2);
+    hCorrToff23->Draw("colz");
+    c2->cd(3);
+    hToffOnline23->Draw("colz");
+
+
+
+    TCanvas *c3 = new TCanvas("c3","c3");
+    c3->Divide(3);
+
+    c3->cd(1);
+    hToff14->Draw("colz");
+    c3->cd(2);
+    hCorrToff14->Draw("colz");
+    c3->cd(3);
+    hToffOnline14->Draw("colz");
+
+
+    TCanvas *c4 = new TCanvas("c4","c4");
+    c4->Divide(3);
+
+    c4->cd(1);
+    hToff24->Draw("colz");
+    c4->cd(2);
+    hCorrToff24->Draw("colz");
+    c4->cd(3);
+    hToffOnline24->Draw("colz");
+
+}
+
+vector<int> SortSection(UShort_t STargFocal[2]){
+    UShort_t FSection ,LSection ;
+    vector<int> Pos(2) ;
+    if (STargFocal[0]<STargFocal[1]){
+        Pos[0] = 0    ;
+        Pos[1]  = 1    ;
+        FSection = STargFocal[0];
+        LSection = STargFocal[1];
+    }
+    else {
+        Pos[0] = 1    ;
+        Pos[1]  = 0   ;
+        FSection = STargFocal[1];
+        LSection = STargFocal[0];    
+    }
+
+    STargFocal[0] = FSection;
+    STargFocal[1] = LSection;
+    return Pos; 
+}
+
+vector<double> ToffCalc(vector<double> ToffP2P){
+
+    vector<double> res;
+    double Sum = 0;
+    res.push_back(Sum); // first section 
+    for (int i=0; i<ToffP2P.size() ; i++){
+        Sum += ToffP2P.at(i);
+        res.push_back(Sum);
+    }
+    return res;
+}
diff --git a/Projects/AlPhaPha/2024/macro/mwpc/Toff/output/ReadMe.md b/Projects/AlPhaPha/2024/macro/mwpc/Toff/output/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..b9c3d0261a8238e58145e56b1b1804a454f11bf7
--- /dev/null
+++ b/Projects/AlPhaPha/2024/macro/mwpc/Toff/output/ReadMe.md
@@ -0,0 +1 @@
+# Output here
diff --git a/Projects/AlPhaPha/DataMacro/Merger.C b/Projects/AlPhaPha/DataMacro/Merger.C
index aea1e96403ffeb705ed143b8440f7f0de18f75c5..66c65707a18abfc391fc2071159fa1789e034faf 100644
--- a/Projects/AlPhaPha/DataMacro/Merger.C
+++ b/Projects/AlPhaPha/DataMacro/Merger.C
@@ -11,7 +11,7 @@ void Merger(int N, const char* outputDir, const char* outputFileName, const char
             continue;
         }
         merger.AddFile(fileName);  // Add file to the merger
-
+        cout << "Added file " << fileName << endl; 
         // Display progress
         int progress = ((i + 1) * 100) / N;
         std::cout << "\rMerging files: " << progress << "% complete." << std::flush;
diff --git a/Projects/AlPhaPha/DataMacro/output/ReadMe.md b/Projects/AlPhaPha/DataMacro/output/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..7f7cf92728778dc17d27c4bab8a9c12808786473
--- /dev/null
+++ b/Projects/AlPhaPha/DataMacro/output/ReadMe.md
@@ -0,0 +1,9 @@
+# How it works
+
+Please create a directory holding the data cut by Secator.C
+
+```
+mkdir run_RUNUMBER
+
+```
+and use secator to cut the data in the directory
diff --git a/Projects/AlPhaPha/DataMacro/output/analysis/ReadMe.md b/Projects/AlPhaPha/DataMacro/output/analysis/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..91298cc8030a794f4558a4d27001a2a1aa29e82f
--- /dev/null
+++ b/Projects/AlPhaPha/DataMacro/output/analysis/ReadMe.md
@@ -0,0 +1,9 @@
+# How it works
+
+Please create a directory holding the data analysed by the snakemake before
+merger
+
+```
+mkdir run_RUNUMBER
+
+```
diff --git a/Projects/AlPhaPha/conversion/2024/ChainConvert.sh b/Projects/AlPhaPha/conversion/2024/ChainConvert.sh
index fdffedb5e2d53aa3cd91e650c69db8c3483fec90..a3933aa0fc4702e222e307e792c020850e0808ac 100644
--- a/Projects/AlPhaPha/conversion/2024/ChainConvert.sh
+++ b/Projects/AlPhaPha/conversion/2024/ChainConvert.sh
@@ -3,11 +3,15 @@
 max_jobs=20  # Set the maximum number of parallel jobs (cores)
 
 for run in {201..260}; do
-  while [ $(jobs | wc -l) -ge $max_jobs ]; do
+  while [ $(jobs -r | wc -l) -ge $max_jobs ]; do
     wait -n  # Wait for at least one job to finish
+    echo "A job has finished. $(jobs -r | wc -l) jobs remaining."
   done
-  root "convert.C($run)" &
+  root -b -q "convert.C($run)" &
+  echo "Started job for run $run. $(jobs -r | wc -l) jobs currently running."
 done
 
-wait  # Wait for all jobs to finish
+# Ensure all remaining jobs are completed
+wait
+echo "All jobs are complete."
 
diff --git a/Projects/AlPhaPha/conversion/2024/convert.C b/Projects/AlPhaPha/conversion/2024/convert.C
index 51574c3217b63cd54c6c330b563d0faac551ba9f..18862b4db7ae08b352682ad41b75c31096815830 100644
--- a/Projects/AlPhaPha/conversion/2024/convert.C
+++ b/Projects/AlPhaPha/conversion/2024/convert.C
@@ -4,6 +4,7 @@ void convert(int run=204){
   m_pista = new TPISTAData();
   m_fpmw = new TFPMWData();
   m_ic = new TICData();
+  m_time = new TTimeData();
   m_exogam = new TExogamCalData();
 
   int Year = 2024;
@@ -23,6 +24,7 @@ void convert(int run=204){
   output_tree->Branch("PISTA","TPISTAData",&m_pista);
   output_tree->Branch("FPMW","TFPMWData",&m_fpmw);
   output_tree->Branch("IC","TICData",&m_ic);
+  output_tree->Branch("Time","TTimeData",&m_time);
   output_tree->Branch("Exogam","TExogamCalData",&m_exogam);
 
   output_tree->Branch("T_TMW0_FPMW0",&T_TMW0_FPMW0,"T_TMW0_FPMW0/F");
@@ -53,98 +55,134 @@ void convert(int run=204){
 
 
 
+  auto start = std::chrono::high_resolution_clock::now();
   int nentries = input_tree->GetEntries();
   for(int i=0; i<nentries; i++){
     Clear();
     input_tree->GetEntry(i);
-    if(i%10000==0) cout << "\033[34m\rProcessing tree... " <<(double)i/nentries*100 << "\% done" << flush;
+
+
+    if (i % 100000  == 0 && i > 0 ) {
+            auto now = std::chrono::high_resolution_clock::now();
+            std::chrono::duration<double> elapsed = now - start;
+            double avgTimePerIteration = elapsed.count() / i;
+            double timeLeft = avgTimePerIteration * (nentries - i);
+
+            std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
+        }
     
    fVAMOS_TS_sec = TMWPat_0TS*1e-8;
    fPISTA_TS_sec = PISTA_TS*1e-8;
 
     // IC //
-    for(int i=0; i<11; i++){
+    for (int i=0; i<ICRawM; i++){
+      m_ic->SetIC_TS(ICRawTS[i]);
       m_ic->SetIC_Section(i+1);
       m_ic->SetIC_Charge(IC[i]);
     }
 
+    // Time //
+    
+    for (int i=0; i<MTOF_FP0_T0VM;i++){
+        m_time->SetTS_MWPC13(MTOF_FP0_T0VTS[i]); 
+        m_time->SetTime_MWPC13(MTOF_FP0_T0V[i]); 
+        m_time->SetSection_MWPC3(MTOF_FP0_T0VN[i]); 
+    }
+    for (int i=0; i<MTOF_FP0_T1VM;i++){
+        m_time->SetTS_MWPC23(MTOF_FP0_T1VTS[i]);
+        m_time->SetTime_MWPC23(MTOF_FP0_T1V[i]);
+    }
+
+    for (int i=0; i<MTOF_FP1_T0VM;i++){
+        m_time->SetTS_MWPC14(MTOF_FP1_T0VTS[i]); 
+        m_time->SetTime_MWPC14(MTOF_FP1_T0V[i]); 
+        m_time->SetSection_MWPC4(MTOF_FP1_T0VN[i]); 
+    }
+
+    for (int i=0; i<MTOF_FP1_T1VM;i++){
+        m_time->SetTS_MWPC24(MTOF_FP1_T1VTS[i]); 
+        m_time->SetTime_MWPC24(MTOF_FP1_T1V[i]); 
+    }
+
+
+
     // -TMW1- //
     for(int p=0;p<TMW1_XRawM; p++){
-      int strip = TMW1_XRawNr[p];
-      double charge = TMW1_XRaw[p];
-      m_fpmw->SetFPMW_X(1,strip,charge);
+        int strip = TMW1_XRawNr[p];
+        double charge = TMW1_XRaw[p];
+        m_fpmw->SetFPMW_X(1,strip,charge);
     }
     for(int p=0;p<TMW1_YRawM; p++){
-      int strip = TMW1_YRawNr[p];
-      double charge = TMW1_YRaw[p];
-      m_fpmw->SetFPMW_Y(1,strip,charge);
+        int strip = TMW1_YRawNr[p];
+        double charge = TMW1_YRaw[p];
+        m_fpmw->SetFPMW_Y(1,strip,charge);
     }
     // -TMW2- //
     for(int p=0;p<TMW2_XRawM; p++){
-      int strip = TMW2_XRawNr[p];
-      double charge = TMW2_XRaw[p];
-      m_fpmw->SetFPMW_X(2,strip,charge);
+        int strip = TMW2_XRawNr[p];
+        double charge = TMW2_XRaw[p];
+        m_fpmw->SetFPMW_X(2,strip,charge);
     }
     for(int p=0;p<TMW2_YRawM; p++){
-      int strip = TMW2_YRawNr[p];
-      double charge = TMW2_YRaw[p];
-      m_fpmw->SetFPMW_Y(2,strip,charge);
+        int strip = TMW2_YRawNr[p];
+        double charge = TMW2_YRaw[p];
+        m_fpmw->SetFPMW_Y(2,strip,charge);
     }
 
     // -FPMW0- //
     for(int p=0;p<FPMW0_XRawM; p++){
-      int strip = FPMW0_XRawNr[p];
-      double charge = FPMW0_XRaw[p];
-      m_fpmw->SetFPMW_X(3,strip,charge);
+        int strip = FPMW0_XRawNr[p];
+        double charge = FPMW0_XRaw[p];
+        m_fpmw->SetFPMW_X(3,strip,charge);
     }
     for(int p=0;p<FPMW0_YRawM; p++){
-      int strip = FPMW0_YRawNr[p];
-      double charge = FPMW0_YRaw[p];
-      m_fpmw->SetFPMW_Y(3,strip,charge);
+        int strip = FPMW0_YRawNr[p];
+        double charge = FPMW0_YRaw[p];
+        m_fpmw->SetFPMW_Y(3,strip,charge);
     }
     // -FPMW1- //
     for(int p=0;p<FPMW1_XRawM; p++){
-      int strip = FPMW1_XRawNr[p];
-      double charge = FPMW1_XRaw[p];
-      m_fpmw->SetFPMW_X(4,strip,charge);
+        int strip = FPMW1_XRawNr[p];
+        double charge = FPMW1_XRaw[p];
+        m_fpmw->SetFPMW_X(4,strip,charge);
     }
     for(int p=0;p<FPMW1_YRawM; p++){
-      int strip = FPMW1_YRawNr[p];
-      double charge = FPMW1_YRaw[p];
-      m_fpmw->SetFPMW_Y(4,strip,charge);
+        int strip = FPMW1_YRawNr[p];
+        double charge = FPMW1_YRaw[p];
+        m_fpmw->SetFPMW_Y(4,strip,charge);
     }
 
     if(fVAMOS_TS_sec>0 || fPISTA_TS_sec>0){
-      if(OutersVM<25){
-        for(int p=0; p<Inner6MVM; p++){
-          //if(Inner6MVM==2) cout << "********p= " << p << endl;
-          int crystal = Inner6MVN[p];
-          double E = Inner6MV[p];
-          double EHG = Inner20MV[p];
-          double TDC = DeltaTV[p];  // Existe pas en 2024
-          unsigned long long TS = Inner6MVTS[p];
-          int seg = -1;
-          double outers1 = -1000;
-          double outers2 = -1000;
-          double outers3 = -1000;
-          double outers4 = -1000;
-
-          //cout << "*****************mult= " << OutersVM << endl;
-          for(int i=0; i<OutersVM; i++){
-            seg = OutersVN[i] - 4*crystal;
-            // cout << i << " " << OutersVN[i] << " " << crystal << " " << seg << endl;
-            if(seg==0) outers1 = OutersV[i];
-            else if(seg==1) outers2 = OutersV[i];
-            else if(seg==2) outers3 = OutersV[i];
-            else if(seg==3) outers4 = OutersV[i];
-          }
-          m_exogam->SetExo(crystal,E,EHG,TS,TDC,0,0,outers1,outers2,outers3,outers4);
-          //cout << outers1 << " " << outers2 << " " << outers3 << " " << outers4 << endl;
-          //if(Inner6MVM==2){
-          //  cout << "setting p= " << p << " " << outers1 << " " << outers2 << " " << outers3 << " " << outers4 << endl;
-          //}
+        if(OutersVM<25){
+            for(int p=0; p<Inner6MVM; p++){
+                //if(Inner6MVM==2) cout << "********p= " << p << endl;
+                int crystal = Inner6MVN[p];
+                double E = Inner6MV[p];
+                double EHG = Inner20MV[p];
+                double TDC = DeltaTV[p];  // Existe pas en 2024
+                unsigned long long TS = Inner6MVTS[p];
+                int seg = -1;
+                double outers1 = -1000;
+                double outers2 = -1000;
+                double outers3 = -1000;
+                double outers4 = -1000;
+
+                //cout << "*****************mult= " << OutersVM << endl;
+                for(int i=0; i<OutersVM; i++){
+                    seg = OutersVN[i] - 4*crystal;
+                    // cout << i << " " << OutersVN[i] << " " << crystal << " " << seg << endl;
+                    if(seg==0) outers1 = OutersV[i];
+                    else if(seg==1) outers2 = OutersV[i];
+                    else if(seg==2) outers3 = OutersV[i];
+                    else if(seg==3) outers4 = OutersV[i];
+                }
+                m_exogam->SetExo(crystal,E,EHG,TS,TDC,0,0,outers1,outers2,outers3,outers4);
+                //cout << outers1 << " " << outers2 << " " << outers3 << " " << outers4 << endl;
+                //if(Inner6MVM==2){
+                //  cout << "setting p= " << p << " " << outers1 << " " << outers2 << " " << outers3 << " " << outers4 << endl;
+                //}
+            }
         }
-      }
     }
 
     if(fPISTA_TS_sec>0 || fVAMOS_TS_sec>0)
@@ -159,145 +197,160 @@ void convert(int run=204){
 
 ///////////////////////////////////////////////////
 void Clear(){
-  m_fpmw->Clear();
-  m_ic->Clear();
-  m_pista->Clear();
-  m_exogam->Clear();
+    m_fpmw->Clear();
+    m_ic->Clear();
+    m_time->Clear();
+    m_pista->Clear();
+    m_exogam->Clear();
 }
 
 
 ///////////////////////////////////////////////////
 void InitInputTree(){
-  input_tree->SetBranchAddress("PISTA",&m_pista);
-
-  // TAC
-  input_tree->SetBranchStatus("T_TMW1_FPMW0_C","true");
-  input_tree->SetBranchAddress("T_TMW1_FPMW0_C",&T_TMW0_FPMW0);
-  input_tree->SetBranchStatus("T_TMW1_FPMW1_C","true");
-  input_tree->SetBranchAddress("T_TMW1_FPMW1_C",&T_TMW0_FPMW1);
-  input_tree->SetBranchStatus("T_TMW2_FPMW0_C","true");
-  input_tree->SetBranchAddress("T_TMW2_FPMW0_C",&T_TMW1_FPMW0);
-  input_tree->SetBranchStatus("T_TMW2_FPMW1_C","true");
-  input_tree->SetBranchAddress("T_TMW2_FPMW1_C",&T_TMW1_FPMW1);
-
-  // Pat
-  //input_tree->SetBranchStatus("MTOF_FP0_T0VN","true");
-  //input_tree->SetBranchAddress("MTOF_FP0_T0VN",&fFPMWPat_0RawNr);
-  input_tree->SetBranchStatus("TMWPat_00TS","true");
-  input_tree->SetBranchAddress("TMWPat_00TS",&TMWPat_0TS);
-  input_tree->SetBranchStatus("PISTA_TS","true");
-  input_tree->SetBranchAddress("PISTA_TS",&PISTA_TS);
-
-  //MTOF
-
-  input_tree->SetBranchStatus("MTOF_FP0_T0VN","true");
-  input_tree->SetBranchAddress("MTOF_FP0_T0VN",&MTOF_FP0_T0VN);
-  input_tree->SetBranchStatus("MTOF_FP1_T0VN","true");
-  input_tree->SetBranchAddress("MTOF_FP1_T0VN",&MTOF_FP1_T0VN);
-  input_tree->SetBranchStatus("MTOF_FP0_T1VN","true");
-  input_tree->SetBranchAddress("MTOF_FP0_T1VN",&MTOF_FP0_T1VN);
-  input_tree->SetBranchStatus("MTOF_FP1_T1VN","true");
-  input_tree->SetBranchAddress("MTOF_FP1_T1VN",&MTOF_FP1_T1VN);
-
-  input_tree->SetBranchStatus("MTOF_FP0_T0VM","true");
-  input_tree->SetBranchAddress("MTOF_FP0_T0VM",&MTOF_FP0_T0VM);
-  input_tree->SetBranchStatus("MTOF_FP1_T0VM","true");
-  input_tree->SetBranchAddress("MTOF_FP1_T0VM",&MTOF_FP1_T0VM);
-  input_tree->SetBranchStatus("MTOF_FP0_T1VM","true");
-  input_tree->SetBranchAddress("MTOF_FP0_T1VM",&MTOF_FP0_T1VM);
-  input_tree->SetBranchStatus("MTOF_FP1_T1VM","true");
-  input_tree->SetBranchAddress("MTOF_FP1_T1VM",&MTOF_FP1_T1VM);
-
-  input_tree->SetBranchStatus("MTOF_FP0_T0V","true");
-  input_tree->SetBranchAddress("MTOF_FP0_T0V",&MTOF_FP0_T0V);
-  input_tree->SetBranchStatus("MTOF_FP1_T0V","true");
-  input_tree->SetBranchAddress("MTOF_FP1_T0V",&MTOF_FP1_T0V);
-  input_tree->SetBranchStatus("MTOF_FP0_T1V","true");
-  input_tree->SetBranchAddress("MTOF_FP0_T1V",&MTOF_FP0_T1V);
-  input_tree->SetBranchStatus("MTOF_FP1_T1V","true");
-  input_tree->SetBranchAddress("MTOF_FP1_T1V",&MTOF_FP1_T1V);
-
-
-
-  // IC
-  input_tree->SetBranchStatus("IC","true");
-  input_tree->SetBranchAddress("IC",&IC);
-
-  // FPMW0-X
-  input_tree->SetBranchStatus("FPMW0_XRawM","true");
-  input_tree->SetBranchAddress("FPMW0_XRawM",&FPMW0_XRawM);
-  input_tree->SetBranchStatus("FPMW0_XRaw","true");
-  input_tree->SetBranchAddress("FPMW0_XRaw",FPMW0_XRaw);
-  input_tree->SetBranchStatus("FPMW0_XRawNr","true");
-  input_tree->SetBranchAddress("FPMW0_XRawNr",FPMW0_XRawNr);
-  // FPMW0-Y
-  input_tree->SetBranchStatus("FPMW0_YRawM","true");
-  input_tree->SetBranchAddress("FPMW0_YRawM",&FPMW0_YRawM);
-  input_tree->SetBranchStatus("FPMW0_YRaw","true");
-  input_tree->SetBranchAddress("FPMW0_YRaw",FPMW0_YRaw);
-  input_tree->SetBranchStatus("FPMW0_YRawNr","true");
-  input_tree->SetBranchAddress("FPMW0_YRawNr",FPMW0_YRawNr);
-  // FPMW1-X
-  input_tree->SetBranchStatus("FPMW1_XRawM","true");
-  input_tree->SetBranchAddress("FPMW1_XRawM",&FPMW1_XRawM);
-  input_tree->SetBranchStatus("FPMW1_XRaw","true");
-  input_tree->SetBranchAddress("FPMW1_XRaw",FPMW1_XRaw);
-  input_tree->SetBranchStatus("FPMW1_XRawNr","true");
-  input_tree->SetBranchAddress("FPMW1_XRawNr",FPMW1_XRawNr);
-  // FPMW0-Y
-  input_tree->SetBranchStatus("FPMW1_YRawM","true");
-  input_tree->SetBranchAddress("FPMW1_YRawM",&FPMW1_YRawM);
-  input_tree->SetBranchStatus("FPMW1_YRaw","true");
-  input_tree->SetBranchAddress("FPMW1_YRaw",FPMW1_YRaw);
-  input_tree->SetBranchStatus("FPMW1_YRawNr","true");
-  input_tree->SetBranchAddress("FPMW1_YRawNr",FPMW1_YRawNr);
-  // TMW1-X
-  input_tree->SetBranchStatus("TMW1_XRawM","true");
-  input_tree->SetBranchAddress("TMW1_XRawM",&TMW1_XRawM);
-  input_tree->SetBranchStatus("TMW1_XRaw","true");
-  input_tree->SetBranchAddress("TMW1_XRaw",TMW1_XRaw);
-  input_tree->SetBranchStatus("TMW1_XRawNr","true");
-  input_tree->SetBranchAddress("TMW1_XRawNr",TMW1_XRawNr);
-  // TMW1-Y
-  input_tree->SetBranchStatus("TMW1_YRawM","true");
-  input_tree->SetBranchAddress("TMW1_YRawM",&TMW1_YRawM);
-  input_tree->SetBranchStatus("TMW1_YRaw","true");
-  input_tree->SetBranchAddress("TMW1_YRaw",TMW1_YRaw);
-  input_tree->SetBranchStatus("TMW1_YRawNr","true");
-  input_tree->SetBranchAddress("TMW1_YRawNr",TMW1_YRawNr);
-  // TMW2-X
-  input_tree->SetBranchStatus("TMW2_XRawM","true");
-  input_tree->SetBranchAddress("TMW2_XRawM",&TMW2_XRawM);
-  input_tree->SetBranchStatus("TMW2_XRaw","true");
-  input_tree->SetBranchAddress("TMW2_XRaw",TMW2_XRaw);
-  input_tree->SetBranchStatus("TMW2_XRawNr","true");
-  input_tree->SetBranchAddress("TMW2_XRawNr",TMW2_XRawNr);
-  // TMW2-Y
-  input_tree->SetBranchStatus("TMW2_YRawM","true");
-  input_tree->SetBranchAddress("TMW2_YRawM",&TMW2_YRawM);
-  input_tree->SetBranchStatus("TMW2_YRaw","true");
-  input_tree->SetBranchAddress("TMW2_YRaw",TMW2_YRaw);
-  input_tree->SetBranchStatus("TMW2_YRawNr","true");
-  input_tree->SetBranchAddress("TMW2_YRawNr",TMW2_YRawNr);
-  // Exogam
-  input_tree->SetBranchStatus("Inner6MVM","true");
-  input_tree->SetBranchAddress("Inner6MVM",&Inner6MVM);
-  input_tree->SetBranchStatus("Inner6MV","true");
-  input_tree->SetBranchAddress("Inner6MV",Inner6MV);
-  input_tree->SetBranchStatus("Inner6MVN","true");
-  input_tree->SetBranchAddress("Inner6MVN",Inner6MVN);
-  input_tree->SetBranchStatus("Inner6MVTS","true");
-  input_tree->SetBranchAddress("Inner6MVTS",Inner6MVTS);
-
-  input_tree->SetBranchStatus("OutersVM","true");
-  input_tree->SetBranchAddress("OutersVM",&OutersVM);
-  input_tree->SetBranchStatus("OutersV","true");
-  input_tree->SetBranchAddress("OutersV",OutersV);
-  input_tree->SetBranchStatus("OutersVN","true");
-  input_tree->SetBranchAddress("OutersVN",OutersVN);
-
-  input_tree->SetBranchStatus("Inner20MV","true");
-  input_tree->SetBranchAddress("Inner20MV",Inner20MV);
+    input_tree->SetBranchAddress("PISTA",&m_pista);
+
+    // TAC
+    input_tree->SetBranchStatus("T_TMW1_FPMW0_C","true");
+    input_tree->SetBranchAddress("T_TMW1_FPMW0_C",&T_TMW0_FPMW0);
+    input_tree->SetBranchStatus("T_TMW1_FPMW1_C","true");
+    input_tree->SetBranchAddress("T_TMW1_FPMW1_C",&T_TMW0_FPMW1);
+    input_tree->SetBranchStatus("T_TMW2_FPMW0_C","true");
+    input_tree->SetBranchAddress("T_TMW2_FPMW0_C",&T_TMW1_FPMW0);
+    input_tree->SetBranchStatus("T_TMW2_FPMW1_C","true");
+    input_tree->SetBranchAddress("T_TMW2_FPMW1_C",&T_TMW1_FPMW1);
+
+    // Pat
+    //input_tree->SetBranchStatus("MTOF_FP0_T0VN","true");
+    //input_tree->SetBranchAddress("MTOF_FP0_T0VN",&fFPMWPat_0RawNr);
+    input_tree->SetBranchStatus("TMWPat_00TS","true");
+    input_tree->SetBranchAddress("TMWPat_00TS",&TMWPat_0TS);
+    input_tree->SetBranchStatus("PISTA_TS","true");
+    input_tree->SetBranchAddress("PISTA_TS",&PISTA_TS);
+
+    //MTOF
+
+    input_tree->SetBranchStatus("MTOF_FP0_T0VN","true");
+    input_tree->SetBranchAddress("MTOF_FP0_T0VN",&MTOF_FP0_T0VN);
+    input_tree->SetBranchStatus("MTOF_FP1_T0VN","true");
+    input_tree->SetBranchAddress("MTOF_FP1_T0VN",&MTOF_FP1_T0VN);
+    input_tree->SetBranchStatus("MTOF_FP0_T1VN","true");
+    input_tree->SetBranchAddress("MTOF_FP0_T1VN",&MTOF_FP0_T1VN);
+    input_tree->SetBranchStatus("MTOF_FP1_T1VN","true");
+    input_tree->SetBranchAddress("MTOF_FP1_T1VN",&MTOF_FP1_T1VN);
+
+    input_tree->SetBranchStatus("MTOF_FP0_T0VM","true");
+    input_tree->SetBranchAddress("MTOF_FP0_T0VM",&MTOF_FP0_T0VM);
+    input_tree->SetBranchStatus("MTOF_FP1_T0VM","true");
+    input_tree->SetBranchAddress("MTOF_FP1_T0VM",&MTOF_FP1_T0VM);
+    input_tree->SetBranchStatus("MTOF_FP0_T1VM","true");
+    input_tree->SetBranchAddress("MTOF_FP0_T1VM",&MTOF_FP0_T1VM);
+    input_tree->SetBranchStatus("MTOF_FP1_T1VM","true");
+    input_tree->SetBranchAddress("MTOF_FP1_T1VM",&MTOF_FP1_T1VM);
+
+    input_tree->SetBranchStatus("MTOF_FP0_T0V","true");
+    input_tree->SetBranchAddress("MTOF_FP0_T0V",&MTOF_FP0_T0V);
+    input_tree->SetBranchStatus("MTOF_FP1_T0V","true");
+    input_tree->SetBranchAddress("MTOF_FP1_T0V",&MTOF_FP1_T0V);
+    input_tree->SetBranchStatus("MTOF_FP0_T1V","true");
+    input_tree->SetBranchAddress("MTOF_FP0_T1V",&MTOF_FP0_T1V);
+    input_tree->SetBranchStatus("MTOF_FP1_T1V","true");
+    input_tree->SetBranchAddress("MTOF_FP1_T1V",&MTOF_FP1_T1V);
+
+
+    input_tree->SetBranchStatus("MTOF_FP0_T0VTS","true");
+    input_tree->SetBranchAddress("MTOF_FP0_T0VTS",&MTOF_FP0_T0VTS);
+    input_tree->SetBranchStatus("MTOF_FP1_T0VTS","true");
+    input_tree->SetBranchAddress("MTOF_FP1_T0VTS",&MTOF_FP1_T0VTS);
+    input_tree->SetBranchStatus("MTOF_FP0_T1VTS","true");
+    input_tree->SetBranchAddress("MTOF_FP0_T1VTS",&MTOF_FP0_T1VTS);
+    input_tree->SetBranchStatus("MTOF_FP1_T1VTS","true");
+    input_tree->SetBranchAddress("MTOF_FP1_T1VTS",&MTOF_FP1_T1VTS);
+
+    // IC
+    input_tree->SetBranchStatus("IC","true");
+    input_tree->SetBranchAddress("IC",&IC);
+
+    input_tree->SetBranchStatus("ICRawTS","true");
+    input_tree->SetBranchAddress("ICRawTS",&ICRawTS);
+
+    input_tree->SetBranchStatus("ICRawM","true");
+    input_tree->SetBranchAddress("ICRawM",&ICRawM);
+
+    // FPMW0-X
+    input_tree->SetBranchStatus("FPMW0_XRawM","true");
+    input_tree->SetBranchAddress("FPMW0_XRawM",&FPMW0_XRawM);
+    input_tree->SetBranchStatus("FPMW0_XRaw","true");
+    input_tree->SetBranchAddress("FPMW0_XRaw",FPMW0_XRaw);
+    input_tree->SetBranchStatus("FPMW0_XRawNr","true");
+    input_tree->SetBranchAddress("FPMW0_XRawNr",FPMW0_XRawNr);
+    // FPMW0-Y
+    input_tree->SetBranchStatus("FPMW0_YRawM","true");
+    input_tree->SetBranchAddress("FPMW0_YRawM",&FPMW0_YRawM);
+    input_tree->SetBranchStatus("FPMW0_YRaw","true");
+    input_tree->SetBranchAddress("FPMW0_YRaw",FPMW0_YRaw);
+    input_tree->SetBranchStatus("FPMW0_YRawNr","true");
+    input_tree->SetBranchAddress("FPMW0_YRawNr",FPMW0_YRawNr);
+    // FPMW1-X
+    input_tree->SetBranchStatus("FPMW1_XRawM","true");
+    input_tree->SetBranchAddress("FPMW1_XRawM",&FPMW1_XRawM);
+    input_tree->SetBranchStatus("FPMW1_XRaw","true");
+    input_tree->SetBranchAddress("FPMW1_XRaw",FPMW1_XRaw);
+    input_tree->SetBranchStatus("FPMW1_XRawNr","true");
+    input_tree->SetBranchAddress("FPMW1_XRawNr",FPMW1_XRawNr);
+    // FPMW0-Y
+    input_tree->SetBranchStatus("FPMW1_YRawM","true");
+    input_tree->SetBranchAddress("FPMW1_YRawM",&FPMW1_YRawM);
+    input_tree->SetBranchStatus("FPMW1_YRaw","true");
+    input_tree->SetBranchAddress("FPMW1_YRaw",FPMW1_YRaw);
+    input_tree->SetBranchStatus("FPMW1_YRawNr","true");
+    input_tree->SetBranchAddress("FPMW1_YRawNr",FPMW1_YRawNr);
+    // TMW1-X
+    input_tree->SetBranchStatus("TMW1_XRawM","true");
+    input_tree->SetBranchAddress("TMW1_XRawM",&TMW1_XRawM);
+    input_tree->SetBranchStatus("TMW1_XRaw","true");
+    input_tree->SetBranchAddress("TMW1_XRaw",TMW1_XRaw);
+    input_tree->SetBranchStatus("TMW1_XRawNr","true");
+    input_tree->SetBranchAddress("TMW1_XRawNr",TMW1_XRawNr);
+    // TMW1-Y
+    input_tree->SetBranchStatus("TMW1_YRawM","true");
+    input_tree->SetBranchAddress("TMW1_YRawM",&TMW1_YRawM);
+    input_tree->SetBranchStatus("TMW1_YRaw","true");
+    input_tree->SetBranchAddress("TMW1_YRaw",TMW1_YRaw);
+    input_tree->SetBranchStatus("TMW1_YRawNr","true");
+    input_tree->SetBranchAddress("TMW1_YRawNr",TMW1_YRawNr);
+    // TMW2-X
+    input_tree->SetBranchStatus("TMW2_XRawM","true");
+    input_tree->SetBranchAddress("TMW2_XRawM",&TMW2_XRawM);
+    input_tree->SetBranchStatus("TMW2_XRaw","true");
+    input_tree->SetBranchAddress("TMW2_XRaw",TMW2_XRaw);
+    input_tree->SetBranchStatus("TMW2_XRawNr","true");
+    input_tree->SetBranchAddress("TMW2_XRawNr",TMW2_XRawNr);
+    // TMW2-Y
+    input_tree->SetBranchStatus("TMW2_YRawM","true");
+    input_tree->SetBranchAddress("TMW2_YRawM",&TMW2_YRawM);
+    input_tree->SetBranchStatus("TMW2_YRaw","true");
+    input_tree->SetBranchAddress("TMW2_YRaw",TMW2_YRaw);
+    input_tree->SetBranchStatus("TMW2_YRawNr","true");
+    input_tree->SetBranchAddress("TMW2_YRawNr",TMW2_YRawNr);
+    // Exogam
+    input_tree->SetBranchStatus("Inner6MVM","true");
+    input_tree->SetBranchAddress("Inner6MVM",&Inner6MVM);
+    input_tree->SetBranchStatus("Inner6MV","true");
+    input_tree->SetBranchAddress("Inner6MV",Inner6MV);
+    input_tree->SetBranchStatus("Inner6MVN","true");
+    input_tree->SetBranchAddress("Inner6MVN",Inner6MVN);
+    input_tree->SetBranchStatus("Inner6MVTS","true");
+    input_tree->SetBranchAddress("Inner6MVTS",Inner6MVTS);
+
+    input_tree->SetBranchStatus("OutersVM","true");
+    input_tree->SetBranchAddress("OutersVM",&OutersVM);
+    input_tree->SetBranchStatus("OutersV","true");
+    input_tree->SetBranchAddress("OutersV",OutersV);
+    input_tree->SetBranchStatus("OutersVN","true");
+    input_tree->SetBranchAddress("OutersVN",OutersVN);
+
+    input_tree->SetBranchStatus("Inner20MV","true");
+    input_tree->SetBranchAddress("Inner20MV",Inner20MV);
 
 }
 
diff --git a/Projects/AlPhaPha/conversion/2024/convert.h b/Projects/AlPhaPha/conversion/2024/convert.h
index 8b7a4face728fb452516e33db43042a18e32d5a7..a53108fc74eba43b2f45270e9e15c3019f82671e 100644
--- a/Projects/AlPhaPha/conversion/2024/convert.h
+++ b/Projects/AlPhaPha/conversion/2024/convert.h
@@ -1,6 +1,7 @@
 TPISTAData* m_pista;
 TFPMWData* m_fpmw;
 TICData* m_ic;
+TTimeData* m_time;
 TExogamCalData* m_exogam;
 //TFile* ofile;
 TChain* input_tree;
@@ -19,10 +20,15 @@ Float_t MTOF_FP1_T0V[92];
 Float_t MTOF_FP0_T1V[92];
 Float_t MTOF_FP1_T1V[92];
 
-Int_t MTOF_FP0_T0VN[20];
-Int_t MTOF_FP1_T0VN[20];
-Int_t MTOF_FP0_T1VN[20];
-Int_t MTOF_FP1_T1VN[20];
+short MTOF_FP0_T0VN[20];
+short MTOF_FP1_T0VN[20];
+short MTOF_FP0_T1VN[20];
+short MTOF_FP1_T1VN[20];
+
+long MTOF_FP0_T0VTS[20];
+long MTOF_FP0_T1VTS[20];
+long MTOF_FP1_T0VTS[20];
+long MTOF_FP1_T1VTS[20];
 
 Int_t MTOF_FP0_T0VM;
 Int_t MTOF_FP1_T0VM;
@@ -43,7 +49,9 @@ ULong64_t fPISTA_TS_sec;
 ULong64_t PISTA_TS;
 
 // IC //
-float IC[11];
+Float_t IC[11];
+long ICRawTS[11];
+int ICRawM;
 
 // TW1 //
 Int_t TMW1_XRawM;
diff --git a/Projects/PISTA/GEF.source b/Projects/PISTA/GEF.source
new file mode 100755
index 0000000000000000000000000000000000000000..c11d02e25794b76f88dd29c94ad816bb1dfd0020
--- /dev/null
+++ b/Projects/PISTA/GEF.source
@@ -0,0 +1,21 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%% An Isotropic Source to be used as EventGenerator %%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%      Energy are given in MeV , Position in mm      % 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+GEFReader
+ GEFversion= 2023.33
+ InputDataFile= /home/sofia/Physics/Codes/GEF_2024.3.3/out/240Pu_8MeV.lmd
+ x0= 0 
+ y0= 0 
+ z0= 0 mm
+ TwoBodyReaction= 238U(12C,10Be)240Pu@1428
+ FissioningSystem= 240Pu
+ SigmaX= 0 mm
+ SigmaY= 0 mm
+ Particle= fragments  
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Supported particle type: proton, neutron, gamma, fragments.
+% If you want to see all particles of the file, you may give no argument.
+% KineticEnergy_FS gives additional kinetic energy along Z and boosts fragments
+% and evaporated particles accordingly. To be refined to various angles.
diff --git a/Projects/PISTA/pista.detector b/Projects/PISTA/pista.detector
new file mode 100644
index 0000000000000000000000000000000000000000..6429b8458d912747af604fde2c06cd8babafe171
--- /dev/null
+++ b/Projects/PISTA/pista.detector
@@ -0,0 +1,90 @@
+%%%%%%%%%%%%%%%%%%%%
+Target
+ THICKNESS= 0.44 micrometer
+ RADIUS= 5 mm
+ MATERIAL= C
+ ANGLE= 0 deg
+ X= 0 mm
+ Y= 0 mm
+ Z= 0 mm
+ 
+%%%%%%%%%%%%%%%%%%%%
+Vamos
+ R= 162.7 mm
+ Theta= 20 deg
+
+Vamos TMW1
+ Z = 0 mm
+ Gas= iC4H10
+ Pressure= 0.01 bar
+
+Vamos TMW2
+ Z = 109.3 mm
+ Gas= iC4H10
+ Pressure= 0.01 bar
+
+
+
+%%%%%%%%%%%%%%%%%%%%
+PISTA
+ VERSION= 1
+ POS_A= 36.71 96.1 50.7
+ POS_B= -35.92 95.8 51.3 
+ POS_C= -19.35 56.5 93.4
+ POS_D= 20.8 56.6 93.1
+
+%%%%%%%%%%%%%%%%%%%%
+PISTA
+ VERSION= 1
+ POS_A= -42.15 93.1 51.1
+ POS_B= -93.62 41.8 51.6
+ POS_C= -54.12 25.3 93.6
+ POS_D= -25.66 53.6 93.4
+
+%%%%%%%%%%%%%%%%%%%%
+PISTA
+ VERSION= 1
+ POS_A= -95.98 35.6 51.3
+ POS_B= -95.63 -37.1 51.5
+ POS_C= -56.22 -20.7 93.7
+ POS_D= -56.39 19.5 93.6
+
+%%%%%%%%%%%%%%%%%%%%
+PISTA
+ VERSION= 1
+ POS_A= -93.34 -43.5 50.9
+ POS_B= -41.88 -94.8 51.3
+ POS_C= -25.41 -55.2 93.2
+ POS_D= -53.84 -26.8 93.0
+
+%%%%%%%%%%%%%%%%%%%%
+PISTA
+ VERSION= 1
+ POS_A= -35.66 -97.1 51.3
+ POS_B= 36.98 -96.9 51.1
+ POS_C= 20.9 -57.4 93.4
+ POS_D= -19.24 -57.6 93.5
+
+%%%%%%%%%%%%%%%%%%%%
+PISTA
+ VERSION= 1
+ POS_A= 43.66 -94.4 50.9
+ POS_B= 95.19 -43.3 50.8
+ POS_C= 56.03 -26.6 93.1
+ POS_D= 27.54 -54.9 93.2
+
+%%%%%%%%%%%%%%%%%%%%
+PISTA
+ VERSION= 1
+ POS_A= 96.87 -36.8 50.3
+ POS_B= 97.41 35.8 50.4
+ POS_C= 57.83 20.0 92.6
+ POS_D= 57.52 -20.1 92.6
+
+%%%%%%%%%%%%%%%%%%%%
+PISTA
+ VERSION= 1
+ POS_A= 94.39 42.0 50.8 
+ POS_B= 42.94 93.3 50.7
+ POS_C= 26.47 54.1 93.0
+ POS_D= 54.9 25.7 93.1
diff --git a/Projects/PISTA/project.config b/Projects/PISTA/project.config
new file mode 100644
index 0000000000000000000000000000000000000000..c519edf640d2dcbca6b7a9befa756c910634213c
--- /dev/null
+++ b/Projects/PISTA/project.config
@@ -0,0 +1,5 @@
+Project pista
+ AnalysisOutput= ./root/analysis
+ SimulationOutput= ./root/simulation
+ EnergyLoss= ./EnergyLossTable
+