FastJet 3.0.0
CDFJetCluPlugin.cc
00001 //STARTHEADER
00002 // $Id: CDFJetCluPlugin.cc 2577 2011-09-13 15:11:38Z salam $
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/CDFJetCluPlugin.hh"
00030 #include "fastjet/ClusterSequence.hh"
00031 #include <sstream>
00032 #include <cassert>
00033 
00034 // CDF stuff
00035 #include "JetCluAlgorithm.hh"
00036 #include "PhysicsTower.hh"
00037 #include "Cluster.hh"
00038 
00039 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00040 
00041 using namespace std;
00042 using namespace cdf;
00043 
00044 string CDFJetCluPlugin::description () const {
00045   ostringstream desc;
00046   
00047   desc << "CDF JetClu jet algorithm with " 
00048        << "seed_threshold = "     << seed_threshold    () << ", "
00049        << "cone_radius = "        << cone_radius       () << ", "
00050        << "adjacency_cut = "      << adjacency_cut     () << ", " 
00051        << "max_iterations = "     << max_iterations    () << ", "
00052        << "iratch = "             << iratch            () << ", "
00053        << "overlap_threshold = "  << overlap_threshold () ;
00054 
00055   return desc.str();
00056 }
00057 
00058 
00059 void CDFJetCluPlugin::run_clustering(ClusterSequence & clust_seq) const {
00060  
00061   // create the physics towers needed by the CDF code
00062   vector<PhysicsTower> towers;
00063   towers.reserve(clust_seq.jets().size());
00064 
00065   // create a map to identify jets (actually just the input particles)...
00066   //map<double,int> jetmap;
00067 
00068   for (unsigned i = 0; i < clust_seq.jets().size(); i++) {
00069     PseudoJet particle(clust_seq.jets()[i]);
00070     //_insert_unique(particle, jetmap);
00071     LorentzVector fourvect(particle.px(), particle.py(),
00072                            particle.pz(), particle.E());
00073     PhysicsTower tower(fourvect);
00074     // add tracking information for later
00075     tower.fjindex = i;
00076     towers.push_back(tower);
00077   }
00078 
00079   // prepare the CDF algorithm
00080   JetCluAlgorithm j(seed_threshold(), cone_radius(), adjacency_cut(),
00081                     max_iterations(), iratch(), overlap_threshold());
00082     
00083   // run the CDF algorithm
00084   std::vector<Cluster> jets;
00085   j.run(towers,jets);
00086 
00087 
00088   // now transfer the jets back into our own structure -- we will
00089   // mimic the cone code with a sequential recombination sequence in
00090   // which the jets are built up by adding one particle at a time
00091 
00092   // NB: with g++-4.0, the reverse iterator code gave problems, so switch
00093   //     to indices instead
00094   //for(vector<Cluster>::const_reverse_iterator jetIter = jets.rbegin(); 
00095   //                                    jetIter != jets.rend(); jetIter++) {
00096   //  const vector<PhysicsTower> & tower_list = jetIter->towerList;
00097   //  int jet_k = jetmap[tower_list[0].fourVector.E];
00098   //
00099   //  int ntow = int(jetIter->towerList.size());
00100 
00101   for(int iCDFjets = jets.size()-1; iCDFjets >= 0; iCDFjets--) {
00102 
00103     const vector<PhysicsTower> & tower_list = jets[iCDFjets].towerList;
00104     int ntow = int(tower_list.size());
00105     
00106     // 2008-09-04: sort the towerList (according to fjindex) so as
00107     //             to have a consistent order for particles in jet
00108     //             (necessary because addition of ultra-soft particles
00109     //             sometimes often modifies the order, while maintaining
00110     //             the same overall set)
00111     vector<int>    jc_indices(ntow);
00112     vector<double> fj_indices(ntow); // use double: benefit from existing routine
00113     for (int itow = 0; itow < ntow; itow++) {
00114       jc_indices[itow] = itow;
00115       fj_indices[itow] = tower_list[itow].fjindex;
00116     }
00117     sort_indices(jc_indices, fj_indices);
00118 
00119     int jet_k = tower_list[jc_indices[0]].fjindex;
00120   
00121     for (int itow = 1; itow < ntow; itow++) {
00122       if (tower_list[jc_indices[itow]].Et() > 1e-50) {
00123       }
00124       int jet_i = jet_k;
00125       // retrieve our index for the jet
00126       int jet_j;
00127       jet_j = tower_list[jc_indices[itow]].fjindex;
00128 
00129       // safety check
00130       assert (jet_j >= 0 && jet_j < int(towers.size()));
00131 
00132       // do a fake recombination step with dij=0
00133       double dij = 0.0;
00134 
00135       // JetClu does E-scheme recombination so we can stick with the
00136       // simple option
00137       clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, jet_k);
00138 
00139     }
00140   
00141     // NB: put a sensible looking d_iB just to be nice...
00142     double d_iB = clust_seq.jets()[jet_k].perp2();
00143     clust_seq.plugin_record_iB_recombination(jet_k, d_iB);
00144   }
00145 
00146 
00147   // following code is for testing only
00148   //cout << endl;
00149   //for(vector<Cluster>::const_iterator jetIter = jets.begin(); 
00150   //                                    jetIter != jets.end(); jetIter++) {
00151   //  cout << jetIter->fourVector.pt() << " " << jetIter->fourVector.y() << endl;
00152   //}
00153   //cout << "-----------------------------------------------------\n";
00154   //vector<PseudoJet> ourjets(clust_seq.inclusive_jets());
00155   //for (vector<PseudoJet>::const_iterator ourjet = ourjets.begin();
00156   //     ourjet != ourjets.end(); ourjet++) {
00157   //  cout << ourjet->perp() << " " << ourjet->rap() << endl;
00158   //}
00159   //cout << endl;
00160 }
00161 
00162 
00163 
00164 FASTJET_END_NAMESPACE      // defined in fastjet/internal/base.hh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends