[no commit message]

This commit is contained in:
Alexander Nozik 2016-04-05 22:14:48 +03:00
parent 96aa27758e
commit f1eb4eba02
8 changed files with 191 additions and 157 deletions

View File

@ -118,7 +118,7 @@ public class VACFrame extends javax.swing.JFrame {
initComponents(); initComponents();
split.getRightComponent().setMinimumSize(new Dimension()); split.getRightComponent().setMinimumSize(new Dimension());
split.setDividerLocation(1.0); 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); JTextAreaAppender app = new JTextAreaAppender(consoleBox);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

View File

@ -18,14 +18,12 @@ package inr.numass;
import hep.dataforge.actions.ActionUtils; import hep.dataforge.actions.ActionUtils;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import static hep.dataforge.context.GlobalContext.out; import static hep.dataforge.context.GlobalContext.out;
import hep.dataforge.data.DataNode;
import hep.dataforge.data.FileDataFactory; import hep.dataforge.data.FileDataFactory;
import hep.dataforge.datafitter.MINUITPlugin; import hep.dataforge.datafitter.MINUITPlugin;
import hep.dataforge.io.IOManager; import hep.dataforge.io.IOManager;
import hep.dataforge.io.MetaFileReader; import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import static inr.numass.NumassContext.printDescription; import static inr.numass.NumassContext.printDescription;
import inr.numass.workbench.Workbench;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.Locale; import java.util.Locale;

View File

@ -53,7 +53,7 @@ public class NumassContext extends Context {
} }
private void init() { private void init() {
attachIoManager(new NumassIO()); setIO(new NumassIO());
loadPlugin("inr.numass:numass"); loadPlugin("inr.numass:numass");
} }

View File

@ -13,154 +13,156 @@
* 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.context.GlobalContext; 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 hep.dataforge.maths.NamedDoubleSet;
import static hep.dataforge.names.NamedUtils.combineNamesWithEquals; import static hep.dataforge.names.NamedUtils.combineNamesWithEquals;
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;
import static java.lang.Math.sqrt; 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;
*
* @author Darksnake /**
*/ *
public class GaussResolution extends AbstractParametricFunction implements Transmission { * @author Darksnake
*/
private static final String[] list = {"w"}; public class GaussResolution extends AbstractParametricFunction implements Transmission {
private double cutoff = 4d; private static final String[] list = {"w"};
private final UnivariateIntegrator integrator = new SimpsonIntegrator(1e-3, Double.MAX_VALUE, 3, 64);
private double cutoff = 4d;
/** private final UnivariateIntegrator integrator = new SimpsonIntegrator(1e-3, Double.MAX_VALUE, 3, 64);
*
* @param cutoff - расстояние в сигмах от среднего значения, на котором /**
* функция считается обращающейся в ноль *
*/ * @param cutoff - расстояние в сигмах от среднего значения, на котором
public GaussResolution(double cutoff) { * функция считается обращающейся в ноль
super(list); */
this.cutoff = 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)) { @Override
return 0; public double derivValue(String name, double X, NamedDoubleSet pars) {
} if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
switch (name) { return 0;
case "pos": }
return this.value(X, pars) * (X - getPos(pars)) / getW(pars) / getW(pars); switch (name) {
case "w": case "pos":
return this.value(X, pars) * ((X - getPos(pars)) * (X - getPos(pars)) / getW(pars) / getW(pars) / getW(pars) - 1 / getW(pars)); return this.value(X, pars) * (X - getPos(pars)) / getW(pars) / getW(pars);
default: case "w":
return 0; 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())) { @Override
int maxEval = GlobalContext.instance().getInt("INTEGR_POINTS", 500); public ParametricFunction getConvolutedSpectrum(final RangedNamedSetSpectrum bare) {
return new AbstractParametricFunction(combineNamesWithEquals(this.namesAsArray(), bare.namesAsArray())) {
@Override int maxEval = GlobalContext.instance().getInt("INTEGR_POINTS", 500);
public double derivValue(String parName, double x, NamedDoubleSet set) {
double a = getLowerBound(set); @Override
double b = getUpperBound(set); public double derivValue(String parName, double x, NamedDoubleSet set) {
assert b > a; double a = getLowerBound(set);
return integrator.integrate(maxEval, getDerivProduct(parName, bare, set, x), a, b); 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)) { @Override
return true; public boolean providesDeriv(String name) {
} if ("w".equals(name)) {
return bare.providesDeriv(name); return true;
} }
return bare.providesDeriv(name);
@Override }
public double value(double x, NamedDoubleSet set) {
double a = getLowerBound(set); @Override
double b = getUpperBound(set); public double value(double x, NamedDoubleSet set) {
assert b > a; double a = getLowerBound(set);
return integrator.integrate(maxEval, getProduct(bare, set, x), a, b); 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); @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; private UnivariateFunction getDerivProduct(final String name, final ParametricFunction bare, final NamedDoubleSet pars, final double x0) {
double res2; return (double x) -> {
try { double res1;
res1 = bare.derivValue(name, x0 - x, pars) * GaussResolution.this.value(x, pars); double res2;
} catch (NameNotFoundException ex1) { try {
res1 = 0; res1 = bare.derivValue(name, x0 - x, pars) * GaussResolution.this.value(x, pars);
} } catch (NameNotFoundException ex1) {
try { res1 = 0;
res2 = bare.value(x0 - x, pars) * GaussResolution.this.derivValue(name, x, pars); }
} catch (NameNotFoundException ex2) { try {
res2 = 0; res2 = bare.value(x0 - x, pars) * GaussResolution.this.derivValue(name, x, pars);
} } catch (NameNotFoundException ex2) {
return res1 + res2; res2 = 0;
}; }
} return res1 + res2;
};
private double getLowerBound(final NamedDoubleSet pars) { }
return getPos(pars) - cutoff * getW(pars);
} private double getLowerBound(final NamedDoubleSet pars) {
return getPos(pars) - cutoff * getW(pars);
private double getPos(NamedDoubleSet pars) { }
// return pars.getValue("pos");
// вряд ли стоит ожидать, что разрешение будет сдвигать среднее, поэтому оставляем один параметр private double getPos(NamedDoubleSet pars) {
return 0; // 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); private UnivariateFunction getProduct(final ParametricFunction bare, final NamedDoubleSet pars, final double x0) {
assert !isNaN(res); return (double x) -> {
return res; 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);
} 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); @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");
} private double getW(NamedDoubleSet pars) {
return pars.getValue("w");
@Override }
public boolean providesDeriv(String name) {
return true; @Override
} public boolean providesDeriv(String name) {
return true;
@Override }
public double value(double X, NamedDoubleSet pars) {
if (abs(X - getPos(pars)) > cutoff * getW(pars)) { @Override
return 0; public double value(double X, NamedDoubleSet pars) {
} if (abs(X - getPos(pars)) > cutoff * getW(pars)) {
double aux = (X - getPos(pars)) / getW(pars); return 0;
return exp(-aux * aux / 2) / getW(pars) / sqrt(2 * Math.PI); }
} double aux = (X - getPos(pars)) / getW(pars);
} return exp(-aux * aux / 2) / getW(pars) / sqrt(2 * Math.PI);
}
}

View File

@ -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;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
/** /**
* *

View File

@ -18,6 +18,7 @@ import hep.dataforge.data.FileDataFactory;
import hep.dataforge.description.ActionDescriptor; import hep.dataforge.description.ActionDescriptor;
import hep.dataforge.description.DescriptorUtils; import hep.dataforge.description.DescriptorUtils;
import hep.dataforge.exceptions.NameNotFoundException; import hep.dataforge.exceptions.NameNotFoundException;
import hep.dataforge.fx.FXProcessManager;
import hep.dataforge.fx.LogOutputPane; import hep.dataforge.fx.LogOutputPane;
import hep.dataforge.fx.MetaEditor; import hep.dataforge.fx.MetaEditor;
import hep.dataforge.fx.MetaTreeItem; import hep.dataforge.fx.MetaTreeItem;
@ -30,6 +31,7 @@ import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.plots.PlotFrame; import hep.dataforge.plots.PlotFrame;
import hep.dataforge.plots.PlotHolder; import hep.dataforge.plots.PlotHolder;
import hep.dataforge.plots.PlotsPlugin; import hep.dataforge.plots.PlotsPlugin;
import hep.dataforge.plots.fx.PlotContainer;
import hep.dataforge.utils.MetaFactory; import hep.dataforge.utils.MetaFactory;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import inr.numass.NumassIO; import inr.numass.NumassIO;
@ -48,13 +50,16 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Accordion; import javafx.scene.control.Accordion;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
import javafx.scene.control.TabPane; import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane; import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import javafx.stage.Stage;
import org.controlsfx.control.StatusBar; import org.controlsfx.control.StatusBar;
/** /**
@ -76,6 +81,9 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
Map<String, StagePane> stages = new ConcurrentHashMap<>(); Map<String, StagePane> stages = new ConcurrentHashMap<>();
FXProcessManager processManager = new FXProcessManager();
Stage processManagerStage;
@FXML @FXML
private StatusBar statusBar; private StatusBar statusBar;
@FXML @FXML
@ -126,7 +134,8 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
private void buildContext(Meta config) { private void buildContext(Meta config) {
this.context = this.contextFactory.build(parentContext, 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(); buildContextPane();
this.logPane.attachLog(context); this.logPane.attachLog(context);
context.getLogger().addAppender(logPane.getLoggerAppender()); context.getLogger().addAppender(logPane.getLoggerAppender());
@ -136,6 +145,20 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
((PlotsPlugin) context.provide("plots")).setPlotHolderDelegate(this); ((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) { private Tab findTabWithName(TabPane pane, String name) {
return pane.getTabs().stream().filter((t) -> t.getText().equals(name)).findFirst().orElse(null); 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") @SuppressWarnings("unchecked")
public void runActions() { public void runActions() {
clearAllStages(); clearAllStages();
showTaskPane();
new Thread(() -> { new Thread(() -> {
DataNode data = new FileDataFactory().build(getContext(), getDataConfiguration()); DataNode data = new FileDataFactory().build(getContext(), getDataConfiguration());
if (data.isEmpty()) { if (data.isEmpty()) {

View File

@ -14,6 +14,7 @@ import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
/** /**
* *
* @author Alexander Nozik * @author Alexander Nozik
@ -29,7 +30,7 @@ public class Workbench extends Application {
NumassWorkbenchController controller = loader.getController(); NumassWorkbenchController controller = loader.getController();
controller.setContextFactory(NumassContext::new); controller.setContextFactory(NumassContext::new);
primaryStage.setTitle("Numass workbench"); primaryStage.setTitle("Numass workbench");
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();

View File

@ -24,6 +24,7 @@ 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;
/** /**
* *