GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -u -r1.5 -r1.6
--- HPSEcal.java 13 Apr 2011 21:58:24 -0000 1.5
+++ HPSEcal.java 13 Apr 2011 23:28:35 -0000 1.6
@@ -7,6 +7,7 @@
import org.jdom.Element;
import org.jdom.JDOMException;
+import org.lcsim.geometry.compact.converter.lcdd.util.Box;
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;
@@ -30,10 +31,16 @@
* @author Jeremy McCormick
* @author Tim Nelson
*
- * @version $Id: HPSEcal.java,v 1.5 2011/04/13 21:58:24 jeremy Exp $
+ * @version $Id: HPSEcal.java,v 1.6 2011/04/13 23:28:35 jeremy Exp $
*/
public class HPSEcal extends LCDDSubdetector
{
+ // Tolerance factor for moving crystals to appropriate place in mom volume.
+ static final double tolerance = 0.1;
+
+ // Tolerance factor for separating crystals to avoid overlaps.
+ static final double crystalTolerance = 0.1;
+
HPSEcal(Element node) throws JDOMException
{
super(node);
@@ -74,7 +81,22 @@
lcdd.add(crystalLogVol);
Define define = lcdd.getDefine();
- Volume mother = lcdd.pickMotherVolume(this);
+ //Volume mother = lcdd.pickMotherVolume(this);
+
+ // Mother volume dimensions.
+ double mx, my, mz;
+ double margin = 1.1;
+ mx = nx*Math.max(dx2,dx1);
+ //mx *= margin;
+ my = ny*Math.max(dy2, dy1);
+ //my *= margin;
+ mz = dz;
+ //mz *= margin;
+ Box momBox = new Box("mom_box", mx*2*margin, my*2*margin, mz*2*margin);
+ Volume momVol = new Volume("mom_volume", momBox, lcdd.getMaterial("Air"));
+
+ lcdd.add(momBox);
+ lcdd.add(momVol);
// Slope of the trapezoid side in X.
double sx = (dx2-dx1)/(2*dz);
@@ -91,12 +113,9 @@
// Distance between (virtual) angular origin and center of trapezoid in X.
double z0x = dx1/sx+dz;
- // // Distance between (virtual) angular origin and center of trapezoid in Y.
+ // Distance between (virtual) angular origin and center of trapezoid in Y.
double z0y = dy1/sy+dz;
-
- // Always 0. (no rotation about Z)
- //double thetaz = 0;
-
+
// Odd or even number of crystals in X.
boolean oddx = (nx % 2 != 0);
@@ -113,7 +132,7 @@
double ycorrtot = 0;
double zcorrtoty = 0;
- //double fudgeFactor = .01;
+ //double fudgeFactor = .01;
for (int iy=1; iy<=ny; iy++)
{
@@ -124,7 +143,7 @@
double thetax = coeffy*dthetax;
double zcorry = dy1*(2*sin(coeffy*dthetax));
double ycorr = zcorry*tan((coeffy-1)*dthetax);
- double ycenter = z0y*sin(coeffy*dthetax)+ycorr+ycorrtot;
+ double ycenter = z0y*sin(coeffy*dthetax)+ycorr+ycorrtot+(crystalTolerance*iy);
for (int ix=0; ix<=nx; ix++)
{
@@ -139,13 +158,12 @@
double thetay = coeffx*dthetay;
double zcorrx = dx1*(2*sin(coeffx*dthetay));
- // Center point of trap front face along line instead of edge.
+ // NOTE Center point of trap front face along line instead of edge.
// double zcorr = dx1*(sin(2*ix*dthetay))+sin(2*(ix-1)*dthetay));
double xcorr = zcorrx*tan((coeffx-1)*dthetay);
- //+ fudgeFactor;
- double xcenter = z0x*sin(coeffx*dthetay)+xcorr+xcorrtot;
+ double xcenter = z0x*sin(coeffx*dthetay)+xcorr+xcorrtot+(crystalTolerance*ix);
double zcenter = z0y*(cos(coeffy*dthetax)-1)+z0x*(cos(coeffx*dthetay)-1)+zcorrx+zcorrtotx+zcorry+zcorrtoty;
-
+
//double thetaz = -Math.pow(sin(thetay),2)*thetax;
double thetaz = 0;
@@ -155,7 +173,7 @@
//if (iy == ny)
//{
Position ipos =
- new Position(baseName+"_pos_pos", xcenter, ycenter, zcenter);
+ new Position(baseName+"_pos_pos", xcenter, ycenter-my*margin+tolerance, zcenter-((margin-1)*mz)+tolerance);
Rotation irot =
new Rotation(baseName+"_rot_pos", thetax, -thetay, thetaz);
@@ -163,32 +181,40 @@
define.addRotation(irot);
// Place crystal.
- PhysVol posCrystalPlacement = new PhysVol(crystalLogVol, mother, ipos, irot);
+ PhysVol posCrystalPlacement = new PhysVol(crystalLogVol, momVol, ipos, irot);
// TODO Add PhysVolID.
// Reflection to negative.
if (ix != 0)
{
Position iposneg =
- new Position(baseName+"_pos_neg", -xcenter, ycenter, zcenter);
+ new Position(baseName+"_pos_neg", -xcenter, ycenter-my*margin+tolerance, zcenter-((margin-1)*mz)+tolerance);
Rotation irotneg =
new Rotation(baseName+"_rot_neg", thetax, thetay, thetaz);
define.addPosition(iposneg);
define.addRotation(irotneg);
- PhysVol negCrystalPlacement = new PhysVol(crystalLogVol, mother, iposneg, irotneg);
+ PhysVol negCrystalPlacement = new PhysVol(crystalLogVol, momVol, iposneg, irotneg);
// TODO Add PhysVolID.
}
//}
- // Increment running X and Z totals.
+ // Increment running X and Z totals and include tolerance to avoid overlaps.
xcorrtot += xcorr;
zcorrtotx += zcorrx;
}
-
+
// Increment running Y totals.
ycorrtot += ycorr;
zcorrtoty += zcorry;
}
+
+ // Mother volume placement.
+ Volume world = lcdd.pickMotherVolume(this);
+ Position mpos = new Position(momVol.getVolumeName() + "_pos", 0, 0, 0);
+ Rotation mrot = new Rotation(momVol.getVolumeName() + "_rot", 0, 0, 0);
+ define.addPosition(mpos);
+ define.addRotation(mrot);
+ new PhysVol(momVol, world, mpos, mrot);
}
}
\ No newline at end of file