31 #include "fastjet/ClusterSequence.hh" 32 #include "fastjet/internal/ClosestPair2D.hh" 38 FASTJET_BEGIN_NAMESPACE
48 MirrorInfo(
int a,
int b) : orig(a), mirror(b) {}
49 MirrorInfo() : orig(0), mirror(0) {}
55 bool make_mirror(Coord2D & point,
double Dlim) {
56 if (point.y < Dlim) {point.y += twopi;
return true;}
57 if (twopi-point.y < Dlim) {point.y -= twopi;
return true;}
63 using namespace Private;
69 void ClusterSequence::_CP2DChan_limited_cluster (
double Dlim) {
71 unsigned int n = _initial_n;
73 vector<MirrorInfo> coordIDs(2*n);
74 vector<int> jetIDs(2*n);
75 vector<Coord2D> coords(2*n);
83 double Dlim4mirror = min(Dlim,pi);
86 double minrap = numeric_limits<double>::max();
87 double maxrap = -minrap;
90 for (
unsigned jet_i = 0; jet_i < _jets.size(); jet_i++) {
94 if (_history[_jets[jet_i].cluster_hist_index()].child != Invalid ||
95 (_jets[jet_i].E() == abs(_jets[jet_i].pz()) &&
96 _jets[jet_i].perp2() == 0.0)
101 coordIDs[jet_i].orig = ++coord_index;
102 coords[coord_index] = Coord2D(_jets[jet_i].rap(), _jets[jet_i].phi_02pi());
103 jetIDs[coord_index] = jet_i;
104 minrap = min(coords[coord_index].x,minrap);
105 maxrap = max(coords[coord_index].x,maxrap);
107 Coord2D mirror_point(coords[coord_index]);
108 if (make_mirror(mirror_point, Dlim4mirror)) {
109 coordIDs[jet_i].mirror = ++coord_index;
110 coords[coord_index] = mirror_point;
111 jetIDs[coord_index] = jet_i;
113 coordIDs[jet_i].mirror = Invalid;
118 coords.resize(coord_index+1);
121 Coord2D left_edge(minrap-1.0, -3.15);
122 Coord2D right_edge(maxrap+1.0, 9.45);
127 ClosestPair2D cp(coords, left_edge, right_edge);
134 vector<Coord2D> new_points(2);
135 vector<unsigned int> cIDs_to_remove(4);
136 vector<unsigned int> new_cIDs(2);
140 unsigned int cID1, cID2;
142 cp.closest_pair(cID1,cID2,distance2);
145 if (distance2 > Dlim*Dlim) {
break;}
151 int jet_i = jetIDs[cID1];
152 int jet_j = jetIDs[cID2];
153 assert (jet_i != jet_j);
155 _do_ij_recombination_step(jet_i, jet_j, distance2, newjet_k);
159 if (--n_active == 1) {
break;}
162 cIDs_to_remove.resize(0);
163 cIDs_to_remove.push_back(coordIDs[jet_i].orig);
164 cIDs_to_remove.push_back(coordIDs[jet_j].orig);
165 if (coordIDs[jet_i].mirror != Invalid)
166 cIDs_to_remove.push_back(coordIDs[jet_i].mirror);
167 if (coordIDs[jet_j].mirror != Invalid)
168 cIDs_to_remove.push_back(coordIDs[jet_j].mirror);
170 Coord2D new_point(_jets[newjet_k].rap(),_jets[newjet_k].phi_02pi());
171 new_points.resize(0);
172 new_points.push_back(new_point);
173 if (make_mirror(new_point, Dlim4mirror)) new_points.push_back(new_point);
176 cp.replace_many(cIDs_to_remove, new_points, new_cIDs);
179 coordIDs[newjet_k].orig = new_cIDs[0];
180 jetIDs[new_cIDs[0]] = newjet_k;
181 if (new_cIDs.size() == 2) {
182 coordIDs[newjet_k].mirror = new_cIDs[1];
183 jetIDs[new_cIDs[1]] = newjet_k;
184 }
else {coordIDs[newjet_k].mirror = Invalid;}
202 void ClusterSequence::_CP2DChan_cluster_2pi2R () {
204 if (_jet_algorithm != cambridge_algorithm)
throw Error(
"CP2DChan clustering method called for a jet-finder that is not the cambridge algorithm");
208 _CP2DChan_limited_cluster(_Rparam);
211 _do_Cambridge_inclusive_jets();
218 void ClusterSequence::_CP2DChan_cluster_2piMultD () {
221 if (_Rparam >= 0.39) {
222 _CP2DChan_limited_cluster(min(_Rparam/2,0.3));
226 _CP2DChan_cluster_2pi2R ();
232 void ClusterSequence::_CP2DChan_cluster () {
234 if (_jet_algorithm != cambridge_algorithm)
throw Error(
"_CP2DChan_cluster called for a jet-finder that is not the cambridge algorithm");
236 unsigned int n = _jets.size();
238 vector<MirrorInfo> coordIDs(2*n);
239 vector<int> jetIDs(2*n);
240 vector<Coord2D> coords(2*n);
243 double minrap = numeric_limits<double>::max();
244 double maxrap = -minrap;
246 for (
unsigned i = 0; i < n; i++) {
248 if (_jets[i].E() == abs(_jets[i].pz()) && _jets[i].perp2() == 0.0) {
249 coordIDs[i] = MirrorInfo(BeamJet,BeamJet);
251 coordIDs[i].orig = coord_index;
252 coordIDs[i].mirror = coord_index+1;
253 coords[coord_index] = Coord2D(_jets[i].rap(), _jets[i].phi_02pi());
254 coords[coord_index+1] = Coord2D(_jets[i].rap(), _jets[i].phi_02pi()+twopi);
255 jetIDs[coord_index] = i;
256 jetIDs[coord_index+1] = i;
257 minrap = min(coords[coord_index].x,minrap);
258 maxrap = max(coords[coord_index].x,maxrap);
263 for (
unsigned i = n; i < 2*n; i++) {coordIDs[i].orig = Invalid;}
266 coords.resize(coord_index);
269 Coord2D left_edge(minrap-1.0, 0.0);
270 Coord2D right_edge(maxrap+1.0, 2*twopi);
273 ClosestPair2D cp(coords, left_edge, right_edge);
276 vector<Coord2D> new_points(2);
277 vector<unsigned int> cIDs_to_remove(4);
278 vector<unsigned int> new_cIDs(2);
281 unsigned int cID1, cID2;
283 cp.closest_pair(cID1,cID2,distance2);
287 if (distance2 > 1.0) {
break;}
290 int jet_i = jetIDs[cID1];
291 int jet_j = jetIDs[cID2];
292 assert (jet_i != jet_j);
294 _do_ij_recombination_step(jet_i, jet_j, distance2, newjet_k);
297 cIDs_to_remove[0] = coordIDs[jet_i].orig;
298 cIDs_to_remove[1] = coordIDs[jet_i].mirror;
299 cIDs_to_remove[2] = coordIDs[jet_j].orig;
300 cIDs_to_remove[3] = coordIDs[jet_j].mirror;
301 new_points[0] = Coord2D(_jets[newjet_k].rap(),_jets[newjet_k].phi_02pi());
302 new_points[1] = Coord2D(_jets[newjet_k].rap(),_jets[newjet_k].phi_02pi()+twopi);
306 new_cIDs[0] = cp.replace(cIDs_to_remove[0], cIDs_to_remove[2], new_points[0]);
307 new_cIDs[1] = cp.replace(cIDs_to_remove[1], cIDs_to_remove[3], new_points[1]);
309 coordIDs[jet_i].orig = Invalid;
310 coordIDs[jet_j].orig = Invalid;
312 coordIDs[newjet_k] = MirrorInfo(new_cIDs[0], new_cIDs[1]);
313 jetIDs[new_cIDs[0]] = newjet_k;
314 jetIDs[new_cIDs[1]] = newjet_k;
333 _do_Cambridge_inclusive_jets();
346 void ClusterSequence::_do_Cambridge_inclusive_jets () {
347 unsigned int n = _history.size();
348 for (
unsigned int hist_i = 0; hist_i < n; hist_i++) {
349 if (_history[hist_i].child == Invalid) {
350 _do_iB_recombination_step(_history[hist_i].jetp_index, 1.0);
355 FASTJET_END_NAMESPACE