FastJet 3.0beta1
|
00001 //STARTHEADER 00002 // $Id: PseudoJet.hh 2521 2011-08-08 15:25:15Z salam $ 00003 // 00004 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin Salam and Gregory Soyez 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 #include "fastjet/internal/IsBase.hh" 00042 #include "fastjet/SharedPtr.hh" 00043 #include "fastjet/Error.hh" 00044 #include "fastjet/PseudoJetStructureBase.hh" 00045 00046 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 00047 00048 //using namespace std; 00049 00050 /// Used to protect against parton-level events where pt can be zero 00051 /// for some partons, giving rapidity=infinity. KtJet fails in those cases. 00052 const double MaxRap = 1e5; 00053 00054 /// default value for phi, meaning it (and rapidity) have yet to be calculated) 00055 const double pseudojet_invalid_phi = -100.0; 00056 00057 // forward definition 00058 class ClusterSequenceAreaBase; 00059 00060 /// @ingroup basic_classes 00061 /// \class PseudoJet 00062 /// Class to contain pseudojets, including minimal information of use to 00063 /// jet-clustering routines. 00064 class PseudoJet { 00065 00066 public: 00067 //---------------------------------------------------------------------- 00068 /// @name Constructors and destructor 00069 //\{ 00070 /// default constructor, which as of FJ3.0 provides an object for 00071 /// which all operations are now valid and which has zero momentum 00072 /// 00073 // (cf. this is actually OK from a timing point of view and in some 00074 // cases better than just having the default constructor for the 00075 // internal shared pointer: see PJtiming.cc and the notes therein) 00076 PseudoJet() : _px(0), _py(0), _pz(0), _E(0) {_finish_init(); _reset_indices();} 00077 /// construct a pseudojet from explicit components 00078 PseudoJet(const double px, const double py, const double pz, const double E); 00079 00080 /// constructor from any object that has px,py,pz,E = some_four_vector[0--3], 00081 template <class L> PseudoJet(const L & some_four_vector); 00082 00083 // Constructor that performs minimal initialisation (only that of 00084 // the shared pointers), of use in certain speed-critical contexts 00085 PseudoJet(bool dummy) {} 00086 00087 /// default (virtual) destructor 00088 virtual ~PseudoJet(){}; 00089 //\} ---- end of constructors and destructors -------------------------- 00090 00091 //---------------------------------------------------------------------- 00092 /// @name Kinematic access functions 00093 //\{ 00094 //---------------------------------------------------------------------- 00095 inline double E() const {return _E;} 00096 inline double e() const {return _E;} // like CLHEP 00097 inline double px() const {return _px;} 00098 inline double py() const {return _py;} 00099 inline double pz() const {return _pz;} 00100 00101 /// returns phi (in the range 0..2pi) 00102 inline double phi() const {return phi_02pi();} 00103 00104 /// returns phi in the range -pi..pi 00105 inline double phi_std() const { 00106 _ensure_valid_rap_phi(); 00107 return _phi > pi ? _phi-twopi : _phi;} 00108 00109 /// returns phi in the range 0..2pi 00110 inline double phi_02pi() const { 00111 _ensure_valid_rap_phi(); 00112 return _phi; 00113 } 00114 00115 /// returns the rapidity or some large value when the rapidity 00116 /// is infinite 00117 inline double rap() const { 00118 _ensure_valid_rap_phi(); 00119 return _rap; 00120 } 00121 00122 /// the same as rap() 00123 inline double rapidity() const {return rap();} // like CLHEP 00124 00125 /// returns the pseudo-rapidity or some large value when the 00126 /// rapidity is infinite 00127 double pseudorapidity() const; 00128 double eta() const {return pseudorapidity();} 00129 00130 /// returns the squared transverse momentum 00131 inline double kt2() const {return _kt2;} 00132 /// returns the squared transverse momentum 00133 inline double perp2() const {return _kt2;} // like CLHEP 00134 /// returns the scalar transverse momentum 00135 inline double perp() const {return sqrt(_kt2);} // like CLHEP 00136 /// returns the squared invariant mass // like CLHEP 00137 inline double m2() const {return (_E+_pz)*(_E-_pz)-_kt2;} 00138 /// returns the squared transverse mass = kt^2+m^2 00139 inline double mperp2() const {return (_E+_pz)*(_E-_pz);} 00140 /// returns the transverse mass = sqrt(kt^2+m^2) 00141 inline double mperp() const {return sqrt(std::abs(mperp2()));} 00142 /// returns the invariant mass 00143 /// (If m2() is negative then -sqrt(-m2()) is returned, as in CLHEP) 00144 inline double m() const; 00145 /// return px^2+py^2+pz^2 00146 inline double modp2() const {return _kt2+_pz*_pz;} 00147 /// return the transverse energy 00148 inline double Et() const {return (_kt2==0) ? 0.0 : _E/sqrt(1.0+_pz*_pz/_kt2);} 00149 /// return the transverse energy squared 00150 inline double Et2() const {return (_kt2==0) ? 0.0 : _E*_E/(1.0+_pz*_pz/_kt2);} 00151 00152 /// returns component i, where X==0, Y==1, Z==2, E==3 00153 double operator () (int i) const ; 00154 /// returns component i, where X==0, Y==1, Z==2, E==3 00155 inline double operator [] (int i) const { return (*this)(i); }; // this too 00156 00157 00158 00159 /// returns kt distance (R=1) between this jet and another 00160 double kt_distance(const PseudoJet & other) const; 00161 00162 /// returns squared cylinder (rap-phi) distance between this jet and another 00163 double plain_distance(const PseudoJet & other) const; 00164 /// returns squared cylinder (rap-phi) distance between this jet and 00165 /// another 00166 inline double squared_distance(const PseudoJet & other) const { 00167 return plain_distance(other);} 00168 00169 /// return the cylinder (rap-phi) distance between this jet and another, 00170 /// \f$\Delta_R = \sqrt{\Delta y^2 + \Delta \phi^2}\f$. 00171 inline double delta_R(const PseudoJet & other) const { 00172 return sqrt(squared_distance(other)); 00173 } 00174 00175 /// returns other.phi() - this.phi(), constrained to be in 00176 /// range -pi .. pi 00177 double delta_phi_to(const PseudoJet & other) const; 00178 00179 //// this seemed to compile except if it was used 00180 //friend inline double 00181 // kt_distance(const PseudoJet & jet1, const PseudoJet & jet2) { 00182 // return jet1.kt_distance(jet2);} 00183 00184 /// returns distance between this jet and the beam 00185 inline double beam_distance() const {return _kt2;} 00186 00187 /// return a valarray containing the four-momentum (components 0-2 00188 /// are 3-mom, component 3 is energy). 00189 std::valarray<double> four_mom() const; 00190 00191 //\} ------- end of kinematic access functions 00192 00193 // taken from CLHEP 00194 enum { X=0, Y=1, Z=2, T=3, NUM_COORDINATES=4, SIZE=NUM_COORDINATES }; 00195 00196 00197 //---------------------------------------------------------------------- 00198 /// @name Kinematic modification functions 00199 //\{ 00200 //---------------------------------------------------------------------- 00201 /// transform this jet (given in the rest frame of prest) into a jet 00202 /// in the lab frame [NOT FULLY TESTED] 00203 PseudoJet & boost(const PseudoJet & prest); 00204 /// transform this jet (given in lab) into a jet in the rest 00205 /// frame of prest [NOT FULLY TESTED] 00206 PseudoJet & unboost(const PseudoJet & prest); 00207 00208 void operator*=(double); 00209 void operator/=(double); 00210 void operator+=(const PseudoJet &); 00211 void operator-=(const PseudoJet &); 00212 00213 /// reset the 4-momentum according to the supplied components and 00214 /// put the user and history indices back to their default values 00215 inline void reset(double px, double py, double pz, double E); 00216 00217 /// reset the PseudoJet to be equal to psjet (including its 00218 /// indices); NB if the argument is derived from a PseudoJet then 00219 /// the "reset" used will be the templated version 00220 /// 00221 /// Note: this is included on top of the templated version because 00222 /// PseudoJet is not "derived" from PseudoJet, so the templated 00223 /// reset would not handle this case properly. 00224 inline void reset(const PseudoJet & psjet) { 00225 (*this) = psjet; 00226 } 00227 00228 /// reset the 4-momentum according to the supplied generic 4-vector 00229 /// (accessible via indexing, [0]==px,...[3]==E) and put the user 00230 /// and history indices back to their default values. 00231 template <class L> inline void reset(const L & some_four_vector) { 00232 // check if some_four_vector can be cast to a PseudoJet 00233 // 00234 // Note that a regular dynamic_cast would not work here because 00235 // there is no guarantee that L is polymorphic. We use a more 00236 // complex construct here that works also in such a case. As for 00237 // dynamic_cast, NULL is returned if L is not derived from 00238 // PseudoJet 00239 const PseudoJet * pj = cast_if_derived<const PseudoJet>(&some_four_vector); 00240 00241 if (pj){ 00242 (*this) = *pj; 00243 } else { 00244 reset(some_four_vector[0], some_four_vector[1], 00245 some_four_vector[2], some_four_vector[3]); 00246 } 00247 } 00248 00249 /// reset the PseudoJet according to the specified pt, rapidity, 00250 /// azimuth and mass (also resetting indices, etc.) 00251 /// (phi should satisfy -2pi<phi<4pi) 00252 inline void reset_PtYPhiM(double pt, double y, double phi, double m=0.0) { 00253 reset_momentum_PtYPhiM(pt, y, phi, m); 00254 _reset_indices(); 00255 } 00256 00257 /// reset the 4-momentum according to the supplied components 00258 /// but leave all other information (indices, user info, etc.) 00259 /// untouched 00260 inline void reset_momentum(double px, double py, double pz, double E); 00261 00262 /// reset the 4-momentum according to the components of the supplied 00263 /// PseudoJet, including cached components; note that the template 00264 /// version (below) will be called for classes derived from PJ. 00265 inline void reset_momentum(const PseudoJet & pj); 00266 00267 /// reset the 4-momentum according to the specified pt, rapidity, 00268 /// azimuth and mass (phi should satisfy -2pi<phi<4pi) 00269 void reset_momentum_PtYPhiM(double pt, double y, double phi, double m=0.0); 00270 00271 /// reset the 4-momentum according to the supplied generic 4-vector 00272 /// (accessible via indexing, [0]==px,...[3]==E), but leave all 00273 /// other information (indices, user info, etc.) untouched 00274 template <class L> inline void reset_momentum(const L & some_four_vector) { 00275 reset_momentum(some_four_vector[0], some_four_vector[1], 00276 some_four_vector[2], some_four_vector[3]); 00277 } 00278 00279 /// in some cases when setting a 4-momentum, the user/program knows 00280 /// what rapidity and azimuth are associated with that 4-momentum; 00281 /// by calling this routine the user can provide the information 00282 /// directly to the PseudoJet and avoid expensive rap-phi 00283 /// recalculations. 00284 /// 00285 /// - \param rap rapidity 00286 /// - \param phi (in range -twopi...4*pi) 00287 /// 00288 /// USE WITH CAUTION: there are no checks that the rapidity and 00289 /// azimuth supplied are sensible, nor does this reset the 00290 /// 4-momentum components if things don't match. 00291 void set_cached_rap_phi(double rap, double phi); 00292 00293 00294 //\} --- end of kin mod functions ------------------------------------ 00295 00296 //---------------------------------------------------------------------- 00297 /// @name User index functions 00298 /// 00299 /// To allow the user to set and access an integer index which can 00300 /// be exploited by the user to associate extra information with a 00301 /// particle/jet (for example pdg id, or an indication of a 00302 /// particle's origin within the user's analysis) 00303 // 00304 //\{ 00305 00306 /// return the user_index, 00307 inline int user_index() const {return _user_index;} 00308 /// set the user_index, intended to allow the user to add simple 00309 /// identifying information to a particle/jet 00310 inline void set_user_index(const int index) {_user_index = index;} 00311 00312 //\} ----- end of use index functions --------------------------------- 00313 00314 //---------------------------------------------------------------------- 00315 /// @name User information types and functions 00316 /// 00317 /// Allows PseudoJet to carry extra user info (as an object derived from 00318 /// UserInfoBase). 00319 //\{ 00320 00321 /// @ingroup user_info 00322 /// \class UserInfoBase 00323 /// a base class to hold extra user information in a PseudoJet 00324 /// 00325 /// This is a base class to help associate extra user information 00326 /// with a jet. The user should store their information in a class 00327 /// derived from this. This allows information of arbitrary 00328 /// complexity to be easily associated with a PseudoJet (in contrast 00329 /// to the user index). For example, in a Monte Carlo simulation, 00330 /// the user information might include the PDG ID, and the position 00331 /// of the production vertex for the particle. 00332 /// 00333 /// The PseudoJet is able to store a shared pointer to any object 00334 /// derived from UserInfo. The use of a shared pointer frees the 00335 /// user of the need to handle the memory management associated with 00336 /// the information. 00337 /// 00338 /// Having the user information derive from a common base class also 00339 /// facilitates dynamic casting, etc. 00340 /// 00341 class UserInfoBase{ 00342 public: 00343 // dummy ctor 00344 UserInfoBase(){}; 00345 00346 // dummy virtual dtor 00347 // makes it polymorphic to allow for dynamic_cast 00348 virtual ~UserInfoBase(){}; 00349 }; 00350 00351 /// error class to be thrown if accessing user info when it doesn't 00352 /// exist 00353 class InexistentUserInfo : public Error { 00354 public: 00355 InexistentUserInfo(); 00356 }; 00357 00358 /// sets the internal shared pointer to the user information. 00359 /// 00360 /// Note that the PseudoJet will now _own_ the pointer, and delete 00361 /// the corresponding object when it (the jet, and any copies of the jet) 00362 /// goes out of scope. 00363 void set_user_info(UserInfoBase * user_info_in) { 00364 _user_info.reset(user_info_in); 00365 } 00366 00367 /// returns a reference to the dynamic cast conversion of user_info 00368 /// to type L. 00369 /// 00370 /// Usage: suppose you have previously set the user info with a pointer 00371 /// to an object of type MyInfo, 00372 /// 00373 /// class MyInfo: public PseudoJet::UserInfoBase { 00374 /// MyInfo(int id) : _pdg_id(id); 00375 /// int pdg_id() const {return _pdg_id;} 00376 /// int _pdg_id; 00377 /// }; 00378 /// 00379 /// PseudoJet particle(...); 00380 /// particle.set_user_info(new MyInfo(its_pdg_id)); 00381 /// 00382 /// Then you would access that pdg_id() as 00383 /// 00384 /// particle.user_info<MyInfo>().pdg_id(); 00385 /// 00386 /// It's overkill for just a single integer, but scales easily to 00387 /// more extensive information. 00388 /// 00389 /// Note that user_info() throws an InexistentUserInfo() error if 00390 /// there is no user info; throws a std::bad_cast if the conversion 00391 /// doesn't work 00392 /// 00393 /// If this behaviour does not fit your needs, use instead the the 00394 /// user_info_ptr() or user_info_shared_ptr() member functions. 00395 template<class L> 00396 const L & user_info() const{ 00397 if (_user_info.get() == 0) throw InexistentUserInfo(); 00398 return dynamic_cast<const L &>(* _user_info.get()); 00399 } 00400 00401 /// returns true if the PseudoJet has user information 00402 bool has_user_info() const{ 00403 return _user_info.get(); 00404 } 00405 00406 /// returns true if the PseudoJet has user information than can be 00407 /// cast to the template argument type. 00408 template<class L> 00409 bool has_user_info() const{ 00410 return _user_info.get() && dynamic_cast<const L *>(_user_info.get()); 00411 } 00412 00413 /// retrieve a pointer to the (const) user information 00414 const UserInfoBase * user_info_ptr() const{ 00415 if (!_user_info()) return NULL; 00416 return _user_info.get(); 00417 } 00418 00419 00420 /// retrieve a (const) shared pointer to the user information 00421 const SharedPtr<UserInfoBase> & user_info_shared_ptr() const{ 00422 return _user_info; 00423 } 00424 00425 /// retrieve a (non-const) shared pointer to the user information; 00426 /// you can use this, for example, to set the shared pointer, eg 00427 /// 00428 /// \code 00429 /// p2.user_info_shared_ptr() = p1.user_info_shared_ptr(); 00430 /// \endcode 00431 /// 00432 /// or 00433 /// 00434 /// \code 00435 /// SharedPtr<PseudoJet::UserInfoBase> info_shared(new MyInfo(...)); 00436 /// p2.user_info_shared_ptr() = info_shared; 00437 /// \endcode 00438 SharedPtr<UserInfoBase> & user_info_shared_ptr(){ 00439 return _user_info; 00440 } 00441 00442 // \} --- end of extra info functions --------------------------------- 00443 00444 //---------------------------------------------------------------------- 00445 /// @name Description 00446 /// 00447 /// Since a PseudoJet can have a structure that contains a variety 00448 /// of information, we provide a description that allows one to check 00449 /// exactly what kind of PseudoJet we are dealing with 00450 // 00451 //\{ 00452 00453 /// return a string describing what kind of PseudoJet we are dealing with 00454 std::string description() const; 00455 00456 //\} ----- end of description functions --------------------------------- 00457 00458 //------------------------------------------------------------- 00459 /// @name Access to the associated ClusterSequence object. 00460 /// 00461 /// In addition to having kinematic information, jets may contain a 00462 /// reference to an associated ClusterSequence (this is the case, 00463 /// for example, if the jet has been returned by a ClusterSequence 00464 /// member function). 00465 //\{ 00466 //------------------------------------------------------------- 00467 /// returns true if this PseudoJet has an associated ClusterSequence. 00468 bool has_associated_cluster_sequence() const; 00469 00470 /// returns true if this PseudoJet has an associated and still 00471 /// valid ClusterSequence. 00472 bool has_valid_cluster_sequence() const; 00473 00474 /// get a (const) pointer to the parent ClusterSequence (NULL if 00475 /// inexistent) 00476 const ClusterSequence* associated_cluster_sequence() const; 00477 00478 /// if the jet has a valid associated cluster sequence then return a 00479 /// pointer to it; otherwise throw an error 00480 const ClusterSequence * validated_cs() const; 00481 00482 /// if the jet has valid area information then return a pointer to 00483 /// the associated ClusterSequenceAreaBase object; otherwise throw an error 00484 const ClusterSequenceAreaBase * validated_csab() const; 00485 00486 //\} 00487 00488 //------------------------------------------------------------- 00489 /// @name Access to the associated PseudoJetStructureBase object. 00490 /// 00491 /// In addition to having kinematic information, jets may contain a 00492 /// reference to an associated ClusterSequence (this is the case, 00493 /// for example, if the jet has been returned by a ClusterSequence 00494 /// member function). 00495 //\{ 00496 //------------------------------------------------------------- 00497 00498 /// set the associated structure 00499 void set_structure_shared_ptr(const SharedPtr<PseudoJetStructureBase> &structure); 00500 00501 /// return true if there is some structure associated with this PseudoJet 00502 bool has_structure() const; 00503 00504 /// return a pointer to the structure (of type 00505 /// PseudoJetStructureBase*) associated with this PseudoJet. 00506 /// 00507 /// return NULL if there is no associated structure 00508 const PseudoJetStructureBase* structure_ptr() const; 00509 00510 /// return a non-const pointer to the structure (of type 00511 /// PseudoJetStructureBase*) associated with this PseudoJet. 00512 /// 00513 /// return NULL if there is no associated structure 00514 /// 00515 /// Only use this if you know what you are doing. In any case, 00516 /// prefer the 'structure_ptr()' (the const version) to this method, 00517 /// unless you really need a write access to the PseudoJet's 00518 /// underlying structure. 00519 PseudoJetStructureBase* structure_non_const_ptr(); 00520 00521 /// return a pointer to the structure (of type 00522 /// PseudoJetStructureBase*) associated with this PseudoJet. 00523 /// 00524 /// throw an error if there is no associated structure 00525 const PseudoJetStructureBase* validated_structure_ptr() const; 00526 00527 /// return a reference to the shared pointer to the 00528 /// PseudoJetStructureBase associated with this PseudoJet 00529 const SharedPtr<PseudoJetStructureBase> & structure_shared_ptr() const; 00530 00531 /// returns a reference to the structure casted to the requested 00532 /// structure type 00533 /// 00534 /// If there is no sructure associated, an Error is thrown. 00535 /// If the type is not met, a std::bad_cast error is thrown. 00536 template<typename StructureType> 00537 const StructureType & structure() const; 00538 00539 /// check if the PseudoJet has the structure resulting from a Transformer 00540 /// (that is, its structure is compatible with a Transformer::StructureType). 00541 /// If there is no structure, false is returned. 00542 template<typename TransformerType> 00543 bool has_structure_of() const; 00544 00545 /// this is a helper to access any structure created by a Transformer 00546 /// (that is, of type Transformer::StructureType). 00547 /// 00548 /// If there is no structure, or if the structure is not compatible 00549 /// with TransformerType, an error is thrown. 00550 template<typename TransformerType> 00551 const typename TransformerType::StructureType & structure_of() const; 00552 00553 //\} 00554 00555 //------------------------------------------------------------- 00556 /// @name Methods for access to information about jet structure 00557 /// 00558 /// These allow access to jet constituents, and other jet 00559 /// subtructure information. They only work if the jet is associated 00560 /// with a ClusterSequence. 00561 //------------------------------------------------------------- 00562 //\{ 00563 00564 /// check if it has been recombined with another PseudoJet in which 00565 /// case, return its partner through the argument. Otherwise, 00566 /// 'partner' is set to 0. 00567 /// 00568 /// an Error is thrown if this PseudoJet has no currently valid 00569 /// associated ClusterSequence 00570 virtual bool has_partner(PseudoJet &partner) const; 00571 00572 /// check if it has been recombined with another PseudoJet in which 00573 /// case, return its child through the argument. Otherwise, 'child' 00574 /// is set to 0. 00575 /// 00576 /// an Error is thrown if this PseudoJet has no currently valid 00577 /// associated ClusterSequence 00578 virtual bool has_child(PseudoJet &child) const; 00579 00580 /// check if it is the product of a recombination, in which case 00581 /// return the 2 parents through the 'parent1' and 'parent2' 00582 /// arguments. Otherwise, set these to 0. 00583 /// 00584 /// an Error is thrown if this PseudoJet has no currently valid 00585 /// associated ClusterSequence 00586 virtual bool has_parents(PseudoJet &parent1, PseudoJet &parent2) const; 00587 00588 /// check if the current PseudoJet contains the one passed as 00589 /// argument. 00590 /// 00591 /// an Error is thrown if this PseudoJet has no currently valid 00592 /// associated ClusterSequence 00593 virtual bool contains(const PseudoJet &constituent) const; 00594 00595 /// check if the current PseudoJet is contained the one passed as 00596 /// argument. 00597 /// 00598 /// an Error is thrown if this PseudoJet has no currently valid 00599 /// associated ClusterSequence 00600 virtual bool is_inside(const PseudoJet &jet) const; 00601 00602 00603 /// returns true if the PseudoJet has constituents 00604 virtual bool has_constituents() const; 00605 00606 /// retrieve the constituents. 00607 /// 00608 /// an Error is thrown if this PseudoJet has no currently valid 00609 /// associated ClusterSequence or other substructure information 00610 virtual std::vector<PseudoJet> constituents() const; 00611 00612 00613 /// returns true if the PseudoJet has support for exclusive subjets 00614 virtual bool has_exclusive_subjets() const; 00615 00616 /// return a vector of all subjets of the current jet (in the sense 00617 /// of the exclusive algorithm) that would be obtained when running 00618 /// the algorithm with the given dcut. 00619 /// 00620 /// Time taken is O(m ln m), where m is the number of subjets that 00621 /// are found. If m gets to be of order of the total number of 00622 /// constituents in the jet, this could be substantially slower than 00623 /// just getting that list of constituents. 00624 /// 00625 /// an Error is thrown if this PseudoJet has no currently valid 00626 /// associated ClusterSequence 00627 std::vector<PseudoJet> exclusive_subjets (const double & dcut) const; 00628 00629 /// return the size of exclusive_subjets(...); still n ln n with same 00630 /// coefficient, but marginally more efficient than manually taking 00631 /// exclusive_subjets.size() 00632 /// 00633 /// an Error is thrown if this PseudoJet has no currently valid 00634 /// associated ClusterSequence 00635 int n_exclusive_subjets(const double & dcut) const; 00636 00637 /// return the list of subjets obtained by unclustering the supplied 00638 /// jet down to nsub subjets. Throws an error if there are fewer than 00639 /// nsub particles in the jet. 00640 /// 00641 /// For ClusterSequence type jets, requires nsub ln nsub time 00642 /// 00643 /// An Error is thrown if this PseudoJet has no currently valid 00644 /// associated ClusterSequence 00645 std::vector<PseudoJet> exclusive_subjets (int nsub) const; 00646 00647 /// return the list of subjets obtained by unclustering the supplied 00648 /// jet down to nsub subjets (or all constituents if there are fewer 00649 /// than nsub). 00650 /// 00651 /// For ClusterSequence type jets, requires nsub ln nsub time 00652 /// 00653 /// An Error is thrown if this PseudoJet has no currently valid 00654 /// associated ClusterSequence 00655 std::vector<PseudoJet> exclusive_subjets_up_to (int nsub) const; 00656 00657 /// return the dij that was present in the merging nsub+1 -> nsub 00658 /// subjets inside this jet. 00659 /// 00660 /// an Error is thrown if this PseudoJet has no currently valid 00661 /// associated ClusterSequence 00662 double exclusive_subdmerge(int nsub) const; 00663 00664 /// return the maximum dij that occurred in the whole event at the 00665 /// stage that the nsub+1 -> nsub merge of subjets occurred inside 00666 /// this jet. 00667 /// 00668 /// an Error is thrown if this PseudoJet has no currently valid 00669 /// associated ClusterSequence 00670 double exclusive_subdmerge_max(int nsub) const; 00671 00672 00673 /// returns true if a jet has pieces 00674 /// 00675 /// By default a single particle or a jet coming from a 00676 /// ClusterSequence have no pieces and this methos will return false. 00677 /// 00678 /// In practice, this is equivalent to have an structure of type 00679 /// CompositeJetStructure. 00680 virtual bool has_pieces() const; 00681 00682 00683 /// retrieve the pieces that make up the jet. 00684 /// 00685 /// If the jet does not support pieces, an error is throw 00686 virtual std::vector<PseudoJet> pieces() const; 00687 00688 00689 // the following ones require a computation of the area in the 00690 // parent ClusterSequence (See ClusterSequenceAreaBase for details) 00691 //------------------------------------------------------------------ 00692 00693 /// check if it has a defined area 00694 virtual bool has_area() const; 00695 00696 /// return the jet (scalar) area. 00697 /// throws an Error if there is no support for area in the parent CS 00698 virtual double area() const; 00699 00700 /// return the error (uncertainty) associated with the determination 00701 /// of the area of this jet. 00702 /// throws an Error if there is no support for area in the parent CS 00703 virtual double area_error() const; 00704 00705 /// return the jet 4-vector area. 00706 /// throws an Error if there is no support for area in the parent CS 00707 virtual PseudoJet area_4vector() const; 00708 00709 /// true if this jet is made exclusively of ghosts. 00710 /// throws an Error if there is no support for area in the parent CS 00711 virtual bool is_pure_ghost() const; 00712 00713 //\} --- end of jet structure ------------------------------------- 00714 00715 00716 00717 //---------------------------------------------------------------------- 00718 /// @name Members mainly intended for internal use 00719 //---------------------------------------------------------------------- 00720 //\{ 00721 /// return the cluster_hist_index, intended to be used by clustering 00722 /// routines. 00723 inline int cluster_hist_index() const {return _cluster_hist_index;} 00724 /// set the cluster_hist_index, intended to be used by clustering routines. 00725 inline void set_cluster_hist_index(const int index) {_cluster_hist_index = index;} 00726 00727 /// alternative name for cluster_hist_index() [perhaps more meaningful] 00728 inline int cluster_sequence_history_index() const { 00729 return cluster_hist_index();} 00730 /// alternative name for set_cluster_hist_index(...) [perhaps more 00731 /// meaningful] 00732 inline void set_cluster_sequence_history_index(const int index) { 00733 set_cluster_hist_index(index);} 00734 00735 //\} ---- end of internal use functions --------------------------- 00736 00737 protected: 00738 00739 SharedPtr<PseudoJetStructureBase> _structure; 00740 SharedPtr<UserInfoBase> _user_info; 00741 00742 00743 private: 00744 // NB: following order must be kept for things to behave sensibly... 00745 double _px,_py,_pz,_E; 00746 mutable double _phi, _rap; 00747 double _kt2; 00748 int _cluster_hist_index, _user_index; 00749 00750 /// calculate phi, rap, kt2 based on the 4-momentum components 00751 void _finish_init(); 00752 /// set the indices to default values 00753 void _reset_indices(); 00754 00755 /// ensure that the internal values for rapidity and phi 00756 /// correspond to 4-momentum structure 00757 inline void _ensure_valid_rap_phi() const { 00758 if (_phi == pseudojet_invalid_phi) _set_rap_phi(); 00759 } 00760 00761 /// set cached rapidity and phi values 00762 void _set_rap_phi() const; 00763 }; 00764 00765 00766 //---------------------------------------------------------------------- 00767 // routines for basic binary operations 00768 00769 PseudoJet operator+(const PseudoJet &, const PseudoJet &); 00770 PseudoJet operator-(const PseudoJet &, const PseudoJet &); 00771 PseudoJet operator*(double, const PseudoJet &); 00772 PseudoJet operator*(const PseudoJet &, double); 00773 PseudoJet operator/(const PseudoJet &, double); 00774 00775 /// returns true if the 4 momentum components of the two PseudoJets 00776 /// are identical and all the internal indices (user, cluster_history) 00777 /// + structure and user-info shared pointers are too 00778 bool operator==(const PseudoJet &, const PseudoJet &); 00779 00780 /// inequality test which is exact opposite of operator== 00781 inline bool operator!=(const PseudoJet & a, const PseudoJet & b) {return !(a==b);} 00782 00783 /// Can only be used with val=0 and tests whether all four 00784 /// momentum components are equal to val (=0.0) 00785 bool operator==(const PseudoJet & jet, const double val); 00786 00787 /// Can only be used with val=0 and tests whether at least one of the 00788 /// four momentum components is different from val (=0.0) 00789 inline bool operator!=(const PseudoJet & a, const double & val) {return !(a==val);} 00790 00791 inline double dot_product(const PseudoJet & a, const PseudoJet & b) { 00792 return a.E()*b.E() - a.px()*b.px() - a.py()*b.py() - a.pz()*b.pz(); 00793 } 00794 00795 /// returns true if the momenta of the two input jets are identical 00796 bool have_same_momentum(const PseudoJet &, const PseudoJet &); 00797 00798 /// return a pseudojet with the given pt, y, phi and mass 00799 /// (phi should satisfy -2pi<phi<4pi) 00800 PseudoJet PtYPhiM(double pt, double y, double phi, double m = 0.0); 00801 00802 //---------------------------------------------------------------------- 00803 // Routines to do with providing sorted arrays of vectors. 00804 00805 /// return a vector of jets sorted into decreasing transverse momentum 00806 std::vector<PseudoJet> sorted_by_pt(const std::vector<PseudoJet> & jets); 00807 00808 /// return a vector of jets sorted into increasing rapidity 00809 std::vector<PseudoJet> sorted_by_rapidity(const std::vector<PseudoJet> & jets); 00810 00811 /// return a vector of jets sorted into decreasing energy 00812 std::vector<PseudoJet> sorted_by_E(const std::vector<PseudoJet> & jets); 00813 00814 /// return a vector of jets sorted into increasing pz 00815 std::vector<PseudoJet> sorted_by_pz(const std::vector<PseudoJet> & jets); 00816 00817 //---------------------------------------------------------------------- 00818 // some code to help sorting 00819 00820 /// sort the indices so that values[indices[0->n-1]] is sorted 00821 /// into increasing order 00822 void sort_indices(std::vector<int> & indices, 00823 const std::vector<double> & values); 00824 00825 /// given a vector of values with a one-to-one correspondence with the 00826 /// vector of objects, sort objects into an order such that the 00827 /// associated values would be in increasing order (but don't actually 00828 /// touch the values vector in the process). 00829 template<class T> std::vector<T> objects_sorted_by_values(const std::vector<T> & objects, 00830 const std::vector<double> & values); 00831 00832 /// \if internal_doc 00833 /// @ingroup internal 00834 /// \class IndexedSortHelper 00835 /// a class that helps us carry out indexed sorting. 00836 /// \endif 00837 class IndexedSortHelper { 00838 public: 00839 inline IndexedSortHelper (const std::vector<double> * reference_values) { 00840 _ref_values = reference_values; 00841 }; 00842 inline int operator() (const int & i1, const int & i2) const { 00843 return (*_ref_values)[i1] < (*_ref_values)[i2]; 00844 }; 00845 private: 00846 const std::vector<double> * _ref_values; 00847 }; 00848 00849 00850 //---------------------------------------------------------------------- 00851 /// constructor from any object that has px,py,pz,E = some_four_vector[0--3], 00852 // NB: do not know if it really needs to be inline, but when it wasn't 00853 // linking failed with g++ (who knows what was wrong...) 00854 template <class L> inline PseudoJet::PseudoJet(const L & some_four_vector) { 00855 reset(some_four_vector); 00856 } 00857 00858 //---------------------------------------------------------------------- 00859 inline void PseudoJet::_reset_indices() { 00860 set_cluster_hist_index(-1); 00861 set_user_index(-1); 00862 _structure.reset(); 00863 _user_info.reset(); 00864 } 00865 00866 00867 // taken literally from CLHEP 00868 inline double PseudoJet::m() const { 00869 double mm = m2(); 00870 return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm); 00871 } 00872 00873 00874 inline void PseudoJet::reset(double px, double py, double pz, double E) { 00875 _px = px; 00876 _py = py; 00877 _pz = pz; 00878 _E = E; 00879 _finish_init(); 00880 _reset_indices(); 00881 } 00882 00883 inline void PseudoJet::reset_momentum(double px, double py, double pz, double E) { 00884 _px = px; 00885 _py = py; 00886 _pz = pz; 00887 _E = E; 00888 _finish_init(); 00889 } 00890 00891 inline void PseudoJet::reset_momentum(const PseudoJet & pj) { 00892 _px = pj._px ; 00893 _py = pj._py ; 00894 _pz = pj._pz ; 00895 _E = pj._E ; 00896 _phi = pj._phi; 00897 _rap = pj._rap; 00898 _kt2 = pj._kt2; 00899 } 00900 00901 //------------------------------------------------------------------------------- 00902 // implementation of the templated accesses to the underlying structyre 00903 //------------------------------------------------------------------------------- 00904 00905 // returns a reference to the structure casted to the requested 00906 // structure type 00907 // 00908 // If there is no sructure associated, an Error is thrown. 00909 // If the type is not met, a std::bad_cast error is thrown. 00910 template<typename StructureType> 00911 const StructureType & PseudoJet::structure() const{ 00912 return dynamic_cast<const StructureType &>(* validated_structure_ptr()); 00913 00914 } 00915 00916 // check if the PseudoJet has the structure resulting from a Transformer 00917 // (that is, its structure is compatible with a Transformer::StructureType) 00918 template<typename TransformerType> 00919 bool PseudoJet::has_structure_of() const{ 00920 if (!_structure()) return false; 00921 00922 return dynamic_cast<const typename TransformerType::StructureType *>(_structure.get()) != 0; 00923 } 00924 00925 // this is a helper to access a structure created by a Transformer 00926 // (that is, of type Transformer::StructureType) 00927 // NULL is returned if the corresponding type is not met 00928 template<typename TransformerType> 00929 const typename TransformerType::StructureType & PseudoJet::structure_of() const{ 00930 if (!_structure()) 00931 throw Error("Trying to access the structure of a PseudoJet without an associated structure"); 00932 00933 return dynamic_cast<const typename TransformerType::StructureType &>(*_structure); 00934 } 00935 00936 00937 00938 //------------------------------------------------------------------------------- 00939 // helper functions to build a jet made of pieces 00940 // 00941 // Note that there are more complete versions of these functions, with 00942 // an additional argument for a recombination scheme, in 00943 // JetDefinition.hh 00944 // ------------------------------------------------------------------------------- 00945 00946 /// build a "CompositeJet" from the vector of its pieces 00947 /// 00948 /// In this case, E-scheme recombination is assumed to compute the 00949 /// total momentum 00950 PseudoJet join(const std::vector<PseudoJet> & pieces); 00951 00952 /// build a MergedJet from a single PseudoJet 00953 PseudoJet join(const PseudoJet & j1); 00954 00955 /// build a MergedJet from 2 PseudoJet 00956 PseudoJet join(const PseudoJet & j1, const PseudoJet & j2); 00957 00958 /// build a MergedJet from 3 PseudoJet 00959 PseudoJet join(const PseudoJet & j1, const PseudoJet & j2, const PseudoJet & j3); 00960 00961 /// build a MergedJet from 4 PseudoJet 00962 PseudoJet join(const PseudoJet & j1, const PseudoJet & j2, const PseudoJet & j3, const PseudoJet & j4); 00963 00964 00965 00966 FASTJET_END_NAMESPACE 00967 00968 #endif // __FASTJET_PSEUDOJET_HH__