Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -217,30 +217,36 @@ public Bank getDataBankADC(String name, DetectorType type){
List<DetectorDataDgtz> adcDGTZ = this.getEntriesADC(type);
if (adcDGTZ.isEmpty()) return null;

Bank adcBANK = new Bank(schemaFactory.getSchema(name), adcDGTZ.size());

Bank adcBANK = new Bank(schemaFactory.getSchema(name),
adcDGTZ.stream().mapToInt(b -> b.getADCSize()).sum());

int row = 0;
for(int i = 0; i < adcDGTZ.size(); i++){
adcBANK.putByte( 0, i, (byte) adcDGTZ.get(i).getDescriptor().getSector());
adcBANK.putByte( 1, i, (byte) adcDGTZ.get(i).getDescriptor().getLayer());
adcBANK.putShort(2, i, (short) adcDGTZ.get(i).getDescriptor().getComponent());
adcBANK.putByte( 3, i, (byte) adcDGTZ.get(i).getDescriptor().getOrder());
adcBANK.putInt( 4, i, adcDGTZ.get(i).getADCData(0).getADC());
if (type == DetectorType.BMT || type == DetectorType.FMT || type == DetectorType.FTTRK) {
adcBANK.putInt( 4, i, adcDGTZ.get(i).getADCData(0).getHeight());
adcBANK.putInt( 7, i, adcDGTZ.get(i).getADCData(0).getIntegral());
adcBANK.putLong(8, i, adcDGTZ.get(i).getADCData(0).getTimeStamp());
}
if(type == DetectorType.BAND) {
adcBANK.putInt( 5, i, adcDGTZ.get(i).getADCData(0).getHeight());
adcBANK.putFloat(6, i, (float) adcDGTZ.get(i).getADCData(0).getTime());
adcBANK.putShort(7, i, (short) adcDGTZ.get(i).getADCData(0).getPedestal());
}
else {
adcBANK.putFloat(5, i, (float) adcDGTZ.get(i).getADCData(0).getTime());
adcBANK.putShort(6, i, (short) adcDGTZ.get(i).getADCData(0).getPedestal());
for (int j = 0; j<adcDGTZ.get(i).getADCSize(); j++) {
adcBANK.putByte( 0, row, (byte) adcDGTZ.get(i).getDescriptor().getSector());
adcBANK.putByte( 1, row, (byte) adcDGTZ.get(i).getDescriptor().getLayer());
adcBANK.putShort(2, row, (short) adcDGTZ.get(i).getDescriptor().getComponent());
adcBANK.putByte( 3, row, (byte) adcDGTZ.get(i).getDescriptor().getOrder());
adcBANK.putInt( 4, row, adcDGTZ.get(i).getADCData(j).getADC());
if (type == DetectorType.BMT || type == DetectorType.FMT || type == DetectorType.FTTRK) {
adcBANK.putInt( 4, row, adcDGTZ.get(i).getADCData(j).getHeight());
adcBANK.putInt( 7, row, adcDGTZ.get(i).getADCData(j).getIntegral());
adcBANK.putLong(8, row, adcDGTZ.get(i).getADCData(j).getTimeStamp());
}
if(type == DetectorType.BAND) {
adcBANK.putInt( 5, row, adcDGTZ.get(i).getADCData(j).getHeight());
adcBANK.putFloat(6, row, (float) adcDGTZ.get(i).getADCData(j).getTime());
adcBANK.putShort(7, row, (short) adcDGTZ.get(i).getADCData(j).getPedestal());
}
else {
adcBANK.putFloat(5, row, (float) adcDGTZ.get(i).getADCData(j).getTime());
adcBANK.putShort(6, row, (short) adcDGTZ.get(i).getADCData(j).getPedestal());
}
if(type == DetectorType.BST) adcBANK.putLong(7, row, adcDGTZ.get(i).getADCData(j).getTimeStamp());
row++;
}
if(type == DetectorType.BST) adcBANK.putLong(7, i, adcDGTZ.get(i).getADCData(0).getTimeStamp());
}
}

return adcBANK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jlab.detector.base.DetectorType;
import org.jlab.detector.calib.utils.ConstantsManager;
import org.jlab.detector.decode.DetectorDataDgtz.ADCData;
import org.jlab.detector.decode.FADCData.Peak;
import org.jlab.utils.groups.IndexedTable;

/**
Expand All @@ -30,7 +31,7 @@ public class DetectorEventDecoder {
private final HashMap<DetectorType,String> transTableNames = new HashMap<>();
private final HashMap<DetectorType,String> fitterTableNames = new HashMap<>();

private final ExtendedFADCFitter extendedFitter = new ExtendedFADCFitter();
private final ExtendedFADCMultiFitter extendedFitter = new ExtendedFADCMultiFitter();
private final MVTFitter mvtFitter = new MVTFitter();

private HashMap<DetectorType,IndexedTable> fitterTables = new HashMap<>();
Expand Down Expand Up @@ -219,17 +220,33 @@ private void fitPulses(DetectorDataDgtz data, IndexedTable cfg) {
ADCData adc = data.getADCData(i);
if(adc.getPulseSize()>0){
try {
extendedFitter.fit(nsa, nsb, tet, ped, adc.getPulseArray());
Peak[] hits = extendedFitter.fit(nsa, nsb, tet, ped, adc.getPulseArray());
if (hits.length > 0) {
adc.setIntegral(hits[0].adc + hits[0].ped*(nsa+nsb));
adc.setHeight((short) hits[0].pulsePeakValue);
adc.setTimeWord(hits[0].t0);
adc.setPedestal((short) hits[0].ped);
adc.setADC(nsa, nsb);
// extra hits get a new object here:
for (int j = 1; j < hits.length; j++) {
ADCData a = new ADCData();
a.setTimeStamp(adc.getTimeStamp());
a.setOrder(adc.getOrder());
a.setIntegral(hits[j].adc + hits[j].ped*(nsa+nsb));
a.setHeight((short) hits[j].pulsePeakValue);
a.setTimeWord(hits[j].t0);
a.setPedestal((short) hits[j].ped);
a.setADC(nsa, nsb);
data.addADC(a);
}
}

} catch (Exception e) {
e.printStackTrace();
System.err.println(">>>> error : fitting pulse "+dd.getCrate()+
" / "+dd.getSlot()+" / "+dd.getChannel());
}
adc.setIntegral(extendedFitter.adc + extendedFitter.ped*(nsa+nsb));
adc.setHeight((short) this.extendedFitter.pulsePeakValue);
adc.setTimeWord(this.extendedFitter.t0);
adc.setPedestal((short) this.extendedFitter.ped);
}
data.getADCData(i).setADC(nsa, nsb);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,22 @@
package org.jlab.detector.decode;

import org.jlab.detector.decode.FADCData.Peak;

/**
*
* @author gavalian
*/
public class ExtendedFADCFitter implements IFADCFitter {

private int pedistalMinBin = 1;
private int pedistalMaxBin = 5;

int p1=1,p2=15;
int mmsum,summing_in_progress;
public class ExtendedFADCFitter extends Peak implements IFADCFitter {

public int t0,adc,ped,pedsum;
public int thresholdCrossing,pulsePeakValue, pulsePeakPosition, pulseWidth;
public double baseline, rms;
private int tcourse, tfine;
private final int pedistalMaxBin = 5;
private final int p1 = 1;
private final int p2 = 15;

public ExtendedFADCFitter(){

}
public ExtendedFADCFitter(){}

public void fitCourseTime(int nsa, int nsb, int tet, int pedr, short[] pulse) {
pedsum=0;adc=0;mmsum=0;summing_in_progress=0;
for (int mm=0; mm<pulse.length; mm++) {
if(mm>p1 && mm<=p2) pedsum+=pulse[mm];
if(mm==p2) pedsum=pedsum/(p2-p1);
if(mm>p2) {
if (pedr==0) ped=pedsum;
if (pedr!=0) ped=pedr;
if ((summing_in_progress==0) && pulse[mm]>ped+tet) {
summing_in_progress=1;
tcourse = mm;
t0 = (tcourse << 6);
for (int ii=1; ii<nsb+1;ii++) adc+=(pulse[mm-ii]-ped);
mmsum=nsb;
}
if(summing_in_progress>0 && mmsum>(nsa+nsb)) summing_in_progress=-1;
if(summing_in_progress>0) {adc+=(pulse[mm]-ped); mmsum++;}
}
}
}

public void fit(int nsa, int nsb, int tet, int pedr, short[] pulse) {
t0=0; adc=0; ped=0; pedsum=0; baseline=0; rms=0;
thresholdCrossing=0; pulsePeakValue=0; pulsePeakPosition=0; pulseWidth=0;
tcourse=0; tfine=0;
@Override
public Peak[] fit(int nsa, int nsb, int tet, int pedr, short[] pulse) {
zero();
double noise = 0;
int tstart = pedistalMaxBin+1;
int tcross = 0;
Expand All @@ -58,7 +29,7 @@ public void fit(int nsa, int nsb, int tet, int pedr, short[] pulse) {
pedsum += pulse[bin];
}
ped=pedsum/pulse.length;
return;
return new Peak[]{this};
}
if (pedr==0) {
tstart = p2+1;
Expand Down Expand Up @@ -109,57 +80,16 @@ public void fit(int nsa, int nsb, int tet, int pedr, short[] pulse) {
int a0 = pulse[s0];
int a1 = pulse[s0+1];
// set course time to be the sample before the 50% crossing
tcourse = s0;
tcoarse = s0;
// set the fine time from interpolation between the two samples before and after the 50% crossing (6 bits resolution)
tfine = ((int) ((halfMax - a0)/(a1-a0) * 64));
t0 = (tcourse << 6) + tfine;
t0 = (tcoarse << 6) + tfine;
}
if(s1>-1 && s0>-1) {
int a0 = pulse[s1];
int a1 = pulse[s1+1];
pulseWidth = s1 - s0;
}
}
}

private double findPedestal(DetectorDataDgtz.ADCData data){
int ped = 0;
for(int i = this.pedistalMinBin; i < this.pedistalMaxBin; i++){
ped += data.getPulseValue(i);
}
double ped_norm = ((double) ped) / (Math.abs(this.pedistalMaxBin-this.pedistalMinBin));
return ped_norm;
}

private int findMaximumADC(DetectorDataDgtz.ADCData data){
int bin = this.pedistalMaxBin ;
int max = data.getPulseValue(pedistalMaxBin);

for(int i = this.pedistalMaxBin; i < data.getPulseSize(); i++){
if(data.getPulseValue(i)>max){
max = data.getPulseValue(i);
bin = i;
}
}
return bin;
}

private int findPulseIntegral(DetectorDataDgtz.ADCData data, int maxValueBin, int nsa, int nsb){
int min_bin = maxValueBin - nsb;
int max_bin = maxValueBin + nsa;
if(min_bin>=0&&max_bin<data.getPulseSize()){

} else {
System.out.println("MIN _ MAX out of range....");
}
return 0;
}

@Override
public void fit(DetectorDataDgtz.ADCData data) {
if(data.getPulseSize()>this.pedistalMaxBin){
double ped = this.findPedestal(data);
}
return new Peak[]{this};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package org.jlab.detector.decode;

import java.util.ArrayList;
import java.util.List;
import org.jlab.detector.decode.FADCData.Peak;

public class ExtendedFADCMultiFitter extends Peak implements IFADCFitter {

static final int PED_BIN1=1;
static final int PED_BIN2=15;

public ExtendedFADCMultiFitter(){}

@Override
public Peak[] fit(int nsa, int nsb, int tet, int pedr, short[] pulse) {

zero();

if (pulse.length < PED_BIN2+1) return new Peak[]{this};

if (pedr != 0) {
// user-defined pedestal:
baseline = ped = pedr;
}
else {
// calculate pedestal:
for (int bin = PED_BIN1+1; bin < PED_BIN2+1; bin++) {
pedsum += pulse[bin];
rms += pulse[bin] * pulse[bin];
}
baseline = ((double) pedsum) / (PED_BIN2 - PED_BIN1);
ped = (int)baseline;
rms = Math.sqrt(rms / (PED_BIN2 - PED_BIN1) - baseline * baseline);
}

boolean belowThreshold = false;
List<Peak> hits = new ArrayList<>(3);

for (int crossBin = PED_BIN2+1; crossBin<pulse.length; crossBin++) {

// mark that we went below theshold:
if (pulse[crossBin] <= ped+tet) belowThreshold = true;

// we went below and above theshold again:
else if (belowThreshold) {

belowThreshold = false;

// find the maximum:
for (int maxBin = crossBin; maxBin<pulse.length; maxBin++) {
if (pulse[maxBin] < pulse[maxBin-1]) {

// found maximum, now make a new hit:
Peak f = new Peak();
hits.add(f);
f.ped = ped;
f.t0 = f.thresholdCrossing = f.tcoarse = crossBin;
f.pulsePeakPosition = maxBin-1;
f.pulsePeakValue = pulse[maxBin-1];

// define its energy:
for (int eBin = Math.max(crossBin-nsb,0); eBin<pulse.length && eBin<crossBin+nsa; eBin++)
f.adc += pulse[eBin] - f.ped;

final double halfMax = (f.pulsePeakValue + baseline)/2;

// find the half-max crossing upwards:
for (int halfBinUp = crossBin; halfBinUp < maxBin; halfBinUp++) {
if (pulse[halfBinUp] <= halfMax && pulse[halfBinUp+1] > halfMax) {

// found half-height, now define timing:
int a0 = pulse[halfBinUp];
int a1 = pulse[halfBinUp+1];
f.tcoarse = halfBinUp;
f.tfine = ((int) ((halfMax - a0)/(a1-a0) * 64));
f.t0 = (f.tcoarse << 6) + f.tfine;

// find the half-max crossing downwards:
for (int halfBinDown = halfBinUp; halfBinDown<pulse.length-1; halfBinDown++) {
if (pulse[halfBinDown] > halfMax && pulse[halfBinDown+1] <= halfMax) {
f.pulseWidth = halfBinDown - halfBinUp;
break;
}
}
break;
}
}

// add the new hit we just made:

// move search bin forward:
crossBin = f.pulsePeakPosition + 1;
break;
}
}
}
}
return hits.stream().toArray(Peak[]::new);
}

}
Loading
Loading