fix:beta calibration table数据

This commit is contained in:
xiaoguangbin 2024-07-25 14:24:51 +08:00
parent 2e08948302
commit 566657c339

View File

@ -13,12 +13,12 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.cache.Cache;
import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.apache.commons.math3.fitting.GaussianCurveFitter;
import org.apache.commons.math3.fitting.WeightedObservedPoints;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.cache.LocalCache;
import org.jeecg.common.cache.SelfCache;
import org.jeecg.common.constant.DateConstant;
import org.jeecg.common.properties.ParameterProperties;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.system.util.JwtUtil;
@ -1742,6 +1742,9 @@ public class SelfStationServiceImpl implements ISelfStationService {
}
//Beta-Gamma Spectrum: QC 散点图相关数据
List<HistogramData> histogramDataList = new LinkedList<>();
// todo 减少数量 暂时写512
gChannels = 512;
bChannels = 512;
for (int column=0; column<gChannels; column++) {
for (int row=0; row<bChannels; row++) {
Long index = column * bChannels + row;
@ -1798,6 +1801,34 @@ public class SelfStationServiceImpl implements ISelfStationService {
// E_β=661.6-E_γE_γ=F(C)
//中心C_β=F(E_β)范围[C_β-3(C_β ), C_β+3(C_β )]
// 高斯函数拟合得到拟合的中心道址显示Energy vs. Channel
//页面展示的表单数据数组
List<TableWidget> table = new LinkedList<>();
for (int i = 0; i < oldScatterSeries.size(); i++) {
SeriseData data = oldScatterSeries.get(i);
WeightedObservedPoints points = new WeightedObservedPoints();
// 通过散点图gamma的channel拿到当前beta横向数据
List<SeriseData> seriseDatas = this.getGateGamma(5, 256, (int) data.getX(), betaDataFile);
seriseDatas.forEach(f->{
// x = beta channel, y = beta energy
double x = f.getX();
double left = x - Math.cbrt(x);
double right = x + Math.cbrt(x);
points.add(x, left, right);
});
// 使用高斯曲线拟合观测点
GaussianCurveFitter fitter = GaussianCurveFitter.create();
double[] parameters = fitter.fit(points.toList());
//表单数据信息
TableWidget tableWidget = new TableWidget();
tableWidget.setRowCount(i+1);
tableWidget.setChannel(parameters[0]);
tableWidget.setEnergy(parameters[0]);
System.out.println("table:" + parameters[0]);
table.add(tableWidget);
}
map.put("tableWidgets", table);
//判断人工交互的道值与能量对应参数数组是否为空
if (Objects.nonNull(betaDataFile.getBgPara()) && CollectionUtils.isNotEmpty(betaDataFile.getBetaList())) {
@ -2998,6 +3029,39 @@ public class SelfStationServiceImpl implements ISelfStationService {
return result;
}
private List<SeriseData> getGateGamma(int channelWidth, int chartHeight, int gammaChannel, SelfStationData betaDataFile){
List<SeriseData> serise_data = new LinkedList<>();
//选择矩形框高度
Integer flagHeight = channelWidth * (chartHeight/256);
int value = Double.valueOf(flagHeight / 2).intValue();
//计算得到最高值
int up = gammaChannel - value;
if (up<0){
up = 0;
}
//计算得到最低值
int down = up + value;
EnergySpectrumStruct struct = betaDataFile.getQcStruct();
if (Objects.nonNull(struct)) {
//Beta-Gamma Spectrum: QC
long bChannels = struct.b_channels;
List<Long> hCounts = struct.h_counts;
for ( int i=0; i<bChannels; ++i ) {
long count = 0;
for (int j=up; j<=down; ++j) {
Long index = j * bChannels + i;
count += hCounts.get(index.intValue());
}
SeriseData temp = new SeriseData();
temp.setX(i);
temp.setY(count);
serise_data.add(temp);
}
}
return serise_data;
}
@Override
@DS("ora")