00001
00002
00003
00004
00005
00006
00007 #include <iostream>
00008 #include <ctime>
00009 #include <algorithm>
00010 #include <list>
00011 #include <utility>
00012 #include <functional>
00013 #include <vector>
00014 #include <map>
00015 using std::map;
00016 using std::multimap;
00017 using std::vector;
00018 using std::copy;
00019 using std::find;
00020 using std::find_first_of;
00021 using std::sort;
00022
00023 #include "StProtoJet.h"
00024 #include "StEtaPhiCell.h"
00025 #include "Functors.h"
00026 #include "StJetSpliterMerger.h"
00027
00028 void StJetSpliterMerger::splitMerge(CellList& preJets)
00029 {
00030 _preJets.clear();
00031 copy(preJets.begin(), preJets.end(), back_inserter(_preJets));
00032 preJets.clear();
00033
00034 while(!_preJets.empty()) {
00035
00036 _OverlapList.clear();
00037
00038 _preJets.sort(StJetEtCellEtGreaterThan());
00039
00040 for (CellList::iterator otherIt = ++(_preJets.begin()); otherIt != _preJets.end(); ++otherIt) {
00041
00042 StEtaPhiCell::CellList& otherCells = (*otherIt)->cellList();
00043 EtNeighbor neighbor;
00044
00045 for (StEtaPhiCell::CellList::iterator rootSetIt = _preJets.front()->cellList().begin(); rootSetIt != _preJets.front()->cellList().end(); ++rootSetIt) {
00046 for (StEtaPhiCell::CellList::iterator otherSetIt = otherCells.begin(); otherSetIt != otherCells.end(); ++otherSetIt) {
00047 neighbor.check(*rootSetIt, *otherSetIt);
00048 }
00049 }
00050
00051 if (neighbor.nCommonCells <= 0) continue;
00052
00053 neighbor._otherCell = otherIt;
00054 _OverlapList.push_back(neighbor);
00055
00056 }
00057
00058 if (_OverlapList.empty()) {
00059 preJets.push_back(_preJets.front());
00060 _preJets.pop_front();
00061 } else {
00062
00063 EtNeighbor& n = *min_element(_OverlapList.begin(), _OverlapList.end());
00064
00065 StEtaPhiCell& neighborJet = **(n._otherCell);
00066
00067 if (n.sharedEt/neighborJet.eT() > splitFraction() ) {
00068 merge(*_preJets.front(), neighborJet, n.cells);
00069
00070
00071 _preJets.erase(n._otherCell);
00072 } else {
00073 split(*_preJets.front(), neighborJet, n.cells);
00074 }
00075
00076 }
00077 }
00078 }
00079
00080
00081 void StJetSpliterMerger::merge(StEtaPhiCell& root, StEtaPhiCell& neighbor, CellVec& commonCells)
00082 {
00083 CellList& rootList = root.cellList();
00084 CellList& neighborList = neighbor.cellList();
00085
00086 for (CellList::iterator it2=neighborList.begin(); it2!=neighborList.end(); ++it2) {
00087
00088 if (std::find(rootList.begin(), rootList.end(), (*it2))==rootList.end() ) {
00089 rootList.push_back(*it2);
00090 }
00091 }
00092
00093
00094 PostMergeUpdater updater;
00095 updater(root);
00096 }
00097
00098
00099 void StJetSpliterMerger::split(StEtaPhiCell& root, StEtaPhiCell& neighbor, CellVec& commonCells)
00100 {
00101 CellList& rootList = root.cellList();
00102 CellList& neighborList = neighbor.cellList();
00103
00104 for (CellVec::iterator it=commonCells.begin(); it!=commonCells.end(); ++it) {
00105
00106 double distanceToRoot = root.distance(**it);
00107 double distanceToNeighbor = neighbor.distance(**it);
00108 if (distanceToRoot<distanceToNeighbor) {
00109 neighborList.remove(*it);
00110 } else {
00111 rootList.remove(*it);
00112 }
00113 }
00114
00115 PostMergeUpdater updater;
00116 updater(root);
00117 updater(neighbor);
00118
00119 }
00120
00121
00122 void PreJetLazyUpdater ::operator()(StEtaPhiCell& cell)
00123 {
00124 sumEt += cell.eT();
00125 }
00126
00127 void PreJetLazyUpdater ::operator()(StEtaPhiCell* cell)
00128 {
00129 (*this)(*cell);
00130 }
00131
00132 void PostMergeUpdater::operator()(StEtaPhiCell& cell)
00133 {
00134
00135 PreJetLazyUpdater updater;
00136 updater = for_each( cell.cellList().begin(), cell.cellList().end(), updater );
00137
00138
00139 cell.mEt = updater.sumEt;
00140 }