LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  June 2015

HPS-SVN June 2015

Subject:

r3150 - /java/trunk/detector-model/src/main/java/org/lcsim/geometry/compact/converter/SurveyResult.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Wed, 17 Jun 2015 01:27:26 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (271 lines)

Author: [log in to unmask]
Date: Tue Jun 16 18:27:16 2015
New Revision: 3150

Log:
Class to hold survey info.

Added:
    java/trunk/detector-model/src/main/java/org/lcsim/geometry/compact/converter/SurveyResult.java

Added: java/trunk/detector-model/src/main/java/org/lcsim/geometry/compact/converter/SurveyResult.java
 =============================================================================
--- java/trunk/detector-model/src/main/java/org/lcsim/geometry/compact/converter/SurveyResult.java	(added)
+++ java/trunk/detector-model/src/main/java/org/lcsim/geometry/compact/converter/SurveyResult.java	Tue Jun 16 18:27:16 2015
@@ -0,0 +1,255 @@
+/**
+ * 
+ */
+package org.lcsim.geometry.compact.converter;
+
+import hep.physics.vec.BasicHep3Matrix;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
+
+import java.util.List;
+
+import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
+import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
+import org.jdom.DataConversionException;
+import org.jdom.Element;
+import org.lcsim.detector.IRotation3D;
+import org.lcsim.detector.Rotation3D;
+import org.lcsim.detector.Transform3D;
+import org.lcsim.detector.Translation3D;
+
+/**
+ * Class to keep survey results.
+ * 
+ * @author Per Hansson Adrian <[log in to unmask]>
+ *
+ */
+public class SurveyResult {
+
+    String name;
+    String desc;
+    private Hep3Vector origin;
+    private Hep3Vector x;
+    private Hep3Vector y;
+    private Hep3Vector z;
+    
+    public SurveyResult(String name,Element node) {
+        this.name = name;
+        try {
+            setResults(node);
+        } catch (DataConversionException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    
+    private final void initFromDetectorXmlNode(Element detectorNode) {
+        Element element = findResultFromDetector(detectorNode);
+        if(element == null) {
+            System.out.printf("%s: no element from for %s \n", this.getClass().getSimpleName(),this.name);
+        } else {
+
+            try {
+                setResults(element);
+            } catch (DataConversionException e) {
+                new RuntimeException("cannot get the results from xml", e);
+            }
+        }
+    }   
+    
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        sb.append("Name: " + this.getName());
+        sb.append(" Desc.: " + this.getDesc() + "\n");
+        sb.append("Origin: " + this.getOrigin().toString() + "\n");
+        sb.append("unit x: " + this.getX().toString() + "\n");
+        sb.append("unit y: " + this.getY().toString() + "\n");
+        sb.append("unit z: " + this.getZ().toString() + "\n");
+        return sb.toString();
+    }
+    
+    
+    public String getDesc() {
+        return this.desc;
+    }
+
+    private void setResults(Element element) throws DataConversionException {
+        
+        setDesc(element.getAttributeValue("desc"));
+        
+        Element eO = element.getChild("origin");
+        if (eO == null) throw new RuntimeException("No origin node foudn for this element");
+
+
+        setOrigin(getUnit(eO));
+
+
+        List<Element> eUnitVectors = element.getChildren("unitvec");
+        if (eUnitVectors == null) throw new RuntimeException("No unitvec node foudn for this element");
+        if(eUnitVectors.size()!=3) throw new RuntimeException("Need 3 unitvecs");
+        for (Element ev : eUnitVectors) {
+            switch (ev.getAttributeValue("name")) {
+            case "X": setX(getUnit(ev));
+            break;
+            case "Y": setY(getUnit(ev));
+            break;
+            case "Z": setZ(getUnit(ev));
+            break;
+            default: throw new RuntimeException("This attribute name is wrong " + ev.getAttributeValue("name"));
+            }
+        }
+
+
+
+    }
+
+    public void setDesc(String desc) {
+       this.desc = desc;
+        
+    }
+
+    public static SurveyResult findResultFromDetector(Element detectorNode,  String name) {
+        Element elementSurveyVolumes = detectorNode.getChild("SurveyVolumes");
+        if(elementSurveyVolumes==null) {
+           System.out.printf("WARNING: no XML file for survey information available.\n");
+           //throw new RuntimeException("no SurveyVolumes in this xml file.");
+           return null;
+        }
+        List<Element> list = elementSurveyVolumes.getChildren("SurveyVolume");
+        for(Element element : list) {
+            if(element.getAttribute("name")!=null) {
+                if(element.getAttributeValue("name").compareTo(name) == 0) {
+                    return new SurveyResult(name, element);
+                } 
+            } else {
+                throw new RuntimeException("this element is not formatted correctly");
+            }
+        }
+        return null;
+    
+    }
+    
+    private Element findResultFromDetector(Element detectorNode) {
+        Element elementSurveyVolumes = detectorNode.getChild("SurveyVolumes");
+             if(elementSurveyVolumes==null) {
+                 throw new RuntimeException("no SurveyVolumes in this xml file.");
+             }
+             List<Element> list = elementSurveyVolumes.getChildren("SurveyVolume");
+             for(Element element : list) {
+                 if(element.getAttribute("name")!=null) {
+                     if(element.getAttributeValue("name").compareTo(name) == 0) {
+                         return element;
+                     } 
+                 } else {
+                     throw new RuntimeException("this element is not formatted correctly");
+                 }
+             }
+             return null;
+         }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Hep3Vector getX() {
+        return x;
+    }
+
+    public Hep3Vector getY() {
+        return y;
+    }
+
+    public Hep3Vector getZ() {
+        return z;
+    }
+    
+    public Hep3Vector getOrigin() {
+        return origin;
+    }
+
+        
+    protected void setX(Hep3Vector unit) {
+        this.x = unit;
+    }
+    protected void setY(Hep3Vector unit) {
+        this.y = unit;
+    }
+    protected void setZ(Hep3Vector unit) {
+        this.z = unit;
+    }
+    protected void setOrigin(Hep3Vector unit) {
+        this.origin = unit;
+    }
+
+    private Hep3Vector getUnit(Element e) throws DataConversionException  {
+        Hep3Vector v = new BasicHep3Vector(e.getAttribute("x").getDoubleValue(), e.getAttribute("y").getDoubleValue(), e.getAttribute("z").getDoubleValue());
+        return v;
+    }
+
+
+    public void rotate(Rotation rot) {
+       setOrigin( new BasicHep3Vector(rot.applyTo(new Vector3D(getOrigin().v())).toArray()) );
+       setX( new BasicHep3Vector(rot.applyTo(new Vector3D(getX().v())).toArray()) );
+       setY( new BasicHep3Vector(rot.applyTo(new Vector3D(getY().v())).toArray()) );
+       setZ( new BasicHep3Vector(rot.applyTo(new Vector3D(getZ().v())).toArray()) );
+        
+    }
+    
+    public void rotateOrigin(Rotation rot) {
+        setOrigin( new BasicHep3Vector(rot.applyTo(new Vector3D(getOrigin().v())).toArray()) );
+    }
+    
+    public void rotateUnitVectors(Rotation rot) {
+        setX( new BasicHep3Vector(rot.applyTo(new Vector3D(getX().v())).toArray()) );
+        setY( new BasicHep3Vector(rot.applyTo(new Vector3D(getY().v())).toArray()) );
+        setZ( new BasicHep3Vector(rot.applyTo(new Vector3D(getZ().v())).toArray()) );
+         
+     }
+
+
+    public Rotation getRotationFrom(SurveyCoordinateSystem coord) {
+        return new Rotation(new Vector3D(coord.u().v()), new Vector3D(coord.v().v()), new Vector3D(getX().v()), new Vector3D(getY().v()));
+    }
+
+
+    public Translation3D getTranslationFrom(SurveyCoordinateSystem coord) {
+        return new Translation3D(VecOp.sub(getOrigin(), coord.origin()));
+    }
+    
+    
+    public Transform3D getTransformation() {
+        // Find the transform between the two frames - use transform classes here (not really needed)
+        Translation3D translation = new Translation3D(origin.x(), origin.y(), origin.z());
+        Rotation3D rotation = new Rotation3D(
+                new BasicHep3Matrix(
+                        x.x(),y.x(),z.x(),
+                        x.y(),y.y(),z.y(),
+                        x.z(),y.z(),z.z()
+                        ));
+        Transform3D envelopeToSupportTransform = new Transform3D(translation, rotation);
+        return envelopeToSupportTransform;
+    }
+    
+    
+    public void transform(Transform3D t) {
+        Transform3D t_this = getTransformation();
+        Hep3Vector v = t_this.getTranslation().getTranslationVector();
+        Hep3Vector vrot = t.rotated(v);
+        Hep3Vector vrottrans = t.translated(vrot);
+        origin = vrottrans;
+        rotate(t.getRotation());
+    }
+    
+    public void rotate(IRotation3D r) {
+        r.rotate(x);
+        r.rotate(y);
+        r.rotate(z);
+    }
+    
+}

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use