CommonTools
RecoAlgos
plugins
JetConstituentSelector.cc
Go to the documentation of this file.
1
/* \class PFJetSelector
2
*
3
* Selects jets with a configurable string-based cut,
4
* and also writes out the constituents of the jet
5
* into a separate collection.
6
*
7
* \author: Sal Rappoccio
8
*
9
*
10
* for more details about the cut syntax, see the documentation
11
* page below:
12
*
13
* https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePhysicsCutParser
14
*
15
*/
16
17
#include "
CommonTools/UtilAlgos/interface/StringCutObjectSelector.h
"
18
#include "
DataFormats/JetReco/interface/Jet.h
"
19
#include "
DataFormats/JetReco/interface/PFJet.h
"
20
#include "
DataFormats/JetReco/interface/GenJet.h
"
21
#include "
DataFormats/PatCandidates/interface/Jet.h
"
22
#include "
DataFormats/PatCandidates/interface/PackedCandidate.h
"
23
#include "
DataFormats/PatCandidates/interface/PackedGenParticle.h
"
24
#include "
DataFormats/JetReco/interface/CaloJet.h
"
25
#include "
FWCore/Framework/interface/stream/EDProducer.h
"
26
#include "
FWCore/Framework/interface/MakerMacros.h
"
27
#include "
FWCore/Framework/interface/Event.h
"
28
#include "
FWCore/ParameterSet/interface/ConfigurationDescriptions.h
"
29
#include "
FWCore/ParameterSet/interface/ParameterSetDescription.h
"
30
31
template
<
class
T,
typename
C = std::vector<
typename
T::ConstituentTypeFwdPtr>>
32
class
JetConstituentSelector
:
public
edm::stream::EDProducer
<> {
33
public
:
34
using
JetsOutput
= std::vector<T>;
35
using
ConstituentsOutput
=
C
;
36
using
ValueType
=
typename
C::value_type
;
37
38
JetConstituentSelector
(
edm::ParameterSet
const
&
params
)
39
:
srcToken_
{consumes<edm::View<T>>(
params
.getParameter<
edm::InputTag
>(
"src"
))},
40
selector_
{
params
.getParameter<
std::string
>(
"cut"
)} {
41
produces<JetsOutput>();
42
produces<ConstituentsOutput>(
"constituents"
);
43
}
44
45
static
void
fillDescriptions
(
edm::ConfigurationDescriptions
& descriptions) {
46
edm::ParameterSetDescription
desc;
47
desc.
add
<
edm::InputTag
>(
"src"
)->setComment(
"InputTag used for retrieving jets in event."
);
48
desc.
add
<
std::string
>(
"cut"
)->setComment(
49
"Cut used by which to select jets. For example:\n"
50
" \"pt > 100.0 && abs(rapidity()) < 2.4\"."
);
51
52
// addDefault must be used here instead of add unless this function is specialized
53
// for different sets of template parameter types. Each specialization would need
54
// a different module label. Otherwise the generated cfi filenames will conflict
55
// for the different plugins.
56
descriptions.
addDefault
(desc);
57
}
58
59
// Default initialization is for edm::FwdPtr. Specialization (below) is for edm::Ptr.
60
typename
ConstituentsOutput::value_type
const
initptr
(
edm::Ptr<reco::Candidate>
const
& dau)
const
{
61
return
typename
ConstituentsOutput::value_type
(dau, dau);
62
}
63
64
void
produce
(
edm::Event
&
iEvent
,
edm::EventSetup
const
& iSetup)
override
{
65
auto
jets
= std::make_unique<JetsOutput>();
66
auto
candsOut = std::make_unique<ConstituentsOutput>();
67
68
edm::Handle<edm::View<T>
> h_jets;
69
iEvent
.getByToken(
srcToken_
, h_jets);
70
71
// Now set the Ptrs with the orphan handles.
72
for
(
auto
const
&
jet
: *h_jets) {
73
// Check the selection
74
if
(
selector_
(
jet
)) {
75
// Add the jets that pass to the output collection
76
jets
->push_back(
jet
);
77
78
for
(
unsigned
int
ida{}; ida <
jet
.numberOfDaughters(); ++ida) {
79
candsOut->emplace_back(
initptr
(
jet
.daughterPtr(ida)));
80
}
81
}
82
}
83
84
iEvent
.put(
std::move
(
jets
));
85
iEvent
.put(
std::move
(candsOut),
"constituents"
);
86
}
87
88
private
:
89
edm::EDGetTokenT<edm::View<T>
>
const
srcToken_
;
90
StringCutObjectSelector<T>
const
selector_
;
91
};
92
93
template
<>
94
edm::Ptr<pat::PackedCandidate>
const
95
JetConstituentSelector<pat::Jet, std::vector<edm::Ptr<pat::PackedCandidate>
>>::initptr(
96
edm::Ptr<reco::Candidate>
const
& dau)
const
{
97
edm::Ptr<pat::PackedCandidate>
retval(dau);
98
return
retval;
99
}
100
101
template
<>
102
edm::Ptr<pat::PackedGenParticle>
const
103
JetConstituentSelector<reco::GenJet, std::vector<edm::Ptr<pat::PackedGenParticle>
>>::initptr(
104
edm::Ptr<reco::Candidate>
const
& dau)
const
{
105
edm::Ptr<pat::PackedGenParticle>
retval(dau);
106
return
retval;
107
}
108
109
using
PFJetConstituentSelector
=
JetConstituentSelector<reco::PFJet>
;
110
using
GenJetConstituentSelector
=
JetConstituentSelector<reco::GenJet, std::vector<edm::FwdPtr<reco::GenParticle>
>>;
111
using
GenJetPackedConstituentSelector
=
112
JetConstituentSelector<reco::GenJet, std::vector<edm::FwdPtr<pat::PackedGenParticle>
>>;
113
using
GenJetPackedConstituentPtrSelector
=
114
JetConstituentSelector<reco::GenJet, std::vector<edm::Ptr<pat::PackedGenParticle>
>>;
115
using
PatJetConstituentSelector
=
JetConstituentSelector<pat::Jet, std::vector<edm::FwdPtr<pat::PackedCandidate>
>>;
116
using
PatJetConstituentPtrSelector
=
JetConstituentSelector<pat::Jet, std::vector<edm::Ptr<pat::PackedCandidate>
>>;
117
using
MiniAODJetConstituentSelector
=
118
JetConstituentSelector<reco::PFJet, std::vector<edm::FwdPtr<pat::PackedCandidate>
>>;
119
using
MiniAODJetConstituentPtrSelector
=
120
JetConstituentSelector<reco::PFJet, std::vector<edm::Ptr<pat::PackedCandidate>
>>;
121
122
DEFINE_FWK_MODULE
(
PFJetConstituentSelector
);
123
DEFINE_FWK_MODULE
(
GenJetConstituentSelector
);
124
DEFINE_FWK_MODULE
(
GenJetPackedConstituentPtrSelector
);
125
DEFINE_FWK_MODULE
(
PatJetConstituentSelector
);
126
DEFINE_FWK_MODULE
(
PatJetConstituentPtrSelector
);
127
DEFINE_FWK_MODULE
(
MiniAODJetConstituentSelector
);
ConfigurationDescriptions.h
CaloJet.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition:
ParameterSetDescription.h:95
JetConstituentSelector::srcToken_
const edm::EDGetTokenT< edm::View< T > > srcToken_
Definition:
JetConstituentSelector.cc:89
StringCutObjectSelector.h
CalibrationSummaryClient_cfi.params
params
Definition:
CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT
Definition:
EDGetToken.h:33
PFJet.h
PackedGenParticle.h
edm::ParameterSetDescription
Definition:
ParameterSetDescription.h:52
JetConstituentSelector::ValueType
typename C::value_type ValueType
Definition:
JetConstituentSelector.cc:36
EDProducer.h
Jet.h
JetConstituentSelector::JetsOutput
std::vector< T > JetsOutput
Definition:
JetConstituentSelector.cc:34
singleTopDQM_cfi.jets
jets
Definition:
singleTopDQM_cfi.py:42
JetConstituentSelector::produce
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
Definition:
JetConstituentSelector.cc:64
edm::Handle
Definition:
AssociativeIterator.h:50
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
JetConstituentSelector
Definition:
JetConstituentSelector.cc:32
JetConstituentSelector::ConstituentsOutput
C ConstituentsOutput
Definition:
JetConstituentSelector.cc:35
JetConstituentSelector::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition:
JetConstituentSelector.cc:45
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition:
ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition:
ParameterSet.h:36
Event.h
PackedCandidate.h
iEvent
int iEvent
Definition:
GenABIO.cc:224
edm::stream::EDProducer
Definition:
EDProducer.h:38
edm::EventSetup
Definition:
EventSetup.h:57
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition:
JetExtendedAssociation.h:30
Jet.h
edm::Ptr< reco::Candidate >
eostools.move
def move(src, dest)
Definition:
eostools.py:511
gen::C
C
Definition:
PomwigHadronizer.cc:76
JetConstituentSelector::JetConstituentSelector
JetConstituentSelector(edm::ParameterSet const ¶ms)
Definition:
JetConstituentSelector.cc:38
metsig::jet
Definition:
SignAlgoResolutions.h:47
StringCutObjectSelector< T >
JetConstituentSelector::selector_
const StringCutObjectSelector< T > selector_
Definition:
JetConstituentSelector.cc:90
GenJet.h
edm::Event
Definition:
Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition:
ConfigurationDescriptions.cc:99
edm::InputTag
Definition:
InputTag.h:15
JetConstituentSelector::initptr
const ConstituentsOutput::value_type initptr(edm::Ptr< reco::Candidate > const &dau) const
Definition:
JetConstituentSelector.cc:60
Generated for CMSSW Reference Manual by
1.8.16