Author: [log in to unmask]
Date: Mon May 16 14:32:37 2016
New Revision: 4356
Log:
Minor code cleanup and formatting.
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/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
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 Mon May 16 14:32:37 2016
@@ -1,52 +1,49 @@
-
package org.hps.detector.ecal.geo2015.ecal;
-import org.hps.detector.ecal.geo2015.geoutils.GVector;
+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 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.detector.ecal.geo2015.geoutils.GVector;
+import org.hps.conditions.ecal.EcalCrystalPosition.EcalCrystalPositionCollection;
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 :/
+ * 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 static Logger LOGGER = Logger.getLogger(HPSEcal3Converter.class.getPackage().getName());
+ public static Logger LOGGER = Logger.getLogger(Transformations.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
+ /* vector of translation */
+ private GVector transVec;
+ private double[] rotation;
-
- private Map<String, Crystal> crystalMap; //Map of crystals with key = ("c#column:l#layer")
+ /* name "top" or "bottom" to tranform Ecal top or bottom module respectively */
+ private String module;
- //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));
+ /* geometrically defined center mass of top module */
+ private final GVector CMvec_nom_top = 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]));
this.transVec = new GVector(trans);
@@ -55,154 +52,141 @@
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);
}
- catch (FileNotFoundException ex) {
- Logger.getLogger(Transformations.class.getName()).log(Level.SEVERE, null, ex);
- }
-
}
- //returns the map of crystals
+ // returns the map of crystals
public Map<String, Crystal> getCrystalMap() {
return this.crystalMap;
}
- //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();
+ // does all the transformatios initiated in constructor
+ private void makeTransformation() throws Exception {
+ // trying to access database to read ecal crystal positions and channels
- //define number of crystals
- int Ncrys = positions.size();
+ // initializing database access
+ DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance();
+ EcalCrystalPositionCollection positions = mgr.getCachedConditions(EcalCrystalPositionCollection.class,
+ "ecal_crystal_positions").getCachedData();
- //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("Got " + positions.size() + " ECal crystal positions from database.");
- // LOGGER.info(data.toString());
- GVector[] frontXYZ = new GVector[Ncrys];
- GVector[] backXYZ = new GVector[Ncrys];
+ EcalChannel.EcalChannelCollection channels = mgr.getCachedConditions(EcalChannel.EcalChannelCollection.class,
+ "ecal_channels").getCachedData();
- //declaring temp center mass vector to be used in the loop
- GVector CMvec_nom = new GVector();
+ 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
/*
- * 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" );
+ * 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");
*/
- // translate the coordinate system to CM
- for (int loop = 0; loop < Ncrys; loop++) {
+ if (frontXYZ[loop] == null || backXYZ[loop] == null) {
+ throw new RuntimeException("The front or back vectors are null.");
+ }
- //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());
+ // dfine the position as a geant4position object for a crystal
+ Geant4Position g4pos = new Geant4Position(frontXYZ[loop], backXYZ[loop]);
- 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 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());
- }
- LOGGER.info(("Number of crystal map content after transformations in the "+this.module+" module = " + crystalMap.size()));
+ // 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());
}
- catch (RuntimeException e) {
- e.printStackTrace(new PrintStream("Database manager object was not initialized properly or required data were not cached."));
- }
+ LOGGER.info(("Number of crystal map content after transformations in the " + this.module + " module = "
+ + crystalMap.size()));
}
}
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 Mon May 16 14:32:37 2016
@@ -1,7 +1,6 @@
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;
@@ -11,7 +10,6 @@
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;
@@ -34,13 +32,10 @@
import org.lcsim.geometry.subdetector.HPSEcal4;
/*
- * For class description contact Jeremy
- * For implementatoin details contact Annie
- *
+ * 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());
@@ -56,127 +51,120 @@
@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};
try {
-
- 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);
+ 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();
+
+ } 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++;
+
}
- 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);
}
+ LOGGER.info(("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 Mon May 16 14:32:37 2016
@@ -1,16 +1,13 @@
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;
import org.lcsim.geometry.compact.converter.lcdd.util.PhysVol;
@@ -20,132 +17,113 @@
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])
+ * @author annie
+ * @author jeremym
*/
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 {
- 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.");
+
+ 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();
+
+ 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.");
+
+ 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);
+
}
- 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);
-
- }
-
- }
- }
- catch (ConditionsManager.ConditionsNotFoundException ex) {
- Logger.getLogger(HPSEcal4.class.getName()).log(Level.SEVERE, null, ex);
+
}
-
}
public boolean isCalorimeter() {
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 Mon May 16 14:32:37 2016
@@ -41,6 +41,14 @@
EcalChannel channel = channels.findChannel(channelId);
System.out.println(channel);
//System.out.println(position);
+ double frontX = position.getFrontX();
+ double frontY = position.getFrontY();
+ double frontZ = position.getFrontZ();
+ double backX = position.getBackX();
+ double backY = position.getBackY();
+ double backZ = position.getBackZ();
+ System.out.println("fx, fy, fz, bx, by, bz = " + frontX + ", " + frontY + ", " + frontZ + ", " +
+ backX + ", " + backY + ", " + backZ);
System.out.println();
System.out.println("back "+xback+" "+yback+" "+zback+" ");
System.out.println("front "+xfront+" "+yfront+" "+zfront+" ");
|