Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FastJetAlgoSub.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FastJetAlgoSub.cc
1 
2 #include "FastJetAlgoSub.h"
3 
4 #include <jetbase/Jet.h>
5 #include <jetbase/Jetv2.h>
6 #include <jetbase/JetContainer.h>
7 
8 // fastjet includes
9 #include <fastjet/ClusterSequence.hh>
10 #include <fastjet/JetDefinition.hh>
11 #include <fastjet/PseudoJet.hh>
12 
13 // standard includes
14 #include <cstddef>
15 #include <iostream>
16 #include <map>
17 #include <memory>
18 #include <utility>
19 #include <vector>
20 
21 using namespace std;
22 
24  : _verbosity(verbosity)
25  , _algo(algo)
26  , _par(par)
27 {
28  fastjet::ClusterSequence clusseq;
29  if (_verbosity > 0)
30  {
31  clusseq.print_banner();
32  }
33  else
34  {
35  ostringstream nullstream;
36  clusseq.set_fastjet_banner_stream(&nullstream);
37  clusseq.print_banner();
38  clusseq.set_fastjet_banner_stream(&cout);
39  }
40 }
41 
42 void FastJetAlgoSub::identify(std::ostream& os)
43 {
44  os << " FastJetAlgoSub: ";
45  if (_algo == Jet::ANTIKT)
46  os << "ANTIKT r=" << _par;
47  else if (_algo == Jet::KT)
48  os << "KT r=" << _par;
49  else if (_algo == Jet::CAMBRIDGE)
50  os << "CAMBRIDGE r=" << _par;
51  os << endl;
52 }
53 
54 /* std::vector<Jet*> FastJetAlgoSub::get_jets(std::vector<Jet*> particles) */
55 /* { }; // deprecated by iterating from JetMap; now is JetContainer and most code moved into */
56  // into cluster_and_fill
57 
58 void FastJetAlgoSub::cluster_and_fill(std::vector<Jet*>& particles, JetContainer* jetcont)
59 {
60  if (_verbosity > 1) cout << "FastJetAlgoSub::process_event -- entered" << endl;
61 
62  // translate to fastjet
63  std::vector<fastjet::PseudoJet> pseudojets;
64  for (unsigned int ipart = 0; ipart < particles.size(); ++ipart)
65  {
66  float this_e = particles[ipart]->get_e();
67 
68  if (this_e == 0.) continue;
69 
70  float this_px = particles[ipart]->get_px();
71  float this_py = particles[ipart]->get_py();
72  float this_pz = particles[ipart]->get_pz();
73 
74  if (this_e < 0)
75  {
76  // make energy = +1 MeV for purposes of clustering
77  float e_ratio = 0.001 / this_e;
78 
79  this_e = this_e * e_ratio;
80  this_px = this_px * e_ratio;
81  this_py = this_py * e_ratio;
82  this_pz = this_pz * e_ratio;
83 
84  if (_verbosity > 5)
85  {
86  std::cout << " FastJetAlgoSub input particle with negative-E, original kinematics px / py / pz / E = ";
87  std::cout << particles[ipart]->get_px() << " / " << particles[ipart]->get_py() << " / " << particles[ipart]->get_pz() << " / " << particles[ipart]->get_e() << std::endl;
88  std::cout << " --> entering with modified kinematics px / py / pz / E = " << this_px << " / " << this_py << " / " << this_pz << " / " << this_e << std::endl;
89  }
90  }
91 
92  fastjet::PseudoJet pseudojet(this_px, this_py, this_pz, this_e);
93 
94  pseudojet.set_user_index(ipart);
95  pseudojets.push_back(pseudojet);
96  }
97 
98  // run fast jet
99  fastjet::JetDefinition* jetdef = NULL;
100  if (_algo == Jet::ANTIKT)
101  jetdef = new fastjet::JetDefinition(fastjet::antikt_algorithm, _par, fastjet::E_scheme, fastjet::Best);
102  else if (_algo == Jet::KT)
103  jetdef = new fastjet::JetDefinition(fastjet::kt_algorithm, _par, fastjet::E_scheme, fastjet::Best);
104  else if (_algo == Jet::CAMBRIDGE)
105  jetdef = new fastjet::JetDefinition(fastjet::cambridge_algorithm, _par, fastjet::E_scheme, fastjet::Best);
106  else
107  return;
108 
109  fastjet::ClusterSequence jetFinder(pseudojets, *jetdef);
110  std::vector<fastjet::PseudoJet> fastjets = jetFinder.inclusive_jets();
111  delete jetdef;
112 
113  // translate into jet output...
114  std::vector<Jet*> jets;
115  for (unsigned int ijet = 0; ijet < fastjets.size(); ++ijet)
116  {
117  auto jet = jetcont->add_jet();
118 
119  if (_verbosity > 5 && fastjets[ijet].perp() > 15)
120  {
121  std::cout << " FastJetAlgoSub : jet # " << ijet << " comes out of clustering with pt / eta / phi = " << fastjets[ijet].perp() << " / " << fastjets[ijet].eta() << " / " << fastjets[ijet].phi();
122  std::cout << ", px / py / pz / e = " << fastjets[ijet].px() << " / " << fastjets[ijet].py() << " / " << fastjets[ijet].pz() << " / " << fastjets[ijet].e() << std::endl;
123  }
124 
125  float total_px = 0;
126  float total_py = 0;
127  float total_pz = 0;
128  float total_e = 0;
129 
130  // copy components into output jet
131  std::vector<fastjet::PseudoJet> comps = fastjets[ijet].constituents();
132  for (unsigned int icomp = 0; icomp < comps.size(); ++icomp)
133  {
134  Jet* particle = particles[comps[icomp].user_index()];
135 
136  total_px += particle->get_px();
137  total_py += particle->get_py();
138  total_pz += particle->get_pz();
139  total_e += particle->get_e();
140  jet->insert_comp(particle->get_comp_vec(), true);
141  }
142 
143  jet->set_comp_sort_flag(); // make sure jet know comps might not be sorted
144  // alternatively can just ommit the `true`
145  // in insert_comp call above
146  jet->set_px(total_px);
147  jet->set_py(total_py);
148  jet->set_pz(total_pz);
149  jet->set_e(total_e);
150  jet->set_id(ijet);
151 
152  if (_verbosity > 5 && fastjets[ijet].perp() > 15)
153  {
154  std::cout << " FastJetAlgoSub : jet # " << ijet << " after correcting for proper constituent kinematics, pt / eta / phi = " << jet->get_pt() << " / " << jet->get_eta() << " / " << jet->get_phi();
155  std::cout << ", px / py / pz / e = " << jet->get_px() << " / " << jet->get_py() << " / " << jet->get_pz() << " / " << jet->get_e() << std::endl;
156  }
157  }
158 
159  if (_verbosity > 1) cout << "FastJetAlgoSub::process_event -- exited" << endl;
160  return;
161 }