View Javadoc

1   package org.lcsim.recon.tracking.trffit;
2   
3   import org.lcsim.recon.tracking.trfbase.Hit;
4   import java.util.*;
5   import org.lcsim.recon.tracking.trfutil.Assert;
6   
7   /** TrackMcHitInfo handles information about the MC Id of
8    * the hits on a track.
9    *
10   *@author Norman A. Graf
11   *@version 1.0
12   *
13   */
14  public class TrackMcHitInfo
15  {
16      
17      // The map of Mc Ids with their number of hits
18      private Map _mcidmap;
19      
20      // The number of hits on this track
21      private int _numhits;
22      
23      // The best mc id
24      private int _bestid;
25      
26      // The purity
27      private double _purity;
28      
29      // The list of all Mc Ids
30      private List _mcidlist;
31      
32      //methods
33      
34      //
35      
36      /**
37       *Default Constructor leaves the object incomplete
38       *
39       */
40      public TrackMcHitInfo()
41      {
42      }
43      
44      //
45      
46      /**
47       *Full Constructor
48       *
49       * @param   nhits  The number of hits on this track.
50       * @param   mcidmap  The map of number of hits per MC ID keyed on id.
51       */
52      public TrackMcHitInfo(int nhits, Map mcidmap)
53      {
54          _mcidlist = new ArrayList();
55          _mcidmap = new HashMap(mcidmap);
56          _numhits = nhits;
57          _bestid = 0;
58          _purity = 0.;
59          //Map contains the MC track id paired with the number of times it occurred
60          //on the track
61          int nentries = 0;
62          // Loop over the map...
63          for( Iterator it=mcidmap.entrySet().iterator(); it.hasNext(); )
64          {
65              Map.Entry e = (Map.Entry) it.next();
66  //            System.out.println( e.getKey()+ ": " + e.getValue() );
67              _mcidlist.add( e.getKey() );
68              if ( ((Integer)e.getValue()).intValue()>nentries )
69              {
70                  nentries = ((Integer)e.getValue()).intValue();
71                  Assert.assertTrue(nentries<= nhits);// Can't have more occurrences than hits.
72                  _bestid = ( (Integer)e.getKey()).intValue();// Best id by definition
73                  _purity = (double)nentries/(double)_numhits; // Purity is fraction of possible hits
74              }
75          }
76      }
77      
78      //
79      
80      /**
81       *Return the best MC ID for this track.
82       * This is defined as the MC ID with the most number of Hits (not measurements!)
83       *
84       * @return  The MC Track ID for this track.
85       */
86      public int bestMcId()
87      {
88          return _bestid;
89      }
90      
91      //
92      
93      /**
94       *Return the purity of this track.
95       * This is defined as the ratio of number of hits with best id to total number of hits
96       *
97       * @return The purity of the track defined as the ratio of the number of
98       * best MC ID its to the total number of hits on the track.
99       */
100     public double purity()
101     {
102         return _purity;
103     }
104     
105     //
106     
107     /**
108      *Return the number of hits on this track.
109      *
110      * @return The total number of hits on this track. Note that this
111      * is not the number of measurements, or degrees of freedom.
112      */
113     public int numHits()
114     {
115         return _numhits;
116     }
117     
118     //
119     
120     /**
121      *Return the full list of MC IDs.
122      *
123      * @return  The list of MC IDs associated with this track.
124      */
125     public List mc_idlist()
126     {
127         return new ArrayList(_mcidlist);
128     }
129     
130     //
131     
132     /**
133      * Return a map of MC IDs with the number of hits for that ID.
134      *
135      * @return Map keyed on MC ID containing the number of hits for that ID.
136      */
137     public Map mcHitNumber()
138     {
139         return new HashMap(_mcidmap);
140     }
141     
142     
143     /**
144      * Output stream
145      *
146      * @return String representation of the class
147      */
148     public String toString()
149     {
150         return getClass().getName();
151     }
152     
153 }
154