CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/PhysicsTools/PatAlgos/src/MultiIsolator.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/PatAlgos/interface/MultiIsolator.h"
00002 #include "PhysicsTools/PatAlgos/interface/SimpleIsolator.h"
00003 #include "PhysicsTools/PatAlgos/interface/IsoDepositIsolator.h"
00004 #include "DataFormats/PatCandidates/interface/Flags.h"
00005 #include <sstream>
00006 
00007 using namespace pat::helper;
00008 
00009 MultiIsolator::MultiIsolator(const edm::ParameterSet &conf, bool cuts) {
00010     using pat::Flags;
00011     if (conf.exists("tracker")) addIsolator(conf.getParameter<edm::ParameterSet>("tracker"), cuts, Flags::Isolation::Tracker, pat::TrackIso);
00012     if (conf.exists("ecal"))    addIsolator(conf.getParameter<edm::ParameterSet>("ecal"),    cuts, Flags::Isolation::ECal, pat::EcalIso);
00013     if (conf.exists("hcal"))    addIsolator(conf.getParameter<edm::ParameterSet>("hcal"),    cuts, Flags::Isolation::HCal, pat::HcalIso);
00014     if (conf.exists("calo"))    addIsolator(conf.getParameter<edm::ParameterSet>("calo"),    cuts, Flags::Isolation::Calo, pat::CaloIso);
00015     if (conf.exists("calo") && (conf.exists("ecal") || conf.exists("hcal"))) {
00016         throw cms::Exception("Configuration") << 
00017             "MultiIsolator: you can't specify both 'calo' isolation and 'ecal'/'hcal', " <<
00018             "as the 'calo' isolation flag is just the logical OR of 'ecal' and 'hcal'.\n";                            
00019     }
00020     if (conf.exists("pfAllParticles"))  addIsolator(conf.getParameter<edm::ParameterSet>("pfAllParticles"), cuts,Flags::Isolation::Calo, pat::PfAllParticleIso);         
00021     if (conf.exists("pfChargedHadron")) addIsolator(conf.getParameter<edm::ParameterSet>("pfChargedHadron"), cuts,Flags::Isolation::Calo, pat::PfChargedHadronIso);      
00022     if (conf.exists("pfNeutralHadron")) addIsolator(conf.getParameter<edm::ParameterSet>("pfNeutralHadron"), cuts,Flags::Isolation::Calo, pat::PfNeutralHadronIso);      
00023     if (conf.exists("pfGamma"))         addIsolator(conf.getParameter<edm::ParameterSet>("pfGamma"), cuts,Flags::Isolation::Calo, pat::PfGammaIso);
00024     if (conf.exists("user")) {
00025    
00026         std::vector<edm::ParameterSet> psets = conf.getParameter<std::vector<edm::ParameterSet> >("user");
00027         if (psets.size() > 5) {
00028             throw cms::Exception("Configuration") << 
00029                 "MultiIsolator: you can specify at most 5 user isolation collections.\n";            
00030         }
00031         uint32_t bit = Flags::Isolation::User1;
00032         for (std::vector<edm::ParameterSet>::const_iterator it = psets.begin(), ed = psets.end(); it != ed; ++it, bit <<= 1) {
00033             addIsolator(*it, cuts, bit, pat::IsolationKeys(pat::UserBaseIso + (it - psets.begin())));
00034         }
00035     }
00036 }
00037 
00038 
00039 void 
00040 MultiIsolator::addIsolator(BaseIsolator *iso, uint32_t mask, pat::IsolationKeys key) {
00041     isolators_.push_back(iso);
00042     masks_.push_back(mask); 
00043     keys_.push_back(key);
00044 }
00045 
00046 BaseIsolator * 
00047 MultiIsolator::make(const edm::ParameterSet &conf, bool withCut) {
00048     if (conf.empty()) return 0;
00049     if (conf.exists("placeholder") && conf.getParameter<bool>("placeholder")) return 0;
00050     if (conf.exists("deltaR")) {
00051         return new IsoDepositIsolator(conf, withCut);
00052     } else {
00053         return new SimpleIsolator(conf, withCut);
00054     }
00055 }
00056 
00057 
00058 void 
00059 MultiIsolator::addIsolator(const edm::ParameterSet &conf, bool withCut, uint32_t mask, pat::IsolationKeys key) {
00060    BaseIsolator * iso = make(conf, withCut);
00061     if (iso) addIsolator(iso, mask, key);
00062 }
00063 
00064 
00065 void
00066 MultiIsolator::beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) {
00067     for (boost::ptr_vector<BaseIsolator>::iterator it = isolators_.begin(), ed = isolators_.end(); it != ed; ++it) {
00068         it->beginEvent(event, eventSetup);
00069     }
00070 }
00071 
00072 void
00073 MultiIsolator::endEvent() {
00074     for (boost::ptr_vector<BaseIsolator>::iterator it = isolators_.begin(), ed = isolators_.end(); it != ed; ++it) {
00075         it->endEvent();
00076     }
00077 }
00078 
00079 void
00080 MultiIsolator::print(std::ostream &out) const {
00081     for (boost::ptr_vector<BaseIsolator>::const_iterator it = isolators_.begin(), ed = isolators_.end(); it != ed; ++it) {
00082         out << " * ";
00083         it->print(out); 
00084         out << ": Flag " << pat::Flags::bitToString( masks_[it - isolators_.begin()] ) << "\n";
00085     }    
00086     out << "\n";
00087 }
00088 
00089 std::string 
00090 MultiIsolator::printSummary() const {
00091     std::ostringstream isoSumm;
00092     print(isoSumm);
00093     return isoSumm.str();
00094 }
00095