using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GenesisDisplayTool { public class MeanCalculate { public static void ResetProcessingListsTof(ref List>[] processingTofUpMean, ref List>[] processingTofDownMean, ref List>[] processingDifTofMean) { for (UInt16 Path = 0; Path < Constants.NumberOfPaths; Path++) { for (UInt16 Hit = 0; Hit < 8; Hit++) { processingTofUpMean[Path][Hit].Clear(); processingTofDownMean[Path][Hit].Clear(); processingDifTofMean[Path][Hit].Clear(); } } } public static void ResetProcessingListsMultihitMean(ref List processingThreeHitsMean, ref List processing8HitsMean, ref List[] processingThreeHitsTotalMean, ref List[] processing8HitsTotalMean) { processingThreeHitsMean.Clear(); processing8HitsMean.Clear(); for (UInt16 Path = 0; Path < Constants.NumberOfPaths; Path++) { processingThreeHitsTotalMean[Path].Clear(); processing8HitsTotalMean[Path].Clear(); } } public static void ResetProcessingListsOthersMean(ref List[] processingPulsewidthUpMean, ref List[] processingPulsewidthDownMean, ref List[] processingAmplitudeUpMean, ref List[] processingAmplitudeDownMean, ref List[] processingTemperatureMean, ref List[] processingFlowMean ) { for (UInt16 Path = 0; Path < 3; Path++) { processingPulsewidthUpMean[Path].Clear(); processingPulsewidthDownMean[Path].Clear(); processingAmplitudeUpMean[Path].Clear(); processingAmplitudeDownMean[Path].Clear(); processingTemperatureMean[Path].Clear(); processingFlowMean[Path].Clear(); } } public static void ResetCalculationResults(ref DecodedData[] decoded) { DecodedData[] temp = new DecodedData[3]; temp = decoded; for (UInt16 Path = 0; Path<3; Path++ ) { temp[Path].PulsewidthDownMean = 0; temp[Path].PulsewidthUpMean = 0; temp[Path].AmpDownMean = 0; temp[Path].AmpUpMean = 0; temp[Path].DifTof3HitsMean = 0; temp[Path].DifTof8HitsMean = 0; temp[Path].TemperatureColdMean = 0; temp[Path].TemperatureHotMean = 0; temp[Path].TofSumOfAllDownMean = 0; temp[Path].TofSumOfAllUpMean = 0; temp[Path].DifTof3HitsMean = 0; temp[Path].DifTof8HitsMean = 0; for (UInt16 Hit = 0; Hit<8; Hit++) { temp[Path].TofDownMean[Hit] = 0; temp[Path].TofUpMean[Hit] = 0; temp[Path].DifTofMean[Hit] = 0; } } decoded = temp; } public static void ResetCounters(ref UInt16[] telegramCounterTofMean, ref UInt16[] telegramCounterDifTofMean, ref UInt16[] telegramCounterMultiHitMean, ref UInt16[] telegramCounterOthersMean, ref UInt16[] telegramCounterTemperatureMean, ref UInt16[] telegramCounterFlowMean) { for (UInt16 Path = 0; Path < 3; Path++) { telegramCounterTofMean[Path] = 0; telegramCounterDifTofMean[Path] = 0; telegramCounterMultiHitMean[Path] = 0; telegramCounterOthersMean[Path] = 0; telegramCounterTemperatureMean[Path] = 0; telegramCounterFlowMean[Path] = 0; } } public static DecodedData[] Tof(UInt16 inputPath, DecodedData[] inputData, ref UInt16[] telegramCounterTofMean, ref List>[] processingTofUpMean, ref List>[] processingTofDownMean, UInt16 numberOfValues) { try { #region Initial filling if (telegramCounterTofMean[inputPath] < numberOfValues) { #region Add values for (UInt16 Hit = 0; Hit < 8; Hit++) { processingTofUpMean[inputPath][Hit].Add(inputData[inputPath].TofUp[Hit]); processingTofDownMean[inputPath][Hit].Add(inputData[inputPath].TofDown[Hit]); } #endregion #region Calculate first value if(telegramCounterTofMean[inputPath] == numberOfValues-1) { for(UInt16 Hit = 0; Hit< 8; Hit++) { #region Calculate values inputData[inputPath].TofUpMean[Hit] = processingTofUpMean[inputPath][Hit].Mean(); inputData[inputPath].TofDownMean[Hit] = processingTofDownMean[inputPath][Hit].Mean(); #endregion } } #endregion #region Counter telegramCounterTofMean[inputPath]++; #endregion } #endregion #region Moving average else { #region Prepare data and calculate for (UInt16 Hit = 0; Hit < 8; Hit++) { #region Remove first element processingTofUpMean[inputPath][Hit].RemoveAt(0); processingTofDownMean[inputPath][Hit].RemoveAt(0); #endregion #region Add last element processingTofUpMean[inputPath][Hit].Add(inputData[inputPath].TofUp[Hit]); processingTofDownMean[inputPath][Hit].Add(inputData[inputPath].TofUp[Hit]); #endregion #region Calculate values inputData[inputPath].TofUpMean[Hit] = processingTofUpMean[inputPath][Hit].Mean(); inputData[inputPath].TofDownMean[Hit] = processingTofDownMean[inputPath][Hit].Mean(); #endregion } #endregion } #endregion } catch (Exception ex) { #region Error ErrorLog.Log(LogErrReason.Exception(), "MeanCalculate.Tof() failed", "0x" + ex.HResult.ToString("X"), inputPath.ToString()); #endregion } #region Return data return inputData; #endregion } public static DecodedData[] DifTof(UInt16 inputPath, DecodedData[] inputData, ref UInt16[] telegramCounterDifTofMean, ref List>[] processingListDifTofMean, UInt16 numberOfValues) { try { #region Initial fill if (telegramCounterDifTofMean[inputPath] < numberOfValues) { #region Fill list for (UInt16 Hit = 0; Hit < 8; Hit++) processingListDifTofMean[inputPath][Hit].Add(inputData[inputPath].DifTof[Hit]); #endregion #region Calculate first value if (telegramCounterDifTofMean[inputPath] == numberOfValues - 1) { for(UInt16 Hit = 0; Hit < 8; Hit++) inputData[inputPath].DifTofMean[Hit] = processingListDifTofMean[inputPath][Hit].Mean(); } #endregion #region Counter telegramCounterDifTofMean[inputPath]++; #endregion } #endregion #region Moving average else { for (UInt16 Hit = 0; Hit < 8; Hit++) { #region Remove first element processingListDifTofMean[inputPath][Hit].RemoveAt(0); #endregion #region Add last element processingListDifTofMean[inputPath][Hit].Add(inputData[inputPath].DifTof[Hit]); #endregion #region Calculate values inputData[inputPath].DifTofMean[Hit] = processingListDifTofMean[inputPath][Hit].Mean(); #endregion } } #endregion } catch (Exception ex) { #region Error ErrorLog.Log(LogErrReason.Exception(), "MeanCalculate.DifTof() failed", "0x" + ex.HResult.ToString("X"), "Path= " + inputPath.ToString()); #endregion } #region Return data return inputData; #endregion } public static DecodedData[] Multihit(UInt16 inputPath, DecodedData[] inputData, ref UInt16[] telegramCounterfMultihitMean, ref List[] processingThreeHitsTotal, ref List processingThreeHits, ref List[] processingEightHitsTotal, ref List processingEightHits, UInt16 numberOfValues) { // try // { #region Definitions and initializations double[] ThreeHitsMean = new double[3] { 0, 0, 0 }; // Mean Value over first three hits double[] ThreeHitsTotalMean = new double[3] { 0, 0, 0 }; // Mean Value over N mean values of first three hits double[] EightHitsMean = new double[3] { 0, 0, 0 }; // Mean Value over first three hits double[] EightHitsTotalMean = new double[3] { 0, 0, 0 }; #endregion #region Prepare input values #region Fill first three hits processingThreeHits.Add(inputData[inputPath].DifTof[Constants.HIT0]); processingThreeHits.Add(inputData[inputPath].DifTof[Constants.HIT1]); processingThreeHits.Add(inputData[inputPath].DifTof[Constants.HIT2]); #endregion #region Fill first eight hits for (UInt16 Hit = 0; Hit < 8; Hit++) processingEightHits.Add(inputData[inputPath].DifTof[Hit]); #endregion #region Obtain mean value ThreeHitsMean[inputPath] = processingThreeHits.Mean(); processingThreeHits.Clear(); EightHitsMean[inputPath] = processingEightHits.Mean(); processingEightHits.Clear(); #endregion #endregion #region Initial filling if (telegramCounterfMultihitMean[inputPath] < numberOfValues) { #region Three/ eight hits processingThreeHitsTotal[inputPath].Add(ThreeHitsMean[inputPath]); processingEightHitsTotal[inputPath].Add(EightHitsMean[inputPath]); #endregion #region First calculation if (telegramCounterfMultihitMean[inputPath] == numberOfValues - 1) { #region Calculate values ThreeHitsTotalMean[inputPath] = processingThreeHitsTotal[inputPath].Mean(); EightHitsTotalMean[inputPath] = processingEightHitsTotal[inputPath].Mean(); #endregion #region Assign to global data object inputData[inputPath].DifTof3HitsMean = ThreeHitsTotalMean[inputPath]; inputData[inputPath].DifTof8HitsMean = EightHitsTotalMean[inputPath]; #endregion } #endregion #region Counter telegramCounterfMultihitMean[inputPath]++; #endregion } #endregion #region Moving average else { #region Remove first element processingThreeHitsTotal[inputPath].RemoveAt(0); processingEightHitsTotal[inputPath].RemoveAt(0); #endregion #region Add last element processingThreeHitsTotal[inputPath].Add(ThreeHitsMean[inputPath]); processingEightHitsTotal[inputPath].Add(EightHitsMean[inputPath]); #endregion #region Calculate values ThreeHitsTotalMean[inputPath] = processingThreeHitsTotal[inputPath].Mean(); EightHitsTotalMean[inputPath] = processingEightHitsTotal[inputPath].Mean(); #endregion #region Assign to global data object inputData[inputPath].DifTof3HitsMean = ThreeHitsTotalMean[inputPath]; inputData[inputPath].DifTof8HitsMean = EightHitsTotalMean[inputPath]; #endregion } #endregion /* } catch (Exception ex) { #region Error ErrorLog.Log(LogErrReason.Exception(), "MeanCalculate.Multihit() failed", "0x" + ex.HResult.ToString("X"), "Path= " + inputPath.ToString()); #endregion }*/ #region Return data return inputData; #endregion } public static DecodedData[] MultihitNoOverallAvg(UInt16 inputPath, DecodedData[] inputData) { try { #region Definitions and initializations double[] ThreeHitsMean = new double[3] { 0, 0, 0 }; // Mean Value over first three hits double[] EightHitsMean = new double[3] { 0, 0, 0 }; List ProcessingThreeHits = new List(); List ProcessingEightHits = new List(); #endregion #region Fill first three hits ProcessingThreeHits.Add(inputData[inputPath].DifTof[Constants.HIT0]); ProcessingThreeHits.Add(inputData[inputPath].DifTof[Constants.HIT1]); ProcessingThreeHits.Add(inputData[inputPath].DifTof[Constants.HIT2]); #endregion #region Fill first eight hits for (UInt16 Hit = 0; Hit < 8; Hit++) ProcessingEightHits.Add(inputData[inputPath].DifTof[Hit]); #endregion #region Obtain mean value ThreeHitsMean[inputPath] = ProcessingThreeHits.Mean(); ProcessingThreeHits.Clear(); EightHitsMean[inputPath] = ProcessingEightHits.Mean(); ProcessingEightHits.Clear(); #endregion #region Assign to global data object inputData[inputPath].DifTof3HitsMean = ThreeHitsMean[inputPath]; inputData[inputPath].DifTof8HitsMean = EightHitsMean[inputPath]; #endregion } catch (Exception ex) { #region Error ErrorLog.Log(LogErrReason.Exception(), "MeanCalculate.MultihitNoOverallAvg() failed", "0x" + ex.HResult.ToString("X"), "Path= " + inputPath.ToString()); #endregion } #region Return data return inputData; #endregion } public static DecodedData[] Others(UInt16 inputPath, DecodedData[] inputData, ref UInt16[] telegramCounterOthersMean, ref List[] processingPulsewidthUpMean, ref List[] processingAmplitudeUpMean, ref List[] processingPulsewidthDownMean, ref List[] processingAmplitudeDownMean, UInt16 numberOfValues) { try { #region Definitions and initializations double[] PulsewidthUpMean = new double[3]; double[] PulsewidthDownMean = new double[3]; double[] AmplitudeUpMean = new double[3]; double[] AmplitudeDownMean = new double[3]; #endregion #region Initial filling if (telegramCounterOthersMean[inputPath] < numberOfValues) { #region Pulsewidth/ amplitude up processingPulsewidthUpMean[inputPath].Add(inputData[inputPath].PulsewidthUp); processingAmplitudeUpMean[inputPath].Add(inputData[inputPath].AmpUpCalculated); #endregion #region Pulsewidth/ amplitude down processingPulsewidthDownMean[inputPath].Add(inputData[inputPath].PulsewidthDown); processingAmplitudeDownMean[inputPath].Add(inputData[inputPath].AmpDownCalculated); #endregion #region First calculation if (telegramCounterOthersMean[inputPath] == numberOfValues - 1) { #region Calculate values PulsewidthUpMean[inputPath] = processingPulsewidthUpMean[inputPath].Mean(); AmplitudeUpMean[inputPath] = processingAmplitudeUpMean[inputPath].Mean(); PulsewidthDownMean[inputPath] = processingPulsewidthDownMean[inputPath].Mean(); AmplitudeDownMean[inputPath] = processingAmplitudeDownMean[inputPath].Mean(); #endregion #region Assign to global object inputData[inputPath].PulsewidthUpMean = PulsewidthUpMean[inputPath]; inputData[inputPath].AmpUpMean = AmplitudeUpMean[inputPath]; inputData[inputPath].PulsewidthDownMean = PulsewidthDownMean[inputPath]; inputData[inputPath].AmpDownMean = AmplitudeDownMean[inputPath]; #endregion } #endregion #region Counter telegramCounterOthersMean[inputPath]++; #endregion } #endregion #region Moving average else { #region Remove first element processingPulsewidthUpMean[inputPath].RemoveAt(0); processingAmplitudeUpMean[inputPath].RemoveAt(0); processingPulsewidthDownMean[inputPath].RemoveAt(0); processingAmplitudeDownMean[inputPath].RemoveAt(0); #endregion #region Add last element processingPulsewidthUpMean[inputPath].Add(inputData[inputPath].PulsewidthUp); processingAmplitudeUpMean[inputPath].Add(inputData[inputPath].AmpUpCalculated); processingPulsewidthDownMean[inputPath].Add(inputData[inputPath].PulsewidthDown); processingAmplitudeDownMean[inputPath].Add(inputData[inputPath].AmpDownCalculated); #endregion #region Calculate values PulsewidthUpMean[inputPath] = processingPulsewidthUpMean[inputPath].Mean(); AmplitudeUpMean[inputPath] = processingAmplitudeUpMean[inputPath].Mean(); PulsewidthDownMean[inputPath] = processingPulsewidthDownMean[inputPath].Mean(); AmplitudeDownMean[inputPath] = processingAmplitudeDownMean[inputPath].Mean(); #endregion #region Assign to global data object inputData[inputPath].PulsewidthUpMean = PulsewidthUpMean[inputPath]; inputData[inputPath].AmpUpMean = AmplitudeUpMean[inputPath]; inputData[inputPath].PulsewidthDownMean = PulsewidthDownMean[inputPath]; inputData[inputPath].AmpDownMean = AmplitudeDownMean[inputPath]; #endregion } #endregion } catch (Exception ex) { #region Error ErrorLog.Log(LogErrReason.Exception(), "MeanCalculate.Others() failed", "0x" + ex.HResult.ToString("X"), "Path= " + inputPath.ToString()); #endregion } #region Return data return inputData; #endregion } public static double Temperature(UInt16 inputPath, double[] temperatureCold, ref UInt16[] telegramCounterTemperatureMean, ref List[] processingTemperatureMean, UInt16 numberOfValues) { #region Definitions and initializations double TemperatureColdMean = 0; #endregion try { #region Initial fill if (telegramCounterTemperatureMean[inputPath] < numberOfValues) { #region Copy data to list processingTemperatureMean[inputPath].Add(temperatureCold[inputPath]); #endregion #region First calculation if(telegramCounterTemperatureMean[inputPath] == numberOfValues-1) { #region Calculate values TemperatureColdMean = processingTemperatureMean[inputPath].Mean(); #endregion } #endregion #region Counter telegramCounterTemperatureMean[inputPath]++; #endregion } #endregion #region Moving average else { #region Remove first element processingTemperatureMean[inputPath].RemoveAt(0); #endregion #region Add last element processingTemperatureMean[inputPath].Add(temperatureCold[inputPath]); #endregion #region Calculate values TemperatureColdMean = processingTemperatureMean[inputPath].Mean(); #endregion } #endregion } catch(Exception ex) { #region Error ErrorLog.Log(LogErrReason.Exception(), "MeanCalculate.Temperature() failed", "0x" + ex.HResult.ToString("X"), "Path= " + inputPath.ToString()); #endregion } #region Return data return TemperatureColdMean; #endregion } public static DecodedData[] Flow(UInt16 inputPath, DecodedData[] inputDataFlowMean, ref UInt16[] telegramCounterFlowMean, ref List[] processingFlowMean, UInt16 numberOfValues) { #region Definitions and initializations double[] FlowMean = new double[3]; #endregion try { #region Initial fill if (telegramCounterFlowMean[inputPath] < numberOfValues) { #region Copy data to list processingFlowMean[inputPath].Add(inputDataFlowMean[inputPath].Flow); #endregion #region First calculation if (telegramCounterFlowMean[inputPath] == numberOfValues - 1) { #region Calculate values FlowMean[inputPath] = processingFlowMean[inputPath].Mean(); #endregion #region Assign to global object inputDataFlowMean[inputPath].FlowMean = FlowMean[inputPath]; #endregion } #endregion #region Counter telegramCounterFlowMean[inputPath]++; #endregion } #endregion #region Moving average else { #region Remove first element processingFlowMean[inputPath].RemoveAt(0); #endregion #region Add last element processingFlowMean[inputPath].Add(inputDataFlowMean[inputPath].Flow); #endregion #region Calculate values FlowMean[inputPath] = processingFlowMean[inputPath].Mean(); #endregion #region Assign to global object inputDataFlowMean[inputPath].FlowMean = FlowMean[inputPath]; #endregion } #endregion } catch (Exception ex) { #region Error ErrorLog.Log(LogErrReason.Exception(), "MeanCalculate.Flow() failed", "0x" + ex.HResult.ToString("X"), "Path= " + inputPath.ToString()); #endregion } #region Return data return inputDataFlowMean; #endregion } } }