CMS 3D CMS Logo

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:
102  case Sum:
104  case SumRelative:
105  return dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy();
106  case Sum2:
108  case Sum2Relative:
109  return dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy());
110  case Max:
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 }
pat::helper::IsoDepositIsolator::description
std::string description() const override
Definition: IsoDepositIsolator.cc:84
IsoDepositVetos.h
funct::false
false
Definition: Factorize.h:34
pat::helper::IsoDepositIsolator::beginEvent
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: IsoDepositIsolator.cc:75
IsoDepositVetoFactory.h
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
pat::helper::IsoDepositIsolator::handle_
edm::Handle< Isolation > handle_
Definition: IsoDepositIsolator.h:24
reco::IsoDeposit::sum2Within
double sum2Within(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:143
reco::isodeposit::ConeVeto
Definition: IsoDepositVetos.h:9
pat::helper::IsoDepositIsolator::SumRelative
Definition: IsoDepositIsolator.h:23
reco::IsoDeposit::countWithin
double countWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:134
reco::isodeposit
Definition: IsoDeposit.h:31
pat::helper::IsoDepositIsolator::vetos_
reco::isodeposit::AbsVetos vetos_
Definition: IsoDepositIsolator.h:28
PVValHelper::eta
Definition: PVValidationHelpers.h:69
pat::helper::IsoDepositIsolator::inputIsoDepositToken_
edm::EDGetTokenT< Isolation > inputIsoDepositToken_
Definition: IsoDepositIsolator.h:31
pat::helper::IsoDepositIsolator::evdepVetos_
reco::isodeposit::EventDependentAbsVetos evdepVetos_
Definition: IsoDepositIsolator.h:29
pat::helper::IsoDepositIsolator
Definition: IsoDepositIsolator.h:10
Sum
Definition: SiPixelActionExecutor.h:21
pat::helper::IsoDepositIsolator::Max
Definition: IsoDepositIsolator.h:23
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
IsoDepositIsolator.h
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:674
edm::ParameterSet
Definition: ParameterSet.h:36
pat::helper::IsoDepositIsolator::getValue
float getValue(const edm::ProductID &id, size_t index) const override
Definition: IsoDepositIsolator.cc:91
pat::helper::BaseIsolator::input_
edm::InputTag input_
Definition: BaseIsolator.h:42
reco::IsoDeposit::sumWithin
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:137
pat::helper::IsoDepositIsolator::endEvent
void endEvent() override
Definition: IsoDepositIsolator.cc:82
reco::IsoDeposit::candEnergy
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:129
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
edm::EventSetup
Definition: EventSetup.h:57
pat::helper::IsoDepositIsolator::skipDefaultVeto_
bool skipDefaultVeto_
Definition: IsoDepositIsolator.h:30
pat::helper::BaseIsolator
Definition: BaseIsolator.h:13
pat::helper::IsoDepositIsolator::MaxRelative
Definition: IsoDepositIsolator.h:23
reco::isodeposit::ThresholdVeto
Definition: IsoDepositVetos.h:21
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
std
Definition: JetResolutionObject.h:76
reco::IsoDeposit::eta
double eta() const
Definition: IsoDeposit.h:76
pat::helper::IsoDepositIsolator::Sum
Definition: IsoDepositIsolator.h:23
reco::IsoDeposit::maxWithin
double maxWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:146
edm::ValueMap< float >
reco::isodeposit::Direction
Definition: IsoDepositDirection.h:19
Exception
Definition: hltDiff.cc:246
pat::helper::IsoDepositIsolator::Count
Definition: IsoDepositIsolator.h:23
pat::helper::IsoDepositIsolator::deltaR_
float deltaR_
Definition: IsoDepositIsolator.h:26
options_cfi.eventSetup
eventSetup
Definition: options_cfi.py:12
vstring
vector< string > vstring
Definition: ExoticaDQM.cc:8
reco::IsoDeposit
Definition: IsoDeposit.h:49
reco::IsoDeposit::phi
double phi() const
Definition: IsoDeposit.h:77
pat::helper::IsoDepositIsolator::Sum2
Definition: IsoDepositIsolator.h:23
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
cms::Exception
Definition: Exception.h:70
IsoDepositVetoFactory::make
static reco::isodeposit::AbsVeto * make(const char *string, edm::ConsumesCollector &iC)
Definition: IsoDepositVetoFactory.cc:72
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
PbPb_ZMuSkimMuonDPG_cff.veto
veto
Definition: PbPb_ZMuSkimMuonDPG_cff.py:61
pat::helper::IsoDepositIsolator::~IsoDepositIsolator
~IsoDepositIsolator() override
Definition: IsoDepositIsolator.cc:69
reco::isodeposit::EventDependentAbsVeto
Definition: EventDependentAbsVeto.h:10
pat::helper::IsoDepositIsolator::mode_
Mode mode_
Definition: IsoDepositIsolator.h:27
boostedElectronIsolation_cff.vetos
vetos
Definition: boostedElectronIsolation_cff.py:79
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
edm::ProductID
Definition: ProductID.h:27
pat::helper::IsoDepositIsolator::Sum2Relative
Definition: IsoDepositIsolator.h:23