StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StJetSpliterMerger.cxx
1 // $Id: StJetSpliterMerger.cxx,v 1.9 2008/05/08 05:02:13 tai Exp $
2 //StJetSpliterMerger.cxx
3 //M.L. Miller (Yale Software)
4 //10/02
5 
6 //std
7 #include <iostream>
8 #include <ctime>
9 #include <algorithm>
10 #include <list>
11 #include <utility>
12 #include <functional>
13 #include <vector>
14 #include <map>
15 using std::map;
16 using std::multimap;
17 using std::vector;
18 using std::copy;
19 using std::find;
20 using std::find_first_of;
21 using std::sort;
22 
23 #include "StProtoJet.h"
24 #include "StEtaPhiCell.h"
25 #include "Functors.h"
26 #include "StJetSpliterMerger.h"
27 
28 void StJetSpliterMerger::splitMerge(CellList& preJets)
29 {
30  _preJets.clear();
31  copy(preJets.begin(), preJets.end(), back_inserter(_preJets));
32  preJets.clear();
33 
34  while(!_preJets.empty()) {
35 
36  _OverlapList.clear();
37 
38  _preJets.sort(StJetEtCellEtGreaterThan());
39 
40  for (CellList::iterator otherIt = ++(_preJets.begin()); otherIt != _preJets.end(); ++otherIt) {
41 
42  StEtaPhiCell::CellList& otherCells = (*otherIt)->cellList();
43  EtNeighbor neighbor;
44 
45  for (StEtaPhiCell::CellList::iterator rootSetIt = _preJets.front()->cellList().begin(); rootSetIt != _preJets.front()->cellList().end(); ++rootSetIt) {
46  for (StEtaPhiCell::CellList::iterator otherSetIt = otherCells.begin(); otherSetIt != otherCells.end(); ++otherSetIt) {
47  neighbor.check(*rootSetIt, *otherSetIt);
48  }
49  }
50 
51  if (neighbor.nCommonCells <= 0) continue;
52 
53  neighbor._otherCell = otherIt;
54  _OverlapList.push_back(neighbor);
55 
56  }
57 
58  if (_OverlapList.empty()) {
59  preJets.push_back(_preJets.front());
60  _preJets.pop_front();
61  } else {
62 
63  EtNeighbor& n = *min_element(_OverlapList.begin(), _OverlapList.end());
64 
65  StEtaPhiCell& neighborJet = **(n._otherCell);
66 
67  if (n.sharedEt/neighborJet.eT() > splitFraction() ) { //merge these two
68  merge(*_preJets.front(), neighborJet, n.cells);
69 
70  //remove neighbor jet
71  _preJets.erase(n._otherCell);
72  } else { //split these two
73  split(*_preJets.front(), neighborJet, n.cells);
74  }
75 
76  }
77  }
78 }
79 
80 //this really has to be encapsulated in StEtaPhiCell class. For now we bust out the guts of the code here
81 void StJetSpliterMerger::merge(StEtaPhiCell& root, StEtaPhiCell& neighbor, CellVec& commonCells)
82 {
83  CellList& rootList = root.cellList();
84  CellList& neighborList = neighbor.cellList();
85 
86  for (CellList::iterator it2=neighborList.begin(); it2!=neighborList.end(); ++it2) {
87  //add to root
88  if (std::find(rootList.begin(), rootList.end(), (*it2))==rootList.end() ) {
89  rootList.push_back(*it2);
90  }
91  }
92 
93  //assume that neighbor will be discarded. Don't waste time removing cells from neighbor
94  PostMergeUpdater updater;
95  updater(root);
96 }
97 
98 //this really has to be encapsulated in StEtaPhiCell class. For now we bust out the guts of the code here
99 void StJetSpliterMerger::split(StEtaPhiCell& root, StEtaPhiCell& neighbor, CellVec& commonCells)
100 {
101  CellList& rootList = root.cellList();
102  CellList& neighborList = neighbor.cellList();
103 
104  for (CellVec::iterator it=commonCells.begin(); it!=commonCells.end(); ++it) {
105 
106  double distanceToRoot = root.distance(**it);
107  double distanceToNeighbor = neighbor.distance(**it);
108  if (distanceToRoot<distanceToNeighbor) { //root keeps it
109  neighborList.remove(*it);
110  } else { //neighbor keeps it
111  rootList.remove(*it);
112  }
113  }
114 
115  PostMergeUpdater updater;
116  updater(root);
117  updater(neighbor);
118 
119 }
120 
121 
122 void PreJetLazyUpdater ::operator()(StEtaPhiCell& cell)
123 {
124  sumEt += cell.eT();
125 }
126 
127 void PreJetLazyUpdater ::operator()(StEtaPhiCell* cell)
128 {
129  (*this)(*cell);
130 }
131 
132 void PostMergeUpdater::operator()(StEtaPhiCell& cell)
133 {
134  //now update each cell:
135  PreJetLazyUpdater updater;
136  updater = for_each( cell.cellList().begin(), cell.cellList().end(), updater );
137 
138  //now update jet-eT
139  cell.mEt = updater.sumEt;
140 }
void splitMerge(CellList &jets)
action