FastJet  3.2.0
test.cc
1 #include <iostream>
2 #include <fastjet/ClusterSequence.hh>
3 #include <fastjet/tools/Recluster.hh>
4 
5 using namespace std;
6 using namespace fastjet;
7 
8 //----------------------------------------------------------------------
9 // set up a class to give standard (by default E-scheme)
10 // recombination, with additional tracking of flavour information in
11 // the user_index.
12 //
13 // b-tagged particles are assumed to have their user_index set to 1,
14 // and other particles should have user_index to 0.
15 //
16 // Watch out however that, by default, the user_index of a particle is
17 // set to -1 and you may not have control over that (e.g. if you
18 // compute the jet area using explicit ghosts, the ghosts will have a
19 // default user_index of -1). For that reason, if one of the particle
20 // being combined has a user index of -1, we assume it is not b-tagged
21 // (i.e. we count it as 0 in the recombination)
22 //
23 // This will work for native algorithms, but not for all plugins
24 //----------------------------------------------------------------------
26 
27 class FlavourRecombiner : public DefRecomb {
28 public:
29  FlavourRecombiner(RecombinationScheme recomb_scheme = E_scheme) :
30  DefRecomb(recomb_scheme) {};
31 
32  virtual std::string description() const {
33  return DefRecomb::description()+" (with user index addition)";}
34 
35  /// recombine pa and pb and put result into pab
36  virtual void recombine(const PseudoJet & pa, const PseudoJet & pb,
37  PseudoJet & pab) const {
38  DefRecomb::recombine(pa,pb,pab);
39  // Note: see the above discussion for the fact that we consider
40  // negative user indices as "0"
41  pab.set_user_index(max(pa.user_index(),0) + max(pb.user_index(),0));
42  }
43 };
44 
45 //----------------------------------------------------------------------
46 // forward declaration for printing out info about a jet
47 //----------------------------------------------------------------------
48 ostream & operator<<(ostream &, const PseudoJet &);
49 
50 //----------------------------------------------------------------------
51 // get the hardest jet
52 //----------------------------------------------------------------------
53 PseudoJet hardest_jet(vector<PseudoJet> &particles){
54  double R = 1.2;
55  FlavourRecombiner *flav_recombiner=new FlavourRecombiner; // for tracking flavour
56  JetDefinition jet_def(cambridge_algorithm, R, flav_recombiner);
57  jet_def.delete_recombiner_when_unused();
58 
59  ClusterSequence *cs = new ClusterSequence(particles, jet_def);
60  vector<PseudoJet> jets = sorted_by_pt(cs->inclusive_jets());
62 
63  cout << "Ran: " << jet_def.description() << endl << endl;
64  cout << "Hardest jet: " << jets[0] << endl << endl;
65 
66  return jets[0];
67 }
68 
69 //----------------------------------------------------------------------
70 // core of the program
71 //----------------------------------------------------------------------
72 int main(){
73  vector<PseudoJet> particles;
74 
75  // read in data in format px py pz E b-tag [last of these is optional]
76  // lines starting with "#" are considered as comments and discarded
77  //----------------------------------------------------------
78 
79  string line;
80  while (getline(cin,line)) {
81  if (line.substr(0,1) == "#") {continue;}
82  istringstream linestream(line);
83  double px,py,pz,E;
84  linestream >> px >> py >> pz >> E;
85 
86  // optionally read in btag information
87  int btag;
88  if (! (linestream >> btag)) btag = 0;
89 
90  // construct the particle
91  PseudoJet particle(px,py,pz,E);
92  particle.set_user_index(btag); // btag info goes in user index, for flavour tracking
93  particles.push_back(particle);
94  }
95 
96 
97  // set up the jet finding
98  //
99  // This also shows how to use the "FlavourRecombiner" user-defined
100  // recombiner
101  // ----------------------------------------------------------
102  PseudoJet j = hardest_jet(particles);
103 
104  Recluster f1(kt_algorithm, 0.2);
105  PseudoJet fj1 = f1(j);
106  cout << "Recluster1 jet: " << fj1 << endl << endl;
107 
108  //delete the original CS
109  j=PseudoJet();
110 
111  Recluster f2(cambridge_algorithm, 1.0);
112  PseudoJet fj2 = f2(fj1);
113  cout << "Recluster1 jet: " << fj2 << endl << endl;
114 
115  return 0;
116 }
117 
118 //----------------------------------------------------------------------
119 // does the actual work for printing out a jet
120 //----------------------------------------------------------------------
121 ostream & operator<<(ostream & ostr, const PseudoJet & jet) {
122  ostr << "pt, y, phi ="
123  << " " << jet.perp()
124  << " " << jet.rap()
125  << " " << jet.phi()
126  << ", mass = " << jet.m()
127  << ", btag = " << jet.user_index();
128  return ostr;
129 }
double rap() const
returns the rapidity or some large value when the rapidity is infinite
Definition: PseudoJet.hh:123
vector< PseudoJet > sorted_by_pt(const vector< PseudoJet > &jets)
return a vector of jets sorted into decreasing kt2
Definition: PseudoJet.cc:770
void set_user_index(const int index)
set the user_index, intended to allow the user to add simple identifying information to a particle/je...
Definition: PseudoJet.hh:334
deals with clustering
std::vector< PseudoJet > inclusive_jets(const double ptmin=0.0) const
return a vector of all jets (in the sense of the inclusive algorithm) with pt >= ptmin.
ostream & operator<<(ostream &, PseudoJet &)
does the actual work for printing out a jet
A class that will provide the recombination scheme facilities and/or allow a user to extend these fac...
virtual std::string description() const
return a textual description of the recombination scheme implemented here
int main()
an example program showing how to use fastjet
Definition: 01-basic.cc:50
the FastJet namespace
RecombinationScheme
The various recombination schemes.
Recluster a jet&#39;s constituents with a new jet definition.
Definition: Recluster.hh:73
double phi() const
returns phi (in the range 0..2pi)
Definition: PseudoJet.hh:108
virtual void recombine(const PseudoJet &pa, const PseudoJet &pb, PseudoJet &pab) const
recombine pa and pb and put result into pab
int user_index() const
return the user_index,
Definition: PseudoJet.hh:331
double perp() const
returns the scalar transverse momentum
Definition: PseudoJet.hh:143
double m() const
returns the invariant mass (If m2() is negative then -sqrt(-m2()) is returned, as in CLHEP) ...
Definition: PseudoJet.hh:945
void delete_self_when_unused()
by calling this routine you tell the ClusterSequence to delete itself when all the Pseudojets associa...
Class to contain pseudojets, including minimal information of use to jet-clustering routines...
Definition: PseudoJet.hh:67
class that is intended to hold a full definition of the jet clusterer