Go to the documentation of this file.00001 #include "FWCore/Framework/interface/EDProducer.h"
00002 #include "FWCore/Utilities/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 reco;
00036
00037 typedef edm::ValueMap<float> TkIsoMap;
00038
00039 IsolationProducerForTracks::IsolationProducerForTracks(const ParameterSet & pset) :
00040 tracks_( pset.getParameter<InputTag>( "tracks" ) ),
00041 highPtTracks_( pset.getParameter<InputTag>( "highPtTracks" ) ),
00042 isoDeps_( pset.getParameter<InputTag>( "isoDeps" ) ),
00043 trackPtMin_( pset.getParameter<double>( "trackPtMin" ) ),
00044 coneSize_( pset.getParameter<double>( "coneSize" ) )
00045 {
00046 produces<TkIsoMap>();
00047 }
00048
00049 void IsolationProducerForTracks::produce(Event & event, const EventSetup & setup) {
00050 std::auto_ptr<TkIsoMap> caloIsolations(new TkIsoMap);
00051 TkIsoMap::Filler filler(*caloIsolations);
00052 {
00053 Handle<CandidateView> tracks;
00054 event.getByLabel(tracks_, tracks);
00055
00056 Handle<CandidateView> highPtTracks;
00057 event.getByLabel(highPtTracks_, highPtTracks);
00058
00059 Handle<IsoDepositMap> isoDeps;
00060 event.getByLabel(isoDeps_, isoDeps);
00061
00062 int nTracks = tracks->size();
00063 int nHighPtTracks = highPtTracks->size();
00064 std::vector<double> iso(nTracks);
00065
00066 OverlapChecker overlap;
00067
00068 for(int i = 0; i < nTracks; ++i ) {
00069 const Candidate & tkCand = (*tracks)[ i ];
00070 double caloIso = - 1.0;
00071 if( tkCand.pt() > trackPtMin_) {
00072 for(int j = 0; j < nHighPtTracks; ++j ) {
00073 const Candidate & highPtTkCand = (*highPtTracks)[ j ];
00074 if(overlap(tkCand, highPtTkCand) ) {
00075 CandidateBaseRef tkRef = highPtTracks->refAt(j);
00076 const IsoDeposit &isoDep = (*isoDeps)[tkRef];
00077 caloIso = isoDep.depositWithin(coneSize_);
00078 break;
00079 }
00080 }
00081 }
00082 iso[i] = caloIso;
00083 }
00084 filler.insert(tracks, iso.begin(), iso.end());
00085 }
00086
00087
00088 filler.fill();
00089 event.put(caloIsolations);
00090 }
00091
00092 #include "FWCore/Framework/interface/MakerMacros.h"
00093
00094 DEFINE_FWK_MODULE(IsolationProducerForTracks);