Author: [log in to unmask]
Date: Wed May 4 16:15:15 2016
New Revision: 4350
Log:
Crystal positions now are read from database,
some comments added, minor modifications
Added:
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/GVector.java
- copied, changed from r4349, java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Vector.java
java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalTransformationsTest.java
- copied, changed from r4349, java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalCrystalPositionTest.java
Removed:
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Vector.java
Modified:
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/DataLoader.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/StatFunUtils.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/Crystal.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/CrystalTaitBryanAngleCalculator.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/Geant4Position.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/ECalRotationCalculator.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/EcalNominal.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/EcalSurveyData.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/Transformations.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/ (props changed)
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/CenterMass.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Line.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Plane.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/lcsim/detector/converter/compact/HPSEcal4Converter.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSEcal4.java
java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalCrystalPositionTest.java
java/branches/HPSJAVA-409/detector-model/src/test/java/org/lcsim/detector/converter/compact/HPSEcal4ConverterTest.java
java/branches/HPSJAVA-409/detector-model/src/test/java/org/lcsim/geometry/compact/converter/lcdd/HPSEcal4LCDDTest.java
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/DataLoader.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/DataLoader.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/DataLoader.java Wed May 4 16:15:15 2016
@@ -18,7 +18,7 @@
/**
* Class to read the data from a file
- * @author SA
+ * @author Annie Simonyan [log in to unmask]
*/
public class DataLoader {
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/StatFunUtils.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/StatFunUtils.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/StatFunUtils.java Wed May 4 16:15:15 2016
@@ -1,26 +1,22 @@
package org.hps.detector.ecal.geo2015.base;
/**
- * Some static functions, well, just one
+ * Some static functions which I couldn't find in java standard libraries
*
- * @author SA
+ * @author Annie Simonyan [log in to unmask]
*/
public class StatFunUtils {
/*****
- * Function to doubles to rounds up the value to 'places' digits after the ","
+ * Function for double to round up the arg. value to 'places' digits after the semicolon
******/
public static double round(double value, int places) {
if (places < 0 || places > 16) {
throw new IllegalArgumentException();
}
- long factor = (long) Math.pow(10, places);
- // System.out.println(factor+" val = "+value);
+ long factor = (long) Math.pow(10, places);
value = value * factor;
- // System.out.println("again "+value);
- long tmp = Math.round(value);
- // System.out.println("tmp = "+tmp);
- // System.out.println((double) tmp / factor);
+ long tmp = Math.round(value);
return (double) tmp / factor;
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/Crystal.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/Crystal.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/Crystal.java Wed May 4 16:15:15 2016
@@ -1,39 +1,65 @@
package org.hps.detector.ecal.geo2015.crystal;
+
+/*
+ * This class describes a single crystal
+ * as an object with layer and column number (Y and X in ECal) and position coordinates in geant4 convention,
+ * (it's center (x,y,z) coordinates and Tait-Bryan (phi, theta, psi) angles to define rotation)
+ *
+ * @author Annie Simonyan [log in to unmask]
+ */
+
public class Crystal {
- private int layer;
- private int column;
- private Geant4Position pos;
+ private int layer; //crystal Y(row) (-5;5)
+ private int column; //crystal X(column) (-23;23)
+ private Geant4Position pos; //crystal position in Geant4 convention
+ //arguments for constructor are
+ //1 int-X crystal column number (-23;23), exclude 0
+ //2 int-Y crystal row number (-5;5). exclude 0
+ //3 Geant4Position - crystal position coordinates in geant4 convention,
+ //(it's center (x,y,z) coordinates and Tait-Bryan (phi, theta, psi) angles to define rotation)
public Crystal(int icol, int ilayer, Geant4Position ipos) {
this.layer = ilayer;
this.column = icol;
this.pos = ipos;
}
+ //returns crystal position coordinates in geant4 convention,
+ //(it's center (x,y,z) coordinates and Tait-Bryan (phi, theta, psi) angles to define rotation)
public Geant4Position getCrystalG4Pos() {
return this.pos;
}
+ //returns crystal Y(row) number (-5;5), except 0
public int getLayer() {
return this.layer;
}
+ ///returns crystal X(column) number (-23;23), except 0
public int getColumn() {
return this.column;
}
+ //set crystal Y(row) number (-5;5), except 0
public void setLayer(int ilayer) {
this.layer = ilayer;
}
+ //set crystal X(column) number (-23;23), except 0
public void setColumn(int icol) {
this.column = icol;
}
+ //set crystal position coordinates in geant4 convention,
+ //(it's center (x,y,z) coordinates and Tait-Bryan (phi, theta, psi) angles to define rotation)
public void setG4Position(Geant4Position ipos) {
this.pos = ipos;
}
-
+
+ //returns crystal attributes as String - (X,Y)Geant4Position
+ public String toString(){
+ return ("("+column+","+layer+")"+ pos.toString());
+ }
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/CrystalTaitBryanAngleCalculator.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/CrystalTaitBryanAngleCalculator.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/CrystalTaitBryanAngleCalculator.java Wed May 4 16:15:15 2016
@@ -4,30 +4,39 @@
*/
package org.hps.detector.ecal.geo2015.crystal;
-import org.hps.detector.ecal.geo2015.geoutils.Vector;
+import org.hps.detector.ecal.geo2015.geoutils.GVector;
/**
- * Calculates Euler(actually tait-bryan) angles for a rotation, that transfers the crystal from it's initial
- * state-parallel to Z axis To final state-defined by 2 points in front and back faces.
- *
- * @author SA
+ * Calculates Euler(actually Tait-Bryan) angles for a rotation, that transfers the crystal from it's initial
+ * state-parallel to Z axis To final state-defined by 2 center points in front and back faces of the crystal.
+ * for information about Tait-Bryan angles look here: http://sedris.org/wg8home/Documents/WG80485.pdf
+ *
+ * phi - rotation angle around x
+ * theta - rotation angle around y
+ * psi - rotation angle around z
+ *
+ * @author Annie Simonyan [log in to unmask]
*/
public class CrystalTaitBryanAngleCalculator {
+
+ private double phi = 0; //Tait-Bryan phi angle
+ private double theta = 0; ////Tait-Bryan theta angle
+ private final double psi = 0; ////Tait-Bryan psi angle
- private double phi = 0;
- private double theta = 0;
- private final double psi = 0;
+ private static final GVector ini = new GVector(0, 0, 1); //initial state vector
- private static final Vector ini = new Vector(0, 0, 1);
-
- private Vector fin;
+ private GVector fin; //final state vector
private double cosTheta = 0;
private double sinTheta = 0;
private double cosPhi = 0;
private double sinPhi = 0;
- public CrystalTaitBryanAngleCalculator(Vector vec_fin) {
+
+ //contractor: the argument is the final state unitary vector,
+ //if not unit, it will be redefined as unitary
+ //initial state is defined as (0,0,1) vector, which is parallel to Z(beam direction)
+ public CrystalTaitBryanAngleCalculator(GVector vec_fin) {
fin = vec_fin;
if (vec_fin.isUnitary() == false) {
@@ -38,6 +47,7 @@
this.theta = this.CalcTheta();
}
+ //calculates phi angle
private double CalcPhi() {
sinPhi = -fin.y;
@@ -46,6 +56,8 @@
return Math.asin(this.sinPhi);
}
+
+ //calculates theta angle after phi is calculated
private double CalcTheta() {
if (this.cosPhi == 0)
@@ -56,16 +68,24 @@
return Math.asin(this.sinTheta);
}
+
+ //returns value of theta in rad
public double getTheta() {
return this.theta;
}
+ //returns value of phi anlge in rad
public double getPhi() {
return this.phi;
}
-
+
+ //returns value of psi angle in rad
public double getPsi() {
return this.psi;
}
-
+
+ //returns Tait-Bryan angles as a String in the format of (phi, theta, psi)
+ public String toString(){
+ return ("("+this.phi+","+this.theta+","+this.psi+")");
+ }
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/Geant4Position.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/Geant4Position.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/Geant4Position.java Wed May 4 16:15:15 2016
@@ -1,63 +1,75 @@
package org.hps.detector.ecal.geo2015.crystal;
-import org.hps.detector.ecal.geo2015.geoutils.Vector;
+import java.util.logging.Logger;
+import org.hps.detector.ecal.geo2015.geoutils.GVector;
+
/**
* Calculates G4 position for a crystal, by it's front and back face coordinates calculates the position for the center
* of the crystal calculates the rotation of the crystal in convention of Tait-Bryan angles, {phi, theta, psi} *****
* dear reader google it if confused :P
+ * or look here: http://sedris.org/wg8home/Documents/WG80485.pdf
+ * Brief:
+ * phi-rotation around X
+ * theta-rotation around Y
+ * psi-rotation around Z
*
- * @author SA
+ * @author Annie Simonyan [log in to unmask]
*/
public class Geant4Position {
- private Vector centerPoint;
- private Vector crysvec;
- private double[] taitbriangles; // { phi,theta,psi=0};
- private double[] center_arr;
+ private static Logger LOGGER = Logger.getLogger(Geant4Position.class.getPackage().getName());
+
+ private GVector centerPoint; // center coordinate
+ private GVector crysvec; // crystal vector formed by front face center point and back face center point
+ private double[] taitbriangles; // { phi,theta,psi=0}; Tait-Bryan angles to define crystal orientation in the space
+ private double[] centerArr; //crystal center coordinates as a double[3] array
- public Geant4Position(Vector point1, Vector point2) {
-
- if (point1 == null || point2 == null)
- System.err.println("The arguments can't be 0.");
-
+ //contsructor arguments
+ //1 Vector - (x,y,z) of crystal front face center point as Vector
+ //2 Vector - (x,y,z) of crystal back face center point as Vector
+ public Geant4Position(GVector point1, GVector point2) {
centerPoint = point2.Add(point1).Multiply(0.5);
- center_arr = new double[3];
- center_arr[0] = centerPoint.x;
- center_arr[1] = centerPoint.y;
- center_arr[2] = centerPoint.z;
+ centerArr = new double[3];
+ centerArr[0] = centerPoint.x;
+ centerArr[1] = centerPoint.y;
+ centerArr[2] = centerPoint.z;
crysvec = (point2.Substract(centerPoint)).getUnitVector();
- System.out.println("*************** center unit vector **********");
- crysvec.Print();
- System.out.println("*********************************************");
+ LOGGER.info("*************** center unit vector **********");
+ LOGGER.info(crysvec.toString());
+ LOGGER.info("*********************************************");
taitbriangles = new double[3];
this.TaitBryanAnglesforCrys();
}
- public Vector getCenter() {
+ //returns the center coordinates as a Vector
+ public GVector getCenter() {
return this.centerPoint;
}
+ //returns center coordinates as an array of doubles
public double[] getCenterArr() {
- double[] center_arr = {centerPoint.x, centerPoint.y, centerPoint.z};
- return center_arr;
+ return centerArr;
}
+ //returns Tait-Bryan angles as an array of doubles [phi, theta, psi]
public double[] getTaitBryanAngles() {
return this.taitbriangles;
}
- private void TaitBryanAnglesforCrys() {
+ //calculates Tait-Bryan angles for the object orientation defined by initial and final state vectors
+ //throws arithmetical exception if the phi angle is calculated wrong or 0
+ private void TaitBryanAnglesforCrys() throws ArithmeticException{
CrystalTaitBryanAngleCalculator crysTBang = new CrystalTaitBryanAngleCalculator(crysvec);
/*
* please vec should go from the center, even though it's not changing much
*/
- if (crysTBang.getPhi() == Double.NaN) {
- System.out.print("chert: Phi is undefined\n");
+ if (crysTBang.getPhi() == Double.NaN) {
this.taitbriangles[0] = -111111;
+ throw new ArithmeticException("chert: Phi is undefined\n");
} else {
this.taitbriangles[0] = -crysTBang.getPhi();
}
@@ -65,11 +77,18 @@
this.taitbriangles[2] = -crysTBang.getPsi();
}
+ //Print crystal center coordinates(X,Y,Z) and Tait-Bryan angles
public void Print() {
System.out.println("Crys Center coordinates:\t");
this.centerPoint.Print();
System.out.println("Tait Brian angles phi = " + Math.toDegrees(this.taitbriangles[0]) + "\t theta = "
+ Math.toDegrees(this.taitbriangles[1]) + "\t psi = " + Math.toDegrees(this.taitbriangles[2]) + "\n");
}
+
+ //return Geant4Position object attributes as a String
+ public String toString(){
+ return ("\"Crys Center coordinates:\\t\""+this.centerPoint.toString()+"Tait Brian angles phi = " + Math.toDegrees(this.taitbriangles[0]) + "\t theta = "
+ + Math.toDegrees(this.taitbriangles[1]) + "\t psi = " + Math.toDegrees(this.taitbriangles[2]) + "\n");
+ }
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/ECalRotationCalculator.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/ECalRotationCalculator.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/ECalRotationCalculator.java Wed May 4 16:15:15 2016
@@ -1,28 +1,39 @@
package org.hps.detector.ecal.geo2015.ecal;
-import org.hps.detector.ecal.geo2015.geoutils.Vector;
+import org.hps.detector.ecal.geo2015.geoutils.GVector;
import org.hps.detector.ecal.geo2015.base.StatFunUtils;
/*
- * This class will calculate rotation angles of ECal modules plane (4 measuring
- * points), for ecal conditions
+ * This class will calculate rotation angles of ECal top or bottom module plane defind by (4 measuring target points)
+ * in XYZ space
+ *
+ * Rotation angles are defined as follows:
+ * alpha - rotation around Z
+ * beta - rotation around Y=0 for this calculations
+ * gamma - rotation around X
*/
/**
*
- * @author SA
+ * @author Annie Simonyan
*/
public class ECalRotationCalculator {
- private Vector n_ini, n_fin; //normal of the plane before and after rotation.
+ private GVector n_ini, n_fin; //normal of the plane before and after rotation.
- private double a0 = 0.0, b0 = 0.0, c0 = 0.0;
- private double a = 0.0, b = 0, c = 0;
+ private double a0 = 0.0, b0 = 0.0, c0 = 0.0; //parameters of initial plane equation
+ private double a = 0.0, b = 0, c = 0; //parameters of final plane equation
private double alpha = 0.0; //Rz
//private double betta = 0.0; //Ry
private double gamma = 0.0; //Rx
+ //default constractor, don't really use it
public ECalRotationCalculator(){}
+
+ //meaningful constructor
+ //argument should be:
+ //"top" - for top module calculation
+ //"bottom" - for bottom module calculation
public ECalRotationCalculator(String str /*str = top(default) or str = bottom*/) {
n_ini = EcalSurveyData.plABCDtop_ini.getNormalUnitVector();
@@ -60,8 +71,9 @@
calcGamma();
calcAlpha();
- }
+ };
+ //Calculate gamma rotation angle
private void calcGamma() {
double tg_gamma = 0.0;
@@ -76,6 +88,7 @@
}
+ //calculate alpha rotation angle
private void calcAlpha() {
double ham = (a * a0 - b * (b0 * Math.cos(gamma) - c0 * Math.sin(gamma)));
@@ -86,21 +99,20 @@
alpha = Math.PI-alpha;
}
+ //return value of alpha - rotatoin around Z
public double getAlpha() {
return this.alpha;
}
+ //return value of gamma - rotatoin around X
public double getGamma() {
return this.gamma;
}
+ //returns true if the normal vectors of the initial and final plane are actually normal
private boolean checkNormals() {
- if (Double.compare(StatFunUtils.round(n_ini.Module(),12),1.0)==0 && Double.compare(StatFunUtils.round(n_fin.Module(),12),1.0)==0) {
- return true;
- }
-
- return false;
- }
+ return(Double.compare(StatFunUtils.round(n_ini.Module(),12),1.0)==0 && Double.compare(StatFunUtils.round(n_fin.Module(),12),1.0)==0);
+ }
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/EcalNominal.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/EcalNominal.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/EcalNominal.java Wed May 4 16:15:15 2016
@@ -1,16 +1,12 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
package org.hps.detector.ecal.geo2015.ecal;
import org.hps.detector.ecal.geo2015.geoutils.Plane;
-import org.hps.detector.ecal.geo2015.geoutils.Vector;
+import org.hps.detector.ecal.geo2015.geoutils.GVector;
/**
- *
- * @author AS
+ * This class holds the nominal(by initial design) coordinates for 4 measuring points of each ecal module
+ *
+ * @author Annie Simonyan ([log in to unmask])
*/
public class EcalNominal {
@@ -21,10 +17,10 @@
public static final double[] Ctop = {517.38, 230.79, 933.73}; //(x,y,z) point C initial
public static final double[] Dtop = {517.38, 230.79, 1083.73}; //(x,y,z) point D initial
- public static final Vector AtopVec = new Vector(Atop);
- public static final Vector BtopVec = new Vector(Btop);
- public static final Vector CtopVec = new Vector(Ctop);
- public static final Vector DtopVec = new Vector(Dtop);
+ public static final GVector AtopVec = new GVector(Atop);
+ public static final GVector BtopVec = new GVector(Btop);
+ public static final GVector CtopVec = new GVector(Ctop);
+ public static final GVector DtopVec = new GVector(Dtop);
//Nominal plane of top module
@@ -38,10 +34,10 @@
public static final double[] Cbot = {517.38, -230.93, 933.73}; //(x,y,z) point C initial
public static final double[] Dbot = {517.38, -230.93, 1083.73}; //(x,y,z) point D initial
- public static final Vector AbotVec = new Vector(Abot);
- public static final Vector BbotVec = new Vector(Bbot);
- public static final Vector CbotVec = new Vector(Cbot);
- public static final Vector DbotVec = new Vector(Dbot);
+ public static final GVector AbotVec = new GVector(Abot);
+ public static final GVector BbotVec = new GVector(Bbot);
+ public static final GVector CbotVec = new GVector(Cbot);
+ public static final GVector DbotVec = new GVector(Dbot);
//Nominal plane of bottom module
public static Plane plABCDbot_ini = new Plane(Abot, Bbot, Cbot);
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/EcalSurveyData.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/EcalSurveyData.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/EcalSurveyData.java Wed May 4 16:15:15 2016
@@ -6,12 +6,12 @@
package org.hps.detector.ecal.geo2015.ecal;
import org.hps.detector.ecal.geo2015.geoutils.Plane;
-import org.hps.detector.ecal.geo2015.geoutils.Vector;
+import org.hps.detector.ecal.geo2015.geoutils.GVector;
/**
* Class to hold the survey results (positions of 4 targets of calorimeter in the hall)
* I agree, probably not the best idea to have a class as a "data-holder"
- * @author SA
+ * @author Annie Simonyan
*/
public class EcalSurveyData {
@@ -22,10 +22,10 @@
public static final double[] Ctop = {517.38, 230.79, 933.73}; //(x,y,z) point C initial
public static final double[] Dtop = {517.38, 230.79, 1083.73}; //(x,y,z) point D initial
- public static final Vector AtopVec = new Vector(Atop);
- public static final Vector BtopVec = new Vector(Btop);
- public static final Vector CtopVec = new Vector(Ctop);
- public static final Vector DtopVec = new Vector(Dtop);
+ public static final GVector AtopVec = new GVector(Atop);
+ public static final GVector BtopVec = new GVector(Btop);
+ public static final GVector CtopVec = new GVector(Ctop);
+ public static final GVector DtopVec = new GVector(Dtop);
//Survey measurements for top module
public static final double[] topAsur = {-298.67, 233.7, 939.11}; //{x,y,z} point Atop final=measured=from survey
@@ -33,10 +33,10 @@
public static final double[] topCsur = {516.53, 233.26, 938.25}; //(x,y,z) point C final
public static final double[] topDsur = {517.07, 233.24, 1088.29}; //(x,y,z) point D final
- public static final Vector topAsurVec = new Vector(topAsur);
- public static final Vector topBsurVec = new Vector(topBsur);
- public static final Vector topCsurVec = new Vector(topCsur);
- public static final Vector topDsurVec = new Vector(topDsur);
+ public static final GVector topAsurVec = new GVector(topAsur);
+ public static final GVector topBsurVec = new GVector(topBsur);
+ public static final GVector topCsurVec = new GVector(topCsur);
+ public static final GVector topDsurVec = new GVector(topDsur);
//Nominal plane of top module
public static Plane plABCDtop_ini = new Plane(Atop, Btop, Ctop);
@@ -76,10 +76,10 @@
public static final double[] Cbot = {517.38, -230.93, 933.73}; //(x,y,z) point C initial
public static final double[] Dbot = {517.38, -230.93, 1083.73}; //(x,y,z) point D initial
- public static final Vector AbotVec = new Vector(Abot);
- public static final Vector BbotVec = new Vector(Bbot);
- public static final Vector CbotVec = new Vector(Cbot);
- public static final Vector DbotVec = new Vector(Dbot);
+ public static final GVector AbotVec = new GVector(Abot);
+ public static final GVector BbotVec = new GVector(Bbot);
+ public static final GVector CbotVec = new GVector(Cbot);
+ public static final GVector DbotVec = new GVector(Dbot);
//Survey measurements for top module
public static final double[] botAsur = {-299.94, -232.07, 937.16}; //{x,y,z} point Atop final=measured=from survey
@@ -87,10 +87,10 @@
public static final double[] botCsur = {517.21, -231.41, 935.97}; //(x,y,z) point C final
public static final double[] botDsur = {517.44, -231.45, 1086.01}; //(x,y,z) point D final
- public static final Vector botAsurVec = new Vector(botAsur);
- public static final Vector botBsurVec = new Vector(botBsur);
- public static final Vector botCsurVec = new Vector(botCsur);
- public static final Vector botDsurVec = new Vector(botDsur);
+ public static final GVector botAsurVec = new GVector(botAsur);
+ public static final GVector botBsurVec = new GVector(botBsur);
+ public static final GVector botCsurVec = new GVector(botCsur);
+ public static final GVector botDsurVec = new GVector(botDsur);
//Nominal plane of top module
public static Plane plABCDbot_ini = new Plane(Abot, Bbot, Cbot);
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/Transformations.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/Transformations.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/Transformations.java Wed May 4 16:15:15 2016
@@ -1,172 +1,208 @@
-/*
- * To change this license header, choose License Headers in Project Properties. To change this template file, choose
- * Tools | Templates and open the template in the editor.
- */
+
package org.hps.detector.ecal.geo2015.ecal;
-import org.hps.detector.ecal.geo2015.geoutils.Vector;
-import org.hps.detector.ecal.geo2015.base.DataLoader;
+import org.hps.detector.ecal.geo2015.geoutils.GVector;
import org.hps.detector.ecal.geo2015.crystal.Crystal;
import org.hps.detector.ecal.geo2015.crystal.Geant4Position;
-import java.io.File;
-import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.PrintStream;
import java.util.Map;
import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.hps.conditions.database.DatabaseConditionsManager;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalCrystalPosition;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.converter.compact.HPSEcal3Converter;
/**
- * Class does all the transformations to rotate and translate the modules of ecal by given arguments from rel to it's
- * nominal pos. An issue is, that once a module is transformed, the non modified module map remains undefined This needs
- * to be fixed or not? Has bunch of printouts for debuging, will be removed soon, I hope soon :/
- *
- * @author SA
+ * Class does all the transformations to rotate and translate the modules of
+ * ecal by given arguments from rel to it's nominal pos. An issue is, that once
+ * a module is transformed, the non modified module map remains undefined This
+ * needs to be fixed or not? Has bunch of printouts for debuging, will be
+ * removed soon, I hope soon :/
+ *
+ * @author Annie Simonyan [log in to unmask]
*/
public class Transformations {
- public Vector transVec;
- public double[] rotation;
- private String module;// top or bottom or all
- private Vector CMvec_nom_top = new Vector(109.88, 230.79, 1008.73);
- private Vector CMvec_nom_bot = new Vector(109.88, -230.79, 1008.73);
-
- private Map<String, Crystal> crystalMap;
-
- public Transformations(String module, double[] trans, double[] rot) {
- System.out.println(module);
- System.out.println("trans arg " + trans[0] + "\t" + trans[1] + "\t" + trans[2]);
- System.out.println("rot arg " + rot[0] + "\t" + rot[1] + "\t" + rot[2]);
- this.transVec = new Vector(trans);
- transVec.Print();
+ public static Logger LOGGER = Logger.getLogger(HPSEcal3Converter.class.getPackage().getName());
+
+ public GVector transVec; //vector of translation
+ public double[] rotation; // rotation
+
+ private String module;// name "top" or "bottom" to tranform Ecal top or bottom module respectively
+
+ private final GVector CMvec_nom_top = new GVector(109.88, 230.79, 1008.73); //geometrically defined center mass of top module
+ private final GVector CMvec_nom_bot = new GVector(109.88, -230.79, 1008.73); //geometrically defined center mass of bottom module
+
+
+ private Map<String, Crystal> crystalMap; //Map of crystals with key = ("c#column:l#layer")
+
+ //constructor with argumnets
+ //1 - module name "top" or "bottom" - case is ignored
+ //2 - translation in the space as an array with translation vector coordinates [x,y,z]
+ //3 - rotation in the space as an array with rotation angles [Rz-alpha, Ry-beta, Rx-gamma]
+ public Transformations(String module, double[] trans, double[] rot) throws ConditionsManager.ConditionsNotFoundException {
+ LOGGER.info(("transformations for the module = "+module));
+ LOGGER.info(("translation arg " + trans[0] + "\t" + trans[1] + "\t" + trans[2]));
+ LOGGER.info(("rotation arg " + rot[0] + "\t" + rot[1] + "\t" + rot[2]));
+ this.transVec = new GVector(trans);
+ LOGGER.info(transVec.toString());
this.rotation = rot;
- System.out.println("rotation " + this.rotation[0] + "\t" + this.rotation[1] + "\t" + this.rotation[2]);
+ LOGGER.info(("rotation " + this.rotation[0] + "\t" + this.rotation[1] + "\t" + this.rotation[2]));
this.module = module;
this.crystalMap = new HashMap<String, Crystal>();
try {
this.makeTransformation();
- } catch (IOException e) {
- System.err.print("Can't do transformations, for some reason " + crystalMap.size());
- }
+ }
+ catch (FileNotFoundException ex) {
+ Logger.getLogger(Transformations.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
}
+ //returns the map of crystals
public Map<String, Crystal> getCrystalMap() {
return this.crystalMap;
}
- private void makeTransformation() throws IOException {
- DataLoader data = new DataLoader();
-
- data.setSplitSimbol("\t");
- data.LoadData("/projet/nucleon2/annie/HPS/withHPS_Java/SENA/hps_trunk_dev/HPSJAVA_409anothercopy02_02_2016/detector-model/src/main/java/org/hps/detector/ecal/geo2015/data/Crystal_COORDINATES_relTarget.txt");
- System.out.println("FILE PATHHHHHH " + (new File(".").getAbsolutePath().toString()));
- System.out.println("FILE PATH11111 " + System.getProperty("user.dir")
- + "/src/main/java/org/hps/detector/ecal/geo2015/data/Crystal_COORDINATES_relTarget.txt");
-
- // data.LoadData(System.getProperty("user.dir")+"/src/main/java/org/hps/detector/ecal/geo2015/data/Crystal_COORDINATES_relTarget.txt");
- // data.LoadData(FileSystems.getDefault().getPath("data", "Crystal_COORDINATES_relTarget.txt").toString());
- System.out.println("Number of coloms read from the file = " + data.getNumberCols());
-
- Double[] N = data.getColumn(0);
- Double[] layer = data.getColumn(1);
- Double[] col = data.getColumn(2);
- Double[] Xfront = data.getColumn(3);
- Double[] Yfront = data.getColumn(4);
- Double[] Zfront = data.getColumn(5);
- Double[] Xback = data.getColumn(6);
- Double[] Yback = data.getColumn(7);
- Double[] Zback = data.getColumn(8);
-
- // data.Print();
- Vector[] frontXYZ = new Vector[N.length];
- Vector[] backXYZ = new Vector[N.length];
-
- Vector CMvec_nom = new Vector();
-
- /*
- * File wfile = new File("../data/output_relTarget.txt"); FileWriter fw = new
- * FileWriter(wfile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(
- * "#column /t #layer /t #front_faceX /t #front_faceY /t #front_faceZ /t #back_faceX /t #back_faceY /t #back_faceZ \n"
- * );
- */
- // translate the coordinate system to CM
- for (int loop = 0; loop < N.length; loop++) {
-
- if (this.module.compareToIgnoreCase("bottom") == 0 && layer[loop] > 0) {
+ //does all the transformatios initiated in constructor
+ private void makeTransformation() throws FileNotFoundException, ConditionsManager.ConditionsNotFoundException{
+ //trying to access database to read ecal crystal positions and channels
+ try {
+
+ //initializing database access
+ DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
+ EcalCrystalPosition.EcalCrystalPositionCollection positions
+ = mgr.getCachedConditions(EcalCrystalPosition.EcalCrystalPositionCollection.class, "ecal_crystal_positions").getCachedData();
+
+ EcalChannel.EcalChannelCollection channels
+ = mgr.getCachedConditions(EcalChannel.EcalChannelCollection.class, "ecal_channels").getCachedData();
+
+ //define number of crystals
+ int Ncrys = positions.size();
+
+ //crystal layer is equivalent to Y(-5;5) and col-> to X(-23;23) of ecal mapping
+ int[] layer = new int[Ncrys];
+ int[] col = new int[Ncrys];
+
+ // LOGGER.info(data.toString());
+ GVector[] frontXYZ = new GVector[Ncrys];
+ GVector[] backXYZ = new GVector[Ncrys];
+
+ //declaring temp center mass vector to be used in the loop
+ GVector CMvec_nom = new GVector();
+
+ /*
+ * File wfile = new File("../data/output_relTarget.txt"); FileWriter
+ * fw = new FileWriter(wfile.getAbsoluteFile()); BufferedWriter bw =
+ * new BufferedWriter(fw); bw.write( "#column /t #layer /t
+ * #front_faceX /t #front_faceY /t #front_faceZ /t #back_faceX /t
+ * #back_faceY /t #back_faceZ \n" );
+ */
+ // translate the coordinate system to CM
+ for (int loop = 0; loop < Ncrys; loop++) {
+
+ //getting the EcalCrystalPosition object for a crystal
+ EcalCrystalPosition position = positions.get(loop);
+ int channelId = position.getChannelId();
+ //reading crystal layer(row)-Y and column-X from channels collection in database
+ layer[loop] = channels.findChannel(channelId).getY();
+ col[loop] = channels.findChannel(channelId).getX();
+ //reading crystal position from positions collection in database
+ frontXYZ[loop] = new GVector(position.getFrontX(), position.getFrontY(), position.getFrontZ());
+ backXYZ[loop] = new GVector(position.getBackX(), position.getBackY(), position.getBackZ());
+
+ if (this.module.compareToIgnoreCase("bottom") == 0 && layer[loop] > 0) {
// crystalMap.put(String.format("c%d:l%d", col[loop].intValue(), layer[loop].intValue()),
- // new Crystal(col[loop].intValue(), layer[loop].intValue(),
- // new Geant4Position(frontXYZ[loop], backXYZ[loop])));
- continue;
- } else if (this.module.compareToIgnoreCase("top") == 0 && layer[loop] < 0) {
- // crystalMap.put(String.format("c%d:l%d", col[loop].intValue(), layer[loop].intValue()),
- // new Crystal(col[loop].intValue(), layer[loop].intValue(),
- // new Geant4Position(frontXYZ[loop], backXYZ[loop])));
- continue;
+ // new Crystal(col[loop].intValue(), layer[loop].intValue(),
+ // new Geant4Position(frontXYZ[loop], backXYZ[loop])));
+ continue;
+ }
+ else if (this.module.compareToIgnoreCase("top") == 0 && layer[loop] < 0) {
+ // crystalMap.put(String.format("c%d:l%d", col[loop].intValue(), layer[loop].intValue()),
+ // new Crystal(col[loop].intValue(), layer[loop].intValue(),
+ // new Geant4Position(frontXYZ[loop], backXYZ[loop])));
+ continue;
+ }
+
+ LOGGER.info("Initial position are:");
+ LOGGER.info(frontXYZ[loop].toString());
+ LOGGER.info(backXYZ[loop].toString());
+
+ //setting the right vector to move to center mass system of a module
+ if (layer[loop] > 0) {
+ CMvec_nom = CMvec_nom_top;
+ }
+ else if (layer[loop] < 0) {
+ CMvec_nom = CMvec_nom_bot;
+ }
+
+ // translate by the vector = center of coordinate system, I mean
+ // where the ecal is.
+ frontXYZ[loop] = frontXYZ[loop].TranslateBy(CMvec_nom.getOpposite());
+ backXYZ[loop] = backXYZ[loop].TranslateBy(CMvec_nom.getOpposite());
+ // frontXYZ[loop] = frontXYZ[loop].TranslateBy(CMvec_nom);
+ // backXYZ[loop] = backXYZ[loop].TranslateBy(CMvec_nom);
+
+ LOGGER.info(CMvec_nom.toString());
+ LOGGER.info("after translation to CM COO-system");
+ //LOGGER.info(frontXYZ[loop].toString());
+ //LOGGER.info(backXYZ[loop].toString());
+
+ // / Rotate the modules by angle calc from suvey data
+ frontXYZ[loop] = frontXYZ[loop].RotateBy(this.rotation[0], this.rotation[1], this.rotation[2]);
+ backXYZ[loop] = backXYZ[loop].RotateBy(this.rotation[0], this.rotation[1], this.rotation[2]);
+
+ LOGGER.info("after module plane rotation");
+ //LOGGER.info(frontXYZ[loop].toString());
+ //LOGGER.info(backXYZ[loop].toString());
+
+ // Translate modules by the translation vector the diff of CM
+ frontXYZ[loop] = frontXYZ[loop].TranslateBy(transVec);
+ backXYZ[loop] = backXYZ[loop].TranslateBy(transVec);
+
+ LOGGER.info("after translation by survey shift");
+ //LOGGER.info(frontXYZ[loop].toString());
+ //LOGGER.info(backXYZ[loop].toString());
+
+ // / Translate back to initial coordinate system
+ frontXYZ[loop] = frontXYZ[loop].TranslateBy(CMvec_nom);
+ backXYZ[loop] = backXYZ[loop].TranslateBy(CMvec_nom);
+ LOGGER.info("after translation back to initial system");
+ //LOGGER.info(frontXYZ[loop].toString());
+ //LOGGER.info(backXYZ[loop].toString());
+
+ //uncomment if need to write things in a file
+ /*
+ * bw.write(String.valueOf(col[loop].intValue()) + "\t" +
+ * String.valueOf(layer[loop].intValue()) + "\t" +
+ * String.valueOf(frontXYZ[loop].x) + "\t" +
+ * String.valueOf(frontXYZ[loop].y) + "\t" +
+ * String.valueOf(frontXYZ[loop].z) + "\t" +
+ * String.valueOf(backXYZ[loop].x) + "\t" +
+ * String.valueOf(backXYZ[loop].y) + "\t" +
+ * String.valueOf(backXYZ[loop].z) + "\n");
+ */
+ if (frontXYZ[loop] == null || backXYZ[loop] == null) {
+ throw new RuntimeException("The vectors are 0? really? Should never ever happen, contact the author.");
+ }
+
+ //dfine the position as a geant4position object for a crystal
+ Geant4Position g4pos = new Geant4Position(frontXYZ[loop], backXYZ[loop]);
+
+ //put the crystal in the map with the corresponding key
+ crystalMap.put(String.format("c%d:l%d", col[loop], layer[loop]), new Crystal(col[loop], layer[loop], g4pos));
+ LOGGER.info(("icol = " + col[loop] + " ilay = " + layer[loop]));
+ LOGGER.info(g4pos.toString());
}
- frontXYZ[loop] = new Vector(Xfront[loop], Yfront[loop], Zfront[loop]);
- backXYZ[loop] = new Vector(Xback[loop], Yback[loop], Zback[loop]);
-
- System.out.println("Initial position");
- frontXYZ[loop].Print();
- backXYZ[loop].Print();
-
- if (layer[loop] > 0) {
- CMvec_nom = CMvec_nom_top;
- } else if (layer[loop] < 0) {
- CMvec_nom = CMvec_nom_bot;
- }
-
- // translate by the vector = center of coordinate system, I mean
- // where the ecal is.
- frontXYZ[loop] = frontXYZ[loop].TranslateBy(CMvec_nom.getOpposite());
- backXYZ[loop] = backXYZ[loop].TranslateBy(CMvec_nom.getOpposite());
- // frontXYZ[loop] = frontXYZ[loop].TranslateBy(CMvec_nom);
- // backXYZ[loop] = backXYZ[loop].TranslateBy(CMvec_nom);
-
- CMvec_nom.Print();
- System.out.println("after translation to CM COO-system");
- // frontXYZ[loop].Print();
- // backXYZ[loop].Print();
-
- // / Rotate the modules by angle calc from suvey data
- frontXYZ[loop] = frontXYZ[loop].RotateBy(this.rotation[0], this.rotation[1], this.rotation[2]);
- backXYZ[loop] = backXYZ[loop].RotateBy(this.rotation[0], this.rotation[1], this.rotation[2]);
-
- System.out.println("after module plane rotation");
- // frontXYZ[loop].Print();
- // backXYZ[loop].Print();
-
- // Translate modules by the translation vector the diff of CM
- frontXYZ[loop] = frontXYZ[loop].TranslateBy(transVec);
- backXYZ[loop] = backXYZ[loop].TranslateBy(transVec);
-
- System.out.println("after translation by survey shift");
- // frontXYZ[loop].Print();
- // backXYZ[loop].Print();
-
- // / Translate back to initial coordinate system
- frontXYZ[loop] = frontXYZ[loop].TranslateBy(CMvec_nom);
- backXYZ[loop] = backXYZ[loop].TranslateBy(CMvec_nom);
- System.out.println("after translation back to initial system");
- frontXYZ[loop].Print();
- backXYZ[loop].Print();
-
- /*
- * bw.write(String.valueOf(col[loop].intValue()) + "\t" + String.valueOf(layer[loop].intValue()) + "\t" +
- * String.valueOf(frontXYZ[loop].x) + "\t" + String.valueOf(frontXYZ[loop].y) + "\t" +
- * String.valueOf(frontXYZ[loop].z) + "\t" + String.valueOf(backXYZ[loop].x) + "\t" +
- * String.valueOf(backXYZ[loop].y) + "\t" + String.valueOf(backXYZ[loop].z) + "\n");
- */
-
- if (frontXYZ[loop] == null || backXYZ[loop] == null)
- System.err.println("The vectors are 0? really? Should never happen");
-
- Geant4Position g4pos = new Geant4Position(frontXYZ[loop], backXYZ[loop]);
-
- crystalMap.put(String.format("c%d:l%d", col[loop].intValue(), layer[loop].intValue()), new Crystal(
- col[loop].intValue(), layer[loop].intValue(), g4pos));
- System.out.println("icol = " + col[loop].intValue() + " ilay = " + layer[loop].intValue());
- g4pos.Print();
- }
- System.err.println("Number of map content Transformations " + crystalMap.size());
-
+ LOGGER.info(("Number of crystal map content after transformations in the "+this.module+" module = " + crystalMap.size()));
+ }
+ catch (RuntimeException e) {
+ e.printStackTrace(new PrintStream("Database manager object was not initialized properly or required data were not cached."));
+ }
}
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/CenterMass.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/CenterMass.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/CenterMass.java Wed May 4 16:15:15 2016
@@ -5,10 +5,10 @@
package org.hps.detector.ecal.geo2015.geoutils;
/**
- * The Class is implemented to calculate not fairly called "center mass" Defined as a Point with a coordinates as
- * arithmetical mean of the corresponding coordinates of points-arguments
+ * The Class is implemented to calculate not fairly called "center mass" of a system from geometrical points
+ * Center mass here is defined as a Point with a coordinates = arithmetical mean of the corresponding coordinates of points-arguments
*
- * @author AS
+ * @author Annie Simonyan [log in to unmask]
*/
public class CenterMass {
@@ -19,9 +19,9 @@
}
/*
- * Meaningful constructor :D with Vectors as argument for 4 points only
+ * Meaningful constructor, with Vvectors as argument for 4 points only
*/
- public CenterMass(Vector pointA, Vector pointB, Vector pointC, Vector pointD) {
+ public CenterMass(GVector pointA, GVector pointB, GVector pointC, GVector pointD) {
xc = (pointA.x + pointB.x + pointC.x + pointD.x) / 4;
yc = (pointA.y + pointB.y + pointC.y + pointD.y) / 4;
@@ -45,24 +45,32 @@
zc = zc / N;
}
- private double xc = 0., yc = 0., zc = 0.;
+ private double xc = 0., yc = 0., zc = 0.; //coordinates of center mass
+ //returns X coordinate of center mass
public double getCMx() {
return xc;
}
+
+ //returns Y coordinate of center mass
public double getCMy() {
return yc;
}
+
+ //reutrns Z coordinate of center mass
public double getCMz() {
return zc;
}
- public Vector getCMvector() {
- return (new Vector(xc, yc, zc));
+ //returns (X,Y,Z) coordinates of center mass as a Vvector object
+ public GVector getCMvector() {
+ return (new GVector(xc, yc, zc));
}
+
+ //returns (X,Y,Z) coordinates of center mass as an array of doubles
public double[] getCMarray() {
double[] center = {this.xc, this.yc, this.zc};
return center;
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/GVector.java (from r4349, java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Vector.java)
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Vector.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/GVector.java Wed May 4 16:15:15 2016
@@ -1,33 +1,40 @@
-/*
- * To change this license header, choose License Headers in Project Properties. To change this template file, choose
- * Tools | Templates and open the template in the editor.
- */
-
package org.hps.detector.ecal.geo2015.geoutils;
+import hep.physics.vec.BasicHep3Vector;
import org.hps.detector.ecal.geo2015.base.StatFunUtils;
+
/**
- * Define Vector in a 3D coordinate system operations and manipulations with the characteristics of the line
+ * To define a vector in (XYZ) coordinate system as a geometrical object,
+ * define operations, manipulations with the vectors
+ * This class is similar to HepVector
*
- * @author AS
+ * @author Annie Simonyan [log in to unmask]
*/
-public class Vector {
+public class GVector {
public double x = 0, y = 0, z = 0;
private double[] vec;
- public Vector() {
+ //default constructor
+ public GVector() {
}
- public Vector(double[] array) {
+ //constructor: argument - double[3]={x,y,z} array for vector coordinates
+ public GVector(double[] array) {
vec = array;
this.x = array[0];
this.y = array[1];
this.z = array[2];
}
- public Vector(double x, double y, double z) {
+ //converts this Vvector to BasicHep3Vector
+ public BasicHep3Vector getHepVector(){
+ return new BasicHep3Vector(this.x, this.y, this.z);
+ }
+
+ //constructor: arguments - double(x,y,z) coordinates of vector
+ public GVector(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
@@ -38,63 +45,80 @@
}
+ //set vector x coordinate
public void SetX(double x) {
this.x = x;
}
+ //set vector y coordinate
public void SetY(double y) {
this.y = y;
}
+
+ //set vector z coordinate
public void SetZ(double z) {
this.z = z;
}
+ //set vector (x,y,z) coordinates
public void SetXYZ(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
+ //check if the vector is unit vector
public boolean isUnitary() {
return (Double.compare(StatFunUtils.round(this.Module(), 12), 1.0) == 0);
}
- // /Vector Module
+ //returns the module of the vector
public double Module() {
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
}
- public Vector Multiply(double k) {
+ //vector multiplication by cooficent k
+ public GVector Multiply(double k) {
- return (new Vector(k * this.x, k * this.y, k * this.z));
+ return (new GVector(k * this.x, k * this.y, k * this.z));
}
- public Vector Add(Vector vec2) {
+ //returns new vector = sum of this vector and argument vec2
+ public GVector Add(GVector vec2) {
- return (new Vector(this.x + vec2.x, this.y + vec2.y, this.z + vec2.z));
+ return (new GVector(this.x + vec2.x, this.y + vec2.y, this.z + vec2.z));
}
- public Vector getOpposite() {
- return (new Vector(-this.x, -this.y, -this.z));
+ //returns new vector opposite to this vector
+ public GVector getOpposite() {
+ return (new GVector(-this.x, -this.y, -this.z));
}
- public Vector Substract(Vector vec2) {
+ //returns new vector = this vector - argument vector
+ public GVector Substract(GVector vec2) {
- return (new Vector(this.x - vec2.x, this.y - vec2.y, this.z - vec2.z));
+ return (new GVector(this.x - vec2.x, this.y - vec2.y, this.z - vec2.z));
}
- public Vector TranslateBy(Vector trvec) {
+ //returns new vector defined as translation of this vector by argument vector
+ public GVector TranslateBy(GVector trvec) {
// return this.Substract(trvec);
return this.Add(trvec);
}
/*
- * Rotation as Rz-alpha Ry-beta Rx-gamma
+ * Returns new vector = this vector rotated by (alpha, betta, gamma) rotation
+ * (Rz-alpha,Ry-beta,Rx-gamma)
+ *
+ * Vector rotation defined as:
+ * alpha-rotation around Z axis
+ * beta-rotation around Y axis
+ * gamma-rotation around X axis
*/
- public Vector RotateBy(double alpha, double betta, double gamma) {
+ public GVector RotateBy(double alpha, double betta, double gamma) {
double cos_alpha = Math.cos(alpha);
double sin_alpha = Math.sin(alpha);
@@ -115,16 +139,16 @@
double zz = this.x * (-sin_betta) + this.y * (cos_betta * sin_gamma) + this.z * (cos_betta * cos_gamma);
- return (new Vector(xx, yy, zz));
+ return (new GVector(xx, yy, zz));
}
- // Scaliar multiplication of vectors
- public double ScaliarM(Vector vec2) {
+ // returns scaliar multiplication of vectors
+ public double ScaliarM(GVector vec2) {
return this.x * vec2.x + this.y * vec2.y + this.z * vec2.z;
}
- // angle between vectors
- public double Angle(Vector vec2) {
+ //returns angle between vectors in rad
+ public double Angle(GVector vec2) {
// System.out.print("Scaliar= "+this.ScaliarM(vec2) +" modN1 = "+this.Module()+" modN2 = "+vec2.Module()+"\n");
// System.out.print(this.ScaliarM(vec2)/(this.Module()*vec2.Module())+ "\n");
// System.out.println(Math.acos(this.ScaliarM(vec2)/(this.Module()*vec2.Module())));
@@ -139,20 +163,30 @@
return Math.acos(cosAlpha);
}
+ //returns coordinates of this vector as an array of doubles
public double[] getVector() {
return this.vec;
}
- public Vector getUnitVector() {
- return new Vector(this.x / this.Module(), this.y / this.Module(), this.z / this.Module());
+ //returns new vector, which is unit vector of this vector
+ public GVector getUnitVector() {
+ return new GVector(this.x / this.Module(), this.y / this.Module(), this.z / this.Module());
}
- public Vector getCenter() {
+
+ //returns the center coordinates of this vector as a Vvector object
+ public GVector getCenter() {
return (this.Multiply(0.5));
}
+ //Print the coordinates of the Vector as (x,y,z)
public void Print() {
System.out.println("(" + this.x + ", " + this.y + ", " + this.z + ")");
}
+
+ //returns coordinates of the vector as a String "(x,y,z)"
+ public String toString(){
+ return ("(" + this.x + ", " + this.y + ", " + this.z + ")");
+ }
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Line.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Line.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Line.java Wed May 4 16:15:15 2016
@@ -6,17 +6,17 @@
package org.hps.detector.ecal.geo2015.geoutils;
/**
- * @author AS
+ * @author Annie Simonyan
*/
public class Line {
// private double a=0, b=0, c=0; //ax+by+c=0
- private Vector vec_n; // napravlyayushiy vector
+ private GVector vec_n; // napravlyayushiy vector
private double[] point;
// Define a line with a vector and a point it goes through
- public Line(Vector vec, double x, double y, double z) {
- this.setVec_n(new Vector(vec.x, vec.y, vec.z));
+ public Line(GVector vec, double x, double y, double z) {
+ this.setVec_n(new GVector(vec.x, vec.y, vec.z));
point = new double[3];
point[0] = x;
point[1] = y;
@@ -24,21 +24,21 @@
}
// Define a line that goes through 2 points, M0 and M1
- public Line(Vector vecM0, Vector vecM1) {
+ public Line(GVector vecM0, GVector vecM1) {
setVec_n(vecM1.Substract(vecM0));
point = vecM0.getVector();
}
- public Vector getCenter(Vector vecM0, Vector vecM1) {
+ public GVector getCenter(GVector vecM0, GVector vecM1) {
return (vecM1.Substract(vecM0)).Multiply(0.5);
}
- public Vector getVec_n() {
+ public GVector getVec_n() {
return vec_n;
}
- public void setVec_n(Vector vec_n) {
+ public void setVec_n(GVector vec_n) {
this.vec_n = vec_n;
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Plane.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Plane.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/Plane.java Wed May 4 16:15:15 2016
@@ -1,6 +1,8 @@
/*
* Supposed to calculate plane equation for any 3 points not in one line I will not check this, so please take care the
* shape is Ax+By+Cy+D=0 Get the ABCD constants as array or whatever.
+ *
+ * @author Annie Simonyan
*/
package org.hps.detector.ecal.geo2015.geoutils;
@@ -11,7 +13,7 @@
// Plane full equation constants
private double A, B, C, D;
- private Vector normal = new Vector();
+ private GVector normal = new GVector();
// Plane as a ranges on XYZ axises
private double a = 0., b = 0., c = 0.;
@@ -42,9 +44,9 @@
normal.SetXYZ(A, B, C);
}
- public Vector getNormalUnitVector() {
+ public GVector getNormalUnitVector() {
double mod = normal.Module();
- Vector uNorm = new Vector(normal.x / mod, normal.y / mod, normal.z / mod);
+ GVector uNorm = new GVector(normal.x / mod, normal.y / mod, normal.z / mod);
return uNorm;
}
@@ -78,7 +80,7 @@
return K;
}
- public Vector getNormal() {
+ public GVector getNormal() {
return this.normal;
}
@@ -94,14 +96,14 @@
}
public double getAngle(Plane pl2) {
- Vector normal2 = pl2.getNormal();
+ GVector normal2 = pl2.getNormal();
double angle = this.normal.Angle(normal2);
return Math.PI / 2 - angle;
}
public double getEffAngle(Plane pl2) {
- Vector normal2 = pl2.getNormal();
+ GVector normal2 = pl2.getNormal();
double angle = this.normal.Angle(normal2);
if (angle > (Math.PI / 2.0))
angle = Math.PI - angle;
@@ -169,4 +171,12 @@
public void PrintGeoRanges() {
System.out.print("X/(" + this.a + ") + Y/(" + this.b + ") + Z/(" + this.c + ") =1\n");
}
+
+ public String toString(){
+ return (this.A + "x + " + "(" + (this.B) + ")" + "y + " + " (" + this.C + ")" + "z + " + "(" + this.D
+ + ")" + "= 0\n");
+ }
+ public String toStringGeoRanges(){
+ return ("X/(" + this.a + ") + Y/(" + this.b + ") + Z/(" + this.c + ") =1\n");
+ }
}
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/lcsim/detector/converter/compact/HPSEcal4Converter.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/lcsim/detector/converter/compact/HPSEcal4Converter.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/lcsim/detector/converter/compact/HPSEcal4Converter.java Wed May 4 16:15:15 2016
@@ -1,6 +1,7 @@
package org.lcsim.detector.converter.compact;
import java.util.Map;
+import java.util.logging.Level;
import java.util.logging.Logger;
import org.hps.detector.ecal.geo2015.crystal.Crystal;
@@ -10,6 +11,7 @@
import org.hps.detector.ecal.HPSEcalDetectorElement;
import org.jdom.DataConversionException;
import org.jdom.Element;
+import org.lcsim.conditions.ConditionsManager;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.ILogicalVolume;
import org.lcsim.detector.IPhysicalVolume;
@@ -31,6 +33,14 @@
import org.lcsim.geometry.compact.Subdetector;
import org.lcsim.geometry.subdetector.HPSEcal4;
+/*
+ * For class description contact Jeremy
+ * For implementatoin details contact Annie
+ *
+ * @author Annie Simonyan ([log in to unmask]), Jeremy McCormick ([log in to unmask])
+ */
+
+
public class HPSEcal4Converter extends AbstractSubdetectorConverter {
private static Logger LOGGER = Logger.getLogger(HPSEcal4Converter.class.getPackage().getName());
@@ -46,150 +56,127 @@
@Override
public void convert(final Subdetector subdet, final Detector detector) {
- LOGGER.info("converting subdetector " + subdet.getName());
-
- helper = subdet.getDetectorElement().getIdentifierHelper();
- dict = helper.getIdentifierDictionary();
-
- // Crystal dimensions.
- final Element dimensions = subdet.getNode().getChild("dimensions");
-
- double dx1, dx2, dy1, dy2, dz;
- Element layout;
- int nx, ny;
- double dface;
-
- // initial definitions for translation and rotation parameters
- double tr_top[] = {-100, -100, -100};
- double tr_bot[] = {-100, -100, -100};
- double rot_top[] = {-100, -100, -100};
- double rot_bot[] = {-100, -100, -100};
-
try {
- dx1 = dimensions.getAttribute("x1").getDoubleValue();
- dx2 = dimensions.getAttribute("x2").getDoubleValue();
- dy1 = dimensions.getAttribute("y1").getDoubleValue();
- dy2 = dimensions.getAttribute("y2").getDoubleValue();
- dz = dimensions.getAttribute("z").getDoubleValue();
-
- Element tra = subdet.getNode().getChild("translations");
-
- tr_top[0] = tra.getAttribute("top_tr_x").getDoubleValue();
- tr_top[1] = tra.getAttribute("top_tr_y").getDoubleValue();
- tr_top[2] = tra.getAttribute("top_tr_z").getDoubleValue();
-
- tr_bot[0] = tra.getAttribute("bot_tr_x").getDoubleValue();
- tr_bot[1] = tra.getAttribute("bot_tr_y").getDoubleValue();
- tr_bot[2] = tra.getAttribute("bot_tr_z").getDoubleValue();
-
- Element rota = subdet.getNode().getChild("rotations");
-
- rot_top[0] = rota.getAttribute("top_rot_alpha").getDoubleValue();
- rot_top[1] = rota.getAttribute("top_rot_beta").getDoubleValue();
- rot_top[2] = rota.getAttribute("top_rot_gamma").getDoubleValue();
-
- rot_bot[0] = rota.getAttribute("bot_rot_alpha").getDoubleValue();
- rot_bot[1] = rota.getAttribute("bot_rot_beta").getDoubleValue();
- rot_bot[2] = rota.getAttribute("bot_rot_gamma").getDoubleValue();
-
- layout = subdet.getNode().getChild("layout");
- nx = layout.getAttribute("nx").getIntValue();
- ny = layout.getAttribute("ny").getIntValue();
- dface = layout.getAttribute("dface").getDoubleValue();
-
- } catch (final DataConversionException e) {
- throw new RuntimeException("Error converting HPSEcal4 from XML.", e);
+
+ LOGGER.info(("converting subdetector " + subdet.getName()));
+ helper = subdet.getDetectorElement().getIdentifierHelper();
+ dict = helper.getIdentifierDictionary();
+ final Element dimensions = subdet.getNode().getChild("dimensions");
+ double dx1, dx2, dy1, dy2, dz;
+ Element layout;
+ double tr_top[] = {-100, -100, -100};
+ double tr_bot[] = {-100, -100, -100};
+ double rot_top[] = {-100, -100, -100};
+ double rot_bot[] = {-100, -100, -100};
+ try {
+ dx1 = dimensions.getAttribute("x1").getDoubleValue();
+ dx2 = dimensions.getAttribute("x2").getDoubleValue();
+ dy1 = dimensions.getAttribute("y1").getDoubleValue();
+ dy2 = dimensions.getAttribute("y2").getDoubleValue();
+ dz = dimensions.getAttribute("z").getDoubleValue();
+
+ Element tra = subdet.getNode().getChild("translations");
+
+ tr_top[0] = tra.getAttribute("top_tr_x").getDoubleValue();
+ tr_top[1] = tra.getAttribute("top_tr_y").getDoubleValue();
+ tr_top[2] = tra.getAttribute("top_tr_z").getDoubleValue();
+
+ tr_bot[0] = tra.getAttribute("bot_tr_x").getDoubleValue();
+ tr_bot[1] = tra.getAttribute("bot_tr_y").getDoubleValue();
+ tr_bot[2] = tra.getAttribute("bot_tr_z").getDoubleValue();
+
+ Element rota = subdet.getNode().getChild("rotations");
+
+ rot_top[0] = rota.getAttribute("top_rot_alpha").getDoubleValue();
+ rot_top[1] = rota.getAttribute("top_rot_beta").getDoubleValue();
+ rot_top[2] = rota.getAttribute("top_rot_gamma").getDoubleValue();
+
+ rot_bot[0] = rota.getAttribute("bot_rot_alpha").getDoubleValue();
+ rot_bot[1] = rota.getAttribute("bot_rot_beta").getDoubleValue();
+ rot_bot[2] = rota.getAttribute("bot_rot_gamma").getDoubleValue();
+
+ layout = subdet.getNode().getChild("layout");
+
+ } catch (final DataConversionException e) {
+ throw new RuntimeException("Error converting HPSEcal4 from XML.", e);
+ }
+ final Element mat = subdet.getNode().getChild("material");
+ final String materialName = mat.getAttributeValue("name");
+ final Trd crystalTrap = new Trd("crystal_trap", dx1, dx2, dy1, dy2, dz);
+ final ILogicalVolume crystalLogVol = new LogicalVolume("crystal_volume", crystalTrap, MaterialStore
+ .getInstance().get(materialName));
+ Transformations trans_top = new Transformations("top", tr_top, rot_top);
+ Map<String, Crystal> topMap = trans_top.getCrystalMap();
+ Transformations trans_bot = new Transformations("bottom", tr_bot, rot_bot);
+ Map<String, Crystal> botMap = trans_bot.getCrystalMap();
+ LOGGER.info(("Number of crystal map content for bottom module " + botMap.size()));
+ LOGGER.info(("Number of crystal map content for top module " + topMap.size()));
+ final String baseName = subdet.getName() + "_crystal";
+ final ILogicalVolume mom = detector.getWorldVolume().getLogicalVolume();
+ int crystaln = 1;
+ for (int iy = -5; iy <= 5; iy++) {
+ if (iy == 0)
+ continue;
+
+ // loop over columns
+ for (int ix = -23; ix <= 23; ix++) {
+ if (ix == 0) {
+ continue;
+ }
+
+ // z axis rotation parameter of the whole module
+ double zrot_cry = rot_bot[0];
+
+ Crystal crystal = botMap.get(String.format("c%d:l%d", ix, iy));
+
+ if (iy > 0) {
+ crystal = topMap.get(String.format("c%d:l%d", ix, iy));
+ // z axis rotation parameter of the whole module
+ zrot_cry = rot_top[0];
+ }
+
+ if (crystal == null)
+ //skip the ecal gap
+ if ((iy == -1 && ix > -11 && ix < -1) || (iy == 1 && ix > -11 && ix < -1))
+ continue;
+ else
+ throw new NullPointerException(iy + " " + ix
+ + " crystal is null, the map is screwed, the compiler really feels sorry for you.");
+
+ if (crystal.getCrystalG4Pos() == null)
+ throw new NullPointerException("g4pos of crystal is null, the map is screwed, sorry\n");
+
+ //double[] centerxyz = {0, 0, 0};
+ //double[] thetaxyz = {0, 0, 0};
+
+ double[] centerxyz = crystal.getCrystalG4Pos().getCenterArr();
+ double[] thetaxyz = crystal.getCrystalG4Pos().getTaitBryanAngles();
+
+
+ final ITranslation3D iposBot = new Translation3D(centerxyz[0], centerxyz[1], centerxyz[2]);
+ final IRotation3D irotBot = new RotationGeant(thetaxyz[0], thetaxyz[1], thetaxyz[2] - zrot_cry); // thetaxyz[2]-zrot_cry=
+ // the
+ // compound
+ // rotation
+ // for
+ // the
+ // Psie
+ // final IRotation3D irotBot = new RotationGeant(thetaxyz[0], thetaxyz[1], thetaxyz[2]+zrot_cry); //
+ // thetaxyz[2]+zrot_cry= the compound rotation for the Psie
+
+ // Place the crystal.
+ final IPhysicalVolume CrystalPlacement = new PhysicalVolume(new Transform3D(iposBot, irotBot), baseName
+ + crystaln, crystalLogVol, mom, crystaln);
+ this.createDetectorElement(detector, subdet, CrystalPlacement, ix, iy);
+ crystaln++;
+
+ }
+ }
+ LOGGER.info(("In HPSEcal4Converter crystal in top module:" + topMap.size()
+ + " crystals in bottom module: " + botMap.size()));
+ } catch (ConditionsManager.ConditionsNotFoundException ex) {
+ Logger.getLogger(HPSEcal4Converter.class.getName()).log(Level.SEVERE, null, ex);
}
-
- // Crystal material.
- final Element mat = subdet.getNode().getChild("material");
- final String materialName = mat.getAttributeValue("name");
-
- // Setup crystal logical volume.
- final Trd crystalTrap = new Trd("crystal_trap", dx1, dx2, dy1, dy2, dz);
- final ILogicalVolume crystalLogVol = new LogicalVolume("crystal_volume", crystalTrap, MaterialStore
- .getInstance().get(materialName));
-
- //
- // Translate and rotate the modules by the rotation and translation vectors
- // defined in compact.xml file, or by default?
- // it's not really clear what you dear hps user want
- //
- Transformations trans_top = new Transformations("top", tr_top, rot_top);
- Map<String, Crystal> topMap = trans_top.getCrystalMap();
- Transformations trans_bot = new Transformations("bottom", tr_bot, rot_bot);
- Map<String, Crystal> botMap = trans_bot.getCrystalMap();
- System.err.println("Number of map content " + botMap.size());
- System.err.println("Number of map content " + topMap.size());
-
- // Base name for volume.
- final String baseName = subdet.getName() + "_crystal";
-
- // World volume.
- final ILogicalVolume mom = detector.getWorldVolume().getLogicalVolume();
- // crystal counter
- int crystaln = 1;
-
- // loop over layers
- for (int iy = -5; iy <= 5; iy++) {
- if (iy == 0)
- continue;
-
- // loop over columns
- for (int ix = -23; ix <= 23; ix++) {
- if (ix == 0) {
- continue;
- }
-
- // z axis rotation parameter of the whole module
- double zrot_cry = rot_bot[0];
-
- Crystal crystal = botMap.get(String.format("c%d:l%d", ix, iy));
-
- if (iy > 0) {
- crystal = topMap.get(String.format("c%d:l%d", ix, iy));
- // z axis rotation parameter of the whole module
- zrot_cry = rot_top[0];
- }
-
- if (crystal == null)
- if ((iy == -1 && ix > -11 && ix < -1) || (iy == 1 && ix > -11 && ix < -1))
- continue;
- else
- System.err.println(iy + " " + ix
- + " crystal is null, the map is screwed, the compiler really feels sorry for you.");
-
- if (crystal.getCrystalG4Pos() == null)
- System.err.print("g4pos of crystal is null, the map is screwed, sorry\n");
-
- double[] centerxyz = {0, 0, 0};
- double[] thetaxyz = {0, 0, 0};
- if (crystal != null) {
- centerxyz = crystal.getCrystalG4Pos().getCenterArr();
- thetaxyz = crystal.getCrystalG4Pos().getTaitBryanAngles();
- }
-
- final ITranslation3D iposBot = new Translation3D(centerxyz[0], centerxyz[1], centerxyz[2]);
- final IRotation3D irotBot = new RotationGeant(thetaxyz[0], thetaxyz[1], thetaxyz[2] - zrot_cry); // thetaxyz[2]-zrot_cry=
- // the
- // compound
- // rotation
- // for
- // the
- // Psie
- // final IRotation3D irotBot = new RotationGeant(thetaxyz[0], thetaxyz[1], thetaxyz[2]+zrot_cry); //
- // thetaxyz[2]+zrot_cry= the compound rotation for the Psie
-
- // Place the crystal.
- final IPhysicalVolume CrystalPlacement = new PhysicalVolume(new Transform3D(iposBot, irotBot), baseName
- + crystaln, crystalLogVol, mom, crystaln);
- this.createDetectorElement(detector, subdet, CrystalPlacement, ix, iy);
- crystaln++;
-
- }
- }
- System.err.println("In HPSEcal4Converter crystal in top module:" + topMap.size()
- + " crystals in bottom module: " + botMap.size());
}
/**
Modified: java/branches/HPSJAVA-409/detector-model/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSEcal4.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSEcal4.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSEcal4.java Wed May 4 16:15:15 2016
@@ -1,11 +1,15 @@
package org.lcsim.geometry.compact.converter.lcdd;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.hps.detector.ecal.geo2015.crystal.Crystal;
import org.hps.detector.ecal.geo2015.ecal.Transformations;
import org.jdom.Element;
import org.jdom.JDOMException;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.converter.compact.HPSEcal4Converter;
import org.lcsim.geometry.compact.converter.lcdd.util.Define;
import org.lcsim.geometry.compact.converter.lcdd.util.LCDD;
@@ -16,174 +20,130 @@
import org.lcsim.geometry.compact.converter.lcdd.util.Trapezoid;
import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
+
+/*
+ * For class description contact Jeremy
+ * For implementatoin details contact Annie
+ *
+ * @author Annie Simonyan ([log in to unmask]), Jeremy McCormick ([log in to unmask])
+ */
+
public class HPSEcal4 extends LCDDSubdetector {
-
+ private static Logger LOGGER = Logger.getLogger(HPSEcal4Converter.class.getPackage().getName());
HPSEcal4(Element node) throws JDOMException {
super(node);
}
void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException {
- if (sens == null)
- throw new RuntimeException("SensitiveDetector parameter points to null.");
-
- // Crystal dimensions.
- Element dimensions = node.getChild("dimensions");
- double dx1 = dimensions.getAttribute("x1").getDoubleValue();
- double dx2 = dimensions.getAttribute("x2").getDoubleValue();
- double dy1 = dimensions.getAttribute("y1").getDoubleValue();
- double dy2 = dimensions.getAttribute("y2").getDoubleValue();
- double dz = dimensions.getAttribute("z").getDoubleValue();
-
- int system = this.getSystemID();
-
- // Crystal material.
- Element mat = node.getChild("material");
- String materialName = mat.getAttributeValue("name");
-
- Element tra = node.getChild("translations");
- double tr_top[] = {-100, -100, -100};
- tr_top[0] = tra.getAttribute("top_tr_x").getDoubleValue();
- tr_top[1] = tra.getAttribute("top_tr_y").getDoubleValue();
- tr_top[2] = tra.getAttribute("top_tr_z").getDoubleValue();
- double tr_bot[] = {-100, -100, -100};
- tr_bot[0] = tra.getAttribute("bot_tr_x").getDoubleValue();
- tr_bot[1] = tra.getAttribute("bot_tr_y").getDoubleValue();
- tr_bot[2] = tra.getAttribute("bot_tr_z").getDoubleValue();
-
- Element rota = node.getChild("rotations");
- double rot_top[] = {-100, -100, -100};
- rot_top[0] = rota.getAttribute("top_rot_alpha").getDoubleValue();
- rot_top[1] = rota.getAttribute("top_rot_beta").getDoubleValue();
- rot_top[2] = rota.getAttribute("top_rot_gamma").getDoubleValue();
- double rot_bot[] = {-100, -100, -100};
- rot_bot[0] = rota.getAttribute("bot_rot_alpha").getDoubleValue();
- rot_bot[1] = rota.getAttribute("bot_rot_beta").getDoubleValue();
- rot_bot[2] = rota.getAttribute("bot_rot_gamma").getDoubleValue();
-
- // Layout parameters.
- Element layout = node.getChild("layout");
- double beamgap = 0;
- if (layout.getAttribute("beamgap") != null) {
- beamgap = layout.getAttribute("beamgap").getDoubleValue();
- } else {
- if (layout.getAttribute("beamgapTop") == null || layout.getAttribute("beamgapBottom") == null) {
- throw new RuntimeException(
- "Missing beamgap parameter in layout element, and beamgapTop or beamgapBottom was not provided.");
+ try {
+ if (sens == null)
+ throw new RuntimeException("SensitiveDetector parameter points to null.");
+ Element dimensions = node.getChild("dimensions");
+ double dx1 = dimensions.getAttribute("x1").getDoubleValue();
+ double dx2 = dimensions.getAttribute("x2").getDoubleValue();
+ double dy1 = dimensions.getAttribute("y1").getDoubleValue();
+ double dy2 = dimensions.getAttribute("y2").getDoubleValue();
+ double dz = dimensions.getAttribute("z").getDoubleValue();
+ int system = this.getSystemID();
+ Element mat = node.getChild("material");
+ String materialName = mat.getAttributeValue("name");
+ Element tra = node.getChild("translations");
+ double tr_top[] = {-100, -100, -100};
+ tr_top[0] = tra.getAttribute("top_tr_x").getDoubleValue();
+ tr_top[1] = tra.getAttribute("top_tr_y").getDoubleValue();
+ tr_top[2] = tra.getAttribute("top_tr_z").getDoubleValue();
+ double tr_bot[] = {-100, -100, -100};
+ tr_bot[0] = tra.getAttribute("bot_tr_x").getDoubleValue();
+ tr_bot[1] = tra.getAttribute("bot_tr_y").getDoubleValue();
+ tr_bot[2] = tra.getAttribute("bot_tr_z").getDoubleValue();
+ Element rota = node.getChild("rotations");
+ double rot_top[] = {-100, -100, -100};
+ rot_top[0] = rota.getAttribute("top_rot_alpha").getDoubleValue();
+ rot_top[1] = rota.getAttribute("top_rot_beta").getDoubleValue();
+ rot_top[2] = rota.getAttribute("top_rot_gamma").getDoubleValue();
+ double rot_bot[] = {-100, -100, -100};
+ rot_bot[0] = rota.getAttribute("bot_rot_alpha").getDoubleValue();
+ rot_bot[1] = rota.getAttribute("bot_rot_beta").getDoubleValue();
+ rot_bot[2] = rota.getAttribute("bot_rot_gamma").getDoubleValue();
+ Element layout = node.getChild("layout");
+ double beamgap = 0;
+ if (layout.getAttribute("beamgap") != null) {
+ beamgap = layout.getAttribute("beamgap").getDoubleValue();
+ } else {
+ if (layout.getAttribute("beamgapTop") == null || layout.getAttribute("beamgapBottom") == null) {
+ throw new RuntimeException(
+ "Missing beamgap parameter in layout element, and beamgapTop or beamgapBottom was not provided.");
+ }
}
- }
-
- int nx = layout.getAttribute("nx").getIntValue();
- int ny = layout.getAttribute("ny").getIntValue();
- double dface = layout.getAttribute("dface").getDoubleValue();
-
- // Setup crystal logical volume.
- // dy1=dx1=1.00; dy2=dx2=20.00; dz=50;
- Trapezoid crystalTrap = new Trapezoid("crystal_trap", dx1, dx2, dy1, dy2, dz);
- Volume crystalLogVol = new Volume("crystal_volume", crystalTrap, lcdd.getMaterial(materialName));
- crystalLogVol.setSensitiveDetector(sens);
-
- // Set vis attributes on crystal log vol.
- setVisAttributes(lcdd, this.getNode(), crystalLogVol);
-
- // Add shape and log vol to lcdd.
- lcdd.add(crystalTrap);
- lcdd.add(crystalLogVol);
-
- // Place crystals in world volume.
- Volume world = lcdd.pickMotherVolume(this);
-
- //
- // defines the constant from compact.xml, may be
- //
-
- Define define = lcdd.getDefine();
-
- //
- // Defining the translation and the rotation of top and bottom based on
- // Survey Aug2015
- //
-
- double[] top_tr = {0, 0, 0};
- double[] top_rot = {0, 0, 0};
- double[] bot_tr = {0, 0, 0};
- double[] bot_rot = {0, 0, 0};
-
- /*
- * double[] top_tr = { -0.710000000000008, 2.7249999999999943, 4.9375 }; double[] top_rot = {
- * 6.496421277200071E-4, 0.0, -4.688234741242468E-4 }; double[] bot_tr = { -0.4049999999999727,
- * -0.9124999999999659, 2.6224999999999454 }; double[] bot_rot = { 5.150274940439736E-4, 0.0,
- * 0.0013469727279283583 };
- */
-
- /*
- * double[] top_tr = {100, 0, 0 }; double[] top_rot = { Math.toRadians(-20),0,0}; double[] bot_tr = { 0,0,0 };
- * double[] bot_rot = { 0,0,0 };
- */
-
- // I had my reasons to do so, will change in the end
- top_rot = rot_top;
- top_tr = tr_top;
- bot_rot = rot_bot;
- bot_tr = tr_bot;
-
- Transformations trans_top = new Transformations("top", top_tr, top_rot);
- Map<String, Crystal> topMap = trans_top.getCrystalMap();
- Transformations trans_bot = new Transformations("bottom", bot_tr, bot_rot);
- Map<String, Crystal> botMap = trans_bot.getCrystalMap();
- System.err.println("Number of map content " + botMap.size());
- System.err.println("Number of map content " + topMap.size());
-
- for (int iy = -5; iy <= 5; iy++) {
- if (iy == 0)
- continue;
- for (int ix = -23; ix <= 23; ix++) {
- if (ix == 0) {
+ int nx = layout.getAttribute("nx").getIntValue();
+ int ny = layout.getAttribute("ny").getIntValue();
+ double dface = layout.getAttribute("dface").getDoubleValue();
+ Trapezoid crystalTrap = new Trapezoid("crystal_trap", dx1, dx2, dy1, dy2, dz);
+ Volume crystalLogVol = new Volume("crystal_volume", crystalTrap, lcdd.getMaterial(materialName));
+ crystalLogVol.setSensitiveDetector(sens);
+ setVisAttributes(lcdd, this.getNode(), crystalLogVol);
+ lcdd.add(crystalTrap);
+ lcdd.add(crystalLogVol);
+ Volume world = lcdd.pickMotherVolume(this);
+ Define define = lcdd.getDefine();
+ Transformations trans_top = new Transformations("top", tr_top, rot_top);
+ Map<String, Crystal> topMap = trans_top.getCrystalMap();
+ Transformations trans_bot = new Transformations("bottom", tr_bot, rot_bot);
+ Map<String, Crystal> botMap = trans_bot.getCrystalMap();
+ LOGGER.info(("Number of crystal map content for bottom module " + botMap.size()));
+ LOGGER.info(("Number of crystal map content for top module " + topMap.size()));
+ for (int iy = -5; iy <= 5; iy++) {
+ if (iy == 0)
continue;
+ for (int ix = -23; ix <= 23; ix++) {
+ if (ix == 0) {
+ continue;
+ }
+
+ // z axis rotation parameter of the whole module
+ double zrot_cry = rot_bot[0];
+ String baseName = "crystal" + ix + "-" + iy;
+
+ Crystal crystal = botMap.get(String.format("c%d:l%d", ix, iy));
+
+ if (iy > 0) {
+ crystal = topMap.get(String.format("c%d:l%d", ix, iy));
+ // z axis rotation parameter of entire module
+ zrot_cry = rot_top[0];
+ }
+
+ if (crystal == null)
+ if ((iy == -1 && ix > -11 && ix < -1) || (iy == 1 && ix > -11 && ix < -1))
+ continue;
+ else
+ throw new RuntimeException(iy + " " + ix + " crystal is null, the map is screwed");
+
+ if (crystal.getCrystalG4Pos() == null)
+ throw new RuntimeException("g4pos of crystal is null, the map is screwed, sorry\n");
+
+ double [] centerxyz = crystal.getCrystalG4Pos().getCenterArr();
+ double [] thetaxyz = crystal.getCrystalG4Pos().getTaitBryanAngles();
+
+
+ // Transform of crystal.
+ Position ipos = new Position(baseName + "_pos", centerxyz[0], centerxyz[1], centerxyz[2]);
+ Rotation irot = new Rotation(baseName + "_rot", thetaxyz[0], thetaxyz[1], thetaxyz[2] - zrot_cry);
+ define.addPosition(ipos);
+ define.addRotation(irot);
+
+ // Place the crystal.
+ PhysVol CrystalPlacementBot = new PhysVol(crystalLogVol, world, ipos, irot);
+ // Add volume IDs.
+ CrystalPlacementBot.addPhysVolID("system", system);
+ CrystalPlacementBot.addPhysVolID("ix", ix);
+ CrystalPlacementBot.addPhysVolID("iy", iy);
+
}
-
- // z axis rotation parameter of the whole module
- double zrot_cry = bot_rot[0];
- String baseName = "crystal" + ix + "-" + iy;
-
- Crystal crystal = botMap.get(String.format("c%d:l%d", ix, iy));
-
- if (iy > 0) {
- crystal = topMap.get(String.format("c%d:l%d", ix, iy));
- // z axis rotation parameter of the whole module
- zrot_cry = top_rot[0];
- }
-
- if (crystal == null)
- if ((iy == -1 && ix > -11 && ix < -1) || (iy == 1 && ix > -11 && ix < -1))
- continue;
- else
- System.err.println(iy + " " + ix + " crystal is null, the map is screwed");
-
- if (crystal.getCrystalG4Pos() == null)
- System.err.print("g4pos of crystal is null, the map is screwed, sorry\n");
-
- double[] centerxyz = {0, 0, 0};
- double[] thetaxyz = {0, 0, 0};
- if (crystal != null) {
- centerxyz = crystal.getCrystalG4Pos().getCenterArr();
- thetaxyz = crystal.getCrystalG4Pos().getTaitBryanAngles();
- }
-
- // Transform of crystal.
- Position ipos = new Position(baseName + "_pos", centerxyz[0], centerxyz[1], centerxyz[2]);
- Rotation irot = new Rotation(baseName + "_rot", thetaxyz[0], thetaxyz[1], thetaxyz[2] - zrot_cry);
- define.addPosition(ipos);
- define.addRotation(irot);
-
- // Place the crystal.
- PhysVol CrystalPlacementBot = new PhysVol(crystalLogVol, world, ipos, irot);
- // Add volume IDs.
- CrystalPlacementBot.addPhysVolID("system", system);
- CrystalPlacementBot.addPhysVolID("ix", ix);
- CrystalPlacementBot.addPhysVolID("iy", iy);
-
+
}
-
+ }
+ catch (ConditionsManager.ConditionsNotFoundException ex) {
+ Logger.getLogger(HPSEcal4.class.getName()).log(Level.SEVERE, null, ex);
}
}
Modified: java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalCrystalPositionTest.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalCrystalPositionTest.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalCrystalPositionTest.java Wed May 4 16:15:15 2016
@@ -31,10 +31,19 @@
for (EcalCrystalPosition position : positions) {
int channelId = position.getChannelId();
+ double xback = position.getBackX();
+ double yback = position.getBackY();
+ double zback = position.getBackZ();
+ double xfront = (double)position.getFrontX();
+ double yfront = (double)position.getFrontY();
+ double zfront = (double)position.getFrontZ();
+ position.getRowId();
EcalChannel channel = channels.findChannel(channelId);
System.out.println(channel);
- System.out.println(position);
+ //System.out.println(position);
System.out.println();
+ System.out.println("back "+xback+" "+yback+" "+zback+" ");
+ System.out.println("front "+xfront+" "+yfront+" "+zfront+" ");
}
}
}
Copied: java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalTransformationsTest.java (from r4349, java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalCrystalPositionTest.java)
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalCrystalPositionTest.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalTransformationsTest.java Wed May 4 16:15:15 2016
@@ -1,40 +1,76 @@
package org.hps.detector.ecal;
+import java.util.Map;
import junit.framework.TestCase;
import org.hps.conditions.database.DatabaseConditionsManager;
-import org.hps.conditions.ecal.EcalChannel;
-import org.hps.conditions.ecal.EcalCrystalPosition;
-import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
-import org.hps.conditions.ecal.EcalCrystalPosition.EcalCrystalPositionCollection;
-
+import org.hps.detector.ecal.geo2015.crystal.Crystal;
+import org.hps.detector.ecal.geo2015.ecal.Transformations;
/**
- * Simplistic test of loading ECal crystal positions from the conditions database
- * and associating to an ecal channel object.
+ * Simplistic test of loading ECal crystal positions from the conditions
+ * database and associating to an ecal channel object.
* <p>
* This test must go into the <i>detector-model</i> module because the detector
- * converters are not available in the <i>conditions</i> package.
- *
- * @author jeremym
+ * converters are not available in the <i>conditions</i> package.
+ *
+ * @author Annie Simonyan [log in to unmask]
*/
-public class EcalCrystalPositionTest extends TestCase {
-
- public void testEcalCrystalPositions() throws Exception {
+public class EcalTransformationsTest extends TestCase {
+
+ public void testEcalTransformationsTest() throws Exception {
+ double[] tr = {0, 0, 0};
+ double[] rot = {0, 0, 0};
DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
- mgr.setDetector("HPS-PhysicsRun2016-Nominal-v4-4", 0); /* any run number and detector will work here */
+ mgr.setDetector("HPS-PhysicsRun2016-Nominal-v4-4", 0); /* any run number and detector will work here*/
+
+ Transformations transtop = new Transformations("top", tr, rot);
+ Transformations transbot = new Transformations("bottom", tr, rot);
+
+ Transformations.LOGGER.toString();
+
+ Map<String, Crystal> topModule = transtop.getCrystalMap();
+ Map<String, Crystal> bottomModule = transbot.getCrystalMap();
+ System.out.println(topModule.size() + " for top module\n" + bottomModule.size() + " for bottom module");
+
+ // loop over crystals
+ for (int iy = -5; iy <= 5; iy++) {
+ //there is no crystal with row=0, skip
+ if (iy == 0) {
+ continue;
+ }
+
+ for (int ix = -23; ix <= 23; ix++) {
+ //there is no crystal with column=0, skip
+ if (ix == 0) {
+ continue;
+ }
+
+ //get the crystal from the Map of crystals, key format is "c#column:l#row"
+ Crystal crystal = bottomModule.get(String.format("c%d:l%d", ix, iy));
+ if (iy > 0) {
+ crystal = topModule.get(String.format("c%d:l%d", ix, iy));
+ }
+
+ if (crystal != null) {
+ //print the g4 coordinates of the crystal
+ crystal.getCrystalG4Pos().Print();
+ }
+ else {
+ //skip the ecal gap
+ if ((iy == -1 && ix > -11 && ix < -1) || (iy == 1 && ix > -11 && ix < -1)) {
+ }
+ else {
+ throw new NullPointerException(iy + " " + ix
+ + " crystal is null, the map is screwed, the compiler really feels sorry for you.");
+ }
+ }
+
+ }
+
+ }
- EcalCrystalPositionCollection positions =
- mgr.getCachedConditions(EcalCrystalPositionCollection.class, "ecal_crystal_positions").getCachedData();
- EcalChannelCollection channels =
- mgr.getCachedConditions(EcalChannelCollection.class, "ecal_channels").getCachedData();
- for (EcalCrystalPosition position : positions) {
- int channelId = position.getChannelId();
- EcalChannel channel = channels.findChannel(channelId);
- System.out.println(channel);
- System.out.println(position);
- System.out.println();
- }
}
+
}
Modified: java/branches/HPSJAVA-409/detector-model/src/test/java/org/lcsim/detector/converter/compact/HPSEcal4ConverterTest.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/test/java/org/lcsim/detector/converter/compact/HPSEcal4ConverterTest.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/test/java/org/lcsim/detector/converter/compact/HPSEcal4ConverterTest.java Wed May 4 16:15:15 2016
@@ -1,22 +1,26 @@
package org.lcsim.detector.converter.compact;
+import java.io.IOException;
import java.io.InputStream;
-import java.util.List;
import java.util.logging.Logger;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.hps.conditions.database.DatabaseConditionsManager;
+import org.jdom.JDOMException;
+import org.lcsim.conditions.ConditionsManager;
import org.lcsim.detector.converter.compact.HPSEcal4Converter;
import org.lcsim.geometry.subdetector.HPSEcal4;
import org.lcsim.geometry.Detector;
import org.lcsim.geometry.GeometryReader;
+import org.lcsim.util.xml.ElementFactory;
/**
- * Unit test for the HPSTracker2Coverter.
+ * Unit test for the HPSTracker2Converter.
*
* @author SA [log in to unmask]
*/
@@ -32,7 +36,10 @@
}
private static final String resource = "/org/lcsim/geometry/subdetector/HPSEcal4Test.xml";
- public void setUp() {
+ public void setUp() throws ConditionsManager.ConditionsNotFoundException {
+ DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
+ mgr.setDetector("HPS-PhysicsRun2016-Nominal-v4-4", 0); /* any run number and detector will work here */
+
InputStream in = this.getClass().getResourceAsStream(resource);
GeometryReader reader = new GeometryReader();
@@ -40,7 +47,7 @@
try {
detector = reader.read(in);
}
- catch (Throwable x) {
+ catch (IOException | JDOMException | ElementFactory.ElementCreationException x) {
throw new RuntimeException(x);
}
}
Modified: java/branches/HPSJAVA-409/detector-model/src/test/java/org/lcsim/geometry/compact/converter/lcdd/HPSEcal4LCDDTest.java
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/test/java/org/lcsim/geometry/compact/converter/lcdd/HPSEcal4LCDDTest.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/test/java/org/lcsim/geometry/compact/converter/lcdd/HPSEcal4LCDDTest.java Wed May 4 16:15:15 2016
@@ -9,29 +9,32 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.hps.conditions.database.DatabaseConditionsManager;
/**
-*
-* @author Annie Simonyan <[log in to unmask]>
-*/
+ *
+ * @author Annie Simonyan <[log in to unmask]>
+ */
public class HPSEcal4LCDDTest extends TestCase {
-
- public HPSEcal4LCDDTest(String name)
- {
- super(name);
- }
-
- public static TestSuite suite()
- {
- return new TestSuite(HPSEcal4LCDDTest.class);
- }
-
- public void test_converter() throws Exception
- {
- //InputStream in = HPSTestRunTracker2014.class.getResourceAsStream("/org/lcsim/geometry/subdetector/HPSEcal4Test.xml");
- InputStream in = this.getClass().getResourceAsStream("/org/lcsim/geometry/subdetector/HPSEcal4Test.xml");
- OutputStream out = new BufferedOutputStream(new FileOutputStream(new TestOutputFile("HPSEcal4Test.lcdd")));
- new Main().convert("HPSEcal4Test",in,out);
- }
- }
+ public HPSEcal4LCDDTest(String name) {
+ super(name);
+ }
+
+ public static TestSuite suite() {
+ return new TestSuite(HPSEcal4LCDDTest.class);
+ }
+
+ public void test_converter() throws Exception {
+ DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
+ mgr.setDetector("HPS-PhysicsRun2016-Nominal-v4-4", 0); /*
+ * any run number and detector will work here
+ */
+
+ //InputStream in = HPSTestRunTracker2014.class.getResourceAsStream("/org/lcsim/geometry/subdetector/HPSEcal4Test.xml");
+ InputStream in = this.getClass().getResourceAsStream("/org/lcsim/geometry/subdetector/HPSEcal4Test.xml");
+
+ OutputStream out = new BufferedOutputStream(new FileOutputStream(new TestOutputFile("HPSEcal4Test.lcdd")));
+ new Main().convert("HPSEcal4Test", in, out);
+ }
+}
|