@@ -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