CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IsoDepositIsolator.cc
Go to the documentation of this file.
2 #include <sstream>
3 
6 
7 #include <boost/regex.hpp>
8 
11 using namespace reco::isodeposit;
12 
13 IsoDepositIsolator::IsoDepositIsolator(const edm::ParameterSet &conf, bool withCut) :
14  BaseIsolator(conf,withCut), deltaR_(conf.getParameter<double>("deltaR")),
15  mode_(Sum), skipDefaultVeto_(false)
16 {
17  if (conf.exists("mode")) {
18  std::string mode = conf.getParameter<std::string>("mode");
19  if (mode == "sum") mode_ = Sum;
20  else if (mode == "sumRelative") mode_ = SumRelative;
21  else if (mode == "max") mode_ = Max;
22  else if (mode == "maxRelative") mode_ = MaxRelative;
23  else if (mode == "sum2") mode_ = Sum2;
24  else if (mode == "sum2Relative") mode_ = Sum2Relative;
25  else if (mode == "count") mode_ = Count;
26  else throw cms::Exception("Not Implemented") << "Mode '" << mode << "' not implemented. " <<
27  "Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'sum2', 'sum2Relative', 'count'." <<
28  "New methods can be easily implemented if requested.";
29  }
30 
31  if (conf.exists("veto")) {
32  vetos_.push_back(new ConeVeto(Direction(), conf.getParameter<double>("veto")));
33  }
34  if (conf.exists("threshold")) {
35  vetos_.push_back(new ThresholdVeto(conf.getParameter<double>("threshold")));
36  }
37  if (conf.exists("skipDefaultVeto")) {
38  skipDefaultVeto_ = conf.getParameter<bool>("skipDefaultVeto");
39  }
40 
41  if (conf.exists("vetos")) { // expert configuration
42  if (!vetos_.empty())
43  throw cms::Exception("Configuration") << "You can't both configure this module with 'veto'/'threshold' AND with 'vetos'!";
44  if (!conf.exists("skipDefaultVeto"))
45  throw cms::Exception("Configuration") << "When using the expert configuration variable 'vetos' you must specify the value for 'skipDefaultVeto' too.";
46 
47  typedef std::vector<std::string> vstring;
48  vstring vetos = conf.getParameter< vstring >("vetos");
50  for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
51  vetos_.push_back( IsoDepositVetoFactory::make( it->c_str(), evdep ) );
52  if (evdep != 0) evdepVetos_.push_back(evdep);
53  }
54  }
55 
56 }
57 
59  for (AbsVetos::iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
60  delete *it;
61  }
62 }
63 
64 void
66  event.getByLabel(input_, handle_);
67  for (EventDependentAbsVetos::iterator it = evdepVetos_.begin(), ed = evdepVetos_.end(); it != ed; ++it) {
68  (*it)->setEvent(event,eventSetup);
69  }
70 }
71 
72 void
74  handle_.clear();
75 }
76 
77 std::string
79  using namespace std;
80  ostringstream oss;
81  oss << input_.encode() << "(dR=" << deltaR_ <<")";
82  return oss.str();
83 }
84 
85 float
87  const reco::IsoDeposit &dep = handle_->get(id, index);
88 
89  double eta = dep.eta(), phi = dep.phi(); // better to center on the deposit direction that could be, e.g., the impact point at calo
90  for (AbsVetos::const_iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
91  (const_cast<AbsVeto *>(*it))->centerOn(eta, phi); // I need the const_cast to be able to 'move' the veto
92  }
93  switch (mode_) {
94  case Count: return dep.countWithin(deltaR_, vetos_, skipDefaultVeto_);
95  case Sum: return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_);
96  case SumRelative: return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy() ;
97  case Sum2: return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_);
98  case Sum2Relative: return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy()) ;
99  case Max: return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_);
100  case MaxRelative: return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy() ;
101  }
102  throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line " << __LINE__; // avoid gcc warning
103 }
104 
T getParameter(std::string const &) const
virtual void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:131
double sum2Within(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:146
double eta() const
Definition: IsoDeposit.h:69
reco::isodeposit::AbsVetos vetos_
double phi() const
Definition: IsoDeposit.h:70
bool exists(std::string const &parameterName) const
checks if a parameter exists
double deltaR_
double countWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:134
T eta() const
double maxWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:150
std::string encode() const
Definition: InputTag.cc:72
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:138
edm::Handle< Isolation > handle_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
reco::isodeposit::EventDependentAbsVetos evdepVetos_
tuple conf
Definition: dbtoconf.py:185
std::vector< std::string > vstring
static reco::isodeposit::AbsVeto * make(const char *string)
virtual float getValue(const edm::ProductID &id, size_t index) const
virtual std::string description() const
Definition: DDAxes.h:10