FastJet 3.0alpha3
12-filter.cc
Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 /// \file
00003 /// \page Example12 12 - use of filtering
00004 ///
00005 /// fastjet example program illustrating the use of the fastjet::Filter class
00006 ///
00007 /// To do that, we apply different filter examples on a either the
00008 /// hardest jet of the given event or the composition of the two
00009 /// hardest jets: a filter keeping a fixed number of subjets (as in
00010 /// arXiv:0802.2470), and a "trimmer" i.e. a filter keeping subjets
00011 /// carrying a sufficient fraction of the pt of the jet
00012 /// (arXiv:0912.1342).
00013 ///
00014 /// run it with    : ./12-filter < data/single-event.dat
00015 ///
00016 /// Source code: 12-filter.cc
00017 //----------------------------------------------------------------------
00018 
00019 #include <fastjet/PseudoJet.hh>
00020 #include <fastjet/ClusterSequence.hh>
00021 #include <fastjet/Selector.hh>
00022 #include <iostream>
00023 #include "fastjet/tools/Filter.hh"
00024 
00025 #include <cstdio>   // needed for io
00026 
00027 using namespace fastjet;
00028 using namespace std;
00029 
00030 // a function returning
00031 //   min(Rmax, deltaR_factor * deltaR(j1,j2))
00032 // where j1 and j2 are the 2 subjets of j
00033 // if the jet does not have 2 exactly pieces, Rmax is used.
00034 class DynamicRfilt : public FunctionOfPseudoJet<double>{
00035 public:
00036   // default ctor 
00037   DynamicRfilt(double Rmax, double deltaR_factor) : _Rmax(Rmax), _deltaR_factor(deltaR_factor){}
00038 
00039   // action of the function
00040   double result(const PseudoJet &j) const{
00041     if (! j.has_pieces()) return _Rmax;
00042 
00043     vector<PseudoJet> pieces = j.pieces();
00044     if (! pieces.size()==2) return _Rmax;
00045 
00046     double deltaR = pieces[0].delta_R(pieces[1]);
00047     return min(_Rmax, _deltaR_factor * deltaR);
00048   }
00049 
00050 private:
00051   double _Rmax, _deltaR_factor;
00052 };
00053 
00054 /// an example program showing how to use fastjet
00055 int main (int argc, char ** argv) {
00056   // read in input particles
00057   //----------------------------------------------------------
00058   vector<PseudoJet> input_particles;
00059   
00060   double px, py , pz, E;
00061   while (cin >> px >> py >> pz >> E) {
00062     // create a fastjet::PseudoJet with these components and put it onto
00063     // back of the input_particles vector
00064     input_particles.push_back(PseudoJet(px,py,pz,E)); 
00065   }
00066  
00067   // get the resulting jets ordered in pt
00068   //----------------------------------------------------------
00069   JetDefinition jet_def(cambridge_algorithm, 1.2);
00070   ClusterSequence clust_seq(input_particles, jet_def);
00071   vector<fastjet::PseudoJet> inclusive_jets = sorted_by_pt(clust_seq.inclusive_jets(5.0));
00072 
00073   // label the columns
00074   printf("%5s %15s %15s %15s\n","jet #", "rapidity", "phi", "pt");
00075  
00076   // print out the details for each jet
00077   for (unsigned int i = 0; i < inclusive_jets.size(); i++) {
00078     printf("%5u %15.8f %15.8f %15.8f\n",
00079            i, inclusive_jets[i].rap(), inclusive_jets[i].phi(),
00080            inclusive_jets[i].perp());
00081   }
00082 
00083   // simple test to avoid that the example below crashes:
00084   // make sure there is at least 2 jets above our 5 GeV
00085   if (inclusive_jets.size()<2){
00086     cout << "Please provide an event with at least 2 jets above 5 GeV" << endl;
00087     return 1;
00088   }
00089 
00090   // the sample PseudoJet that we shall filter
00091   //  - the hardest jet of the event
00092   //  - the composition of the 2 hardest jets (showing that the Filter
00093   //    can also be applied on a CompositeJet)
00094   //----------------------------------------------------------
00095   vector<PseudoJet> candidates;
00096   candidates.push_back(inclusive_jets[0]);
00097   candidates.push_back(join(inclusive_jets[1],inclusive_jets[2]));
00098 
00099   // create a few filters
00100   //----------------------------------------------------------
00101   vector<Filter> filters;
00102 
00103   // the Aachen/Cambridge filter with Rfilt=0.3
00104   filters.push_back(Filter(JetDefinition(cambridge_algorithm, 0.3), SelectorNHardest(3)));
00105 
00106   // the Aachen/Cambridge filter with Rfilt=min(0.3, 0.5*Rbb) as in arXiv:0802.2470
00107   SharedPtr<DynamicRfilt> dynamic_Rfilt(new DynamicRfilt(0.3, 0.5));
00108   filters.push_back(Filter(dynamic_Rfilt.get(), SelectorNHardest(3)));
00109 
00110   // Filtering with a pt cut as for trimming (arXiv:0912.1342)
00111   filters.push_back(Filter(JetDefinition(kt_algorithm, 0.2), SelectorPtFractionMin(0.03)));
00112 
00113   // apply the various filters on the test PseudoJet
00114   // and show the result
00115   //----------------------------------------------------------
00116   for (vector<PseudoJet>::iterator jit=candidates.begin(); jit!=candidates.end(); jit++){
00117     const PseudoJet & c = *jit;
00118     cout << "Original jet : " << c.description() << endl;
00119     cout << "  rap = " << c.rap() << ", phi = " << c.phi() << ", pt = " << c.perp() << endl;
00120 
00121     for (vector<Filter>::iterator it=filters.begin(); it!=filters.end(); it++){
00122       const Filter & f = *it;
00123       
00124       cout << "Applying filter: " << f.description() << endl;
00125       PseudoJet j = f(c);
00126       
00127       cout << "Resulting jet : " << j.description() << endl;
00128       cout << "  rap = " << j.rap() << ", phi = " << j.phi() << ", pt = " << j.perp() << endl;
00129       cout << "  #pieces: " << j.pieces().size() << endl;
00130       
00131       // access properties specific to the Filter
00132       //
00133       // We first make sure that the jet indeed has a structure
00134       // compatible with the result of a Filter (using
00135       // has_structure_of()), then retrieve the pieces rejected by the
00136       // filter (using structure_of())
00137       assert(j.has_structure_of<Filter>());
00138       const Filter::StructureType & fj_struct = j.structure_of<Filter>();
00139       cout << "  #rejected pieces: " << fj_struct.rejected().size() << endl;
00140     }
00141     cout << endl;
00142   }
00143 
00144   return 0;
00145 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends