Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PHPy8JetTrigger.C
Go to the documentation of this file.
1 #include "PHPy8JetTrigger.h"
2 
3 #include <Pythia8/Pythia.h>
4 
5 // fastjet includes
6 #include <fastjet/JetDefinition.hh>
7 #include <fastjet/PseudoJet.hh>
8 #include <fastjet/ClusterSequence.hh>
9 #include <fastjet/SISConePlugin.hh>
10 #include <cassert>
11 
12 using namespace std;
13 
14 //__________________________________________________________
15 PHPy8JetTrigger::PHPy8JetTrigger(const std::string &name):
16  PHPy8GenTrigger(name),
17  _theEtaHigh(4.0),
18  _theEtaLow(1.0),
19  _minPt(10.0),
20  _minZ(0.0),
21  _R(1.0)
22  {}
23 
25  if (_verbosity > 0) PrintConfig();
26 }
27 
28 bool PHPy8JetTrigger::Apply(Pythia8::Pythia *pythia) {
29 
30  if (_verbosity > 2) {
31  cout << "PHPy8JetTrigger::Apply - pythia event size: "
32  << pythia->event.size() << endl;
33  }
34 
35  // Loop over all particles in the event
36  std::vector<fastjet::PseudoJet> pseudojets;
37  for (int i = 0; i < pythia->event.size(); ++i) {
38 
39  if (pythia->event[i].status() > 0) { //only stable particles
40 
41  // remove some particles (muons, taus, neutrinos)...
42  // 12 == nu_e
43  // 13 == muons
44  // 14 == nu_mu
45  // 15 == taus
46  // 16 == nu_tau
47  if ((abs(pythia->event[i].id()) >= 12) && (abs(pythia->event[i].id()) <= 16)) continue;
48 
49  // remove acceptance... _etamin,_etamax
50  if ((pythia->event[i].px() == 0.0) && (pythia->event[i].py() == 0.0)) continue; // avoid pt=0
51  if ( (pythia->event[i].eta() < _theEtaLow ||
52  pythia->event[i].eta() > _theEtaHigh)) continue;
53 
54 
55  fastjet::PseudoJet pseudojet (pythia->event[i].px(),
56  pythia->event[i].py(),
57  pythia->event[i].pz(),
58  pythia->event[i].e());
59  pseudojet.set_user_index(i);
60  pseudojets.push_back(pseudojet);
61 
62  }
63 
64  }
65 
66  // Call FastJet
67 
68  fastjet::JetDefinition *jetdef = new fastjet::JetDefinition(fastjet::antikt_algorithm,_R, fastjet::E_scheme,fastjet::Best);
69  fastjet::ClusterSequence jetFinder(pseudojets,*jetdef);
70  std::vector<fastjet::PseudoJet> fastjets = jetFinder.inclusive_jets();
71  delete jetdef;
72 
73  bool jetFound = false;
74  double max_pt = -1;
75  for (unsigned int ijet = 0; ijet < fastjets.size(); ++ijet) {
76 
77  const double pt = sqrt(pow(fastjets[ijet].px(),2) + pow(fastjets[ijet].py(),2));
78 
79  if (pt > max_pt) max_pt = pt;
80 
81  if(pt > _minPt){
82 
83  if(_minZ>0.0){
84 
85  // Loop over constituents, caluclate the z of the leading particle
86 
87  float leading_Z = 0.0;
88 
89  float jet_ptot = sqrt( pow(fastjets[ijet].px(),2) +
90  pow(fastjets[ijet].py(),2) +
91  pow(fastjets[ijet].pz(),2) );
92 
93  vector<fastjet::PseudoJet> constituents = fastjets[ijet].constituents();
94  for (unsigned int j=0; j<constituents.size(); j++){
95 
96  float con_ptot = sqrt( pow(constituents[j].px(),2) +
97  pow(constituents[j].py(),2) +
98  pow(constituents[j].pz(),2) );
99 
100  float ctheta = (constituents[j].px()*fastjets[ijet].px() +
101  constituents[j].py()*fastjets[ijet].py() +
102  constituents[j].pz()*fastjets[ijet].pz())/(con_ptot*jet_ptot);
103 
104  float z_constit = con_ptot*ctheta/jet_ptot;
105 
106  if(z_constit>leading_Z) leading_Z = z_constit;
107 
108  }
109 
110  if(leading_Z>_minZ){
111  jetFound = true;
112  break;
113  }
114 
115  }
116  else {
117  jetFound = true;
118  break;
119  }
120  }
121  }
122 
123  if (_verbosity > 2) {
124  cout << "PHPy8JetTrigger::Apply - max_pt = "<<max_pt<<", and jetFound = "<<jetFound<<endl;
125  }
126 
127  return jetFound;
128 }
129 
130 void PHPy8JetTrigger::SetEtaHighLow(double etaHigh, double etaLow) {
131 
132  _theEtaHigh = etaHigh;
133  _theEtaLow = etaLow;
134 
135  if (_theEtaHigh<_theEtaLow)
136  {
137  swap(_theEtaHigh, _theEtaLow);
138  }
139 
140 }
141 
142 void PHPy8JetTrigger::SetMinJetPt(double minPt) {
143  _minPt = minPt;
144 }
145 
147  _minZ = minZ;
148 }
149 
150 void PHPy8JetTrigger::SetJetR(double R) {
151  _R = R;
152 }
153 
155  cout << "---------------- PHPy8JetTrigger::PrintConfig --------------------" << endl;
156 
157  cout << " Particles EtaCut: " << _theEtaLow << " < eta < " << _theEtaHigh << endl;
158  cout << " Minimum Jet pT: " << _minPt << " GeV/c" << endl;
159  cout << " Anti-kT Radius: " << _R << endl;
160  cout << "-----------------------------------------------------------------------" << endl;
161 }
void SetEtaHighLow(double etaHigh, double etaLow)
bool Apply(Pythia8::Pythia *pythia)
void swap(array< T, N > &x, array< T, N > &y)
Definition: array.hpp:366
void SetJetR(double R)
PHPy8JetTrigger(const std::string &name="PHPy8JetTrigger")
void SetMinLeadingZ(double minZ)
void SetMinJetPt(double minPt)
virtual ~PHPy8JetTrigger()