src
RecoEgamma
PhotonIdentification
plugins
cuts
PhoMVACut.cc
Go to the documentation of this file.
1
#include "
PhysicsTools/SelectorUtils/interface/CutApplicatorWithEventContentBase.h
"
2
#include "
DataFormats/EgammaCandidates/interface/Photon.h
"
3
4
class
PhoMVACut
:
public
CutApplicatorWithEventContentBase
{
5
public
:
6
PhoMVACut
(
const
edm::ParameterSet
&
c
);
7
8
result_type
operator()
(
const
reco::PhotonPtr
&)
const
final
;
9
10
void
setConsumes
(
edm::ConsumesCollector
&)
final
;
11
void
getEventContent
(
const
edm::EventBase
&)
final
;
12
13
double
value
(
const
reco::CandidatePtr
&
cand
)
const
final
;
14
15
CandidateType
candidateType
()
const
final {
return
PHOTON
; }
16
17
private
:
18
// Cut values
19
const
std::vector<double>
_mvaCutValues
;
20
21
// Pre-computed MVA value map
22
edm::Handle<edm::ValueMap<float>
>
_mvaValueMap
;
23
edm::Handle<edm::ValueMap<int>
>
_mvaCategoriesMap
;
24
};
25
26
DEFINE_EDM_PLUGIN
(
CutApplicatorFactory
,
PhoMVACut
,
"PhoMVACut"
);
27
28
PhoMVACut::PhoMVACut
(
const
edm::ParameterSet
&
c
)
29
:
CutApplicatorWithEventContentBase
(
c
), _mvaCutValues(
c
.getParameter<
std
::
vector
<double> >(
"mvaCuts"
)) {
30
edm::InputTag
mvaValTag =
c
.getParameter<
edm::InputTag
>(
"mvaValueMapName"
);
31
contentTags_
.emplace(
"mvaVal"
, mvaValTag);
32
33
edm::InputTag
mvaCatTag =
c
.getParameter<
edm::InputTag
>(
"mvaCategoriesMapName"
);
34
contentTags_
.emplace(
"mvaCat"
, mvaCatTag);
35
}
36
37
void
PhoMVACut::setConsumes
(
edm::ConsumesCollector
&
cc
) {
38
auto
mvaVal =
cc
.consumes<
edm::ValueMap<float>
>(
contentTags_
[
"mvaVal"
]);
39
contentTokens_
.emplace(
"mvaVal"
, mvaVal);
40
41
auto
mvaCat =
cc
.consumes<
edm::ValueMap<int>
>(
contentTags_
[
"mvaCat"
]);
42
contentTokens_
.emplace(
"mvaCat"
, mvaCat);
43
}
44
45
void
PhoMVACut::getEventContent
(
const
edm::EventBase
&
ev
) {
46
ev
.getByLabel(
contentTags_
[
"mvaVal"
],
_mvaValueMap
);
47
ev
.getByLabel(
contentTags_
[
"mvaCat"
],
_mvaCategoriesMap
);
48
}
49
50
CutApplicatorBase::result_type
PhoMVACut::operator()
(
const
reco::PhotonPtr
&
cand
)
const
{
51
// in case we are by-value
52
const
std::string
& val_name =
contentTags_
.find(
"mvaVal"
)->second.instance();
53
const
std::string
& cat_name =
contentTags_
.find(
"mvaCat"
)->second.instance();
54
edm::Ptr<pat::Photon>
pat
(
cand
);
55
float
val
= -1.0;
56
int
cat
= -1;
57
if
(
_mvaCategoriesMap
.
isValid
() &&
_mvaCategoriesMap
->
contains
(
cand
.id()) &&
_mvaValueMap
.
isValid
() &&
58
_mvaValueMap
->
contains
(
cand
.id())) {
59
cat
= (*_mvaCategoriesMap)[
cand
];
60
val
= (*_mvaValueMap)[
cand
];
61
}
else
if
(
_mvaCategoriesMap
.
isValid
() &&
_mvaValueMap
.
isValid
() &&
_mvaCategoriesMap
->
idSize
() == 1 &&
62
_mvaValueMap
->
idSize
() == 1 &&
cand
.id() ==
edm::ProductID
()) {
63
// in case we have spoofed a ptr
64
//note this must be a 1:1 valuemap (only one product input)
65
cat
=
_mvaCategoriesMap
->
begin
()[
cand
.key()];
66
val
=
_mvaValueMap
->
begin
()[
cand
.key()];
67
}
else
if
(
_mvaCategoriesMap
.
isValid
() &&
_mvaValueMap
.
isValid
()) {
// throw an exception
68
cat
= (*_mvaCategoriesMap)[
cand
];
69
val
= (*_mvaValueMap)[
cand
];
70
}
71
72
// Find the cut value
73
const
int
iCategory =
_mvaCategoriesMap
.
isValid
() ?
cat
:
pat
->userInt(cat_name);
74
if
(iCategory >= (
int
)(
_mvaCutValues
.size()))
75
throw
cms::Exception
(
" Error in MVA categories: "
)
76
<<
" found a particle with a category larger than max configured "
<< std::endl;
77
const
float
cutValue =
_mvaCutValues
[iCategory];
78
79
// Look up the MVA value for this particle
80
const
float
mvaValue =
_mvaValueMap
.
isValid
() ?
val
:
pat
->userFloat(val_name);
81
82
// Apply the cut and return the result
83
return
mvaValue > cutValue;
84
}
85
86
double
PhoMVACut::value
(
const
reco::CandidatePtr
&
cand
)
const
{
87
// in case we are by-value
88
const
std::string
& val_name =
contentTags_
.find(
"mvaVal"
)->second.instance();
89
edm::Ptr<pat::Photon>
pat
(
cand
);
90
float
val
= 0.0;
91
if
(
_mvaCategoriesMap
.
isValid
() &&
_mvaCategoriesMap
->
contains
(
cand
.id()) &&
_mvaValueMap
.
isValid
() &&
92
_mvaValueMap
->
contains
(
cand
.id())) {
93
val
= (*_mvaValueMap)[
cand
];
94
}
else
if
(
_mvaCategoriesMap
.
isValid
() &&
_mvaValueMap
.
isValid
() &&
_mvaCategoriesMap
->
idSize
() == 1 &&
95
_mvaValueMap
->
idSize
() == 1 &&
cand
.id() ==
edm::ProductID
()) {
96
// in case we have spoofed a ptr
97
//note this must be a 1:1 valuemap (only one product input)
98
val
=
_mvaValueMap
->
begin
()[
cand
.key()];
99
}
else
if
(
_mvaCategoriesMap
.
isValid
() &&
_mvaValueMap
.
isValid
()) {
100
val
= (*_mvaValueMap)[
cand
];
101
}
102
const
float
mvaValue =
_mvaValueMap
.
isValid
() ?
val
:
pat
->userFloat(val_name);
103
return
mvaValue;
104
}
makeMEIFBenchmarkPlots.ev
ev
Definition:
makeMEIFBenchmarkPlots.py:55
CutApplicatorWithEventContentBase
Definition:
CutApplicatorWithEventContentBase.h:19
CutApplicatorWithEventContentBase::contentTags_
std::unordered_map< std::string, edm::InputTag > contentTags_
Definition:
CutApplicatorWithEventContentBase.h:35
Exception
Definition:
hltDiff.cc:245
runTheMatrix.const
const
Definition:
runTheMatrix.py:341
edm::ValueMap::idSize
size_t idSize() const
Definition:
ValueMap.h:157
PhoMVACut::PhoMVACut
PhoMVACut(const edm::ParameterSet &c)
Definition:
PhoMVACut.cc:28
PhoMVACut::candidateType
CandidateType candidateType() const final
Definition:
PhoMVACut.cc:15
gpuPixelDoublets::cc
uint32_t cc[maxCellsPerHit]
Definition:
gpuFishbone.h:49
edm::Handle
Definition:
AssociativeIterator.h:50
Photon.h
std
Definition:
JetResolutionObject.h:76
HltBtagPostValidation_cff.c
c
Definition:
HltBtagPostValidation_cff.py:31
PhoMVACut::_mvaValueMap
edm::Handle< edm::ValueMap< float > > _mvaValueMap
Definition:
PhoMVACut.cc:22
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
pat
Definition:
HeavyIon.h:7
PhoMVACut::getEventContent
void getEventContent(const edm::EventBase &) final
Definition:
PhoMVACut.cc:45
PhoMVACut::operator()
result_type operator()(const reco::PhotonPtr &) const final
Definition:
PhoMVACut.cc:50
PhoMVACut::value
double value(const reco::CandidatePtr &cand) const final
Definition:
PhoMVACut.cc:86
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
CutApplicatorWithEventContentBase.h
edm::Ptr
Definition:
AssociationVector.h:31
edm::EventBase
Definition:
EventBase.h:47
edm::ValueMap::begin
const_iterator begin() const
Definition:
ValueMap.h:229
edm::ValueMap< float >
PhoMVACut::_mvaCutValues
const std::vector< double > _mvaCutValues
Definition:
PhoMVACut.cc:19
PhoMVACut::setConsumes
void setConsumes(edm::ConsumesCollector &) final
Definition:
PhoMVACut.cc:37
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
PhoMVACut::_mvaCategoriesMap
edm::Handle< edm::ValueMap< int > > _mvaCategoriesMap
Definition:
PhoMVACut.cc:23
CutApplicatorBase::PHOTON
Definition:
CutApplicatorBase.h:47
heppy_batch.val
val
Definition:
heppy_batch.py:351
PhoMVACut
Definition:
PhoMVACut.cc:4
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