GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
diff -N LCDDFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LCDDFactory.java 19 Jan 2006 01:57:02 -0000 1.1
@@ -0,0 +1,415 @@
+package org.lcsim.geometry.compact.converter.lcdd.util;
+
+import org.lcsim.geometry.compact.converter.lcdd.util.*;
+import java.util.List;
+
+/*
+ *
+ * LCDD object factory.
+ *
+ * @author jeremym
+ * @version $Id: LCDDFactory.java,v 1.1 2006/01/19 01:57:02 jeremy Exp $
+ */
+public final class LCDDFactory
+{
+ private LCDD _lcdd;
+
+ boolean _autoAdd = false;
+
+ public void setLCDD(LCDD lcdd)
+ {
+ _lcdd = lcdd;
+ }
+
+ public void setAutoAdd(boolean autoAdd)
+ {
+ _autoAdd = autoAdd;
+ }
+
+ // top-level LCDD container element
+
+ public LCDD createLCDD()
+ {
+ LCDD lcdd = new LCDD();
+ return lcdd;
+ }
+
+ // header elements
+
+ public Detector createDetector(
+ String title,
+ String version,
+ String url)
+ {
+ Detector det = new Detector();
+ det.setTitle(title);
+ det.setVersion(version);
+ det.setURL(url);
+ return det;
+ }
+
+ public Author createAuthor(
+ String name,
+ String email)
+ {
+ Author author = new Author();
+ author.setName(name);
+ author.setAuthorEmail(email);
+ return author;
+ }
+
+ public Generator createGenerator(
+ String title,
+ String version,
+ String file,
+ long checksum)
+ {
+ Generator generator = new Generator();
+ generator.setTitle(title);
+ generator.setVersion(version);
+ generator.setFile(file);
+ generator.setChecksum(checksum);
+ return generator;
+ }
+
+ public Header createHeader(String comment)
+ {
+ Header header = new Header();
+ header.setComment(comment);
+ return header;
+ }
+
+ public Box createBox(String name, double x, double y, double z)
+ {
+ Box box = new Box(name);
+ box.setX(x);
+ box.setY(y);
+ box.setZ(z);
+ return box;
+ }
+
+ public Tube createTube(String name, double rmin, double rmax, double z,
+ double deltaphi)
+ {
+ Tube tube = new Tube(name);
+ tube.setRMax(rmax);
+ tube.setRMin(rmin);
+ tube.setZ(z);
+ tube.setDeltaPhi(deltaphi);
+ return tube;
+ }
+
+ public Trapezoid createTrapezoid(
+ String name,
+ double x1,
+ double x2,
+ double y1,
+ double y2,
+ double z)
+ {
+ Trapezoid trd = new Trapezoid(name);
+ trd.setX1(x1);
+ trd.setX2(x2);
+ trd.setY1(y1);
+ trd.setY2(y2);
+ trd.setZ(z);
+ return trd;
+ }
+
+ public SubtractionSolid createSubtractionSolid(
+ String name,
+ Solid first,
+ Solid second,
+ Position pos,
+ Rotation rot)
+ {
+ SubtractionSolid sub = new SubtractionSolid(name);
+ sub.setFirstSolid(first);
+ sub.setSecondSolid(second);
+ sub.setPosition(pos);
+ sub.setRotation(rot);
+ return sub;
+ }
+
+ // Volume
+
+ public Volume createVolume(String name, Material material, Solid solid)
+ {
+ Volume volume = new Volume(name);
+ volume.setMaterial(material);
+ volume.setSolid(solid);
+ return volume;
+ }
+
+ public Volume createVolume(String name, Material material, Solid solid,
+ SensitiveDetector sd, Region region, LimitSet limits,
+ List<PhysVol> pvs)
+ {
+ Volume volume = createVolume(name, material, solid);
+
+ volume.setSensitiveDetector(sd);
+ volume.setRegion(region);
+ volume.setRegion(region);
+
+ if (pvs != null)
+ {
+ for (PhysVol pv : pvs)
+ {
+ volume.addPhysVol(pv);
+ }
+ }
+
+ return volume;
+ }
+
+ public Constant createConstant(String name, double value)
+ {
+ Constant constant = new Constant(name, value);
+ return constant;
+ }
+
+ public Constant createConstant(String name, String value)
+ {
+ Constant constant = new Constant(name, value);
+ return constant;
+ }
+
+ public IDField createIDField(String label, int start, int length,
+ boolean signed)
+ {
+ IDField field = new IDField();
+ field.setLabel(label);
+ field.setStart(start);
+ field.setLength(length);
+ field.setSigned(signed);
+ return field;
+ }
+
+ public IDSpec createIDSpec(String name, int length, List<IDField> fields)
+ {
+ IDSpec spec = new IDSpec(name);
+ spec.setLength(length);
+ if (fields != null)
+ {
+ for (IDField field : fields)
+ {
+ spec.addIDField(field);
+ }
+ }
+ return spec;
+ }
+
+ public Limit createLimit(
+ String name,
+ String particles,
+ double value,
+ String unit)
+ {
+ Limit limit = new Limit(name);
+ limit.setParticles(particles);
+ limit.setValue(value);
+ limit.setUnit(unit);
+ return limit;
+ }
+
+ public LimitSet createLimitSet(String name, List<Limit> limits)
+ {
+ LimitSet limitset = new LimitSet(name);
+ if (limits != null)
+ {
+ for (Limit limit : limits)
+ {
+ limitset.addLimit(limit);
+ }
+ }
+ return limitset;
+ }
+
+ public Material createMaterial(String name)
+ {
+ Material material = new Material(name);
+ return material;
+ }
+
+ public PhysVol createPhysVol(Volume volume, Position position,
+ Rotation rotation, List<PhysVolID> ids)
+ {
+ PhysVol pv = new PhysVol();
+ pv.setVolume(volume);
+ pv.setPosition(position);
+ pv.setRotation(rotation);
+ if (ids != null)
+ {
+ for (PhysVolID id : ids)
+ {
+ pv.addPhysVolID(id);
+ }
+ }
+ return pv;
+ }
+
+ public Polycone createPolycone(String name, double startPhi,
+ double deltaPhi, List<ZPlane> zplanes)
+ {
+ Polycone polycone = new Polycone(name);
+ polycone.setStartPhi(startPhi);
+ polycone.setDeltaPhi(deltaPhi);
+ if (zplanes != null)
+ {
+ for (ZPlane zplane : zplanes)
+ {
+ polycone.addZPlane(zplane);
+ }
+ }
+ return polycone;
+ }
+
+ public PolyhedraRegular createPolyhedraRegular(String name, int nsides,
+ double rmin, double rmax, double zlength)
+ {
+ PolyhedraRegular polyhedra = new PolyhedraRegular(name, nsides, rmin,
+ rmax, zlength);
+ return polyhedra;
+ }
+
+ public ZPlane createZPlane(double rmin, double rmax, double z)
+ {
+ ZPlane zplane = new ZPlane(rmin, rmax, z);
+ return zplane;
+ }
+
+ public Position createPosition(String name, double x, double y, double z)
+ {
+ Position position = new Position(name);
+ position.setX(x);
+ position.setY(y);
+ position.setZ(z);
+ return position;
+ }
+
+ // detectors
+
+ public Calorimeter createCalorimeter(String name, Segmentation seg)
+ {
+ Calorimeter cal = new Calorimeter(name);
+ cal.setSegmentation(seg);
+ return cal;
+ }
+
+ public Tracker createTracker(String name)
+ {
+ Tracker trk = new Tracker(name);
+ return trk;
+ }
+
+ // segmentations
+
+ public ProjectiveCylinder createProjectiveCylinder(int ntheta, int nphi)
+ {
+ ProjectiveCylinder seg = new ProjectiveCylinder();
+ seg.setNTheta(ntheta);
+ seg.setNPhi(nphi);
+ return seg;
+ }
+
+ public ProjectiveZPlane createProjectiveZPlane(int ntheta, int nphi)
+ {
+ ProjectiveZPlane seg = new ProjectiveZPlane();
+ seg.setNTheta(ntheta);
+ seg.setNPhi(nphi);
+ return seg;
+ }
+
+ public GridXYZ createGridXYZ(double x, double y, double z)
+ {
+ GridXYZ seg = new GridXYZ();
+ seg.setGridSizeX(x);
+ seg.setGridSizeY(y);
+ seg.setGridSizeZ(z);
+ return seg;
+ }
+
+ public NonprojectiveCylinder createNonprojectiveCylinder(double gridSizeZ,
+ double gridSizePhi)
+ {
+ NonprojectiveCylinder seg = new NonprojectiveCylinder();
+ seg.setGridSizeZ(gridSizeZ);
+ seg.setGridSizePhi(gridSizePhi);
+ return seg;
+ }
+
+ public Region createRegion(
+ String name,
+ boolean storeSecondaries,
+ double energyCut,
+ double rangeCut,
+ String eunit,
+ String lunit)
+ {
+ Region region = new Region(name);
+ region.setStoreSecondaries(storeSecondaries);
+ region.setThreshold(energyCut);
+ region.setCut(rangeCut);
+ region.setEnergyUnit(eunit);
+ region.setLengthUnit(lunit);
+ return region;
+ }
+
+ public Rotation createRotation(
+ String name,
+ double x,
+ double y,
+ double z)
+ {
+ Rotation rot = new Rotation(name);
+ rot.setX(x);
+ rot.setY(y);
+ rot.setZ(z);
+ return rot;
+ }
+
+ // mag field
+
+ public Solenoid createSolenoid(
+ String name,
+ double BInner,
+ double BOuter,
+ double rInner,
+ double zMax)
+ {
+ Solenoid sol = new Solenoid(name);
+ sol.setInnerField(BInner);
+ sol.setOuterField(BOuter);
+ sol.setInnerRadius(rInner);
+ sol.setZMax(zMax);
+ return sol;
+ }
+
+ public RZFieldMap createRZFieldMap(
+ String name,
+ int numBinsR,
+ int numBinsZ,
+ double gridSizeR,
+ double gridSizeZ,
+ String lunit,
+ String funit,
+ List<RZBData> data
+ )
+ {
+ RZFieldMap field = new RZFieldMap(name);
+ field.setNumBinsR(numBinsR);
+ field.setNumBinsZ(numBinsZ);
+ field.setGridSizeR(gridSizeR);
+ field.setGridSizeZ(gridSizeZ);
+ field.setLengthUnit(lunit);
+ field.setFieldUnit(funit);
+ if ( data != null )
+ {
+ for ( RZBData rzb : data )
+ {
+ field.addRZBData(rzb);
+ }
+ }
+ return field;
+ }
+}