Changeset 49234af in git for external/fastjet/ClusterSequence.cc
- Timestamp:
- Dec 9, 2014, 1:27:13 PM (10 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/fastjet/ClusterSequence.cc
rf6b6ee7 r49234af 1 // STARTHEADER2 // $Id $1 //FJSTARTHEADER 2 // $Id: ClusterSequence.cc 3685 2014-09-11 20:15:00Z salam $ 3 3 // 4 // Copyright (c) 2005-201 3, Matteo Cacciari, Gavin P. Salam and Gregory Soyez4 // Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez 5 5 // 6 6 //---------------------------------------------------------------------- … … 13 13 // 14 14 // 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 16 17 // 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. 18 20 // 19 21 // FastJet is distributed in the hope that it will be useful, … … 25 27 // along with FastJet. If not, see <http://www.gnu.org/licenses/>. 26 28 //---------------------------------------------------------------------- 27 // ENDHEADER29 //FJENDHEADER 28 30 29 31 #include "fastjet/Error.hh" … … 32 34 #include "fastjet/ClusterSequenceStructure.hh" 33 35 #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__ 34 42 #include<iostream> 35 43 #include<sstream> … … 187 195 //DEP //---------------------------------------------------------------------- 188 196 //DEP void ClusterSequence::_initialise_and_run ( 189 //DEP const double &R,197 //DEP const double R, 190 198 //DEP const Strategy & strategy, 191 199 //DEP const bool & writeout_combinations) { … … 273 281 // ./fastjet_timing_plugins -kt -nhardest 30 -repeat 50000 -strategy -3 -R 0.5 -nev 1 < ../../data/Pythia-PtMin1000-LHC-1000ev.dat 274 282 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) { 275 289 int N = _jets.size(); 276 290 //if (N <= 55*max(0.5,min(1.0,_Rparam))) {// old empirical scaling with R … … 324 338 // run the code containing the selected strategy 325 339 // 326 // We order the strategies st qrting from the ones used by the Best340 // We order the strategies starting from the ones used by the Best 327 341 // strategy in the order of increasing N, then the remaining ones 328 342 // again in the order of increasing N. … … 334 348 } else if (_strategy == N2MinHeapTiled) { 335 349 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 336 386 } else if (_strategy == NlnN) { 337 387 this->_delaunay_cluster(); … … 359 409 // these needs to be defined outside the class definition. 360 410 bool ClusterSequence::_first_time = true; 361 int ClusterSequence::_n_exclusive_warnings = 0;411 LimitedWarning ClusterSequence::_exclusive_warnings; 362 412 363 413 … … 473 523 474 524 //---------------------------------------------------------------------- 475 // Return the component corresponding to the specified index.476 // taken from CLHEP477 525 string ClusterSequence::strategy_string (Strategy strategy_in) const { 478 526 string strategy; … … 492 540 case N2PoorTiled: 493 541 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; 494 550 case N3Dumb: 495 551 strategy = "N3Dumb"; break; … … 528 584 } else {return 1.0;} 529 585 } 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 530 730 } 531 731 … … 662 862 //---------------------------------------------------------------------- 663 863 // return all inclusive jets with pt > ptmin 664 vector<PseudoJet> ClusterSequence::inclusive_jets (const double &ptmin) const{864 vector<PseudoJet> ClusterSequence::inclusive_jets (const double ptmin) const{ 665 865 double dcut = ptmin*ptmin; 666 866 int i = _history.size() - 1; // last jet … … 714 914 // return the number of exclusive jets that would have been obtained 715 915 // running the algorithm in exclusive mode with the given dcut 716 int ClusterSequence::n_exclusive_jets (const double &dcut) const {916 int ClusterSequence::n_exclusive_jets (const double dcut) const { 717 917 718 918 // first locate the point where clustering would have stopped (i.e. the … … 733 933 // return all exclusive jets that would have been obtained running 734 934 // the algorithm in exclusive mode with the given dcut 735 vector<PseudoJet> ClusterSequence::exclusive_jets (const double &dcut) const {935 vector<PseudoJet> ClusterSequence::exclusive_jets (const double dcut) const { 736 936 int njets = n_exclusive_jets(dcut); 737 937 return exclusive_jets(njets); … … 742 942 // return the jets obtained by clustering the event to n jets. 743 943 // Throw an error if there are fewer than n particles. 744 vector<PseudoJet> ClusterSequence::exclusive_jets (const int &njets) const {944 vector<PseudoJet> ClusterSequence::exclusive_jets (const int njets) const { 745 945 746 946 // make sure the user does not ask for more than jets than there … … 759 959 // return the jets obtained by clustering the event to n jets. 760 960 // If there are fewer than n particles, simply return all particles 761 vector<PseudoJet> ClusterSequence::exclusive_jets_up_to (const int &njets) const {961 vector<PseudoJet> ClusterSequence::exclusive_jets_up_to (const int njets) const { 762 962 763 963 // provide a warning when extracting exclusive jets for algorithms 764 964 // 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, 766 966 // genkt and ee_genkt (both with p>=0) 767 967 // For plugins, we check Plugin::exclusive_sequence_meaningful() … … 773 973 (_jet_def.extra_param() <0)) && 774 974 ((_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."); 779 977 } 780 978 … … 829 1027 /// return the dmin corresponding to the recombination that went from 830 1028 /// n+1 to n jets 831 double ClusterSequence::exclusive_dmerge (const int &njets) const {1029 double ClusterSequence::exclusive_dmerge (const int njets) const { 832 1030 assert(njets >= 0); 833 1031 if (njets >= _initial_n) {return 0.0;} … … 841 1039 /// exclusive_dmerge, except in cases where the dmin do not increase 842 1040 /// monotonically. 843 double ClusterSequence::exclusive_dmerge_max (const int &njets) const {1041 double ClusterSequence::exclusive_dmerge_max (const int njets) const { 844 1042 assert(njets >= 0); 845 1043 if (njets >= _initial_n) {return 0.0;} … … 853 1051 /// the algorithm with the given dcut. 854 1052 std::vector<PseudoJet> ClusterSequence::exclusive_subjets 855 (const PseudoJet & jet, const double &dcut) const {1053 (const PseudoJet & jet, const double dcut) const { 856 1054 857 1055 set<const history_element*> subhist; … … 876 1074 /// exclusive_subjets.size() 877 1075 int ClusterSequence::n_exclusive_subjets(const PseudoJet & jet, 878 const double &dcut) const {1076 const double dcut) const { 879 1077 set<const history_element*> subhist; 880 1078 // get the set of history elements that correspond to subjets at … … 1181 1379 // //---------------------------------------------------------------------- 1182 1380 // // 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{ 1184 1382 // vector<PseudoJet> jets = sorted_by_pt(inclusive_jets(ptmin)); 1185 1383 // … … 1257 1455 // initialise the history in a standard way 1258 1456 void 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) { 1262 1460 1263 1461 history_element element; … … 1429 1627 /// of the recombined jet, newjet_k. 1430 1628 void 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, 1433 1631 int & newjet_k) { 1434 1632 … … 1466 1664 /// jet_i with the beam 1467 1665 void ClusterSequence::_do_iB_recombination_step( 1468 const int & jet_i, const double &diB) {1666 const int jet_i, const double diB) { 1469 1667 // get history index 1470 1668 int newstep_k = _history.size();
Note:
See TracChangeset
for help on using the changeset viewer.