rivet is hosted by Hepforge, IPPP Durham
FastJets.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Config/RivetCommon.hh"
00003 #include "Rivet/Tools/Logging.hh"
00004 #include "Rivet/Projections/FastJets.hh"
00005 #include "Rivet/Projections/HeavyHadrons.hh"
00006 #include "Rivet/Projections/TauFinder.hh"
00007 
00008 namespace Rivet {
00009 
00010 
00011   void FastJets::_initBase() {
00012     setName("FastJets");
00013     addProjection(HeavyHadrons(), "HFHadrons");
00014     addProjection(TauFinder(TauFinder::HADRONIC), "Taus");
00015   }
00016 
00017   void FastJets::_init1(JetAlgName alg, double rparameter, double seed_threshold) {
00018     _initBase();
00019     MSG_DEBUG("JetAlg = " << alg);
00020     MSG_DEBUG("R parameter = " << rparameter);
00021     MSG_DEBUG("Seed threshold = " << seed_threshold);
00022     if (alg == KT) {
00023       _jdef = fastjet::JetDefinition(fastjet::kt_algorithm, rparameter, fastjet::E_scheme);
00024     } else if (alg == CAM) {
00025       _jdef = fastjet::JetDefinition(fastjet::cambridge_algorithm, rparameter, fastjet::E_scheme);
00026     } else if (alg == ANTIKT) {
00027       _jdef = fastjet::JetDefinition(fastjet::antikt_algorithm, rparameter, fastjet::E_scheme);
00028     } else if (alg == DURHAM) {
00029       _jdef = fastjet::JetDefinition(fastjet::ee_kt_algorithm, fastjet::E_scheme);
00030     } else {
00031       // Plugins:
00032       if (alg == SISCONE) {
00033         const double OVERLAP_THRESHOLD = 0.75;
00034         _plugin.reset(new fastjet::SISConePlugin(rparameter, OVERLAP_THRESHOLD));
00035       // } else if (alg == PXCONE) {
00036       //   string msg = "PxCone currently not supported, since FastJet doesn't install it by default. ";
00037       //   msg += "Please notify the Rivet authors if this behaviour should be changed.";
00038       //   throw Error(msg);
00039         //_plugin.reset(new fastjet::PxConePlugin(rparameter));
00040       } else if (alg == ATLASCONE) {
00041         const double OVERLAP_THRESHOLD = 0.5;
00042         _plugin.reset(new fastjet::ATLASConePlugin(rparameter, seed_threshold, OVERLAP_THRESHOLD));
00043       } else if (alg == CMSCONE) {
00044         _plugin.reset(new fastjet::CMSIterativeConePlugin(rparameter, seed_threshold));
00045       } else if (alg == CDFJETCLU) {
00046         const double OVERLAP_THRESHOLD = 0.75;
00047         _plugin.reset(new fastjet::CDFJetCluPlugin(rparameter, OVERLAP_THRESHOLD, seed_threshold));
00048       } else if (alg == CDFMIDPOINT) {
00049         const double OVERLAP_THRESHOLD = 0.5;
00050         _plugin.reset(new fastjet::CDFMidPointPlugin(rparameter, OVERLAP_THRESHOLD, seed_threshold));
00051       } else if (alg == D0ILCONE) {
00052         const double min_jet_Et = 6.0;
00053         _plugin.reset(new fastjet::D0RunIIConePlugin(rparameter, min_jet_Et));
00054       } else if (alg == JADE) {
00055         _plugin.reset(new fastjet::JadePlugin());
00056       } else if (alg == TRACKJET) {
00057         _plugin.reset(new fastjet::TrackJetPlugin(rparameter));
00058       }
00059       _jdef = fastjet::JetDefinition(_plugin.get());
00060     }
00061   }
00062 
00063   void FastJets::_init2(fastjet::JetAlgorithm type,
00064                         fastjet::RecombinationScheme recom, double rparameter) {
00065     _initBase();
00066     _jdef = fastjet::JetDefinition(type, rparameter, recom);
00067   }
00068 
00069   void FastJets::_init3(const fastjet::JetDefinition& jdef) {
00070     _initBase();
00071     _jdef = jdef;
00072   }
00073 
00074   void FastJets::_init4(fastjet::JetDefinition::Plugin* plugin) {
00075     _initBase();
00076     _plugin.reset(plugin);
00077     _jdef = fastjet::JetDefinition(_plugin.get());
00078   }
00079 
00080 
00081 
00082   int FastJets::compare(const Projection& p) const {
00083     const FastJets& other = dynamic_cast<const FastJets&>(p);
00084     return \
00085       cmp(_useMuons, other._useMuons) ||
00086       cmp(_useInvisibles, other._useInvisibles) ||
00087       mkNamedPCmp(other, "FS") ||
00088       cmp(_jdef.jet_algorithm(), other._jdef.jet_algorithm()) ||
00089       cmp(_jdef.recombination_scheme(), other._jdef.recombination_scheme()) ||
00090       cmp(_jdef.plugin(), other._jdef.plugin()) ||
00091       cmp(_jdef.R(), other._jdef.R()) ||
00092       cmp(_adef, other._adef);
00093   }
00094 
00095 
00096   namespace {
00097     bool isPromptInvisible(const Particle& p) { return !(p.isVisible() || p.fromDecay()); }
00098     // bool isMuon(const Particle& p) { return p.abspid() == PID::MUON; }
00099     bool isPromptMuon(const Particle& p) { return isMuon(p) && !p.fromDecay(); }
00100   }
00101 
00102 
00103   void FastJets::project(const Event& e) {
00104     // Assemble final state particles
00105     const string fskey = (_useInvisibles == JetAlg::NO_INVISIBLES) ? "VFS" : "FS";
00106     Particles fsparticles = applyProjection<FinalState>(e, fskey).particles();
00107     // Remove prompt invisibles if needed (already done by VFS if using NO_INVISIBLES)
00108     if (_useInvisibles == JetAlg::DECAY_INVISIBLES)
00109       fsparticles.erase( std::remove_if(fsparticles.begin(), fsparticles.end(), isPromptInvisible), fsparticles.end() );
00110     // Remove prompt/all muons if needed
00111     if (_useMuons == JetAlg::DECAY_MUONS)
00112       fsparticles.erase( std::remove_if(fsparticles.begin(), fsparticles.end(), isPromptMuon), fsparticles.end() );
00113     else if (_useMuons == JetAlg::NO_MUONS)
00114       fsparticles.erase( std::remove_if(fsparticles.begin(), fsparticles.end(), isMuon), fsparticles.end() );
00115 
00116     // Tagging particles
00117     /// @todo Allow the user to specify tag particle kinematic thresholds
00118     const Particles chadrons = applyProjection<HeavyHadrons>(e, "HFHadrons").cHadrons();
00119     const Particles bhadrons = applyProjection<HeavyHadrons>(e, "HFHadrons").bHadrons();
00120     const Particles taus = applyProjection<FinalState>(e, "Taus").particles();
00121     calc(fsparticles, chadrons+bhadrons+taus);
00122   }
00123 
00124 
00125   void FastJets::calc(const Particles& fsparticles, const Particles& tagparticles) {
00126     _particles.clear();
00127     vector<fastjet::PseudoJet> pjs;
00128 
00129     /// @todo Use FastJet3's UserInfo system
00130 
00131     // Store 4 vector data about each particle into FastJet's PseudoJets
00132     int counter = 1;
00133     foreach (const Particle& p, fsparticles) {
00134       const FourMomentum fv = p.momentum();
00135       fastjet::PseudoJet pj(fv.px(), fv.py(), fv.pz(), fv.E()); ///< @todo Eliminate with implicit cast?
00136       pj.set_user_index(counter);
00137       pjs.push_back(pj);
00138       _particles[counter] = p;
00139       counter += 1;
00140     }
00141     // And the same for ghost tagging particles (with negative user indices)
00142     counter = 1;
00143     foreach (const Particle& p, tagparticles) {
00144       const FourMomentum fv = 1e-20 * p.momentum(); ///< Ghostify the momentum
00145       fastjet::PseudoJet pj(fv.px(), fv.py(), fv.pz(), fv.E()); ///< @todo Eliminate with implicit cast?
00146       pj.set_user_index(-counter);
00147       pjs.push_back(pj);
00148       _particles[-counter] = p;
00149       counter += 1;
00150     }
00151 
00152     MSG_DEBUG("Running FastJet ClusterSequence construction");
00153     // Choose cseq as basic or area-calculating
00154     if (_adef == NULL) {
00155       _cseq.reset(new fastjet::ClusterSequence(pjs, _jdef));
00156     } else {
00157       _cseq.reset(new fastjet::ClusterSequenceArea(pjs, _jdef, *_adef));
00158     }
00159   }
00160 
00161 
00162   void FastJets::reset() {
00163     _yscales.clear();
00164     _particles.clear();
00165     /// @todo _cseq = fastjet::ClusterSequence();
00166   }
00167 
00168 
00169   size_t FastJets::numJets(double ptmin) const {
00170     if (_cseq.get() == NULL) return 0;
00171     return _cseq->inclusive_jets(ptmin).size();
00172   }
00173 
00174 
00175   Jets FastJets::_jets(double ptmin) const {
00176     Jets rtn;
00177     foreach (const fastjet::PseudoJet& pj, pseudojets()) {
00178       assert(clusterSeq() != NULL);
00179       const PseudoJets parts = clusterSeq()->constituents(pj);
00180       vector<Particle> constituents, tags;
00181       constituents.reserve(parts.size());
00182       foreach (const fastjet::PseudoJet& p, parts) {
00183         map<int, Particle>::const_iterator found = _particles.find(p.user_index());
00184         // assert(found != _particles.end());
00185         if (found == _particles.end() && p.is_pure_ghost()) continue; //< Pure FJ ghosts are ok
00186         assert(found != _particles.end()); //< Anything else must be known
00187         assert(found->first != 0); //< All mapping IDs are pos-def (particles) or neg-def (tags)
00188         if (found->first > 0) constituents.push_back(found->second);
00189         else if (found->first < 0) tags.push_back(found->second);
00190       }
00191       Jet j(pj, constituents, tags);
00192       rtn.push_back(j);
00193     }
00194     /// @todo Cache?
00195     return rtn;
00196   }
00197 
00198 
00199   PseudoJets FastJets::pseudoJets(double ptmin) const {
00200     return (clusterSeq() != NULL) ? clusterSeq()->inclusive_jets(ptmin) : PseudoJets();
00201   }
00202 
00203 
00204 
00205 }