Skip to content

Commit

Permalink
Mutifile Calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
Am6er committed Jan 21, 2023
1 parent 3b46aa8 commit 7059a5d
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 28 deletions.
4 changes: 2 additions & 2 deletions BecquerelMonitor/BecquerelMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<MinimumRequiredVersion>2022.07.08.7</MinimumRequiredVersion>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>index.html</WebPage>
<ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>2023.01.21.2</ApplicationVersion>
<ApplicationRevision>4</ApplicationRevision>
<ApplicationVersion>2023.01.21.4</ApplicationVersion>
<UseApplicationTrust>true</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
15 changes: 12 additions & 3 deletions BecquerelMonitor/DCEnergyCalibrationView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 62 additions & 18 deletions BecquerelMonitor/DCEnergyCalibrationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ public DCEnergyCalibrationView(MainForm mainForm)
void DCEnergyCalibrationView_Load(object sender, EventArgs e)
{
this.HideMultipointForm();
this.LoadCalibrationPoints();
}

public void LoadCalibrationPoints()
{
if (this.mainForm.ActiveDocument != null &&
this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count > 0)
{
List<CalibrationPoint> points = this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints;
foreach (CalibrationPoint point in points)
{
AddCalibration(point.Channel, point.Energy, point.Count);
}
}
}

// Token: 0x06000815 RID: 2069 RVA: 0x0002DD18 File Offset: 0x0002BF18
Expand Down Expand Up @@ -65,7 +79,7 @@ public void SetEnergyCalibration(EnergyCalibration energyCalibration, EnergyCali
this.numericUpDown4.Text = this.energyCalibration.Coefficients[4].ToString();
}
this.formLoading = false;
this.calibrationPoints.Clear();
//this.calibrationPoints.Clear();
this.ShowCalibrationPoints();
this.UpdateMultipointButtonState();
}
Expand Down Expand Up @@ -374,9 +388,16 @@ void button8_Click(object sender, EventArgs e)
// Token: 0x06000829 RID: 2089 RVA: 0x0002E478 File Offset: 0x0002C678
void UpdateMultipointButtonState()
{
this.button7.Enabled = (this.calibrationPoints.Count > 0 && !this.channelPickupProcessing && this.multipointModified);
if (this.mainForm.ActiveDocument != null)
{
this.button7.Enabled = (this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count > 0 && !this.channelPickupProcessing && this.multipointModified);
this.button9.Enabled = (this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count > 0 && !this.channelPickupProcessing);
} else
{
this.button7.Enabled = false;
this.button9.Enabled = false;
}
this.button8.Enabled = (!this.channelPickupProcessing);
this.button9.Enabled = (this.calibrationPoints.Count > 0 && !this.channelPickupProcessing);
this.button11.Enabled = this.channelPickupProcessing;
if (this.calibrationDone)
{
Expand All @@ -400,7 +421,7 @@ void energySpectrumView_ChannelPickuped(object sender, ChannelPickupedEventArgs
}
decimal energy = Math.Round((decimal)this.energyCalibration.ChannelToEnergy((double)e.Channel), 2);
CalibrationPoint item = new CalibrationPoint(e.Channel, energy, e.Count);
this.calibrationPoints.Add(item);
this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Add(item);
this.multipointModified = true;
this.calibrationDone = false;
this.ShowCalibrationPoints();
Expand All @@ -410,7 +431,7 @@ void energySpectrumView_ChannelPickuped(object sender, ChannelPickupedEventArgs
public void AddCalibration(int channel, decimal energy, int count)
{
CalibrationPoint item = new CalibrationPoint(channel, energy, count);
this.calibrationPoints.Add(item);
this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Add(item);
this.multipointModified = true;
this.calibrationDone = false;
this.ShowCalibrationPoints();
Expand Down Expand Up @@ -447,13 +468,13 @@ void button9_Click(object sender, EventArgs e)
{
num = 0;
}
if (num < 0 && num >= this.calibrationPoints.Count)
if (num < 0 && num >= this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count)
{
return;
}
try
{
this.calibrationPoints.RemoveAt(num);
this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.RemoveAt(num);
} catch
{

Expand All @@ -471,8 +492,8 @@ void ShowCalibrationPoints()
int num = 1;
this.table1.SuspendLayout();
this.tableModel1.Rows.Clear();
this.calibrationPoints.Sort();
foreach (CalibrationPoint calibrationPoint in this.calibrationPoints)
this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Sort();
foreach (CalibrationPoint calibrationPoint in this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints)
{
Row row = new Row();
row.Cells.Add(new Cell(num.ToString()));
Expand Down Expand Up @@ -508,10 +529,10 @@ void table1_EditingStopped(object sender, CellEditEventArgs e)
if (e.Column == 1)
{
string text = ((NumberCellEditor)e.Editor).TextBox.Text;
this.calibrationPoints[row.Index].Channel = (int)decimal.Parse(text);
if (this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum.Length > this.calibrationPoints[row.Index].Channel)
this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Channel = (int)decimal.Parse(text);
if (this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum.Length > this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Channel)
{
this.calibrationPoints[row.Index].Count = this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum[this.calibrationPoints[row.Index].Channel];
this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Count = this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum[this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Channel];
}
else
{
Expand All @@ -525,7 +546,7 @@ void table1_EditingStopped(object sender, CellEditEventArgs e)
else if (e.Column == 2)
{
string text2 = ((NumberCellEditor)e.Editor).TextBox.Text;
this.calibrationPoints[row.Index].Energy = decimal.Parse(text2);
this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Energy = decimal.Parse(text2);
this.multipointModified = true;
this.calibrationDone = false;
this.UpdateMultipointButtonState();
Expand All @@ -538,9 +559,35 @@ void table1_EditingStopped(object sender, CellEditEventArgs e)
}
}

void button14_Click(object sender, EventArgs e)
{
List<CalibrationPoint> points = new List<CalibrationPoint>();

if (this.mainForm.DocumentList != null)
{
foreach (DocEnergySpectrum doc in this.mainForm.DocumentList)
{
foreach(ResultData data in doc.ResultDataFile.ResultDataList)
{
if (data.CalibrationPoints.Count > 0)
{
points.AddRange(data.CalibrationPoints);
}
}
}
foreach (CalibrationPoint point in points)
{
AddCalibration(point.Channel, point.Energy, point.Count);
}
}
}

void checkBox2_Click(object sender, EventArgs e)
{
this.button7.Enabled = true;
if (this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count > 0)
{
this.button7.Enabled = true;
}
}

// Token: 0x06000831 RID: 2097 RVA: 0x0002E8C0 File Offset: 0x0002CAC0
Expand All @@ -553,7 +600,7 @@ void button7_Click(object sender, EventArgs e)

int PolynomOrder = (int)this.numericUpDown6.Value;
double[] matrix;
List<CalibrationPoint> points = this.calibrationPoints;
List<CalibrationPoint> points = this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints;
if (points.Count == 1)
{
CalibrationPoint zero = new CalibrationPoint(0, 0, 0);
Expand Down Expand Up @@ -674,8 +721,5 @@ void DCEnergyCalibrationView_SizeChanged(object sender, EventArgs e)

// Token: 0x0400041D RID: 1053
bool multipointModified;

// Token: 0x0400041E RID: 1054
List<CalibrationPoint> calibrationPoints = new List<CalibrationPoint>();
}
}
32 changes: 31 additions & 1 deletion BecquerelMonitor/DCEnergyCalibrationView.resx
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
<value>$this</value>
</data>
<data name="button9.Location" type="System.Drawing.Point, System.Drawing">
<value>159, 5</value>
<value>115, 5</value>
</data>
<data name="&gt;&gt;numericUpDown2.Parent" xml:space="preserve">
<value>groupBox1</value>
Expand Down Expand Up @@ -1131,4 +1131,34 @@
<data name="checkBox2.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Right</value>
</data>
<data name="&gt;&gt;button14.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="button14.TabIndex" type="System.Int32, mscorlib">
<value>9</value>
</data>
<data name="button14.Location" type="System.Drawing.Point, System.Drawing">
<value>185, 5</value>
</data>
<data name="&gt;&gt;button14.Name" xml:space="preserve">
<value>button14</value>
</data>
<data name="&gt;&gt;button14.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="button14.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="button14.Text" xml:space="preserve">
<value>Get all points</value>
</data>
<data name="button14.ToolTip" xml:space="preserve">
<value>Get all calibration points from all documents in this table</value>
</data>
<data name="button14.Size" type="System.Drawing.Size, System.Drawing">
<value>66, 23</value>
</data>
<data name="&gt;&gt;button14.Parent" xml:space="preserve">
<value>panel1</value>
</data>
</root>
6 changes: 6 additions & 0 deletions BecquerelMonitor/DCEnergyCalibrationView.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -687,4 +687,10 @@
<data name="checkBox2.ToolTip" xml:space="preserve">
<value>Использовать точки калибровки с весами, которые рассчитываются исходя из числа импульсов на этом канале.</value>
</data>
<data name="button14.Text" xml:space="preserve">
<value>Собрать всё</value>
</data>
<data name="button14.ToolTip" xml:space="preserve">
<value>Собрать все точки калибровки по всем открытым документам в этой таблице</value>
</data>
</root>
9 changes: 9 additions & 0 deletions BecquerelMonitor/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,7 @@ public void RefreshAllView()
if (this.dcEnergyCalibrationView != null)
{
this.dcEnergyCalibrationView.UpdateEnergyCalibrationConfig();
this.dcEnergyCalibrationView.LoadCalibrationPoints();
}
foreach (DocEnergySpectrum docEnergySpectrum in this.documentManager.DocumentList)
{
Expand Down Expand Up @@ -2431,6 +2432,14 @@ void CloseAllDocuments()
}
}

public List<DocEnergySpectrum> DocumentList
{
get
{
return this.documentManager.DocumentList;
}
}

// Token: 0x040005C7 RID: 1479
LayoutMode layoutMode;

Expand Down
4 changes: 2 additions & 2 deletions BecquerelMonitor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyVersion("2023.01.21.2")]
[assembly: AssemblyVersion("2023.01.21.4")]
[assembly: AssemblyProduct("BecquerelMonitor")]
[assembly: AssemblyCopyright("free")]
[assembly: AssemblyTrademark("none")]
[assembly: AssemblyConfiguration("")]
[assembly: Guid("40110b38-4882-47c1-ad94-a71e58dcb5f8")]
[assembly: AssemblyFileVersion("2023.01.21.2")]
[assembly: AssemblyFileVersion("2023.01.21.4")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("free")]
[assembly: CompilationRelaxations(8)]
Expand Down
15 changes: 15 additions & 0 deletions BecquerelMonitor/ResultData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ public PeakDetectionMethodConfig PeakDetectionMethodConfig
}
}

[XmlIgnore]
public List<CalibrationPoint> CalibrationPoints
{
get
{
return this.calibrationPoints;
}
set
{
this.calibrationPoints = value;
}
}

// Token: 0x170001F9 RID: 505
// (get) Token: 0x0600069B RID: 1691 RVA: 0x00027B38 File Offset: 0x00025D38
// (set) Token: 0x0600069C RID: 1692 RVA: 0x00027B40 File Offset: 0x00025D40
Expand Down Expand Up @@ -468,5 +481,7 @@ public ResultData(ResultData_097b old)

// Token: 0x04000376 RID: 886
List<Peak> calibrationPeaks = new List<Peak>();

List<CalibrationPoint> calibrationPoints = new List<CalibrationPoint>();
}
}
5 changes: 3 additions & 2 deletions BecquerelMonitor/Utils/CalibrationSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,23 @@ public static double[] SolveWeighted (List<CalibrationPoint> points, int Polynom
double[,] dense_weight = new double[points.Count, points.Count];

double max_count = 1.0;
double max_count_sqrt = 1.0;
for (int i = 0; i < points.Count; i++)
{
if (points[i].Count > max_count)
{
max_count = points[i].Count;
}
}
max_count = Math.Sqrt(max_count);
max_count_sqrt = Math.Sqrt(max_count);

for (int i = 0; i < points.Count; i++)
{
for (int j = 0; j < points.Count; j ++)
{
if (i == j)
{
dense_weight[i, j] = Math.Sqrt((double)points[i].Count) / (double)max_count;
dense_weight[i, j] = Math.Sqrt((double)points[i].Count) / max_count_sqrt;
}
else
{
Expand Down

0 comments on commit 7059a5d

Please sign in to comment.