Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "PhysicsTools/PatAlgos/interface/IsoDepositIsolator.h"
0002 #include <sstream>
0003 
0004 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
0005 #include "PhysicsTools/IsolationAlgos/interface/IsoDepositVetoFactory.h"
0006 
0007 using pat::helper::BaseIsolator;
0008 using pat::helper::IsoDepositIsolator;
0009 using namespace reco::isodeposit;
0010 
0011 IsoDepositIsolator::IsoDepositIsolator(const edm::ParameterSet &conf, edm::ConsumesCollector &iC, bool withCut)
0012     : BaseIsolator(conf, iC, withCut),
0013       deltaR_(conf.getParameter<double>("deltaR")),
0014       mode_(Sum),
0015       skipDefaultVeto_(false),
0016       inputIsoDepositToken_(iC.consumes<Isolation>(input_)) {
0017   if (conf.exists("mode")) {
0018     std::string mode = conf.getParameter<std::string>("mode");
0019     if (mode == "sum")
0020       mode_ = Sum;
0021     else if (mode == "sumRelative")
0022       mode_ = SumRelative;
0023     else if (mode == "max")
0024       mode_ = Max;
0025     else if (mode == "maxRelative")
0026       mode_ = MaxRelative;
0027     else if (mode == "sum2")
0028       mode_ = Sum2;
0029     else if (mode == "sum2Relative")
0030       mode_ = Sum2Relative;
0031     else if (mode == "count")
0032       mode_ = Count;
0033     else
0034       throw cms::Exception("Not Implemented")
0035           << "Mode '" << mode << "' not implemented. "
0036           << "Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'sum2', 'sum2Relative', 'count'."
0037           << "New methods can be easily implemented if requested.";
0038   }
0039 
0040   if (conf.exists("veto")) {
0041     vetos_.push_back(new ConeVeto(Direction(), conf.getParameter<double>("veto")));
0042   }
0043   if (conf.exists("threshold")) {
0044     vetos_.push_back(new ThresholdVeto(conf.getParameter<double>("threshold")));
0045   }
0046   if (conf.exists("skipDefaultVeto")) {
0047     skipDefaultVeto_ = conf.getParameter<bool>("skipDefaultVeto");
0048   }
0049 
0050   if (conf.exists("vetos")) {  // expert configuration
0051     if (!vetos_.empty())
0052       throw cms::Exception("Configuration")
0053           << "You can't both configure this module with 'veto'/'threshold' AND with 'vetos'!";
0054     if (!conf.exists("skipDefaultVeto"))
0055       throw cms::Exception("Configuration") << "When using the expert configuration variable 'vetos' you must specify "
0056                                                "the value for 'skipDefaultVeto' too.";
0057 
0058     typedef std::vector<std::string> vstring;
0059     vstring vetos = conf.getParameter<vstring>("vetos");
0060     reco::isodeposit::EventDependentAbsVeto *evdep = nullptr;
0061     for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
0062       vetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
0063       if (evdep != nullptr)
0064         evdepVetos_.push_back(evdep);
0065     }
0066   }
0067 }
0068 
0069 IsoDepositIsolator::~IsoDepositIsolator() {
0070   for (auto veto : vetos_) {
0071     delete veto;
0072   }
0073 }
0074 
0075 void IsoDepositIsolator::beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) {
0076   event.getByToken(inputIsoDepositToken_, handle_);
0077   for (auto veto : evdepVetos_) {
0078     veto->setEvent(event, eventSetup);
0079   }
0080 }
0081 
0082 void IsoDepositIsolator::endEvent() { handle_.clear(); }
0083 
0084 std::string IsoDepositIsolator::description() const {
0085   using namespace std;
0086   ostringstream oss;
0087   oss << input_.encode() << "(dR=" << deltaR_ << ")";
0088   return oss.str();
0089 }
0090 
0091 float IsoDepositIsolator::getValue(const edm::ProductID &id, size_t index) const {
0092   const reco::IsoDeposit &dep = handle_->get(id, index);
0093 
0094   double eta = dep.eta(),
0095          phi = dep.phi();  // better to center on the deposit direction that could be, e.g., the impact point at calo
0096   for (auto veto : vetos_) {
0097     veto->centerOn(eta, phi);
0098   }
0099   switch (mode_) {
0100     case Count:
0101       return dep.countWithin(deltaR_, vetos_, skipDefaultVeto_);
0102     case Sum:
0103       return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_);
0104     case SumRelative:
0105       return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy();
0106     case Sum2:
0107       return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_);
0108     case Sum2Relative:
0109       return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy());
0110     case Max:
0111       return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_);
0112     case MaxRelative:
0113       return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy();
0114   }
0115   throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line "
0116                                       << __LINE__;  // avoid gcc warning
0117 }