Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PHPy8ParticleTrigger.C
Go to the documentation of this file.
1 #include "PHPy8ParticleTrigger.h"
2 
3 #include <Pythia8/Pythia.h>
4 
5 using namespace std;
6 
7 //__________________________________________________________
9  PHPy8GenTrigger(name),
10  _theEtaHigh(-999.9),
11  _theEtaLow(-999.9),
12  _thePtHigh(999.9),
13  _thePtLow(-999.9),
14  _thePHigh(999.9),
15  _thePLow(-999.9),
16  _thePxHigh(999.9),
17  _thePxLow(-999.9),
18  _thePyHigh(999.9),
19  _thePyLow(-999.9),
20  _thePzHigh(999.9),
21  _thePzLow(-999.9),
22 
23  _doEtaHighCut(false),
24  _doEtaLowCut(false),
25  _doBothEtaCut(false),
26 
27  _doAbsEtaHighCut(false),
28  _doAbsEtaLowCut(false),
29  _doBothAbsEtaCut(false),
30 
31  _doPtHighCut(false),
32  _doPtLowCut(false),
33  _doBothPtCut(false),
34 
35  _doPHighCut(false),
36  _doPLowCut(false),
37  _doBothPCut(false),
38 
39  _doPxHighCut(false),
40  _doPxLowCut(false),
41  _doBothPxCut(false),
42  _doPyHighCut(false),
43  _doPyLowCut(false),
44  _doBothPyCut(false),
45  _doPzHighCut(false),
46  _doPzLowCut(false),
47  _doBothPzCut(false)
48 {}
49 
51  if (_verbosity > 0) PrintConfig();
52 }
53 
54 bool PHPy8ParticleTrigger::Apply(Pythia8::Pythia *pythia) {
55 
56  if (_verbosity > 2) {
57  cout << "PHPy8ParticleTrigger::Apply - pythia event size: "
58  << pythia->event.size() << endl;
59  }
60 
61  // Loop over all particles in the event
62  for (int i = 0; i < pythia->event.size(); ++i) {
63 
64  // loop over all the trigger particle criteria
65  for (int j = 0; j < int(_theParticles.size()); j++) {
66 
67  bool passedParents = false;
68  if (pythia->event[i].id() == _theParticles[j] &&
69  pythia->event[i].status() > 0) { //only stable particles
70 
71  if (_doBothEtaCut && (pythia->event[i].eta() < _theEtaLow ||
72  pythia->event[i].eta() > _theEtaHigh)) continue;
73  if (_doEtaLowCut && pythia->event[i].eta() < _theEtaLow) continue;
74  if (_doEtaHighCut && pythia->event[i].eta() > _theEtaHigh) continue;
75 
76  if (_doBothAbsEtaCut && (abs(pythia->event[i].eta()) < _theEtaLow ||
77  abs(pythia->event[i].eta()) > _theEtaHigh)) continue;
78  if (_doAbsEtaLowCut && abs(pythia->event[i].eta()) < _theEtaLow) continue;
79  if (_doAbsEtaHighCut && abs(pythia->event[i].eta()) > _theEtaHigh) continue;
80 
81  if (_doBothPtCut && (pythia->event[i].pT() < _thePtLow ||
82  pythia->event[i].pT() > _thePtHigh)) continue;
83  if (_doPtHighCut && pythia->event[i].pT() > _thePtHigh ) continue;
84  if (_doPtLowCut && pythia->event[i].pT() < _thePtLow) continue;
85 
86  if (_doBothPCut && (pythia->event[i].pAbs() < _thePLow ||
87  pythia->event[i].pAbs() > _thePHigh)) continue;
88  if (_doPHighCut && pythia->event[i].pAbs() > _thePHigh ) continue;
89  if (_doPLowCut && pythia->event[i].pAbs() < _thePLow) continue;
90 
91  if (_doBothPxCut && (pythia->event[i].px() < _thePxLow ||
92  pythia->event[i].px() > _thePxHigh)) continue;
93  if (_doPxHighCut && pythia->event[i].px() > _thePxHigh ) continue;
94  if (_doPxLowCut && pythia->event[i].px() < _thePxLow) continue;
95 
96  if (_doBothPyCut && (pythia->event[i].py() < _thePyLow ||
97  pythia->event[i].py() > _thePyHigh)) continue;
98  if (_doPyHighCut && pythia->event[i].py() > _thePyHigh ) continue;
99  if (_doPyLowCut && pythia->event[i].py() < _thePyLow) continue;
100 
101  if (_doBothPzCut && (pythia->event[i].pz() < _thePzLow ||
102  pythia->event[i].pz() > _thePzHigh)) continue;
103  if (_doPzHighCut && pythia->event[i].pz() > _thePzHigh ) continue;
104  if (_doPzLowCut && pythia->event[i].pz() < _thePzLow) continue;
105 
106  if (_verbosity > 5) {
107  cout << "stable " << pythia->event[i].id()
108  << " pt: " << pythia->event[i].pT()
109  << " pz: " << pythia->event[i].pz()
110  << " p: " << pythia->event[i].pAbs()
111  << " eta: " << pythia->event[i].eta() << endl;
112  }
113 
114  // loop over all partents to this particle
115  for (int k = 0; k < int(_theParents.size()); k++) {
116  // check Mothers
117  std::vector<int> moms = pythia->event[i].motherList();
118  for (int m = 0; m < int(moms.size()) ; m++) {
119  if (abs(pythia->event[ moms[m] ].id()) == abs(_theParents[k])) {
120  passedParents = true;
121  if (_verbosity > 5) cout << "found parent!" << endl;
122  break;
123  }
124  }//moms for loop
125  if (passedParents) break;
126  }//parents for loop
127 
128  //If we made it here and it passes parents, success!
129  if (_theParents.size() == 0 || passedParents) return true;
130 
131  }//if _theParticles
132  }//_theParticles for loop
133 
134  }//pythia event for loop
135 
136  return false;
137 }
138 
139 void PHPy8ParticleTrigger::AddParticles(std::string particles) {
140  std::vector<int> addedParts = convertToInts(particles);
141  _theParticles.insert(_theParticles.end(),addedParts.begin(),addedParts.end());
142 }
143 
145  _theParticles.push_back(particle);
146 }
147 
148 void PHPy8ParticleTrigger::AddParticles(std::vector<int> particles) {
149  _theParticles.insert(_theParticles.end(),particles.begin(),particles.end());
150 }
151 
152 void PHPy8ParticleTrigger::AddParents(std::string parents) {
153  std::vector<int> addedParents = convertToInts(parents);
154  _theParents.insert(_theParents.end(),addedParents.begin(),addedParents.end());
155 }
156 
158  _theParents.push_back(parent);
159 }
160 
161 void PHPy8ParticleTrigger::AddParents(std::vector<int> parents) {
162  _theParents.insert(_theParents.end(),parents.begin(),parents.end());
163 }
164 
166  _thePtHigh = pt;
167  if (_doPtLowCut) _doBothPtCut = true;
168  else _doPtHighCut = true;
169 }
170 
172  _thePtLow = pt;
173  if (_doPtHighCut) _doBothPtCut = true;
174  else _doPtLowCut = true;
175 }
176 
177 void PHPy8ParticleTrigger::SetPtHighLow(double ptHigh, double ptLow) {
178  if (ptHigh < ptLow) {
179  _thePtHigh = ptLow;
180  _thePtLow = ptHigh;
181  } else {
182  _thePtHigh = ptHigh;
183  _thePtLow = ptLow;
184  }
185  _doBothPtCut = true;
186  _doPtLowCut = false;
187  _doPtHighCut = false;
188 }
189 
191  _thePHigh = p;
192  if (_doPLowCut) {
193  _doBothPCut = true;
194  _doPLowCut = false;
195  } else {
196  _doPHighCut = true;
197  }
198 }
199 
201  _thePLow = p;
202  if (_doPHighCut) {
203  _doBothPCut = true;
204  _doPHighCut = false;
205  } else {
206  _doPLowCut = true;
207  }
208 }
209 
210 void PHPy8ParticleTrigger::SetPHighLow(double pHigh, double pLow) {
211  if (pHigh < pLow) {
212  _thePHigh = pLow;
213  _thePLow= pHigh;
214  } else {
215  _thePHigh = pHigh;
216  _thePLow = pLow;
217  }
218  _doBothPCut = true;
219  _doPLowCut = false;
220  _doPHighCut = false;
221 }
222 
224  _theEtaHigh = eta;
225  if (_doEtaLowCut) {
226  _doBothEtaCut = true;
227  _doEtaLowCut = false;
228  } else {
229  _doEtaHighCut = true;
230  }
231 }
232 
234  _theEtaLow = eta;
235  if (_doEtaHighCut) {
236  _doBothEtaCut = true;
237  _doEtaHighCut = false;
238  } else {
239  _doEtaLowCut = true;
240  }
241 }
242 
243 void PHPy8ParticleTrigger::SetEtaHighLow(double etaHigh, double etaLow) {
244  _theEtaHigh = etaHigh;
245  _theEtaLow = etaLow;
246  _doBothEtaCut = true;
247  _doEtaHighCut = false;
248  _doEtaLowCut = false;
249 }
250 
252  _theEtaHigh = eta;
253  if (_doAbsEtaLowCut) {
254  _doBothAbsEtaCut = true;
255  _doAbsEtaLowCut = false;
256  } else {
257  _doAbsEtaHighCut = true;
258  }
259 }
260 
262  _theEtaLow = eta;
263  if (_doAbsEtaHighCut) {
264  _doBothAbsEtaCut = true;
265  _doAbsEtaHighCut = false;
266  } else {
267  _doAbsEtaLowCut = true;
268  }
269 }
270 
271 void PHPy8ParticleTrigger::SetAbsEtaHighLow(double etaHigh, double etaLow) {
272  _theEtaHigh = etaHigh;
273  _theEtaLow = etaLow;
274  _doBothAbsEtaCut = true;
275  _doAbsEtaLowCut = false;
276  _doAbsEtaHighCut = false;
277 }
278 
280  _thePxHigh = px;
281  if (_doPxLowCut) {
282  _doBothPxCut = true;
283  _doPxLowCut = false;
284  } else {
285  _doPxHighCut = true;
286  }
287 }
288 
290  _thePxLow = px;
291  if (_doPxHighCut) {
292  _doBothPxCut = true;
293  _doPxHighCut = false;
294  } else {
295  _doPxLowCut = true;
296  }
297 }
298 
299 void PHPy8ParticleTrigger::SetPxHighLow(double pxHigh, double pxLow) {
300  if (pxHigh < pxLow) {
301  _thePxHigh = pxLow;
302  _thePxLow= pxHigh;
303  } else {
304  _thePxHigh = pxHigh;
305  _thePxLow = pxLow;
306  }
307  _doBothPxCut = true;
308  _doPxLowCut = false;
309  _doPxHighCut = false;
310 }
311 
313  _thePyHigh = py;
314  if (_doPyLowCut) {
315  _doBothPyCut = true;
316  _doPyLowCut = false;
317  } else {
318  _doPyHighCut = true;
319  }
320 }
321 
323  _thePyLow = py;
324  if (_doPyHighCut) {
325  _doBothPyCut = true;
326  _doPyHighCut = false;
327  } else {
328  _doPyLowCut = true;
329  }
330 }
331 
332 void PHPy8ParticleTrigger::SetPyHighLow(double pyHigh, double pyLow) {
333  if (pyHigh < pyLow) {
334  _thePyHigh = pyLow;
335  _thePyLow= pyHigh;
336  } else {
337  _thePyHigh = pyHigh;
338  _thePyLow = pyLow;
339  }
340  _doBothPyCut = true;
341  _doPyLowCut = false;
342  _doPyHighCut = false;
343 }
344 
346  _thePzHigh = pz;
347  if (_doPzLowCut) {
348  _doBothPzCut = true;
349  _doPzLowCut = false;
350  } else {
351  _doPzHighCut = true;
352  }
353 }
354 
356  _thePzLow = pz;
357  if (_doPzHighCut) {
358  _doBothPzCut = true;
359  _doPzHighCut = false;
360  } else {
361  _doPzLowCut = true;
362  }
363 }
364 
365 void PHPy8ParticleTrigger::SetPzHighLow(double pzHigh, double pzLow) {
366  if (pzHigh < pzLow) {
367  _thePzHigh = pzLow;
368  _thePzLow= pzHigh;
369  } else {
370  _thePzHigh = pzHigh;
371  _thePzLow = pzLow;
372  }
373  _doBothPzCut = true;
374  _doPzLowCut = false;
375  _doPzHighCut = false;
376 }
377 
379  cout << "---------------- PHPy8ParticleTrigger::PrintConfig --------------------" << endl;
380  cout << " Particles: ";
381  for (int i = 0; i < int(_theParticles.size()); i++) cout << _theParticles[i] << " ";
382  cout << endl;
383 
384  cout << " Parents: ";
385  for (int i = 0; i < int(_theParents.size()); i++) cout << _theParents[i] << " ";
386  cout << endl;
387 
388  if (_doEtaHighCut||_doEtaLowCut||_doBothEtaCut)
389  cout << " doEtaCut: " << _theEtaLow << " < eta < " << _theEtaHigh << endl;
390  if (_doAbsEtaHighCut||_doAbsEtaLowCut||_doBothAbsEtaCut)
391  cout << " doAbsEtaCut: " << _theEtaLow << " < |eta| < " << _theEtaHigh << endl;
392  if (_doPtHighCut||_doPtLowCut||_doBothPtCut)
393  cout << " doPtCut: " << _thePtLow << " < pT < " << _thePtHigh << endl;
394  if (_doPHighCut||_doPLowCut||_doBothPCut)
395  cout << " doPCut: " << _thePLow << " < p < " << _thePHigh << endl;
396  if (_doPxHighCut||_doPxLowCut||_doBothPxCut)
397  cout << " doPxCut: " << _thePxLow << " < px < " << _thePxHigh << endl;
398  if (_doPyHighCut||_doPyLowCut||_doBothPyCut)
399  cout << " doPyCut: " << _thePyLow << " < py < " << _thePyHigh << endl;
400  if (_doPzHighCut||_doPzLowCut||_doBothPzCut)
401  cout << " doPzCut: " << _thePzLow << " < pz < " << _thePzHigh << endl;
402  cout << "-----------------------------------------------------------------------" << endl;
403 }
void AddParents(std::string parents)
bool Apply(Pythia8::Pythia *pythia)
void AddParticles(std::string particles)
void SetEtaHigh(double eta)
void SetPHighLow(double pHigh, double pLow)
void SetPyHighLow(double pzHigh, double pzLow)
void SetAbsEtaLow(double eta)
void SetPzHighLow(double pzHigh, double pzLow)
void SetAbsEtaHigh(double eta)
void SetEtaLow(double eta)
void SetPxHighLow(double pzHigh, double pzLow)
void SetEtaHighLow(double etaHigh, double etaLow)
std::vector< int > convertToInts(std::string s)
void SetAbsEtaHighLow(double etaHigh, double etaLow)
void SetPtHighLow(double ptHigh, double ptLow)
PHPy8ParticleTrigger(const std::string &name="PHPy8ParticleTrigger")