fastjet 2.4.5
|
00001 //STARTHEADER 00002 // $Id: PseudoJet.hh 1510 2009-04-13 08:48:41Z salam $ 00003 // 00004 // Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam 00005 // 00006 //---------------------------------------------------------------------- 00007 // This file is part of FastJet. 00008 // 00009 // FastJet is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 2 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // The algorithms that underlie FastJet have required considerable 00015 // development and are described in hep-ph/0512210. If you use 00016 // FastJet as part of work towards a scientific publication, please 00017 // include a citation to the FastJet paper. 00018 // 00019 // FastJet is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with FastJet; if not, write to the Free Software 00026 // Foundation, Inc.: 00027 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 //---------------------------------------------------------------------- 00029 //ENDHEADER 00030 00031 00032 #ifndef __FASTJET_PSEUDOJET_HH__ 00033 #define __FASTJET_PSEUDOJET_HH__ 00034 00035 #include<valarray> 00036 #include<vector> 00037 #include<cassert> 00038 #include<cmath> 00039 #include<iostream> 00040 #include "fastjet/internal/numconsts.hh" 00041 00042 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 00043 00044 //using namespace std; 00045 00048 const double MaxRap = 1e5; 00049 00052 class PseudoJet { 00053 00054 public: 00055 PseudoJet() {}; 00057 PseudoJet(const double px, const double py, const double pz, const double E); 00059 template <class L> PseudoJet(const L & some_four_vector) ; 00060 00061 // first "const double &" says that result is a reference to the 00062 // stored value and that we will not change that stored value. 00063 // 00064 // second "const" says that "this" will not be modified by these 00065 // functions. 00066 inline double E() const {return _E;} 00067 inline double e() const {return _E;} // like CLHEP 00068 inline double px() const {return _px;} 00069 inline double py() const {return _py;} 00070 inline double pz() const {return _pz;} 00071 00073 inline double phi() const {return phi_02pi();} 00074 00076 inline double phi_std() const { 00077 return _phi > pi ? _phi-twopi : _phi;} 00078 00080 inline double phi_02pi() const {return _phi;} 00081 00084 inline double rap() const {return _rap;} 00085 00087 inline double rapidity() const {return _rap;} // like CLHEP 00088 00091 double pseudorapidity() const; 00092 double eta() const {return pseudorapidity();} 00093 00095 inline double kt2() const {return _kt2;} 00097 inline double perp2() const {return _kt2;} // like CLHEP 00099 inline double perp() const {return sqrt(_kt2);} // like CLHEP 00101 inline double m2() const {return (_E+_pz)*(_E-_pz)-_kt2;} 00103 inline double mperp2() const {return (_E+_pz)*(_E-_pz);} 00105 inline double mperp() const {return sqrt(std::abs(mperp2()));} 00108 inline double m() const; 00110 inline double modp2() const {return _kt2+_pz*_pz;} 00112 inline double Et() const {return (_kt2==0) ? 0.0 : _E/sqrt(1.0+_pz*_pz/_kt2);} 00114 inline double Et2() const {return (_kt2==0) ? 0.0 : _E*_E/(1.0+_pz*_pz/_kt2);} 00115 00117 double operator () (int i) const ; 00119 inline double operator [] (int i) const { return (*this)(i); }; // this too 00120 00121 00122 // taken from CLHEP 00123 enum { X=0, Y=1, Z=2, T=3, NUM_COORDINATES=4, SIZE=NUM_COORDINATES }; 00124 00125 00128 PseudoJet & boost(const PseudoJet & prest); 00131 PseudoJet & unboost(const PseudoJet & prest); 00132 00135 inline int cluster_hist_index() const {return _cluster_hist_index;} 00137 inline void set_cluster_hist_index(const int index) {_cluster_hist_index = index;} 00138 00140 inline int cluster_sequence_history_index() const { 00141 return cluster_hist_index();} 00144 inline void set_cluster_sequence_history_index(const int index) { 00145 set_cluster_hist_index(index);} 00146 00147 00149 inline int user_index() const {return _user_index;} 00151 inline void set_user_index(const int index) {_user_index = index;} 00152 00155 std::valarray<double> four_mom() const; 00156 00158 double kt_distance(const PseudoJet & other) const; 00159 00161 double plain_distance(const PseudoJet & other) const; 00164 inline double squared_distance(const PseudoJet & other) const { 00165 return plain_distance(other);} 00166 00169 double delta_phi_to(const PseudoJet & other) const; 00170 00172 //friend inline double 00173 // kt_distance(const PseudoJet & jet1, const PseudoJet & jet2) { 00174 // return jet1.kt_distance(jet2);} 00175 00177 inline double beam_distance() const {return _kt2;} 00178 00179 00180 void operator*=(double); 00181 void operator/=(double); 00182 void operator+=(const PseudoJet &); 00183 void operator-=(const PseudoJet &); 00184 00187 inline void reset(double px, double py, double pz, double E); 00188 00193 inline void reset(const PseudoJet & psjet) { 00194 (*this) = psjet; 00195 } 00196 00200 template <class L> inline void reset(const L & some_four_vector) { 00201 reset(some_four_vector[0], some_four_vector[1], 00202 some_four_vector[2], some_four_vector[3]); 00203 } 00204 00205 private: 00206 // NB: following order must be kept for things to behave sensibly... 00207 double _px,_py,_pz,_E; 00208 double _phi, _rap, _kt2; 00209 int _cluster_hist_index, _user_index; 00211 void _finish_init(); 00213 void _reset_indices(); 00214 00215 //vertex_type * vertex0, vertex1; 00216 }; 00217 00218 00219 //---------------------------------------------------------------------- 00220 // routines for basic binary operations 00221 00222 PseudoJet operator+(const PseudoJet &, const PseudoJet &); 00223 PseudoJet operator-(const PseudoJet &, const PseudoJet &); 00224 PseudoJet operator*(double, const PseudoJet &); 00225 PseudoJet operator*(const PseudoJet &, double); 00226 PseudoJet operator/(const PseudoJet &, double); 00227 00228 inline double dot_product(const PseudoJet & a, const PseudoJet & b) { 00229 return a.E()*b.E() - a.px()*b.px() - a.py()*b.py() - a.pz()*b.pz(); 00230 } 00231 00233 bool have_same_momentum(const PseudoJet &, const PseudoJet &); 00234 00236 PseudoJet PtYPhiM(double pt, double y, double phi, double m = 0.0); 00237 00238 //---------------------------------------------------------------------- 00239 // Routines to do with providing sorted arrays of vectors. 00240 00242 std::vector<PseudoJet> sorted_by_pt(const std::vector<PseudoJet> & jets); 00243 00245 std::vector<PseudoJet> sorted_by_rapidity(const std::vector<PseudoJet> & jets); 00246 00248 std::vector<PseudoJet> sorted_by_E(const std::vector<PseudoJet> & jets); 00249 00251 std::vector<PseudoJet> sorted_by_pz(const std::vector<PseudoJet> & jets); 00252 00253 //---------------------------------------------------------------------- 00254 // some code to help sorting 00255 00258 void sort_indices(std::vector<int> & indices, 00259 const std::vector<double> & values); 00260 00265 template<class T> std::vector<T> objects_sorted_by_values(const std::vector<T> & objects, 00266 const std::vector<double> & values); 00267 00269 class IndexedSortHelper { 00270 public: 00271 inline IndexedSortHelper (const std::vector<double> * reference_values) { 00272 _ref_values = reference_values; 00273 }; 00274 inline int operator() (const int & i1, const int & i2) const { 00275 return (*_ref_values)[i1] < (*_ref_values)[i2]; 00276 }; 00277 private: 00278 const std::vector<double> * _ref_values; 00279 }; 00280 00281 00282 //---------------------------------------------------------------------- 00284 // NB: do not know if it really needs to be inline, but when it wasn't 00285 // linking failed with g++ (who knows what was wrong...) 00286 template <class L> inline PseudoJet::PseudoJet(const L & some_four_vector) { 00287 00288 _px = some_four_vector[0]; 00289 _py = some_four_vector[1]; 00290 _pz = some_four_vector[2]; 00291 _E = some_four_vector[3]; 00292 _finish_init(); 00293 // some default values for these two indices 00294 _reset_indices(); 00295 } 00296 00297 00298 //---------------------------------------------------------------------- 00299 inline void PseudoJet::_reset_indices() { 00300 set_cluster_hist_index(-1); 00301 set_user_index(-1); 00302 } 00303 00304 //---------------------------------------------------------------------- 00308 // template<> inline void PseudoJet::reset<PseudoJet>(const PseudoJet & psjet) { 00309 // (*this) = psjet; 00310 // } 00311 00319 00320 // taken literally from CLHEP 00321 inline double PseudoJet::m() const { 00322 double mm = m2(); 00323 return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm); 00324 } 00325 00326 00327 inline void PseudoJet::reset(double px, double py, double pz, double E) { 00328 _px = px; 00329 _py = py; 00330 _pz = pz; 00331 _E = E; 00332 _finish_init(); 00333 _reset_indices(); 00334 } 00335 00336 00337 FASTJET_END_NAMESPACE 00338 00339 #endif // __FASTJET_PSEUDOJET_HH__