CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/PhysicsTools/PatAlgos/src/IsoDepositIsolator.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/PatAlgos/interface/IsoDepositIsolator.h"
00002 #include <sstream>
00003 
00004 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
00005 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositVetoFactory.h"
00006 
00007 #include <boost/regex.hpp>
00008 
00009 using pat::helper::IsoDepositIsolator;
00010 using pat::helper::BaseIsolator;
00011 using namespace reco::isodeposit;
00012 
00013 IsoDepositIsolator::IsoDepositIsolator(const edm::ParameterSet &conf, bool withCut) :
00014     BaseIsolator(conf,withCut), deltaR_(conf.getParameter<double>("deltaR")), 
00015     mode_(Sum), skipDefaultVeto_(false)
00016 {
00017     if (conf.exists("mode")) {
00018         std::string mode = conf.getParameter<std::string>("mode");
00019         if (mode == "sum") mode_ = Sum;
00020         else if (mode == "sumRelative") mode_ = SumRelative;
00021         else if (mode == "max") mode_ = Max;                  
00022         else if (mode == "maxRelative") mode_ = MaxRelative;  
00023         else if (mode == "sum2") mode_ = Sum2;
00024         else if (mode == "sum2Relative") mode_ = Sum2Relative;
00025         else if (mode == "count") mode_ = Count;
00026         else throw cms::Exception("Not Implemented") << "Mode '" << mode << "' not implemented. " <<
00027                 "Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'sum2', 'sum2Relative', 'count'." <<
00028                 "New methods can be easily implemented if requested.";
00029     }
00030 
00031     if (conf.exists("veto")) {
00032         vetos_.push_back(new ConeVeto(Direction(), conf.getParameter<double>("veto"))); 
00033     }
00034     if (conf.exists("threshold")) {
00035         vetos_.push_back(new ThresholdVeto(conf.getParameter<double>("threshold"))); 
00036     }
00037     if (conf.exists("skipDefaultVeto")) {
00038         skipDefaultVeto_ = conf.getParameter<bool>("skipDefaultVeto");
00039     }
00040 
00041     if (conf.exists("vetos")) { // expert configuration
00042         if (!vetos_.empty()) 
00043             throw cms::Exception("Configuration") << "You can't both configure this module with 'veto'/'threshold' AND with 'vetos'!";
00044         if (!conf.exists("skipDefaultVeto")) 
00045             throw cms::Exception("Configuration") << "When using the expert configuration variable 'vetos' you must specify the value for 'skipDefaultVeto' too.";
00046 
00047         typedef std::vector<std::string> vstring;
00048         vstring vetos = conf.getParameter< vstring >("vetos");
00049         reco::isodeposit::EventDependentAbsVeto *evdep = 0;
00050         for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
00051               vetos_.push_back( IsoDepositVetoFactory::make( it->c_str(), evdep ) );
00052               if (evdep != 0) evdepVetos_.push_back(evdep);
00053         }
00054     }
00055 
00056 }
00057 
00058 IsoDepositIsolator::~IsoDepositIsolator() {
00059     for (AbsVetos::iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
00060         delete *it;
00061     }
00062 }
00063 
00064 void
00065 IsoDepositIsolator::beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) {
00066     event.getByLabel(input_, handle_);
00067     for (EventDependentAbsVetos::iterator it = evdepVetos_.begin(), ed = evdepVetos_.end(); it != ed; ++it) {
00068         (*it)->setEvent(event,eventSetup);
00069     }
00070 }
00071 
00072 void
00073 IsoDepositIsolator::endEvent() {
00074     handle_.clear();
00075 }
00076 
00077 std::string 
00078 IsoDepositIsolator::description() const {
00079     using namespace std;
00080     ostringstream oss;
00081     oss << input_.encode() << "(dR=" << deltaR_ <<")";
00082     return oss.str();
00083 }
00084 
00085 float
00086 IsoDepositIsolator::getValue(const edm::ProductID &id, size_t index) const {
00087     const reco::IsoDeposit &dep = handle_->get(id, index);
00088 
00089     double eta = dep.eta(), phi = dep.phi(); // better to center on the deposit direction that could be, e.g., the impact point at calo
00090     for (AbsVetos::const_iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
00091         (const_cast<AbsVeto *>(*it))->centerOn(eta, phi); // I need the const_cast to be able to 'move' the veto
00092     }
00093     switch (mode_) {
00094         case Count:        return dep.countWithin(deltaR_, vetos_, skipDefaultVeto_);
00095         case Sum:          return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_);
00096         case SumRelative:  return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy() ;
00097         case Sum2:         return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_);
00098         case Sum2Relative: return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy()) ;
00099         case Max:          return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_);
00100         case MaxRelative:  return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy() ;
00101     }
00102     throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line " << __LINE__; // avoid gcc warning
00103 }
00104