Fork me on GitHub

Ignore:
Timestamp:
Dec 9, 2014, 1:27:13 PM (10 years ago)
Author:
Michele <michele.selvaggi@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
37deb3b, 9e991f8
Parents:
f6b6ee7 (diff), e7e90df (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'TestFastJet310b1'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/fastjet/ClusterSequence.cc

    rf6b6ee7 r49234af  
    1 //STARTHEADER
    2 // $Id$
     1//FJSTARTHEADER
     2// $Id: ClusterSequence.cc 3685 2014-09-11 20:15:00Z salam $
    33//
    4 // Copyright (c) 2005-2013, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
     4// Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
    55//
    66//----------------------------------------------------------------------
     
    1313//
    1414//  The algorithms that underlie FastJet have required considerable
    15 //  development and are described in hep-ph/0512210. If you use
     15//  development. They are described in the original FastJet paper,
     16//  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
    1617//  FastJet as part of work towards a scientific publication, please
    17 //  include a citation to the FastJet paper.
     18//  quote the version you use and include a citation to the manual and
     19//  optionally also to hep-ph/0512210.
    1820//
    1921//  FastJet is distributed in the hope that it will be useful,
     
    2527//  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
    2628//----------------------------------------------------------------------
    27 //ENDHEADER
     29//FJENDHEADER
    2830
    2931#include "fastjet/Error.hh"
     
    3234#include "fastjet/ClusterSequenceStructure.hh"
    3335#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__
    3442#include<iostream>
    3543#include<sstream>
     
    187195//DEP //----------------------------------------------------------------------
    188196//DEP void ClusterSequence::_initialise_and_run (
    189 //DEP                             const double & R,
     197//DEP                             const double R,
    190198//DEP                             const Strategy & strategy,
    191199//DEP                             const bool & writeout_combinations) {
     
    273281  //             ./fastjet_timing_plugins -kt -nhardest 30 -repeat 50000 -strategy -3 -R 0.5 -nev 1  <  ../../data/Pythia-PtMin1000-LHC-1000ev.dat
    274282  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) {
    275289    int N = _jets.size();
    276290    //if (N <= 55*max(0.5,min(1.0,_Rparam))) {// old empirical scaling with R
     
    324338  // run the code containing the selected strategy
    325339  //
    326   // We order the strategies stqrting from the ones used by the Best
     340  // We order the strategies starting from the ones used by the Best
    327341  // strategy in the order of increasing N, then the remaining ones
    328342  // again in the order of increasing N.
     
    334348  } else if (_strategy == N2MinHeapTiled) {
    335349    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
    336386  } else if (_strategy == NlnN) {
    337387    this->_delaunay_cluster();
     
    359409// these needs to be defined outside the class definition.
    360410bool ClusterSequence::_first_time = true;
    361 int ClusterSequence::_n_exclusive_warnings = 0;
     411LimitedWarning ClusterSequence::_exclusive_warnings;
    362412
    363413
     
    473523
    474524//----------------------------------------------------------------------
    475 // Return the component corresponding to the specified index.
    476 // taken from CLHEP
    477525string ClusterSequence::strategy_string (Strategy strategy_in)  const {
    478526  string strategy;
     
    492540  case N2PoorTiled:
    493541    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;
    494550  case N3Dumb:
    495551    strategy = "N3Dumb"; break;
     
    528584    } else {return 1.0;}
    529585  } 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.
     603Strategy 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
    530730}
    531731
     
    662862//----------------------------------------------------------------------
    663863// return all inclusive jets with pt > ptmin
    664 vector<PseudoJet> ClusterSequence::inclusive_jets (const double & ptmin) const{
     864vector<PseudoJet> ClusterSequence::inclusive_jets (const double ptmin) const{
    665865  double dcut = ptmin*ptmin;
    666866  int i = _history.size() - 1; // last jet
     
    714914// return the number of exclusive jets that would have been obtained
    715915// running the algorithm in exclusive mode with the given dcut
    716 int ClusterSequence::n_exclusive_jets (const double & dcut) const {
     916int ClusterSequence::n_exclusive_jets (const double dcut) const {
    717917
    718918  // first locate the point where clustering would have stopped (i.e. the
     
    733933// return all exclusive jets that would have been obtained running
    734934// the algorithm in exclusive mode with the given dcut
    735 vector<PseudoJet> ClusterSequence::exclusive_jets (const double & dcut) const {
     935vector<PseudoJet> ClusterSequence::exclusive_jets (const double dcut) const {
    736936  int njets = n_exclusive_jets(dcut);
    737937  return exclusive_jets(njets);
     
    742942// return the jets obtained by clustering the event to n jets.
    743943// Throw an error if there are fewer than n particles.
    744 vector<PseudoJet> ClusterSequence::exclusive_jets (const int & njets) const {
     944vector<PseudoJet> ClusterSequence::exclusive_jets (const int njets) const {
    745945
    746946  // make sure the user does not ask for more than jets than there
     
    759959// return the jets obtained by clustering the event to n jets.
    760960// If there are fewer than n particles, simply return all particles
    761 vector<PseudoJet> ClusterSequence::exclusive_jets_up_to (const int & njets) const {
     961vector<PseudoJet> ClusterSequence::exclusive_jets_up_to (const int njets) const {
    762962
    763963  // provide a warning when extracting exclusive jets for algorithms
    764964  // that does not support it explicitly.
    765   // Native algorithm that support it are: kt, ee_kt, cambridge,
     965  // Native algorithm that support it are: kt, ee_kt, Cambridge/Aachen,
    766966  //   genkt and ee_genkt (both with p>=0)
    767967  // For plugins, we check Plugin::exclusive_sequence_meaningful()
     
    773973       (_jet_def.extra_param() <0)) &&
    774974      ((_jet_def.jet_algorithm() != plugin_algorithm) ||
    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;
     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.");
    779977  }
    780978
     
    8291027/// return the dmin corresponding to the recombination that went from
    8301028/// n+1 to n jets
    831 double ClusterSequence::exclusive_dmerge (const int & njets) const {
     1029double ClusterSequence::exclusive_dmerge (const int njets) const {
    8321030  assert(njets >= 0);
    8331031  if (njets >= _initial_n) {return 0.0;}
     
    8411039/// exclusive_dmerge, except in cases where the dmin do not increase
    8421040/// monotonically.
    843 double ClusterSequence::exclusive_dmerge_max (const int & njets) const {
     1041double ClusterSequence::exclusive_dmerge_max (const int njets) const {
    8441042  assert(njets >= 0);
    8451043  if (njets >= _initial_n) {return 0.0;}
     
    8531051/// the algorithm with the given dcut.
    8541052std::vector<PseudoJet> ClusterSequence::exclusive_subjets
    855    (const PseudoJet & jet, const double & dcut) const {
     1053   (const PseudoJet & jet, const double dcut) const {
    8561054
    8571055  set<const history_element*> subhist;
     
    8761074/// exclusive_subjets.size()
    8771075int ClusterSequence::n_exclusive_subjets(const PseudoJet & jet,
    878                         const double & dcut) const {
     1076                        const double dcut) const {
    8791077  set<const history_element*> subhist;
    8801078  // get the set of history elements that correspond to subjets at
     
    11811379// //----------------------------------------------------------------------
    11821380// // print out all inclusive jets with pt > ptmin
    1183 // void ClusterSequence::print_jets (const double & ptmin) const{
     1381// void ClusterSequence::print_jets (const double ptmin) const{
    11841382//     vector<PseudoJet> jets = sorted_by_pt(inclusive_jets(ptmin));
    11851383//
     
    12571455// initialise the history in a standard way
    12581456void ClusterSequence::_add_step_to_history (
    1259                const int & step_number, const int & parent1,
    1260                const int & parent2, const int & jetp_index,
    1261                const double & dij) {
     1457               const int step_number, const int parent1,
     1458               const int parent2, const int jetp_index,
     1459               const double dij) {
    12621460
    12631461  history_element element;
     
    14291627/// of the recombined jet, newjet_k.
    14301628void ClusterSequence::_do_ij_recombination_step(
    1431                                const int & jet_i, const int & jet_j,
    1432                                const double & dij,
     1629                               const int jet_i, const int jet_j,
     1630                               const double dij,
    14331631                               int & newjet_k) {
    14341632
     
    14661664/// jet_i with the beam
    14671665void ClusterSequence::_do_iB_recombination_step(
    1468                                   const int & jet_i, const double & diB) {
     1666                                  const int jet_i, const double diB) {
    14691667  // get history index
    14701668  int newstep_k = _history.size();
Note: See TracChangeset for help on using the changeset viewer.