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  July 2015

HPS-SVN July 2015

Subject:

r3215 - /java/trunk/users/src/main/java/org/hps/users/phansson/ReadSurveyRotations.java

From:

[log in to unmask]

Reply-To:

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

Date:

Wed, 1 Jul 2015 10:30:04 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (199 lines)

Author: [log in to unmask]
Date: Wed Jul  1 03:29:53 2015
New Revision: 3215

Log:
read rotations from survey

Added:
    java/trunk/users/src/main/java/org/hps/users/phansson/ReadSurveyRotations.java

Added: java/trunk/users/src/main/java/org/hps/users/phansson/ReadSurveyRotations.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/phansson/ReadSurveyRotations.java	(added)
+++ java/trunk/users/src/main/java/org/hps/users/phansson/ReadSurveyRotations.java	Wed Jul  1 03:29:53 2015
@@ -0,0 +1,183 @@
+/**
+ * 
+ */
+package org.hps.users.phansson;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
+import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder;
+import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
+import org.hps.util.BasicLogFormatter;
+import org.lcsim.util.log.LogUtil;
+
+/**
+ * @author Per Hansson Adrian <[log in to unmask]>
+ *
+ */
+public class ReadSurveyRotations {
+
+    final static Logger logger = LogUtil.create(ReadSurveyRotations.class.getSimpleName(), new BasicLogFormatter(), Level.INFO);
+    
+    String name;
+    String parent;
+    Hep3Vector u;
+    Hep3Vector v;
+    Hep3Vector w;
+    
+    /**
+     * @param args
+     */
+    public static void main(String[] args) {
+
+        
+        List<ReadSurveyRotations> rotSurvey = getRotations(args[0]);
+        logger.info("Found " + rotSurvey.size() + " survey rotations");
+        
+        List<ReadSurveyRotations> rotIdeal = getRotations(args[1]);
+        logger.info("Found " + rotIdeal.size() + " ideal rotations");
+        
+        
+        
+        for (ReadSurveyRotations r : rotIdeal) {
+            for (ReadSurveyRotations rs : rotSurvey) {
+                if(rs.equals(r)) {
+                    Rotation rotation = new Rotation(get3DVector(r.u), get3DVector(r.v), get3DVector(rs.u), get3DVector(rs.v));
+                    //logger.fine(r.name + " in " + r.parent + " u " + r.u.toString() + " v " + r.v.toString() + " v " + r.w.toString());
+                    if(args.length>3) {
+                        if(!Pattern.matches(args[2], r.name) || !Pattern.matches(args[3], r.parent)) {
+                            continue;
+                        }
+                    }
+                    StringBuffer sb = new StringBuffer();
+                    sb.append( String.format("%s in %s\n", r.name,r.parent) );
+                    sb.append( String.format("u: %s -> %s\n", r.u.toString(),rs.u.toString()) );
+                    sb.append( String.format("v: %s -> %s\n", r.v.toString(),rs.v.toString()) );
+                    sb.append( String.format("w: %s -> %s\n", r.w.toString(),rs.w.toString()) );
+                    sb.append( String.format("w: %s -> %s\n", r.w.toString(),rs.w.toString()) );
+                    double cardanAngles[] = rotation.getAngles(RotationOrder.XYZ);
+                    sb.append( String.format("%s in %s Cardan XYZ: %f,%f,%f\n", r.name, r.parent, cardanAngles[0],cardanAngles[1],cardanAngles[2]) );
+                    System.out.printf("%s\n", sb.toString());
+                } 
+            }   
+        }
+        
+        
+        
+        
+        
+    }
+    
+    
+    private static Vector3D get3DVector(Hep3Vector x) {
+        return new Vector3D(x.x(), x.y(), x.z());
+    }
+    
+    public boolean equals(ReadSurveyRotations other) {
+        return other==null ? false : this.name.equals(other.name) && this.parent.equals(other.parent);
+    }
+    
+    
+    private static double convertDouble(String str) {
+        return new BigDecimal(str).doubleValue();
+    }
+    
+    private static Hep3Vector getVector(String str) {
+        Pattern p = Pattern.compile("\\s*(\\S+),\\s*(\\S+),\\s*(\\S+).*");
+        Matcher matcher = p.matcher(str);
+        if(!matcher.matches()) {
+            throw new RuntimeException("cannot match vector to string \"" + str + "\"");
+        }
+        return new BasicHep3Vector(convertDouble(matcher.group(1)), convertDouble(matcher.group(2)), convertDouble(matcher.group(3)));
+        
+    }
+    
+    
+    
+    public ReadSurveyRotations(String name, String parent, Hep3Vector u, Hep3Vector v, Hep3Vector w) {
+        this.name = name;
+        this.parent = parent;
+        this.u = u;
+        this.v = v;
+        this.w = w;
+    }
+    
+    
+    private static List<ReadSurveyRotations> getRotations(String fileName) {
+        
+        List<ReadSurveyRotations> list = new ArrayList<ReadSurveyRotations>();
+        
+        
+        Pattern pattern = Pattern.compile("(.*)\\sorigin\\sin\\s(\\S+)\\s.*\\(mm\\)\\su.*\\[(.*)\\]\\sv.*\\[(.*)\\]\\sw.*\\[(.*)\\].*");
+        //Pattern.compile(".*mm.*u\s[(.*)].*v\s[(.*)].*w\s[(.*)]");
+        Matcher matcher;
+        File file = new File(fileName);
+        //File outputFile = new File(fileName+".rot");
+        try {
+            
+            //FileWriter writer = new FileWriter(outputFile);
+            //BufferedWriter bWriter = new BufferedWriter(writer);
+            FileReader reader = new FileReader(file);
+            BufferedReader bReader = new BufferedReader(reader);
+  
+            String line;
+            try {
+                while((line = bReader.readLine()) != null) {
+                    //logger.info(line);
+                    matcher = pattern.matcher(line);
+                    if(matcher.matches()) {
+                        String name = matcher.group(1);
+                        String parent = matcher.group(2);
+                        //logger.info("matched " + name + " g1 " + matcher.group(3));
+                        Hep3Vector u = getVector(matcher.group(3));
+                        Hep3Vector v = getVector(matcher.group(4));
+                        Hep3Vector w = getVector(matcher.group(5));
+                        if(Math.abs(u.magnitude()-1.0)>0.0001 || Math.abs(v.magnitude()-1.0)>0.0001 ||Math.abs(w.magnitude()-1.0)>0.0001 ) {
+                            logger.warning(line);
+                            logger.warning("name: " + name + " unit vectors: " + u.toString() + " " + v.toString() + " " + w.toString());
+                            throw new RuntimeException("error reading vectors");
+                        }
+                        ReadSurveyRotations rot = new ReadSurveyRotations(name, parent, u, v, w);
+                        list.add(rot);
+                    }
+                }
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+            try {
+                bReader.close();
+                reader.close();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+            
+            
+            
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+        
+        return list;
+        
+        
+    }
+    
+
+
+}

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