24 produces<nanoaod::FlatTable>();
28 else if (type ==
"Electron")
30 else if (type ==
"ElectronDressed")
32 else if (type ==
"Tau")
34 else if (type ==
"Photon")
36 else if (type ==
"Other")
39 throw cms::Exception(
"Configuration",
"Unsupported objType '" + type +
"'\n");
44 "1 = prompt muon (including gamma*->mu mu), 15 = muon from prompt tau, " 45 "5 = muon from b, 4 = muon from c, 3 = muon from light or unknown, 0 = unmatched";
49 "1 = prompt electron (including gamma*->mu mu), 15 = electron from prompt tau, 22 = prompt photon (likely " 51 "5 = electron from b, 4 = electron from c, 3 = electron from light or unknown, 0 = unmatched";
55 "1 = prompt electron (including gamma*->mu mu), 15 = electron from prompt tau, 22 = prompt photon (likely " 57 "5 = electron from b, 4 = electron from c, 3 = electron from light or unknown, 0 = unmatched";
60 flavDoc_ =
"1 = prompt photon, 11 = prompt electron, 0 = unknown or unmatched";
64 "1 = prompt electron, 2 = prompt muon, 3 = tau->e decay, 4 = tau->mu decay, 5 = hadronic tau decay, 0 = " 65 "unknown or unmatched";
68 flavDoc_ =
"1 = from hard scatter, 0 = unknown or unmatched";
89 unsigned int ncand = cands->
size();
91 auto tab = std::make_unique<nanoaod::FlatTable>(ncand,
objName_,
false,
true);
110 std::vector<int>
key(ncand, -1), flav(ncand, 0);
111 for (
unsigned int i = 0;
i < ncand; ++
i) {
118 matchVisTau = (*mapVisTau)[cands->
ptrAt(
i)];
121 matchDressedLep = (*mapDressedLep)[cands->
ptrAt(
i)];
123 hasTauAnc = (*mapTauAnc)[matchDressedLep];
134 if (match->isPromptFinalState())
136 else if (match->isDirectPromptTauDecayProductFinalState())
142 if (match->isPromptFinalState())
143 flav[
i] = (match->pdgId() == 22 ? 22 : 1);
144 else if (match->isDirectPromptTauDecayProductFinalState())
151 if (matchDressedLep->pdgId() == 22)
158 for (
auto& consti : matchDressedLep->getGenConstituents()) {
159 if (
abs(consti->pdgId()) != 11)
161 if (consti->pt() <
minpt)
163 minpt = consti->
pt();
164 highestPtConstituent = consti;
166 if (highestPtConstituent) {
168 std::find_if(genParts->begin(), genParts->end(), [highestPtConstituent](
reco::GenParticle genp) {
169 return (
abs(genp.pdgId()) == 11) && (
deltaR(genp, *highestPtConstituent) < 0.01) &&
170 (
abs(genp.pt() - highestPtConstituent->
pt()) / highestPtConstituent->
pt() < 0.01);
172 if (iter != genParts->end()) {
173 key[
i] = iter - genParts->begin();
178 else if (match->isPromptFinalState())
179 flav[
i] = (match->pdgId() == 22 ? 22 : 1);
180 else if (match->isDirectPromptTauDecayProductFinalState())
186 if (match->isPromptFinalState() && match->pdgId() == 22)
188 else if ((match->isPromptFinalState() || match->isDirectPromptTauDecayProductFinalState()) &&
189 abs(match->pdgId()) == 11)
194 if (match.
isNonnull() && match->statusFlags().isPrompt() &&
abs(match->pdgId()) == 11)
196 else if (match.
isNonnull() && match->statusFlags().isPrompt() &&
abs(match->pdgId()) == 13)
198 else if (match.
isNonnull() && match->isDirectPromptTauDecayProductFinalState() &&
abs(match->pdgId()) == 11)
200 else if (match.
isNonnull() && match->isDirectPromptTauDecayProductFinalState() &&
abs(match->pdgId()) == 13)
206 flav[
i] = match->statusFlags().fromHardProcess();
214 tab->addColumn<uint8_t>(branchName_ +
"Flav",
216 "Flavour of genParticle (DressedLeptons for electrons) for " + doc_ +
": " +
flavDoc_,
220 tab->addColumn<uint8_t>(branchName_ +
"Flav",
222 "Flavour of genParticle for " + doc_ +
": " +
flavDoc_,
230 for (
unsigned int im = 0, nm = match->numberOfMothers(); im < nm; ++im) {
233 if (mom.
key() >= match.
key())
236 if (
id / 1000 == 5 ||
id / 100 == 5 ||
id == 5)
238 if (
id / 1000 == 4 ||
id / 100 == 4 ||
id == 4)
240 if (mom->status() == 2) {
253 desc.
add<
std::string>(
"objName")->setComment(
"name of the nanoaod::FlatTable to extend with this table");
256 "name of the column to write (the final branch in the nanoaod will be <objName>_<branchName>Idx and " 257 "<objName>_<branchName>Flav");
258 desc.
add<
std::string>(
"docString")->setComment(
"documentation to forward to the output");
260 "physics object collection for the reconstructed objects (e.g. leptons)");
262 "tag to an edm::Association<GenParticleCollection> mapping src to gen, such as the one produced by MCMatcher");
264 "type of object to match (Muon, Electron, Tau, Photon, Other), taylors what's in t Flav branch");
266 ->setComment(
"as mcMap, but pointing to the visible gen taus (only if objType == Tau)");
268 ->setComment(
"as mcMap, but pointing to gen dressed leptons (only if objType == Electrons)");
270 ->setComment(
"Value map of matched gen electrons containing info on the tau ancestry");
272 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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
enum CandMCMatchTableProducer::MatchType type_
double pt() const final
transverse momentum
const std::string branchName_
const std::string objName_
key_type key() const
Accessor for product key.
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMapVisTau_
edm::EDGetTokenT< reco::GenParticleCollection > genPartsToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
#define DEFINE_FWK_MODULE(type)
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
edm::EDGetTokenT< edm::ValueMap< bool > > mapTauAnc_
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::EDGetTokenT< edm::Association< reco::GenJetCollection > > candMapDressedLep_
edm::View< Candidate > CandidateView
view of a collection containing candidates