Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHPy8ParticleTrigger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHPy8ParticleTrigger.cc
1 #include "PHPy8ParticleTrigger.h"
2 
3 #include <Pythia8/Event.h> // for Event, Particle
4 #include <Pythia8/Pythia.h>
5 
6 #include <algorithm> // for max
7 #include <cstdlib> // for abs
8 #include <iostream> // for operator<<, endl, basic_ostream, basic_o...
9 
10 using namespace std;
11 
12 //__________________________________________________________
14  : PHPy8GenTrigger(name)
15  , _theEtaHigh(-999.9)
16  , _theEtaLow(-999.9)
17  , _thePtHigh(999.9)
18  , _thePtLow(-999.9)
19  , _thePHigh(999.9)
20  , _thePLow(-999.9)
21  , _thePzHigh(999.9)
22  , _thePzLow(-999.9)
23  ,
24 
25  _doEtaHighCut(false)
26  , _doEtaLowCut(false)
27  , _doBothEtaCut(false)
28  ,
29 
30  _doAbsEtaHighCut(false)
31  , _doAbsEtaLowCut(false)
32  , _doBothAbsEtaCut(false)
33  ,
34 
35  _doPtHighCut(false)
36  , _doPtLowCut(false)
37  , _doBothPtCut(false)
38  ,
39 
40  _doPHighCut(false)
41  , _doPLowCut(false)
42  , _doBothPCut(false)
43  ,
44 
45  _doPzHighCut(false)
46  , _doPzLowCut(false)
47  , _doBothPzCut(false)
48 {
49 }
50 
52 {
53  if (Verbosity() > 0)
54  {
55  PrintConfig();
56  }
57 }
58 
59 bool PHPy8ParticleTrigger::Apply(Pythia8::Pythia *pythia)
60 {
61  if (Verbosity() > 2)
62  {
63  cout << "PHPy8ParticleTrigger::Apply - pythia event size: "
64  << pythia->event.size() << endl;
65  }
66 
67  // Loop over all particles in the event
68  for (int i = 0; i < pythia->event.size(); ++i)
69  {
70  // loop over all the trigger particle criteria
71  for (int j = 0; j < int(_theParticles.size()); j++)
72  {
73  if (pythia->event[i].id() == _theParticles[j] &&
74  (pythia->event[i].status() > 0 //only stable particles
75  or (not m_doStableParticleOnly) // or not
76  ))
77  {
78  if (_doBothYCut && (pythia->event[i].y() < _theYLow ||
79  pythia->event[i].y() > _theYHigh))
80  {
81  continue;
82  }
83  if (_doYLowCut && pythia->event[i].y() < _theYLow)
84  {
85  continue;
86  }
87  if (_doYHighCut && pythia->event[i].y() > _theYHigh)
88  {
89  continue;
90  }
91 
92  if (_doBothEtaCut && (pythia->event[i].eta() < _theEtaLow ||
93  pythia->event[i].eta() > _theEtaHigh))
94  {
95  continue;
96  }
97  if (_doEtaLowCut && pythia->event[i].eta() < _theEtaLow)
98  {
99  continue;
100  }
101  if (_doEtaHighCut && pythia->event[i].eta() > _theEtaHigh)
102  {
103  continue;
104  }
105 
106  if (_doBothAbsEtaCut && (abs(pythia->event[i].eta()) < _theEtaLow ||
107  abs(pythia->event[i].eta()) > _theEtaHigh))
108  {
109  continue;
110  }
111  if (_doAbsEtaLowCut && abs(pythia->event[i].eta()) < _theEtaLow)
112  {
113  continue;
114  }
115  if (_doAbsEtaHighCut && abs(pythia->event[i].eta()) > _theEtaHigh)
116  {
117  continue;
118  }
119 
120  if (_doBothPtCut && (pythia->event[i].pT() < _thePtLow ||
121  pythia->event[i].pT() > _thePtHigh))
122  {
123  continue;
124  }
125  if (_doPtHighCut && pythia->event[i].pT() > _thePtHigh)
126  {
127  continue;
128  }
129  if (_doPtLowCut && pythia->event[i].pT() < _thePtLow)
130  {
131  continue;
132  }
133 
134  if (_doBothPCut && (pythia->event[i].pAbs() < _thePLow ||
135  pythia->event[i].pAbs() > _thePHigh))
136  {
137  continue;
138  }
139  if (_doPHighCut && pythia->event[i].pAbs() > _thePHigh)
140  {
141  continue;
142  }
143  if (_doPLowCut && pythia->event[i].pAbs() < _thePLow)
144  {
145  continue;
146  }
147 
148  if (_doBothPzCut && (pythia->event[i].pz() < _thePzLow ||
149  pythia->event[i].pz() > _thePzHigh))
150  {
151  continue;
152  }
153  if (_doPzHighCut && pythia->event[i].pz() > _thePzHigh)
154  {
155  continue;
156  }
157  if (_doPzLowCut && pythia->event[i].pz() < _thePzLow)
158  {
159  continue;
160  }
161 
162  if (Verbosity() > 5)
163  {
164  cout << "stable " << pythia->event[i].id()
165  << " pt: " << pythia->event[i].pT()
166  << " pz: " << pythia->event[i].pz()
167  << " p: " << pythia->event[i].pAbs()
168  << " eta: " << pythia->event[i].eta()
169  << " y: " << pythia->event[i].y() << endl;
170  }
171 
172  // loop over all partents to this particle
173  bool passedParents = false;
174  for (int k = 0; k < int(_theParents.size()); k++)
175  {
176  // check Mothers
177  std::vector<int> moms = pythia->event[i].motherList();
178  for (int m = 0; m < int(moms.size()); m++)
179  {
180  if (abs(pythia->event[moms[m]].id()) == abs(_theParents[k]))
181  {
182  passedParents = true;
183  if (Verbosity() > 5)
184  {
185  cout << "found parent!" << endl;
186  }
187  break;
188  }
189  } //moms for loop
190  if (passedParents)
191  {
192  break;
193  }
194  } //parents for loop
195 
196  //If we made it here and it passes parents, success!
197  if (_theParents.size() == 0 || passedParents)
198  {
199  return true;
200  }
201 
202  } //if _theParticles
203  } //_theParticles for loop
204 
205  } //pythia event for loop
206 
207  return false;
208 }
209 
211 {
212  std::vector<int> addedParts = convertToInts(particles);
213  _theParticles.insert(_theParticles.end(), addedParts.begin(), addedParts.end());
214 }
215 
217 {
218  _theParticles.push_back(particle);
219 }
220 
222 {
223  _theParticles.insert(_theParticles.end(), particles.begin(), particles.end());
224 }
225 
227 {
228  std::vector<int> addedParents = convertToInts(parents);
229  _theParents.insert(_theParents.end(), addedParents.begin(), addedParents.end());
230 }
231 
233 {
234  _theParents.push_back(parent);
235 }
236 
237 void PHPy8ParticleTrigger::AddParents(std::vector<int> parents)
238 {
239  _theParents.insert(_theParents.end(), parents.begin(), parents.end());
240 }
241 
243 {
244  _thePtHigh = pt;
245  if (_doPtLowCut)
246  {
247  _doBothPtCut = true;
248  }
249  else
250  {
251  _doPtHighCut = true;
252  }
253 }
254 
256 {
257  _thePtLow = pt;
258  if (_doPtHighCut)
259  {
260  _doBothPtCut = true;
261  }
262  else
263  {
264  _doPtLowCut = true;
265  }
266 }
267 
268 void PHPy8ParticleTrigger::SetPtHighLow(double ptHigh, double ptLow)
269 {
270  if (ptHigh < ptLow)
271  {
272  _thePtHigh = ptLow;
273  _thePtLow = ptHigh;
274  }
275  else
276  {
277  _thePtHigh = ptHigh;
278  _thePtLow = ptLow;
279  }
280  _doBothPtCut = true;
281  _doPtLowCut = false;
282  _doPtHighCut = false;
283 }
284 
286 {
287  _thePHigh = p;
288  if (_doPLowCut)
289  {
290  _doBothPCut = true;
291  _doPLowCut = false;
292  }
293  else
294  {
295  _doPHighCut = true;
296  }
297 }
298 
300 {
301  _thePLow = p;
302  if (_doPHighCut)
303  {
304  _doBothPCut = true;
305  _doPHighCut = false;
306  }
307  else
308  {
309  _doPLowCut = true;
310  }
311 }
312 
313 void PHPy8ParticleTrigger::SetPHighLow(double pHigh, double pLow)
314 {
315  if (pHigh < pLow)
316  {
317  _thePHigh = pLow;
318  _thePLow = pHigh;
319  }
320  else
321  {
322  _thePHigh = pHigh;
323  _thePLow = pLow;
324  }
325  _doBothPCut = true;
326  _doPLowCut = false;
327  _doPHighCut = false;
328 }
329 
331 {
332  _theYHigh = Y;
333  if (_doYLowCut)
334  {
335  _doBothYCut = true;
336  _doYLowCut = false;
337  }
338  else
339  {
340  _doYHighCut = true;
341  }
342 }
343 
345 {
346  _theYLow = Y;
347  if (_doYHighCut)
348  {
349  _doBothYCut = true;
350  _doYHighCut = false;
351  }
352  else
353  {
354  _doYLowCut = true;
355  }
356 }
357 
358 void PHPy8ParticleTrigger::SetYHighLow(double YHigh, double YLow)
359 {
360  _theYHigh = YHigh;
361  _theYLow = YLow;
362  _doBothYCut = true;
363  _doYHighCut = false;
364  _doYLowCut = false;
365 }
366 
368 {
369  _theEtaHigh = eta;
370  if (_doEtaLowCut)
371  {
372  _doBothEtaCut = true;
373  _doEtaLowCut = false;
374  }
375  else
376  {
377  _doEtaHighCut = true;
378  }
379 }
380 
382 {
383  _theEtaLow = eta;
384  if (_doEtaHighCut)
385  {
386  _doBothEtaCut = true;
387  _doEtaHighCut = false;
388  }
389  else
390  {
391  _doEtaLowCut = true;
392  }
393 }
394 
395 void PHPy8ParticleTrigger::SetEtaHighLow(double etaHigh, double etaLow)
396 {
397  _theEtaHigh = etaHigh;
398  _theEtaLow = etaLow;
399  _doBothEtaCut = true;
400  _doEtaHighCut = false;
401  _doEtaLowCut = false;
402 }
403 
405 {
406  _theEtaHigh = eta;
407  if (_doAbsEtaLowCut)
408  {
409  _doBothAbsEtaCut = true;
410  _doAbsEtaLowCut = false;
411  }
412  else
413  {
414  _doAbsEtaHighCut = true;
415  }
416 }
417 
419 {
420  _theEtaLow = eta;
421  if (_doAbsEtaHighCut)
422  {
423  _doBothAbsEtaCut = true;
424  _doAbsEtaHighCut = false;
425  }
426  else
427  {
428  _doAbsEtaLowCut = true;
429  }
430 }
431 
432 void PHPy8ParticleTrigger::SetAbsEtaHighLow(double etaHigh, double etaLow)
433 {
434  _theEtaHigh = etaHigh;
435  _theEtaLow = etaLow;
436  _doBothAbsEtaCut = true;
437  _doAbsEtaLowCut = false;
438  _doAbsEtaHighCut = false;
439 }
440 
442 {
443  _thePzHigh = pz;
444  if (_doPzLowCut)
445  {
446  _doBothPzCut = true;
447  _doPzLowCut = false;
448  }
449  else
450  {
451  _doPzHighCut = true;
452  }
453 }
454 
456 {
457  _thePzLow = pz;
458  if (_doPzHighCut)
459  {
460  _doBothPzCut = true;
461  _doPzHighCut = false;
462  }
463  else
464  {
465  _doPzLowCut = true;
466  }
467 }
468 
469 void PHPy8ParticleTrigger::SetPzHighLow(double pzHigh, double pzLow)
470 {
471  if (pzHigh < pzLow)
472  {
473  _thePzHigh = pzLow;
474  _thePzLow = pzHigh;
475  }
476  else
477  {
478  _thePzHigh = pzHigh;
479  _thePzLow = pzLow;
480  }
481  _doBothPzCut = true;
482  _doPzLowCut = false;
483  _doPzHighCut = false;
484 }
485 
487 {
488  cout << "---------------- PHPy8ParticleTrigger::PrintConfig --------------------" << endl;
489 
491  {
492  cout << "Process stable particles only." << endl;
493  }
494  else
495  {
496  cout << "Process both unstable and stable particles." << endl;
497  }
498 
499  cout << " Particles: ";
500  for (int i = 0; i < int(_theParticles.size()); i++)
501  {
502  cout << _theParticles[i] << " ";
503  }
504  cout << endl;
505 
506  cout << " Parents: ";
507  for (int i = 0; i < int(_theParents.size()); i++)
508  {
509  cout << _theParents[i] << " ";
510  }
511  cout << endl;
512 
514  {
515  cout << " doYCut: " << _theYLow << " < Y < " << _theYHigh << endl;
516  }
518  {
519  cout << " doEtaCut: " << _theEtaLow << " < eta < " << _theEtaHigh << endl;
520  }
522  {
523  cout << " doAbsEtaCut: " << _theEtaLow << " < |eta| < " << _theEtaHigh << endl;
524  }
526  {
527  cout << " doPtCut: " << _thePtLow << " < pT < " << _thePtHigh << endl;
528  }
530  {
531  cout << " doPCut: " << _thePLow << " < p < " << _thePHigh << endl;
532  }
534  {
535  cout << " doPzCut: " << _thePzLow << " < pz < " << _thePzHigh << endl;
536  }
537  cout << "-----------------------------------------------------------------------" << endl;
538 }