View Javadoc

1   package org.lcsim.recon.cat.util;
2   
3   import java.util.*;
4   
5   import org.lcsim.conditions.ConditionsListener;
6   import org.lcsim.conditions.ConditionsEvent;
7   import org.lcsim.conditions.ConditionsManager;
8   import org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException;
9   import org.lcsim.event.*;
10  import org.lcsim.event.EventHeader.LCMetaData;
11  import org.lcsim.geometry.*;
12  import org.lcsim.util.Driver;
13  
14  /**
15   * The class provides access to general use constants and SiD-specific detector information.
16   * <p>
17   * Units, physics constants and frequently used particles PGD encodings are defined
18   * as static fields. Default units (those equal to 1.0) are millimeter, second, Tesla, and GeV.
19   * <p>
20   * Detector-specific constants are accessible through an instance of <tt>Const</tt>
21   * that can be obtained with a call to <tt>Const.det()</tt>.
22   * These constants are initialized automatically once the detector information becomes 
23   * available, and updated if the detector changes. An attempt to call {@link #det()} 
24   * before the detector classes have been initialized by the framework (usually just 
25   * before the first event processing starts) will throw <tt>NullPointerException</tt>.
26   *
27   * @author D. Onoprienko
28   * @version $Id: Const.java,v 1.1 2007/04/06 21:48:15 onoprien Exp $
29   */
30  public class Const implements ConditionsListener {
31    
32  // --- Units :  ----------------------------------------------------------------
33    
34    public static final double mm = 1.;
35    public static final double millimeter = mm;
36    public static final double meter = 1000. * mm;
37    public static final double m = 1000. * mm;
38    public static final double centimeter = 10. * mm;
39    public static final double cm = 10. * mm;
40    public static final double micrometer = 0.001 * mm;
41    
42    public static final double second = 1.;
43    public static final double sec = second;
44    public static final double millisecond = 1.e-3 * second;
45    public static final double microsecond = 1.e-6 * second;
46    public static final double nanosecond = 1.e-9 * second;
47    
48    public static final double Tesla = 1.;
49    
50    public static final double GeV = 1.;
51    public static final double TeV = 1.e3 * GeV;
52    public static final double MeV = 1.e-3 * GeV;
53    public static final double eV = 1.e-9 * GeV;
54    
55    public static final double degree = Math.PI / 180.;
56    
57  // -- Physics constants :  -----------------------------------------------------
58    
59    public static final double SPEED_OF_LIGHT = 2.99792458e8 * (meter/second);
60    
61  // -- Frequently used particles :  ---------------------------------------------
62    
63    public enum Particle {
64      
65      PI_PLUS(211),
66      PI_MINUS(-211),
67      PI_0(111),
68      K_SHORT(310),
69      LAMBDA(3122),
70      SIGMA_PLUS(3222),
71      SIGMA_MINUS(3112),
72      SIGMA_0(3212);
73      
74      public final int PDGID;    
75      private Particle(int pdgID) {PDGID = pdgID;}
76    }
77    
78  // -- Detector parameters :  ---------------------------------------------------
79    
80    /** Returns an instance of <tt>Const</tt> that can be used to retrieve various detector parameters. */
81    static public Const det() {return _det;}
82    
83    public final SubDet VXD_BARREL;
84    public final SubDet VXD_ENDCAP;
85    public final SubDet TRACKER_BARREL;
86    public final SubDet TRACKER_ENDCAP;
87    public final SubDet TRACKER_FORWARD;
88    
89    /** 
90     * Returns <tt>true</tt> if tracking subdetector supplied as an argument is an endcap.
91     */
92    public boolean isEndcap(Subdetector sub) {
93      return get(sub).isEndcap();
94    }
95    /**
96     * Returns <tt>true</tt> if tracking subdetector with system ID supplied as an
97     * argument is an endcap.
98     */
99    public boolean isEndcap(int sysID) {
100     return get(sysID).isEndcap();
101   }
102   
103   /** 
104    * Returns <tt>true</tt> if tracking subdetector supplied as an argument 
105    * is a part of the vertex detector.
106    */
107   public boolean isVXD(Subdetector sub) {
108     return get(sub).isVXD();
109   }
110   /**
111    * Returns <tt>true</tt> if tracking subdetector with system ID supplied as an
112    * argument is a part of the vertex detector.
113    */
114   public boolean isVXD(int sysID) {
115     return get(sysID).isVXD();
116   }
117   
118   /** 
119    * Returns <tt>true</tt> if tracking subdetector supplied as an argument provides
120    * 3-demensional measurement (silicon pixels).
121    */
122   public boolean is3D(Subdetector sub) {
123     return get(sub).is3D();
124   }
125   /**
126    * Returns <tt>true</tt> if tracking subdetector with system ID supplied as an
127    * argument provides 3-demensional measurement (silicon pixels).
128    */
129   public boolean is3D(int sysID) {
130     return get(sysID).is3D();
131   }
132   
133   /** 
134    * Returns number of layers in the tracking subdetector supplied as an argument.
135    */
136   public int nLayers(Subdetector sub) {
137     return get(sub).nLayers();
138   }
139   /**
140    * Returns number of layers in the tracking subdetector with system ID supplied as an argument.
141    */
142   public int nLayers(int sysID) {
143     return get(sysID).nLayers();
144   }
145   
146   /** Helper class that contains parameters of one of the tracking subdetectors. */
147   public class SubDet {
148     
149     public String name() {return _name;}
150     public Subdetector subdetector() {return _subd;}
151     public int sysID() {return _sysID;}
152     public int nLayers() {return _nLayers;}
153     public boolean isEndcap() {return _isEndcap;}
154     public boolean isVXD() {return _isVXD;}
155     public boolean is3D() {return _is3D;}
156     
157     private SubDet(String name, boolean isEndcap, boolean isVXD, boolean is3D) {
158       _name = name;
159       _isEndcap = isEndcap;
160       _isVXD = isVXD;
161       _is3D = is3D;
162       _subDetList.add(this);
163     }
164 
165     private void initialize() {
166       _subd = _detector.getSubdetector(_name);
167       if (_subd == null) {
168         _sysID = -1;
169         _nLayers = 0;
170       } else {
171         _sysID = _subd.getSystemID();
172         _nLayers = _subd.getLayering().getNumberOfLayers();
173       }
174     }
175 
176     private String _name;
177     private Subdetector _subd;
178     private int _sysID;
179     private int _nLayers;
180     private boolean _isEndcap;
181     private boolean _isVXD;
182     private boolean _is3D;
183   }
184 
185   // -- Detector-dependent initialization :  -----------------------------------
186   
187   static private Const _det = new Const();
188 
189   private Const() {
190     _subDetList = new ArrayList<SubDet>(5);
191     VXD_BARREL =      new SubDet("VertexBarrel",  false,  true,  true);
192     VXD_ENDCAP =      new SubDet("VertexEndcap",   true,  true,  true);
193     TRACKER_BARREL =  new SubDet("TrackerBarrel", false, false, false);
194     TRACKER_ENDCAP =  new SubDet("TrackerEndcap",  true, false, false);
195     TRACKER_FORWARD = new SubDet("TrackerForward", true, false, false);
196     ConditionsManager.defaultInstance().addConditionsListener(this);
197     conditionsChanged(null);
198   }
199   
200   /** Called by the framework when the detector information changes. */
201   public void conditionsChanged(ConditionsEvent event) {
202     ConditionsManager conMan = (event == null) ? ConditionsManager.defaultInstance() : event.getConditionsManager();
203     try {
204       Detector det = conMan.getCachedConditions(Detector.class,"compact.xml").getCachedData();
205       if (det != _detector) {
206         _detector = det;
207         _bField = _detector.getFieldMap().getField(new double[]{0.,0.,0.})[2];
208         for (SubDet sd : _subDetList) sd.initialize();
209       }
210     } catch (ConditionsSetNotFoundException x) {}
211   }
212   
213   // -- Private parts :  -------------------------------------------------------
214 
215   private SubDet get(Subdetector subdetector) {
216     for (SubDet sd : _subDetList) if (sd._subd == subdetector) return sd;
217     return null;
218   }
219   private SubDet get(int sysID) {
220     for (SubDet sd : _subDetList) if (sd._sysID == sysID) return sd;
221     return null;
222   }
223   
224   private Detector _detector;
225   private ArrayList<SubDet> _subDetList;
226   private double _bField;
227 
228 }