File indexing completed on 2025-08-05 08:16:00
0001 #include "PHPy8ParticleTrigger.h"
0002
0003 #include <Pythia8/Event.h> // for Event, Particle
0004 #include <Pythia8/Pythia.h>
0005
0006 #include <algorithm> // for max
0007 #include <cstdlib> // for abs
0008 #include <iostream> // for operator<<, endl, basic_ostream, basic_o...
0009
0010
0011 PHPy8ParticleTrigger::PHPy8ParticleTrigger(const std::string &name)
0012 : PHPy8GenTrigger(name)
0013 , _theEtaHigh(-999.9)
0014 , _theEtaLow(-999.9)
0015 , _thePtHigh(999.9)
0016 , _thePtLow(-999.9)
0017 , _thePHigh(999.9)
0018 , _thePLow(-999.9)
0019 , _thePzHigh(999.9)
0020 , _thePzLow(-999.9)
0021 ,
0022
0023 _doEtaHighCut(false)
0024 , _doEtaLowCut(false)
0025 , _doBothEtaCut(false)
0026 ,
0027
0028 _doAbsEtaHighCut(false)
0029 , _doAbsEtaLowCut(false)
0030 , _doBothAbsEtaCut(false)
0031 ,
0032
0033 _doPtHighCut(false)
0034 , _doPtLowCut(false)
0035 , _doBothPtCut(false)
0036 ,
0037
0038 _doPHighCut(false)
0039 , _doPLowCut(false)
0040 , _doBothPCut(false)
0041 ,
0042
0043 _doPzHighCut(false)
0044 , _doPzLowCut(false)
0045 , _doBothPzCut(false)
0046 {
0047 }
0048
0049 PHPy8ParticleTrigger::~PHPy8ParticleTrigger()
0050 {
0051 if (Verbosity() > 0)
0052 {
0053 PrintConfig();
0054 }
0055 }
0056
0057 bool PHPy8ParticleTrigger::Apply(Pythia8::Pythia *pythia)
0058 {
0059 if (Verbosity() > 2)
0060 {
0061 std::cout << "PHPy8ParticleTrigger::Apply - pythia event size: "
0062 << pythia->event.size() << std::endl;
0063 }
0064
0065
0066 for (int i = 0; i < pythia->event.size(); ++i)
0067 {
0068
0069 for (int _theParticle : _theParticles)
0070 {
0071 if (pythia->event[i].id() == _theParticle &&
0072 (pythia->event[i].status() > 0
0073 or (not m_doStableParticleOnly)
0074 ))
0075 {
0076 if (_doBothYCut && (pythia->event[i].y() < _theYLow ||
0077 pythia->event[i].y() > _theYHigh))
0078 {
0079 continue;
0080 }
0081 if (_doYLowCut && pythia->event[i].y() < _theYLow)
0082 {
0083 continue;
0084 }
0085 if (_doYHighCut && pythia->event[i].y() > _theYHigh)
0086 {
0087 continue;
0088 }
0089
0090 if (_doBothEtaCut && (pythia->event[i].eta() < _theEtaLow ||
0091 pythia->event[i].eta() > _theEtaHigh))
0092 {
0093 continue;
0094 }
0095 if (_doEtaLowCut && pythia->event[i].eta() < _theEtaLow)
0096 {
0097 continue;
0098 }
0099 if (_doEtaHighCut && pythia->event[i].eta() > _theEtaHigh)
0100 {
0101 continue;
0102 }
0103
0104 if (_doBothAbsEtaCut && (std::abs(pythia->event[i].eta()) < _theEtaLow ||
0105 std::abs(pythia->event[i].eta()) > _theEtaHigh))
0106 {
0107 continue;
0108 }
0109 if (_doAbsEtaLowCut && std::abs(pythia->event[i].eta()) < _theEtaLow)
0110 {
0111 continue;
0112 }
0113 if (_doAbsEtaHighCut && std::abs(pythia->event[i].eta()) > _theEtaHigh)
0114 {
0115 continue;
0116 }
0117
0118 if (_doBothPtCut && (pythia->event[i].pT() < _thePtLow ||
0119 pythia->event[i].pT() > _thePtHigh))
0120 {
0121 continue;
0122 }
0123 if (_doPtHighCut && pythia->event[i].pT() > _thePtHigh)
0124 {
0125 continue;
0126 }
0127 if (_doPtLowCut && pythia->event[i].pT() < _thePtLow)
0128 {
0129 continue;
0130 }
0131
0132 if (_doBothPCut && (pythia->event[i].pAbs() < _thePLow ||
0133 pythia->event[i].pAbs() > _thePHigh))
0134 {
0135 continue;
0136 }
0137 if (_doPHighCut && pythia->event[i].pAbs() > _thePHigh)
0138 {
0139 continue;
0140 }
0141 if (_doPLowCut && pythia->event[i].pAbs() < _thePLow)
0142 {
0143 continue;
0144 }
0145
0146 if (_doBothPzCut && (pythia->event[i].pz() < _thePzLow ||
0147 pythia->event[i].pz() > _thePzHigh))
0148 {
0149 continue;
0150 }
0151 if (_doPzHighCut && pythia->event[i].pz() > _thePzHigh)
0152 {
0153 continue;
0154 }
0155 if (_doPzLowCut && pythia->event[i].pz() < _thePzLow)
0156 {
0157 continue;
0158 }
0159
0160 if (Verbosity() > 5)
0161 {
0162 std::cout << "stable " << pythia->event[i].id()
0163 << " pt: " << pythia->event[i].pT()
0164 << " pz: " << pythia->event[i].pz()
0165 << " p: " << pythia->event[i].pAbs()
0166 << " eta: " << pythia->event[i].eta()
0167 << " y: " << pythia->event[i].y() << std::endl;
0168 }
0169
0170
0171 bool passedParents = false;
0172 for (int _theParent : _theParents)
0173 {
0174
0175 std::vector<int> moms = pythia->event[i].motherList();
0176 for (int mom : moms)
0177 {
0178 if (std::abs(pythia->event[mom].id()) == std::abs(_theParent))
0179 {
0180 passedParents = true;
0181 if (Verbosity() > 5)
0182 {
0183 std::cout << "found parent!" << std::endl;
0184 }
0185 break;
0186 }
0187 }
0188 if (passedParents)
0189 {
0190 break;
0191 }
0192 }
0193
0194
0195 if (_theParents.size() == 0 || passedParents)
0196 {
0197 return true;
0198 }
0199
0200 }
0201 }
0202
0203 }
0204
0205 return false;
0206 }
0207
0208 void PHPy8ParticleTrigger::AddParticles(const std::string &particles)
0209 {
0210 std::vector<int> addedParts = convertToInts(particles);
0211 _theParticles.insert(_theParticles.end(), addedParts.begin(), addedParts.end());
0212 }
0213
0214 void PHPy8ParticleTrigger::AddParticles(int particle)
0215 {
0216 _theParticles.push_back(particle);
0217 }
0218
0219 void PHPy8ParticleTrigger::AddParticles(std::vector<int> particles)
0220 {
0221 _theParticles.insert(_theParticles.end(), particles.begin(), particles.end());
0222 }
0223
0224 void PHPy8ParticleTrigger::AddParents(const std::string &parents)
0225 {
0226 std::vector<int> addedParents = convertToInts(parents);
0227 _theParents.insert(_theParents.end(), addedParents.begin(), addedParents.end());
0228 }
0229
0230 void PHPy8ParticleTrigger::AddParents(int parent)
0231 {
0232 _theParents.push_back(parent);
0233 }
0234
0235 void PHPy8ParticleTrigger::AddParents(std::vector<int> parents)
0236 {
0237 _theParents.insert(_theParents.end(), parents.begin(), parents.end());
0238 }
0239
0240 void PHPy8ParticleTrigger::SetPtHigh(double pt)
0241 {
0242 _thePtHigh = pt;
0243 if (_doPtLowCut)
0244 {
0245 _doBothPtCut = true;
0246 }
0247 else
0248 {
0249 _doPtHighCut = true;
0250 }
0251 }
0252
0253 void PHPy8ParticleTrigger::SetPtLow(double pt)
0254 {
0255 _thePtLow = pt;
0256 if (_doPtHighCut)
0257 {
0258 _doBothPtCut = true;
0259 }
0260 else
0261 {
0262 _doPtLowCut = true;
0263 }
0264 }
0265
0266 void PHPy8ParticleTrigger::SetPtHighLow(double ptHigh, double ptLow)
0267 {
0268 if (ptHigh < ptLow)
0269 {
0270 _thePtHigh = ptLow;
0271 _thePtLow = ptHigh;
0272 }
0273 else
0274 {
0275 _thePtHigh = ptHigh;
0276 _thePtLow = ptLow;
0277 }
0278 _doBothPtCut = true;
0279 _doPtLowCut = false;
0280 _doPtHighCut = false;
0281 }
0282
0283 void PHPy8ParticleTrigger::SetPHigh(double p)
0284 {
0285 _thePHigh = p;
0286 if (_doPLowCut)
0287 {
0288 _doBothPCut = true;
0289 _doPLowCut = false;
0290 }
0291 else
0292 {
0293 _doPHighCut = true;
0294 }
0295 }
0296
0297 void PHPy8ParticleTrigger::SetPLow(double p)
0298 {
0299 _thePLow = p;
0300 if (_doPHighCut)
0301 {
0302 _doBothPCut = true;
0303 _doPHighCut = false;
0304 }
0305 else
0306 {
0307 _doPLowCut = true;
0308 }
0309 }
0310
0311 void PHPy8ParticleTrigger::SetPHighLow(double pHigh, double pLow)
0312 {
0313 if (pHigh < pLow)
0314 {
0315 _thePHigh = pLow;
0316 _thePLow = pHigh;
0317 }
0318 else
0319 {
0320 _thePHigh = pHigh;
0321 _thePLow = pLow;
0322 }
0323 _doBothPCut = true;
0324 _doPLowCut = false;
0325 _doPHighCut = false;
0326 }
0327
0328 void PHPy8ParticleTrigger::SetYHigh(double Y)
0329 {
0330 _theYHigh = Y;
0331 if (_doYLowCut)
0332 {
0333 _doBothYCut = true;
0334 _doYLowCut = false;
0335 }
0336 else
0337 {
0338 _doYHighCut = true;
0339 }
0340 }
0341
0342 void PHPy8ParticleTrigger::SetYLow(double Y)
0343 {
0344 _theYLow = Y;
0345 if (_doYHighCut)
0346 {
0347 _doBothYCut = true;
0348 _doYHighCut = false;
0349 }
0350 else
0351 {
0352 _doYLowCut = true;
0353 }
0354 }
0355
0356 void PHPy8ParticleTrigger::SetYHighLow(double YHigh, double YLow)
0357 {
0358 _theYHigh = YHigh;
0359 _theYLow = YLow;
0360 _doBothYCut = true;
0361 _doYHighCut = false;
0362 _doYLowCut = false;
0363 }
0364
0365 void PHPy8ParticleTrigger::SetEtaHigh(double eta)
0366 {
0367 _theEtaHigh = eta;
0368 if (_doEtaLowCut)
0369 {
0370 _doBothEtaCut = true;
0371 _doEtaLowCut = false;
0372 }
0373 else
0374 {
0375 _doEtaHighCut = true;
0376 }
0377 }
0378
0379 void PHPy8ParticleTrigger::SetEtaLow(double eta)
0380 {
0381 _theEtaLow = eta;
0382 if (_doEtaHighCut)
0383 {
0384 _doBothEtaCut = true;
0385 _doEtaHighCut = false;
0386 }
0387 else
0388 {
0389 _doEtaLowCut = true;
0390 }
0391 }
0392
0393 void PHPy8ParticleTrigger::SetEtaHighLow(double etaHigh, double etaLow)
0394 {
0395 _theEtaHigh = etaHigh;
0396 _theEtaLow = etaLow;
0397 _doBothEtaCut = true;
0398 _doEtaHighCut = false;
0399 _doEtaLowCut = false;
0400 }
0401
0402 void PHPy8ParticleTrigger::SetAbsEtaHigh(double eta)
0403 {
0404 _theEtaHigh = eta;
0405 if (_doAbsEtaLowCut)
0406 {
0407 _doBothAbsEtaCut = true;
0408 _doAbsEtaLowCut = false;
0409 }
0410 else
0411 {
0412 _doAbsEtaHighCut = true;
0413 }
0414 }
0415
0416 void PHPy8ParticleTrigger::SetAbsEtaLow(double eta)
0417 {
0418 _theEtaLow = eta;
0419 if (_doAbsEtaHighCut)
0420 {
0421 _doBothAbsEtaCut = true;
0422 _doAbsEtaHighCut = false;
0423 }
0424 else
0425 {
0426 _doAbsEtaLowCut = true;
0427 }
0428 }
0429
0430 void PHPy8ParticleTrigger::SetAbsEtaHighLow(double etaHigh, double etaLow)
0431 {
0432 _theEtaHigh = etaHigh;
0433 _theEtaLow = etaLow;
0434 _doBothAbsEtaCut = true;
0435 _doAbsEtaLowCut = false;
0436 _doAbsEtaHighCut = false;
0437 }
0438
0439 void PHPy8ParticleTrigger::SetPzHigh(double pz)
0440 {
0441 _thePzHigh = pz;
0442 if (_doPzLowCut)
0443 {
0444 _doBothPzCut = true;
0445 _doPzLowCut = false;
0446 }
0447 else
0448 {
0449 _doPzHighCut = true;
0450 }
0451 }
0452
0453 void PHPy8ParticleTrigger::SetPzLow(double pz)
0454 {
0455 _thePzLow = pz;
0456 if (_doPzHighCut)
0457 {
0458 _doBothPzCut = true;
0459 _doPzHighCut = false;
0460 }
0461 else
0462 {
0463 _doPzLowCut = true;
0464 }
0465 }
0466
0467 void PHPy8ParticleTrigger::SetPzHighLow(double pzHigh, double pzLow)
0468 {
0469 if (pzHigh < pzLow)
0470 {
0471 _thePzHigh = pzLow;
0472 _thePzLow = pzHigh;
0473 }
0474 else
0475 {
0476 _thePzHigh = pzHigh;
0477 _thePzLow = pzLow;
0478 }
0479 _doBothPzCut = true;
0480 _doPzLowCut = false;
0481 _doPzHighCut = false;
0482 }
0483
0484 void PHPy8ParticleTrigger::PrintConfig()
0485 {
0486 std::cout << "---------------- PHPy8ParticleTrigger::PrintConfig --------------------" << std::endl;
0487
0488 if (m_doStableParticleOnly)
0489 {
0490 std::cout << "Process stable particles only." << std::endl;
0491 }
0492 else
0493 {
0494 std::cout << "Process both unstable and stable particles." << std::endl;
0495 }
0496
0497 std::cout << " Particles: ";
0498 for (int _theParticle : _theParticles)
0499 {
0500 std::cout << _theParticle << " ";
0501 }
0502 std::cout << std::endl;
0503
0504 std::cout << " Parents: ";
0505 for (int _theParent : _theParents)
0506 {
0507 std::cout << _theParent << " ";
0508 }
0509 std::cout << std::endl;
0510
0511 if (_doYHighCut || _doYLowCut || _doBothYCut)
0512 {
0513 std::cout << " doYCut: " << _theYLow << " < Y < " << _theYHigh << std::endl;
0514 }
0515 if (_doEtaHighCut || _doEtaLowCut || _doBothEtaCut)
0516 {
0517 std::cout << " doEtaCut: " << _theEtaLow << " < eta < " << _theEtaHigh << std::endl;
0518 }
0519 if (_doAbsEtaHighCut || _doAbsEtaLowCut || _doBothAbsEtaCut)
0520 {
0521 std::cout << " doAbsEtaCut: " << _theEtaLow << " < |eta| < " << _theEtaHigh << std::endl;
0522 }
0523 if (_doPtHighCut || _doPtLowCut || _doBothPtCut)
0524 {
0525 std::cout << " doPtCut: " << _thePtLow << " < pT < " << _thePtHigh << std::endl;
0526 }
0527 if (_doPHighCut || _doPLowCut || _doBothPCut)
0528 {
0529 std::cout << " doPCut: " << _thePLow << " < p < " << _thePHigh << std::endl;
0530 }
0531 if (_doPzHighCut || _doPzLowCut || _doBothPzCut)
0532 {
0533 std::cout << " doPzCut: " << _thePzLow << " < pz < " << _thePzHigh << std::endl;
0534 }
0535 std::cout << "-----------------------------------------------------------------------" << std::endl;
0536 }