00001 //STARTHEADER 00002 // $Id: PseudoJetPlusInfo.hh 1885 2011-01-27 14:50:21Z salam $ 00003 // 00004 // Copyright (c) 2005-2010, 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 #ifndef __PSEUDOJET_PLUS_INFO_HH__ 00032 #define __PSEUDOJET_PLUS_INFO_HH__ 00033 00034 #include "fastjet/internal/numconsts.hh" 00035 #include "fastjet/PseudoJet.hh" 00036 #include <vector> 00037 00038 FASTJET_BEGIN_NAMESPACE 00039 00040 //----------------------------------------------- 00041 /// \ingroup extra_info 00042 /// \class PseudoJetPlusInfo 00043 /// a templated extension of PseudoJet that carries extra information 00044 /// 00045 /// a class that carries the PseudoJet together with some extra info 00046 /// though you could live with the PseudoJet::_extra_info which is 00047 /// already in PseudoJet, this class is mostly a helper that deals 00048 /// with the association of a generic extra info (derived 00049 /// PsseudoJet::ExtraInfo) to a PseudoJet 00050 /// 00051 /// WARNING: the template parameter T (i.e. your specific extra info 00052 /// type) has to be derived from PseudoJet::ExtraInfo (this is mostly 00053 /// related to the use of dynamic_casts that we have adopted as a 00054 /// safe-keeper against misuse of pointers) 00055 //----------------------------------------------- 00056 template<typename TExtraInfo> 00057 class PseudoJetPlusInfo : public PseudoJet{ 00058 public: 00059 /// ctor with full initialisation 00060 /// \param pj the underlying PseudoJet 00061 /// \param ei the extra information 00062 PseudoJetPlusInfo(const PseudoJet &pj, const TExtraInfo &ei) : PseudoJet(pj){ 00063 const ExtraInfo * extra_info_ptr = extra_info(); 00064 if (!extra_info_ptr) { 00065 extra_info_shared().reset(new TExtraInfo(ei)); 00066 } else if (dynamic_cast<const TExtraInfo*>(extra_info_ptr)) { 00067 // then this is already a valid PseudoJetPlusInfo 00068 // don't do anything 00069 } else { 00070 // we already have an info but of wrong type! 00071 throw ("invalid extra_info for initialising PseudoJetPlusInfo"); 00072 } 00073 } 00074 00075 /// copy ctor from PseudoJet 00076 /// this version requires that the ExtraInfo pointer is dynamic-castable 00077 /// onto a pointer to TExtraInfo before making te copy 00078 /// If no extra info is present, just discard it 00079 PseudoJetPlusInfo(const PseudoJet &pj) : PseudoJet(pj){ 00080 const ExtraInfo * extra_info_ptr = pj.extra_info(); 00081 if (extra_info_ptr) { 00082 if (dynamic_cast<const TExtraInfo*>(extra_info_ptr)) { 00083 extra_info_shared().reset(pj.extra_info_shared()); 00084 } else { 00085 throw("invalid extra_info in copy constructor for PseudoJetPlusInfo"); 00086 } 00087 } 00088 } 00089 00090 00091 /// retrieve a pointer to the extra information 00092 const TExtraInfo* extra_info() const{ 00093 if (!extra_info_shared()()) return NULL; 00094 return dynamic_cast<TExtraInfo*>(extra_info_shared().get()); 00095 } 00096 }; 00097 00098 00099 /// a helper to copy a vector of PseudoJet's into a vector of PseudoJetPlusInfo 00100 /// This should allow construct like 00101 /// vector<MyPseudoJet> jets 00102 /// = convert_to<MyPseudoJet>(sorted_by_pt(cs.inclusive_jets())); 00103 template<typename T, typename U> 00104 std::vector<T> convert_vector_to(const std::vector<U> & in){ 00105 std::vector<T> res; 00106 copy(in.begin(), in.end(), back_inserter(res)); 00107 return res; 00108 } 00109 00110 00111 00112 00113 FASTJET_END_NAMESPACE 00114 00115 #endif // __PSEUDOJET_PLUS_INFO_HH__