From 9ede4467a0802e742979120e9ad395608db875c6 Mon Sep 17 00:00:00 2001
From: Hugo Jacob <hugojacob57@gmail.com>
Date: Wed, 19 Jul 2023 16:58:24 +0200
Subject: [PATCH] Adding TAC Data Class + Changing TS to ULong64 in Exo and ZDD
 Data Classes

---
 NPLib/Detectors/Exogam/TExogamData.h |  18 +-
 NPLib/Detectors/TAC/CMakeLists.txt   |   6 +
 NPLib/Detectors/TAC/TTACData.cxx     |  64 +++++
 NPLib/Detectors/TAC/TTACData.h       |  89 +++++++
 NPLib/Detectors/TAC/TTACPhysics.cxx  | 344 +++++++++++++++++++++++++++
 NPLib/Detectors/TAC/TTACPhysics.h    | 180 ++++++++++++++
 NPLib/Detectors/TAC/TTACSpectra.cxx  | 174 ++++++++++++++
 NPLib/Detectors/TAC/TTACSpectra.h    |  62 +++++
 NPLib/Detectors/ZDD/TZDDData.h       |  24 +-
 9 files changed, 940 insertions(+), 21 deletions(-)
 create mode 100644 NPLib/Detectors/TAC/CMakeLists.txt
 create mode 100644 NPLib/Detectors/TAC/TTACData.cxx
 create mode 100644 NPLib/Detectors/TAC/TTACData.h
 create mode 100644 NPLib/Detectors/TAC/TTACPhysics.cxx
 create mode 100644 NPLib/Detectors/TAC/TTACPhysics.h
 create mode 100644 NPLib/Detectors/TAC/TTACSpectra.cxx
 create mode 100644 NPLib/Detectors/TAC/TTACSpectra.h

diff --git a/NPLib/Detectors/Exogam/TExogamData.h b/NPLib/Detectors/Exogam/TExogamData.h
index eb2e8c1be..953fc1464 100644
--- a/NPLib/Detectors/Exogam/TExogamData.h
+++ b/NPLib/Detectors/Exogam/TExogamData.h
@@ -30,15 +30,15 @@ class TExogamData : public TObject {
  private:
   std::vector<UShort_t> fEXO_E;
   std::vector<UShort_t> fEXO_E_CrystalNbr;
-  std::vector<UShort_t> fEXO_E_TS;
+  std::vector<ULong64_t> fEXO_E_TS;
 
   std::vector<UShort_t> fEXO_HG; // Same as Energy but with High Gain (for Low Energy events) 
   std::vector<UShort_t> fEXO_HG_CrystalNbr;
-  std::vector<UShort_t> fEXO_HG_TS;
+  std::vector<ULong64_t> fEXO_HG_TS;
 
   std::vector<UShort_t> fEXO_TDC; // Internal TDC of EXOGAM
   std::vector<UShort_t> fEXO_TDC_CrystalNbr;
-  std::vector<UShort_t> fEXO_TDC_TS;
+  std::vector<ULong64_t> fEXO_TDC_TS;
 
   std::vector<UShort_t> fEXO_Outer;
   std::vector<UShort_t> fEXO_Outer_SubCrystalNbr; 
@@ -58,17 +58,17 @@ class TExogamData : public TObject {
   void Dump() const;
 
   /////////////////////           SETTERS           ////////////////////////
-  inline void SetInner6MV(UShort_t& Energy, UShort_t& DetNumb, UShort_t& TimeStamp) {
+  inline void SetInner6MV(UShort_t& Energy, UShort_t& DetNumb, ULong64_t& TimeStamp) {
     fEXO_E.push_back(Energy);
     fEXO_E_CrystalNbr.push_back(DetNumb);
     fEXO_E_TS.push_back(TimeStamp);
   }
-  inline void SetInner20MV(UShort_t& Energy, UShort_t& DetNumb, UShort_t& TimeStamp) {
+  inline void SetInner20MV(UShort_t& Energy, UShort_t& DetNumb, ULong64_t& TimeStamp) {
     fEXO_HG.push_back(Energy);
     fEXO_HG_CrystalNbr.push_back(DetNumb);
     fEXO_HG_TS.push_back(TimeStamp);
   }
-  inline void SetDeltaTV(UShort_t& Time, UShort_t& DetNumb, UShort_t& TimeStamp) {
+  inline void SetDeltaTV(UShort_t& Time, UShort_t& DetNumb, ULong64_t& TimeStamp) {
     fEXO_TDC.push_back(Time);
     fEXO_TDC_CrystalNbr.push_back(DetNumb);
     fEXO_TDC_TS.push_back(TimeStamp);
@@ -88,13 +88,13 @@ class TExogamData : public TObject {
   /////////////////////           GETTERS           ////////////////////////
   inline UShort_t GetEXO_E(UShort_t& i) { return fEXO_E[i]; }
   inline UShort_t GetEXO_E_CrystalNbr(UShort_t& i) { return fEXO_E_CrystalNbr[i]; }
-  inline UShort_t GetEXO_E_TS(UShort_t& i) { return fEXO_E_TS[i]; }
+  inline ULong64_t GetEXO_E_TS(UShort_t& i) { return fEXO_E_TS[i]; }
   inline UShort_t GetEXO_HG(UShort_t& i) { return fEXO_HG[i]; }
   inline UShort_t GetEXO_HG_CrystalNbr(UShort_t& i) { return fEXO_HG_CrystalNbr[i]; }
-  inline UShort_t GetEXO_HG_TS(UShort_t& i) { return fEXO_HG_TS[i]; }
+  inline ULong64_t GetEXO_HG_TS(UShort_t& i) { return fEXO_HG_TS[i]; }
   inline UShort_t GetEXO_TDC(UShort_t& i) { return fEXO_TDC[i]; }
   inline UShort_t GetEXO_TDC_CrystalNbr(UShort_t& i) { return fEXO_TDC_CrystalNbr[i]; }
-  inline UShort_t GetEXO_TDC_TS(UShort_t& i) { return fEXO_TDC_TS[i]; }
+  inline ULong64_t GetEXO_TDC_TS(UShort_t& i) { return fEXO_TDC_TS[i]; }
   inline UShort_t GetEXO_Outer(UShort_t& i) { return fEXO_Outer[i]; }
   inline UShort_t GetEXO_Outer_SubCrystalNbr(UShort_t& i) { return fEXO_Outer_SubCrystalNbr[i]; }
   inline UShort_t GetEXO_BGO(UShort_t& i) { return fEXO_BGO[i]; }
diff --git a/NPLib/Detectors/TAC/CMakeLists.txt b/NPLib/Detectors/TAC/CMakeLists.txt
new file mode 100644
index 000000000..c52326331
--- /dev/null
+++ b/NPLib/Detectors/TAC/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_custom_command(OUTPUT TTACPhysicsDict.cxx COMMAND ../../scripts/build_dict.sh TTACPhysics.h TTACPhysicsDict.cxx TTACPhysics.rootmap libNPTAC.dylib DEPENDS TTACPhysics.h)
+add_custom_command(OUTPUT TTACDataDict.cxx COMMAND ../../scripts/build_dict.sh TTACData.h TTACDataDict.cxx TTACData.rootmap libNPTAC.dylib DEPENDS TTACData.h)
+add_library(NPTAC SHARED TTACSpectra.cxx TTACData.cxx TTACPhysics.cxx TTACDataDict.cxx TTACPhysicsDict.cxx )
+target_link_libraries(NPTAC ${ROOT_LIBRARIES} NPCore) 
+install(FILES TTACData.h TTACPhysics.h TTACSpectra.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+
diff --git a/NPLib/Detectors/TAC/TTACData.cxx b/NPLib/Detectors/TAC/TTACData.cxx
new file mode 100644
index 000000000..6a5126c6c
--- /dev/null
+++ b/NPLib/Detectors/TAC/TTACData.cxx
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2023   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Hugo Jacob  contact address: hjacob@ijclab.in2p3.fr                        *
+ *                                                                           *
+ * Creation Date  : July 2023                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold TAC Raw data                                    *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+#include "TTACData.h"
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+using namespace std; 
+
+ClassImp(TTACData)
+
+
+//////////////////////////////////////////////////////////////////////
+TTACData::TTACData() {
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+TTACData::~TTACData() {
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+void TTACData::Clear() { 
+  fTAC_Channel.clear();
+  fTAC_Nbr.clear();
+  fTAC_TS.clear();
+}
+
+
+
+//////////////////////////////////////////////////////////////////////
+void TTACData::Dump() const {
+  // This method is very useful for debuging and worth the dev.
+  cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event [TTACData::Dump()] XXXXXXXXXXXXXXXXX" << endl;
+
+  size_t mysize = fTAC_Channel.size();
+  cout << "TAC_Mult: " << mysize << endl;
+  for (size_t i = 0 ; i < mysize ; i++){
+    cout << "TACNbr: " << fTAC_Nbr[i]  << " Channel: " << fTAC_Channel[i] << " TS: " << fTAC_TS[i] << endl;
+  }
+}
diff --git a/NPLib/Detectors/TAC/TTACData.h b/NPLib/Detectors/TAC/TTACData.h
new file mode 100644
index 000000000..be342c449
--- /dev/null
+++ b/NPLib/Detectors/TAC/TTACData.h
@@ -0,0 +1,89 @@
+#ifndef __TACDATA__
+#define __TACDATA__
+/*****************************************************************************
+ * Copyright (C) 2009-2023   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Hugo Jacob  contact address: hjacob@ijclab.in2p3.fr                        *
+ *                                                                           *
+ * Creation Date  : July 2023                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold TAC Raw data                                    *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// STL
+#include <vector>
+using namespace std;
+
+// ROOT
+#include "TObject.h"
+
+class TTACData : public TObject {
+  //////////////////////////////////////////////////////////////
+  // data members are hold into vectors in order 
+  // to allow multiplicity treatment
+  private: 
+    // Energy
+    vector<UShort_t>   fTAC_Channel;
+    vector<UShort_t>   fTAC_Nbr;
+    vector<ULong64_t>  fTAC_TS;
+
+  //////////////////////////////////////////////////////////////
+  // Constructor and destructor
+  public: 
+    TTACData();
+    ~TTACData();
+    
+
+  //////////////////////////////////////////////////////////////
+  // 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    ////////////////////////
+    inline void SetTAC(const UShort_t& TACNbr,const UShort_t& Channel, const ULong64_t& TS){
+      fTAC_Nbr.push_back(TACNbr);
+      fTAC_Channel.push_back(Channel);
+      fTAC_TS.push_back(TS);
+    };//!
+
+
+
+    //////////////////////    GETTERS    ////////////////////////
+    // Energy
+    inline UShort_t GetTAC_Mult() const
+      {return fTAC_Channel.size();}
+    inline UShort_t GetTAC_Channel(const unsigned int &i) const 
+      {return fTAC_Channel[i];}//!
+    inline UShort_t GetTAC_Nbr(const unsigned int &i) const 
+      {return fTAC_Nbr[i];}//!
+    inline ULong64_t GetTAC_TS(const unsigned int &i) const 
+      {return fTAC_TS[i];}//!
+
+
+  //////////////////////////////////////////////////////////////
+  // Required for ROOT dictionnary
+  ClassDef(TTACData,1)  // TACData structure
+};
+
+#endif
diff --git a/NPLib/Detectors/TAC/TTACPhysics.cxx b/NPLib/Detectors/TAC/TTACPhysics.cxx
new file mode 100644
index 000000000..f477dbb9a
--- /dev/null
+++ b/NPLib/Detectors/TAC/TTACPhysics.cxx
@@ -0,0 +1,344 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2023   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Hugo Jacob  contact address: hjacob@ijclab.in2p3.fr                        *
+ *                                                                           *
+ * Creation Date  : July 2023                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold TAC Treated  data                               *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+#include "TTACPhysics.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(TTACPhysics)
+
+
+///////////////////////////////////////////////////////////////////////////
+TTACPhysics::TTACPhysics()
+   : m_EventData(new TTACData),
+     m_PreTreatedData(new TTACData),
+     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 TTACPhysics::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 TTACPhysics::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 TTACPhysics::BuildSimplePhysicalEvent() {
+  BuildPhysicalEvent();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::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 TTACPhysics::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("TAC/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("TAC/TIME"+NPL::itoa(m_EventData->GetT_DetectorNbr(i)),m_EventData->Get_Time(i));
+    m_PreTreatedData->SetTime(m_EventData->GetT_DetectorNbr(i), Time);
+  }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::ReadAnalysisConfig() {
+  bool ReadingStatus = false;
+
+  // path to file
+  string FileName = "./configs/ConfigTAC.dat";
+
+  // open analysis config file
+  ifstream AnalysisConfigFile;
+  AnalysisConfigFile.open(FileName.c_str());
+
+  if (!AnalysisConfigFile.is_open()) {
+    cout << " No ConfigTAC.dat found: Default parameter loaded for Analayis " << FileName << endl;
+    return;
+  }
+  cout << " Loading user parameter for Analysis from ConfigTAC.dat " << endl;
+
+  // Save it in a TAsciiFile
+  TAsciiFile* asciiConfig = RootOutput::getInstance()->GetAsciiFileAnalysisConfig();
+  asciiConfig->AppendLine("%%% ConfigTAC.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 = "ConfigTAC";
+    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 TTACPhysics::Clear() {
+  DetectorNumber.clear();
+  Energy.clear();
+  Time.clear();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::ReadConfiguration(NPL::InputParser parser) {
+  vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("TAC");
+  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 << "////  TAC " << 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 << "////  TAC " << 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 TTACPhysics::InitSpectra() {
+  m_Spectra = new TTACSpectra(m_NumberOfDetectors);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::FillSpectra() {
+  m_Spectra -> FillRawSpectra(m_EventData);
+  m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData);
+  m_Spectra -> FillPhysicsSpectra(m_EventPhysics);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::CheckSpectra() {
+  m_Spectra->CheckSpectra();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::ClearSpectra() {
+  // To be done
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+map< string , TH1*> TTACPhysics::GetSpectra() {
+  if(m_Spectra)
+    return m_Spectra->GetMapHisto();
+  else{
+    map< string , TH1*> empty;
+    return empty;
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::WriteSpectra() {
+  m_Spectra->WriteSpectra();
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::AddParameterToCalibrationManager() {
+  CalibrationManager* Cal = CalibrationManager::getInstance();
+  for (int i = 0; i < m_NumberOfDetectors; ++i) {
+    Cal->AddParameter("TAC", "D"+ NPL::itoa(i+1)+"_ENERGY","TAC_D"+ NPL::itoa(i+1)+"_ENERGY");
+    Cal->AddParameter("TAC", "D"+ NPL::itoa(i+1)+"_TIME","TAC_D"+ NPL::itoa(i+1)+"_TIME");
+  }
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::InitializeRootInputRaw() {
+  TChain* inputChain = RootInput::getInstance()->GetChain();
+  inputChain->SetBranchStatus("TAC",  true );
+  inputChain->SetBranchAddress("TAC", &m_EventData );
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::InitializeRootInputPhysics() {
+  TChain* inputChain = RootInput::getInstance()->GetChain();
+  inputChain->SetBranchAddress("TAC", &m_EventPhysics);
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////
+void TTACPhysics::InitializeRootOutput() {
+  TTree* outputTree = RootOutput::getInstance()->GetTree();
+  outputTree->Branch("TAC", "TTACPhysics", &m_EventPhysics);
+}
+*/
+
+
+////////////////////////////////////////////////////////////////////////////////
+//            Construct Method to be pass to the DetectorFactory              //
+////////////////////////////////////////////////////////////////////////////////
+NPL::VDetector* TTACPhysics::Construct() {
+  return (NPL::VDetector*) new TTACPhysics();
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+//            Registering the construct method to the factory                 //
+////////////////////////////////////////////////////////////////////////////////
+extern "C"{
+class proxy_TAC{
+  public:
+    proxy_TAC(){
+      NPL::DetectorFactory::getInstance()->AddToken("TAC","TAC");
+      NPL::DetectorFactory::getInstance()->AddDetector("TAC",TTACPhysics::Construct);
+    }
+};
+
+proxy_TAC p_TAC;
+}
+
diff --git a/NPLib/Detectors/TAC/TTACPhysics.h b/NPLib/Detectors/TAC/TTACPhysics.h
new file mode 100644
index 000000000..64d231693
--- /dev/null
+++ b/NPLib/Detectors/TAC/TTACPhysics.h
@@ -0,0 +1,180 @@
+#ifndef TTACPHYSICS_H
+#define TTACPHYSICS_H
+/*****************************************************************************
+ * Copyright (C) 2009-2023   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Hugo Jacob  contact address: hjacob@ijclab.in2p3.fr                        *
+ *                                                                           *
+ * Creation Date  : July 2023                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold TAC 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 "TTACData.h"
+#include "TTACSpectra.h"
+#include "NPCalibrationManager.h"
+#include "NPVDetector.h"
+#include "NPInputParser.h"
+// forward declaration
+class TTACSpectra;
+
+
+
+class TTACPhysics : public TObject, public NPL::VDetector {
+  //////////////////////////////////////////////////////////////
+  // constructor and destructor
+  public:
+    TTACPhysics();
+    ~TTACPhysics() {};
+
+
+  //////////////////////////////////////////////////////////////
+  // 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 TTACSpectra class
+    // instantiate the TTACSpectra 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 TAC 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 TTACData object to TTACPhysics. 
+    // needed for online analysis for example
+    void SetRawDataPointer(TTACData* rawDataPointer) {m_EventData = rawDataPointer;}
+    
+  // objects are not written in the TTree
+  private:
+    TTACData*         m_EventData;        //!
+    TTACData*         m_PreTreatedData;   //!
+    TTACPhysics*      m_EventPhysics;     //!
+
+  // getters for raw and pre-treated data object
+  public:
+    TTACData* GetRawData()        const {return m_EventData;}
+    TTACData* 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:
+    TTACSpectra* m_Spectra; // !
+
+  // spectra getter
+  public:
+    map<string, TH1*>   GetSpectra(); 
+
+  // Static constructor to be passed to the Detector Factory
+  public:
+    static NPL::VDetector* Construct();
+
+    ClassDef(TTACPhysics,1)  // TACPhysics structure
+};
+#endif
diff --git a/NPLib/Detectors/TAC/TTACSpectra.cxx b/NPLib/Detectors/TAC/TTACSpectra.cxx
new file mode 100644
index 000000000..be58ca908
--- /dev/null
+++ b/NPLib/Detectors/TAC/TTACSpectra.cxx
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * Copyright (C) 2009-2023   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Hugo Jacob  contact address: hjacob@ijclab.in2p3.fr                        *
+ *                                                                           *
+ * Creation Date  : July 2023                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold TAC Spectra                                     *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// class header 
+#include "TTACSpectra.h"
+
+// STL
+#include <iostream>  
+#include <string>
+using namespace std;
+
+// NPTool header
+#include "NPOptionManager.h"
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TTACSpectra::TTACSpectra() 
+   : fNumberOfDetectors(0) {
+  SetName("TAC");
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TTACSpectra::TTACSpectra(unsigned int NumberOfDetectors) {
+  if(NPOptionManager::getInstance()->GetVerboseLevel()>0)
+    cout << "************************************************" << endl
+      << "TTACSpectra : Initalizing control spectra for " 
+      << NumberOfDetectors << " Detectors" << endl
+      << "************************************************" << endl ;
+  SetName("TAC");
+  fNumberOfDetectors = NumberOfDetectors;
+
+  InitRawSpectra();
+  InitPreTreatedSpectra();
+  InitPhysicsSpectra();
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+TTACSpectra::~TTACSpectra() {
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TTACSpectra::InitRawSpectra() {
+  static string name;
+  for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors
+    // Energy 
+    name = "TAC"+NPL::itoa(i+1)+"_ENERGY_RAW";
+    AddHisto1D(name, name, 4096, 0, 16384, "TAC/RAW");
+    // Time 
+    name = "TAC"+NPL::itoa(i+1)+"_TIME_RAW";
+    AddHisto1D(name, name, 4096, 0, 16384, "TAC/RAW");
+  } // end loop on number of detectors
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TTACSpectra::InitPreTreatedSpectra() {
+  static string name;
+  for (unsigned int i = 0; i < fNumberOfDetectors; i++) { // loop on number of detectors
+    // Energy 
+    name = "TAC"+NPL::itoa(i+1)+"_ENERGY_CAL";
+    AddHisto1D(name, name, 500, 0, 25, "TAC/CAL");
+    // Time
+    name = "TAC"+NPL::itoa(i+1)+"_TIME_CAL";
+    AddHisto1D(name, name, 500, 0, 25, "TAC/CAL");
+
+  
+  }  // end loop on number of detectors
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TTACSpectra::InitPhysicsSpectra() {
+  static string name;
+  // Kinematic Plot 
+  name = "TAC_ENERGY_TIME";
+  AddHisto2D(name, name, 500, 0, 500, 500, 0, 50, "TAC/PHY");
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+/*void TTACSpectra::FillRawSpectra(TTACData* RawData) {
+  static string name;
+  static string family;
+
+  // Energy 
+  unsigned int sizeE = RawData->GetMultEnergy();
+  for (unsigned int i = 0; i < sizeE; i++) {
+    name = "TAC"+NPL::itoa(RawData->GetE_DetectorNbr(i))+"_ENERGY_RAW";
+    family = "TAC/RAW";
+
+    FillSpectra(family,name,RawData->Get_Energy(i));
+  }
+
+  // Time
+  unsigned int sizeT = RawData->GetMultTime();
+  for (unsigned int i = 0; i < sizeT; i++) {
+    name = "TAC"+NPL::itoa(RawData->GetT_DetectorNbr(i))+"_TIME_RAW";
+    family = "TAC/RAW";
+
+    FillSpectra(family,name,RawData->Get_Time(i));
+  }
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TTACSpectra::FillPreTreatedSpectra(TTACData* PreTreatedData) {
+  static string name;
+  static string family;
+  
+  // Energy 
+  unsigned int sizeE = PreTreatedData->GetMultEnergy();
+  for (unsigned int i = 0; i < sizeE; i++) {
+    name = "TAC"+NPL::itoa(PreTreatedData->GetE_DetectorNbr(i))+"_ENERGY_CAL";
+    family = "TAC/CAL";
+
+    FillSpectra(family,name,PreTreatedData->Get_Energy(i));
+  }
+
+  // Time
+  unsigned int sizeT = PreTreatedData->GetMultTime();
+  for (unsigned int i = 0; i < sizeT; i++) {
+    name = "TAC"+NPL::itoa(PreTreatedData->GetT_DetectorNbr(i))+"_TIME_CAL";
+    family = "TAC/CAL";
+
+    FillSpectra(family,name,PreTreatedData->Get_Time(i));
+  }
+}
+*/
+
+
+////////////////////////////////////////////////////////////////////////////////
+void TTACSpectra::FillPhysicsSpectra(TTACPhysics* Physics) {
+  static string name;
+  static string family;
+  family= "TAC/PHY";
+
+  // Energy vs time
+  unsigned int sizeE = Physics->Energy.size();
+  for(unsigned int i = 0 ; i < sizeE ; i++){
+    name = "TAC_ENERGY_TIME";
+    FillSpectra(family,name,Physics->Energy[i],Physics->Time[i]);
+  }
+}
+
diff --git a/NPLib/Detectors/TAC/TTACSpectra.h b/NPLib/Detectors/TAC/TTACSpectra.h
new file mode 100644
index 000000000..4ef4f1abb
--- /dev/null
+++ b/NPLib/Detectors/TAC/TTACSpectra.h
@@ -0,0 +1,62 @@
+#ifndef TTACSPECTRA_H
+#define TTACSPECTRA_H
+/*****************************************************************************
+ * Copyright (C) 2009-2023   this file is part of the NPTool Project       *
+ *                                                                           *
+ * For the licensing terms see $NPTOOL/Licence/NPTool_Licence                *
+ * For the list of contributors see $NPTOOL/Licence/Contributors             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Original Author: Hugo Jacob  contact address: hjacob@ijclab.in2p3.fr                        *
+ *                                                                           *
+ * Creation Date  : July 2023                                           *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold TAC Spectra                                     *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *   
+ *                                                                           *
+ *****************************************************************************/
+
+// NPLib headers
+#include "NPVSpectra.h"
+#include "TTACData.h"
+#include "TTACPhysics.h"
+
+// Forward Declaration
+class TTACPhysics;
+
+
+class TTACSpectra : public VSpectra {
+  //////////////////////////////////////////////////////////////
+  // constructor and destructor
+  public:
+    TTACSpectra();
+    TTACSpectra(unsigned int NumberOfDetectors);
+    ~TTACSpectra();
+
+  //////////////////////////////////////////////////////////////
+  // Initialization methods
+  private:
+    void InitRawSpectra();
+    void InitPreTreatedSpectra();
+    void InitPhysicsSpectra();
+
+  //////////////////////////////////////////////////////////////
+  // Filling methods
+  public:
+    void FillRawSpectra(TTACData*);
+    void FillPreTreatedSpectra(TTACData*);
+    void FillPhysicsSpectra(TTACPhysics*);
+
+  //////////////////////////////////////////////////////////////
+  // Detector parameters 
+  private:
+    unsigned int fNumberOfDetectors;
+};
+
+#endif
diff --git a/NPLib/Detectors/ZDD/TZDDData.h b/NPLib/Detectors/ZDD/TZDDData.h
index b03959fe4..f25b6f24d 100644
--- a/NPLib/Detectors/ZDD/TZDDData.h
+++ b/NPLib/Detectors/ZDD/TZDDData.h
@@ -39,22 +39,22 @@ class TZDDData : public TObject {
     // IC
     vector<UShort_t>   fZDD_IC_E;
     vector<UShort_t>   fZDD_IC_N;
-    vector<UShort_t>   fZDD_IC_TS;
+    vector<ULong64_t>   fZDD_IC_TS;
 
     // Plastic
     vector<UShort_t>   fZDD_PM_E;
     vector<UShort_t>   fZDD_PM_N;
-    vector<UShort_t>   fZDD_PM_TS;
+    vector<ULong64_t>   fZDD_PM_TS;
     
     // DC
     vector<UShort_t>   fZDD_DC_E;
     vector<UShort_t>   fZDD_DC_N;
-    vector<UShort_t>   fZDD_DC_TS;
+    vector<ULong64_t>   fZDD_DC_TS;
     
     // EXOZDD
     vector<UShort_t>   fZDD_EXO_E;
     vector<UShort_t>   fZDD_EXO_N;
-    vector<UShort_t>   fZDD_EXO_TS;
+    vector<ULong64_t>   fZDD_EXO_TS;
 
 
   //////////////////////////////////////////////////////////////
@@ -80,22 +80,22 @@ class TZDDData : public TObject {
   public:
     //////////////////////    SETTERS    ////////////////////////
     // Energy
-    inline void SetZDDIC(const UShort_t& DetNumb,const UShort_t& Energy, const UShort_t& TimeStamp){
+    inline void SetZDDIC(const UShort_t& DetNumb,const UShort_t& Energy, const ULong64_t& TimeStamp){
       fZDD_IC_E.push_back(Energy);
       fZDD_IC_N.push_back(DetNumb);
       fZDD_IC_TS.push_back(TimeStamp);
     };//!
-    inline void SetZDDPM(const UShort_t& DetNumb,const UShort_t& Energy, const UShort_t& TimeStamp){
+    inline void SetZDDPM(const UShort_t& DetNumb,const UShort_t& Energy, const ULong64_t& TimeStamp){
       fZDD_PM_E.push_back(Energy);
       fZDD_PM_N.push_back(DetNumb);
       fZDD_PM_TS.push_back(TimeStamp);
     };//!
-    inline void SetZDDDC(const UShort_t& DetNumb,const UShort_t& Energy, const UShort_t& TimeStamp){
+    inline void SetZDDDC(const UShort_t& DetNumb,const UShort_t& Energy, const ULong64_t& TimeStamp){
       fZDD_DC_E.push_back(Energy);
       fZDD_DC_N.push_back(DetNumb);
       fZDD_DC_TS.push_back(TimeStamp);
     };//!
-    inline void SetZDDEXO(const UShort_t& DetNumb,const UShort_t& Energy, const UShort_t& TimeStamp){
+    inline void SetZDDEXO(const UShort_t& DetNumb,const UShort_t& Energy, const ULong64_t& TimeStamp){
       fZDD_EXO_E.push_back(Energy);
       fZDD_EXO_N.push_back(DetNumb);
       fZDD_EXO_TS.push_back(TimeStamp);
@@ -104,16 +104,16 @@ class TZDDData : public TObject {
     //////////////////////    GETTERS    ////////////////////////
     inline UShort_t GetZDD_ICE(UShort_t& i) { return fZDD_IC_E[i]; }
     inline UShort_t GetZDD_ICN(UShort_t& i) { return fZDD_IC_N[i]; }
-    inline UShort_t GetZDD_ICTS(UShort_t& i) { return fZDD_IC_TS[i]; }
+    inline ULong64_t GetZDD_ICTS(UShort_t& i) { return fZDD_IC_TS[i]; }
     inline UShort_t GetZDD_PME(UShort_t& i) { return fZDD_PM_E[i]; }
     inline UShort_t GetZDD_PMN(UShort_t& i) { return fZDD_PM_N[i]; }
-    inline UShort_t GetZDD_PMTS(UShort_t& i) { return fZDD_PM_TS[i]; }
+    inline ULong64_t GetZDD_PMTS(UShort_t& i) { return fZDD_PM_TS[i]; }
     inline UShort_t GetZDD_DCE(UShort_t& i) { return fZDD_DC_E[i]; }
     inline UShort_t GetZDD_DCN(UShort_t& i) { return fZDD_DC_N[i]; }
-    inline UShort_t GetZDD_DCTS(UShort_t& i) { return fZDD_DC_TS[i]; }
+    inline ULong64_t GetZDD_DCTS(UShort_t& i) { return fZDD_DC_TS[i]; }
     inline UShort_t GetZDD_EXOE(UShort_t& i) { return fZDD_EXO_E[i]; }
     inline UShort_t GetZDD_EXON(UShort_t& i) { return fZDD_EXO_N[i]; }
-    inline UShort_t GetZDD_EXOTS(UShort_t& i) { return fZDD_EXO_TS[i]; }
+    inline ULong64_t GetZDD_EXOTS(UShort_t& i) { return fZDD_EXO_TS[i]; }
 
   //////////////////////////////////////////////////////////////
   // Required for ROOT dictionnary
-- 
GitLab