1 #ifndef MuonIsolationProducers_MuIsolatorResultProducer_H
2 #define MuonIsolationProducers_MuIsolatorResultProducer_H
30 template <
typename BT>
37 typedef typename std::vector<pair_type>
map_type;
52 template <
typename BT = reco::Cand
idate>
88 void initVetos(std::vector<reco::IsoDeposit::Vetos*>& vetos,
CandMap& candMap)
const;
90 template <
typename RT>
113 template <
typename BT>
114 template <
typename RT>
119 std::vector<RT> resV(results.size());
120 for (
unsigned int i = 0;
i < resV.size(); ++
i)
121 resV[
i] = results[
i].val<RT>();
122 auto outMap = std::make_unique<edm::ValueMap<RT>>();
126 if (!candMapT.
get().empty()) {
127 filler.insert(candMapT.
handle(), resV.begin(), resV.end());
135 template <
typename BT>
140 LogDebug(metname) <<
"Before calling writeOutMap with result type " << theIsolator->resultType();
142 if (theResultType == Isolator::ISOL_INT_TYPE)
144 if (theResultType == Isolator::ISOL_FLOAT_TYPE)
146 if (theResultType == Isolator::ISOL_BOOL_TYPE)
151 template <
typename BT>
153 if (theResultType == Isolator::ISOL_FLOAT_TYPE)
154 produces<edm::ValueMap<float>>();
155 if (theResultType == Isolator::ISOL_INT_TYPE)
156 produces<edm::ValueMap<int>>();
157 if (theResultType == Isolator::ISOL_BOOL_TYPE)
158 produces<edm::ValueMap<bool>>();
185 template <
typename BT>
188 theRemoveOtherVetos(par.getParameter<bool>(
"RemoveOtherVetos")),
189 theIsolator(nullptr),
191 LogDebug(
"RecoMuon|MuonIsolation") <<
" MuIsolatorResultProducer CTOR";
194 std::vector<edm::ParameterSet> depositInputs = par.
getParameter<std::vector<edm::ParameterSet>>(
"InputMuIsoDeposits");
196 std::vector<double> dWeights(depositInputs.size());
197 std::vector<double> dThresholds(depositInputs.size());
199 for (
unsigned int iDep = 0; iDep < depositInputs.size(); ++iDep) {
202 dConf.
weight = depositInputs[iDep].getParameter<
double>(
"DepositWeight");
203 dConf.
threshold = depositInputs[iDep].getParameter<
double>(
"DepositThreshold");
205 dWeights[iDep] = dConf.
weight;
214 if (isolatorType ==
"IsolatorByDeposit") {
216 if (coneSizeType ==
"FixedConeSize") {
222 }
else if (coneSizeType ==
"CutsConeSize") {
228 }
else if (isolatorType ==
"IsolatorByNominalEfficiency") {
232 }
else if (isolatorType ==
"IsolatorByDepositCount") {
234 if (coneSizeType ==
"FixedConeSize") {
240 }
else if (coneSizeType ==
"CutsConeSize") {
248 edm::LogError(
"MuonIsolationProducers") <<
"Failed to initialize an isolator";
273 template <
typename BT>
277 LogDebug(
"RecoMuon|MuIsolatorResultProducer") <<
" MuIsolatorResultProducer DTOR";
280 template <
typename BT>
283 LogDebug(metname) <<
" Muon Deposit producing..."
284 <<
" BEGINING OF EVENT "
285 <<
"================================";
290 if (theRemoveOtherVetos && !theVetoCuts.selectAll) {
291 if (theBeamlineOption ==
"BeamSpotFromEvent") {
296 event.getByLabel(theBeamSpotLabel, beamSpotH);
299 theBeam = beamSpotH->position();
300 LogTrace(metname) <<
"Extracted beam point at " << theBeam << std::endl;
312 unsigned int colSize = initAssociation(event, candMapT);
318 std::vector<reco::IsoDeposit::Vetos*> vetoDeps(theDepositConfs.size(),
nullptr);
321 if (theRemoveOtherVetos) {
322 initVetos(vetoDeps, candMapT);
326 for (
unsigned int muI = 0; muI < colSize; ++muI) {
327 results[muI] = theIsolator->result(candMapT.
get()[muI].second, *(candMapT.
get()[muI].first));
329 if (results[muI].typeF() != theIsolator->resultType()) {
330 edm::LogError(
"MuonIsolationProducers") <<
"Failed to get result from the isolator";
335 LogDebug(metname) <<
"Ready to write out results of size " << results.size();
336 writeOut(event, candMapT, results);
338 for (
unsigned int iDep = 0; iDep < vetoDeps.size(); ++iDep) {
340 if (vetoDeps[iDep]) {
341 delete vetoDeps[iDep];
342 vetoDeps[iDep] =
nullptr;
347 template <
typename BT>
353 for (
unsigned int iMap = 0; iMap < theDepositConfs.size(); ++iMap) {
355 event.getByLabel(theDepositConfs[iMap].
tag, depH);
356 LogDebug(metname) <<
"Got Deposits of size " << depH->size();
363 event.get(depH->begin().
id(), keyH);
365 typename CT::const_iterator depHCI = depH->begin().begin();
366 typename CT::const_iterator depEnd = depH->begin().end();
367 unsigned int keyI = 0;
368 for (; depHCI != depEnd; ++depHCI, ++keyI) {
374 for (; muI != candMapT.
get().end(); ++muI) {
375 if (muI->first == muPtr)
378 if (muI->first != muPtr) {
379 edm::LogError(
"MuonIsolationProducers") <<
"Failed to align muon map";
381 muI->second[iMap].dep = &*depHCI;
385 LogDebug(metname) <<
"Picked and aligned nDeps = " << candMapT.
get().size();
386 return candMapT.
get().size();
389 template <
typename BT>
393 if (theRemoveOtherVetos) {
394 LogDebug(metname) <<
"Start checking for vetos based on input/expected vetos.size of " << vetos.size()
395 <<
" passed at " << &vetos <<
" and an input map.size of " << candMapT.
get().size();
397 unsigned int muI = 0;
398 for (; muI < candMapT.
get().size(); ++muI) {
400 double d0 = ((mu->vx() - theBeam.x()) * mu->py() - (mu->vy() - theBeam.y()) * mu->px()) / mu->pt();
401 LogDebug(metname) <<
"Muon at index " << muI;
402 if (theVetoCuts.selectAll || (fabs(mu->eta()) < theVetoCuts.muAbsEtaMax && mu->pt() > theVetoCuts.muPtMin &&
403 fabs(mu->vz()) < theVetoCuts.muAbsZMax && fabs(d0) < theVetoCuts.muD0Max)) {
404 LogDebug(metname) <<
"muon passes the cuts";
405 for (
unsigned int iDep = 0; iDep < candMapT.
get()[muI].second.size(); ++iDep) {
406 if (vetos[iDep] ==
nullptr)
409 vetos[iDep]->push_back(candMapT.
get()[muI].second[iDep].dep->veto());
414 LogDebug(metname) <<
"Assigning vetos";
416 for (; muI < candMapT.
get().size(); ++muI) {
417 for (
unsigned int iDep = 0; iDep < candMapT.
get()[muI].second.size(); ++iDep) {
418 candMapT.
get()[muI].second[iDep].vetos = vetos[iDep];
421 LogDebug(metname) <<
"Done with vetos";
muisorhelper::ResultType ResultType
std::pair< key_type, value_type > pair_type
MuIsolatorResultProducer(const edm::ParameterSet &)
constructor with config
std::vector< Result > Results
const std::string metname
map_type::iterator iterator
std::vector< DepositConf > theDepositConfs
bool theRemoveOtherVetos
choose which muon vetos should be removed from all deposits
void callWhatProduces()
declare what's going to be produced
Log< level::Error, false > LogError
std::vector< pair_type > map_type
muonisolation::MuIsoBaseIsolator Isolator
edm::RefToBase< BT > key_type
Isolator * theIsolator
the isolator
std::string theBeamlineOption
beam spot
void produce(edm::Event &, const edm::EventSetup &) override
void setHandle(const handle_type &rhs)
edm::Handle< edm::View< BT > > handle_type
math::XYZPoint Point
point in the space
void initVetos(std::vector< reco::IsoDeposit::Vetos * > &vetos, CandMap &candMap) const
muisorhelper::Isolator Isolator
virtual ResultType resultType() const =0
muisorhelper::DepositContainer DepositContainer
static constexpr float d0
edm::InputTag theBeamSpotLabel
std::vector< DepositAndVetos > DepositContainer
Isolator::ResultType ResultType
T getParameter(std::string const &) const
unsigned int initAssociation(edm::Event &event, CandMap &candMapT) const
Isolator::DepositContainer DepositContainer
std::vector< Veto > Vetos
std::vector< value_type > container
DepositContainer value_type
void writeOutImpl(edm::Event &event, const CandMap &candMapT, const Results &results) const
actually do the writing here
const handle_type & handle() const
void writeOut(edm::Event &event, const CandMap &candMap, const Results &results) const
choose which result type to write here
~MuIsolatorResultProducer() override
destructor
edm::ParameterSet theConfig
reco::TrackBase::Point theBeam
muisorhelper::Results Results
muisorhelper::CandMap< BT > CandMap
muisorhelper::Result Result