4 added + 3 modified, total 7 files
lcio/config
diff -u -r1.54 -r1.55
--- lcio.properties 2 Jun 2006 00:22:56 -0000 1.54
+++ lcio.properties 28 Jun 2006 23:25:17 -0000 1.55
@@ -1,7 +1,7 @@
# ANT property file for LCIO
#
# Author: Mark Donszelmann
-# Version: $Id: lcio.properties,v 1.54 2006/06/02 00:22:56 jeremy Exp $
+# Version: $Id: lcio.properties,v 1.55 2006/06/28 23:25:17 jeremy Exp $
#
debug=true
@@ -25,7 +25,7 @@
test.classpath=lib/lcio.jar;tools/sio.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar
test.format=frames
-classpath=src/java;tools/sio.jar;tools/saxpath.jar;tools/jel.jar;tools/jdom.jar;tools/jaxen-core.jar;tools/jaxen-jdom.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar
+classpath=src/java;tools/sio.jar;tools/saxpath.jar;tools/jel.jar;tools/jdom.jar;tools/jaxen-core.jar;tools/jaxen-jdom.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar;tools/freehep-physics.jar;tools/freehep-hep.jar
srcpath=src/java
exp.srcpath=
lcio/src/java/hep/lcio/util
diff -N StdhepConvertCommandHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ StdhepConvertCommandHandler.java 28 Jun 2006 23:25:17 -0000 1.1
@@ -0,0 +1,64 @@
+package hep.lcio.util;
+
+import java.io.File;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+public class StdhepConvertCommandHandler extends CommandHandler
+{
+ File infile;
+ File outfile;
+
+ StdhepConvertCommandHandler()
+ {
+ super("stdhep","Convert Stdhep file to LCIO.");
+
+ options = createStdhepConvertOptions();
+ }
+
+ private static Options createStdhepConvertOptions()
+ {
+ Options options = new Options();
+
+ Option opt = new Option("i", true, "Input Stdhep file.");
+ opt.setArgs(1);
+ options.addOption(opt);
+
+ opt = new Option("o", true, "Output LCIO file.");
+ opt.setArgs(1);
+ options.addOption(opt);
+
+ return options;
+ }
+
+ public void parse(String[] argv) throws Exception
+ {
+ CommandLine cl = parser.parse(options, argv);
+
+ if (cl.hasOption("i"))
+ {
+ infile = new File(cl.getOptionValue("i"));
+ }
+ else {
+ printUsage(true);
+ }
+
+ String lcioname =
+ infile.getAbsolutePath().replace(".stdhep",".slcio");
+
+ if (cl.hasOption("o"))
+ {
+ lcioname = cl.getOptionValue("o");
+ }
+
+ outfile = new File(lcioname);
+ }
+
+ public void execute() throws Exception
+ {
+ StdhepConverter converter = new StdhepConverter();
+ converter.convert(infile, outfile);
+ }
+}
\ No newline at end of file
lcio/src/java/hep/lcio/util
diff -N StdhepConverter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ StdhepConverter.java 28 Jun 2006 23:25:17 -0000 1.1
@@ -0,0 +1,240 @@
+package hep.lcio.util;
+
+import hep.io.stdhep.StdhepEvent;
+import hep.io.stdhep.StdhepReader;
+import hep.io.stdhep.StdhepRecord;
+import hep.lcio.event.LCIO;
+import hep.lcio.implementation.event.ILCCollection;
+import hep.lcio.implementation.event.ILCEvent;
+import hep.lcio.implementation.event.IMCParticle;
+import hep.lcio.implementation.io.LCFactory;
+import hep.lcio.io.LCWriter;
+import hep.physics.particle.properties.ParticlePropertyManager;
+import hep.physics.particle.properties.ParticlePropertyProvider;
+import hep.physics.particle.properties.ParticleType;
+import hep.physics.particle.properties.UnknownParticleIDException;
+
+import java.io.EOFException;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A class that converts StdhepEvents to LCCollections of MCParticles.
+ * Based on Tony Johnson's StdhepConverter from the org.lcsim package.
+ * Changed to use LCIO objects instead of MCEvent and modified for
+ * Java 1.4 compatibility.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: StdhepConverter.java,v 1.1 2006/06/28 23:25:17 jeremy Exp $
+ */
+class StdhepConverter
+{
+ private ParticlePropertyProvider ppp = ParticlePropertyManager.getParticlePropertyProvider();
+
+ // c_light copied from CLHEP 1.9.2.2
+ // CLHEP/Units/PhysicalConstants.h
+ private static final double c_light = 2.99792458e+8;
+
+ StdhepConverter()
+ {}
+
+ public void convert(File stdhep, File lcio) throws Exception
+ {
+ // Create StdhepReader with the input file path.
+ StdhepReader reader =
+ new StdhepReader(stdhep.getAbsolutePath());
+
+ // Create LCWriter with the output file path.
+ LCWriter writer =
+ LCFactory.getInstance().createLCWriter();
+ writer.open(lcio.getAbsolutePath());
+
+ try
+ {
+ // Loop over all records in the Stdhep file.
+ for (;;)
+ {
+ // Get the next Stdhep event.
+ StdhepRecord record = reader.nextRecord();
+
+ // Only process StdhepEvent records.
+ if (record instanceof StdhepEvent)
+ {
+ // Convert to an LCCollection of MCParticle objects.
+ ILCCollection mcpcoll =
+ convert((StdhepEvent) record);
+
+ // Make a new LCEvent.
+ ILCEvent event = new ILCEvent();
+
+ // FIXME: What should this be set to?
+ // NullPointerException if not set to something.
+ event.setDetectorName("test");
+
+ // FIXME: What values for these?
+ event.setEventNumber(0);
+ event.setRunNumber(0);
+ event.setTimeStamp(0);
+
+ // Add the MCParticle collection to the event.
+ event.addCollection(mcpcoll, LCIO.MCPARTICLE);
+
+ // Write out the event to the LCIO file.
+ writer.writeEvent(event);
+ }
+ }
+ }
+ catch (EOFException e)
+ {
+ // End of Stdhep file.
+ }
+
+ reader.close();
+
+ writer.close();
+ }
+
+ private void checkAndAddDaughter(IMCParticle[] particle, List ancestors, int parentID, int childID)
+ {
+ if (parentID == childID)
+ return; // Can't be parent of self
+ Set ancestor = (Set) ancestors.get(childID);
+ boolean added = ancestor.add(particle[parentID]);
+ if (added)
+ particle[parentID].addDaughter(particle[childID]);
+ //System.out.println("add "+parentID+" "+childID+" "+added);
+ }
+
+ private int fillIndexVec(int[] vec, int idx1, int idx2)
+ {
+ int l = 0;
+ if (idx1 != -1 && idx2 != -1)
+ {
+ if (idx1 < idx2)
+ {
+ for (int i = idx1; i < (idx2 + 1); i++)
+ {
+ vec[l++] = i;
+ }
+ }
+ else if (idx1 > idx2)
+ {
+ vec[l++] = idx1;
+ vec[l++] = idx2;
+ }
+ // indices are equal
+ else
+ {
+ vec[l++] = idx1;
+ }
+ }
+ else if (idx1 != -1)
+ {
+ vec[l++] = idx1;
+ }
+ else if (idx2 != -1)
+ {
+ vec[l++] = idx2;
+ }
+ return l;
+ }
+
+ /**
+ * Convert a StdhepEvent to an LCCollection of MCParticle objects.
+ * @param hepevt The StdhepEvent to be converted.
+ * @return An LCCollection of MCParticle objects converted from hepevt.
+ */
+ public ILCCollection convert(StdhepEvent hepevt)
+ {
+ ILCCollection mcpcoll = new ILCCollection(LCIO.MCPARTICLE);
+
+ int n = hepevt.getNHEP();
+
+ IMCParticle particles[] = new IMCParticle[n];
+
+ for (int i = 0; i < n; i++)
+ {
+ // Create new MCParticle for this Stdhep record.
+ IMCParticle particle = new IMCParticle();
+
+ // Add MCParticle to the temp array.
+ particles[i] = particle;
+
+ // Set vertex from VHEP.
+ double vertex[] =
+ { hepevt.getVHEP(i, 0), hepevt.getVHEP(i, 1), hepevt.getVHEP(i, 2) };
+ particle.setVertex(vertex);
+
+ // Set momentum from PHEP.
+ double momentum[] =
+ { hepevt.getPHEP(i, 0), hepevt.getPHEP(i, 1), hepevt.getPHEP(i, 2) };
+ particle.setMomentum(momentum);
+
+ // Lookup the particle by PDG using the Particle Property Provider.
+ ParticleType type;
+ try {
+ // Get the particle type.
+ type = ppp.get(hepevt.getIDHEP(i));
+
+ // Set the charge.
+ particle.setCharge((float) type.getCharge());
+ }
+ catch (UnknownParticleIDException e)
+ {
+ // Flag the particle with NaN for unknown charge.
+ particle.setCharge(Float.NaN);
+ }
+
+ // Set mass from PHEP.
+ particle.setMass((float)hepevt.getPHEP(i, 4));
+
+ // Set PDG from IDHEP.
+ particle.setPDG(hepevt.getIDHEP(i));
+
+ // Set time from VHEP(4).
+ // Convert to mm/c^2 from mm/c, as in slic/StdHepToLcioConvertor .
+ particle.setTime((float)(hepevt.getVHEP(i, 3) / c_light));
+ }
+
+ int[] vec = new int[n];
+ //List<Set<BasicParticle>> ancestors = new ArrayList<Set<BasicParticle>>(n);
+ List ancestors = new ArrayList();
+ for (int i = 0; i < n; i++)
+ ancestors.add(new HashSet());
+ // Deal with parents
+ for (int i = 0; i < n; i++)
+ {
+ int idx1 = hepevt.getJMOHEP(i, 0) - 1;
+ int idx2 = hepevt.getJMOHEP(i, 1) - 1;
+ int l = fillIndexVec(vec, idx1, idx2);
+ //System.out.println("parent: "+i+" "+idx1+" "+idx2+" "+l);
+ for (int j = 0; j < l; j++)
+ {
+ checkAndAddDaughter(particles, ancestors, vec[j], i);
+ }
+ }
+ // Deal with daughters
+ for (int i = 0; i < n; i++)
+ {
+ int idx1 = hepevt.getJDAHEP(i, 0) % 10000 - 1;
+ int idx2 = hepevt.getJDAHEP(i, 1) % 10000 - 1;
+ int l = fillIndexVec(vec, idx1, idx2);
+ //System.out.println("child: "+i+" "+idx1+" "+idx2+" "+l);
+ for (int j = 0; j < l; j++)
+ {
+ checkAndAddDaughter(particles, ancestors, i, vec[j]);
+ }
+ }
+
+ // Add particles to the collection.
+ for (int i=0; i<n; i++)
+ {
+ mcpcoll.add(particles[i]);
+ }
+
+ return mcpcoll;
+ }
+}
\ No newline at end of file
lcio/src/java/hep/lcio/util
diff -u -r1.11 -r1.12
--- CommandLineTool.java 28 Jun 2006 18:31:55 -0000 1.11
+++ CommandLineTool.java 28 Jun 2006 23:25:17 -0000 1.12
@@ -42,7 +42,7 @@
* @see hep.lcio.util.RandomEvent random [X]
* -generate X random events
*
- * @see hep.lcio.util.Validate validate [x]
+ * @see hep.lcio.util.Validate validate [X]
* -Is an LCIO file?
* -version check
*
@@ -61,7 +61,7 @@
* FIXME: Implement all of the above commands.
*
* @author jeremym
- * @version $Id: CommandLineTool.java,v 1.11 2006/06/28 18:31:55 jeremy Exp $
+ * @version $Id: CommandLineTool.java,v 1.12 2006/06/28 23:25:17 jeremy Exp $
*/
public class CommandLineTool
{
@@ -103,6 +103,7 @@
addCommandHandler(new HeaderCountCommandHandler());
addCommandHandler(new RandomEventCommandHandler());
addCommandHandler(new ValidateCommandHandler());
+ addCommandHandler(new StdhepConvertCommandHandler());
// addCommandHandler(new PrintEventCommandHandler());
// addCommandHandler(new FilterEventCommandHandler());
lcio/tools
diff -u -r1.2 -r1.3
--- lcio 2 Jun 2006 00:22:58 -0000 1.2
+++ lcio 28 Jun 2006 23:25:18 -0000 1.3
@@ -34,6 +34,7 @@
LOCALCLASSPATH=$LCIO/lib/lcio.jar:$LCIO/tools/sio.jar:$LCIO/tools/jdom.jar:$LCIO/tools/saxpath.jar
LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/jaxen-jdom.jar:$LCIO/tools/jaxen-core.jar:$LCIO/tools/jel.jar
LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/commons-cli-1.0.jar:$LCIO/tools/commons-lang-2.1.jar
+LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/freehep-hep.jar:$LCIO/tools/freehep-physics.jar:$LCIO/tools/freehep-base.jar
# OS specific support for Cygwin
cygwin=false;
CVSspam 0.2.8