00001 #include "FWCore/Framework/interface/EDProducer.h"
00002 #include "FWCore/ParameterSet/interface/InputTag.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "DataFormats/Common/interface/ValueMap.h"
00006
00007 class IsolationProducerForTracks : public edm::EDProducer {
00008 public:
00009 IsolationProducerForTracks(const edm::ParameterSet & );
00010 private:
00011 void produce(edm::Event& event, const edm::EventSetup& setup);
00012
00013 edm::InputTag tracks_;
00014 edm::InputTag highPtTracks_;
00015 edm::InputTag isoDeps_;
00016 double trackPtMin_;
00017 double coneSize_;
00018
00019 };
00020
00021
00022 #include "DataFormats/Common/interface/Handle.h"
00023 #include "DataFormats/Common/interface/Association.h"
00024 #include "DataFormats/Common/interface/Ref.h"
00025 #include "DataFormats/Candidate/interface/Candidate.h"
00026 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00027 #include "DataFormats/Candidate/interface/OverlapChecker.h"
00028 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00029 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00030 #include <iostream>
00031 #include <iterator>
00032 #include <vector>
00033
00034 using namespace edm;
00035 using namespace std;
00036 using namespace reco;
00037
00038 typedef edm::ValueMap<float> TkIsoMap;
00039
00040 IsolationProducerForTracks::IsolationProducerForTracks(const ParameterSet & pset) :
00041 tracks_( pset.getParameter<InputTag>( "tracks" ) ),
00042 highPtTracks_( pset.getParameter<InputTag>( "highPtTracks" ) ),
00043 isoDeps_( pset.getParameter<InputTag>( "isoDeps" ) ),
00044 trackPtMin_( pset.getParameter<double>( "trackPtMin" ) ),
00045 coneSize_( pset.getParameter<double>( "coneSize" ) )
00046 {
00047 produces<TkIsoMap>();
00048 }
00049
00050 void IsolationProducerForTracks::produce(Event & event, const EventSetup & setup) {
00051 std::auto_ptr<TkIsoMap> caloIsolations(new TkIsoMap);
00052 TkIsoMap::Filler filler(*caloIsolations);
00053 {
00054 Handle<CandidateView> tracks;
00055 event.getByLabel(tracks_, tracks);
00056
00057 Handle<CandidateView> highPtTracks;
00058 event.getByLabel(highPtTracks_, highPtTracks);
00059
00060 Handle<IsoDepositMap> isoDeps;
00061 event.getByLabel(isoDeps_, isoDeps);
00062
00063 int nTracks = tracks->size();
00064 int nHighPtTracks = highPtTracks->size();
00065 std::vector<double> iso(nTracks);
00066
00067 OverlapChecker overlap;
00068
00069 for(int i = 0; i < nTracks; ++i ) {
00070 const Candidate & tkCand = (*tracks)[ i ];
00071 double caloIso = - 1.0;
00072 if( tkCand.pt() > trackPtMin_) {
00073 for(int j = 0; j < nHighPtTracks; ++j ) {
00074 const Candidate & highPtTkCand = (*highPtTracks)[ j ];
00075 if(overlap(tkCand, highPtTkCand) ) {
00076 CandidateBaseRef tkRef = highPtTracks->refAt(j);
00077 const IsoDeposit &isoDep = (*isoDeps)[tkRef];
00078 caloIso = isoDep.depositWithin(coneSize_);
00079 break;
00080 }
00081 }
00082 }
00083 iso[i] = caloIso;
00084 }
00085 filler.insert(tracks, iso.begin(), iso.end());
00086 }
00087
00088
00089 filler.fill();
00090 event.put(caloIsolations);
00091 }
00092
00093 #include "FWCore/Framework/interface/MakerMacros.h"
00094
00095 DEFINE_FWK_MODULE(IsolationProducerForTracks);