Skip to content

Commit

Permalink
Add weighted calibration functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Am6er committed Jan 21, 2023
1 parent 7346d3c commit dedad91
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 43 deletions.
2 changes: 1 addition & 1 deletion BecquerelMonitor/BecquerelMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>index.html</WebPage>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>2023.01.19.1</ApplicationVersion>
<ApplicationVersion>2023.01.21.1</ApplicationVersion>
<UseApplicationTrust>true</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
28 changes: 16 additions & 12 deletions BecquerelMonitor/CalibrationPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace BecquerelMonitor
{
// Token: 0x020000A5 RID: 165
public class CalibrationPoint : IComparable
{
// Token: 0x1700024E RID: 590
// (get) Token: 0x06000836 RID: 2102 RVA: 0x0002FB90 File Offset: 0x0002DD90
// (set) Token: 0x06000837 RID: 2103 RVA: 0x0002FB98 File Offset: 0x0002DD98
public int Channel
{
get
Expand All @@ -20,9 +16,6 @@ public int Channel
}
}

// Token: 0x1700024F RID: 591
// (get) Token: 0x06000838 RID: 2104 RVA: 0x0002FBA4 File Offset: 0x0002DDA4
// (set) Token: 0x06000839 RID: 2105 RVA: 0x0002FBAC File Offset: 0x0002DDAC
public decimal Energy
{
get
Expand All @@ -35,23 +28,34 @@ public decimal Energy
}
}

// Token: 0x0600083A RID: 2106 RVA: 0x0002FBB8 File Offset: 0x0002DDB8
public CalibrationPoint(int channel, decimal energy)
public int Count
{
get
{
return this.count;
}
set
{
this.count = value;
}
}

public CalibrationPoint(int channel, decimal energy, int count)
{
this.channel = channel;
this.energy = energy;
this.count = count;
}

// Token: 0x0600083B RID: 2107 RVA: 0x0002FBD0 File Offset: 0x0002DDD0
public int CompareTo(object obj)
{
return this.channel.CompareTo(((CalibrationPoint)obj).Channel);
}

// Token: 0x0400043E RID: 1086
int channel;

// Token: 0x0400043F RID: 1087
decimal energy;

int count;
}
}
17 changes: 16 additions & 1 deletion BecquerelMonitor/ChannelPickupedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,28 @@ public int Channel
}
}

public int Count
{
get
{
return this.count;
}
set
{
this.count = value;
}
}

// Token: 0x0600096D RID: 2413 RVA: 0x000373C8 File Offset: 0x000355C8
public ChannelPickupedEventArgs(int channel)
public ChannelPickupedEventArgs(int channel, int count)
{
this.channel = channel;
this.count = count;
}

// Token: 0x04000542 RID: 1346
int channel;

int count;
}
}
22 changes: 16 additions & 6 deletions BecquerelMonitor/DCEnergyCalibrationView.Designer.cs

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

42 changes: 28 additions & 14 deletions BecquerelMonitor/DCEnergyCalibrationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.Remoting.Channels;
using System.Windows.Forms;
using XPTable.Editors;
using XPTable.Events;
Expand Down Expand Up @@ -398,17 +399,17 @@ void energySpectrumView_ChannelPickuped(object sender, ChannelPickupedEventArgs
return;
}
decimal energy = Math.Round((decimal)this.energyCalibration.ChannelToEnergy((double)e.Channel), 2);
CalibrationPoint item = new CalibrationPoint(e.Channel, energy);
CalibrationPoint item = new CalibrationPoint(e.Channel, energy, e.Count);
this.calibrationPoints.Add(item);
this.multipointModified = true;
this.calibrationDone = false;
this.ShowCalibrationPoints();
this.ClearChannelPickupState();
}

public void AddCalibration(int channel, decimal energy)
public void AddCalibration(int channel, decimal energy, int count)
{
CalibrationPoint item = new CalibrationPoint(channel, energy);
CalibrationPoint item = new CalibrationPoint(channel, energy, count);
this.calibrationPoints.Add(item);
this.multipointModified = true;
this.calibrationDone = false;
Expand Down Expand Up @@ -508,6 +509,15 @@ void table1_EditingStopped(object sender, CellEditEventArgs e)
{
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.calibrationPoints[row.Index].Count = this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum[this.calibrationPoints[row.Index].Channel];
}
else
{
throw new Exception(Resources.ERRCalibrationChannelExceed);
}

this.multipointModified = true;
this.calibrationDone = false;
this.UpdateMultipointButtonState();
Expand All @@ -520,21 +530,19 @@ void table1_EditingStopped(object sender, CellEditEventArgs e)
this.calibrationDone = false;
this.UpdateMultipointButtonState();
}
else if (e.Column == 4)
{
string text2 = ((NumberCellEditor)e.Editor).TextBox.Text;
this.calibrationPoints[row.Index].Energy = decimal.Parse(text2);
this.multipointModified = true;
this.calibrationDone = false;
this.UpdateMultipointButtonState();
}
}
catch (Exception)
catch (Exception ex)
{
MessageBox.Show(String.Format(Resources.ERRAddCalibrationPoints, ((NumberCellEditor)e.Editor).TextBox.Text, ex.Message), Resources.ErrorExclamation, MessageBoxButtons.OK, MessageBoxIcon.Error);
e.Cancel = true;
}
}

void checkBox2_Click(object sender, EventArgs e)
{
this.button7.Enabled = true;
}

// Token: 0x06000831 RID: 2097 RVA: 0x0002E8C0 File Offset: 0x0002CAC0
void button7_Click(object sender, EventArgs e)
{
Expand All @@ -548,13 +556,19 @@ void button7_Click(object sender, EventArgs e)
List<CalibrationPoint> points = this.calibrationPoints;
if (points.Count == 1)
{
CalibrationPoint zero = new CalibrationPoint(0, 0);
CalibrationPoint zero = new CalibrationPoint(0, 0, 0);
points.Add(zero);
PolynomOrder += 1;
}
try
{
matrix = Utils.CalibrationSolver.Solve(points, PolynomOrder);
if (this.checkBox2.Checked)
{
matrix = Utils.CalibrationSolver.SolveWeighted(points, PolynomOrder);
} else
{
matrix = Utils.CalibrationSolver.Solve(points, PolynomOrder);
}
if (matrix == null) throw new Exception("Error");
}
catch (Exception)
Expand Down
33 changes: 33 additions & 0 deletions BecquerelMonitor/DCEnergyCalibrationView.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1095,4 +1095,37 @@
<data name="checkBox1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
</data>
<data name="&gt;&gt;checkBox2.Name" xml:space="preserve">
<value>checkBox2</value>
</data>
<data name="&gt;&gt;checkBox2.Type" xml:space="preserve">
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="checkBox2.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="&gt;&gt;checkBox2.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="&gt;&gt;checkBox2.Parent" xml:space="preserve">
<value>panel1</value>
</data>
<data name="checkBox2.Size" type="System.Drawing.Size, System.Drawing">
<value>100, 16</value>
</data>
<data name="checkBox2.Text" xml:space="preserve">
<value>Weights</value>
</data>
<data name="checkBox2.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="checkBox2.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="checkBox2.Location" type="System.Drawing.Point, System.Drawing">
<value>360, 30</value>
</data>
<data name="checkBox2.ToolTip" xml:space="preserve">
<value>Use calibration points weights, which depends from counts in channel.</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 @@ -681,4 +681,10 @@
<data name="textColumn1.Text" xml:space="preserve">
<value>#</value>
</data>
<data name="checkBox2.Text" xml:space="preserve">
<value>Веса</value>
</data>
<data name="checkBox2.ToolTip" xml:space="preserve">
<value>Использовать точки калибровки с весами, которые рассчитываются исходя из числа импульсов на этом канале.</value>
</data>
</root>
9 changes: 8 additions & 1 deletion BecquerelMonitor/DCPeakDetectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ void ToolStripMenuItem1_Click(object sender, EventArgs e)
diff = 0;
}
energy = Convert.ToDecimal(row.Cells[1].Text) - diff;
this.mainForm.addCalibration(channel, energy);
if (this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum.Length > channel)
{
this.mainForm.addCalibration(channel, energy, this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum[channel]);
} else
{
throw new Exception(Resources.ERRCalibrationChannelExceed);
}

} catch (Exception ex)
{
MessageBox.Show(String.Format(Resources.ERRAddCalibrationPoints, channel.ToString(), ex.Message), Resources.ErrorExclamation, MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down
4 changes: 2 additions & 2 deletions BecquerelMonitor/DeviceConfigForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ void energySpectrumView_ChannelPickuped(object sender, ChannelPickupedEventArgs
return;
}
decimal energy = Math.Round((decimal)this.activeDeviceConfig.EnergyCalibration.ChannelToEnergy((double)e.Channel), 2);
CalibrationPoint item = new CalibrationPoint(e.Channel, energy);
CalibrationPoint item = new CalibrationPoint(e.Channel, energy, e.Count);
this.calibrationPoints.Add(item);
this.multipointModified = true;
this.calibrationDone = false;
Expand Down Expand Up @@ -1263,7 +1263,7 @@ void button1_Click(object sender, EventArgs e)
List<CalibrationPoint> points = this.calibrationPoints;
if (points.Count == 1)
{
CalibrationPoint zero = new CalibrationPoint(0, 0);
CalibrationPoint zero = new CalibrationPoint(0, 0, 0);
points.Add(zero);
}
try
Expand Down
2 changes: 1 addition & 1 deletion BecquerelMonitor/EnergySpectrumView.Designer.cs

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

4 changes: 2 additions & 2 deletions BecquerelMonitor/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,9 @@ public DeviceConfigForm ShowDeviceConfigForm(DeviceConfigInfo config)
return this.deviceConfigForm;
}

public void addCalibration(int channel, decimal energy)
public void addCalibration(int channel, decimal energy, int count)
{
this.dcEnergyCalibrationView.AddCalibration(channel, energy);
this.dcEnergyCalibrationView.AddCalibration(channel, energy, count);
}

// Token: 0x06000A6E RID: 2670 RVA: 0x0003E0BC File Offset: 0x0003C2BC
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.19.1")]
[assembly: AssemblyVersion("2023.01.21.1")]
[assembly: AssemblyProduct("BecquerelMonitor")]
[assembly: AssemblyCopyright("free")]
[assembly: AssemblyTrademark("none")]
[assembly: AssemblyConfiguration("")]
[assembly: Guid("40110b38-4882-47c1-ad94-a71e58dcb5f8")]
[assembly: AssemblyFileVersion("2023.01.19.1")]
[assembly: AssemblyFileVersion("2023.01.21.1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("free")]
[assembly: CompilationRelaxations(8)]
Expand Down
9 changes: 9 additions & 0 deletions BecquerelMonitor/Properties/Resources.Designer.cs

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

5 changes: 4 additions & 1 deletion BecquerelMonitor/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3827,7 +3827,7 @@ http://xptable.sourceforge.net/</value>
<data name="icon256" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAABMYAAAPaCAIAAADz3MP1AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
wQAADsEBuJFr7QAA/7JJREFUeF7M/YeXbEeV7Y3y3ruNjvdVdbz33sp774UskkAOhISQQHhoGt/duKYB
wAAADsABataJCQAA/7JJREFUeF7M/YeXbEeV7Y3y3ruNjvdVdbz33sp774UskkAOhISQQHhoGt/duKYB
AY3rS7vX9xvfuH/l99v7lzlrVeydec5R0/e9MebYY8WMGSti76yMWPNkVp2PrNu0a4j1m3eDIbNhy56A
5tqNO9ds2LF6/faqERkYIA6isakApjaFzCwwOyCoQ+qoxCqdN6hDRpEkirly4xu37rU3eeydg1mLXL1p
55rNu4ZYu2W3AYJoIOvDN2AxoK6kgiFi3dY9YP22vcLmtcMFDNHIgg0L+7wF4k1LBzZvPyizbmEvWL+4
Expand Down Expand Up @@ -36873,4 +36873,7 @@ see peak in spectrum now).</value>
<data name="ProgressDateFmt" xml:space="preserve">
<value>d\d\ hh\:mm\:ss</value>
</data>
<data name="ERRCalibrationChannelExceed" xml:space="preserve">
<value>The selected channel exceeds the size of the spectrum</value>
</data>
</root>
Loading

0 comments on commit dedad91

Please sign in to comment.