CMS 3D CMS Logo

PFIsolation.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/PFCandProducer/interface/PFIsolation.h"
00002 #include "PhysicsTools/PFCandProducer/interface/FetchCollection.h"
00003 
00004 #include "DataFormats/ParticleFlowCandidate/interface/IsolatedPFCandidate.h"
00005 #include "DataFormats/ParticleFlowCandidate/interface/IsolatedPFCandidateFwd.h"
00006 
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 
00009 // #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 
00013 #include "DataFormats/Math/interface/deltaR.h"
00014 
00015 using namespace std;
00016 using namespace edm;
00017 using namespace reco;
00018 
00019 PFIsolation::PFIsolation(const edm::ParameterSet& iConfig) {
00020   
00021 
00022 
00023   inputTagPFCandidates_ 
00024     = iConfig.getParameter<InputTag>("PFCandidates");
00025 
00026   inputTagPFCandidatesForIsolation_ 
00027     = iConfig.getParameter<InputTag>("PFCandidatesForIsolation");
00028 
00029   verbose_ = 
00030     iConfig.getUntrackedParameter<bool>("verbose",false);
00031 
00032 
00033 
00034   produces<reco::IsolatedPFCandidateCollection>();
00035   
00036 
00037 
00038   max_ptFraction_InCone_ 
00039     = iConfig.getParameter<double>("max_ptFraction_InCone");  
00040 
00041   isolation_Cone_DeltaR_
00042     = iConfig.getParameter<double>("isolation_Cone_DeltaR");  
00043 
00044   isolation_InnerCone_DeltaR_
00045     = iConfig.getParameter<double>("isolation_InnerCone_DeltaR");  
00046 
00047 //   LogDebug("PFIsolation")
00048 //     <<" input collection : "<<inputTagPFCandidates_ <<"\t"
00049 //     <<" max_ptFraction_InCone : "<<max_ptFraction_InCone_<<"\t";
00050    
00051   
00052 
00053 }
00054 
00055 
00056 
00057 PFIsolation::~PFIsolation() { }
00058 
00059 
00060 
00061 void PFIsolation::beginJob(const edm::EventSetup & es) { }
00062 
00063 
00064 void PFIsolation::produce(Event& iEvent, 
00065                           const EventSetup& iSetup) {
00066   
00067 //   LogDebug("PFIsolation")<<"START event: "<<iEvent.id().event()
00068 //                       <<" in run "<<iEvent.id().run()<<endl;
00069   
00070   
00071   
00072   // get PFCandidates
00073 
00074   Handle<PFCandidateCollection> pfCandidates;
00075   pfpat::fetchCollection(pfCandidates, 
00076                          inputTagPFCandidates_, 
00077                          iEvent );
00078 
00079   Handle<PFCandidateCollection> pfCandidatesForIsolation;
00080   pfpat::fetchCollection( pfCandidatesForIsolation, 
00081                           inputTagPFCandidatesForIsolation_, 
00082                           iEvent );
00083 
00084   // get PFCandidates for isolation
00085   
00086   
00087   auto_ptr< reco::IsolatedPFCandidateCollection > 
00088     pOutput( new reco::IsolatedPFCandidateCollection ); 
00089   
00090   for( unsigned i=0; i<pfCandidates->size(); i++ ) {
00091 
00092     const PFCandidatePtr candptr( pfCandidates,i);
00093 
00094     double ptFractionInCone = computeIsolation( *candptr,
00095                                                 *pfCandidatesForIsolation,
00096                                                 isolation_Cone_DeltaR_ );
00097 
00098     if( ptFractionInCone < max_ptFraction_InCone_ ) {
00099       pOutput->push_back( IsolatedPFCandidate( candptr, 
00100                                                ptFractionInCone ) );
00101     }
00102     
00103   }
00104   
00105   iEvent.put( pOutput );
00106   
00107 //   LogDebug("PFIsolation")<<"STOP event: "<<iEvent.id().event()
00108 //                       <<" in run "<<iEvent.id().run()<<endl;
00109 }
00110 
00111 
00112 double 
00113 PFIsolation::computeIsolation( const PFCandidate& cand,
00114                                const PFCandidateCollection& candsForIsolation,
00115                                double isolationCone ) 
00116   const {
00117 
00118   
00119   double sumpt = 0;
00120 
00121   if(verbose_) {
00122     cout<<"compute isolation for "<<cand<<endl;
00123   }
00124     
00125   
00126   for( unsigned i=0; i<candsForIsolation.size(); i++ ) {
00127     
00128     double dR = deltaR( cand,  candsForIsolation[i] );
00129 
00130     // need a clean way to compare candidates for equality... 
00131     // maybe checking the components as well: same blocks, same elements
00132     // need to wait 
00133     if( dR < isolation_InnerCone_DeltaR_ ) continue;
00134 
00135     if( verbose_ ) {
00136       cout<<"\t"<<candsForIsolation[i]<<endl;
00137     }
00138 
00139     if(dR < isolationCone ) {
00140       if( verbose_ ) {
00141         cout<<"\t\tpassed ! DeltaR = "<<dR
00142             <<", pT = "<<candsForIsolation[i].pt()<<endl;
00143       }
00144       sumpt += candsForIsolation[i].pt();
00145     }
00146   }
00147   
00148   sumpt /= cand.pt();
00149 
00150   if( verbose_ ) {
00151     cout<<"\tisolation = "<<sumpt<<endl;
00152   }
00153 
00154   return sumpt;
00155 
00156 }
00157 
00158 

Generated on Tue Jun 9 17:41:49 2009 for CMSSW by  doxygen 1.5.4