Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHPy6ParticleTrigger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHPy6ParticleTrigger.cc
1 #include "PHPy6ParticleTrigger.h"
2 #include "PHPy6GenTrigger.h"
3 
4 #pragma GCC diagnostic push
5 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6 #include <HepMC/GenEvent.h>
7 #include <HepMC/GenVertex.h> // for GenVertex, GenVertex::particles_in...
8 #pragma GCC diagnostic pop
9 
10 #include <HepMC/GenParticle.h> // for GenParticle
11 #include <HepMC/SimpleVector.h> // for FourVector
12 
13 #include <cmath> // for sqrt
14 #include <cstdlib> // for abs
15 #include <iostream>
16 
17 using namespace std;
18 
19 //___________________________________________________________________________
21  : PHPy6GenTrigger(name)
22  ,
23 
24  _theEtaHigh(-999.9)
25  , _theEtaLow(-999.9)
26  , _thePtHigh(999.9)
27  , _thePtLow(-999.9)
28  , _thePHigh(999.9)
29  , _thePLow(-999.9)
30  , _thePzHigh(999.9)
31  , _thePzLow(-999.9)
32  ,
33 
34  _doEtaHighCut(false)
35  , _doEtaLowCut(false)
36  , _doBothEtaCut(false)
37  ,
38 
39  _doAbsEtaHighCut(false)
40  , _doAbsEtaLowCut(false)
41  , _doBothAbsEtaCut(false)
42  ,
43 
44  _doPtHighCut(false)
45  , _doPtLowCut(false)
46  , _doBothPtCut(false)
47  ,
48 
49  _doPHighCut(false)
50  , _doPLowCut(false)
51  , _doBothPCut(false)
52  ,
53 
54  _doPzHighCut(false)
55  , _doPzLowCut(false)
56  , _doBothPzCut(false)
57 {
58 }
59 
60 bool PHPy6ParticleTrigger::Apply(const HepMC::GenEvent *evt)
61 {
62  // Print Out Trigger Information Once, for Posterity
63  static int trig_info_printed = 0;
64  if (trig_info_printed == 0)
65  {
66  PrintConfig();
67  trig_info_printed = 1;
68  }
69 
70  // for ( HepMC::GenEvent::particle_const_iterator p
71  // = evt->particles_begin(); p != evt->particles_end(); ++p ){
72  // if ( (abs((*p)->pdg_id()) == 11) && ((*p)->status()==1) &&
73  // ((*p)->momentum().pseudoRapidity() > eta_low) && ((*p)->momentum().pseudoRapidity() < eta_high) &&
74  // ( ) {
75  // if(((*p)->pdg_id()) == 11) n_em_found++;
76  // if(((*p)->pdg_id()) == -11) n_ep_found++;
77  // }
78  // }
79  //
80  // if( (RequireOR && ((n_em_found>=n_em_required)||(n_ep_found>=n_ep_required)) ) ||
81  // (RequireElectron && (n_em_found>=n_em_required)) ||
82  // (RequirePositron && (n_ep_found>=n_ep_required)) ||
83  // (RequireAND && (n_em_found>=n_em_required) && (n_ep_found>=n_ep_required)) ||
84  // (RequireCOMBO && (n_em_found+n_ep_found)>=n_comb_required) )
85  // {
86  // ++ntriggered_forward_electron;
87  // return true;
88  // }
89 
90  // Loop over all particles in the event
91  for (HepMC::GenEvent::particle_const_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p)
92  {
93  // loop over all the trigger particle criteria
94  for (int j = 0; j < int(_theParticles.size()); j++)
95  {
96  double p_pT = sqrt(pow((*p)->momentum().px(), 2) + pow((*p)->momentum().py(), 2));
97  double p_pAbs = sqrt(pow((*p)->momentum().px(), 2) + pow((*p)->momentum().py(), 2) + pow((*p)->momentum().pz(), 2));
98  if ((*p)->pdg_id() == _theParticles[j] &&
99  (*p)->status() == 1)
100  { //only stable particles
101 
102  if (_doBothEtaCut && ((*p)->momentum().eta() < _theEtaLow ||
103  (*p)->momentum().eta() > _theEtaHigh)) continue;
104  if (_doEtaLowCut && (*p)->momentum().eta() < _theEtaLow) continue;
105  if (_doEtaHighCut && (*p)->momentum().eta() > _theEtaHigh) continue;
106 
107  if (_doBothAbsEtaCut && (abs((*p)->momentum().eta()) < _theEtaLow ||
108  abs((*p)->momentum().eta()) > _theEtaHigh)) continue;
109  if (_doAbsEtaLowCut && abs((*p)->momentum().eta()) < _theEtaLow) continue;
110  if (_doAbsEtaHighCut && abs((*p)->momentum().eta()) > _theEtaHigh) continue;
111 
112  if (_doBothPtCut && (p_pT < _thePtLow ||
113  p_pT > _thePtHigh)) continue;
114  if (_doPtHighCut && p_pT > _thePtHigh) continue;
115  if (_doPtLowCut && p_pT < _thePtLow) continue;
116 
117  if (_doBothPCut && (p_pAbs < _thePLow ||
118  p_pAbs > _thePHigh)) continue;
119  if (_doPHighCut && p_pAbs > _thePHigh) continue;
120  if (_doPLowCut && p_pAbs < _thePLow) continue;
121 
122  if (_doBothPzCut && ((*p)->momentum().pz() < _thePzLow ||
123  (*p)->momentum().pz() > _thePzHigh)) continue;
124  if (_doPzHighCut && (*p)->momentum().pz() > _thePzHigh) continue;
125  if (_doPzLowCut && (*p)->momentum().pz() < _thePzLow) continue;
126 
127  if (Verbosity() > 5)
128  {
129  cout << "stable " << (*p)->pdg_id()
130  << " pt: " << p_pT
131  << " pz: " << (*p)->momentum().pz()
132  << " p: " << p_pAbs
133  << " eta: " << (*p)->momentum().eta() << endl;
134  }
135 
136  // loop over all partents to this particle
137  bool passedParents = false;
138  for (int k = 0; k < int(_theParents.size()); k++)
139  {
140  // check Mothers
141  for (HepMC::GenVertex::particles_in_const_iterator p_parent = (*p)->production_vertex()->particles_in_const_begin();
142  p_parent != (*p)->production_vertex()->particles_in_const_end();
143  ++p_parent)
144  {
145  if (abs((*p_parent)->pdg_id()) == abs(_theParents[k]))
146  {
147  passedParents = true;
148  if (Verbosity() > 5) cout << "found parent!" << endl;
149  break;
150  }
151  } //moms for loop
152  if (passedParents) break;
153  } //parents for loop
154 
155  //If we made it here and it passes parents, success!
156  if (_theParents.size() == 0 || passedParents) return true;
157 
158  } //if _theParticles
159  } //_theParticles for loop
160 
161  } //pythia event for loop
162 
163  return false;
164 }
165 
167 {
168  std::vector<int> addedParts = convertToInts(particles);
169  _theParticles.insert(_theParticles.end(), addedParts.begin(), addedParts.end());
170 }
171 
173 {
174  _theParticles.push_back(particle);
175 }
176 
178 {
179  _theParticles.insert(_theParticles.end(), particles.begin(), particles.end());
180 }
181 
183 {
184  std::vector<int> addedParents = convertToInts(parents);
185  _theParents.insert(_theParents.end(), addedParents.begin(), addedParents.end());
186 }
187 
189 {
190  _theParents.push_back(parent);
191 }
192 
193 void PHPy6ParticleTrigger::AddParents(std::vector<int> parents)
194 {
195  _theParents.insert(_theParents.end(), parents.begin(), parents.end());
196 }
197 
199 {
200  _thePtHigh = pt;
201  if (_doPtLowCut)
202  _doBothPtCut = true;
203  else
204  _doPtHighCut = true;
205 }
206 
208 {
209  _thePtLow = pt;
210  if (_doPtHighCut)
211  _doBothPtCut = true;
212  else
213  _doPtLowCut = true;
214 }
215 
216 void PHPy6ParticleTrigger::SetPtHighLow(double ptHigh, double ptLow)
217 {
218  if (ptHigh < ptLow)
219  {
220  _thePtHigh = ptLow;
221  _thePtLow = ptHigh;
222  }
223  else
224  {
225  _thePtHigh = ptHigh;
226  _thePtLow = ptLow;
227  }
228  _doBothPtCut = true;
229  _doPtLowCut = false;
230  _doPtHighCut = false;
231 }
232 
234 {
235  _thePHigh = p;
236  if (_doPLowCut)
237  {
238  _doBothPCut = true;
239  _doPLowCut = false;
240  }
241  else
242  {
243  _doPHighCut = true;
244  }
245 }
246 
248 {
249  _thePLow = p;
250  if (_doPHighCut)
251  {
252  _doBothPCut = true;
253  _doPHighCut = false;
254  }
255  else
256  {
257  _doPLowCut = true;
258  }
259 }
260 
261 void PHPy6ParticleTrigger::SetPHighLow(double pHigh, double pLow)
262 {
263  if (pHigh < pLow)
264  {
265  _thePHigh = pLow;
266  _thePLow = pHigh;
267  }
268  else
269  {
270  _thePHigh = pHigh;
271  _thePLow = pLow;
272  }
273  _doBothPCut = true;
274  _doPLowCut = false;
275  _doPHighCut = false;
276 }
277 
279 {
280  _theEtaHigh = eta;
281  if (_doEtaLowCut)
282  {
283  _doBothEtaCut = true;
284  _doEtaLowCut = false;
285  }
286  else
287  {
288  _doEtaHighCut = true;
289  }
290 }
291 
293 {
294  _theEtaLow = eta;
295  if (_doEtaHighCut)
296  {
297  _doBothEtaCut = true;
298  _doEtaHighCut = false;
299  }
300  else
301  {
302  _doEtaLowCut = true;
303  }
304 }
305 
306 void PHPy6ParticleTrigger::SetEtaHighLow(double etaHigh, double etaLow)
307 {
308  _theEtaHigh = etaHigh;
309  _theEtaLow = etaLow;
310  _doBothEtaCut = true;
311  _doEtaHighCut = false;
312  _doEtaLowCut = false;
313 }
314 
316 {
317  _theEtaHigh = eta;
318  if (_doAbsEtaLowCut)
319  {
320  _doBothAbsEtaCut = true;
321  _doAbsEtaLowCut = false;
322  }
323  else
324  {
325  _doAbsEtaHighCut = true;
326  }
327 }
328 
330 {
331  _theEtaLow = eta;
332  if (_doAbsEtaHighCut)
333  {
334  _doBothAbsEtaCut = true;
335  _doAbsEtaHighCut = false;
336  }
337  else
338  {
339  _doAbsEtaLowCut = true;
340  }
341 }
342 
343 void PHPy6ParticleTrigger::SetAbsEtaHighLow(double etaHigh, double etaLow)
344 {
345  _theEtaHigh = etaHigh;
346  _theEtaLow = etaLow;
347  _doBothAbsEtaCut = true;
348  _doAbsEtaLowCut = false;
349  _doAbsEtaHighCut = false;
350 }
351 
353 {
354  _thePzHigh = pz;
355  if (_doPzLowCut)
356  {
357  _doBothPzCut = true;
358  _doPzLowCut = false;
359  }
360  else
361  {
362  _doPzHighCut = true;
363  }
364 }
365 
367 {
368  _thePzLow = pz;
369  if (_doPzHighCut)
370  {
371  _doBothPzCut = true;
372  _doPzHighCut = false;
373  }
374  else
375  {
376  _doPzLowCut = true;
377  }
378 }
379 
380 void PHPy6ParticleTrigger::SetPzHighLow(double pzHigh, double pzLow)
381 {
382  if (pzHigh < pzLow)
383  {
384  _thePzHigh = pzLow;
385  _thePzLow = pzHigh;
386  }
387  else
388  {
389  _thePzHigh = pzHigh;
390  _thePzLow = pzLow;
391  }
392  _doBothPzCut = true;
393  _doPzLowCut = false;
394  _doPzHighCut = false;
395 }
396 
398 {
399  cout << "---------------- PHPy6ParticleTrigger::PrintConfig --------------------" << endl;
400  cout << " Particles: ";
401  for (int i = 0; i < int(_theParticles.size()); i++) cout << _theParticles[i] << " ";
402  cout << endl;
403 
404  cout << " Parents: ";
405  for (int i = 0; i < int(_theParents.size()); i++) cout << _theParents[i] << " ";
406  cout << endl;
407 
409  cout << " doEtaCut: " << _theEtaLow << " < eta < " << _theEtaHigh << endl;
411  cout << " doAbsEtaCut: " << _theEtaLow << " < |eta| < " << _theEtaHigh << endl;
413  cout << " doPtCut: " << _thePtLow << " < pT < " << _thePtHigh << endl;
415  cout << " doPCut: " << _thePLow << " < p < " << _thePHigh << endl;
417  cout << " doPzCut: " << _thePzLow << " < pz < " << _thePzHigh << endl;
418  cout << "-----------------------------------------------------------------------" << endl;
419 }