View Javadoc

1   package org.lcsim.recon.cluster.fixedcone;
2   
3   import java.util.List;
4   import org.lcsim.event.CalorimeterHit;
5   import org.lcsim.event.Cluster;
6   import org.lcsim.event.EventHeader;
7   import org.lcsim.geometry.IDDecoder;
8   import org.lcsim.util.Driver;
9   import org.lcsim.recon.util.CalorimeterInformation;
10  import org.lcsim.geometry.Calorimeter.CalorimeterType;
11  
12  /**
13   * FixedConeClusterer implements a
14   * <font face="symbol">q-f </font> cone clustering algorithm
15   * that assigns all neighboring hits to the same cluster if they fall
16   * within a radius R of the cluster axis. The axis is originally defined
17   * by a seed cell, and is iteratively updated as cells are added.
18   * This version of the ClusterBuilder splits overlapping clusters
19   * by assigning cells in the overlap region to the nearest cluster axis.
20   * By default only the "EcalBarrHits" collection is clustered and written
21   * to event with the name "EcalBarrHitsFixedConeClusters"
22   *
23   * @author Norman A. Graf
24   * @version 1.0
25   */
26  
27  public class FixedConeClusterDriver extends Driver
28  {
29      private double _radius;
30      private double _seedEnergy;
31      private double _minEnergy;
32      private FixedConeClusterer _clusterer;
33      private String[] _collNames;
34      private boolean _doall;
35      private String _nameExt;
36      
37      IDDecoder _decoder;
38      
39      /**
40       * Constructor
41       *
42       * @param   radius The cone radius in <font face="symbol">q-f </font> space
43       * @param   seed   The minimum energy for a cone seed cell (in GeV)
44       * @param   minE   The minimum energy for a cluster (in GeV)
45       */
46      public FixedConeClusterDriver(double radius, double seed, double minE)
47      {
48          _radius = radius;
49          // overwrite later with sampling fraction correction
50          _seedEnergy = seed;
51          _minEnergy = minE;
52          _clusterer = new FixedConeClusterer(_radius, _seedEnergy, _minEnergy);
53          _doall = false;
54          _nameExt = "FixedConeClusters";
55      }
56      
57      
58      /**
59       * Processes an Event to find CalorimeterClusters
60       *
61       * @param   event  The Event to process
62       */
63      protected void process(EventHeader event)
64      {
65          if(_collNames == null)
66          {
67              CalorimeterInformation ci = CalorimeterInformation.instance();
68              _collNames = new String[1];
69              _collNames[0] = ci.getCollectionName(CalorimeterType.EM_BARREL);
70          }
71        List<List<CalorimeterHit>> collections = event.get(CalorimeterHit.class);
72        for (List<CalorimeterHit> collection: collections)
73        {
74          String name = event.getMetaData(collection).getName();
75          boolean doit = false;
76          if(_doall)
77          {
78              doit = true;
79          }
80          else
81          {
82              for(int i=0;i<_collNames.length;i++)
83              {
84                  if(name.compareTo(_collNames[i]) == 0)
85                  {
86                      doit = true;
87                      break;
88                  }
89              }
90          }
91          if(doit)
92          {
93              List<Cluster> clusters = _clusterer.createClusters(collection);
94  //        System.out.println("found "+clusters.size()+" clusters");
95              if (clusters.size() > 0) event.put(name+_nameExt,clusters);
96          }
97        }
98      }
99      
100   /**
101    * Set the extension of the hit collection name to use
102    * when writing the cluster collection to event
103    *
104    * @param   ext - the extension to add to the hit collection name
105    */
106    public void setClusterNameExtension(String ext)
107    {
108        _nameExt = ext;
109    }
110   /**
111    * Set the names of the CalorimeterHit collections to cluster
112    *
113    * @param   names - an array of Strings containing the names of the
114    *                  hit collections to cluster
115    */
116    public void setCollectionNames(String[] names)
117    {
118        _collNames = names;
119        _doall = false;
120    }
121   /**
122    * Set a flag to cluster all CalorimeterHit collections
123    *
124    */
125    public void setClusterAllCollections()
126    {
127        _doall = true;
128    }
129     public String toString()
130     {
131         return "FixedConeClusterDriver with clusterer "+_clusterer;
132     }
133 }