From 6f65eace3c06874135d0179ee5aac6fccf7c09df Mon Sep 17 00:00:00 2001
From: adrien-matta <a.matta@surrey.ac.uk>
Date: Tue, 22 Apr 2014 15:48:43 +0100
Subject: [PATCH] * Adding Riken data file to NPL

---
 NPLib/Physics/NPFunction.cxx | 20 +++++++-
 NPLib/Physics/NPReaction.cxx | 17 ++++++-
 NPLib/Riken/Makefile         | 42 +++++++++++++++++
 NPLib/Riken/TRIPSData.cxx    | 45 ++++++++++++++++++
 NPLib/Riken/TRIPSData.h      | 90 ++++++++++++++++++++++++++++++++++++
 5 files changed, 210 insertions(+), 4 deletions(-)
 create mode 100755 NPLib/Riken/Makefile
 create mode 100755 NPLib/Riken/TRIPSData.cxx
 create mode 100755 NPLib/Riken/TRIPSData.h

diff --git a/NPLib/Physics/NPFunction.cxx b/NPLib/Physics/NPFunction.cxx
index 13acc62e5..42d72f9c4 100644
--- a/NPLib/Physics/NPFunction.cxx
+++ b/NPLib/Physics/NPFunction.cxx
@@ -201,8 +201,24 @@ bool OpenASCIIorROOTFile(string filename, ifstream &ASCII , TFile &ROOT){
   }
   
   else {
-    ROOT.Open(filename.c_str(),"READ");
-    return false;
+    if(ROOT.Open(filename.c_str(),"READ")){
+      return false;
+    }
+  
+    else{
+      
+      cout << 1 << endl;
+      if(ROOT.Open(StandardPath.c_str(),"READ")){
+        cout << 2 << endl;
+        return false;
+      }
+      else{
+        cout << 3 << endl;
+        cout << "Error, file " << StandardPath << " not found " << endl ;
+        exit(1);
+      }
+    }
+    
   }
   
 }
diff --git a/NPLib/Physics/NPReaction.cxx b/NPLib/Physics/NPReaction.cxx
index db4c8db32..b67f2ccc6 100644
--- a/NPLib/Physics/NPReaction.cxx
+++ b/NPLib/Physics/NPReaction.cxx
@@ -210,8 +210,21 @@ double Reaction::ShootRandomThetaCM(){
   if(fDoubleDifferentialCrossSectionHist){
     // Take a slice in energy
     TAxis* Y = fDoubleDifferentialCrossSectionHist->GetYaxis();
-    TH1D* Proj = fDoubleDifferentialCrossSectionHist
-          ->ProjectionY("proj",Y->FindBin(fBeamEnergy),Y->FindBin(fBeamEnergy));
+    int binY;
+      
+    // Those test are there for the tail event of the energy distribution
+    // In case the energy is outside the range of the 2D histo we take the 
+    // closest availabile CS
+    if(Y->FindBin(fBeamEnergy) > Y->GetLast())
+      binY = Y->GetLast()-1;
+
+    else if(Y->FindBin(fBeamEnergy) < Y->GetFirst())
+      binY = Y->GetFirst();
+
+    else
+      binY = Y->FindBin(fBeamEnergy);
+
+    TH1D* Proj = fDoubleDifferentialCrossSectionHist->ProjectionX("proj",binY,binY);
     SetThetaCM( theta=Proj->GetRandom()*deg );
    }
   else
diff --git a/NPLib/Riken/Makefile b/NPLib/Riken/Makefile
new file mode 100755
index 000000000..f36d3d182
--- /dev/null
+++ b/NPLib/Riken/Makefile
@@ -0,0 +1,42 @@
+include ../Makefile.arch
+
+#------------------------------------------------------------------------------
+SHARELIB      =  libRIPSData.so 
+
+all:            $(SHARELIB)
+#------------------------------------------------------------------------------
+############### Detector ##############
+
+## RIPS ##
+libRIPSData.so:	TRIPSData.o	TRIPSDataDict.o
+			$(LD) $(SOFLAGS) $^ $(OutPutOpt) $@
+
+TRIPSDataDict.cxx:	TRIPSData.h
+			rootcint -f $@ -c $^
+
+#libRIPSPhysics.so:	TRIPSPhysics.o	TRIPSPhysicsDict.o
+#			$(LD) $(SOFLAGS) $^ $(OutPutOpt) $@
+
+#TRIPSPhysicsDict.cxx:	TRIPSPhysics.h
+#			rootcint -f $@ -c $^
+
+# dependances
+TRIPSData.o:	TRIPSData.cxx	TRIPSData.h
+#TRIPSPhysics.o:	TRIPSPhysics.cxx	TRIPSPhysics.h
+#######################################
+
+############# Clean and More ##########
+clean:
+	@rm -f core *~ *.o *Dict*
+
+distclean:
+	  make clean; rm -f *.so
+
+.SUFFIXES: .$(SrcSuf)
+
+###
+
+.$(SrcSuf).$(ObjSuf):
+	$(CXX) $(CXXFLAGS) $(INCLUDE) -c $<
+
+
diff --git a/NPLib/Riken/TRIPSData.cxx b/NPLib/Riken/TRIPSData.cxx
new file mode 100755
index 000000000..ce4b8a187
--- /dev/null
+++ b/NPLib/Riken/TRIPSData.cxx
@@ -0,0 +1,45 @@
+#include <iostream>
+#include "TRIPSData.h"
+
+
+ClassImp(TRIPSData)
+
+TRIPSData::TRIPSData()
+{
+}
+
+
+
+TRIPSData::~TRIPSData()
+{
+}
+
+
+
+void TRIPSData::Clear()
+{
+   RunNumber = -1 ;
+   EventNumber = -1;
+
+   fRIPS_PPAC_N.clear();
+   fRIPS_PPAC_X.clear();
+   fRIPS_PPAC_Y.clear();
+   fRIPS_PPAC_T.clear();
+   
+   fRIPS_Plastic_N.clear();
+   fRIPS_Plastic_E.clear();
+   fRIPS_Plastic_EL.clear();
+   fRIPS_Plastic_ER.clear();
+   fRIPS_Plastic_TL.clear();
+   fRIPS_Plastic_TR.clear();
+   
+   fRIPS_RF_N.clear();
+   fRIPS_RF_T.clear();
+}
+
+
+
+void TRIPSData::Dump() const
+{
+   cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event XXXXXXXXXXXXXXXXX" << endl;
+}
diff --git a/NPLib/Riken/TRIPSData.h b/NPLib/Riken/TRIPSData.h
new file mode 100755
index 000000000..c665d3ffe
--- /dev/null
+++ b/NPLib/Riken/TRIPSData.h
@@ -0,0 +1,90 @@
+#ifndef __RIPSDATA__
+#define __RIPSDATA__
+
+#include <vector>
+#include <iostream>
+#include "TObject.h"
+using namespace std ;
+
+class TRIPSData : public TObject {
+ private:
+ 
+   // PPAC
+   int RunNumber;
+   int EventNumber;
+   vector<int>    fRIPS_PPAC_N;
+   vector<double> fRIPS_PPAC_X;
+   vector<double> fRIPS_PPAC_Y;
+   vector<double> fRIPS_PPAC_T;
+   
+   // Plastic
+   vector<int>    fRIPS_Plastic_N;
+   vector<double> fRIPS_Plastic_E;
+   vector<double> fRIPS_Plastic_EL;
+   vector<double> fRIPS_Plastic_ER;
+   vector<double> fRIPS_Plastic_TL;
+   vector<double> fRIPS_Plastic_TR;
+   
+   // RF
+   vector<int>    fRIPS_RF_N;
+   vector<double> fRIPS_RF_T;
+   
+ public:
+   TRIPSData();
+   virtual ~TRIPSData();
+
+   void   Clear();
+   void   Clear(const Option_t*) {};
+   void   Dump() const;
+
+   /////////////////////           GETTERS           ////////////////////////
+   int GetRunNumber()   {return RunNumber;}
+   int GetEventNumber() {return EventNumber;}
+   
+   // PPAC
+   int      GetMultPPAC()    {return fRIPS_PPAC_N.size();}
+   int      GetPPACN(int i)  {return fRIPS_PPAC_N[i];}
+   double   GetPPACX(int i)  {return fRIPS_PPAC_X[i];}
+   double   GetPPACY(int i)  {return fRIPS_PPAC_Y[i];}
+   double   GetPPACT(int i)  {return fRIPS_PPAC_T[i];}
+   
+   // Plastic
+   int      GetMultPlastic()     {return fRIPS_Plastic_N.size();}
+   int      GetPlasticN(int i)   {return fRIPS_Plastic_N[i];}
+   double   GetPlasticE(int i)   {return fRIPS_Plastic_E[i];}
+   double   GetPlasticER(int i)  {return fRIPS_Plastic_ER[i];}
+   double   GetPlasticEL(int i)  {return fRIPS_Plastic_EL[i];}
+   double   GetPlasticTL(int i)  {return fRIPS_Plastic_TL[i];}
+   double   GetPlasticTR(int i)  {return fRIPS_Plastic_TR[i];}
+   
+   // RF
+   int      GetMultRF()     {return fRIPS_RF_N.size();}
+   double   GetRFN(int i)   {return fRIPS_RF_N[i];}
+   double   GetRFT(int i)   {return fRIPS_RF_T[i];}
+   
+   /////////////////////           SETTERS           ////////////////////////
+   void  SetRunNumber(int value)   {RunNumber=value;}
+   void  SetEventNumber(int value) {EventNumber=value;}
+   
+   // PPAC
+   void  SetPPACN(int value)     {fRIPS_PPAC_N.push_back(value);}
+   void  SetPPACX(double value)  {fRIPS_PPAC_X.push_back(value);}
+   void  SetPPACY(double value)  {fRIPS_PPAC_Y.push_back(value);}
+   void  SetPPACT(double value)  {fRIPS_PPAC_T.push_back(value);}
+   
+   // Plastic
+   void  SetPlasticN(int value)      {fRIPS_Plastic_N.push_back(value);}
+   void  SetPlasticE(double value)   {fRIPS_Plastic_E.push_back(value);}
+   void  SetPlasticER(double value)  {fRIPS_Plastic_ER.push_back(value);}
+   void  SetPlasticEL(double value)  {fRIPS_Plastic_EL.push_back(value);}
+   void  SetPlasticTL(double value)  {fRIPS_Plastic_TL.push_back(value);}
+   void  SetPlasticTR(double value)  {fRIPS_Plastic_TR.push_back(value);}
+   
+   // RF
+   void  SetRFN(int value)      {fRIPS_RF_N.push_back(value);}
+   void  SetRFT(double value)   {fRIPS_RF_T.push_back(value);}
+   //
+   ClassDef(TRIPSData,1)  // PlasticData structure
+};
+
+#endif
-- 
GitLab