src
RecoEgamma
ElectronIdentification
plugins
cuts
GsfEleMVACut.cc
Go to the documentation of this file.
1
#include "
PhysicsTools/SelectorUtils/interface/CutApplicatorWithEventContentBase.h
"
2
#include "
DataFormats/EgammaCandidates/interface/GsfElectron.h
"
3
#include "
CommonTools/Utils/interface/StringObjectFunction.h
"
4
5
class
GsfEleMVACut
:
public
CutApplicatorWithEventContentBase
{
6
public
:
7
GsfEleMVACut
(
const
edm::ParameterSet
&
c
);
8
9
result_type
operator()
(
const
reco::GsfElectronPtr
&)
const
final
;
10
11
void
setConsumes
(
edm::ConsumesCollector
&)
final
;
12
void
getEventContent
(
const
edm::EventBase
&)
final
;
13
14
CandidateType
candidateType
()
const
final {
return
ELECTRON
; }
15
16
private
:
17
double
value
(
const
reco::CandidatePtr
&
cand
)
const
final
;
18
19
// Cut formulas
20
const
std::vector<std::string>
mvaCutStrings_
;
21
std::vector<StringObjectFunction<reco::GsfElectron>>
cutFormula_
;
22
23
const
int
nCuts_
;
24
25
// Pre-computed MVA value map
26
edm::Handle<edm::ValueMap<float>
>
mvaValueMap_
;
27
edm::Handle<edm::ValueMap<int>
>
mvaCategoriesMap_
;
28
};
29
30
DEFINE_EDM_PLUGIN
(
CutApplicatorFactory
,
GsfEleMVACut
,
"GsfEleMVACut"
);
31
32
GsfEleMVACut::GsfEleMVACut
(
const
edm::ParameterSet
&
c
)
33
:
CutApplicatorWithEventContentBase
(
c
),
34
mvaCutStrings_(
c
.getParameter<
std
::
vector
<
std
::
string
>>(
"mvaCuts"
)),
35
nCuts_(mvaCutStrings_.
size
()) {
36
edm::InputTag
mvaValTag =
c
.getParameter<
edm::InputTag
>(
"mvaValueMapName"
);
37
contentTags_
.emplace(
"mvaVal"
, mvaValTag);
38
39
edm::InputTag
mvaCatTag =
c
.getParameter<
edm::InputTag
>(
"mvaCategoriesMapName"
);
40
contentTags_
.emplace(
"mvaCat"
, mvaCatTag);
41
42
for
(
auto
& cutString :
mvaCutStrings_
) {
43
cutFormula_
.push_back(
StringObjectFunction<reco::GsfElectron>
(cutString));
44
}
45
}
46
47
void
GsfEleMVACut::setConsumes
(
edm::ConsumesCollector
&
cc
) {
48
auto
mvaVal =
cc
.consumes<
edm::ValueMap<float>
>(
contentTags_
[
"mvaVal"
]);
49
contentTokens_
.emplace(
"mvaVal"
, mvaVal);
50
51
auto
mvaCat =
cc
.consumes<
edm::ValueMap<int>
>(
contentTags_
[
"mvaCat"
]);
52
contentTokens_
.emplace(
"mvaCat"
, mvaCat);
53
}
54
55
void
GsfEleMVACut::getEventContent
(
const
edm::EventBase
&
ev
) {
56
ev
.getByLabel(
contentTags_
[
"mvaVal"
],
mvaValueMap_
);
57
ev
.getByLabel(
contentTags_
[
"mvaCat"
],
mvaCategoriesMap_
);
58
}
59
60
CutApplicatorBase::result_type
GsfEleMVACut::operator()
(
const
reco::GsfElectronPtr
&
cand
)
const
{
61
// in case we are by-value
62
const
std::string
& val_name =
contentTags_
.find(
"mvaVal"
)->second.instance();
63
const
std::string
& cat_name =
contentTags_
.find(
"mvaCat"
)->second.instance();
64
edm::Ptr<pat::Electron>
pat
(
cand
);
65
float
val
= -1.0;
66
int
cat
= -1;
67
if
(
mvaCategoriesMap_
.
isValid
() &&
mvaCategoriesMap_
->
contains
(
cand
.id()) &&
mvaValueMap_
.
isValid
() &&
68
mvaValueMap_
->
contains
(
cand
.id())) {
69
cat
= (*mvaCategoriesMap_)[
cand
];
70
val
= (*mvaValueMap_)[
cand
];
71
}
else
if
(
mvaCategoriesMap_
.
isValid
() &&
mvaValueMap_
.
isValid
() &&
mvaCategoriesMap_
->
idSize
() == 1 &&
72
mvaValueMap_
->
idSize
() == 1 &&
cand
.id() ==
edm::ProductID
()) {
73
// in case we have spoofed a ptr
74
//note this must be a 1:1 valuemap (only one product input)
75
cat
=
mvaCategoriesMap_
->
begin
()[
cand
.key()];
76
val
=
mvaValueMap_
->
begin
()[
cand
.key()];
77
}
else
if
(
mvaCategoriesMap_
.
isValid
() &&
mvaValueMap_
.
isValid
()) {
// throw an exception
78
cat
= (*mvaCategoriesMap_)[
cand
];
79
val
= (*mvaValueMap_)[
cand
];
80
}
81
82
// Find the cut formula
83
const
int
iCategory =
mvaCategoriesMap_
.
isValid
() ?
cat
:
pat
->userInt(cat_name);
84
if
(iCategory >=
nCuts_
)
85
throw
cms::Exception
(
" Error in MVA categories: "
)
86
<<
" found a particle with a category larger than max configured "
<< std::endl;
87
88
// Look up the MVA value for this particle
89
const
float
mvaValue =
mvaValueMap_
.
isValid
() ?
val
:
pat
->userFloat(val_name);
90
91
// Apply the cut and return the result
92
return
mvaValue >
cutFormula_
[iCategory](*cand);
93
}
94
95
double
GsfEleMVACut::value
(
const
reco::CandidatePtr
&
cand
)
const
{
96
// in case we are by-value
97
const
std::string
& val_name =
contentTags_
.find(
"mvaVal"
)->second.instance();
98
edm::Ptr<pat::Electron>
pat
(
cand
);
99
float
val
= 0.0;
100
if
(
mvaCategoriesMap_
.
isValid
() &&
mvaCategoriesMap_
->
contains
(
cand
.id()) &&
mvaValueMap_
.
isValid
() &&
101
mvaValueMap_
->
contains
(
cand
.id())) {
102
val
= (*mvaValueMap_)[
cand
];
103
}
else
if
(
mvaCategoriesMap_
.
isValid
() &&
mvaValueMap_
.
isValid
() &&
mvaCategoriesMap_
->
idSize
() == 1 &&
104
mvaValueMap_
->
idSize
() == 1 &&
cand
.id() ==
edm::ProductID
()) {
105
// in case we have spoofed a ptr
106
//note this must be a 1:1 valuemap (only one product input)
107
val
=
mvaValueMap_
->
begin
()[
cand
.key()];
108
}
else
if
(
mvaCategoriesMap_
.
isValid
() &&
mvaValueMap_
.
isValid
()) {
// throw an exception
109
val
= (*mvaValueMap_)[
cand
];
110
}
111
112
const
float
mvaValue =
mvaValueMap_
.
isValid
() ?
val
:
pat
->userFloat(val_name);
113
return
mvaValue;
114
}
findQualityFiles.size
size
Write out results.
Definition:
findQualityFiles.py:443
makeMEIFBenchmarkPlots.ev
ev
Definition:
makeMEIFBenchmarkPlots.py:55
CutApplicatorWithEventContentBase
Definition:
CutApplicatorWithEventContentBase.h:19
GsfEleMVACut::mvaCategoriesMap_
edm::Handle< edm::ValueMap< int > > mvaCategoriesMap_
Definition:
GsfEleMVACut.cc:27
GsfEleMVACut::value
double value(const reco::CandidatePtr &cand) const final
Definition:
GsfEleMVACut.cc:95
CutApplicatorWithEventContentBase::contentTags_
std::unordered_map< std::string, edm::InputTag > contentTags_
Definition:
CutApplicatorWithEventContentBase.h:35
StringObjectFunction< reco::GsfElectron >
CutApplicatorBase::ELECTRON
Definition:
CutApplicatorBase.h:47
Exception
Definition:
hltDiff.cc:245
runTheMatrix.const
const
Definition:
runTheMatrix.py:345
edm::ValueMap::idSize
size_t idSize() const
Definition:
ValueMap.h:157
gpuPixelDoublets::cc
uint32_t cc[maxCellsPerHit]
Definition:
gpuFishbone.h:49
edm::Handle
Definition:
AssociativeIterator.h:50
GsfEleMVACut::GsfEleMVACut
GsfEleMVACut(const edm::ParameterSet &c)
Definition:
GsfEleMVACut.cc:32
GsfEleMVACut::setConsumes
void setConsumes(edm::ConsumesCollector &) final
Definition:
GsfEleMVACut.cc:47
GsfEleMVACut::nCuts_
const int nCuts_
Definition:
GsfEleMVACut.cc:23
std
Definition:
JetResolutionObject.h:76
GsfEleMVACut::cutFormula_
std::vector< StringObjectFunction< reco::GsfElectron > > cutFormula_
Definition:
GsfEleMVACut.cc:21
HltBtagPostValidation_cff.c
c
Definition:
HltBtagPostValidation_cff.py:35
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
StringObjectFunction.h
pat
Definition:
HeavyIon.h:7
eostools.cat
def cat(path)
Definition:
eostools.py:401
edm::ProductID
Definition:
ProductID.h:27
edmplugin::PluginFactory
Definition:
PluginFactory.h:35
candidate_functions::CandidateCut::result_type
bool result_type
Definition:
CandidateCut.h:11
GsfEleMVACut::operator()
result_type operator()(const reco::GsfElectronPtr &) const final
Definition:
GsfEleMVACut.cc:60
CutApplicatorWithEventContentBase.h
edm::Ptr< reco::GsfElectron >
GsfEleMVACut::getEventContent
void getEventContent(const edm::EventBase &) final
Definition:
GsfEleMVACut.cc:55
GsfEleMVACut::candidateType
CandidateType candidateType() const final
Definition:
GsfEleMVACut.cc:14
edm::EventBase
Definition:
EventBase.h:47
GsfEleMVACut
Definition:
GsfEleMVACut.cc:5
edm::ValueMap::begin
const_iterator begin() const
Definition:
ValueMap.h:229
GsfElectron.h
edm::ValueMap< float >
CutApplicatorWithEventContentBase::contentTokens_
std::unordered_map< std::string, edm::EDGetToken > contentTokens_
Definition:
CutApplicatorWithEventContentBase.h:40
edm::HandleBase::isValid
bool isValid() const
Definition:
HandleBase.h:70
edm::InputTag
Definition:
InputTag.h:15
trackerHitRTTI::vector
Definition:
trackerHitRTTI.h:21
CutApplicatorBase::CandidateType
CandidateType
Definition:
CutApplicatorBase.h:47
edm::ParameterSet
Definition:
ParameterSet.h:47
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition:
PluginFactory.h:123
cand
Definition:
decayParser.h:32
GsfEleMVACut::mvaValueMap_
edm::Handle< edm::ValueMap< float > > mvaValueMap_
Definition:
GsfEleMVACut.cc:26
GsfEleMVACut::mvaCutStrings_
const std::vector< std::string > mvaCutStrings_
Definition:
GsfEleMVACut.cc:20
heppy_batch.val
val
Definition:
heppy_batch.py:351
edm::ValueMap::contains
bool contains(ProductID id) const
Definition:
ValueMap.h:155
edm::ConsumesCollector
Definition:
ConsumesCollector.h:45
Generated for CMSSW Reference Manual by
1.8.14