FastJet 3.0.2
CompositeJetStructure.cc
00001 //STARTHEADER
00002 // $Id: CompositeJetStructure.cc 2696 2011-11-15 09:42:59Z soyez $
00003 //
00004 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. 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, see <http://www.gnu.org/licenses/>.
00026 //----------------------------------------------------------------------
00027 //ENDHEADER
00028 
00029 #include <fastjet/CompositeJetStructure.hh>
00030 
00031 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00032 
00033 using namespace std;
00034 
00035 
00036 //-------------------------------------------------------------------------------
00037 // \class CompositeJetStructure
00038 // The structure for a jet made of pieces
00039 //
00040 // This stores the vector of the pieces that make the jet and provide
00041 // the methods to access them
00042 // -------------------------------------------------------------------------------
00043 
00044 CompositeJetStructure::CompositeJetStructure(const std::vector<PseudoJet> & initial_pieces, 
00045                                              const JetDefinition::Recombiner * recombiner)
00046   : _pieces(initial_pieces){
00047   // deal with area support (cache the area if needed)
00048   //--------------------------------------------------
00049   // check if all the pieces have area, in which case store it
00050   bool has_area_local = true;
00051   for (vector<PseudoJet>::const_iterator pit=_pieces.begin(); pit!=_pieces.end(); pit++){
00052     if (!pit->has_area()){
00053       has_area_local = false;
00054       continue;
00055     }
00056   }
00057 
00058   if (has_area_local){
00059     _area_4vector_ptr = new PseudoJet();
00060     for (unsigned int i=0; i<_pieces.size(); i++){
00061       const PseudoJet & p = _pieces[i];
00062       if (recombiner)
00063         recombiner->plus_equal(*_area_4vector_ptr, p.area_4vector());
00064       else
00065         *_area_4vector_ptr += p.area_4vector();
00066     } 
00067   } else {
00068     _area_4vector_ptr = 0;
00069   }
00070 
00071 }
00072 
00073 
00074 // description
00075 std::string CompositeJetStructure::description() const{ 
00076   string str = "Composite PseudoJet";
00077   return str; 
00078 }
00079 
00080 
00081 
00082 // things reimplemented from the base structure
00083 //------------------------------------------------------------------------------
00084 bool CompositeJetStructure::has_constituents() const{
00085   //for (vector<PseudoJet>::const_iterator pit=_pieces.begin(); pit!=_pieces.end(); pit++)
00086   //  if (!pit->has_constituents()) return false;
00087   //
00088   //return true;
00089 
00090   // the only case where we do not have constituents is the case where
00091   // there is no pieces!
00092   return _pieces.size()!=0;
00093 }
00094 
00095 std::vector<PseudoJet> CompositeJetStructure::constituents(const PseudoJet & /*jet*/) const{
00096   // recurse into the pieces that ahve constituents, just append the others
00097   // the following code automatically throws an Error if any of the
00098   // pieces has no constituents
00099   vector<PseudoJet> all_constituents;
00100   for (unsigned i = 0; i < _pieces.size(); i++) {
00101     if (_pieces[i].has_constituents()){
00102       vector<PseudoJet> constits = _pieces[i].constituents();
00103       copy(constits.begin(), constits.end(), back_inserter(all_constituents));
00104     } else {
00105       all_constituents.push_back(_pieces[i]);
00106     }
00107   }
00108  
00109   return all_constituents;
00110 }
00111 
00112 std::vector<PseudoJet> CompositeJetStructure::pieces(const PseudoJet & /*jet*/) const{
00113   return _pieces;
00114 }
00115 
00116 
00117 // area-related material
00118 
00119 // check if it has a well-defined area
00120 bool CompositeJetStructure::has_area() const{
00121   return (_area_4vector_ptr != 0);
00122 }
00123 
00124 // return the jet (scalar) area.
00125 double CompositeJetStructure::area(const PseudoJet & /*reference*/) const{
00126   if (! has_area())
00127     throw Error("One or more of this composite jet's pieces does not support area");
00128 
00129   double a=0;
00130   for (unsigned i = 0; i < _pieces.size(); i++)
00131     a += _pieces[i].area();
00132 
00133   return a;
00134 }
00135 
00136 // return the error (uncertainty) associated with the determination
00137 // of the area of this jet.
00138 // 
00139 // Be conservative: return the sum of the errors
00140 double CompositeJetStructure::area_error(const PseudoJet & /*reference*/) const{
00141   if (! has_area())
00142     throw Error("One or more of this composite jet's pieces does not support area");
00143 
00144   double a_err=0;
00145   for (unsigned i = 0; i < _pieces.size(); i++)
00146     a_err += _pieces[i].area();
00147 
00148   return a_err;
00149 }
00150 
00151 // return the jet 4-vector area.
00152 PseudoJet CompositeJetStructure::area_4vector(const PseudoJet & /*reference*/) const{
00153   if (! has_area())
00154     throw Error("One or more of this composite jet's pieces does not support area");
00155 
00156   return *_area_4vector_ptr; // one is supposed to call has_area before!
00157 }
00158 
00159 // true if this jet is made exclusively of ghosts.
00160 //
00161 // In this case, it will be true if all pieces are pure ghost
00162 bool CompositeJetStructure::is_pure_ghost(const PseudoJet & /*reference*/) const{
00163   for (unsigned i = 0; i < _pieces.size(); i++)
00164     if (! _pieces[i].is_pure_ghost()) return false;
00165 
00166   return true;
00167 }
00168 
00169 
00170 
00171 FASTJET_END_NAMESPACE      // defined in fastjet/internal/base.hh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends