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  October 2014

HPS-SVN October 2014

Subject:

r1323 - /java/trunk/tracking/src/main/java/org/hps/svt/alignment/BuildMillepedeCompact.java

From:

[log in to unmask]

Reply-To:

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

Date:

Tue, 28 Oct 2014 17:04:08 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (213 lines)

Author: phansson
Date: Tue Oct 28 10:04:05 2014
New Revision: 1323

Log:
New interface b/w Millepede and compact. Not tested yet.

Added:
    java/trunk/tracking/src/main/java/org/hps/svt/alignment/BuildMillepedeCompact.java

Added: java/trunk/tracking/src/main/java/org/hps/svt/alignment/BuildMillepedeCompact.java
 =============================================================================
--- java/trunk/tracking/src/main/java/org/hps/svt/alignment/BuildMillepedeCompact.java	(added)
+++ java/trunk/tracking/src/main/java/org/hps/svt/alignment/BuildMillepedeCompact.java	Tue Oct 28 10:04:05 2014
@@ -0,0 +1,197 @@
+package org.hps.svt.alignment;
+
+/**
+ * Class building a new compact.xml detector based on MillepedeII input corrections
+ * @author phansson
+ * created on 1/15/2014
+ */
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.hps.conditions.deprecated.HPSSVTSensorSetup;
+import org.hps.conditions.deprecated.SvtUtils;
+import org.hps.recon.tracking.CoordinateTransformations;
+import org.jdom.DataConversionException;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.ITransform3D;
+import org.lcsim.detector.tracker.silicon.ChargeCarrier;
+import org.lcsim.detector.tracker.silicon.SiSensor;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.GeometryReader;
+import org.lcsim.geometry.compact.converter.MilleParameter;
+import org.lcsim.util.xml.ElementFactory.ElementCreationException;
+
+
+public class BuildMillepedeCompact {
+
+	private static Options createCmdLineOpts() {
+		Options options = new Options();
+		options.addOption(new Option("c",true,"The path to the compact xml file."));
+		options.addOption(new Option("o",true,"The name of the new compact xml file."));
+		return options;
+	}
+	
+	private static void printHelpAndExit(Options options) {
+		HelpFormatter help = new HelpFormatter();
+		help.printHelp(" ", options);
+		System.exit(1);
+	}
+	
+		
+	public static void main(String[] args) {
+
+		// Setup command line input
+		Options options = createCmdLineOpts();
+		if (args.length == 0) {
+			printHelpAndExit(options);
+		}
+
+		CommandLineParser parser = new PosixParser();
+		CommandLine cl = null;
+		try {
+			cl = parser.parse(options, args);
+		} catch (ParseException e) {
+			throw new RuntimeException("Problem parsing command line options.",e);
+		}
+		
+		String compactFilename = null;  
+		if(cl.hasOption("c")) {
+			compactFilename = cl.getOptionValue("c");
+		} else {
+			printHelpAndExit(options);
+		}
+		
+		String compactFilenameNew = "compact_new.xml";
+		if(cl.hasOption("o")) {
+			compactFilenameNew = cl.getOptionValue("o");
+		}
+
+		
+		
+		File compactFile = new File(compactFilename);
+		
+		// read XML
+		SAXBuilder builder = new SAXBuilder();
+		Document compact_document = null;
+		try {
+			compact_document = (Document) builder.build(compactFile);
+		} catch (JDOMException | IOException e1) {
+			throw new RuntimeException("problem with JDOM ", e1);
+		}
+		
+		
+		
+		// Loop over all millepede input files and build a list of parameters
+		
+		List<MilleParameter> params = new ArrayList<MilleParameter>();
+		
+		FileInputStream inMille = null;
+		BufferedReader brMille = null;
+		try {
+			for(String milleFilename : cl.getArgs()) {
+				inMille = new FileInputStream(milleFilename);
+				brMille = new BufferedReader(new InputStreamReader(inMille));
+				String line;
+				while((line = brMille.readLine()) != null) {
+					//System.out.printf("%s\n",line);
+					if(!line.contains("Parameter") && !line.contains("!")) {
+						
+						MilleParameter par = new MilleParameter(line);
+						//System.out.println(par.getXMLName() + " " + par.getValue());
+						
+						//add the parameter
+						params.add(par);
+						
+					}
+				}
+				brMille.close();
+			}
+		}
+		catch (IOException e) {
+			throw new RuntimeException("problem reading mille file",e);
+		}
+		
+		Element rootNode = compact_document.getRootElement();
+        
+		for(MilleParameter p : params) {
+		    System.out.println("Update value for " + p.getXMLName());
+            Element node = findNode(rootNode,p.getXMLName());
+            double correction = p.getValue();
+            double oldValue = 0;
+            try {
+                oldValue = node.getAttribute("value").getDoubleValue();
+            } catch (DataConversionException e) {
+                e.printStackTrace();
+            }
+            double newValue = oldValue + correction;
+            System.out.println("old " + oldValue + " correction " + correction + " -> new "  + newValue);
+            node.setAttribute("value", String.format("%.6f",newValue));
+		}		
+		
+
+		// Save new XML file
+		
+		XMLOutputter xmlOutput = new XMLOutputter();
+		// display nice 
+		//xmlOutput.setFormat(Format.getPrettyFormat());
+		try {
+			xmlOutput.output(compact_document, new FileWriter(compactFilenameNew));
+		} catch (IOException e) {
+			throw new RuntimeException("problem with xml output",e);
+		}
+			
+		
+		
+		
+		
+	}
+
+	
+	private static Element findNode(Element node, String name) {
+	    List list = node.getChildren();
+	    for(Object o : list) {
+	        Element element = (Element) o;
+	        if(element.getAttributeValue("name").compareTo(name) == 0) {
+	            return element;
+	        } 
+	        return findNode(element,name);
+	    }
+	    return null;
+	}
+	
+	
+
+	
+	
+	
+
+}

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