View Javadoc

1   package org.lcsim.geometry;
2   
3   import hep.physics.vec.Hep3Vector;
4   
5   import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
6   import org.lcsim.geometry.util.IDDescriptor;
7   
8   /**
9    * 
10   * The compact detector description's interface for identifier decoding.
11   * 
12   * @author tonyj
13   * @author jeremym
14   */
15  // List of TODOs
16  // -------------
17  // TODO: The getX/Y/Z methods should be removed. Instead use getPosition()[i] or
18  // getPositionVec.x/y/z().
19  // TODO: The findCellContainingXYZ methods probably don't belong here. In general, hard to
20  // implement and not always implemented by subclasses.
21  // This functionality should reside in a geometer class.
22  // TODO: Do NOT need three similar versions of findCellContainingXYZ() in the interface,
23  // because it is confusing. One should be good enough.
24  // TODO: The methods related to getting ID meta information should be left in
25  // IDDescriptor. No need to push these methods up to here and clutter the interface.
26  // TODO: The class hierarchy of sub-classes far too complicated. (CalorimeterIDDecoder,
27  // geometry.util, segmentation, BaseIDDecoder, etc.)
28  // TODO: Methods like getSystemID() should use getValue("system") instead. Same for
29  // getLayer().
30  // TODO: The methods getPhi() and getTheta() can be easily computed from position or
31  // retrieved from position vector.
32  // TODO: The method getSubdetector() needs to be revisted. This should instead be
33  // retrieved from the hit's metadata.
34  // TODO: In general, the fact that the decoder holds "state" of a current ID is not good
35  // and could potentially lead to some odd behaviors. A better
36  // method signature would be getFieldValue("field", int id). Then there is no implied
37  // state in the decoder or interface.
38  public interface IDDecoder
39  {
40      /**
41       * Constant that flags an invalid index, i.e. for a field that does not exist.
42       */
43      public static final int INVALID_INDEX = -1;
44  
45      /**
46       * Load the decoder with a 64-bit id value from the hit.
47       */
48      public void setID( long id );
49  
50      /**
51       * Get the value of the given field.
52       * 
53       * @param field The name of the field.
54       * @return The integer value of the field.
55       */
56      public int getValue( String field );
57  
58      /**
59       * Get the value of a field by index.
60       * 
61       * @param index The index into the id.
62       * @return The integer value of the field.
63       */
64      public int getValue( int index );
65  
66      /**
67       * Get all decoded field values.
68       * 
69       * @param buffer The buffer to receive values.
70       * @return The buffer with field values.
71       */
72      public int[] getValues(int[] buffer);
73      
74      /**
75       * Get the number of fields in this id description.
76       * 
77       * @return The number of fields.
78       */
79      public int getFieldCount();
80  
81      /**
82       * Get field name by index.
83       * 
84       * @param index The index of the field.
85       * @return The field name.
86       */
87      public String getFieldName( int index );
88  
89      /**
90       * Get field index by name.
91       * 
92       * @param name The name of the field.
93       * @return The index of the field.
94       */
95      public int getFieldIndex( String name );
96  
97      /**
98       * Set the ID description of this decoder.
99       * 
100      * @param id The ID description.
101      */
102     public void setIDDescription( IDDescriptor id );
103 
104     /**
105      * Get the ID description of this decoder.
106      * 
107      * @return The ID description.
108      */
109     public IDDescriptor getIDDescription();
110 
111     /**
112      * Get the layer number for the current id.
113      * 
114      * @return layer number
115      */
116     public int getLayer();
117 
118     /**
119      * Get the layer number, possibly adjusted for topologies such as EcalBarrel. The
120      * default implementation returns the value of {{@link #getLayer()}.
121      * 
122      * @return The pseudo layer number.
123      */
124     public int getVLayer();
125 
126     /**
127      * @return Hep3Vector representing the position of the current ID.
128      */
129     public Hep3Vector getPositionVector();
130 
131     /**
132      * @return position as double array of length 3
133      */
134     public double[] getPosition();
135 
136     /**
137      * @return X coordinate
138      */
139     public double getX();
140 
141     /**
142      * @return Y coordinate
143      */
144     public double getY();
145 
146     /**
147      * @return Z coordinate
148      */
149     public double getZ();
150 
151     /**
152      * @return phi angle
153      */
154     public double getPhi();
155 
156     /**
157      * The decoded theta angle of this id.
158      * 
159      * @return The theta angle.
160      */
161     public double getTheta();
162 
163     /**
164      * Locate a cell from a global position.
165      * 
166      * @param pos The position.
167      * @return The cell id.
168      */
169     public long findCellContainingXYZ( Hep3Vector pos );
170 
171     /**
172      * Locate a cell from a global position.
173      * 
174      * @param pos The position.
175      * @return The cell id.
176      */
177     public long findCellContainingXYZ( double[] pos );
178 
179     // Removed. --JM
180     // public long findCellContainingXYZ(double x, double y, double z);
181 
182     /**
183      * Get the flag that indicates barrel or endcap, i.e. the "barrel" field.
184      */
185     public BarrelEndcapFlag getBarrelEndcapFlag();
186 
187     /**
188      * Get the system ID, i.e. the "system" field.
189      */
190     public int getSystemID();
191 
192     /**
193      * @deprecated Use {@link #getSystemID()} instead
194      */
195     public int getSystemNumber();
196 
197     /**
198      * Get the Subdetector associated with this IDDecoder, or null if not applicable.
199      */
200     public Subdetector getSubdetector();
201 
202     /**
203      * Does this Decoder support cell neighboring?
204      * 
205      * @return True if Decoder supports neighbors; false if not.
206      */
207     public boolean supportsNeighbours();
208 
209     /**
210      * Get the current cell's neighbors using default neighboring parameters (usually
211      * 1,1,1).
212      * 
213      * @return The cell neighbors.
214      */
215     public long[] getNeighbourIDs();
216 
217     /**
218      * Get the current cell's neighbors using fully specified neighboring parameters.
219      * 
220      * @param deltaLayer The number of layers to neighbor (plus or minus).
221      * @param deltaTheta The number of cells in theta to neighbor (plus or minus).
222      * @param deltaPhi The number of cells in phi to neighbor (plus or minus).
223      * @return
224      */
225     public long[] getNeighbourIDs( int deltaLayer, int deltaTheta, int deltaPhi );
226 }