24 produces<nanoaod::FlatTable>();
31 else throw cms::Exception(
"Configuration",
"Unsupported objType '"+type+
"'\n");
34 case MMuon:
flavDoc_ =
"1 = prompt muon (including gamma*->mu mu), 15 = muon from prompt tau, " 35 "5 = muon from b, 4 = muon from c, 3 = muon from light or unknown, 0 = unmatched";
break;
36 case MElectron:
flavDoc_ =
"1 = prompt electron (including gamma*->mu mu), 15 = electron from prompt tau, 22 = prompt photon (likely conversion), " 37 "5 = electron from b, 4 = electron from c, 3 = electron from light or unknown, 0 = unmatched";
break;
38 case MPhoton:
flavDoc_ =
"1 = prompt photon, 13 = prompt electron, 0 = unknown or unmatched";
break;
39 case MTau:
flavDoc_ =
"1 = prompt electron, 2 = prompt muon, 3 = tau->e decay, 4 = tau->mu decay, 5 = hadronic tau decay, 0 = unknown or unmatched";
break;
40 case MOther:
flavDoc_ =
"1 = from hard scatter, 0 = unknown or unmatched";
break;
54 unsigned int ncand = cands->
size();
56 auto tab = std::make_unique<nanoaod::FlatTable>(ncand,
objName_,
false,
true);
66 std::vector<int>
key(ncand, -1), flav(ncand, 0);
67 for (
unsigned int i = 0;
i < ncand; ++
i) {
72 matchVisTau = (*mapVisTau)[cands->
ptrAt(
i)];
79 if (match->isPromptFinalState()) flav[
i] = 1;
80 else if (match->isDirectPromptTauDecayProductFinalState()) flav[
i] = 15;
84 if (match->isPromptFinalState()) flav[
i] = (match->pdgId() == 22 ? 22 : 1);
85 else if (match->isDirectPromptTauDecayProductFinalState()) flav[
i] = 15;
89 if (match->isPromptFinalState()) flav[
i] = (match->pdgId() == 22 ? 1 : 13);
93 if ( match.
isNonnull() && match->statusFlags().isPrompt() &&
abs(match->pdgId()) == 11 ) flav[
i] = 1;
94 else if ( match.
isNonnull() && match->statusFlags().isPrompt() &&
abs(match->pdgId()) == 13 ) flav[
i] = 2;
95 else if ( match.
isNonnull() && match->isDirectPromptTauDecayProductFinalState() &&
abs(match->pdgId()) == 11 ) flav[
i] = 3;
96 else if ( match.
isNonnull() && match->isDirectPromptTauDecayProductFinalState() &&
abs(match->pdgId()) == 13 ) flav[
i] = 4;
97 else if ( matchVisTau.
isNonnull() ) flav[
i] = 5;
100 flav[
i] = match->statusFlags().fromHardProcess();
112 for (
unsigned int im = 0, nm = match->numberOfMothers(); im < nm; ++im) {
115 if (mom.
key() >= match.
key())
continue;
117 if (
id / 1000 == 5 ||
id / 100 == 5 ||
id == 5)
return 5;
118 if (
id / 1000 == 4 ||
id / 100 == 4 ||
id == 4) has4 =
true;
119 if (mom->status() == 2) {
121 if (
id == 5)
return 5;
122 else if (
id == 4) has4 =
true;
130 desc.
add<
std::string>(
"objName")->setComment(
"name of the nanoaod::FlatTable to extend with this table");
131 desc.
add<
std::string>(
"branchName")->setComment(
"name of the column to write (the final branch in the nanoaod will be <objName>_<branchName>Idx and <objName>_<branchName>Flav");
132 desc.
add<
std::string>(
"docString")->setComment(
"documentation to forward to the output");
133 desc.
add<
edm::InputTag>(
"src")->setComment(
"physics object collection for the reconstructed objects (e.g. leptons)");
134 desc.
add<
edm::InputTag>(
"mcMap")->setComment(
"tag to an edm::Association<GenParticleCollection> mapping src to gen, such as the one produced by MCMatcher");
135 desc.
add<
std::string>(
"objType")->setComment(
"type of object to match (Muon, Electron, Tau, Photon, Other), taylors what's in t Flav branch");
136 desc.
addOptional<
edm::InputTag>(
"mcMapVisTau")->setComment(
"as mcMap, but pointing to the visible gen taus (only if objType == Tau)");
137 descriptions.
add(
"candMcMatchTable", desc);
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Ptr< value_type > ptrAt(size_type i) const
#define DEFINE_FWK_MODULE(type)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
enum CandMCMatchTableProducer::MatchType type_
const std::string branchName_
const std::string objName_
key_type key() const
Accessor for product key.
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMapVisTau_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Abs< T >::type abs(const T &t)
const edm::EDGetTokenT< reco::CandidateView > src_
static int getParentHadronFlag(const reco::GenParticleRef match)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMap_
void produce(edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
CandMCMatchTableProducer(edm::ParameterSet const ¶ms)
~CandMCMatchTableProducer() override
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
edm::View< Candidate > CandidateView
view of a collection containing candidates