Commit in lcsim/src/org/lcsim on MAIN | |||
event/Hit.java | +1 | -2 | 1.3 -> 1.4 |
event/base/BaseHit.java | +95 | -114 | 1.11 -> 1.12 |
/BaseHitWithPosition.java | +27 | -39 | 1.2 -> 1.3 |
/BaseLCSimEvent.java | +8 | -6 | 1.9 -> 1.10 |
/BaseSimTrackerHit.java | +4 | -4 | 1.16 -> 1.17 |
recon/tracking/digitization/sisim/config/SimTrackerHitReadoutDriver.java | +55 | -62 | 1.4 -> 1.5 |
util/lcio/SIOSimTrackerHit.java | +3 | -1 | 1.17 -> 1.18 |
+193 | -228 |
refactoring of base hit classes; DetectorElement lookup should now always be done with ID and not position
diff -u -r1.3 -r1.4 --- Hit.java 18 Mar 2009 03:52:06 -0000 1.3 +++ Hit.java 10 Jul 2012 00:11:23 -0000 1.4 @@ -5,8 +5,7 @@
import org.lcsim.detector.identifier.Identifiable; import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
-public interface Hit -extends HasMetaData, HasDetectorElement, Identifiable
+public interface Hit extends HasMetaData, HasDetectorElement, Identifiable
{ DetectorIdentifierHelper getDetectorIdentifierHelper();
diff -u -r1.11 -r1.12 --- BaseHit.java 30 Apr 2012 22:55:48 -0000 1.11 +++ BaseHit.java 10 Jul 2012 00:11:24 -0000 1.12 @@ -15,194 +15,175 @@
/** * A base class for hit-like objects.
+ *
* @author Jeremy McCormick <[log in to unmask]> */
-public abstract class BaseHit -implements Hit -{ - protected LCMetaData meta;
+public abstract class BaseHit implements Hit { + + protected LCMetaData meta;
protected IExpandedIdentifier expId; protected IIdentifier compactId; protected IDetectorElement de; /** * Get the metadata associated with this hit.
+ *
* @return The hit's metadata. */
- public LCMetaData getMetaData() - {
+ public LCMetaData getMetaData() {
return meta; } /**
- * Set the metadata associated with this hit. - * By default, this will not override an - * existing value. - */ - public void setMetaData(LCMetaData meta) - { - if (this.meta == null) - { - this.meta = meta; - }
+ * Set the metadata associated with this hit. By default, this will not override an existing value. + */ + public void setMetaData(LCMetaData meta) { + if (this.meta == null) { + this.meta = meta; + } + setupDetectorElement();
}
-
+
/** * Get the subdetector that this hit belongs to.
+ *
* @return The Subdetector of this hit. */
- public Subdetector getSubdetector() - {
+ public Subdetector getSubdetector() {
return getIDDecoder().getSubdetector(); } /**
- * Get the deepest {@see org.lcsim.detector.IDetectorElement} associated with this hit. - * If this is not set manually using {@see #setDetectorElement(IDetectorElement)} - * then the subdetector's DetectorElement is searched using the hit's identifier. - * @return The IDetectorElement for this hit. - */ - public IDetectorElement getDetectorElement() - { - if (de == null) - { - findDetectorElementByIdentifier(); - }
+ * Get the {@see org.lcsim.detector.IDetectorElement} associated with this hit. + * @return The IDetectorElement for this hit. + */ + public IDetectorElement getDetectorElement() {
return de; }
-
+
/**
- * Set the @see org.lcsim.detector.IDetectorElement of this hit. - * By default, this will not override an existing value.
+ * Set the @see org.lcsim.detector.IDetectorElement of this hit. By default, this will not override an + * existing value.
*/
- public void setDetectorElement(IDetectorElement de) - { - if (this.de == null) - { - this.de = de; - }
+ public void setDetectorElement(IDetectorElement de) { + if (this.de == null) { + this.de = de; + }
} /**
- * Get the {@see org.lcsim.detector.identifier.IExpandedIdentifier} - * of this hit. - * @return The <code>IExpandedIdentifier</code> of this hit.
+ * Get the {@see org.lcsim.detector.identifier.IExpandedIdentifier} of this hit. + * @return The expanded identifier of this hit.
*/
- public IExpandedIdentifier getExpandedIdentifier() - { - if (expId == null) - {
+ public IExpandedIdentifier getExpandedIdentifier() { + if (expId == null) {
expId = getIdentifierHelper().unpack(getIdentifier()); } return expId; } /**
- * Get the identifier of this hit.
+ * Get the identifier of this hit.
* @return The identifier of this hit. */
- public IIdentifier getIdentifier() - {
+ public IIdentifier getIdentifier() {
return compactId; } /**
- * Get the identifier helper of this hit.
+ * Get the identifier helper of this hit.
* @return The hit's identifier helper. */
- public IIdentifierHelper getIdentifierHelper() - {
+ public IIdentifierHelper getIdentifierHelper() {
return getSubdetector().getDetectorElement().getIdentifierHelper(); }
-
+
/**
- * Get the detector identifier helper of this hit.
+ * Get the detector identifier helper of this hit.
* @return The hit's detector identifier helper. */
- public DetectorIdentifierHelper getDetectorIdentifierHelper() - { - return (DetectorIdentifierHelper)getIdentifierHelper();
+ public DetectorIdentifierHelper getDetectorIdentifierHelper() { + return (DetectorIdentifierHelper)getIdentifierHelper();
} /**
- * Get the {@see org.lcsim.geometryIDDecoder} of this hit.
+ * Get the {@see org.lcsim.geometryIDDecoder} of this hit.
* @return The hit's id decoder. */
- public IDDecoder getIDDecoder() - {
+ public IDDecoder getIDDecoder() {
return meta.getIDDecoder(); }
-
+
/**
- * Get the layer number of this hit.
+ * Get the layer number of this hit.
* @return The layer number of this hit. */
- public int getLayerNumber() - { - return getIdentifierHelper().getValue(getIdentifier(), "layer");
+ public int getLayerNumber() { + return getIdentifierHelper().getValue(getIdentifier(), "layer");
}
- - /** - * Get the barrel flag of this hit.
+ + /** + * Get the barrel flag of this hit.
* @return The barrel flag of this hit. */
- public BarrelEndcapFlag getBarrelEndcapFlag() - { - return BarrelEndcapFlag - .createBarrelEndcapFlag( - getIdentifierHelper().getValue(getIdentifier(), "barrel"));
+ public BarrelEndcapFlag getBarrelEndcapFlag() { + return BarrelEndcapFlag.createBarrelEndcapFlag(getIdentifierHelper().getValue(getIdentifier(), "barrel"));
}
-
+
/** * Get the system id of this hit. * @return The system id of this hit. */
- public int getSystemId() - { - return getIdentifierHelper().getValue(getIdentifier(), "system");
+ public int getSystemId() { + return getIdentifierHelper().getValue(getIdentifier(), "system");
}
-
+
/**
- * Get a field value from the hit's identifier.
+ * Get a field value from the hit's identifier.
* @return The field value from the hit's identifier. */
- public int getIdentifierFieldValue(String field) - { - return getIdentifierHelper().getValue(getIdentifier(), field);
+ public int getIdentifierFieldValue(String field) { + return getIdentifierHelper().getValue(getIdentifier(), field);
}
-
+
/**
- * Use the {@link IIdentifier} associated with this hit to find its DetectorElement.
+ * Use the {@link IIdentifier} associated with this hit to find its DetectorElement + * in the geometry hierarchy and set a member variable to point to it.
*/
- private void findDetectorElementByIdentifier() - { - if (this.de == null) - { - IDetectorElementContainer srch = DetectorElementStore.getInstance().find(getIdentifier()); - - if (srch.size() == 0) - { - throw new RuntimeException("No DetectorElement found for SimTrackerHit with id <" + getIdentifier().toHexString() + ">."); - } - - if (srch.size() == 1) - { - this.de = srch.get(0); - } - - // This can happen sometimes, because the identifiers are not guaranteed to be unique across the detector hierarchy. - if (srch.size() > 1) - { - // Pick the first leaf DetectorElement that is found. - for (IDetectorElement xde : srch) - { - if (!xde.hasChildren()) - { - this.de = xde; - break; - } - } - }
+ private void findDetectorElementByIdentifier() { + if (this.de == null) { + IDetectorElementContainer srch = DetectorElementStore.getInstance().find(getIdentifier()); + + if (srch.size() == 0) { + throw new RuntimeException("No DetectorElement found for SimTrackerHit with id <" + getIdentifier().toHexString() + ">."); + } + + if (srch.size() == 1) { + this.de = srch.get(0); + } + + // This can happen sometimes, because the identifiers are not guaranteed to be unique. + if (srch.size() > 1) { + // Pick the first leaf DetectorElement. + for (IDetectorElement xde : srch) { + if (!xde.hasChildren()) { + this.de = xde; + break; + } + } + }
}
- }
+ } + + /** + * Setup link to the DetectorElement using the hit's ID. + */ + private void setupDetectorElement() { + try { + findDetectorElementByIdentifier(); + //System.out.println("Assigned DetectorElement <" + de.getName() + "> to hit."); + } catch (RuntimeException x) { + throw new RuntimeException("Failed to find DetectorElement for hit."); + } + }
}
\ No newline at end of file
diff -u -r1.2 -r1.3 --- BaseHitWithPosition.java 23 Apr 2009 23:09:53 -0000 1.2 +++ BaseHitWithPosition.java 10 Jul 2012 00:11:24 -0000 1.3 @@ -3,51 +3,39 @@
import hep.physics.vec.BasicHep3Vector; import hep.physics.vec.Hep3Vector;
-import org.lcsim.detector.IDetectorElement;
import org.lcsim.event.HitWithPosition;
-public abstract class BaseHitWithPosition extends BaseHit implements HitWithPosition -{ - protected Hep3Vector positionVec; - - /** - * Get the position of this hit in mm as a {@see hep.physics.vec.Hep3Vector}. - * Depends on implementation of {@see #getPosition()}. - * @return The vector position of the hit in mm. - */ - public Hep3Vector getPositionVec() - { - if (positionVec == null) - { - double[] p = getPosition(); - positionVec = new BasicHep3Vector(p[0],p[1],p[2]); - } - return positionVec;
+public abstract class BaseHitWithPosition extends BaseHit implements HitWithPosition { + + protected Hep3Vector positionVec; + + protected BaseHitWithPosition() {
}
- /** - * Override super's method in order to find the DetectorElement - * if the hit has a position.
+ protected BaseHitWithPosition(double[] position) { + if (position == null) + throw new IllegalArgumentException("The position points to null."); + positionVec = new BasicHep3Vector(position[0], position[1], position[2]); + } + + public void setPosition(double[] position) { + positionVec = new BasicHep3Vector(position[0], position[1], position[2]); + } + + /** + * Get the position of the hit. This may be different than the position of the hit's DetectorElement. + * @return The position of this hit as a double array of size 3.
*/
- public IDetectorElement getDetectorElement() - { - try - { - // First try id lookup using superclass's method, because it is fast. - super.getDetectorElement(); - } - catch (RuntimeException x) - { - // Id lookup failed. Try using the position. - de = getSubdetector().getDetectorElement().findDetectorElement(getPositionVec()); - } - return de;
+ public double[] getPosition() { + return positionVec.v();
} /**
- * Get the position of this hit in mm as a double array. - * Subclasses must implement this method. - * @return The position of this hit as a double array of size 3.
+ * Get the position of this hit in mm as a {@see hep.physics.vec.Hep3Vector}. + * @return The position vector of the hit in mm.
*/
- public abstract double[] getPosition(); -}
+ public Hep3Vector getPositionVec() { + return positionVec; + } + +}
\ No newline at end of file
diff -u -r1.9 -r1.10 --- BaseLCSimEvent.java 2 Jul 2012 21:50:17 -0000 1.9 +++ BaseLCSimEvent.java 10 Jul 2012 00:11:24 -0000 1.10 @@ -160,17 +160,19 @@
LCMetaData meta = new MetaData(name, type, flags, readoutName); metaDataMap.put(collection,meta);
+ setCollectionMetaData(collection, type, meta); + } + + private void setCollectionMetaData(List collection, Class type, LCMetaData meta) { + System.out.println("setCollectionMetaData");
// Set MetaData on collection objects.
- if (HasMetaData.class.isAssignableFrom(type)) - { - for (Object o : collection) - {
+ if (HasMetaData.class.isAssignableFrom(type)) { + for (Object o : collection) {
if (o instanceof HasMetaData) {
- // some types of objects may ignore this if meta is already set
((HasMetaData)o).setMetaData(meta); } }
- }
+ }
} protected void put(String name, List collection, Class type, int flags, Map intMap, Map floatMap, Map stringMap)
diff -u -r1.16 -r1.17 --- BaseSimTrackerHit.java 2 Sep 2011 00:19:43 -0000 1.16 +++ BaseSimTrackerHit.java 10 Jul 2012 00:11:24 -0000 1.17 @@ -14,7 +14,7 @@
/** * A concrete implementation of SimTrackerHit. * @author Jeremy McCormick
- * @version $Id: BaseSimTrackerHit.java,v 1.16 2011/09/02 00:19:43 jeremy Exp $
+ * @version $Id: BaseSimTrackerHit.java,v 1.17 2012/07/10 00:11:24 jeremy Exp $
*/ public class BaseSimTrackerHit extends BaseHitWithPosition implements SimTrackerHit {
@@ -58,14 +58,14 @@
LCMetaData meta, IDetectorElement de) {
- if (position == null) - throw new IllegalArgumentException("The position points to null!");
+ super(position); +
if (position.length != 3) throw new IllegalArgumentException("The position array is of the wrong size!"); for (int i=0, n=this.position.length; i < n; i++) { this.position[i] = position[i];
- }
+ }
if (momentum == null) throw new IllegalArgumentException("The momentum points to null!");
diff -u -r1.4 -r1.5 --- SimTrackerHitReadoutDriver.java 26 Mar 2012 17:04:10 -0000 1.4 +++ SimTrackerHitReadoutDriver.java 10 Jul 2012 00:11:24 -0000 1.5 @@ -4,87 +4,80 @@
import java.util.List; import org.lcsim.event.EventHeader;
+import org.lcsim.event.EventHeader.LCMetaData;
import org.lcsim.event.SimTrackerHit; /**
- * Assigns {@link org.lcsim.event.SimTrackerHit} objects to the readouts of their - * corresponding {@link org.lcsim.detector.IDetectorElement}.
+ * This Driver assigns {@link org.lcsim.event.SimTrackerHit} objects to the readouts + * of their corresponding {@link org.lcsim.detector.IDetectorElement}. + *
* @author jeremym */
-public class SimTrackerHitReadoutDriver extends CollectionHandler -{ - boolean needCleanupDriver = true; - static boolean debug = false; - - public SimTrackerHitReadoutDriver() - {} - - public SimTrackerHitReadoutDriver(List<String> collectionNames) - {
+public class SimTrackerHitReadoutDriver extends CollectionHandler { + + boolean needCleanupDriver = true; + static boolean debug = false; + + public SimTrackerHitReadoutDriver() { + } + + public SimTrackerHitReadoutDriver(List<String> collectionNames) {
super(collectionNames); }
- public SimTrackerHitReadoutDriver(String[] collectionNames) - {
+ public SimTrackerHitReadoutDriver(String[] collectionNames) {
super(collectionNames); }
- - public void setReadoutCollections(String[] collectionNames) - { - super.setCollections(collectionNames);
+ + public void setReadoutCollections(String[] collectionNames) { + super.setCollections(collectionNames);
}
- - public void setDebug(boolean debug) - { - SimTrackerHitReadoutDriver.debug = debug;
+ + public void setDebug(boolean debug) { + SimTrackerHitReadoutDriver.debug = debug;
}
- - public void startOfData() - { - if (needCleanupDriver) - { - add(new ReadoutCleanupDriver(new ArrayList<String>(collections))); - needCleanupDriver=false; - } - } - - protected void process(EventHeader header) - {
+ + public void startOfData() { + if (needCleanupDriver) { + add(new ReadoutCleanupDriver(new ArrayList<String>(collections))); + needCleanupDriver = false; + } + } + + protected void process(EventHeader header) {
super.process(header);
- - if (debug) - {
+ + if (debug) {
System.out.println(this.getClass().getSimpleName() + " - handling collections");
- - for (String cname : this.collections) - {
+ + for (String cname : this.collections) {
System.out.println(" " + cname); } }
-
+
List<List<SimTrackerHit>> collections = header.get(SimTrackerHit.class);
- for (List<SimTrackerHit> collection : collections) - { - if (canHandle(header.getMetaData(collection).getName())) - { - for (SimTrackerHit hit : collection) - { - if (hit.getDetectorElement() == null) - throw new RuntimeException("Can't find DetectorElement for hit!"); - hit.getDetectorElement().getReadout().addHit(hit); - if (debug) - { - System.out.println("driver assigned hit " + hit.getExpandedIdentifier().toString() + " to " + hit.getDetectorElement().getName() + " with id " + hit.getDetectorElement().getExpandedIdentifier().toString() + "."); - System.out.println(" hit raw: " + hit.getIdentifier().toHexString() + ", DE raw: " + hit.getDetectorElement().getIdentifier().toHexString()); - System.out.println(" hit pos: " + hit.getPositionVec().toString() + ", DE pos: " + hit.getDetectorElement().getGeometry().getPosition().toString()); - System.out.println(); - if (!hit.getDetectorElement().getReadout().getHits(SimTrackerHit.class).contains(hit)) - { - throw new RuntimeException("Readout of " + hit.getDetectorElement().getName() + " is missing a SimTrackerHit that points to it."); - } - }
+ for (List<SimTrackerHit> collection : collections) { + LCMetaData meta = header.getMetaData(collection); + if (canHandle(meta.getName())) { + for (SimTrackerHit hit : collection) { + hit.setMetaData(meta); + hit.getDetectorElement().getReadout().addHit(hit); + if (debug) { + System.out.println("Driver assigned hit " + hit.getExpandedIdentifier().toString() + " to " + + hit.getDetectorElement().getName() + " with id " + hit.getDetectorElement().getExpandedIdentifier().toString() + + "."); + System.out.println(" hit raw: " + hit.getIdentifier().toHexString() + ", DE raw: " + + hit.getDetectorElement().getIdentifier().toHexString()); + System.out.println(" hit pos: " + hit.getPositionVec().toString() + ", DE pos: " + + hit.getDetectorElement().getGeometry().getPosition().toString()); + System.out.println(); + if (!hit.getDetectorElement().getReadout().getHits(SimTrackerHit.class).contains(hit)) { + throw new RuntimeException("Readout of " + hit.getDetectorElement().getName() + + " is missing a SimTrackerHit that points to it."); + } + }
} }
- }
+ }
} }
\ No newline at end of file
diff -u -r1.17 -r1.18 --- SIOSimTrackerHit.java 2 Sep 2011 00:19:43 -0000 1.17 +++ SIOSimTrackerHit.java 10 Jul 2012 00:11:24 -0000 1.18 @@ -3,6 +3,7 @@
import hep.io.sio.SIOInputStream; import hep.io.sio.SIOOutputStream; import hep.io.sio.SIORef;
+import hep.physics.vec.BasicHep3Vector;
import java.io.IOException;
@@ -15,7 +16,7 @@
* The SIO implementation of {@link org.lcsim.event.SimTrackerHit}. * @author Tony Johnson * @author Jeremy McCormick
- * @version $Id: SIOSimTrackerHit.java,v 1.17 2011/09/02 00:19:43 jeremy Exp $
+ * @version $Id: SIOSimTrackerHit.java,v 1.18 2012/07/10 00:11:24 jeremy Exp $
*/ class SIOSimTrackerHit extends BaseSimTrackerHit {
@@ -43,6 +44,7 @@
position[0] = in.readDouble(); position[1] = in.readDouble(); position[2] = in.readDouble();
+ setPosition(position);
// Energy. dEdx = in.readFloat();
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1