rivet is hosted by Hepforge, IPPP Durham
LeadingParticlesFinalState.cc
Go to the documentation of this file.
00001 #include "Rivet/Projections/LeadingParticlesFinalState.hh"
00002 #include "Rivet/Particle.hh"
00003 
00004 namespace Rivet {
00005 
00006 
00007   int LeadingParticlesFinalState::compare(const Projection& p) const {
00008     // First compare the final states we are running on
00009     int fscmp = mkNamedPCmp(p, "FS");
00010     if (fscmp != EQUIVALENT) return fscmp;
00011 
00012     // Then compare the two as final states
00013     const LeadingParticlesFinalState& other = dynamic_cast<const LeadingParticlesFinalState&>(p);
00014     fscmp = FinalState::compare(other);
00015     if (fscmp != EQUIVALENT) return fscmp;
00016 
00017     int locmp = cmp(_leading_only, other._leading_only);
00018     if (locmp != EQUIVALENT) return locmp;
00019 
00020     // Finally compare the IDs
00021     if (_ids < other._ids) return ORDERED;
00022     else if (other._ids < _ids) return UNORDERED;
00023     return EQUIVALENT;
00024   }
00025 
00026 
00027   void LeadingParticlesFinalState::project(const Event & e) {
00028     _theParticles.clear();
00029     const FinalState& fs = applyProjection<FinalState>(e, "FS");
00030 
00031     // Temporary container
00032     map<long, Particles::const_iterator> tmp;
00033 
00034     const Particles& particles = fs.particles();
00035     MSG_DEBUG("Original final state particles size " << particles.size());
00036     Particles::const_iterator ifs;
00037     for (ifs = particles.begin(); ifs != particles.end(); ++ifs) {
00038       if (inList(*ifs) && FinalState::accept(*ifs->genParticle())) {
00039         // Look for an existing particle in tmp container
00040         map < long, Particles::const_iterator >::const_iterator itmp = tmp.find(ifs->pdgId());
00041         if (itmp != tmp.end()) {  // if a particle with this type has been already selected
00042           // If the new pT is higher than the previous one, then substitute...
00043           if (ifs->pT() > itmp->second->pT()) {
00044             tmp[ifs->pdgId()] = ifs;
00045           }
00046           // ...otherwise insert in the container
00047         } else {
00048           tmp[ifs->pdgId()] = ifs;
00049         }
00050       }
00051     }
00052 
00053     // Loop on the tmp container and fill _theParticles
00054     map<long, Particles::const_iterator>::const_iterator i;
00055     for (i = tmp.begin(); i != tmp.end(); ++i) {
00056       MSG_DEBUG("LeadingParticlesFinalState is accepting particle ID " << i->second->pdgId()
00057                << " with momentum " << i->second->momentum());
00058       _theParticles.push_back(*(i->second));
00059     }
00060 
00061     if (_leading_only) {
00062       double ptmax=0.0;
00063       Particle pmax;
00064 
00065       foreach (const Particle& p, _theParticles) {
00066         if (p.pT() > ptmax) {
00067           ptmax = p.pT();
00068           pmax = p;
00069         }
00070       }
00071 
00072       _theParticles.clear();
00073       _theParticles.push_back(pmax);
00074     }
00075   }
00076 
00077 
00078   bool LeadingParticlesFinalState::inList(const Particle & particle) const {
00079     std::set < long >::const_iterator ilist = _ids.find(particle.pdgId());
00080     if (ilist != _ids.end()) return true;
00081     return false;
00082   }
00083 
00084 
00085 }