Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:03

0001 #include "PhysicsTools/PatAlgos/interface/MultiIsolator.h"
0002 #include "PhysicsTools/PatAlgos/interface/SimpleIsolator.h"
0003 #include "PhysicsTools/PatAlgos/interface/IsoDepositIsolator.h"
0004 #include "DataFormats/PatCandidates/interface/Flags.h"
0005 #include <sstream>
0006 
0007 using namespace pat::helper;
0008 
0009 MultiIsolator::MultiIsolator(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC, bool cuts) {
0010   using pat::Flags;
0011   if (conf.exists("tracker"))
0012     addIsolator(conf.getParameter<edm::ParameterSet>("tracker"), iC, cuts, Flags::Isolation::Tracker, pat::TrackIso);
0013   if (conf.exists("ecal"))
0014     addIsolator(conf.getParameter<edm::ParameterSet>("ecal"), iC, cuts, Flags::Isolation::ECal, pat::EcalIso);
0015   if (conf.exists("hcal"))
0016     addIsolator(conf.getParameter<edm::ParameterSet>("hcal"), iC, cuts, Flags::Isolation::HCal, pat::HcalIso);
0017   if (conf.exists("calo"))
0018     addIsolator(conf.getParameter<edm::ParameterSet>("calo"), iC, cuts, Flags::Isolation::Calo, pat::CaloIso);
0019   if (conf.exists("calo") && (conf.exists("ecal") || conf.exists("hcal"))) {
0020     throw cms::Exception("Configuration")
0021         << "MultiIsolator: you can't specify both 'calo' isolation and 'ecal'/'hcal', "
0022         << "as the 'calo' isolation flag is just the logical OR of 'ecal' and 'hcal'.\n";
0023   }
0024   if (conf.exists("pfAllParticles"))
0025     addIsolator(
0026         conf.getParameter<edm::ParameterSet>("pfAllParticles"), iC, cuts, Flags::Isolation::Calo, pat::PfAllParticleIso);
0027   if (conf.exists("pfChargedHadron"))
0028     addIsolator(conf.getParameter<edm::ParameterSet>("pfChargedHadron"),
0029                 iC,
0030                 cuts,
0031                 Flags::Isolation::Calo,
0032                 pat::PfChargedHadronIso);
0033   if (conf.exists("pfNeutralHadron"))
0034     addIsolator(conf.getParameter<edm::ParameterSet>("pfNeutralHadron"),
0035                 iC,
0036                 cuts,
0037                 Flags::Isolation::Calo,
0038                 pat::PfNeutralHadronIso);
0039   if (conf.exists("pfGamma"))
0040     addIsolator(conf.getParameter<edm::ParameterSet>("pfGamma"), iC, cuts, Flags::Isolation::Calo, pat::PfGammaIso);
0041   if (conf.exists("user")) {
0042     std::vector<edm::ParameterSet> psets = conf.getParameter<std::vector<edm::ParameterSet> >("user");
0043     if (psets.size() > 5) {
0044       throw cms::Exception("Configuration") << "MultiIsolator: you can specify at most 5 user isolation collections.\n";
0045     }
0046     uint32_t bit = Flags::Isolation::User1;
0047     for (std::vector<edm::ParameterSet>::const_iterator it = psets.begin(), ed = psets.end(); it != ed;
0048          ++it, bit <<= 1) {
0049       addIsolator(*it, iC, cuts, bit, pat::IsolationKeys(pat::UserBaseIso + (it - psets.begin())));
0050     }
0051   }
0052 }
0053 
0054 void MultiIsolator::addIsolator(BaseIsolator *iso, uint32_t mask, pat::IsolationKeys key) {
0055   isolators_.emplace_back(iso);
0056   masks_.push_back(mask);
0057   keys_.push_back(key);
0058 }
0059 
0060 BaseIsolator *MultiIsolator::make(const edm::ParameterSet &conf, edm::ConsumesCollector &iC, bool withCut) {
0061   if (conf.empty())
0062     return nullptr;
0063   if (conf.exists("placeholder") && conf.getParameter<bool>("placeholder"))
0064     return nullptr;
0065   if (conf.exists("deltaR")) {
0066     return new IsoDepositIsolator(conf, iC, withCut);
0067   } else {
0068     return new SimpleIsolator(conf, iC, withCut);
0069   }
0070 }
0071 
0072 void MultiIsolator::addIsolator(
0073     const edm::ParameterSet &conf, edm::ConsumesCollector &iC, bool withCut, uint32_t mask, pat::IsolationKeys key) {
0074   BaseIsolator *iso = make(conf, iC, withCut);
0075   if (iso)
0076     addIsolator(iso, mask, key);
0077 }
0078 
0079 void MultiIsolator::beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) {
0080   for (auto it = isolators_.begin(), ed = isolators_.end(); it != ed; ++it) {
0081     (*it)->beginEvent(event, eventSetup);
0082   }
0083 }
0084 
0085 void MultiIsolator::endEvent() {
0086   for (auto it = isolators_.begin(), ed = isolators_.end(); it != ed; ++it) {
0087     (*it)->endEvent();
0088   }
0089 }
0090 
0091 void MultiIsolator::print(std::ostream &out) const {
0092   for (auto it = isolators_.cbegin(), ed = isolators_.end(); it != ed; ++it) {
0093     out << " * ";
0094     (*it)->print(out);
0095     out << ": Flag " << pat::Flags::bitToString(masks_[it - isolators_.begin()]) << "\n";
0096   }
0097   out << "\n";
0098 }
0099 
0100 std::string MultiIsolator::printSummary() const {
0101   std::ostringstream isoSumm;
0102   print(isoSumm);
0103   return isoSumm.str();
0104 }