Changeset 49234af in git for external/fastjet/JetDefinition.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/JetDefinition.cc
rf6b6ee7 r49234af 1 // STARTHEADER2 // $Id $3 // 4 // Copyright (c) 2005-201 1, Matteo Cacciari, Gavin P. Salam and Gregory Soyez1 //FJSTARTHEADER 2 // $Id: JetDefinition.cc 3677 2014-09-09 22:45:25Z soyez $ 3 // 4 // 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/JetDefinition.hh" … … 68 70 // cross-check the number of parameters that were declared in setting up the 69 71 // algorithm (passed internally from the public constructors) 70 switch (jet_algorithm_in) { 71 case ee_kt_algorithm: 72 if (nparameters != 0) { 73 ostringstream oss; 74 oss << "ee_kt_algorithm should be constructed with 0 parameters but was called with " 75 << nparameters << " parameter(s)\n"; 76 throw Error(oss.str()); 77 } 78 break; 79 case genkt_algorithm: 80 case ee_genkt_algorithm: 81 if (nparameters != 2) { 82 ostringstream oss; 83 oss << "(ee_)genkt_algorithm should be constructed with 2 parameters but was called with " 84 << nparameters << " parameter(s)\n"; 85 throw Error(oss.str()); 86 } 87 break; 88 default: 89 if (nparameters != 1) { 90 ostringstream oss; 91 oss << "The jet algorithm you requested (" 92 << jet_algorithm_in << ") should be constructed with 1 parameter but was called with " 93 << nparameters << " parameter(s)\n"; 94 throw Error(oss.str()); 95 } 72 unsigned int nparameters_expected = n_parameters_for_algorithm(jet_algorithm_in); 73 if (nparameters != (int) nparameters_expected){ 74 ostringstream oss; 75 oss << "The jet algorithm you requested (" 76 << jet_algorithm_in << ") should be constructed with " << nparameters_expected 77 << " parameter(s) but was called with " << nparameters << " parameter(s)\n"; 78 throw Error(oss.str()); 96 79 } 97 80 … … 106 89 107 90 //---------------------------------------------------------------------- 91 // returns true if the jet definition involves an algorithm 92 // intended for use on a spherical geometry (e.g. e+e- algorithms, 93 // as opposed to most pp algorithms, which use a cylindrical, 94 // rapidity-phi geometry). 95 bool JetDefinition::is_spherical() const { 96 if (jet_algorithm() == plugin_algorithm) { 97 return plugin()->is_spherical(); 98 } else { 99 return (jet_algorithm() == ee_kt_algorithm || // as of 2013-02-14, the two 100 jet_algorithm() == ee_genkt_algorithm // native spherical algorithms 101 ); 102 } 103 } 104 105 //---------------------------------------------------------------------- 108 106 string JetDefinition::description() const { 107 ostringstream name; 108 109 name << description_no_recombiner(); 110 111 if ((jet_algorithm() == plugin_algorithm) || (jet_algorithm() == undefined_jet_algorithm)){ 112 return name.str(); 113 } 114 115 if (n_parameters_for_algorithm(jet_algorithm()) == 0) 116 name << " with "; 117 else 118 name << " and "; 119 name << recombiner()->description(); 120 121 return name.str(); 122 } 123 124 //---------------------------------------------------------------------- 125 string JetDefinition::description_no_recombiner() const { 126 109 127 ostringstream name; 110 128 if (jet_algorithm() == plugin_algorithm) { 111 129 return plugin()->description(); 112 } else if (jet_algorithm() == kt_algorithm) {113 name << "Longitudinally invariant kt algorithm with R = " << R();114 name << " and " << recombiner()->description();115 } else if (jet_algorithm() == cambridge_algorithm) {116 name << "Longitudinally invariant Cambridge/Aachen algorithm with R = "117 << R() ;118 name << " and " << recombiner()->description();119 } else if (jet_algorithm() == antikt_algorithm) {120 name << "Longitudinally invariant anti-kt algorithm with R = "121 << R() ;122 name << " and " << recombiner()->description();123 } else if (jet_algorithm() == genkt_algorithm) {124 name << "Longitudinally invariant generalised kt algorithm with R = "125 << R() << ", p = " << extra_param();126 name << " and " << recombiner()->description();127 } else if (jet_algorithm() == cambridge_for_passive_algorithm) {128 name << "Longitudinally invariant Cambridge/Aachen algorithm with R = "129 << R() << "and a special hack whereby particles with kt < "130 << extra_param() << "are treated as passive ghosts";131 } else if (jet_algorithm() == ee_kt_algorithm) {132 name << "e+e- kt (Durham) algorithm (NB: no R)";133 name << " with " << recombiner()->description();134 } else if (jet_algorithm() == ee_genkt_algorithm) {135 name << "e+e- generalised kt algorithm with R = "136 << R() << ", p = " << extra_param();137 name << " and " << recombiner()->description();138 130 } else if (jet_algorithm() == undefined_jet_algorithm) { 139 name << "uninitialised JetDefinition (jet_algorithm=undefined_jet_algorithm)" ; 140 } else { 141 throw Error("JetDefinition::description(): unrecognized jet_algorithm"); 142 } 131 return "uninitialised JetDefinition (jet_algorithm=undefined_jet_algorithm)" ; 132 } 133 134 name << algorithm_description(jet_algorithm()); 135 switch (n_parameters_for_algorithm(jet_algorithm())){ 136 case 0: name << " (NB: no R)"; break; 137 case 1: name << " with R = " << R(); break; // the parameter is always R 138 case 2: 139 // the 1st parameter is always R 140 name << " with R = " << R(); 141 // the 2nd depends on the algorithm 142 if (jet_algorithm() == cambridge_for_passive_algorithm){ 143 name << "and a special hack whereby particles with kt < " 144 << extra_param() << "are treated as passive ghosts"; 145 } else { 146 name << ", p = " << extra_param(); 147 } 148 }; 149 143 150 return name.str(); 144 151 } 145 152 146 153 //---------------------------------------------------------------------- 154 string JetDefinition::algorithm_description(const JetAlgorithm jet_alg){ 155 ostringstream name; 156 switch (jet_alg){ 157 case plugin_algorithm: return "plugin algorithm"; 158 case kt_algorithm: return "Longitudinally invariant kt algorithm"; 159 case cambridge_algorithm: return "Longitudinally invariant Cambridge/Aachen algorithm"; 160 case antikt_algorithm: return "Longitudinally invariant anti-kt algorithm"; 161 case genkt_algorithm: return "Longitudinally invariant generalised kt algorithm"; 162 case cambridge_for_passive_algorithm: return "Longitudinally invariant Cambridge/Aachen algorithm"; 163 case ee_kt_algorithm: return "e+e- kt (Durham) algorithm (NB: no R)"; 164 case ee_genkt_algorithm: return "e+e- generalised kt algorithm"; 165 case undefined_jet_algorithm: return "undefined jet algorithm"; 166 default: 167 throw Error("JetDefinition::algorithm_description(): unrecognized jet_algorithm"); 168 }; 169 } 170 171 //---------------------------------------------------------------------- 172 unsigned int JetDefinition::n_parameters_for_algorithm(const JetAlgorithm jet_alg){ 173 switch (jet_alg) { 174 case ee_kt_algorithm: return 0; 175 case genkt_algorithm: 176 case ee_genkt_algorithm: return 2; 177 default: return 1; 178 }; 179 } 180 181 //---------------------------------------------------------------------- 147 182 void JetDefinition::set_recombination_scheme( 148 183 RecombinationScheme recomb_scheme) { … … 150 185 151 186 // do not forget to delete the existing recombiner if needed 152 if (_ recombiner_shared()) _recombiner_shared.reset();187 if (_shared_recombiner()) _shared_recombiner.reset(); 153 188 154 189 _recombiner = 0; 190 } 191 192 void JetDefinition::set_recombiner(const JetDefinition &other_jet_def){ 193 // make sure the "invariants" of the other jet def are sensible 194 assert(other_jet_def._recombiner || 195 other_jet_def.recombination_scheme() != external_scheme); 196 197 // first treat the situation where we're using the default recombiner 198 if (other_jet_def._recombiner == 0){ 199 set_recombination_scheme(other_jet_def.recombination_scheme()); 200 return; 201 } 202 203 // in other cases, copy the pointer to the recombiner 204 _recombiner = other_jet_def._recombiner; 205 // set the default recombiner appropriately 206 _default_recombiner = DefaultRecombiner(external_scheme); 207 // and set the _shared_recombiner to the same state 208 // as in the other_jet_def, whatever that was 209 _shared_recombiner.reset(other_jet_def._shared_recombiner); 210 211 // NB: it is tempting to go via set_recombiner and then to sort 212 // out the shared part, but this would be dangerous in the 213 // specific (rare?) case where other_jet_def is the same as this 214 // it deletes_recombiner_when_unused. In that case the shared 215 // pointer reset would delete the recombiner. 155 216 } 156 217 … … 163 224 if (other_jd.recombination_scheme() != scheme) return false; 164 225 165 // if the scheme is "external", also check that they ahve the same226 // if the scheme is "external", also check that they have the same 166 227 // recombiner 167 228 return (scheme != external_scheme) … … 169 230 } 170 231 171 /// allows to let the JetDefinitionhandle the deletion of the232 /// causes the JetDefinition to handle the deletion of the 172 233 /// recombiner when it is no longer used 173 234 void JetDefinition::delete_recombiner_when_unused(){ 174 235 if (_recombiner == 0){ 175 236 throw Error("tried to call JetDefinition::delete_recombiner_when_unused() for a JetDefinition without a user-defined recombination scheme"); 176 } 177 178 _recombiner_shared.reset(_recombiner); 237 } else if (_shared_recombiner.get()) { 238 throw Error("Error in JetDefinition::delete_recombiner_when_unused: the recombiner is already scheduled for deletion when unused (or was already set as shared)"); 239 } 240 241 _shared_recombiner.reset(_recombiner); 179 242 } 180 243 … … 207 270 case BIpt2_scheme: 208 271 return "boost-invariant pt2 scheme recombination"; 272 case WTA_pt_scheme: 273 return "pt-ordered Winner-Takes-All recombination"; 274 // Energy-ordering can lead to dangerous situations with particles at 275 // rest. We instead implement the WTA_modp_scheme 276 // 277 // case WTA_E_scheme: 278 // return "energy-ordered Winner-Takes-All recombination"; 279 case WTA_modp_scheme: 280 return "|3-momentum|-ordered Winner-Takes-All recombination"; 209 281 default: 210 282 ostringstream err; … … 246 318 weightb = pb.perp2(); 247 319 break; 320 case WTA_pt_scheme:{ 321 const PseudoJet & phard = (pa.pt2() >= pb.pt2()) ? pa : pb; 322 /// keep y,phi and m from the hardest, sum pt 323 pab.reset_PtYPhiM(pa.pt()+pb.pt(), 324 phard.rap(), phard.phi(), phard.m()); 325 return;} 326 // Energy-ordering can lead to dangerous situations with particles at 327 // rest. We instead implement the WTA_modp_scheme 328 // 329 // case WTA_E_scheme:{ 330 // const PseudoJet & phard = (pa.E() >= pb.E()) ? pa : pb; 331 // /// keep 3-momentum direction and mass from the hardest, sum energies 332 // /// 333 // /// If the particle with the largest energy is at rest, the sum 334 // /// remains at rest, implying that the mass of the sum is larger 335 // /// than the mass of pa. 336 // double Eab = pa.E() + pb.E(); 337 // double scale = (phard.modp2()==0.0) 338 // ? 0.0 339 // : sqrt((Eab*Eab - phard.m2())/phard.modp2()); 340 // pab.reset(phard.px()*scale, phard.py()*scale, phard.pz()*scale, Eab); 341 // return;} 342 case WTA_modp_scheme:{ 343 // Note: we need to compute both a and b modp. And we need pthard 344 // and its modp. If we want to avoid repeating the test and do 345 // only 2 modp calculations, we'd have to duplicate the code (or 346 // use a pair<const PJ&>). An alternative is to write modp_soft as 347 // modp_ab-modp_hard but this could suffer from larger rounding 348 // errors 349 bool a_hardest = (pa.modp2() >= pb.modp2()); 350 const PseudoJet & phard = a_hardest ? pa : pb; 351 const PseudoJet & psoft = a_hardest ? pb : pa; 352 /// keep 3-momentum direction and mass from the hardest, sum modp 353 /// 354 /// If the hardest particle is at rest, the sum remains at rest 355 /// (the energy of the sum is therefore the mass of pa) 356 double modp_hard = phard.modp(); 357 double modp_ab = modp_hard + psoft.modp(); 358 if (phard.modp2()==0.0){ 359 pab.reset(0.0, 0.0, 0.0, phard.m()); 360 } else { 361 double scale = modp_ab/modp_hard; 362 pab.reset(phard.px()*scale, phard.py()*scale, phard.pz()*scale, 363 sqrt(modp_ab*modp_ab + phard.m2())); 364 } 365 return;} 248 366 default: 249 367 ostringstream err; … … 281 399 case BIpt_scheme: 282 400 case BIpt2_scheme: 401 case WTA_pt_scheme: 402 //case WTA_E_scheme: 403 case WTA_modp_scheme: 283 404 break; 284 405 case pt_scheme:
Note:
See TracChangeset
for help on using the changeset viewer.