View Javadoc

1   /**
2    * @author jstrube
3    * @version $Id: LCIOParameters.java,v 1.1 2007/11/29 02:25:55 jstrube Exp $ 
4    */
5   package org.lcsim.event;
6   
7   import static java.lang.Math.cos;
8   import static java.lang.Math.sin;
9   import static org.lcsim.constants.Constants.fieldConversion;
10  import static org.lcsim.event.LCIOParameters.ParameterName.d0;
11  import static org.lcsim.event.LCIOParameters.ParameterName.omega;
12  import static org.lcsim.event.LCIOParameters.ParameterName.phi0;
13  import static org.lcsim.event.LCIOParameters.ParameterName.tanLambda;
14  import static org.lcsim.event.LCIOParameters.ParameterName.z0;
15  import hep.physics.vec.Hep3Vector;
16  
17  import org.lcsim.spacegeom.CartesianPoint;
18  import org.lcsim.spacegeom.CartesianVector;
19  import org.lcsim.spacegeom.SpacePoint;
20  import org.lcsim.spacegeom.SpaceVector;
21  
22  public class LCIOParameters {
23      public enum ParameterName {
24          d0, phi0, omega, z0, tanLambda
25      }
26      
27      /**
28       * Computes the momentum vector from a given parameter set
29       * 
30       * @param parameters
31       *                The Parameter object
32       * @return The momentum vector corresponding to the given parameters
33       */
34      public static Hep3Vector Parameters2Momentum(LCIOParameters parameters) {
35          double pt = parameters.pt;
36  
37          return new CartesianVector(pt * cos(parameters.get(phi0)), pt
38                  * sin(parameters.get(phi0)), pt * parameters.get(tanLambda));
39      }
40  
41      /**
42       * Computes the point of closest approach on the track to the given
43       * reference point. Note that this function does not do any swimming. It
44       * merely returns a different representation of the given parameters.
45       * This is meaningless without the reference point however. In order to
46       * prevent the user from having to know the implementation details, the
47       * reference point is made an explicit parameter.
48       * 
49       * @param parameters
50       *                The Parameter object
51       * @param refPoint
52       *                The reference point
53       * @return The point of closest approach on the track to the reference
54       *         point
55       */
56      public static SpacePoint Parameters2Position(LCIOParameters parameters,
57              SpacePoint refPoint) {
58          double d_0 = parameters.get(d0);
59          double z_0 = parameters.get(z0);
60          double phi_0 = parameters.get(phi0);
61  
62          double x = refPoint.x() - d_0 * sin(phi_0);
63          double y = refPoint.y() + d_0 * cos(phi_0);
64          double z = refPoint.z() + z_0;
65  
66          return new CartesianPoint(x, y, z);
67      }
68  
69      /**
70       * Calculates the parameters of the Track under the assumption that the
71       * space-momentum representation is given at the POCA to the reference
72       * point.
73       * 
74       * @param pos
75       *                The point of closest approach on the track to the
76       *                reference point
77       * @param mom
78       *                The momentum vector at
79       * @see pos
80       * @param ref
81       *                The reference point
82       * @param charge
83       *                The charge of the particle
84       * @param Bz
85       *                The z component of the magnetic field. Assuming a
86       *                homogeneous field parallel to z
87       * @return The Parameter object corresponding to the arguments
88       */
89      public static LCIOParameters SpaceMomentum2Parameters(SpacePoint pos,
90              Hep3Vector p, SpacePoint ref, int charge, double field_z) {
91          // Hep3Vector is stupid
92          SpaceVector mom = new CartesianVector(p.v());
93          LCIOParameters result = new LCIOParameters();
94          double aqBz = charge * field_z * fieldConversion;
95          double x = pos.x() - ref.x();
96          double y = pos.y() - ref.y();
97          double z_0 = pos.z() - ref.z();
98          double phi_0 = mom.phi();
99          double pt = mom.rxy();
100 
101         result.set(d0, -x * sin(phi_0) + y * cos(phi_0));
102         result.set(phi0, phi_0);
103         result.set(omega, aqBz / pt);
104         result.set(z0, z_0);
105         result.set(tanLambda, mom.z() / pt);
106         result.setPt(pt);
107         return result;
108     }
109 
110     double[] values;
111     double pt;
112 
113     public LCIOParameters(LCIOParameters parameters) {
114         values = parameters.values.clone();
115         pt = parameters.pt;
116     }
117 
118     LCIOParameters() {
119         values = new double[5];
120         pt = 0;
121     }
122 
123     public LCIOParameters(double[] vals, double p_t) {
124         values = vals;
125         pt = p_t;
126     }
127 
128     public double get(ParameterName name) {
129         return values[name.ordinal()];
130     }
131 
132     public double getPt() {
133         return pt;
134     }
135 
136     public double[] getValues() {
137         return values;
138     }
139 
140     public void set(ParameterName name, double val) {
141         values[name.ordinal()] = val;
142     }
143 
144     void setPt(double p_t) {
145         pt = p_t;
146     }
147 
148     public String toString() {
149         StringBuilder sb = new StringBuilder();
150         sb.append(String.format("Parameters:\n"));
151         for (ParameterName p : ParameterName.values()) {
152             sb.append(String.format("%10s: %g\n", p.name(), values[p
153                     .ordinal()]));
154         }
155         sb.append(String.format("%10s: %g\n", "pt", pt));
156         return sb.toString();
157     }
158 }