From 565079ccf30ed3e338f4383e73398cc8720fc3bf Mon Sep 17 00:00:00 2001
From: flavigny <flavigny@lpccaen.in2p3.fr>
Date: Mon, 12 Apr 2021 15:55:41 +0200
Subject: [PATCH] * Adding Data an Physics class for RIBF PPAC (work in
 progress)

---
 .../Detectors/BigRIPS/BigRIPSPPACVariables.h  | 115 +++++
 NPLib/Detectors/BigRIPS/CMakeLists.txt        |   9 +
 NPLib/Detectors/BigRIPS/TBigRIPSPPACData.cxx  |  90 ++++
 NPLib/Detectors/BigRIPS/TBigRIPSPPACData.h    | 137 ++++++
 .../Detectors/BigRIPS/TBigRIPSPPACPhysics.cxx | 405 ++++++++++++++++++
 NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.h | 162 +++++++
 6 files changed, 918 insertions(+)
 create mode 100644 NPLib/Detectors/BigRIPS/BigRIPSPPACVariables.h
 create mode 100644 NPLib/Detectors/BigRIPS/CMakeLists.txt
 create mode 100644 NPLib/Detectors/BigRIPS/TBigRIPSPPACData.cxx
 create mode 100644 NPLib/Detectors/BigRIPS/TBigRIPSPPACData.h
 create mode 100644 NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.cxx
 create mode 100644 NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.h

diff --git a/NPLib/Detectors/BigRIPS/BigRIPSPPACVariables.h b/NPLib/Detectors/BigRIPS/BigRIPSPPACVariables.h
new file mode 100644
index 000000000..9b2cefe14
--- /dev/null
+++ b/NPLib/Detectors/BigRIPS/BigRIPSPPACVariables.h
@@ -0,0 +1,115 @@
+#ifndef BIGRIPSPPACVariables_H
+#define BIGRIPSPPACVariables_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: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
+ *                                                                           *
+ * Creation Date  : October 2020                                             *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold SamuraiFDC0 treated data                                 *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *  
+ *  little class to index each of the DC wire                                *
+ *                                                                           *
+ *****************************************************************************/
+
+#include <iostream>
+using namespace std;
+
+class BigRIPSPPACVariables{
+  public:
+   BigRIPSPPACVariables(){};  
+   ~BigRIPSPPACVariables(){};  
+
+  public:
+    std::vector<double> FTX1;
+    std::vector<double> FTX2;
+    std::vector<double> FTY1;
+    std::vector<double> FTY2;
+    std::vector<double> FTA;
+
+    void Clear(){
+        FTX1.clear();
+        FTX2.clear();
+        FTY1.clear();
+        FTY2.clear();
+        FTA.clear();
+    }
+    void Print(){
+        //cout << "XXXXXXXXXXXXXXXXXXXXXXXX PPAC Event XXXXXXXXXXXXXXXXX" << endl;
+        cout << "FTX1_Mult = " << FTX1.size();
+        for (UShort_t i = 0; i < FTX1.size(); i++){cout << "\tFTX1: " << FTX1[i] << endl;}
+        cout << "FTX2_Mult = " << FTX2.size();
+        for (UShort_t i = 0; i < FTX2.size(); i++){cout << "\tFTX2: " << FTX2[i] << endl;}
+        cout << "FTY1_Mult = " << FTY1.size();
+        for (UShort_t i = 0; i < FTY1.size(); i++){cout << "\tFTY1: " << FTY1[i] << endl;}
+        cout << "FTY2_Mult = " << FTY2.size();
+        for (UShort_t i = 0; i < FTY2.size(); i++){cout << "\tFTY2: " << FTY2[i] << endl;}
+        cout << "FTA_Mult = " << FTA.size();
+        for (UShort_t i = 0; i < FTA.size(); i++){cout << "\tFTA: " << FTA[i] << endl;}
+    }
+
+    bool HasTXs(){
+        if(FTX1.size()==1 && FTX2.size()==1){return true;}
+        else{return false;}
+    }
+    bool HasTYs(){
+        if(FTY1.size()==1 && FTY2.size()==1){return true;}
+        else{return false;}
+    }
+    bool HasTA(){
+        if(FTA.size()==1){return true;}
+        else{return false;}
+    }
+    bool HasEverything(){
+        if(FTX1.size()==1 && FTX2.size()==1 &&
+           FTY1.size()==1 && FTY2.size()==1 &&
+           FTA.size()==1){
+            return true;
+        }else{return false;}
+    }
+/*
+  public:
+    void SetTX1(double value){TX1=value;}
+    void SetTX2(double value){TX2=value;}
+    void SetTY1(double value){TY1=value;}
+    void SetTY2(double value){TY2=value;}
+    void SetTA(double value){TA=value;}
+
+
+    int GetTX1Mult() const {return TX1.size();}
+    int const GetTX1(const unsigned int& i){return fPPAC_TX1[i];};
+
+    int GetTX2Mult() const {return fPPAC_TX2_ID.size();}
+    int const GetTX2(const unsigned int& i){return fPPAC_TX2[i];};
+
+    int GetTY1Mult() const {return fPPAC_TY1_ID.size();}
+    int const GetTY1(const unsigned int& i){return fPPAC_TY1[i];};
+
+    int GetTY2Mult() const {return fPPAC_TY2_ID.size();}
+    int const GetTY2(const unsigned int& i){return fPPAC_TY2[i];};
+
+    int GetTAMult() const {return fPPAC_TA_ID.size();}
+    int const GetTA(const unsigned int& i){return fPPAC_TA[i];};
+
+
+    double GetTX1(){return TX1;}
+    double GetTX2(){return TX2;}
+    double GetTY1(){return TY1;}
+    double GetTY2(){return TY2;}
+    double GetTA(){return TA;}
+ */  
+  };
+
+#endif
diff --git a/NPLib/Detectors/BigRIPS/CMakeLists.txt b/NPLib/Detectors/BigRIPS/CMakeLists.txt
new file mode 100644
index 000000000..a40bdd27f
--- /dev/null
+++ b/NPLib/Detectors/BigRIPS/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_custom_command(OUTPUT TBigRIPSPPACDataDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TBigRIPSPPACData.h TBigRIPSPPACDataDict.cxx TBigRIPSPPACData.rootmap libNPBigRIPS.dylib DEPENDS TBigRIPSPPACData.h)
+
+add_custom_command(OUTPUT TBigRIPSPPACPhysicsDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TBigRIPSPPACPhysics.h TBigRIPSPPACPhysicsDict.cxx TBigRIPSPPACPhysics.rootmap libNPBigRIPS.dylib DEPENDS TBigRIPSPPACPhysics.h)
+
+add_library(NPBigRIPS SHARED TBigRIPSPPACData.cxx TBigRIPSPPACDataDict.cxx TBigRIPSPPACPhysics.cxx TBigRIPSPPACPhysicsDict.cxx)
+
+target_link_libraries(NPBigRIPS ${ROOT_LIBRARIES} NPCore NPTrackReconstruction) 
+install(FILES TBigRIPSPPACData.h TBigRIPSPPACPhysics.h  DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
+
diff --git a/NPLib/Detectors/BigRIPS/TBigRIPSPPACData.cxx b/NPLib/Detectors/BigRIPS/TBigRIPSPPACData.cxx
new file mode 100644
index 000000000..e64b1834d
--- /dev/null
+++ b/NPLib/Detectors/BigRIPS/TBigRIPSPPACData.cxx
@@ -0,0 +1,90 @@
+#include "TBigRIPSPPACData.h"
+#include <iostream>
+
+TBigRIPSPPACData::TBigRIPSPPACData(){};
+TBigRIPSPPACData::~TBigRIPSPPACData(){};
+
+/*
+void TBigRIPSPPACData::SetData(const int& FP, const int& ID, const int& Edge, const int& value,const int& VariableType){
+  fPPAC_FP.push_back(FP);
+  fPPAC_ID.push_back(ID);
+  fPPAC_Edge.push_back(Edge);
+  switch(VariableType){
+      case 0: fPPAC_TX1.push_back(value); break; 
+      case 1: fPPAC_TX2.push_back(value); break; 
+      case 2: fPPAC_TY1.push_back(value); break; 
+      case 3: fPPAC_TY2.push_back(value); break; 
+      case 4: fPPAC_TA.push_back(value); break; 
+      case 5: fPPAC_QX1.push_back(value); break; 
+      case 6: fPPAC_QX2.push_back(value); break; 
+      case 7: fPPAC_QY1.push_back(value); break; 
+      case 8: fPPAC_QY2.push_back(value); break; 
+      case 9: fPPAC_QA.push_back(value); break; 
+  }
+}
+*/
+////////////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACData::Clear(){
+ // fPPAC_FP.clear();
+ // fPPAC_ID.clear();
+ // fPPAC_Edge.clear();
+  fPPAC_TX1.clear(); 
+  fPPAC_TX2.clear(); 
+  fPPAC_TY1.clear(); 
+  fPPAC_TY2.clear();
+  fPPAC_TA.clear(); 
+  fPPAC_QX1.clear(); 
+  fPPAC_QX2.clear(); 
+  fPPAC_QY1.clear(); 
+  fPPAC_QY2.clear();
+  fPPAC_QA.clear(); 
+
+  fPPAC_TX1_ID.clear(); 
+  fPPAC_TX2_ID.clear(); 
+  fPPAC_TY1_ID.clear(); 
+  fPPAC_TY2_ID.clear();
+  fPPAC_TA_ID.clear(); 
+  fPPAC_QX1_ID.clear(); 
+  fPPAC_QX2_ID.clear(); 
+  fPPAC_QY1_ID.clear(); 
+  fPPAC_QY2_ID.clear();
+  fPPAC_QA_ID.clear(); 
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACData::Print(){
+  using namespace std;
+
+  cout << " -- Event:" << endl;
+  //cout << "   - Multiplicity: " << Mult() << endl;
+
+}
+////////////////////////////////////////////////////////////////////////////////
+/*
+unsigned int TBigRIPSPPACData::MultLayer(unsigned int det , unsigned int layer, int edge){
+  unsigned int mult=0;
+  unsigned int size = fDC_DetectorNbr.size();
+  for(unsigned int i = 0 ; i< size ; i++ ){
+    if(fDC_DetectorNbr[i]==det)
+      if(fDC_LayerNbr[i]==layer)
+        if(fDC_Edge[i]==edge && edge!=-1) // edge type is specified (0 or 1)
+          mult++;
+        else if(edge==-1)// edge type is not specified
+          mult++;
+  }
+  return mult;
+
+}
+////////////////////////////////////////////////////////////////////////////////
+std::vector<int> TBigRIPSPPACData::GetWire(unsigned int det , unsigned int layer){
+  std::vector<int> wires;
+  unsigned int size = fDC_DetectorNbr.size();
+  for(unsigned int i = 0 ; i< size ; i++ ){
+    if(fDC_DetectorNbr[i]==det)
+      if(fDC_LayerNbr[i]==layer)
+        wires.push_back(fDC_WireNbr[i]);
+  }
+  return wires;
+}
+*/
+ClassImp(TBigRIPSPPACData); 
diff --git a/NPLib/Detectors/BigRIPS/TBigRIPSPPACData.h b/NPLib/Detectors/BigRIPS/TBigRIPSPPACData.h
new file mode 100644
index 000000000..b28c0468b
--- /dev/null
+++ b/NPLib/Detectors/BigRIPS/TBigRIPSPPACData.h
@@ -0,0 +1,137 @@
+#ifndef TDCDATA_H
+#define TDCDATA_H
+#include "TObject.h"
+#include <vector>
+class TBigRIPSPPACData: public TObject{
+  public:
+    TBigRIPSPPACData();
+    ~TBigRIPSPPACData();
+
+  private:
+    //std::vector<int> fPPAC_FP; //focal plane
+    //std::vector<int> fPPAC_ID; //specific ID
+    //std::vector<int> fPPAC_Edge;
+
+    std::vector<int> fPPAC_TX1;
+    std::vector<int> fPPAC_TX2;
+    std::vector<int> fPPAC_TY1;
+    std::vector<int> fPPAC_TY2;
+    std::vector<int> fPPAC_TA;
+    std::vector<int> fPPAC_QX1;
+    std::vector<int> fPPAC_QX2;
+    std::vector<int> fPPAC_QY1;
+    std::vector<int> fPPAC_QY2;
+    std::vector<int> fPPAC_QA;
+
+    std::vector<int> fPPAC_TX1_ID;
+    std::vector<int> fPPAC_TX2_ID;
+    std::vector<int> fPPAC_TY1_ID;
+    std::vector<int> fPPAC_TY2_ID;
+    std::vector<int> fPPAC_TA_ID;
+    std::vector<int> fPPAC_QX1_ID;
+    std::vector<int> fPPAC_QX2_ID;
+    std::vector<int> fPPAC_QY1_ID;
+    std::vector<int> fPPAC_QY2_ID;
+    std::vector<int> fPPAC_QA_ID;
+
+/*
+    enum ChannelType{
+        TX1,
+        TX2,
+        TY1,
+        TY2,
+        TA,
+        QX1,
+        QX2,
+        QY1,
+        QY2,
+        QA
+    };//should match with the Channel Type define in Unpacker 
+  */
+
+  public:
+    void Clear();
+    void Print();
+    void Clear(const Option_t*) {};
+    void Dump() const{};
+  
+  public:
+    //void SetData(const int& FP, const int& ID, const int& Edge, const int& Value,const int& VariableType);
+
+    //unsigned int Mult(){return fPPAC_DetectorNbr.size();};
+    //unsigned int MultLayer(unsigned int det , unsigned int layer, int edge=-1);
+    //int const GetID(const unsigned int& i){return fPPAC_ID[i];};
+    //int const GetFP(const unsigned int& i){return fPPAC_FP[i];};
+    //int const GetEdge(const unsigned int& i){return fPPAC_Edge[i];};
+    /*
+    double const GetTX2(const unsigned int& i){return fPPAC_TX2[i];};
+    double const GetTY1(const unsigned int& i){return fPPAC_TY1[i];};
+    double const GetTY2(const unsigned int& i){return fPPAC_TY2[i];};
+    double const GetTA(const unsigned int& i){return fPPAC_TA[i];};
+    double const GetQX1(const unsigned int& i){return fPPAC_QX1[i];};
+    double const GetQX2(const unsigned int& i){return fPPAC_QX2[i];};
+    double const GetQY1(const unsigned int& i){return fPPAC_QY1[i];};
+    double const GetQY2(const unsigned int& i){return fPPAC_QY2[i];};
+    double const GetQA(const unsigned int& i){return fPPAC_QA[i];};
+*/
+
+    //void SetID(const int& i){fPPAC_ID.push_back(i);}
+    //void SetFP(const int& i){fPPAC_FP.push_back(i);}
+    //void SetEdge(const int& i){fPPAC_Edge.push_back(i);}
+    void SetTX1(const int& T, const int& ID){fPPAC_TX1.push_back(T);fPPAC_TX1_ID.push_back(ID);}
+    void SetTX2(const int& T, const int& ID){fPPAC_TX2.push_back(T);fPPAC_TX2_ID.push_back(ID);}
+    void SetTY1(const int& T, const int& ID){fPPAC_TY1.push_back(T);fPPAC_TY1_ID.push_back(ID);}
+    void SetTY2(const int& T, const int& ID){fPPAC_TY2.push_back(T);fPPAC_TY2_ID.push_back(ID);}
+    void SetTA(const int& T, const int& ID){fPPAC_TA.push_back(T);fPPAC_TA_ID.push_back(ID);}
+
+    void SetQX1(const int& Q, const int& ID){fPPAC_QX1.push_back(Q);fPPAC_TX1_ID.push_back(ID);}
+    void SetQX2(const int& Q, const int& ID){fPPAC_QX2.push_back(Q);fPPAC_TX2_ID.push_back(ID);}
+    void SetQY1(const int& Q, const int& ID){fPPAC_QY1.push_back(Q);fPPAC_TY1_ID.push_back(ID);}
+    void SetQY2(const int& Q, const int& ID){fPPAC_QY2.push_back(Q);fPPAC_TY2_ID.push_back(ID);}
+    void SetQA(const int& Q, const int& ID){fPPAC_QA.push_back(Q);fPPAC_TA_ID.push_back(ID);}
+
+
+    int GetTX1Mult() const {return fPPAC_TX1_ID.size();}
+    int const GetTX1(const unsigned int& i){return fPPAC_TX1[i];};
+    int const GetTX1ID(const unsigned int& i){return fPPAC_TX1_ID[i];};
+
+    int GetTX2Mult() const {return fPPAC_TX2_ID.size();}
+    int const GetTX2(const unsigned int& i){return fPPAC_TX2[i];};
+    int const GetTX2ID(const unsigned int& i){return fPPAC_TX2_ID[i];};
+
+    int GetTY1Mult() const {return fPPAC_TY1_ID.size();}
+    int const GetTY1(const unsigned int& i){return fPPAC_TY1[i];};
+    int const GetTY1ID(const unsigned int& i){return fPPAC_TY1_ID[i];};
+
+    int GetTY2Mult() const {return fPPAC_TY2_ID.size();}
+    int const GetTY2(const unsigned int& i){return fPPAC_TY2[i];};
+    int const GetTY2ID(const unsigned int& i){return fPPAC_TY2_ID[i];};
+
+    int GetTAMult() const {return fPPAC_TA_ID.size();}
+    int const GetTA(const unsigned int& i){return fPPAC_TA[i];};
+    int const GetTAID(const unsigned int& i){return fPPAC_TA_ID[i];};
+
+    int GetQX1Mult() const {return fPPAC_QX1_ID.size();}
+    int const GetQX1(const unsigned int& i){return fPPAC_QX1[i];};
+    int const GetQX1ID(const unsigned int& i){return fPPAC_QX1_ID[i];};
+
+    int GetQX2Mult() const {return fPPAC_QX2_ID.size();}
+    int const GetQX2(const unsigned int& i){return fPPAC_QX2[i];};
+    int const GetQX2ID(const unsigned int& i){return fPPAC_QX2_ID[i];};
+
+    int GetQY1Mult() const {return fPPAC_QY1_ID.size();}
+    int const GetQY1(const unsigned int& i){return fPPAC_QY1[i];};
+    int const GetQY1ID(const unsigned int& i){return fPPAC_QY1_ID[i];};
+
+    int GetQY2Mult() const {return fPPAC_QY2_ID.size();}
+    int const GetQY2(const unsigned int& i){return fPPAC_QY2[i];};
+    int const GetQY2ID(const unsigned int& i){return fPPAC_QY2_ID[i];};
+
+    int GetQAMult() const {return fPPAC_QA_ID.size();}
+    int const GetQA(const unsigned int& i){return fPPAC_QA[i];};
+    int const GetQAID(const unsigned int& i){return fPPAC_QA_ID[i];};
+
+    ClassDef(TBigRIPSPPACData,1); 
+};
+
+#endif
diff --git a/NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.cxx b/NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.cxx
new file mode 100644
index 000000000..5aa87730c
--- /dev/null
+++ b/NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.cxx
@@ -0,0 +1,405 @@
+/*****************************************************************************
+ * 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: F, Flavigny   contact address: flavigny@lpccaen.in2p3.fr *
+ *                                                                           *
+ * Creation Date  : April 2021                                               *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold RIBF PPAC treated data                                   *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *****************************************************************************/
+#include "TBigRIPSPPACPhysics.h"
+
+//   STL
+#include <sstream>
+#include <iostream>
+#include <cmath>
+#include <stdlib.h>
+#include <limits>
+
+//   NPL
+#include "RootInput.h"
+#include "RootOutput.h"
+#include "TAsciiFile.h"
+#include "NPOptionManager.h"
+#include "NPDetectorFactory.h"
+#include "NPSystemOfUnits.h"
+//   ROOT
+using namespace NPUNITS;
+///////////////////////////////////////////////////////////////////////////
+
+ClassImp(TBigRIPSPPACPhysics)
+  ///////////////////////////////////////////////////////////////////////////
+  TBigRIPSPPACPhysics::TBigRIPSPPACPhysics(){
+    m_EventData         = new TBigRIPSPPACData ;
+    m_PreTreatedData    = new TBigRIPSPPACData ;
+    m_EventPhysics      = this ;
+    //m_Spectra           = NULL;
+  }
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::BuildSimplePhysicalEvent(){
+  BuildPhysicalEvent();
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::BuildPhysicalEvent(){
+  PreTreat();
+  return;
+}
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::PreTreat(){
+
+  ClearPreTreatedData();
+
+  //static map<std::pair<int,int>, std::vector<int> > data ; 
+  static map<int, BigRIPSPPACVariables > Fdata ; 
+  //static map<std::pair<int,int>, bool > multiHit ; 
+
+  //pair of detector ID and variable type (TX1,TX2,TY1,TY2,TA)=(0,1,2,3,4)
+  std::pair<unsigned int, double> pair_id_type; 
+  int id, TimeRaw;
+
+  //pair_id_type.second = 0; //TX1
+  unsigned int sizeTX1 = m_EventData->GetTX1Mult();
+  for(unsigned int i = 0 ; i < sizeTX1 ; i++){
+        id = m_EventData->GetTX1ID(i);
+        TimeRaw = m_EventData->GetTX1(i);
+        if(TimeRaw>RawLowerLimit[id] && TimeRaw<RawUpperLimit[id]){
+/*
+            pair_id_type.first = id;
+            if(data[pair_id_type].size()==0){
+                data[pair_id_type].push_back(TimeRaw); 
+            }else {
+                multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+*/
+            if(Fdata[id].FTX1.size()==0){
+                Fdata[id].FTX1.push_back(TimeRaw*ch2ns_TX1[id]); 
+            }else {
+               // multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+        }
+  }
+
+//  pair_id_type.second = 1; //TX2
+  unsigned int sizeTX2 = m_EventData->GetTX2Mult();
+  for(unsigned int i = 0 ; i < sizeTX2 ; i++){
+        id = m_EventData->GetTX2ID(i);
+        TimeRaw = m_EventData->GetTX2(i);
+        if(TimeRaw>RawLowerLimit[id] && TimeRaw<RawUpperLimit[id]){
+/*
+            pair_id_type.first = id;
+            if(data[pair_id_type].size()==0){
+                data[pair_id_type].push_back(TimeRaw); 
+            }else {
+                multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+*/
+            if(Fdata[id].FTX2.size()==0){
+                Fdata[id].FTX2.push_back(TimeRaw*ch2ns_TX2[id]); 
+            }else {
+               // multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+        }
+  }
+
+//  pair_id_type.second = 2; //TY1
+  unsigned int sizeTY1 = m_EventData->GetTY1Mult();
+  for(unsigned int i = 0 ; i < sizeTY1 ; i++){
+        id = m_EventData->GetTY1ID(i);
+        TimeRaw = m_EventData->GetTY1(i);
+        if(TimeRaw>RawLowerLimit[id] && TimeRaw<RawUpperLimit[id]){
+/*
+            pair_id_type.first = id;
+            if(data[pair_id_type].size()==0){
+                data[pair_id_type].push_back(TimeRaw); 
+            }else {
+                multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+*/
+            if(Fdata[id].FTY1.size()==0){
+                Fdata[id].FTY1.push_back(TimeRaw*ch2ns_TY1[id]); 
+            }else {
+               // multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+        }
+  }
+
+// pair_id_type.second = 3; //TY2
+  unsigned int sizeTY2 = m_EventData->GetTY2Mult();
+  for(unsigned int i = 0 ; i < sizeTY2 ; i++){
+        id = m_EventData->GetTY2ID(i);
+        TimeRaw = m_EventData->GetTY2(i);
+        if(TimeRaw>RawLowerLimit[id] && TimeRaw<RawUpperLimit[id]){
+/*
+            pair_id_type.first = id;
+            if(data[pair_id_type].size()==0){
+                data[pair_id_type].push_back(TimeRaw); 
+            }else {
+                multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+*/
+            if(Fdata[id].FTY2.size()==0){
+                Fdata[id].FTY2.push_back(TimeRaw*ch2ns_TY2[id]); 
+            }else {
+               // multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+        }
+  }
+
+// pair_id_type.second = 4; //TA
+  unsigned int sizeTA = m_EventData->GetTAMult();
+  for(unsigned int i = 0 ; i < sizeTA ; i++){
+        id = m_EventData->GetTAID(i);
+        TimeRaw = m_EventData->GetTA(i);
+        if(TimeRaw>RawLowerLimit[id] && TimeRaw<RawUpperLimit[id]){
+/*
+            pair_id_type.first = id;
+            if(data[pair_id_type].size()==0){
+                data[pair_id_type].push_back(TimeRaw); 
+            }else {
+                multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+*/
+            if(Fdata[id].FTA.size()==0){
+                Fdata[id].FTA.push_back(TimeRaw*ch2ns_TA[id]); 
+            }else {
+               // multiHit[pair_id_type]=true; //multiple value for same TDC ch.
+            }
+
+        }
+  }
+
+/*  
+  for(auto it = data.begin();it!=data.end();++it){
+    pair_id_type = it->first;
+    cout<< "ID:"<<pair_id_type.first<<"\tType:"<<pair_id_type.second<<" \tT:"<<data[pair_id_type][0]<<endl; 
+  }
+*/
+  int j=0;
+    BigRIPSPPACVariables toto;
+  for(auto it = Fdata.begin();it!=Fdata.end();++it){
+    id = it->first;
+    ID.push_back(id);
+    FP.push_back(FPL[id]);
+    toto.Clear();
+    toto = it->second;
+    //cout<< "ID:"<<id<<endl;
+    //cout<< "ch2nsX1:"<<ch2ns_TX1[id]<<endl;
+    //cout<< "ch2nsX2:"<<ch2ns_TX2[id]<<endl;
+    //cout<< "ch2nsY1:"<<ch2ns_TY1[id]<<endl;
+    //cout<< "ch2nsY2:"<<ch2ns_TY2[id]<<endl;
+    //cout<< "ch2nsA:"<<ch2ns_TA[id]<<endl;
+    //toto.Print(); 
+    for (int i=0; i<toto.FTX1.size(); i++) TX1.push_back(toto.FTX1[i]);
+    for (int i=0; i<toto.FTX2.size(); i++) TX2.push_back(toto.FTX2[i]);
+    for (int i=0; i<toto.FTY1.size(); i++) TY1.push_back(toto.FTY1[i]);
+    for (int i=0; i<toto.FTY2.size(); i++) TY2.push_back(toto.FTY2[i]);
+    for (int i=0; i<toto.FTA.size(); i++) TA.push_back(toto.FTA[i]);
+    //TX1=toto.FTX1;
+    //TX2=toto.FTX2;
+    //TY1=toto.FTY1;
+    //TY2=toto.FTY2;
+    //TA=toto.FTA;
+
+    //if(toto.HasTXs()) {TDiffX.push_back(TX1[j]-TX2[j]);}
+    if(toto.HasTXs()) {TDiffX.push_back(toto.FTX1[0]-toto.FTX2[0]);}
+    else {TDiffX.push_back(-99999);}
+    //if(toto.HasTXs() && toto.HasTA()) {TSumX.push_back(TX1[j]+TX2[j]-2*TA[j]);}
+    if(toto.HasTXs() && toto.HasTA()) {TSumX.push_back(toto.FTX1[0]+toto.FTX2[0]-2*toto.FTA[0]);}
+    else {TSumX.push_back(-99999);}
+    //if(toto.HasTYs()) {TDiffY.push_back(TY1[j]-TY2[j]);}
+    if(toto.HasTYs()) {TDiffY.push_back(toto.FTY1[0]-toto.FTY2[0]);}
+    else {TDiffY.push_back(-99999);}
+    //if(toto.HasTYs() && toto.HasTA()) {TSumY.push_back(TY1[j]+TY2[j]-2*TA[j]);}
+    if(toto.HasTYs() && toto.HasTA()) {TSumY.push_back(toto.FTY1[0]+toto.FTY2[0]-2*toto.FTA[0]);}
+    else {TSumY.push_back(-99999);}
+    j++;
+  }
+  //Print(); 
+  Fdata.clear();
+
+  return;
+}
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::Clear(){
+    TX1.clear();
+    TX2.clear();
+    TY1.clear();
+    TY2.clear();
+    TA.clear();
+    TSumX.clear();
+    TDiffX.clear();
+    TSumY.clear();
+    TDiffY.clear();
+    ID.clear();
+    FP.clear();
+    //Data.clear();
+}
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::Print(){
+    cout << "XXXXXXXXXXXXXXXXXXXXXXXX PPAC Physics Event XXXXXXXXXXXXXXXXX" << endl;
+    cout << "TX1_Mult = " << TX1.size();
+    for (UShort_t i = 0; i < TX1.size(); i++){cout << "\tTX1: " << TX1[i] << endl;}
+    cout << "TX2_Mult = " << TX2.size();
+    for (UShort_t i = 0; i < TX2.size(); i++){cout << "\tTX2: " << TX2[i] << endl;}
+    cout << "TY1_Mult = " << TY1.size();
+    for (UShort_t i = 0; i < TY1.size(); i++){cout << "\tTY1: " << TY1[i] << endl;}
+    cout << "TY2_Mult = " << TY2.size();
+    for (UShort_t i = 0; i < TY2.size(); i++){cout << "\tTY2: " << TY2[i] << endl;}
+    cout << "TA_Mult = " << TA.size();
+    for (UShort_t i = 0; i < TA.size(); i++){cout << "\tTA: " << TA[i] << endl;}
+    cout << "TDiffX_Mult = " << TDiffX.size();
+    for (UShort_t i = 0; i < TDiffX.size(); i++){cout << "\tTDiffX: " << TDiffX[i] << endl;}
+    cout << "TDiffY_Mult = " << TDiffY.size();
+    for (UShort_t i = 0; i < TDiffY.size(); i++){cout << "\tTDiffY: " << TDiffY[i] << endl;}
+    cout << "TSumX_Mult = " << TSumX.size();
+    for (UShort_t i = 0; i < TSumX.size(); i++){cout << "\tTSumX: " << TSumX[i] << endl;}
+    cout << "TSumY_Mult = " << TSumY.size();
+    for (UShort_t i = 0; i < TSumY.size(); i++){cout << "\tTSumY: " << TSumY[i] << endl;}
+}
+///////////////////////////////////////////////////////////////////////////
+
+////   Innherited from VDetector Class   ////
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::ReadConfiguration(NPL::InputParser parser){
+  vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("BigRIPSPPAC");
+  if(NPOptionManager::getInstance()->GetVerboseLevel())
+    cout << "//// " << blocks.size() << " PPAC detector file found " << endl; 
+
+  vector<string> token= {"XML"};
+
+  for(unsigned int i = 0 ; i < blocks.size() ; i++){
+    cout << endl << "////  BigRIPSPPAC file (" << i+1 << ")" << endl;
+    string xmlpath = blocks[i]->GetString("XML");
+    NPL::XmlParser xml;
+    xml.LoadFile(xmlpath);
+    AddPPACs("BigRIPSPPAC",xml);
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::AddPPACs(string name, NPL::XmlParser& xml){
+  std::vector<NPL::XML::block*> b = xml.GetAllBlocksWithName(name);  
+
+  if(name=="BigRIPSPPAC"){
+    unsigned int size = b.size();
+    for(unsigned int i = 0 ; i < size ; i++){
+      unsigned int ID = b[i]->AsInt("ID"); 
+      //string sDir = b[i]->AsString("anodedir");
+      RawLowerLimit[ID] = b[i]->AsInt("tdc_underflow"); 
+      RawUpperLimit[ID] = b[i]->AsInt("tdc_overflow"); 
+      FPL[ID] = b[i]->AsInt("FPL"); 
+      ch2ns_TX1[ID] = b[i]->AsDouble("x1_ch2ns"); 
+      ch2ns_TX2[ID] = b[i]->AsDouble("x2_ch2ns"); 
+      ch2ns_TY1[ID] = b[i]->AsDouble("y1_ch2ns"); 
+      ch2ns_TY2[ID] = b[i]->AsDouble("y2_ch2ns"); 
+      ch2ns_TA[ID] = b[i]->AsDouble("a_ch2ns"); 
+    }
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::InitSpectra(){  
+  //m_Spectra = new TBigRIPSPPACSpectra(m_NumberOfDetector);
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::FillSpectra(){  
+  //  m_Spectra -> FillRawSpectra(m_EventData);
+  //  m_Spectra -> FillPreTreatedSpectra(m_PreTreatedData);
+  //  m_Spectra -> FillPhysicsSpectra(m_EventPhysics);
+}
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::CheckSpectra(){  
+  //  m_Spectra->CheckSpectra();  
+}
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::ClearSpectra(){  
+  // To be done
+}
+///////////////////////////////////////////////////////////////////////////
+map< string , TH1*> TBigRIPSPPACPhysics::GetSpectra() {
+  /*  if(m_Spectra)
+      return m_Spectra->GetMapHisto();
+      else{
+      map< string , TH1*> empty;
+      return empty;
+      }*/
+  map< string , TH1*> empty;
+  return empty;
+
+} 
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::WriteSpectra(){
+  // m_Spectra->WriteSpectra();
+}
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::AddParameterToCalibrationManager(){
+  //CalibrationManager* Cal = CalibrationManager::getInstance();
+
+  // each layer
+  //for( int l = 0 ; l < 14 ; ++l){
+  //  Cal->AddParameter("SamuraiFDC2", "L"+ NPL::itoa(l),"FDC2_L"+ NPL::itoa(l));
+  //}
+
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::InitializeRootInputRaw(){
+  TChain* inputChain = RootInput::getInstance()->GetChain()   ;
+  inputChain->SetBranchStatus( "BigRIPSPPAC" , true );
+  // The following line is necessary only for system were the tree is splitted
+  // (older root version). The found argument silenced the Branches not found
+  // warning for non splitted tree.
+  if(inputChain->FindBranch("fPPAC_*"))
+    inputChain->SetBranchStatus( "fPPAC_*",true);
+  inputChain->SetBranchAddress( "BigRIPSPPAC" , &m_EventData );
+
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::InitializeRootInputPhysics(){
+}
+
+///////////////////////////////////////////////////////////////////////////
+void TBigRIPSPPACPhysics::InitializeRootOutput(){
+  TTree* outputTree = RootOutput::getInstance()->GetTree();
+  outputTree->Branch( "PPAC" , "TBigRIPSPPACPhysics" , &m_EventPhysics );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//            Construct Method to be pass to the DetectorFactory              //
+////////////////////////////////////////////////////////////////////////////////
+NPL::VDetector* TBigRIPSPPACPhysics::Construct(){
+  return (NPL::VDetector*) new TBigRIPSPPACPhysics();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//            Registering the construct method to the factory                 //
+////////////////////////////////////////////////////////////////////////////////
+extern "C"{
+  class proxy_bigripsPPAC{
+    public:
+      proxy_bigripsPPAC(){
+        NPL::DetectorFactory::getInstance()->AddToken("BigRIPSPPAC","BigRIPS");
+        NPL::DetectorFactory::getInstance()->AddDetector("BigRIPSPPAC",TBigRIPSPPACPhysics::Construct);
+      }
+  };
+
+  proxy_bigripsPPAC p_bigripsPPAC;
+}
+
diff --git a/NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.h b/NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.h
new file mode 100644
index 000000000..1396f8947
--- /dev/null
+++ b/NPLib/Detectors/BigRIPS/TBigRIPSPPACPhysics.h
@@ -0,0 +1,162 @@
+#ifndef TBIGRIPSPPACPHYSICS_H
+#define TBIGRIPSPPACPHYSICS_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: Adrien MATTA  contact address: matta@lpccaen.in2p3.fr    *
+ *                                                                           *
+ * Creation Date  : October 2020                                             *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ *  This class hold SamuraiFDC2 treated data                                 *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *  
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+// STL
+#include <vector>
+#include <map>
+
+// NPL
+#include "TBigRIPSPPACData.h"
+#include "BigRIPSPPACVariables.h"
+//#include "TBigRIPSPPACSpectra.h"
+#include "NPCalibrationManager.h"
+#include "NPVDetector.h"
+#include "NPInputParser.h"
+#include "NPXmlParser.h"
+#include "NPDCReconstruction.h"
+// ROOT 
+#include "TVector3.h" 
+// Forward declaration
+//class TBigRIPSPPACSpectra;
+
+
+using namespace std ;
+
+class TBigRIPSPPACPhysics : public TObject, public NPL::VDetector{
+  public:
+    TBigRIPSPPACPhysics();
+    ~TBigRIPSPPACPhysics() {};
+
+  public: 
+    void Clear();   
+    void Clear(const Option_t*) {};
+    void Print();   
+
+  public:
+    std::vector<double> TX1;
+    std::vector<double> TX2;
+    std::vector<double> TY1;
+    std::vector<double> TY2;
+    std::vector<double> TA;
+    std::vector<double> TSumX;
+    std::vector<double> TDiffX;
+    std::vector<double> TSumY;
+    std::vector<double> TDiffY;
+    std::vector<int> ID;
+    std::vector<int> FP;
+    //map<int,vector<double>> Data ;
+
+    int PileUp;
+
+  public:
+    // Projected position at given Z plan
+    TVector3 ProjectedPosition(double Z);
+
+  private: // Xml file read to add PPACs and their parameters 
+    void AddPPACs(string name, NPL::XmlParser&);//! take the XML file and fill in parameters of each PPAC
+    map<int,double> RawUpperLimit;//! Upper Value of TDC range considered for a PPAC
+    map<int,double> RawLowerLimit;//! Lower Value of TDC range considered for a PPAC 
+    map<int,double> FPL;//! Focal plane where the PPAC is located
+    map<int,double> ch2ns_TX1; 
+    map<int,double> ch2ns_TX2; 
+    map<int,double> ch2ns_TY1; 
+    map<int,double> ch2ns_TY2; 
+    map<int,double> ch2ns_TA;
+  
+  public: //   Innherited from VDetector Class
+
+    // Read stream at ConfigFile to pick-up parameters of detector (Position,...) using Token
+    void ReadConfiguration(NPL::InputParser) ;
+
+    // Add Parameter to the CalibrationManger
+    void AddParameterToCalibrationManager() ;      
+
+    // Activated associated Branches and link it to the private member DetectorData address
+    // In this method mother Branches (Detector) AND daughter leaf (fDetector_parameter) have to be activated
+    void InitializeRootInputRaw() ;
+
+    // Activated associated Branches and link it to the private member DetectorPhysics address
+    // In this method mother Branches (Detector) AND daughter leaf (parameter) have to be activated
+    void InitializeRootInputPhysics() ;
+
+    // Create associated branches and associated private member DetectorPhysics address
+    void InitializeRootOutput() ;
+
+    // This method is called at each event read from the Input Tree. Aime is to build treat Raw dat in order to extract physical parameter. 
+    void BuildPhysicalEvent() ;
+
+    // Same as above, but only the simplest event and/or simple method are used (low multiplicity, faster algorythm but less efficient ...).
+    // This method aimed to be used for analysis performed during experiment, when speed is requiered.
+    // NB: This method can eventually be the same as BuildPhysicalEvent.
+    void BuildSimplePhysicalEvent() ;
+
+    // Same as above but for online analysis
+    void BuildOnlinePhysicalEvent()  {BuildPhysicalEvent();};
+
+    // Those two method all to clear the Event Physics or Data
+    void ClearEventPhysics() {Clear();}      
+    void ClearEventData()    {m_EventData->Clear();}   
+
+    // Method related to the TSpectra classes, aimed at providing a framework for online applications
+    // Instantiate the Spectra class and the histogramm throught it
+    void InitSpectra();
+    // Fill the spectra hold by the spectra class
+    void FillSpectra();
+    // Used for Online mainly, perform check on the histo and for example change their color if issues are found
+    void CheckSpectra();
+    // Used for Online only, clear all the spectra hold by the Spectra class
+    void ClearSpectra();
+    // Write Spectra to file
+    void WriteSpectra();
+
+  public:      //   Specific to SamuraiFDC2 Array
+
+    //   Clear The PreTeated object
+    void ClearPreTreatedData()   {m_PreTreatedData->Clear();}
+
+    //   Remove bad channel, calibrate the data and apply threshold
+    void PreTreat();
+
+    // Retrieve raw and pre-treated data
+    TBigRIPSPPACData* GetRawData()        const {return m_EventData;}
+    TBigRIPSPPACData* GetPreTreatedData() const {return m_PreTreatedData;}
+
+  private:   //   Root Input and Output tree classes
+    TBigRIPSPPACData*         m_EventData;//!
+    TBigRIPSPPACData*         m_PreTreatedData;//!
+    TBigRIPSPPACPhysics*      m_EventPhysics;//!
+
+
+  private: // Spectra Class
+   // TBigRIPSPPACSpectra* m_Spectra; // !
+
+  public: // Spectra Getter
+    map< string , TH1*> GetSpectra(); 
+
+  public: // Static constructor to be passed to the Detector Factory
+    static NPL::VDetector* Construct();
+    ClassDef(TBigRIPSPPACPhysics,1)  // BigRIPSPPACPhysics structure
+};
+
+#endif
-- 
GitLab