1 package org.hps.recon.tracking;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6
7
8 import org.lcsim.detector.tracker.silicon.HpsSiSensor;
9 import org.lcsim.event.RawTrackerHit;
10
11
12
13
14
15
16
17 public class DumbShaperFit implements ShaperFitAlgorithm {
18
19 private boolean debug = false;
20
21 public DumbShaperFit() {
22 }
23
24 public void setDebug(boolean debug) {
25 this.debug = debug;
26 }
27
28 @Override
29 public Collection<ShapeFitParameters> fitShape(RawTrackerHit rth, PulseShape shape) {
30 short[] samples = rth.getADCValues();
31 HpsSiSensor sensor =(HpsSiSensor) rth.getDetectorElement();
32 int channel = rth.getIdentifierFieldValue("strip");
33 return fitShape(channel, samples, sensor);
34 }
35
36 public Collection<ShapeFitParameters> fitShape(int channel, short[] samples, HpsSiSensor sensor){
37
38 ShapeFitParameters fitresults = new ShapeFitParameters();
39 double[] pedSub = {-99.0, -99.0, -99.0, -99.0, -99.0, -99.0};
40 double maxADC = -99999;
41 int iMax = -1;
42 double t0 = -999;
43 for (int i = 0; i < 6; i++) {
44 pedSub[i] = samples[i] - sensor.getPedestal(channel, i);
45 if (pedSub[i] > maxADC) {
46 maxADC = pedSub[i];
47 iMax = i;
48 }
49 }
50 if (iMax > 0 && iMax < 5) {
51 t0 = (pedSub[iMax - 1] * 24.0 * (iMax - 1) + pedSub[iMax] * 24.0 * (iMax) + pedSub[iMax + 1] * 24.0 * (iMax + 1)) / (pedSub[iMax - 1] + pedSub[iMax] + pedSub[iMax + 1]);
52 } else if (iMax == 0) {
53 t0 = (pedSub[iMax] * 24.0 * (iMax) + pedSub[iMax + 1] * 24.0 * (iMax + 1)) / (pedSub[iMax] + pedSub[iMax + 1]);
54 } else if (iMax == 5) {
55 t0 = (pedSub[iMax] * 24.0 * (iMax) + pedSub[iMax - 1] * 24.0 * (iMax - 1)) / (pedSub[iMax - 1] + pedSub[iMax]);
56 }
57
58
59
60 if (iMax == 0 || iMax == 5) {
61 t0 = -99;
62 }
63
64 for (int i = 0; i < iMax; i++) {
65 if (pedSub[i + 1] < pedSub[i]) {
66 t0 = -99;
67 }
68 }
69
70 for (int i = iMax; i < 5; i++) {
71 if (pedSub[i + 1] > pedSub[i]) {
72 t0 = -99;
73 }
74 }
75
76 fitresults.setAmp(maxADC);
77 fitresults.setT0(t0);
78
79 ArrayList<ShapeFitParameters> fits = new ArrayList<ShapeFitParameters>();
80 fits.add(fitresults);
81 return fits;
82 }
83 }