From 3028bc9bbfce4c0f2298d957e96a49c2ff633ef5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Val=C3=A9rian=20Alcindor?= <valerian.alcindor@hotmail.fr>
Date: Thu, 28 Jan 2021 15:38:01 +0100
Subject: [PATCH] Several updates related to STRASSE and quasi free scattering

---
 NPLib/Detectors/GAGG/CMakeLists.txt        |   6 +
 NPLib/Detectors/GAGG/TGAGGData.cxx         |  79 +++++
 NPLib/Detectors/GAGG/TGAGGData.h           | 104 +++++++
 NPLib/Detectors/GAGG/TGAGGPhysics.cxx      | 344 +++++++++++++++++++++
 NPLib/Detectors/GAGG/TGAGGPhysics.h        | 180 +++++++++++
 NPLib/Detectors/GAGG/TGAGGSpectra.cxx      | 174 +++++++++++
 NPLib/Detectors/GAGG/TGAGGSpectra.h        |  62 ++++
 NPSimulation/Detectors/GAGG/CMakeLists.txt |   2 +
 NPSimulation/Detectors/GAGG/GAGG.cc        | 292 +++++++++++++++++
 NPSimulation/Detectors/GAGG/GAGG.hh        | 117 +++++++
 Projects/GAGG/Analysis.cxx                 |  68 ++++
 Projects/GAGG/Analysis.h                   |  42 +++
 Projects/GAGG/CMakeLists.txt               |   5 +
 Projects/GAGG/GAGG.detector                |  25 ++
 14 files changed, 1500 insertions(+)
 create mode 100644 NPLib/Detectors/GAGG/CMakeLists.txt
 create mode 100644 NPLib/Detectors/GAGG/TGAGGData.cxx
 create mode 100644 NPLib/Detectors/GAGG/TGAGGData.h
 create mode 100644 NPLib/Detectors/GAGG/TGAGGPhysics.cxx
 create mode 100644 NPLib/Detectors/GAGG/TGAGGPhysics.h
 create mode 100644 NPLib/Detectors/GAGG/TGAGGSpectra.cxx
 create mode 100644 NPLib/Detectors/GAGG/TGAGGSpectra.h
 create mode 100644 NPSimulation/Detectors/GAGG/CMakeLists.txt
 create mode 100644 NPSimulation/Detectors/GAGG/GAGG.cc
 create mode 100644 NPSimulation/Detectors/GAGG/GAGG.hh
 create mode 100644 Projects/GAGG/Analysis.cxx
 create mode 100644 Projects/GAGG/Analysis.h
 create mode 100644 Projects/GAGG/CMakeLists.txt
 create mode 100644 Projects/GAGG/GAGG.detector

diff --git a/NPLib/Detectors/GAGG/CMakeLists.txt b/NPLib/Detectors/GAGG/CMakeLists.txt
new file mode 100644
index 000000000..85c18a037
--- /dev/null
+++ b/NPLib/Detectors/GAGG/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_custom_command(OUTPUT TGAGGPhysicsDict.cxx COMMAND ../../scripts/build_dict.sh TGAGGPhysics.h TGAGGPhysicsDict.cxx TGAGGPhysics.rootmap libNPGAGG.dylib DEPENDS TGAGGPhysics.h)
+add_custom_command(OUTPUT TGAGGDataDict.cxx COMMAND ../../scripts/build_dict.sh TGAGGData.h TGAGGDataDict.cxx TGAGGData.rootmap libNPGAGG.dylib DEPENDS TGAGGData.h)
+add_library(NPGAGG SHARED TGAGGSpectra.cxx TGAGGData.cxx TGAGGPhysics.cxx TGAGGDataDict.cxx TGAGGPhysicsDict.cxx )
+target_link_libraries(NPGAGG ${ROOT_LIBRARIES} NPCore) 
+install(FILES TGAGGData.h TGAGGPhysics.h TGAGGSpectra.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+
diff --git a/NPLib/Detectors/GAGG/TGAGGData.cxx b/NPLib/Detectors/GAGG/TGAGGData.cxx
new file mode 100644
index 000000000..d322c583a
--- /dev/null
+++ b/NPLib/Detectors/GAGG/TGAGGData.cxx
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * 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: Valerian Alcindor  contact address:                         *
+ *                                                                           *
+ * Creation Date  : October 2020                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold GAGG Raw data                                    *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+#include "TGAGGData.h"
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+using namespace std; 
+
+ClassImp(TGAGGData)
+
+
+//////////////////////////////////////////////////////////////////////
+TGAGGData::TGAGGData() {
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+TGAGGData::~TGAGGData() {
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+void TGAGGData::Clear() {
+  // Energy
+  fGAGG_E_DetectorNbr.clear();
+  fGAGG_Energy.clear();
+  // Time
+  fGAGG_T_DetectorNbr.clear();
+  fGAGG_Time.clear();
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+void TGAGGData::Dump() const {
+  // This method is very useful for debuging and worth the dev.
+  cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TGAGGData::Dump()] XXXXXXXXXXXXXXXXX" << endl;
+
+  // Energy
+  size_t mysize = fGAGG_E_DetectorNbr.size();
+  cout << "GAGG_E_Mult: " << mysize << endl;
+ 
+  for (size_t i = 0 ; i < mysize ; i++){
+    cout << "DetNbr: " << fGAGG_E_DetectorNbr[i]
+         << " Energy: " << fGAGG_Energy[i];
+  }
+  
+  // Time
+  mysize = fGAGG_T_DetectorNbr.size();
+  cout << "GAGG_T_Mult: " << mysize << endl;
+ 
+  for (size_t i = 0 ; i < mysize ; i++){
+    cout << "DetNbr: " << fGAGG_T_DetectorNbr[i]
+         << " Time: " << fGAGG_Time[i];
+  }
+}
diff --git a/NPLib/Detectors/GAGG/TGAGGData.h b/NPLib/Detectors/GAGG/TGAGGData.h
new file mode 100644
index 000000000..4bab60375
--- /dev/null
+++ b/NPLib/Detectors/GAGG/TGAGGData.h
@@ -0,0 +1,104 @@
+#ifndef __GAGGDATA__
+#define __GAGGDATA__
+/*****************************************************************************
+ * 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: Valerian Alcindor  contact address:                         *
+ *                                                                           *
+ * Creation Date  : October 2020                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold GAGG Raw data                                    *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// STL
+#include <vector>
+using namespace std;
+
+// ROOT
+#include "TObject.h"
+
+class TGAGGData : public TObject {
+  //////////////////////////////////////////////////////////////
+  // data members are hold into vectors in order 
+  // to allow multiplicity treatment
+  private: 
+    // Energy
+    vector<UShort_t>   fGAGG_E_DetectorNbr;
+    vector<Double_t>   fGAGG_Energy;
+
+    // Time
+    vector<UShort_t>   fGAGG_T_DetectorNbr;
+    vector<Double_t>   fGAGG_Time;
+
+
+  //////////////////////////////////////////////////////////////
+  // Constructor and destructor
+  public: 
+    TGAGGData();
+    ~TGAGGData();
+    
+
+  //////////////////////////////////////////////////////////////
+  // 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    ////////////////////////
+    // Energy
+    inline void SetEnergy(const UShort_t& DetNbr,const Double_t& Energy){
+      fGAGG_E_DetectorNbr.push_back(DetNbr);
+      fGAGG_Energy.push_back(Energy);
+    };//!
+
+    // Time
+    inline void SetTime(const UShort_t& DetNbr,const Double_t& Time)	{
+      fGAGG_T_DetectorNbr.push_back(DetNbr);     
+      fGAGG_Time.push_back(Time);
+    };//!
+
+
+    //////////////////////    GETTERS    ////////////////////////
+    // Energy
+    inline UShort_t GetMultEnergy() const
+      {return fGAGG_E_DetectorNbr.size();}
+    inline UShort_t GetE_DetectorNbr(const unsigned int &i) const 
+      {return fGAGG_E_DetectorNbr[i];}//!
+    inline Double_t Get_Energy(const unsigned int &i) const 
+      {return fGAGG_Energy[i];}//!
+
+    // Time
+    inline UShort_t GetMultTime() const
+      {return fGAGG_T_DetectorNbr.size();}
+    inline UShort_t GetT_DetectorNbr(const unsigned int &i) const 
+      {return fGAGG_T_DetectorNbr[i];}//!
+    inline Double_t Get_Time(const unsigned int &i) const 
+      {return fGAGG_Time[i];}//!
+
+
+  //////////////////////////////////////////////////////////////
+  // Required for ROOT dictionnary
+  ClassDef(TGAGGData,1)  // GAGGData structure
+};
+
+#endif
diff --git a/NPLib/Detectors/GAGG/TGAGGPhysics.cxx b/NPLib/Detectors/GAGG/TGAGGPhysics.cxx
new file mode 100644
index 000000000..c21990260
--- /dev/null
+++ b/NPLib/Detectors/GAGG/TGAGGPhysics.cxx
@@ -0,0 +1,344 @@
+/*****************************************************************************
+ * 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: Valerian Alcindor  contact address:                         *
+ *                                                                           *
+ * Creation Date  : October 2020                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold GAGG Treated  data                               *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+#include "TGAGGPhysics.h"
+
+//   STL
+#include <sstream>
+#include <iostream>
+#include <cmath>
+#include <stdlib.h>
+#include <limits>
+using namespace std;
+
+//   NPL
+#include "RootInput.h"
+#include "RootOutput.h"
+#include "NPDetectorFactory.h"
+#include "NPOptionManager.h"
+
+//   ROOT
+#include "TChain.h"
+
+ClassImp(TGAGGPhysics)
+
+
+///////////////////////////////////////////////////////////////////////////
+TGAGGPhysics::TGAGGPhysics()
+   : m_EventData(new TGAGGData),
+     m_PreTreatedData(new TGAGGData),
+     m_EventPhysics(this),
+     m_Spectra(0),
+     m_E_RAW_Threshold(0), // adc channels
+     m_E_Threshold(0),     // MeV
+     m_NumberOfDetectors(0) {
+}
+
+///////////////////////////////////////////////////////////////////////////
+/// A usefull method to bundle all operation to add a detector
+void TGAGGPhysics::AddDetector(TVector3 , string ){
+  // In That simple case nothing is done
+  // Typically for more complex detector one would calculate the relevant 
+  // positions (stripped silicon) or angles (gamma array)
+  m_NumberOfDetectors++;
+} 
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::AddDetector(double R, double Theta, double Phi, string shape){
+  // Compute the TVector3 corresponding
+  TVector3 Pos(R*sin(Theta)*cos(Phi),R*sin(Theta)*sin(Phi),R*cos(Theta));
+  // Call the cartesian method
+  AddDetector(Pos,shape);
+} 
+  
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::BuildSimplePhysicalEvent() {
+  BuildPhysicalEvent();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::BuildPhysicalEvent() {
+  // apply thresholds and calibration
+  PreTreat();
+
+  // match energy and time together
+  unsigned int mysizeE = m_PreTreatedData->GetMultEnergy();
+  unsigned int mysizeT = m_PreTreatedData->GetMultTime();
+  for (UShort_t e = 0; e < mysizeE ; e++) {
+    for (UShort_t t = 0; t < mysizeT ; t++) {
+      if (m_PreTreatedData->GetE_DetectorNbr(e) == m_PreTreatedData->GetT_DetectorNbr(t)) {
+        DetectorNumber.push_back(m_PreTreatedData->GetE_DetectorNbr(e));
+        Energy.push_back(m_PreTreatedData->Get_Energy(e));
+        Time.push_back(m_PreTreatedData->Get_Time(t));
+      }
+    }
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::PreTreat() {
+  // This method typically applies thresholds and calibrations
+  // Might test for disabled channels for more complex detector
+
+  // clear pre-treated object
+  ClearPreTreatedData();
+
+  // instantiate CalibrationManager
+  static CalibrationManager* Cal = CalibrationManager::getInstance();
+
+  // Energy
+  unsigned int mysize = m_EventData->GetMultEnergy();
+  for (UShort_t i = 0; i < mysize ; ++i) {
+    if (m_EventData->Get_Energy(i) > m_E_RAW_Threshold) {
+      Double_t Energy = Cal->ApplyCalibration("GAGG/ENERGY"+NPL::itoa(m_EventData->GetE_DetectorNbr(i)),m_EventData->Get_Energy(i));
+      if (Energy > m_E_Threshold) {
+        m_PreTreatedData->SetEnergy(m_EventData->GetE_DetectorNbr(i), Energy);
+      }
+    }
+  }
+
+  // Time 
+  mysize = m_EventData->GetMultTime();
+  for (UShort_t i = 0; i < mysize; ++i) {
+    Double_t Time= Cal->ApplyCalibration("GAGG/TIME"+NPL::itoa(m_EventData->GetT_DetectorNbr(i)),m_EventData->Get_Time(i));
+    m_PreTreatedData->SetTime(m_EventData->GetT_DetectorNbr(i), Time);
+  }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::ReadAnalysisConfig() {
+  bool ReadingStatus = false;
+
+  // path to file
+  string FileName = "./configs/ConfigGAGG.dat";
+
+  // open analysis config file
+  ifstream AnalysisConfigFile;
+  AnalysisConfigFile.open(FileName.c_str());
+
+  if (!AnalysisConfigFile.is_open()) {
+    cout << " No ConfigGAGG.dat found: Default parameter loaded for Analayis " << FileName << endl;
+    return;
+  }
+  cout << " Loading user parameter for Analysis from ConfigGAGG.dat " << endl;
+
+  // Save it in a TAsciiFile
+  TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
+  asciiConfig->AppendLine("%%% ConfigGAGG.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 = "ConfigGAGG";
+    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=="E_RAW_THRESHOLD") {
+        AnalysisConfigFile >> DataBuffer;
+        m_E_RAW_Threshold = atof(DataBuffer.c_str());
+        cout << whatToDo << " " << m_E_RAW_Threshold << endl;
+      }
+
+      else if (whatToDo=="E_THRESHOLD") {
+        AnalysisConfigFile >> DataBuffer;
+        m_E_Threshold = atof(DataBuffer.c_str());
+        cout << whatToDo << " " << m_E_Threshold << endl;
+      }
+
+      else {
+        ReadingStatus = false;
+      }
+    }
+  }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::Clear() {
+  DetectorNumber.clear();
+  Energy.clear();
+  Time.clear();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::ReadConfiguration(NPL::InputParser parser) {
+  vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("GAGG");
+  if(NPOptionManager::getInstance()->GetVerboseLevel())
+    cout << "//// " << blocks.size() << " detectors found " << endl; 
+
+  vector<string> cart = {"POS","Shape"};
+  vector<string> sphe = {"R","Theta","Phi","Shape"};
+
+  for(unsigned int i = 0 ; i < blocks.size() ; i++){
+    if(blocks[i]->HasTokenList(cart)){
+      if(NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "////  GAGG " << i+1 <<  endl;
+    
+      TVector3 Pos = blocks[i]->GetTVector3("POS","mm");
+      string Shape = blocks[i]->GetString("Shape");
+      AddDetector(Pos,Shape);
+    }
+    else if(blocks[i]->HasTokenList(sphe)){
+      if(NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "////  GAGG " << i+1 <<  endl;
+      double R = blocks[i]->GetDouble("R","mm");
+      double Theta = blocks[i]->GetDouble("Theta","deg");
+      double Phi = blocks[i]->GetDouble("Phi","deg");
+      string Shape = blocks[i]->GetString("Shape");
+      AddDetector(R,Theta,Phi,Shape);
+    }
+    else{
+      cout << "ERROR: check your input file formatting " << endl;
+      exit(1);
+    }
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::InitSpectra() {
+  m_Spectra = new TGAGGSpectra(m_NumberOfDetectors);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::FillSpectra() {
+  m_Spectra -> FillRawSpectra(m_EventData);
+  m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData);
+  m_Spectra -> FillPhysicsSpectra(m_EventPhysics);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::CheckSpectra() {
+  m_Spectra->CheckSpectra();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::ClearSpectra() {
+  // To be done
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+map< string , TH1*> TGAGGPhysics::GetSpectra() {
+  if(m_Spectra)
+    return m_Spectra->GetMapHisto();
+  else{
+    map< string , TH1*> empty;
+    return empty;
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::WriteSpectra() {
+  m_Spectra->WriteSpectra();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::AddParameterToCalibrationManager() {
+  CalibrationManager* Cal = CalibrationManager::getInstance();
+  for (int i = 0; i < m_NumberOfDetectors; ++i) {
+    Cal->AddParameter("GAGG", "D"+ NPL::itoa(i+1)+"_ENERGY","GAGG_D"+ NPL::itoa(i+1)+"_ENERGY");
+    Cal->AddParameter("GAGG", "D"+ NPL::itoa(i+1)+"_TIME","GAGG_D"+ NPL::itoa(i+1)+"_TIME");
+  }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::InitializeRootInputRaw() {
+  TChain* inputChain = RootInput::getInstance()->GetChain();
+  inputChain->SetBranchStatus("GAGG",  true );
+  inputChain->SetBranchAddress("GAGG", &m_EventData );
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::InitializeRootInputPhysics() {
+  TChain* inputChain = RootInput::getInstance()->GetChain();
+  inputChain->SetBranchAddress("GAGG", &m_EventPhysics);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TGAGGPhysics::InitializeRootOutput() {
+  TTree* outputTree = RootOutput::getInstance()->GetTree();
+  outputTree->Branch("GAGG", "TGAGGPhysics", &m_EventPhysics);
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+//            Construct Method to be pass to the DetectorFactory              //
+////////////////////////////////////////////////////////////////////////////////
+NPL::VDetector* TGAGGPhysics::Construct() {
+  return (NPL::VDetector*) new TGAGGPhysics();
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+//            Registering the construct method to the factory                 //
+////////////////////////////////////////////////////////////////////////////////
+extern "C"{
+class proxy_GAGG{
+  public:
+    proxy_GAGG(){
+      NPL::DetectorFactory::getInstance()->AddToken("GAGG","GAGG");
+      NPL::DetectorFactory::getInstance()->AddDetector("GAGG",TGAGGPhysics::Construct);
+    }
+};
+
+proxy_GAGG p_GAGG;
+}
+
diff --git a/NPLib/Detectors/GAGG/TGAGGPhysics.h b/NPLib/Detectors/GAGG/TGAGGPhysics.h
new file mode 100644
index 000000000..ce7052377
--- /dev/null
+++ b/NPLib/Detectors/GAGG/TGAGGPhysics.h
@@ -0,0 +1,180 @@
+#ifndef TGAGGPHYSICS_H
+#define TGAGGPHYSICS_H
+/*****************************************************************************
+ * 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: Valerian Alcindor  contact address:                         *
+ *                                                                           *
+ * Creation Date  : October 2020                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold GAGG Treated data                                *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// C++ headers 
+#include <vector>
+#include <map>
+#include <string>
+using namespace std;
+
+// ROOT headers
+#include "TObject.h"
+#include "TH1.h"
+#include "TVector3.h"
+// NPTool headers
+#include "TGAGGData.h"
+#include "TGAGGSpectra.h"
+#include "NPCalibrationManager.h"
+#include "NPVDetector.h"
+#include "NPInputParser.h"
+// forward declaration
+class TGAGGSpectra;
+
+
+
+class TGAGGPhysics : public TObject, public NPL::VDetector {
+  //////////////////////////////////////////////////////////////
+  // constructor and destructor
+  public:
+    TGAGGPhysics();
+    ~TGAGGPhysics() {};
+
+
+  //////////////////////////////////////////////////////////////
+  // Inherited from TObject and overriden to avoid warnings
+  public: 
+    void Clear();   
+    void Clear(const Option_t*) {};
+
+
+  //////////////////////////////////////////////////////////////
+  // data obtained after BuildPhysicalEvent() and stored in
+  // output ROOT file
+  public:
+    vector<int>      DetectorNumber;
+    vector<double>   Energy;
+    vector<double>   Time;
+
+  /// A usefull method to bundle all operation to add a detector
+  void AddDetector(TVector3 POS, string shape); 
+  void AddDetector(double R, double Theta, double Phi, string shape); 
+  
+  //////////////////////////////////////////////////////////////
+  // methods inherited from the VDetector ABC class
+  public:
+    // read stream from ConfigFile to pick-up detector parameters
+    void ReadConfiguration(NPL::InputParser);
+
+    // add parameters to the CalibrationManger
+    void AddParameterToCalibrationManager();
+
+    // method called event by event, aiming at extracting the 
+    // physical information from detector
+    void BuildPhysicalEvent();
+
+    // same as BuildPhysicalEvent() method but with a simpler
+    // treatment
+    void BuildSimplePhysicalEvent();
+
+    // same as above but for online analysis
+    void BuildOnlinePhysicalEvent()  {BuildPhysicalEvent();};
+
+    // activate raw data object and branches from input TChain
+    // in this method mother branches (Detector) AND daughter leaves 
+    // (fDetector_parameter) have to be activated
+    void InitializeRootInputRaw();
+
+    // activate physics data object and branches from input TChain
+    // in this method mother branches (Detector) AND daughter leaves 
+    // (fDetector_parameter) have to be activated
+    void InitializeRootInputPhysics();
+
+    // create branches of output ROOT file
+    void InitializeRootOutput();
+
+    // clear the raw and physical data objects event by event
+    void ClearEventPhysics() {Clear();}      
+    void ClearEventData()    {m_EventData->Clear();}   
+
+    // methods related to the TGAGGSpectra class
+    // instantiate the TGAGGSpectra class and 
+    // declare list of histograms
+    void InitSpectra();
+
+    // fill the spectra
+    void FillSpectra();
+
+    // used for Online mainly, sanity check for histograms and 
+    // change their color if issues are found, for example
+    void CheckSpectra();
+
+    // used for Online only, clear all the spectra
+    void ClearSpectra();
+
+    // write spectra to ROOT output file
+    void WriteSpectra();
+
+
+  //////////////////////////////////////////////////////////////
+  // specific methods to GAGG array
+  public:
+    // remove bad channels, calibrate the data and apply thresholds
+    void PreTreat();
+
+    // clear the pre-treated object
+    void ClearPreTreatedData()   {m_PreTreatedData->Clear();}
+
+    // read the user configuration file. If no file is found, load standard one
+    void ReadAnalysisConfig();
+
+    // give and external TGAGGData object to TGAGGPhysics. 
+    // needed for online analysis for example
+    void SetRawDataPointer(TGAGGData* rawDataPointer) {m_EventData = rawDataPointer;}
+    
+  // objects are not written in the TTree
+  private:
+    TGAGGData*         m_EventData;        //!
+    TGAGGData*         m_PreTreatedData;   //!
+    TGAGGPhysics*      m_EventPhysics;     //!
+
+  // getters for raw and pre-treated data object
+  public:
+    TGAGGData* GetRawData()        const {return m_EventData;}
+    TGAGGData* GetPreTreatedData() const {return m_PreTreatedData;}
+
+  // parameters used in the analysis
+  private:
+    // thresholds
+    double m_E_RAW_Threshold; //!
+    double m_E_Threshold;     //!
+
+  // number of detectors
+  private:
+    int m_NumberOfDetectors;  //!
+
+  // spectra class
+  private:
+    TGAGGSpectra* m_Spectra; // !
+
+  // spectra getter
+  public:
+    map<string, TH1*>   GetSpectra(); 
+
+  // Static constructor to be passed to the Detector Factory
+  public:
+    static NPL::VDetector* Construct();
+
+    ClassDef(TGAGGPhysics,1)  // GAGGPhysics structure
+};
+#endif
diff --git a/NPLib/Detectors/GAGG/TGAGGSpectra.cxx b/NPLib/Detectors/GAGG/TGAGGSpectra.cxx
new file mode 100644
index 000000000..d8821b63f
--- /dev/null
+++ b/NPLib/Detectors/GAGG/TGAGGSpectra.cxx
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * 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: Valerian Alcindor  contact address:                         *
+ *                                                                           *
+ * Creation Date  : October 2020                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold GAGG Spectra                                     *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// class header 
+#include "TGAGGSpectra.h"
+
+// STL
+#include <iostream>  
+#include <string>
+using namespace std;
+
+// NPTool header
+#include "NPOptionManager.h"
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TGAGGSpectra::TGAGGSpectra() 
+   : fNumberOfDetectors(0) {
+  SetName("GAGG");
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TGAGGSpectra::TGAGGSpectra(unsigned int NumberOfDetectors) {
+  if(NPOptionManager::getInstance()->GetVerboseLevel()>0)
+    cout << "************************************************" << endl
+      << "TGAGGSpectra : Initalizing control spectra for " 
+      << NumberOfDetectors << " Detectors" << endl
+      << "************************************************" << endl ;
+  SetName("GAGG");
+  fNumberOfDetectors = NumberOfDetectors;
+
+  InitRawSpectra();
+  InitPreTreatedSpectra();
+  InitPhysicsSpectra();
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TGAGGSpectra::~TGAGGSpectra() {
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TGAGGSpectra::InitRawSpectra() {
+  static string name;
+  for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors
+    // Energy 
+    name = "GAGG"+NPL::itoa(i+1)+"_ENERGY_RAW";
+    AddHisto1D(name, name, 4096, 0, 16384, "GAGG/RAW");
+    // Time 
+    name = "GAGG"+NPL::itoa(i+1)+"_TIME_RAW";
+    AddHisto1D(name, name, 4096, 0, 16384, "GAGG/RAW");
+  } // end loop on number of detectors
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TGAGGSpectra::InitPreTreatedSpectra() {
+  static string name;
+  for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors
+    // Energy 
+    name = "GAGG"+NPL::itoa(i+1)+"_ENERGY_CAL";
+    AddHisto1D(name, name, 500, 0, 25, "GAGG/CAL");
+    // Time
+    name = "GAGG"+NPL::itoa(i+1)+"_TIME_CAL";
+    AddHisto1D(name, name, 500, 0, 25, "GAGG/CAL");
+
+  
+  }  // end loop on number of detectors
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TGAGGSpectra::InitPhysicsSpectra() {
+  static string name;
+  // Kinematic Plot 
+  name = "GAGG_ENERGY_TIME";
+  AddHisto2D(name, name, 500, 0, 500, 500, 0, 50, "GAGG/PHY");
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TGAGGSpectra::FillRawSpectra(TGAGGData* RawData) {
+  static string name;
+  static string family;
+
+  // Energy 
+  unsigned int sizeE = RawData->GetMultEnergy();
+  for (unsigned int i = 0; i < sizeE; i++) {
+    name = "GAGG"+NPL::itoa(RawData->GetE_DetectorNbr(i))+"_ENERGY_RAW";
+    family = "GAGG/RAW";
+
+    FillSpectra(family,name,RawData->Get_Energy(i));
+  }
+
+  // Time
+  unsigned int sizeT = RawData->GetMultTime();
+  for (unsigned int i = 0; i < sizeT; i++) {
+    name = "GAGG"+NPL::itoa(RawData->GetT_DetectorNbr(i))+"_TIME_RAW";
+    family = "GAGG/RAW";
+
+    FillSpectra(family,name,RawData->Get_Time(i));
+  }
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TGAGGSpectra::FillPreTreatedSpectra(TGAGGData* PreTreatedData) {
+  static string name;
+  static string family;
+  
+  // Energy 
+  unsigned int sizeE = PreTreatedData->GetMultEnergy();
+  for (unsigned int i = 0; i < sizeE; i++) {
+    name = "GAGG"+NPL::itoa(PreTreatedData->GetE_DetectorNbr(i))+"_ENERGY_CAL";
+    family = "GAGG/CAL";
+
+    FillSpectra(family,name,PreTreatedData->Get_Energy(i));
+  }
+
+  // Time
+  unsigned int sizeT = PreTreatedData->GetMultTime();
+  for (unsigned int i = 0; i < sizeT; i++) {
+    name = "GAGG"+NPL::itoa(PreTreatedData->GetT_DetectorNbr(i))+"_TIME_CAL";
+    family = "GAGG/CAL";
+
+    FillSpectra(family,name,PreTreatedData->Get_Time(i));
+  }
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TGAGGSpectra::FillPhysicsSpectra(TGAGGPhysics* Physics) {
+  static string name;
+  static string family;
+  family= "GAGG/PHY";
+
+  // Energy vs time
+  unsigned int sizeE = Physics->Energy.size();
+  for(unsigned int i = 0 ; i < sizeE ; i++){
+    name = "GAGG_ENERGY_TIME";
+    FillSpectra(family,name,Physics->Energy[i],Physics->Time[i]);
+  }
+}
+
diff --git a/NPLib/Detectors/GAGG/TGAGGSpectra.h b/NPLib/Detectors/GAGG/TGAGGSpectra.h
new file mode 100644
index 000000000..fd73ea4a4
--- /dev/null
+++ b/NPLib/Detectors/GAGG/TGAGGSpectra.h
@@ -0,0 +1,62 @@
+#ifndef TGAGGSPECTRA_H
+#define TGAGGSPECTRA_H
+/*****************************************************************************
+ * 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: Valerian Alcindor  contact address:                         *
+ *                                                                           *
+ * Creation Date  : October 2020                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold GAGG Spectra                                     *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// NPLib headers
+#include "NPVSpectra.h"
+#include "TGAGGData.h"
+#include "TGAGGPhysics.h"
+
+// Forward Declaration
+class TGAGGPhysics;
+
+
+class TGAGGSpectra : public VSpectra {
+  //////////////////////////////////////////////////////////////
+  // constructor and destructor
+  public:
+    TGAGGSpectra();
+    TGAGGSpectra(unsigned int NumberOfDetectors);
+    ~TGAGGSpectra();
+
+  //////////////////////////////////////////////////////////////
+  // Initialization methods
+  private:
+    void InitRawSpectra();
+    void InitPreTreatedSpectra();
+    void InitPhysicsSpectra();
+
+  //////////////////////////////////////////////////////////////
+  // Filling methods
+  public:
+    void FillRawSpectra(TGAGGData*);
+    void FillPreTreatedSpectra(TGAGGData*);
+    void FillPhysicsSpectra(TGAGGPhysics*);
+
+  //////////////////////////////////////////////////////////////
+  // Detector parameters 
+  private:
+    unsigned int fNumberOfDetectors;
+};
+
+#endif
diff --git a/NPSimulation/Detectors/GAGG/CMakeLists.txt b/NPSimulation/Detectors/GAGG/CMakeLists.txt
new file mode 100644
index 000000000..1d2d60509
--- /dev/null
+++ b/NPSimulation/Detectors/GAGG/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(NPSGAGG SHARED  GAGG.cc)
+target_link_libraries(NPSGAGG NPSCore ${ROOT_LIBRARIES} ${Geant4_LIBRARIES} ${NPLib_LIBRARIES} -lNPGAGG)
diff --git a/NPSimulation/Detectors/GAGG/GAGG.cc b/NPSimulation/Detectors/GAGG/GAGG.cc
new file mode 100644
index 000000000..8986b07b5
--- /dev/null
+++ b/NPSimulation/Detectors/GAGG/GAGG.cc
@@ -0,0 +1,292 @@
+/*****************************************************************************
+ * 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: Valerian Alcindor  contact address:                         *
+ *                                                                           *
+ * Creation Date  : October 2020                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class describe  GAGG simulation                             *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+
+// C++ headers
+#include <sstream>
+#include <cmath>
+#include <limits>
+//G4 Geometry object
+#include "G4Tubs.hh"
+#include "G4Box.hh"
+
+//G4 sensitive
+#include "G4SDManager.hh"
+#include "G4MultiFunctionalDetector.hh"
+
+//G4 various object
+#include "G4Material.hh"
+#include "G4Transform3D.hh"
+#include "G4PVPlacement.hh"
+#include "G4VisAttributes.hh"
+#include "G4Colour.hh"
+
+// NPTool header
+#include "GAGG.hh"
+#include "CalorimeterScorers.hh"
+#include "InteractionScorers.hh"
+#include "RootOutput.h"
+#include "MaterialManager.hh"
+#include "NPSDetectorFactory.hh"
+#include "NPOptionManager.h"
+#include "NPSHitsMap.hh"
+// CLHEP header
+#include "CLHEP/Random/RandGauss.h"
+
+using namespace std;
+using namespace CLHEP;
+
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+namespace GAGG_NS{
+  // Energy and time Resolution
+  const double EnergyThreshold = 0.1*MeV;
+  const double ResoTime = 4.5*ns ;
+  const double ResoEnergy = 1.0*MeV ;
+  const double Radius = 50*mm ; 
+  const double Width = 100*mm ;
+  const double Thickness = 300*mm ;
+  const string Material = "BC400";
+}
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+// GAGG Specific Method
+GAGG::GAGG(){
+  m_Event = new TGAGGData() ;
+  m_GAGGScorer = 0;
+  m_SquareDetector = 0;
+  m_CylindricalDetector = 0;
+
+
+  // RGB Color + Transparency
+  m_VisSquare = new G4VisAttributes(G4Colour(0, 1, 0, 0.5));   
+  m_VisCylinder = new G4VisAttributes(G4Colour(0, 0, 1, 0.5));   
+
+}
+
+GAGG::~GAGG(){
+}
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+void GAGG::AddDetector(G4ThreeVector POS, string  Shape){
+  // Convert the POS value to R theta Phi as Spherical coordinate is easier in G4 
+  m_R.push_back(POS.mag());
+  m_Theta.push_back(POS.theta());
+  m_Phi.push_back(POS.phi());
+  m_Shape.push_back(Shape);
+}
+
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+void GAGG::AddDetector(double  R, double  Theta, double  Phi, string  Shape){
+  m_R.push_back(R);
+  m_Theta.push_back(Theta);
+  m_Phi.push_back(Phi);
+  m_Shape.push_back(Shape);
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+G4LogicalVolume* GAGG::BuildSquareDetector(){
+  if(!m_SquareDetector){
+    G4Box* box = new G4Box("GAGG_Box",GAGG_NS::Width*0.5,
+        GAGG_NS::Width*0.5,GAGG_NS::Thickness*0.5);
+
+    G4Material* DetectorMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(GAGG_NS::Material);
+    m_SquareDetector = new G4LogicalVolume(box,DetectorMaterial,"logic_GAGG_Box",0,0,0);
+    m_SquareDetector->SetVisAttributes(m_VisSquare);
+    m_SquareDetector->SetSensitiveDetector(m_GAGGScorer);
+  }
+  return m_SquareDetector;
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+G4LogicalVolume* GAGG::BuildCylindricalDetector(){
+  if(!m_CylindricalDetector){
+    G4Tubs* tub = new G4Tubs("GAGG_Cyl",0,GAGG_NS::Radius,GAGG_NS::Thickness*0.5,0,360*deg);
+
+    G4Material* DetectorMaterial = MaterialManager::getInstance()->GetMaterialFromLibrary(GAGG_NS::Material);
+    m_CylindricalDetector = new G4LogicalVolume(tub,DetectorMaterial,"logic_GAGG_tub",0,0,0);
+    m_CylindricalDetector->SetVisAttributes(m_VisSquare);
+    m_CylindricalDetector->SetSensitiveDetector(m_GAGGScorer);
+
+  }
+  return m_CylindricalDetector;
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+// Virtual Method of NPS::VDetector class
+
+// Read stream at Configfile to pick-up parameters of detector (Position,...)
+// Called in DetecorConstruction::ReadDetextorConfiguration Method
+void GAGG::ReadConfiguration(NPL::InputParser parser){
+  vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("GAGG");
+  if(NPOptionManager::getInstance()->GetVerboseLevel())
+    cout << "//// " << blocks.size() << " detectors found " << endl; 
+
+  vector<string> cart = {"POS","Shape"};
+  vector<string> sphe = {"R","Theta","Phi","Shape"};
+
+  for(unsigned int i = 0 ; i < blocks.size() ; i++){
+    if(blocks[i]->HasTokenList(cart)){
+      if(NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "////  GAGG " << i+1 <<  endl;
+    
+      G4ThreeVector Pos = NPS::ConvertVector(blocks[i]->GetTVector3("POS","mm"));
+      string Shape = blocks[i]->GetString("Shape");
+      AddDetector(Pos,Shape);
+    }
+    else if(blocks[i]->HasTokenList(sphe)){
+      if(NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << endl << "////  GAGG " << i+1 <<  endl;
+      double R = blocks[i]->GetDouble("R","mm");
+      double Theta = blocks[i]->GetDouble("Theta","deg");
+      double Phi = blocks[i]->GetDouble("Phi","deg");
+      string Shape = blocks[i]->GetString("Shape");
+      AddDetector(R,Theta,Phi,Shape);
+    }
+    else{
+      cout << "ERROR: check your input file formatting " << endl;
+      exit(1);
+    }
+  }
+}
+
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+
+// Construct detector and inialise sensitive part.
+// Called After DetecorConstruction::AddDetector Method
+void GAGG::ConstructDetector(G4LogicalVolume* world){
+  for (unsigned short i = 0 ; i < m_R.size() ; i++) {
+
+    G4double wX = m_R[i] * sin(m_Theta[i] ) * cos(m_Phi[i] ) ;
+    G4double wY = m_R[i] * sin(m_Theta[i] ) * sin(m_Phi[i] ) ;
+    G4double wZ = m_R[i] * cos(m_Theta[i] ) ;
+    G4ThreeVector Det_pos = G4ThreeVector(wX, wY, wZ) ;
+    // So the face of the detector is at R instead of the middle
+    Det_pos+=Det_pos.unit()*GAGG_NS::Thickness*0.5;
+    // Building Detector reference frame
+    G4double ii = cos(m_Theta[i]) * cos(m_Phi[i]);
+    G4double jj = cos(m_Theta[i]) * sin(m_Phi[i]);
+    G4double kk = -sin(m_Theta[i]);
+    G4ThreeVector Y(ii,jj,kk);
+    G4ThreeVector w = Det_pos.unit();
+    G4ThreeVector u = w.cross(Y);
+    G4ThreeVector v = w.cross(u);
+    v = v.unit();
+    u = u.unit();
+
+    G4RotationMatrix* Rot = new G4RotationMatrix(u,v,w);
+
+    if(m_Shape[i] == "Cylindrical"){
+      new G4PVPlacement(G4Transform3D(*Rot,Det_pos),
+          BuildCylindricalDetector(),
+          "GAGG",world,false,i+1);
+    }
+
+    else if(m_Shape[i] == "Square"){
+      new G4PVPlacement(G4Transform3D(*Rot,Det_pos),
+          BuildSquareDetector(),
+          "GAGG",world,false,i+1);
+    }
+  }
+}
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+// Add Detector branch to the EventTree.
+// Called After DetecorConstruction::AddDetector Method
+void GAGG::InitializeRootOutput(){
+  RootOutput *pAnalysis = RootOutput::getInstance();
+  TTree *pTree = pAnalysis->GetTree();
+  if(!pTree->FindBranch("GAGG")){
+    pTree->Branch("GAGG", "TGAGGData", &m_Event) ;
+  }
+  pTree->SetBranchAddress("GAGG", &m_Event) ;
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+// Read sensitive part and fill the Root tree.
+// Called at in the EventAction::EndOfEventAvtion
+void GAGG::ReadSensitive(const G4Event* ){
+  m_Event->Clear();
+
+  ///////////
+  // Calorimeter scorer
+  CalorimeterScorers::PS_Calorimeter* Scorer= (CalorimeterScorers::PS_Calorimeter*) m_GAGGScorer->GetPrimitive(0);
+
+  unsigned int size = Scorer->GetMult(); 
+  for(unsigned int i = 0 ; i < size ; i++){
+    vector<unsigned int> level = Scorer->GetLevel(i); 
+    double Energy = RandGauss::shoot(Scorer->GetEnergy(i),GAGG_NS::ResoEnergy);
+    if(Energy>GAGG_NS::EnergyThreshold){
+      double Time = RandGauss::shoot(Scorer->GetTime(i),GAGG_NS::ResoTime);
+      int DetectorNbr = level[0];
+      m_Event->SetEnergy(DetectorNbr,Energy);
+      m_Event->SetTime(DetectorNbr,Time); 
+    }
+  }
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+////////////////////////////////////////////////////////////////   
+void GAGG::InitializeScorers() { 
+  // This check is necessary in case the geometry is reloaded
+  bool already_exist = false; 
+  m_GAGGScorer = CheckScorer("GAGGScorer",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) ;
+  G4VPrimitiveScorer* Interaction= new InteractionScorers::PS_Interactions("Interaction",ms_InterCoord, 0) ;
+  //and register it to the multifunctionnal detector
+  m_GAGGScorer->RegisterPrimitive(Calorimeter);
+  m_GAGGScorer->RegisterPrimitive(Interaction);
+  G4SDManager::GetSDMpointer()->AddNewDetector(m_GAGGScorer) ;
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+////////////////////////////////////////////////////////////////////////////////
+//            Construct Method to be pass to the DetectorFactory              //
+////////////////////////////////////////////////////////////////////////////////
+NPS::VDetector* GAGG::Construct(){
+  return  (NPS::VDetector*) new GAGG();
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+////////////////////////////////////////////////////////////////////////////////
+//            Registering the construct method to the factory                 //
+////////////////////////////////////////////////////////////////////////////////
+extern"C" {
+  class proxy_nps_GAGG{
+    public:
+      proxy_nps_GAGG(){
+        NPS::DetectorFactory::getInstance()->AddToken("GAGG","GAGG");
+        NPS::DetectorFactory::getInstance()->AddDetector("GAGG",GAGG::Construct);
+      }
+  };
+
+  proxy_nps_GAGG p_nps_GAGG;
+}
diff --git a/NPSimulation/Detectors/GAGG/GAGG.hh b/NPSimulation/Detectors/GAGG/GAGG.hh
new file mode 100644
index 000000000..03b734013
--- /dev/null
+++ b/NPSimulation/Detectors/GAGG/GAGG.hh
@@ -0,0 +1,117 @@
+#ifndef GAGG_h
+#define GAGG_h 1
+/*****************************************************************************
+ * 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: Valerian Alcindor  contact address:                         *
+ *                                                                           *
+ * Creation Date  : October 2020                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class describe  GAGG simulation                             *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+
+// C++ header
+#include <string>
+#include <vector>
+using namespace std;
+
+// G4 headers
+#include "G4ThreeVector.hh"
+#include "G4RotationMatrix.hh"
+#include "G4LogicalVolume.hh"
+#include "G4MultiFunctionalDetector.hh"
+
+// NPTool header
+#include "NPSVDetector.hh"
+#include "TGAGGData.h"
+#include "NPInputParser.h"
+
+class GAGG : public NPS::VDetector{
+  ////////////////////////////////////////////////////
+  /////// Default Constructor and Destructor /////////
+  ////////////////////////////////////////////////////
+  public:
+    GAGG() ;
+    virtual ~GAGG() ;
+
+    ////////////////////////////////////////////////////
+    /////// Specific Function of this Class ///////////
+    ////////////////////////////////////////////////////
+  public:
+    // Cartesian
+    void AddDetector(G4ThreeVector POS, string Shape);
+    // Spherical
+    void AddDetector(double R,double Theta,double Phi,string Shape);  
+
+
+    G4LogicalVolume* BuildSquareDetector();
+    G4LogicalVolume* BuildCylindricalDetector();
+  
+  private:
+    G4LogicalVolume* m_SquareDetector;
+    G4LogicalVolume* m_CylindricalDetector;
+    
+    ////////////////////////////////////////////////////
+    //////  Inherite from NPS::VDetector class /////////
+    ////////////////////////////////////////////////////
+  public:
+    // Read stream at Configfile to pick-up parameters of detector (Position,...)
+    // 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 the MUST2Array
+    void InitializeScorers() ;
+
+    //   Associated Scorer
+    G4MultiFunctionalDetector* m_GAGGScorer ;
+    ////////////////////////////////////////////////////
+    ///////////Event class to store Data////////////////
+    ////////////////////////////////////////////////////
+  private:
+    TGAGGData* m_Event ;
+
+    ////////////////////////////////////////////////////
+    ///////////////Private intern Data//////////////////
+    ////////////////////////////////////////////////////
+  private: // Geometry
+    // Detector Coordinate 
+    vector<double>  m_R; 
+    vector<double>  m_Theta;
+    vector<double>  m_Phi; 
+    
+    //   Shape type
+    vector<string> m_Shape ;
+   
+    // Visualisation Attribute
+    G4VisAttributes* m_VisSquare;
+    G4VisAttributes* m_VisCylinder;
+
+  // Needed for dynamic loading of the library
+  public:
+    static NPS::VDetector* Construct();
+};
+#endif
diff --git a/Projects/GAGG/Analysis.cxx b/Projects/GAGG/Analysis.cxx
new file mode 100644
index 000000000..7705d9d30
--- /dev/null
+++ b/Projects/GAGG/Analysis.cxx
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * 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: XAUTHORX  contact address: XMAILX                        *
+ *                                                                           *
+ * Creation Date  : XMONTHX XYEARX                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class describe  GAGG analysis project                       *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+
+#include<iostream>
+using namespace std;
+#include"Analysis.h"
+#include"NPAnalysisFactory.h"
+#include"NPDetectorManager.h"
+////////////////////////////////////////////////////////////////////////////////
+Analysis::Analysis(){
+}
+////////////////////////////////////////////////////////////////////////////////
+Analysis::~Analysis(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::Init(){
+   GAGG= (TGAGGPhysicsPhysics*) m_DetectorManager->GetDetector("GAGG");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::TreatEvent(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::End(){
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+//            Construct Method to be pass to the DetectorFactory              //
+////////////////////////////////////////////////////////////////////////////////
+NPL::VAnalysis* Analysis::Construct(){
+  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;
+}
+
diff --git a/Projects/GAGG/Analysis.h b/Projects/GAGG/Analysis.h
new file mode 100644
index 000000000..e468d3513
--- /dev/null
+++ b/Projects/GAGG/Analysis.h
@@ -0,0 +1,42 @@
+#ifndef Analysis_h 
+#define Analysis_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: XAUTHORX  contact address: XMAILX                        *
+ *                                                                           *
+ * Creation Date  : XMONTHX XYEARX                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class describe  GAGG analysis project                       *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+
+#include"NPVAnalysis.h"
+#include"TGAGGPhysics.h"
+class Analysis: public NPL::VAnalysis{
+  public:
+    Analysis();
+    ~Analysis();
+
+  public: 
+    void Init();
+    void TreatEvent();
+    void End();
+
+   static NPL::VAnalysis* Construct();
+
+  private:
+   TGAGGPhysics* GAGG;
+
+};
+#endif
diff --git a/Projects/GAGG/CMakeLists.txt b/Projects/GAGG/CMakeLists.txt
new file mode 100644
index 000000000..22c74affd
--- /dev/null
+++ b/Projects/GAGG/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required (VERSION 2.8) 
+# Setting the policy to match Cmake version
+cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
+# include the default NPAnalysis cmake file
+include("../../NPLib/ressources/CMake/NPAnalysis.cmake")
diff --git a/Projects/GAGG/GAGG.detector b/Projects/GAGG/GAGG.detector
new file mode 100644
index 000000000..ebf9dd080
--- /dev/null
+++ b/Projects/GAGG/GAGG.detector
@@ -0,0 +1,25 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+Target
+ THICKNESS= 10 micrometer
+ RADIUS=	20 mm
+ MATERIAL= CD2
+ ANGLE= 0 deg
+ X= 0 mm
+ Y= 0 mm
+ Z= 0 mm
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+GAGG
+ POS= 0 0 350 mm
+ Shape= Square
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+GAGG
+ POS = 35 35 35 cm
+ Shape= Square
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+GAGG
+ R= 350 mm
+ THETA= 90 deg
+ PHI= 63 deg
+ Shape= Cylindrical
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
-- 
GitLab