00001
00002 #include "StConeJetFinder.h"
00003
00004 #include "StJetSpliterMerger.h"
00005
00006 #include <iostream>
00007
00008 using namespace std;
00009 using namespace StSpinJet;
00010
00011 StConeJetFinder::StConeJetFinder(const StConePars& pars)
00012 : StConeJetFinderBase(pars)
00013 , mMerger(new StJetSpliterMerger())
00014 {
00015 mMerger->setSplitFraction(mPars.splitFraction());
00016 }
00017
00018 StConeJetFinder::~StConeJetFinder()
00019 {
00020 delete mMerger;
00021 }
00022
00023 StJetEtCellFactory* StConeJetFinder::makeCellFactory()
00024 {
00025 return new StJetEtCellFactory;
00026 }
00027
00028 void StConeJetFinder::findJets(JetList& protoJetList, const FourVecList& particleList)
00029 {
00030 deleteToDelete();
00031
00032 CellList orderedCellList = generateEtOrderedCellList(particleList);
00033
00034 CellList toSearchCellList = generateToSearchListFrom(orderedCellList);
00035
00036 CellList protoJetCellList = findProtoJetsAroundCells(toSearchCellList);
00037
00038 if (mPars.addMidpoints()) {
00039 CellList midpointList = generateMidpointList(protoJetCellList);
00040
00041 CellList midpointProtoJetCellList = findProtoJetsAroundMidpoints(midpointList);
00042
00043 protoJetCellList.insert(protoJetCellList.end(), midpointProtoJetCellList.begin(), midpointProtoJetCellList.end());
00044 }
00045
00046 if (mPars.doSplitMerge()) {
00047 mMerger->splitMerge(protoJetCellList);
00048 }
00049
00050 storeTheResults(protoJetList, protoJetCellList);
00051
00052 }
00053
00054 StEtaPhiCell::CellList StConeJetFinder::generateEtOrderedCellList(const FourVecList& particleList)
00055 {
00056 JetList protoJetList;
00057
00058 for(FourVecList::const_iterator particle = particleList.begin(); particle != particleList.end(); ++particle) {
00059 protoJetList.push_back(StProtoJet(*particle));
00060 }
00061
00062 _cellGrid.fillGridWith(protoJetList);
00063 return _cellGrid.EtSortedCellList();
00064 }
00065
00066 StEtaPhiCell::CellList StConeJetFinder::findProtoJetsAroundCells(CellList& toSearchList)
00067 {
00068 CellList protoJetCellList;
00069
00070 for (CellList::iterator cell = toSearchList.begin(); cell != toSearchList.end(); ++cell) {
00071
00072 if (shouldNotSearchForJetAroundThis((*cell))) continue;
00073
00074 if(StEtaPhiCell* jetCell = findJetAroundThis(*cell)) {
00075 protoJetCellList.push_back(jetCell);
00076 }
00077 }
00078
00079 return protoJetCellList;
00080 }
00081
00082
00083 StEtaPhiCell* StConeJetFinder::findJetAroundThis(StEtaPhiCell* cell)
00084 {
00085 initializeWorkCell(cell);
00086
00087 if (mPars.performMinimization()) {
00088 return findJetWithStableCone();
00089 } else {
00090 formCone();
00091 return createJetCellFor(*mWorkCell);
00092 }
00093
00094 }
00095
00096 StEtaPhiCell* StConeJetFinder::createJetCellFor(StEtaPhiCell& cell)
00097 {
00098 cell.setEt(0);
00099 for(CellList::iterator etCell = cell.cellList().begin(); etCell != cell.cellList().end(); ++etCell) {
00100 (*etCell)->update();
00101 cell.setEt(cell.Et() + (*etCell)->eT());
00102 }
00103 StEtaPhiCell* ret = cell.clone();
00104 _toDelete.push_back(ret);
00105 return ret;
00106 }
00107
00108 void StConeJetFinder::deleteToDelete()
00109 {
00110 for(vector<StEtaPhiCell*>::iterator it = _toDelete.begin(); it != _toDelete.end(); ++it)
00111 delete *it;
00112
00113 _toDelete.clear();
00114 }
00115
00116
00117 bool StConeJetFinder::shouldNotSearchForJetAroundThis(const StEtaPhiCell* cell) const
00118 {
00119 if (cell->empty()) return true;
00120
00121 return false;
00122 }
00123
00124 StEtaPhiCell::CellList StConeJetFinder::generateMidpointList(const CellList& protoJetCellList)
00125 {
00126 CellList midpointList;
00127
00128 for (CellList::const_iterator pj1 = protoJetCellList.begin(); pj1 != protoJetCellList.end(); ++pj1) {
00129 for (CellList::const_iterator pj2 = pj1; pj2 != protoJetCellList.end(); ++pj2) {
00130
00131 if ((*pj1)->isSamePosition(**pj2)) continue;
00132
00133 if ((*pj1)->distance(**pj2) > 2.0*mPars.coneRadius()) continue;
00134
00135 midpointList.push_back(_cellGrid.findMidpointCell(**pj1, **pj2));
00136
00137 }
00138 }
00139 return midpointList;
00140 }
00141
00142 StEtaPhiCell::CellList StConeJetFinder::findProtoJetsAroundMidpoints(CellList& midpointList)
00143 {
00144 CellList ret;
00145 for (CellList::iterator it = midpointList.begin(); it != midpointList.end(); ++it) {
00146
00147 initializeWorkCell(*it);
00148
00149 formCone();
00150 if (mPars.requiredStableMidpoints()) {
00151 const StProtoJet& centroid = mWorkCell->centroid();
00152 if (isInTheVolume(centroid.eta(), centroid.phi())) {
00153 if(areTheyInTheSameCell(mWorkCell->eta(), mWorkCell->phi(), centroid.eta(), centroid.phi())) {
00154 ret.push_back(createJetCellFor(*mWorkCell));
00155 }
00156 }
00157 } else {
00158 ret.push_back(createJetCellFor(*mWorkCell));
00159 }
00160 }
00161 return ret;
00162 }
00163
00164 bool StConeJetFinder::shouldNotAddToTheCell(const StEtaPhiCell& theCell, const StEtaPhiCell& otherCell) const
00165 {
00166 if (otherCell.empty()) return true;
00167 if (otherCell.eT() <= mPars.assocEtMin()) return true;
00168 return false;
00169 }
00170
00171 void StConeJetFinder::storeTheResults(JetList& protoJetList, const CellList& protoJetCellList)
00172 {
00173 protoJetList.clear();
00174
00175 for (CellList::const_iterator jet = protoJetCellList.begin(); jet != protoJetCellList.end(); ++jet) {
00176
00177 if ((*jet)->cellList().size() == 0) continue;
00178
00179 protoJetList.push_back( collectCell(*jet) );
00180 }
00181 }
00182
00183 StEtaPhiCell* StConeJetFinder::findJetWithStableCone()
00184 {
00185 StEtaPhiCell* ret(0);
00186
00187 static const int maxAttempt = 100;
00188
00189 int _searchCounter = 0;
00190
00191 while(1) {
00192
00193 if (++_searchCounter > maxAttempt) break;
00194
00195 formCone();
00196
00197 const StProtoJet& centroid = mWorkCell->centroid();
00198
00199 if (!isInTheVolume(centroid.eta(), centroid.phi())) break;
00200
00201 if(areTheyInTheSameCell(mWorkCell->eta(), mWorkCell->phi(), centroid.eta(), centroid.phi())) {
00202 ret = createJetCellFor(*mWorkCell);
00203 break;
00204 }
00205
00206 StEtaPhiCell* newCenterCell = _cellGrid.Cell(mWorkCell->centroid().eta(), mWorkCell->centroid().phi());
00207 if (!newCenterCell) break;
00208
00209 initializeWorkCell(newCenterCell);
00210
00211 }
00212
00213 return ret;
00214 }
00215
00216
00217 bool StConeJetFinder::isInTheVolume(double eta, double phi)
00218 {
00219 return (_cellGrid.Cell(eta, phi)) ? true : false;
00220 }
00221
00222 bool StConeJetFinder::areTheyInTheSameCell(double eta1, double phi1, double eta2, double phi2)
00223 {
00224 return(_cellGrid.Cell(eta1, phi1)->isSamePosition(*_cellGrid.Cell(eta2, phi2)));
00225 }
00226
00227
00228