diff --git a/examples/apply_model.xml b/examples/apply_model.xml
index d5d7325d95..71eaa865d6 100644
--- a/examples/apply_model.xml
+++ b/examples/apply_model.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/examples/fellwalker_example.xml b/examples/fellwalker_example.xml
index a99eaeae5e..a569b2ab1a 100644
--- a/examples/fellwalker_example.xml
+++ b/examples/fellwalker_example.xml
@@ -10,6 +10,7 @@
+
diff --git a/examples/forErna/std_analysis_erna.xml b/examples/forErna/std_analysis_erna.xml
index 8c591342ba..5bef51d55a 100644
--- a/examples/forErna/std_analysis_erna.xml
+++ b/examples/forErna/std_analysis_erna.xml
@@ -11,6 +11,7 @@
+
diff --git a/examples/forErna/std_analysis_mc_erna.xml b/examples/forErna/std_analysis_mc_erna.xml
index a5983bf9f8..4f9d5585d5 100644
--- a/examples/forErna/std_analysis_mc_erna.xml
+++ b/examples/forErna/std_analysis_mc_erna.xml
@@ -8,6 +8,7 @@
+
diff --git a/examples/mc_viewer.xml b/examples/mc_viewer.xml
index 505b1e25f6..bc2a701c6a 100644
--- a/examples/mc_viewer.xml
+++ b/examples/mc_viewer.xml
@@ -8,6 +8,7 @@
+
diff --git a/examples/measure_performance.xml b/examples/measure_performance.xml
index daae93157f..3316de5f55 100644
--- a/examples/measure_performance.xml
+++ b/examples/measure_performance.xml
@@ -7,6 +7,7 @@
+
diff --git a/examples/stdAnalysis/data/analysis.xml b/examples/stdAnalysis/data/analysis.xml
index 421e3c1cd5..aa70016536 100644
--- a/examples/stdAnalysis/data/analysis.xml
+++ b/examples/stdAnalysis/data/analysis.xml
@@ -9,8 +9,9 @@
-
+
+
diff --git a/examples/stdAnalysis/mc/analysis_mc.xml b/examples/stdAnalysis/mc/analysis_mc.xml
index 990c7dbda8..518642b85c 100644
--- a/examples/stdAnalysis/mc/analysis_mc.xml
+++ b/examples/stdAnalysis/mc/analysis_mc.xml
@@ -8,7 +8,7 @@
-
+
diff --git a/examples/stdAnalysis/mc/analysis_mc_dispRF.xml b/examples/stdAnalysis/mc/analysis_mc_dispRF.xml
index a997a79cee..4289d213aa 100644
--- a/examples/stdAnalysis/mc/analysis_mc_dispRF.xml
+++ b/examples/stdAnalysis/mc/analysis_mc_dispRF.xml
@@ -11,6 +11,7 @@
+
diff --git a/examples/studies/closedShutterGainCalibration.xml b/examples/studies/closedShutterGainCalibration.xml
index b83bd42b17..6371d362c9 100644
--- a/examples/studies/closedShutterGainCalibration.xml
+++ b/examples/studies/closedShutterGainCalibration.xml
@@ -8,6 +8,7 @@
+
diff --git a/examples/studies/extractionTest.xml b/examples/studies/extractionTest.xml
index 8bc0ecf7a5..9bb0702fb7 100644
--- a/examples/studies/extractionTest.xml
+++ b/examples/studies/extractionTest.xml
@@ -6,6 +6,7 @@
+
diff --git a/examples/studies/fits_writer.xml b/examples/studies/fits_writer.xml
index ceadb9ad04..69d52e3d9b 100644
--- a/examples/studies/fits_writer.xml
+++ b/examples/studies/fits_writer.xml
@@ -9,6 +9,7 @@
+
diff --git a/examples/studies/jumpStudy.xml b/examples/studies/jumpStudy.xml
index de1a27149d..419c10205a 100644
--- a/examples/studies/jumpStudy.xml
+++ b/examples/studies/jumpStudy.xml
@@ -6,6 +6,7 @@
+
diff --git a/examples/studies/muon_fitting.xml b/examples/studies/muon_fitting.xml
index 8213fed911..b5818806c9 100644
--- a/examples/studies/muon_fitting.xml
+++ b/examples/studies/muon_fitting.xml
@@ -7,6 +7,7 @@
+
diff --git a/examples/studies/muon_identification.xml b/examples/studies/muon_identification.xml
index cbb7bc23b7..47a52209fd 100644
--- a/examples/studies/muon_identification.xml
+++ b/examples/studies/muon_identification.xml
@@ -10,6 +10,7 @@
+
diff --git a/examples/studies/pedestalNsbStudy.xml b/examples/studies/pedestalNsbStudy.xml
index ddff530cb4..5f5f7d36d1 100644
--- a/examples/studies/pedestalNsbStudy.xml
+++ b/examples/studies/pedestalNsbStudy.xml
@@ -6,6 +6,7 @@
+
@@ -18,7 +19,7 @@
-
diff --git a/examples/studies/singlePeExtractor/singlePeMinimalExample.xml b/examples/studies/singlePeExtractor/singlePeMinimalExample.xml
index 76449fb55f..2db9801ac8 100644
--- a/examples/studies/singlePeExtractor/singlePeMinimalExample.xml
+++ b/examples/studies/singlePeExtractor/singlePeMinimalExample.xml
@@ -11,6 +11,7 @@
+
diff --git a/examples/studies/singlePeExtractor/std_analysis_on_reconstructed_data.xml b/examples/studies/singlePeExtractor/std_analysis_on_reconstructed_data.xml
index db8a43c0c3..73dd4932fc 100644
--- a/examples/studies/singlePeExtractor/std_analysis_on_reconstructed_data.xml
+++ b/examples/studies/singlePeExtractor/std_analysis_on_reconstructed_data.xml
@@ -11,6 +11,7 @@
+
diff --git a/examples/studies/test_saturated_pulses.xml b/examples/studies/test_saturated_pulses.xml
index e802852706..a1dbdb41af 100644
--- a/examples/studies/test_saturated_pulses.xml
+++ b/examples/studies/test_saturated_pulses.xml
@@ -4,6 +4,7 @@
+
@@ -19,7 +20,7 @@
-
@@ -27,7 +28,7 @@
-
diff --git a/examples/studies/timeCalibrationComparison.xml b/examples/studies/timeCalibrationComparison.xml
index a98c3b5712..8d0899f6cb 100644
--- a/examples/studies/timeCalibrationComparison.xml
+++ b/examples/studies/timeCalibrationComparison.xml
@@ -6,6 +6,7 @@
+
diff --git a/examples/viewer.xml b/examples/viewer.xml
index 744258c08f..421b7570b4 100644
--- a/examples/viewer.xml
+++ b/examples/viewer.xml
@@ -8,6 +8,7 @@
+
@@ -25,12 +26,14 @@
diff --git a/src/main/java/fact/calibrationservice/SinglePulseGainCalibService.java b/src/main/java/fact/calibrationservice/SinglePulseGainCalibService.java
new file mode 100644
index 0000000000..11a07164b9
--- /dev/null
+++ b/src/main/java/fact/calibrationservice/SinglePulseGainCalibService.java
@@ -0,0 +1,66 @@
+package fact.calibrationservice;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import stream.annotations.Parameter;
+import stream.io.SourceURL;
+import stream.io.CsvStream;
+import stream.Data;
+import fact.Constants;
+import stream.service.Service;
+
+/**
+ *
+ **/
+public class SinglePulseGainCalibService implements Service {
+
+ Logger log = LoggerFactory.getLogger(SinglePulseGainCalibService.class);
+
+ boolean isInit = false;
+ public double[] integralSinglePulseGain;
+
+ @Parameter(
+ required = false,
+ description = "The path to the integral single pulse gain file."
+ )
+ SourceURL integralGainFile;
+
+ public void init() {
+ integralSinglePulseGain = new double[Constants.NUMBEROFPIXEL];
+ Data integralGainData = null;
+ try {
+ CsvStream stream = new CsvStream(integralGainFile, " ");
+ stream.setHeader(false);
+ stream.init();
+ integralGainData = stream.readNext();
+
+ for (int i = 0 ; i < Constants.NUMBEROFPIXEL ; i++){
+ String key = "column:" + (i);
+ integralSinglePulseGain[i] = (Double) integralGainData.get(key);
+ }
+
+ } catch (Exception e) {
+ log.error(
+ "Failed to load the integral single pulse gain file: {}",
+ e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ public double[] getIntegralSinglePulseGain() {
+ if (isInit == false){
+ init();
+ isInit = true;
+ }
+ return integralSinglePulseGain;
+ }
+
+ @Override
+ public void reset() throws Exception {
+ }
+
+ public void setIntegralGainFile(SourceURL integralGainFile) {
+ this.integralGainFile = integralGainFile;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/fact/extraction/BasicExtraction.java b/src/main/java/fact/extraction/BasicExtraction.java
index 2d40327d8a..45e79ca0ef 100644
--- a/src/main/java/fact/extraction/BasicExtraction.java
+++ b/src/main/java/fact/extraction/BasicExtraction.java
@@ -2,14 +2,14 @@
import fact.Constants;
import fact.Utils;
+import fact.calibrationservice.SinglePulseGainCalibService;
import org.jfree.chart.plot.IntervalMarker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import stream.Data;
import stream.Processor;
import stream.annotations.Parameter;
-import stream.io.CsvStream;
-import stream.io.SourceURL;
+import stream.annotations.Service;
/**
* This processor performs a basic extraction on the data array. It contains three steps:
@@ -31,9 +31,8 @@ public class BasicExtraction implements Processor {
protected String outputKeyMaxAmplPos = null;
@Parameter(required = true, description="outputKey for the calculated photoncharge")
protected String outputKeyPhotonCharge = null;
-
- @Parameter(required = false, description = "The url to the inputfiles for the gain calibration constants",defaultValue="file:src/main/resources/defaultIntegralGains.csv")
- protected SourceURL url = null;
+ @Service(required = true, description = "The calibration service for the integral single pulse gain")
+ SinglePulseGainCalibService gainService;
@Parameter(required = false, description="start slice of the search window for the max amplitude", defaultValue="35")
protected int startSearchWindow = 35;
@Parameter(required = false, description="range of the search window for the max amplitude", defaultValue="90")
@@ -55,6 +54,7 @@ public Data process(Data input) {
int roi = (Integer) input.get("NROI");
npix = (Integer) input.get("NPIX");
+ integralGains = gainService.getIntegralSinglePulseGain();
double[] data = (double[]) input.get(dataKey);
@@ -133,29 +133,6 @@ public double calculateIntegral(int px, int startingPosition, int integralSize,
}
return integral;
}
-
-
- public double[] loadIntegralGainFile(SourceURL inputUrl, Logger log) {
- double[] integralGains = new double[npix];
- Data integralGainData = null;
- try {
- CsvStream stream = new CsvStream(inputUrl, " ");
- stream.setHeader(false);
- stream.init();
- integralGainData = stream.readNext();
-
- for (int i = 0 ; i < npix ; i++){
- String key = "column:" + (i);
- integralGains[i] = (Double) integralGainData.get(key);
- }
- return integralGains;
-
- } catch (Exception e) {
- log.error("Failed to load integral Gain data: {}", e.getMessage());
- e.printStackTrace();
- return null;
- }
- }
public String getDataKey() {
return dataKey;
@@ -165,6 +142,10 @@ public void setDataKey(String dataKey) {
this.dataKey = dataKey;
}
+ public void setGainService(SinglePulseGainCalibService gainService) {
+ this.gainService = gainService;
+ }
+
public String getOutputKeyMaxAmplPos() {
return outputKeyMaxAmplPos;
}
@@ -221,19 +202,4 @@ public int getValidMinimalSlice() {
public void setValidMinimalSlice(int validMinimalSlice) {
this.validMinimalSlice = validMinimalSlice;
}
-
- public void setUrl(SourceURL url) {
- try {
- integralGains = loadIntegralGainFile(url,log);
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage());
- }
- this.url = url;
- }
-
- public SourceURL getUrl() {
- return url;
- }
-
-
}
diff --git a/src/main/java/fact/photonstream/ConvertSinglePulses2Timeseries.java b/src/main/java/fact/photonstream/ConvertSinglePulses2Timeseries.java
index edaf72d839..f3b2ae838e 100644
--- a/src/main/java/fact/photonstream/ConvertSinglePulses2Timeseries.java
+++ b/src/main/java/fact/photonstream/ConvertSinglePulses2Timeseries.java
@@ -1,19 +1,22 @@
package fact.photonstream;
+import fact.Constants;
+import fact.calibrationservice.SinglePulseGainCalibService;
import fact.photonstream.timeSeriesExtraction.AddFirstArrayToSecondArray;
-import fact.photonstream.timeSeriesExtraction.SinglePulseExtractor;
import fact.photonstream.timeSeriesExtraction.TemplatePulse;
import fact.photonstream.timeSeriesExtraction.ElementWise;
import org.apache.commons.lang3.ArrayUtils;
import stream.Data;
-import stream.Processor;
+import stream.ProcessContext;
+import stream.StatefulProcessor;
import stream.annotations.Parameter;
+import stream.annotations.Service;
/**
* Created by jebuss on 28.10.16.
*/
-public class ConvertSinglePulses2Timeseries implements Processor {
+public class ConvertSinglePulses2Timeseries implements StatefulProcessor {
@Parameter(required = true, description = "The arrival slices of the single pulses.")
private String singlePulsesKey = null;
@@ -26,6 +29,14 @@ public class ConvertSinglePulses2Timeseries implements Processor {
@Parameter(required = false, description = "The reconstructed baseline of the original time series.")
private String baseLineKey = null;
+ @Service(
+ required = false,
+ description = "The calibration service for the integral single pulse gain"
+ )
+ SinglePulseGainCalibService gainService = null;
+ protected double[] gainCorrection = null;
+ private int npix = Constants.NUMBEROFPIXEL;
+
@Override
public Data process(Data input) {
@@ -57,12 +68,11 @@ public Data process(Data input) {
currentTimeSeries = ElementWise.add(currentTimeSeries, baseLine[pix]);
timeSeries = ArrayUtils.addAll(timeSeries, currentTimeSeries);
- }
- SinglePulseExtractor.Config config = new SinglePulseExtractor.Config();
- timeSeries = ElementWise.multiply(
- timeSeries,
- config.factSinglePeAmplitudeInMv);
+ timeSeries = ElementWise.multiply(
+ timeSeries,
+ gainCorrection[pix]);
+ }
input.put(timeSeriesKey, timeSeries);
@@ -84,4 +94,28 @@ public void setBaseLineKey(String baseLineKey) {
public void setRoi(int roi) {
this.roi = roi;
}
+
+ @Override
+ public void init(ProcessContext processContext) throws Exception {
+
+ double factSinglePePulseIntegral = TemplatePulse.factSinglePePulseIntegral();
+
+ if(gainService == null) {
+ gainCorrection = new double[npix];
+ for(int i=0; i height/2.) {
+ return i - 1;
+ }
+ }
+ return samples.length;
+ }
+
+ public static double integrate(double[] samples, int start, int length) {
+ double sum = 0;
+ for (int i=0; i < length; i++) {
+ sum += samples[start+i];
+ }
+ return sum;
+ }
+
+ public static double mean(double[] foo) {
+ if (foo.length == 0) { return Double.NaN; }
+
+ double m = 0.;
+ for (double a: foo){
+ m += a;
+ }
+ return m / foo.length;
+ }
+
}
\ No newline at end of file
diff --git a/src/main/resources/default/data/extraction.xml b/src/main/resources/default/data/extraction.xml
index 06f4b0016e..62504ef183 100644
--- a/src/main/resources/default/data/extraction.xml
+++ b/src/main/resources/default/data/extraction.xml
@@ -3,7 +3,7 @@
dataKey="DataCalibrated"
outputKeyMaxAmplPos="maxPos"
outputKeyPhotonCharge="photoncharge"
- url="${integralGainFile}"
+ gainService="gainService"
startSearchWindow="${basicExtraction_startSearchWindow}"
rangeSearchWindow="${basicExtraction_rangeSearchWindow}"
rangeHalfHeightWindow="${basicExtraction_rangeHalfHeigthWindow}"
@@ -35,7 +35,7 @@
dataKey="DataCalibrated"
outputKeyMaxAmplPos="maxPos"
outputKeyPhotonCharge="photoncharge"
- url="${integralGainFile}"
+ gainService="gainService"
startSearchWindow="${basicExtraction_startSearchWindow}"
rangeSearchWindow="${basicExtraction_rangeSearchWindow}"
rangeHalfHeightWindow="${basicExtraction_rangeHalfHeigthWindow}"
diff --git a/src/main/resources/default/mc/extraction_mc.xml b/src/main/resources/default/mc/extraction_mc.xml
index f4b1d25d0f..9a49bbe6a7 100644
--- a/src/main/resources/default/mc/extraction_mc.xml
+++ b/src/main/resources/default/mc/extraction_mc.xml
@@ -3,7 +3,7 @@
dataKey="DataCalibrated"
outputKeyMaxAmplPos="maxPos"
outputKeyPhotonCharge="photoncharge"
- url="${integralGainFile}"
+ gainService="gainService"
startSearchWindow="${basicExtraction_startSearchWindow}"
rangeSearchWindow="${basicExtraction_rangeSearchWindow}"
rangeHalfHeightWindow="${basicExtraction_rangeHalfHeigthWindow}"
@@ -35,7 +35,7 @@
dataKey="DataCalibrated"
outputKeyMaxAmplPos="maxPos"
outputKeyPhotonCharge="photoncharge"
- url="${integralGainFile}"
+ gainService="gainService"
startSearchWindow="${basicExtraction_startSearchWindow}"
rangeSearchWindow="${basicExtraction_rangeSearchWindow}"
rangeHalfHeightWindow="${basicExtraction_rangeHalfHeigthWindow}"
diff --git a/src/test/java/fact/UtilsTests.java b/src/test/java/fact/UtilsTests.java
index 56fdc107a8..45206beb81 100644
--- a/src/test/java/fact/UtilsTests.java
+++ b/src/test/java/fact/UtilsTests.java
@@ -14,4 +14,24 @@ public void flattenEmpty2dArray(){
Assert.assertEquals(result.length, 0);
}
+
+ @Test
+ public void flattenSomeArrays(){
+
+ final int num_arrays = 10;
+ final int array_length = 2;
+ double[][] someNumbers = new double[num_arrays][array_length];
+ for (int i=0; i