TrackJetPlugin.cc

Go to the documentation of this file.
00001 //STARTHEADER
00002 // $Id: TrackJetPlugin.cc 1491 2009-03-11 17:04:38Z salam $
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 // fastjet stuff
00032 #include "fastjet/ClusterSequence.hh"
00033 #include "fastjet/TrackJetPlugin.hh"
00034 
00035 // other stuff
00036 #include <vector>
00037 #include <sstream>
00038 
00039 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00040 
00041 using namespace std;
00042 
00043 class TrackJetParticlePtr{
00044 public:
00045   TrackJetParticlePtr(int i_index, double i_perp2)
00046     :  index(i_index), perp2(i_perp2){}
00047 
00048   int index;
00049   double perp2;
00050 
00051   bool operator <(const TrackJetParticlePtr &other) const { 
00052     return perp2>other.perp2;
00053   }
00054 };
00055 
00056 string TrackJetPlugin::description () const {
00057   ostringstream desc;
00058   desc << "TrackJet algorithm with R = " << R();
00059   return desc.str();
00060 }
00061 
00062 void TrackJetPlugin::run_clustering(ClusterSequence & clust_seq) const {
00063   // we first need to sort the particles in pt
00064   vector<TrackJetParticlePtr> particle_list;
00065 
00066   const vector<PseudoJet> & jets = clust_seq.jets();  
00067   int index=0;
00068   for (vector<PseudoJet>::const_iterator mom_it = jets.begin(); mom_it != jets.end(); mom_it++){
00069     particle_list.push_back(TrackJetParticlePtr(index, mom_it->perp2()));
00070     index++;
00071   }
00072 
00073   // sort the particles into decreasing pt
00074   sort(particle_list.begin(), particle_list.end());
00075 
00076 
00077   // if we're using a recombination scheme different from the E scheme,
00078   // we first need to update the particles' energy so that they
00079   // are massless (and rapidity = pseudorapidity)
00080   vector<PseudoJet> tuned_particles = clust_seq.jets();
00081   vector<PseudoJet> tuned_tracks = clust_seq.jets();
00082   for (vector<PseudoJet>::iterator pit = tuned_particles.begin();
00083        pit != tuned_particles.end(); pit++)
00084     _jet_recombiner.preprocess(*pit);
00085   for (vector<PseudoJet>::iterator pit = tuned_tracks.begin();
00086        pit != tuned_tracks.end(); pit++)
00087     _track_recombiner.preprocess(*pit);
00088 
00089 
00090   // we'll just need the particle indices for what follows
00091   list<int> sorted_pt_index;
00092   for (vector<TrackJetParticlePtr>::iterator mom_it = particle_list.begin();
00093        mom_it != particle_list.end(); mom_it++)
00094     sorted_pt_index.push_back(mom_it->index);
00095   
00096   // now start building the jets
00097   while (sorted_pt_index.size()){
00098     // note that here 'track' refers to the direction we're using to test if a particle belongs to the jet
00099     // 'jet' refers to the momentum of the jet
00100     // the difference between the two is in the recombination scheme used to compute the sum of 4-vectors
00101     int current_jet_index = sorted_pt_index.front();
00102     PseudoJet current_jet   = tuned_particles[current_jet_index];
00103     PseudoJet current_track = tuned_tracks[current_jet_index];
00104 
00105     // remove the first particle from the available ones    
00106     list<int>::iterator index_it = sorted_pt_index.begin();
00107     sorted_pt_index.erase(index_it);
00108 
00109     // start browsing the remaining ones
00110     index_it = sorted_pt_index.begin();
00111     while (index_it != sorted_pt_index.end()){
00112       const PseudoJet & current_particle = tuned_particles[*index_it];
00113       const PseudoJet & current_particle_track = tuned_tracks[*index_it];
00114 
00115       // check if the particle is within a distance R of the jet
00116       double distance2 = current_track.plain_distance(current_particle_track);
00117       if (distance2 <= _radius2){
00118         // add the particle to the jet
00119         PseudoJet new_track;
00120         PseudoJet new_jet;
00121         _jet_recombiner.recombine(current_jet, current_particle, new_jet);
00122         _track_recombiner.recombine(current_track, current_particle_track, new_track);
00123 
00124         int new_jet_index;
00125         clust_seq.plugin_record_ij_recombination(current_jet_index, *index_it, distance2, new_jet, new_jet_index);
00126 
00127         current_jet = new_jet;
00128         current_track = new_track;
00129         current_jet_index = new_jet_index;
00130 
00131         // particle has been clustered so remove it from the list
00132         sorted_pt_index.erase(index_it);
00133 
00134         // and don't forget to start again from the beginning
00135         //  as the jet axis may have changed
00136         index_it = sorted_pt_index.begin();
00137       } else {
00138         index_it++;
00139       }
00140     }
00141 
00142     // now we have a final jet, so cluster it with the beam
00143     clust_seq.plugin_record_iB_recombination(current_jet_index, _radius2);
00144   }
00145     
00146 }
00147 
00148 FASTJET_END_NAMESPACE      // defined in fastjet/internal/base.hh

Generated on Fri Apr 17 16:15:10 2009 for fastjet by  doxygen 1.5.7.1