View Javadoc

1   package org.lcsim.util.heprep;
2   
3   import hep.graphics.heprep.HepRepFactory;
4   import hep.graphics.heprep.HepRepInstance;
5   import hep.graphics.heprep.HepRepInstanceTree;
6   import hep.graphics.heprep.HepRepPoint;
7   import hep.graphics.heprep.HepRepType;
8   import hep.graphics.heprep.HepRepTypeTree;
9   import hep.physics.matrix.SymmetricMatrix;
10  import hep.physics.vec.Hep3Vector;
11  
12  import java.awt.Color;
13  import java.util.List;
14  
15  import org.lcsim.event.EventHeader;
16  import org.lcsim.event.Vertex;
17  import org.lcsim.event.EventHeader.LCMetaData;
18  
19  import Jama.EigenvalueDecomposition;
20  import Jama.Matrix;
21  
22  /**
23   * Representation of the Candidate vertices before fitting
24   * 
25   * @author jstrube
26   * @version $Id: VertexConverter.java,v 1.5 2007/10/03 16:47:22 ngraf Exp $
27   * 
28   */
29  public class VertexConverter implements HepRepCollectionConverter {
30      private Color[] colors;
31  
32      private static final double[] zero = { 0,0,0 };
33      public VertexConverter() {
34          ColorMap cm = new RainbowColorMap();
35          colors = new Color[11];
36          for (int i=0; i<colors.length; i++) colors[i] = cm.getColor(((double) i)/colors.length,1);
37      }
38  
39      public boolean canHandle(Class k) {
40          return Vertex.class.isAssignableFrom(k);
41      }
42  
43      public void convert(EventHeader event, List collection, HepRepFactory factory
44              , HepRepTypeTree typeTree, HepRepInstanceTree instanceTree) {
45          LCMetaData meta = event.getMetaData(collection);
46          String name = meta.getName();        
47          HepRepType typeX = factory.createHepRepType(typeTree, name);
48          typeX.addAttValue("layer", LCSimHepRepConverter.PARTICLES_LAYER);
49          typeX.addAttValue("drawAs", "Ellipsoid");
50          typeX.addAttValue("Radius", 1);
51          typeX.addAttValue("Radius2", 2);
52          typeX.addAttValue("Radius3", 3);
53          typeX.addAttValue("color", Color.RED);
54          typeX.addAttValue("fill", true);
55          typeX.addAttValue("fillColor", Color.RED);
56          typeX.addAttValue("MarkName", "Box");
57          typeX.addAttDef("nTracks", "number of Tracks", "physics", "");
58          
59          // TODO allow the error ellipse to be defined in terms of a confidence level
60          // for this, will need to get the number of degrees of freedom from the vertex
61          // fit. See Numerical Recipes for the procedure to calculate the following numbers.
62          //
63          //  confidence level                    number of degrees of freedom
64          //                          1        2       3      4       5      6
65          //     68.3 %               1.00     2.30    3.53    4.72    5.89   7.04
66          //     90   %               2.71     4.61    6.25    7.78    9.24  10.6
67          //     95.4 %               4.00     6.17    8.02    9.70   11.3   12.8
68          //     99   %               6.63     9.21   11.3    13.3    15.1   16.8
69          //     99.99%              15.1     18.4    21.1    23.5    25.7   27.8
70          //
71          double nSigma = 30.; 
72          typeX.addAttDef("sigma", "error scale factor", "physics", "The error in each dimension is multiplied by this factor");
73          typeX.addAttValue("sigma", nSigma);
74          
75  //        HepRepType typeY = factory.createHepRepType(typeTree, name);
76  //        typeY.addAttValue("layer", LCSimHepRepConverter.PARTICLES_LAYER);
77  //        typeY.addAttValue("drawAs","Line");
78  //        typeY.addAttDef("pT","Transverse momentum", "physics", "");
79  //        typeY.addAttDef("dedX","de/Dx", "physics", "");
80          int iColor = 0;
81          
82          HepRepType typeY = factory.createHepRepType(typeTree, name+"Tracks");
83          typeY.addAttValue("layer", LCSimHepRepConverter.PARTICLES_LAYER);
84          typeY.addAttValue("drawAs", "Line");
85          
86          
87          for (Vertex vtx : (List<Vertex>) collection) {
88              Color vertexColor = colors[iColor];
89              iColor = (iColor+2) % colors.length;
90              Hep3Vector pos = vtx.getPosition();
91              HepRepInstance instanceV = factory.createHepRepInstance(instanceTree, typeX);
92              instanceV.addAttValue("color", vertexColor);
93              instanceV.addAttValue("fillColor", vertexColor);
94              
95              SymmetricMatrix covMatrix = vtx.getCovMatrix();
96              
97              EigenvalueDecomposition vtxEigen = new EigenvalueDecomposition(Jama.util.Maths.toJamaMatrix(covMatrix));
98              Matrix eigenVals = vtxEigen.getD();
99              instanceV.addAttValue("Radius", nSigma*Math.sqrt(eigenVals.get(0, 0)));
100             instanceV.addAttValue("Radius2", nSigma*Math.sqrt(eigenVals.get(1, 1)));
101             instanceV.addAttValue("Radius3", nSigma*Math.sqrt(eigenVals.get(2, 2)));
102             
103             Matrix eigenVecs = vtxEigen.getV();
104             assert eigenVecs.getRowDimension() == 3;
105             assert eigenVecs.getColumnDimension() == 3;
106             double theta = -Math.asin(eigenVecs.get(1, 2));
107             double phi = Math.atan2(eigenVecs.get(0, 2),eigenVecs.get(2, 2));
108             double omega = Math.atan2(eigenVecs.get(0, 1), eigenVecs.get(1,1));
109 
110             instanceV.addAttValue("Phi", phi);
111             instanceV.addAttValue("Theta", theta);
112             instanceV.addAttValue("Omega", omega);
113             instanceV.addAttValue("x", pos.x());
114             instanceV.addAttValue("y", pos.y());
115             instanceV.addAttValue("z", pos.z());
116             HepRepPoint pp = factory.createHepRepPoint(instanceV, pos.x(), pos.y(), pos.z());
117             
118         }
119     }
120 }