Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHPy8JetTrigger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHPy8JetTrigger.cc
1 #include "PHPy8JetTrigger.h"
2 
3 #include <Pythia8/Event.h> // for Event, Particle
4 #include <Pythia8/Pythia.h>
5 
6 // fastjet includes
7 #include <fastjet/ClusterSequence.hh>
8 #include <fastjet/JetDefinition.hh>
9 #include <fastjet/PseudoJet.hh>
10 
11 #include <algorithm> // for max
12 #include <cmath> // for sqrt
13 #include <cstdlib> // for abs
14 #include <iostream> // for operator<<, endl, basic_ostream
15 #include <memory> // for allocator_traits<>::value_type
16 #include <utility> // for swap
17 #include <vector> // for vector
18 
19 using namespace std;
20 
21 //__________________________________________________________
23  : PHPy8GenTrigger(name)
24  , _theEtaHigh(4.0)
25  , _theEtaLow(1.0)
26  , _minPt(10.0)
27  , _minZ(0.0)
28  , _R(1.0)
29  , _nconst(0)
30 {
31 }
32 
34 {
35  if (Verbosity() > 0)
36  {
37  PrintConfig();
38  }
39 }
40 
41 bool PHPy8JetTrigger::Apply(Pythia8::Pythia *pythia)
42 {
43  if (Verbosity() > 2)
44  {
45  cout << "PHPy8JetTrigger::Apply - pythia event size: "
46  << pythia->event.size() << endl;
47  }
48 
49  // Loop over all particles in the event
50  std::vector<fastjet::PseudoJet> pseudojets;
51  for (int i = 0; i < pythia->event.size(); ++i)
52  {
53  if (pythia->event[i].status() > 0)
54  { //only stable particles
55 
56  // remove some particles (muons, taus, neutrinos)...
57  // 12 == nu_e
58  // 13 == muons
59  // 14 == nu_mu
60  // 15 == taus
61  // 16 == nu_tau
62  if ((abs(pythia->event[i].id()) >= 12) && (abs(pythia->event[i].id()) <= 16))
63  {
64  continue;
65  }
66 
67  // remove acceptance... _etamin,_etamax
68  if ((pythia->event[i].px() == 0.0) && (pythia->event[i].py() == 0.0))
69  {
70  continue; // avoid pt=0
71  }
72  if ((pythia->event[i].eta() < _theEtaLow ||
73  pythia->event[i].eta() > _theEtaHigh))
74  {
75  continue;
76  }
77 
78  fastjet::PseudoJet pseudojet(pythia->event[i].px(),
79  pythia->event[i].py(),
80  pythia->event[i].pz(),
81  pythia->event[i].e());
82  pseudojet.set_user_index(i);
83  pseudojets.push_back(pseudojet);
84  }
85  }
86 
87  // Call FastJet
88 
89  fastjet::JetDefinition *jetdef = new fastjet::JetDefinition(fastjet::antikt_algorithm, _R, fastjet::E_scheme, fastjet::Best);
90  fastjet::ClusterSequence jetFinder(pseudojets, *jetdef);
91  std::vector<fastjet::PseudoJet> fastjets = jetFinder.inclusive_jets();
92  delete jetdef;
93 
94  bool jetFound = false;
95  double max_pt = -1;
96  for (unsigned int ijet = 0; ijet < fastjets.size(); ++ijet)
97  {
98  const double pt = sqrt(fastjets[ijet].px() * fastjets[ijet].px() + fastjets[ijet].py() * fastjets[ijet].py());
99 
100  if (pt > max_pt)
101  {
102  max_pt = pt;
103  }
104 
105  vector<fastjet::PseudoJet> constituents = fastjets[ijet].constituents();
106  int ijet_nconst = constituents.size();
107 
108  if (pt > _minPt && ijet_nconst >= _nconst)
109  {
110  if (_minZ > 0.0)
111  {
112  // Loop over constituents, calculate the z of the leading particle
113 
114  double leading_Z = 0.0;
115 
116  double jet_ptot = sqrt(fastjets[ijet].px() * fastjets[ijet].px() +
117  fastjets[ijet].py() * fastjets[ijet].py() +
118  fastjets[ijet].pz() * fastjets[ijet].pz());
119 
120  for (unsigned int j = 0; j < constituents.size(); j++)
121  {
122  double con_ptot = sqrt(constituents[j].px() * constituents[j].px() +
123  constituents[j].py() * constituents[j].py() +
124  constituents[j].pz() * constituents[j].pz());
125 
126  double ctheta = (constituents[j].px() * fastjets[ijet].px() +
127  constituents[j].py() * fastjets[ijet].py() +
128  constituents[j].pz() * fastjets[ijet].pz()) /
129  (con_ptot * jet_ptot);
130 
131  double z_constit = con_ptot * ctheta / jet_ptot;
132 
133  if (z_constit > leading_Z)
134  {
135  leading_Z = z_constit;
136  }
137  }
138 
139  if (leading_Z > _minZ)
140  {
141  jetFound = true;
142  break;
143  }
144  }
145  else
146  {
147  jetFound = true;
148  break;
149  }
150  }
151  }
152 
153  if (Verbosity() > 2)
154  {
155  cout << "PHPy8JetTrigger::Apply - max_pt = " << max_pt << ", and jetFound = " << jetFound << endl;
156  }
157 
158  return jetFound;
159 }
160 
161 void PHPy8JetTrigger::SetEtaHighLow(double etaHigh, double etaLow)
162 {
163  _theEtaHigh = etaHigh;
164  _theEtaLow = etaLow;
165 
166  if (_theEtaHigh < _theEtaLow)
167  {
169  }
170 }
171 
173 {
174  _minPt = minPt;
175 }
176 
178 {
179  _minZ = minZ;
180 }
181 
183 {
184  _R = R;
185 }
186 
188 {
189  _nconst = nconst;
190 }
191 
193 {
194  cout << "---------------- PHPy8JetTrigger::PrintConfig --------------------" << endl;
195 
196  cout << " Particles EtaCut: " << _theEtaLow << " < eta < " << _theEtaHigh << endl;
197  cout << " Minimum Jet pT: " << _minPt << " GeV/c" << endl;
198  cout << " Anti-kT Radius: " << _R << endl;
199  cout << "-----------------------------------------------------------------------" << endl;
200 }