View Javadoc

1   package org.lcsim.recon.cat;
2   
3   import java.util.*;
4   
5   import org.lcsim.event.*;
6   import org.lcsim.util.Driver;
7   
8   import org.lcsim.recon.cat.util.NoSuchParameterException;
9   
10  /**
11   * Driver for removing tracker hits associated with previously found tracks.
12   *
13   * @author D. Onoprienko
14   * @version $Id: AssociatedHitRemover.java,v 1.1 2007/04/06 21:48:14 onoprien Exp $
15   */
16  public class AssociatedHitRemover extends Driver {
17    
18    // --  Constructors :  -------------------------------------------------------
19    
20    public AssociatedHitRemover() {}
21    
22    // -- Setters :  -------------------------------------------------------------
23    
24    /**
25     * Set any <tt>String</tt> parameter.
26     * The following parameters can be set with this method:<br>
27     * <tt>"Track_List"</tt> - name of input track list. Hits associated with tracks from this list will be excluded.
28     * <tt>"Input_Tracker_Hit_List"</tt> - name of input hit list.
29     * <tt>"Output_Tracker_Hit_List"</tt> - name of output hit list.
30     * @param name   Name of parameter to be set
31     * @param value  Value to be assigned to the parameter.
32     * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
33     *         Subclasses may catch this exception after a call to <tt>super.set()</tt>
34     *         and set their own parameters.
35     */
36    public void set(String name, Object value) throws NoSuchParameterException {
37      if (name.equalsIgnoreCase("Track_List")) {
38        _trackListName = (String)value;
39      } else if (name.equalsIgnoreCase("Input_Tracker_Hit_List")) {
40        _inputTrackerHitListName = (String)value;
41      } else if (name.equalsIgnoreCase("Output_Tracker_Hit_List")) {
42        _outputTrackerHitListName = (String)value;
43      } else {
44        throw new NoSuchParameterException(name, this.getClass());
45      }
46    }
47    
48    
49    // -- Processing event :  ----------------------------------------------------
50    
51    /**
52     * Process event.
53     */
54    public void process(EventHeader event) {
55      
56      _event = event;
57      
58      // Fetch input lists :
59      
60      _inputTrackerHitList = _event.get(TrackerHit.class, _inputTrackerHitListName);
61      _trackList = _event.get(Track.class, _trackListName);
62      
63      // Compile list of tracker hits associated with tracks :
64      
65      ArrayList<TrackerHit> associatedTrackerHitList = new ArrayList<TrackerHit>();
66      for (Track track : _trackList) {
67        associatedTrackerHitList.addAll(track.getTrackerHits());
68      }
69      
70      // Compile a list of unassociated hits :
71      
72      ArrayList _outputTrackerHitList = new ArrayList<TrackerHit>();
73      for (TrackerHit hit : _inputTrackerHitList) {
74        for (TrackerHit assHit : associatedTrackerHitList) {
75          hit = match(hit, assHit);
76          if (hit == null) break;
77        }
78        if (hit != null) _outputTrackerHitList.add(hit);
79      }
80      _outputTrackerHitList.trimToSize();
81      
82      // Put the output list back into the event :
83      
84      _event.put(_outputTrackerHitListName, _outputTrackerHitList, TrackerHit.class, 0);
85      
86      return;
87      
88    }
89  
90    /**
91     * Returns the remaining portion of hit after subtracting refHit from it.
92     * Used for matching hits from input collection with hits associated with
93     * previously found tracks. Simple implementation here returns the original hit
94     * if both <tt>hit</tt> and <tt>refHit</tt> refer to the same object. Subclasses 
95     * may override this method with more elaborate algorithms.
96     */
97    protected TrackerHit match(TrackerHit hit, TrackerHit refHit) {
98      return (hit == refHit) ? null : hit ;
99    }
100   
101   // -- Private helper methods :  ----------------------------------------------
102   
103   
104   // -- Private data :  --------------------------------------------------------
105   
106   protected EventHeader _event;
107   
108   protected String _inputTrackerHitListName;
109   protected String _trackListName;
110   protected String _outputTrackerHitListName;
111   
112   protected List<TrackerHit> _inputTrackerHitList;
113   protected List<Track> _trackList;
114   protected ArrayList<TrackerHit> _outputTrackerHitList;
115   
116 }