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