From 17aeb99a4f4b0bd8cb801fd24b8078054e40a0e3 Mon Sep 17 00:00:00 2001
From: moukaddam <mhd.moukaddam@gmail.com>
Date: Tue, 7 Mar 2017 15:54:55 +0000
Subject: [PATCH] Adding a user-defined thickness of dead layer in the
 SimpleCalibration method

---
 NPLib/Calibration/NPSiliconCalibrator.cxx | 22 +++++++++++++++-------
 NPLib/Calibration/NPSiliconCalibrator.h   |  2 +-
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/NPLib/Calibration/NPSiliconCalibrator.cxx b/NPLib/Calibration/NPSiliconCalibrator.cxx
index 1242e5b63..48aaf921d 100644
--- a/NPLib/Calibration/NPSiliconCalibrator.cxx
+++ b/NPLib/Calibration/NPSiliconCalibrator.cxx
@@ -24,7 +24,7 @@ NPL::SiliconCalibrator::~SiliconCalibrator(){
 }
 
 //////////////////////////////////////////////
-double NPL::SiliconCalibrator::ZeroExtrapolation(TH1* histo, NPL::CalibrationSource* CS, NPL::EnergyLoss* EL, vector<double>& coeff, unsigned int pedestal, unsigned int max_iteration,double rmin,double rmax){
+double NPL::SiliconCalibrator::ZeroExtrapolation(TH1* histo, NPL::CalibrationSource* CS, NPL::EnergyLoss* EL, vector<double>& coeff, unsigned int pedestal, unsigned int max_iteration, double rmin,double rmax){
   if(histo->GetEntries()==0){
     coeff.clear();
     coeff.push_back(0);
@@ -134,7 +134,7 @@ double NPL::SiliconCalibrator::ZeroExtrapolation(TH1* histo, NPL::CalibrationSou
   return Assume_Thickness/micrometer;
 }
 ////////////////////////////////////////////////////////////////////////////////
-double NPL::SiliconCalibrator::SimpleCalibration(TH1* histo, NPL::CalibrationSource* CS, NPL::EnergyLoss* EL, vector<double>& coeff, double rmin,double rmax){
+double NPL::SiliconCalibrator::SimpleCalibration(TH1* histo, NPL::CalibrationSource* CS, NPL::EnergyLoss* EL, vector<double>& coeff, double Assume_Thickness, double rmin,double rmax){
   if(histo->GetEntries()==0){
     coeff.clear();
     coeff.push_back(0);
@@ -157,7 +157,7 @@ double NPL::SiliconCalibrator::SimpleCalibration(TH1* histo, NPL::CalibrationSou
     }
   }
 
-  if(counts < 30){
+  if(counts == 0){
     coeff.clear();
     coeff.push_back(0);
     coeff.push_back(-1);
@@ -175,14 +175,22 @@ double NPL::SiliconCalibrator::SimpleCalibration(TH1* histo, NPL::CalibrationSou
     Source_E[i] = CS->GetEnergies()[i][0];
     Source_Sig[i] = CS->GetEnergiesErrors()[i][0]; 
   }
+
+  // Compute the new assumed energies   
+  vector<double> Assume_E ; // Energie calculated assuming Assume_Thickness deadlayer of Al
+  Assume_E.resize(source_size,0); 
+  for(unsigned int i = 0 ; i < source_size ; i++){
+    Assume_E[i] = EL->Slow(Source_E[i], Assume_Thickness, 0); // Assume_Thickness in micrometer
+  }
+
   TGraphErrors* g = FitSpectrum(histo,rmin,rmax);
-  double dist = FitPoints(g,Source_E , Source_Sig, coeff, 0 );
+  double DistanceToPedestal = FitPoints(g, &Assume_E[0] , Source_Sig, coeff, 0 );
 
   delete g;
-  if(dist!=-3)
-    return abs(dist);
+  if(DistanceToPedestal!=-3)
+    return abs(DistanceToPedestal);
   else 
-    return dist;
+    return DistanceToPedestal;
 }
 
 
diff --git a/NPLib/Calibration/NPSiliconCalibrator.h b/NPLib/Calibration/NPSiliconCalibrator.h
index cdc5b97a9..eab6a935d 100644
--- a/NPLib/Calibration/NPSiliconCalibrator.h
+++ b/NPLib/Calibration/NPSiliconCalibrator.h
@@ -26,7 +26,7 @@ namespace NPL{
       // Use the Zero Extrapolation method to perform fit and return the dead layer thickness
       double ZeroExtrapolation(TH1* histo, NPL::CalibrationSource* CS, NPL::EnergyLoss* EL, vector<double>& coeff, unsigned int pedestal, unsigned int max_iteration = 10000 , double rmin=-1,double rmax=-1);
 
-      double SimpleCalibration(TH1* histo, NPL::CalibrationSource* CS, NPL::EnergyLoss* EL, vector<double>& coeff, double rmin=-1,double rmax=-1);
+      double SimpleCalibration(TH1* histo, NPL::CalibrationSource* CS, NPL::EnergyLoss* EL, vector<double>& coeff, double Assume_Thickness=0,double rmin=-1,double rmax=-1);
 
       // Return distance to pedestal. Use energies in Energies to perform fit and fill coeff with the results
       double FitPoints(TGraphErrors* Graph, double* Energies , double* ErrEnergies, vector<double>& coeff , double pedestal = 0 );
-- 
GitLab