1 package org.hps.recon.tracking;
2
3 import java.util.Collection;
4
5 import org.lcsim.event.RawTrackerHit;
6
7
8
9
10
11 public class ShaperPileupFitAlgorithm implements ShaperFitAlgorithm {
12
13 ShaperLinearFitAlgorithm onePulseFitter = new ShaperLinearFitAlgorithm(1);
14 ShaperLinearFitAlgorithm twoPulseFitter = new ShaperLinearFitAlgorithm(2);
15 private boolean debug = false;
16 private double refitThreshold = 0.5;
17 private int totalFits = 0;
18 private int refitAttempts = 0;
19 private int refitsAccepted = 0;
20
21 public ShaperPileupFitAlgorithm() {
22 }
23
24 public ShaperPileupFitAlgorithm(double threshold) {
25 refitThreshold = threshold;
26 }
27
28
29 public Collection<ShapeFitParameters> fitShape(RawTrackerHit rth, PulseShape shape) {
30
31 Collection<ShapeFitParameters> fittedPulses = onePulseFitter.fitShape(rth, shape);
32 double singlePulseChiProb = fittedPulses.iterator().next().getChiProb();
33 totalFits++;
34 if (singlePulseChiProb < refitThreshold) {
35 refitAttempts++;
36
37 Collection<ShapeFitParameters> doublePulse = twoPulseFitter.fitShape(rth, shape);
38 double doublePulseChiProb = doublePulse.iterator().next().getChiProb();
39 if (doublePulseChiProb > singlePulseChiProb) {
40 refitsAccepted++;
41 fittedPulses = doublePulse;
42 }
43 }
44 if (debug && totalFits % 10000 == 0) {
45 System.out.format("%d fits, %d refit attempts, %d refits accepted\n", totalFits, refitAttempts, refitsAccepted);
46 }
47 return fittedPulses;
48 }
49
50 public void setDebug(boolean debug) {
51 this.debug = debug;
52 onePulseFitter.setDebug(debug);
53 twoPulseFitter.setDebug(debug);
54 }
55
56 }