CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IsoDepositIsolator.cc
Go to the documentation of this file.
2 #include <sstream>
3 
6 
9 using namespace reco::isodeposit;
10 
11 IsoDepositIsolator::IsoDepositIsolator(const edm::ParameterSet &conf, edm::ConsumesCollector &iC, bool withCut)
12  : BaseIsolator(conf, iC, withCut),
13  deltaR_(conf.getParameter<double>("deltaR")),
14  mode_(Sum),
15  skipDefaultVeto_(false),
16  inputIsoDepositToken_(iC.consumes<Isolation>(input_)) {
17  if (conf.exists("mode")) {
18  std::string mode = conf.getParameter<std::string>("mode");
19  if (mode == "sum")
20  mode_ = Sum;
21  else if (mode == "sumRelative")
23  else if (mode == "max")
24  mode_ = Max;
25  else if (mode == "maxRelative")
27  else if (mode == "sum2")
28  mode_ = Sum2;
29  else if (mode == "sum2Relative")
31  else if (mode == "count")
32  mode_ = Count;
33  else
34  throw cms::Exception("Not Implemented")
35  << "Mode '" << mode << "' not implemented. "
36  << "Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'sum2', 'sum2Relative', 'count'."
37  << "New methods can be easily implemented if requested.";
38  }
39 
40  if (conf.exists("veto")) {
41  vetos_.push_back(new ConeVeto(Direction(), conf.getParameter<double>("veto")));
42  }
43  if (conf.exists("threshold")) {
44  vetos_.push_back(new ThresholdVeto(conf.getParameter<double>("threshold")));
45  }
46  if (conf.exists("skipDefaultVeto")) {
47  skipDefaultVeto_ = conf.getParameter<bool>("skipDefaultVeto");
48  }
49 
50  if (conf.exists("vetos")) { // expert configuration
51  if (!vetos_.empty())
52  throw cms::Exception("Configuration")
53  << "You can't both configure this module with 'veto'/'threshold' AND with 'vetos'!";
54  if (!conf.exists("skipDefaultVeto"))
55  throw cms::Exception("Configuration") << "When using the expert configuration variable 'vetos' you must specify "
56  "the value for 'skipDefaultVeto' too.";
57 
58  typedef std::vector<std::string> vstring;
59  vstring vetos = conf.getParameter<vstring>("vetos");
61  for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
62  vetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
63  if (evdep != nullptr)
64  evdepVetos_.push_back(evdep);
65  }
66  }
67 }
68 
70  for (auto veto : vetos_) {
71  delete veto;
72  }
73 }
74 
76  event.getByToken(inputIsoDepositToken_, handle_);
77  for (auto veto : evdepVetos_) {
78  veto->setEvent(event, eventSetup);
79  }
80 }
81 
83 
85  using namespace std;
86  ostringstream oss;
87  oss << input_.encode() << "(dR=" << deltaR_ << ")";
88  return oss.str();
89 }
90 
91 float IsoDepositIsolator::getValue(const edm::ProductID &id, size_t index) const {
92  const reco::IsoDeposit &dep = handle_->get(id, index);
93 
94  double eta = dep.eta(),
95  phi = dep.phi(); // better to center on the deposit direction that could be, e.g., the impact point at calo
96  for (auto veto : vetos_) {
97  veto->centerOn(eta, phi);
98  }
99  switch (mode_) {
100  case Count:
101  return dep.countWithin(deltaR_, vetos_, skipDefaultVeto_);
102  case Sum:
103  return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_);
104  case SumRelative:
105  return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy();
106  case Sum2:
107  return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_);
108  case Sum2Relative:
109  return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy());
110  case Max:
111  return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_);
112  case MaxRelative:
113  return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy();
114  }
115  throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line "
116  << __LINE__; // avoid gcc warning
117 }
static reco::isodeposit::AbsVeto * make(const char *string, edm::ConsumesCollector &iC)
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:129
double sum2Within(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:143
double eta() const
Definition: IsoDeposit.h:76
vector< string > vstring
Definition: ExoticaDQM.cc:8
reco::isodeposit::AbsVetos vetos_
std::string description() const override
double phi() const
Definition: IsoDeposit.h:77
bool exists(std::string const &parameterName) const
checks if a parameter exists
double countWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:134
double maxWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:146
float getValue(const edm::ProductID &id, size_t index) const override
std::string encode() const
Definition: InputTag.cc:159
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:137
edm::Handle< Isolation > handle_
reco::isodeposit::EventDependentAbsVetos evdepVetos_
edm::EDGetTokenT< Isolation > inputIsoDepositToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) override