Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:49

0001 /**  \class L2MuonIsolationProducer
0002  *
0003  *   \author  J. Alcaraz
0004  */
0005 
0006 // Framework
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/ConsumesCollector.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
0015 #include "RecoMuon/L2MuonIsolationProducer/src/L2MuonIsolationProducer.h"
0016 
0017 #include "DataFormats/Common/interface/AssociationMap.h"
0018 #include "DataFormats/TrackReco/interface/Track.h"
0019 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0020 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0021 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0022 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
0023 
0024 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractor.h"
0025 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositExtractorFactory.h"
0026 #include "RecoMuon/MuonIsolation/interface/MuonIsolatorFactory.h"
0027 
0028 #include <string>
0029 
0030 using namespace edm;
0031 using namespace std;
0032 using namespace reco;
0033 using namespace muonisolation;
0034 
0035 /// constructor with config
0036 L2MuonIsolationProducer::L2MuonIsolationProducer(const ParameterSet& par)
0037     : theSACollectionLabel(par.getParameter<edm::InputTag>("StandAloneCollectionLabel")) {
0038   LogDebug("Muon|RecoMuon|L2MuonIsolationProducer") << " L2MuonIsolationProducer constructor called";
0039 
0040   theSACollectionToken = consumes<RecoChargedCandidateCollection>(theSACollectionLabel);
0041 
0042   //
0043   // Extractor
0044   //
0045   edm::ParameterSet extractorPSet = par.getParameter<edm::ParameterSet>("ExtractorPSet");
0046   std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
0047   theExtractor = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{
0048       IsoDepositExtractorFactory::get()->create(extractorName, extractorPSet, consumesCollector())};
0049 
0050   edm::ParameterSet isolatorPSet = par.getParameter<edm::ParameterSet>("IsolatorPSet");
0051   bool haveIsolator = !isolatorPSet.empty();
0052   optOutputDecision = haveIsolator;
0053   if (optOutputDecision) {
0054     std::string type = isolatorPSet.getParameter<std::string>("ComponentName");
0055     theDepositIsolator = std::unique_ptr<muonisolation::MuIsoBaseIsolator>{
0056         MuonIsolatorFactory::get()->create(type, isolatorPSet, consumesCollector())};
0057   }
0058   if (optOutputDecision)
0059     produces<edm::ValueMap<bool>>();
0060   produces<reco::IsoDepositMap>();
0061 
0062   optOutputIsolatorFloat = par.getParameter<bool>("WriteIsolatorFloat");
0063   if (optOutputIsolatorFloat && haveIsolator) {
0064     produces<edm::ValueMap<float>>();
0065   }
0066 }
0067 
0068 /// destructor
0069 L2MuonIsolationProducer::~L2MuonIsolationProducer() {
0070   LogDebug("Muon|RecoMuon|L2MuonIsolationProducer") << " L2MuonIsolationProducer destructor called";
0071 }
0072 
0073 /// ParameterSet descriptions
0074 void L2MuonIsolationProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0075   edm::ParameterSetDescription desc;
0076   desc.add<edm::InputTag>("StandAloneCollectionLabel", edm::InputTag("hltL2MuonCandidates"));
0077   edm::ParameterSetDescription extractorPSet;
0078   {
0079     extractorPSet.add<double>("DR_Veto_H", 0.1);
0080     extractorPSet.add<bool>("Vertex_Constraint_Z", false);
0081     extractorPSet.add<double>("Threshold_H", 0.5);
0082     extractorPSet.add<std::string>("ComponentName", "CaloExtractor");
0083     extractorPSet.add<double>("Threshold_E", 0.2);
0084     extractorPSet.add<double>("DR_Max", 1.0);
0085     extractorPSet.add<double>("DR_Veto_E", 0.07);
0086     extractorPSet.add<double>("Weight_E", 1.5);
0087     extractorPSet.add<bool>("Vertex_Constraint_XY", false);
0088     extractorPSet.addUntracked<std::string>("DepositLabel", "EcalPlusHcal");
0089     extractorPSet.add<edm::InputTag>("CaloTowerCollectionLabel", edm::InputTag("towerMaker"));
0090     extractorPSet.add<double>("Weight_H", 1.0);
0091   }
0092   desc.add<edm::ParameterSetDescription>("ExtractorPSet", extractorPSet);
0093   edm::ParameterSetDescription isolatorPSet;
0094   {
0095     std::vector<double> temp;
0096     isolatorPSet.add<std::vector<double>>("ConeSizesRel", std::vector<double>(1, 0.3));
0097     isolatorPSet.add<double>("EffAreaSFEndcap", 1.0);
0098     isolatorPSet.add<bool>("CutAbsoluteIso", true);
0099     isolatorPSet.add<bool>("AndOrCuts", true);
0100     isolatorPSet.add<edm::InputTag>("RhoSrc", edm::InputTag("hltKT6CaloJetsForMuons", "rho"));
0101     isolatorPSet.add<std::vector<double>>("ConeSizes", std::vector<double>(1, 0.3));
0102     isolatorPSet.add<std::string>("ComponentName", "CutsIsolatorWithCorrection");
0103     isolatorPSet.add<bool>("ReturnRelativeSum", false);
0104     isolatorPSet.add<double>("RhoScaleBarrel", 1.0);
0105     isolatorPSet.add<double>("EffAreaSFBarrel", 1.0);
0106     isolatorPSet.add<bool>("CutRelativeIso", false);
0107     isolatorPSet.add<std::vector<double>>("EtaBounds", std::vector<double>(1, 2.411));
0108     isolatorPSet.add<std::vector<double>>("Thresholds", std::vector<double>(1, 9.9999999E7));
0109     isolatorPSet.add<bool>("ReturnAbsoluteSum", true);
0110     isolatorPSet.add<std::vector<double>>("EtaBoundsRel", std::vector<double>(1, 2.411));
0111     isolatorPSet.add<std::vector<double>>("ThresholdsRel", std::vector<double>(1, 9.9999999E7));
0112     isolatorPSet.add<double>("RhoScaleEndcap", 1.0);
0113     isolatorPSet.add<double>("RhoMax", 9.9999999E7);
0114     isolatorPSet.add<bool>("UseRhoCorrection", true);
0115   }
0116   desc.add<edm::ParameterSetDescription>("IsolatorPSet", isolatorPSet);
0117   desc.add<bool>("WriteIsolatorFloat", false);
0118   descriptions.add("hltL2MuonIsolations", desc);
0119 }
0120 
0121 /// build deposits
0122 void L2MuonIsolationProducer::produce(Event& event, const EventSetup& eventSetup) {
0123   std::string metname = "Muon|RecoMuon|L2MuonIsolationProducer";
0124 
0125   LogDebug(metname) << " L2 Muon Isolation producing...";
0126 
0127   // Take the SA container
0128   LogDebug(metname) << " Taking the StandAlone muons: " << theSACollectionLabel;
0129   Handle<RecoChargedCandidateCollection> muons;
0130   event.getByToken(theSACollectionToken, muons);
0131 
0132   // Find deposits and load into event
0133   LogDebug(metname) << " Get energy around";
0134   auto depMap = std::make_unique<reco::IsoDepositMap>();
0135   auto isoMap = std::make_unique<edm::ValueMap<bool>>();
0136   auto isoFloatMap = std::make_unique<edm::ValueMap<float>>();
0137 
0138   unsigned int nMuons = muons->size();
0139   std::vector<IsoDeposit> deps(nMuons);
0140   std::vector<bool> isos(nMuons, false);
0141   std::vector<float> isoFloats(nMuons, 0);
0142 
0143   // fill track collection to use for vetos calculation
0144   TrackCollection muonTracks;
0145   for (unsigned int i = 0; i < nMuons; i++) {
0146     TrackRef tk = (*muons)[i].track();
0147     muonTracks.push_back(*tk);
0148   }
0149 
0150   theExtractor->fillVetos(event, eventSetup, muonTracks);
0151 
0152   for (unsigned int i = 0; i < nMuons; i++) {
0153     TrackRef tk = (*muons)[i].track();
0154 
0155     deps[i] = theExtractor->deposit(event, eventSetup, *tk);
0156 
0157     if (optOutputDecision) {
0158       muonisolation::MuIsoBaseIsolator::DepositContainer isoContainer(
0159           1, muonisolation::MuIsoBaseIsolator::DepositAndVetos(&deps[i]));
0160       muonisolation::MuIsoBaseIsolator::Result isoResult = theDepositIsolator->result(isoContainer, *tk, &event);
0161       isos[i] = isoResult.valBool;
0162       isoFloats[i] = isoResult.valFloat;
0163     }
0164   }
0165 
0166   //!do the business of filling iso map
0167   reco::IsoDepositMap::Filler depFiller(*depMap);
0168   depFiller.insert(muons, deps.begin(), deps.end());
0169   depFiller.fill();
0170   event.put(std::move(depMap));
0171 
0172   if (optOutputDecision) {
0173     edm::ValueMap<bool>::Filler isoFiller(*isoMap);
0174     isoFiller.insert(muons, isos.begin(), isos.end());
0175     isoFiller.fill();  //! annoying -- I will forget it at some point
0176     event.put(std::move(isoMap));
0177 
0178     if (optOutputIsolatorFloat) {
0179       edm::ValueMap<float>::Filler isoFloatFiller(*isoFloatMap);
0180       isoFloatFiller.insert(muons, isoFloats.begin(), isoFloats.end());
0181       isoFloatFiller.fill();  //! annoying -- I will forget it at some point
0182       event.put(std::move(isoFloatMap));
0183     }
0184   }
0185 
0186   LogDebug(metname) << " Event loaded"
0187                     << "================================";
0188 }