Skip to content

Commit b4b32b2

Browse files
committed
fix
1 parent f0970cf commit b4b32b2

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,14 @@ private void fitPulses(DetectorDataDgtz data, IndexedTable cfg) {
220220
if (adc.getPulseSize() > 0) {
221221
try {
222222
ExtendedFADCFitter[] hits = extendedFitter.multiFit(nsa, nsb, tet, ped, adc.getPulseArray());
223+
// the first hit is treated conventionally:
223224
adc.setADC(nsa, nsb);
224225
adc.setIntegral(hits[0].adc + hits[0].ped*(nsa+nsb));
225226
adc.setHeight((short) hits[0].pulsePeakValue);
226227
adc.setTimeWord(hits[0].t0);
227228
adc.setPedestal((short) hits[0].ped);
228-
for (int j = 0; j < hits.length; j++) {
229+
// and extra hits get a new object here:
230+
for (int j = 1; j < hits.length; j++) {
229231
ADCData a = new ADCData();
230232
a.setADC(nsa, nsb);
231233
a.setOrder(adc.getOrder());
@@ -236,6 +238,7 @@ private void fitPulses(DetectorDataDgtz data, IndexedTable cfg) {
236238
data.addADC(a);
237239
}
238240
} catch (Exception e) {
241+
e.printStackTrace();
239242
System.err.println(">>>> error : fitting pulse "+dd.getCrate()+
240243
" / "+dd.getSlot()+" / "+dd.getChannel());
241244
}

‎common-tools/clas-detector/src/main/java/org/jlab/detector/decode/ExtendedFADCFitter.java‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,37 +167,44 @@ public ExtendedFADCFitter[] multiFit(int nsa, int nsb, int tet, int pedr, short[
167167

168168
List<ExtendedFADCFitter> hits = new ArrayList<>();
169169

170-
// start with our conventional pulse fitting:
170+
// initialize with our conventional pulse fitting:
171171
fit(nsa, nsb, tet, pedr, pulse);
172172
hits.add(this);
173173

174174
// and look for more later pulses:
175175
if (pulsePeakPosition > 0) {
176+
177+
// start at the first pulse's maximum and look forward:
176178
boolean belowThreshold = false;
177-
for (int bin=pulsePeakPosition+1; bin<pulse.length; bin++) {
179+
for (int crossBin=pulsePeakPosition+1; crossBin<pulse.length; crossBin++) {
178180

179181
// mark that we went below theshold:
180-
if (pulse[bin] <= ped+tet) belowThreshold = true;
182+
if (pulse[crossBin] <= ped+tet) belowThreshold = true;
181183

182-
// we crossed theshold again, find the next hit:
184+
// we went below and above theshold again:
183185
else if (belowThreshold) {
184186

185187
belowThreshold = false;
186188

187-
// search for the maximum:
188-
for (int maxBin = bin; maxBin<pulse.length; maxBin++) {
189-
// found the next hit's maximum:
189+
// find the maximum:
190+
for (int maxBin = crossBin; maxBin<pulse.length; maxBin++) {
190191
if (pulse[maxBin] < pulse[maxBin-1]) {
191192

192193
// make a new hit:
193194
ExtendedFADCFitter f = new ExtendedFADCFitter();
194-
f.thresholdCrossing = bin;
195+
f.ped = ped;
196+
f.thresholdCrossing = crossBin;
195197
f.pulsePeakPosition = maxBin-1;
196198
f.pulsePeakValue = pulse[maxBin-1];
197199

200+
// define its energy:
201+
final int eLimit = Math.min(pulse.length, crossBin + nsa);
202+
for (int eBin = Math.max(crossBin-nsb,0); eBin < eLimit; eBin++)
203+
f.adc += pulse[eBin] - f.ped;
204+
198205
// find the half-max crossing upwards:
199206
final double halfMax = (pulse[maxBin-1] + baseline)/2;
200-
for (int halfBinUp = bin+1; halfBinUp < maxBin; halfBinUp++) {
207+
for (int halfBinUp = crossBin+1; halfBinUp < maxBin; halfBinUp++) {
201208
if (pulse[halfBinUp] <= halfMax && pulse[halfBinUp+1] > halfMax) {
202209

203210
// define timing:
@@ -220,8 +227,9 @@ else if (belowThreshold) {
220227

221228
// add the new hit we just made:
222229
hits.add(f);
230+
223231
// move search bin forward:
224-
bin = f.pulsePeakPosition;
232+
crossBin = f.pulsePeakPosition;
225233
break;
226234
}
227235
}

0 commit comments

Comments
 (0)