StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StConeJetFinder.cxx
1 // $Id: StConeJetFinder.cxx,v 1.53 2010/07/02 21:47:56 pibero Exp $
2 #include "StConeJetFinder.h"
3 
4 #include "StJetSpliterMerger.h"
5 
6 #include <iostream>
7 
8 using namespace std;
9 using namespace StSpinJet;
10 
11 StConeJetFinder::StConeJetFinder(const StConePars& pars)
12  : StConeJetFinderBase(pars)
13  , mMerger(new StJetSpliterMerger())
14 {
15  mMerger->setSplitFraction(mPars.splitFraction());
16 }
17 
18 StConeJetFinder::~StConeJetFinder()
19 {
20  delete mMerger;
21 }
22 
23 StJetEtCellFactory* StConeJetFinder::makeCellFactory()
24 {
25  return new StJetEtCellFactory;
26 }
27 
28 void StConeJetFinder::findJets(JetList& protoJetList, const FourVecList& particleList)
29 {
30  deleteToDelete();
31 
32  CellList orderedCellList = generateEtOrderedCellList(particleList);
33 
34  CellList toSearchCellList = generateToSearchListFrom(orderedCellList);
35 
36  CellList protoJetCellList = findProtoJetsAroundCells(toSearchCellList);
37 
38  if (mPars.addMidpoints()) {
39  CellList midpointList = generateMidpointList(protoJetCellList);
40 
41  CellList midpointProtoJetCellList = findProtoJetsAroundMidpoints(midpointList);
42 
43  protoJetCellList.insert(protoJetCellList.end(), midpointProtoJetCellList.begin(), midpointProtoJetCellList.end());
44  }
45 
46  if (mPars.doSplitMerge()) {
47  mMerger->splitMerge(protoJetCellList);
48  }
49 
50  storeTheResults(protoJetList, protoJetCellList);
51 
52 }
53 
54 StEtaPhiCell::CellList StConeJetFinder::generateEtOrderedCellList(const FourVecList& particleList)
55 {
56  JetList protoJetList;
57 
58  for(FourVecList::const_iterator particle = particleList.begin(); particle != particleList.end(); ++particle) {
59  protoJetList.push_back(StProtoJet(*particle));
60  }
61 
62  _cellGrid.fillGridWith(protoJetList);
63  return _cellGrid.EtSortedCellList();
64 }
65 
66 StEtaPhiCell::CellList StConeJetFinder::findProtoJetsAroundCells(CellList& toSearchList)
67 {
68  CellList protoJetCellList;
69 
70  for (CellList::iterator cell = toSearchList.begin(); cell != toSearchList.end(); ++cell) {
71 
72  if (shouldNotSearchForJetAroundThis((*cell))) continue;
73 
74  if(StEtaPhiCell* jetCell = findJetAroundThis(*cell)) {
75  protoJetCellList.push_back(jetCell);
76  }
77  }
78 
79  return protoJetCellList;
80 }
81 
82 
83 StEtaPhiCell* StConeJetFinder::findJetAroundThis(StEtaPhiCell* cell)
84 {
85  initializeWorkCell(cell);
86 
87  if (mPars.performMinimization()) {
88  return findJetWithStableCone();
89  } else {
90  formCone();
91  return createJetCellFor(*mWorkCell);
92  }
93 
94 }
95 
96 StEtaPhiCell* StConeJetFinder::createJetCellFor(StEtaPhiCell& cell)
97 {
98  cell.setEt(0);
99  for(CellList::iterator etCell = cell.cellList().begin(); etCell != cell.cellList().end(); ++etCell) {
100  (*etCell)->update();
101  cell.setEt(cell.Et() + (*etCell)->eT());
102  }
103  StEtaPhiCell* ret = cell.clone();
104  _toDelete.push_back(ret);
105  return ret;
106 }
107 
108 void StConeJetFinder::deleteToDelete()
109 {
110  for(vector<StEtaPhiCell*>::iterator it = _toDelete.begin(); it != _toDelete.end(); ++it)
111  delete *it;
112 
113  _toDelete.clear();
114 }
115 
116 
117 bool StConeJetFinder::shouldNotSearchForJetAroundThis(const StEtaPhiCell* cell) const
118 {
119  if (cell->empty()) return true;
120 
121  return false;
122 }
123 
124 StEtaPhiCell::CellList StConeJetFinder::generateMidpointList(const CellList& protoJetCellList)
125 {
126  CellList midpointList;
127 
128  for (CellList::const_iterator pj1 = protoJetCellList.begin(); pj1 != protoJetCellList.end(); ++pj1) {
129  for (CellList::const_iterator pj2 = pj1; pj2 != protoJetCellList.end(); ++pj2) {
130 
131  if ((*pj1)->isSamePosition(**pj2)) continue;
132 
133  if ((*pj1)->distance(**pj2) > 2.0*mPars.coneRadius()) continue;
134 
135  midpointList.push_back(_cellGrid.findMidpointCell(**pj1, **pj2));
136 
137  }
138  }
139  return midpointList;
140 }
141 
142 StEtaPhiCell::CellList StConeJetFinder::findProtoJetsAroundMidpoints(CellList& midpointList)
143 {
144  CellList ret;
145  for (CellList::iterator it = midpointList.begin(); it != midpointList.end(); ++it) {
146 
147  initializeWorkCell(*it);
148 
149  formCone();
150  if (mPars.requiredStableMidpoints()) {
151  const StProtoJet& centroid = mWorkCell->centroid();
152  if (isInTheVolume(centroid.eta(), centroid.phi())) {
153  if(areTheyInTheSameCell(mWorkCell->eta(), mWorkCell->phi(), centroid.eta(), centroid.phi())) {
154  ret.push_back(createJetCellFor(*mWorkCell));
155  }
156  }
157  } else {
158  ret.push_back(createJetCellFor(*mWorkCell));
159  }
160  }
161  return ret;
162 }
163 
164 bool StConeJetFinder::shouldNotAddToTheCell(const StEtaPhiCell& theCell, const StEtaPhiCell& otherCell) const
165 {
166  if (otherCell.empty()) return true;
167  if (otherCell.eT() <= mPars.assocEtMin()) return true;
168  return false;
169 }
170 
171 void StConeJetFinder::storeTheResults(JetList& protoJetList, const CellList& protoJetCellList)
172 {
173  protoJetList.clear();
174 
175  for (CellList::const_iterator jet = protoJetCellList.begin(); jet != protoJetCellList.end(); ++jet) {
176 
177  if ((*jet)->cellList().size() == 0) continue;
178 
179  protoJetList.push_back( collectCell(*jet) );
180  }
181 }
182 
183 StEtaPhiCell* StConeJetFinder::findJetWithStableCone()
184 {
185  StEtaPhiCell* ret(0);
186 
187  static const int maxAttempt = 100;
188 
189  int _searchCounter = 0;
190 
191  while(1) {
192 
193  if (++_searchCounter > maxAttempt) break;
194 
195  formCone();
196 
197  const StProtoJet& centroid = mWorkCell->centroid();
198 
199  if (!isInTheVolume(centroid.eta(), centroid.phi())) break;
200 
201  if(areTheyInTheSameCell(mWorkCell->eta(), mWorkCell->phi(), centroid.eta(), centroid.phi())) {
202  ret = createJetCellFor(*mWorkCell);
203  break;
204  }
205 
206  StEtaPhiCell* newCenterCell = _cellGrid.Cell(mWorkCell->centroid().eta(), mWorkCell->centroid().phi());
207  if (!newCenterCell) break;
208 
209  initializeWorkCell(newCenterCell);
210 
211  }
212 
213  return ret;
214 }
215 
216 
217 bool StConeJetFinder::isInTheVolume(double eta, double phi)
218 {
219  return (_cellGrid.Cell(eta, phi)) ? true : false;
220 }
221 
222 bool StConeJetFinder::areTheyInTheSameCell(double eta1, double phi1, double eta2, double phi2)
223 {
224  return(_cellGrid.Cell(eta1, phi1)->isSamePosition(*_cellGrid.Cell(eta2, phi2)));
225 }
226 
227 
228 
void splitMerge(CellList &jets)
action
StEtaPhiCell * mWorkCell
run-time pars