Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:19:30

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