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"
,
edm::InputTag
(
""
))->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 \"pt > 100.0 && abs(rapidity()) < 2.4\"."
);
50
descriptions.
addWithDefaultLabel
(
desc
);
51
}
52
53
// Default initialization is for edm::FwdPtr. Specialization (below) is for edm::Ptr.
54
typename
ConstituentsOutput::value_type
const
initptr
(
edm::Ptr<reco::Candidate>
const
& dau)
const
{
55
return
typename
ConstituentsOutput::value_type
(dau, dau);
56
}
57
58
void
produce
(
edm::Event
&
iEvent
,
edm::EventSetup
const
& iSetup)
override
{
59
auto
jets
= std::make_unique<JetsOutput>();
60
auto
candsOut = std::make_unique<ConstituentsOutput>();
61
62
edm::Handle<edm::View<T>
> h_jets;
63
iEvent
.getByToken(
srcToken_
, h_jets);
64
65
// Now set the Ptrs with the orphan handles.
66
for
(
auto
const
&
jet
: *h_jets) {
67
// Check the selection
68
if
(
selector_
(
jet
)) {
69
// Add the jets that pass to the output collection
70
jets
->push_back(
jet
);
71
72
for
(
unsigned
int
ida{}; ida <
jet
.numberOfDaughters(); ++ida) {
73
candsOut->emplace_back(
initptr
(
jet
.daughterPtr(ida)));
74
}
75
}
76
}
77
78
iEvent
.put(
std::move
(
jets
));
79
iEvent
.put(
std::move
(candsOut),
"constituents"
);
80
}
81
82
private
:
83
edm::EDGetTokenT<edm::View<T>
>
const
srcToken_
;
84
StringCutObjectSelector<T>
const
selector_
;
85
};
86
87
template
<>
88
edm::Ptr<pat::PackedCandidate>
const
89
JetConstituentSelector<pat::Jet, std::vector<edm::Ptr<pat::PackedCandidate>
>>::initptr(
90
edm::Ptr<reco::Candidate>
const
& dau)
const
{
91
edm::Ptr<pat::PackedCandidate>
retval(dau);
92
return
retval;
93
}
94
95
template
<>
96
edm::Ptr<pat::PackedGenParticle>
const
97
JetConstituentSelector<reco::GenJet, std::vector<edm::Ptr<pat::PackedGenParticle>
>>::initptr(
98
edm::Ptr<reco::Candidate>
const
& dau)
const
{
99
edm::Ptr<pat::PackedGenParticle>
retval(dau);
100
return
retval;
101
}
102
103
using
PFJetConstituentSelector
=
JetConstituentSelector<reco::PFJet>
;
104
using
GenJetConstituentSelector
=
JetConstituentSelector<reco::GenJet, std::vector<edm::FwdPtr<reco::GenParticle>
>>;
105
using
GenJetPackedConstituentSelector
=
106
JetConstituentSelector<reco::GenJet, std::vector<edm::FwdPtr<pat::PackedGenParticle>
>>;
107
using
GenJetPackedConstituentPtrSelector
=
108
JetConstituentSelector<reco::GenJet, std::vector<edm::Ptr<pat::PackedGenParticle>
>>;
109
using
PatJetConstituentSelector
=
JetConstituentSelector<pat::Jet, std::vector<edm::FwdPtr<pat::PackedCandidate>
>>;
110
using
PatJetConstituentPtrSelector
=
JetConstituentSelector<pat::Jet, std::vector<edm::Ptr<pat::PackedCandidate>
>>;
111
using
MiniAODJetConstituentSelector
=
112
JetConstituentSelector<reco::PFJet, std::vector<edm::FwdPtr<pat::PackedCandidate>
>>;
113
using
MiniAODJetConstituentPtrSelector
=
114
JetConstituentSelector<reco::PFJet, std::vector<edm::Ptr<pat::PackedCandidate>
>>;
115
116
DEFINE_FWK_MODULE
(
PFJetConstituentSelector
);
117
DEFINE_FWK_MODULE
(
GenJetConstituentSelector
);
118
DEFINE_FWK_MODULE
(
GenJetPackedConstituentPtrSelector
);
119
DEFINE_FWK_MODULE
(
PatJetConstituentSelector
);
120
DEFINE_FWK_MODULE
(
PatJetConstituentPtrSelector
);
121
DEFINE_FWK_MODULE
(
MiniAODJetConstituentSelector
);
metsig::jet
Definition:
SignAlgoResolutions.h:47
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition:
ConfigurationDescriptions.cc:87
JetConstituentSelector::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition:
JetConstituentSelector.cc:45
EDProducer.h
JetConstituentSelector::initptr
ConstituentsOutput::value_type const initptr(edm::Ptr< reco::Candidate > const &dau) const
Definition:
JetConstituentSelector.cc:54
JetConstituentSelector::selector_
StringCutObjectSelector< T > const selector_
Definition:
JetConstituentSelector.cc:84
StringCutObjectSelector.h
Event.h
StringCutObjectSelector< T >
edm::Handle
Definition:
AssociativeIterator.h:50
JetConstituentSelector::JetConstituentSelector
JetConstituentSelector(edm::ParameterSet const ¶ms)
Definition:
JetConstituentSelector.cc:38
HLT_2022v15_cff.InputTag
InputTag
Definition:
HLT_2022v15_cff.py:60417
PDWG_EXODelayedJetMET_cff.jets
jets
Definition:
PDWG_EXODelayedJetMET_cff.py:14
PackedCandidate.h
edm::EDGetTokenT
Definition:
EDGetToken.h:37
PackedGenParticle.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSetDescription
Definition:
ParameterSetDescription.h:52
iEvent
int iEvent
Definition:
GenABIO.cc:224
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition:
JetExtendedAssociation.h:30
ParameterSetDescription.h
submitPVResolutionJobs.desc
string desc
Definition:
submitPVResolutionJobs.py:251
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
edm::EventSetup
Definition:
EventSetup.h:59
Jet.h
edm::Ptr< reco::Candidate >
CaloJet.h
correctionTermsCaloMet_cff.C
C
Definition:
correctionTermsCaloMet_cff.py:34
submitPVValidationJobs.params
def params
Definition:
submitPVValidationJobs.py:482
JetConstituentSelector::srcToken_
edm::EDGetTokenT< edm::View< T > > const srcToken_
Definition:
JetConstituentSelector.cc:83
edm::stream::EDProducer
Definition:
EDProducer.h:36
JetConstituentSelector::ConstituentsOutput
C ConstituentsOutput
Definition:
JetConstituentSelector.cc:35
JetConstituentSelector::produce
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
Definition:
JetConstituentSelector.cc:58
edm::InputTag
Definition:
InputTag.h:15
Jet.h
JetConstituentSelector::ValueType
typename C::value_type ValueType
Definition:
JetConstituentSelector.cc:36
edm::ParameterSet
Definition:
ParameterSet.h:47
JetConstituentSelector::JetsOutput
std::vector< T > JetsOutput
Definition:
JetConstituentSelector.cc:34
ConfigurationDescriptions.h
edm::Event
Definition:
Event.h:73
PFJet.h
MakerMacros.h
eostools.move
def move(src, dest)
Definition:
eostools.py:511
edm::ConfigurationDescriptions
Definition:
ConfigurationDescriptions.h:28
JetConstituentSelector
Definition:
JetConstituentSelector.cc:32
GenJet.h
Generated for CMSSW Reference Manual by
1.8.14