From aaa6019dc0f16e36ec5132865b5e10f37ad0884e Mon Sep 17 00:00:00 2001
From: Morfouace <morfouac@ipno.in2p3.fr>
Date: Fri, 20 Jan 2017 09:16:13 -0500
Subject: [PATCH] * Adding AnnularS4 to NPTool (simple version)

---
 NPLib/Detectors/AnnularS4/CMakeLists.txt      |   6 +
 NPLib/Detectors/AnnularS4/TAnnularS4Data.cxx  |  94 +++++
 NPLib/Detectors/AnnularS4/TAnnularS4Data.h    | 101 +++++
 .../Detectors/AnnularS4/TAnnularS4Physics.cxx | 366 ++++++++++++++++++
 NPLib/Detectors/AnnularS4/TAnnularS4Physics.h | 184 +++++++++
 .../Detectors/AnnularS4/TAnnularS4Spectra.cxx | 174 +++++++++
 NPLib/Detectors/AnnularS4/TAnnularS4Spectra.h |  62 +++
 7 files changed, 987 insertions(+)
 create mode 100644 NPLib/Detectors/AnnularS4/CMakeLists.txt
 create mode 100644 NPLib/Detectors/AnnularS4/TAnnularS4Data.cxx
 create mode 100644 NPLib/Detectors/AnnularS4/TAnnularS4Data.h
 create mode 100644 NPLib/Detectors/AnnularS4/TAnnularS4Physics.cxx
 create mode 100644 NPLib/Detectors/AnnularS4/TAnnularS4Physics.h
 create mode 100644 NPLib/Detectors/AnnularS4/TAnnularS4Spectra.cxx
 create mode 100644 NPLib/Detectors/AnnularS4/TAnnularS4Spectra.h

diff --git a/NPLib/Detectors/AnnularS4/CMakeLists.txt b/NPLib/Detectors/AnnularS4/CMakeLists.txt
new file mode 100644
index 000000000..570d77d95
--- /dev/null
+++ b/NPLib/Detectors/AnnularS4/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_custom_command(OUTPUT TAnnularS4PhysicsDict.cxx COMMAND ../../scripts/build_dict.sh TAnnularS4Physics.h TAnnularS4PhysicsDict.cxx TAnnularS4Physics.rootmap libNPAnnularS4.dylib DEPENDS TAnnularS4Physics.h)
+add_custom_command(OUTPUT TAnnularS4DataDict.cxx COMMAND ../../scripts/build_dict.sh TAnnularS4Data.h TAnnularS4DataDict.cxx TAnnularS4Data.rootmap libNPAnnularS4.dylib DEPENDS TAnnularS4Data.h)
+add_library(NPAnnularS4 SHARED TAnnularS4Spectra.cxx TAnnularS4Data.cxx TAnnularS4Physics.cxx TAnnularS4DataDict.cxx TAnnularS4PhysicsDict.cxx )
+target_link_libraries(NPAnnularS4 ${ROOT_LIBRARIES} NPCore) 
+install(FILES TAnnularS4Data.h TAnnularS4Physics.h TAnnularS4Spectra.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+
diff --git a/NPLib/Detectors/AnnularS4/TAnnularS4Data.cxx b/NPLib/Detectors/AnnularS4/TAnnularS4Data.cxx
new file mode 100644
index 000000000..364104f39
--- /dev/null
+++ b/NPLib/Detectors/AnnularS4/TAnnularS4Data.cxx
@@ -0,0 +1,94 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2017   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Pierre Morfouace  contact address: morfouac@nscl.msu.edu                        *
+ *                                                                           *
+ * Creation Date  : January 2017                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold AnnularS4 Raw data                                    *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+#include "TAnnularS4Data.h"
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+using namespace std; 
+
+ClassImp(TAnnularS4Data)
+
+
+//////////////////////////////////////////////////////////////////////
+TAnnularS4Data::TAnnularS4Data() {
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+TAnnularS4Data::~TAnnularS4Data() {
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+void TAnnularS4Data::Clear() {
+    // DSSD
+    // (Th,E)
+    fS4_E_DetNbr.clear();
+    fS4_E_StripNbr.clear();
+    fS4_E_SectorNbr.clear();
+    fS4_E_Energy.clear();
+    // (Th,T)
+    fS4_T_DetNbr.clear();
+    fS4_T_StripNbr.clear();
+    fS4_T_SectorNbr.clear();
+    fS4_T_Time.clear();
+   
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+void TAnnularS4Data::Dump() const {
+  // This method is very useful for debuging and worth the dev.
+  cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TAnnularS4Data::Dump()] XXXXXXXXXXXXXXXXX" << endl;
+
+    // DSSD
+    // (Th,E)
+    cout << "S4_MultThE = " << fS4_E_DetNbr.size() << endl;
+    for (UShort_t i = 0; i < fS4_E_DetNbr.size(); i++)
+        cout << "Det: " << fS4_E_DetNbr[i] << " Strip: " << fS4_E_StripNbr[i] << " Sector: " << fS4_E_SectorNbr[i] <<  " Energy: " << fS4_E_Energy[i] << endl;
+    // (Th,T)
+    cout << "S4_MultThT = " << fS4_T_DetNbr.size() << endl;
+    for (UShort_t i = 0; i < fS4_T_DetNbr.size(); i++)
+        cout << "Det: " << fS4_T_DetNbr[i] << " Strip: " << fS4_T_StripNbr[i] << " Sector: " << fS4_T_SectorNbr[i] <<" Time: " << fS4_T_Time[i] << endl;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/NPLib/Detectors/AnnularS4/TAnnularS4Data.h b/NPLib/Detectors/AnnularS4/TAnnularS4Data.h
new file mode 100644
index 000000000..ee0360990
--- /dev/null
+++ b/NPLib/Detectors/AnnularS4/TAnnularS4Data.h
@@ -0,0 +1,101 @@
+#ifndef __AnnularS4DATA__
+#define __AnnularS4DATA__
+/*****************************************************************************
+ * Copyright (C) 2009-2017   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Pierre Morfouace  contact address: morfouac@nscl.msu.edu                        *
+ *                                                                           *
+ * Creation Date  : January 2017                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold AnnularS4 Raw data                                    *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// STL
+#include <vector>
+using namespace std;
+
+// ROOT
+#include "TObject.h"
+
+class TAnnularS4Data : public TObject {
+  //////////////////////////////////////////////////////////////
+  // data members are hold into vectors in order 
+  // to allow multiplicity treatment
+  private: 
+    // ADC
+    vector<UShort_t>   fS4_E_DetNbr;
+    vector<UShort_t>   fS4_E_StripNbr;
+    vector<UShort_t>   fS4_E_SectorNbr;
+    vector<Double_t>   fS4_E_Energy;
+    // TDC
+    vector<UShort_t>   fS4_T_DetNbr;
+    vector<UShort_t>   fS4_T_StripNbr;
+    vector<UShort_t>   fS4_T_SectorNbr;
+    vector<Double_t>   fS4_T_Time;
+
+  //////////////////////////////////////////////////////////////
+  // Constructor and destructor
+  public: 
+    TAnnularS4Data();
+    virtual ~TAnnularS4Data();
+    
+
+  //////////////////////////////////////////////////////////////
+  // 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    ////////////////////////
+    // (Th,E)
+    void   SetS4_E_DetectorNbr(const int& det)     {fS4_E_DetNbr.push_back(det);}
+    void   SetS4_E_StripNbr(const int& Nr)         {fS4_E_StripNbr.push_back(Nr);}
+    void   SetS4_E_SectorNbr(const int& Nr)        {fS4_E_SectorNbr.push_back(Nr);}
+    void   SetS4_E_Energy(const double& E)          {fS4_E_Energy.push_back(E);}
+    // (Th,T)
+    void   SetS4_T_DetectorNbr(const int& det)      {fS4_T_DetNbr.push_back(det);}
+    void   SetS4_T_StripNbr(const int& Nr)          {fS4_T_StripNbr.push_back(Nr);}
+    void   SetS4_T_SectorNbr(const int& Nr)         {fS4_T_SectorNbr.push_back(Nr);}
+    void   SetS4_T_Time(const double& T)            {fS4_T_Time.push_back(T);}
+    
+    //////////////////////    GETTERS    ////////////////////////
+    // (Th,E)
+    unsigned int   GetS4EMult()                 const {return fS4_E_StripNbr.size();}
+    int   GetS4_E_DetectorNbr(const int& i)     const {return fS4_E_DetNbr.at(i);}
+    int   GetS4_E_StripNbr(const int& i)        const {return fS4_E_StripNbr.at(i);}
+    int   GetS4_E_SectorNbr(const int& i)       const {return fS4_E_SectorNbr.at(i);}
+    double   GetS4_E_Energy(const int& i)       const {return fS4_E_Energy.at(i);}
+    // (Th,T)
+    unsigned int   GetS4TMult()                 const {return fS4_T_DetNbr.size();}
+    int   GetS4_T_DetectorNbr(const int& i)     const {return fS4_T_DetNbr.at(i);}
+    int   GetS4_T_StripNbr(const int& i)        const {return fS4_T_StripNbr.at(i);}
+    int   GetS4_T_SectorNbr(const int& i)       const {return fS4_T_SectorNbr.at(i);}
+    double   GetS4_T_Time(const int& i)         const {return fS4_T_Time.at(i);}
+   
+
+  //////////////////////////////////////////////////////////////
+  // Required for ROOT dictionnary
+  ClassDef(TAnnularS4Data,1)  // AnnularS4Data structure
+};
+
+#endif
diff --git a/NPLib/Detectors/AnnularS4/TAnnularS4Physics.cxx b/NPLib/Detectors/AnnularS4/TAnnularS4Physics.cxx
new file mode 100644
index 000000000..1b33c7b95
--- /dev/null
+++ b/NPLib/Detectors/AnnularS4/TAnnularS4Physics.cxx
@@ -0,0 +1,366 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2017   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Pierre Morfouace  contact address: morfouac@nscl.msu.edu                        *
+ *                                                                           *
+ * Creation Date  : January 2017                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold AnnularS4 Treated  data                               *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+
+#include "TAnnularS4Physics.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(TAnnularS4Physics)
+
+
+///////////////////////////////////////////////////////////////////////////
+TAnnularS4Physics::TAnnularS4Physics()
+: m_EventData(new TAnnularS4Data),
+m_PreTreatedData(new TAnnularS4Data),
+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 TAnnularS4Physics::AddDetector(TVector3 ){
+    // 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 TAnnularS4Physics::AddDetector(double R, double Theta, double Phi){
+    // 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);
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::BuildSimplePhysicalEvent() {
+    BuildPhysicalEvent();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::BuildPhysicalEvent() {
+    // apply thresholds and calibration
+    PreTreat();
+    
+    // match energy and time together
+    unsigned int mysizeE = m_PreTreatedData->GetS4EMult();
+    unsigned int mysizeT = m_PreTreatedData->GetS4TMult();
+    for (UShort_t e = 0; e < mysizeE ; e++) {
+        for (UShort_t t = 0; t < mysizeT ; t++) {
+            if (m_PreTreatedData->GetS4_E_DetectorNbr(e) == m_PreTreatedData->GetS4_T_DetectorNbr(t)) {
+                DetectorNumber.push_back(m_PreTreatedData->GetS4_E_DetectorNbr(e));
+                Energy.push_back(m_PreTreatedData->GetS4_E_Energy(e));
+                StripNbr.push_back(m_PreTreatedData->GetS4_E_StripNbr(e));
+                SectorNbr.push_back(m_PreTreatedData->GetS4_E_SectorNbr(e));
+                Time.push_back(m_PreTreatedData->GetS4_T_Time(t));
+            }
+        }
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::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->GetS4EMult();
+    for (UShort_t i = 0; i < mysize ; ++i) {
+        if (m_EventData->GetS4_E_Energy(i) > m_E_RAW_Threshold) {
+            Double_t Energy = Cal->ApplyCalibration("AnnularS4/ENERGY"+NPL::itoa(m_EventData->GetS4_E_DetectorNbr(i)),m_EventData->GetS4_E_Energy(i));
+            if (Energy > m_E_Threshold) {
+                m_PreTreatedData->SetS4_E_Energy(Energy);
+                m_PreTreatedData->SetS4_E_StripNbr(m_EventData->GetS4_E_StripNbr(i));
+                m_PreTreatedData->SetS4_E_DetectorNbr(m_EventData->GetS4_E_DetectorNbr(i));
+                m_PreTreatedData->SetS4_E_SectorNbr(m_EventData->GetS4_E_SectorNbr(i));
+            }
+        }
+    }
+    
+    // Time
+    mysize = m_EventData->GetS4TMult();
+    for (UShort_t i = 0; i < mysize; ++i) {
+        Double_t Time= Cal->ApplyCalibration("AnnularS4/TIME"+NPL::itoa(m_EventData->GetS4_T_DetectorNbr(i)),m_EventData->GetS4_T_Time(i));
+        m_PreTreatedData->SetS4_T_Time(Time);
+        m_PreTreatedData->SetS4_T_StripNbr(m_EventData->GetS4_T_StripNbr(i));
+        m_PreTreatedData->SetS4_T_DetectorNbr(m_EventData->GetS4_T_DetectorNbr(i));
+        m_PreTreatedData->SetS4_T_SectorNbr(m_EventData->GetS4_T_SectorNbr(i));
+    }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::ReadAnalysisConfig() {
+    bool ReadingStatus = false;
+    
+    // path to file
+    string FileName = "./configs/ConfigAnnularS4.dat";
+    
+    // open analysis config file
+    ifstream AnalysisConfigFile;
+    AnalysisConfigFile.open(FileName.c_str());
+    
+    if (!AnalysisConfigFile.is_open()) {
+        cout << " No ConfigAnnularS4.dat found: Default parameter loaded for Analayis " << FileName << endl;
+        return;
+    }
+    cout << " Loading user parameter for Analysis from ConfigAnnularS4.dat " << endl;
+    
+    // Save it in a TAsciiFile
+    TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
+    asciiConfig->AppendLine("%%% ConfigAnnularS4.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 = "ConfigAnnularS4";
+        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 TAnnularS4Physics::Clear() {
+    DetectorNumber.clear();
+    Energy.clear();
+    Time.clear();
+    StripNbr.clear();
+    SectorNbr.clear();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::ReadConfiguration(NPL::InputParser parser) {
+    vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("AnnularS4");
+    if(NPOptionManager::getInstance()->GetVerboseLevel())
+        cout << "//// " << blocks.size() << " detectors found " << endl;
+    
+    vector<string> cart = {"POS"};
+    vector<string> sphe = {"R","Theta","Phi"};
+    
+    for(unsigned int i = 0 ; i < blocks.size() ; i++){
+        if(blocks[i]->HasTokenList(cart)){
+            if(NPOptionManager::getInstance()->GetVerboseLevel())
+                cout << endl << "////  AnnularS4 " << i+1 <<  endl;
+            
+            TVector3 Pos = blocks[i]->GetTVector3("POS","mm");
+            AddDetector(Pos);
+        }
+        else if(blocks[i]->HasTokenList(sphe)){
+            if(NPOptionManager::getInstance()->GetVerboseLevel())
+                cout << endl << "////  AnnularS4 " << i+1 <<  endl;
+            double R = blocks[i]->GetDouble("R","mm");
+            double Theta = blocks[i]->GetDouble("Theta","deg");
+            double Phi = blocks[i]->GetDouble("Phi","deg");
+            AddDetector(R,Theta,Phi);
+        }
+        else{
+            cout << "ERROR: check your input file formatting " << endl;
+            exit(1);
+        }
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::InitSpectra() {
+    m_Spectra = new TAnnularS4Spectra(m_NumberOfDetectors);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::FillSpectra() {
+    m_Spectra -> FillRawSpectra(m_EventData);
+    m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData);
+    m_Spectra -> FillPhysicsSpectra(m_EventPhysics);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::CheckSpectra() {
+    m_Spectra->CheckSpectra();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::ClearSpectra() {
+    // To be done
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+map< string , TH1*> TAnnularS4Physics::GetSpectra() {
+    if(m_Spectra)
+        return m_Spectra->GetMapHisto();
+    else{
+        map< string , TH1*> empty;
+        return empty;
+    }
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+vector<TCanvas*> TAnnularS4Physics::GetCanvas() {
+    if(m_Spectra)
+        return m_Spectra->GetCanvas();
+    else{
+        vector<TCanvas*> empty;
+        return empty;
+    }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::WriteSpectra() {
+    m_Spectra->WriteSpectra();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::AddParameterToCalibrationManager() {
+    CalibrationManager* Cal = CalibrationManager::getInstance();
+    for (int i = 0; i < m_NumberOfDetectors; ++i) {
+        Cal->AddParameter("AnnularS4", "D"+ NPL::itoa(i+1)+"_ENERGY","AnnularS4_D"+ NPL::itoa(i+1)+"_ENERGY");
+        Cal->AddParameter("AnnularS4", "D"+ NPL::itoa(i+1)+"_TIME","AnnularS4_D"+ NPL::itoa(i+1)+"_TIME");
+    }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::InitializeRootInputRaw() {
+    TChain* inputChain = RootInput::getInstance()->GetChain();
+    inputChain->SetBranchStatus("AnnularS4",  true );
+    inputChain->SetBranchAddress("AnnularS4", &m_EventData );
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::InitializeRootInputPhysics() {
+    TChain* inputChain = RootInput::getInstance()->GetChain();
+    inputChain->SetBranchAddress("AnnularS4", &m_EventPhysics);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TAnnularS4Physics::InitializeRootOutput() {
+    TTree* outputTree = RootOutput::getInstance()->GetTree();
+    outputTree->Branch("AnnularS4", "TAnnularS4Physics", &m_EventPhysics);
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+//            Construct Method to be pass to the DetectorFactory              //
+////////////////////////////////////////////////////////////////////////////////
+NPL::VDetector* TAnnularS4Physics::Construct() {
+    return (NPL::VDetector*) new TAnnularS4Physics();
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+//            Registering the construct method to the factory                 //
+////////////////////////////////////////////////////////////////////////////////
+extern "C"{
+    class proxy_AnnularS4{
+    public:
+        proxy_AnnularS4(){
+            NPL::DetectorFactory::getInstance()->AddToken("AnnularS4","AnnularS4");
+            NPL::DetectorFactory::getInstance()->AddDetector("AnnularS4",TAnnularS4Physics::Construct);
+        }
+    };
+    
+    proxy_AnnularS4 p_AnnularS4;
+}
+
diff --git a/NPLib/Detectors/AnnularS4/TAnnularS4Physics.h b/NPLib/Detectors/AnnularS4/TAnnularS4Physics.h
new file mode 100644
index 000000000..2d2b41e43
--- /dev/null
+++ b/NPLib/Detectors/AnnularS4/TAnnularS4Physics.h
@@ -0,0 +1,184 @@
+#ifndef TAnnularS4PHYSICS_H
+#define TAnnularS4PHYSICS_H
+/*****************************************************************************
+ * Copyright (C) 2009-2017   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Pierre Morfouace  contact address: morfouac@nscl.msu.edu                        *
+ *                                                                           *
+ * Creation Date  : January 2017                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold AnnularS4 Treated data                                *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// C++ headers 
+#include <vector>
+#include <map>
+#include <string>
+using namespace std;
+
+// ROOT headers
+#include "TObject.h"
+#include "TH1.h"
+#include "TCanvas.h"
+#include "TVector3.h"
+// NPTool headers
+#include "TAnnularS4Data.h"
+#include "TAnnularS4Spectra.h"
+#include "NPCalibrationManager.h"
+#include "NPVDetector.h"
+#include "NPInputParser.h"
+// forward declaration
+class TAnnularS4Spectra;
+
+
+
+class TAnnularS4Physics : public TObject, public NPL::VDetector {
+  //////////////////////////////////////////////////////////////
+  // constructor and destructor
+  public:
+    TAnnularS4Physics();
+    ~TAnnularS4Physics() {};
+
+
+  //////////////////////////////////////////////////////////////
+  // 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>  StripNbr;
+    vector<double>  SectorNbr;
+    vector<double>  Time;
+
+  /// A usefull method to bundle all operation to add a detector
+  void AddDetector(TVector3 POS);
+  void AddDetector(double R, double Theta, double Phi);
+  
+  //////////////////////////////////////////////////////////////
+  // 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 TAnnularS4Spectra class
+    // instantiate the TAnnularS4Spectra 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 AnnularS4 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 TAnnularS4Data object to TAnnularS4Physics. 
+    // needed for online analysis for example
+    void SetRawDataPointer(TAnnularS4Data* rawDataPointer) {m_EventData = rawDataPointer;}
+    
+  // objects are not written in the TTree
+  private:
+    TAnnularS4Data*         m_EventData;        //!
+    TAnnularS4Data*         m_PreTreatedData;   //!
+    TAnnularS4Physics*      m_EventPhysics;     //!
+
+  // getters for raw and pre-treated data object
+  public:
+    TAnnularS4Data* GetRawData()        const {return m_EventData;}
+    TAnnularS4Data* 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:
+    TAnnularS4Spectra* m_Spectra; // !
+
+  // spectra getter
+  public:
+    map<string, TH1*>   GetSpectra(); 
+    vector<TCanvas*>    GetCanvas();
+
+  // Static constructor to be passed to the Detector Factory
+  public:
+    static NPL::VDetector* Construct();
+
+    ClassDef(TAnnularS4Physics,1)  // AnnularS4Physics structure
+};
+#endif
diff --git a/NPLib/Detectors/AnnularS4/TAnnularS4Spectra.cxx b/NPLib/Detectors/AnnularS4/TAnnularS4Spectra.cxx
new file mode 100644
index 000000000..3f5cdfc16
--- /dev/null
+++ b/NPLib/Detectors/AnnularS4/TAnnularS4Spectra.cxx
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2017   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Pierre Morfouace  contact address: morfouac@nscl.msu.edu                        *
+ *                                                                           *
+ * Creation Date  : January 2017                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold AnnularS4 Spectra                                     *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// class header 
+#include "TAnnularS4Spectra.h"
+
+// STL
+#include <iostream>  
+#include <string>
+using namespace std;
+
+// NPTool header
+#include "NPOptionManager.h"
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TAnnularS4Spectra::TAnnularS4Spectra() 
+   : fNumberOfDetectors(0) {
+  SetName("AnnularS4");
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TAnnularS4Spectra::TAnnularS4Spectra(unsigned int NumberOfDetectors) {
+  if(NPOptionManager::getInstance()->GetVerboseLevel()>0)
+    cout << "************************************************" << endl
+      << "TAnnularS4Spectra : Initalizing control spectra for " 
+      << NumberOfDetectors << " Detectors" << endl
+      << "************************************************" << endl ;
+  SetName("AnnularS4");
+  fNumberOfDetectors = NumberOfDetectors;
+
+  InitRawSpectra();
+  InitPreTreatedSpectra();
+  InitPhysicsSpectra();
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TAnnularS4Spectra::~TAnnularS4Spectra() {
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TAnnularS4Spectra::InitRawSpectra() {
+  static string name;
+  for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors
+    // Energy 
+    name = "AnnularS4"+NPL::itoa(i+1)+"_ENERGY_RAW";
+    AddHisto1D(name, name, 4096, 0, 16384, "AnnularS4/RAW");
+    // Time 
+    name = "AnnularS4"+NPL::itoa(i+1)+"_TIME_RAW";
+    AddHisto1D(name, name, 4096, 0, 16384, "AnnularS4/RAW");
+  } // end loop on number of detectors
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TAnnularS4Spectra::InitPreTreatedSpectra() {
+  static string name;
+  for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors
+    // Energy 
+    name = "AnnularS4"+NPL::itoa(i+1)+"_ENERGY_CAL";
+    AddHisto1D(name, name, 500, 0, 25, "AnnularS4/CAL");
+    // Time
+    name = "AnnularS4"+NPL::itoa(i+1)+"_TIME_CAL";
+    AddHisto1D(name, name, 500, 0, 25, "AnnularS4/CAL");
+
+  
+  }  // end loop on number of detectors
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TAnnularS4Spectra::InitPhysicsSpectra() {
+  static string name;
+  // Kinematic Plot 
+  name = "AnnularS4_ENERGY_TIME";
+  AddHisto2D(name, name, 500, 0, 500, 500, 0, 50, "AnnularS4/PHY");
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TAnnularS4Spectra::FillRawSpectra(TAnnularS4Data* RawData) {
+  /*static string name;
+  static string family;
+
+  // Energy 
+  unsigned int sizeE = RawData->GetMultEnergy();
+  for (unsigned int i = 0; i < sizeE; i++) {
+    name = "AnnularS4"+NPL::itoa(RawData->GetE_DetectorNbr(i))+"_ENERGY_RAW";
+    family = "AnnularS4/RAW";
+
+    GetHisto(family,name) -> Fill(RawData->Get_Energy(i));
+  }
+
+  // Time
+  unsigned int sizeT = RawData->GetMultTime();
+  for (unsigned int i = 0; i < sizeT; i++) {
+    name = "AnnularS4"+NPL::itoa(RawData->GetT_DetectorNbr(i))+"_TIME_RAW";
+    family = "AnnularS4/RAW";
+
+    GetHisto(family,name) -> Fill(RawData->Get_Time(i));
+  }*/
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TAnnularS4Spectra::FillPreTreatedSpectra(TAnnularS4Data* PreTreatedData) {
+  /*static string name;
+  static string family;
+  
+  // Energy 
+  unsigned int sizeE = PreTreatedData->GetMultEnergy();
+  for (unsigned int i = 0; i < sizeE; i++) {
+    name = "AnnularS4"+NPL::itoa(PreTreatedData->GetE_DetectorNbr(i))+"_ENERGY_CAL";
+    family = "AnnularS4/CAL";
+
+    GetHisto(family,name) -> Fill(PreTreatedData->Get_Energy(i));
+  }
+
+  // Time
+  unsigned int sizeT = PreTreatedData->GetMultTime();
+  for (unsigned int i = 0; i < sizeT; i++) {
+    name = "AnnularS4"+NPL::itoa(PreTreatedData->GetT_DetectorNbr(i))+"_TIME_CAL";
+    family = "AnnularS4/CAL";
+
+    GetHisto(family,name) -> Fill(PreTreatedData->Get_Time(i));
+  }*/
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TAnnularS4Spectra::FillPhysicsSpectra(TAnnularS4Physics* Physics) {
+  /*static string name;
+  static string family;
+  family= "AnnularS4/PHY";
+
+  // Energy vs time
+  unsigned int sizeE = Physics->Energy.size();
+  for(unsigned int i = 0 ; i < sizeE ; i++){
+    name = "AnnularS4_ENERGY_TIME";
+    GetHisto(family,name) -> Fill(Physics->Energy[i],Physics->Time[i]);
+  }*/
+}
+
diff --git a/NPLib/Detectors/AnnularS4/TAnnularS4Spectra.h b/NPLib/Detectors/AnnularS4/TAnnularS4Spectra.h
new file mode 100644
index 000000000..c9e5f62d4
--- /dev/null
+++ b/NPLib/Detectors/AnnularS4/TAnnularS4Spectra.h
@@ -0,0 +1,62 @@
+#ifndef TAnnularS4SPECTRA_H
+#define TAnnularS4SPECTRA_H
+/*****************************************************************************
+ * Copyright (C) 2009-2017   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Pierre Morfouace  contact address: morfouac@nscl.msu.edu                        *
+ *                                                                           *
+ * Creation Date  : January 2017                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold AnnularS4 Spectra                                     *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// NPLib headers
+#include "NPVSpectra.h"
+#include "TAnnularS4Data.h"
+#include "TAnnularS4Physics.h"
+
+// Forward Declaration
+class TAnnularS4Physics;
+
+
+class TAnnularS4Spectra : public VSpectra {
+  //////////////////////////////////////////////////////////////
+  // constructor and destructor
+  public:
+    TAnnularS4Spectra();
+    TAnnularS4Spectra(unsigned int NumberOfDetectors);
+    ~TAnnularS4Spectra();
+
+  //////////////////////////////////////////////////////////////
+  // Initialization methods
+  private:
+    void InitRawSpectra();
+    void InitPreTreatedSpectra();
+    void InitPhysicsSpectra();
+
+  //////////////////////////////////////////////////////////////
+  // Filling methods
+  public:
+    void FillRawSpectra(TAnnularS4Data*);
+    void FillPreTreatedSpectra(TAnnularS4Data*);
+    void FillPhysicsSpectra(TAnnularS4Physics*);
+
+  //////////////////////////////////////////////////////////////
+  // Detector parameters 
+  private:
+    unsigned int fNumberOfDetectors;
+};
+
+#endif
-- 
GitLab