From 2411f48d36d445ed6445d82681bc2e4a1034b2ed Mon Sep 17 00:00:00 2001
From: Adrien Matta <matta@lpccaen.in2p3.fr>
Date: Fri, 29 Mar 2019 08:27:46 +0100
Subject: [PATCH] * Mugast strip ordering now done in PreTreat instead of Raw
 filling

---
 NPLib/Core/NPSpectraServer.cxx                | 10 +-
 NPLib/Core/NPVSpectra.cxx                     |  4 +-
 NPLib/Detectors/MUST2/TMust2Spectra.cxx       | 91 +++++++++++++------
 .../ModularLeaf/TModularLeafPhysics.cxx       |  5 -
 NPLib/Detectors/Mugast/CMakeLists.txt         |  2 +-
 NPLib/Detectors/Mugast/TMugastPhysics.cxx     | 14 ++-
 NPLib/Detectors/Mugast/TMugastSpectra.cxx     | 74 +++++++++------
 Projects/MUGAST/Analysis.cxx                  | 46 ++++------
 Projects/MUGAST/Analysis.h                    |  5 +-
 .../MUGAST_Manu.detector                      | 63 +++++++------
 10 files changed, 180 insertions(+), 134 deletions(-)

diff --git a/NPLib/Core/NPSpectraServer.cxx b/NPLib/Core/NPSpectraServer.cxx
index 4846e9ddc..b55aac87f 100644
--- a/NPLib/Core/NPSpectraServer.cxx
+++ b/NPLib/Core/NPSpectraServer.cxx
@@ -69,7 +69,7 @@ NPL::SpectraServer::SpectraServer(){
 void NPL::SpectraServer::CheckRequest(){
   if(m_Server && m_Monitor){
     m_Monitor->ResetInterrupt();
-    TSocket* s = m_Monitor->Select(100);
+    TSocket* s = m_Monitor->Select(1);
     if(s && s!=(TSocket*)-1){
         HandleSocket(s);
     }
@@ -107,7 +107,7 @@ void NPL::SpectraServer::HandleSocket(TSocket* s){
 
     // send requested object back
     static TMessage answer(kMESS_OBJECT|kMESS_ACK);
-    answer.SetCompressionLevel(1);
+    answer.SetCompressionLevel();
     answer.Reset();
     TObject* h =NULL;
     if (!strcmp(request, "RequestSpectra")){
@@ -153,13 +153,9 @@ void NPL::SpectraServer::FillSpectra(const std::string& name,const double& valx)
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::SpectraServer::FillSpectra(const std::string& name,const double& valx,const double& valy){
   // Fill the local histo
-  int val = ((TH2*) m_Spectra->FindObject(name.c_str()))->Fill(valx,valy);
+  ((TH2*) m_Spectra->FindObject(name.c_str()))->Fill(valx,valy);
 }
 ////////////////////////////////////////////////////////////////////////////////
 void NPL::SpectraServer::AddSpectra(TH1* h){
   m_Spectra->Add(h);
 }
-////////////////////////////////////////////////////////////////////////////////
-//void NPL::SpectraServer::AddSpectra(TH2* h){
-//  m_Spectra->Add(h);
-//}
diff --git a/NPLib/Core/NPVSpectra.cxx b/NPLib/Core/NPVSpectra.cxx
index 46290f0a2..48ceccf69 100644
--- a/NPLib/Core/NPVSpectra.cxx
+++ b/NPLib/Core/NPVSpectra.cxx
@@ -45,7 +45,7 @@ VSpectra::VSpectra(){
 ////////////////////////////////////////////////////////////////////////////////
 TH1* VSpectra::AddHisto1D(string name, string title, Int_t nbinsx, Double_t xlow, Double_t xup, string family){
   // create histo
-  TH1 *hist = new TH1D(name.c_str(), title.c_str(), nbinsx, xlow, xup);
+  TH1 *hist = new TH1F(name.c_str(), title.c_str(), nbinsx, xlow, xup);
 
   string index= family+"/"+name;
 
@@ -61,7 +61,7 @@ TH1* VSpectra::AddHisto1D(string name, string title, Int_t nbinsx, Double_t xlow
 ////////////////////////////////////////////////////////////////////////////////
 TH1* VSpectra::AddHisto2D(string name, string title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup, string family){
   // create histo
-  TH1 *hist = new TH2D(name.c_str(), title.c_str(), nbinsx, xlow, xup, nbinsy, ylow, yup);
+  TH1 *hist = new TH2F(name.c_str(), title.c_str(), nbinsx, xlow, xup, nbinsy, ylow, yup);
 
   string index= family+"/"+name;
 
diff --git a/NPLib/Detectors/MUST2/TMust2Spectra.cxx b/NPLib/Detectors/MUST2/TMust2Spectra.cxx
index 3352abdb6..f35d41b42 100644
--- a/NPLib/Detectors/MUST2/TMust2Spectra.cxx
+++ b/NPLib/Detectors/MUST2/TMust2Spectra.cxx
@@ -95,7 +95,8 @@ void TMust2Spectra::InitRawSpectra(){
 
     // STRY_T_RAW
     name = "MM"+NPL::itoa(i+1)+"_STRY_T_RAW";
-    AddHisto2D(name, name, fStripY, 1, fStripY+1, 512, 0, 8192, "MUST2/RAW/STRYT");
+    // AddHisto2D(name, name, fStripY, 1, fStripY+1, 512, 0, 8192, "MUST2/RAW/STRYT");
+    AddHisto2D(name, name, fStripY, 1, fStripY+1, 2000, 0, 16300, "MUST2/RAW/STRYT");
 
     // SILI_E_RAW
     name = "MM"+NPL::itoa(i+1)+"_SILI_E_RAW";
@@ -117,8 +118,7 @@ void TMust2Spectra::InitRawSpectra(){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void TMust2Spectra::InitPreTreatedSpectra()
-{
+void TMust2Spectra::InitPreTreatedSpectra(){
 
   string name;
   for (unsigned int i = 0; i < fNumberOfTelescope; i++) { // loop on number of detectors
@@ -130,6 +130,10 @@ void TMust2Spectra::InitPreTreatedSpectra()
     name = "MM"+NPL::itoa(i+1)+"_STRY_E_CAL";
     AddHisto2D(name, name, fStripY, 1, fStripY+1, 500, 0, 50, "MUST2/CAL/STRYE");
 
+    // STR X-Y Correlation
+    name = "MM"+NPL::itoa(i+1)+"_STRXY_CORR_CAL";
+    AddHisto2D(name, name, 500, 0, 50, 500, 0, 50, "MUST2/CAL/STRXY");
+
     // STRX_T_CAL
     name = "MM"+NPL::itoa(i+1)+"_STRX_T_CAL";
     AddHisto2D(name, name, fStripX, 1, fStripX+1, 1000, 0, 1000, "MUST2/CAL/STRXT");
@@ -225,11 +229,12 @@ void TMust2Spectra::InitPhysicsSpectra(){
 ////////////////////////////////////////////////////////////////////////////////
 void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
 
-  string name;
-  string family;
+  static string name;
+  static string family;
 
   // STRX_E 
-  for (unsigned int i = 0; i < RawData->GetMMStripXEMult(); i++) {
+  unsigned int size = RawData->GetMMStripXEMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MM"+NPL::itoa(RawData->GetMMStripXEDetectorNbr(i))+"_STRX_E_RAW";
     family = "MUST2/RAW/STRXE";
 
@@ -239,7 +244,8 @@ void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
   }
 
   // STRY_E
-  for (unsigned int i = 0; i < RawData->GetMMStripYEMult(); i++) {
+  size = RawData->GetMMStripYEMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MM"+NPL::itoa( RawData->GetMMStripYEDetectorNbr(i) )+"_STRY_E_RAW";
     family = "MUST2/RAW/STRYE";
 
@@ -249,7 +255,8 @@ void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
   }
 
   // STRX_T
-  for (unsigned int i = 0; i < RawData->GetMMStripXTMult(); i++) {
+  size =  RawData->GetMMStripXTMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MM"+NPL::itoa(RawData->GetMMStripXTDetectorNbr(i))+"_STRX_T_RAW";
     family = "MUST2/RAW/STRXT";
 
@@ -257,8 +264,10 @@ void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
         ,RawData->GetMMStripXTStripNbr(i),
         RawData->GetMMStripXTTime(i));
   }
+
   // STRY_T
-  for (unsigned int i = 0; i < RawData->GetMMStripYTMult(); i++) {
+  size = RawData->GetMMStripYTMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MM"+NPL::itoa(RawData->GetMMStripYTDetectorNbr(i))+"_STRY_T_RAW";
     family = "MUST2/RAW/STRYT";
 
@@ -268,7 +277,8 @@ void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
   }
 
   // SILI_E
-  for (unsigned int i = 0; i < RawData->GetMMSiLiEMult(); i++) {
+  size = RawData->GetMMSiLiEMult(); 
+  for (unsigned int i = 0; i < size; i++) {
     name = "MM"+NPL::itoa( RawData->GetMMSiLiEDetectorNbr(i))+"_SILI_E_RAW";
     family = "MUST2/RAW/SILIE";
 
@@ -278,7 +288,8 @@ void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
   }
 
   // SILI_T
-  for (unsigned int i = 0; i < RawData->GetMMSiLiTMult(); i++) {
+  size = RawData->GetMMSiLiTMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MM"+NPL::itoa(RawData->GetMMSiLiTDetectorNbr(i))+"_SILI_T_RAW";
     family = "MUST2/RAW/SILIT";
 
@@ -288,7 +299,8 @@ void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
   }
 
   // CSI_E
-  for (unsigned int i = 0; i < RawData->GetMMCsIEMult(); i++) {
+  size = RawData->GetMMCsIEMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MM"+NPL::itoa(RawData->GetMMCsIEDetectorNbr(i))+"_CSI_E_RAW";
     family = "MUST2/RAW/CSIE";
 
@@ -298,7 +310,8 @@ void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
   }
 
   // CSI_T
-  for (unsigned int i = 0; i < RawData->GetMMCsITMult(); i++) {
+  size = RawData->GetMMCsITMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MM"+NPL::itoa( RawData->GetMMCsITDetectorNbr(i))+"_CSI_T_RAW";
     family = "MUST2/RAW/CSIT";
 
@@ -312,10 +325,11 @@ void TMust2Spectra::FillRawSpectra(TMust2Data* RawData){
 ////////////////////////////////////////////////////////////////////////////////
 void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
 
-  string name ;
-  string family;
+  static string name ;
+  static string family;
   // STRX_E
-  for (unsigned int i = 0; i < PreTreatedData->GetMMStripXEMult(); i++) {
+  unsigned int sizeX = PreTreatedData->GetMMStripXEMult();
+  for (unsigned int i = 0; i < sizeX; i++) {
     name = "MM"+NPL::itoa(PreTreatedData->GetMMStripXEDetectorNbr(i))+"_STRX_E_CAL";
     family = "MUST2/CAL/STRXE";
 
@@ -324,7 +338,8 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
         PreTreatedData->GetMMStripXEEnergy(i));
   }
   // STRY_E
-  for (unsigned int i = 0; i < PreTreatedData->GetMMStripYEMult(); i++) {
+  unsigned int sizeY = PreTreatedData->GetMMStripYEMult();
+  for (unsigned int i = 0; i < sizeY ; i++) {
     name = "MM"+NPL::itoa( PreTreatedData->GetMMStripYEDetectorNbr(i))+"_STRY_E_CAL";
     family = "MUST2/CAL/STRYE";
 
@@ -332,8 +347,23 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
         ,PreTreatedData->GetMMStripYEStripNbr(i), 
         PreTreatedData->GetMMStripYEEnergy(i));
   }
+
+ // STR XY Correlation
+  for (unsigned int i = 0; i < sizeX; i++) {
+    for (unsigned int j = 0; j < sizeY; j++) {
+      if(PreTreatedData->GetMMStripXEDetectorNbr(i)==PreTreatedData->GetMMStripYEDetectorNbr(j))
+    name = "MM"+NPL::itoa( PreTreatedData->GetMMStripXEDetectorNbr(i) )+"_STRXY_CORR_CAL";
+    family = "MUST2/CAL/STRXY";
+
+    FillSpectra(family,name
+        ,PreTreatedData->GetMMStripXEEnergy(i),
+        PreTreatedData->GetMMStripYEEnergy(j));
+    }
+  }
+
   // STRX_T
-  for (unsigned int i = 0; i < PreTreatedData->GetMMStripXTMult(); i++) {
+  unsigned int size = PreTreatedData->GetMMStripXTMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MM"+NPL::itoa(PreTreatedData->GetMMStripXTDetectorNbr(i))+"_STRX_T_CAL";
     family = "MUST2/CAL/STRXT";
 
@@ -342,7 +372,8 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
         PreTreatedData->GetMMStripXTTime(i));
   }
   // STRY_T
-  for (unsigned int i = 0; i < PreTreatedData->GetMMStripYTMult(); i++) {
+  size = PreTreatedData->GetMMStripYTMult(); 
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MM"+NPL::itoa(PreTreatedData->GetMMStripYTDetectorNbr(i))+"_STRY_T_CAL";
     family = "MUST2/CAL/STRYT";
 
@@ -351,7 +382,8 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
         PreTreatedData->GetMMStripYTTime(i));
   }
   // SILI_E
-  for (unsigned int i = 0; i < PreTreatedData->GetMMSiLiEMult(); i++) {
+  size = PreTreatedData->GetMMSiLiEMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MM"+NPL::itoa(PreTreatedData->GetMMSiLiEDetectorNbr(i) )+"_SILI_E_CAL";
     family = "MUST2/CAL/SILIE";
 
@@ -360,7 +392,8 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
         PreTreatedData->GetMMSiLiEEnergy(i));
   }
   // SILI_T
-  for (unsigned int i = 0; i < PreTreatedData->GetMMSiLiTMult(); i++) {
+  size = PreTreatedData->GetMMSiLiTMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MM"+NPL::itoa(PreTreatedData->GetMMSiLiTDetectorNbr(i))+"_SILI_T_CAL";
     family = "MUST2/CAL/SILIT";
 
@@ -369,7 +402,8 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
         PreTreatedData->GetMMSiLiTTime(i));
   }
   // CSI_E
-  for (unsigned int i = 0; i < PreTreatedData->GetMMCsIEMult(); i++) {
+  size =  PreTreatedData->GetMMCsIEMult();
+  for (unsigned int i = 0; i < size ;i++) {
     name = "MM"+NPL::itoa(PreTreatedData->GetMMCsIEDetectorNbr(i))+"_CSI_E_CAL";
     family = "MUST2/CAL/CSIE";
 
@@ -379,7 +413,8 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
   }
 
   // CSI_T
-  for (unsigned int i = 0; i < PreTreatedData->GetMMCsITMult(); i++) {
+  size = PreTreatedData->GetMMCsITMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MM"+NPL::itoa(PreTreatedData->GetMMCsITDetectorNbr(i))+"_CSI_T_CAL";
     family = "MUST2/CAL/CSIT";
 
@@ -391,8 +426,9 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
 
   //E-CSI ID
   family = "MUST2/CAL/ID";
-  for (unsigned int i = 0; i < PreTreatedData->GetMMStripXEMult(); i++) {
-    for (unsigned int j = 0; j < PreTreatedData->GetMMCsIEMult(); j++) {
+  size= PreTreatedData->GetMMCsIEMult();
+  for (unsigned int i = 0; i < sizeX; i++) {
+    for (unsigned int j = 0; j < size; j++) {
 
       if(PreTreatedData->GetMMStripXEDetectorNbr(i) == PreTreatedData->GetMMCsIEDetectorNbr(j)){ 
         name = "MM"+NPL::itoa(PreTreatedData->GetMMStripXEDetectorNbr(i))+"_CSI"+NPL::itoa(PreTreatedData->GetMMCsIECristalNbr(j))+"_CAL_ID";
@@ -410,8 +446,9 @@ void TMust2Spectra::FillPreTreatedSpectra(TMust2Data* PreTreatedData){
 ////////////////////////////////////////////////////////////////////////////////
 void TMust2Spectra::FillPhysicsSpectra(TMust2Physics* Physics){
 
-  string name;
-  string family= "MUST2/PHY";
+  static string name;
+  static string family;
+  family = "MUST2/PHY";
   // X-Y Impact Matrix
 
   for(unsigned int i = 0 ; i < Physics->Si_E.size(); i++){
diff --git a/NPLib/Detectors/ModularLeaf/TModularLeafPhysics.cxx b/NPLib/Detectors/ModularLeaf/TModularLeafPhysics.cxx
index 860e40c68..f146b1493 100644
--- a/NPLib/Detectors/ModularLeaf/TModularLeafPhysics.cxx
+++ b/NPLib/Detectors/ModularLeaf/TModularLeafPhysics.cxx
@@ -146,21 +146,16 @@ void TModularLeafPhysics::InitializeRootOutput(){
 
 ///////////////////////////////////////////////////////////////////////////
 void TModularLeafPhysics::BuildPhysicalEvent(){
-cout << 1 << endl;
   static CalibrationManager* Cal = CalibrationManager::getInstance();
   static string name;
   std::map<std::string,short>::iterator it;
 
-cout << 2 << endl;
   for(it = m_RawData.begin() ; it != m_RawData.end() ; it++){
-    // cout << it->first << " " << it->second << endl;
     name = it->first + "/" +it->first; 
-    cout << name << endl;
     if(it->second != m_DefaultValue){
       m_CalibratedData[it->first] = Cal->ApplyCalibration(name, it->second);
     }
   }
-cout << 3 << endl;
 }
 
 ///////////////////////////////////////////////////////////////////////////
diff --git a/NPLib/Detectors/Mugast/CMakeLists.txt b/NPLib/Detectors/Mugast/CMakeLists.txt
index 1239b94fb..316612843 100644
--- a/NPLib/Detectors/Mugast/CMakeLists.txt
+++ b/NPLib/Detectors/Mugast/CMakeLists.txt
@@ -4,4 +4,4 @@ add_custom_command(OUTPUT TMugastDataDict.cxx COMMAND ../../scripts/build_dict.s
 add_library(NPMugast SHARED TMugastData.cxx TMugastDataDict.cxx TMugastPhysics.cxx TMugastPhysicsDict.cxx TMugastSpectra.h TMugastSpectra.cxx)
 target_link_libraries(NPMugast ${ROOT_LIBRARIES} NPCore) 
 #install(FILES TMugastData.h TMugastPhysics.h TMugastSpectra.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
-install(FILES MugastMap.h TMugastData.h TMugastPhysics.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+install(FILES MugastMap.h TMugastSpectra.h TMugastData.h TMugastPhysics.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
diff --git a/NPLib/Detectors/Mugast/TMugastPhysics.cxx b/NPLib/Detectors/Mugast/TMugastPhysics.cxx
index ea4fa6b6d..180257163 100644
--- a/NPLib/Detectors/Mugast/TMugastPhysics.cxx
+++ b/NPLib/Detectors/Mugast/TMugastPhysics.cxx
@@ -85,16 +85,17 @@ void TMugastPhysics::PreTreat() {
   DSSDY_TMult = m_EventData->GetDSSDYTMult();
   SecondLayer_EMult = m_EventData->GetSecondLayerEMult();
   SecondLayer_TMult = m_EventData->GetSecondLayerTMult();
-
+  MG_DetectorType type = MG_NOCHANGE;
   //   X
   //   E
   for (unsigned int i = 0; i < DSSDX_EMult; ++i) {
+    type=DetectorType[m_EventData->GetDSSDXEDetectorNbr(i)];
     if (m_EventData->GetDSSDXEEnergy(i) > m_DSSD_X_E_RAW_Threshold
         && IsValidChannel(0, m_EventData->GetDSSDXEDetectorNbr(i),
           m_EventData->GetDSSDXEStripNbr(i))) {
       double EX = fDSSD_X_E(m_EventData, i);
       if (EX > m_DSSD_X_E_Threshold)
-        m_PreTreatedData->SetDSSDXE(MG_NOCHANGE,
+        m_PreTreatedData->SetDSSDXE(type,
             m_EventData->GetDSSDXEDetectorNbr(i),
             m_EventData->GetDSSDXEStripNbr(i), EX);
     }
@@ -102,9 +103,10 @@ void TMugastPhysics::PreTreat() {
 
   //   T
   for (unsigned int i = 0; i < DSSDX_TMult; ++i) {
+    type=DetectorType[m_EventData->GetDSSDXTDetectorNbr(i)];
     if (IsValidChannel(0, m_EventData->GetDSSDXTDetectorNbr(i),
           m_EventData->GetDSSDXTStripNbr(i)))
-      m_PreTreatedData->SetDSSDXT(MG_NOCHANGE,
+      m_PreTreatedData->SetDSSDXT(type,
           m_EventData->GetDSSDXTDetectorNbr(i),
           m_EventData->GetDSSDXTStripNbr(i),
           fDSSD_X_T(m_EventData, i));
@@ -113,12 +115,13 @@ void TMugastPhysics::PreTreat() {
   //   Y
   //   E
   for (unsigned int i = 0; i < DSSDY_EMult; ++i) {
+    type=DetectorType[m_EventData->GetDSSDYEDetectorNbr(i)];
     if (m_EventData->GetDSSDYEEnergy(i) < m_DSSD_Y_E_RAW_Threshold
         && IsValidChannel(1, m_EventData->GetDSSDYEDetectorNbr(i),
           m_EventData->GetDSSDYEStripNbr(i))) {
       double EY = fDSSD_Y_E(m_EventData, i);
       if (EY > m_DSSD_Y_E_Threshold)
-        m_PreTreatedData->SetDSSDYE(MG_NOCHANGE,
+        m_PreTreatedData->SetDSSDYE(type,
             m_EventData->GetDSSDYEDetectorNbr(i),
             m_EventData->GetDSSDYEStripNbr(i), EY);
     }
@@ -126,9 +129,10 @@ void TMugastPhysics::PreTreat() {
 
   //   T
   for (unsigned int i = 0; i < DSSDY_TMult; ++i) {
+    type=DetectorType[m_EventData->GetDSSDYTDetectorNbr(i)];
     if (IsValidChannel(1, m_EventData->GetDSSDYTDetectorNbr(i),
           m_EventData->GetDSSDYTStripNbr(i)))
-      m_PreTreatedData->SetDSSDYT(MG_NOCHANGE,
+      m_PreTreatedData->SetDSSDYT(type,
           m_EventData->GetDSSDYTDetectorNbr(i),
           m_EventData->GetDSSDYTStripNbr(i),
           fDSSD_Y_T(m_EventData, i));
diff --git a/NPLib/Detectors/Mugast/TMugastSpectra.cxx b/NPLib/Detectors/Mugast/TMugastSpectra.cxx
index 903f4fe5b..efbcc76ba 100644
--- a/NPLib/Detectors/Mugast/TMugastSpectra.cxx
+++ b/NPLib/Detectors/Mugast/TMugastSpectra.cxx
@@ -109,8 +109,7 @@ void TMugastSpectra::InitRawSpectra(){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void TMugastSpectra::InitPreTreatedSpectra()
-{
+void TMugastSpectra::InitPreTreatedSpectra(){
 
   string name;
   for (unsigned int i = 0; i < fNumberOfTelescope; i++) { // loop on number of detectors
@@ -122,6 +121,10 @@ void TMugastSpectra::InitPreTreatedSpectra()
     name = "MG"+NPL::itoa(fTelescopeToIndex[i])+"_STRY_E_CAL";
     AddHisto2D(name, name, fStripY, 1, fStripY+1, 10000, 0, 50, "Mugast/CAL/STRYE");
 
+    // STR X-Y Correlation
+    name = "MG"+NPL::itoa(fTelescopeToIndex[i])+"_STRXY_CORR_CAL";
+    AddHisto2D(name, name, 500, 0, 50, 500, 0, 50, "Mugast/CAL/STRXY");
+
     // STRX_T_CAL
     name = "MG"+NPL::itoa(fTelescopeToIndex[i])+"_STRX_T_CAL";
     AddHisto2D(name, name, fStripX, 1, fStripX+1, 1000, 0, 1000, "Mugast/CAL/STRXT");
@@ -154,12 +157,6 @@ void TMugastSpectra::InitPhysicsSpectra(){
   name = "MG_THETA_E";
   AddHisto2D(name, name,360,0,180,500,0,50,"Mugast/PHY");
 
-  // X-Y Energy Correlation
-  for (unsigned int i = 0 ; i < fNumberOfTelescope ; i++) { // loop on number of detectors
-    name = "MG"+NPL::itoa(fTelescopeToIndex[i])+"_XY_COR";
-    AddHisto2D(name, name,500,0,50,500,0,50, "Mugast/PHY"); 
-  }
-
   // ID Plot
   // E-TOF:
   name = "MG_E_TOF";
@@ -200,7 +197,8 @@ void TMugastSpectra::FillRawSpectra(TMugastData* RawData){
   static string family;
 
   // STRX_E 
-  for (unsigned int i = 0; i < RawData->GetDSSDXEMult(); i++) {
+  unsigned int size = RawData->GetDSSDXEMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MG"+NPL::itoa( RawData->GetDSSDXEDetectorNbr(i))+"_STRX_E_RAW";
     family = "Mugast/RAW/STRXE";
 
@@ -210,7 +208,8 @@ void TMugastSpectra::FillRawSpectra(TMugastData* RawData){
   }
 
   // STRY_E
-  for (unsigned int i = 0; i < RawData->GetDSSDYEMult(); i++) {
+  size = RawData->GetDSSDYEMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MG"+NPL::itoa( RawData->GetDSSDYEDetectorNbr(i) )+"_STRY_E_RAW";
     family = "Mugast/RAW/STRYE";
 
@@ -220,7 +219,8 @@ void TMugastSpectra::FillRawSpectra(TMugastData* RawData){
   }
 
   // STRX_T
-  for (unsigned int i = 0; i < RawData->GetDSSDXTMult(); i++) {
+  size = RawData->GetDSSDXTMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MG"+NPL::itoa(RawData->GetDSSDXTDetectorNbr(i))+"_STRX_T_RAW";
     family = "Mugast/RAW/STRXT";
 
@@ -228,8 +228,10 @@ void TMugastSpectra::FillRawSpectra(TMugastData* RawData){
         ,RawData->GetDSSDXTStripNbr(i),
         RawData->GetDSSDXTTime(i));
   }
+
   // STRY_T
-  for (unsigned int i = 0; i < RawData->GetDSSDYTMult(); i++) {
+  size = RawData->GetDSSDYTMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MG"+NPL::itoa( RawData->GetDSSDYTDetectorNbr(i))+"_STRY_T_RAW";
     family = "Mugast/RAW/STRYT";
 
@@ -239,7 +241,8 @@ void TMugastSpectra::FillRawSpectra(TMugastData* RawData){
   }
 
   // SDLR_E
-  for (unsigned int i = 0; i < RawData->GetSecondLayerEMult(); i++) {
+  size = RawData->GetSecondLayerEMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MG"+NPL::itoa( RawData->GetSecondLayerEDetectorNbr(i))+"_SDLR_E_RAW";
     family = "Mugast/RAW/SDLRE";
 
@@ -249,7 +252,8 @@ void TMugastSpectra::FillRawSpectra(TMugastData* RawData){
   }
 
   // SDLR_T
-  for (unsigned int i = 0; i < RawData->GetSecondLayerTMult(); i++) {
+  size = RawData->GetSecondLayerTMult();
+  for (unsigned int i = 0; i < size ; i++) {
     name = "MG"+NPL::itoa(RawData->GetSecondLayerTDetectorNbr(i))+"_SDLR_T_RAW";
     family = "Mugast/RAW/SDLRT";
 
@@ -266,7 +270,8 @@ void TMugastSpectra::FillPreTreatedSpectra(TMugastData* PreTreatedData){
   static string name ;
   static string family;
   // STRX_E
-  for (unsigned int i = 0; i < PreTreatedData->GetDSSDXEMult(); i++) {
+  unsigned int sizeX = PreTreatedData->GetDSSDXEMult();
+  for (unsigned int i = 0; i < sizeX ; i++) {
     name = "MG"+NPL::itoa( PreTreatedData->GetDSSDXEDetectorNbr(i))+"_STRX_E_CAL";
     family = "Mugast/CAL/STRXE";
 
@@ -275,7 +280,8 @@ void TMugastSpectra::FillPreTreatedSpectra(TMugastData* PreTreatedData){
         PreTreatedData->GetDSSDXEEnergy(i));
   }
   // STRY_E
-  for (unsigned int i = 0; i < PreTreatedData->GetDSSDYEMult(); i++) {
+  unsigned int sizeY = PreTreatedData->GetDSSDYEMult();
+  for (unsigned int i = 0; i < sizeY; i++) {
     name = "MG"+NPL::itoa( PreTreatedData->GetDSSDYEDetectorNbr(i))+"_STRY_E_CAL";
     family = "Mugast/CAL/STRYE";
 
@@ -283,8 +289,23 @@ void TMugastSpectra::FillPreTreatedSpectra(TMugastData* PreTreatedData){
         ,PreTreatedData->GetDSSDYEStripNbr(i), 
         PreTreatedData->GetDSSDYEEnergy(i));
   }
+
+  // STR XY Correlation
+  for (unsigned int i = 0; i < sizeX; i++) {
+    for (unsigned int j = 0; j < sizeY; j++) {
+      if(PreTreatedData->GetDSSDXEDetectorNbr(i)==PreTreatedData->GetDSSDYEDetectorNbr(j))
+    name = "MG"+NPL::itoa( PreTreatedData->GetDSSDXEDetectorNbr(i) )+"_STRXY_CORR_CAL";
+    family = "Mugast/CAL/STRXY";
+    FillSpectra(family,name
+        ,PreTreatedData->GetDSSDXEEnergy(i),
+        PreTreatedData->GetDSSDYEEnergy(j));
+    }
+  }
+
+
   // STRX_T
-  for (unsigned int i = 0; i < PreTreatedData->GetDSSDXTMult(); i++) {
+  unsigned int size = PreTreatedData->GetDSSDXTMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MG"+NPL::itoa( PreTreatedData->GetDSSDXTDetectorNbr(i))+"_STRX_T_CAL";
     family = "Mugast/CAL/STRXT";
 
@@ -293,7 +314,8 @@ void TMugastSpectra::FillPreTreatedSpectra(TMugastData* PreTreatedData){
         PreTreatedData->GetDSSDXTTime(i));
   }
   // STRY_T
-  for (unsigned int i = 0; i < PreTreatedData->GetDSSDYTMult(); i++) {
+  size = PreTreatedData->GetDSSDYTMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MG"+NPL::itoa( PreTreatedData->GetDSSDYTDetectorNbr(i))+"_STRY_T_CAL";
     family = "Mugast/CAL/STRYT";
 
@@ -302,7 +324,8 @@ void TMugastSpectra::FillPreTreatedSpectra(TMugastData* PreTreatedData){
         PreTreatedData->GetDSSDYTTime(i));
   }
   // SDLR_E
-  for (unsigned int i = 0; i < PreTreatedData->GetSecondLayerEMult(); i++) {
+  size = PreTreatedData->GetSecondLayerEMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MG"+NPL::itoa( PreTreatedData->GetSecondLayerEDetectorNbr(i))+"_SDLR_E_CAL";
     family = "Mugast/CAL/SDLRE";
 
@@ -311,7 +334,8 @@ void TMugastSpectra::FillPreTreatedSpectra(TMugastData* PreTreatedData){
         PreTreatedData->GetSecondLayerEEnergy(i));
   }
   // SDLR_T
-  for (unsigned int i = 0; i < PreTreatedData->GetSecondLayerTMult(); i++) {
+  size = PreTreatedData->GetSecondLayerTMult();
+  for (unsigned int i = 0; i < size; i++) {
     name = "MG"+NPL::itoa( PreTreatedData->GetSecondLayerTDetectorNbr(i))+"_SDLR_T_CAL";
     family = "Mugast/CAL/SDLRT";
 
@@ -322,8 +346,9 @@ void TMugastSpectra::FillPreTreatedSpectra(TMugastData* PreTreatedData){
  
   //E-SDLR ID
   family = "Mugast/CAL/ID";
-  for (unsigned int i = 0; i < PreTreatedData->GetDSSDXEMult(); i++) {
-    for (unsigned int j = 0; j < PreTreatedData->GetSecondLayerEMult(); j++) {
+  size = PreTreatedData->GetSecondLayerEMult();
+  for (unsigned int i = 0; i < sizeX; i++) {
+    for (unsigned int j = 0; j < size; j++) {
 
       if(PreTreatedData->GetDSSDXEDetectorNbr(i) == PreTreatedData->GetSecondLayerEDetectorNbr(j)){ 
         name = "MG"+NPL::itoa( PreTreatedData->GetDSSDXEDetectorNbr(i))+"_SDLR"+NPL::itoa(PreTreatedData->GetSecondLayerEStripNbr(j))+"_CAL_ID";
@@ -354,11 +379,6 @@ void TMugastSpectra::FillPhysicsSpectra(TMugastPhysics* Physics){
     Theta = Theta/deg;
     FillSpectra(family,name,Theta,Physics->DSSD_E[i]);
 
-    // STRX_E_CAL
-//    name = "MG"+NPL::itoa( Physics->TelescopeNumber[i])+"_XY_COR";
- //   FillSpectra(family,name,Physics->DSSD_E[i],Physics->DSSD_EY[i]);
-
-
     // Fill only for particle stopped in the first stage
     if(Physics->SecondLayer_E[i]<0 ){
       // E-TOF:
diff --git a/Projects/MUGAST/Analysis.cxx b/Projects/MUGAST/Analysis.cxx
index e9d626c18..ffa956c65 100644
--- a/Projects/MUGAST/Analysis.cxx
+++ b/Projects/MUGAST/Analysis.cxx
@@ -42,7 +42,7 @@ void Analysis::Init() {
   myInit = new TInitialConditions();
   // get MUST2 and Gaspard objects
   M2 = (TMust2Physics*)  m_DetectorManager -> GetDetector("M2Telescope");
-  GD = (GaspardTracker*) m_DetectorManager -> GetDetector("GaspardTracker");
+  MG = (TMugastPhysics*) m_DetectorManager -> GetDetector("Mugast");
 
   // get reaction information
   myReaction.ReadConfigurationFile(NPOptionManager::getInstance()->GetReactionFile());
@@ -55,8 +55,8 @@ void Analysis::Init() {
   string WindowsMaterial = "";//m_DetectorManager->GetWindowsMaterial();
 
  // energy losses
-  string light=NPL::ChangeNameToG4Standard(myReaction.GetNucleus3().GetName());
-  string beam=NPL::ChangeNameToG4Standard(myReaction.GetNucleus1().GetName());
+  string light=NPL::ChangeNameToG4Standard(myReaction.GetNucleus3()->GetName());
+  string beam=NPL::ChangeNameToG4Standard(myReaction.GetNucleus1()->GetName());
   LightTarget = NPL::EnergyLoss(light+"_"+TargetMaterial+".G4table","G4Table",100 );
   LightAl = NPL::EnergyLoss(light+"_Al.G4table","G4Table",100);
   LightSi = NPL::EnergyLoss(light+"_Si.G4table","G4Table",100);
@@ -77,6 +77,7 @@ void Analysis::Init() {
   DetectorNumber = 0;
   ThetaNormalTarget = 0;
   ThetaM2Surface = 0;
+  ThetaMGSurface = 0;
   Si_E_M2 = 0;
   CsI_E_M2 = 0;
   Energy = 0;
@@ -99,8 +100,7 @@ void Analysis::TreatEvent() {
   BeamImpact = TVector3(0,0,zImpact); 
   // determine beam energy for a randomized interaction point in target
   // 1% FWHM randominastion (E/100)/2.35
-  myReaction.SetBeamEnergy(Rand.Gaus(myInit->GetIncidentFinalKineticEnergy(),myInit->GetIncidentFinalKineticEnergy()/235));
-
+  //myReaction.SetBeamEnergy(Rand.Gaus(myInit->GetIncidentFinalKineticEnergy(),myInit->GetIncidentFinalKineticEnergy()/235));
 
   //////////////////////////// LOOP on MUST2 //////////////////
   for(unsigned int countMust2 = 0 ; countMust2 < M2->Si_E.size() ; countMust2++){
@@ -166,51 +166,45 @@ void Analysis::TreatEvent() {
 
   ////////////////////////////////////////////////////////////////////////////
   ////////////////////////////////////////////////////////////////////////////
-  //////////////////////////// LOOP on GASPARD //////////////////
-  if(GD->GetEnergyDeposit()>0){
-    /************************************************/
+  //////////////////////////// LOOP on MUGAST //////////////////
+  
+/*  
+for(unsigned int countMugast = 0 ; countMugast < MG->DSSD_E.size() ; countMugast++){
+  if(MG->GetEnergyDeposit(countMugast)>0){
     // Part 1 : Impact Angle
-    ThetaGDSurface = 0;
+    ThetaMGSurface = 0;
     ThetaNormalTarget = 0;
-    TVector3 HitDirection = GD -> GetPositionOfInteraction() - BeamImpact ;
+    TVector3 HitDirection = MG -> GetPositionOfInteraction(countMugast) - BeamImpact ;
     ThetaLab = HitDirection.Angle( BeamDirection );
 
-    X =  GD -> GetPositionOfInteraction().X();
-    Y =  GD -> GetPositionOfInteraction().Y();
-    Z =  GD -> GetPositionOfInteraction().Z();
+    X =  MG -> GetPositionOfInteraction(countMugast).X();
+    Y =  MG -> GetPositionOfInteraction(countMugast).Y();
+    Z =  MG -> GetPositionOfInteraction(countMugast).Z();
 
-    ThetaGDSurface = HitDirection.Angle( TVector3(0,0,1) ) ;
+    ThetaMGSurface = HitDirection.Angle( TVector3(0,0,1) ) ;
     ThetaNormalTarget = HitDirection.Angle( TVector3(0,0,1) ) ;
 
-    /************************************************/
 
-    /************************************************/
     // Part 2 : Impact Energy
     Energy = ELab = 0;
-    Energy = GD->GetEnergyDeposit();
+    Energy = MG->GetEnergyDeposit(countMugast);
     // Target Correction
     ELab   = LightTarget.EvaluateInitialEnergy( Energy ,TargetThickness*0.5-zImpact, ThetaNormalTarget);
 
     if(LightWindow)
       ELab = LightWindow->EvaluateInitialEnergy( ELab ,WindowsThickness, ThetaNormalTarget);
     
-      dE= myInit->GetKineticEnergy(0) - ELab ;
-      dTheta = (myInit->GetThetaLab_WorldFrame(0)*deg-ThetaLab)/deg ;
-    /************************************************/
-
-    /************************************************/
     // Part 3 : Excitation Energy Calculation
     Ex = myReaction.ReconstructRelativistic( ELab , ThetaLab );
 
-    /************************************************/
 
-    /************************************************/
     // Part 4 : Theta CM Calculation
     ThetaCM  = myReaction.EnergyLabToThetaCM( ELab , ThetaLab)/deg;
     ThetaLab=ThetaLab/deg;
 
-    /************************************************/
-  }//end loop GASPARD
+  }//end loop Mugast
+}
+*/
 
 }
 
diff --git a/Projects/MUGAST/Analysis.h b/Projects/MUGAST/Analysis.h
index 53cdc0439..fec4a4a39 100644
--- a/Projects/MUGAST/Analysis.h
+++ b/Projects/MUGAST/Analysis.h
@@ -27,7 +27,7 @@
 #include"RootOutput.h"
 #include"RootInput.h"
 #include "TMust2Physics.h"
-#include "GaspardTracker.h"
+#include "TMugastPhysics.h"
 #include "TInitialConditions.h"
 #include <TRandom3.h>
 #include <TVector3.h>
@@ -76,6 +76,7 @@ class Analysis: public NPL::VAnalysis{
   int DetectorNumber  ;
   double ThetaNormalTarget;
   double ThetaM2Surface ;
+  double ThetaMGSurface ;
   double Si_E_M2 ;
   double CsI_E_M2  ;
   double Energy ;
@@ -89,7 +90,7 @@ class Analysis: public NPL::VAnalysis{
   double dTheta;
   // Branches and detectors
   TMust2Physics* M2;
-  GaspardTracker* GD;
+  TMugastPhysics* MG;
   TInitialConditions* myInit ;
 
 };
diff --git a/Projects/MUGAST/DetectorConfiguration/MUGAST_Manu.detector b/Projects/MUGAST/DetectorConfiguration/MUGAST_Manu.detector
index d9ae240d8..ede013b3f 100644
--- a/Projects/MUGAST/DetectorConfiguration/MUGAST_Manu.detector
+++ b/Projects/MUGAST/DetectorConfiguration/MUGAST_Manu.detector
@@ -11,48 +11,47 @@ Target
  Z= 0
  NBLAYERS= 100
 
-
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 GaspardTracker
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1 Annular Back
 GPDAnnular
-        Z=      -134.15
-        RMIN=     16
-        RMAX=     45
-        FIRSTSTAGE=  1
-        SECONDSTAGE= 1
-        THIRDSTAGE=  1
-        VIS= all
+ Z=      -134.15
+ RMIN=     16
+ RMAX=     45
+ FIRSTSTAGE=  1
+ SECONDSTAGE= 1
+ THIRDSTAGE=  1
+ VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1 End-Cap Back
 GPDTrapezoid
-   X128_Y128=        41.963   21.364  -99.28
-   X1_Y128=          23.737   39.592  -99.282
-   X128_Y1=         122.368   54.712  -31.789
-   X1_Y1= 	     57.084  119.996  -31.789
-   FIRSTSTAGE=    1
-   SECONDSTAGE=   0
-   THIRDSTAGE=    0
-   VIS= all
+ X128_Y128=        41.963   21.364  -99.28
+ X1_Y128=          23.737   39.592  -99.282
+ X128_Y1=         122.368   54.712  -31.789
+ X1_Y1= 	     57.084  119.996  -31.789
+ FIRSTSTAGE=    1
+ SECONDSTAGE=   0
+ THIRDSTAGE=    0
+ VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2
 GPDTrapezoid
-   X128_Y128=       -41.963  -21.364  -99.28
-   X1_Y128=         -23.737  -39.592  -99.282
-   X128_Y1=        -122.368  -54.712  -31.789
-   X1_Y1= 	    -57.084 -119.996  -31.789
-   FIRSTSTAGE= 1
-   SECONDSTAGE= 0
-   THIRDSTAGE= 0
-   VIS= all
+ X128_Y128=       -41.963  -21.364  -99.28
+ X1_Y128=         -23.737  -39.592  -99.282
+ X128_Y1=        -122.368  -54.712  -31.789
+ X1_Y1= 	    -57.084 -119.996  -31.789
+ FIRSTSTAGE= 1
+ SECONDSTAGE= 0
+ THIRDSTAGE= 0
+ VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%3
 GPDTrapezoid
-   X128_Y128=      -21.364   41.963  -99.28
-   X1_Y128=        -39.592   23.737  -99.282
-   X128_Y1=        -54.712  122.368  -31.789
-   X1_Y1= 	  -119.996   57.084  -31.789
-   FIRSTSTAGE= 1
-   SECONDSTAGE= 0
-   THIRDSTAGE= 0
-   VIS= all
+ X128_Y128=      -21.364   41.963  -99.28
+ X1_Y128=        -39.592   23.737  -99.282
+ X128_Y1=        -54.712  122.368  -31.789
+ X1_Y1= 	  -119.996   57.084  -31.789
+ FIRSTSTAGE= 1
+ SECONDSTAGE= 0
+ THIRDSTAGE= 0
+ VIS= all
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%4
 GPDTrapezoid
    X128_Y128=      21.364  -41.963  -99.28
-- 
GitLab