lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- SIOSimCalorimeterHit.java 16 Feb 2005 07:28:06 -0000 1.2
+++ SIOSimCalorimeterHit.java 29 Jul 2005 02:43:28 -0000 1.3
@@ -11,133 +11,135 @@
/**
*
* @author Tony Johnson
- * @version $Id: SIOSimCalorimeterHit.java,v 1.2 2005/02/16 07:28:06 tonyj Exp $
+ * @version $Id: SIOSimCalorimeterHit.java,v 1.3 2005/07/29 02:43:28 jeremy Exp $
*/
class SIOSimCalorimeterHit implements SimCalorimeterHit
{
- private float energy;
- private int cellId0;
- private int cellId1;
- private double[] position = new double[3];
- private int nContributions;
- private Object[] particle;
- private float[] energyContrib;
- private float[] time;
- private int[] pdg;
-
- SIOSimCalorimeterHit(SIOInputStream in, int flags, int version) throws IOException
- {
- cellId0 = in.readInt();
- if (LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_ID1) || version==8) cellId1 = in.readInt();
- else cellId1 = 0;
- energy = in.readFloat();
-
- if (LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_LONG))
- {
- position[0] = in.readFloat();
- position[1] = in.readFloat();
- position[2] = in.readFloat();
- }
- nContributions = in.readInt();
- particle = new Object[nContributions];
- energyContrib = new float[nContributions];
- time = new float[nContributions];
-
- boolean hasPDG = LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_PDG);
- if (hasPDG) pdg = new int[nContributions];
- for (int i = 0; i < nContributions; i++)
- {
- particle[i] = in.readPntr();
- energyContrib[i] = in.readFloat();
- time[i] = in.readFloat();
- if (hasPDG) pdg[i] = in.readInt();
- }
- if ( version > 1000 ) in.readPTag(this);
- }
- /**
- * Raw energy deposited in Calorimeter Cell
- */
- public double getEnergy()
- {
- return energy;
- }
-
- public long getCellID()
- {
- return ((long) cellId1)<<32 | cellId0;
- }
-
- public double getTime()
- {
- // Somewhat arbitrarily decide that the time of the hit
- // is the earliest hit contribution time
-
- if (time.length == 0) return 0;
- double t = time[1];
- for (int i=1; i<time.length; i++)
- {
- t = Math.min(t,time[i]);
- }
- return t;
- }
-
- public MCParticle getMCParticle(int index)
- {
- Object p = particle[index];
- if (p instanceof SIORef) p = ((SIORef) p).getObject();
- return (MCParticle) p;
- }
-
- public double getContributedEnergy(int index)
- {
- return energyContrib[index];
- }
-
- public int getPDG(int index)
- {
- return pdg[index];
- }
-
- public double getContributedTime(int index)
- {
- return time[index];
- }
-
- public double[] getPosition()
- {
- return position;
- }
-
- public int getMCParticleCount()
- {
- return particle.length;
- }
- static void write(SimCalorimeterHit hit, SIOOutputStream out, int flags) throws IOException
- {
- long cellID = hit.getCellID();
- out.writeInt((int) cellID);
- if (LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_ID1)) out.writeInt((int) (cellID>>32));
- out.writeFloat((float) hit.getEnergy());
-
- if ((flags & (1 << LCIOConstants.CHBIT_LONG)) != 0)
- {
- double[] pos = hit.getPosition();
- out.writeFloat((float) pos[0]);
- out.writeFloat((float) pos[1]);
- out.writeFloat((float) pos[2]);
- }
-
- boolean hasPDG = LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_PDG);
- int n = hit.getMCParticleCount();
- out.writeInt(n);
- for (int i = 0; i < n; i++)
- {
- out.writePntr(hit.getMCParticle(i));
- out.writeFloat((float) hit.getContributedEnergy(i));
- out.writeFloat((float) hit.getContributedTime(i));
- if (hasPDG) out.writeInt(hit.getPDG(i));
- }
- out.writePTag(hit);
- }
-
+ private float energy;
+ private int cellId0;
+ private int cellId1;
+ private double[] position = new double[3];
+ private int nContributions;
+ private Object[] particle;
+ private float[] energyContrib;
+ private float[] time;
+ private int[] pdg;
+
+ SIOSimCalorimeterHit(SIOInputStream in, int flags, int version) throws IOException
+ {
+ cellId0 = in.readInt();
+ if (LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_ID1) || version==8) cellId1 = in.readInt();
+ else cellId1 = 0;
+ energy = in.readFloat();
+
+ if (LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_LONG))
+ {
+ position[0] = in.readFloat();
+ position[1] = in.readFloat();
+ position[2] = in.readFloat();
+ }
+ nContributions = in.readInt();
+ particle = new Object[nContributions];
+ energyContrib = new float[nContributions];
+ time = new float[nContributions];
+
+ boolean hasPDG = LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_PDG);
+ if (hasPDG) pdg = new int[nContributions];
+ for (int i = 0; i < nContributions; i++)
+ {
+ particle[i] = in.readPntr();
+ energyContrib[i] = in.readFloat();
+ time[i] = in.readFloat();
+ if (hasPDG) pdg[i] = in.readInt();
+ }
+ if ( version > 1000 ) in.readPTag(this);
+ }
+ /**
+ * Raw energy deposited in Calorimeter Cell
+ */
+ public double getEnergy()
+ {
+ return energy;
+ }
+
+ public long getCellID()
+ {
+ return ((long) cellId1)<<32 | cellId0;
+ }
+
+ // Somewhat arbitrarily decide that the time of the hit
+ // is the earliest time from MCParticle contributions
+ public double getTime()
+ {
+ if (time.length == 0) return 0;
+ double t = time[0];
+ if ( time.length > 1 )
+ {
+ for (int i=1; i<time.length; i++)
+ {
+ t = Math.min(t,time[i]);
+ }
+ }
+ return t;
+ }
+
+ public MCParticle getMCParticle(int index)
+ {
+ Object p = particle[index];
+ if (p instanceof SIORef) p = ((SIORef) p).getObject();
+ return (MCParticle) p;
+ }
+
+ public double getContributedEnergy(int index)
+ {
+ return energyContrib[index];
+ }
+
+ public int getPDG(int index)
+ {
+ return pdg[index];
+ }
+
+ public double getContributedTime(int index)
+ {
+ return time[index];
+ }
+
+ public double[] getPosition()
+ {
+ return position;
+ }
+
+ public int getMCParticleCount()
+ {
+ return particle.length;
+ }
+ static void write(SimCalorimeterHit hit, SIOOutputStream out, int flags) throws IOException
+ {
+ long cellID = hit.getCellID();
+ out.writeInt((int) cellID);
+ if (LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_ID1)) out.writeInt((int) (cellID>>32));
+ out.writeFloat((float) hit.getEnergy());
+
+ if ((flags & (1 << LCIOConstants.CHBIT_LONG)) != 0)
+ {
+ double[] pos = hit.getPosition();
+ out.writeFloat((float) pos[0]);
+ out.writeFloat((float) pos[1]);
+ out.writeFloat((float) pos[2]);
+ }
+
+ boolean hasPDG = LCIOUtil.bitTest(flags,LCIOConstants.CHBIT_PDG);
+ int n = hit.getMCParticleCount();
+ out.writeInt(n);
+ for (int i = 0; i < n; i++)
+ {
+ out.writePntr(hit.getMCParticle(i));
+ out.writeFloat((float) hit.getContributedEnergy(i));
+ out.writeFloat((float) hit.getContributedTime(i));
+ if (hasPDG) out.writeInt(hit.getPDG(i));
+ }
+ out.writePTag(hit);
+ }
+
}