From 6cbf5aeddf1d8957d679e6ac575350f8eb8fc98f Mon Sep 17 00:00:00 2001
From: Giulio Gaio <giulio.gaio@elettra.eu>
Date: Tue, 2 May 2023 22:21:56 +0200
Subject: [PATCH] Fixed position and std 1D calculation

---
 src/DataVampire.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/DataVampire.cpp b/src/DataVampire.cpp
index d18d6c3..1068df9 100644
--- a/src/DataVampire.cpp
+++ b/src/DataVampire.cpp
@@ -2387,11 +2387,13 @@ void DataVampire::process_1D(int32_t cache_idx, int32_t auto_bck_samples)
 
 			if (cache_buffer[cache_idx].datavalid[i*wave_size+j]) {
 				sum += val; 
-				pos += val * (j + 1);
+				pos += val * (double)(j + 1);
 				cnt++;
 			}				
 		}
 		mean = sum / (double) cnt;
+		pos /= sum;
+
 
 		// get std
 		cnt = 0;
@@ -2403,7 +2405,8 @@ void DataVampire::process_1D(int32_t cache_idx, int32_t auto_bck_samples)
 		}		
 		if (cnt != 0)
 			std = pow(std / (double) cnt, 0.5);
-		std = 0;
+		else
+			std = 0;
 
 		cache_buffer[cache_idx].sum[i] = sum;
 		cache_buffer[cache_idx].mean[i] = mean;
-- 
GitLab