View Javadoc

1   package org.lcsim.lcio;
2   
3   import hep.io.sio.SIOInputStream;
4   import hep.io.sio.SIOOutputStream;
5   import hep.io.sio.SIORef;
6   import hep.physics.vec.BasicHep3Vector;
7   
8   import java.io.IOException;
9   
10  import org.lcsim.event.base.BaseSimTrackerHit;
11  import org.lcsim.event.MCParticle;
12  import org.lcsim.event.SimTrackerHit;
13  import org.lcsim.event.EventHeader.LCMetaData;
14  
15  /**
16   * The SIO implementation of {@link org.lcsim.event.SimTrackerHit}.
17   * @author Tony Johnson
18   * @author Jeremy McCormick
19   * @version $Id: SIOSimTrackerHit.java,v 1.18 2012/07/10 00:11:24 jeremy Exp $
20   */
21  class SIOSimTrackerHit extends BaseSimTrackerHit
22  {    
23      private Object particleref;
24          
25      SIOSimTrackerHit(SIOInputStream in, int flags, int version, LCMetaData meta) throws IOException
26      {
27          // Read in the two 32-bit cell IDs.
28          cellID0 = in.readInt();
29          if(version >= 1060)
30          {
31              if(LCIOUtil.bitTest(flags, LCIOConstants.THBIT_ID1))
32              {
33                  cellID1 = in.readInt();
34              }
35          }
36          
37          // Make the 64-bit ID.
38          this.id = ((long) cellID1) << 32 | cellID0;
39  
40          // Position.
41          position[0] = in.readDouble();
42          position[1] = in.readDouble();
43          position[2] = in.readDouble();
44          positionVec = new BasicHep3Vector(position[0], position[1], position[2]);
45          
46          // Energy.
47          dEdx = in.readFloat();
48          
49          // Time.
50          time = in.readFloat();
51          
52          // MCParticle pointer.
53          particleref = in.readPntr();        
54         
55          // Momentum.
56          if (LCIOUtil.bitTest(flags, LCIOConstants.THBIT_MOMENTUM))
57          {
58              momentum[0] = in.readFloat();
59              momentum[1] = in.readFloat();
60              momentum[2] = in.readFloat();
61              if (version > 1006)
62                  pathLength = in.readFloat();
63          }
64  
65          // Pointer tag.
66          if (version > 1000)
67              in.readPTag(this);
68  
69          setMetaData(meta);
70      }   
71  
72      public MCParticle getMCParticle()
73      {
74          if (mcparticle == null) 
75          { // Check if this has been cached already.
76              if (particleref instanceof SIORef)
77              {
78                  particleref = ((SIORef) particleref).getObject();
79                  mcparticle = (MCParticle)particleref;
80              }
81              else 
82              {
83                  // Added a throw here.  I think this probably constitutes a fatal error.  --JM
84                  // mg May 22/2010 remove this exception
85  //                throw new RuntimeException("Referenced object is not an MCParticle!");
86                  
87              }
88          }
89          return mcparticle;
90      }
91      
92      static void write(SimTrackerHit hit, SIOOutputStream out, int flags) throws IOException
93      {
94          // Cell ID.
95          long cellID = hit.getCellID64();
96          out.writeInt((int) cellID);
97          if (LCIOUtil.bitTest(flags, LCIOConstants.THBIT_ID1))
98          {
99              out.writeInt((int) (cellID >> 32));
100         }
101 
102         double[] pos = hit.getPoint();
103         out.writeDouble(pos[0]);
104         out.writeDouble(pos[1]);
105         out.writeDouble(pos[2]);
106         out.writeFloat((float) hit.getdEdx());
107         out.writeFloat((float) hit.getTime());
108         out.writePntr(hit.getMCParticle());
109         if (LCIOUtil.bitTest(flags, LCIOConstants.THBIT_MOMENTUM))
110         {
111             double[] p = hit.getMomentum();
112             out.writeFloat((float) p[0]);
113             out.writeFloat((float) p[1]);
114             out.writeFloat((float) p[2]);
115             out.writeFloat((float) hit.getPathLength());
116         }
117         out.writePTag(hit);
118     }
119 }