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