diff --git a/numass-main/src/main/groovy/inr/numass/scripts/CountRateSummary.groovy b/numass-main/src/main/groovy/inr/numass/scripts/CountRateSummary.groovy new file mode 100644 index 00000000..984dd715 --- /dev/null +++ b/numass-main/src/main/groovy/inr/numass/scripts/CountRateSummary.groovy @@ -0,0 +1,28 @@ +package inr.numass.scripts + +import hep.dataforge.grind.GrindWorkspaceBuilder +import hep.dataforge.tables.Table +import inr.numass.workspace.* + +/** + * Created by darksnake on 26-Dec-16. + */ + + +GrindWorkspaceBuilder numass = new GrindWorkspaceBuilder().read(new File("D:\\Work\\Numass\\sterile2016_10\\workspace.groovy")).startup { + it.loadTask(NumassPrepareTask) + it.loadTask(NumassTableFilterTask) + it.loadTask(NumassFitScanTask) + it.loadTask(NumassSubstractEmptySourceTask) + it.loadTask(NumassFitScanSummaryTask) + it.loadTask(NumassFitTask) + it.loadTask(NumassFitSummaryTask) +} + +numass.runTask("prepare", "fill_1_all").forEachDataWithType(Table) { + Table table = it.get(); + def dp18 = table.find { it["Uset"] == 18000 } + def dp17 = table.find { it["Uset"] == 17000 } + println "${it.name}\t${dp18["CR"]}\t${dp18["CRerr"]}\t${dp17["CR"]}\t${dp17["CRerr"]}" +} + diff --git a/numass-main/src/main/java/inr/numass/models/sterile/NumassResolution.java b/numass-main/src/main/java/inr/numass/models/sterile/NumassResolution.java index 3d3ec8d0..19f99824 100644 --- a/numass-main/src/main/java/inr/numass/models/sterile/NumassResolution.java +++ b/numass-main/src/main/java/inr/numass/models/sterile/NumassResolution.java @@ -5,13 +5,14 @@ */ package inr.numass.models.sterile; -import hep.dataforge.stat.parametric.AbstractParametricBiFunction; import hep.dataforge.meta.Meta; +import hep.dataforge.stat.parametric.AbstractParametricBiFunction; import hep.dataforge.values.NamedValueSet; import inr.numass.models.ResolutionFunction; -import static java.lang.Math.sqrt; import org.apache.commons.math3.analysis.BivariateFunction; +import static java.lang.Math.sqrt; + /** * * @author Alexander Nozik @@ -60,7 +61,7 @@ public class NumassResolution extends AbstractParametricBiFunction { @Override public double value(double E, double U, NamedValueSet set) { assert resA > 0; - if (resB == 0) { + if (resB <= 0) { return this.getValueFast(E, U); } assert resB > 0; diff --git a/numass-main/src/main/java/inr/numass/workspace/NumassPrepareTask.java b/numass-main/src/main/java/inr/numass/workspace/NumassPrepareTask.java index 2fa76feb..d9b866e3 100644 --- a/numass-main/src/main/java/inr/numass/workspace/NumassPrepareTask.java +++ b/numass-main/src/main/java/inr/numass/workspace/NumassPrepareTask.java @@ -21,9 +21,9 @@ import hep.dataforge.workspace.TaskModel; import inr.numass.actions.MergeDataAction; import inr.numass.actions.MonitorCorrectAction; import inr.numass.actions.PrepareDataAction; -import inr.numass.storage.NumassData; -import inr.numass.storage.NumassDataLoader; -import inr.numass.storage.NumassStorage; +import inr.numass.debunch.DebunchReport; +import inr.numass.debunch.FrameAnalizer; +import inr.numass.storage.*; import java.net.URI; @@ -93,9 +93,9 @@ public class NumassPrepareTask extends AbstractTask { callback.setMaxProgress(StorageUtils.loaderStream(storage).count()); StorageUtils.loaderStream(storage).forEach(pair -> { Loader loader = pair.getValue(); - if (loader instanceof NumassData) { + if (loader instanceof NumassDataLoader) { NumassDataLoader nd = (NumassDataLoader) loader; - Data datum = Data.buildStatic(nd); + Data datum = buildData(context, nd, meta); if (filter.acceptData(pair.getKey(), datum)) { boolean accept = true; if (forwardOnly || reverseOnly) { @@ -124,6 +124,30 @@ public class NumassPrepareTask extends AbstractTask
{ return builder; } + private Data buildData(Context context, NumassDataLoader loader, Meta meta) { + if (meta.hasNode("debunch")) { + return Data.buildStatic(loader.applyRawTransformation(rp -> debunch(context, rp, meta.getMeta("debunch")))); + } else { + return Data.buildStatic(loader); + } + } + + private NMPoint debunch(Context context, RawNMPoint point, Meta meta) { + int upper = meta.getInt("upperchanel", RawNMPoint.MAX_CHANEL); + int lower = meta.getInt("lowerchanel", 0); + double rejectionprob = meta.getDouble("rejectprob", 1e-10); + double framelength = meta.getDouble("framelength", 1); + double maxCR = meta.getDouble("maxcr", 500d); + + double cr = point.selectChanels(lower, upper).getCR(); + if (cr < maxCR) { + DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point); + return new NMPoint(report.getPoint()); + } else { + return new NMPoint(point); + } + } + private DataNode runAction(GenericAction action, ProgressCallback callback, Context context, DataNode data, Meta meta) { return action.run(context, data, meta); } diff --git a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java index 134dfc8f..fc519093 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -200,6 +200,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader new NMPoint(p)); + return readPoint(envelope, NMPoint::new); } private Map> getItems() { @@ -303,11 +304,15 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader getNMPoints() { - return this.getPoints().stream().parallel().map(env -> readPoint(env)).collect(Collectors.toList()); + return this.getPoints().stream().parallel().map(this::readPoint).collect(Collectors.toList()); + } + + public List getNMPoints(Function transformation) { + return this.getPoints().stream().parallel().map(env -> readPoint(env, transformation)).collect(Collectors.toList()); } public List getRawPoints() { - return this.getPoints().stream().parallel().map(env -> readRawPoint(env)).collect(Collectors.toList()); + return this.getPoints().stream().parallel().map(this::readRawPoint).collect(Collectors.toList()); } private List getPoints() { @@ -323,11 +328,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader { List points = getPoints(); - if (getPoints().size() >= 2) { - return readTime(points.get(0).meta()).isAfter(readTime(points.get(1).meta())); - } else { - return false; - } + return getPoints().size() >= 2 && readTime(points.get(0).meta()).isAfter(readTime(points.get(1).meta())); }); } @@ -376,4 +377,44 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader transform) { + return new NumassData() { + @Override + public String getDescription() { + return NumassDataLoader.this.getDescription(); + } + + @Override + public Meta meta() { + return NumassDataLoader.this.meta(); + } + + @Override + public List getNMPoints() { + return NumassDataLoader.this.getNMPoints(transform); + } + + @Override + public boolean isEmpty() { + return NumassDataLoader.this.isEmpty(); + } + + @Override + public Instant startTime() { + return NumassDataLoader.this.startTime(); + } + + @Override + public String getName() { + return NumassDataLoader.this.getName(); + } + }; + } }