Main Page
Namespaces
Classes
Package Documentation
CommonTools
ParticleFlow
interface
ElectronIDPFCandidateSelectorDefinition.h
Go to the documentation of this file.
1
#ifndef CommonTools_ParticleFlow_ElectronIDPFCandidateSelectorDefinition
2
#define CommonTools_ParticleFlow_ElectronIDPFCandidateSelectorDefinition
3
12
#include "
FWCore/Framework/interface/Event.h
"
13
#include "
FWCore/Framework/interface/ConsumesCollector.h
"
14
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
15
#include "
DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h
"
16
#include "
DataFormats/ParticleFlowCandidate/interface/PFCandidate.h
"
17
#include "
DataFormats/Common/interface/ValueMap.h
"
18
#include "
DataFormats/EgammaCandidates/interface/GsfElectron.h
"
19
#include "
CommonTools/ParticleFlow/interface/PFCandidateSelectorDefinition.h
"
20
#include <algorithm>
21
22
namespace
pf2pat
{
23
24
struct
ElectronIDPFCandidateSelectorDefinition
:
public
PFCandidateSelectorDefinition
{
25
26
ElectronIDPFCandidateSelectorDefinition
(
const
edm::ParameterSet
&
cfg
,
edm::ConsumesCollector
&& iC ) :
27
electronsToken_
( iC.consumes<
reco
::
GsfElectronCollection
>( cfg.getParameter<
edm
::InputTag >(
"recoGsfElectrons"
) ) ),
28
electronIdToken_
( iC.consumes<
edm
::ValueMap<
float
> >( cfg.getParameter<
edm
::InputTag >(
"electronIdMap"
) ) )
29
{
30
if
(cfg.
exists
(
"bitsToCheck"
)) {
31
isBitMap_
=
true
;
32
mask_
= 0;
33
if
(cfg.
existsAs
<std::vector<std::string> >(
"bitsToCheck"
)) {
34
std::vector<std::string> strbits = cfg.
getParameter
<std::vector<std::string> >(
"bitsToCheck"
);
35
for
(std::vector<std::string>::const_iterator istrbit = strbits.begin(), estrbit = strbits.end();
36
istrbit != estrbit; ++istrbit) {
37
if
(*istrbit ==
"id"
) {
mask_
|= 1; }
38
else
if
(*istrbit ==
"iso"
) {
mask_
|= 2; }
39
else
if
(*istrbit ==
"conv"
) {
mask_
|= 4; }
40
else
if
(*istrbit ==
"ip"
) {
mask_
|= 8; }
41
else
throw
cms::Exception
(
"Configuration"
) <<
"ElectronIDPFCandidateSelector: "
<<
42
"bitsToCheck allowed string values are only id(0), iso(1), conv(2), ip(3).\n"
<<
43
"Otherwise, use uint32_t bitmask).\n"
;
44
}
45
}
else
if
(cfg.
existsAs
<uint32_t>(
"bitsToCheck"
)) {
46
mask_
= cfg.
getParameter
<uint32_t>(
"bitsToCheck"
);
47
}
else
{
48
throw
cms::Exception
(
"Configuration"
) <<
"ElectronIDPFCandidateSelector: "
<<
49
"bitsToCheck must be either a vector of strings, or a uint32 bitmask.\n"
;
50
}
51
}
else
{
52
isBitMap_
=
false
;
53
value_
= cfg.
getParameter
<
double
>(
"electronIdCut"
);
54
}
55
}
56
57
void
select
(
const
HandleToCollection
&
hc
,
58
const
edm::Event
&
e
,
59
const
edm::EventSetup
&
s
) {
60
selected_
.clear();
61
62
edm::Handle<reco::GsfElectronCollection>
electrons
;
63
e.
getByToken
(
electronsToken_
, electrons);
64
65
edm::Handle<edm::ValueMap<float>
> electronId;
66
e.
getByToken
(
electronIdToken_
, electronId);
67
68
unsigned
key
=0;
69
for
( collection::const_iterator pfc = hc->begin();
70
pfc != hc->end(); ++pfc, ++
key
) {
71
72
// Get GsfTrack for matching with reco::GsfElectron objects
73
reco::GsfTrackRef
PfTk = pfc->gsfTrackRef();
74
75
// skip ones without GsfTrack: they won't be matched anyway
76
if
(PfTk.
isNull
())
continue
;
77
78
int
match
= -1;
79
// try first the non-ambiguous tracks
80
for
(reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
81
if
(it->gsfTrack() == PfTk) { match = it - electrons->begin();
break
; }
82
}
83
// then the ambiguous ones
84
if
(match == -1) {
85
for
(reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
86
if
(
std::count
(it->ambiguousGsfTracksBegin(), it->ambiguousGsfTracksEnd(), PfTk) > 0) {
87
match = it - electrons->begin();
break
;
88
}
89
}
90
}
91
// if found, make a GsfElectronRef and read electron id
92
if
(match != -1) {
93
reco::GsfElectronRef
ref(electrons,match);
94
float
eleId = (*electronId)[ref];
95
bool
pass =
false
;
96
if
(
isBitMap_
) {
97
uint32_t thisval = eleId;
98
pass = ((thisval &
mask_
) ==
mask_
);
99
}
else
{
100
pass = (eleId >
value_
);
101
}
102
if
(pass) {
103
selected_
.push_back(
reco::PFCandidate
(*pfc) );
104
reco::PFCandidatePtr
ptrToMother( hc, key );
105
selected_
.back().setSourceCandidatePtr( ptrToMother );
106
}
107
}
108
}
109
}
110
111
private
:
112
edm::EDGetTokenT<reco::GsfElectronCollection>
electronsToken_
;
113
edm::EDGetTokenT<edm::ValueMap<float>
>
electronIdToken_
;
114
bool
isBitMap_
;
115
uint32_t
mask_
;
116
double
value_
;
117
};
118
}
119
120
#endif
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
pf2pat::ElectronIDPFCandidateSelectorDefinition
Selects PFCandidates basing on cuts provided with string cut parser.
Definition:
ElectronIDPFCandidateSelectorDefinition.h:24
KineDebug3::count
void count()
Definition:
KinematicConstrainedVertexUpdatorT.h:23
nano_cff.electrons
electrons
Definition:
nano_cff.py:35
edm::ParameterSet::existsAs
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition:
ParameterSet.h:186
Exception
Definition:
hltDiff.cc:292
pf2pat::ElectronIDPFCandidateSelectorDefinition::ElectronIDPFCandidateSelectorDefinition
ElectronIDPFCandidateSelectorDefinition(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
Definition:
ElectronIDPFCandidateSelectorDefinition.h:26
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:579
edm::Ref< GsfTrackCollection >
Event.h
alignCSCRings.s
s
Definition:
alignCSCRings.py:91
edm::Handle
Definition:
AssociativeIterator.h:48
edm::ParameterSet::exists
bool exists(std::string const ¶meterName) const
checks if a parameter exists
Definition:
ParameterSet.cc:760
MillePedeFileConverter_cfg.e
e
Definition:
MillePedeFileConverter_cfg.py:37
crabWrapper.key
key
Definition:
crabWrapper.py:17
pf2pat::ElectronIDPFCandidateSelectorDefinition::mask_
uint32_t mask_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:115
ValueMap.h
reco::GsfElectronCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
Definition:
GsfElectronFwd.h:14
edm::EDGetTokenT< reco::GsfElectronCollection >
ParameterSet.h
PFCandidateSelectorDefinition.h
PFCandidate.h
pf2pat::ElectronIDPFCandidateSelectorDefinition::isBitMap_
bool isBitMap_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:114
pf2pat::ElectronIDPFCandidateSelectorDefinition::electronIdToken_
edm::EDGetTokenT< edm::ValueMap< float > > electronIdToken_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:113
edm::EventSetup
Definition:
EventSetup.h:52
edm::Ptr< PFCandidate >
objects.autophobj.float
float
Definition:
autophobj.py:147
looper.cfg
cfg
Definition:
looper.py:294
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition:
Ref.h:250
GsfElectron.h
pf2pat::ElectronIDPFCandidateSelectorDefinition::select
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
Definition:
ElectronIDPFCandidateSelectorDefinition.h:57
pf2pat
Definition:
ElectronIDPFCandidateSelectorDefinition.h:22
pf2pat::PFCandidateSelectorDefinition::selected_
container selected_
Definition:
PFCandidateSelectorDefinition.h:35
pf2pat::ElectronIDPFCandidateSelectorDefinition::electronsToken_
edm::EDGetTokenT< reco::GsfElectronCollection > electronsToken_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:112
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition:
PFCandidate.h:40
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:43
edm
HLT enums.
Definition:
AlignableModifier.h:17
AnalysisDataFormats_SUSYBSMObjects::hc
susybsm::HSCParticleCollection hc
Definition:
classes.h:25
pf2pat::PFCandidateSelectorDefinition
Definition:
PFCandidateSelectorDefinition.h:11
edm::ParameterSet
Definition:
ParameterSet.h:36
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:10
edm::Event
Definition:
Event.h:70
pf2pat::ElectronIDPFCandidateSelectorDefinition::value_
double value_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:116
PFCandidateFwd.h
ConsumesCollector.h
edm::ConsumesCollector
Definition:
ConsumesCollector.h:39
Generated for CMSSW Reference Manual by
1.8.11