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:

r1333 - /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:

Wed, 29 Oct 2014 16:21:13 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (156 lines)

Author: phansson
Date: Wed Oct 29 09:21:10 2014
New Revision: 1333

Log:
Update so that it actually works.

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

Modified: java/trunk/tracking/src/main/java/org/hps/svt/alignment/BuildMillepedeCompact.java
 =============================================================================
--- java/trunk/tracking/src/main/java/org/hps/svt/alignment/BuildMillepedeCompact.java	(original)
+++ java/trunk/tracking/src/main/java/org/hps/svt/alignment/BuildMillepedeCompact.java	Wed Oct 29 09:21:10 2014
@@ -33,6 +33,7 @@
 import org.hps.conditions.deprecated.HPSSVTSensorSetup;
 import org.hps.conditions.deprecated.SvtUtils;
 import org.hps.recon.tracking.CoordinateTransformations;
+import org.jdom.Attribute;
 import org.jdom.DataConversionException;
 import org.jdom.Document;
 import org.jdom.Element;
@@ -53,10 +54,15 @@
 
 public class BuildMillepedeCompact {
 
-	private static Options createCmdLineOpts() {
+	private static String detectorName = "Tracker";
+	private static boolean replaceConstant = false;
+
+
+    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."));
+		options.addOption(new Option("r", false, "Replace correction instead of adding to it."));
 		return options;
 	}
 	
@@ -93,6 +99,10 @@
 		String compactFilenameNew = "compact_new.xml";
 		if(cl.hasOption("o")) {
 			compactFilenameNew = cl.getOptionValue("o");
+		}
+		
+		if(cl.hasOption("r")) {
+		    replaceConstant = true;
 		}
 
 		
@@ -140,23 +150,52 @@
 			throw new RuntimeException("problem reading mille file",e);
 		}
 		
+		System.out.printf("Found %d millepede parameters\n ", params.size());
+		
+		
+
 		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));
-		}		
-		
+		List<Element> detectors = rootNode.getChildren("detectors");
+		for(Element detectorsNode : detectors) {
+		    List<Element> detectorNode = detectorsNode.getChildren("detector");
+		    if(detectorNode!=null) {
+		        System.out.println(detectorNode.size() + " detectors");
+		        for(Element detector : detectorNode) {
+		            if(detector.getAttribute("name")!=null) {
+		                if(detector.getAttributeValue("name").compareTo(detectorName)==0 ) {
+		                    System.out.println("Found " + detectorName);
+		                    for(MilleParameter p : params) {
+		                        Element node = findMillepedeConstantNode(detector,Integer.toString(p.getId()));
+		                        if(node!=null) {
+		                            double correction = p.getValue();
+		                            double oldValue = 0;
+		                            try {
+		                                oldValue = node.getAttribute("value").getDoubleValue();
+		                            } catch (DataConversionException e) {
+		                                e.printStackTrace();
+		                            }
+		                            double newValue;
+		                            if(replaceConstant) {
+		                                newValue = correction;
+		                            } else {
+		                                newValue = oldValue + correction;
+		                            }
+		                            System.out.println("Update " + p.getId() + ": " + oldValue + " (corr. " + correction + ") ->  "  + newValue );
+		                            node.setAttribute("value", String.format("%.6f",newValue));
+		                        } else {
+		                            throw new RuntimeException("no element found for " + p.getId() + " check format of compact file");
+		                        }
+		                    }       
+		                }
+		            } else {
+		                throw new RuntimeException("this detector node element is not formatted correctly");
+		            }
+		        }
+		    } else {
+		        throw new RuntimeException("this detector node element is not formatted correctly");
+		    }
+		}
+
 
 		// Save new XML file
 		
@@ -175,19 +214,25 @@
 		
 	}
 
-	
-	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);
+
+	private static Element findMillepedeConstantNode(Element detector, String name) {
+	    Element element_constants = detector.getChild("millepede_constants");
+	    if(element_constants==null) {
+	        throw new RuntimeException("no alignment constants in this xml file.");
+	    }
+	    List<Element> list = element_constants.getChildren("millepede_constant");
+	    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;
 	}
-	
+
 	
 
 	

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