Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/fastjet/ClusterSequence.cc

    r273e668 rd69dfe4  
    1 //FJSTARTHEADER
    2 // $Id: ClusterSequence.cc 3685 2014-09-11 20:15:00Z salam $
     1//STARTHEADER
     2// $Id$
    33//
    4 // Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
     4// Copyright (c) 2005-2013, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
    55//
    66//----------------------------------------------------------------------
     
    1313//
    1414//  The algorithms that underlie FastJet have required considerable
    15 //  development. They are described in the original FastJet paper,
    16 //  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
     15//  development and are described in hep-ph/0512210. If you use
    1716//  FastJet as part of work towards a scientific publication, please
    18 //  quote the version you use and include a citation to the manual and
    19 //  optionally also to hep-ph/0512210.
     17//  include a citation to the FastJet paper.
    2018//
    2119//  FastJet is distributed in the hope that it will be useful,
     
    2725//  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
    2826//----------------------------------------------------------------------
    29 //FJENDHEADER
     27//ENDHEADER
    3028
    3129#include "fastjet/Error.hh"
     
    3432#include "fastjet/ClusterSequenceStructure.hh"
    3533#include "fastjet/version.hh" // stores the current version number
    36 #include "fastjet/internal/LazyTiling9Alt.hh"
    37 #include "fastjet/internal/LazyTiling9.hh"
    38 #include "fastjet/internal/LazyTiling25.hh"
    39 #ifndef __FJCORE__
    40 #include "fastjet/internal/LazyTiling9SeparateGhosts.hh"
    41 #endif  // __FJCORE__
    4234#include<iostream>
    4335#include<sstream>
     
    195187//DEP //----------------------------------------------------------------------
    196188//DEP void ClusterSequence::_initialise_and_run (
    197 //DEP                             const double R,
     189//DEP                             const double & R,
    198190//DEP                             const Strategy & strategy,
    199191//DEP                             const bool & writeout_combinations) {
     
    281273  //             ./fastjet_timing_plugins -kt -nhardest 30 -repeat 50000 -strategy -3 -R 0.5 -nev 1  <  ../../data/Pythia-PtMin1000-LHC-1000ev.dat
    282274  if (_strategy == Best) {
    283     _strategy = _best_strategy();
    284 #ifdef DROP_CGAL
    285     // fall back strategy for large N when CGAL is missing
    286     if (_strategy == NlnN) _strategy = N2MHTLazy25;
    287 #endif  // DROP_CGAL
    288   } else if (_strategy == BestFJ30) {
    289275    int N = _jets.size();
    290276    //if (N <= 55*max(0.5,min(1.0,_Rparam))) {// old empirical scaling with R
     
    338324  // run the code containing the selected strategy
    339325  //
    340   // We order the strategies starting from the ones used by the Best
     326  // We order the strategies stqrting from the ones used by the Best
    341327  // strategy in the order of increasing N, then the remaining ones
    342328  // again in the order of increasing N.
     
    348334  } else if (_strategy == N2MinHeapTiled) {
    349335    this->_minheap_faster_tiled_N2_cluster();
    350   } else if (_strategy == N2MHTLazy9Alt) {
    351     // attempt to use an external tiling routine -- it manipulates
    352     // the CS history via the plugin mechanism
    353     _plugin_activated = true;
    354     LazyTiling9Alt tiling(*this);
    355     tiling.run();
    356     _plugin_activated = false;
    357 
    358   } else if (_strategy == N2MHTLazy25) {
    359     // attempt to use an external tiling routine -- it manipulates
    360     // the CS history via the plugin mechanism
    361     _plugin_activated = true;
    362     LazyTiling25 tiling(*this);
    363     tiling.run();
    364     _plugin_activated = false;
    365 
    366   } else if (_strategy == N2MHTLazy9) {
    367     // attempt to use an external tiling routine -- it manipulates
    368     // the CS history via the plugin mechanism
    369     _plugin_activated = true;
    370     LazyTiling9 tiling(*this);
    371     tiling.run();
    372     _plugin_activated = false;
    373 
    374 #ifndef __FJCORE__
    375   } else if (_strategy == N2MHTLazy9AntiKtSeparateGhosts) {
    376     // attempt to use an external tiling routine -- it manipulates
    377     // the CS history via the plugin mechanism
    378     _plugin_activated = true;
    379     LazyTiling9SeparateGhosts tiling(*this);
    380     tiling.run();
    381     _plugin_activated = false;
    382 #else
    383     throw Error("N2MHTLazy9AntiKtSeparateGhosts strategy not supported with FJCORE");
    384 #endif  // __FJCORE__
    385 
    386336  } else if (_strategy == NlnN) {
    387337    this->_delaunay_cluster();
     
    409359// these needs to be defined outside the class definition.
    410360bool ClusterSequence::_first_time = true;
    411 LimitedWarning ClusterSequence::_exclusive_warnings;
     361int ClusterSequence::_n_exclusive_warnings = 0;
    412362
    413363
     
    523473
    524474//----------------------------------------------------------------------
     475// Return the component corresponding to the specified index.
     476// taken from CLHEP
    525477string ClusterSequence::strategy_string (Strategy strategy_in)  const {
    526478  string strategy;
     
    540492  case N2PoorTiled:
    541493    strategy = "N2PoorTiled"; break;
    542   case N2MHTLazy9:
    543     strategy = "N2MHTLazy9"; break;
    544   case N2MHTLazy9Alt:
    545     strategy = "N2MHTLazy9Alt"; break;
    546   case N2MHTLazy25:
    547     strategy = "N2MHTLazy25"; break;
    548   case N2MHTLazy9AntiKtSeparateGhosts:
    549     strategy = "N2MHTLazy9AntiKtSeparateGhosts"; break;
    550494  case N3Dumb:
    551495    strategy = "N3Dumb"; break;
     
    584528    } else {return 1.0;}
    585529  } else {throw Error("Unrecognised jet algorithm");}
    586 }
    587 
    588 //----------------------------------------------------------------------
    589 // returns a suggestion for the best strategy to use on event
    590 // multiplicity, algorithm, R, etc.
    591 //
    592 // Some of the work to establish the best strategy is collected in
    593 // issue-tracker/2014-07-auto-strategy-selection;
    594 // transition_fit_v2.fit indicates the results of the fits that we're
    595 // using here. (Automatically generated by transition_fit_v2.gp).
    596 //
    597 // The transition to NlnN is always present, and it is the the
    598 // caller's responsibility to drop back down to N2MHTLazy25 if NlnN
    599 // isn't available.
    600 //
    601 // This routine should be called only if the jet alg is one of kt,
    602 // antikt, cam or genkt.
    603 Strategy ClusterSequence::_best_strategy() const {
    604   int N = _jets.size();
    605   // define bounded R, always above 0.1, because we don't trust any
    606   // of our parametrizations below R = 0.1
    607   double bounded_R = max(_Rparam, 0.1);
    608 
    609   // the very first test thing is a quick hard-coded test to decide
    610   // if we immediately opt for N2Plain
    611   if (N <= 30 || N <= 39.0/(bounded_R + 0.6)) {
    612     return N2Plain;
    613   }
    614  
    615   // Define objects that describe our various boundaries. A prefix N_
    616   // indicates that boundary is for N, while L_ means it's for log(N).
    617   //
    618   // Hopefully having them static will ensure minimal overhead
    619   // in creating them; collecting them in one place should
    620   // help with updates?
    621   //
    622   const static _Parabola N_Tiled_to_MHT_lowR             (-45.4947,54.3528,44.6283);
    623   const static _Parabola L_MHT_to_MHTLazy9_lowR          (0.677807,-1.05006,10.6994);
    624   const static _Parabola L_MHTLazy9_to_MHTLazy25_akt_lowR(0.169967,-0.512589,12.1572);
    625   const static _Parabola L_MHTLazy9_to_MHTLazy25_kt_lowR (0.16237,-0.484612,12.3373);
    626   const static _Parabola L_MHTLazy9_to_MHTLazy25_cam_lowR = L_MHTLazy9_to_MHTLazy25_kt_lowR;
    627   const static _Parabola L_MHTLazy25_to_NlnN_akt_lowR    (0.0472051,-0.22043,15.9196);
    628   const static _Parabola L_MHTLazy25_to_NlnN_kt_lowR     (0.118609,-0.326811,14.8287);
    629   const static _Parabola L_MHTLazy25_to_NlnN_cam_lowR    (0.10119,-0.295748,14.3924);
    630 
    631   const static _Line     L_Tiled_to_MHTLazy9_medR         (-1.31304,7.29621);
    632   const static _Parabola L_MHTLazy9_to_MHTLazy25_akt_medR = L_MHTLazy9_to_MHTLazy25_akt_lowR;
    633   const static _Parabola L_MHTLazy9_to_MHTLazy25_kt_medR  = L_MHTLazy9_to_MHTLazy25_kt_lowR;
    634   const static _Parabola L_MHTLazy9_to_MHTLazy25_cam_medR = L_MHTLazy9_to_MHTLazy25_cam_lowR;
    635   const static _Parabola L_MHTLazy25_to_NlnN_akt_medR     = L_MHTLazy25_to_NlnN_akt_lowR;
    636   const static _Parabola L_MHTLazy25_to_NlnN_kt_medR      = L_MHTLazy25_to_NlnN_kt_lowR;
    637   const static _Parabola L_MHTLazy25_to_NlnN_cam_medR     = L_MHTLazy25_to_NlnN_cam_lowR;
    638 
    639   const static double    N_Plain_to_MHTLazy9_largeR         = 75;
    640   const static double    N_MHTLazy9_to_MHTLazy25_akt_largeR = 700;
    641   const static double    N_MHTLazy9_to_MHTLazy25_kt_largeR  = 1000;
    642   const static double    N_MHTLazy9_to_MHTLazy25_cam_largeR = 1000;
    643   const static double    N_MHTLazy25_to_NlnN_akt_largeR     = 100000;
    644   const static double    N_MHTLazy25_to_NlnN_kt_largeR      = 40000;
    645   const static double    N_MHTLazy25_to_NlnN_cam_largeR     = 15000;
    646 
    647   // We have timing studies only for kt, cam and antikt; for other
    648   // algorithms we set the local jet_algorithm variable to the one of
    649   // kt,cam,antikt that we think will be closest in behaviour to the
    650   // other alg.
    651   JetAlgorithm jet_algorithm;
    652   if (_jet_algorithm == genkt_algorithm) {
    653     // for genkt, then we set the local jet_algorithm variable (used
    654     // only for strategy choice) to be either kt or antikt, depending on
    655     // the p value.
    656     double p   = jet_def().extra_param();
    657     if (p < 0.0) jet_algorithm = antikt_algorithm;
    658     else         jet_algorithm =     kt_algorithm;
    659   } else if (_jet_algorithm == cambridge_for_passive_algorithm) {
    660     // we assume (but haven't tested) that using the kt-alg timing
    661     // transitions should be adequate for cambridge_for_passive_algorithm
    662     jet_algorithm = kt_algorithm;
    663   } else {
    664     jet_algorithm = _jet_algorithm;
    665   }
    666 
    667   if (bounded_R < 0.65) {
    668     // low R case
    669     if          (N    < N_Tiled_to_MHT_lowR(bounded_R))              return N2Tiled;
    670     double logN = log(double(N));
    671     if          (logN < L_MHT_to_MHTLazy9_lowR(bounded_R))           return N2MinHeapTiled;
    672     else {
    673       if (jet_algorithm == antikt_algorithm){
    674         if      (logN < L_MHTLazy9_to_MHTLazy25_akt_lowR(bounded_R)) return N2MHTLazy9;
    675         else if (logN < L_MHTLazy25_to_NlnN_akt_lowR(bounded_R))     return N2MHTLazy25;
    676         else                                                         return NlnN;
    677       } else if (jet_algorithm == kt_algorithm){
    678         if      (logN < L_MHTLazy9_to_MHTLazy25_kt_lowR(bounded_R))  return N2MHTLazy9;
    679         else if (logN < L_MHTLazy25_to_NlnN_kt_lowR(bounded_R))      return N2MHTLazy25;
    680         else                                                         return NlnN;
    681       } else if (jet_algorithm == cambridge_algorithm)  {
    682         if      (logN < L_MHTLazy9_to_MHTLazy25_cam_lowR(bounded_R)) return N2MHTLazy9;
    683         else if (logN < L_MHTLazy25_to_NlnN_cam_lowR(bounded_R))     return N2MHTLazy25;
    684         else                                                         return NlnNCam;
    685       }
    686     }
    687   } else if (bounded_R < 0.5*pi) {
    688     // medium R case
    689     double logN = log(double(N));
    690     if      (logN < L_Tiled_to_MHTLazy9_medR(bounded_R))             return N2Tiled;
    691     else {
    692       if (jet_algorithm == antikt_algorithm){
    693         if      (logN < L_MHTLazy9_to_MHTLazy25_akt_medR(bounded_R)) return N2MHTLazy9;
    694         else if (logN < L_MHTLazy25_to_NlnN_akt_medR(bounded_R))     return N2MHTLazy25;
    695         else                                                         return NlnN;
    696       } else if (jet_algorithm == kt_algorithm){
    697         if      (logN < L_MHTLazy9_to_MHTLazy25_kt_medR(bounded_R))  return N2MHTLazy9;
    698         else if (logN < L_MHTLazy25_to_NlnN_kt_medR(bounded_R))      return N2MHTLazy25;
    699         else                                                         return NlnN;
    700       } else if (jet_algorithm == cambridge_algorithm)  {
    701         if      (logN < L_MHTLazy9_to_MHTLazy25_cam_medR(bounded_R)) return N2MHTLazy9;
    702         else if (logN < L_MHTLazy25_to_NlnN_cam_medR(bounded_R))     return N2MHTLazy25;
    703         else                                                         return NlnNCam;
    704       }
    705     }
    706   } else {
    707     // large R case (R > pi/2)
    708     if      (N    < N_Plain_to_MHTLazy9_largeR)                      return N2Plain;
    709     else {
    710       if (jet_algorithm == antikt_algorithm){
    711         if      (N < N_MHTLazy9_to_MHTLazy25_akt_largeR)             return N2MHTLazy9;
    712         else if (N < N_MHTLazy25_to_NlnN_akt_largeR)                 return N2MHTLazy25;
    713         else                                                         return NlnN;
    714       } else if (jet_algorithm == kt_algorithm){
    715         if      (N < N_MHTLazy9_to_MHTLazy25_kt_largeR)              return N2MHTLazy9;
    716         else if (N < N_MHTLazy25_to_NlnN_kt_largeR)                  return N2MHTLazy25;
    717         else                                                         return NlnN;
    718       } else if (jet_algorithm == cambridge_algorithm)  {
    719         if      (N < N_MHTLazy9_to_MHTLazy25_cam_largeR)             return N2MHTLazy9;
    720         else if (N < N_MHTLazy25_to_NlnN_cam_largeR)                 return N2MHTLazy25;
    721         else                                                         return NlnNCam;
    722       }
    723     }
    724   }
    725  
    726   bool code_should_never_reach_here = false;
    727   assert(code_should_never_reach_here);
    728   return N2MHTLazy9;
    729 
    730530}
    731531
     
    862662//----------------------------------------------------------------------
    863663// return all inclusive jets with pt > ptmin
    864 vector<PseudoJet> ClusterSequence::inclusive_jets (const double ptmin) const{
     664vector<PseudoJet> ClusterSequence::inclusive_jets (const double & ptmin) const{
    865665  double dcut = ptmin*ptmin;
    866666  int i = _history.size() - 1; // last jet
     
    914714// return the number of exclusive jets that would have been obtained
    915715// running the algorithm in exclusive mode with the given dcut
    916 int ClusterSequence::n_exclusive_jets (const double dcut) const {
     716int ClusterSequence::n_exclusive_jets (const double & dcut) const {
    917717
    918718  // first locate the point where clustering would have stopped (i.e. the
     
    933733// return all exclusive jets that would have been obtained running
    934734// the algorithm in exclusive mode with the given dcut
    935 vector<PseudoJet> ClusterSequence::exclusive_jets (const double dcut) const {
     735vector<PseudoJet> ClusterSequence::exclusive_jets (const double & dcut) const {
    936736  int njets = n_exclusive_jets(dcut);
    937737  return exclusive_jets(njets);
     
    942742// return the jets obtained by clustering the event to n jets.
    943743// Throw an error if there are fewer than n particles.
    944 vector<PseudoJet> ClusterSequence::exclusive_jets (const int njets) const {
     744vector<PseudoJet> ClusterSequence::exclusive_jets (const int & njets) const {
    945745
    946746  // make sure the user does not ask for more than jets than there
     
    959759// return the jets obtained by clustering the event to n jets.
    960760// If there are fewer than n particles, simply return all particles
    961 vector<PseudoJet> ClusterSequence::exclusive_jets_up_to (const int njets) const {
     761vector<PseudoJet> ClusterSequence::exclusive_jets_up_to (const int & njets) const {
    962762
    963763  // provide a warning when extracting exclusive jets for algorithms
    964764  // that does not support it explicitly.
    965   // Native algorithm that support it are: kt, ee_kt, Cambridge/Aachen,
     765  // Native algorithm that support it are: kt, ee_kt, cambridge,
    966766  //   genkt and ee_genkt (both with p>=0)
    967767  // For plugins, we check Plugin::exclusive_sequence_meaningful()
     
    973773       (_jet_def.extra_param() <0)) &&
    974774      ((_jet_def.jet_algorithm() != plugin_algorithm) ||
    975        (!_jet_def.plugin()->exclusive_sequence_meaningful()))) {
    976     _exclusive_warnings.warn("dcut and exclusive jets for jet-finders other than kt, C/A or genkt with p>=0 should be interpreted with care.");
     775       (!_jet_def.plugin()->exclusive_sequence_meaningful())) &&
     776      (_n_exclusive_warnings < 5)) {
     777    _n_exclusive_warnings++;
     778    cerr << "FastJet WARNING: dcut and exclusive jets for jet-finders other than kt should be interpreted with care." << endl;
    977779  }
    978780
     
    1027829/// return the dmin corresponding to the recombination that went from
    1028830/// n+1 to n jets
    1029 double ClusterSequence::exclusive_dmerge (const int njets) const {
     831double ClusterSequence::exclusive_dmerge (const int & njets) const {
    1030832  assert(njets >= 0);
    1031833  if (njets >= _initial_n) {return 0.0;}
     
    1039841/// exclusive_dmerge, except in cases where the dmin do not increase
    1040842/// monotonically.
    1041 double ClusterSequence::exclusive_dmerge_max (const int njets) const {
     843double ClusterSequence::exclusive_dmerge_max (const int & njets) const {
    1042844  assert(njets >= 0);
    1043845  if (njets >= _initial_n) {return 0.0;}
     
    1051853/// the algorithm with the given dcut.
    1052854std::vector<PseudoJet> ClusterSequence::exclusive_subjets
    1053    (const PseudoJet & jet, const double dcut) const {
     855   (const PseudoJet & jet, const double & dcut) const {
    1054856
    1055857  set<const history_element*> subhist;
     
    1074876/// exclusive_subjets.size()
    1075877int ClusterSequence::n_exclusive_subjets(const PseudoJet & jet,
    1076                         const double dcut) const {
     878                        const double & dcut) const {
    1077879  set<const history_element*> subhist;
    1078880  // get the set of history elements that correspond to subjets at
     
    13791181// //----------------------------------------------------------------------
    13801182// // print out all inclusive jets with pt > ptmin
    1381 // void ClusterSequence::print_jets (const double ptmin) const{
     1183// void ClusterSequence::print_jets (const double & ptmin) const{
    13821184//     vector<PseudoJet> jets = sorted_by_pt(inclusive_jets(ptmin));
    13831185//
     
    14551257// initialise the history in a standard way
    14561258void ClusterSequence::_add_step_to_history (
    1457                const int step_number, const int parent1,
    1458                const int parent2, const int jetp_index,
    1459                const double dij) {
     1259               const int & step_number, const int & parent1,
     1260               const int & parent2, const int & jetp_index,
     1261               const double & dij) {
    14601262
    14611263  history_element element;
     
    16271429/// of the recombined jet, newjet_k.
    16281430void ClusterSequence::_do_ij_recombination_step(
    1629                                const int jet_i, const int jet_j,
    1630                                const double dij,
     1431                               const int & jet_i, const int & jet_j,
     1432                               const double & dij,
    16311433                               int & newjet_k) {
    16321434
     
    16641466/// jet_i with the beam
    16651467void ClusterSequence::_do_iB_recombination_step(
    1666                                   const int jet_i, const double diB) {
     1468                                  const int & jet_i, const double & diB) {
    16671469  // get history index
    16681470  int newstep_k = _history.size();
Note: See TracChangeset for help on using the changeset viewer.