Author: [log in to unmask]
Date: Tue May 17 17:13:42 2016
New Revision: 4357
Log:
[HPSJAVA-409] First round of cleanup on new ECal geometry code (consolidate everything into one package).
Added:
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/CenterMass.java
- copied, changed from r4353, 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/CrystalTaitBryanAngleCalculator.java
- copied, changed from r4353, 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/DataLoader.java
- copied, changed from r4353, 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/ECalRotationCalculator.java
- copied, changed from r4356, 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/EcalNominal.java
- copied, changed from r4353, 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/EcalSurveyData.java
- copied, changed from r4353, 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/GVector.java
- copied, changed from r4353, java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/GVector.java
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/Geant4Position.java
- copied, changed from r4353, 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/Line.java
- copied, changed from r4353, 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/Plane.java
- copied, changed from r4353, 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/StatFunUtils.java
- copied, changed from r4353, 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/Transformations.java
- copied, changed from r4356, java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/Transformations.java
Removed:
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/base/
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/crystal/
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/data/
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/ecal/
java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/
java/branches/HPSJAVA-409/detector-model/src/test/java/org/hps/detector/ecal/EcalTransformationsTest.java
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/geometry/compact/converter/lcdd/HPSEcal4.java
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/CenterMass.java (from r4353, 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/CenterMass.java Tue May 17 17:13:42 2016
@@ -1,14 +1,10 @@
-/*
- * 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;
+package org.hps.detector.ecal;
/**
* 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 Annie Simonyan [log in to unmask]
+ * @author Annie Simonyan
*/
public class CenterMass {
@@ -22,24 +18,21 @@
* Meaningful constructor, with Vvectors as argument for 4 points only
*/
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;
- zc = (pointA.z + pointB.z + pointC.z + pointD.z) / 4;
+ xc = (pointA.x() + pointB.x() + pointC.x() + pointD.x()) / 4;
+ yc = (pointA.y() + pointB.y() + pointC.y() + pointD.y()) / 4;
+ zc = (pointA.z() + pointB.z() + pointC.z() + pointD.z()) / 4;
}
/*
* Meaningful constructor, for any number of points arguments should be arrays of (Xs[], Ys[], Zs[]) of points
*/
public CenterMass(double[] x, double[] y, double[] z) {
-
int N = x.length;
for (int loop = 0; loop < N; loop++) {
xc = xc + x[loop];
yc = yc + y[loop];
zc = zc + z[loop];
}
-
xc = xc / N;
yc = yc / N;
zc = zc / N;
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/CrystalTaitBryanAngleCalculator.java (from r4353, 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/CrystalTaitBryanAngleCalculator.java Tue May 17 17:13:42 2016
@@ -2,9 +2,8 @@
* 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.crystal;
+package org.hps.detector.ecal;
-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
@@ -17,57 +16,47 @@
*
* @author Annie Simonyan [log in to unmask]
*/
-public class CrystalTaitBryanAngleCalculator {
+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
+ // final state vector
+ private GVector fin;
- private GVector fin; //final state vector
-
- private double cosTheta = 0;
private double sinTheta = 0;
private double cosPhi = 0;
private double sinPhi = 0;
-
//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) {
- fin = vec_fin.getUnitVector();
+ public CrystalTaitBryanAngleCalculator(GVector vecFin) {
+ fin = vecFin;
+ if (vecFin.isUnitary() == false) {
+ fin = vecFin.getUnitVector();
}
-
- this.phi = this.CalcPhi();
- this.theta = this.CalcTheta();
+ this.phi = this.calculatePhi();
+ this.theta = this.calculateTheta();
}
//calculates phi angle
- private double CalcPhi() {
-
- sinPhi = -fin.y;
+ private double calculatePhi() {
+ sinPhi = -fin.y();
cosPhi = Math.sqrt(1 - this.sinPhi * this.sinPhi);
-
return Math.asin(this.sinPhi);
}
-
//calculates theta angle after phi is calculated
- private double CalcTheta() {
-
- if (this.cosPhi == 0)
+ private double calculateTheta() {
+ if (this.cosPhi == 0) {
this.sinTheta = Double.NaN;
- else
- this.sinTheta = fin.x / this.cosPhi;
-
+ } else {
+ this.sinTheta = fin.x() / this.cosPhi;
+ }
return Math.asin(this.sinTheta);
}
-
//returns value of theta in rad
public double getTheta() {
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/DataLoader.java (from r4353, 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/DataLoader.java Tue May 17 17:13:42 2016
@@ -1,9 +1,4 @@
-/*
- * 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.base;
+package org.hps.detector.ecal;
//import static com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type.Int;
import java.io.BufferedReader;
@@ -17,11 +12,11 @@
/**
- * Class to read the data from a file
- * @author Annie Simonyan [log in to unmask]
+ * Class to read the data from a file.
+ *
+ * @author Annie Simonyan
*/
-
-public class DataLoader {
+class DataLoader {
private final ArrayList<String[]> dataset = new ArrayList<>();
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/ECalRotationCalculator.java (from r4356, 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/ECalRotationCalculator.java Tue May 17 17:13:42 2016
@@ -1,118 +1,105 @@
-package org.hps.detector.ecal.geo2015.ecal;
+package org.hps.detector.ecal;
-import org.hps.detector.ecal.geo2015.geoutils.GVector;
-import org.hps.detector.ecal.geo2015.base.StatFunUtils;
-
-/*
- * 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
- */
/**
- *
+ * 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 Annie Simonyan
*/
public class ECalRotationCalculator {
- private GVector 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; //parameters of initial plane equation
- private double a = 0.0, b = 0, c = 0; //parameters of final plane equation
+ 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
+ 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*/) {
+ // 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();
n_fin = EcalSurveyData.plABCDtop_fin.getNormalUnitVector();
-
-
- if (str.compareToIgnoreCase("bottom")==0) {
- n_ini = EcalSurveyData.plABCDbot_ini.getNormalUnitVector();
-
+
+ if (str.compareToIgnoreCase("bottom") == 0) {
+ n_ini = EcalSurveyData.plABCDbot_ini.getNormalUnitVector();
+
n_fin = EcalSurveyData.plABCDbot_fin.getNormalUnitVector();
-
-
+
}
-
- //for tests
- // n_ini = EcalSurveyData.plYZ.getNormalUnitVector();
- // n_fin = EcalSurveyData.plXY.getNormalUnitVector();
-
+ // for tests
+ // n_ini = EcalSurveyData.plYZ.getNormalUnitVector();
+ // n_fin = EcalSurveyData.plXY.getNormalUnitVector();
+
if (!checkNormals()) {
- System.err.print("In class **** "+this.getClass()+" **** normals are not fine\n");
+ System.err.print("In class **** " + this.getClass() + " **** normals are not fine\n");
return;
}
- a0 = n_ini.x;
- b0 = n_ini.y;
- c0 = n_ini.z;
+ a0 = n_ini.x();
+ b0 = n_ini.y();
+ c0 = n_ini.z();
- a = n_fin.x;
- b = n_fin.y;
- c = n_fin.z;
+ a = n_fin.x();
+ b = n_fin.y();
+ c = n_fin.z();
- // System.out.println(a + " " + b + " " + c);
- // System.out.println(a0 + " " + b0 + " " + c0);
+ // System.out.println(a + " " + b + " " + c);
+ // System.out.println(a0 + " " + b0 + " " + c0);
calcGamma();
calcAlpha();
};
- //Calculate gamma rotation angle
+ // Calculate gamma rotation angle
private void calcGamma() {
double tg_gamma = 0.0;
if (b0 == 0) {
gamma = Math.PI / 2;
- }
- else {
+ } else {
tg_gamma = (c - c0) / b0;
gamma = Math.atan(tg_gamma);
}
-
}
- //calculate alpha rotation angle
+ // calculate alpha rotation angle
private void calcAlpha() {
double ham = (a * a0 - b * (b0 * Math.cos(gamma) - c0 * Math.sin(gamma)));
double hayt = a0 * (a0 + c0 * Math.cos(gamma)) + Math.pow((b0 * Math.cos(gamma) - c0 * Math.sin(gamma)), 2);
alpha = Math.acos(ham / hayt);
- if(alpha>Math.PI/2)
- alpha = Math.PI-alpha;
+ if (alpha > Math.PI / 2)
+ alpha = Math.PI - alpha;
}
- //return value of alpha - rotatoin around Z
+ // return value of alpha - rotatoin around Z
public double getAlpha() {
return this.alpha;
}
- //return value of gamma - rotatoin around X
+ // 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
+ // returns true if the normal vectors of the initial and final plane are actually normal
private boolean checkNormals() {
- return(Double.compare(StatFunUtils.round(n_ini.Module(),12),1.0)==0 && Double.compare(StatFunUtils.round(n_fin.Module(),12),1.0)==0);
- }
+ return (Double.compare(StatFunUtils.round(n_ini.Module(), 12), 1.0) == 0 && Double.compare(
+ StatFunUtils.round(n_fin.Module(), 12), 1.0) == 0);
+ }
}
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/EcalNominal.java (from r4353, 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/EcalNominal.java Tue May 17 17:13:42 2016
@@ -1,7 +1,4 @@
-package org.hps.detector.ecal.geo2015.ecal;
-
-import org.hps.detector.ecal.geo2015.geoutils.Plane;
-import org.hps.detector.ecal.geo2015.geoutils.GVector;
+package org.hps.detector.ecal;
/**
* This class holds the nominal(by initial design) coordinates for 4 measuring points of each ecal module
@@ -22,7 +19,6 @@
public static final GVector CtopVec = new GVector(Ctop);
public static final GVector DtopVec = new GVector(Dtop);
-
//Nominal plane of top module
public static Plane plABCDtop_ini = new Plane(Atop, Btop, Ctop);
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/EcalSurveyData.java (from r4353, 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/EcalSurveyData.java Tue May 17 17:13:42 2016
@@ -3,10 +3,8 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
-package org.hps.detector.ecal.geo2015.ecal;
+package org.hps.detector.ecal;
-import org.hps.detector.ecal.geo2015.geoutils.Plane;
-import org.hps.detector.ecal.geo2015.geoutils.GVector;
/**
* Class to hold the survey results (positions of 4 targets of calorimeter in the hall)
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/GVector.java (from r4353, java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/GVector.java)
=============================================================================
--- java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/geo2015/geoutils/GVector.java (original)
+++ java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/GVector.java Tue May 17 17:13:42 2016
@@ -1,19 +1,16 @@
-package org.hps.detector.ecal.geo2015.geoutils;
+package org.hps.detector.ecal;
import hep.physics.vec.BasicHep3Vector;
-import org.hps.detector.ecal.geo2015.base.StatFunUtils;
-
/**
- * To define a vector in (XYZ) coordinate system as a geometrical object,
- * define operations, manipulations with the vectors
+ * Defines a vector in (XYZ) coordinate system as a geometrical object.
* This class is similar to HepVector
*
- * @author Annie Simonyan [log in to unmask]
+ * CrystalTaitBryanAngleCalculator.java
*/
public class GVector {
- public double x = 0, y = 0, z = 0;
+ private double x = 0, y = 0, z = 0;
private double[] vec;
//default constructor
@@ -42,7 +39,18 @@
vec[0] = x;
vec[1] = y;
vec[2] = z;
-
+ }
+
+ public double x() {
+ return x;
+ }
+
+ public double y() {
+ return y;
+ }
+
+ public double z() {
+ return z;
}
//set vector x coordinate
@@ -176,7 +184,6 @@
//returns the center coordinates of this vector as a Vvector object
public GVector getCenter() {
-
return (this.Multiply(0.5));
}
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/Geant4Position.java (from r4353, 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/Geant4Position.java Tue May 17 17:13:42 2016
@@ -1,14 +1,12 @@
-package org.hps.detector.ecal.geo2015.crystal;
-
-import java.util.logging.Logger;
-import org.hps.detector.ecal.geo2015.geoutils.GVector;
+package org.hps.detector.ecal;
/**
* 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
+ * of the crystal calculates the rotation of the crystal in convention of Tait-Bryan angles, {phi, theta, psi}
+ *
* or look here: http://sedris.org/wg8home/Documents/WG80485.pdf
+ *
* Brief:
* phi-rotation around X
* theta-rotation around Y
@@ -17,8 +15,6 @@
* @author Annie Simonyan [log in to unmask]
*/
public class Geant4Position {
-
- 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
@@ -31,17 +27,12 @@
public Geant4Position(GVector point1, GVector point2) {
centerPoint = point2.Add(point1).Multiply(0.5);
centerArr = new double[3];
- centerArr[0] = centerPoint.x;
- centerArr[1] = centerPoint.y;
- centerArr[2] = centerPoint.z;
+ centerArr[0] = centerPoint.x();
+ centerArr[1] = centerPoint.y();
+ centerArr[2] = centerPoint.z();
crysvec = (point2.Substract(centerPoint)).getUnitVector();
- LOGGER.info("*************** center unit vector **********");
- LOGGER.info(crysvec.toString());
- LOGGER.info("*********************************************");
-
taitbriangles = new double[3];
- this.TaitBryanAnglesforCrys();
-
+ this.calculateTaitBryanAngles();
}
//returns the center coordinates as a Vector
@@ -61,28 +52,19 @@
//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{
+ private void calculateTaitBryanAngles() 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) {
- this.taitbriangles[0] = -111111;
- throw new ArithmeticException("chert: Phi is undefined\n");
- } else {
- this.taitbriangles[0] = -crysTBang.getPhi();
+ if (crysTBang.getPhi() == Double.NaN) {
+ throw new ArithmeticException("Calculated Tait-Bryan phi angle is NaN.");
}
+ this.taitbriangles[0] = -crysTBang.getPhi();
this.taitbriangles[1] = -crysTBang.getTheta();
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
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/Line.java (from r4353, 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/Line.java Tue May 17 17:13:42 2016
@@ -3,7 +3,7 @@
* Tools | Templates and open the template in the editor.
*/
-package org.hps.detector.ecal.geo2015.geoutils;
+package org.hps.detector.ecal;
/**
* @author Annie Simonyan
@@ -16,7 +16,7 @@
// Define a line with a vector and a point it goes through
public Line(GVector vec, double x, double y, double z) {
- this.setVec_n(new GVector(vec.x, vec.y, vec.z));
+ this.setVec_n(new GVector(vec.x(), vec.y(), vec.z()));
point = new double[3];
point[0] = x;
point[1] = y;
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/Plane.java (from r4353, 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/Plane.java Tue May 17 17:13:42 2016
@@ -1,12 +1,11 @@
-/*
+package org.hps.detector.ecal;
+
+/**
* 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;
-
public class Plane {
private double c1 = 0., c2 = 0., c3 = 0., c4 = 0., c5 = 0., c6 = 0.;
@@ -46,7 +45,7 @@
public GVector getNormalUnitVector() {
double mod = normal.Module();
- GVector uNorm = new GVector(normal.x / mod, normal.y / mod, normal.z / mod);
+ GVector uNorm = new GVector(normal.x() / mod, normal.y() / mod, normal.z() / mod);
return uNorm;
}
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/StatFunUtils.java (from r4353, 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/StatFunUtils.java Tue May 17 17:13:42 2016
@@ -1,11 +1,11 @@
-package org.hps.detector.ecal.geo2015.base;
+package org.hps.detector.ecal;
/**
* Some static functions which I couldn't find in java standard libraries
*
- * @author Annie Simonyan [log in to unmask]
+ * @author Annie Simonyan
*/
-public class StatFunUtils {
+class StatFunUtils {
/*****
* Function for double to round up the arg. value to 'places' digits after the semicolon
Copied: java/branches/HPSJAVA-409/detector-model/src/main/java/org/hps/detector/ecal/Transformations.java (from r4356, 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/Transformations.java Tue May 17 17:13:42 2016
@@ -1,25 +1,17 @@
-package org.hps.detector.ecal.geo2015.ecal;
+package org.hps.detector.ecal;
-import java.util.HashMap;
-import java.util.Map;
import java.util.logging.Logger;
-import org.hps.conditions.database.DatabaseConditionsManager;
import org.hps.conditions.ecal.EcalChannel;
-import org.hps.detector.ecal.geo2015.crystal.Crystal;
-import org.hps.detector.ecal.geo2015.crystal.Geant4Position;
-import org.hps.detector.ecal.geo2015.geoutils.GVector;
-import org.hps.conditions.ecal.EcalCrystalPosition.EcalCrystalPositionCollection;
import org.hps.conditions.ecal.EcalCrystalPosition;
/**
- * 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 :/
+ * Performs vector transformations to calculate center of crystal volume from front and back
+ * positions as defined in the conditions database.
*
- * @author Annie Simonyan [log in to unmask]
+ * @author Annie Simonyan
*/
-public class Transformations {
+public final class Transformations {
public static Logger LOGGER = Logger.getLogger(Transformations.class.getPackage().getName());
@@ -27,166 +19,48 @@
private GVector transVec;
private double[] rotation;
- /* name "top" or "bottom" to tranform Ecal top or bottom module respectively */
- private String module;
-
/* geometrically defined center mass of top module */
- private final GVector CMvec_nom_top = new GVector(109.88, 230.79, 1008.73);
+ private final GVector vecTop = new GVector(109.88, 230.79, 1008.73);
/* geometrically defined center mass of bottom module */
- private final GVector CMvec_nom_bot = new GVector(109.88, -230.79, 1008.73);
-
- /* Map of crystals with key = ("c#column:l#layer") */
- private Map<String, Crystal> crystalMap;
-
- // 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) {
- 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]));
+ private final GVector vecBot = new GVector(109.88, -230.79, 1008.73);
+
+ /**
+ * Create a new <code>Transformations</code> object.
+ *
+ * @param trans translation in space as an array containing [x,y,z] coordinates
+ * @param rot rotation in space as an array with angles [alpha, beta, gamma] or [rx, ry, rz]
+ */
+ public Transformations(double[] trans, double[] rot) {
this.transVec = new GVector(trans);
- LOGGER.info(transVec.toString());
this.rotation = rot;
- 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 (Exception e) {
- throw new RuntimeException(e);
+ }
+
+ public Geant4Position transformToGeant4(EcalCrystalPosition position, EcalChannel channel) {
+
+ // Define untransformed front and back positions.
+ GVector frontVec = new GVector(position.getFrontX(), position.getFrontY(), position.getFrontZ());
+ GVector backVec = new GVector(position.getBackX(), position.getBackY(), position.getBackZ());
+
+ // Determine local coordinate system based on top or bottom half.
+ GVector coordOrigin;
+ if (channel.getY() > 0) {
+ coordOrigin = vecTop;
+ } else {
+ coordOrigin = vecBot;
}
+
+ // Transform front and back global positions into the local coordinate system.
+ frontVec = transformVector(frontVec, coordOrigin);
+ backVec = transformVector(backVec, coordOrigin);
+
+ // Return G4 position using front and back position vectors.
+ return new Geant4Position(frontVec, backVec);
}
-
- // returns the map of crystals
- public Map<String, Crystal> getCrystalMap() {
- return this.crystalMap;
- }
-
- // does all the transformatios initiated in constructor
- private void makeTransformation() throws Exception {
- // trying to access database to read ecal crystal positions and channels
-
- // initializing database access
- DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
- EcalCrystalPositionCollection positions = mgr.getCachedConditions(EcalCrystalPositionCollection.class,
- "ecal_crystal_positions").getCachedData();
-
- LOGGER.info("Got " + positions.size() + " ECal crystal positions from database.");
-
- EcalChannel.EcalChannelCollection channels = mgr.getCachedConditions(EcalChannel.EcalChannelCollection.class,
- "ecal_channels").getCachedData();
-
- LOGGER.info("Got " + channels.size() + " ECal crystal positions from database.");
-
- // 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();
-
- // 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;
- }
-
- 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 front or back vectors are null.");
- }
-
- // 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());
- }
- LOGGER.info(("Number of crystal map content after transformations in the " + this.module + " module = "
- + crystalMap.size()));
+
+ private GVector transformVector(GVector vec, GVector coordOrigin) {
+ return vec.TranslateBy(coordOrigin.getOpposite())
+ .RotateBy(this.rotation[0], this.rotation[1], this.rotation[2])
+ .TranslateBy(transVec)
+ .TranslateBy(coordOrigin);
}
}
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 Tue May 17 17:13:42 2016
@@ -1,25 +1,28 @@
package org.lcsim.detector.converter.compact;
-import java.util.Map;
import java.util.logging.Logger;
-import org.hps.detector.ecal.geo2015.crystal.Crystal;
-import org.hps.detector.ecal.geo2015.ecal.Transformations;
-
+import org.hps.conditions.database.DatabaseConditionsManager;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalCrystalPosition;
+import org.hps.conditions.ecal.EcalCrystalPosition.EcalCrystalPositionCollection;
+import org.hps.conditions.ecal.EcalChannel;
import org.hps.detector.ecal.EcalCrystal;
+import org.hps.detector.ecal.Geant4Position;
import org.hps.detector.ecal.HPSEcalDetectorElement;
+import org.hps.detector.ecal.Transformations;
import org.jdom.DataConversionException;
import org.jdom.Element;
+import org.lcsim.detector.ITranslation3D;
+import org.lcsim.detector.IRotation3D;
+import org.lcsim.detector.Translation3D;
+import org.lcsim.detector.RotationGeant;
+import org.lcsim.detector.Transform3D;
+import org.lcsim.detector.PhysicalVolume;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.ILogicalVolume;
import org.lcsim.detector.IPhysicalVolume;
-import org.lcsim.detector.IRotation3D;
-import org.lcsim.detector.ITranslation3D;
import org.lcsim.detector.LogicalVolume;
-import org.lcsim.detector.PhysicalVolume;
-import org.lcsim.detector.RotationGeant;
-import org.lcsim.detector.Transform3D;
-import org.lcsim.detector.Translation3D;
import org.lcsim.detector.identifier.ExpandedIdentifier;
import org.lcsim.detector.identifier.IExpandedIdentifier;
import org.lcsim.detector.identifier.IIdentifier;
@@ -32,35 +35,31 @@
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])
+ *
+ * @author annie
+ * @author jeremym
*/
public class HPSEcal4Converter extends AbstractSubdetectorConverter {
private static Logger LOGGER = Logger.getLogger(HPSEcal4Converter.class.getPackage().getName());
- // Margin for mother volume.
- // private static final double margin = 1.1;
-
private IIdentifierDictionary dict;
private IIdentifierHelper helper;
-
- // private List<CrystalRange> ranges = new ArrayList<CrystalRange>();
@Override
public void convert(final Subdetector subdet, final Detector detector) {
- 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;
- double tr_top[] = {-100, -100, -100};
- double tr_bot[] = {-100, -100, -100};
- double rot_top[] = {-100, -100, -100};
- double rot_bot[] = {-100, -100, -100};
+ double trTop[] = new double[3];
+ double trBot[] = new double[3];
+ double rotTop[] = new double[3];
+ double rotBot[] = new double[3];
+
try {
dx1 = dimensions.getAttribute("x1").getDoubleValue();
dx2 = dimensions.getAttribute("x2").getDoubleValue();
@@ -70,23 +69,23 @@
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();
+ trTop[0] = tra.getAttribute("top_tr_x").getDoubleValue();
+ trTop[1] = tra.getAttribute("top_tr_y").getDoubleValue();
+ trTop[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();
+ trBot[0] = tra.getAttribute("bot_tr_x").getDoubleValue();
+ trBot[1] = tra.getAttribute("bot_tr_y").getDoubleValue();
+ trBot[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();
+ rotTop[0] = rota.getAttribute("top_rot_alpha").getDoubleValue();
+ rotTop[1] = rota.getAttribute("top_rot_beta").getDoubleValue();
+ rotTop[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();
+ rotBot[0] = rota.getAttribute("bot_rot_alpha").getDoubleValue();
+ rotBot[1] = rota.getAttribute("bot_rot_beta").getDoubleValue();
+ rotBot[2] = rota.getAttribute("bot_rot_gamma").getDoubleValue();
} catch (final DataConversionException e) {
throw new RuntimeException("Error converting HPSEcal4 from XML.", e);
@@ -96,75 +95,56 @@
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()));
+ Transformations transTop = new Transformations(trTop, rotTop);
+ Transformations transBot = new Transformations(trBot, rotBot);
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;
+
+ // Get database conditions.
+ DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
+ EcalCrystalPositionCollection positions = mgr.getCachedConditions(EcalCrystalPositionCollection.class,
+ "ecal_crystal_positions").getCachedData();
+ EcalChannelCollection channels = mgr.getCachedConditions(EcalChannelCollection.class,
+ "ecal_channels").getCachedData();
+
+ // Loop over crystal positions.
+ for (EcalCrystalPosition position : positions) {
- // loop over columns
- for (int ix = -23; ix <= 23; ix++) {
- if (ix == 0) {
- continue;
- }
+ // Get channel info.
+ int channelId = position.getChannelId();
+ EcalChannel channel = channels.findChannel((long) channelId);
+ int iy = channel.getY();
+ int ix = channel.getX();
- // z axis rotation parameter of the whole module
- double zrot_cry = rot_bot[0];
+ // z axis rotation parameter of the whole module
+ double zrotCry;
+ Transformations trans;
+ if (iy > 0) {
+ zrotCry = rotTop[0];
+ trans = transTop;
+ } else {
+ zrotCry = rotBot[0];
+ trans = transBot;
+ }
+
+ Geant4Position g4pos = trans.transformToGeant4(position, channel);
+ double[] centerxyz = g4pos.getCenterArr();
+ double[] thetaxyz = g4pos.getTaitBryanAngles();
+
+ final ITranslation3D iposBot = new Translation3D(centerxyz[0], centerxyz[1], centerxyz[2]);
+ final IRotation3D irotBot = new RotationGeant(thetaxyz[0], thetaxyz[1], thetaxyz[2] - zrotCry);
- 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()));
-
+ // Place the crystal.
+ final IPhysicalVolume CrystalPlacement = new PhysicalVolume(
+ new Transform3D(iposBot, irotBot),
+ baseName + channelId,
+ crystalLogVol,
+ mom,
+ channelId);
+
+ // Create the DE pointing to the crystal vol.
+ this.createDetectorElement(detector, subdet, CrystalPlacement, ix, iy);
+ }
}
/**
@@ -194,7 +174,6 @@
@Override
public IDetectorElement makeSubdetectorDetectorElement(final Detector detector, final Subdetector subdetector) {
- LOGGER.info("creating detector element for subdetector " + subdetector.getName());
final IDetectorElement subdetectorDE = new HPSEcalDetectorElement(subdetector.getName(),
detector.getDetectorElement());
subdetector.setDetectorElement(subdetectorDE);
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 Tue May 17 17:13:42 2016
@@ -1,10 +1,10 @@
package org.lcsim.geometry.compact.converter.lcdd;
-import java.util.Map;
import java.util.logging.Logger;
-import org.hps.detector.ecal.geo2015.crystal.Crystal;
-import org.hps.detector.ecal.geo2015.ecal.Transformations;
+import org.hps.conditions.database.DatabaseConditionsManager;
+import org.hps.detector.ecal.Geant4Position;
+import org.hps.detector.ecal.Transformations;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.lcsim.detector.converter.compact.HPSEcal4Converter;
@@ -16,12 +16,18 @@
import org.lcsim.geometry.compact.converter.lcdd.util.SensitiveDetector;
import org.lcsim.geometry.compact.converter.lcdd.util.Trapezoid;
import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
+import org.hps.conditions.ecal.EcalCrystalPosition;
+import org.hps.conditions.ecal.EcalCrystalPosition.EcalCrystalPositionCollection;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
-/*
+/**
+ * Convert a compact subdetector to LCDD output using ECal database conditions
+ * for the crystal positions.
+ *
* @author annie
* @author jeremym
*/
-
public class HPSEcal4 extends LCDDSubdetector {
private static Logger LOGGER = Logger.getLogger(HPSEcal4Converter.class.getPackage().getName());
@@ -32,35 +38,40 @@
void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException {
- if (sens == null)
+ if (sens == null) {
throw new RuntimeException("SensitiveDetector parameter points to null.");
+ }
+
+ int system = this.getSystemID();
+ Element mat = node.getChild("material");
+ String materialName = mat.getAttributeValue("name");
+
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();
+ double trTop[] = new double[3];
+ trTop[0] = tra.getAttribute("top_tr_x").getDoubleValue();
+ trTop[1] = tra.getAttribute("top_tr_y").getDoubleValue();
+ trTop[2] = tra.getAttribute("top_tr_z").getDoubleValue();
+ double trBot[] = new double[3];
+ trBot[0] = tra.getAttribute("bot_tr_x").getDoubleValue();
+ trBot[1] = tra.getAttribute("bot_tr_y").getDoubleValue();
+ trBot[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();
+ double rotTop[] = new double[3];
+ rotTop[0] = rota.getAttribute("top_rot_alpha").getDoubleValue();
+ rotTop[1] = rota.getAttribute("top_rot_beta").getDoubleValue();
+ rotTop[2] = rota.getAttribute("top_rot_gamma").getDoubleValue();
+ double rotBot[] = new double[3];
+ rotBot[0] = rota.getAttribute("bot_rot_alpha").getDoubleValue();
+ rotBot[1] = rota.getAttribute("bot_rot_beta").getDoubleValue();
+ rotBot[2] = rota.getAttribute("bot_rot_gamma").getDoubleValue();
Trapezoid crystalTrap = new Trapezoid("crystal_trap", dx1, dx2, dy1, dy2, dz);
Volume crystalLogVol = new Volume("crystal_volume", crystalTrap, lcdd.getMaterial(materialName));
@@ -70,62 +81,60 @@
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;
- }
+
+ Transformations transTop = new Transformations(trTop, rotTop);
+ Transformations transBot = new Transformations(trBot, rotBot);
+
+ // Get database conditions.
+ DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
+ EcalCrystalPositionCollection positions = mgr.getCachedConditions(EcalCrystalPositionCollection.class,
+ "ecal_crystal_positions").getCachedData();
+ EcalChannelCollection channels = mgr.getCachedConditions(EcalChannelCollection.class,
+ "ecal_channels").getCachedData();
+
+ LOGGER.info("Read " + positions.size() + " ECal crystal positions from conditions database.");
+
+ // Loop over crystal positions.
+ for (EcalCrystalPosition position : positions) {
+
+ int channelId = position.getChannelId();
+ EcalChannel channel = channels.findChannel((long) channelId);
+ int iy = channel.getY();
+ int ix = channel.getX();
+ String baseName = "crystal" + ix + "_" + iy;
+
+ // z axis rotation parameter of the whole module
+ double zrot_cry = rotBot[0];
+ Transformations trans = transBot;
+ if (iy > 0) {
+ // z axis rotation parameter of entire module
+ zrot_cry = rotTop[0];
+ trans = transTop;
+ }
+
+ Geant4Position g4pos = trans.transformToGeant4(position, channel);
+ double[] centerxyz = g4pos.getCenterArr();
+ double[] thetaxyz = g4pos.getTaitBryanAngles();
- // z axis rotation parameter of the whole module
- double zrot_cry = rot_bot[0];
- String baseName = "crystal" + ix + "-" + iy;
+ // 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);
- 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.");
-
- if (crystal.getCrystalG4Pos() == null)
- throw new RuntimeException("g4pos of crystal is null.");
-
- 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);
-
- }
-
- }
+ // Place the crystal with volume IDs.
+ PhysVol CrystalPlacementBot = new PhysVol(crystalLogVol, world, ipos, irot);
+ CrystalPlacementBot.addPhysVolID("system", system);
+ CrystalPlacementBot.addPhysVolID("ix", ix);
+ CrystalPlacementBot.addPhysVolID("iy", iy);
+
+ // Debug print all info about physvol.
+ LOGGER.fine("Created physvol for crystal (" + ix + ", " + iy + "); channel ID " + channelId
+ + "; pos (" + centerxyz[0] + ", " + centerxyz[1] + ", " + centerxyz[2]
+ + "); rot (" + thetaxyz[0] + ", " + thetaxyz[1] + ", " + (thetaxyz[2] - zrot_cry) + ")");
+ }
}
-
+
public boolean isCalorimeter() {
return true;
}
|