[no commit message]
This commit is contained in:
parent
cd8562abc0
commit
94dba3b02e
@ -7,10 +7,6 @@ mainClassName = mainClass
|
|||||||
|
|
||||||
description = """The main head of all numass projects"""
|
description = """The main head of all numass projects"""
|
||||||
|
|
||||||
ext{
|
|
||||||
defaultNumassPath = 'D:\\loss-2011\\'
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile group: 'commons-cli', name: 'commons-cli', version:'1.+'
|
compile group: 'commons-cli', name: 'commons-cli', version:'1.+'
|
||||||
compile group: 'commons-io', name: 'commons-io', version:'2.+'
|
compile group: 'commons-io', name: 'commons-io', version:'2.+'
|
||||||
@ -20,22 +16,12 @@ dependencies {
|
|||||||
compile project(':numass-storage')
|
compile project(':numass-storage')
|
||||||
}
|
}
|
||||||
|
|
||||||
task runNumass(dependsOn: classes, type : JavaExec){
|
task workbench(dependsOn: classes, type: JavaExec){
|
||||||
main mainClass
|
main 'inr.numass.workbench.Workbench'
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
workingDir defaultNumassPath
|
description "start visual numass workbench"
|
||||||
description "run Main method in the current numass working directory"
|
|
||||||
group "numass"
|
|
||||||
}
|
|
||||||
|
|
||||||
task debugNumass(dependsOn: classes, type: JavaExec) {
|
|
||||||
main mainClass
|
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
|
||||||
workingDir defaultNumassPath
|
|
||||||
ignoreExitValue = true
|
|
||||||
debug = true
|
|
||||||
description "debug Main method in the current numass working directory"
|
|
||||||
group "numass"
|
group "numass"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task listActions(dependsOn: classes, type: JavaExec) {
|
task listActions(dependsOn: classes, type: JavaExec) {
|
||||||
|
0
numass-main/nbproject/project.properties
Normal file
0
numass-main/nbproject/project.properties
Normal file
@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Alexander Nozik.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package inr.numass.scripts
|
|
||||||
|
|
||||||
import hep.dataforge.datafitter.ParamSet
|
|
||||||
import hep.dataforge.io.FittingIOUtils
|
|
||||||
import hep.dataforge.io.PrintFunction
|
|
||||||
import hep.dataforge.maths.NamedDoubleArray
|
|
||||||
import hep.dataforge.maths.NamedDoubleSet
|
|
||||||
import hep.dataforge.maths.NamedMatrix
|
|
||||||
import hep.dataforge.plots.PlotFrame
|
|
||||||
import hep.dataforge.plots.data.PlottableFunction
|
|
||||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame
|
|
||||||
import inr.numass.actions.ShowLossSpectrumAction;
|
|
||||||
import inr.numass.models.ExperimentalVariableLossSpectrum
|
|
||||||
import inr.numass.models.LossCalculator
|
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction
|
|
||||||
|
|
||||||
|
|
||||||
NamedDoubleSet transformOldMeans(NamedDoubleSet old){
|
|
||||||
String[] names = ["exPos", "ionPos", "exW", "ionW", "exIonRatio"];
|
|
||||||
double[] values = new double[5];
|
|
||||||
values[0] = old.getValue("loss_pos1");
|
|
||||||
values[1] = old.getValue("loss_pos2");
|
|
||||||
values[2] = old.getValue("loss_w1");
|
|
||||||
values[3] = old.getValue("loss_w2");
|
|
||||||
values[4] = old.getValue("loss_A1") / old.getValue("loss_A2");
|
|
||||||
|
|
||||||
return new NamedDoubleArray(names, values);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ParamSet transformOldParams(ParamSet old){
|
|
||||||
String[] names = ["exPos", "ionPos", "exW", "ionW", "exIonRatio"];
|
|
||||||
ParamSet res = new ParamSet(names);
|
|
||||||
|
|
||||||
res.setPar("exPos", old.getValue("loss_pos1"), old.getError("loss_pos1"));
|
|
||||||
res.setPar("ionPos", old.getValue("loss_pos2"), old.getError("loss_pos2"));
|
|
||||||
res.setPar("exW", old.getValue("loss_w1"), old.getError("loss_w1"));
|
|
||||||
res.setPar("ionW", old.getValue("loss_w2"), old.getError("loss_w2"));
|
|
||||||
|
|
||||||
double ratioValue = old.getValue("loss_A1") / old.getValue("loss_A2");
|
|
||||||
|
|
||||||
double a1RelErr = old.getError("loss_A1") / old.getValue("loss_A1");
|
|
||||||
double a2RelErr = old.getError("loss_A2") / old.getValue("loss_A2");
|
|
||||||
double ratioErr = Math.sqrt(a1RelErr*a1RelErr + a2RelErr*a2RelErr)*ratioValue;
|
|
||||||
res.setPar("exIonRatio", ratioValue, ratioErr);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintWriter out = new PrintWriter(System.out);
|
|
||||||
|
|
||||||
String name = "log14_h2_new"
|
|
||||||
//String name = "log18_long"
|
|
||||||
//String name = "log25_long"
|
|
||||||
|
|
||||||
OldFitResultReader reader = new OldFitResultReader();
|
|
||||||
reader.readFile(new File("C:\\Users\\darksnake\\Dropbox\\Numass\\Analysis\\loss-2014_november\\old_loss\\results\\final\\${name}.txt"));
|
|
||||||
|
|
||||||
double threshold = 17d;
|
|
||||||
|
|
||||||
ParamSet means = transformOldParams (reader.getParamSet());
|
|
||||||
|
|
||||||
double ionRatio = ShowLossSpectrumAction.calcultateIonRatio(means, threshold);
|
|
||||||
NamedMatrix cov = NamedMatrix.diagonal(means.getParErrors());
|
|
||||||
double ionRatioError = ShowLossSpectrumAction.calultateIonRatioError(name, means, cov, threshold);
|
|
||||||
|
|
||||||
println String.format("The ionization ratio (using threshold %f) is %f%n", threshold, ionRatio);
|
|
||||||
println String.format("The ionization ratio standard deviation (using threshold %f) is %f%n", threshold, ionRatioError);
|
|
||||||
println "*** FIT RESULT ***"
|
|
||||||
|
|
||||||
FittingIOUtils.printParamSet(out, means);
|
|
||||||
|
|
||||||
println means.toString();
|
|
||||||
|
|
||||||
UnivariateFunction scatterFunction = LossCalculator.getSingleScatterFunction(means);
|
|
||||||
PlotFrame frame = JFreeChartFrame.drawFrame("Differential scattering crossection for "+name, null);
|
|
||||||
frame.add(new PlottableFunction("Cross-section", null, scatterFunction, 0, 100, 1000));
|
|
||||||
|
|
||||||
PrintFunction.printFunctionSimple(out, scatterFunction, 0, 100, 500);
|
|
@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Alexander Nozik.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package inr.numass.scripts
|
|
||||||
|
|
||||||
import hep.dataforge.datafitter.ParamSet
|
|
||||||
import hep.dataforge.maths.NamedDoubleArray
|
|
||||||
import hep.dataforge.maths.NamedDoubleSet
|
|
||||||
import hep.dataforge.maths.NamedMatrix
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
import org.apache.commons.math3.linear.Array2DRowRealMatrix
|
|
||||||
import org.apache.commons.math3.linear.RealMatrix
|
|
||||||
import java.util.Scanner
|
|
||||||
import java.util.regex.Matcher
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author darksnake
|
|
||||||
*/
|
|
||||||
class OldFitResultReader {
|
|
||||||
private static Pattern meanPattern = ~/\"(?<name>.*)\"\s*:\s*(?<value>[\d.]*)\s*/;
|
|
||||||
|
|
||||||
private NamedDoubleSet means;
|
|
||||||
private RealMatrix covariance;
|
|
||||||
|
|
||||||
void readMeans(String input){
|
|
||||||
Scanner scan = new Scanner(input);
|
|
||||||
List<String> names = new ArrayList<>();
|
|
||||||
List<Double> values = new ArrayList<>();
|
|
||||||
while(scan.hasNextLine()){
|
|
||||||
String nextLine = scan.nextLine();
|
|
||||||
if(!nextLine.isEmpty()){
|
|
||||||
Matcher match = meanPattern.matcher(nextLine);
|
|
||||||
match.matches();
|
|
||||||
names << match.group("name");
|
|
||||||
values << Double.parseDouble(match.group("value"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.means = new NamedDoubleArray(names.toArray(new String[names.size()]), values.toArray(new double[values.size()]));
|
|
||||||
}
|
|
||||||
|
|
||||||
void readCovariance(String input){
|
|
||||||
Scanner scan = new Scanner(input);
|
|
||||||
List<List<Double>> matrix = new ArrayList<>();
|
|
||||||
while(scan.hasNextLine()){
|
|
||||||
String nextLine = scan.nextLine();
|
|
||||||
if(!nextLine.isEmpty()){
|
|
||||||
Scanner lineScan = new Scanner(nextLine);
|
|
||||||
List<Double> line = new ArrayList<>();
|
|
||||||
while(lineScan.hasNextDouble()){
|
|
||||||
line << lineScan.nextDouble();
|
|
||||||
}
|
|
||||||
matrix << line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Array2DRowRealMatrix result = new Array2DRowRealMatrix(matrix.size(),matrix.size());
|
|
||||||
for(int i = 0; i< matrix.size; i++){
|
|
||||||
List<Double> line = matrix.get(i);
|
|
||||||
for(int j = 0; j< matrix.size; j++){
|
|
||||||
result.setEntry(i,j,line[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.covariance = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void readFile(File file){
|
|
||||||
String text = file.getText();
|
|
||||||
Pattern pattern = Pattern.compile(/.*The best fit values are:\s*(?<parameters>.*)Covariation marix:\s*(?<covariance>.*)Best Likelihood logarithm/, Pattern.DOTALL);
|
|
||||||
List results = text.findAll(pattern);
|
|
||||||
|
|
||||||
String res = results.get(results.size()-1);
|
|
||||||
Matcher match = pattern.matcher(res);
|
|
||||||
match.matches();
|
|
||||||
readMeans(match.group("parameters"));
|
|
||||||
readCovariance(match.group("covariance"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NamedDoubleSet getMeans(){
|
|
||||||
return means;
|
|
||||||
}
|
|
||||||
|
|
||||||
ParamSet getParamSet(){
|
|
||||||
ParamSet res = new ParamSet();
|
|
||||||
NamedMatrix cov = getCovariance();
|
|
||||||
for(String name: means.names()){
|
|
||||||
res.setPar(name, means.getValue(name), Math.sqrt(Math.abs(cov.getElement(name, name))));
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
NamedMatrix getCovariance(){
|
|
||||||
return new NamedMatrix(covariance, means.namesAsArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -40,6 +40,9 @@ import org.apache.commons.cli.Options;
|
|||||||
import org.apache.commons.cli.ParseException;
|
import org.apache.commons.cli.ParseException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -17,6 +17,7 @@ package inr.numass;
|
|||||||
|
|
||||||
import hep.dataforge.actions.ActionManager;
|
import hep.dataforge.actions.ActionManager;
|
||||||
import hep.dataforge.context.Context;
|
import hep.dataforge.context.Context;
|
||||||
|
import hep.dataforge.context.GlobalContext;
|
||||||
import hep.dataforge.description.ActionDescriptor;
|
import hep.dataforge.description.ActionDescriptor;
|
||||||
import hep.dataforge.description.DescriptorFormatter;
|
import hep.dataforge.description.DescriptorFormatter;
|
||||||
import hep.dataforge.description.DescriptorUtils;
|
import hep.dataforge.description.DescriptorUtils;
|
||||||
@ -25,6 +26,7 @@ import hep.dataforge.exceptions.DescriptorException;
|
|||||||
import hep.dataforge.maths.integration.GaussRuleIntegrator;
|
import hep.dataforge.maths.integration.GaussRuleIntegrator;
|
||||||
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
|
import inr.numass.storage.SetDirectionUtility;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,8 +54,11 @@ public class NumassContext extends Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
setIO(new NumassIO());
|
GlobalContext.registerContext(this);
|
||||||
|
loadPlugin("hep.dataforge:actions");
|
||||||
loadPlugin("inr.numass:numass");
|
loadPlugin("inr.numass:numass");
|
||||||
|
setIO(new NumassIO());
|
||||||
|
SetDirectionUtility.load(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printDescription(Context context, boolean allowANSI) throws DescriptorException {
|
public static void printDescription(Context context, boolean allowANSI) throws DescriptorException {
|
||||||
@ -75,4 +80,10 @@ public class NumassContext extends Context {
|
|||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
SetDirectionUtility.save(this);
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,18 +60,18 @@ public class NumassIO extends BasicIOManager {
|
|||||||
|
|
||||||
String dirName = String.join(File.separator, tokens);
|
String dirName = String.join(File.separator, tokens);
|
||||||
String fileName = name.removeNameSpace().toString() + ".out";
|
String fileName = name.removeNameSpace().toString() + ".out";
|
||||||
return buildOut(getOutputDir(), dirName, fileName);
|
return buildOut(getWorkDirectory(), dirName, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getOutputDir() {
|
// private File getOutputDir() {
|
||||||
String outputDirPath = getContext().getString(NUMASS_OUTPUT_CONTEXT_KEY, ".dataforge");
|
// String outputDirPath = getContext().getString(NUMASS_OUTPUT_CONTEXT_KEY, ".");
|
||||||
File res = new File(getRootDirectory(), outputDirPath);
|
// File res = new File(getRootDirectory(), outputDirPath);
|
||||||
if (!res.exists()) {
|
// if (!res.exists()) {
|
||||||
res.mkdir();
|
// res.mkdir();
|
||||||
}
|
// }
|
||||||
return res;
|
// return res;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
protected OutputStream buildOut(File parentDir, String dirName, String fileName) {
|
protected OutputStream buildOut(File parentDir, String dirName, String fileName) {
|
||||||
File outputFile;
|
File outputFile;
|
||||||
|
@ -111,15 +111,27 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
|
|||||||
} else {
|
} else {
|
||||||
pb.putValue("Monitor", corrFactor);
|
pb.putValue("Monitor", corrFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
pb.putValue("CR", Value.of(dp.getValue("CR").doubleValue() / corrFactor));
|
pb.putValue("CR", Value.of(dp.getValue("CR").doubleValue() / corrFactor));
|
||||||
pb.putValue("Window", Value.of(dp.getValue("Window").doubleValue() / corrFactor));
|
pb.putValue("Window", Value.of(dp.getValue("Window").doubleValue() / corrFactor));
|
||||||
pb.putValue("Corrected", Value.of(dp.getValue("Corrected").doubleValue() / corrFactor));
|
pb.putValue("Corrected", Value.of(dp.getValue("Corrected").doubleValue() / corrFactor));
|
||||||
pb.putValue("CRerr", Value.of(err));
|
pb.putValue("CRerr", Value.of(err));
|
||||||
|
} else {
|
||||||
|
double corrFactor = dp.getValue("CR").doubleValue() / norm;
|
||||||
|
if (dp.names().contains("Monitor")) {
|
||||||
|
pb.putValue("Monitor", Value.of(dp.getValue("Monitor").doubleValue() / corrFactor));
|
||||||
|
} else {
|
||||||
|
pb.putValue("Monitor", corrFactor);
|
||||||
|
}
|
||||||
|
pb.putValue("CR", norm);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.getBoolean("calculateRelative", false)) {
|
if (meta.getBoolean("calculateRelative", false)) {
|
||||||
pb.putValue("relCR", pb.build().getValue("CR").doubleValue() / norm);
|
pb.putValue("relCR", pb.build().getValue("CR").doubleValue() / norm);
|
||||||
pb.putValue("relCRerr", pb.build().getValue("CRerr").doubleValue() / norm);
|
pb.putValue("relCRerr", pb.build().getValue("CRerr").doubleValue() / norm);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataList.add(pb.build());
|
dataList.add(pb.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,10 +33,13 @@ import hep.dataforge.tables.TableFormat;
|
|||||||
import inr.numass.storage.NMPoint;
|
import inr.numass.storage.NMPoint;
|
||||||
import inr.numass.storage.NumassData;
|
import inr.numass.storage.NumassData;
|
||||||
import inr.numass.storage.RawNMPoint;
|
import inr.numass.storage.RawNMPoint;
|
||||||
|
import inr.numass.utils.ExpressionUtils;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -46,6 +49,8 @@ import java.util.List;
|
|||||||
@ValueDef(name = "lowerWindow", type = "NUMBER", def = "0", info = "Base for the window lowerWindow bound")
|
@ValueDef(name = "lowerWindow", type = "NUMBER", def = "0", info = "Base for the window lowerWindow bound")
|
||||||
@ValueDef(name = "lowerWindowSlope", type = "NUMBER", def = "0", info = "Slope for the window lowerWindow bound")
|
@ValueDef(name = "lowerWindowSlope", type = "NUMBER", def = "0", info = "Slope for the window lowerWindow bound")
|
||||||
@ValueDef(name = "upperWindow", type = "NUMBER", info = "Upper bound for window")
|
@ValueDef(name = "upperWindow", type = "NUMBER", info = "Upper bound for window")
|
||||||
|
@ValueDef(name = "correction",
|
||||||
|
info = "An expression to correct coun tumber depending on potential U, count rate CR and point length T")
|
||||||
@ValueDef(name = "deadTime", type = "NUMBER", def = "0", info = "Dead time in us")
|
@ValueDef(name = "deadTime", type = "NUMBER", def = "0", info = "Dead time in us")
|
||||||
public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
|
public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
|
||||||
|
|
||||||
@ -55,7 +60,7 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
|
|||||||
double b = meta.getDouble("lowerWindow", 0);
|
double b = meta.getDouble("lowerWindow", 0);
|
||||||
double a = meta.getDouble("lowerWindowSlope", 0);
|
double a = meta.getDouble("lowerWindowSlope", 0);
|
||||||
|
|
||||||
return (int) (b + Uset * a);
|
return Math.max((int) (b + Uset * a), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,13 +82,26 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
|
|||||||
int a = getLowerBorder(meta, Uset);
|
int a = getLowerBorder(meta, Uset);
|
||||||
int b = Math.min(upper, RawNMPoint.MAX_CHANEL);
|
int b = Math.min(upper, RawNMPoint.MAX_CHANEL);
|
||||||
|
|
||||||
// analyzer.setMonitorCorrector(corrector);
|
// count in window
|
||||||
long wind = point.getCountInWindow(a, b);
|
long wind = point.getCountInWindow(a, b);
|
||||||
|
|
||||||
|
// count in window with deadTime applied
|
||||||
double corr = point.getCountRate(a, b, deadTime) * point.getLength();// - bkg * (b - a);
|
double corr = point.getCountRate(a, b, deadTime) * point.getLength();// - bkg * (b - a);
|
||||||
|
|
||||||
|
// count rate after all corrections
|
||||||
double cr = point.getCountRate(a, b, deadTime);
|
double cr = point.getCountRate(a, b, deadTime);
|
||||||
|
// count rate error after all corrections
|
||||||
double crErr = point.getCountRateErr(a, b, deadTime);
|
double crErr = point.getCountRateErr(a, b, deadTime);
|
||||||
|
|
||||||
|
if(meta.hasValue("correction")){
|
||||||
|
Map<String,Double> exprParams = new HashMap<>();
|
||||||
|
exprParams.put("U", point.getUread());
|
||||||
|
exprParams.put("CR", cr);
|
||||||
|
exprParams.put("T", time);
|
||||||
|
double correctionFactor = ExpressionUtils.evaluate(meta.getString("correction"), exprParams);
|
||||||
|
cr = cr*correctionFactor;
|
||||||
|
crErr = crErr*correctionFactor;
|
||||||
|
}
|
||||||
|
|
||||||
Instant timestamp = point.getStartTime();
|
Instant timestamp = point.getStartTime();
|
||||||
|
|
||||||
|
@ -80,9 +80,5 @@ public class ReadNumassStorageAction extends GenericAction<Void, NumassData> {
|
|||||||
throw new RuntimeException("Failed to load storage", ex);
|
throw new RuntimeException("Failed to load storage", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import hep.dataforge.io.ColumnedDataWriter;
|
|||||||
import hep.dataforge.io.PrintFunction;
|
import hep.dataforge.io.PrintFunction;
|
||||||
import hep.dataforge.io.reports.Reportable;
|
import hep.dataforge.io.reports.Reportable;
|
||||||
import hep.dataforge.maths.GridCalculator;
|
import hep.dataforge.maths.GridCalculator;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import hep.dataforge.maths.NamedMatrix;
|
import hep.dataforge.maths.NamedMatrix;
|
||||||
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
||||||
import hep.dataforge.meta.Laminate;
|
import hep.dataforge.meta.Laminate;
|
||||||
@ -41,6 +40,7 @@ import hep.dataforge.tables.ListTable;
|
|||||||
import hep.dataforge.tables.MapPoint;
|
import hep.dataforge.tables.MapPoint;
|
||||||
import hep.dataforge.tables.Table;
|
import hep.dataforge.tables.Table;
|
||||||
import hep.dataforge.tables.XYAdapter;
|
import hep.dataforge.tables.XYAdapter;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import inr.numass.NumassContext;
|
import inr.numass.NumassContext;
|
||||||
import inr.numass.models.ExperimentalVariableLossSpectrum;
|
import inr.numass.models.ExperimentalVariableLossSpectrum;
|
||||||
import inr.numass.models.LossCalculator;
|
import inr.numass.models.LossCalculator;
|
||||||
@ -129,7 +129,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// double integralThreshold = reader.getDouble("numass.eGun", 19005d) - reader.getDouble("integralThreshold", 14.82);
|
// double integralThreshold = reader.getDouble("numass.eGun", 19005d) - reader.getDouble("integralThreshold", 14.82);
|
||||||
// double integralRatio = calculateIntegralExIonRatio(input.getDataSet(), input.getParameters().getValue("X"), integralThreshold);
|
// double integralRatio = calculateIntegralExIonRatio(input.getDataSet(), input.getParameters().getDouble("X"), integralThreshold);
|
||||||
// writer.printf("The excitation to ionization ratio from integral spectrum (using threshold %f) is %f%n", integralThreshold, integralRatio);
|
// writer.printf("The excitation to ionization ratio from integral spectrum (using threshold %f) is %f%n", integralThreshold, integralRatio);
|
||||||
writer.println();
|
writer.println();
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double calcultateIonRatio(NamedDoubleSet set, double threshold) {
|
public static double calcultateIonRatio(NamedValueSet set, double threshold) {
|
||||||
UnivariateIntegrator integrator = NumassContext.highDensityIntegrator;
|
UnivariateIntegrator integrator = NumassContext.highDensityIntegrator;
|
||||||
UnivariateFunction integrand = LossCalculator.getSingleScatterFunction(set);
|
UnivariateFunction integrand = LossCalculator.getSingleScatterFunction(set);
|
||||||
return 1d - integrator.integrate(integrand, 5d, threshold);
|
return 1d - integrator.integrate(integrand, 5d, threshold);
|
||||||
@ -211,7 +211,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("Unchecked")
|
@SuppressWarnings("Unchecked")
|
||||||
public double calultateIonRatioError(Context context, String name, NamedDoubleSet parameters, NamedMatrix covariance, double threshold) {
|
public double calultateIonRatioError(Context context, String name, NamedValueSet parameters, NamedMatrix covariance, double threshold) {
|
||||||
int number = 10000;
|
int number = 10000;
|
||||||
|
|
||||||
double[] res = new GaussianParameterGenerator(parameters, covariance)
|
double[] res = new GaussianParameterGenerator(parameters, covariance)
|
||||||
@ -233,7 +233,7 @@ public class ShowLossSpectrumAction extends OneToOneAction<FitState, FitState> {
|
|||||||
return new DescriptiveStatistics(res).getStandardDeviation();
|
return new DescriptiveStatistics(res).getStandardDeviation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Table generateSpread(PrintWriter writer, String name, NamedDoubleSet parameters, NamedMatrix covariance) {
|
public static Table generateSpread(PrintWriter writer, String name, NamedValueSet parameters, NamedMatrix covariance) {
|
||||||
int numCalls = 1000;
|
int numCalls = 1000;
|
||||||
int gridPoints = 200;
|
int gridPoints = 200;
|
||||||
double a = 8;
|
double a = 8;
|
||||||
|
@ -80,7 +80,7 @@ public class SummaryAction extends ManyToOneAction<FitState, Table> {
|
|||||||
Value[] values = new Value[names.length];
|
Value[] values = new Value[names.length];
|
||||||
values[0] = Value.of(key);
|
values[0] = Value.of(key);
|
||||||
for (int i = 0; i < parNames.length; i++) {
|
for (int i = 0; i < parNames.length; i++) {
|
||||||
Value val = Value.of(state.getParameters().getValue(parNames[i]));
|
Value val = Value.of(state.getParameters().getDouble(parNames[i]));
|
||||||
values[2 * i + 1] = val;
|
values[2 * i + 1] = val;
|
||||||
Value err = Value.of(state.getParameters().getError(parNames[i]));
|
Value err = Value.of(state.getParameters().getError(parNames[i]));
|
||||||
values[2 * i + 2] = err;
|
values[2 * i + 2] = err;
|
||||||
|
@ -17,10 +17,10 @@ package inr.numass.data;
|
|||||||
|
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import static hep.dataforge.maths.MatrixOperations.inverse;
|
import static hep.dataforge.maths.MatrixOperations.inverse;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import hep.dataforge.maths.NamedMatrix;
|
import hep.dataforge.maths.NamedMatrix;
|
||||||
import hep.dataforge.tables.DataPoint;
|
import hep.dataforge.tables.DataPoint;
|
||||||
import hep.dataforge.tables.ListTable;
|
import hep.dataforge.tables.ListTable;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import inr.numass.utils.TritiumUtils;
|
import inr.numass.utils.TritiumUtils;
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
||||||
@ -38,7 +38,7 @@ public class SpectrumInformation {
|
|||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamedMatrix getExpetedCovariance(NamedDoubleSet set, ListTable data, String... parNames) {
|
public NamedMatrix getExpetedCovariance(NamedValueSet set, ListTable data, String... parNames) {
|
||||||
String[] names = parNames;
|
String[] names = parNames;
|
||||||
if (names.length == 0) {
|
if (names.length == 0) {
|
||||||
names = source.namesAsArray();
|
names = source.namesAsArray();
|
||||||
@ -56,7 +56,7 @@ public class SpectrumInformation {
|
|||||||
* @param parNames
|
* @param parNames
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public NamedMatrix getInformationMatrix(NamedDoubleSet set, ListTable data, String... parNames) {
|
public NamedMatrix getInformationMatrix(NamedValueSet set, ListTable data, String... parNames) {
|
||||||
SpectrumDataAdapter reader = TritiumUtils.adapter();
|
SpectrumDataAdapter reader = TritiumUtils.adapter();
|
||||||
|
|
||||||
String[] names = parNames;
|
String[] names = parNames;
|
||||||
@ -80,11 +80,11 @@ public class SpectrumInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// формула правильная!
|
// формула правильная!
|
||||||
public double getPoinSignificance(NamedDoubleSet set, String name1, String name2, double x) {
|
public double getPoinSignificance(NamedValueSet set, String name1, String name2, double x) {
|
||||||
return source.derivValue(name1, x, set) * source.derivValue(name2, x, set) / source.value(x, set);
|
return source.derivValue(name1, x, set) * source.derivValue(name2, x, set) / source.value(x, set);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamedMatrix getPointInfoMatrix(NamedDoubleSet set, double x, double t, String... parNames) {
|
public NamedMatrix getPointInfoMatrix(NamedValueSet set, double x, double t, String... parNames) {
|
||||||
assert source.names().contains(set.namesAsArray());
|
assert source.names().contains(set.namesAsArray());
|
||||||
|
|
||||||
String[] names = parNames;
|
String[] names = parNames;
|
||||||
@ -119,7 +119,7 @@ public class SpectrumInformation {
|
|||||||
* @param name2
|
* @param name2
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnivariateFunction getSignificanceFunction(final NamedDoubleSet set, final String name1, final String name2) {
|
public UnivariateFunction getSignificanceFunction(final NamedValueSet set, final String name1, final String name2) {
|
||||||
return (double d) -> getPoinSignificance(set, name1, name2, d);
|
return (double d) -> getPoinSignificance(set, name1, name2, d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,8 @@ package inr.numass.models;
|
|||||||
|
|
||||||
import hep.dataforge.exceptions.NotDefinedException;
|
import hep.dataforge.exceptions.NotDefinedException;
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
import hep.dataforge.values.ValueProvider;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
import static java.lang.Math.exp;
|
import static java.lang.Math.exp;
|
||||||
@ -89,11 +90,11 @@ public class BetaSpectrum extends AbstractParametricFunction implements RangedNa
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
double derivRootsterile(String name, double E, NamedDoubleSet pars) throws NotDefinedException {
|
double derivRootsterile(String name, double E, ValueProvider pars) throws NotDefinedException {
|
||||||
double E0 = pars.getValue("E0");
|
double E0 = pars.getDouble("E0");
|
||||||
double mnu2 = pars.getValue("mnu2");
|
double mnu2 = pars.getDouble("mnu2");
|
||||||
double mst2 = pars.getValue("msterile2");
|
double mst2 = pars.getDouble("msterile2");
|
||||||
double u2 = pars.getValue("U2");
|
double u2 = pars.getDouble("U2");
|
||||||
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "E0":
|
case "E0":
|
||||||
@ -117,7 +118,7 @@ public class BetaSpectrum extends AbstractParametricFunction implements RangedNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String name, double E, NamedDoubleSet pars) throws NotDefinedException {
|
public double derivValue(String name, double E, NamedValueSet pars) throws NotDefinedException {
|
||||||
if (this.fss == null) {
|
if (this.fss == null) {
|
||||||
return this.derivRootsterile(name, E, pars);
|
return this.derivRootsterile(name, E, pars);
|
||||||
}
|
}
|
||||||
@ -137,12 +138,12 @@ public class BetaSpectrum extends AbstractParametricFunction implements RangedNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double max(NamedDoubleSet set) {
|
public Double max(NamedValueSet set) {
|
||||||
return set.getValue("E0");
|
return set.getDouble("E0");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double min(NamedDoubleSet set) {
|
public Double min(NamedValueSet set) {
|
||||||
return 0d;
|
return 0d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,11 +185,11 @@ public class BetaSpectrum extends AbstractParametricFunction implements RangedNa
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
double rootsterile(double E, NamedDoubleSet pars) {
|
double rootsterile(double E, ValueProvider pars) {
|
||||||
double E0 = pars.getValue("E0");
|
double E0 = pars.getDouble("E0");
|
||||||
double mnu2 = pars.getValue("mnu2");
|
double mnu2 = pars.getDouble("mnu2");
|
||||||
double mst2 = pars.getValue("msterile2");
|
double mst2 = pars.getDouble("msterile2");
|
||||||
double u2 = pars.getValue("U2");
|
double u2 = pars.getDouble("U2");
|
||||||
|
|
||||||
if (u2 == 0) {
|
if (u2 == 0) {
|
||||||
return root(E0, mnu2, E);
|
return root(E0, mnu2, E);
|
||||||
@ -206,7 +207,7 @@ public class BetaSpectrum extends AbstractParametricFunction implements RangedNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double E, NamedDoubleSet pars) {
|
public double value(double E, NamedValueSet pars) {
|
||||||
if (this.fss == null) {
|
if (this.fss == null) {
|
||||||
return rootsterile(E, pars);
|
return rootsterile(E, pars);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import inr.numass.NumassContext;
|
import inr.numass.NumassContext;
|
||||||
import inr.numass.utils.TritiumUtils;
|
import inr.numass.utils.TritiumUtils;
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
@ -38,7 +38,7 @@ public class CustomNBkgSpectrum extends NBkgSpectrum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double x, NamedDoubleSet set) {
|
public double value(double x, NamedValueSet set) {
|
||||||
if (customBackgroundFunction == null) {
|
if (customBackgroundFunction == null) {
|
||||||
return super.value(x, set);
|
return super.value(x, set);
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,63 +13,63 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.exceptions.NamingException;
|
import hep.dataforge.exceptions.NamingException;
|
||||||
import hep.dataforge.exceptions.NotDefinedException;
|
import hep.dataforge.exceptions.NotDefinedException;
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.maths.integration.GaussRuleIntegrator;
|
||||||
import hep.dataforge.maths.integration.GaussRuleIntegrator;
|
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
||||||
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.math3.analysis.BivariateFunction;
|
import org.apache.commons.math3.analysis.BivariateFunction;
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
public class EmpiricalLossSpectrum extends AbstractParametricFunction {
|
public class EmpiricalLossSpectrum extends AbstractParametricFunction {
|
||||||
|
|
||||||
public static String[] names = {"X", "shift"};
|
public static String[] names = {"X", "shift"};
|
||||||
private final UnivariateFunction transmission;
|
private final UnivariateFunction transmission;
|
||||||
private final double eMax;
|
private final double eMax;
|
||||||
|
|
||||||
private final UnivariateIntegrator integrator;
|
private final UnivariateIntegrator integrator;
|
||||||
|
|
||||||
public EmpiricalLossSpectrum(UnivariateFunction transmission, double eMax) throws NamingException {
|
public EmpiricalLossSpectrum(UnivariateFunction transmission, double eMax) throws NamingException {
|
||||||
super(names);
|
super(names);
|
||||||
integrator = new GaussRuleIntegrator(300);
|
integrator = new GaussRuleIntegrator(300);
|
||||||
this.transmission = transmission;
|
this.transmission = transmission;
|
||||||
this.eMax = eMax;
|
this.eMax = eMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
public double derivValue(String parName, double x, NamedValueSet set) {
|
||||||
throw new NotDefinedException();
|
throw new NotDefinedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double U, NamedDoubleSet set) {
|
public double value(double U, NamedValueSet set) {
|
||||||
if (U >= eMax) {
|
if (U >= eMax) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
double X = set.getValue("X");
|
double X = set.getDouble("X");
|
||||||
final double shift = set.getValue("shift");
|
final double shift = set.getDouble("shift");
|
||||||
|
|
||||||
//FIXME тут толщины усреднены по длине источника, а надо брать чистого Пуассона
|
//FIXME тут толщины усреднены по длине источника, а надо брать чистого Пуассона
|
||||||
final List<Double> probs = LossCalculator.instance().getGunLossProbabilities(X);
|
final List<Double> probs = LossCalculator.instance().getGunLossProbabilities(X);
|
||||||
final double noLossProb = probs.get(0);
|
final double noLossProb = probs.get(0);
|
||||||
final BivariateFunction lossFunction = (Ei, Ef) -> {
|
final BivariateFunction lossFunction = (Ei, Ef) -> {
|
||||||
return LossCalculator.instance().getLossValue(probs, Ei, Ef);
|
return LossCalculator.instance().getLossValue(probs, Ei, Ef);
|
||||||
};
|
};
|
||||||
UnivariateFunction integrand = (double x) -> transmission.value(x) * lossFunction.value(x, U - shift);
|
UnivariateFunction integrand = (double x) -> transmission.value(x) * lossFunction.value(x, U - shift);
|
||||||
return noLossProb * transmission.value(U - shift) + integrator.integrate(integrand, U, eMax);
|
return noLossProb * transmission.value(U - shift) + integrator.integrate(integrand, U, eMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean providesDeriv(String name) {
|
public boolean providesDeriv(String name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,166 +13,167 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.exceptions.NotDefinedException;
|
import hep.dataforge.exceptions.NotDefinedException;
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import org.apache.commons.math3.analysis.BivariateFunction;
|
import hep.dataforge.values.ValueProvider;
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import org.apache.commons.math3.analysis.BivariateFunction;
|
||||||
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
/**
|
|
||||||
* Experimental differential loss spectrum
|
/**
|
||||||
*
|
* Experimental differential loss spectrum
|
||||||
* @author darksnake
|
*
|
||||||
*/
|
* @author darksnake
|
||||||
public class ExperimentalVariableLossSpectrum extends VariableLossSpectrum {
|
*/
|
||||||
|
public class ExperimentalVariableLossSpectrum extends VariableLossSpectrum {
|
||||||
public static ExperimentalVariableLossSpectrum withGun(double eGun, double resA, double eMax, double smootherW) {
|
|
||||||
return new ExperimentalVariableLossSpectrum(new GunSpectrum(), eMax,smootherW);
|
public static ExperimentalVariableLossSpectrum withGun(double eGun, double resA, double eMax, double smootherW) {
|
||||||
}
|
return new ExperimentalVariableLossSpectrum(new GunSpectrum(), eMax,smootherW);
|
||||||
|
}
|
||||||
public static ExperimentalVariableLossSpectrum withData(final UnivariateFunction transmission, double eMax, double smootherW) {
|
|
||||||
return new ExperimentalVariableLossSpectrum(new AbstractParametricFunction(new String[0]) {
|
public static ExperimentalVariableLossSpectrum withData(final UnivariateFunction transmission, double eMax, double smootherW) {
|
||||||
|
return new ExperimentalVariableLossSpectrum(new AbstractParametricFunction(new String[0]) {
|
||||||
@Override
|
|
||||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
@Override
|
||||||
throw new NotDefinedException();
|
public double derivValue(String parName, double x, NamedValueSet set) {
|
||||||
}
|
throw new NotDefinedException();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean providesDeriv(String name) {
|
@Override
|
||||||
return false;
|
public boolean providesDeriv(String name) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public double value(double x, NamedDoubleSet set) {
|
@Override
|
||||||
return transmission.value(x);
|
public double value(double x, NamedValueSet set) {
|
||||||
}
|
return transmission.value(x);
|
||||||
}, eMax,smootherW);
|
}
|
||||||
}
|
}, eMax,smootherW);
|
||||||
|
}
|
||||||
Loss loss;
|
|
||||||
|
Loss loss;
|
||||||
// private double smootherW;
|
|
||||||
// public ExperimentalVariableLossSpectrum(UnivariateFunction transmission, double eMax, double smootherW) throws NamingException {
|
// private double smootherW;
|
||||||
// super(transmission, eMax);
|
// public ExperimentalVariableLossSpectrum(UnivariateFunction transmission, double eMax, double smootherW) throws NamingException {
|
||||||
// loss = new Loss(smootherW);
|
// super(transmission, eMax);
|
||||||
// }
|
// loss = new Loss(smootherW);
|
||||||
public ExperimentalVariableLossSpectrum(ParametricFunction transmission, double eMax, double smootherW) {
|
// }
|
||||||
super(transmission, eMax);
|
public ExperimentalVariableLossSpectrum(ParametricFunction transmission, double eMax, double smootherW) {
|
||||||
loss = new Loss(smootherW);
|
super(transmission, eMax);
|
||||||
}
|
loss = new Loss(smootherW);
|
||||||
|
}
|
||||||
// public ExperimentalVariableLossSpectrum(double eGun, double resA, double eMax, double smootherW) throws NamingException {
|
|
||||||
// super(eGun, resA, eMax);
|
// public ExperimentalVariableLossSpectrum(double eGun, double resA, double eMax, double smootherW) throws NamingException {
|
||||||
// loss = new Loss(smootherW);
|
// super(eGun, resA, eMax);
|
||||||
// }
|
// loss = new Loss(smootherW);
|
||||||
@Override
|
// }
|
||||||
public UnivariateFunction singleScatterFunction(
|
@Override
|
||||||
double exPos,
|
public UnivariateFunction singleScatterFunction(
|
||||||
double ionPos,
|
double exPos,
|
||||||
double exW,
|
double ionPos,
|
||||||
double ionW,
|
double exW,
|
||||||
double exIonRatio) {
|
double ionW,
|
||||||
|
double exIonRatio) {
|
||||||
return (double eps) -> {
|
|
||||||
if (eps <= 0) {
|
return (double eps) -> {
|
||||||
return 0;
|
if (eps <= 0) {
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
return (loss.excitation(exPos, exW).value(eps) * exIonRatio + loss.ionization(ionPos, ionW).value(eps)) / (1d + exIonRatio);
|
|
||||||
};
|
return (loss.excitation(exPos, exW).value(eps) * exIonRatio + loss.ionization(ionPos, ionW).value(eps)) / (1d + exIonRatio);
|
||||||
}
|
};
|
||||||
|
}
|
||||||
public static class Loss {
|
|
||||||
|
public static class Loss {
|
||||||
private BivariateFunction smoother;
|
|
||||||
|
private BivariateFunction smoother;
|
||||||
private double smootherNorm;
|
|
||||||
|
private double smootherNorm;
|
||||||
public Loss(double smootherW) {
|
|
||||||
if (smootherW == 0) {
|
public Loss(double smootherW) {
|
||||||
smoother = (e1, e2) -> 0;
|
if (smootherW == 0) {
|
||||||
smootherNorm = 0;
|
smoother = (e1, e2) -> 0;
|
||||||
}
|
smootherNorm = 0;
|
||||||
|
}
|
||||||
smoother = (e1, e2) -> {
|
|
||||||
double delta = e1 - e2;
|
smoother = (e1, e2) -> {
|
||||||
if (delta < 0) {
|
double delta = e1 - e2;
|
||||||
return 0;
|
if (delta < 0) {
|
||||||
} else {
|
return 0;
|
||||||
return Math.exp(-delta * delta / 2 / smootherW / smootherW);
|
} else {
|
||||||
}
|
return Math.exp(-delta * delta / 2 / smootherW / smootherW);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
smootherNorm = Math.sqrt(2 * Math.PI) * smootherW / 2;
|
|
||||||
}
|
smootherNorm = Math.sqrt(2 * Math.PI) * smootherW / 2;
|
||||||
|
}
|
||||||
public UnivariateFunction total(
|
|
||||||
final double exPos,
|
public UnivariateFunction total(
|
||||||
final double ionPos,
|
final double exPos,
|
||||||
final double exW,
|
final double ionPos,
|
||||||
final double ionW,
|
final double exW,
|
||||||
final double exIonRatio) {
|
final double ionW,
|
||||||
return (eps) -> (excitation(exPos, exW).value(eps) * exIonRatio + ionization(ionPos, ionW).value(eps)) / (1d + exIonRatio);
|
final double exIonRatio) {
|
||||||
}
|
return (eps) -> (excitation(exPos, exW).value(eps) * exIonRatio + ionization(ionPos, ionW).value(eps)) / (1d + exIonRatio);
|
||||||
|
}
|
||||||
public UnivariateFunction total(NamedDoubleSet set) {
|
|
||||||
final double exPos = set.getValue("exPos");
|
public UnivariateFunction total(ValueProvider set) {
|
||||||
final double ionPos = set.getValue("ionPos");
|
final double exPos = set.getDouble("exPos");
|
||||||
final double exW = set.getValue("exW");
|
final double ionPos = set.getDouble("ionPos");
|
||||||
final double ionW = set.getValue("ionW");
|
final double exW = set.getDouble("exW");
|
||||||
final double exIonRatio = set.getValue("exIonRatio");
|
final double ionW = set.getDouble("ionW");
|
||||||
return total(exPos, ionPos, exW, ionW, exIonRatio);
|
final double exIonRatio = set.getDouble("exIonRatio");
|
||||||
}
|
return total(exPos, ionPos, exW, ionW, exIonRatio);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Excitation spectrum
|
/**
|
||||||
*
|
* Excitation spectrum
|
||||||
* @param exPos
|
*
|
||||||
* @param exW
|
* @param exPos
|
||||||
* @return
|
* @param exW
|
||||||
*/
|
* @return
|
||||||
public UnivariateFunction excitation(double exPos, double exW) {
|
*/
|
||||||
return (double eps) -> {
|
public UnivariateFunction excitation(double exPos, double exW) {
|
||||||
double z = eps - exPos;
|
return (double eps) -> {
|
||||||
double res;
|
double z = eps - exPos;
|
||||||
|
double res;
|
||||||
double norm = smootherNorm + Math.sqrt(Math.PI / 2) * exW / 2;
|
|
||||||
|
double norm = smootherNorm + Math.sqrt(Math.PI / 2) * exW / 2;
|
||||||
if (z < 0) {
|
|
||||||
res = Math.exp(-2 * z * z / exW / exW);
|
if (z < 0) {
|
||||||
} else {
|
res = Math.exp(-2 * z * z / exW / exW);
|
||||||
res = smoother.value(z, 0);
|
} else {
|
||||||
}
|
res = smoother.value(z, 0);
|
||||||
|
}
|
||||||
return res / norm;
|
|
||||||
};
|
return res / norm;
|
||||||
}
|
};
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Ionization spectrum
|
/**
|
||||||
*
|
* Ionization spectrum
|
||||||
* @param ionPos
|
*
|
||||||
* @param ionW
|
* @param ionPos
|
||||||
* @return
|
* @param ionW
|
||||||
*/
|
* @return
|
||||||
public UnivariateFunction ionization(double ionPos, double ionW) {
|
*/
|
||||||
return (double eps) -> {
|
public UnivariateFunction ionization(double ionPos, double ionW) {
|
||||||
double res;
|
return (double eps) -> {
|
||||||
double norm = smootherNorm + ionW * Math.PI / 4d;
|
double res;
|
||||||
|
double norm = smootherNorm + ionW * Math.PI / 4d;
|
||||||
if (eps - ionPos > 0) {
|
|
||||||
res = 1 / (1 + 4 * (eps - ionPos) * (eps - ionPos) / ionW / ionW);
|
if (eps - ionPos > 0) {
|
||||||
} else {
|
res = 1 / (1 + 4 * (eps - ionPos) * (eps - ionPos) / ionW / ionW);
|
||||||
res = smoother.value(0, eps - ionPos);
|
} else {
|
||||||
}
|
res = smoother.value(0, eps - ionPos);
|
||||||
|
}
|
||||||
return res / norm;
|
|
||||||
};
|
return res / norm;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
@ -19,8 +19,9 @@ import hep.dataforge.context.GlobalContext;
|
|||||||
import hep.dataforge.exceptions.NameNotFoundException;
|
import hep.dataforge.exceptions.NameNotFoundException;
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import static hep.dataforge.names.NamedUtils.combineNamesWithEquals;
|
import static hep.dataforge.names.NamedUtils.combineNamesWithEquals;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
import hep.dataforge.values.ValueProvider;
|
||||||
import static java.lang.Double.isNaN;
|
import static java.lang.Double.isNaN;
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
import static java.lang.Math.exp;
|
import static java.lang.Math.exp;
|
||||||
@ -28,6 +29,12 @@ import static java.lang.Math.sqrt;
|
|||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
import org.apache.commons.math3.analysis.integration.SimpsonIntegrator;
|
import org.apache.commons.math3.analysis.integration.SimpsonIntegrator;
|
||||||
import org.apache.commons.math3.analysis.integration.UnivariateIntegrator;
|
import org.apache.commons.math3.analysis.integration.UnivariateIntegrator;
|
||||||
|
import static java.lang.Double.isNaN;
|
||||||
|
import static java.lang.Math.abs;
|
||||||
|
import static java.lang.Double.isNaN;
|
||||||
|
import static java.lang.Math.abs;
|
||||||
|
import static java.lang.Double.isNaN;
|
||||||
|
import static java.lang.Math.abs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -51,7 +58,7 @@ public class GaussResolution extends AbstractParametricFunction implements Trans
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String name, double X, NamedDoubleSet pars) {
|
public double derivValue(String name, double X, NamedValueSet pars) {
|
||||||
if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
|
if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -71,7 +78,7 @@ public class GaussResolution extends AbstractParametricFunction implements Trans
|
|||||||
int maxEval = GlobalContext.instance().getInt("INTEGR_POINTS", 500);
|
int maxEval = GlobalContext.instance().getInt("INTEGR_POINTS", 500);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
public double derivValue(String parName, double x, NamedValueSet set) {
|
||||||
double a = getLowerBound(set);
|
double a = getLowerBound(set);
|
||||||
double b = getUpperBound(set);
|
double b = getUpperBound(set);
|
||||||
assert b > a;
|
assert b > a;
|
||||||
@ -87,7 +94,7 @@ public class GaussResolution extends AbstractParametricFunction implements Trans
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double x, NamedDoubleSet set) {
|
public double value(double x, NamedValueSet set) {
|
||||||
double a = getLowerBound(set);
|
double a = getLowerBound(set);
|
||||||
double b = getUpperBound(set);
|
double b = getUpperBound(set);
|
||||||
assert b > a;
|
assert b > a;
|
||||||
@ -97,11 +104,11 @@ public class GaussResolution extends AbstractParametricFunction implements Trans
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getDeriv(String name, NamedDoubleSet set, double input, double output) {
|
public double getDeriv(String name, NamedValueSet set, double input, double output) {
|
||||||
return this.derivValue(name, output - input, set);
|
return this.derivValue(name, output - input, set);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnivariateFunction getDerivProduct(final String name, final ParametricFunction bare, final NamedDoubleSet pars, final double x0) {
|
private UnivariateFunction getDerivProduct(final String name, final ParametricFunction bare, final NamedValueSet pars, final double x0) {
|
||||||
return (double x) -> {
|
return (double x) -> {
|
||||||
double res1;
|
double res1;
|
||||||
double res2;
|
double res2;
|
||||||
@ -119,17 +126,17 @@ public class GaussResolution extends AbstractParametricFunction implements Trans
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getLowerBound(final NamedDoubleSet pars) {
|
private double getLowerBound(final NamedValueSet pars) {
|
||||||
return getPos(pars) - cutoff * getW(pars);
|
return getPos(pars) - cutoff * getW(pars);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getPos(NamedDoubleSet pars) {
|
private double getPos(ValueProvider pars) {
|
||||||
// return pars.getValue("pos");
|
// return pars.getDouble("pos");
|
||||||
// вряд ли стоит ожидать, что разрешение будет сдвигать среднее, поэтому оставляем один параметр
|
// вряд ли стоит ожидать, что разрешение будет сдвигать среднее, поэтому оставляем один параметр
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnivariateFunction getProduct(final ParametricFunction bare, final NamedDoubleSet pars, final double x0) {
|
private UnivariateFunction getProduct(final ParametricFunction bare, final NamedValueSet pars, final double x0) {
|
||||||
return (double x) -> {
|
return (double x) -> {
|
||||||
double res = bare.value(x0 - x, pars) * GaussResolution.this.value(x, pars);
|
double res = bare.value(x0 - x, pars) * GaussResolution.this.value(x, pars);
|
||||||
assert !isNaN(res);
|
assert !isNaN(res);
|
||||||
@ -137,17 +144,17 @@ public class GaussResolution extends AbstractParametricFunction implements Trans
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getUpperBound(final NamedDoubleSet pars) {
|
private double getUpperBound(final NamedValueSet pars) {
|
||||||
return getPos(pars) + cutoff * getW(pars);
|
return getPos(pars) + cutoff * getW(pars);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getValue(NamedDoubleSet set, double input, double output) {
|
public double getValue(NamedValueSet set, double input, double output) {
|
||||||
return this.value(output - input, set);
|
return this.value(output - input, set);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getW(NamedDoubleSet pars) {
|
private double getW(ValueProvider pars) {
|
||||||
return pars.getValue("w");
|
return pars.getDouble("w");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -156,11 +163,11 @@ public class GaussResolution extends AbstractParametricFunction implements Trans
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double X, NamedDoubleSet pars) {
|
public double value(double x, NamedValueSet pars) {
|
||||||
if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
|
if (abs(x - getPos(pars)) > cutoff * getW(pars)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
double aux = (X - getPos(pars)) / getW(pars);
|
double aux = (x - getPos(pars)) / getW(pars);
|
||||||
return exp(-aux * aux / 2) / getW(pars) / sqrt(2 * Math.PI);
|
return exp(-aux * aux / 2) / getW(pars) / sqrt(2 * Math.PI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,77 +13,78 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.exceptions.NotDefinedException;
|
import hep.dataforge.exceptions.NotDefinedException;
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import static java.lang.Math.exp;
|
import hep.dataforge.values.ValueProvider;
|
||||||
import static java.lang.Math.sqrt;
|
import static java.lang.Math.exp;
|
||||||
|
import static java.lang.Math.sqrt;
|
||||||
/**
|
|
||||||
*
|
/**
|
||||||
* @author Darksnake
|
*
|
||||||
*/
|
* @author Darksnake
|
||||||
public class GaussSourceSpectrum extends AbstractParametricFunction implements RangedNamedSetSpectrum {
|
*/
|
||||||
|
public class GaussSourceSpectrum extends AbstractParametricFunction implements RangedNamedSetSpectrum {
|
||||||
private static final String[] list = {"pos", "sigma"};
|
|
||||||
private final double cutoff = 4d;
|
private static final String[] list = {"pos", "sigma"};
|
||||||
|
private final double cutoff = 4d;
|
||||||
public GaussSourceSpectrum() {
|
|
||||||
super(list);
|
public GaussSourceSpectrum() {
|
||||||
}
|
super(list);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public double derivValue(String parName, double E, NamedDoubleSet set) {
|
@Override
|
||||||
switch (parName) {
|
public double derivValue(String parName, double E, NamedValueSet set) {
|
||||||
case "pos":
|
switch (parName) {
|
||||||
return getGaussPosDeriv(E, getPos(set), getSigma(set));
|
case "pos":
|
||||||
case "sigma":
|
return getGaussPosDeriv(E, getPos(set), getSigma(set));
|
||||||
return getGaussSigmaDeriv(E, getPos(set), getSigma(set));
|
case "sigma":
|
||||||
default:
|
return getGaussSigmaDeriv(E, getPos(set), getSigma(set));
|
||||||
throw new NotDefinedException();
|
default:
|
||||||
}
|
throw new NotDefinedException();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
double getGauss(double E, double pos, double sigma) {
|
|
||||||
double aux = (E - pos) / sigma;
|
double getGauss(double E, double pos, double sigma) {
|
||||||
return exp(-aux * aux / 2) / sigma / sqrt(2 * Math.PI);
|
double aux = (E - pos) / sigma;
|
||||||
}
|
return exp(-aux * aux / 2) / sigma / sqrt(2 * Math.PI);
|
||||||
|
}
|
||||||
double getGaussPosDeriv(double E, double pos, double sigma) {
|
|
||||||
return getGauss(E, pos, sigma) * (E - pos) / sigma / sigma;
|
double getGaussPosDeriv(double E, double pos, double sigma) {
|
||||||
}
|
return getGauss(E, pos, sigma) * (E - pos) / sigma / sigma;
|
||||||
|
}
|
||||||
double getGaussSigmaDeriv(double E, double pos, double sigma) {
|
|
||||||
return getGauss(E, pos, sigma) * ((E - pos) * (E - pos) / sigma / sigma / sigma - 1 / sigma);
|
double getGaussSigmaDeriv(double E, double pos, double sigma) {
|
||||||
}
|
return getGauss(E, pos, sigma) * ((E - pos) * (E - pos) / sigma / sigma / sigma - 1 / sigma);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public Double max(NamedDoubleSet set) {
|
@Override
|
||||||
return getPos(set) + cutoff * getSigma(set);
|
public Double max(NamedValueSet set) {
|
||||||
}
|
return getPos(set) + cutoff * getSigma(set);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public Double min(NamedDoubleSet set) {
|
@Override
|
||||||
return getPos(set) - cutoff * getSigma(set);
|
public Double min(NamedValueSet set) {
|
||||||
}
|
return getPos(set) - cutoff * getSigma(set);
|
||||||
|
}
|
||||||
private double getPos(NamedDoubleSet set) {
|
|
||||||
return set.getValue("pos");
|
private double getPos(ValueProvider set) {
|
||||||
}
|
return set.getDouble("pos");
|
||||||
|
}
|
||||||
private double getSigma(NamedDoubleSet set) {
|
|
||||||
return set.getValue("sigma");
|
private double getSigma(ValueProvider set) {
|
||||||
}
|
return set.getDouble("sigma");
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean providesDeriv(String name) {
|
@Override
|
||||||
return this.names().contains(name);
|
public boolean providesDeriv(String name) {
|
||||||
}
|
return this.names().contains(name);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public double value(final double E, NamedDoubleSet set) {
|
@Override
|
||||||
return getGauss(E, getPos(set), getSigma(set));
|
public double value(final double E, NamedValueSet set) {
|
||||||
}
|
return getGauss(E, getPos(set), getSigma(set));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -17,8 +17,8 @@ package inr.numass.models;
|
|||||||
|
|
||||||
import hep.dataforge.exceptions.NotDefinedException;
|
import hep.dataforge.exceptions.NotDefinedException;
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import inr.numass.NumassContext;
|
import inr.numass.NumassContext;
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
import static java.lang.Math.exp;
|
import static java.lang.Math.exp;
|
||||||
@ -42,10 +42,10 @@ public class GunSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String parName, final double U, NamedDoubleSet set) {
|
public double derivValue(String parName, final double U, NamedValueSet set) {
|
||||||
final double pos = set.getValue("pos");
|
final double pos = set.getDouble("pos");
|
||||||
final double sigma = set.getValue("sigma");
|
final double sigma = set.getDouble("sigma");
|
||||||
final double resA = set.getValue("resA");
|
final double resA = set.getDouble("resA");
|
||||||
|
|
||||||
if(sigma == 0) throw new NotDefinedException();
|
if(sigma == 0) throw new NotDefinedException();
|
||||||
|
|
||||||
@ -132,10 +132,10 @@ public class GunSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(final double U, NamedDoubleSet set) {
|
public double value(final double U, NamedValueSet set) {
|
||||||
final double pos = set.getValue("pos");
|
final double pos = set.getDouble("pos");
|
||||||
final double sigma = set.getValue("sigma");
|
final double sigma = set.getDouble("sigma");
|
||||||
final double resA = set.getValue("resA");
|
final double resA = set.getDouble("resA");
|
||||||
|
|
||||||
if (sigma <1e-5 ) {
|
if (sigma <1e-5 ) {
|
||||||
return transmissionValueFast(U, pos, resA);
|
return transmissionValueFast(U, pos, resA);
|
||||||
|
@ -13,77 +13,78 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.exceptions.NotDefinedException;
|
import hep.dataforge.exceptions.NotDefinedException;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.names.Names;
|
||||||
import hep.dataforge.names.Names;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import static java.lang.Math.abs;
|
import hep.dataforge.values.ValueProvider;
|
||||||
import static java.lang.Math.exp;
|
import static java.lang.Math.abs;
|
||||||
import static java.lang.Math.sqrt;
|
import static java.lang.Math.exp;
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import static java.lang.Math.sqrt;
|
||||||
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
public class GunTailSpectrum implements RangedNamedSetSpectrum {
|
|
||||||
|
public class GunTailSpectrum implements RangedNamedSetSpectrum {
|
||||||
private final double cutoff = 4d;
|
|
||||||
|
private final double cutoff = 4d;
|
||||||
private final String[] list = {"pos", "tailShift", "tailAmp", "sigma"};
|
|
||||||
|
private final String[] list = {"pos", "tailShift", "tailAmp", "sigma"};
|
||||||
@Override
|
|
||||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
@Override
|
||||||
throw new NotDefinedException();
|
public double derivValue(String parName, double x, NamedValueSet set) {
|
||||||
}
|
throw new NotDefinedException();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public Double max(NamedDoubleSet set) {
|
@Override
|
||||||
return set.getValue("pos") + cutoff * set.getValue("sigma");
|
public Double max(NamedValueSet set) {
|
||||||
}
|
return set.getDouble("pos") + cutoff * set.getDouble("sigma");
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public Double min(NamedDoubleSet set) {
|
@Override
|
||||||
return 0d;
|
public Double min(NamedValueSet set) {
|
||||||
}
|
return 0d;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public Names names() {
|
@Override
|
||||||
return Names.of(list);
|
public Names names() {
|
||||||
}
|
return Names.of(list);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean providesDeriv(String name) {
|
@Override
|
||||||
return false;
|
public boolean providesDeriv(String name) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public double value(double E, NamedDoubleSet set) {
|
@Override
|
||||||
double pos = set.getValue("pos");
|
public double value(double E, NamedValueSet set) {
|
||||||
double amp = set.getValue("tailAmp");
|
double pos = set.getDouble("pos");
|
||||||
double sigma = set.getValue("sigma");
|
double amp = set.getDouble("tailAmp");
|
||||||
|
double sigma = set.getDouble("sigma");
|
||||||
if (E >= pos + cutoff * sigma) {
|
|
||||||
return 0d;
|
if (E >= pos + cutoff * sigma) {
|
||||||
}
|
return 0d;
|
||||||
|
}
|
||||||
return gauss(E, pos, sigma) * (1 - amp) + amp * tail(E, pos, set);
|
|
||||||
}
|
return gauss(E, pos, sigma) * (1 - amp) + amp * tail(E, pos, set);
|
||||||
|
}
|
||||||
double gauss(double E, double pos, double sigma) {
|
|
||||||
if (abs(E - pos) > cutoff * sigma) {
|
double gauss(double E, double pos, double sigma) {
|
||||||
return 0;
|
if (abs(E - pos) > cutoff * sigma) {
|
||||||
}
|
return 0;
|
||||||
double aux = (E - pos) / sigma;
|
}
|
||||||
return exp(-aux * aux / 2) / sigma / sqrt(2 * Math.PI);
|
double aux = (E - pos) / sigma;
|
||||||
}
|
return exp(-aux * aux / 2) / sigma / sqrt(2 * Math.PI);
|
||||||
|
}
|
||||||
double tail(double E, double pos, NamedDoubleSet set) {
|
|
||||||
|
double tail(double E, double pos, ValueProvider set) {
|
||||||
double tailShift = set.getValue("tailShift");
|
|
||||||
|
double tailShift = set.getDouble("tailShift");
|
||||||
double delta = Math.max(pos - E - tailShift, 1d);
|
|
||||||
UnivariateFunction func = (double d) -> 1d / d / d;
|
double delta = Math.max(pos - E - tailShift, 1d);
|
||||||
// double tailNorm = NumassContext.defaultIntegrator.integrate(func, 0d, 300d);
|
UnivariateFunction func = (double d) -> 1d / d / d;
|
||||||
|
// double tailNorm = NumassContext.defaultIntegrator.integrate(func, 0d, 300d);
|
||||||
return func.value(delta);
|
|
||||||
}
|
return func.value(delta);
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.functions.FunctionCaching;
|
import hep.dataforge.functions.FunctionCaching;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import hep.dataforge.maths.integration.GaussRuleIntegrator;
|
import hep.dataforge.maths.integration.GaussRuleIntegrator;
|
||||||
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
||||||
import hep.dataforge.plots.XYPlotFrame;
|
import hep.dataforge.plots.XYPlotFrame;
|
||||||
import hep.dataforge.plots.data.PlottableFunction;
|
import hep.dataforge.plots.data.PlottableFunction;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import static java.lang.Math.exp;
|
import static java.lang.Math.exp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -115,13 +115,13 @@ public class LossCalculator {
|
|||||||
return (e) -> func.value(e) / norm;
|
return (e) -> func.value(e) / norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnivariateFunction getSingleScatterFunction(NamedDoubleSet set) {
|
public static UnivariateFunction getSingleScatterFunction(NamedValueSet set) {
|
||||||
|
|
||||||
final double exPos = set.getValue("exPos");
|
final double exPos = set.getDouble("exPos");
|
||||||
final double ionPos = set.getValue("ionPos");
|
final double ionPos = set.getDouble("ionPos");
|
||||||
final double exW = set.getValue("exW");
|
final double exW = set.getDouble("exW");
|
||||||
final double ionW = set.getValue("ionW");
|
final double ionW = set.getDouble("ionW");
|
||||||
final double exIonRatio = set.getValue("exIonRatio");
|
final double exIonRatio = set.getDouble("exIonRatio");
|
||||||
|
|
||||||
return getSingleScatterFunction(exPos, ionPos, exW, ionW, exIonRatio);
|
return getSingleScatterFunction(exPos, ionPos, exW, ionW, exIonRatio);
|
||||||
}
|
}
|
||||||
@ -146,27 +146,27 @@ public class LossCalculator {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void plotScatter(XYPlotFrame frame, NamedDoubleSet set) {
|
public static void plotScatter(XYPlotFrame frame, NamedValueSet set) {
|
||||||
//"X", "shift", "exPos", "ionPos", "exW", "ionW", "exIonRatio"
|
//"X", "shift", "exPos", "ionPos", "exW", "ionW", "exIonRatio"
|
||||||
|
|
||||||
// JFreeChartFrame frame = JFreeChartFrame.drawFrame("Differential scattering crosssection", null);
|
// JFreeChartFrame frame = JFreeChartFrame.drawFrame("Differential scattering crosssection", null);
|
||||||
double X = set.getValue("X");
|
double X = set.getDouble("X");
|
||||||
|
|
||||||
final double exPos = set.getValue("exPos");
|
final double exPos = set.getDouble("exPos");
|
||||||
|
|
||||||
final double ionPos = set.getValue("ionPos");
|
final double ionPos = set.getDouble("ionPos");
|
||||||
|
|
||||||
final double exW = set.getValue("exW");
|
final double exW = set.getDouble("exW");
|
||||||
|
|
||||||
final double ionW = set.getValue("ionW");
|
final double ionW = set.getDouble("ionW");
|
||||||
|
|
||||||
final double exIonRatio = set.getValue("exIonRatio");
|
final double exIonRatio = set.getDouble("exIonRatio");
|
||||||
|
|
||||||
UnivariateFunction scatterFunction = getSingleScatterFunction(exPos, ionPos, exW, ionW, exIonRatio);
|
UnivariateFunction scatterFunction = getSingleScatterFunction(exPos, ionPos, exW, ionW, exIonRatio);
|
||||||
|
|
||||||
if (set.names().contains("X")) {
|
if (set.names().contains("X")) {
|
||||||
final LossCalculator loss = LossCalculator.instance;
|
final LossCalculator loss = LossCalculator.instance;
|
||||||
final List<Double> probs = loss.getGunLossProbabilities(set.getValue("X"));
|
final List<Double> probs = loss.getGunLossProbabilities(set.getDouble("X"));
|
||||||
UnivariateFunction single = (double e) -> probs.get(1) * scatterFunction.value(e);
|
UnivariateFunction single = (double e) -> probs.get(1) * scatterFunction.value(e);
|
||||||
frame.add(new PlottableFunction("Single scattering", x->single.value(x), 0, 100, 1000));
|
frame.add(new PlottableFunction("Single scattering", x->single.value(x), 0, 100, 1000));
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@ package inr.numass.models;
|
|||||||
|
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import hep.dataforge.names.NamedUtils;
|
import hep.dataforge.names.NamedUtils;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
import hep.dataforge.values.ValueProvider;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.math3.analysis.BivariateFunction;
|
import org.apache.commons.math3.analysis.BivariateFunction;
|
||||||
@ -141,7 +142,7 @@ public class ModularSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String parName, double U, NamedDoubleSet set) {
|
public double derivValue(String parName, double U, NamedValueSet set) {
|
||||||
if (U >= sourceSpectrum.max(set)) {
|
if (U >= sourceSpectrum.max(set)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -177,12 +178,12 @@ public class ModularSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getTrap(NamedDoubleSet set) {
|
private double getTrap(ValueProvider set) {
|
||||||
return set.getValue("trap");
|
return set.getDouble("trap");
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getX(NamedDoubleSet set) {
|
private double getX(ValueProvider set) {
|
||||||
return set.getValue("X");
|
return set.getDouble("X");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -223,7 +224,7 @@ public class ModularSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double U, NamedDoubleSet set) {
|
public double value(double U, NamedValueSet set) {
|
||||||
if (U >= sourceSpectrum.max(set)) {
|
if (U >= sourceSpectrum.max(set)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,10 @@ package inr.numass.models;
|
|||||||
|
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import static hep.dataforge.names.NamedUtils.combineNamesWithEquals;
|
import static hep.dataforge.names.NamedUtils.combineNamesWithEquals;
|
||||||
import hep.dataforge.utils.MultiCounter;
|
import hep.dataforge.utils.MultiCounter;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
import hep.dataforge.values.ValueProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -38,7 +39,7 @@ public class NBkgSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
public double derivValue(String parName, double x, NamedValueSet set) {
|
||||||
this.counter.increase(parName);
|
this.counter.increase(parName);
|
||||||
switch (parName) {
|
switch (parName) {
|
||||||
case "N":
|
case "N":
|
||||||
@ -50,12 +51,12 @@ public class NBkgSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getBkg(NamedDoubleSet set) {
|
private double getBkg(ValueProvider set) {
|
||||||
return set.getValue("bkg");
|
return set.getDouble("bkg");
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getN(NamedDoubleSet set) {
|
private double getN(ValueProvider set) {
|
||||||
return set.getValue("N");
|
return set.getDouble("N");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,7 +72,7 @@ public class NBkgSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double x, NamedDoubleSet set) {
|
public double value(double x, NamedValueSet set) {
|
||||||
this.counter.increase("value");
|
this.counter.increase("value");
|
||||||
return getN(set) * source.value(x, set) + getBkg(set);
|
return getN(set) * source.value(x, set) + getBkg(set);
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,14 @@ import hep.dataforge.functions.AbstractParametricFunction;
|
|||||||
import static hep.dataforge.functions.FunctionUtils.getSpectrumDerivativeFunction;
|
import static hep.dataforge.functions.FunctionUtils.getSpectrumDerivativeFunction;
|
||||||
import static hep.dataforge.functions.FunctionUtils.getSpectrumFunction;
|
import static hep.dataforge.functions.FunctionUtils.getSpectrumFunction;
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleArray;
|
import hep.dataforge.maths.MathUtils;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.maths.NamedVector;
|
||||||
import hep.dataforge.names.AbstractNamedSet;
|
import hep.dataforge.names.AbstractNamedSet;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
import hep.dataforge.values.ValueProvider;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator;
|
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -60,7 +63,7 @@ public class NamedSpectrumCaching extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
public double derivValue(String parName, double x, NamedValueSet set) {
|
||||||
if (!isCachingEnabled()) {
|
if (!isCachingEnabled()) {
|
||||||
return source.derivValue(parName, x, set);
|
return source.derivValue(parName, x, set);
|
||||||
}
|
}
|
||||||
@ -105,7 +108,7 @@ public class NamedSpectrumCaching extends AbstractParametricFunction {
|
|||||||
return source.providesDeriv(name);
|
return source.providesDeriv(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean sameSet(NamedDoubleSet set1, NamedDoubleSet set2) {
|
protected boolean sameSet(ValueProvider set1, ValueProvider set2) {
|
||||||
// if((set1 instanceof NamedDoubleSet)&&(set2 instanceof NamedDoubleSet)){
|
// if((set1 instanceof NamedDoubleSet)&&(set2 instanceof NamedDoubleSet)){
|
||||||
// double[] v1 = ((NamedDoubleSet)set1).getAllValues();
|
// double[] v1 = ((NamedDoubleSet)set1).getAllValues();
|
||||||
// double[] v2 = ((NamedDoubleSet)set2).getAllValues();
|
// double[] v2 = ((NamedDoubleSet)set2).getAllValues();
|
||||||
@ -113,7 +116,7 @@ public class NamedSpectrumCaching extends AbstractParametricFunction {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
for (String name : this.names()) {
|
for (String name : this.names()) {
|
||||||
if (set1.getValue(name) != set2.getValue(name)) {
|
if (!Objects.equals(set1.getDouble(name), set2.getDouble(name))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,8 +140,7 @@ public class NamedSpectrumCaching extends AbstractParametricFunction {
|
|||||||
/*
|
/*
|
||||||
* Подразумевается, что трансформация одна и та же и для спектра, и для производных.
|
* Подразумевается, что трансформация одна и та же и для спектра, и для производных.
|
||||||
*/
|
*/
|
||||||
protected double transformation(CacheElement cache,
|
protected double transformation(CacheElement cache, NamedValueSet newSet, double x) throws TransformationNotAvailable {
|
||||||
NamedDoubleSet newSet, double x) throws TransformationNotAvailable {
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -150,7 +152,7 @@ public class NamedSpectrumCaching extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double x, NamedDoubleSet set) {
|
public double value(double x, NamedValueSet set) {
|
||||||
if (!isCachingEnabled()) {
|
if (!isCachingEnabled()) {
|
||||||
return source.value(x, set);
|
return source.value(x, set);
|
||||||
}
|
}
|
||||||
@ -187,22 +189,22 @@ public class NamedSpectrumCaching extends AbstractParametricFunction {
|
|||||||
protected class CacheElement extends AbstractNamedSet implements UnivariateFunction {
|
protected class CacheElement extends AbstractNamedSet implements UnivariateFunction {
|
||||||
|
|
||||||
private UnivariateFunction cachedSpectrum;
|
private UnivariateFunction cachedSpectrum;
|
||||||
private final NamedDoubleSet cachedParameters;
|
private final NamedValueSet cachedParameters;
|
||||||
String parName;
|
String parName;
|
||||||
|
|
||||||
CacheElement(NamedDoubleSet parameters, String parName) {
|
CacheElement(NamedValueSet parameters, String parName) {
|
||||||
super(source);
|
super(source);
|
||||||
//на всякий случай обрезаем набор параметров до необходимого
|
//на всякий случай обрезаем набор параметров до необходимого
|
||||||
String[] names = source.namesAsArray();
|
String[] names = source.namesAsArray();
|
||||||
this.cachedParameters = new NamedDoubleArray(names, parameters.getValues(names));
|
this.cachedParameters = new NamedVector(names, MathUtils.getDoubleArray(parameters));
|
||||||
UnivariateFunction func = getSpectrumDerivativeFunction(parName, source, parameters);
|
UnivariateFunction func = getSpectrumDerivativeFunction(parName, source, parameters);
|
||||||
generate(func);
|
generate(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheElement(NamedDoubleSet parameters) {
|
CacheElement(NamedValueSet parameters) {
|
||||||
super(source);
|
super(source);
|
||||||
String[] names = source.namesAsArray();
|
String[] names = source.namesAsArray();
|
||||||
this.cachedParameters = new NamedDoubleArray(names, parameters.getValues(names));
|
this.cachedParameters = new NamedVector(names, MathUtils.getDoubleArray(parameters));
|
||||||
UnivariateFunction func = getSpectrumFunction(source, parameters);
|
UnivariateFunction func = getSpectrumFunction(source, parameters);
|
||||||
generate(func);
|
generate(func);
|
||||||
}
|
}
|
||||||
@ -227,7 +229,7 @@ public class NamedSpectrumCaching extends AbstractParametricFunction {
|
|||||||
return this.cachedSpectrum.value(x);
|
return this.cachedSpectrum.value(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamedDoubleSet getCachedParameters() {
|
public NamedValueSet getCachedParameters() {
|
||||||
return this.cachedParameters;
|
return this.cachedParameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,38 +13,38 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
public class SimpleRange implements SpectrumRange{
|
public class SimpleRange implements SpectrumRange{
|
||||||
Double min;
|
Double min;
|
||||||
Double max;
|
Double max;
|
||||||
|
|
||||||
public SimpleRange(Double min, Double max) {
|
public SimpleRange(Double min, Double max) {
|
||||||
if(min>=max){
|
if(min>=max){
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double max(NamedDoubleSet set) {
|
public Double max(NamedValueSet set) {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double min(NamedDoubleSet set) {
|
public Double min(NamedValueSet set) {
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,16 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates a range in witch spectrum is not 0
|
* Calculates a range in witch spectrum is not 0
|
||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
public interface SpectrumRange {
|
public interface SpectrumRange {
|
||||||
Double min(NamedDoubleSet set);
|
Double min(NamedValueSet set);
|
||||||
Double max(NamedDoubleSet set);
|
Double max(NamedValueSet set);
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,9 @@ package inr.numass.models;
|
|||||||
|
|
||||||
|
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import hep.dataforge.names.NameSetContainer;
|
import hep.dataforge.names.NameSetContainer;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
import hep.dataforge.values.ValueProvider;
|
||||||
import org.apache.commons.math3.analysis.BivariateFunction;
|
import org.apache.commons.math3.analysis.BivariateFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,18 +28,18 @@ import org.apache.commons.math3.analysis.BivariateFunction;
|
|||||||
*/
|
*/
|
||||||
public interface Transmission extends NameSetContainer{
|
public interface Transmission extends NameSetContainer{
|
||||||
|
|
||||||
double getValue(NamedDoubleSet set, double input, double output);
|
double getValue(NamedValueSet set, double input, double output);
|
||||||
double getDeriv(String name, NamedDoubleSet set, double input, double output);
|
double getDeriv(String name, NamedValueSet set, double input, double output);
|
||||||
boolean providesDeriv(String name);
|
boolean providesDeriv(String name);
|
||||||
|
|
||||||
ParametricFunction getConvolutedSpectrum(RangedNamedSetSpectrum bare);
|
ParametricFunction getConvolutedSpectrum(RangedNamedSetSpectrum bare);
|
||||||
|
|
||||||
|
|
||||||
default BivariateFunction getBivariateFunction(final NamedDoubleSet params){
|
default BivariateFunction getBivariateFunction(final NamedValueSet params){
|
||||||
return (double input, double output) -> getValue(params, input, output);
|
return (double input, double output) -> getValue(params, input, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
default BivariateFunction getBivariateDerivFunction(final String name, final NamedDoubleSet params){
|
default BivariateFunction getBivariateDerivFunction(final String name, final NamedValueSet params){
|
||||||
return (double input, double output) -> getDeriv(name, params, input, output);
|
return (double input, double output) -> getDeriv(name, params, input, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package inr.numass.models;
|
|||||||
|
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import inr.numass.NumassContext;
|
import inr.numass.NumassContext;
|
||||||
import org.apache.commons.math3.analysis.BivariateFunction;
|
import org.apache.commons.math3.analysis.BivariateFunction;
|
||||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||||
@ -45,7 +45,7 @@ class TransmissionConvolution extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(final String parName, final double U, NamedDoubleSet set) {
|
public double derivValue(final String parName, final double U, NamedValueSet set) {
|
||||||
double min = range.min(set);
|
double min = range.min(set);
|
||||||
double max = range.max(set);
|
double max = range.max(set);
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class TransmissionConvolution extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(final double U, NamedDoubleSet set) {
|
public double value(final double U, NamedValueSet set) {
|
||||||
double min = range.min(set);
|
double min = range.min(set);
|
||||||
double max = range.max(set);
|
double max = range.max(set);
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
package inr.numass.models;
|
package inr.numass.models;
|
||||||
|
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleArray;
|
import hep.dataforge.maths.NamedVector;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
import hep.dataforge.values.NamedValueSet;
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -39,11 +39,11 @@ public class TritiumSpectrumCaching extends NamedSpectrumCaching {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double transformation(CacheElement cache, NamedDoubleSet newSet, double x) throws TransformationNotAvailable {
|
protected double transformation(CacheElement cache, NamedValueSet newSet, double x) throws TransformationNotAvailable {
|
||||||
double res;
|
double res;
|
||||||
NamedDoubleArray curSet = new NamedDoubleArray(newSet);
|
NamedVector curSet = new NamedVector(newSet);
|
||||||
double E0new = newSet.getValue("E0");
|
double E0new = newSet.getDouble("E0");
|
||||||
double E0old = cache.getCachedParameters().getValue("E0");
|
double E0old = cache.getCachedParameters().getDouble("E0");
|
||||||
double E0delta = E0new - E0old;
|
double E0delta = E0new - E0old;
|
||||||
if (abs(E0delta) > delta) {
|
if (abs(E0delta) > delta) {
|
||||||
LoggerFactory.getLogger(getClass())
|
LoggerFactory.getLogger(getClass())
|
||||||
|
@ -18,8 +18,9 @@ package inr.numass.models;
|
|||||||
import hep.dataforge.exceptions.NotDefinedException;
|
import hep.dataforge.exceptions.NotDefinedException;
|
||||||
import hep.dataforge.functions.AbstractParametricFunction;
|
import hep.dataforge.functions.AbstractParametricFunction;
|
||||||
import hep.dataforge.functions.ParametricFunction;
|
import hep.dataforge.functions.ParametricFunction;
|
||||||
import hep.dataforge.maths.NamedDoubleSet;
|
|
||||||
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
import hep.dataforge.maths.integration.UnivariateIntegrator;
|
||||||
|
import hep.dataforge.values.NamedValueSet;
|
||||||
|
import hep.dataforge.values.ValueProvider;
|
||||||
import inr.numass.NumassContext;
|
import inr.numass.NumassContext;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.math3.analysis.BivariateFunction;
|
import org.apache.commons.math3.analysis.BivariateFunction;
|
||||||
@ -41,7 +42,7 @@ public class VariableLossSpectrum extends AbstractParametricFunction {
|
|||||||
return new VariableLossSpectrum(new AbstractParametricFunction(new String[0]) {
|
return new VariableLossSpectrum(new AbstractParametricFunction(new String[0]) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
public double derivValue(String parName, double x, NamedValueSet set) {
|
||||||
throw new NotDefinedException();
|
throw new NotDefinedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ public class VariableLossSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double x, NamedDoubleSet set) {
|
public double value(double x, NamedValueSet set) {
|
||||||
return transmission.value(x);
|
return transmission.value(x);
|
||||||
}
|
}
|
||||||
}, eMax);
|
}, eMax);
|
||||||
@ -68,17 +69,17 @@ public class VariableLossSpectrum extends AbstractParametricFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
public double derivValue(String parName, double x, NamedValueSet set) {
|
||||||
throw new NotDefinedException();
|
throw new NotDefinedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double value(double U, NamedDoubleSet set) {
|
public double value(double U, NamedValueSet set) {
|
||||||
if (U >= eMax) {
|
if (U >= eMax) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
double X = set.getValue("X");
|
double X = set.getDouble("X");
|
||||||
final double shift = set.getValue("shift");
|
final double shift = set.getDouble("shift");
|
||||||
|
|
||||||
final LossCalculator loss = LossCalculator.instance();
|
final LossCalculator loss = LossCalculator.instance();
|
||||||
|
|
||||||
@ -107,13 +108,13 @@ public class VariableLossSpectrum extends AbstractParametricFunction {
|
|||||||
return noLossProb * transmission.value(U - shift, set) + integrator.integrate(integrand, U, eMax);
|
return noLossProb * transmission.value(U - shift, set) + integrator.integrate(integrand, U, eMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnivariateFunction singleScatterFunction(NamedDoubleSet set) {
|
public UnivariateFunction singleScatterFunction(ValueProvider set) {
|
||||||
|
|
||||||
final double exPos = set.getValue("exPos");
|
final double exPos = set.getDouble("exPos");
|
||||||
final double ionPos = set.getValue("ionPos");
|
final double ionPos = set.getDouble("ionPos");
|
||||||
final double exW = set.getValue("exW");
|
final double exW = set.getDouble("exW");
|
||||||
final double ionW = set.getValue("ionW");
|
final double ionW = set.getDouble("ionW");
|
||||||
final double exIonRatio = set.getValue("exIonRatio");
|
final double exIonRatio = set.getDouble("exIonRatio");
|
||||||
|
|
||||||
return singleScatterFunction(exPos, ionPos, exW, ionW, exIonRatio);
|
return singleScatterFunction(exPos, ionPos, exW, ionW, exIonRatio);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package inr.numass.utils;
|
||||||
|
|
||||||
|
import groovy.lang.Binding;
|
||||||
|
import groovy.lang.GroovyShell;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.codehaus.groovy.control.CompilerConfiguration;
|
||||||
|
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexander Nozik
|
||||||
|
*/
|
||||||
|
public class ExpressionUtils {
|
||||||
|
|
||||||
|
public static Double evaluate(String expression, Map<String, Double> binding) {
|
||||||
|
Binding b = new Binding(binding);
|
||||||
|
// Add imports for script.
|
||||||
|
ImportCustomizer importCustomizer = new ImportCustomizer();
|
||||||
|
// import static com.mrhaki.blog.Type.*
|
||||||
|
importCustomizer.addStaticStars("java.lang.Math");
|
||||||
|
|
||||||
|
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||||
|
configuration.addCompilationCustomizers(importCustomizer); // Create shell and execute script.
|
||||||
|
|
||||||
|
GroovyShell shell = new GroovyShell(b,configuration);
|
||||||
|
return (Double) shell.evaluate(expression);
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,9 @@ import java.io.FileNotFoundException;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import static java.util.Locale.setDefault;
|
import static java.util.Locale.setDefault;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -132,6 +132,13 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildContext(Meta config) {
|
private void buildContext(Meta config) {
|
||||||
|
if (this.context != null) {
|
||||||
|
try {
|
||||||
|
this.context.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
context.getLogger().error("Failed to close context", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.context = this.contextFactory.build(parentContext, config);
|
this.context = this.contextFactory.build(parentContext, config);
|
||||||
context.setIO(new WorkbenchIOManager(new NumassIO(), this));
|
context.setIO(new WorkbenchIOManager(new NumassIO(), this));
|
||||||
processWindow = ProcessManagerFragment.attachToContext(context);
|
processWindow = ProcessManagerFragment.attachToContext(context);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.workbench;
|
package inr.numass.workbench;
|
||||||
|
|
||||||
|
import hep.dataforge.context.GlobalContext;
|
||||||
import inr.numass.NumassContext;
|
import inr.numass.NumassContext;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
@ -40,6 +41,14 @@ public class Workbench extends Application {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() throws Exception {
|
||||||
|
GlobalContext.instance().close();
|
||||||
|
super.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
|
32
numass-main/src/test/java/inr/numass/NumassContextTest.java
Normal file
32
numass-main/src/test/java/inr/numass/NumassContextTest.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package inr.numass;
|
||||||
|
|
||||||
|
import inr.numass.storage.SetDirectionUtility;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexander Nozik
|
||||||
|
*/
|
||||||
|
public class NumassContextTest {
|
||||||
|
|
||||||
|
public NumassContextTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of close method, of class NumassContext.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testClose() throws Exception {
|
||||||
|
System.out.println("close");
|
||||||
|
NumassContext instance = new NumassContext();
|
||||||
|
instance.close();
|
||||||
|
assert SetDirectionUtility.cacheFile(instance).exists();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package inr.numass.actions;
|
||||||
|
|
||||||
|
import inr.numass.utils.ExpressionUtils;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexander Nozik
|
||||||
|
*/
|
||||||
|
public class PrepareDataActionTest {
|
||||||
|
|
||||||
|
public PrepareDataActionTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExpression() {
|
||||||
|
Map<String, Double> exprParams = new HashMap<>();
|
||||||
|
exprParams.put("U", 18000d);
|
||||||
|
double correctionFactor = ExpressionUtils.evaluate("1 + 13.265 * exp(- U / 2343.4)", exprParams);
|
||||||
|
Assert.assertEquals("Testing expression calculation", 1.006125, correctionFactor, 1e-5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -25,6 +25,37 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import static java.util.Locale.setDefault;
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
import static java.util.Locale.setDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -129,6 +129,8 @@ public class NMPoint {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO move dead time out of here!
|
||||||
public double getCountRate(int from, int to, double deadTime) {
|
public double getCountRate(int from, int to, double deadTime) {
|
||||||
double wind = getCountInWindow(from, to) / getLength();
|
double wind = getCountInWindow(from, to) / getLength();
|
||||||
double res;
|
double res;
|
||||||
|
@ -316,12 +316,14 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
|
|||||||
|
|
||||||
public boolean isReversed() {
|
public boolean isReversed() {
|
||||||
//TODO replace by meta tag in later revisions
|
//TODO replace by meta tag in later revisions
|
||||||
List<Envelope> points = getPoints();
|
return SetDirectionUtility.isReversed(getFullPath(), n -> {
|
||||||
if (getPoints().size() >= 2) {
|
List<Envelope> points = getPoints();
|
||||||
return readTime(points.get(0).meta()).isAfter(readTime(points.get(1).meta()));
|
if (getPoints().size() >= 2) {
|
||||||
} else {
|
return readTime(points.get(0).meta()).isAfter(readTime(points.get(1).meta()));
|
||||||
return false;
|
} else {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package inr.numass.storage;
|
||||||
|
|
||||||
|
import hep.dataforge.context.Context;
|
||||||
|
import hep.dataforge.context.GlobalContext;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A temporary utility to store set directions to avoid multiple file reading
|
||||||
|
*
|
||||||
|
* @author Alexander Nozik
|
||||||
|
*/
|
||||||
|
public class SetDirectionUtility {
|
||||||
|
|
||||||
|
private static final String FILE_NAME = "numass_set_direction.map";
|
||||||
|
|
||||||
|
private static Map<String, Boolean> directionMap = new HashMap<>();
|
||||||
|
|
||||||
|
private static boolean isLoaded = false;
|
||||||
|
|
||||||
|
static synchronized boolean isReversed(String setName, Function<String, Boolean> provider) {
|
||||||
|
if (!isLoaded) {
|
||||||
|
load(GlobalContext.instance());
|
||||||
|
}
|
||||||
|
return directionMap.computeIfAbsent(setName, provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File cacheFile(Context context) {
|
||||||
|
return new File(context.io().getTmpDirectory(), FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void load(Context context) {
|
||||||
|
context.getLogger().info("Loading set direction utility");
|
||||||
|
File file = cacheFile(context);
|
||||||
|
if (file.exists()) {
|
||||||
|
try (ObjectInputStream st = new ObjectInputStream(new FileInputStream(file))) {
|
||||||
|
directionMap = (Map<String, Boolean>) st.readObject();
|
||||||
|
context.getLogger().info("Set directions successfully loaded from file");
|
||||||
|
} catch (ClassNotFoundException | IOException ex) {
|
||||||
|
context.getLogger().error("Failed to load numass direction mapping", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void save(Context context) {
|
||||||
|
try {
|
||||||
|
File file = cacheFile(context);
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
try (ObjectOutputStream st = new ObjectOutputStream(new FileOutputStream(file))) {
|
||||||
|
st.writeObject(directionMap);
|
||||||
|
context.getLogger().info("Set directions successfully saved to file");
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
context.getLogger().error("Failed to save numass direction mapping", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user