fastjet 2.4.5
run_jet_finder.cc
Go to the documentation of this file.
00001 //STARTHEADER
00002 // $Id: run_jet_finder.cc 1555 2009-05-08 11:48:38Z cacciari $
00003 //
00004 // Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam
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 #include "fastjet/PseudoJet.hh"
00032 #include "fastjet/ClusterSequence.hh"
00033 #include<iostream> // needed for io
00034 #include<sstream>  // needed for internal io
00035 #include<vector> 
00036 #include <cstdio>
00037 
00038 using namespace std;
00039 
00040 // a declaration of a function that pretty prints a list of jets
00041 void print_jets (const fastjet::ClusterSequence &, 
00042                  const vector<fastjet::PseudoJet> &);
00043 
00044 
00045 
00048 void run_jet_finder (const vector<fastjet::PseudoJet> & input_particles,
00049                      const fastjet::JetDefinition & jet_def) {
00050   
00051   // run the jet clustering with the above jet definition
00052   fastjet::ClusterSequence clust_seq(input_particles, jet_def);
00053 
00054   // tell the user what was done
00055   cout << "Ran " << jet_def.description() << endl;
00056 
00057   // extract the inclusive jets with pt > 5 GeV
00058   double ptmin = 5.0;
00059   vector<fastjet::PseudoJet> inclusive_jets = clust_seq.inclusive_jets(ptmin);
00060 
00061   // print them out
00062   cout << "Printing inclusive jets with pt > "<< ptmin<<" GeV\n";
00063   cout << "---------------------------------------\n";
00064   print_jets(clust_seq, inclusive_jets);
00065   cout << endl;
00066 
00067   // print out unclustered stuff
00068   cout << clust_seq.unclustered_particles().size() << " particles unclustered" << endl << endl;
00069 }
00070 
00071 
00072 //----------------------------------------------------------------------
00074 void read_input_particles(istream & input, 
00075                           vector<fastjet::PseudoJet> & input_particles){
00076 
00077   // read in input particles
00078   double px, py , pz, E;
00079   string line;
00080   while (getline(input, line)) {
00081     if (line.substr(0,1) == "#") {continue;}
00082     istringstream linestream(line);
00083     linestream >> px >> py >> pz >> E;
00084   // create a fastjet::PseudoJet with these components and put it onto
00085     // back of the input_particles vector
00086     input_particles.push_back(fastjet::PseudoJet(px,py,pz,E)); 
00087   }
00088   
00089 }
00090 
00091 //----------------------------------------------------------------------
00093 void print_jets (const fastjet::ClusterSequence & clust_seq, 
00094                  const vector<fastjet::PseudoJet> & jets) {
00095 
00096   // sort jets into increasing pt
00097   vector<fastjet::PseudoJet> sorted_jets = sorted_by_pt(jets);  
00098 
00099   // label the columns
00100   printf("%5s %15s %15s %15s %15s\n","jet #", "rapidity", 
00101          "phi", "pt", "n constituents");
00102   
00103   // print out the details for each jet
00104   for (unsigned int i = 0; i < sorted_jets.size(); i++) {
00105     int n_constituents = clust_seq.constituents(sorted_jets[i]).size();
00106     printf("%5u %15.8f %15.8f %15.8f %8u\n",
00107            i, sorted_jets[i].rap(), sorted_jets[i].phi(),
00108            sorted_jets[i].perp(), n_constituents);
00109   }
00110 
00111 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines