View Javadoc
1   package org.hps.recon.tracking;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   
6   
7   //===>import org.hps.conditions.deprecated.HPSSVTCalibrationConstants.ChannelConstants;
8   import org.lcsim.detector.tracker.silicon.HpsSiSensor;
9   import org.lcsim.event.RawTrackerHit;
10  
11  /**
12   *
13   * @author Matt Graham
14   */
15  // FIXME: Change the name of the class to SimpleShaperFit - OM
16  // TODO: Add class documentation.
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          // mg...put in a cut here to make sure pulse shape is reasonable
59          // if not, set t0 to -99 (which will fail the later t0>0 cut
60          if (iMax == 0 || iMax == 5) {
61              t0 = -99;
62          }
63          // make sure it goes up below iMax
64          for (int i = 0; i < iMax; i++) {
65              if (pedSub[i + 1] < pedSub[i]) {
66                  t0 = -99;
67              }
68          }
69          // ...and down below iMax
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  }