CMS 3D CMS Logo

CandIsolatorFromDeposits.cc
Go to the documentation of this file.
2 
3 // Framework
9 
11 
18 
21 #include <string>
22 #include <regex>
23 
25 
26 using namespace edm;
27 using namespace reco;
28 using namespace reco::isodeposit;
29 
30 bool isNumber(const std::string &str) {
31  static const std::regex re("^[+-]?(\\d+\\.?|\\d*\\.\\d*)$");
32  return regex_match(str.c_str(), re);
33 }
34 double toNumber(const std::string &str) { return atof(str.c_str()); }
35 
37  : srcToken_(iC.consumes<reco::IsoDepositMap>(iConfig.getParameter<edm::InputTag>("src"))),
38  deltaR_(iConfig.getParameter<double>("deltaR")),
39  weightExpr_(iConfig.getParameter<std::string>("weight")),
40  skipDefaultVeto_(iConfig.getParameter<bool>("skipDefaultVeto"))
41 //,vetos_(new AbsVetos())
42 {
43  std::string mode = iConfig.getParameter<std::string>("mode");
44  if (mode == "sum")
45  mode_ = Sum;
46  else if (mode == "sumRelative")
48  else if (mode == "sum2")
49  mode_ = Sum2;
50  else if (mode == "sum2Relative")
52  else if (mode == "max")
53  mode_ = Max;
54  else if (mode == "maxRelative")
56  else if (mode == "nearestDR")
57  mode_ = NearestDR;
58  else if (mode == "count")
59  mode_ = Count;
60  else if (mode == "meanDR")
61  mode_ = MeanDR;
62  else if (mode == "sumDR")
63  mode_ = SumDR;
64  else
65  throw cms::Exception("Not Implemented") << "Mode '" << mode << "' not implemented. "
66  << "Supported modes are 'sum', 'sumRelative', 'count'." <<
67  //"Supported modes are 'sum', 'sumRelative', 'max', 'maxRelative', 'count'." << // TODO: on request only
68  "New methods can be easily implemented if requested.";
69  typedef std::vector<std::string> vstring;
70  vstring vetos = iConfig.getParameter<vstring>("vetos");
72  for (vstring::const_iterator it = vetos.begin(), ed = vetos.end(); it != ed; ++it) {
73  vetos_.push_back(IsoDepositVetoFactory::make(it->c_str(), evdep, iC));
74  if (evdep)
75  evdepVetos_.push_back(evdep);
76  }
77  std::string weight = iConfig.getParameter<std::string>("weight");
78  if (isNumber(weight)) {
79  //std::cout << "Weight is a simple number, " << toNumber(weight) << std::endl;
81  usesFunction_ = false;
82  } else {
83  usesFunction_ = true;
84  //std::cout << "Weight is a function, this might slow you down... " << std::endl;
85  }
86  //std::cout << "CandIsolatorFromDeposits::SingleDeposit::SingleDeposit: Total of " << vetos_.size() << " vetos" << std::endl;
87 }
89  for (AbsVetos::iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
90  delete *it;
91  }
92  vetos_.clear();
93  // NOTE: we DON'T have to delete the evdepVetos_, they have already been deleted above. We just clear the vectors
94  evdepVetos_.clear();
95 }
97  iEvent.getByToken(srcToken_, hDeps_);
98  for (EventDependentAbsVetos::iterator it = evdepVetos_.begin(), ed = evdepVetos_.end(); it != ed; ++it) {
99  (*it)->setEvent(iEvent, iSetup);
100  }
101 }
102 
104  const IsoDeposit &dep = (*hDeps_)[cand];
105  double eta = dep.eta(), phi = dep.phi(); // better to center on the deposit direction
106  // that could be, e.g., the impact point at calo
107  for (AbsVetos::iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
108  (*it)->centerOn(eta, phi);
109  }
110  double weight = (usesFunction_ ? weightExpr_(*cand) : weight_);
111  switch (mode_) {
112  case Count:
113  return weight * dep.countWithin(deltaR_, vetos_, skipDefaultVeto_);
114  case Sum:
115  return weight * dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_);
116  case SumRelative:
117  return weight * dep.sumWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy();
118  case Sum2:
119  return weight * dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_);
120  case Sum2Relative:
121  return weight * dep.sum2Within(deltaR_, vetos_, skipDefaultVeto_) / (dep.candEnergy() * dep.candEnergy());
122  case Max:
123  return weight * dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_);
124  case NearestDR:
125  return weight * dep.nearestDR(deltaR_, vetos_, skipDefaultVeto_);
126  case MaxRelative:
127  return weight * dep.maxWithin(deltaR_, vetos_, skipDefaultVeto_) / dep.candEnergy();
128  case MeanDR:
129  return weight * dep.algoWithin<reco::IsoDeposit::MeanDRAlgo>(deltaR_, vetos_, skipDefaultVeto_);
130  case SumDR:
131  return weight * dep.algoWithin<reco::IsoDeposit::SumDRAlgo>(deltaR_, vetos_, skipDefaultVeto_);
132  }
133  throw cms::Exception("Logic error") << "Should not happen at " << __FILE__ << ", line "
134  << __LINE__; // avoid gcc warning
135 }
136 
139  typedef std::vector<edm::ParameterSet> VPSet;
140  VPSet depPSets = par.getParameter<VPSet>("deposits");
141  for (VPSet::const_iterator it = depPSets.begin(), ed = depPSets.end(); it != ed; ++it) {
142  sources_.push_back(SingleDeposit(*it, consumesCollector()));
143  }
144  if (sources_.empty())
145  throw cms::Exception("Configuration Error") << "Please specify at least one deposit!";
146  produces<CandDoubleMap>();
147 }
148 
151  std::vector<SingleDeposit>::iterator it, begin = sources_.begin(), end = sources_.end();
152  for (it = begin; it != end; ++it)
153  it->cleanup();
154 }
155 
158  std::vector<SingleDeposit>::iterator it, begin = sources_.begin(), end = sources_.end();
159  for (it = begin; it != end; ++it)
160  it->open(event, eventSetup);
161 
162  const IsoDepositMap &map = begin->map();
163 
164  if (map.empty()) { // !!???
165  event.put(std::make_unique<CandDoubleMap>());
166  return;
167  }
168  auto ret = std::make_unique<CandDoubleMap>();
170 
171  typedef reco::IsoDepositMap::const_iterator iterator_i;
173  iterator_i depI = map.begin();
174  iterator_i depIEnd = map.end();
175  for (; depI != depIEnd; ++depI) {
176  std::vector<double> retV(depI.size(), 0);
178  event.get(depI.id(), candH);
179  const edm::View<reco::Candidate> &candV = *candH;
180 
181  iterator_ii depII = depI.begin();
182  iterator_ii depIIEnd = depI.end();
183  size_t iRet = 0;
184  for (; depII != depIIEnd; ++depII, ++iRet) {
185  double sum = 0;
186  for (it = begin; it != end; ++it)
187  sum += it->compute(candV.refAt(iRet));
188  retV[iRet] = sum;
189  }
190  filler.insert(candH, retV.begin(), retV.end());
191  }
192  filler.fill();
193  event.put(std::move(ret));
194 }
195 
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
CandIsolatorFromDeposits::SingleDeposit::compute
double compute(const reco::CandidateBaseRef &cand)
Definition: CandIsolatorFromDeposits.cc:103
CandIsolatorFromDeposits::SingleDeposit::mode_
Mode mode_
Definition: CandIsolatorFromDeposits.h:48
CandIsolatorFromDeposits::SingleDeposit
Definition: CandIsolatorFromDeposits.h:39
edm::View::begin
const_iterator begin() const
reco::IsoDeposit::nearestDR
double nearestDR(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:150
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
Muon.h
IsoDepositVetos.h
MessageLogger.h
CandIsolatorFromDeposits::SingleDeposit::cleanup
void cleanup()
Definition: CandIsolatorFromDeposits.cc:88
EDProducer.h
ESHandle.h
edm::View::refAt
RefToBase< value_type > refAt(size_type i) const
IsoDepositVetoFactory.h
edm
HLT enums.
Definition: AlignableModifier.h:19
CandIsolatorFromDeposits::CandIsolatorFromDeposits
CandIsolatorFromDeposits(const edm::ParameterSet &)
constructor with config
Definition: CandIsolatorFromDeposits.cc:138
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
CandIsolatorFromDeposits::sources_
std::vector< SingleDeposit > sources_
Definition: CandIsolatorFromDeposits.h:60
CandIsolatorFromDeposits::SingleDeposit::SingleDeposit
SingleDeposit(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
Definition: CandIsolatorFromDeposits.cc:36
CandIsolatorFromDeposits::SingleDeposit::usesFunction_
bool usesFunction_
Definition: CandIsolatorFromDeposits.h:51
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::Handle
Definition: AssociativeIterator.h:50
IsoDepositDirection.h
CandIsolatorFromDeposits::Sum
Definition: CandIsolatorFromDeposits.h:31
CandIsolatorFromDeposits::SumRelative
Definition: CandIsolatorFromDeposits.h:31
reco::IsoDeposit::sum2Within
double sum2Within(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:143
MakerMacros.h
edm::ValueMap::const_iterator
Definition: ValueMap.h:170
reco::IsoDeposit::countWithin
double countWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:134
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::isodeposit
Definition: IsoDeposit.h:31
PVValHelper::eta
Definition: PVValidationHelpers.h:70
mps_fire.end
end
Definition: mps_fire.py:242
str
#define str(s)
Definition: TestProcessor.cc:53
CandIsolatorFromDeposits::NearestDR
Definition: CandIsolatorFromDeposits.h:31
CandIsolatorFromDeposits.h
IsoDeposit.h
edm::View
Definition: CaloClusterFwd.h:14
edm::ParameterSet
Definition: ParameterSet.h:47
CandIsolatorFromDeposits::Max
Definition: CandIsolatorFromDeposits.h:31
CandAssociation.h
Event.h
reco::IsoDeposit::SumDRAlgo
Definition: IsoDeposit.h:237
CandIsolatorFromDeposits::SingleDeposit::open
void open(const edm::Event &iEvent, const edm::EventSetup &iSetup)
Definition: CandIsolatorFromDeposits.cc:96
CandIsolatorFromDeposits::SingleDeposit::vetos_
reco::isodeposit::AbsVetos vetos_
Definition: CandIsolatorFromDeposits.h:54
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
cand
Definition: decayParser.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
reco::IsoDeposit::sumWithin
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:137
toNumber
double toNumber(const std::string &str)
Definition: CandIsolatorFromDeposits.cc:34
reco::IsoDeposit::candEnergy
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:129
CandIsolatorFromDeposits::Sum2
Definition: CandIsolatorFromDeposits.h:31
edm::EventSetup
Definition: EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::IsoDeposit::algoWithin
double algoWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Get some info about the deposit (e.g. sum, max, sum2, count)
Definition: IsoDeposit.h:309
DDAxes::phi
CandIsolatorFromDeposits::~CandIsolatorFromDeposits
~CandIsolatorFromDeposits() override
destructor
Definition: CandIsolatorFromDeposits.cc:150
HistogramManager_cfi.VPSet
def VPSet(*args)
Definition: HistogramManager_cfi.py:404
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
reco::IsoDeposit::eta
double eta() const
Definition: IsoDeposit.h:76
CandIsolatorFromDeposits::produce
void produce(edm::Event &, const edm::EventSetup &) override
build deposits
Definition: CandIsolatorFromDeposits.cc:157
reco::IsoDeposit::maxWithin
double maxWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:146
isNumber
bool isNumber(const std::string &str)
Definition: CandIsolatorFromDeposits.cc:30
edm::ValueMap
Definition: ValueMap.h:107
CandIsolatorFromDeposits::MaxRelative
Definition: CandIsolatorFromDeposits.h:31
Exception
Definition: hltDiff.cc:245
EventSetup.h
vstring
vector< string > vstring
Definition: ExoticaDQM.cc:8
reco::IsoDeposit
Definition: IsoDeposit.h:49
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase< Candidate >
CandIsolatorFromDeposits::SingleDeposit::weight_
double weight_
Definition: CandIsolatorFromDeposits.h:52
reco::IsoDeposit::phi
double phi() const
Definition: IsoDeposit.h:77
CandIsolatorFromDeposits::SumDR
Definition: CandIsolatorFromDeposits.h:31
CandIsolatorFromDeposits::Count
Definition: CandIsolatorFromDeposits.h:31
cms::Exception
Definition: Exception.h:70
IsoDepositFwd.h
edm::helper::Filler
Definition: ValueMap.h:22
genParticles_cff.map
map
Definition: genParticles_cff.py:11
IsoDepositVetoFactory::make
static reco::isodeposit::AbsVeto * make(const char *string, edm::ConsumesCollector &iC)
Definition: IsoDepositVetoFactory.cc:72
reco::IsoDeposit::MeanDRAlgo
Definition: IsoDeposit.h:223
CandIsolatorFromDeposits::Sum2Relative
Definition: CandIsolatorFromDeposits.h:31
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
CandIsolatorFromDeposits::SingleDeposit::evdepVetos_
reco::isodeposit::EventDependentAbsVetos evdepVetos_
Definition: CandIsolatorFromDeposits.h:55
reco::isodeposit::EventDependentAbsVeto
Definition: EventDependentAbsVeto.h:10
CandIsolatorFromDeposits
Definition: CandIsolatorFromDeposits.h:27
boostedElectronIsolation_cff.vetos
vetos
Definition: boostedElectronIsolation_cff.py:79
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
weight
Definition: weight.py:1
CandIsolatorFromDeposits::MeanDR
Definition: CandIsolatorFromDeposits.h:31