lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/geom
diff -u -r1.5 -r1.6
--- CalGeometry.java 19 Mar 2009 19:08:22 -0000 1.5
+++ CalGeometry.java 21 Mar 2009 05:27:49 -0000 1.6
@@ -24,9 +24,18 @@
* Provides various calorimeter geometry related services to other classes.
* Singleton of this class is available at run time through {@link JobManager} by
* calling <tt>JobManager.defaultInstance().get(CalGeometry.class)</tt>.
+ * <p>
+ * An object of a concrete extension of this class must be instantiated and passed
+ * to {@link org.lcsim.contrib.onoprien.crux.recon.CalorimeterDriver}. The extending
+ * class must implement abstract methods {@link #getModules()},
+ * {@link #nextLayers(Trajectory) nextLayers(Trajectory)}, and
+ * {@link #nextLayers(CalLayer, Trajectory) nextLayers(CalLayer, Trajectory)}, dividing
+ * the calorimeter into modules and defining neighbor relations between them. Default
+ * implementation capabale of handling simple geometries
+ * is available - see {@link DefaultCalGeometry}.
*
* @author D. Onoprienko
- * @version $Id: CalGeometry.java,v 1.5 2009/03/19 19:08:22 onoprien Exp $
+ * @version $Id: CalGeometry.java,v 1.6 2009/03/21 05:27:49 onoprien Exp $
*/
abstract public class CalGeometry implements JobEventListener {
@@ -49,6 +58,7 @@
_de2cl.put(layer.getDetectorElement(), layer);
}
}
+ //printModules();
}
@@ -193,7 +203,7 @@
double zHalf = tube.getZHalfLength();
Hep3Vector pos = gInfo.getPosition();
double z = pos.z();
- if (pos.x() > Double.MIN_VALUE || pos.y() > Double.MIN_VALUE) {
+ if (pos.x() > 0.001 || pos.y() > 0.001) {
throw new IllegalArgumentException("Cannot create reference surface for Tube at position "+ pos);
}
if (Math.abs(z) < zHalf) { // barrel cylinder
@@ -206,4 +216,21 @@
}
}
+// -- Diagnostics : -----------------------------------------------------------
+
+ private void printModules() {
+ System.out.println("");
+ System.out.println("Modules");
+ for (CalModule module : getModules()) {
+ System.out.println("");
+ System.out.println("Module "+ module.getName() +
+ " subd "+ module.getSubdetector().getName() +" att "+ module.getAttributes());
+ System.out.println("");
+ for (CalLayer layer : module.getLayers()) {
+ System.out.println("Layer "+ layer.getLayerID() +" ordinal "+ layer.getLayerOrdinal() +
+ " decoded "+ layer.getLayerDecoded() +" de "+ layer.getDetectorElement().getName());
+ }
+ }
+ }
+
}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/geom
diff -u -r1.1 -r1.2
--- DefaultCalGeometry.java 19 Mar 2009 06:08:03 -0000 1.1
+++ DefaultCalGeometry.java 21 Mar 2009 05:27:49 -0000 1.2
@@ -5,6 +5,7 @@
import hep.physics.vec.Hep3Vector;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.IDetectorElementVisitor;
+import org.lcsim.detector.IGeometryInfo;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.geometry.IDDecoder;
import org.lcsim.geometry.Detector;
@@ -24,15 +25,18 @@
/**
* Default implementation of {@link CalGeometry}.
* Optimized implementations can be written for particular detectors to improve performance.
+ * <p>
+ * Currently, this class can only handle cylindrical calorimeters. 6 modules are created,
+ * one for each endcap and one for the barrel, both for ECAL and HCAL.
*
* @author D. Onoprienko
- * @version $Id: DefaultCalGeometry.java,v 1.1 2009/03/19 06:08:03 onoprien Exp $
+ * @version $Id: DefaultCalGeometry.java,v 1.2 2009/03/21 05:27:49 onoprien Exp $
*/
public class DefaultCalGeometry extends CalGeometry implements JobEventListener {
// -- Private parts : ---------------------------------------------------------
- private ArrayList<CalModule> _modules;
+ private List<CalModule> _modules;
private ArrayList<List<CalModule>> _previousModules;
private ArrayList<List<CalModule>> _nextModules;
@@ -44,77 +48,22 @@
}
public void detectorChanged(JobEvent jEvent) {
- moduleInit(jEvent);
- super.detectorChanged(jEvent);
- }
-
-
-// -- Implementing CalGeometry : ----------------------------------------------
-
- /** Returns an unmodifiable list of calorimeter modules, ordered by module ID. */
- public List<CalModule> getModules() {
- return Collections.unmodifiableList(_modules);
- }
-
- /**
- * Returns a list of layers the specified trajectory might cross after coming out of the
- * given layer - more likely first. The origin of the trajectory should belong to the
- * specified layer - no checking is done.
- */
- public List<CalLayer> nextLayers(CalLayer layer, Trajectory trajectory) {
- Surface surface = layer.getReferenceSurface();
- Hep3Vector dir = trajectory.getDirection();
- Hep3Vector pos = trajectory.getPosition();
- double dirSign;
- if (surface instanceof ZDisk) {
- dirSign = dir.z()*pos.z();
- } else {
- dirSign = pos.x()*dir.x() + pos.y()*dir.y();
- }
- int iDirSign = (int) Math.signum(dirSign);
- CalModule module = layer.getModule();
- CalLayer nextLayer = module.getLayerByOrdinal(layer.getLayerOrdinal()+iDirSign);
- ArrayList<CalLayer> out = new ArrayList<CalLayer>();
- if (nextLayer == null) {
- if (iDirSign > 0) {
- List<CalModule> nextModules = _nextModules.get(module.getID());
- for (CalModule mod : nextModules) out.add(mod.getLayerByOrdinal(0));
- } else {
- List<CalModule> nextModules = _previousModules.get(module.getID());
- for (CalModule mod : nextModules) out.add(mod.getLayerByOrdinal(mod.getLayers().size()-1));
- }
- } else {
- out.add(nextLayer);
- }
- return out;
- }
-
- /**
- * Returns a list of layers the specified trajectory might cross next - more likely first.
- */
- public List<CalLayer> nextLayers(Trajectory trajectory) {
- throw new UnsupportedOperationException();
- }
-
-
-// -- Division of calorimeter into modules : ----------------------------------
-
- protected void moduleInit(JobEvent jEvent) {
// create modules
-
+
CalModule eBar = new CalModule("ECAL_BARREL", EnumSet.of(ECAL, BARREL, ENTRY), "EMBarrel");
CalModule hBar = new CalModule("HCAL_BARREL", EnumSet.of(HCAL, BARREL, EXIT), "HADBarrel");
CalModule eSouthEnd = new CalModule("ECAL_ENDCAP_SOUTH", EnumSet.of(ECAL, ENDCAP, SOUTH, ENTRY), "EMEndcap");
CalModule eNorthEnd = new CalModule("ECAL_ENDCAP_NORTH", EnumSet.of(ECAL, ENDCAP, NORTH, ENTRY), "EMEndcap");
CalModule hSouthEnd = new CalModule("HCAL_ENDCAP_SOUTH", EnumSet.of(HCAL, ENDCAP, SOUTH, EXIT), "HADEndcap");
CalModule hNorthEnd = new CalModule("HCAL_ENDCAP_NORTH", EnumSet.of(HCAL, ENDCAP, NORTH, EXIT), "HADEndcap");
-
+
_modules = new ArrayList<CalModule>(6);
Collections.addAll(_modules, eBar, hBar, eSouthEnd, eNorthEnd, hSouthEnd, hNorthEnd);
-
+ _modules = Collections.unmodifiableList(_modules);
+
// neighbors
-
+
List<CalModule> emptyList = Collections.emptyList();
_previousModules = new ArrayList<List<CalModule>>(6);
Collections.addAll( _previousModules,
@@ -134,34 +83,43 @@
emptyList,
emptyList
);
-
- // assign DetectorElements
-
+
+ // create layers
+
Detector det = jEvent.getDetector();
int idOffset = 0;
int moduleID = 0;
- for (CalModule module : _modules) {
+ for (final CalModule module : _modules) {
Subdetector sd = det.getSubdetector(module.getSubdetectorName());
final List<IDetectorElement> deList = new ArrayList<IDetectorElement>(50);
sd.getDetectorElement().traverseDescendantsPreOrder(new IDetectorElementVisitor() {
public void visit(IDetectorElement de) {
- String name = de.getName();
- if (name.contains("layer") || name.contains("sensor")) {
- deList.add(de);
+ if (de.isSensitive()) {
+ if (module.isBarrel()) {
+ deList.add(de);
+ } else {
+ IGeometryInfo gInfo = de.getGeometry();
+ double z = gInfo.getPosition().z();
+ if ((z > 0. && module.isNorth()) || (z < 0. && module.isSouth())) {
+ deList.add(de);
+ }
+ }
}
}
public boolean isDone() {return false;}
});
TreeMap<Integer, IDetectorElement> deMap = new TreeMap<Integer, IDetectorElement>();
for (IDetectorElement de : deList) {
+
+ //int idLayerIndex = de.getIdentifierHelper().getFieldIndex("layer");
+ //int layer = de.getExpandedIdentifier().getValue(idLayerIndex);
String name = de.getName();
- if (module.isBarrel() ||
- ((name.contains("negative") && module.isSouth()) || (name.contains("positive") && module.isNorth()))) {
- name = name.replaceFirst(".*layer","");
- name = name.replaceFirst(".*sensor","");
- int layer = Integer.parseInt(name);
- deMap.put(layer, de);
- }
+ name = name.replaceFirst(".*layer","");
+ name = name.replaceFirst("_.*","");
+ int layer = Integer.parseInt(name);
+
+ IDetectorElement duplicate = deMap.put(layer, de);
+ if (duplicate != null) throw new RuntimeException("More than 1 DetectorElement in the same layer");
}
ArrayList<CalLayer> layerList = new ArrayList<CalLayer>(deMap.size());
int ordinal = 0;
@@ -174,6 +132,58 @@
module.initialize(moduleID++, sd, layerList);
idOffset += layerList.size();
}
+
+ // CalGeometry initialization
+
+ super.detectorChanged(jEvent);
+ }
+
+
+// -- Implementing CalGeometry : ----------------------------------------------
+
+ /** Returns an unmodifiable list of calorimeter modules, ordered by module ID. */
+ public List<CalModule> getModules() {
+ return _modules;
+ }
+
+ /**
+ * Returns a list of layers the specified trajectory might cross after coming out of the
+ * given layer - more likely first. The origin of the trajectory should belong to the
+ * specified layer - no checking is done.
+ */
+ public List<CalLayer> nextLayers(CalLayer layer, Trajectory trajectory) {
+ Surface surface = layer.getReferenceSurface();
+ Hep3Vector dir = trajectory.getDirection();
+ Hep3Vector pos = trajectory.getPosition();
+ double dirSign;
+ if (surface instanceof ZDisk) {
+ dirSign = dir.z()*pos.z();
+ } else {
+ dirSign = pos.x()*dir.x() + pos.y()*dir.y();
+ }
+ int iDirSign = (int) Math.signum(dirSign);
+ CalModule module = layer.getModule();
+ CalLayer nextLayer = module.getLayerByOrdinal(layer.getLayerOrdinal()+iDirSign);
+ ArrayList<CalLayer> out = new ArrayList<CalLayer>();
+ if (nextLayer == null) {
+ if (iDirSign > 0) {
+ List<CalModule> nextModules = _nextModules.get(module.getID());
+ for (CalModule mod : nextModules) out.add(mod.getLayerByOrdinal(0));
+ } else {
+ List<CalModule> nextModules = _previousModules.get(module.getID());
+ for (CalModule mod : nextModules) out.add(mod.getLayerByOrdinal(mod.getLayers().size()-1));
+ }
+ } else {
+ out.add(nextLayer);
+ }
+ return out;
+ }
+
+ /**
+ * Returns a list of layers the specified trajectory might cross next - more likely first.
+ */
+ public List<CalLayer> nextLayers(Trajectory trajectory) {
+ throw new UnsupportedOperationException();
}
}