CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoMuon/L3MuonIsolationProducer/src/L3MuonIsolationProducer.cc

Go to the documentation of this file.
00001 #include "L3MuonIsolationProducer.h"
00002 
00003 // Framework
00004 #include "FWCore/Framework/interface/EDProducer.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "DataFormats/Common/interface/Handle.h"
00008 
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 
00013 #include "DataFormats/Common/interface/AssociationMap.h"
00014 #include "DataFormats/TrackReco/interface/Track.h"
00015 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00016 
00017 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00018 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00019 
00020 #include "RecoMuon/MuonIsolation/interface/Range.h"
00021 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00022 
00023 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
00024 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractorFactory.h"
00025 
00026 #include "L3NominalEfficiencyConfigurator.h"
00027 
00028 #include <string>
00029 
00030 using namespace edm;
00031 using namespace std;
00032 using namespace reco;
00033 using namespace muonisolation;
00034 
00036 L3MuonIsolationProducer::L3MuonIsolationProducer(const ParameterSet& par) :
00037   theConfig(par),
00038   theMuonCollectionLabel(par.getParameter<InputTag>("inputMuonCollection")),
00039   optOutputIsoDeposits(par.getParameter<bool>("OutputMuIsoDeposits")),
00040   theExtractor(0),
00041   theTrackPt_Min(-1)
00042   {
00043   LogDebug("RecoMuon|L3MuonIsolationProducer")<<" L3MuonIsolationProducer CTOR";
00044 
00045   if (optOutputIsoDeposits) produces<reco::IsoDepositMap>();
00046   produces<edm::ValueMap<bool> >();
00047 }
00048   
00050 L3MuonIsolationProducer::~L3MuonIsolationProducer(){
00051   LogDebug("RecoMuon|L3MuonIsolationProducer")<<" L3MuonIsolationProducer DTOR";
00052   if (theExtractor) delete theExtractor;
00053 }
00054 
00055 void L3MuonIsolationProducer::beginJob()
00056 {
00057 
00058   //
00059   // Extractor
00060   //
00061   edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
00063   theTrackPt_Min = theConfig.getParameter<double>("TrackPt_Min");
00064   std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
00065   theExtractor = IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet);
00066   std::string depositType = extractorPSet.getUntrackedParameter<std::string>("DepositLabel");
00067   
00068   //
00069   // Cuts
00070   //
00071   edm::ParameterSet cutsPSet = theConfig.getParameter<edm::ParameterSet>("CutsPSet");
00072   std::string cutsName = cutsPSet.getParameter<std::string>("ComponentName");
00073   if (cutsName == "SimpleCuts") {
00074     theCuts = Cuts(cutsPSet);
00075   } 
00076   else if (
00077 //        (cutsName== "L3NominalEfficiencyCuts_PXLS" && depositType=="PXLS")
00078 //     || (cutsName== "L3NominalEfficiencyCuts_TRKS" && depositType=="TRKS") 
00080            (cutsName== "L3NominalEfficiencyCuts_PXLS" )
00081            || (cutsName== "L3NominalEfficiencyCuts_TRKS") ) {
00082     theCuts = L3NominalEfficiencyConfigurator(cutsPSet).cuts();
00083   } 
00084   else {
00085     LogError("L3MuonIsolationProducer::beginJob")
00086       <<"cutsName: "<<cutsPSet<<" is not recognized:"
00087       <<" theCuts not set!";
00088   }
00089   LogTrace("")<< theCuts.print();
00090 
00091   // (kludge) additional cut on the number of tracks
00092   theMaxNTracks = cutsPSet.getParameter<int>("maxNTracks");
00093   theApplyCutsORmaxNTracks = cutsPSet.getParameter<bool>("applyCutsORmaxNTracks");
00094 }
00095 
00096 void L3MuonIsolationProducer::produce(Event& event, const EventSetup& eventSetup){
00097   std::string metname = "RecoMuon|L3MuonIsolationProducer";
00098   
00099   LogDebug(metname)<<" L3 Muon Isolation producing..."
00100                     <<" BEGINING OF EVENT " <<"================================";
00101 
00102   // Take the SA container
00103   LogTrace(metname)<<" Taking the muons: "<<theMuonCollectionLabel;
00104   Handle<TrackCollection> muons;
00105   event.getByLabel(theMuonCollectionLabel,muons);
00106 
00107   std::auto_ptr<reco::IsoDepositMap> depMap( new reco::IsoDepositMap());
00108   std::auto_ptr<edm::ValueMap<bool> > isoMap( new edm::ValueMap<bool> ());
00109 
00110 
00111   //
00112   // get Vetos and deposits
00113   //
00114   unsigned int nMuons = muons->size();
00115 
00116   IsoDeposit::Vetos vetos(nMuons);
00117   
00118   std::vector<IsoDeposit> deps(nMuons);
00119   std::vector<bool> isos(nMuons, false);
00120 
00121   for (unsigned int i=0; i<nMuons; i++) {
00122     TrackRef mu(muons,i);
00123     deps[i] = theExtractor->deposit(event, eventSetup, *mu);
00124     vetos[i] = deps[i].veto();
00125   }
00126 
00127   //
00128   // add here additional vetos
00129   //
00130   //.....
00131 
00132   //
00133   // actual cut step
00134   //
00135   for(unsigned int iMu=0; iMu < nMuons; ++iMu){
00136     const reco::Track* mu = &(*muons)[iMu];
00137 
00138     const IsoDeposit & deposit = deps[iMu];
00139     LogTrace(metname)<< deposit.print();
00140 
00141     const Cuts::CutSpec & cut = theCuts( mu->eta());
00142     std::pair<double, int> sumAndCount = deposit.depositAndCountWithin(cut.conesize, vetos, theTrackPt_Min);
00143 
00144     double value = sumAndCount.first;
00145     int count = sumAndCount.second;
00146 
00147     bool result = (value < cut.threshold); 
00148     if (theApplyCutsORmaxNTracks ) result |= count <= theMaxNTracks;
00149     LogTrace(metname)<<"deposit in cone: "<<value<<"with count "<<count<<" is isolated: "<<result;
00150 
00151     isos[iMu] = result;
00152   }
00153 
00154   //
00155   // store
00156   //
00157   if (optOutputIsoDeposits){
00158     reco::IsoDepositMap::Filler depFiller(*depMap);
00159     depFiller.insert(muons, deps.begin(), deps.end());
00160     depFiller.fill();
00161     event.put(depMap);
00162   }
00163   edm::ValueMap<bool> ::Filler isoFiller(*isoMap);
00164   isoFiller.insert(muons, isos.begin(), isos.end());
00165   isoFiller.fill();
00166   event.put(isoMap);
00167 
00168   LogTrace(metname) <<" END OF EVENT " <<"================================";
00169 }