View Javadoc

1   package org.lcsim.recon.tracking.vsegment.hitmaking;
2   
3   import java.util.*;
4   
5   import org.lcsim.event.EventHeader;
6   import org.lcsim.recon.cat.util.NoSuchParameterException;
7   import org.lcsim.util.Driver;
8   
9   import org.lcsim.recon.tracking.vsegment.geom.Sensor;
10  import org.lcsim.recon.tracking.vsegment.geom.SensorType;
11  import org.lcsim.recon.tracking.vsegment.hit.TrackerCluster;
12  import org.lcsim.recon.tracking.vsegment.hit.TrackerHit;
13  
14  import static org.lcsim.recon.tracking.vsegment.hitmaking.HitMakingDriver.UsedClusters;
15  
16  /**
17   * Driver that that constructs {@link TrackerHit} collection given {@link TrackerCluster}
18   * collection. 
19   *
20   * @author D. Onoprienko
21   * @version $Id: HitMakingDriver.java,v 1.1 2008/12/06 21:53:44 onoprien Exp $
22   */
23  public class HitMakingDriver extends Driver {
24    
25  // -- Constructors :  ----------------------------------------------------------
26    
27    public HitMakingDriver(TrackerHitMaker hitMaker) {
28      _clusterMapName = "INPUT_MAP_NAME";
29      _hitMapName= "OUTPUT_MAP_NAME";
30      _hitMaker = hitMaker;
31      _registerHitsWithClusters = false;
32      _usedClusters = UsedClusters.INCLUDE_NEW;
33      
34    }
35  
36  // -- Setters :  ---------------------------------------------------------------
37  
38    /**
39     * Set any <tt>String</tt> parameter. 
40     * The following parameters can be set with this method:
41     * <p><dl>
42     * <dt>"INPUT_MAP_NAME"</dt> <dd>Name of input collection of tracker clusters
43     *       (type <tt>HashMap&lt;Sensor, ArrayList&lt;TrackerCluster&gt;&gt;</tt>). 
44     *       <br>Default: "TrackerClusters".</dd>
45     * <dt>"OUTPUT_MAP_NAME"</dt> <dd>Name of output collection of tracker hits
46     *       (type <tt>HashMap&lt;Sensor, ArrayList&lt;TrackerHit&gt;&gt;</tt>). 
47     *       <br>Default: "TrackerHits".</dd>
48     * <dt>"USED_CLUSTERS"</dt> <dd>Tell the driver what to do with <tt>Clusters</tt>
49     *       that already have <tt>TYrackerHits</tt> associated with them. Possible values:
50     *           <tt>"SKIP"</tt> - ignore used clusters;
51     *           <tt>"INCLUDE_OLD"</tt> - include existing <tt>TrackerHits</tt> associated with
52     *                                    used clusters into the output collection;
53     *           <tt>"INCLUDE_NEW"</tt> - produce new <tt>TrackerHits</tt> from used clusters,
54     *                                    and include them into output collection.
55     *           <br>Default: "INCLUDE_NEW".</dd></dl>
56     * 
57     * @param name   Name of parameter to be set. Case is ignored.
58     * @param value  Value to be assigned to the parameter.
59     * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
60     *         Subclasses may catch this exception after a call to <tt>super.set()</tt>
61     *         and set their own parameters.
62     */
63    public void set(String name, String value) {
64      if (name.equalsIgnoreCase("INPUT_MAP_NAME")) {
65        _clusterMapName = value;
66      } else if (name.equalsIgnoreCase("OUTPUT_MAP_NAME")) {
67        _hitMapName = value;
68      } else if (name.equalsIgnoreCase("USED_CLUSTERS")) {
69        if (value.equalsIgnoreCase("SKIP")) {
70          _usedClusters = UsedClusters.SKIP;
71        } else if (value.equalsIgnoreCase("INCLUDE_OLD")) {
72          _usedClusters = UsedClusters.INCLUDE_OLD;
73        } else if (value.equalsIgnoreCase("INCLUDE_NEW")) {
74          _usedClusters = UsedClusters.INCLUDE_NEW;
75        } else if (value.equalsIgnoreCase("UPDATE_SKIP")) {
76          _usedClusters = UsedClusters.UPDATE_SKIP;
77          throw new IllegalArgumentException("Not yet implemented: set(" + name + ", " + value + ")");
78        } else if (value.equalsIgnoreCase("UPDATE_INCLUDE")) {
79          _usedClusters = UsedClusters.UPDATE_INCLUDE;
80          throw new IllegalArgumentException("Not yet implemented: set(" + name + ", " + value + ")");
81        } else {
82          throw new IllegalArgumentException("Illegal value: set(" + name + ", " + value + ")");
83        }
84      } else {
85        throw new NoSuchParameterException(name, this.getClass());
86      }
87    }
88  
89    /**
90     * Set any <tt>boolean</tt> parameter. 
91     * The following parameters can be set with this method:
92     * <p><dl>
93     * <dt>"REGISTER_HITS_WITH_CLUSTERS"</dt> <dd>If set to <tt>true</tt>, newly created
94     *           tracker hits will be registered with clusters from which they were 
95     *           produced, and can be later accessed through a call to 
96     *           {@link TrackerCluster#getTrackerHits} method.
97     *           <br>Default: <tt>false</tt>.</dd></dl>
98     * 
99     * @param name   Name of parameter to be set. Case is ignored.
100    * @param value  Value to be assigned to the parameter.
101    * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
102    *         Subclasses may catch this exception after a call to <tt>super.set()</tt>
103    *         and set their own parameters.
104    */
105   public void set(String name, boolean value) {
106     if (name.equalsIgnoreCase("REGISTER_HITS_WITH_CLUSTERS")) {
107       _registerHitsWithClusters = value;
108     } else {
109       throw new NoSuchParameterException(name, this.getClass());
110     }
111   }
112   
113 // -- Event processing :  ------------------------------------------------------
114   
115   public void process(EventHeader event) {
116     
117 //    System.out.println(" ");
118 //    System.out.println("Starting TrackerHit making");
119     
120     super.process(event);
121     
122     HashMap<Sensor, ArrayList<TrackerCluster>> clusterMap = 
123             (HashMap<Sensor, ArrayList<TrackerCluster>>) event.get(_clusterMapName);
124     HashMap<Sensor, ArrayList<TrackerHit>> hitMap = new HashMap<Sensor, ArrayList<TrackerHit>>();
125 
126     for (Sensor sensor : clusterMap.keySet()) {
127       List<TrackerCluster> clusterList = clusterMap.get(sensor);
128       ArrayList<TrackerHit> hitList = new ArrayList<TrackerHit>(clusterList.size());
129       for (TrackerCluster cluster : clusterList) {
130         List<TrackerHit> oldHits = cluster.getTrackerHits();
131         if (oldHits.isEmpty() || _usedClusters == UsedClusters.INCLUDE_NEW) {
132           TrackerHit hit = _hitMaker.make(cluster);
133           hitList.add(hit);
134           if (_registerHitsWithClusters) {
135             cluster.addTrackerHit(hit);
136           }
137         } else if (_usedClusters == UsedClusters.INCLUDE_OLD) {
138           hitList.addAll(oldHits);
139         }
140       }
141       if (! hitList.isEmpty()) {
142         hitList.trimToSize();
143         hitMap.put(sensor, hitList);
144       }
145     }
146 
147     event.put(_hitMapName, hitMap);
148   }
149   
150 // -- Private parts :  ---------------------------------------------------------
151   
152   private String _clusterMapName;
153   private String _hitMapName;
154   
155   protected boolean _registerHitsWithClusters;
156   
157   protected TrackerHitMaker _hitMaker;
158   
159   protected enum UsedClusters {SKIP, INCLUDE_OLD, INCLUDE_NEW, UPDATE_SKIP, UPDATE_INCLUDE}
160   protected UsedClusters _usedClusters;
161 }