Fork me on GitHub

source: svn/trunk/Utilities/Fastjet/src/ClusterSequence_N2.cc@ 309

Last change on this file since 309 was 11, checked in by severine ovyn, 16 years ago

Fastjet added; CDFCones directory has been changed

File size: 6.3 KB
RevLine 
[11]1//STARTHEADER
2// $Id: ClusterSequence_N2.cc,v 1.1 2008-11-06 14:32:14 ovyn Exp $
3//
4// Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam
5//
6//----------------------------------------------------------------------
7// This file is part of FastJet.
8//
9// FastJet is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; either version 2 of the License, or
12// (at your option) any later version.
13//
14// The algorithms that underlie FastJet have required considerable
15// development and are described in hep-ph/0512210. If you use
16// FastJet as part of work towards a scientific publication, please
17// include a citation to the FastJet paper.
18//
19// FastJet is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU General Public License for more details.
23//
24// You should have received a copy of the GNU General Public License
25// along with FastJet; if not, write to the Free Software
26// Foundation, Inc.:
27// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28//----------------------------------------------------------------------
29//ENDHEADER
30
31
32// The plain N^2 part of the ClusterSequence class -- separated out
33// from the rest of the class implementation so as to speed up
34// compilation of this particular part while it is under test.
35
36#include "../include/fastjet/PseudoJet.hh"
37#include "../include/fastjet/ClusterSequence.hh"
38#include<iostream>
39
40FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
41
42
43using namespace std;
44
45//----------------------------------------------------------------------
46/// Order(N^2) clustering
47///
48void ClusterSequence::_simple_N2_cluster() {
49 int n = _jets.size();
50 BriefJet * briefjets = new BriefJet[n];
51 BriefJet * jetA = briefjets, * jetB;
52
53 // initialise the basic jet info
54 for (int i = 0; i< n; i++) {
55 _bj_set_jetinfo(jetA, i);
56 jetA++; // move on to next entry of briefjets
57 }
58 BriefJet * tail = jetA; // a semaphore for the end of briefjets
59 BriefJet * head = briefjets; // a nicer way of naming start
60
61 // now initialise the NN distances: jetA will run from 1..n-1; and
62 // jetB from 0..jetA-1
63 for (jetA = head + 1; jetA != tail; jetA++) {
64 // set NN info for jetA based on jets running from head..jetA-1,
65 // checking in the process whether jetA itself is an undiscovered
66 // NN of one of those jets.
67 _bj_set_NN_crosscheck(jetA, head, jetA);
68 }
69
70
71 // now create the diJ (where J is i's NN) table -- remember that
72 // we differ from standard normalisation here by a factor of R2
73 double * diJ = new double[n];
74 jetA = head;
75 for (int i = 0; i < n; i++) {
76 diJ[i] = _bj_diJ(jetA);
77 jetA++; // have jetA follow i
78 }
79
80 // now run the recombination loop
81 int history_location = n-1;
82 while (tail != head) {
83
84 // find the minimum of the diJ on this round
85 double diJ_min = diJ[0];
86 int diJ_min_jet = 0;
87 for (int i = 1; i < n; i++) {
88 if (diJ[i] < diJ_min) {diJ_min_jet = i; diJ_min = diJ[i];}
89 }
90
91 // do the recombination between A and B
92 history_location++;
93 jetA = & briefjets[diJ_min_jet];
94 jetB = jetA->NN;
95 // put the normalisation back in
96 diJ_min *= _invR2;
97 if (jetB != NULL) {
98 // jet-jet recombination
99 // If necessary relabel A & B to ensure jetB < jetA, that way if
100 // the larger of them == newtail then that ends up being jetA and
101 // the new jet that is added as jetB is inserted in a position that
102 // has a future!
103 if (jetA < jetB) {swap(jetA,jetB);}
104
105 int nn; // new jet index
106 _do_ij_recombination_step(jetA->_jets_index, jetB->_jets_index, diJ_min, nn);
107
108 //OBS // get the two history indices
109 //OBS int hist_a = _jets[jetA->_jets_index].cluster_hist_index();
110 //OBS int hist_b = _jets[jetB->_jets_index].cluster_hist_index();
111 //OBS // create the recombined jet
112 //OBS _jets.push_back(_jets[jetA->_jets_index] + _jets[jetB->_jets_index]);
113 //OBS int nn = _jets.size() - 1;
114 //OBS _jets[nn].set_cluster_hist_index(history_location);
115 //OBS // update history
116 //OBS _add_step_to_history(history_location,
117 //OBS min(hist_a,hist_b),max(hist_a,hist_b),
118 //OBS nn, diJ_min);
119 // what was jetB will now become the new jet
120 _bj_set_jetinfo(jetB, nn);
121 } else {
122 // jet-beam recombination
123 _do_iB_recombination_step(jetA->_jets_index, diJ_min);
124 //OBS // get the hist_index
125 //OBS int hist_a = _jets[jetA->_jets_index].cluster_hist_index();
126 //OBS _add_step_to_history(history_location,hist_a,BeamJet,Invalid,diJ_min);
127 }
128
129 // now update our nearest neighbour info and diJ table
130 // first reduce size of table
131 tail--; n--;
132 // Copy last jet contents and diJ info into position of jetA
133 *jetA = *tail;
134 diJ[jetA - head] = diJ[tail-head];
135
136 // Initialise jetB's NN distance as well as updating it for
137 // other particles.
138 // NB: by having different loops for jetB == or != NULL we could
139 // perhaps save a few percent (usually avoid one if inside loop),
140 // but will not do it for now because on laptop fluctuations are
141 // too large to reliably measure a few percent difference...
142 for (BriefJet * jetI = head; jetI != tail; jetI++) {
143 // see if jetI had jetA or jetB as a NN -- if so recalculate the NN
144 if (jetI->NN == jetA || jetI->NN == jetB) {
145 _bj_set_NN_nocross(jetI, head, tail);
146 diJ[jetI-head] = _bj_diJ(jetI); // update diJ
147 }
148 // check whether new jetB is closer than jetI's current NN and
149 // if need be update things
150 if (jetB != NULL) {
151 double dist = _bj_dist(jetI,jetB);
152 if (dist < jetI->NN_dist) {
153 if (jetI != jetB) {
154 jetI->NN_dist = dist;
155 jetI->NN = jetB;
156 diJ[jetI-head] = _bj_diJ(jetI); // update diJ...
157 }
158 }
159 if (dist < jetB->NN_dist) {
160 if (jetI != jetB) {
161 jetB->NN_dist = dist;
162 jetB->NN = jetI;}
163 }
164 }
165 // if jetI's NN is the new tail then relabel it so that it becomes jetA
166 if (jetI->NN == tail) {jetI->NN = jetA;}
167 }
168
169
170 if (jetB != NULL) {diJ[jetB-head] = _bj_diJ(jetB);}
171
172
173 }
174
175
176 // final cleaning up;
177 delete[] diJ;
178 delete[] briefjets;
179}
180
181FASTJET_END_NAMESPACE
182
Note: See TracBrowser for help on using the repository browser.