[no commit message]
This commit is contained in:
parent
96aa27758e
commit
f1eb4eba02
@ -118,7 +118,7 @@ public class VACFrame extends javax.swing.JFrame {
|
||||
initComponents();
|
||||
split.getRightComponent().setMinimumSize(new Dimension());
|
||||
split.setDividerLocation(1.0);
|
||||
GlobalContext.instance().attachIoManager(new BasicIOManager(new TextAreaOutputStream(consoleBox, "CONSOLE")));
|
||||
GlobalContext.instance().setIO(new BasicIOManager(new TextAreaOutputStream(consoleBox, "CONSOLE")));
|
||||
|
||||
JTextAreaAppender app = new JTextAreaAppender(consoleBox);
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
|
@ -18,14 +18,12 @@ package inr.numass;
|
||||
import hep.dataforge.actions.ActionUtils;
|
||||
import hep.dataforge.context.Context;
|
||||
import static hep.dataforge.context.GlobalContext.out;
|
||||
import hep.dataforge.data.DataNode;
|
||||
import hep.dataforge.data.FileDataFactory;
|
||||
import hep.dataforge.datafitter.MINUITPlugin;
|
||||
import hep.dataforge.io.IOManager;
|
||||
import hep.dataforge.io.MetaFileReader;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import static inr.numass.NumassContext.printDescription;
|
||||
import inr.numass.workbench.Workbench;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Locale;
|
||||
|
@ -53,7 +53,7 @@ public class NumassContext extends Context {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
attachIoManager(new NumassIO());
|
||||
setIO(new NumassIO());
|
||||
loadPlugin("inr.numass:numass");
|
||||
}
|
||||
|
||||
|
@ -13,154 +13,156 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.models;
|
||||
|
||||
import hep.dataforge.context.GlobalContext;
|
||||
import hep.dataforge.exceptions.NameNotFoundException;
|
||||
import hep.dataforge.functions.AbstractParametricFunction;
|
||||
import hep.dataforge.functions.ParametricFunction;
|
||||
import hep.dataforge.maths.NamedDoubleSet;
|
||||
import static hep.dataforge.names.NamedUtils.combineNamesWithEquals;
|
||||
import static java.lang.Double.isNaN;
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.exp;
|
||||
import static java.lang.Math.sqrt;
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.analysis.integration.SimpsonIntegrator;
|
||||
import org.apache.commons.math3.analysis.integration.UnivariateIntegrator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class GaussResolution extends AbstractParametricFunction implements Transmission {
|
||||
|
||||
private static final String[] list = {"w"};
|
||||
|
||||
private double cutoff = 4d;
|
||||
private final UnivariateIntegrator integrator = new SimpsonIntegrator(1e-3, Double.MAX_VALUE, 3, 64);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cutoff - расстояние в сигмах от среднего значения, на котором
|
||||
* функция считается обращающейся в ноль
|
||||
*/
|
||||
public GaussResolution(double cutoff) {
|
||||
super(list);
|
||||
this.cutoff = cutoff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double derivValue(String name, double X, NamedDoubleSet pars) {
|
||||
if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
|
||||
return 0;
|
||||
}
|
||||
switch (name) {
|
||||
case "pos":
|
||||
return this.value(X, pars) * (X - getPos(pars)) / getW(pars) / getW(pars);
|
||||
case "w":
|
||||
return this.value(X, pars) * ((X - getPos(pars)) * (X - getPos(pars)) / getW(pars) / getW(pars) / getW(pars) - 1 / getW(pars));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParametricFunction getConvolutedSpectrum(final RangedNamedSetSpectrum bare) {
|
||||
return new AbstractParametricFunction(combineNamesWithEquals(this.namesAsArray(), bare.namesAsArray())) {
|
||||
int maxEval = GlobalContext.instance().getInt("INTEGR_POINTS", 500);
|
||||
|
||||
@Override
|
||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
||||
double a = getLowerBound(set);
|
||||
double b = getUpperBound(set);
|
||||
assert b > a;
|
||||
return integrator.integrate(maxEval, getDerivProduct(parName, bare, set, x), a, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean providesDeriv(String name) {
|
||||
if ("w".equals(name)) {
|
||||
return true;
|
||||
}
|
||||
return bare.providesDeriv(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double value(double x, NamedDoubleSet set) {
|
||||
double a = getLowerBound(set);
|
||||
double b = getUpperBound(set);
|
||||
assert b > a;
|
||||
return integrator.integrate(maxEval, getProduct(bare, set, x), a, b);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeriv(String name, NamedDoubleSet set, double input, double output) {
|
||||
return this.derivValue(name, output - input, set);
|
||||
}
|
||||
|
||||
private UnivariateFunction getDerivProduct(final String name, final ParametricFunction bare, final NamedDoubleSet pars, final double x0) {
|
||||
return (double x) -> {
|
||||
double res1;
|
||||
double res2;
|
||||
try {
|
||||
res1 = bare.derivValue(name, x0 - x, pars) * GaussResolution.this.value(x, pars);
|
||||
} catch (NameNotFoundException ex1) {
|
||||
res1 = 0;
|
||||
}
|
||||
try {
|
||||
res2 = bare.value(x0 - x, pars) * GaussResolution.this.derivValue(name, x, pars);
|
||||
} catch (NameNotFoundException ex2) {
|
||||
res2 = 0;
|
||||
}
|
||||
return res1 + res2;
|
||||
};
|
||||
}
|
||||
|
||||
private double getLowerBound(final NamedDoubleSet pars) {
|
||||
return getPos(pars) - cutoff * getW(pars);
|
||||
}
|
||||
|
||||
private double getPos(NamedDoubleSet pars) {
|
||||
// return pars.getValue("pos");
|
||||
// вряд ли стоит ожидать, что разрешение будет сдвигать среднее, поэтому оставляем один параметр
|
||||
return 0;
|
||||
}
|
||||
|
||||
private UnivariateFunction getProduct(final ParametricFunction bare, final NamedDoubleSet pars, final double x0) {
|
||||
return (double x) -> {
|
||||
double res = bare.value(x0 - x, pars) * GaussResolution.this.value(x, pars);
|
||||
assert !isNaN(res);
|
||||
return res;
|
||||
};
|
||||
}
|
||||
|
||||
private double getUpperBound(final NamedDoubleSet pars) {
|
||||
return getPos(pars) + cutoff * getW(pars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue(NamedDoubleSet set, double input, double output) {
|
||||
return this.value(output - input, set);
|
||||
}
|
||||
|
||||
private double getW(NamedDoubleSet pars) {
|
||||
return pars.getValue("w");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean providesDeriv(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double value(double X, NamedDoubleSet pars) {
|
||||
if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
|
||||
return 0;
|
||||
}
|
||||
double aux = (X - getPos(pars)) / getW(pars);
|
||||
return exp(-aux * aux / 2) / getW(pars) / sqrt(2 * Math.PI);
|
||||
}
|
||||
}
|
||||
package inr.numass.models;
|
||||
|
||||
import hep.dataforge.context.GlobalContext;
|
||||
import hep.dataforge.exceptions.NameNotFoundException;
|
||||
import hep.dataforge.functions.AbstractParametricFunction;
|
||||
import hep.dataforge.functions.ParametricFunction;
|
||||
import hep.dataforge.maths.NamedDoubleSet;
|
||||
import static hep.dataforge.names.NamedUtils.combineNamesWithEquals;
|
||||
import static java.lang.Double.isNaN;
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.exp;
|
||||
import static java.lang.Math.sqrt;
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.analysis.integration.SimpsonIntegrator;
|
||||
import org.apache.commons.math3.analysis.integration.UnivariateIntegrator;
|
||||
import static java.lang.Double.isNaN;
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class GaussResolution extends AbstractParametricFunction implements Transmission {
|
||||
|
||||
private static final String[] list = {"w"};
|
||||
|
||||
private double cutoff = 4d;
|
||||
private final UnivariateIntegrator integrator = new SimpsonIntegrator(1e-3, Double.MAX_VALUE, 3, 64);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cutoff - расстояние в сигмах от среднего значения, на котором
|
||||
* функция считается обращающейся в ноль
|
||||
*/
|
||||
public GaussResolution(double cutoff) {
|
||||
super(list);
|
||||
this.cutoff = cutoff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double derivValue(String name, double X, NamedDoubleSet pars) {
|
||||
if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
|
||||
return 0;
|
||||
}
|
||||
switch (name) {
|
||||
case "pos":
|
||||
return this.value(X, pars) * (X - getPos(pars)) / getW(pars) / getW(pars);
|
||||
case "w":
|
||||
return this.value(X, pars) * ((X - getPos(pars)) * (X - getPos(pars)) / getW(pars) / getW(pars) / getW(pars) - 1 / getW(pars));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParametricFunction getConvolutedSpectrum(final RangedNamedSetSpectrum bare) {
|
||||
return new AbstractParametricFunction(combineNamesWithEquals(this.namesAsArray(), bare.namesAsArray())) {
|
||||
int maxEval = GlobalContext.instance().getInt("INTEGR_POINTS", 500);
|
||||
|
||||
@Override
|
||||
public double derivValue(String parName, double x, NamedDoubleSet set) {
|
||||
double a = getLowerBound(set);
|
||||
double b = getUpperBound(set);
|
||||
assert b > a;
|
||||
return integrator.integrate(maxEval, getDerivProduct(parName, bare, set, x), a, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean providesDeriv(String name) {
|
||||
if ("w".equals(name)) {
|
||||
return true;
|
||||
}
|
||||
return bare.providesDeriv(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double value(double x, NamedDoubleSet set) {
|
||||
double a = getLowerBound(set);
|
||||
double b = getUpperBound(set);
|
||||
assert b > a;
|
||||
return integrator.integrate(maxEval, getProduct(bare, set, x), a, b);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDeriv(String name, NamedDoubleSet set, double input, double output) {
|
||||
return this.derivValue(name, output - input, set);
|
||||
}
|
||||
|
||||
private UnivariateFunction getDerivProduct(final String name, final ParametricFunction bare, final NamedDoubleSet pars, final double x0) {
|
||||
return (double x) -> {
|
||||
double res1;
|
||||
double res2;
|
||||
try {
|
||||
res1 = bare.derivValue(name, x0 - x, pars) * GaussResolution.this.value(x, pars);
|
||||
} catch (NameNotFoundException ex1) {
|
||||
res1 = 0;
|
||||
}
|
||||
try {
|
||||
res2 = bare.value(x0 - x, pars) * GaussResolution.this.derivValue(name, x, pars);
|
||||
} catch (NameNotFoundException ex2) {
|
||||
res2 = 0;
|
||||
}
|
||||
return res1 + res2;
|
||||
};
|
||||
}
|
||||
|
||||
private double getLowerBound(final NamedDoubleSet pars) {
|
||||
return getPos(pars) - cutoff * getW(pars);
|
||||
}
|
||||
|
||||
private double getPos(NamedDoubleSet pars) {
|
||||
// return pars.getValue("pos");
|
||||
// вряд ли стоит ожидать, что разрешение будет сдвигать среднее, поэтому оставляем один параметр
|
||||
return 0;
|
||||
}
|
||||
|
||||
private UnivariateFunction getProduct(final ParametricFunction bare, final NamedDoubleSet pars, final double x0) {
|
||||
return (double x) -> {
|
||||
double res = bare.value(x0 - x, pars) * GaussResolution.this.value(x, pars);
|
||||
assert !isNaN(res);
|
||||
return res;
|
||||
};
|
||||
}
|
||||
|
||||
private double getUpperBound(final NamedDoubleSet pars) {
|
||||
return getPos(pars) + cutoff * getW(pars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue(NamedDoubleSet set, double input, double output) {
|
||||
return this.value(output - input, set);
|
||||
}
|
||||
|
||||
private double getW(NamedDoubleSet pars) {
|
||||
return pars.getValue("w");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean providesDeriv(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double value(double X, NamedDoubleSet pars) {
|
||||
if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
|
||||
return 0;
|
||||
}
|
||||
double aux = (X - getPos(pars)) / getW(pars);
|
||||
return exp(-aux * aux / 2) / getW(pars) / sqrt(2 * Math.PI);
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,14 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -18,6 +18,7 @@ import hep.dataforge.data.FileDataFactory;
|
||||
import hep.dataforge.description.ActionDescriptor;
|
||||
import hep.dataforge.description.DescriptorUtils;
|
||||
import hep.dataforge.exceptions.NameNotFoundException;
|
||||
import hep.dataforge.fx.FXProcessManager;
|
||||
import hep.dataforge.fx.LogOutputPane;
|
||||
import hep.dataforge.fx.MetaEditor;
|
||||
import hep.dataforge.fx.MetaTreeItem;
|
||||
@ -30,6 +31,7 @@ import hep.dataforge.meta.MetaBuilder;
|
||||
import hep.dataforge.plots.PlotFrame;
|
||||
import hep.dataforge.plots.PlotHolder;
|
||||
import hep.dataforge.plots.PlotsPlugin;
|
||||
import hep.dataforge.plots.fx.PlotContainer;
|
||||
import hep.dataforge.utils.MetaFactory;
|
||||
import hep.dataforge.values.Value;
|
||||
import inr.numass.NumassIO;
|
||||
@ -48,13 +50,16 @@ import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Accordion;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TitledPane;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import org.controlsfx.control.StatusBar;
|
||||
|
||||
/**
|
||||
@ -76,6 +81,9 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
|
||||
Map<String, StagePane> stages = new ConcurrentHashMap<>();
|
||||
|
||||
FXProcessManager processManager = new FXProcessManager();
|
||||
Stage processManagerStage;
|
||||
|
||||
@FXML
|
||||
private StatusBar statusBar;
|
||||
@FXML
|
||||
@ -126,7 +134,8 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
|
||||
private void buildContext(Meta config) {
|
||||
this.context = this.contextFactory.build(parentContext, config);
|
||||
context.attachIoManager(new WorkbenchIOManager(new NumassIO(), this));
|
||||
context.setIO(new WorkbenchIOManager(new NumassIO(), this));
|
||||
context.setProcessManager(processManager);
|
||||
buildContextPane();
|
||||
this.logPane.attachLog(context);
|
||||
context.getLogger().addAppender(logPane.getLoggerAppender());
|
||||
@ -136,6 +145,20 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
((PlotsPlugin) context.provide("plots")).setPlotHolderDelegate(this);
|
||||
}
|
||||
|
||||
private void showTaskPane() {
|
||||
if (processManagerStage == null) {
|
||||
processManagerStage = new Stage();
|
||||
processManagerStage.setWidth(400);
|
||||
processManagerStage.setHeight(400);
|
||||
AnchorPane pane = new AnchorPane();
|
||||
processManager.show(pane);
|
||||
Scene scene = new Scene(pane, 400, 400);
|
||||
processManagerStage.setTitle("Task manager");
|
||||
processManagerStage.setScene(scene);
|
||||
}
|
||||
processManagerStage.show();
|
||||
}
|
||||
|
||||
private Tab findTabWithName(TabPane pane, String name) {
|
||||
return pane.getTabs().stream().filter((t) -> t.getText().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
@ -304,6 +327,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
@SuppressWarnings("unchecked")
|
||||
public void runActions() {
|
||||
clearAllStages();
|
||||
showTaskPane();
|
||||
new Thread(() -> {
|
||||
DataNode data = new FileDataFactory().build(getContext(), getDataConfiguration());
|
||||
if (data.isEmpty()) {
|
||||
|
@ -14,6 +14,7 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
@ -29,7 +30,7 @@ public class Workbench extends Application {
|
||||
|
||||
NumassWorkbenchController controller = loader.getController();
|
||||
controller.setContextFactory(NumassContext::new);
|
||||
|
||||
|
||||
primaryStage.setTitle("Numass workbench");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
@ -24,6 +24,7 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Locale;
|
||||
import static java.util.Locale.setDefault;
|
||||
import static java.util.Locale.setDefault;
|
||||
|
||||
/**
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user