21 doc_(params.getParameter<std::
string>(
"docString")),
24 produces<nanoaod::FlatTable>();
28 else if (type ==
"Electron")
30 else if (type ==
"Tau")
32 else if (type ==
"Photon")
34 else if (type ==
"Other")
37 throw cms::Exception(
"Configuration",
"Unsupported objType '" + type +
"'\n");
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";
82 unsigned int ncand = cands->size();
84 auto tab = std::make_unique<nanoaod::FlatTable>(ncand,
objName_,
false,
true);
103 std::vector<int>
key(ncand, -1), flav(ncand, 0);
104 for (
unsigned int i = 0;
i < ncand; ++
i) {
109 bool hasTauAnc =
false;
111 matchVisTau = (*mapVisTau)[cands->ptrAt(
i)];
114 matchDressedLep = (*mapDressedLep)[cands->ptrAt(
i)];
116 hasTauAnc = (*mapTauAnc)[matchDressedLep];
128 if (match->isPromptFinalState())
130 else if (match->isDirectPromptTauDecayProductFinalState())
137 if (matchDressedLep->pdgId() == 22)
140 flav[
i] = (hasTauAnc) ? 15 : 1;
144 for (
auto& consti : matchDressedLep->getGenConstituents()) {
145 if (
abs(consti->pdgId()) != 11)
147 if (consti->pt() <
minpt)
149 minpt = consti->
pt();
150 highestPtConstituent = consti;
152 if (highestPtConstituent) {
155 return (
abs(
genp.pdgId()) == 11) && (
deltaR(
genp, *highestPtConstituent) < 0.01) &&
156 (
abs(
genp.pt() - highestPtConstituent->
pt()) / highestPtConstituent->
pt() < 0.01);
158 if (iter != genParts->end()) {
159 key[
i] = iter - genParts->begin();
164 else if (match->isPromptFinalState())
165 flav[
i] = (match->pdgId() == 22 ? 22 : 1);
166 else if (match->isDirectPromptTauDecayProductFinalState())
172 if (match->isPromptFinalState() && match->pdgId() == 22)
174 else if ((match->isPromptFinalState() || match->isDirectPromptTauDecayProductFinalState()) &&
175 abs(match->pdgId()) == 11)
180 if (match.
isNonnull() && match->statusFlags().isPrompt() &&
abs(match->pdgId()) == 11)
182 else if (match.
isNonnull() && match->statusFlags().isPrompt() &&
abs(match->pdgId()) == 13)
184 else if (match.
isNonnull() && match->isDirectPromptTauDecayProductFinalState() &&
abs(match->pdgId()) == 11)
186 else if (match.
isNonnull() && match->isDirectPromptTauDecayProductFinalState() &&
abs(match->pdgId()) == 13)
192 flav[
i] = match->statusFlags().fromHardProcess();
196 tab->addColumn<
int>(
branchName_ +
"Idx",
key,
"Index into genParticle list for " +
doc_);
197 tab->addColumn<uint8_t>(branchName_ +
"Flav",
199 "Flavour of genParticle (DressedLeptons for electrons) for " +
doc_ +
": " +
flavDoc_);
206 for (
unsigned int im = 0, nm = match->numberOfMothers(); im < nm; ++im) {
209 if (mom.
key() >= match.
key())
212 if (
id / 1000 == 5 ||
id / 100 == 5 ||
id == 5)
214 if (
id / 1000 == 4 ||
id / 100 == 4 ||
id == 4)
216 if (mom->status() == 2) {
229 desc.
add<
std::string>(
"objName")->setComment(
"name of the nanoaod::FlatTable to extend with this table");
232 "name of the column to write (the final branch in the nanoaod will be <objName>_<branchName>Idx and "
233 "<objName>_<branchName>Flav");
234 desc.
add<
std::string>(
"docString")->setComment(
"documentation to forward to the output");
236 "physics object collection for the reconstructed objects (e.g. leptons)");
238 "tag to an edm::Association<GenParticleCollection> mapping src to gen, such as the one produced by MCMatcher");
240 "type of object to match (Muon, Electron, Tau, Photon, Other), taylors what's in t Flav branch");
242 ->setComment(
"as mcMap, but pointing to the visible gen taus (only if objType == Tau)");
244 ->setComment(
"as mcMap, but pointing to gen dressed leptons (only if objType == Electrons)");
246 ->setComment(
"Value map of matched gen electrons containing info on the tau ancestry");
248 descriptions.
add(
"candMcMatchTable", desc);
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
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.
double pt() const final
transverse momentum
bool getByToken(EDGetToken token, Handle< PROD > &result) 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_
edm::EDGetTokenT< reco::GenParticleCollection > genPartsToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
tuple key
prepare the HTCondor submission files and eventually submit them
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)
tuple genp
produce generated paricles in acceptance #
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMap_
edm::EDGetTokenT< edm::ValueMap< bool > > mapTauAnc_
T getParameter(std::string const &) const
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