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
24
25
26
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
60
61
62
63
64
65
66
67
68
69
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
76
77
78
79
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 }