View Javadoc

1   package org.lcsim.geometry.compact;
2   
3   import java.awt.Color;
4   
5   import org.jdom.Attribute;
6   import org.jdom.Element;
7   import org.jdom.JDOMException;
8   import org.lcsim.detector.IDetectorElement;
9   import org.lcsim.geometry.IDDecoder;
10  import org.lcsim.geometry.layer.Layering;
11  
12  /**
13   *
14   * Basic implementation of org.lcsim.geometry.Subdetector.
15   *
16   * @author Tony Johnson <tonyj@slac.stanford.edu>
17   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
18   * 
19   * @version $Id: Subdetector.java,v 1.25 2010/12/03 01:23:07 jeremy Exp $
20   */
21  public class Subdetector implements org.lcsim.geometry.Subdetector
22  {
23      // FIXME: Why is reflect a general attribute of Subdetector?  It only makes
24      //        sense for endcaps.
25      // Make default setting true so that when it isn't set, we get two endcaps as expected.
26      private boolean reflect = true;
27  
28      private Readout readout;
29      private String name;
30      private int systemID;
31      //private ParameterSet _parameters;
32      private VisAttributes vis;
33      private Element node;
34      private IDetectorElement de;
35      private boolean insideTrackingVolume = false;
36      String digiCollectionName = null;
37  
38      protected Subdetector(Element element) throws JDOMException
39      {
40          // XML node.
41          node = element;
42          
43          // Subdetector name.
44          name = element.getAttributeValue("name");
45  
46          // Reflect attribute.
47          Attribute r = element.getAttribute("reflect");
48          reflect = r != null && r.getBooleanValue();
49  
50          // Don't need a null check on id, as the compact schema include a default of 0.
51          systemID = element.getAttribute("id").getIntValue();
52  
53          // Check if inside tracking volume.
54          Attribute insideAttrib = node.getAttribute("insideTrackingVolume");
55          try
56          {
57              if (insideAttrib == null)
58              {
59                  if (isTracker())
60                  {
61                      insideTrackingVolume = true;
62                  } 
63                  else
64                  {
65                      insideTrackingVolume = false;
66                  }
67              } else
68              {
69                  insideTrackingVolume = insideAttrib.getBooleanValue();
70              }
71          } 
72          catch (org.jdom.DataConversionException dce)
73          {
74              throw new RuntimeException("Error converting insideTrackingVolume attribute.", dce);
75          }
76          
77          // Set default digitized hits collection name.
78          digiCollectionName = this.getName().replace("Hits","DigiHits");
79      }
80  
81      protected void setReadout(Readout r)
82      {
83          // Require a valid system id.
84          if (systemID == 0)
85              throw new RuntimeException("The detector " + getName() + " cannot have a readout" + " because it does not have a valid system id.");
86          this.readout = r;
87      }
88  
89      /**
90       * Get the readout associated with this detector.
91       * 
92       * @return The readout, or <CODE>null</CODE> if no readout is associated with the detector.
93       */
94      public Readout getReadout()
95      {
96          return readout;
97      }
98  
99      /*
100     public void setParameters(ParameterSet parameters)
101     {
102         _parameters = parameters;
103     }
104     
105     public ParameterSet getParameterSet()
106     {
107         return _parameters;
108     }
109      */
110 
111     public IDDecoder getIDDecoder()
112     {
113         return getReadout().getIDDecoder();
114     }
115 
116     public String getName()
117     {
118         return name;
119     }
120 
121     public int getSystemID()
122     {
123         return (systemID);
124     }
125 
126     public boolean isBarrel()
127     {
128         return false;
129     }
130 
131     public boolean isEndcap()
132     {
133         return false;
134     }
135 
136     public boolean isCalorimeter()
137     {
138         return false;
139     }
140 
141     public boolean isTracker()
142     {
143         return false;
144     }
145 
146     public boolean isLayered()
147     {
148         return false;
149     }
150 
151     public double[] transformLocalToGlobal(double[] locPos)
152     {
153         return locPos;
154     }
155 
156     public boolean getReflect()
157     {
158         return reflect;
159     }
160 
161     public Layering getLayering()
162     {
163         throw new RuntimeException("layers not implemented");
164     }
165 
166     public void setVisAttributes(VisAttributes vis)
167     {
168         this.vis = vis;
169     }
170 
171     public VisAttributes getVisAttributes()
172     {
173         // Make a default VisAttributes if it is null.
174         if ( vis == null )
175         {
176             vis = new VisAttributes( getName() + "_vis" );
177             
178             // Set color to white so it will show in Wired and Geant4.
179             vis.setColor( Color.WHITE );
180         }
181         return vis;
182     }
183 
184     public Element getNode()
185     {
186         return node;
187     }
188 
189     public IDetectorElement getDetectorElement()
190     {
191         return de;
192     }
193 
194     public void setDetectorElement(IDetectorElement de)
195     {
196         this.de = de;
197     }
198 
199     public boolean isInsideTrackingVolume()
200     {
201         return insideTrackingVolume;
202     }
203     
204     public String getHitsCollectionName()
205     {
206         return getReadout().getName();
207     }
208     
209     /**
210      * Allow setting of digi collection name by external digitization Driver.
211      * This will override the default setting based on digisim's default.
212      * @param digiCollecionName The new name for digitized hits collection.
213      */
214     public void setDigiHitsCollectionName(String digiCollectionName)
215     {
216         this.digiCollectionName = digiCollectionName;
217     }
218     
219     /**
220      * Get the name of the digitized hits collection.
221      * @return The digitized hits collection name.
222      */
223     public String getDigiHitsCollectionName()
224     {
225         return digiCollectionName;
226     }
227 }