1
2
3
4
5
6
7
8
9 package org.lcsim.recon.cluster.localequivalence;
10
11 import java.util.ArrayList;
12 import java.util.Comparator;
13 import java.util.List;
14 import java.util.SortedSet;
15 import java.util.TreeSet;
16 import org.lcsim.event.CalorimeterHit;
17
18
19
20
21
22 public class NNCluster implements Comparable
23 {
24
25 private SortedSet _cells;
26 private double _value = 0;
27 private List<CalorimeterHit> _hits = new ArrayList<CalorimeterHit>();
28
29
30
31
32
33 public NNCluster()
34 {
35 _cells = new TreeSet( new Comparator()
36 {
37 public int compare(Object o1, Object o2)
38 {
39
40 double value1 = ((Cell)o1).value();
41 double value2 = ((Cell)o2).value();
42 if(value1!=value2) return (value1< (value2) ? -1 : (value1 == (value2) ? 0 : 1));
43
44 long ndx1 = ((Cell)o1).cellID();
45 long ndx2 = ((Cell)o2).cellID();
46 return (ndx1<ndx2 ? -1 : ((ndx1==ndx2) ? 0 : 1));
47
48 }
49 }
50 );
51 }
52
53 public SortedSet cells()
54 {
55 return _cells;
56 }
57
58 public int size()
59 {
60 return _cells.size();
61 }
62
63 public void addCell(Cell cell)
64 {
65 _cells.add(cell);
66 _value+=cell.value();
67 Cell3D c3d = (Cell3D) cell;
68 _hits.add(c3d.getCalorimeterHit());
69 }
70
71 public List<CalorimeterHit> hits()
72 {
73 return _hits;
74 }
75
76 public Cell highestCell()
77 {
78 return (Cell)_cells.last();
79 }
80
81 public double value()
82 {
83 return _value;
84 }
85
86
87 public int compareTo(Object o)
88 {
89 double value = ( (NNCluster) o)._value;
90
91
92 return (_value < value ? -1 : (_value == value ? 0 : 1));
93 }
94
95 public String toString()
96 {
97 return "\n NNCluster with "+size()+" cells, centered at "+highestCell().cellID()+" value= "+_value+"\n"+_cells;
98 }
99 }