View Javadoc

1   package org.lcsim.recon.tracking.vsegment.hitmaking.hitmakers;
2   
3   import hep.physics.matrix.SymmetricMatrix;
4   import hep.physics.vec.BasicHep3Vector;
5   import hep.physics.vec.Hep3Vector;
6   import hep.physics.vec.VecOp;
7   import org.lcsim.recon.cat.util.NoSuchParameterException;
8   import org.lcsim.units.clhep.SystemOfUnits;
9   
10  import org.lcsim.recon.tracking.vsegment.geom.Sensor;
11  import org.lcsim.recon.tracking.vsegment.geom.SensorType;
12  import org.lcsim.recon.tracking.vsegment.hit.DigiTrackerHit;
13  import org.lcsim.recon.tracking.vsegment.hit.TrackerCluster;
14  import org.lcsim.recon.tracking.vsegment.hit.TrackerHit;
15  import org.lcsim.recon.tracking.vsegment.hit.base.TrackerHitPoint;
16  import org.lcsim.recon.tracking.vsegment.hit.base.TrackerHitSegment;
17  import org.lcsim.recon.tracking.vsegment.hitmaking.TrackerHitMaker;
18  import org.lcsim.recon.tracking.vsegment.transform.CartesianToCylindrical;
19  import org.lcsim.recon.tracking.vsegment.transform.Rotation3D;
20  import org.lcsim.recon.tracking.vsegment.transform.Transformation3D;
21  
22  /**
23   * Simplistic <tt>TrackerHitMaker</tt>.
24   * Trajectory is ignored by all methods.
25   * Hit position is calculated as signal-weighted average of all channels.
26   * For strips, the length and V-position of the hit are the length and V-position
27   * of the shortest strip.
28   *
29   * @author D. Onoprienko
30   * @version $Id: TrackerHitMakerBasic.java,v 1.1 2008/12/06 21:53:44 onoprien Exp $
31   */
32  public class TrackerHitMakerBasic implements TrackerHitMaker {
33    
34  // -- Constructors :  ----------------------------------------------------------
35    
36    public TrackerHitMakerBasic() {
37      set("ERROR_PIXELS", 0.005);
38      set("ERROR_STRIPS", 0.007);
39    }
40    
41  // -- Setters :  ---------------------------------------------------------------
42  
43    /**
44     * Set algorithm parameters. 
45     * The following parameters can be set with this method :
46     * <p><dl>
47     * <dt>"ERROR_PIXELS"</dt> <dd>The <tt>values</tt> argument should be a double value
48     *           giving the minimal error to be assigned to hits in pixels, in millimeters.
49     *           <br>Default: <tt>0.005</tt> (no smearing).</dd>
50     * <dt>"ERROR_STRIPS"</dt> <dd>The <tt>values</tt> argument should be a double value
51     *           giving the minimal error to be assigned to hits in stripss, in millimeters.
52     *           <br>Default: <tt>0.007</tt> (no smearing).</dd></dl>
53     * 
54     * @param name   Name of parameter to be set. Case is ignored.
55     * @param values  Zero or more objects or numbers defining the value of the parameter.
56     * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
57     */
58    public void set(String name, Object... values) {
59      Object value = values.length == 0 ? null : values[0];
60      try {
61        if (name.equalsIgnoreCase("ERROR_PIXELS")) {
62          _err2Pixels = ((Double) values[0]) * SystemOfUnits.mm;
63          _err2Pixels *= _err2Pixels;
64        } else if (name.equalsIgnoreCase("ERROR_STRIPS")) {
65          _err2Strips = ((Double) values[0]) * SystemOfUnits.mm;
66          _err2Strips *= _err2Strips;
67        } else {
68          throw new NoSuchParameterException(name, this.getClass());
69        }
70      } catch (ClassCastException x) {
71        throw new IllegalArgumentException(x);
72      } catch (ArrayIndexOutOfBoundsException xx){
73        throw new IllegalArgumentException(xx);
74      }
75    }
76    
77  // -- Making and updating hits :  ----------------------------------------------
78    
79    /**
80     * Makes a new <tt>TrackerHit</tt>.
81     */
82    public TrackerHit make(TrackerCluster cluster) {
83  
84      Sensor sensor = cluster.getSensor();
85      SensorType sType = sensor.getType();
86      double signal = 0;
87      double[] minDim = new double[]{Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE};
88      int[] minDimChannel = new int[3];
89      double[] posMean = new double[3];
90  //    double[] pos2Mean = new double[3];
91      for (DigiTrackerHit digiHit : cluster.getDigiHits()) {
92        double s = digiHit.getSignal();
93        signal += s;
94        int channel = digiHit.getChannel();
95        double[] pos = sType.getChannelPosition(channel).v();
96        double[] dim = sType.getChannelDimensions(channel).v();
97        for (int i=0; i<3; i++) {
98          posMean[i] += pos[i]*s;
99  //        pos2Mean[i] += pos[i]*pos[i]*s;
100         if (dim[i] < minDim[i]) {
101           minDim[i] = dim[i];
102           minDimChannel[i] = channel;
103         }
104       }
105     }
106 
107 //    double[] pos = new double[3];
108 //    double[] error = new double[3];
109     for (int i=0; i<3; i++) {
110       posMean[i] /= signal;
111 //      pos2Mean[i] /= signal;
112 //      double err2 = pos2Mean[i] - posMean[i]*posMean[i];
113 //      error[i] = (err2 > _err2Min) ? err2 : (minDim[i]*minDim[i])/12.;
114 //      pos[i] = posMean[i];
115     }
116     
117     Transformation3D trans = sensor.getRotation();
118     double cU = 1.;
119     if (trans instanceof CartesianToCylindrical) {
120       cU = posMean[2];
121     } else if (trans instanceof Rotation3D) {
122       cU = 1.;
123     } else {
124       throw new RuntimeException("TrackerHitMakerBasic is only intended to work with flat or cylindrical sensors");
125     }
126 
127     TrackerHit hit;
128     if (sType.getHitDimension() == 1) { // Strips
129       posMean[1] = sType.getChannelPosition(minDimChannel[1]).y();
130       double cUU = _err2Strips / (cU*cU);
131       double length = minDim[1];
132       double cVV = (length*length)/12.;
133       SymmetricMatrix cov = new SymmetricMatrix(3, new double[]{cUU, 0., cVV,0., 0., 0.}, true);
134       hit = new TrackerHitSegment(cluster, new BasicHep3Vector(posMean), length, cov, true);
135     } else {  // Pixels
136       double cUU = _err2Pixels / (cU*cU);
137       SymmetricMatrix cov = new SymmetricMatrix(3, new double[]{cUU, 0., _err2Pixels,0., 0., 0.}, true);
138       hit = new TrackerHitPoint(cluster, new BasicHep3Vector(posMean), cov, true);
139     }
140     return hit;
141   }
142   
143 // -- Helper methods:  ---------------------------------------------------------
144 
145   private Hep3Vector sqr(Hep3Vector v) {
146     double[] a = v.v();
147     for (int i=0; i<3; i++) a[i] = a[i]*a[i];
148     return new BasicHep3Vector(a);
149   }
150   
151 // -- Private parts :  ---------------------------------------------------------
152   
153   private double _err2Pixels;
154   private double _err2Strips;
155 }