View Javadoc

1   package org.lcsim.event.base;
2   
3   import hep.physics.vec.BasicHep3Vector;
4   import hep.physics.vec.BasicHepLorentzVector;
5   import hep.physics.vec.Hep3Vector;
6   import hep.physics.vec.HepLorentzVector;
7   
8   import java.util.ArrayList;
9   import java.util.List;
10  
11  import org.lcsim.event.Cluster;
12  import org.lcsim.event.ParticleID;
13  import org.lcsim.event.ReconstructedParticle;
14  import org.lcsim.event.Track;
15  import org.lcsim.event.Vertex;
16  
17  /**
18   * Default implementation of ReconstructedParticle
19   * @author Norman Graf
20   * @version $Id: BaseReconstructedParticle.java,v 1.12 2011/04/14 05:02:26 grefe Exp $
21   * Change setParticleIdUsed to check that ParticleID is in the ParticleID list,
22   * and if not add it.
23   *                    Ron Cassell
24   */
25  public class BaseReconstructedParticle implements ReconstructedParticle
26  {
27      protected int _type;
28      protected HepLorentzVector _fourVec = new BasicHepLorentzVector(0.,0.,0.,0.);
29      protected double[] _covMatrix = new double[10];
30      protected double _mass;
31      protected double _charge;
32      protected Hep3Vector _referencePoint = new BasicHep3Vector(0.,0.,0.);
33      protected List<ParticleID> _particleIds = new ArrayList<ParticleID>();
34      protected ParticleID _particleIdUsed = new UnknownParticleID();
35      protected double _goodnessOfPid;
36      protected List<ReconstructedParticle> _particles = new ArrayList<ReconstructedParticle>();
37      protected List<Cluster> _clusters = new ArrayList<Cluster>();
38      protected List<Track> _tracks = new ArrayList<Track>();
39      protected Vertex _vertex;
40      
41      /** Creates a new instance of BaseReconstructedParticle */
42      public BaseReconstructedParticle()
43      {
44      }
45      
46      public BaseReconstructedParticle(double mass) {
47      	_mass = mass;
48      }
49      
50      public BaseReconstructedParticle(HepLorentzVector v) {
51          _fourVec = v;
52      }
53      
54      public BaseReconstructedParticle(double mass, HepLorentzVector v) {
55          _fourVec = v;
56      	_mass = mass;
57      }
58      
59      public BaseReconstructedParticle(double E, Hep3Vector v) {
60          _fourVec = new BasicHepLorentzVector(E,v);
61      }
62      
63      public BaseReconstructedParticle(double E, double px, double py, double pz) {
64          _fourVec = new BasicHepLorentzVector(E, px, py, pz);
65      }
66      
67      public void set4Vector(HepLorentzVector v)
68      {
69          _fourVec = v;
70      }
71      
72      public void setMass(double m)
73      {
74          _mass = m;
75      }
76      
77      public void setCharge(double c)
78      {
79          _charge = c;
80      }
81      
82      public void setType(int t)
83      {
84          _type = t;
85      }
86      
87      public void setReferencePoint(Hep3Vector v)
88      {
89          _referencePoint = v;
90      }
91      
92      public void setReferencePoint(double x, double y, double z)
93      {
94          _referencePoint = new BasicHep3Vector(x, y, z);
95      }
96      
97      public void setParticleIdUsed(ParticleID id)
98      {
99          if(!_particleIds.contains(id))_particleIds.add(id);
100         _particleIdUsed = id;
101     }
102     
103     public void setGoodnessOfPid(double g)
104     {
105         _goodnessOfPid = g;
106     }
107     
108 // ReconstructedParticle interface
109     
110     /**
111      * Type of reconstructed particle.
112      *  Check/set collection parameters ReconstructedParticleTypeNames and
113      *  ReconstructedParticleTypeValues.
114      * @return the type
115      */
116     public int getType()
117     {
118         return _type;
119     }
120     
121     /**
122      * The magnitude of the reconstructed particle's momentum
123      * @return the momentum of this particle.
124      */
125     public Hep3Vector getMomentum()
126     {
127         return _fourVec.v3();
128     }
129     
130     /**
131      * Energy of the  reconstructed particle
132      * @return the energy of this particle in GeV
133      */
134     public double getEnergy()
135     {
136         return _fourVec.t();
137     }
138     
139     /**
140      * Covariance matrix of the reconstructed particle's 4vector (10 parameters).
141      *  Stored as lower triangle matrix of the four momentum (px,py,pz,E), i.e.
142      *  cov(px,px), cov(py,px), cov( py,py ) , ....
143      * @return covariance matrix as a packed array
144      */
145     public double[] getCovMatrix()
146     {
147         return _covMatrix;
148     }
149     
150     /**
151      * Mass of the  reconstructed particle, set independently from four vector quantities
152      * @return the mass in GeV
153      */
154     public double getMass()
155     {
156         return _mass;
157     }
158     
159     /**
160      * Charge of the reconstructed particle.
161      * @return the charge in units of the electron charge
162      */
163     public double getCharge()
164     {
165         return _charge;
166     }
167     
168     /**
169      * Reference point of the reconstructedParticle parameters.
170      * @return the reference point for this particle in mm
171      */
172     public Hep3Vector getReferencePoint()
173     {
174         return _referencePoint;
175     }
176     
177     /**
178      * The particle Id's sorted by their likelihood.
179      * @see ParticleID
180      * @return a list of particle IDs for this particle, sorted by likelihood
181      */
182     public List<ParticleID> getParticleIDs()
183     {
184         return _particleIds;
185     }
186     
187     /**
188      * The particle Id used for the kinematics of this particle.
189      * @see ParticleID
190      * @return the most likely identification for this particle
191      */
192     public ParticleID getParticleIDUsed()
193     {
194         return _particleIdUsed;
195     }
196     
197     /**
198      * The overall goodness of the PID on a scale of [0;1].
199      * @return the "goodness" of this identification. not yet defined.
200      */
201     public double getGoodnessOfPID()
202     {
203         return _goodnessOfPid;
204     }
205     
206     /**
207      * The reconstructed particles that have been combined to this particle.
208      * @return a list of ReconstructedParticles if this is a compund ReconstructedParticle
209      */
210     public List<ReconstructedParticle> getParticles()
211     {
212         return _particles;
213     }
214     
215     /**
216      * The clusters that have been used for this particle.
217      * @return the list of calorimeter clusters contributing to this ReconstructedParticle
218      */
219     public List<Cluster> getClusters()
220     {
221         return _clusters;
222     }
223     
224     /**
225      * The tracks that have been used for this particle.
226      * @return the list of tracks contributing to this ReconstructedParticle
227      */
228     public List<Track> getTracks()
229     {
230         return _tracks;
231     }
232     
233     /**
234      * Add a ParticleID object.
235      * @see ParticleID
236      * @param pid The ParticleID to associate with this ReconstructedParticle
237      */
238     public void addParticleID(ParticleID pid)
239     {
240         _particleIds.add(pid);
241         _particleIdUsed = pid;
242     }
243     
244     /**
245      * Adds a particle that has been used to create this particle.
246      * @param particle A ReconstructedParticle which contributes to this ReconstructedParticle.
247      */
248     // TODO make sure kinematics of this particle are also updated
249     public void addParticle(ReconstructedParticle particle)
250     {
251         _particles.add(particle);
252     }
253     
254     /**
255      * Adds a cluster that has been used to create this particle.
256      * @param cluster A Cluster which contributes to this ReconstructedParticle.
257      */
258     // TODO make sure kinematics of this particle are also updated
259     public void addCluster(Cluster cluster)
260     {
261         _clusters.add(cluster);
262     }
263     
264     /**
265      * Adds a track that has been used to create this particle.
266      * @param track A Track which contributes to this ReconstructedParticle.
267      */
268     // TODO make sure kinematics of this particle are also updated
269     public void addTrack(Track track)
270     {
271         _tracks.add(track);
272     }
273     
274     /**
275      * Returns this particle's momentum and energy as a four vector
276      * @return The four vector representation of this ReconstructedParticle.
277      */
278     // TODO fix this so that adding tracks or clusters or ReconstructedParticle
279     // either updates the four-vector, or it can be set independently.
280     public HepLorentzVector asFourVector()
281     {
282         return _fourVec;
283     }
284     
285     // TODO finish this...
286     public String toString()
287     {       
288         String className = getClass().getName();
289         int lastDot = className.lastIndexOf('.');
290         if(lastDot!=-1)className = className.substring(lastDot+1);
291         String pidUsed = "";
292         try {
293         	pidUsed = String.valueOf(_particleIdUsed.getPDG());
294         } catch (NullPointerException e) {
295         	pidUsed = "no particle ID defined";
296         }
297         StringBuffer sb = new StringBuffer(className+": Type: "+_type+" pdgID: "+pidUsed+" \n");
298         sb.append("E: "+getEnergy());
299         return sb.toString();
300     }
301 
302    public Vertex getStartVertex()
303    {
304       return _vertex;
305    }
306    public void setStartVertex(Vertex vertex)
307    {
308       _vertex = vertex;
309    }
310     
311 }