View Javadoc

1   package org.lcsim.recon.tracking.vsegment.geom.sensortypes;
2   
3   import java.util.*;
4   
5   import hep.physics.vec.BasicHep3Vector;
6   import hep.physics.vec.Hep3Vector;
7   
8   import org.lcsim.recon.tracking.vsegment.geom.SensorType;
9   
10  /**
11   *
12   * @author D.Onoprienko
13   * @version $Id: WedgeSideParallel.java,v 1.1 2008/12/06 21:53:44 onoprien Exp $
14   */
15  public class WedgeSideParallel implements SensorType {
16    
17  // -- Constructors :  ----------------------------------------------------------
18    
19    public WedgeSideParallel(boolean left, double shortBase, double longBase, double angle, double pitch, double thickness) {
20      _left = left;
21      _thickness = thickness;
22      _pitch = pitch;
23      _tan = Math.tan(angle/2.);
24      _cotan2 = 1./Math.tan(angle);
25      _side = ((longBase - shortBase)/2.)/Math.sin(angle/2.);
26      _maxID = (int) Math.floor((longBase * Math.cos(angle/2.))/pitch);
27      _uCorner = shortBase * Math.cos(angle/2.);
28      _offset = (left) ? 0. : (_maxID * pitch) - _uCorner;
29      _vConst = - (shortBase/2.) / Math.sin(angle/2.);
30      
31    }
32  
33    public WedgeSideParallel(double rMin, double side, double angle, double pitch, boolean left, double thickness) {
34      _left = left;
35      _thickness = thickness;
36      _side = side;
37      _tan = Math.tan(angle/2.);
38      _cotan2 = 1./Math.tan(angle);
39      _pitch = pitch;
40      _maxID = (int) Math.floor(((rMin+side)*Math.sin(angle))/pitch);
41      _uCorner = rMin * Math.sin(angle);
42      _offset = (left) ? 0. : (_maxID * pitch) - _uCorner;
43      _vConst = - rMin;
44    }
45  // -----------------------------------------------------------------------------
46  
47    /**
48     * Converts a point in local sensor coordinates to channel ID.
49     * Returns -1 if the point is outside of sensor sensitive area.
50     */
51    public int getChannelID(Hep3Vector point) {
52      double u = point.x();
53      int channel = (int) Math.floor((u + _offset) / _pitch);
54      return ((channel < 0) || (channel > _maxID)) ? -1 : channel;
55    }
56    
57    /**
58     * Returns position of the center of a given channel, in local sensor coordinates.
59     */
60    public Hep3Vector getChannelPosition(int channelID) {
61      double u = ((channelID + .5) * _pitch) - _offset;
62      double v;
63      if (_left) {
64        if (u < _uCorner) {
65          v = _side/2. - u * _tan;
66        } else {
67          v = ((_side - u * _tan) + (u * _cotan2 + _vConst) )/2.;
68        }
69      } else {
70        if (u < 0.) {
71          v = (_side + u * _tan - u * _cotan2 )/2.;
72        } else {
73          v = _side/2. + u * _tan;
74        }
75      }
76      return new BasicHep3Vector(u,v,0.);
77    }
78    
79    /** Returns maximum channel ID on this sensor. */
80    public int getMaxChannelID() {
81      return _maxID;
82    }
83    
84    /** Returns <tt>true</tt> if channel with this ID exists on this sensor. */
85    public boolean isValidChannelID(int channelID) {
86      return channelID > -1 && channelID <= _maxID;
87    }
88    
89    /** Returns dimensions of a given channel along U, V, W. */
90    public Hep3Vector getChannelDimensions(int channelID) {
91      double u = ((channelID + .5) * _pitch) - _offset;
92      double length;
93      if (_left) {
94        if (u < _uCorner) {
95          length = _side;
96        } else {
97          length = (_side - u * _tan) - (u * _cotan2 + _vConst);
98        }
99      } else {
100       if (u < 0.) {
101         length = (_side + u * _tan) + u * _cotan2 ;
102       } else {
103         length = _side;
104       }
105     }
106     if (length < 0.) System.out.println("U: "+u+" left "+_left);
107     return new BasicHep3Vector(_pitch, length, _thickness);
108     
109   }
110   
111   /**
112    * Returns the dimension of a measurement by this type of sensor (1 since 
113    * <tt>WedgeSideParallel</tt> is always tiled with strips).
114    */
115   public int getHitDimension() {return 1;}
116   
117   /**
118    * Returns ID of a channel obtained by shifting the given channel by the given
119    * number of channels in the given direction along the local reference frame axis. 
120    * Returns <tt>-1</tt> if shifting puts the point outside of the sensor boundaries.
121    * Throws <tt>IllegalArgumentException</tt> if this type of sensor does not have a
122    * concept of a neighbor in the given direction. 
123    *
124    * @param channelID  ID of the original channel
125    * @param shiftV     move in <tt>V</tt> direction by <tt>shiftV</tt> channels
126    * @param shiftU     move in <tt>U</tt> direction by <tt>shiftU</tt> channels
127    */
128   public int getNeighbor(int channelID, int shiftU, int shiftV) {
129     if (shiftV != 0) return -1;
130     int channel = channelID + shiftU;
131     return ((channel < 0) || (channel > _maxID)) ? -1 : channel;
132   }
133   
134   /**
135    * Returns array of IDs of all immediate neighbor channels.
136    */
137   public List<Integer> getNeighbors(int channelID) {
138     ArrayList<Integer> out = new ArrayList<Integer>(2);
139     if (channelID > 0) out.add(channelID - 1);
140     if (channelID < _maxID) out.add(channelID + 1);
141     return out;
142   }
143   
144   /**
145    * Returns an array of (U,V) coordinates of corners of the sensor.
146    * Useful for event display. The dimensions of the returned array are [4][2].
147    */
148   public double[][] getCorners() {
149     double[][] out = new double[4][2];
150     out[0] = new double[]{0.,0.};
151     if (_left) {
152       out[1] = new double[]{0.,_side};
153       double u = (_side - _vConst) * Math.sin(2.*Math.atan(_tan));
154       out[2] = new double[]{u, _side - u * _tan};
155       out[3] = new double[]{_uCorner, - _uCorner * _tan};
156     } else {
157       double u = - _side * Math.sin(2.*Math.atan(_tan));
158       out[1] = new double[]{u, - u * _cotan2};
159       out[2] = new double[]{_uCorner, _side + _uCorner * _tan};
160       out[3] = new double[]{_uCorner, _uCorner * _tan};
161     }
162     return out;
163   }
164   
165 // -- Private parts :  ---------------------------------------------------------
166   
167   private boolean _left;
168   
169   private int _maxID;
170   private double _thickness;
171   private double _offset;
172   private double _pitch;
173   private double _side;
174   private double _tan;
175   private double _cotan2;
176   private double _uCorner;
177   private double _vConst;
178   
179 }