Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Individual pixel gain in spe #204

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/apply_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<property name="auxFolder" value="file:src/main/resources/aux/" />
<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="${auxFolder}" />

<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<!--In case you want to analyze .zfits files.-->
Expand Down
1 change: 1 addition & 0 deletions examples/fellwalker_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<property name="outfile" value="file:/home/fabian/testoutfile_mc.txt" />

<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />

<stream id="fact" class="fact.io.FITSStream" url="${infile}"/>

Expand Down
1 change: 1 addition & 0 deletions examples/forErna/std_analysis_erna.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<property name="pixelDelayFile" value="classpath:/default/delays_lightpulser_20150217.csv" />

<service id="auxService" class="fact.auxservice.SqliteService" url="${db}" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<!-- Has to be a FactFileListMultiStream in order to work on tasks from gridmap and the executor script.-->
Expand Down
1 change: 1 addition & 0 deletions examples/forErna/std_analysis_mc_erna.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<property name="integralGainFile" value="classpath:/default/defaultIntegralGains.csv" />

<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />

<!-- Has to be a FactFileListMultiStream in order to work on tasks from gridmap and the executor script.-->
<stream id="fact" class="fact.io.FactFileListMultiStream" url="${input}">
Expand Down
1 change: 1 addition & 0 deletions examples/mc_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<!-- The calibration service delivers aux data to the processors -->
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />

<!-- Name of the stream and url to the input file -->
<stream id="fact" class="fact.io.FITSStream" url="${infile}" />
Expand Down
1 change: 1 addition & 0 deletions examples/measure_performance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<property name="pixelDelayFile" value="classpath:/default/delays_lightpulser_20150217.csv" />

<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="file:src/main/resources/aux/" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<stream id="fact" class="fact.io.zfits.ZFitsStream" url="${infile}"/>
Expand Down
3 changes: 2 additions & 1 deletion examples/stdAnalysis/data/analysis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<property name="pixelDelayFile" value="classpath:/default/delays_lightpulser_20150217.csv" />

<property name="auxFolder" value="file:src/main/resources/aux/" />
<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="${auxFolder}" />

<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="${auxFolder}" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<!--In case you want to analyze .zfits files.-->
Expand Down
2 changes: 1 addition & 1 deletion examples/stdAnalysis/mc/analysis_mc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<property name="integralGainFile" value="classpath:/default/defaultIntegralGains.csv" />

<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<stream id="fact" class="fact.io.FITSStream" url="${infile}"/>

<process id="2" input="fact">
Expand Down
1 change: 1 addition & 0 deletions examples/stdAnalysis/mc/analysis_mc_dispRF.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<property name="outfile" value="file:/home/fabian/testoutfile_mc.txt" />

<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />

<stream id="fact" class="fact.io.FITSStream" url="${infile}"/>

Expand Down
1 change: 1 addition & 0 deletions examples/studies/closedShutterGainCalibration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<property name="pixelDelayFile" value="classpath:/default/delays_20141114.csv" />

<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="file:src/main/resources/aux/" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<!-- Open Shutter Data: -->
Expand Down
1 change: 1 addition & 0 deletions examples/studies/extractionTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<property name="integralGainFile" value="classpath:/default/defaultIntegralGains.csv" />

<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />

<!-- Name of the stream and url to the input file -->
<stream id="fact" class="fact.io.FITSStream" url="${infile}" />
Expand Down
1 change: 1 addition & 0 deletions examples/studies/fits_writer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<property name="auxFolder" value="file:src/main/resources/aux/" />

<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="${auxFolder}" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<stream id="zfits" class="fact.io.zfits.ZFitsStream" url="${infile}"/>
Expand Down
1 change: 1 addition & 0 deletions examples/studies/jumpStudy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<property name="integralGainFile" value="classpath:/default/gain_sorted_20131127.csv" />
<property name="pixelDelayFile" value="classpath:/default/delays_20141114.csv" />
<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="file:src/main/resources/aux/" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<!-- Name des Streams und pfad zu dem Daten-File -->
<!-- <stream id="fact" class="fact.io.FITSStream" url="file:${infile}" limit="100"/> -->
<stream id="fact" class="fact.io.FITSStream" url="${infile}" />
Expand Down
1 change: 1 addition & 0 deletions examples/studies/muon_fitting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<property name="drsfile" value="file:src/main/resources/testMcDrsFile.drs.fits.gz" />

<property name="integralGainFile" value="classpath:/default/defaultIntegralGains.csv" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<!-- Name of the stream and url to the input file -->
Expand Down
1 change: 1 addition & 0 deletions examples/studies/muon_identification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<property name="auxpath" value="file:src/main/resources/aux/" />

<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="${auxpath}" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<property name="outfile" value="facttools.json" />
Expand Down
3 changes: 2 additions & 1 deletion examples/studies/pedestalNsbStudy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<property name="integralGainFile" value="classpath:/default/gain_sorted_20131127.csv" />
<property name="pixelDelayFile" value="classpath:/default/delays_20141114.csv" />
<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="file:src/main/resources/aux/" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
<!-- Name des Streams und pfad zu dem Daten-File -->
<stream id="fact" class="fact.io.FITSStream" url="${infile}" limit="3" />
Expand All @@ -18,7 +19,7 @@
<fact.datacorrection.RemoveSpikes dataKey="DataCalibrated" outputKey="DataCalibrated" startCellKey="StartCellData" leftBorder="6" spikeLimit="20" topSlopeLimit="16" maxSpikeLength="4" />
<!--<fact.filter.ArrayTimeCorrection dataKey="DataCalibrated" timeCalibConstKey="timeCalibConst" outputKey="DataCalibrated" />-->
<fact.datacorrection.InterpolateTimeSeries calibService="calibService" interpolateTimeLine="True" dataKey="DataCalibrated" dataOutputKey="DataCalibrated" />
<fact.extraction.BasicExtraction dataKey="DataCalibrated" outputKeyMaxAmplPos="maxPos" outputKeyPhotonCharge="photoncharge" url="${integralGainFile}" startSearchWindow="${basicExtraction_startSearchWindow}"
<fact.extraction.BasicExtraction dataKey="DataCalibrated" outputKeyMaxAmplPos="maxPos" outputKeyPhotonCharge="photoncharge" gainService="gainService" startSearchWindow="${basicExtraction_startSearchWindow}"
rangeSearchWindow="${basicExtraction_rangeSearchWindow}" rangeHalfHeightWindow="25" />
<fact.extraction.RisingEdgeForPositions dataKey="DataCalibrated" amplitudePositionsKey="maxPos" outputKey="arrivalTimePos" maxSlopesKey="maxSlopesPos" />
<fact.extraction.RisingEdgePolynomFit dataKey="DataCalibrated" risingEdgeKey="arrivalTimePos" outputKey="arrivalTime" numberOfPoints="11" maxSlopesKey="maxSlopes" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<property name="output" value="file:testoutfile.json" />

<property name="auxFolder" value="file:src/main/resources/aux/" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="${auxFolder}" />

<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<property name="output" value="file:testoutfile.json" />

<property name="auxFolder" value="file:src/main/resources/aux/" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="${auxFolder}" />

<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
Expand Down
5 changes: 3 additions & 2 deletions examples/studies/test_saturated_pulses.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<property name="infile" value="file:src/main/resources/testMcFile.fits.gz" />
<property name="drsfile" value="file:src/main/resources/testMcDrsFile.drs.fits.gz" />
<property name="integralGainFile" value="classpath:/default/defaultIntegralGains.csv" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<!-- Name of the stream and url to the input file -->
<stream id="fact" class="fact.io.FITSStream" url="${infile}" />
<!-- Description of the process and the corresponding stream -->
Expand All @@ -19,15 +20,15 @@
<!--badChidIds="863,868,297,927,80,873,1093,1094,527,528,721,722"-->
<!--/>-->
<stream.flow.Skip condition="%{data.TriggerType} != 4" />
<fact.extraction.BasicExtraction dataKey="DataCalibrated" outputKeyMaxAmplPos="maxPos" outputKeyPhotonCharge="photoncharge" url="${integralGainFile}" startSearchWindow="${basicExtraction_startSearchWindow}"
<fact.extraction.BasicExtraction dataKey="DataCalibrated" outputKeyMaxAmplPos="maxPos" outputKeyPhotonCharge="photoncharge" gainService="gainService" startSearchWindow="${basicExtraction_startSearchWindow}"
rangeSearchWindow="${basicExtraction_rangeSearchWindow}" rangeHalfHeightWindow="25" />
<fact.extraction.EstimateBaseline dataKey="DataCalibrated" outputKey="baseline" firstSlice="10" range="40" />
<fact.extraction.RisingEdgeForPositions dataKey="DataCalibrated" amplitudePositionsKey="maxPos" outputKey="arrivalTimePos" maxSlopesKey="maxSlopesPos" />
<fact.extraction.RisingEdgePolynomFit dataKey="DataCalibrated" risingEdgeKey="arrivalTimePos" outputKey="arrivalTime" numberOfPoints="11" maxSlopesKey="maxSlopes" />
<fact.extraction.TimeOverThreshold dataKey="DataCalibrated" outputKey="timeOverThreshold" firstSliceOverThresholdOutputKey="arrivalTimeTOT" positionsKey="maxPos" threshold="1800" thresholdOutputKey="thresholdForToT" />
<fact.extraction.TimeOverThreshold dataKey="DataCalibrated" outputKey="timeOverThreshold1000" firstSliceOverThresholdOutputKey="arrivalTimeTOT1000" positionsKey="maxPos" threshold="1000" thresholdOutputKey="thresholdForToT1000" />
<fact.datacorrection.CorrectSaturation dataKey="DataCalibrated" outputKey="DataNoSat" totKey="timeOverThreshold" firstSliceOverThresholdKey="arrivalTimeTOT" threshold="1800" maxPosKey="maxPos" baselineKey="baseline" />
<fact.extraction.BasicExtraction dataKey="DataNoSat" outputKeyMaxAmplPos="maxPosNoSat" outputKeyPhotonCharge="phChargeNoSat" url="${integralGainFile}" startSearchWindow="${basicExtraction_startSearchWindow}"
<fact.extraction.BasicExtraction dataKey="DataNoSat" outputKeyMaxAmplPos="maxPosNoSat" outputKeyPhotonCharge="phChargeNoSat" gainService="gainService" startSearchWindow="${basicExtraction_startSearchWindow}"
rangeSearchWindow="${basicExtraction_rangeSearchWindow}" rangeHalfHeightWindow="25" />
<fact.extraction.PhotonChargeTimeOverThreshold timeOverThresholdKey="timeOverThreshold" thresholdKey="thresholdForToT" outputKey="photonchargeSaturated" />
<fact.extraction.PhotonChargeTimeOverThreshold timeOverThresholdKey="timeOverThreshold1000" thresholdKey="thresholdForToT1000" outputKey="photonchargeSaturated1000" />
Expand Down
1 change: 1 addition & 0 deletions examples/studies/timeCalibrationComparison.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<property name="integralGainFile" value="classpath:/default/gain_sorted_20131127.csv" />
<property name="pixelDelayFile" value="classpath:/default/delays_20141114.csv" />
<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="file:src/main/resources/aux/" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />
<!-- Name of the stream and url to the input file -->
<stream id="fact" class="fact.io.FITSStream" url="file:${infile}" />
Expand Down
3 changes: 3 additions & 0 deletions examples/viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<property name="auxFolder" value="file:src/main/resources/aux/" />

<service id="auxService" class="fact.auxservice.AuxFileService" auxFolder="${auxFolder}" />
<service id="gainService" class="fact.calibrationservice.SinglePulseGainCalibService" integralGainFile="${integralGainFile}" />
<service id="calibService" class="fact.calibrationservice.ConstantCalibService" />

<stream id="fact" class="fact.io.hdureader.FITSStream" url="${infile}"/>
Expand All @@ -25,12 +26,14 @@
<fact.photonstream.SinglePulseExtraction
dataKey="DataCalibrated"
outputKey="PhotonArrivals"
gainService="gainService"
/>

<fact.photonstream.ConvertSinglePulses2Timeseries
singlePulsesKey="PhotonArrivals"
baseLineKey="PhotonArrivalsBaseLine"
timeSeriesKey="ReconstructedDataCalibrated"
gainService="gainService"
/>

<fact.ShowViewer key="DataCalibrated" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
52 changes: 9 additions & 43 deletions src/main/java/fact/extraction/BasicExtraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}


}
Loading