#include "hit_analyse_v2.h" #include HIT_ANALYSE_V2::HIT_ANALYSE_V2(QObject *parent) : QObject(parent) { } // Define your own functions for matrix operations struct Matrix2x2 { double data[2][2]; }; Matrix2x2 InvertMatrix2x2(const Matrix2x2& mat) { Matrix2x2 result; double det = mat.data[0][0] * mat.data[1][1] - mat.data[0][1] * mat.data[1][0]; if (det != 0.0) { double invDet = 1.0 / det; result.data[0][0] = mat.data[1][1] * invDet; result.data[0][1] = -mat.data[0][1] * invDet; result.data[1][0] = -mat.data[1][0] * invDet; result.data[1][1] = mat.data[0][0] * invDet; } else { // Handle the case when the matrix is not invertible // You might want to implement error handling here. std::cerr << "Matrix not invertible! " << std::endl; } return result; } struct Vector2 { double data[2]; }; QString HIT_ANALYSE_V2::analyseBeamData(QVector dataframe){ double position=0.1; double focus=8; double intensity=1000.0; QString dataString; const int vector_length = 300; // Replace with the actual length of your vectors std::vector signal_list(vector_length); std::vector channel_list(vector_length); std::vector short_signal_list; std::vector short_channel_list; // Create a random number generator with a Gaussian distribution std::random_device rd; std::mt19937 gen(rd()); std::normal_distribution dist(0.0, 17.0); // Mean of 0 and Sigma of 17 // Create a vector to store the generated values std::vector result(vector_length); // Fill the vector with random noise values //add a gaussian profile, focus is FWHM, position is random between 50 and 250 bool fixeddata = true; if (!fixeddata){ position = 50 + (rand() % (int)(250 - 50 + 1)); for (int i = 0; i < vector_length; i++) { double randomValue = dist(gen); signal_list[i] = static_cast(std::round(randomValue)); channel_list[i] = i; signal_list[i] += static_cast(std::round(intensity*exp(-4*log(2)*pow((channel_list[i]-position)/focus,2)))); // std::cerr << channel_list[i] << ", "; } // std::cerr < 34 && channel_list[i] > window_start && channel_list[i] < window_end) { short_signal_list.push_back(signal_list[i]); short_channel_list.push_back(channel_list[i]); } } signal_list.clear(); channel_list.clear(); // Recalculate SumArea using the sieved data SumArea = 0.0; for (int i = 1; i < short_signal_list.size(); i++) { SumArea += short_signal_list[i] * (short_channel_list[i] - short_channel_list[i - 1]); } const int shortlist_length = short_channel_list.size(); if (shortlist_length <= 3) { intensity = -1; focus = -1; position = -128; dataString += QString::number(intensity) + ',' + QString::number(position) + ',' + QString::number(focus) + ',' + QString::number(0); return dataString; } // Re-Estimate sigma sigma = SumArea / Ymax / 2.5066; fac_c = -1.0 / (2.0 * sigma * sigma); // std::cerr << sigma << std::endl; for(int k=0; k