From c7768bfd4643d157f345e9935740ec7b53e45543 Mon Sep 17 00:00:00 2001
From: Jack Christopher Hutchinson Rolph <jack.rolph@desy.de>
Date: Wed, 11 Jan 2023 13:17:37 +0100
Subject: [PATCH] Update PeakOTron.py

---
 PeakOTron.py | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/PeakOTron.py b/PeakOTron.py
index 3bcac3a..f5906d0 100644
--- a/PeakOTron.py
+++ b/PeakOTron.py
@@ -352,6 +352,48 @@ class PeakOTron:
     ########################################################################################################
 
     
+    
+#     def __CalcChi2(self, x, y, y_hat, y_err):
+#         chi2 = np.nansum(((y_hat - y)/y_err)**2)
+#         ndof = len(x) - 10
+#         return chi2, ndof
+    
+    
+    
+#     def GetChi2(self, prefit=False):
+        
+#         if(self._m_DRM is None):
+#             raise Exception ("Fit has not yet been performed. Please first perform a fit.")
+#         else:
+
+#             x_all = self._hist_data["bin_numbers"]
+#             y_all = self._hist_data["counts"]
+#             y_err_all = self._hist_data["counts_error"]
+            
+#             if(self._fit_kwargs["truncate_nsigma0_do"] is not None):
+#                 lim_nsigma0 = self._prefit_values_bin["Q_0"] - self._fit_kwargs["truncate_nsigma0_do"]*self._prefit_values_bin["sigma_0"]
+#                 cond_sel_nsigma0 = (self._hist_data["bin_numbers"]>lim_nsigma0)
+
+#             else:
+#                 cond_sel_nsigma0 = np.full(len(self._hist_data["bin_numbers"]), True).astype(bool)
+
+#             x = x_all[cond_sel_nsigma0]
+#             y = y_all[cond_sel_nsigma0]
+#             y_err = y_err_all[cond_sel_nsigma0]
+
+#             y_hat = self.GetModel(x, prefit=prefit, bin_units=True)
+#             y_hat_err = np.sqrt(y_hat)
+            
+                 
+#             plt.figure()
+#             plt.plot(x, (y-y_hat)/y_err)
+#             plt.show()
+        
+#             chi2, ndof = self.__CalcChi2(x, y, y_hat, y_err)
+
+#             return chi2, ndof
+    
+    
 
     
     def GetChi2(self, pars=None, prefit=False, full=False, n_sigma_lims=[None, None]):
@@ -368,9 +410,11 @@ class PeakOTron:
             y_hat_all = self.GetModel(x_all, prefit=prefit, bin_units=True)
         else:
             y_hat_all = DRM(x_all, **pars)
-     
+            
+        
         conds = []
         
+        
         cond_count = (y_all>1)
 
         conds.append(cond_count)
-- 
GitLab