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   import hep.physics.vec.BasicHepLorentzVector;
8   import hep.physics.vec.Hep3Vector;
9   
10  import java.io.IOException;
11  import java.util.ArrayList;
12  import java.util.Collections;
13  import java.util.List;
14  import org.lcsim.event.Cluster;
15  import org.lcsim.event.ParticleID;
16  import org.lcsim.event.ReconstructedParticle;
17  import org.lcsim.event.Track;
18  import org.lcsim.event.Vertex;
19  import org.lcsim.event.base.BaseReconstructedParticle;
20  
21  /**
22   *
23   * @author Tony Johnson
24   * @version $Id: SIOReconstructedParticle.java,v 1.9 2009/03/12 18:07:42 jeremy Exp $
25   */
26  class SIOReconstructedParticle extends BaseReconstructedParticle
27  {
28     private List<SIORef> tempParticles;
29     private List<SIORef> tempTracks;
30     private List<SIORef> tempClusters;
31     private SIORef tempVertex;
32     
33     SIOReconstructedParticle(SIOInputStream in, int flags, int version) throws IOException
34     {
35        _type = in.readInt();
36        Hep3Vector momentum = new BasicHep3Vector(in.readFloat(),in.readFloat(),in.readFloat());
37        double energy = in.readFloat();
38        _fourVec = new BasicHepLorentzVector(energy,momentum);
39        _covMatrix = new double[10];
40        for (int i=0; i<10; i++) _covMatrix[i] = in.readFloat();
41        _mass = in.readFloat();
42        _charge = in.readFloat();
43        _referencePoint = new BasicHep3Vector(in.readFloat(),in.readFloat(),in.readFloat());
44        int nPid = in.readInt();
45        _particleIds = new ArrayList(nPid);
46        for (int i=0; i<nPid; i++)
47        {
48           ParticleID id = new SIOParticleID(in,flags,version);
49           _particleIds.add(id);
50           in.readPTag(id);
51        }
52        _particleIdUsed = (ParticleID) in.readPntr().getObject();
53        _goodnessOfPid = in.readFloat();
54        int nReco = in.readInt();
55        tempParticles = new ArrayList(nReco);
56        _particles = null;
57        for (int i=0; i<nReco; i++)
58        {
59           tempParticles.add(in.readPntr());
60        }
61        int nTracks = in.readInt();
62        tempTracks = new ArrayList(nTracks);
63        _tracks = null;
64        for (int i=0; i<nTracks; i++)
65        {
66           tempTracks.add(in.readPntr());
67        }
68        int nClust = in.readInt();
69        tempClusters = new ArrayList(nClust);
70        _clusters = null;
71        for (int i=0; i<nClust; i++)
72        {
73           tempClusters.add(in.readPntr());
74        }
75        if (version > 1007)
76        {
77           tempVertex = in.readPntr();
78           _vertex = null;
79        }
80        in.readPTag(this);
81     }
82     
83     static void write(ReconstructedParticle particle, SIOOutputStream out, int flags) throws IOException
84     {
85        out.writeInt(particle.getType());
86        double[] mom = particle.getMomentum().v();
87        for (int i=0; i<3; i++) out.writeFloat((float) mom[i]);
88        out.writeFloat((float) particle.getEnergy());
89        double[] matrix = particle.getCovMatrix();
90        for (int i=0; i<10; i++) out.writeFloat(matrix == null ? 0f : (float)matrix[i]);
91        out.writeFloat((float) particle.getMass());
92        out.writeFloat((float)particle.getCharge());
93        double[] ref = particle.getReferencePoint().v();
94        for (int i=0; i<3; i++) out.writeFloat((float)ref[i]);
95        List<ParticleID> ids = particle.getParticleIDs();
96        //if (!ids.contains(particle.getParticleIDUsed()))
97        //  throw new RuntimeException("The used PID with PDG " + particle.getParticleIDUsed().getPDG()
98        //		  + " is not in the list of candidate PIDs.");
99        out.writeInt(ids.size());
100       for (ParticleID pid : ids )
101       {
102          SIOParticleID.write(pid,out,flags);
103          out.writePTag(pid);
104       }
105       out.writePntr(particle.getParticleIDUsed());
106       out.writeFloat((float)particle.getGoodnessOfPID());
107       List<ReconstructedParticle> particles = particle.getParticles();
108       out.writeInt(particles.size());
109       for (ReconstructedParticle child : particles) out.writePntr(child);
110       List<Track> tracks = particle.getTracks();
111       out.writeInt(tracks.size());
112       for (Track track : tracks) out.writePntr(track);
113       List<Cluster> clusters = particle.getClusters();
114       out.writeInt(clusters.size());
115       for (Cluster cluster : clusters) out.writePntr(cluster);
116       out.writePntr(particle.getStartVertex());
117       out.writePTag(particle);
118    }
119    
120    public List<Cluster> getClusters()
121    {
122       if (tempClusters != null && _clusters == null)
123       {
124          _clusters = new ArrayList<Cluster>(tempClusters.size());
125          for (SIORef ref : tempClusters) _clusters.add((Cluster) ref.getObject());
126          tempClusters = null;
127       }
128       return _clusters == null ? Collections.<Cluster>emptyList() : _clusters;
129    }
130    
131    public List<ReconstructedParticle> getParticles()
132    {
133       if (tempParticles != null && _particles == null)
134       {
135          _particles = new ArrayList<ReconstructedParticle>(tempParticles.size());
136          for (SIORef ref : tempParticles) _particles.add((ReconstructedParticle) ref.getObject());
137          tempParticles = null;
138       }
139       return _particles == null ? Collections.<ReconstructedParticle>emptyList() : _particles;
140    }
141    
142    public List<Track> getTracks()
143    {
144       if (tempTracks != null && _tracks == null)
145       {
146          _tracks = new ArrayList<Track>(tempTracks.size());
147          for (SIORef ref : tempTracks) _tracks.add((Track) ref.getObject());
148          tempTracks = null;
149       }
150       return _tracks == null ? Collections.<Track>emptyList() : _tracks;
151    }
152 
153    public Vertex getStartVertex()
154    {
155       if (_vertex == null && tempVertex != null)
156       {
157          _vertex = (Vertex) tempVertex.getObject();
158          tempVertex = null;
159       }
160       return super.getStartVertex();
161    }
162 }