ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FastJetAlgo.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FastJetAlgo.cc
1 
2 #include "FastJetAlgo.h"
3 
4 #include "Jet.h"
5 #include "Jetv1.h"
6 
7 // fastjet includes
8 #include <fastjet/ClusterSequence.hh>
9 #include <fastjet/JetDefinition.hh>
10 #include <fastjet/PseudoJet.hh>
11 
12 // SoftDrop includes
13 #include <fastjet/contrib/SoftDrop.hh>
14 
15 // standard includes
16 #include <iostream>
17 #include <map> // for _Rb_tree_iterator
18 #include <memory> // for allocator_traits<>::value_type
19 #include <utility> // for pair
20 #include <vector>
21 
22 FastJetAlgo::FastJetAlgo(Jet::ALGO algo, float par, int verbosity)
23  : _verbosity(verbosity)
24  , _algo(algo)
25  , _par(par)
26  , _do_SD(false)
27  , _SD_beta(0)
28  , _SD_zcut(0.1)
29 {
30  fastjet::ClusterSequence clusseq;
31  if (_verbosity > 0)
32  {
33  clusseq.print_banner();
34  }
35  else
36  {
37  std::ostringstream nullstream;
38  clusseq.set_fastjet_banner_stream(&nullstream);
39  clusseq.print_banner();
40  clusseq.set_fastjet_banner_stream(&std::cout);
41  }
42 }
43 
44 void FastJetAlgo::identify(std::ostream& os)
45 {
46  os << " FastJetAlgo: ";
47  if (_algo == Jet::ANTIKT)
48  os << "ANTIKT r=" << _par;
49  else if (_algo == Jet::KT)
50  os << "KT r=" << _par;
51  else if (_algo == Jet::CAMBRIDGE)
52  os << "CAMBRIDGE r=" << _par;
53  os << std::endl;
54 }
55 
56 std::vector<Jet*> FastJetAlgo::get_jets(std::vector<Jet*> particles)
57 {
58  if (_verbosity > 1) std::cout << "FastJetAlgo::process_event -- entered" << std::endl;
59 
60  // translate to fastjet
61  std::vector<fastjet::PseudoJet> pseudojets;
62  for (unsigned int ipart = 0; ipart < particles.size(); ++ipart)
63  {
64  // fastjet performs strangely with exactly (px,py,pz,E) =
65  // (0,0,0,0) inputs, such as placeholder towers or those with
66  // zero'd out energy after CS. this catch also in FastJetAlgoSub
67  if (particles[ipart]->get_e() == 0.) continue;
68 
69  fastjet::PseudoJet pseudojet(particles[ipart]->get_px(),
70  particles[ipart]->get_py(),
71  particles[ipart]->get_pz(),
72  particles[ipart]->get_e());
73  pseudojet.set_user_index(ipart);
74  pseudojets.push_back(pseudojet);
75  }
76 
77  // run fast jet
78  fastjet::JetDefinition* jetdef = nullptr;
79  if (_algo == Jet::ANTIKT)
80  jetdef = new fastjet::JetDefinition(fastjet::antikt_algorithm, _par, fastjet::E_scheme, fastjet::Best);
81  else if (_algo == Jet::KT)
82  jetdef = new fastjet::JetDefinition(fastjet::kt_algorithm, _par, fastjet::E_scheme, fastjet::Best);
83  else if (_algo == Jet::CAMBRIDGE)
84  jetdef = new fastjet::JetDefinition(fastjet::cambridge_algorithm, _par, fastjet::E_scheme, fastjet::Best);
85  else
86  return std::vector<Jet*>();
87  fastjet::ClusterSequence jetFinder(pseudojets, *jetdef);
88  std::vector<fastjet::PseudoJet> fastjets = jetFinder.inclusive_jets();
89  delete jetdef;
90 
91  fastjet::contrib::SoftDrop sd( _SD_beta, _SD_zcut );
92  if ( _verbosity > 5 )
93  std::cout << "FastJetAlgo::get_jets : created SoftDrop groomer configuration : " << sd.description() << std::endl;
94 
95  // translate into jet output...
96  std::vector<Jet*> jets;
97  for (unsigned int ijet = 0; ijet < fastjets.size(); ++ijet)
98  {
99  Jet* jet = new Jetv1();
100  jet->set_px(fastjets[ijet].px());
101  jet->set_py(fastjets[ijet].py());
102  jet->set_pz(fastjets[ijet].pz());
103  jet->set_e(fastjets[ijet].e());
104  jet->set_id(ijet);
105 
106  // if SoftDrop enabled, and jets have > 5 GeV (do not waste time
107  // on very low-pT jets), run SD and pack output into jet properties
108  if ( _do_SD && fastjets[ijet].perp() > 5 ) {
109 
110  fastjet::PseudoJet sd_jet = sd( fastjets[ijet] );
111 
112  if ( _verbosity > 5 ) {
113  std::cout << "original jet: pt / eta / phi / m = " << fastjets[ijet].perp() << " / " << fastjets[ijet].eta() << " / " << fastjets[ijet].phi() << " / " << fastjets[ijet].m() << std::endl;
114  std::cout << "SoftDropped jet: pt / eta / phi / m = " << sd_jet.perp() << " / " << sd_jet.eta() << " / " << sd_jet.phi() << " / " << sd_jet.m() << std::endl;
115 
116  std::cout << " delta_R between subjets: " << sd_jet.structure_of<fastjet::contrib::SoftDrop>().delta_R() << std::endl;
117  std::cout << " symmetry measure(z): " << sd_jet.structure_of<fastjet::contrib::SoftDrop>().symmetry() << std::endl;
118  std::cout << " mass drop(mu): " << sd_jet.structure_of<fastjet::contrib::SoftDrop>().mu() << std::endl;
119  }
120 
121  // attach SoftDrop quantities as jet properties
122  jet->set_property( Jet::PROPERTY::prop_zg , sd_jet.structure_of<fastjet::contrib::SoftDrop>().symmetry() );
123  jet->set_property( Jet::PROPERTY::prop_Rg , sd_jet.structure_of<fastjet::contrib::SoftDrop>().delta_R() );
124  jet->set_property( Jet::PROPERTY::prop_mu , sd_jet.structure_of<fastjet::contrib::SoftDrop>().mu() );
125 
126  }
127 
128  // copy components into output jet
129  std::vector<fastjet::PseudoJet> comps = fastjets[ijet].constituents();
130  for (unsigned int icomp = 0; icomp < comps.size(); ++icomp)
131  {
132  Jet* particle = particles[comps[icomp].user_index()];
133 
134  for (Jet::Iter iter = particle->begin_comp();
135  iter != particle->end_comp();
136  ++iter)
137  {
138  jet->insert_comp(iter->first, iter->second);
139  }
140  }
141 
142  jets.push_back(jet);
143  }
144 
145  if (_verbosity > 1) std::cout << "FastJetAlgo::process_event -- exited" << std::endl;
146 
147  return jets;
148 }