Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:49

0001 #include "AntiTrigger.h"
0002 
0003 /*
0004  * Find decay topologies in HepMC
0005  * Cameron Dean
0006  * 04/06/2021
0007  */
0008 
0009 AntiTrigger::AntiTrigger()
0010   : SubsysReco("ANTITRIGGER")
0011 {
0012 }
0013 
0014 AntiTrigger::AntiTrigger(const std::string &name)
0015   : SubsysReco(name)
0016 {
0017 }
0018 
0019 int AntiTrigger::Init(PHCompositeNode *topNode)
0020 {
0021   if (Verbosity() >= VERBOSITY_SOME)
0022   {
0023     std::cout << "AntiTrigger name: " << Name() << std::endl;
0024 
0025     int numberOfParticles = m_particleList.size();
0026 
0027     std::cout << "Particles to reject: "; 
0028     for (int i = 0; i < numberOfParticles; ++i)
0029     {
0030       std::cout << m_particleList[i]; 
0031       if (i != numberOfParticles - 1) std::cout << ", ";
0032     }
0033     std::cout << std::endl;
0034   }
0035 
0036   int canSearchDecay = parseParticleList();
0037 
0038   return canSearchDecay;
0039 }
0040 
0041 int AntiTrigger::process_event(PHCompositeNode *topNode)
0042 {
0043   bool particleFound = findParticle(topNode);
0044 
0045   if (particleFound) 
0046   {
0047     m_counter += 1;
0048     return Fun4AllReturnCodes::ABORTEVENT;
0049   }
0050   else 
0051   { 
0052     return Fun4AllReturnCodes::EVENT_OK;
0053   }
0054 }
0055 
0056 int AntiTrigger::End(PHCompositeNode *topNode)
0057 {
0058   if (Verbosity() >= VERBOSITY_SOME) printInfo();
0059 
0060   return 0;
0061 }
0062 
0063 int AntiTrigger::parseParticleList()
0064 {
0065   bool listCanBeParsed = true;
0066 
0067   for (int i = 0; i < m_particleList.size(); ++i)
0068   {  
0069     if (particleIsInList(m_particleList[i])) 
0070     {
0071       m_particleIDs.push_back(TDatabasePDG::Instance()->GetParticle(m_particleList[i].c_str())->PdgCode());
0072     }
0073     else
0074     {
0075       listCanBeParsed = false;
0076     }
0077   }
0078 
0079   if (listCanBeParsed)
0080   {
0081     if (Verbosity() >= VERBOSITY_MORE) std::cout << "Your particle list can be parsed" << std::endl;
0082     return 0;
0083   }
0084   else
0085   {
0086     if (Verbosity() >= VERBOSITY_SOME) std::cout << "Your particle list cannot be parsed, " << Name() << " will not be registered" << std::endl;
0087     return Fun4AllReturnCodes::DONOTREGISTERSUBSYSTEM;
0088   }
0089 }
0090 
0091 bool AntiTrigger::findParticle(PHCompositeNode *topNode)
0092 {
0093   bool particleWasFound = false;
0094 
0095   m_geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode, "PHHepMCGenEventMap");
0096   if (!m_geneventmap)
0097   {
0098     std::cout << "AntiTrigger: Missing node PHHepMCGenEventMap" << std::endl;
0099     return 0;
0100   }
0101 
0102   m_genevt = m_geneventmap->get(1);
0103   if (!m_genevt)
0104   {
0105     std::cout <<  "AntiTrigger: Missing node PHHepMCGenEvent" << std::endl;
0106     return 0;
0107   }
0108 
0109   HepMC::GenEvent* theEvent = m_genevt->getEvent();
0110 
0111   for (HepMC::GenEvent::particle_const_iterator p = theEvent->particles_begin(); p != theEvent->particles_end(); ++p)
0112   {
0113     if (std::find(m_particleIDs.begin(), m_particleIDs.end(), abs((*p)->pdg_id())) != m_particleIDs.end())
0114     {
0115       particleWasFound = true;
0116       if (Verbosity() >= VERBOSITY_MORE) std::cout << "This event will be rejected due to: " << (*p)->pdg_id() << std::endl;
0117     }
0118   }
0119 
0120   return particleWasFound;
0121 }
0122 
0123 bool AntiTrigger::particleIsInList(std::string particle)
0124 {
0125   bool particleFound = true;
0126   if (!TDatabasePDG::Instance()->GetParticle(particle.c_str()))
0127   {
0128     if (Verbosity() >= VERBOSITY_SOME)
0129     {
0130       std::cout << "The particle, " << particle << " is not in the particle list" << std::endl;
0131       std::cout << "Check TDatabasePDG for a list of available particles" << std::endl;
0132     }
0133     particleFound = false;
0134   }
0135 
0136   return particleFound;
0137 }
0138 
0139 void AntiTrigger::printInfo()
0140 {
0141   std::cout << "\n---------------AntiTrigger information---------------" << std::endl;
0142   std::cout << "AntiTrigger name: " << Name() << std::endl;
0143   int numberOfParticles = m_particleList.size();
0144   std::cout << "Particles to reject: "; 
0145   for (int i; i < numberOfParticles; ++i)
0146   {
0147     std::cout << m_particleList[i]; 
0148     if (i != numberOfParticles - 1) std::cout << ", ";
0149   }
0150   std::cout << std::endl;
0151   std::cout << "Number of events skipped: " << m_counter << std::endl;
0152   std::cout << "-----------------------------------------------------\n" << std::endl;
0153 }