test
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, edm::ConsumesCollector & iC, bool withCut) :
14  BaseIsolator(conf,iC,withCut), deltaR_(conf.getParameter<double>("deltaR")),
15  mode_(Sum), skipDefaultVeto_(false),
16  inputIsoDepositToken_(iC.consumes<Isolation>(input_))
17 {
18  if (conf.exists("mode")) {
19  std::string mode = conf.getParameter<std::string>("mode");
20  if (mode == "sum") mode_ = Sum;
21  else if (mode == "sumRelative") mode_ = SumRelative;
22  else if (mode == "max") mode_ = Max;
23  else if (mode == "maxRelative") mode_ = MaxRelative;
24  else if (mode == "sum2") mode_ = Sum2;
25  else if (mode == "sum2Relative") mode_ = Sum2Relative;
26  else if (mode == "count") mode_ = Count;
27  else throw cms::Exception("Not Implemented") << "Mode '" << mode << "' not implemented. " <<
28  "Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'sum2', 'sum2Relative', 'count'." <<
29  "New methods can be easily implemented if requested.";
30  }
31 
32  if (conf.exists("veto")) {
33  vetos_.push_back(new ConeVeto(Direction(), conf.getParameter<double>("veto")));
34  }
35  if (conf.exists("threshold")) {
36  vetos_.push_back(new ThresholdVeto(conf.getParameter<double>("threshold")));
37  }
38  if (conf.exists("skipDefaultVeto")) {
39  skipDefaultVeto_ = conf.getParameter<bool>("skipDefaultVeto");
40  }
41 
42  if (conf.exists("vetos")) { // expert configuration
43  if (!vetos_.empty())
44  throw cms::Exception("Configuration") << "You can't both configure this module with 'veto'/'threshold' AND with 'vetos'!";
45  if (!conf.exists("skipDefaultVeto"))
46  throw cms::Exception("Configuration") << "When using the expert configuration variable 'vetos' you must specify the value for 'skipDefaultVeto' too.";
47 
48  typedef std::vector<std::string> vstring;
49  vstring vetos = conf.getParameter< vstring >("vetos");
51  for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
52  vetos_.push_back( IsoDepositVetoFactory::make( it->c_str(), evdep, iC ) );
53  if (evdep != 0) evdepVetos_.push_back(evdep);
54  }
55  }
56 
57 }
58 
60  for (AbsVetos::iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
61  delete *it;
62  }
63 }
64 
65 void
67  event.getByToken(inputIsoDepositToken_, handle_);
68  for (EventDependentAbsVetos::iterator it = evdepVetos_.begin(), ed = evdepVetos_.end(); it != ed; ++it) {
69  (*it)->setEvent(event,eventSetup);
70  }
71 }
72 
73 void
75  handle_.clear();
76 }
77 
80  using namespace std;
81  ostringstream oss;
82  oss << input_.encode() << "(dR=" << deltaR_ <<")";
83  return oss.str();
84 }
85 
86 float
88  const reco::IsoDeposit &dep = handle_->get(id, index);
89 
90  double eta = dep.eta(), phi = dep.phi(); // better to center on the deposit direction that could be, e.g., the impact point at calo
91  for (AbsVetos::const_iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
92  (const_cast<AbsVeto *>(*it))->centerOn(eta, phi); // I need the const_cast to be able to 'move' the veto
93  }
94  switch (mode_) {
95  case Count: return dep.countWithin(deltaR_, vetos_, skipDefaultVeto_);
96  case Sum: return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_);
97  case SumRelative: return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy() ;
98  case Sum2: return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_);
99  case Sum2Relative: return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy()) ;
100  case Max: return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_);
101  case MaxRelative: return dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy() ;
102  }
103  throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line " << __LINE__; // avoid gcc warning
104 }
105 
static reco::isodeposit::AbsVeto * make(const char *string, edm::ConsumesCollector &iC)
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:136
double sum2Within(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:146
double eta() const
Definition: IsoDeposit.h:74
vector< string > vstring
Definition: ExoticaDQM.cc:8
reco::isodeposit::AbsVetos vetos_
double phi() const
Definition: IsoDeposit.h:75
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
double maxWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:150
std::string encode() const
Definition: InputTag.cc:164
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_
edm::EDGetTokenT< Isolation > inputIsoDepositToken_
Geom::Phi< T > phi() const
virtual float getValue(const edm::ProductID &id, size_t index) const
volatile std::atomic< bool > shutdown_flag false
virtual std::string description() const