Changeset 35cdc46 in git for external/fastjet/contribs
- Timestamp:
- Sep 3, 2014, 3:18:54 PM (10 years ago)
- Branches:
- ImprovedOutputFile, Timing, dual_readout, llp, master
- Children:
- be2222c
- Parents:
- 5b5a56b
- Location:
- external/fastjet/contribs
- Files:
-
- 16 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
external/fastjet/contribs/Nsubjettiness/AUTHORS
r5b5a56b r35cdc46 18 18 JHEP 1202:093 (2012), arXiv:1108.2701. 19 19 20 New in v2.0 is the winner-take-all axis, described in: 21 22 Jet Shapes with the Broadening Axis. 23 Andrew J. Larkoski, Duff Neill, and Jesse Thaler. 24 JHEP 1404:017 (2014), arXiv:1401.2158. 25 26 as well as in unpublished work by Gavin Salam. 27 20 28 ---------------------------------------------------------------------- -
external/fastjet/contribs/Nsubjettiness/AxesFinder.cc
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: AxesFinder.cc 670 2014-06-06 01:24:42Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 37 38 template <int N> 38 39 std::vector<LightLikeAxis> AxesFinderFromOnePassMinimization::UpdateAxesFast(const std::vector <LightLikeAxis> & old_axes, 39 const std::vector <fastjet::PseudoJet> & inputJets) {40 const std::vector <fastjet::PseudoJet> & inputJets) const { 40 41 assert(old_axes.size() == N); 41 42 … … 45 46 for (int n = 0; n < N; ++n) { 46 47 new_axes[n].reset(0.0,0.0,0.0,0.0); 47 #ifdef FASTJET248 new_jets[n].reset(0.0,0.0,0.0,0.0);49 #else50 // use cheaper reset if available51 48 new_jets[n].reset_momentum(0.0,0.0,0.0,0.0); 52 #endif53 49 } 54 50 … … 135 131 // (This is just a wrapper for the templated version above.) 136 132 std::vector<LightLikeAxis> AxesFinderFromOnePassMinimization::UpdateAxes(const std::vector <LightLikeAxis> & old_axes, 137 const std::vector <fastjet::PseudoJet> & inputJets) {133 const std::vector <fastjet::PseudoJet> & inputJets) const { 138 134 int N = old_axes.size(); 139 135 switch (N) { … … 166 162 // uses minimization of N-jettiness to continually update axes until convergence. 167 163 // The function returns the axes found at the (local) minimum 168 std::vector<fastjet::PseudoJet> AxesFinderFromOnePassMinimization::get BetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputJets, const std::vector<fastjet::PseudoJet>& seedAxes){164 std::vector<fastjet::PseudoJet> AxesFinderFromOnePassMinimization::getAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputJets, const std::vector<fastjet::PseudoJet>& seedAxes) const { 169 165 170 166 // convert from PseudoJets to LightLikeAxes … … 211 207 } 212 208 213 PseudoJet AxesFinderFromKmeansMinimization::jiggle(const PseudoJet& axis) {209 PseudoJet AxesFinderFromKmeansMinimization::jiggle(const PseudoJet& axis) const { 214 210 double phi_noise = ((double)rand()/(double)RAND_MAX) * _noise_range * 2.0 - _noise_range; 215 211 double rap_noise = ((double)rand()/(double)RAND_MAX) * _noise_range * 2.0 - _noise_range; … … 226 222 227 223 // Repeatedly calls the one pass finder to try to find global minimum 228 std::vector<fastjet::PseudoJet> AxesFinderFromKmeansMinimization::get BetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputJets, const std::vector<fastjet::PseudoJet>& seedAxes){224 std::vector<fastjet::PseudoJet> AxesFinderFromKmeansMinimization::getAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputJets, const std::vector<fastjet::PseudoJet>& seedAxes) const { 229 225 230 226 // first iteration … … 256 252 // It continually updates until it reaches convergence or it reaches the maximum number of attempts. 257 253 // This is essentially the same as a stable cone finder. 258 std::vector<fastjet::PseudoJet> AxesFinderFromGeometricMinimization::get BetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & particles, const std::vector<fastjet::PseudoJet>& currentAxes){254 std::vector<fastjet::PseudoJet> AxesFinderFromGeometricMinimization::getAxes(int /*n_jets*/, const std::vector <fastjet::PseudoJet> & particles, const std::vector<fastjet::PseudoJet>& currentAxes) const { 259 255 260 256 std::vector<fastjet::PseudoJet> seedAxes = currentAxes; 261 double seedTau = _function ->tau(particles, seedAxes);257 double seedTau = _function.tau(particles, seedAxes); 262 258 263 259 for (int i = 0; i < _nAttempts; i++) { … … 270 266 // start from unclustered beam measure 271 267 int minJ = -1; 272 double minDist = _function ->beam_distance_squared(particles[i]);268 double minDist = _function.beam_distance_squared(particles[i]); 273 269 274 270 // which axis am I closest to? 275 271 for (unsigned int j = 0; j < seedAxes.size(); j++) { 276 double tempDist = _function ->jet_distance_squared(particles[i],seedAxes[j]);272 double tempDist = _function.jet_distance_squared(particles[i],seedAxes[j]); 277 273 if (tempDist < minDist) { 278 274 minDist = tempDist; … … 287 283 // calculate tau on new axes 288 284 seedAxes = newAxes; 289 double tempTau = _function ->tau(particles, newAxes);285 double tempTau = _function.tau(particles, newAxes); 290 286 291 287 // close enough to stop? -
external/fastjet/contribs/Nsubjettiness/AxesFinder.hh
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: AxesFinder.hh 678 2014-06-12 20:43:03Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 53 54 class AxesFinder { 54 55 55 protected: 56 AxesFinder* _startingFinder; // storing a possible starting finder if needed 57 std::vector<fastjet::PseudoJet> _seedAxes; 58 59 AxesFinder(AxesFinder* startingFinder = NULL) : _startingFinder(startingFinder) {} 60 61 public: 62 virtual ~AxesFinder(){ 63 if (_startingFinder) delete _startingFinder; //TODO: Convert to smart pointers to avoid this. 64 } 65 66 // Allow setting of seedAxes from a starting finder 67 std::vector<fastjet::PseudoJet> getAxes(int n_jets, const std::vector<fastjet::PseudoJet> & inputs, const std::vector<fastjet::PseudoJet>& currentAxes) { 68 if (_startingFinder) { 69 _seedAxes = _startingFinder->getAxes(n_jets,inputs,currentAxes); 70 return getBetterAxes(n_jets,inputs,_seedAxes); 71 } else { 72 _seedAxes = getBetterAxes(n_jets,inputs,currentAxes); 73 return _seedAxes; 74 } 75 } 76 77 // say what the current seed axes are 78 std::vector<fastjet::PseudoJet> seedAxes() const { 79 return _seedAxes; 80 } 81 82 // This function should be overloaded, and updates the seedAxes 83 virtual std::vector<fastjet::PseudoJet> getBetterAxes(int n_jets, const std::vector<fastjet::PseudoJet> & inputs, const std::vector<fastjet::PseudoJet>& seedAxes) = 0; 84 85 }; 86 56 public: 57 58 // This function should be overloaded, and updates the seedAxes to return new axes 59 virtual std::vector<fastjet::PseudoJet> getAxes(int n_jets, 60 const std::vector<fastjet::PseudoJet>& inputs, 61 const std::vector<fastjet::PseudoJet>& seedAxes) const = 0; 62 // convenient shorthand for squaring 63 static inline double sq(double x) {return x*x;} 64 65 //virtual destructor 66 virtual ~AxesFinder(){} 67 68 }; 69 70 87 71 //------------------------------------------------------------------------ 88 72 /// \class AxesFinderFromExclusiveJetDefinition … … 90 74 // with different jet algorithms. 91 75 class AxesFinderFromExclusiveJetDefinition : public AxesFinder { 92 93 private: 94 fastjet::JetDefinition _def; 95 96 public: 97 AxesFinderFromExclusiveJetDefinition(fastjet::JetDefinition def) : _def(def) {} 98 99 virtual std::vector<fastjet::PseudoJet> getBetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputs, const std::vector<fastjet::PseudoJet>& currentAxes) { 100 fastjet::ClusterSequence jet_clust_seq(inputs, _def); 101 return jet_clust_seq.exclusive_jets(n_jets); 102 } 76 77 public: 78 AxesFinderFromExclusiveJetDefinition(fastjet::JetDefinition def) 79 : _def(def) {} 80 81 virtual std::vector<fastjet::PseudoJet> getAxes(int n_jets, 82 const std::vector <fastjet::PseudoJet> & inputs, 83 const std::vector<fastjet::PseudoJet>& /*seedAxes*/) const { 84 fastjet::ClusterSequence jet_clust_seq(inputs, _def); 85 return jet_clust_seq.exclusive_jets(n_jets); 86 } 87 88 private: 89 fastjet::JetDefinition _def; 90 103 91 }; 104 92 … … 108 96 // winner take all recombination scheme. 109 97 class AxesFinderFromWTA_KT : public AxesFinderFromExclusiveJetDefinition { 110 private: 111 const WinnerTakeAllRecombiner *recomb; 112 public: 113 AxesFinderFromWTA_KT() : AxesFinderFromExclusiveJetDefinition( 114 fastjet::JetDefinition(fastjet::kt_algorithm, 115 fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 116 recomb = new WinnerTakeAllRecombiner(), 117 fastjet::Best)) {} 118 ~AxesFinderFromWTA_KT() {delete recomb;} 119 }; 98 99 public: 100 AxesFinderFromWTA_KT() 101 : AxesFinderFromExclusiveJetDefinition( 102 fastjet::JetDefinition(fastjet::kt_algorithm, 103 fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 104 &_recomb, 105 fastjet::Best)) {} 106 107 private: 108 const WinnerTakeAllRecombiner _recomb; 109 110 }; 120 111 121 112 //------------------------------------------------------------------------ … … 124 115 // winner take all recombination scheme. 125 116 class AxesFinderFromWTA_CA : public AxesFinderFromExclusiveJetDefinition { 126 private: 127 const WinnerTakeAllRecombiner *recomb; 128 public: 129 AxesFinderFromWTA_CA() : AxesFinderFromExclusiveJetDefinition( 130 fastjet::JetDefinition(fastjet::cambridge_algorithm, 131 fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 132 recomb = new WinnerTakeAllRecombiner(), 133 fastjet::Best)) {} 134 ~AxesFinderFromWTA_CA() {delete recomb;} 135 }; 136 137 // The following classes are for testing, and are commented out for initial release 138 // 139 ////------------------------------------------------------------------------ 140 ///// \class AxesFinderFromWTA2_KT 141 //// This class finds axes by finding the exlusive jets after clustering according to a kT algorithm and a 142 //// winner take all recombination scheme with alpha = 2. 143 //class AxesFinderFromWTA2_KT : public AxesFinderFromExclusiveJetDefinition { 144 // private: 145 // const WinnerTakeAllRecombiner *recomb; 146 // public: 147 // AxesFinderFromWTA2_KT() : AxesFinderFromExclusiveJetDefinition( 148 // fastjet::JetDefinition(fastjet::kt_algorithm, 149 // fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 150 // recomb = new WinnerTakeAllRecombiner(2), // uses alpha = 2 here 151 // fastjet::Best)) {} 152 // ~AxesFinderFromWTA2_KT() {delete recomb;} 153 // }; 154 // 155 ////------------------------------------------------------------------------ 156 ///// \class AxesFinderFromWTA2_CA 157 //// This class finds axes by finding the exlusive jets after clustering according to a CA algorithm and a 158 //// winner take all recombination scheme with alpha = 2. 159 //class AxesFinderFromWTA2_CA : public AxesFinderFromExclusiveJetDefinition { 160 // private: 161 // const WinnerTakeAllRecombiner *recomb; 162 // public: 163 // AxesFinderFromWTA2_CA() : AxesFinderFromExclusiveJetDefinition( 164 // fastjet::JetDefinition(fastjet::cambridge_algorithm, 165 // fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 166 // recomb = new WinnerTakeAllRecombiner(2), //uses alpha = 2 here 167 // fastjet::Best)) {} 168 // ~AxesFinderFromWTA2_CA() {delete recomb;} 169 //}; 117 public: 118 AxesFinderFromWTA_CA() 119 : AxesFinderFromExclusiveJetDefinition( 120 fastjet::JetDefinition(fastjet::cambridge_algorithm, 121 fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 122 &_recomb, 123 fastjet::Best)) {} 124 125 private: 126 const WinnerTakeAllRecombiner _recomb; 127 }; 128 170 129 171 130 //------------------------------------------------------------------------ … … 174 133 // E_scheme recombination. 175 134 class AxesFinderFromKT : public AxesFinderFromExclusiveJetDefinition { 176 public: 177 AxesFinderFromKT() : AxesFinderFromExclusiveJetDefinition( 178 fastjet::JetDefinition(fastjet::kt_algorithm, 179 fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 180 fastjet::E_scheme, 181 fastjet::Best)) {} 135 public: 136 AxesFinderFromKT() 137 : AxesFinderFromExclusiveJetDefinition( 138 fastjet::JetDefinition(fastjet::kt_algorithm, 139 fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 140 fastjet::E_scheme, 141 fastjet::Best)) {} 182 142 }; 183 143 … … 187 147 // E_scheme recombination. 188 148 class AxesFinderFromCA : public AxesFinderFromExclusiveJetDefinition { 189 public: 190 AxesFinderFromCA() : AxesFinderFromExclusiveJetDefinition( 191 fastjet::JetDefinition(fastjet::cambridge_algorithm, 192 fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 193 fastjet::E_scheme, 194 fastjet::Best)) {} 149 public: 150 AxesFinderFromCA() 151 : AxesFinderFromExclusiveJetDefinition( 152 fastjet::JetDefinition(fastjet::cambridge_algorithm, 153 fastjet::JetDefinition::max_allowable_R, //maximum jet radius constant 154 fastjet::E_scheme, 155 fastjet::Best)) {} 195 156 }; 196 157 … … 201 162 // This can be implemented with different jet algorithms. 202 163 class AxesFinderFromHardestJetDefinition : public AxesFinder { 203 204 private: 205 fastjet::JetDefinition _def; 206 207 public: 208 AxesFinderFromHardestJetDefinition(fastjet::JetDefinition def) : _def(def) {} 209 210 virtual std::vector<fastjet::PseudoJet> getBetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputs, const std::vector<fastjet::PseudoJet>& currentAxes) { 211 fastjet::ClusterSequence jet_clust_seq(inputs, _def); 212 std::vector<fastjet::PseudoJet> myJets = sorted_by_pt(jet_clust_seq.inclusive_jets()); 213 myJets.resize(n_jets); // only keep n hardest 214 return myJets; 215 } 164 public: 165 AxesFinderFromHardestJetDefinition(fastjet::JetDefinition def) 166 : _def(def) {} 167 168 virtual std::vector<fastjet::PseudoJet> getAxes(int n_jets, 169 const std::vector <fastjet::PseudoJet> & inputs, 170 const std::vector<fastjet::PseudoJet>& /*seedAxes*/) const { 171 fastjet::ClusterSequence jet_clust_seq(inputs, _def); 172 std::vector<fastjet::PseudoJet> myJets = sorted_by_pt(jet_clust_seq.inclusive_jets()); 173 myJets.resize(n_jets); // only keep n hardest 174 return myJets; 175 } 176 177 private: 178 fastjet::JetDefinition _def; 216 179 }; 217 180 … … 221 184 // to an anti kT algorithm and E_scheme. 222 185 class AxesFinderFromAntiKT : public AxesFinderFromHardestJetDefinition { 223 public: 224 AxesFinderFromAntiKT(double R0) : AxesFinderFromHardestJetDefinition(fastjet::JetDefinition(fastjet::antikt_algorithm,R0,fastjet::E_scheme,fastjet::Best)) {} 186 public: 187 AxesFinderFromAntiKT(double R0) 188 : AxesFinderFromHardestJetDefinition( 189 fastjet::JetDefinition(fastjet::antikt_algorithm, 190 R0,fastjet::E_scheme,fastjet::Best)) {} 225 191 }; 226 192 … … 231 197 class AxesFinderFromUserInput : public AxesFinder { 232 198 233 public: 234 AxesFinderFromUserInput() {} 235 236 virtual std::vector<fastjet::PseudoJet> getBetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputs, const std::vector<fastjet::PseudoJet>& currentAxes) { 237 assert(currentAxes.size() == (unsigned int) n_jets); 238 return currentAxes; 239 } 199 public: 200 AxesFinderFromUserInput() {} 201 202 virtual std::vector<fastjet::PseudoJet> getAxes(int n_jets, const std::vector <fastjet::PseudoJet> & /*inputs*/, const std::vector<fastjet::PseudoJet>& currentAxes) const { 203 assert(currentAxes.size() == (unsigned int) n_jets); 204 (void)(n_jets); // adding this line to fix unused-parameter warning 205 return currentAxes; 206 } 240 207 }; 241 208 … … 249 216 class AxesFinderFromOnePassMinimization : public AxesFinder { 250 217 251 private: 252 double _precision; // Desired precision in axes alignment 253 int _halt; // maximum number of steps per iteration 254 255 double _beta; 256 double _Rcutoff; 257 258 DefaultUnnormalizedMeasure _measureFunction; 259 260 public: 261 262 // From a startingFinder, try to minimize the unnormalized_measure 263 AxesFinderFromOnePassMinimization(AxesFinder* startingFinder, double beta, double Rcutoff) 264 : AxesFinder(startingFinder), 265 _precision(0.0001), //hard coded for now 266 _halt(1000), //hard coded for now 267 _beta(beta), 268 _Rcutoff(Rcutoff), 269 _measureFunction(beta, Rcutoff) 270 {} 271 272 virtual std::vector<fastjet::PseudoJet> getBetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputJets, const std::vector<fastjet::PseudoJet>& currentAxes); 273 274 template <int N> std::vector<LightLikeAxis> UpdateAxesFast(const std::vector <LightLikeAxis> & old_axes, 275 const std::vector <fastjet::PseudoJet> & inputJets); 276 277 std::vector<LightLikeAxis> UpdateAxes(const std::vector <LightLikeAxis> & old_axes, 278 const std::vector <fastjet::PseudoJet> & inputJets); 218 public: 219 220 // From a startingFinder, try to minimize the unnormalized_measure 221 AxesFinderFromOnePassMinimization(double beta, double Rcutoff) 222 : _precision(0.0001), //hard coded for now 223 _halt(1000), //hard coded for now 224 _beta(beta), 225 _Rcutoff(Rcutoff), 226 _measureFunction(beta, Rcutoff) 227 {} 228 229 virtual std::vector<fastjet::PseudoJet> getAxes(int n_jets, 230 const std::vector <fastjet::PseudoJet> & inputJets, 231 const std::vector<fastjet::PseudoJet>& currentAxes) const; 232 233 private: 234 double _precision; // Desired precision in axes alignment 235 int _halt; // maximum number of steps per iteration 236 237 double _beta; 238 double _Rcutoff; 239 240 DefaultUnnormalizedMeasureFunction _measureFunction; 241 242 template <int N> std::vector<LightLikeAxis> UpdateAxesFast(const std::vector <LightLikeAxis> & old_axes, 243 const std::vector <fastjet::PseudoJet> & inputJets) const; 244 245 std::vector<LightLikeAxis> UpdateAxes(const std::vector <LightLikeAxis> & old_axes, 246 const std::vector <fastjet::PseudoJet> & inputJets) const; 279 247 280 248 }; … … 288 256 class AxesFinderFromKmeansMinimization : public AxesFinder{ 289 257 290 private: 291 int _n_iterations; // Number of iterations to run (0 for no minimization, 1 for one-pass, >>1 for global minimum) 292 double _noise_range; // noise range for random initialization 293 294 DefaultUnnormalizedMeasure _measureFunction; //function to test whether minimum is reached 295 296 AxesFinderFromOnePassMinimization _onePassFinder; //one pass finder for minimization 297 298 PseudoJet jiggle(const PseudoJet& axis); 299 300 public: 301 AxesFinderFromKmeansMinimization(AxesFinder *startingFinder, double beta, double Rcutoff, int n_iterations) : 302 AxesFinder(startingFinder), 303 _n_iterations(n_iterations), 304 _noise_range(1.0), // hard coded for the time being 305 _measureFunction(beta, Rcutoff), 306 _onePassFinder(NULL, beta, Rcutoff) 307 {} 308 309 virtual std::vector<fastjet::PseudoJet> getBetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputJets, const std::vector<fastjet::PseudoJet>& currentAxes); 310 258 public: 259 AxesFinderFromKmeansMinimization(double beta, double Rcutoff, int n_iterations) 260 : _n_iterations(n_iterations), 261 _noise_range(1.0), // hard coded for the time being 262 _measureFunction(beta, Rcutoff), 263 _onePassFinder(beta, Rcutoff) 264 {} 265 266 virtual std::vector<fastjet::PseudoJet> getAxes(int n_jets, const std::vector <fastjet::PseudoJet> & inputJets, const std::vector<fastjet::PseudoJet>& currentAxes) const; 267 268 private: 269 int _n_iterations; // Number of iterations to run (0 for no minimization, 1 for one-pass, >>1 for global minimum) 270 double _noise_range; // noise range for random initialization 271 272 DefaultUnnormalizedMeasureFunction _measureFunction; //function to test whether minimum is reached 273 274 AxesFinderFromOnePassMinimization _onePassFinder; //one pass finder that is repeatedly called 275 276 PseudoJet jiggle(const PseudoJet& axis) const; 311 277 }; 312 278 … … 317 283 class AxesFinderFromGeometricMinimization : public AxesFinder { 318 284 319 private: 320 MeasureFunction* _function; 321 double _Rcutoff; 322 double _nAttempts; 323 double _accuracy; 324 325 326 public: 327 AxesFinderFromGeometricMinimization(AxesFinder* startingFinder, double beta, double Rcutoff) : AxesFinder(startingFinder), _Rcutoff(Rcutoff) { 328 if (beta != 2.0) { 329 std::cerr << "Geometric minimization is currently only defined for beta = 2.0." << std::endl; 330 exit(1); 331 } 332 333 _nAttempts = 100; 334 _accuracy = 0.000000001; 335 _function = new GeometricMeasure(beta,_Rcutoff); 285 public: 286 AxesFinderFromGeometricMinimization(double beta, double Rcutoff) 287 : _nAttempts(100), 288 _accuracy(0.000000001), 289 _function(beta,Rcutoff) 290 { 291 if (beta != 2.0) { 292 throw Error("Geometric minimization is currently only defined for beta = 2.0."); 336 293 } 337 338 ~AxesFinderFromGeometricMinimization() { 339 delete _function; 340 } 341 342 virtual std::vector<fastjet::PseudoJet> getBetterAxes(int n_jets, const std::vector <fastjet::PseudoJet> & particles, const std::vector<fastjet::PseudoJet>& currentAxes); 294 } 295 296 virtual std::vector<fastjet::PseudoJet> getAxes(int n_jets, const std::vector <fastjet::PseudoJet> & particles, const std::vector<fastjet::PseudoJet>& currentAxes) const; 297 298 private: 299 double _nAttempts; 300 double _accuracy; 301 GeometricMeasureFunction _function; 302 303 343 304 }; 344 305 … … 348 309 // in order to better facilitate calculations. 349 310 class LightLikeAxis { 350 private: 351 double _rap, _phi, _weight, _mom; 352 353 double DistanceSq(double rap2, double phi2) const { 354 double rap1 = _rap; 355 double phi1 = _phi; 356 357 double distRap = rap1-rap2; 358 double distPhi = std::fabs(phi1-phi2); 359 if (distPhi > M_PI) {distPhi = 2.0*M_PI - distPhi;} 360 return sq(distRap) + sq(distPhi); 361 } 362 363 double Distance(double rap2, double phi2) const { 364 return std::sqrt(DistanceSq(rap2,phi2)); 365 } 366 367 311 368 312 public: 369 313 LightLikeAxis() : _rap(0.0), _phi(0.0), _weight(0.0), _mom(0.0) {} … … 399 343 } 400 344 345 private: 346 double _rap, _phi, _weight, _mom; 347 348 double DistanceSq(double rap2, double phi2) const { 349 double rap1 = _rap; 350 double phi1 = _phi; 351 352 double distRap = rap1-rap2; 353 double distPhi = std::fabs(phi1-phi2); 354 if (distPhi > M_PI) {distPhi = 2.0*M_PI - distPhi;} 355 return distRap*distRap + distPhi*distPhi; 356 } 357 358 double Distance(double rap2, double phi2) const { 359 return std::sqrt(DistanceSq(rap2,phi2)); 360 } 361 362 401 363 }; 402 364 -
external/fastjet/contribs/Nsubjettiness/MeasureFunction.cc
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: MeasureFunction.cc 670 2014-06-06 01:24:42Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 36 37 37 38 // Return all of the necessary TauComponents for specific input particles and axes 38 TauComponents MeasureFunction::result(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) { 39 TauComponents MeasureFunction::result(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const { 40 41 // first find partition 42 // this sets jetPartitionStorage and beamPartitionStorage 43 PseudoJet beamPartitionStorage; 44 std::vector<fastjet::PseudoJet> jetPartitionStorage = get_partition(particles,axes,&beamPartitionStorage); 45 46 // then return result calculated from partition 47 return result_from_partition(jetPartitionStorage,axes,&beamPartitionStorage); 48 } 39 49 40 std::vector<double> jetPieces(axes.size(), 0.0); 41 double beamPiece = 0.0; 50 std::vector<fastjet::PseudoJet> MeasureFunction::get_partition(const std::vector<fastjet::PseudoJet>& particles, 51 const std::vector<fastjet::PseudoJet>& axes, 52 PseudoJet * beamPartitionStorage) const { 42 53 43 // Calculates the unnormalized sub-tau values, i.e. a std::vector of the contributions to tau_N of each Voronoi region (or region within R_0) 54 std::vector<std::vector<PseudoJet> > jetPartition(axes.size()); 55 std::vector<PseudoJet> beamPartition; 56 57 // Figures out the partiting of the input particles into the various jet pieces 58 // Based on which axis the parition is closest to 44 59 for (unsigned i = 0; i < particles.size(); i++) { 45 60 … … 60 75 61 76 if (j_min == -1) { 62 if (_has_beam) beamP iece += beam_numerator(particles[i]);77 if (_has_beam) beamPartition.push_back(particles[i]); 63 78 else assert(_has_beam); // this should never happen. 64 79 } else { 65 jetP ieces[j_min] += jet_numerator(particles[i],axes[j_min]);80 jetPartition[j_min].push_back(particles[i]); 66 81 } 67 82 } 68 83 69 // Calculates normalization for tau and subTau if _has_denominator is true, otherwise returns 1.0 (i.e. no normalization) 70 double tauDen = 0.0; 71 if (_has_denominator) { 72 for (unsigned i = 0; i < particles.size(); i++) { 73 tauDen += denominator(particles[i]); 74 } 75 } else { 76 tauDen = 1.0; // if no denominator, then 1.0 for no normalization factor 84 // Store beam partition 85 if (beamPartitionStorage) { 86 *beamPartitionStorage = join(beamPartition); 87 } 88 89 // Store jet partitions 90 std::vector<PseudoJet> jetPartitionStorage(axes.size(),PseudoJet(0,0,0,0)); 91 for (unsigned j = 0; j < axes.size(); j++) { 92 jetPartitionStorage[j] = join(jetPartition[j]); 77 93 } 78 94 95 return jetPartitionStorage; 96 } 97 98 // does partition, but only stores index of PseudoJets 99 std::vector<std::list<int> > MeasureFunction::get_partition_list(const std::vector<fastjet::PseudoJet>& particles, 100 const std::vector<fastjet::PseudoJet>& axes) const { 101 102 std::vector<std::list<int> > jetPartition(axes.size()); 103 104 // Figures out the partiting of the input particles into the various jet pieces 105 // Based on which axis the parition is closest to 106 for (unsigned i = 0; i < particles.size(); i++) { 107 108 // find minimum distance; start with beam (-1) for reference 109 int j_min = -1; 110 double minRsq; 111 if (_has_beam) minRsq = beam_distance_squared(particles[i]); 112 else minRsq = std::numeric_limits<double>::max(); // make it large value 113 114 // check to see which axis the particle is closest to 115 for (unsigned j = 0; j < axes.size(); j++) { 116 double tempRsq = jet_distance_squared(particles[i],axes[j]); // delta R distance 117 if (tempRsq < minRsq) { 118 minRsq = tempRsq; 119 j_min = j; 120 } 121 } 122 123 if (j_min == -1) { 124 assert(_has_beam); // consistency check 125 } else { 126 jetPartition[j_min].push_back(i); 127 } 128 } 129 130 return jetPartition; 131 } 132 133 134 // Uses existing partition and calculates result 135 // TODO: Can we cache this for speed up when doing area subtraction? 136 TauComponents MeasureFunction::result_from_partition(const std::vector<fastjet::PseudoJet>& jet_partition, 137 const std::vector<fastjet::PseudoJet>& axes, 138 PseudoJet * beamPartitionStorage) const { 139 140 std::vector<double> jetPieces(axes.size(), 0.0); 141 double beamPiece = 0.0; 142 143 double tauDen = 0.0; 144 if (!_has_denominator) tauDen = 1.0; // if no denominator, then 1.0 for no normalization factor 145 146 // first find jet pieces 147 for (unsigned j = 0; j < axes.size(); j++) { 148 std::vector<PseudoJet> thisPartition = jet_partition[j].constituents(); 149 for (unsigned i = 0; i < thisPartition.size(); i++) { 150 jetPieces[j] += jet_numerator(thisPartition[i],axes[j]); //numerator jet piece 151 if (_has_denominator) tauDen += denominator(thisPartition[i]); // denominator 152 } 153 } 154 155 // then find beam piece 156 if (_has_beam) { 157 assert(beamPartitionStorage); // make sure I have beam information 158 std::vector<PseudoJet> beamPartition = beamPartitionStorage->constituents(); 159 160 for (unsigned i = 0; i < beamPartition.size(); i++) { 161 beamPiece += beam_numerator(beamPartition[i]); //numerator beam piece 162 if (_has_denominator) tauDen += denominator(beamPartition[i]); // denominator 163 } 164 } 79 165 return TauComponents(jetPieces, beamPiece, tauDen, _has_denominator, _has_beam); 80 166 } 167 168 169 170 81 171 82 172 } //namespace contrib -
external/fastjet/contribs/Nsubjettiness/MeasureFunction.hh
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: MeasureFunction.hh 678 2014-06-12 20:43:03Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 31 32 #include <limits> 32 33 34 33 35 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 34 36 35 37 namespace contrib{ 36 38 37 inline double sq(double x) {return x*x;} 38 39 /////// 40 // 41 // Measure Function 42 // 43 /////// 44 39 /////// 40 // 41 // TauComponents 42 // (eventually we might want to put this in a separate header file) 43 // 44 /////// 45 45 46 /// \class TauComponents 46 47 // This class creates a wrapper for the various tau/subtau values calculated in Njettiness. This class allows Njettiness access to these variables 47 48 // without ever having to do the calculation itself. It takes in subtau numerators and tau denominator from MeasureFunction 48 49 // and outputs tau numerator, and normalized tau and subtau. 49 // TODO: Consider merging with NjettinessExtras. Add axes information?50 50 class TauComponents { 51 private:52 53 // these values are input in the constructor54 std::vector<double> _jet_pieces_numerator;55 double _beam_piece_numerator;56 double _denominator;57 bool _has_denominator; //added so that TauComponents knows if denominator is used or not58 bool _has_beam; //added so that TauComponents knows if beam regions is used or not59 60 // these values are derived from above values61 std::vector<double> _jet_pieces;62 double _beam_piece;63 double _numerator;64 double _tau;65 66 51 67 52 public: … … 115 100 double beam_piece() const { return _beam_piece; } 116 101 double tau() const { return _tau; } 117 118 }; 102 103 private: 104 105 // these values are input in the constructor 106 std::vector<double> _jet_pieces_numerator; 107 double _beam_piece_numerator; 108 double _denominator; 109 bool _has_denominator; //added so that TauComponents knows if denominator is used or not 110 bool _has_beam; //added so that TauComponents knows if beam regions is used or not 111 112 // these values are derived from above values 113 std::vector<double> _jet_pieces; 114 double _beam_piece; 115 double _numerator; 116 double _tau; 117 118 }; 119 120 /////// 121 // 122 // Measure Function 123 // 124 /////// 125 119 126 120 127 //------------------------------------------------------------------------ … … 125 132 class MeasureFunction { 126 133 134 public: 135 //These functions define the measure by which tau_N is calculated, 136 //and are overloaded by the various measures below 137 138 // Distanes to axes. These are called many times, so need to be as fast as possible 139 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const = 0; 140 virtual double beam_distance_squared(const fastjet::PseudoJet& particle) const = 0; 141 142 // The actual measures used in N-(sub)jettiness 143 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const = 0; 144 virtual double beam_numerator(const fastjet::PseudoJet& particle) const = 0; 145 146 // a possible normalization factor 147 virtual double denominator(const fastjet::PseudoJet& particle) const = 0; 148 149 //------ 150 // The functions below call the above functions and are not virtual 151 //------ 152 153 // Return all of the necessary TauComponents for specific input particles and axes 154 // Also have optional pointers to get out information about partitioning 155 TauComponents result(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const; 156 157 // Just getting tau value if that is all that is needed 158 double tau(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const { 159 return result(particles,axes).tau(); 160 } 161 162 // Create the partitioning and stores internally 163 std::vector<fastjet::PseudoJet> get_partition(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes, PseudoJet * beamPartitionStorage = NULL) const; 164 165 // Essentially same as get_partition, but in the form needed for the jet algorithm 166 std::vector<std::list<int> > get_partition_list(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const; 167 168 // calculates the tau result using an existing partition 169 TauComponents result_from_partition(const std::vector<fastjet::PseudoJet>& jet_partitioning, const std::vector<fastjet::PseudoJet>& axes, PseudoJet * beamPartitionStorage = NULL) const; 170 171 // shorthand for squaring 172 static inline double sq(double x) {return x*x;} 173 174 //virtual destructor 175 virtual ~MeasureFunction(){} 176 127 177 protected: 128 178 //bool set by derived classes to choose whether or not to use the denominator … … 133 183 MeasureFunction(bool has_denominator = true, bool has_beam = true) : _has_denominator(has_denominator), _has_beam(has_beam) {} 134 184 135 public: 136 virtual ~MeasureFunction(){} 137 138 //These functions define the measure by which tau_N is calculated, 139 //and are overloaded by the various measures below 140 141 // Distanes to axes. These are called many times, so need to be as fast as possible 142 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) = 0; 143 virtual double beam_distance_squared(const fastjet::PseudoJet& particle) = 0; 144 145 // The actual measures used in N-(sub)jettiness 146 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) = 0; 147 virtual double beam_numerator(const fastjet::PseudoJet& particle) = 0; 148 149 // a possible normalization factor 150 virtual double denominator(const fastjet::PseudoJet& particle) = 0; 151 152 153 // These functions call the above functions and are not virtual 154 155 // Do I cluster a particle into a jet? 156 bool do_cluster(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) { 157 return (jet_distance_squared(particle,axis) <= beam_distance_squared(particle)); 158 } 159 160 // Return all of the necessary TauComponents for specific input particles and axes 161 TauComponents result(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes); 162 163 double tau(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) { 164 return result(particles,axes).tau(); 165 } 166 167 168 }; 169 170 171 /// \class DefaultNormalizedMeasure 185 }; 186 187 188 /// \class DefaultNormalizedMeasureFunction 172 189 // This class is the default measure, inheriting from the class above. This class will calculate tau_N 173 190 // of a jet according to this measure. This measure is defined as the pT of the particle multiplied by deltaR 174 191 // to the power of beta. This class includes the normalization factor determined by R0 175 class DefaultNormalizedMeasure : public MeasureFunction { 176 177 private: 178 double _beta; 179 double _R0; 180 double _Rcutoff; 181 182 public: 183 184 DefaultNormalizedMeasure(double beta, double R0, double Rcutoff, bool normalized = true) 185 : MeasureFunction(normalized), _beta(beta), _R0(R0), _Rcutoff(Rcutoff) {} 186 187 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) { 188 return particle.squared_distance(axis); 189 } 190 191 virtual double beam_distance_squared(const fastjet::PseudoJet& particle) { 192 return sq(_Rcutoff); 193 } 194 195 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) { 196 return particle.perp() * std::pow(jet_distance_squared(particle,axis),_beta/2.0); 197 } 198 199 virtual double beam_numerator(const fastjet::PseudoJet& particle) { 200 return particle.perp() * std::pow(_Rcutoff,_beta); 201 } 202 203 virtual double denominator(const fastjet::PseudoJet& particle) { 204 return particle.perp() * std::pow(_R0,_beta); 205 } 206 192 class DefaultNormalizedMeasureFunction : public MeasureFunction { 193 194 public: 195 196 DefaultNormalizedMeasureFunction(double beta, double R0, double Rcutoff, bool normalized = true) 197 : MeasureFunction(normalized), _beta(beta), _R0(R0), _Rcutoff(Rcutoff) {} 198 199 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const { 200 return particle.squared_distance(axis); 201 } 202 203 virtual double beam_distance_squared(const fastjet::PseudoJet& /*particle*/) const { 204 return sq(_Rcutoff); 205 } 206 207 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const{ 208 return particle.perp() * std::pow(jet_distance_squared(particle,axis),_beta/2.0); 209 } 210 211 virtual double beam_numerator(const fastjet::PseudoJet& particle) const { 212 return particle.perp() * std::pow(_Rcutoff,_beta); 213 } 214 215 virtual double denominator(const fastjet::PseudoJet& particle) const { 216 return particle.perp() * std::pow(_R0,_beta); 217 } 218 219 private: 220 double _beta; 221 double _R0; 222 double _Rcutoff; 223 224 207 225 }; 208 226 209 227 //------------------------------------------------------------------------ 210 /// \class DefaultUnnormalizedMeasure 228 /// \class DefaultUnnormalizedMeasureFunction 211 229 // This class is the unnormalized default measure, inheriting from the class above. The only difference from above 212 230 // is that the denominator is defined to be 1.0 by setting _has_denominator to false. 213 class DefaultUnnormalizedMeasure : public DefaultNormalizedMeasure{214 215 216 // Since all methods are identical, UnnormalizedMeasure inherits directly from NormalizedMeasure. R0 is defaulted to NAN since the value of R0 is unecessary for this class.217 // the "false" flag sets _has_denominator in MeasureFunction to false so no denominator is used.218 DefaultUnnormalizedMeasure(double beta, double Rcutoff) : DefaultNormalizedMeasure(beta, NAN, Rcutoff, false) {}219 220 231 class DefaultUnnormalizedMeasureFunction : public DefaultNormalizedMeasureFunction { 232 233 public: 234 // Since all methods are identical, UnnormalizedMeasure inherits directly 235 // from NormalizedMeasure. R0 is a dummy value since the value of R0 is unecessary for this class, 236 // and the "false" flag sets _has_denominator in MeasureFunction to false so no denominator is used. 237 DefaultUnnormalizedMeasureFunction(double beta, double Rcutoff) 238 : DefaultNormalizedMeasureFunction(beta, std::numeric_limits<double>::quiet_NaN(), Rcutoff, false) {} 221 239 }; 222 240 223 241 //------------------------------------------------------------------------ 224 /// \class GeometricMeasure 242 /// \class GeometricMeasureFunction 225 243 // This class is the geometic measure, inheriting from the class above. This class will calculate tau_N 226 244 // of a jet according to this measure. This measure is defined by the Lorentz dot product between 227 245 // the particle and the axis. This class includes normalization of tau_N. 228 class GeometricMeasure : public MeasureFunction { 229 230 private: 231 double _jet_beta; 232 double _beam_beta; 233 double _Rcutoff; 234 235 // create light-like axis 236 fastjet::PseudoJet lightFrom(const fastjet::PseudoJet& input) const { 237 double length = sqrt(pow(input.px(),2) + pow(input.py(),2) + pow(input.pz(),2)); 238 return fastjet::PseudoJet(input.px()/length,input.py()/length,input.pz()/length,1.0); 239 } 240 241 public: 242 // Right now, we are hard coded for beam_beta = 1.0, but that will need to change 243 GeometricMeasure(double jet_beta, double Rcutoff) : _jet_beta(jet_beta), _beam_beta(1.0), _Rcutoff(Rcutoff) {} 244 245 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) { 246 fastjet::PseudoJet lightAxis = lightFrom(axis); 247 double pseudoRsquared = 2.0*dot_product(lightFrom(axis),particle)/(lightAxis.pt()*particle.pt()); 248 return pseudoRsquared; 249 } 250 251 virtual double beam_distance_squared(const fastjet::PseudoJet& particle) { 252 return sq(_Rcutoff); 253 } 254 255 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) { 256 fastjet::PseudoJet lightAxis = lightFrom(axis); 257 double weight = (_beam_beta == 1.0) ? 1.0 : std::pow(lightAxis.pt(),_beam_beta - 1.0); 258 return particle.pt() * weight * std::pow(jet_distance_squared(particle,axis),_jet_beta/2.0); 259 } 260 261 virtual double beam_numerator(const fastjet::PseudoJet& particle) { 262 double weight = (_beam_beta == 1.0) ? 1.0 : std::pow(particle.pt()/particle.e(),_beam_beta - 1.0); 263 return particle.pt() * weight * std::pow(_Rcutoff,_jet_beta); 264 } 265 266 virtual double denominator(const fastjet::PseudoJet& particle) { 267 return 1.0; 268 } 269 }; 270 271 246 class GeometricMeasureFunction : public MeasureFunction { 247 248 public: 249 // Right now, we are hard coded for beam_beta = 1.0, but that will need to change 250 GeometricMeasureFunction(double jet_beta, double Rcutoff) : 251 MeasureFunction(false), // doesn't have denominator 252 _jet_beta(jet_beta), _beam_beta(1.0), _Rcutoff(Rcutoff) {} 253 254 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const { 255 fastjet::PseudoJet lightAxis = lightFrom(axis); 256 double pseudoRsquared = 2.0*dot_product(lightFrom(axis),particle)/(lightAxis.pt()*particle.pt()); 257 return pseudoRsquared; 258 } 259 260 virtual double beam_distance_squared(const fastjet::PseudoJet& /*particle*/) const { 261 return sq(_Rcutoff); 262 } 263 264 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const { 265 fastjet::PseudoJet lightAxis = lightFrom(axis); 266 double weight = (_beam_beta == 1.0) ? 1.0 : std::pow(lightAxis.pt(),_beam_beta - 1.0); 267 return particle.pt() * weight * std::pow(jet_distance_squared(particle,axis),_jet_beta/2.0); 268 } 269 270 virtual double beam_numerator(const fastjet::PseudoJet& particle) const { 271 double weight = (_beam_beta == 1.0) ? 1.0 : std::pow(particle.pt()/particle.e(),_beam_beta - 1.0); 272 return particle.pt() * weight * std::pow(_Rcutoff,_jet_beta); 273 } 274 275 virtual double denominator(const fastjet::PseudoJet& /*particle*/) const { 276 return std::numeric_limits<double>::quiet_NaN(); 277 } 278 279 280 private: 281 double _jet_beta; 282 double _beam_beta; 283 double _Rcutoff; 284 285 // create light-like axis 286 fastjet::PseudoJet lightFrom(const fastjet::PseudoJet& input) const { 287 double length = sqrt(pow(input.px(),2) + pow(input.py(),2) + pow(input.pz(),2)); 288 return fastjet::PseudoJet(input.px()/length,input.py()/length,input.pz()/length,1.0); 289 } 290 291 }; 292 293 272 294 } //namespace contrib 273 295 -
external/fastjet/contribs/Nsubjettiness/Njettiness.cc
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: Njettiness.cc 677 2014-06-12 18:56:46Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 35 36 /////// 36 37 37 // Helper function to correlate one pass minimization with appropriate measure 38 void Njettiness::setOnePassAxesFinder(MeasureMode measure_mode, AxesFinder* startingFinder, double beta, double Rcutoff) { 39 if (measure_mode == normalized_measure || measure_mode == unnormalized_measure || measure_mode == normalized_cutoff_measure || measure_mode == unnormalized_cutoff_measure) { 40 _axesFinder = new AxesFinderFromOnePassMinimization(startingFinder, beta, Rcutoff); 41 } 42 else if (measure_mode == geometric_measure || measure_mode == geometric_cutoff_measure) { 43 _axesFinder = new AxesFinderFromGeometricMinimization(startingFinder, beta, Rcutoff); 44 } 45 else { 46 std::cerr << "Minimization only set up for normalized_measure, unnormalized_measure, normalized_cutoff_measure, unnormalized_cutoff_measure, geometric_measure, geometric_cutoff_measure" << std::endl; 47 exit(1); } 48 } 49 50 // Parsing needed for constructor to set AxesFinder and MeasureFunction 51 // All of the parameter handling is here, and checking that number of parameters is correct. 52 void Njettiness::setMeasureFunctionandAxesFinder(AxesMode axes_mode, MeasureMode measure_mode, double para1, double para2, double para3, double para4) { 38 Njettiness::Njettiness(const AxesDefinition & axes_def, const MeasureDefinition & measure_def) 39 : _axes_def(axes_def.create()), _measure_def(measure_def.create()) { 40 setMeasureFunctionAndAxesFinder(); // call helper function to do the hard work 41 } 42 43 Njettiness::Njettiness(AxesMode axes_mode, const MeasureDefinition & measure_def) 44 : _axes_def(createAxesDef(axes_mode)), _measure_def(measure_def.create()) { 45 setMeasureFunctionAndAxesFinder(); // call helper function to do the hard work 46 } 47 48 // Convert from MeasureMode enum to MeasureDefinition 49 // This returns a pointer that will be claimed by a SharedPtr 50 MeasureDefinition* Njettiness::createMeasureDef(MeasureMode measure_mode, int num_para, double para1, double para2, double para3) const { 53 51 54 52 // definition of maximum Rcutoff for non-cutoff measures, changed later by other measures 55 53 double Rcutoff = std::numeric_limits<double>::max(); //large number 56 // Most (but all measures have some kind of beta value)57 double beta = NAN;54 // Most (but not all) measures have some kind of beta value 55 double beta = std::numeric_limits<double>::quiet_NaN(); 58 56 // The normalized measures have an R0 value. 59 double R0 = NAN;60 57 double R0 = std::numeric_limits<double>::quiet_NaN(); 58 61 59 // Find the MeasureFunction and set the parameters. 62 60 switch (measure_mode) { … … 64 62 beta = para1; 65 63 R0 = para2; 66 if( correctParameterCount(2, para1, para2, para3, para4))67 _measureFunction = new DefaultNormalizedMeasure(beta, R0, Rcutoff); //normalized_measure requires 2 parameters, beta and R068 else {69 std::cerr << "normalized_measure needs 2 parameters (beta and R0)" << std::endl;70 exit(1);}64 if(num_para == 2) { 65 return new NormalizedMeasure(beta,R0); 66 } else { 67 throw Error("normalized_measure needs 2 parameters (beta and R0)"); 68 } 71 69 break; 72 70 case unnormalized_measure: 73 71 beta = para1; 74 if( correctParameterCount(1, para1, para2, para3, para4))75 _measureFunction = new DefaultUnnormalizedMeasure(beta, Rcutoff); //unnormalized_measure requires 1 parameter, beta76 else {77 std::cerr << "unnormalized_measure needs 1 parameter (beta)" << std::endl;78 exit(1);}72 if(num_para == 1) { 73 return new UnnormalizedMeasure(beta); 74 } else { 75 throw Error("unnormalized_measure needs 1 parameter (beta)"); 76 } 79 77 break; 80 78 case geometric_measure: 81 79 beta = para1; 82 if (correctParameterCount(1, para1, para2, para3, para4))83 _measureFunction = new GeometricMeasure(beta,Rcutoff); //geometric_measure requires 1 parameter, beta84 else {85 std::cerr << "geometric_measure needs 1 parameter (beta)" << std::endl;86 exit(1);}80 if (num_para == 1) { 81 return new GeometricMeasure(beta); 82 } else { 83 throw Error("geometric_measure needs 1 parameter (beta)"); 84 } 87 85 break; 88 86 case normalized_cutoff_measure: … … 90 88 R0 = para2; 91 89 Rcutoff = para3; //Rcutoff parameter is 3rd parameter in normalized_cutoff_measure 92 if (correctParameterCount(3, para1, para2, para3, para4))93 _measureFunction = new DefaultNormalizedMeasure(beta, R0, Rcutoff); //normalized_cutoff_measure requires 3 parameters, beta, R0, and Rcutoff94 else {95 std::cerr << "normalized_cutoff_measure has 3 parameters (beta, R0, Rcutoff)" << std::endl;96 exit(1);}90 if (num_para == 3) { 91 return new NormalizedCutoffMeasure(beta,R0,Rcutoff); 92 } else { 93 throw Error("normalized_cutoff_measure has 3 parameters (beta, R0, Rcutoff)"); 94 } 97 95 break; 98 96 case unnormalized_cutoff_measure: 99 97 beta = para1; 100 98 Rcutoff = para2; //Rcutoff parameter is 2nd parameter in normalized_cutoff_measure 101 if ( correctParameterCount(2, para1, para2, para3, para4))102 _measureFunction = new DefaultUnnormalizedMeasure(beta, Rcutoff); //unnormalized_cutoff_measure requires 2 parameters, beta and Rcutoff103 else {104 std::cerr << "unnormalized_cutoff_measure has 2 parameters (beta, Rcutoff)" << std::endl;105 exit(1);}99 if (num_para == 2) { 100 return new UnnormalizedCutoffMeasure(beta,Rcutoff); 101 } else { 102 throw Error("unnormalized_cutoff_measure has 2 parameters (beta, Rcutoff)"); 103 } 106 104 break; 107 105 case geometric_cutoff_measure: 108 106 beta = para1; 109 107 Rcutoff = para2; //Rcutoff parameter is 2nd parameter in geometric_cutoff_measure 110 if( correctParameterCount(2, para1, para2, para3, para4))111 _measureFunction = new GeometricMeasure(beta,Rcutoff); //geometric_cutoff_measure requires 2 parameters, beta and Rcutoff112 else {113 std::cerr << "geometric_cutoff_measure has 2 parameters (beta,Rcutoff)" << std::endl;114 exit(1);}108 if(num_para == 2) { 109 return new GeometricCutoffMeasure(beta,Rcutoff); 110 } else { 111 throw Error("geometric_cutoff_measure has 2 parameters (beta, Rcutoff)"); 112 } 115 113 break; 116 114 default: 117 115 assert(false); 118 116 break; 119 } 120 121 // Choose which AxesFinder from user input. 122 // Uses setOnePassAxesFinder helpful function to use beta and Rcutoff values about (if needed) 117 } 118 return NULL; 119 } 120 121 // Convert from AxesMode enum to AxesDefinition 122 // This returns a pointer that will be claimed by a SharedPtr 123 AxesDefinition* Njettiness::createAxesDef(Njettiness::AxesMode axes_mode) const { 124 123 125 switch (axes_mode) { 124 126 case wta_kt_axes: 125 _axesFinder = new AxesFinderFromWTA_KT(); 126 break; 127 return new WTA_KT_Axes(); 127 128 case wta_ca_axes: 128 _axesFinder = new AxesFinderFromWTA_CA(); 129 break; 129 return new WTA_CA_Axes(); 130 130 case kt_axes: 131 _axesFinder = new AxesFinderFromKT(); 132 break; 131 return new KT_Axes(); 133 132 case ca_axes: 134 _axesFinder = new AxesFinderFromCA(); 135 break; 133 return new CA_Axes(); 136 134 case antikt_0p2_axes: 137 _axesFinder = new AxesFinderFromAntiKT(0.2); 138 break; 135 return new AntiKT_Axes(0.2); 139 136 case onepass_wta_kt_axes: 140 setOnePassAxesFinder(measure_mode, new AxesFinderFromWTA_KT(), beta, Rcutoff); 141 break; 137 return new OnePass_WTA_KT_Axes(); 142 138 case onepass_wta_ca_axes: 143 setOnePassAxesFinder(measure_mode, new AxesFinderFromWTA_CA(), beta, Rcutoff); 144 break; 139 return new OnePass_WTA_CA_Axes(); 145 140 case onepass_kt_axes: 146 setOnePassAxesFinder(measure_mode, new AxesFinderFromKT(), beta, Rcutoff); 147 break; 141 return new OnePass_KT_Axes(); 148 142 case onepass_ca_axes: 149 setOnePassAxesFinder(measure_mode, new AxesFinderFromCA(), beta, Rcutoff); 150 break; 143 return new OnePass_CA_Axes(); 151 144 case onepass_antikt_0p2_axes: 152 setOnePassAxesFinder(measure_mode, new AxesFinderFromAntiKT(0.2), beta, Rcutoff); 153 break; 145 return new OnePass_AntiKT_Axes(0.2); 154 146 case onepass_manual_axes: 155 setOnePassAxesFinder(measure_mode, new AxesFinderFromUserInput(), beta, Rcutoff); 156 break; 157 case min_axes: //full minimization is not defined for geometric_measure. 158 if (measure_mode == normalized_measure || measure_mode == unnormalized_measure || measure_mode == normalized_cutoff_measure || measure_mode == unnormalized_cutoff_measure) 159 //Defaults to 100 iteration to find minimum 160 _axesFinder = new AxesFinderFromKmeansMinimization(new AxesFinderFromKT(), beta, Rcutoff, 100); 161 else { 162 std::cerr << "Multi-pass minimization only set up for normalized_measure, unnormalized_measure, normalized_cutoff_measure, unnormalized_cutoff_measure." << std::endl; 163 exit(1); 164 } 165 break; 147 return new OnePass_Manual_Axes(); 148 case min_axes: 149 return new MultiPass_Axes(100); 166 150 case manual_axes: 167 _axesFinder = new AxesFinderFromUserInput(); 168 break; 169 // These options have been commented out because they have not been fully tested 170 // case wta2_kt_axes: // option for alpha = 2 added 171 // _axesFinder = new AxesFinderFromWTA2_KT(); 172 // break; 173 // case wta2_ca_axes: // option for alpha = 2 added 174 // _axesFinder = new AxesFinderFromWTA2_CA(); 175 // break; 176 // case onepass_wta2_kt_axes: // option for alpha = 2 added 177 // setOnePassAxesFinder(measure_mode, new AxesFinderFromWTA2_KT(), beta, Rcutoff); 178 // break; 179 // case onepass_wta2_ca_axes: // option for alpha = 2 added 180 // setOnePassAxesFinder(measure_mode, new AxesFinderFromWTA2_CA(), beta, Rcutoff); 181 // break; 151 return new Manual_Axes(); 182 152 default: 183 153 assert(false); 184 break; 185 } 186 154 return NULL; 155 } 156 } 157 158 159 // Parsing needed for constructor to set AxesFinder and MeasureFunction 160 // All of the parameter handling is here, and checking that number of parameters is correct. 161 void Njettiness::setMeasureFunctionAndAxesFinder() { 162 // Get the correct MeasureFunction and AxesFinders 163 _measureFunction.reset(_measure_def->createMeasureFunction()); 164 _startingAxesFinder.reset(_axes_def->createStartingAxesFinder(*_measure_def)); 165 _finishingAxesFinder.reset(_axes_def->createFinishingAxesFinder(*_measure_def)); 187 166 } 188 167 189 168 // setAxes for Manual mode 190 void Njettiness::setAxes( std::vector<fastjet::PseudoJet>myAxes) {191 if (_ current_axes_mode == manual_axes || _current_axes_mode == onepass_manual_axes) {169 void Njettiness::setAxes(const std::vector<fastjet::PseudoJet> & myAxes) { 170 if (_axes_def->supportsManualAxes()) { 192 171 _currentAxes = myAxes; 193 } 194 else { 195 std::cerr << "You can only use setAxes if using manual_axes or onepass_manual_axes measure mode" << std::endl; 196 exit(1); 172 } else { 173 throw Error("You can only use setAxes for manual AxesDefinitions"); 197 174 } 198 175 } … … 200 177 // Calculates and returns all TauComponents that user would want. 201 178 // This information is stored in _current_tau_components for later access as well. 202 TauComponents Njettiness::getTauComponents(unsigned n_jets, const std::vector<fastjet::PseudoJet> & inputJets) {179 TauComponents Njettiness::getTauComponents(unsigned n_jets, const std::vector<fastjet::PseudoJet> & inputJets) const { 203 180 if (inputJets.size() <= n_jets) { //if not enough particles, return zero 204 181 _currentAxes = inputJets; … … 206 183 _current_tau_components = TauComponents(); 207 184 _seedAxes = _currentAxes; 185 _currentJets = _currentAxes; 186 _currentBeam = PseudoJet(0.0,0.0,0.0,0.0); 208 187 } else { 209 _currentAxes = _axesFinder->getAxes(n_jets,inputJets,_currentAxes); // sets current Axes 210 _seedAxes = _axesFinder->seedAxes(); // sets seed Axes (if one pass minimization was used) 211 _current_tau_components = _measureFunction->result(inputJets, _currentAxes); // sets current Tau Values 188 189 _seedAxes = _startingAxesFinder->getAxes(n_jets,inputJets,_currentAxes); //sets starting point for minimization 190 if (_finishingAxesFinder) { 191 _currentAxes = _finishingAxesFinder->getAxes(n_jets,inputJets,_seedAxes); 192 } else { 193 _currentAxes = _seedAxes; 194 } 195 196 // Find partition and store information 197 // (jet information in _currentJets, beam in _currentBeam) 198 _currentJets = _measureFunction->get_partition(inputJets,_currentAxes,&_currentBeam); 199 200 // Find tau value and store information 201 _current_tau_components = _measureFunction->result_from_partition(_currentJets, _currentAxes,&_currentBeam); // sets current Tau Values 212 202 } 213 203 return _current_tau_components; … … 219 209 // Each vector element is a list of ints corresponding to the indices in 220 210 // particles of the particles belonging to that jet. 221 // TODO: Consider moving to MeasureFunction 222 std::vector<std::list<int> > Njettiness::getPartition(const std::vector<fastjet::PseudoJet> & particles) { 223 std::vector<std::list<int> > partitions(_currentAxes.size()); 224 225 for (unsigned i = 0; i < particles.size(); i++) { 226 227 int j_min = -1; 228 // find minimum distance 229 double minR = std::numeric_limits<double>::max(); //large number 230 for (unsigned j = 0; j < _currentAxes.size(); j++) { 231 double tempR = _measureFunction->jet_distance_squared(particles[i],_currentAxes[j]); // delta R distance 232 if (tempR < minR) { 233 minR = tempR; 234 j_min = j; 235 } 236 } 237 if (_measureFunction->do_cluster(particles[i],_currentAxes[j_min])) partitions[j_min].push_back(i); 238 } 239 return partitions; 240 } 241 242 // Having found axes, assign each particle in particles to an axis, and return a set of jets. 243 // Each jet is the sum of particles closest to an axis (Njet = Naxes). 244 // TODO: Consider moving to MeasureFunction 245 std::vector<fastjet::PseudoJet> Njettiness::getJets(const std::vector<fastjet::PseudoJet> & particles) { 246 247 std::vector<fastjet::PseudoJet> jets(_currentAxes.size()); 248 249 std::vector<std::list<int> > partition = getPartition(particles); 250 for (unsigned j = 0; j < partition.size(); ++j) { 251 std::list<int>::const_iterator it, itE; 252 for (it = partition[j].begin(), itE = partition[j].end(); it != itE; ++it) { 253 jets[j] += particles[*it]; 254 } 255 } 256 return jets; 257 } 258 211 std::vector<std::list<int> > Njettiness::getPartitionList(const std::vector<fastjet::PseudoJet> & particles) const { 212 // core code is in MeasureFunction 213 return _measureFunction->get_partition_list(particles,_currentAxes); 214 } 215 216 259 217 } // namespace contrib 260 218 -
external/fastjet/contribs/Nsubjettiness/Njettiness.hh
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: Njettiness.hh 670 2014-06-06 01:24:42Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 25 26 #define __FASTJET_CONTRIB_NJETTINESS_HH__ 26 27 28 27 29 #include "MeasureFunction.hh" 28 30 #include "AxesFinder.hh" 31 #include "NjettinessDefinition.hh" 29 32 30 33 #include "fastjet/PseudoJet.hh" 34 #include "fastjet/SharedPtr.hh" 35 #include <fastjet/LimitedWarning.hh> 36 31 37 #include <cmath> 32 38 #include <vector> 33 39 #include <list> 34 40 35 36 41 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 37 42 38 43 namespace contrib { 39 44 40 45 /////// 41 46 // … … 54 59 55 60 // The various axes choices available to the user 61 // It is recommended to use AxesDefinition instead of these. 56 62 enum AxesMode { 57 63 kt_axes, // exclusive kt axes … … 78 84 // "normalized_cutoff_measure" was the default in v1.0 of Nsubjettiness 79 85 // "unnormalized_measure" is now the recommended default usage 86 // But it is recommended to use MeasureDefinition instead of these. 80 87 enum MeasureMode { 81 88 normalized_measure, //default normalized measure … … 87 94 }; 88 95 89 private: 90 // The chosen axes/measure modes 91 AxesFinder* _axesFinder; // The chosen axes 92 MeasureFunction* _measureFunction; // The chosen measure 96 // Main constructor that uses AxesMode and MeasureDefinition to specify measure 97 // Unlike Nsubjettiness or NjettinessPlugin, the value N is not chosen 98 Njettiness(const AxesDefinition & axes_def, const MeasureDefinition & measure_def); 93 99 94 // Enum information so functions can specify output based on specific options, primarily for setAxes 95 AxesMode _current_axes_mode; 96 MeasureMode _current_measure_mode; 97 98 // Information about the current information 99 TauComponents _current_tau_components; //automatically set to have components of 0; these values will be set by the getTau function call 100 std::vector<fastjet::PseudoJet> _currentAxes; 101 std::vector<fastjet::PseudoJet> _seedAxes; // axes used prior to minimization (if applicable) 102 103 // Needed for compilation of non C++11 users 104 bool isnan(double para) { return para != para; } 100 // Intermediate constructor (needed to enable v1.0.3 backwards compatibility?) 101 Njettiness(AxesMode axes_mode, const MeasureDefinition & measure_def); 105 102 106 // Helpful function to check to make sure input has correct number of parameters 107 bool correctParameterCount(int n, double para1, double para2, double para3, double para4){ 108 int numpara; 109 if (!isnan(para1) && !isnan(para2) && !isnan(para3) && !isnan(para4)) numpara = 4; 110 else if (!isnan(para1) && !isnan(para2) && !isnan(para3) && isnan(para4)) numpara = 3; 111 else if (!isnan(para1) && !isnan(para2) && isnan(para3) && isnan(para4)) numpara = 2; 112 else if (!isnan(para1) && isnan(para2) && isnan(para3) && isnan(para4)) numpara = 1; 113 else numpara = 0; 114 return n == numpara; 103 // Alternative constructor which takes axes/measure information as enums with measure parameters 104 // This version is not recommended 105 Njettiness(AxesMode axes_mode, 106 MeasureMode measure_mode, 107 int num_para, 108 double para1 = std::numeric_limits<double>::quiet_NaN(), 109 double para2 = std::numeric_limits<double>::quiet_NaN(), 110 double para3 = std::numeric_limits<double>::quiet_NaN()) 111 : _axes_def(createAxesDef(axes_mode)), _measure_def(createMeasureDef(measure_mode, num_para, para1, para2, para3)) { 112 setMeasureFunctionAndAxesFinder(); // call helper function to do the hard work 115 113 } 116 114 117 // Helper function to set onepass_axes depending on input measure_mode and startingFinder 118 void setOnePassAxesFinder(MeasureMode measure_mode, AxesFinder* startingFinder, double para1, double Rcutoff); 119 120 // created separate function to set MeasureFunction and AxesFinder in order to keep constructor cleaner. 121 void setMeasureFunctionandAxesFinder(AxesMode axes_mode, MeasureMode measure_mode, double para1, double para2, double para3, double para4); 122 123 public: 124 125 126 // Main constructor which takes axes/measure information, and possible parameters. 127 // Unlike Nsubjettiness or NjettinessPlugin, the value N is not chosen 128 Njettiness(AxesMode axes_mode, 129 MeasureMode measure_mode, 130 double para1 = NAN, 131 double para2 = NAN, 132 double para3 = NAN, 133 double para4 = NAN) 134 : _current_axes_mode(axes_mode), 135 _current_measure_mode(measure_mode) { 136 setMeasureFunctionandAxesFinder(axes_mode, measure_mode, para1, para2, para3, para4); // call helper function to do the hard work 137 } 138 139 ~Njettiness() { 140 // clean house 141 delete _measureFunction; 142 delete _axesFinder; 143 } 115 // destructor 116 ~Njettiness() {}; 144 117 145 118 // setAxes for Manual mode 146 void setAxes( std::vector<fastjet::PseudoJet>myAxes);119 void setAxes(const std::vector<fastjet::PseudoJet> & myAxes); 147 120 148 121 // Calculates and returns all TauComponents that user would want. 149 122 // This information is stored in _current_tau_components for later access as well. 150 TauComponents getTauComponents(unsigned n_jets, const std::vector<fastjet::PseudoJet> & inputJets) ;123 TauComponents getTauComponents(unsigned n_jets, const std::vector<fastjet::PseudoJet> & inputJets) const; 151 124 152 125 // Calculates the value of N-subjettiness, 153 126 // but only returns the tau value from _current_tau_components 154 double getTau(unsigned n_jets, const std::vector<fastjet::PseudoJet> & inputJets) {127 double getTau(unsigned n_jets, const std::vector<fastjet::PseudoJet> & inputJets) const { 155 128 return getTauComponents(n_jets, inputJets).tau(); 156 129 } 157 158 // returns enum information159 MeasureMode currentMeasureMode() { return _current_measure_mode;}160 AxesMode currentAxesMode() { return _current_axes_mode;}161 130 162 131 // Return all relevant information about tau components 163 TauComponents currentTauComponents() {return _current_tau_components;} 164 132 TauComponents currentTauComponents() const {return _current_tau_components;} 165 133 // Return axes found by getTauComponents. 166 std::vector<fastjet::PseudoJet> currentAxes() { return _currentAxes;}134 std::vector<fastjet::PseudoJet> currentAxes() const { return _currentAxes;} 167 135 // Return seedAxes used if onepass minimization (otherwise, same as currentAxes) 168 std::vector<fastjet::PseudoJet> seedAxes() { return _seedAxes;} 136 std::vector<fastjet::PseudoJet> seedAxes() const { return _seedAxes;} 137 // Return jet partition found by getTauComponents. 138 std::vector<fastjet::PseudoJet> currentJets() const {return _currentJets;} 139 // Return beam partition found by getTauComponents. 140 fastjet::PseudoJet currentBeam() const {return _currentBeam;} 169 141 170 142 // partition inputs by Voronoi (each vector stores indices corresponding to inputJets) 171 std::vector<std::list<int> > getPartition (const std::vector<fastjet::PseudoJet> & inputJets);143 std::vector<std::list<int> > getPartitionList(const std::vector<fastjet::PseudoJet> & inputJets) const; 172 144 173 // partition inputs by Voronoi 174 std::vector<fastjet::PseudoJet> getJets(const std::vector<fastjet::PseudoJet> & inputJets); 145 private: 146 147 // Information about Axes and Measures to be Used 148 // Implemented as SharedPtrs to avoid memory management headaches 149 SharedPtr<const AxesDefinition> _axes_def; 150 SharedPtr<const MeasureDefinition> _measure_def; 151 152 // The chosen axes/measure mode workers 153 // Implemented as SharedPtrs to avoid memory management headaches 154 // TODO: make into a SharedPtr<const AxesFinder>? 155 SharedPtr<MeasureFunction> _measureFunction; // The chosen measure 156 SharedPtr<AxesFinder> _startingAxesFinder; // The initial axes finder 157 SharedPtr<AxesFinder> _finishingAxesFinder; // A possible minimization step 158 159 // Information about the current information 160 // Defined as mutables, so user should be aware that these change when getTau is called. 161 mutable TauComponents _current_tau_components; //automatically set to have components of 0; these values will be set by the getTau function call 162 mutable std::vector<fastjet::PseudoJet> _currentAxes; //axes found after minimization 163 mutable std::vector<fastjet::PseudoJet> _seedAxes; // axes used prior to minimization (if applicable) 164 mutable std::vector<fastjet::PseudoJet> _currentJets; //partitioning information 165 mutable fastjet::PseudoJet _currentBeam; //return beam, if requested 166 167 // created separate function to set MeasureFunction and AxesFinder in order to keep constructor cleaner. 168 void setMeasureFunctionAndAxesFinder(); 169 170 // Convert old style enums into new style MeasureDefinition 171 AxesDefinition* createAxesDef(AxesMode axes_mode) const; 172 173 // Convert old style enums into new style MeasureDefinition 174 MeasureDefinition* createMeasureDef(MeasureMode measure_mode, int num_para, double para1, double para2, double para3) const; 175 175 176 176 }; 177 177 178 178 } // namespace contrib 179 179 -
external/fastjet/contribs/Nsubjettiness/NjettinessPlugin.cc
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: NjettinessPlugin.cc 663 2014-06-03 21:26:41Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 29 30 30 31 31 // Constructor with same arguments as Nsubjettiness.32 NjettinessPlugin::NjettinessPlugin(int N, Njettiness::AxesMode axes_mode, Njettiness::MeasureMode measure_mode, double para1, double para2, double para3, double para4)33 : _N(N), _njettinessFinder(axes_mode, measure_mode, para1, para2, para3, para4) {}34 35 // Old constructor for compatibility36 NjettinessPlugin::NjettinessPlugin(int N, Njettiness::AxesMode mode, double beta, double R0, double Rcutoff)37 : _N(N), _njettinessFinder(mode, Njettiness::normalized_cutoff_measure, beta, R0, Rcutoff) {}38 32 39 33 std::string NjettinessPlugin::description() const {return "N-jettiness jet finder";} 40 34 35 41 36 // Clusters the particles according to the Njettiness jet algorithm 42 // TODO: this code should be revisited to see if if can be made more clear. 37 // Apologies for the complication with this code, but we need to make 38 // a fake jet clustering tree. The partitioning is done by getPartitionList 43 39 void NjettinessPlugin::run_clustering(ClusterSequence& cs) const 44 40 { 45 41 std::vector<fastjet::PseudoJet> particles = cs.jets(); 42 43 // HACK: remove area information from particles (in case this is called by 44 // a ClusterSequenceArea. Will be fixed in a future FastJet release) 45 for (unsigned i = 0; i < particles.size(); i++) { 46 particles[i].set_structure_shared_ptr(SharedPtr<PseudoJetStructureBase>()); 47 } 48 49 46 50 _njettinessFinder.getTau(_N, particles); 47 std::vector<std::list<int> > partition = _njettinessFinder.getPartition(particles); 51 52 std::vector<std::list<int> > partition = _njettinessFinder.getPartitionList(particles); 48 53 49 54 std::vector<fastjet::PseudoJet> jet_indices_for_extras; 50 55 51 56 // output clusterings for each jet 52 for (size_t i = 0; i < partition.size(); ++i) { 57 for (size_t i0 = 0; i0 < partition.size(); ++i0) { 58 size_t i = partition.size() - 1 - i0; // reversed order of reading to match axes order 53 59 std::list<int>& indices = partition[i]; 54 60 if (indices.size() == 0) continue; … … 70 76 } 71 77 78 //HACK: Re-reverse order of reading to match CS order 79 reverse(jet_indices_for_extras.begin(),jet_indices_for_extras.end()); 80 72 81 NjettinessExtras * extras = new NjettinessExtras(_njettinessFinder.currentTauComponents(),jet_indices_for_extras,_njettinessFinder.currentAxes()); 73 82 cs.plugin_associate_extras(std::auto_ptr<ClusterSequence::Extras>(extras)); -
external/fastjet/contribs/Nsubjettiness/NjettinessPlugin.hh
r5b5a56b r35cdc46 1 // $Id$2 //3 1 // Nsubjettiness Package 4 2 // Questions/Comments? jthaler@jthaler.net … … 7 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 8 6 // 7 // $Id: NjettinessPlugin.hh 671 2014-06-10 17:47:52Z jthaler $ 9 8 //---------------------------------------------------------------------- 10 9 // This file is part of FastJet contrib. … … 49 48 // to similar information 50 49 class NjettinessExtras : public ClusterSequence::Extras { 51 private: 52 53 TauComponents _tau_components; 54 std::vector<fastjet::PseudoJet> _jets; 55 std::vector<fastjet::PseudoJet> _axes; 56 57 int labelOf(const fastjet::PseudoJet& jet) const { 58 int thisJet = -1; 59 for (unsigned int i = 0; i < _jets.size(); i++) { 60 if (_jets[i].cluster_hist_index() == jet.cluster_hist_index()) { 61 thisJet = i; 62 break; 63 } 64 } 65 return thisJet; 66 } 67 50 68 51 public: 69 52 NjettinessExtras(TauComponents tau_components, std::vector<fastjet::PseudoJet> jets, std::vector<fastjet::PseudoJet> axes) : _tau_components(tau_components), _jets(jets), _axes(axes) {} … … 74 57 std::vector<fastjet::PseudoJet> axes() const {return _axes;} 75 58 76 double totalTau(const fastjet::PseudoJet& jet) const {59 double totalTau(const fastjet::PseudoJet& /*jet*/) const { 77 60 return _tau_components.tau(); 78 61 } 62 79 63 double subTau(const fastjet::PseudoJet& jet) const { 80 if (labelOf(jet) == -1) return NAN;64 if (labelOf(jet) == -1) return std::numeric_limits<double>::quiet_NaN(); // nonsense 81 65 return _tau_components.jet_pieces()[labelOf(jet)]; 82 66 } … … 93 77 return (labelOf(jet) >= 0); 94 78 } 95 79 80 private: 81 82 TauComponents _tau_components; 83 std::vector<fastjet::PseudoJet> _jets; 84 std::vector<fastjet::PseudoJet> _axes; 85 86 int labelOf(const fastjet::PseudoJet& jet) const { 87 int thisJet = -1; 88 for (unsigned int i = 0; i < _jets.size(); i++) { 89 if (_jets[i].cluster_hist_index() == jet.cluster_hist_index()) { 90 thisJet = i; 91 break; 92 } 93 } 94 return thisJet; 95 } 96 96 }; 97 97 … … 122 122 * onepass_wta_kt_axes : one-pass minimization seeded by wta_kt 123 123 * 124 * For the unnormalized_measure, N-jettiness is defined as:124 * For the UnnormalizedMeasure(beta), N-jettiness is defined as: 125 125 * 126 126 * tau_N = Sum_{all particles i} p_T^i min((DR_i1)^beta, (DR_i2)^beta, ...) … … 129 129 * and jet j. 130 130 * 131 * The normalized_meausure include an extra parameter R0, and the various cutoff131 * The NormalizedMeausure include an extra parameter R0, and the various cutoff 132 132 * measures include an Rcutoff, which effectively defines an angular cutoff 133 133 * similar in effect to a cone-jet radius. … … 138 138 public: 139 139 140 NjettinessPlugin(int N, 141 Njettiness::AxesMode axes_mode, 142 Njettiness::MeasureMode measure_mode, 143 double para1 = NAN, 144 double para2 = NAN, 145 double para3 = NAN, 146 double para4 = NAN); 140 // Constructor with same arguments as Nsubjettiness. 141 NjettinessPlugin(int N, 142 const AxesDefinition & axes_def, 143 const MeasureDefinition & measure_def) 144 : _njettinessFinder(axes_def, measure_def), _N(N) {} 145 146 147 // Alternative constructors that define the measure via enums and parameters 148 // These constructors are likely be removed 149 NjettinessPlugin(int N, 150 Njettiness::AxesMode axes_mode, 151 Njettiness::MeasureMode measure_mode) 152 : _njettinessFinder(axes_mode, measure_mode, 0), _N(N) {} 153 154 155 NjettinessPlugin(int N, 156 Njettiness::AxesMode axes_mode, 157 Njettiness::MeasureMode measure_mode, 158 double para1) 159 : _njettinessFinder(axes_mode, measure_mode, 1, para1), _N(N) {} 160 161 162 NjettinessPlugin(int N, 163 Njettiness::AxesMode axes_mode, 164 Njettiness::MeasureMode measure_mode, 165 double para1, 166 double para2) 167 : _njettinessFinder(axes_mode, measure_mode, 2, para1, para2), _N(N) {} 168 169 170 NjettinessPlugin(int N, 171 Njettiness::AxesMode axes_mode, 172 Njettiness::MeasureMode measure_mode, 173 double para1, 174 double para2, 175 double para3) 176 : _njettinessFinder(axes_mode, measure_mode, 3, para1, para2, para3), _N(N) {} 177 147 178 148 179 // Old constructor for backwards compatibility with v1.0, 149 // where normalized_cutoff_measure was the only option180 // where NormalizedCutoffMeasure was the only option 150 181 NjettinessPlugin(int N, 151 182 Njettiness::AxesMode mode, 152 183 double beta, 153 184 double R0, 154 double Rcutoff=std::numeric_limits<double>::max()); 185 double Rcutoff=std::numeric_limits<double>::max()) 186 : _njettinessFinder(mode, NormalizedCutoffMeasure(beta, R0, Rcutoff)), _N(N) {} 187 155 188 156 189 … … 164 197 private: 165 198 199 Njettiness _njettinessFinder; 166 200 int _N; 167 mutable Njettiness _njettinessFinder; // TODO: should muck with this so run_clustering can be const without this mutable168 201 169 202 }; -
external/fastjet/contribs/Nsubjettiness/Nsubjettiness.cc
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: Nsubjettiness.cc 597 2014-04-16 23:07:55Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. -
external/fastjet/contribs/Nsubjettiness/Nsubjettiness.hh
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: Nsubjettiness.hh 670 2014-06-06 01:24:42Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 32 33 #include <string> 33 34 #include <climits> 34 35 35 36 36 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh … … 49 49 public: 50 50 51 // Main constructor, which takes N, axes/measure modes, 52 // and up to four parameters for parameters (i.e. beta, Rcutoff, etc depending on measure) 51 52 // Main constructor, which takes N, the AxesDefiniation, and the MeasureDefinition. 53 // The Definitions are given in NjettinessDefinition.hh 54 // 55 // The recommended AxesDefinitions are (more are available as listed in the README 56 // and defined in NjettinessDefinition.hh): 57 // KT_Axes : exclusive kt axes 58 // WTA_KT_Axes : exclusive kt with winner-take-all recombination 59 // OnePass_KT_Axes : one-pass minimization from kt starting point 60 // OnePass_WTA_KT_Axes : one-pass min. from wta_kt starting point 61 // 62 // The recommended measure definitions are (with the corresponding parameters) 63 // NormalizedMeasure(beta,R0) 64 // : This was the original N-subjettiness measure (dimensionless) 65 // UnnormalizedMeasure(beta) 66 // : This is the new recommended default, same as above but without 67 // : the normalization factor, and hence has units of GeV 68 // NormalizedCutoffMeasure(beta,R0,Rcutoff) 69 // : Same as normalized_measure, but cuts off at Rcutoff 70 // UnnormalizedCutoffMeasure(beta,Rcutoff) 71 // : Same as unnormalized_measure, but cuts off at Rcutoff 72 Nsubjettiness(int N, 73 const AxesDefinition& axes_def, 74 const MeasureDefinition& measure_def) 75 : _njettinessFinder(axes_def,measure_def), _N(N) {} 76 77 78 // Alternative constructors that define the measure via enums and parameters 79 // These constructors are likely be removed 80 // Zero parameter arguments 81 // (Currently, no measure uses this) 82 Nsubjettiness(int N, 83 Njettiness::AxesMode axes_mode, 84 Njettiness::MeasureMode measure_mode) 85 : _njettinessFinder(axes_mode, measure_mode, 0), _N(N) {} 86 87 // One parameter argument 88 // (for unnormalized_measure, para1=beta) 53 89 Nsubjettiness(int N, 54 90 Njettiness::AxesMode axes_mode, 55 91 Njettiness::MeasureMode measure_mode, 56 double para1 = NAN, 57 double para2 = NAN, 58 double para3 = NAN, 59 double para4 = NAN) 60 : _njettinessFinder(axes_mode, measure_mode, para1, para2, para3, para4), _N(N) {} 92 double para1) 93 : _njettinessFinder(axes_mode, measure_mode, 1, para1), _N(N) {} 94 95 // Two parameter arguments 96 // (for normalized_measure, para1=beta, para2=R0) 97 // (for unnormalized_cutoff_measure, para1=beta, para2=Rcutoff) 98 Nsubjettiness(int N, 99 Njettiness::AxesMode axes_mode, 100 Njettiness::MeasureMode measure_mode, 101 double para1, 102 double para2) 103 : _njettinessFinder(axes_mode, measure_mode, 2, para1, para2), _N(N) {} 104 105 // Three parameter arguments 106 // (for unnormalized_cutoff_measure, para1=beta, para2=R0, para3=Rcutoff) 107 Nsubjettiness(int N, 108 Njettiness::AxesMode axes_mode, 109 Njettiness::MeasureMode measure_mode, 110 double para1, 111 double para2, 112 double para3) 113 : _njettinessFinder(axes_mode, measure_mode, 3, para1, para2, para3), _N(N) {} 61 114 62 115 // Old constructor for backwards compatibility with v1.0, … … 67 120 double R0, 68 121 double Rcutoff=std::numeric_limits<double>::max()) 69 : _njettinessFinder(axes_mode, Njettiness::normalized_cutoff_measure, beta, R0, Rcutoff), _N(N) {} 70 71 122 : _njettinessFinder(axes_mode, NormalizedCutoffMeasure(beta,R0,Rcutoff)), _N(N) {} 123 72 124 /// returns tau_N, measured on the constituents of this jet 73 125 double result(const PseudoJet& jet) const; … … 86 138 } 87 139 140 /// returns subjet regions found by result() calculation (these have valid constituents) 141 /// Note that the axes and the subjets are not the same 142 std::vector<fastjet::PseudoJet> currentSubjets() const { 143 return _njettinessFinder.currentJets(); 144 } 145 146 /// returns components of tau_N without recalculating anything 147 TauComponents currentTauComponents() const { 148 return _njettinessFinder.currentTauComponents(); 149 } 150 88 151 // To set axes for manual use 89 void setAxes( std::vector<fastjet::PseudoJet>myAxes) {152 void setAxes(const std::vector<fastjet::PseudoJet> & myAxes) { 90 153 // Cross check that manual axes are being used is in Njettiness 91 154 _njettinessFinder.setAxes(myAxes); … … 95 158 private: 96 159 97 mutableNjettiness _njettinessFinder; // TODO: should muck with this so result can be const without this mutable160 Njettiness _njettinessFinder; // TODO: should muck with this so result can be const without this mutable 98 161 int _N; 99 162 … … 112 175 NsubjettinessRatio(int N, 113 176 int M, 177 const AxesDefinition & axes_def, 178 const MeasureDefinition & measure_def) 179 : _nsub_numerator(N,axes_def,measure_def), 180 _nsub_denominator(M,axes_def,measure_def) {} 181 182 // Alternative constructor with enums and parameters 183 // Again, likely to be removed 184 NsubjettinessRatio(int N, 185 int M, 186 Njettiness::AxesMode axes_mode, 187 Njettiness::MeasureMode measure_mode) 188 : _nsub_numerator(N, axes_mode, measure_mode), 189 _nsub_denominator(M, axes_mode, measure_mode) {} 190 191 192 NsubjettinessRatio(int N, 193 int M, 114 194 Njettiness::AxesMode axes_mode, 115 195 Njettiness::MeasureMode measure_mode, 116 double para1 = NAN, 117 double para2 = NAN, 118 double para3 = NAN, 119 double para4 = NAN) 120 : _nsub_numerator(N, axes_mode, measure_mode, para1, para2, para3, para4), 121 _nsub_denominator(M, axes_mode, measure_mode, para1, para2, para3, para4) {} 122 123 //returns tau_N/tau_M based off the input jet using result function from Nsubjettiness 196 double para1) 197 : _nsub_numerator(N, axes_mode, measure_mode, para1), 198 _nsub_denominator(M, axes_mode, measure_mode, para1) {} 199 200 NsubjettinessRatio(int N, 201 int M, 202 Njettiness::AxesMode axes_mode, 203 Njettiness::MeasureMode measure_mode, 204 double para1, 205 double para2) 206 : _nsub_numerator(N, axes_mode, measure_mode, para1, para2), 207 _nsub_denominator(M, axes_mode, measure_mode, para1, para2) {} 208 209 NsubjettinessRatio(int N, 210 int M, 211 Njettiness::AxesMode axes_mode, 212 Njettiness::MeasureMode measure_mode, 213 double para1, 214 double para2, 215 double para3) 216 : _nsub_numerator(N, axes_mode, measure_mode, para1, para2, para3), 217 _nsub_denominator(M, axes_mode, measure_mode, para1, para2, para3) {} 218 219 //returns tau_N/tau_M based off the input jet using result function from Nsubjettiness 124 220 double result(const PseudoJet& jet) const; 125 221 -
external/fastjet/contribs/Nsubjettiness/VERSION
r5b5a56b r35cdc46 1 1.1.0-beta4 1 2.1.0 -
external/fastjet/contribs/Nsubjettiness/WinnerTakeAllRecombiner.cc
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: WinnerTakeAllRecombiner.cc 597 2014-04-16 23:07:55Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 33 34 34 35 // recombine pa and pb by creating pab with energy of the sum of particle energies in the direction of the harder particle 35 36 36 // updated recombiner to use more general form of a metric equal to E*(pT/E)^(alpha), which reduces to pT*cosh(rap)^(1-alpha) 37 37 // alpha is specified by the user. The default is alpha = 1, which is the typical behavior. alpha = 2 provides a metric which more -
external/fastjet/contribs/Nsubjettiness/WinnerTakeAllRecombiner.hh
r5b5a56b r35cdc46 5 5 // Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason 6 6 // 7 // $Id: WinnerTakeAllRecombiner.hh 670 2014-06-06 01:24:42Z jthaler $ 7 8 //---------------------------------------------------------------------- 8 9 // This file is part of FastJet contrib. … … 50 51 51 52 /// recombine pa and pb and put result into pab 52 virtual void recombine(const fastjet::PseudoJet & pa, const fastjet::PseudoJet & pb, fastjet::PseudoJet & pab) const; 53 virtual void recombine(const fastjet::PseudoJet & pa, 54 const fastjet::PseudoJet & pb, 55 fastjet::PseudoJet & pab) const; 53 56 54 57 private:
Note:
See TracChangeset
for help on using the changeset viewer.