1 #ifndef __FASTJET_NNH_HH__
2 #define __FASTJET_NNH_HH__
34 #include<fastjet/ClusterSequence.hh>
37 FASTJET_BEGIN_NAMESPACE
50 NNHInfo(I * info) : _info(info) {}
51 template<
class NNBJ>
void init_jet(NNBJ * briefjet,
const fastjet::PseudoJet & jet,
int index) { briefjet->init(jet, index, _info);}
62 template<
class NNBJ>
void init_jet(NNBJ * briefjet,
const fastjet::PseudoJet & jet,
int index) { briefjet->init(jet, index);}
113 template<
class BJ,
class I = _NoInfo>
class NNH :
public NNHInfo<I> {
118 NNH(
const std::vector<PseudoJet> & jets) {start(jets);}
119 NNH(
const std::vector<PseudoJet> & jets, I * info) :
NNHInfo<I>(info) {start(jets);}
121 void start(
const std::vector<PseudoJet> & jets);
125 double dij_min(
int & iA,
int & iB);
128 void remove_jet(
int iA);
132 void merge_jets(
int iA,
int iB,
const PseudoJet & jet,
int jet_index);
145 void set_NN_crosscheck(NNBJ * jet, NNBJ * begin, NNBJ * end);
149 void set_NN_nocross (NNBJ * jet, NNBJ * begin, NNBJ * end);
161 std::vector<NNBJ *> where_is;
165 class NNBJ :
public BJ {
167 void init(
const PseudoJet & jet,
int index_in) {
169 other_init(index_in);
171 void init(
const PseudoJet & jet,
int index_in, I * info) {
173 other_init(index_in);
175 void other_init(
int index_in) {
177 NN_dist = BJ::beam_distance();
180 int index()
const {
return _index;}
194 template<
class BJ,
class I>
void NNH<BJ,I>::start(
const std::vector<PseudoJet> & jets) {
196 briefjets =
new NNBJ[n];
197 where_is.resize(2*n);
199 NNBJ * jetA = briefjets;
202 for (
int i = 0; i< n; i++) {
204 this->init_jet(jetA, jets[i], i);
213 for (jetA = head + 1; jetA != tail; jetA++) {
217 set_NN_crosscheck(jetA, head, jetA);
226 double diJ_min = briefjets[0].NN_dist;
228 for (
int i = 1; i < n; i++) {
229 if (briefjets[i].NN_dist < diJ_min) {
231 diJ_min = briefjets[i].NN_dist;
236 NNBJ * jetA = & briefjets[diJ_min_jet];
239 iB = jetA->NN ? jetA->NN->index() : -1;
247 NNBJ * jetA = where_is[iA];
254 where_is[jetA->index()] = jetA;
256 for (NNBJ * jetI = head; jetI != tail; jetI++) {
258 if (jetI->NN == jetA) set_NN_nocross(jetI, head, tail);
261 if (jetI->NN == tail) {jetI->NN = jetA;}
270 NNBJ * jetA = where_is[iA];
271 NNBJ * jetB = where_is[iB];
277 if (jetA < jetB) std::swap(jetA,jetB);
281 this->init_jet(jetB, jet, index);
283 if (index >=
int(where_is.size())) where_is.resize(2*index);
284 where_is[jetB->index()] = jetB;
292 where_is[jetA->index()] = jetA;
294 for (NNBJ * jetI = head; jetI != tail; jetI++) {
296 if (jetI->NN == jetA || jetI->NN == jetB) {
297 set_NN_nocross(jetI, head, tail);
302 double dist = jetI->distance(jetB);
303 if (dist < jetI->NN_dist) {
305 jetI->NN_dist = dist;
309 if (dist < jetB->NN_dist) {
311 jetB->NN_dist = dist;
317 if (jetI->NN == tail) {jetI->NN = jetA;}
325 NNBJ * begin, NNBJ * end) {
326 double NN_dist = jet->beam_distance();
328 for (NNBJ * jetB = begin; jetB != end; jetB++) {
329 double dist = jet->distance(jetB);
330 if (dist < NN_dist) {
334 if (dist < jetB->NN_dist) {
335 jetB->NN_dist = dist;
340 jet->NN_dist = NN_dist;
347 template <
class BJ,
class I>
void NNH<BJ,I>::set_NN_nocross(
348 NNBJ * jet, NNBJ * begin, NNBJ * end) {
349 double NN_dist = jet->beam_distance();
354 for (NNBJ * jetB = begin; jetB != jet; jetB++) {
355 double dist = jet->distance(jetB);
356 if (dist < NN_dist) {
365 for (NNBJ * jetB = jet+1; jetB != end; jetB++) {
366 double dist = jet->distance (jetB);
367 if (dist < NN_dist) {
374 jet->NN_dist = NN_dist;
380 FASTJET_END_NAMESPACE
383 #endif // __FASTJET_NNH_HH__
NNH(const std::vector< PseudoJet > &jets)
constructor with an initial set of jets (which will be assigned indices 0 ...
Help solve closest pair problems with generic interparticle and beam distance.
template that will help initialise a BJ with a PseudoJet and extra information
dummy class, used as a default template argument
Class to contain pseudojets, including minimal information of use to jet-clustering routines...