ECCE @ EIC 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) PrintConfig();
54 }
55 
56 bool PHPy8ParticleTrigger::Apply(Pythia8::Pythia *pythia)
57 {
58  if (Verbosity() > 2)
59  {
60  cout << "PHPy8ParticleTrigger::Apply - pythia event size: "
61  << pythia->event.size() << endl;
62  }
63 
64  // Loop over all particles in the event
65  for (int i = 0; i < pythia->event.size(); ++i)
66  {
67  // loop over all the trigger particle criteria
68  for (int j = 0; j < int(_theParticles.size()); j++)
69  {
70  if (pythia->event[i].id() == _theParticles[j] &&
71  (pythia->event[i].status() > 0 //only stable particles
72  or (not m_doStableParticleOnly) // or not
73  ))
74  {
75  if (_doBothYCut && (pythia->event[i].y() < _theYLow ||
76  pythia->event[i].y() > _theYHigh)) continue;
77  if (_doYLowCut && pythia->event[i].y() < _theYLow) continue;
78  if (_doYHighCut && pythia->event[i].y() > _theYHigh) continue;
79 
80  if (_doBothEtaCut && (pythia->event[i].eta() < _theEtaLow ||
81  pythia->event[i].eta() > _theEtaHigh)) continue;
82  if (_doEtaLowCut && pythia->event[i].eta() < _theEtaLow) continue;
83  if (_doEtaHighCut && pythia->event[i].eta() > _theEtaHigh) continue;
84 
85  if (_doBothAbsEtaCut && (abs(pythia->event[i].eta()) < _theEtaLow ||
86  abs(pythia->event[i].eta()) > _theEtaHigh)) continue;
87  if (_doAbsEtaLowCut && abs(pythia->event[i].eta()) < _theEtaLow) continue;
88  if (_doAbsEtaHighCut && abs(pythia->event[i].eta()) > _theEtaHigh) continue;
89 
90  if (_doBothPtCut && (pythia->event[i].pT() < _thePtLow ||
91  pythia->event[i].pT() > _thePtHigh)) continue;
92  if (_doPtHighCut && pythia->event[i].pT() > _thePtHigh) continue;
93  if (_doPtLowCut && pythia->event[i].pT() < _thePtLow) continue;
94 
95  if (_doBothPCut && (pythia->event[i].pAbs() < _thePLow ||
96  pythia->event[i].pAbs() > _thePHigh)) continue;
97  if (_doPHighCut && pythia->event[i].pAbs() > _thePHigh) continue;
98  if (_doPLowCut && pythia->event[i].pAbs() < _thePLow) continue;
99 
100  if (_doBothPzCut && (pythia->event[i].pz() < _thePzLow ||
101  pythia->event[i].pz() > _thePzHigh)) continue;
102  if (_doPzHighCut && pythia->event[i].pz() > _thePzHigh) continue;
103  if (_doPzLowCut && pythia->event[i].pz() < _thePzLow) continue;
104 
105  if (Verbosity() > 5)
106  {
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()
112  << " y: " << pythia->event[i].y() << endl;
113  }
114 
115  // loop over all partents to this particle
116  bool passedParents = false;
117  for (int k = 0; k < int(_theParents.size()); k++)
118  {
119  // check Mothers
120  std::vector<int> moms = pythia->event[i].motherList();
121  for (int m = 0; m < int(moms.size()); m++)
122  {
123  if (abs(pythia->event[moms[m]].id()) == abs(_theParents[k]))
124  {
125  passedParents = true;
126  if (Verbosity() > 5) cout << "found parent!" << endl;
127  break;
128  }
129  } //moms for loop
130  if (passedParents) break;
131  } //parents for loop
132 
133  //If we made it here and it passes parents, success!
134  if (_theParents.size() == 0 || passedParents) return true;
135 
136  } //if _theParticles
137  } //_theParticles for loop
138 
139  } //pythia event for loop
140 
141  return false;
142 }
143 
144 void PHPy8ParticleTrigger::AddParticles(const std::string &particles)
145 {
146  std::vector<int> addedParts = convertToInts(particles);
147  _theParticles.insert(_theParticles.end(), addedParts.begin(), addedParts.end());
148 }
149 
151 {
152  _theParticles.push_back(particle);
153 }
154 
155 void PHPy8ParticleTrigger::AddParticles(std::vector<int> particles)
156 {
157  _theParticles.insert(_theParticles.end(), particles.begin(), particles.end());
158 }
159 
160 void PHPy8ParticleTrigger::AddParents(const std::string &parents)
161 {
162  std::vector<int> addedParents = convertToInts(parents);
163  _theParents.insert(_theParents.end(), addedParents.begin(), addedParents.end());
164 }
165 
167 {
168  _theParents.push_back(parent);
169 }
170 
171 void PHPy8ParticleTrigger::AddParents(std::vector<int> parents)
172 {
173  _theParents.insert(_theParents.end(), parents.begin(), parents.end());
174 }
175 
177 {
178  _thePtHigh = pt;
179  if (_doPtLowCut)
180  _doBothPtCut = true;
181  else
182  _doPtHighCut = true;
183 }
184 
186 {
187  _thePtLow = pt;
188  if (_doPtHighCut)
189  _doBothPtCut = true;
190  else
191  _doPtLowCut = true;
192 }
193 
194 void PHPy8ParticleTrigger::SetPtHighLow(double ptHigh, double ptLow)
195 {
196  if (ptHigh < ptLow)
197  {
198  _thePtHigh = ptLow;
199  _thePtLow = ptHigh;
200  }
201  else
202  {
203  _thePtHigh = ptHigh;
204  _thePtLow = ptLow;
205  }
206  _doBothPtCut = true;
207  _doPtLowCut = false;
208  _doPtHighCut = false;
209 }
210 
212 {
213  _thePHigh = p;
214  if (_doPLowCut)
215  {
216  _doBothPCut = true;
217  _doPLowCut = false;
218  }
219  else
220  {
221  _doPHighCut = true;
222  }
223 }
224 
226 {
227  _thePLow = p;
228  if (_doPHighCut)
229  {
230  _doBothPCut = true;
231  _doPHighCut = false;
232  }
233  else
234  {
235  _doPLowCut = true;
236  }
237 }
238 
239 void PHPy8ParticleTrigger::SetPHighLow(double pHigh, double pLow)
240 {
241  if (pHigh < pLow)
242  {
243  _thePHigh = pLow;
244  _thePLow = pHigh;
245  }
246  else
247  {
248  _thePHigh = pHigh;
249  _thePLow = pLow;
250  }
251  _doBothPCut = true;
252  _doPLowCut = false;
253  _doPHighCut = false;
254 }
255 
257 {
258  _theYHigh = Y;
259  if (_doYLowCut)
260  {
261  _doBothYCut = true;
262  _doYLowCut = false;
263  }
264  else
265  {
266  _doYHighCut = true;
267  }
268 }
269 
271 {
272  _theYLow = Y;
273  if (_doYHighCut)
274  {
275  _doBothYCut = true;
276  _doYHighCut = false;
277  }
278  else
279  {
280  _doYLowCut = true;
281  }
282 }
283 
284 void PHPy8ParticleTrigger::SetYHighLow(double YHigh, double YLow)
285 {
286  _theYHigh = YHigh;
287  _theYLow = YLow;
288  _doBothYCut = true;
289  _doYHighCut = false;
290  _doYLowCut = false;
291 }
292 
294 {
295  _theEtaHigh = eta;
296  if (_doEtaLowCut)
297  {
298  _doBothEtaCut = true;
299  _doEtaLowCut = false;
300  }
301  else
302  {
303  _doEtaHighCut = true;
304  }
305 }
306 
308 {
309  _theEtaLow = eta;
310  if (_doEtaHighCut)
311  {
312  _doBothEtaCut = true;
313  _doEtaHighCut = false;
314  }
315  else
316  {
317  _doEtaLowCut = true;
318  }
319 }
320 
321 void PHPy8ParticleTrigger::SetEtaHighLow(double etaHigh, double etaLow)
322 {
323  _theEtaHigh = etaHigh;
324  _theEtaLow = etaLow;
325  _doBothEtaCut = true;
326  _doEtaHighCut = false;
327  _doEtaLowCut = false;
328 }
329 
331 {
332  _theEtaHigh = eta;
333  if (_doAbsEtaLowCut)
334  {
335  _doBothAbsEtaCut = true;
336  _doAbsEtaLowCut = false;
337  }
338  else
339  {
340  _doAbsEtaHighCut = true;
341  }
342 }
343 
345 {
346  _theEtaLow = eta;
347  if (_doAbsEtaHighCut)
348  {
349  _doBothAbsEtaCut = true;
350  _doAbsEtaHighCut = false;
351  }
352  else
353  {
354  _doAbsEtaLowCut = true;
355  }
356 }
357 
358 void PHPy8ParticleTrigger::SetAbsEtaHighLow(double etaHigh, double etaLow)
359 {
360  _theEtaHigh = etaHigh;
361  _theEtaLow = etaLow;
362  _doBothAbsEtaCut = true;
363  _doAbsEtaLowCut = false;
364  _doAbsEtaHighCut = false;
365 }
366 
368 {
369  _thePzHigh = pz;
370  if (_doPzLowCut)
371  {
372  _doBothPzCut = true;
373  _doPzLowCut = false;
374  }
375  else
376  {
377  _doPzHighCut = true;
378  }
379 }
380 
382 {
383  _thePzLow = pz;
384  if (_doPzHighCut)
385  {
386  _doBothPzCut = true;
387  _doPzHighCut = false;
388  }
389  else
390  {
391  _doPzLowCut = true;
392  }
393 }
394 
395 void PHPy8ParticleTrigger::SetPzHighLow(double pzHigh, double pzLow)
396 {
397  if (pzHigh < pzLow)
398  {
399  _thePzHigh = pzLow;
400  _thePzLow = pzHigh;
401  }
402  else
403  {
404  _thePzHigh = pzHigh;
405  _thePzLow = pzLow;
406  }
407  _doBothPzCut = true;
408  _doPzLowCut = false;
409  _doPzHighCut = false;
410 }
411 
413 {
414  cout << "---------------- PHPy8ParticleTrigger::PrintConfig --------------------" << endl;
415 
417  cout << "Process stable particles only." << endl;
418  else
419  cout << "Process both unstable and stable particles." << endl;
420 
421  cout << " Particles: ";
422  for (int i = 0; i < int(_theParticles.size()); i++) cout << _theParticles[i] << " ";
423  cout << endl;
424 
425  cout << " Parents: ";
426  for (int i = 0; i < int(_theParents.size()); i++) cout << _theParents[i] << " ";
427  cout << endl;
428 
430  cout << " doYCut: " << _theYLow << " < Y < " << _theYHigh << endl;
432  cout << " doEtaCut: " << _theEtaLow << " < eta < " << _theEtaHigh << endl;
434  cout << " doAbsEtaCut: " << _theEtaLow << " < |eta| < " << _theEtaHigh << endl;
436  cout << " doPtCut: " << _thePtLow << " < pT < " << _thePtHigh << endl;
438  cout << " doPCut: " << _thePLow << " < p < " << _thePHigh << endl;
440  cout << " doPzCut: " << _thePzLow << " < pz < " << _thePzHigh << endl;
441  cout << "-----------------------------------------------------------------------" << endl;
442 }