From f6dd67d947b47c088ca3407ac94ab3569d641b2b Mon Sep 17 00:00:00 2001
From: adrien-matta <a.matta@surrey.ac.uk>
Date: Thu, 4 Jun 2015 12:18:24 +0100
Subject: [PATCH] Adding a Sharc Analysis directory

---
 NPAnalysis/Sharc/Analysis.cxx   | 174 ++++++++++++++++++++++++++++++++
 NPAnalysis/Sharc/Analysis.h     |  87 ++++++++++++++++
 NPAnalysis/Sharc/CMakeLists.txt |  31 ++++++
 3 files changed, 292 insertions(+)
 create mode 100644 NPAnalysis/Sharc/Analysis.cxx
 create mode 100644 NPAnalysis/Sharc/Analysis.h
 create mode 100644 NPAnalysis/Sharc/CMakeLists.txt

diff --git a/NPAnalysis/Sharc/Analysis.cxx b/NPAnalysis/Sharc/Analysis.cxx
new file mode 100644
index 000000000..3c5c5eb9d
--- /dev/null
+++ b/NPAnalysis/Sharc/Analysis.cxx
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * 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"
+////////////////////////////////////////////////////////////////////////////////
+Analysis::Analysis(){
+}
+////////////////////////////////////////////////////////////////////////////////
+Analysis::~Analysis(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::Init(){
+  InitOutputBranch();
+  InitInputBranch();
+  
+  Sharc = (TSharcPhysics*)  m_DetectorManager -> GetDetector("Sharc");
+  LightCD2 = EnergyLoss("proton_CD2.G4table","G4Table",100 );
+  LightAl = EnergyLoss("proton_Al.G4table","G4Table",100);
+  LightSi = EnergyLoss("proton_Si.G4table","G4Table",100);
+  BeamCD2 = EnergyLoss("Rb88_CD2.G4table","G4Table",100);
+  myReaction = new NPL::Reaction();
+  myReaction->ReadConfigurationFile(NPOptionManager::getInstance()->GetReactionFile());
+   TargetThickness = m_DetectorManager->GetTargetThickness()*micrometer;
+  OriginalBeamEnergy = myReaction->GetBeamEnergy();
+   Rand = TRandom3();
+   DetectorNumber = 0 ;
+   ThetaNormalTarget = 0 ;
+   ThetaM2Surface = 0;
+   Si_E_M2 = 0 ;
+   CsI_E_M2 = 0 ;
+   Energy = 0;
+   E_M2 = 0;
+  
+   ThetaSharcSurface = 0;
+   X_Sharc = 0 ;
+   Y_Sharc = 0 ;
+   Z_Sharc = 0 ;
+   Si_E_Sharc = 0 ;
+   E_Sharc = 0;
+   Si_X_Sharc = 0;
+   Si_Y_Sharc = 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::TreatEvent(){
+  // Reinitiate calculated variable
+  ReInitValue();
+  double XTarget = 0;
+  double YTarget = 0;
+  TVector3 BeamDirection = TVector3(0,0,1);
+  double BeamEnergy = BeamCD2.Slow(OriginalBeamEnergy,TargetThickness*0.5,0);
+  myReaction->SetBeamEnergy(BeamEnergy);
+  ////////////////////////////////////////////////////////////////////////////
+  ////////////////////////////////////////////////////////////////////////////
+  //////////////////////////// LOOP on Sharc//////////////////
+  if(Sharc->Strip_E.size()>0){
+    /************************************************/
+    // Part 1 : Impact Angle
+    ThetaSharcSurface = 0;
+    ThetaNormalTarget = 0;
+    if(XTarget>-1000 && YTarget>-1000){
+      TVector3 HitDirection = Sharc -> GetPositionOfInteraction(0) - BeamImpact ;
+      ThetaLab = HitDirection.Angle( BeamDirection );
+      
+      ThetaSharcSurface = HitDirection.Angle( TVector3(0,0,1) ) ;
+      ThetaNormalTarget = HitDirection.Angle( TVector3(0,0,1) ) ;
+    }
+    
+    else{
+      BeamDirection = TVector3(-1000,-1000,-1000);
+      ThetaSharcSurface    = -1000  ;
+      ThetaNormalTarget = -1000  ;
+    }
+    
+    /************************************************/
+    
+    /************************************************/
+    // Part 2 : Impact Energy
+
+    Energy = ELab = 0;
+    if(Sharc->PAD_E[0]>0){
+      Energy = Sharc->PAD_E[0];
+    }
+
+    Energy += Sharc->Strip_E[0];
+    // Target Correction
+    
+   ELab   = LightCD2.EvaluateInitialEnergy( Energy ,TargetThickness*0.5, ThetaNormalTarget);
+   /************************************************/
+    
+    /************************************************/
+    // Part 3 : Excitation Energy Calculation
+    Ex = myReaction -> ReconstructRelativistic( ELab , ThetaLab );
+    
+    /************************************************/
+    
+    /************************************************/
+    // Part 4 : Theta CM Calculation
+    ThetaCM  = myReaction -> EnergyLabToThetaCM( ELab , ThetaLab)/deg;
+    ThetaLab=ThetaLab/deg;
+    ThetaLab=Rand.Uniform(ThetaLab-0.5,ThetaLab+0.5);
+    /************************************************/
+  }//end loop GASPARD
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::End(){
+}
+////////////////////////////////////////////////////////////////////////////////
+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");
+  RootOutput::getInstance()->GetTree()->Branch("ThetaCM",&ThetaCM,"ThetaCM/D");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::InitInputBranch(){
+}
+////////////////////////////////////////////////////////////////////////////////
+void Analysis::ReInitValue(){
+  Ex = -1000 ;
+  ELab = -1000;
+  ThetaLab = -1000;
+  ThetaCM = -1000;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+//            Construct Method to be pass to the AnalysisFactory              //
+////////////////////////////////////////////////////////////////////////////////
+NPL::VAnalysis* Analysis::Construct(){
+  return (NPL::VAnalysis*) new Analysis();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//            Registering the construct method to the factory                 //
+////////////////////////////////////////////////////////////////////////////////
+extern "C"{
+class proxy{
+  public:
+    proxy(){
+      NPL::AnalysisFactory::getInstance()->SetConstructor(Analysis::Construct);
+    }
+};
+
+proxy p;
+}
+
diff --git a/NPAnalysis/Sharc/Analysis.h b/NPAnalysis/Sharc/Analysis.h
new file mode 100644
index 000000000..5b9ce24e5
--- /dev/null
+++ b/NPAnalysis/Sharc/Analysis.h
@@ -0,0 +1,87 @@
+#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             *
+ *****************************************************************************/
+
+/*****************************************************************************
+ * 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"NPEnergyLoss.h"
+#include"NPReaction.h"
+#include"RootOutput.h"
+#include"RootInput.h"
+#include "TSharcPhysics.h"
+#include "TInitialConditions.h"
+#include <TRandom3.h>
+#include <TVector3.h>
+#include <TMath.h>
+
+class Analysis: public NPL::VAnalysis{
+  public:
+    Analysis();
+    ~Analysis();
+
+  public: 
+    void Init();
+    void TreatEvent();
+    void End();
+
+  void InitOutputBranch();
+  void InitInputBranch();
+  void ReInitValue();
+  static NPL::VAnalysis* Construct();
+ 
+  private:
+  double Ex;
+  double ELab;
+  double ThetaLab;
+  double ThetaCM;
+  NPL::Reaction* myReaction;
+TInitialConditions* myInit ;
+  //	Energy loss table: the G4Table are generated by the simulation
+  EnergyLoss LightCD2;
+  EnergyLoss LightAl;
+  EnergyLoss LightSi;
+  EnergyLoss BeamCD2;
+  TVector3 BeamImpact;
+  
+  double TargetThickness ;
+  // Beam Energy
+  double OriginalBeamEnergy ; // AMEV
+                                                           // intermediate variable
+  TRandom3 Rand ;
+  int DetectorNumber  ;
+  double ThetaNormalTarget;
+  double ThetaM2Surface ;
+  double Si_E_M2 ;
+  double CsI_E_M2  ;
+  double Energy ;
+  double E_M2 ;
+  
+  double ThetaSharcSurface ;
+  double X_Sharc ;
+  double Y_Sharc ;
+  double Z_Sharc  ;
+  double Si_E_Sharc ;
+  double E_Sharc ;
+  double Si_X_Sharc ;
+  double Si_Y_Sharc ;
+  TSharcPhysics* Sharc;
+};
+#endif
diff --git a/NPAnalysis/Sharc/CMakeLists.txt b/NPAnalysis/Sharc/CMakeLists.txt
new file mode 100644
index 000000000..1d6a34417
--- /dev/null
+++ b/NPAnalysis/Sharc/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)
-- 
GitLab