fastjet 2.4.5
NestedDefsPlugin.cc
Go to the documentation of this file.
00001 //STARTHEADER
00002 // $Id: NestedDefsPlugin.cc 1394 2009-01-17 05:08:31Z soyez $
00003 //
00004 // Copyright (c) 2007-2008, 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 // TODO
00032 // ? Maybe one could provide additional recomb. dists as an "extra".;
00033 
00034 // fastjet stuff
00035 #include "fastjet/ClusterSequence.hh"
00036 #include "fastjet/NestedDefsPlugin.hh"
00037 
00038 // other stuff
00039 #include <vector>
00040 #include <sstream>
00041 
00042 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00043 
00044 using namespace std;
00045 
00046 string NestedDefsPlugin::description () const {
00047   ostringstream desc;
00048   
00049   desc << "NestedDefs: successive application of " ;
00050   unsigned int i=1;
00051   for (list<JetDefinition>::const_iterator it=_defs.begin();it!=_defs.end();it++){
00052     desc << "Definition " << i++ << " [" << it->description() << "] - ";
00053   }
00054 
00055   return desc.str();
00056 }
00057 
00058 void NestedDefsPlugin::run_clustering(ClusterSequence & clust_seq) const {
00059   vector<PseudoJet> momenta;
00060 
00061   // build the initial list of particles
00062   momenta = clust_seq.jets();
00063   unsigned int step_n = momenta.size();
00064 
00065   // initialise the conversion table, which works as follows
00066   // conversion_table[step_cs_jet_index] = main_cs_jet_index
00067   vector<unsigned int> conversion_table(2*step_n);
00068   vector<unsigned int> new_conversion_table;
00069   for (unsigned int i=0;i<step_n;i++)
00070     conversion_table[i]=i;
00071 
00072   // Now the steps go as follows:
00073   // for each definition in the list, 
00074   //  - do the clustering,
00075   //  - copy the history into the main one
00076   //  - update the list of momenta and the index conversion table
00077   list<JetDefinition>::const_iterator def_iterator = _defs.begin();
00078   unsigned int def_index=0;
00079   bool last_def=false;
00080 
00081   while (def_iterator!=_defs.end()){
00082     last_def = (def_index == (_defs.size()-1));
00083 
00084     // do the clustering
00085     ClusterSequence step_cs(momenta, *def_iterator);
00086 
00087     // clear the momenta as we shall fill them again
00088     momenta.clear();
00089     new_conversion_table.clear();
00090 
00091     // retrieve the history
00092     const vector<ClusterSequence::history_element> & step_history = step_cs.history();
00093 
00094     // copy the history
00095     // note that we skip the initial steps which are just the 
00096     // declaration of the particles.
00097     vector<ClusterSequence::history_element>::const_iterator 
00098       hist_iterator = step_history.begin();
00099 
00100     for (unsigned int i=step_n;i!=0;i--)
00101       hist_iterator++;
00102 
00103     while (hist_iterator != step_history.end()){
00104       // check if it is a recombination with the beam or a simple recombination
00105       if (hist_iterator->parent2 == ClusterSequence::BeamJet){
00106         // save this jet for future clustering
00107         // unless we've reached the last def in which case, record the clustering
00108         unsigned int step_jet_index = step_cs.history()[hist_iterator->parent1].jetp_index;
00109         if (last_def){
00110           clust_seq.plugin_record_iB_recombination(conversion_table[step_jet_index], 
00111                                                    hist_iterator->dij);
00112         } else {
00113           momenta.push_back(step_cs.jets()[step_jet_index]);
00114           new_conversion_table.push_back(conversion_table[step_jet_index]);
00115         }
00116       } else {
00117         // record combination
00118         // note that we set the recombination distance to 0 except for the last alg
00119         unsigned int step_jet1_index = step_cs.history()[hist_iterator->parent1].jetp_index;
00120         unsigned int step_jet2_index = step_cs.history()[hist_iterator->parent2].jetp_index;
00121         PseudoJet newjet = step_cs.jets()[hist_iterator->jetp_index];
00122         int jet_k;
00123         clust_seq.plugin_record_ij_recombination(conversion_table[step_jet1_index], 
00124                                                  conversion_table[step_jet2_index],
00125                                                  last_def ? hist_iterator->dij : 0.0,
00126                                                  newjet, jet_k);
00127 
00128         // save info in the conversion table for tracking purposes
00129         conversion_table[hist_iterator->jetp_index]=jet_k;
00130       }
00131 
00132       // go to the next history element
00133       hist_iterator++;
00134     }
00135 
00136     // finalise this step:
00137     //  - update nr of particles
00138     //  - update conversion table
00139     step_n = momenta.size();
00140     for (unsigned int i=0;i<step_n;i++)
00141       conversion_table[i] = new_conversion_table[i];
00142 
00143     // go to the next alg
00144     def_index++;
00145     def_iterator++;
00146   }
00147 
00148 }
00149 
00150 FASTJET_END_NAMESPACE      // defined in fastjet/internal/base.hh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines