lcsim/src/org/lcsim/recon/calorimetry
diff -N CalorimeterHitType.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CalorimeterHitType.java 5 Apr 2011 14:48:16 -0000 1.1
@@ -0,0 +1,98 @@
+package org.lcsim.recon.calorimetry;
+
+/**
+ * Helper class to encode/decode calorimeter hit types based on the ILD convention.
+ *
+ * @author <a href="mailto:[log in to unmask]">Christian Grefe</a>
+ */
+public class CalorimeterHitType {
+
+ protected int type;
+ protected static int fCaloType = 1;
+ protected static int fCaloID = 10;
+ protected static int fCaloLayout = 1000;
+ protected static int fLayer = 10000;
+
+ /**
+ * Constructor using type obtained from getType method.
+ */
+ public CalorimeterHitType(int type) {
+ this.type = type;
+ }
+
+ /**
+ * Constructor using calorimeter hit information
+ */
+ public CalorimeterHitType(CaloType c, CaloID i, Layout l, int layer) {
+ this.type = c.getValue() * fCaloType + i.getValue() * fCaloID + l.getValue() * fCaloLayout + layer * fLayer;
+ }
+
+ public int toInt() {
+ return type;
+ }
+
+ public CaloType caloType() {
+ return CaloType.values()[type % fCaloID];
+ }
+
+ public CaloID caloID() {
+ return CaloID.values()[(type % fCaloLayout) / fCaloID ];
+ }
+
+ public Layout layout() {
+ return Layout.values()[(type % fLayer) / fCaloLayout];
+ }
+
+ public int layer() {
+ return type / fLayer;
+ }
+
+ public enum CaloType {
+ em(0),
+ had(1),
+ muon(2);
+
+ private int _index;
+ private CaloType(int index) {
+ _index = index;
+ }
+ public int getValue() {
+ return _index;
+ }
+ }
+
+ public enum CaloID {
+ unknown(0),
+ ecal(1),
+ hcal(2),
+ yoke(3),
+ lcal(4),
+ lhcal(5),
+ bcal(6);
+
+ private int _index;
+ private CaloID(int index) {
+ _index = index;
+ }
+ public int getValue() {
+ return _index;
+ }
+ }
+
+ public enum Layout {
+ any(0),
+ barrel(1),
+ endcap(2),
+ plug(3),
+ ring(4);
+
+ private int _index;
+ private Layout(int index) {
+ _index = index;
+ }
+ public int getValue() {
+ return _index;
+ }
+ }
+
+}
lcsim/src/org/lcsim/recon/calorimetry
diff -N CalorimeterHitTypeDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CalorimeterHitTypeDriver.java 5 Apr 2011 14:48:16 -0000 1.1
@@ -0,0 +1,76 @@
+package org.lcsim.recon.calorimetry;
+
+import java.util.List;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.base.BaseCalorimeterHit;
+import org.lcsim.recon.calorimetry.CalorimeterHitType.CaloID;
+import org.lcsim.recon.calorimetry.CalorimeterHitType.CaloType;
+import org.lcsim.recon.calorimetry.CalorimeterHitType.Layout;
+import org.lcsim.util.Driver;
+
+/**
+ * Driver to set the type of all calorimeter hits according to their collection names.
+ *
+ * @author <a href="mailto:[log in to unmask]">Christian Grefe</a>
+ */
+public class CalorimeterHitTypeDriver extends Driver {
+
+ public CalorimeterHitTypeDriver() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ protected void process(EventHeader event) {
+
+ // get all calorimter hit collections
+ List<List<CalorimeterHit>> caloHitLists = event.get(CalorimeterHit.class);
+
+ for (List<CalorimeterHit> caloHitList : caloHitLists) {
+ String collectionName = event.getMetaData(caloHitList).getName().toLowerCase();
+ CaloType caloType;
+ CaloID caloID;
+ Layout layout;
+
+ if (collectionName.contains("ecal")) {
+ caloType = CaloType.em;
+ caloID = CaloID.ecal;
+ } else if (collectionName.contains("hcal")) {
+ caloType = CaloType.had;
+ caloID = CaloID.hcal;
+ } else if (collectionName.contains("muon")) {
+ caloType = CaloType.muon;
+ caloID = CaloID.yoke;
+ } else if (collectionName.contains("beamcal")) {
+ caloType = CaloType.em;
+ caloID = CaloID.bcal;
+ } else if (collectionName.contains("lumical")) {
+ caloType = CaloType.em;
+ caloID = CaloID.lcal;
+ } else {
+ caloType = CaloType.em;
+ caloID = CaloID.unknown;
+ }
+
+ if (collectionName.contains("barrel")) {
+ layout = Layout.barrel;
+ } else if (collectionName.contains("endcap")) {
+ layout = Layout.endcap;
+ } else if (collectionName.contains("plug")) {
+ caloType = CaloType.muon;
+ caloID = CaloID.yoke;
+ layout = Layout.plug;
+ } else {
+ layout = Layout.any;
+ }
+
+ for (CalorimeterHit caloHit : caloHitList) {
+ CalorimeterHitType cht = new CalorimeterHitType(caloType, caloID, layout, caloHit.getLayerNumber());
+ ((BaseCalorimeterHit)caloHit).setType(cht.toInt());
+ }
+ }
+
+ }
+
+}