24 produces<nanoaod::FlatTable>();
28 else if (
type ==
"Electron")
30 else if (
type ==
"Tau")
32 else if (
type ==
"Photon")
34 else if (
type ==
"Other")
42 "1 = prompt muon (including gamma*->mu mu), 15 = muon from prompt tau, " 43 "5 = muon from b, 4 = muon from c, 3 = muon from light or unknown, 0 = unmatched";
47 "1 = prompt electron (including gamma*->mu mu), 15 = electron from prompt tau, 22 = prompt photon (likely " 49 "5 = electron from b, 4 = electron from c, 3 = electron from light or unknown, 0 = unmatched";
52 flavDoc_ =
"1 = prompt photon, 11 = prompt electron, 0 = unknown or unmatched";
56 "1 = prompt electron, 2 = prompt muon, 3 = tau->e decay, 4 = tau->mu decay, 5 = hadronic tau decay, 0 = " 57 "unknown or unmatched";
60 flavDoc_ =
"1 = from hard scatter, 0 = unknown or unmatched";
66 consumes<edm::Association<reco::GenParticleCollection>>(
params.getParameter<
edm::InputTag>(
"mcMapVisTau"));
71 consumes<edm::Association<reco::GenJetCollection>>(
params.getParameter<
edm::InputTag>(
"mcMapDressedLep"));
81 auto ncand = candProd.size();
83 auto tab = std::make_unique<nanoaod::FlatTable>(ncand,
objName_,
false,
true);
101 std::vector<int>
key(ncand, -1), flav(ncand, 0);
102 for (
unsigned int i = 0;
i < ncand; ++
i) {
104 const auto&
cand = candProd.ptrAt(
i);
110 matchVisTau = (*mapVisTau)[
cand];
113 matchDressedLep = (*mapDressedLep)[
cand];
115 hasTauAnc = (*mapTauAnc)[matchDressedLep];
118 if (
match.isNonnull())
127 if (
match->isPromptFinalState())
129 else if (
match->isDirectPromptTauDecayProductFinalState())
136 if (matchDressedLep->pdgId() == 22)
143 for (
auto& consti : matchDressedLep->getGenConstituents()) {
144 if (
abs(consti->pdgId()) != 11)
146 if (consti->pt() <
minpt)
148 minpt = consti->pt();
149 highestPtConstituent = consti;
151 if (highestPtConstituent) {
154 return (
abs(
genp.pdgId()) == 11) && (
deltaR(
genp, *highestPtConstituent) < 0.01) &&
155 (
abs(
genp.pt() - highestPtConstituent->
pt()) / highestPtConstituent->
pt() < 0.01);
157 if (iter != genParts->end()) {
158 key[
i] = iter - genParts->begin();
161 }
else if (!
match.isNonnull())
163 else if (
match->isPromptFinalState())
164 flav[
i] = (
match->pdgId() == 22 ? 22 : 1);
165 else if (
match->isDirectPromptTauDecayProductFinalState())
171 if (
match->isPromptFinalState() &&
match->pdgId() == 22)
173 else if ((
match->isPromptFinalState() ||
match->isDirectPromptTauDecayProductFinalState()) &&
179 if (
match.isNonnull() &&
match->statusFlags().isPrompt() &&
abs(
match->pdgId()) == 11)
181 else if (
match.isNonnull() &&
match->statusFlags().isPrompt() &&
abs(
match->pdgId()) == 13)
183 else if (
match.isNonnull() &&
match->isDirectPromptTauDecayProductFinalState() &&
abs(
match->pdgId()) == 11)
185 else if (
match.isNonnull() &&
match->isDirectPromptTauDecayProductFinalState() &&
abs(
match->pdgId()) == 13)
191 flav[
i] =
match->statusFlags().fromHardProcess();
195 tab->addColumn<
int>(
branchName_ +
"Idx",
key,
"Index into genParticle list for " +
doc_);
198 "Flavour of genParticle (DressedLeptons for electrons) for " +
doc_ +
": " +
flavDoc_);
205 for (
unsigned int im = 0, nm =
match->numberOfMothers(); im < nm; ++im) {
211 if (
id / 1000 == 5 ||
id / 100 == 5 ||
id == 5)
213 if (
id / 1000 == 4 ||
id / 100 == 4 ||
id == 4)
215 if (mom->status() == 2) {
228 desc.add<
std::string>(
"objName")->setComment(
"name of the nanoaod::FlatTable to extend with this table");
231 "name of the column to write (the final branch in the nanoaod will be <objName>_<branchName>Idx and " 232 "<objName>_<branchName>Flav");
233 desc.add<
std::string>(
"docString")->setComment(
"documentation to forward to the output");
235 "physics object collection for the reconstructed objects (e.g. leptons)");
237 "tag to an edm::Association<GenParticleCollection> mapping src to gen, such as the one produced by MCMatcher");
239 "type of object to match (Muon, Electron, Tau, Photon, Other), taylors what's in t Flav branch");
241 ->setComment(
"as mcMap, but pointing to the visible gen taus (only if objType == Tau)");
243 ->setComment(
"as mcMap, but pointing to gen dressed leptons (only if objType == Electrons)");
245 ->setComment(
"Value map of matched gen electrons containing info on the tau ancestry");
246 desc.addOptional<
edm::InputTag>(
"genparticles")->setComment(
"Collection of genParticles to be stored.");
247 descriptions.
add(
"candMcMatchTable",
desc);
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
genp
produce generated paricles in acceptance #
double pt() const final
transverse momentum
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
enum CandMCMatchTableProducer::MatchType type_
bool isNonnull() const
Checks for non-null.
const std::string branchName_
const std::string objName_
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMapVisTau_
key_type key() const
Accessor for product key.
edm::EDGetTokenT< reco::GenParticleCollection > genPartsToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
const edm::EDGetTokenT< reco::CandidateView > src_
static int getParentHadronFlag(const reco::GenParticleRef match)
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMap_
edm::EDGetTokenT< edm::ValueMap< bool > > mapTauAnc_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
CandMCMatchTableProducer(edm::ParameterSet const ¶ms)
void produce(edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
~CandMCMatchTableProducer() override
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > candMapDressedLep_
edm::View< Candidate > CandidateView
view of a collection containing candidates