Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
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 "
DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h
"
13
#include "
DataFormats/ParticleFlowCandidate/interface/PFCandidate.h
"
14
#include "
DataFormats/Common/interface/ValueMap.h
"
15
#include "
DataFormats/EgammaCandidates/interface/GsfElectron.h
"
16
#include "
CommonTools/ParticleFlow/interface/PFCandidateSelectorDefinition.h
"
17
#include <algorithm>
18
19
namespace
pf2pat {
20
21
struct
ElectronIDPFCandidateSelectorDefinition
:
public
PFCandidateSelectorDefinition
{
22
23
ElectronIDPFCandidateSelectorDefinition
(
const
edm::ParameterSet
& cfg ) :
24
electrons_
( cfg.getParameter< edm::InputTag >(
"recoGsfElectrons"
) ),
25
electronId_
( cfg.getParameter< edm::InputTag >(
"electronIdMap"
) )
26
{
27
if
(cfg.
exists
(
"bitsToCheck"
)) {
28
isBitMap_
=
true
;
29
mask_
= 0;
30
if
(cfg.
existsAs
<std::vector<std::string> >(
"bitsToCheck"
)) {
31
std::vector<std::string> strbits = cfg.
getParameter
<std::vector<std::string> >(
"bitsToCheck"
);
32
for
(std::vector<std::string>::const_iterator istrbit = strbits.begin(), estrbit = strbits.end();
33
istrbit != estrbit; ++istrbit) {
34
if
(*istrbit ==
"id"
) {
mask_
|= 1; }
35
else
if
(*istrbit ==
"iso"
) {
mask_
|= 2; }
36
else
if
(*istrbit ==
"conv"
) {
mask_
|= 4; }
37
else
if
(*istrbit ==
"ip"
) {
mask_
|= 8; }
38
else
throw
cms::Exception
(
"Configuration"
) <<
"ElectronIDPFCandidateSelector: "
<<
39
"bitsToCheck allowed string values are only id(0), iso(1), conv(2), ip(3).\n"
<<
40
"Otherwise, use uint32_t bitmask).\n"
;
41
}
42
}
else
if
(cfg.
existsAs
<uint32_t>(
"bitsToCheck"
)) {
43
mask_
= cfg.
getParameter
<uint32_t>(
"bitsToCheck"
);
44
}
else
{
45
throw
cms::Exception
(
"Configuration"
) <<
"ElectronIDPFCandidateSelector: "
<<
46
"bitsToCheck must be either a vector of strings, or a uint32 bitmask.\n"
;
47
}
48
}
else
{
49
isBitMap_
=
false
;
50
value_
= cfg.
getParameter
<
double
>(
"electronIdCut"
);
51
}
52
}
53
54
void
select
(
const
HandleToCollection
& hc,
55
const
edm::Event
&
e
,
56
const
edm::EventSetup
&
s
) {
57
selected_
.clear();
58
59
edm::Handle<reco::GsfElectronCollection>
electrons
;
60
e.
getByLabel
(
electrons_
, electrons);
61
62
edm::Handle<edm::ValueMap<float>
> electronId;
63
e.
getByLabel
(
electronId_
, electronId);
64
65
unsigned
key
=0;
66
for
( collection::const_iterator pfc = hc->begin();
67
pfc != hc->end(); ++pfc, ++
key
) {
68
69
// Get GsfTrack for matching with reco::GsfElectron objects
70
reco::GsfTrackRef
PfTk = pfc->gsfTrackRef();
71
72
// skip ones without GsfTrack: they won't be matched anyway
73
if
(PfTk.
isNull
())
continue
;
74
75
int
match
= -1;
76
// try first the non-ambiguous tracks
77
for
(reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
78
if
(it->gsfTrack() == PfTk) { match = it - electrons->begin();
break
; }
79
}
80
// then the ambiguous ones
81
if
(match == -1) {
82
for
(reco::GsfElectronCollection::const_iterator it = electrons->begin(), ed = electrons->end(); it != ed; ++it) {
83
if
(
std::count
(it->ambiguousGsfTracksBegin(), it->ambiguousGsfTracksEnd(), PfTk) > 0) {
84
match = it - electrons->begin();
break
;
85
}
86
}
87
}
88
// if found, make a GsfElectronRef and read electron id
89
if
(match != -1) {
90
reco::GsfElectronRef
ref(electrons,match);
91
float
eleId = (*electronId)[ref];
92
bool
pass =
false
;
93
if
(
isBitMap_
) {
94
uint32_t thisval = eleId;
95
pass = ((thisval &
mask_
) ==
mask_
);
96
}
else
{
97
pass = (eleId >
value_
);
98
}
99
if
(pass) {
100
selected_
.push_back(
reco::PFCandidate
(*pfc) );
101
reco::PFCandidatePtr
ptrToMother( hc, key );
102
selected_
.back().setSourceCandidatePtr( ptrToMother );
103
}
104
}
105
}
106
}
107
108
private
:
109
edm::InputTag
electrons_
;
110
edm::InputTag
electronId_
;
111
bool
isBitMap_
;
112
uint32_t
mask_
;
113
double
value_
;
114
};
115
}
116
117
#endif
pf2pat::ElectronIDPFCandidateSelectorDefinition::electronId_
edm::InputTag electronId_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:110
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
pf2pat::ElectronIDPFCandidateSelectorDefinition
Selects PFCandidates basing on cuts provided with string cut parser.
Definition:
ElectronIDPFCandidateSelectorDefinition.h:21
prof2calltree.count
list count
Definition:
prof2calltree.py:146
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:187
pf2pat::ElectronIDPFCandidateSelectorDefinition::electrons_
edm::InputTag electrons_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:109
edm::ParameterSet::exists
bool exists(std::string const ¶meterName) const
checks if a parameter exists
Definition:
ParameterSet.cc:743
pf2pat::ElectronIDPFCandidateSelectorDefinition::ElectronIDPFCandidateSelectorDefinition
ElectronIDPFCandidateSelectorDefinition(const edm::ParameterSet &cfg)
Definition:
ElectronIDPFCandidateSelectorDefinition.h:23
pf2pat::ElectronIDPFCandidateSelectorDefinition::mask_
uint32_t mask_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:112
edm::Handle
Definition:
AssociativeIterator.h:48
ValueMap.h
HI_PhotonSkim_cff.electrons
tuple electrons
Definition:
HI_PhotonSkim_cff.py:77
edm::Ptr< PFCandidate >
PFCandidateSelectorDefinition.h
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition:
Ref.h:247
PFCandidate.h
pf2pat::ElectronIDPFCandidateSelectorDefinition::isBitMap_
bool isBitMap_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:111
edm::EventSetup
Definition:
EventSetup.h:44
edm::Event::getByLabel
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition:
Event.h:356
GsfElectron.h
pf2pat::ElectronIDPFCandidateSelectorDefinition::select
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
Definition:
ElectronIDPFCandidateSelectorDefinition.h:54
edm::hlt::Exception
error
Definition:
HLTenums.h:24
alignCSCRings.s
list s
Definition:
alignCSCRings.py:91
pf2pat::PFCandidateSelectorDefinition::selected_
container selected_
Definition:
PFCandidateSelectorDefinition.h:35
alignCSCRings.e
list e
Definition:
alignCSCRings.py:90
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition:
PFCandidate.h:33
edm::InputTag
Definition:
InputTag.h:12
combine.key
list key
Definition:
combine.py:13
pf2pat::PFCandidateSelectorDefinition
Definition:
PFCandidateSelectorDefinition.h:11
edm::ParameterSet
Definition:
ParameterSet.h:35
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:6
edm::Event
Definition:
Event.h:50
pf2pat::ElectronIDPFCandidateSelectorDefinition::value_
double value_
Definition:
ElectronIDPFCandidateSelectorDefinition.h:113
PFCandidateFwd.h
edm::Ref< GsfTrackCollection >
Generated for CMSSW Reference Manual by
1.8.5