View Javadoc

1   package org.lcsim.mc.fast.tracking;
2   
3   import Jama.*;
4   import hep.physics.matrix.SymmetricMatrix;
5   import org.lcsim.util.aida.AIDA;
6   import hep.physics.particle.Particle;
7   import hep.physics.vec.Hep3Vector;
8   import org.lcsim.event.Track;
9   import org.lcsim.event.TrackState;
10  import org.lcsim.event.base.BaseTrackState;
11  
12  import java.io.*;
13  import java.util.ArrayList;
14  import java.util.Collections;
15  import java.util.List;
16  import java.util.Random;
17  import org.lcsim.mc.fast.tracking.SimpleTables;
18  
19  /**
20   * Provides MC smeared track. <br>
21   * Handles to smeared and not-smeared set of DocaTrackParameters are provided. <br>
22   *
23   * @author Tony Johnson, Wolfgang Walkowiak
24   * @version $Id: ReconTrack.java,v 1.12 2012/07/26 16:46:14 grefe Exp $
25   */
26  public class ReconTrack implements Track {
27      private static final String[][] matrixI = { { "(1,1):", "(1,2):", "(1,3):", "(1,4):", "(1,5):" }, { "(2,1):", "(2,2):", "(2,3):", "(2,4):", "(2,5):" }, { "(3,1):", "(3,2):", "(3,3):", "(3,4):", "(3,5):" }, { "(4,1):", "(4,2):", "(4,3):", "(4,4):", "(4,5):" }, { "(5,1):", "(5,2):", "(5,3):", "(5,4):", "(5,5):" } };
28  
29      // =======================================================================
30      //
31      // private members
32      //
33      // =======================================================================
34      private DocaTrackParameters m_nosmear = null;
35      private DocaTrackParameters m_smear = null;
36      transient private Particle mc;
37      private int m_tcharge;
38      private double[] _refpoint = { 0, 0, 0 };
39      private List<TrackState> _trackStates;
40  
41      ReconTrack(double bField, TrackResolutionTables parm, SimpleTables SmTbl, Random rand, Particle mc, boolean hist, boolean simple) {
42          this.mc = mc;
43  
44          // get original momentum from MCParticle
45          // convert to helical parameters
46          m_nosmear = new DocaTrackParameters(bField, mc);
47  
48          double pt = m_nosmear.getPt();
49  
50          if (hist) {
51  
52              double r = Math.abs(m_nosmear.getD0());
53  
54              AIDA aida = AIDA.defaultInstance();
55              aida.cloud1D("ptsqr").fill(pt * pt);
56              aida.cloud1D("pt").fill(pt);
57              aida.cloud1D("phi").fill(m_nosmear.getPhi0());
58              aida.cloud1D("theta").fill(m_nosmear.getTheta());
59              aida.cloud1D("tanL").fill(m_nosmear.getTanL());
60              aida.cloud1D("r").fill(r);
61              aida.cloud1D("z").fill(mc.getOriginZ());
62          }
63          // get appropriate resolution table
64          double abscth = Math.abs(m_nosmear.getCosTheta());
65          double ptot = m_nosmear.getPtot();
66          ResolutionTable table = (abscth < parm.getPolarInner()) ? parm.getBarrelTable() : parm.getEndcapTable();
67  
68          // get resolution values from interpolation and fill error matrix
69          m_nosmear.setErrorMatrix(getErrorMatrixFromTable(table, abscth, ptot));
70  
71          // smear tracks according to error matrix
72          if (simple == true) {
73              m_smear = (DocaTrackParameters) SmearTrackSimple.smearTrackSimple(bField, m_nosmear, rand, SmTbl, pt, hist);
74              // double[] slice = {0, 0, 1, 0, 0};
75              // m_smear = (DocaTrackParameters) SmearTrackSimpleII.SmearTrackSimpleII(bField, m_nosmear, rand, SmTbl, slice, hist);
76          } else {
77              m_smear = (DocaTrackParameters) SmearTrack.smearTrack(bField, m_nosmear, rand);
78          }
79  
80          if (hist) {
81              AIDA aida = AIDA.defaultInstance();
82              aida.cloud1D("ptNew").fill(m_smear.getPt());
83              aida.cloud1D("tanLNew").fill(m_smear.getTanL());
84              aida.cloud1D("rNew").fill(Math.abs(m_smear.getD0()));
85              aida.cloud1D("phiNew").fill(m_smear.getPhi0());
86              aida.cloud1D("zNew").fill(m_smear.getZ0());
87          }
88          m_tcharge = (int) (m_smear.getUnitCharge() * Math.abs(mc.getType().getCharge()));
89          _trackStates = new ArrayList<TrackState>();
90          _trackStates.add(new BaseTrackState(m_smear.getTrackParameters(), bField));
91      }
92  
93      /**
94       * Get the full charge.
95       */
96      public int getCharge() {
97          return m_tcharge;
98      }
99  
100     /**
101      * Get the chi2 from smearing.
102      */
103     public double getChi2() {
104         return m_smear.getChi2();
105     }
106 
107     /**
108      * Get DOCA (2-dim) of smeared track. <br>
109      *
110      * Note: Use #getNotSmearedTrack().getDOCA() to access parameters of the not smeared track.
111      */
112     public double[] getDoca() {
113         return m_smear.getDoca();
114     }
115 
116     public double[] getDocaMomentum(double[] refPoint) {
117         return m_smear.getDocaMomentum(refPoint);
118     }
119 
120     /**
121      * Get momentum at DOCA (2-dim) of smeared track. <br>
122      *
123      * Note: Use #getNotSmearedTrack().getMomentum() to access parameters of the not smeared track.
124      */
125     public double[] getDocaMomentum() {
126         return m_smear.getMomentum();
127     }
128 
129     public Hep3Vector getDocaMomentumVec(Hep3Vector refPoint) {
130         return m_smear.getDocaMomentumVec(refPoint);
131     }
132 
133     /*
134      * Calculate and get Doca momentum on smeared track with respect to any space point.
135      */
136     public Hep3Vector getDocaMomentumVec(double[] refPoint) {
137         return m_smear.getDocaMomentumVec(refPoint);
138     }
139 
140     /**
141      * Get x coordinate of momentum of the smeared track at DOCA.
142      */
143     public double getDocaMomentumX() {
144         return m_smear.getPX();
145     }
146 
147     /**
148      * Get y coordinate of momentum of the smeared track at DOCA.
149      */
150     public double getDocaMomentumY() {
151         return m_smear.getPY();
152     }
153 
154     /**
155      * Get z coordinate of momentum of the smeared track at DOCA.
156      */
157     public double getDocaMomentumZ() {
158         return m_smear.getPZ();
159     }
160 
161     public double[] getDocaPosition(double[] refPoint) {
162         return m_smear.getDocaPosition(refPoint);
163     }
164 
165     /**
166      * Calculate and get Doca position on the smeared track with respect to any space point.
167      */
168     public Hep3Vector getDocaPositionVec(Hep3Vector refPoint) {
169         return m_smear.getDocaPositionVec(refPoint);
170     }
171 
172     public Hep3Vector getDocaPositionVec(double[] refPoint) {
173         return m_smear.getDocaPositionVec(refPoint);
174     }
175 
176     /**
177      * Get transverse momentum of the smeared track at DOCA.
178      */
179     public double getDocaPt() {
180         return m_smear.getPt();
181     }
182 
183     /**
184      * Calculate and get path length on the smeared track for a doca to any space point in respect to the track defining doca (with respect to the origin). The length l is given in the transverse
185      * plane. <br>
186      * Use L = l*tan(lambda) to convert.
187      */
188     public double getDocaTransversePathLength(Hep3Vector refPoint) {
189         return m_smear.getDocaTransversePathLength(refPoint);
190     }
191 
192     public double getDocaTransversePathLength(double[] refPoint) {
193         return m_smear.getDocaTransversePathLength(refPoint);
194     }
195 
196     /**
197      * Get x coordinate of DOCA of smeared track.
198      */
199     public double getDocaX() {
200         return m_smear.getDocaX();
201     }
202 
203     /**
204      * Get y coordinate of DOCA of smeared track.
205      */
206     public double getDocaY() {
207         return m_smear.getDocaY();
208     }
209 
210     /**
211      * Get z coordinate of DOCA of smeared track.
212      */
213     public double getDocaZ() {
214         return m_smear.getDocaZ();
215     }
216 
217     /**
218      * Get the full error matrix.
219      * @see #getTrackParameter
220      */
221     public SymmetricMatrix getErrorMatrix() {
222         return m_smear.getErrorMatrix();
223     }
224 
225     /**
226      * Get the MC particle for this track.
227      */
228     public Particle getMCParticle() {
229         return mc;
230     }
231 
232     public double[] getMomentum(double l) {
233         return m_smear.getMomentum(l);
234     }
235 
236     /**
237      * Get momentum of smeared track at original vertex point. <br>
238      *
239      * Note: Use #getNotSmearedTrack().getMomentum() to access parameters of the not smeared track.
240      */
241     public double[] getMomentum() {
242         return m_smear.getMomentum(m_smear.getL0());
243     }
244 
245     /**
246      * Calculate and get momentum on track with respect to any path length l on track (l in xy plane).
247      */
248     public Hep3Vector getMomentumVec(double l) {
249         return m_smear.getMomentumVec(l);
250     }
251 
252     public Hep3Vector getMomentumVec() {
253         return m_smear.getMomentumVec(m_smear.getL0());
254     }
255 
256     /**
257      * Get x coordinate of momentum of the smeared track at original vertex.
258      */
259     public double getMomentumX() {
260         return m_smear.getMomentum(m_smear.getL0())[0];
261     }
262 
263     /**
264      * Get y coordinate of momentum of the smeared track at original vertex.
265      */
266     public double getMomentumY() {
267         return m_smear.getMomentum(m_smear.getL0())[1];
268     }
269 
270     /**
271      * Get z coordinate of momentum of the smeared track at original vertex.
272      */
273     public double getMomentumZ() {
274         return m_smear.getMomentum(m_smear.getL0())[2];
275     }
276 
277     /**
278      * Get the number degrees of freedom.
279      */
280     public int getNDF() {
281         return m_smear.getNDF();
282     }
283 
284     /**
285      * Get the complete parameter set for the not smeared track.
286      */
287     public DocaTrackParameters getNotSmearedTrack() {
288         return m_nosmear;
289     }
290 
291     /**
292      * Get x coordinate of momentum of the smeared track at original vertex.
293      */
294     public double getPX() {
295         return getMomentumX();
296     }
297 
298     /**
299      * Get y coordinate of momentum of the smeared track at original vertex.
300      */
301     public double getPY() {
302         return getMomentumY();
303     }
304 
305     /**
306      * Get z coordinate of momentum of the smeared track at original vertex.
307      */
308     public double getPZ() {
309         return getMomentumZ();
310     }
311 
312     public double[] getPosition(double l) {
313         return m_smear.getPosition(l);
314     }
315 
316     /**
317      * Calculate and get position on track with respect to any path length l on track (l in xy plane).
318      */
319     public Hep3Vector getPositionVec(double l) {
320         return m_smear.getPositionVec(l);
321     }
322 
323     /**
324      * Get transverse momentum of the smeared track at original vertex.
325      */
326     public double getPt() {
327         double[] p = getMomentum();
328 
329         return Math.sqrt((p[0] * p[0]) + (p[1] * p[1]));
330     }
331 
332     public double getRadiusOfInnermostHit() {
333         return 0; // FixMe:
334     }
335 
336     /**
337      * Get the original vertex point of smeared MC track.
338      */
339 
340     // Get the reference point used for track parameter calculations
341     //
342     public double[] getReferencePoint() {
343         return _refpoint;
344     }
345 
346     public boolean isReferencePointPCA() {
347         return true;
348     }
349 
350     /**
351      * Get x coordinate of the original vertex point of smeared MC track.
352      */
353     public double getReferencePointX() {
354         return getReferencePoint()[0];
355     }
356 
357     /**
358      * Get y coordinate of the original vertex point of smeared MC track.
359      */
360     public double getReferencePointY() {
361         return getReferencePoint()[1];
362     }
363 
364     /**
365      * Get z coordinate of the original vertex point of smeared MC track.
366      */
367     public double getReferencePointZ() {
368         return getReferencePoint()[2];
369     }
370 
371     /**
372      * Get the complete parameter set for the smeared track.
373      */
374     public DocaTrackParameters getSmearedTrack() {
375         return m_smear;
376     }
377 
378     public int[] getSubdetectorHitNumbers() {
379         return new int[0]; // FIXME
380     }
381 
382     /**
383      * Get an individual track parameter. <br>
384      *
385      * The track parameters for LCD are defined as follows
386      * <table>
387      * <tr>
388      * <th>Index</th>
389      * <th>Meaning</th>
390      * </tr>
391      * <tr>
392      * <td>0</td>
393      * <td>d0 = XY impact parameter</td>
394      * <tr>
395      * <tr>
396      * <td>1</td>
397      * <td>phi0</td>
398      * <tr>
399      * </td>
400      * <tr>
401      * <tr>
402      * <td>2</td>
403      * <td>omega = 1/curv.radius (negative for negative tracks)</td>
404      * <tr>
405      * <tr>
406      * <td>3</td>
407      * <td>z0 = z of track (z impact parameter)</td>
408      * <tr>
409      * <tr>
410      * <td>4</td>
411      * <td>s = tan lambda</td>
412      * <tr>
413      * </table>
414      * @param i The index of the track parameter
415      * @return The track parameter with the specified index
416      *
417      *         All parameters are given at the DOCA.
418      */
419     public double getTrackParameter(int i) {
420         return m_smear.getTrackParameter(i);
421     }
422 
423     /**
424      * Get the track parameters as an array
425      * @see #getTrackParameter
426      */
427     public double[] getTrackParameters() {
428         return m_smear.getTrackParameters();
429     }
430 
431     public List getTrackerHits() {
432         return Collections.EMPTY_LIST;
433     }
434 
435     public List getTracks() {
436         return Collections.EMPTY_LIST;
437     }
438 
439     public int getType() {
440         return 0; // FIXME:
441     }
442 
443     /**
444      * Calculate the error matrix for the momentum for a point on the smeared track specified by l.
445      */
446     public SymmetricMatrix calcMomentumErrorMatrix(double l) {
447         return m_smear.calcMomentumErrorMatrix(l);
448     }
449 
450     /**
451      * Calculate the error matrix for the position coordinates for a point on the smeared track specified by l. Result is given as a 3x3 array for the matrix.
452      */
453     public double[][] calcPositionErrorMatrix(double l) {
454         return m_smear.calcPositionErrorMatrix(l);
455     }
456 
457     public boolean fitSuccess() {
458         // FIXME Not implemented in fastMC
459         return false;
460     }
461 
462     public double getdEdx() {
463         return 0; // FIXME
464     }
465 
466     public double getdEdxError() {
467         return 0; // FIXME
468     }
469 
470     public String toString() {
471         java.io.StringWriter buffer = new java.io.StringWriter();
472         java.io.PrintWriter out = new java.io.PrintWriter(buffer);
473 
474         java.text.NumberFormat pf = java.text.NumberFormat.getInstance();
475         pf.setMinimumFractionDigits(12);
476         pf.setMaximumFractionDigits(12);
477         pf.setMinimumIntegerDigits(1);
478         pf.setMaximumIntegerDigits(3);
479         pf.setGroupingUsed(false);
480 
481         Matrix mHlxPar = new Matrix(m_smear.getTrackParameters(), 1);
482 
483         out.println("ReconTrack Parameters:  d0          phi0          omega         z0        tan(lambda)");
484         mHlxPar.print(out, pf, 16);
485         out.println("Error Matrix:");
486         out.println(m_smear.getErrorMatrix());
487 
488         return (buffer.toString());
489     }
490 
491     private SymmetricMatrix getErrorMatrixFromTable(ResolutionTable table, double abscth, double ptot) {
492         SymmetricMatrix errMatrix = new SymmetricMatrix(5);
493         for (int i = 0; i < 5; i++) {
494             for (int j = 0; j <= i; j++) {
495                 errMatrix.setElement(i, j, table.findTable(matrixI[i][j]).interpolateVal(abscth, ptot));
496             }
497         }
498         return errMatrix;
499     }
500 
501     public List<TrackState> getTrackStates() {
502         return _trackStates;
503     }
504 }