Skip to content

Commit ccb4336

Browse files
committed
finish it
1 parent c66e151 commit ccb4336

1 file changed

Lines changed: 40 additions & 37 deletions

File tree

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

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -166,49 +166,52 @@ public void fit(DetectorDataDgtz.ADCData data) {
166166
public ExtendedFADCFitter[] multiFit(int nsa, int nsb, int tet, int ped, short[] pulse) {
167167
List<ExtendedFADCFitter> hits = new ArrayList<>();
168168
fit(nsa, nsb, tet, ped, pulse);
169-
boolean belowThreshold = false;
170-
for (int bin=pulsePeakPosition+1; bin<pulse.length; bin++) {
171-
// mark that we went below theshold:
172-
if (pulse[bin] <= ped+tet) belowThreshold = true;
173-
// we crossed theshold again, find the next hit:
174-
else if (belowThreshold) {
175-
belowThreshold = false;
176-
// search for the maximum:
177-
for (int maxBin = bin; maxBin<pulse.length; maxBin++) {
178-
// found the next hit's maximum:
179-
if (pulse[maxBin] < pulse[maxBin-1]) {
180-
// make a new hit:
181-
ExtendedFADCFitter f = new ExtendedFADCFitter();
182-
f.thresholdCrossing = bin;
183-
f.pulsePeakPosition = maxBin-1;
184-
f.pulsePeakValue = pulse[maxBin-1];
185-
final double halfMax = (pulse[maxBin-1] + baseline)/2;
186-
// find the half-max crossing upwards:
187-
for (int halfBinUp = bin+1; halfBinUp < maxBin; halfBinUp++) {
188-
if (pulse[halfBinUp] <= halfMax && pulse[halfBinUp+1] > halfMax) {
189-
int a0 = pulse[halfBinUp];
190-
int a1 = pulse[halfBinUp+1];
191-
f.tcourse = halfBinUp;
192-
f.tfine = ((int) ((halfMax - a0)/(a1-a0) * 64));
193-
f.t0 = (tcourse << 6) + tfine;
194-
// find the half-max crossing downwards:
195-
for (int halfBinDown = halfBinUp; halfBinDown<pulse.length; halfBinDown++) {
196-
if (pulse[halfBinDown] > halfMax && pulse[halfBinDown+1] <= halfMax) {
197-
f.pulseWidth = halfBinDown - halfBinUp;
198-
break;
169+
hits.add(this);
170+
if (pulsePeakPosition > 0) {
171+
boolean belowThreshold = false;
172+
for (int bin=pulsePeakPosition+1; bin<pulse.length; bin++) {
173+
// mark that we went below theshold:
174+
if (pulse[bin] <= ped+tet) belowThreshold = true;
175+
// we crossed theshold again, find the next hit:
176+
else if (belowThreshold) {
177+
belowThreshold = false;
178+
// search for the maximum:
179+
for (int maxBin = bin; maxBin<pulse.length; maxBin++) {
180+
// found the next hit's maximum:
181+
if (pulse[maxBin] < pulse[maxBin-1]) {
182+
// make a new hit:
183+
ExtendedFADCFitter f = new ExtendedFADCFitter();
184+
f.thresholdCrossing = bin;
185+
f.pulsePeakPosition = maxBin-1;
186+
f.pulsePeakValue = pulse[maxBin-1];
187+
final double halfMax = (pulse[maxBin-1] + baseline)/2;
188+
// find the half-max crossing upwards:
189+
for (int halfBinUp = bin+1; halfBinUp < maxBin; halfBinUp++) {
190+
if (pulse[halfBinUp] <= halfMax && pulse[halfBinUp+1] > halfMax) {
191+
int a0 = pulse[halfBinUp];
192+
int a1 = pulse[halfBinUp+1];
193+
f.tcourse = halfBinUp;
194+
f.tfine = ((int) ((halfMax - a0)/(a1-a0) * 64));
195+
f.t0 = (tcourse << 6) + tfine;
196+
// find the half-max crossing downwards:
197+
for (int halfBinDown = halfBinUp; halfBinDown<pulse.length; halfBinDown++) {
198+
if (pulse[halfBinDown] > halfMax && pulse[halfBinDown+1] <= halfMax) {
199+
f.pulseWidth = halfBinDown - halfBinUp;
200+
break;
201+
}
199202
}
203+
break;
200204
}
201-
break;
202205
}
206+
hits.add(f);
207+
// move search bin forward:
208+
bin = hits.getLast().pulsePeakPosition;
209+
break;
203210
}
204-
hits.add(f);
205-
// move search bin forward:
206-
bin = hits.getLast().pulsePeakPosition;
207-
break;
208211
}
212+
// if we didn't generate a hit, stop:
213+
if (hits.isEmpty()) break;
209214
}
210-
// if we didn't generate a hit, stop:
211-
if (hits.isEmpty()) break;
212215
}
213216
}
214217
return hits.stream().toArray(ExtendedFADCFitter[]::new);

0 commit comments

Comments
 (0)