Go to the documentation of this file.00001
00006
00007 #include "FWCore/Framework/interface/EDProducer.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013
00014 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00015 #include "RecoMuon/L2MuonIsolationProducer/src/L2MuonIsolationProducer.h"
00016
00017 #include "DataFormats/Common/interface/AssociationMap.h"
00018 #include "DataFormats/TrackReco/interface/Track.h"
00019 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00020 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00021
00022 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
00023 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractorFactory.h"
00024 #include "RecoMuon/MuonIsolation/interface/MuonIsolatorFactory.h"
00025
00026 #include <string>
00027
00028 using namespace edm;
00029 using namespace std;
00030 using namespace reco;
00031 using namespace muonisolation;
00032
00034 L2MuonIsolationProducer::L2MuonIsolationProducer(const ParameterSet& par) :
00035 theSACollectionLabel(par.getParameter<edm::InputTag>("StandAloneCollectionLabel")),
00036 theExtractor(0),
00037 theDepositIsolator(0)
00038 {
00039 LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")<<" L2MuonIsolationProducer constructor called";
00040
00041
00042
00043
00044
00045 edm::ParameterSet extractorPSet = par.getParameter<edm::ParameterSet>("ExtractorPSet");
00046 std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
00047 theExtractor = IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet);
00048
00049
00050 edm::ParameterSet isolatorPSet = par.getParameter<edm::ParameterSet>("IsolatorPSet");
00051 bool haveIsolator = !isolatorPSet.empty();
00052 optOutputDecision = haveIsolator;
00053 if (optOutputDecision){
00054 std::string type = isolatorPSet.getParameter<std::string>("ComponentName");
00055 theDepositIsolator = MuonIsolatorFactory::get()->create(type,isolatorPSet);
00056 }
00057 if (optOutputDecision) produces<edm::ValueMap<bool> >();
00058 produces<reco::IsoDepositMap>();
00059
00060 optOutputIsolatorFloat = par.getParameter<bool>("WriteIsolatorFloat");
00061 if (optOutputIsolatorFloat && haveIsolator){
00062 produces<edm::ValueMap<float> >();
00063 }
00064 }
00065
00067 L2MuonIsolationProducer::~L2MuonIsolationProducer(){
00068 LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")<<" L2MuonIsolationProducer destructor called";
00069 if (theExtractor) delete theExtractor;
00070 }
00071
00073 void L2MuonIsolationProducer::beginJob(){
00074
00075 }
00076
00078 void L2MuonIsolationProducer::produce(Event& event, const EventSetup& eventSetup){
00079 std::string metname = "Muon|RecoMuon|L2MuonIsolationProducer";
00080
00081 LogDebug(metname)<<" L2 Muon Isolation producing...";
00082
00083
00084 LogDebug(metname)<<" Taking the StandAlone muons: "<<theSACollectionLabel;
00085 Handle<TrackCollection> tracks;
00086 event.getByLabel(theSACollectionLabel,tracks);
00087
00088
00089 LogDebug(metname)<<" Get energy around";
00090 std::auto_ptr<reco::IsoDepositMap> depMap( new reco::IsoDepositMap());
00091 std::auto_ptr<edm::ValueMap<bool> > isoMap( new edm::ValueMap<bool> ());
00092 std::auto_ptr<edm::ValueMap<float> > isoFloatMap( new edm::ValueMap<float> ());
00093
00094 theExtractor->fillVetos(event,eventSetup,*tracks);
00095
00096 unsigned int nTracks = tracks->size();
00097 std::vector<IsoDeposit> deps(nTracks);
00098 std::vector<bool> isos(nTracks, false);
00099 std::vector<float> isoFloats(nTracks, 0);
00100
00101 for (unsigned int i=0; i<nTracks; i++) {
00102 TrackRef tk(tracks,i);
00103
00104 deps[i] = theExtractor->deposit(event, eventSetup, *tk);
00105
00106 if (optOutputDecision){
00107 muonisolation::MuIsoBaseIsolator::DepositContainer isoContainer(1,muonisolation::MuIsoBaseIsolator::DepositAndVetos(&deps[i]));
00108 muonisolation::MuIsoBaseIsolator::Result isoResult = theDepositIsolator->result( isoContainer, *tk, &event );
00109 isos[i] = isoResult.valBool;
00110 isoFloats[i] = isoResult.valFloat;
00111 }
00112 }
00113
00114
00115
00117 reco::IsoDepositMap::Filler depFiller(*depMap);
00118 depFiller.insert(tracks, deps.begin(), deps.end());
00119 depFiller.fill();
00120 event.put(depMap);
00121
00122 if (optOutputDecision){
00123 edm::ValueMap<bool> ::Filler isoFiller(*isoMap);
00124 isoFiller.insert(tracks, isos.begin(), isos.end());
00125 isoFiller.fill();
00126 event.put(isoMap);
00127
00128 if (optOutputIsolatorFloat){
00129 edm::ValueMap<float> ::Filler isoFloatFiller(*isoFloatMap);
00130 isoFloatFiller.insert(tracks, isoFloats.begin(), isoFloats.end());
00131 isoFloatFiller.fill();
00132 event.put(isoFloatMap);
00133 }
00134 }
00135
00136 LogDebug(metname) <<" Event loaded"
00137 <<"================================";
00138 }