1 added + 9 modified, total 10 files
GeomConverter/src/org/lcsim/geometry
diff -u -r1.9 -r1.10
--- Calorimeter.java 18 Jan 2006 01:46:24 -0000 1.9
+++ Calorimeter.java 1 Feb 2006 01:33:16 -0000 1.10
@@ -3,14 +3,11 @@
import org.lcsim.geometry.util.CalorimeterIDDecoder;
/**
- *
+ *
* @author tonyj
*/
public interface Calorimeter extends Subdetector
-{
- CalorimeterIDDecoder getCalorimeterIDDecoder();
- CalorimeterType getCalorimeterType();
- // Fixme: This would make sense, but is not provided by compact reader
- // so cannot go here.
- // double getSamplingFraction();
+{
+ CalorimeterIDDecoder getCalorimeterIDDecoder();
+ CalorimeterType getCalorimeterType();
}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry/compact
diff -u -r1.3 -r1.4
--- ParameterSet.java 18 Jan 2006 22:46:20 -0000 1.3
+++ ParameterSet.java 1 Feb 2006 01:33:16 -0000 1.4
@@ -6,147 +6,180 @@
import org.jdom.Element;
/**
- *
- * ParameterSet is used to store generic subdetector parameters
- * within the compact Subdetector object. Values are converted
- * from <parameter> elements within the <detector> element. The
- * parameters can be of type Double, Integer, or String.
- *
+ *
+ * ParameterSet is used to store generic subdetector parameters within the
+ * compact Subdetector object. Values are converted from <parameter> elements
+ * within the <detector> element. The parameters can be of type Double, Integer,
+ * or String.
+ *
* @author jeremym
- * @version $Id: ParameterSet.java,v 1.3 2006/01/18 22:46:20 jeremy Exp $
+ * @version $Id: ParameterSet.java,v 1.4 2006/02/01 01:33:16 jeremy Exp $
*/
public class ParameterSet
{
- /* Map for storing and looking up parameters by name. */
- Map<String, Object> _parameters = new HashMap<String, Object>();
-
- /** Constructor taking the <detector> node for a subdetector. */
- protected ParameterSet(Element node)
- {
- convertFromXML(node);
- }
-
- /** Convert <parameter> elements within <detector>. */
- private void convertFromXML(Element node)
- {
- assert(node != null);
- assert(node.getName().compareTo("detector") == 0);
-
- // Iterate over <parameter> elements
- for ( Object object : node.getChildren("parameter") )
- {
- Element element = (Element) object;
-
- // Get name
- String name = element.getAttributeValue("name");
- assert(name != null);
-
- // Get parameter type
- String type = element.getAttributeValue("type");
- assert(type != null);
-
- // Get parameter value (can be null)
- String value = element.getAttributeValue("value");
-
- // Get value from text data within the tag if no value attribute exists
- if ( value == null )
- {
- value = element.getTextNormalize();
- }
-
- Object convert = null;
-
- // Convert to Double
- if ( type.compareToIgnoreCase("double") == 0 )
- {
- convert = Double.parseDouble(value);
- }
- // Convert to Integer
- else if ( type.compareToIgnoreCase("integer") == 0 || type.compareToIgnoreCase("int") == 0 )
- {
- convert = Integer.parseInt(value);
- }
- // Convert to String
- else if ( type.compareToIgnoreCase("string") == 0 ) {
- convert = value;
- }
- // Type is invalid
- else {
- throw new RuntimeException("Unknown parameter type " + type);
- }
-
- // add the parameter
- addParameter(name, convert);
- //System.out.println("added parameter " + name + "=" + convert.toString() );
- }
- }
-
- /** Constructor without Element argument. */
- protected ParameterSet()
- {}
-
- /** Add a parameter to the ParameterSet, checking that the type is valid. */
- protected void addParameter(String name, Object object)
- {
- if ( object instanceof Double || object instanceof Integer || object instanceof String )
- {
- if ( _parameters.get(name) == null )
- {
- _parameters.put(name, object);
- }
- else
- {
- throw new RuntimeException("Parameter " + name + " already exists in this ParameterSet.");
- }
- }
- else
- {
- throw new RuntimeException("Parameter " + name + " is not of type Double, Integer or String.");
- }
- }
-
- /** Return a named parameter as a generic java Object. */
- public Object getParameter(String name, Class klass)
- {
- Object object = _parameters.get(name);
- if ( object.getClass() == klass )
- {
- return object;
- }
- else
- {
- System.err.println("Found object but type does not match.");
- return null;
- }
- }
-
- /** Checks if the parameter exists. */
- public boolean exists(String name)
- {
- return _parameters.containsKey(name);
- }
-
- /** Return the list of parameter names. */
- public Set<String> getParameterNames()
- {
- return _parameters.keySet();
- }
-
- /** Return a named parameter of type Double. */
- public Double getDouble(String name)
- {
- return (Double)getParameter(name, Double.class);
- }
-
- /** Return a named parameter of type Integer. */
- public Integer getInteger(String name)
- {
- return (Integer)getParameter(name, Integer.class);
- }
-
- /** Return a named parameter of type String. */
- public String getString(String name)
- {
- return (String)getParameter(name, String.class);
- }
+ /* Map for storing and looking up parameters by name. */
+ Map<String, Object> _parameters = new HashMap<String, Object>();
+
+ /** Constructor taking the <detector> node for a subdetector. */
+ protected ParameterSet(Element node)
+ {
+ convertFromXML(node);
+ }
+
+ /** Convert <parameter> elements within <detector>. */
+ private void convertFromXML(Element node)
+ {
+ assert (node != null);
+ assert (node.getName().compareTo("detector") == 0);
+
+ // Iterate over <parameter> elements
+ for (Object object : node.getChildren("parameter"))
+ {
+ Element element = (Element) object;
+
+ // Get name
+ String name = element.getAttributeValue("name");
+ assert (name != null);
+
+ // Get parameter type
+ String type = element.getAttributeValue("type");
+
+ // Get parameter value (can be null)
+ String value = element.getAttributeValue("value");
+
+ // Get value from text data within the tag if no value attribute
+ // exists
+ if ( value == null )
+ {
+ value = element.getTextNormalize();
+ }
+
+ Object convert = null;
+
+ // Explicit type conversion
+ if ( type != null )
+ {
+ // Convert to Double
+ if ( type.compareToIgnoreCase("double") == 0 ||
+ type.compareToIgnoreCase("dbl") == 0 )
+ {
+ convert = Double.parseDouble(value);
+ }
+ // Convert to Integer
+ else if ( type.compareToIgnoreCase("integer") == 0
+ || type.compareToIgnoreCase("int") == 0 )
+ {
+ convert = Integer.parseInt(value);
+ }
+ // Convert to String
+ else if ( type.compareToIgnoreCase("string") == 0 ||
+ type.compareToIgnoreCase("str") == 0)
+ {
+ convert = value;
+ }
+ // Type is invalid
+ else
+ {
+ throw new RuntimeException("Unknown type " + type + " for parameter " + name);
+ }
+ }
+ // Implicit type conversion
+ else
+ {
+ try
+ {
+ // First try parsing as Double
+ convert = Double.parseDouble(value);
+ }
+ catch (Exception e)
+ {
+
+ try
+ {
+ // Next try Int
+ convert = Integer.parseInt(value);
+ }
+ catch (Exception ee)
+ {
+ // Lastly, default to String
+ convert = value;
+ }
+ }
+ }
+
+ // add the parameter
+ //System.out.println("adding parameter " + name + "=" + value + " of type " + type);
+ addParameter(name, convert);
+ }
+ }
+
+ /** Constructor without Element argument. */
+ protected ParameterSet()
+ {
+ }
+
+ /** Add a parameter to the ParameterSet, checking that the type is valid. */
+ protected void addParameter(String name, Object object)
+ {
+ if ( object instanceof Double || object instanceof Integer
+ || object instanceof String )
+ {
+ if ( _parameters.get(name) == null )
+ {
+ _parameters.put(name, object);
+ } else
+ {
+ throw new RuntimeException("Parameter " + name
+ + " already exists in this ParameterSet.");
+ }
+ } else
+ {
+ throw new RuntimeException("Parameter " + name
+ + " is not of type Double, Integer or String.");
+ }
+ }
+
+ /** Return a named parameter as a generic java Object. */
+ public Object getParameter(String name, Class klass)
+ {
+ Object object = _parameters.get(name);
+ if ( object.getClass() == klass )
+ {
+ return object;
+ } else
+ {
+ System.err.println("Found object but type does not match.");
+ return null;
+ }
+ }
+
+ /** Checks if the parameter exists. */
+ public boolean exists(String name)
+ {
+ return _parameters.containsKey(name);
+ }
+
+ /** Return the list of parameter names. */
+ public Set<String> getParameterNames()
+ {
+ return _parameters.keySet();
+ }
+
+ /** Return a named parameter of type Double. */
+ public Double getDouble(String name)
+ {
+ return (Double) getParameter(name, Double.class);
+ }
+
+ /** Return a named parameter of type Integer. */
+ public Integer getInteger(String name)
+ {
+ return (Integer) getParameter(name, Integer.class);
+ }
+
+ /** Return a named parameter of type String. */
+ public String getString(String name)
+ {
+ return (String) getParameter(name, String.class);
+ }
}
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -u -r1.4 -r1.5
--- AbstractTestBeam.java 1 Dec 2005 04:11:10 -0000 1.4
+++ AbstractTestBeam.java 1 Feb 2006 01:33:17 -0000 1.5
@@ -88,8 +88,8 @@
int layerCount = 0;
int layerTypeCount = 0;
- double maxLayerX = 0;
- double maxLayerY = 0;
+ //double maxLayerX = 0;
+ //double maxLayerY = 0;
for ( Object lo : node.getChildren("layer") )
{
Element layer = (Element) lo;
GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -u -r1.3 -r1.4
--- EcalBarrel.java 24 Jan 2006 18:58:48 -0000 1.3
+++ EcalBarrel.java 1 Feb 2006 01:33:17 -0000 1.4
@@ -30,13 +30,13 @@
* Class to convert from Ecal model similar to Mokka's "ecal02" to LCDD.
*
* @author jeremym
- * @version $Id: EcalBarrel.java,v 1.3 2006/01/24 18:58:48 jeremy Exp $
+ * @version $Id: EcalBarrel.java,v 1.4 2006/02/01 01:33:17 jeremy Exp $
*/
// FIXME: needs subdetector envelope
public class EcalBarrel extends LCDDSubdetector
{
// change to true if debugging this component
- private boolean _debug = false;
+ private boolean _debug = true;
EcalBarrel(Element node) throws JDOMException
{
GeomConverter/src/org/lcsim/geometry/subdetector
diff -u -r1.3 -r1.4
--- AbstractCalorimeter.java 18 Jan 2006 01:46:25 -0000 1.3
+++ AbstractCalorimeter.java 1 Feb 2006 01:33:17 -0000 1.4
@@ -10,6 +10,7 @@
import org.jdom.JDOMException;
import org.lcsim.geometry.Calorimeter;
import org.lcsim.geometry.util.CalorimeterIDDecoder;
+import org.lcsim.geometry.subdetector.CalorimeterType;
/**
*
@@ -19,20 +20,21 @@
extends AbstractLayeredSubdetector implements Calorimeter
{
protected CalorimeterType _calType;
+ private static final String _typeParamStr = "CALTYPE";
- /** Creates a new instance of AbstractCalorimeter */
public AbstractCalorimeter(Element node) throws JDOMException
{
super(node);
- if ( getParameters().exists("calorimeterType") )
+ if ( getParameters().exists(_typeParamStr) )
{
- String str = getParameters().getString("calorimeterType");
- _calType = new CalorimeterType(str);
+ String str = getParameters().getString(_typeParamStr);
+ _calType = CalorimeterType.convertStringToCalorimeterType(str);
}
else {
- _calType = new CalorimeterType("OTHER");
- }
+ System.err.println("WARNING: no CALTYPE specified for calorimeter " + node.getAttributeValue("name"));
+ _calType = CalorimeterType.UNKNOWN;
+ }
}
public CalorimeterIDDecoder getCalorimeterIDDecoder()
@@ -40,7 +42,7 @@
return (CalorimeterIDDecoder)(getReadout().getIDDecoder() );
}
- public CalorimeterType getCalorimeterType()
+ public CalorimeterType getCalorimeterType()
{
return _calType;
}
GeomConverter/src/org/lcsim/geometry/subdetector
diff -u -r1.4 -r1.5
--- AbstractSubdetector.java 18 Jan 2006 01:46:25 -0000 1.4
+++ AbstractSubdetector.java 1 Feb 2006 01:33:17 -0000 1.5
@@ -31,10 +31,7 @@
/** Creates a new instance of AbstractSubdetector */
public AbstractSubdetector(Element node) throws JDOMException
{
- super(node);
-
-
-
+ super(node);
}
public SubdetectorIDDecoder getSubdetectorIDDecoder()
GeomConverter/src/org/lcsim/geometry/subdetector
diff -u -r1.1 -r1.2
--- CalorimeterType.java 18 Jan 2006 01:46:25 -0000 1.1
+++ CalorimeterType.java 1 Feb 2006 01:33:17 -0000 1.2
@@ -7,57 +7,73 @@
package org.lcsim.geometry.subdetector;
/**
- *
+ *
+ * This enum specifies the general type of a calorimeter Subdetector.
+ * Valid types include HCal, ECal, Muon, and FCal. It can be used to modify
+ * the behavior of algorithms that should only be performed on hits from
+ * certain types of calorimeters.
+ *
* @author jeremym
*/
-public class CalorimeterType
-{
- ECalorimeterType _type = ECalorimeterType.OTHER;
+public enum CalorimeterType
+{
+ FCAL("FCAL"),
+ ECAL("ECAL"),
+ HCAL("HCAL"),
+ MUON("MUON"),
+ UNKNOWN("UNKNOWN");
+
String _typeName;
- enum ECalorimeterType
- {
- FCAL,
- ECAL,
- HCAL,
- MUON,
- OTHER
- }
-
- /** Creates a new instance of CalorimeterType */
- public CalorimeterType(String typeName)
+ CalorimeterType(String typeName)
{
- if ( typeName.compareToIgnoreCase("fcal") == 0 )
+ _typeName = typeName;
+ }
+
+ public static CalorimeterType convertStringToCalorimeterType(String str)
+ {
+ if ( str.compareToIgnoreCase("ecal") == 0 || str.compareToIgnoreCase("em") == 0 )
{
- _type = ECalorimeterType.FCAL;
- _typeName = "FCAL";
- }
- else if ( typeName.compareToIgnoreCase("ecal") == 0 )
+ return ECAL;
+ }
+ else if ( str.compareToIgnoreCase("fcal") == 0 )
{
- _type = ECalorimeterType.ECAL;
- _typeName = "ECAL";
+ return FCAL;
}
- else if ( typeName.compareToIgnoreCase("hcal") == 0 )
+ else if ( str.compareToIgnoreCase("hcal") == 0 || str.compareToIgnoreCase("had") == 0 )
{
- _type = ECalorimeterType.HCAL;
- _typeName = "HCAL";
+ return HCAL;
}
- else if ( typeName.compareToIgnoreCase("muon") == 0 )
+ else if ( str.compareToIgnoreCase("muon") == 0 )
{
- _type = ECalorimeterType.MUON;
- _typeName = "MUON";
+ return MUON;
}
- else {
- _type = ECalorimeterType.OTHER;
- _typeName = typeName; // preserve typeName without enum match
- }
+
+ return UNKNOWN;
}
- ECalorimeterType getType()
+ public static String convertECalorimeterTypeToString(CalorimeterType caltype)
{
- return _type;
- }
-
+ if ( caltype == ECAL )
+ {
+ return "ECAL";
+ }
+ else if ( caltype == FCAL )
+ {
+ return "FCAL";
+ }
+ else if ( caltype == HCAL)
+ {
+ return "HCAL";
+ }
+ else if ( caltype == MUON)
+ {
+ return "MUON";
+ }
+
+ return "UNKNOWN";
+ }
+
public String getTypeName()
{
return toString();
@@ -67,4 +83,29 @@
{
return _typeName;
}
+
+ public boolean isHcal()
+ {
+ return this == HCAL;
+ }
+
+ public boolean isEcal()
+ {
+ return this == ECAL;
+ }
+
+ public boolean isMuon()
+ {
+ return this == MUON;
+ }
+
+ public boolean isFcal()
+ {
+ return this == FCAL;
+ }
+
+ public boolean isUnknown()
+ {
+ return this == UNKNOWN;
+ }
}
GeomConverter/src/org/lcsim/geometry/subdetector
diff -u -r1.4 -r1.5
--- TestBeamCalorimeter.java 18 Jan 2006 01:46:25 -0000 1.4
+++ TestBeamCalorimeter.java 1 Feb 2006 01:33:17 -0000 1.5
@@ -44,6 +44,6 @@
public CalorimeterType getCalorimeterType()
{
- return new CalorimeterType("OTHER");
+ return CalorimeterType.UNKNOWN;
}
}
\ No newline at end of file
GeomConverter/test/org/lcsim/geometry/compact
diff -u -r1.14 -r1.15
--- sdjan03_compact.xml 17 Jan 2006 19:15:25 -0000 1.14
+++ sdjan03_compact.xml 1 Feb 2006 01:33:18 -0000 1.15
@@ -155,8 +155,9 @@
<slice material = "Copper" thickness = "0.1*cm" />
<slice material = "Air" thickness = "0.06*cm" />
</layer>
+ <parameter name="CALTYPE">ECAL</parameter>
</detector>
- <detector id="6" name="EMEendcap" reflect="true" type="CylindricalEndcapCalorimeter" readout="EcalEndcapHits">
+ <detector id="6" name="EMEndcap" reflect="true" type="CylindricalEndcapCalorimeter" readout="EcalEndcapHits">
<dimensions inner_r = "20.0*cm" inner_z = "168.0*cm" outer_r = "125.0*cm" />
<layer repeat="30" >
<slice material = "Tungsten" thickness = "0.25*cm" />
@@ -165,6 +166,7 @@
<slice material = "Copper" thickness = "0.1*cm" />
<slice material = "Air" thickness = "0.06*cm" />
</layer>
+ <parameter name="CALTYPE">ECAL</parameter>
</detector>
<detector id="3" name="HADBarrel" type="CylindricalBarrelCalorimeter" readout="HcalBarrHits">
<dimensions inner_r = "144.0*cm" outer_z = "286.0*cm" />
@@ -172,6 +174,7 @@
<slice material = "Steel235" thickness = "2.0*cm" />
<slice material = "Polystyrene" thickness = "1.0*cm" sensitive = "yes" />
</layer>
+ <parameter name="CALTYPE">HCAL</parameter>
</detector>
<!-- test whether multiple readouts on same detector works okay -->
<detector id="10" name="HADBarrel2" type="CylindricalBarrelCalorimeter" readout="HcalBarrHits">
@@ -180,6 +183,7 @@
<slice material = "Steel235" thickness = "2.0*cm" />
<slice material = "Polystyrene" thickness = "1.0*cm" sensitive = "yes" />
</layer>
+ <parameter name="CALTYPE">HCAL</parameter>
</detector>
<detector id ="7" name="HAD_ENDCAP" reflect="true" type="CylindricalEndcapCalorimeter" readout="HcalEndcapHits">
<dimensions inner_r = "20.0*cm" inner_z = "184.0*cm" outer_r = "142.0*cm" />
@@ -187,6 +191,7 @@
<slice material = "Steel235" thickness = "2.0*cm" />
<slice material = "Polystyrene" thickness = "1.0*cm" sensitive = "yes" />
</layer>
+ <parameter name="CALTYPE">HCAL</parameter>
</detector>
<detector id="4" name="MUON_BARREL" type="CylindricalBarrelCalorimeter" readout="MuonBarrHits" detectorType="calorimeter">
<dimensions inner_r = "337.0*cm" outer_z = "287.0*cm" />
@@ -194,6 +199,7 @@
<slice material = "Iron" thickness = "5.0*cm" />
<slice material = "Air" thickness = "1.5*cm" sensitive = "yes" />
</layer>
+ <parameter name="CALTYPE">MUON</parameter>
</detector>
<detector id="8" name="MUON_ENDCAP" reflect="true" type="CylindricalEndcapCalorimeter" readout="MuonEndcapHits">
<dimensions inner_r = "20.0*cm" inner_z = "287.0*cm" outer_r = "636.0*cm" />
@@ -201,6 +207,7 @@
<slice material = "Iron" thickness = "5.0*cm" />
<slice material = "Air" thickness = "1.5*cm" sensitive = "yes" />
</layer>
+ <parameter name="CALTYPE">MUON</parameter>
</detector>
<detector id="9" name="LUM_ENDCAP" reflect="true" type="CylindricalEndcapCalorimeter" readout="LumEndcapHits">
<dimensions inner_r = "0.0001*cm" inner_z = "310.0*cm" outer_r = "9.2*cm" />
@@ -208,6 +215,7 @@
<slice material="Beryllium" thickness = "10.*cm" />
<slice material="Tungsten" thickness = "35.*cm" sensitive = "yes" />
</layer>
+ <parameter name="CALTYPE">FCAL</parameter>
</detector>
</detectors>
<readouts>
GeomConverter/test/org/lcsim/geometry/subdetector
diff -N CalorimeterTypeTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CalorimeterTypeTest.java 1 Feb 2006 01:33:18 -0000 1.1
@@ -0,0 +1,71 @@
+/*
+ * CylindricalBarrelCalorimeterTest.java
+ *
+ * Created on June 15, 2005, 12:00 PM
+ */
+
+package org.lcsim.geometry.subdetector;
+
+import java.io.InputStream;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.lcsim.geometry.GeometryReader;
+import org.lcsim.geometry.compact.Detector;
+import org.lcsim.geometry.Calorimeter;
+
+/**
+ *
+ * @author jeremym
+ */
+public class CalorimeterTypeTest extends TestCase
+{
+ Detector det;
+
+ /** Creates a new instance of CylindricalBarrelCalorimeterTest */
+ public CalorimeterTypeTest()
+ {
+ }
+
+ protected void setUp() throws java.lang.Exception
+ {
+ InputStream in = this.getClass().getResourceAsStream("/org/lcsim/geometry/compact/sdjan03_compact.xml");
+
+ GeometryReader reader = new GeometryReader();
+ det = reader.read(in);
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new TestSuite(CalorimeterTypeTest.class);
+ }
+
+ public void testCalorimeterType()
+ {
+ Calorimeter ecalBarr = (Calorimeter)det.getSubdetector("EMBarrel");
+ Calorimeter ecalEndcap = (Calorimeter)det.getSubdetector("EMEndcap");
+
+ Calorimeter hcalBarr = (Calorimeter)det.getSubdetector("HADBarrel");
+ Calorimeter hcalEndcap = (Calorimeter)det.getSubdetector("HADEndcap");
+
+ Calorimeter muBarr = (Calorimeter)det.getSubdetector("MUON_BARREL");
+ Calorimeter muEndcap = (Calorimeter)det.getSubdetector("MUON_ENDCAP");
+
+ assert(ecalBarr.getCalorimeterType().isEcal());
+ assert(ecalBarr.getCalorimeterType() == CalorimeterType.ECAL);
+
+ assert(ecalEndcap.getCalorimeterType().isEcal());
+ assert(ecalEndcap.getCalorimeterType() == CalorimeterType.ECAL);
+
+ assert(hcalBarr.getCalorimeterType().isHcal());
+ assert(hcalBarr.getCalorimeterType() == CalorimeterType.HCAL);
+
+ assert(hcalEndcap.getCalorimeterType().isHcal());
+ assert(hcalEndcap.getCalorimeterType() == CalorimeterType.HCAL);
+
+ assert(muBarr.getCalorimeterType().isMuon());
+ assert(muBarr.getCalorimeterType() == CalorimeterType.MUON);
+
+ assert(muEndcap.getCalorimeterType().isMuon());
+ assert(muEndcap.getCalorimeterType() == CalorimeterType.MUON);
+ }
+}
CVSspam 0.2.8