Commit in projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd on MAIN | |||
HPSTestRunTracker2014LCDDBuilder.java | +320 | added 3201 |
First version of a LCDD converter partly using the new stand-alone builder class
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014LCDDBuilder.java (rev 0) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014LCDDBuilder.java 2014-07-24 23:01:22 UTC (rev 3201) @@ -0,0 +1,320 @@
+package org.lcsim.geometry.compact.converter.lcdd; + +import java.util.ArrayList; +import java.util.List; + +import hep.physics.vec.BasicHep3Vector; +import hep.physics.vec.Hep3Vector; +import hep.physics.vec.VecOp; + +import org.jdom.JDOMException; +import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeomDef.BaseGeom; +import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeomDef.TrackingBase; +import org.lcsim.geometry.compact.converter.lcdd.util.Box; +import org.lcsim.geometry.compact.converter.lcdd.util.LCDD; +import org.lcsim.geometry.compact.converter.lcdd.util.Material; +import org.lcsim.geometry.compact.converter.lcdd.util.PhysVol; +import org.lcsim.geometry.compact.converter.lcdd.util.Position; +import org.lcsim.geometry.compact.converter.lcdd.util.Rotation; +import org.lcsim.geometry.compact.converter.lcdd.util.Volume; + +/** + * Class used by LCDD converter to builder detector for SLIC + * + * @author Per Hansson Adrian <[log in to unmask]> + * + */ +public class HPSTestRunTracker2014LCDDBuilder extends HPSTestRunTracker2014Builder { + + + /** + * + * Base geometry class for holding LCDD geometry object definitions where no volume is built but used as reference. + * + * @author Per Hansson Adrian <[log in to unmask]> + * + */ + protected static class GhostBaseGeom extends BaseGeom { + + /** + * Initialize this object with a known volume and no mother. Typically the world volume would use this. + * @param base - object used to get geometry definitions + * @param vol - given volume + */ + public GhostBaseGeom(HPSTestRunTracker2014GeomDef.BaseGeom base, Volume volume) { + super(); + if(isDebug()) System.out.printf("%s: constructing LCDD ghost object %s\n", this.getClass().getSimpleName(),base.getName()); + setName(base.getName()); + setVolume(volume); + if(isDebug()) System.out.printf("%s: DONE constructing LCDD object %s\n", this.getClass().getSimpleName(),base.getName()); + } + + /** + * Initialize with base and mother. This is typically for a reference geometry object + * that is used for referencing coordinate systems but that doesn't have a volume itself. + * @param base - object used to get geometry definitions + * @param mother - mother LCDD object + */ + public GhostBaseGeom(HPSTestRunTracker2014GeomDef.BaseGeom base, BaseGeom mother) { + super(); + if(isDebug()) System.out.printf("%s: constructing LCDD ghost object %s with mother %s\n", this.getClass().getSimpleName(),base.getName(),mother==null?"null":mother.getName()); + setName(base.getName()); + setMother(mother); + if(isDebug()) System.out.printf("%s: DONE constructing LCDD object %s\n", this.getClass().getSimpleName(),base.getName()); + } + + } + + + + + + + protected static class BaseGeomVis { + protected String visName = ""; + public BaseGeomVis() {} + protected String getVisName() { + return visName; + } + protected void setVisName(String visName) { + this.visName = visName; + } + + + } + + + + + + + + + /** + * Base geometry class for holding LCDD geometry object definitions. + * + * @author Per Hansson Adrian <[log in to unmask]> + */ + protected static class BaseGeom extends BaseGeomVis { + private boolean debug = true; + private String name; + private Box box= null; + private Volume volume = null; + private Position pos = null; + private Rotation rot = null; + private PhysVol physVolume = null; + private LCDD lcdd = null; + private BaseGeom mother = null; + public List<BaseGeom> daughters = new ArrayList<BaseGeom>(); + /** + * Default constructor + */ + public BaseGeom() { + } + + /** + * Construct a LCDD geometry object from its geometry definition. + * @param base - input geometry definition + * @param lcdd - lcdd file + * @param mother - reference to mother LCDD definition + */ + public BaseGeom(HPSTestRunTracker2014GeomDef.BaseGeom base, LCDD lcdd, BaseGeom mother) { + if(isDebug()) System.out.printf("%s: constructing LCDD object %s with mother %s\n", this.getClass().getSimpleName(),base.getName(),mother==null?"null":mother.getName()); + this.lcdd = lcdd; + setName(base.getName()); + setMother(mother); + mother.addDaughter(this); + buildBox(base); + buildVolume(base); + setPosAndRot(base); + //buildPhysVolume(mother); + if(isDebug()) System.out.printf("%s: DONE constructing LCDD object %s\n", this.getClass().getSimpleName(),base.getName()); + } + + + protected void buildPhysVolume() { + if(isDebug()) System.out.printf("%s: build phys volume for %s\n", this.getClass().getSimpleName(),getName()); + setPhysVolume(new PhysVol(volume, getMother().getVolume(), getPos(), getRot())); + } + protected void buildBox(HPSTestRunTracker2014GeomDef.BaseGeom base) { + if(isDebug()) System.out.printf("%s: build box for %s\n", this.getClass().getSimpleName(),getName()); + setBox(new Box(getName() + "Box", base.getBoxDim().x(), base.getBoxDim().y(), base.getBoxDim().z())); + } + protected void buildVolume(HPSTestRunTracker2014GeomDef.BaseGeom base) { + if(isDebug()) System.out.printf("%s: build volume for %s with material %s\n", this.getClass().getSimpleName(),getName(),base.getMaterial()); + try { + Material mat = lcdd.getMaterial(base.getMaterial()); + setVolume(new Volume(getName() + "_volume", box, mat)); + } catch (JDOMException e) { + e.printStackTrace(); + } + } + protected void setPosAndRot(HPSTestRunTracker2014GeomDef.BaseGeom base) { + if(isDebug()) System.out.printf("%s: set position and rotation for volume %s\n", this.getClass().getSimpleName(),getName()); + // Vector from origin to center of box locally + Hep3Vector box_center_base_local = base.getCenter(); + //translate to the mother coordinate system + Hep3Vector box_center_base = base.getCoord().getTransformation().transformed(box_center_base_local); + // find the position of the center in the mother coord + Hep3Vector box_center = VecOp.sub(box_center_base, base.getMother().getCenter()); + // Create the LCDD position + setPos(new Position(getName() + "_position",box_center.x(), box_center.y(), box_center.z())); + //Find LCDD Euler rotation angles from coordinate system unit vectors + Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().v(), base.getCoord().w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1)); + setRot(new Rotation(getName() + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z())); + if(isDebug()) { + System.out.printf("%s: box_center_base_local %s\n", this.getClass().getSimpleName(), box_center_base_local.toString()); + System.out.printf("%s: box_center_base %s\n", this.getClass().getSimpleName(), box_center_base.toString()); + System.out.printf("%s: mother center %s\n", this.getClass().getSimpleName(), base.getMother().getCenter().toString()); + System.out.printf("%s: box_center %s\n", this.getClass().getSimpleName(), box_center.toString()); + System.out.printf("%s: pos %s\n", this.getClass().getSimpleName(), getPos().toString()); + System.out.printf("%s: euler %s\n", this.getClass().getSimpleName(), lcdd_rot_angles.toString()); + System.out.printf("%s: rot %s\n", this.getClass().getSimpleName(), getRot().toString()); + } + + } + protected Volume getVolume() { + return volume; + } + protected void setVolume(Volume volume) { + this.volume = volume; + } + protected Box getBox() { + return box; + } + protected void setBox(Box b) { + box = b; + } + protected String getName() { + return name; + } + protected void setName(String name) { + this.name = name; + } + protected Position getPos() { + return pos; + } + protected void setPos(Position pos) { + this.pos = pos; + } + protected Rotation getRot() { + return rot; + } + protected void setRot(Rotation rot) { + this.rot = rot; + } + protected BaseGeom getMother() { + return mother; + } + protected void setMother(BaseGeom mother) { + this.mother = mother; + } + protected PhysVol getPhysVolume() { + return physVolume; + } + protected void setPhysVolume(PhysVol physVolume) { + this.physVolume = physVolume; + } + public boolean isDebug() { + return debug; + } + + protected List<BaseGeom> getDaughters() { + return daughters; + } + + protected void addDaughter(BaseGeom o) { + getDaughters().add(o); + } + } + + + + + + + + + + + protected LCDD lcdd; + protected BaseGeom trackingLCDD; + protected BaseGeom baseLCDD; + protected BaseGeom basePlateLCDD; + protected BaseGeom cSupportLCDD; + protected BaseGeom supportBottomLCDD; + protected BaseGeom supportPlateBottomLCDD; + protected BaseGeom supportTopLCDD; + protected BaseGeom supportPlateTopLCDD; + protected List<BaseGeom> modulesLCDD; + + /** + * Default constructor + */ + public HPSTestRunTracker2014LCDDBuilder(boolean debugFlag) { + super(debugFlag); + } + + + protected void build(Volume worldVolume) { + // go through the list of volumes to build + if(isDebug()) System.out.printf("%s: build the LCDD geometry objects\n", getClass().getSimpleName()); + trackingLCDD = new GhostBaseGeom(getTracking(), worldVolume); + baseLCDD = new BaseGeom(getBase(), lcdd, trackingLCDD); + basePlateLCDD = new BaseGeom(getBasePlate(), lcdd, baseLCDD); + cSupportLCDD = new GhostBaseGeom(getcSupport(), baseLCDD); + supportBottomLCDD = new BaseGeom(getSupportBottom(), lcdd, baseLCDD); + supportPlateBottomLCDD = new BaseGeom(getSupportPlateBottom(), lcdd, supportBottomLCDD); + supportTopLCDD = new BaseGeom(getSupportTop(), lcdd, baseLCDD); + supportPlateTopLCDD = new BaseGeom(getSupportPlateTop(), lcdd, supportTopLCDD); + if(isDebug()) System.out.printf("%s: DONE building the LCDD geometry objects\n", getClass().getSimpleName()); + + modulesLCDD = new ArrayList<BaseGeom>(); + + //set lcdd vis + basePlateLCDD.setVisName("BasePlateVis"); + supportBottomLCDD.setVisName("SupportVolumeVis"); + supportTopLCDD.setVisName("SupportVolumeVis"); + supportPlateBottomLCDD.setVisName("SupportPlateVis"); + supportBottomLCDD.setVisName("SupportVolumeVis"); + + } + + protected void setLCDD(LCDD lcdd) { + this.lcdd = lcdd; + } + protected LCDD getLCDD() { + return lcdd; + } + + protected BaseGeom getTrackingLCDD() { + return trackingLCDD; + } + protected BaseGeom getBaseLCDD() { + return baseLCDD; + } + protected BaseGeom getBasePlateLCDD() { + return basePlateLCDD; + } + protected BaseGeom getcSupportLCDD() { + return cSupportLCDD; + } + protected BaseGeom getSupportBottomLCDD() { + return supportBottomLCDD; + } + protected BaseGeom getSupportPlateBottomLCDD() { + return supportPlateBottomLCDD; + } + protected BaseGeom getSupportTopLCDD() { + return supportTopLCDD; + } + protected BaseGeom getSupportPlateTopLCDD() { + return supportPlateTopLCDD; + } + protected List<BaseGeom> getModulesLCDD() { + return modulesLCDD; + } + + + +}
\ No newline at end of file
Use REPLY-ALL to reply to list
To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1