[no commit message]

This commit is contained in:
Alexander Nozik 2016-04-03 15:49:57 +03:00
parent 5ecad13925
commit 96aa27758e
5 changed files with 76 additions and 4 deletions

View File

@ -0,0 +1,67 @@
/*
* 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.scripts
import hep.dataforge.io.ColumnedDataWriter
import hep.dataforge.points.FormatBuilder
import hep.dataforge.points.ListPointSet
import hep.dataforge.points.MapPoint
import hep.dataforge.points.PointSet
import inr.numass.data.NumassData
import inr.numass.data.*
import javafx.stage.FileChooser
NumassData.metaClass.findPoint{double u ->
delegate.getNMPoints().find{it.getUset() == u}.getMapWithBinning(20,true)
}
Map<Double, Double> dif(NumassData data1, NumassData data2, double uset){
Map<Double, Double> spectrum1 = data1.findPoint(uset);
Map<Double, Double> spectrum2 = data2.findPoint(uset);
Map<Double, Double> dif = new LinkedHashMap<>();
spectrum1.each{ key, value -> dif.put(key, Math.max(spectrum1.get(key)-spectrum2.get(key), 0d))}
return dif;
}
def buildSet(NumassData data1, NumassData data2, double... points){
FormatBuilder builder = new FormatBuilder().addNumber("channel");
List<MapPoint> pointList = new ArrayList<>();
for(double point: points){
builder.addNumber(Double.toString(point));
Map<Double, Double> dif = dif(data1, data2, point);
if(pointList.isEmpty()){
for(Double channel : dif.keySet()){
MapPoint p = new MapPoint();
p.putValue("channel",channel);
pointList.add(p);
}
}
for(MapPoint mp:pointList){
double channel = mp.getValue("channel").doubleValue();
mp.putValue(Double.toString(point), dif.get(channel));
}
}
ListPointSet set = new ListPointSet(pointList,builder.build());
}
NumassData data1 = NMFile.readFile(new File("D:\\Work\\Numass\\transmission 2013\\STABIL04.DAT"));
NumassData data2 = NMFile.readFile(new File("D:\\Work\\Numass\\transmission 2013\\DARK04.DAT"));
double[] points = [14500,15000,15500,16000,18100,18200,18300]
ColumnedDataWriter.writeDataSet(System.out, buildSet(data1,data2,points), "Detector spectrum substraction");

View File

@ -19,6 +19,7 @@ import hep.dataforge.names.NamedMetaHolder;
import hep.dataforge.description.ValueDef; import hep.dataforge.description.ValueDef;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.time.Instant; import java.time.Instant;
@ -39,6 +40,10 @@ public class NMFile extends NamedMetaHolder implements NumassData {
return new NMFile(new NumassDataReader(is, fname, config).read()); return new NMFile(new NumassDataReader(is, fname, config).read());
} }
public static NMFile readFile(File file) throws IOException{
return new NMFile(new NumassDataReader(file).read());
}
private final String head; private final String head;
private final List<NMPoint> points; private final List<NMPoint> points;

View File

@ -20,7 +20,6 @@ import hep.dataforge.points.MapPoint;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import static java.util.Arrays.sort;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@ -44,12 +44,15 @@ public class NumassDataReader {
this(file.getStream(), config.getString(FileDataFactory.FILE_NAME_KEY), config); this(file.getStream(), config.getString(FileDataFactory.FILE_NAME_KEY), config);
} }
public NumassDataReader(File file) throws IOException {
this(new FileInputStream(file), file.getName(), Meta.empty());
}
public NumassDataReader(String file, String fname, Meta config) throws FileNotFoundException { public NumassDataReader(String file, String fname, Meta config) throws FileNotFoundException {
this(new FileInputStream(file), fname, config); this(new FileInputStream(file), fname, config);
if ((fname == null) || (fname.isEmpty())) { if ((fname == null) || (fname.isEmpty())) {
name = file; name = file;
} }
} }
public NumassDataReader(InputStream is, String fname, Meta config) { public NumassDataReader(InputStream is, String fname, Meta config) {

View File

@ -48,8 +48,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemException;
import static org.apache.commons.vfs2.FileType.FOLDER; import static org.apache.commons.vfs2.FileType.FOLDER;