CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/PhysicsTools/PFCandProducer/src/FastJetAlgo.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/PFCandProducer/interface/FastJetAlgo.h"
00002 
00003 #include "DataFormats/Math/interface/LorentzVector.h"
00004 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00005 #include "DataFormats/JetReco/interface/PFJet.h"
00006 
00007 #include "RecoJets/JetProducers/interface/JetSpecific.h"
00008 
00009 #include "fastjet/ClusterSequence.hh"
00010 
00011 
00012 using namespace pf2pat;
00013 using namespace fastjet;
00014 using namespace std;
00015 
00016 
00017 FastJetAlgo::FastJetAlgo( const edm::ParameterSet& ps ) 
00018   : clusterSequence_(0) {
00019   setJetDefinition( ps ); 
00020 }
00021 
00022 void FastJetAlgo::setJetDefinition( const edm::ParameterSet& ps) {
00023   // here extract parameter set info to make the jet definition
00024 
00025   unsigned algorithm = ps.getParameter<unsigned>("algorithm");
00026   double distance = ps.getParameter<double>("distance");
00027 
00028   JetDefinition jetDef( static_cast<JetAlgorithm>(algorithm), distance);
00029   setJetDefinition( jetDef ); 
00030 }
00031 
00032 
00033 void FastJetAlgo::setJetDefinition( const fastjet::JetDefinition& jetDef) {
00034   cout<<jetDef.description()<<endl;
00035   jetDefinition_ = jetDef; 
00036 }
00037 
00038 
00039 const FastJetAlgo::JetCollection& FastJetAlgo::produce( const FastJetAlgo::InputHandle& inputHandle) {
00040   
00041   // the input handle will be necessary to build the Ptrs to the jet constituents.
00042   inputHandle_ = inputHandle;
00043   const InputCollection& inputColl = *inputHandle; 
00044   recoToFastJet( inputColl );
00045   runJetClustering();
00046   return fastJetToReco(); 
00047 }
00048 
00049 void FastJetAlgo::recoToFastJet(const FastJetAlgo::InputCollection& inputColl) {
00050   input_.clear();
00051   typedef InputCollection::const_iterator II;
00052 
00053   unsigned index = 0;
00054   for(II i=inputColl.begin(); i!=inputColl.end(); ++i, ++index) {
00055     input_.push_back( PseudoJet( i->px(), i->py(), i->pz(), i->energy() ) );
00056     input_.back().set_user_index( index );
00057   }
00058 }
00059 
00060 void  FastJetAlgo::runJetClustering() {
00061   output_.clear();
00062   if(clusterSequence_) delete clusterSequence_;
00063   clusterSequence_ = new ClusterSequence(input_, jetDefinition_);
00064 
00065   double ptMin_=2;//COLIN make it an attribute
00066   output_ = clusterSequence_->inclusive_jets( ptMin_ );
00067 }
00068 
00069 
00070 
00071 const FastJetAlgo::JetCollection& FastJetAlgo::fastJetToReco() {
00072   
00073   jetCollection_.clear();
00074 
00075   for(PJI i=output_.begin(); i!=output_.end(); ++i) {
00076     jetCollection_.push_back( makeJet( *i ) ); 
00077   }
00078 
00079   return jetCollection_;
00080 }
00081 
00082 
00083 FastJetAlgo::JetType FastJetAlgo::makeJet( const PseudoJet& pseudoJet) const {
00084   
00085   reco::Particle::LorentzVector p4( pseudoJet.px(), 
00086                                     pseudoJet.py(),
00087                                     pseudoJet.pz(),
00088                                     pseudoJet.E() );
00089   reco::Particle::Point vertex; 
00090   JetType::Specific specific; 
00091     
00092   // need to add the constituents as well (see base Jet, or CompositePtrCandidate)
00093   reco::Jet::Constituents ptrsToConstituents = makeConstituents( pseudoJet );
00094   
00095   makeSpecific( ptrsToConstituents, &specific );
00096   return JetType(p4, vertex, specific, ptrsToConstituents); 
00097 }
00098   
00099 
00100 reco::Jet::Constituents FastJetAlgo::makeConstituents(const fastjet::PseudoJet& pseudoJet) const {
00101   
00102   reco::Jet::Constituents ptrsToConstituents; 
00103   
00104   const PseudoJetCollection& constituents 
00105     = clusterSequence_->constituents(pseudoJet); 
00106   for(PJI jc=constituents.begin(); jc!=constituents.end(); ++jc) {
00107     ptrsToConstituents.push_back( edm::Ptr<reco::Candidate>(inputHandle_, jc->user_index() ) ); 
00108   } 
00109 
00110   return ptrsToConstituents;
00111 }
00112 
00113 
00114 void FastJetAlgo::printPseudoJets( ostream& out) const {
00115 
00116 //   cout<<"Jet Definition:"<<endl;
00117 //   cout<<jetDefinition_;
00118   cout<<"Pseudo jets:"<<endl;
00119   unsigned index = 0;
00120   for(PJI i=output_.begin(); i!=output_.end(); ++i, ++index) {
00121     cout<<index<<" "<<i->Et()<<endl;
00122     
00123     const PseudoJetCollection& constituents = clusterSequence_->constituents( *i );
00124     for(PJI jc=constituents.begin(); jc!=constituents.end(); ++jc) {
00125       cout<<"\t"<<jc->user_index()<<" "<<jc->Et()<<endl;
00126     }
00127   }
00128 }
00129 
00130 
00131 void FastJetAlgo::printJets( ostream& out) const {
00132 
00133 //   cout<<"Jet Definition:"<<endl;
00134 //   cout<<jetDefinition_;
00135   cout<<"Jets:"<<endl;
00136   unsigned index = 0;
00137   for(JI i=jetCollection_.begin(); i!=jetCollection_.end(); ++i, ++index) {
00138     cout<<index<<" "<<(*i)<<endl;
00139     cout<<i->print()<<endl;
00140   }
00141 }
00142 
00143