Author: [log in to unmask]
Date: Tue Feb 10 15:24:24 2015
New Revision: 3524
Log:
Small improvements to how position and geometry is found for hits.
Modified:
projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseCalorimeterHit.java
projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHit.java
projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimTrackerHit.java
Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseCalorimeterHit.java
=============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseCalorimeterHit.java (original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseCalorimeterHit.java Tue Feb 10 15:24:24 2015
@@ -84,10 +84,6 @@
public double getEnergyError() {
return energyError;
}
-
- public IDetectorElement getDetectorElement() {
- return detectorElement;
- }
protected void calculateCorrectedEnergy() {
getIDDecoder().setID(id);
Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHit.java
=============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHit.java (original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHit.java Tue Feb 10 15:24:24 2015
@@ -42,21 +42,8 @@
* Set the metadata associated with this hit.
*/
public void setMetaData(LCMetaData meta) {
-
- this.metaData = meta;
-
- if (this.detectorElement == null) {
- // If the DE is not set yet, try to look it up by ID (might be null).
- detectorElement = findDetectorElement(getIdentifier());
- }
-
- // Calculate the position of the hit. Might use DE.
- calculatePosition();
-
- if (this.detectorElement == null) {
- // If DE is still null, attempt to find it from the position.
- detectorElement = findDetectorElement(positionVec);
- }
+
+ this.metaData = meta;
}
/**
@@ -72,6 +59,18 @@
* @return The IDetectorElement for this hit.
*/
public IDetectorElement getDetectorElement() {
+ if (detectorElement == null) {
+ // Attempt to lookup the geometry using this exact ID.
+ detectorElement = findDetectorElement(getIdentifier());
+ if (detectorElement == null) {
+ // Presumably if the ID lookup fails, this means it has non-geometric fields,
+ // so use the global position instead.
+ if (getPositionVec() != null) {
+ detectorElement = findDetectorElement(getPositionVec());
+ }
+ // Just leave it as null!
+ }
+ }
return detectorElement;
}
@@ -79,7 +78,6 @@
* Set the @see org.lcsim.detector.IDetectorElement of this hit. By default, this will not override an
* existing value.
*/
- // FIXME: This probably should not be in the public API. Where is this actually called from?
public void setDetectorElement(IDetectorElement de) {
this.detectorElement = de;
}
@@ -164,6 +162,9 @@
* @return The position of this hit as a double array of size 3.
*/
public double[] getPosition() {
+ if (positionVec == null) {
+ calculatePosition();
+ }
return positionVec.v();
}
@@ -181,8 +182,8 @@
protected void calculatePosition() {
// Was there no position information provided explicitly?
if (positionVec == null) {
- // Does the hit ID match the DetectorElement exatly?
- if (this.detectorElement != null && this.detectorElement.getIdentifier().equals(getIdentifier())) {
+ // Does the hit ID match the DetectorElement exactly?
+ if (this.detectorElement != null && detectorElement.getIdentifier().equals(getIdentifier())) {
// Set the position from the DetectorElement.
this.positionVec = detectorElement.getGeometry().getPosition();
} else {
@@ -198,46 +199,49 @@
}
}
}
-
- /**
- * Find a DetectorElement by global position.
- * @param position The global position.
- * @return The DetectorElement at position.
- */
- private IDetectorElement findDetectorElement(Hep3Vector position) {
+
+ /**
+ * Find a DetectorElement by its identifier.
+ * @param id The identifier.
+ * @return The DetectorElement matching the identifier.
+ */
+ protected IDetectorElement findDetectorElement(IIdentifier id) {
IDetectorElement mommy = null;
if (this.metaData != null) {
// Use subdetector's volume as top.
mommy = this.getIDDecoder().getSubdetector().getDetectorElement();
}
if (mommy == null) {
- // Use the world volume.
- mommy = ((DetectorElement) DetectorElementStore.getInstance().get(0)).getTop().findDetectorElement(getPositionVec());
- }
- return mommy.findDetectorElement(this.positionVec);
- }
-
- /**
- * Find a DetectorElement by its identifier.
- * @param id The identifier.
- * @return The DetectorElement matching the identifier.
- */
- private IDetectorElement findDetectorElement(IIdentifier id) {
- IDetectorElement mommy = null;
- if (this.metaData != null) {
- // Use subdetector's volume as top.
- mommy = this.getIDDecoder().getSubdetector().getDetectorElement();
- }
- if (mommy == null) {
- // Use the world volume.
+ // Use the world volume as top.
mommy = ((DetectorElement) DetectorElementStore.getInstance().get(0)).getTop();
}
+
+ // Find DetectorElements with exactly matching ID.
IDetectorElementContainer detectorElements = mommy.findDetectorElement(id);
- // FIXME: Beware! The container can be null, which should be fixed at some point (detector-framework).
+
+ // FIXME: Beware! The container itself can be null, which should be fixed (detector-framework).
if (detectorElements != null && detectorElements.size() == 1) {
return detectorElements.get(0);
} else {
return null;
}
}
-}
+
+ /**
+ * Find a DetectorElement by its global Cartesian position.
+ * @param position The position.
+ * @return The DetectorElement at the position.
+ */
+ protected IDetectorElement findDetectorElement(Hep3Vector position) {
+ IDetectorElement mommy = null;
+ if (this.metaData != null) {
+ // Use subdetector's volume as top.
+ mommy = this.getIDDecoder().getSubdetector().getDetectorElement();
+ }
+ if (mommy == null) {
+ // Use the world volume.
+ mommy = ((DetectorElement) DetectorElementStore.getInstance().get(0)).getTop().findDetectorElement(getPositionVec());
+ }
+ return mommy.findDetectorElement(this.positionVec);
+ }
+}
Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimTrackerHit.java
=============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimTrackerHit.java (original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimTrackerHit.java Tue Feb 10 15:24:24 2015
@@ -156,7 +156,11 @@
* Get the {@see org.lcsim.detector.IDetectorElement} associated with this hit.
* @return The IDetectorElement for this hit.
*/
- public IDetectorElement getDetectorElement() {
+ public IDetectorElement getDetectorElement() {
+ if (detectorElement == null) {
+ // By default, use the hit's position to lookup the geometry.
+ detectorElement = findDetectorElement(this.getPositionVec());
+ }
return detectorElement;
}
}
########################################################################
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
|