View Javadoc

1   /*
2    * NNAlgoClusterDriver.java
3    *
4    * Created on April 4, 2006, 2:37 PM
5    *
6    * $Id: $
7    */
8   
9   package org.lcsim.recon.cluster.localequivalence;
10  
11  import java.util.ArrayList;
12  import java.util.HashMap;
13  import java.util.List;
14  import java.util.Map;
15  import org.lcsim.event.CalorimeterHit;
16  import org.lcsim.event.Cluster;
17  import org.lcsim.event.EventHeader;
18  import org.lcsim.util.Driver;
19  import org.lcsim.event.base.BaseCluster;
20  import org.lcsim.lcio.LCIOConstants;
21  
22  /**
23   *
24   * @author Norman Graf
25   */
26  public class NNAlgoClusterDriver extends Driver
27  {
28      // the neighborhood in u to search
29      private int _dU;
30      // the neighborhood in v to search
31      private int _dV;
32      // the neighborood in layers to search
33      private int _dLayer;
34      // energy threshold
35      private double _thresh;
36      
37      private NNAlgo _clusterer;
38      
39      private boolean _doall;
40      private String[] _collNames;
41      private String _nameExt;
42     
43      private boolean debug;
44      
45      /** Creates a new instance of NNAlgoClusterDriver */
46      // JAS needs default constructor
47      public NNAlgoClusterDriver()
48      {
49          this(3, 3, 5, .1); // why was this 15?
50      }
51      // fully qualified constructor
52      public NNAlgoClusterDriver(int dU, int dV, int dLayer, double threshold)
53      {
54          _dU = dU;
55          _dV = dV;
56          _dLayer = dLayer;
57          _thresh = threshold;
58          _doall = true;
59          _collNames = new String[4];
60          _collNames[0] = "EcalBarrelHits";
61          _collNames[1] = "EcalEndcapHits";
62          _collNames[2] = "BeamCalHits";
63          _collNames[3] = "LumiCalHits";
64          _nameExt = "EMClusters";
65          _clusterer = new NNAlgo(_thresh, _dLayer, _dU, _dV);
66      }
67      
68      protected void process(EventHeader event)
69      {
70          //First look for clusters in individual collections
71          
72          List<List<CalorimeterHit>> collections = event.get(CalorimeterHit.class);
73          for (List<CalorimeterHit> collection: collections)
74          {
75              String name = event.getMetaData(collection).getName();
76              boolean doit = false;
77              if(_doall)
78              {
79                  doit = true;
80              }
81              else
82              {
83                  for(int i=0;i<_collNames.length;i++)
84                  {
85                      if(name.compareTo(_collNames[i]) == 0)
86                      {
87                          doit = true;
88                          break;
89                      }
90                  }
91              }
92              if(doit)
93              {
94                  Map<Long, CalorimeterHit> hitmap = new HashMap<Long, CalorimeterHit>();
95                  for(CalorimeterHit hit : collection)
96                  {
97                      hitmap.put(hit.getCellID(), hit);
98                  }
99                  List<NNCluster> clusters = _clusterer.cluster(hitmap);
100                 
101                 List<BaseCluster> bclus = new ArrayList<BaseCluster>();
102                 for(NNCluster clus : clusters)
103                 {
104                     if (clus.size()>5) // TODO fix this hard-coded cut
105                     {
106                         BaseCluster bc = new BaseCluster();
107                         List<CalorimeterHit> hits = clus.hits();
108                         for(CalorimeterHit hit: hits)
109                         {
110                             bc.addHit(hit);
111                         }
112                         bclus.add(bc);
113                     }
114                 }
115                 if (bclus.size() > 0)
116                 {
117                     int flag = 1 << LCIOConstants.CLBIT_HITS;
118                     event.put(name+_nameExt,bclus,Cluster.class,(1<<31));
119                 }
120             }
121         }
122     }
123 }