CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/RecoJets/JetAssociationProducers/src/JetTracksAssociatorAtVertex.cc

Go to the documentation of this file.
00001 // \class JetTracksAssociatorAtVertex JetTracksAssociatorAtVertex.cc 
00002 //
00003 // Original Author:  Andrea Rizzi
00004 //         Created:  Wed Apr 12 11:12:49 CEST 2006
00005 // Accommodated for Jet Package by: Fedor Ratnikov Jul. 30, 2007
00006 // $Id: JetTracksAssociatorAtVertex.cc,v 1.8 2011/11/11 19:44:39 srappocc Exp $
00007 //
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 
00010 // user include files
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "DataFormats/Common/interface/View.h"
00013 #include "DataFormats/JetReco/interface/Jet.h"
00014 #include "DataFormats/TrackReco/interface/Track.h"
00015 #include "DataFormats/JetReco/interface/JetTracksAssociation.h"
00016 
00017 #include "JetTracksAssociatorAtVertex.h"
00018 
00019 JetTracksAssociatorAtVertex::JetTracksAssociatorAtVertex(const edm::ParameterSet& fConfig)
00020   : mJets (fConfig.getParameter<edm::InputTag> ("jets")),
00021     mTracks (fConfig.getParameter<edm::InputTag> ("tracks")),
00022     mAssociator (fConfig.getParameter<double> ("coneSize")),
00023     mAssociatorAssigned (fConfig.getParameter<double> ("coneSize")),
00024     useAssigned(false), pvSrc()
00025 {
00026 
00027   if ( fConfig.exists("useAssigned") ) {
00028     useAssigned = fConfig.getParameter<bool> ("useAssigned");
00029     pvSrc = fConfig.getParameter<edm::InputTag> ("pvSrc");
00030   }
00031 
00032   produces<reco::JetTracksAssociation::Container> ();
00033 }
00034 
00035 JetTracksAssociatorAtVertex::~JetTracksAssociatorAtVertex() {}
00036 
00037 void JetTracksAssociatorAtVertex::produce(edm::Event& fEvent, const edm::EventSetup& fSetup) {
00038   edm::Handle <edm::View <reco::Jet> > jets_h;
00039   fEvent.getByLabel (mJets, jets_h);
00040   edm::Handle <reco::TrackCollection> tracks_h;
00041   fEvent.getByLabel (mTracks, tracks_h);
00042   
00043   std::auto_ptr<reco::JetTracksAssociation::Container> jetTracks (new reco::JetTracksAssociation::Container (reco::JetRefBaseProd(jets_h)));
00044 
00045   // format inputs
00046   std::vector <edm::RefToBase<reco::Jet> > allJets;
00047   allJets.reserve (jets_h->size());
00048   for (unsigned i = 0; i < jets_h->size(); ++i) allJets.push_back (jets_h->refAt(i));
00049   std::vector <reco::TrackRef> allTracks;
00050   allTracks.reserve (tracks_h->size());
00051   // run algo
00052   for (unsigned i = 0; i < tracks_h->size(); ++i) {
00053     allTracks.push_back (reco::TrackRef (tracks_h, i));
00054   }
00055   if ( !useAssigned ) {
00056     mAssociator.produce (&*jetTracks, allJets, allTracks);
00057   } else {
00058     edm::Handle<reco::VertexCollection> pvHandle;
00059     fEvent.getByLabel(pvSrc,pvHandle);
00060     const reco::VertexCollection & vertices = *pvHandle.product();     
00061     mAssociatorAssigned.produce (&*jetTracks, allJets, allTracks,vertices);
00062   }
00063 
00064 
00065   // store output
00066   fEvent.put (jetTracks);
00067 }