From d9e5ff90ec6f23d46d932ad2af75a1cc7653997d Mon Sep 17 00:00:00 2001 From: darksnake Date: Sat, 29 Oct 2016 03:10:11 +0300 Subject: [PATCH] Working on unified output. Minor fixes. --- .../inr/numass/scripts/Underflow.groovy | 2 +- .../main/java/inr/numass/NumassPlugin.java | 2 +- .../models/sterile/NumassTransmission.java | 40 +++++++++++++------ .../inr/numass/utils/ExpressionUtils.java | 1 + 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/numass-main/src/main/groovy/inr/numass/scripts/Underflow.groovy b/numass-main/src/main/groovy/inr/numass/scripts/Underflow.groovy index c1db7221..f31f3df1 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/Underflow.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/Underflow.groovy @@ -14,7 +14,7 @@ import inr.numass.utils.UnderflowCorrection //File dataDir = new File("D:\\Work\\Numass\\data\\2016_04\\T2_data\\Fill_2_2\\set_7_b2a3433e54010000") //File dataDir = new File("D:\\Work\\Numass\\data\\2016_04\\T2_data\\Fill_2_2\\set_6_e26d123e54010000") -File dataDir = new File("D:\\Work\\Numass\\data\\2016_10\\Fill_1\\set_10") +File dataDir = new File("D:\\Work\\Numass\\data\\2016_10\\Fill_2_wide\\\\set_21") if(!dataDir.exists()){ println "dataDir directory does not exist" } diff --git a/numass-main/src/main/java/inr/numass/NumassPlugin.java b/numass-main/src/main/java/inr/numass/NumassPlugin.java index f0d27f6f..91a2a49c 100644 --- a/numass-main/src/main/java/inr/numass/NumassPlugin.java +++ b/numass-main/src/main/java/inr/numass/NumassPlugin.java @@ -101,7 +101,7 @@ public class NumassPlugin extends BasicPlugin { } private void loadMath(MathPlugin math) { - math.registerBivariate("numass.trap2016", (Ei, Ef) -> { + math.registerBivariate("numass.trap.lowFields", (Ei, Ef) -> { return 3.92e-5 * FastMath.exp(-(Ei - Ef) / 300d) + 1.97e-4 - 6.818e-9 * Ei; }); diff --git a/numass-main/src/main/java/inr/numass/models/sterile/NumassTransmission.java b/numass-main/src/main/java/inr/numass/models/sterile/NumassTransmission.java index f59543e5..8647a34d 100644 --- a/numass-main/src/main/java/inr/numass/models/sterile/NumassTransmission.java +++ b/numass-main/src/main/java/inr/numass/models/sterile/NumassTransmission.java @@ -6,12 +6,17 @@ package inr.numass.models.sterile; import hep.dataforge.context.Context; -import hep.dataforge.stat.parametric.AbstractParametricBiFunction; import hep.dataforge.maths.MathPlugin; import hep.dataforge.meta.Meta; +import hep.dataforge.stat.parametric.AbstractParametricBiFunction; import hep.dataforge.values.NamedValueSet; import inr.numass.models.LossCalculator; +import inr.numass.utils.ExpressionUtils; import org.apache.commons.math3.analysis.BivariateFunction; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; /** * @@ -28,12 +33,32 @@ public class NumassTransmission extends AbstractParametricBiFunction { super(list); this.calculator = LossCalculator.instance(); if (meta.hasValue("trapping")) { - trapFunc = MathPlugin.buildFrom(context).buildBivariateFunction(meta.getString("trapping")); + String trapFuncStr = meta.getString("trapping"); + if (trapFuncStr.startsWith("function::")) { + trapFunc = MathPlugin.buildFrom(context).buildBivariateFunction(trapFuncStr.substring(10)); + } else { + trapFunc = (Ei, Ef) -> { + Map binding = new HashMap<>(); + binding.put("Ei", Ei); + binding.put("Ef", Ef); + return ExpressionUtils.evaluate(trapFuncStr, binding); + }; + } } else { - trapFunc = getTrapFunction(context, meta.getNodeOrEmpty("trapping")); + LoggerFactory.getLogger(getClass()).warn("Trapping function not defined. Using default"); + trapFunc = MathPlugin.buildFrom(context).buildBivariateFunction("numass.trap.nominal"); } } + public static double getX(double eIn, NamedValueSet set) { + //From our article + return set.getDouble("X") * Math.log(eIn / ION_POTENTIAL) * eIn * ION_POTENTIAL / 1.9580741410115568e6; + } + + public static double p0(double eIn, NamedValueSet set) { + return LossCalculator.instance().getLossProbability(0, getX(eIn, set)); + } + private BivariateFunction getTrapFunction(Context context, Meta meta) { return MathPlugin.buildFrom(context).buildBivariateFunction(meta); } @@ -55,15 +80,6 @@ public class NumassTransmission extends AbstractParametricBiFunction { return true; } - public static double getX(double eIn, NamedValueSet set) { - //From our article - return set.getDouble("X") * Math.log(eIn / ION_POTENTIAL) * eIn * ION_POTENTIAL / 1.9580741410115568e6; - } - - public static double p0(double eIn, NamedValueSet set) { - return LossCalculator.instance().getLossProbability(0, getX(eIn, set)); - } - @Override public double value(double eIn, double eOut, NamedValueSet set) { //calculate X taking into account its energy dependence diff --git a/numass-main/src/main/java/inr/numass/utils/ExpressionUtils.java b/numass-main/src/main/java/inr/numass/utils/ExpressionUtils.java index c23e5c0c..424a7878 100644 --- a/numass-main/src/main/java/inr/numass/utils/ExpressionUtils.java +++ b/numass-main/src/main/java/inr/numass/utils/ExpressionUtils.java @@ -26,6 +26,7 @@ public class ExpressionUtils { ImportCustomizer importCustomizer = new ImportCustomizer(); // import static com.mrhaki.blog.Type.* importCustomizer.addStaticStars("java.lang.Math"); + importCustomizer.addStaticStars("org.apache.commons.math3.util.FastMath"); CompilerConfiguration configuration = new CompilerConfiguration(); configuration.addCompilationCustomizers(importCustomizer); // Create shell and execute script.