View Javadoc

1   package org.lcsim.recon.tracking.vsegment.clustering;
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.DigiTrackerHit;
12  import org.lcsim.recon.tracking.vsegment.hit.TrackerCluster;
13  import org.lcsim.recon.tracking.vsegment.hit.base.TrackerClusterBasic;
14  import org.lcsim.recon.tracking.vsegment.mctruth.MCTruth;
15  
16  /**
17   * Driver that handles clustering of {@link DigiTrackerHit} objects.
18   * The driver fetches a map of digitized hits from the event, and 
19   * creates a map of clusters. 
20   *
21   * @author D.Onoprienko
22   * @version $Id: ClusteringDriver.java,v 1.1 2008/12/06 21:53:43 onoprien Exp $
23   */
24  public class ClusteringDriver extends Driver {
25  
26  // -- Constructors :  ----------------------------------------------------------
27    
28    public ClusteringDriver(Clusterer clusterer) {
29      _clusterer = clusterer;
30      _inMapName = "DigiTrackerHits";
31      _outMapName = "TrackerClusters";
32    }
33  
34  // -- Setters :  ---------------------------------------------------------------
35  
36    /**
37     * Set any <tt>String</tt> parameter. 
38     * The following parameters can be set with this method:
39     * <dl>
40     * <dt>"INPUT_MAP_NAME"</dt> <dd>Name of input collection of digitized hits
41     *                 (type <tt>HashMap<Sensor, ArrayList<DigiTrackerHit>></tt>). 
42     *                 Default: "DigiTrackerHit".</dd>
43     * <dt>"OUTPUT_MAP_NAME"</dt> <dd>Name of output collection of clusters
44     *             (type <tt>HashMap<Sensor, ArrayList<TrackerCluster>></tt>). 
45     *             Default: "TrackerCluster".</dd></dl>
46     * 
47     * @param name   Name of parameter to be set. Case is ignored.
48     * @param value  Value to be assigned to the parameter.
49     * @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
50     *         Subclasses may catch this exception after a call to <tt>super.set()</tt>
51     *         and set their own parameters.
52     */
53    public void set(String name, String value) {
54      if (name.equalsIgnoreCase("INPUT_MAP_NAME")) {
55        _inMapName = value;
56      } else if (name.equalsIgnoreCase("OUTPUT_MAP_NAME")) {
57        _outMapName = value;
58      } else {
59        throw new NoSuchParameterException(name, this.getClass());
60      }
61    }
62    
63  // -- Event processing :  ------------------------------------------------------
64    
65    public void process(EventHeader event) {
66      
67  //    System.out.println(" ");
68  //    System.out.println("Starting clustering");
69      
70      super.process(event);
71          
72      HashMap<Sensor, ArrayList<DigiTrackerHit>> inMap = (HashMap<Sensor, ArrayList<DigiTrackerHit>>) event.get(_inMapName);
73      HashMap<Sensor, ArrayList<TrackerCluster>> outMap = new HashMap<Sensor, ArrayList<TrackerCluster>>();
74  
75      for (Sensor sensor : inMap.keySet()) {
76        ArrayList<TrackerCluster> clusterList = _clusterer.findClusters(sensor, inMap.get(sensor));
77        if ( ! clusterList.isEmpty()) outMap.put(sensor, clusterList);
78      }
79      
80      MCTruth mcTruth = null;
81      try {
82        mcTruth = (MCTruth) event.get("MCTruth");
83      } catch (IllegalArgumentException x) {}
84      if (mcTruth != null) mcTruth.setTrackerClusters(outMap);
85      
86      event.put(_outMapName, outMap);
87    }
88  
89  // -- Private parts :  ---------------------------------------------------------
90    
91    protected String _inMapName;
92    protected String _outMapName;
93    protected Clusterer _clusterer;
94  }