From aade0d2927659c328882eb47ee3c805427078b8b Mon Sep 17 00:00:00 2001
From: adrien-matta <a.matta@surrey.ac.uk>
Date: Thu, 16 Apr 2015 17:06:37 +0100
Subject: [PATCH] * Progress on new Example1

---
 NPAnalysis/Example1/Analysis.cxx   | 196 ++++++++++++++---------------
 NPAnalysis/Example1/Analysis.h     | 127 ++++++++++---------
 NPAnalysis/Example1/CMakeLists.txt |  31 +++++
 NPAnalysis/Example1/Makefile       |  31 -----
 NPAnalysis/newMUGAST/Analysis.h    |   4 +-
 5 files changed, 196 insertions(+), 193 deletions(-)
 mode change 100755 => 100644 NPAnalysis/Example1/Analysis.cxx
 mode change 100755 => 100644 NPAnalysis/Example1/Analysis.h
 create mode 100644 NPAnalysis/Example1/CMakeLists.txt
 delete mode 100755 NPAnalysis/Example1/Makefile

diff --git a/NPAnalysis/Example1/Analysis.cxx b/NPAnalysis/Example1/Analysis.cxx
old mode 100755
new mode 100644
index 575a3f970..b2b354ec6
--- a/NPAnalysis/Example1/Analysis.cxx
+++ b/NPAnalysis/Example1/Analysis.cxx
@@ -1,91 +1,67 @@
-#include "Analysis.h"
-
-int main(int argc, char** argv){
-  // command line parsing
-  NPOptionManager* myOptionManager = NPOptionManager::getInstance(argc,argv);
-
-  // Instantiate RootInput
-  string runToReadfileName = myOptionManager->GetRunToReadFile();
-  RootInput:: getInstance("RunToTreat.txt");
-  TChain* Chain = RootInput:: getInstance()->GetChain();
-  // if input files are not given, use those from TAsciiFile
-  if (myOptionManager->IsDefault("DetectorConfiguration")) {
-    string name = RootInput::getInstance()->DumpAsciiFile("DetectorConfiguration");
-    myOptionManager->SetDetectorFile(name);
-  }
-
-  // get input files from NPOptionManager
-  string detectorfileName    = myOptionManager->GetDetectorFile();
-  string OutputfileName      = myOptionManager->GetOutputFile();
-
-  // Instantiate RootOutput
-  RootOutput::getInstance("Analysis/"+OutputfileName, "ResultTree");
-  // RootOutput::getInstance()->GetFile()->SetCompressionLevel(0);
-  // Instantiate the detector using a file
-  NPA::DetectorManager* myDetector = new DetectorManager();
-  myDetector->ReadConfigurationFile(detectorfileName);
-  // Attach new branch
+/*****************************************************************************
+ * Copyright (C) 2009-2014    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: a.matta@surrey.ac.uk      *
+ *                                                                           *
+ * Creation Date  : march 2025                                               *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ * Class describing the property of an Analysis object                       *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+#include<iostream>
+using namespace std;
+#include"Analysis.h"
+#include"NPAnalysisFactory.h"
+#include"NPDetectorManager.h"
+#include"NPOptionManager.h"
+#include"RootOutput.h"
+#include"RootInput.h"
+////////////////////////////////////////////////////////////////////////////////
+Analysis::Analysis(){
+}
+////////////////////////////////////////////////////////////////////////////////
+Analysis::~Analysis(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::Init(){
+  M2= (TMust2Physics*) m_DetectorManager->GetDetector("MUST2Array");
+  SSSD= (TSSSDPhysics*) m_DetectorManager->GetDetector("SSSD");
   InitOutputBranch();
   InitInputBranch();
+  Rand = TRandom3();
+  He10Reaction= new NPL::Reaction();
+  He10Reaction->ReadConfigurationFile(NPOptionManager::getInstance()->GetReactionFile());
+  DetectorNumber = 0 ;
+  ThetaNormalTarget = 0 ;
+  ThetaM2Surface = 0; 
+  X_M2 = 0 ;
+  Y_M2 = 0 ;
+  Z_M2 = 0 ;
+  Si_E_M2 = 0 ;
+  CsI_E_M2 = 0 ; 
+  E_SSSD = 0 ;
+  Energy = 0;
+  E_M2 = 0;
+  Si_X_M2 = 0;
+  Si_Y_M2 = 0;
+  ZTarget = 0;
+  TargetThickness = m_DetectorManager->GetTargetThickness();
+}
 
-  //	Instantiate the Reaction
-  NPL::Reaction*  He10Reaction = new Reaction ;
-  He10Reaction	->	ReadConfigurationFile("10He.reaction") ;
-
-  ////////////////////////////////////////////////////////
-
-  // Get pointer to the different detector
-
-  TMust2Physics* M2  = (TMust2Physics*) myDetector -> GetDetector("MUST2");
-  TSSSDPhysics* SSSD = (TSSSDPhysics*)  myDetector -> GetDetector("SSSD");
-
-  // intermediate variable
-  TRandom3 Rand = TRandom3();
-  int DetectorNumber = 0 ;
-  double ThetaNormalTarget = 0 ;
-  double ThetaM2Surface = 0; 
-  double X_M2 = 0 ;
-  double Y_M2 = 0 ;
-  double Z_M2 = 0 ;
-  double Si_E_M2 = 0 ;
-  double CsI_E_M2 = 0 ; 
-  double E_SSSD = 0 ;
-  double Energy = 0;
-  double E_M2 = 0;
-  double Si_X_M2 = 0;
-  double Si_Y_M2 = 0;
-  double ZTarget = 0;
-  double TargetThickness = 18*micrometer;
-  // Get number of events to treat
-  cout << endl << "///////// Starting Analysis ///////// "<< endl;
-  int nentries = Chain->GetEntries();
-  cout << " Number of Event to be treated : " << nentries << endl;
-  clock_t begin = clock();
-  clock_t end = begin;
-  cout.precision(5);
-  //////////////////////////////////////////////////////////////////////////////
-  // main loop on entries //
-  for (int i = 0 ; i < nentries; i++) {
-    if (i%10000 == 0 && i!=0)  {
-      end = clock();
-      long double TimeElapsed = (long double) (end-begin) / CLOCKS_PER_SEC;
-      double percent = (double)i/nentries;
-      double TimeToWait = (TimeElapsed/percent) - TimeElapsed;       
-      cout  << "                                                      "<< flush;
-      cout  << "\r Progression:" 
-            << percent*100 << " % \t | \t Remaining time : ~" 
-            <<  TimeToWait <<"s |  Analysis Rate : "
-            << (double) i/TimeElapsed << flush;
-    }
-    else if (i == nentries-1)  cout << "\r Progression:" << " 100% " <<endl;
-
-
-    // Get the raw Data
-    Chain -> GetEntry(i);
-    // Clear previous Event
-    myDetector->ClearEventPhysics();
-    // Build the current event
-    myDetector->BuildPhysicalEvent();
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::TreatEvent(){
     // Reinitiate calculated variable
     ReInitValue();
 
@@ -94,12 +70,12 @@ int main(int argc, char** argv){
     // This is because the beam diagnosis are not simulated
 
     // PPAC position resolution on target is assumed to be 1mm
-    double XTarget = Rand.Gaus(Init->GetIncidentPositionX(),1);
-    double YTarget = Rand.Gaus(Init->GetIncidentPositionY(),1);
-    TVector3 BeamDirection = Init->GetBeamDirection();
+    double XTarget = Rand.Gaus(Initial->GetIncidentPositionX(),1);
+    double YTarget = Rand.Gaus(Initial->GetIncidentPositionY(),1);
+    TVector3 BeamDirection = Initial->GetBeamDirection();
 
     // Beam energy is measured using F3 and F2 plastic TOF
-    double BeamEnergy = Rand.Gaus(Init->GetIncidentInitialKineticEnergy(),4.5);
+    double BeamEnergy = Rand.Gaus(Initial->GetIncidentInitialKineticEnergy(),4.5);
     BeamEnergy = Li11CD2.Slow(BeamEnergy,TargetThickness/2.,0);
     He10Reaction->SetBeamEnergy(BeamEnergy);
 
@@ -190,22 +166,14 @@ int main(int argc, char** argv){
         }
       } //end loop SSSD
     }//end loop MUST2
+}
 
-    if(ELab>0)
-      RootOutput::getInstance()->GetTree()->Fill();
-  }// loop over events
-
-  cout << "A total of " << nentries << " event has been annalysed " << endl ;
-
-  RootOutput::getInstance()->Destroy();
-  RootInput::getInstance()->Destroy();
-  NPOptionManager::getInstance()->Destroy();
-  /////////////////////////////////////////////////////////////////////////////
-  return 0 ;
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::End(){
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void InitOutputBranch() {
+void Analysis::InitOutputBranch() {
   RootOutput::getInstance()->GetTree()->Branch("Ex",&Ex,"Ex/D");
   RootOutput::getInstance()->GetTree()->Branch("ELab",&ELab,"ELab/D");
   RootOutput::getInstance()->GetTree()->Branch("ThetaLab",&ThetaLab,"ThetaLab/D");
@@ -213,18 +181,38 @@ void InitOutputBranch() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void InitInputBranch(){
-  RootInput:: getInstance()->GetChain()->SetBranchAddress("InitialConditions",&Init );
+void Analysis::InitInputBranch(){
+  RootInput:: getInstance()->GetChain()->SetBranchAddress("InitialConditions",&Initial);
   RootInput:: getInstance()->GetChain()->SetBranchStatus("InitialConditions",true );
   RootInput:: getInstance()->GetChain()->SetBranchStatus("fIC_*",true );
 }
+
 ////////////////////////////////////////////////////////////////////////////////     
-void ReInitValue(){
+void Analysis::ReInitValue(){
   Ex = -1000 ;
   ELab = -1000;
   ThetaLab = -1000;
   ThetaCM = -1000;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+//            Construct Method to be pass to the DetectorFactory              //
+////////////////////////////////////////////////////////////////////////////////
+NPA::VAnalysis* Analysis::Construct(){
+  return (NPA::VAnalysis*) new Analysis();
+}
 
 ////////////////////////////////////////////////////////////////////////////////
+//            Registering the construct method to the factory                 //
+////////////////////////////////////////////////////////////////////////////////
+extern "C"{
+class proxy{
+  public:
+    proxy(){
+      NPA::AnalysisFactory::getInstance()->SetConstructor(Analysis::Construct);
+    }
+};
+
+proxy p;
+}
+
diff --git a/NPAnalysis/Example1/Analysis.h b/NPAnalysis/Example1/Analysis.h
old mode 100755
new mode 100644
index 89aa9a2cb..6537a6a23
--- a/NPAnalysis/Example1/Analysis.h
+++ b/NPAnalysis/Example1/Analysis.h
@@ -1,66 +1,81 @@
-// You can use this file to declare your spectra, file, energy loss , ... and whatever you want.
-// This way you can remove all unnecessary declaration in the main programm.
-// In order to help debugging and organizing we use Name Space.
+#ifndef Analysis_h 
+#define Analysis_h
+/*****************************************************************************
+ * Copyright (C) 2009-2014    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             *
+ *****************************************************************************/
 
-/////////////////////////////////////////////////////////////////////////////////////////////////
-// -------------------------------------- VARIOUS INCLUDE ---------------------------------------
-
-// NPL
-#include "DetectorManager.h"
-#include "NPOptionManager.h"
-#include "NPReaction.h"
-#include "RootInput.h"
-#include "RootOutput.h"
+/*****************************************************************************
+ * Original Author: Adrien MATTA  contact address: a.matta@surrey.ac.uk      *
+ *                                                                           *
+ * Creation Date  : march 2025                                               *
+ * Last update    :                                                          *
+ *---------------------------------------------------------------------------*
+ * Decription:                                                               *
+ * Class describing the property of an Analysis object                       *
+ *                                                                           *
+ *---------------------------------------------------------------------------*
+ * Comment:                                                                  *
+ *                                                                           *
+ *                                                                           *
+ *****************************************************************************/
+#include"NPVAnalysis.h"
+#include"TAnnularS1Physics.h"
 #include "TMust2Physics.h"
 #include "TSSSDPhysics.h"
 #include "TInitialConditions.h"
 #include "NPEnergyLoss.h"
-using namespace NPL ;
-// STL C++
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include <string>
-#include <cmath>
-#include <cstdlib>
-using namespace std;
-// ROOT
-#include <TROOT.h>
-#include <TChain.h>
-#include <TFile.h>
-#include <TVector3.h>
-#include <TRandom3.h>
-#include <TMath.h>
-#include <TObject.h>
+#include "NPReaction.h"
+#include "TRandom3.h"
+class Analysis: public NPA::VAnalysis{
+  public:
+    Analysis();
+    ~Analysis();
+
+  public: 
+    void Init();
+    void TreatEvent();
+    void End();
+    void InitOutputBranch();
+    void InitInputBranch();
+    void ReInitValue();
+    static NPA::VAnalysis* Construct();
 
-// ----------------------------------------------------------------------------------------------
-void InitOutputBranch() ;
-void InitInputBranch() ;
-void ReInitValue() ;
-/////////////////////////////////////////////////////////////////////////////////////////////////
-// ----------------------------------- DOUBLE, INT, BOOL AND MORE -------------------------------
-namespace VARIABLE{
-  double Ex;
-  double ELab;
-  double ThetaLab;
-  double ThetaCM;
-  TInitialConditions* Init = new TInitialConditions();
-}
+  private:
+    double Ex;
+    double ELab;
+    double ThetaLab;
+    double ThetaCM;
+    NPL::Reaction* He10Reaction;
 
-using namespace VARIABLE ;
-// ----------------------------------------------------------------------------------------------
-/////////////////////////////////////////////////////////////////////////////////////////////////
-// -----------------------------------ENERGY LOSS----------------------------------------------
-namespace ENERGYLOSS{
-  //	Energy loss table: the G4Table are generated by the simulation
-  EnergyLoss He3CD2 = EnergyLoss("He3_CD2.G4table","G4Table",100 );
-  EnergyLoss He3Al = EnergyLoss("He3_Al.G4table","G4Table",10);
-  EnergyLoss He3Si = EnergyLoss("He3_Si.G4table","G4Table",10);
-  EnergyLoss Li11CD2 = EnergyLoss("Li11[0.0]_CD2.G4table","G4Table",100);
-}
+    // intermediate variable
+    TRandom3 Rand;
+    int DetectorNumber;
+    double ThetaNormalTarget;
+    double ThetaM2Surface; 
+    double X_M2;
+    double Y_M2;
+    double Z_M2;
+    double Si_E_M2;
+    double CsI_E_M2; 
+    double E_SSSD;
+    double Energy = 0;
+    double E_M2 = 0;
+    double Si_X_M2 = 0;
+    double Si_Y_M2 = 0;
+    double ZTarget = 0;
+    double TargetThickness;
 
-using namespace ENERGYLOSS ;
-// ----------------------------------------------------------------------------------------------
-/////////////////////////////////////////////////////////////////////////////////////////////////
+    NPL::EnergyLoss He3CD2  ;
+    NPL::EnergyLoss He3Al   ;
+    NPL::EnergyLoss He3Si   ;
+    NPL::EnergyLoss Li11CD2 ;
 
+    TMust2Physics* M2;
+    TSSSDPhysics* SSSD;
+    TInitialConditions* Initial;
 
+};
+#endif
diff --git a/NPAnalysis/Example1/CMakeLists.txt b/NPAnalysis/Example1/CMakeLists.txt
new file mode 100644
index 000000000..dc3f3a57e
--- /dev/null
+++ b/NPAnalysis/Example1/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required (VERSION 2.8) 
+#Finding NPTool
+set(NPTOOL "$ENV{NPTOOL}")
+set(NPLIB "${NPTOOL}/NPLib")
+set(NPTOOL_INCLUDE_DIR "${NPLIB}/include")
+set(NPTOOL_LIB_DIR "${NPLIB}/lib")
+  
+include("${NPLIB}/FindROOT.cmake")  
+
+project (NPAnalysis)
+set(CMAKE_BUILD_TYPE Release)  
+# Add root to the link and include directories
+include_directories( ${ROOT_INCLUDE_DIR})
+link_directories( ${ROOT_LIBRARY_DIR})
+include_directories( ${NPTOOL_INCLUDE_DIR})
+link_directories( ${NPTOOL_LIB_DIR})
+
+# Get the compilator flag from root to assure consistancy
+EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
+     ARGS "--cflags"
+     OUTPUT_VARIABLE root_cflags )
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${root_cflags}")
+
+# If the compiler is Clang, silence the unrecognised flags
+if(${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang.*")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -undefined dynamic_lookup")
+endif()
+
+add_library(NPAnalysis SHARED Analysis.cxx)
+target_link_libraries(NPAnalysis ${ROOT_LIBRARIES} -L${NPLIB}/lib -lNPCore -lNPPhysics -lNPInitialConditions -lNPInteractionCoordinates)
diff --git a/NPAnalysis/Example1/Makefile b/NPAnalysis/Example1/Makefile
deleted file mode 100755
index abdac126f..000000000
--- a/NPAnalysis/Example1/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
-# include same architecture file than for NPLib
-# so that consistency is ensured
-include $(NPLIB)/Makefile.arch
-
-# additional libraries
-LIBRARY  = `$(NPLIB)/liblist`
-LIBRARY += -L$(CLHEP_LIB_DIR) -l$(CLHEP_LIB)
-
-PROGRAMS	= NPAnalysis
-
-all:	$(PROGRAMS)
-
-NPAnalysis:	Analysis.o
-	$(LD) $(LDFLAGS) $^ $(LIBS) $(LIBRARY) $(OutPutOpt) $@
-	@echo "$@ done"
-	
-
-# rule for creating .o from .cxx
-.SUFFIXES: .$(SrcSuf)
-.$(SrcSuf).$(ObjSuf):
-	$(CXX) $(CXXFLAGS) $(INCLUDE) -c $<
-
-# some cleaning
-clean:
-	rm -rf *.o
-
-distclean:
-	make clean; rm $(PROGRAMS)
-
-# dependences
-Analysis.o:	Analysis.cxx	Analysis.h
diff --git a/NPAnalysis/newMUGAST/Analysis.h b/NPAnalysis/newMUGAST/Analysis.h
index b9b12da2f..72dd8d00d 100644
--- a/NPAnalysis/newMUGAST/Analysis.h
+++ b/NPAnalysis/newMUGAST/Analysis.h
@@ -46,8 +46,8 @@ class Analysis: public NPA::VAnalysis{
   void InitOutputBranch();
   void InitInputBranch();
   void ReInitValue();
-  
-   static NPA::VAnalysis* Construct();
+  static NPA::VAnalysis* Construct();
+ 
   private:
   double Ex;
   double ELab;
-- 
GitLab