CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/RecoMuon/L2MuonIsolationProducer/src/L2MuonIsolationProducer.cc

Go to the documentation of this file.
00001 
00006 // Framework
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   // Extractor
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   optOutputDecision = !isolatorPSet.empty();
00052   if (optOutputDecision){
00053     std::string type = isolatorPSet.getParameter<std::string>("ComponentName");
00054     theDepositIsolator = MuonIsolatorFactory::get()->create(type,isolatorPSet);
00055   }
00056   if (optOutputDecision) produces<edm::ValueMap<bool> >();
00057   produces<reco::IsoDepositMap>();
00058 }
00059   
00061 L2MuonIsolationProducer::~L2MuonIsolationProducer(){
00062   LogDebug("Muon|RecoMuon|L2MuonIsolationProducer")<<" L2MuonIsolationProducer destructor called";
00063   if (theExtractor) delete theExtractor;
00064 }
00065 
00067 void L2MuonIsolationProducer::beginJob(){
00068 
00069 }
00070 
00072 void L2MuonIsolationProducer::produce(Event& event, const EventSetup& eventSetup){
00073   std::string metname = "Muon|RecoMuon|L2MuonIsolationProducer";
00074   
00075   LogDebug(metname)<<" L2 Muon Isolation producing...";
00076 
00077   // Take the SA container
00078   LogDebug(metname)<<" Taking the StandAlone muons: "<<theSACollectionLabel;
00079   Handle<TrackCollection> tracks;
00080   event.getByLabel(theSACollectionLabel,tracks);
00081 
00082   // Find deposits and load into event
00083   LogDebug(metname)<<" Get energy around";
00084   std::auto_ptr<reco::IsoDepositMap> depMap( new reco::IsoDepositMap());
00085   std::auto_ptr<edm::ValueMap<bool> > isoMap( new edm::ValueMap<bool> ());
00086 
00087   theExtractor->fillVetos(event,eventSetup,*tracks);
00088 
00089   unsigned int nTracks = tracks->size();
00090   std::vector<IsoDeposit> deps(nTracks);
00091   std::vector<bool> isos(nTracks, false);
00092 
00093   for (unsigned int i=0; i<nTracks; i++) {
00094       TrackRef tk(tracks,i);
00095 
00096       deps[i] = theExtractor->deposit(event, eventSetup, *tk);
00097 
00098       if (optOutputDecision){
00099         muonisolation::MuIsoBaseIsolator::DepositContainer isoContainer(1,muonisolation::MuIsoBaseIsolator::DepositAndVetos(&deps[i]));
00100         isos[i] = theDepositIsolator->result( isoContainer, *tk ).valBool;
00101       }
00102   }
00103 
00104   
00105 
00107   reco::IsoDepositMap::Filler depFiller(*depMap);
00108   depFiller.insert(tracks, deps.begin(), deps.end());
00109   depFiller.fill();
00110   event.put(depMap);
00111 
00112   if (optOutputDecision){
00113     edm::ValueMap<bool> ::Filler isoFiller(*isoMap);
00114     isoFiller.insert(tracks, isos.begin(), isos.end());
00115     isoFiller.fill();
00116     event.put(isoMap);
00117   }
00118   
00119   LogDebug(metname) <<" Event loaded"
00120                     <<"================================";
00121 }