CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Types | Protected Attributes
CandMCMatchTableProducer Class Reference
Inheritance diagram for CandMCMatchTableProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 CandMCMatchTableProducer (edm::ParameterSet const &params)
 
void produce (edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 
 ~CandMCMatchTableProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static int getParentHadronFlag (const reco::GenParticleRef match)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Protected Types

enum  MatchType {
  MMuon, MElectron, MTau, MPhoton,
  MOther
}
 

Protected Attributes

const std::string branchName_
 
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMap_
 
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMapVisTau_
 
const std::string doc_
 
std::string flavDoc_
 
const std::string objName_
 
const edm::EDGetTokenT< reco::CandidateViewsrc_
 
enum CandMCMatchTableProducer::MatchType type_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 15 of file CandMCMatchTableProducer.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

CandMCMatchTableProducer::CandMCMatchTableProducer ( edm::ParameterSet const &  params)
inline

Definition at line 17 of file CandMCMatchTableProducer.cc.

References candMapVisTau_, Exception, flavDoc_, edm::ParameterSet::getParameter(), MElectron, MMuon, MOther, MPhoton, MTau, AlCaHLTBitMon_QueryRunRegistry::string, and type_.

17  :
18  objName_(params.getParameter<std::string>("objName")),
19  branchName_(params.getParameter<std::string>("branchName")),
20  doc_(params.getParameter<std::string>("docString")),
21  src_(consumes<reco::CandidateView>(params.getParameter<edm::InputTag>("src"))),
23  {
24  produces<nanoaod::FlatTable>();
25  const std::string & type = params.getParameter<std::string>("objType");
26  if (type == "Muon") type_ = MMuon;
27  else if (type == "Electron") type_ = MElectron;
28  else if (type == "Tau") type_ = MTau;
29  else if (type == "Photon") type_ = MPhoton;
30  else if (type == "Other") type_ = MOther;
31  else throw cms::Exception("Configuration", "Unsupported objType '"+type+"'\n");
32 
33  switch(type_) {
34  case MMuon: flavDoc_ = "1 = prompt muon (including gamma*->mu mu), 15 = muon from prompt tau, " // continues below
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), " // continues below
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, 11 = 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;
41  }
42 
43  if ( type_ == MTau ) {
44  candMapVisTau_ = consumes<edm::Association<reco::GenParticleCollection>>(params.getParameter<edm::InputTag>("mcMapVisTau"));
45  }
46  }
type
Definition: HCALResponse.h:21
enum CandMCMatchTableProducer::MatchType type_
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMapVisTau_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< reco::CandidateView > src_
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMap_
CandMCMatchTableProducer::~CandMCMatchTableProducer ( )
inlineoverride

Definition at line 48 of file CandMCMatchTableProducer.cc.

48 {}

Member Function Documentation

static void CandMCMatchTableProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 132 of file CandMCMatchTableProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), and AlCaHLTBitMon_QueryRunRegistry::string.

132  {
134  desc.add<std::string>("objName")->setComment("name of the nanoaod::FlatTable to extend with this table");
135  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");
136  desc.add<std::string>("docString")->setComment("documentation to forward to the output");
137  desc.add<edm::InputTag>("src")->setComment("physics object collection for the reconstructed objects (e.g. leptons)");
138  desc.add<edm::InputTag>("mcMap")->setComment("tag to an edm::Association<GenParticleCollection> mapping src to gen, such as the one produced by MCMatcher");
139  desc.add<std::string>("objType")->setComment("type of object to match (Muon, Electron, Tau, Photon, Other), taylors what's in t Flav branch");
140  desc.addOptional<edm::InputTag>("mcMapVisTau")->setComment("as mcMap, but pointing to the visible gen taus (only if objType == Tau)");
141  descriptions.add("candMcMatchTable", desc);
142  }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static int CandMCMatchTableProducer::getParentHadronFlag ( const reco::GenParticleRef  match)
inlinestatic

Definition at line 114 of file CandMCMatchTableProducer.cc.

References funct::abs(), edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), and edm::Ref< C, T, F >::key().

Referenced by produce().

114  {
115  bool has4 = false;
116  for (unsigned int im = 0, nm = match->numberOfMothers(); im < nm; ++im) {
117  reco::GenParticleRef mom = match->motherRef(im);
118  assert(mom.isNonnull() && mom.isAvailable()); // sanity
119  if (mom.key() >= match.key()) continue; // prevent circular refs
120  int id = std::abs(mom->pdgId());
121  if (id / 1000 == 5 || id / 100 == 5 || id == 5) return 5;
122  if (id / 1000 == 4 || id / 100 == 4 || id == 4) has4 = true;
123  if (mom->status() == 2) {
124  id = getParentHadronFlag(mom);
125  if (id == 5) return 5;
126  else if (id == 4) has4 = true;
127  }
128  }
129  return has4 ? 4 : 3;
130  }
bool isAvailable() const
Definition: Ref.h:577
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
key_type key() const
Accessor for product key.
Definition: Ref.h:265
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int getParentHadronFlag(const reco::GenParticleRef match)
void CandMCMatchTableProducer::produce ( edm::StreamID  id,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
inlineoverride

Definition at line 50 of file CandMCMatchTableProducer.cc.

References funct::abs(), branchName_, candMap_, candMapVisTau_, egammaForCoreTracking_cff::cands, doc_, flavDoc_, edm::Event::getByToken(), getParentHadronFlag(), mps_fire::i, nanoaod::FlatTable::IntColumn, edm::Ref< C, T, F >::isNonnull(), crabWrapper::key, edm::Ref< C, T, F >::key(), genParticles_cff::map, match(), MElectron, MMuon, eostools::move(), MPhoton, MTau, objName_, edm::View< T >::ptrAt(), edm::Event::put(), edm::View< T >::size(), src_, type_, and nanoaod::FlatTable::UInt8Column.

50  {
51 
53  iEvent.getByToken(src_, cands);
54  unsigned int ncand = cands->size();
55 
56  auto tab = std::make_unique<nanoaod::FlatTable>(ncand, objName_, false, true);
57 
59  iEvent.getByToken(candMap_, map);
60 
62  if ( type_ == MTau ) {
63  iEvent.getByToken(candMapVisTau_, mapVisTau);
64  }
65 
66  std::vector<int> key(ncand, -1), flav(ncand, 0);
67  for (unsigned int i = 0; i < ncand; ++i) {
68  //std::cout << "cand #" << i << ": pT = " << cands->ptrAt(i)->pt() << ", eta = " << cands->ptrAt(i)->eta() << ", phi = " << cands->ptrAt(i)->phi() << std::endl;
69  reco::GenParticleRef match = (*map)[cands->ptrAt(i)];
70  reco::GenParticleRef matchVisTau;
71  if ( type_ == MTau ) {
72  matchVisTau = (*mapVisTau)[cands->ptrAt(i)];
73  }
74  if ( match.isNonnull() ) key[i] = match.key();
75  else if ( matchVisTau.isNonnull() ) key[i] = matchVisTau.key();
76  else continue;
77  switch(type_) {
78  case MMuon:
79  if (match->isPromptFinalState()) flav[i] = 1; // prompt
80  else if (match->isDirectPromptTauDecayProductFinalState()) flav[i] = 15; // tau
81  else flav[i] = getParentHadronFlag(match); // 3 = light, 4 = charm, 5 = b
82  break;
83  case MElectron:
84  if (match->isPromptFinalState()) flav[i] = (match->pdgId() == 22 ? 22 : 1); // prompt electron or photon
85  else if (match->isDirectPromptTauDecayProductFinalState()) flav[i] = 15; // tau
86  else flav[i] = getParentHadronFlag(match); // 3 = light, 4 = charm, 5 = b
87  break;
88  case MPhoton:
89  if (match->isPromptFinalState() && match->pdgId() == 22)
90  flav[i] = 1; // prompt photon
91  else if ((match->isPromptFinalState() || match->isDirectPromptTauDecayProductFinalState()) &&
92  abs(match->pdgId()) == 11)
93  flav[i] = 11; // prompt electron
94  break;
95  case MTau:
96  // CV: assignment of status codes according to https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsToTauTauWorking2016#MC_Matching
97  if ( match.isNonnull() && match->statusFlags().isPrompt() && abs(match->pdgId()) == 11 ) flav[i] = 1;
98  else if ( match.isNonnull() && match->statusFlags().isPrompt() && abs(match->pdgId()) == 13 ) flav[i] = 2;
99  else if ( match.isNonnull() && match->isDirectPromptTauDecayProductFinalState() && abs(match->pdgId()) == 11 ) flav[i] = 3;
100  else if ( match.isNonnull() && match->isDirectPromptTauDecayProductFinalState() && abs(match->pdgId()) == 13 ) flav[i] = 4;
101  else if ( matchVisTau.isNonnull() ) flav[i] = 5;
102  break;
103  default:
104  flav[i] = match->statusFlags().fromHardProcess();
105  };
106  }
107 
108  tab->addColumn<int>(branchName_+"Idx", key, "Index into genParticle list for "+doc_, nanoaod::FlatTable::IntColumn);
109  tab->addColumn<uint8_t>(branchName_+"Flav", flav, "Flavour of genParticle for "+doc_+": "+flavDoc_, nanoaod::FlatTable::UInt8Column);
110 
111  iEvent.put(std::move(tab));
112  }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
Ptr< value_type > ptrAt(size_type i) const
enum CandMCMatchTableProducer::MatchType type_
size_type size() const
key_type key() const
Accessor for product key.
Definition: Ref.h:265
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMapVisTau_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::EDGetTokenT< reco::CandidateView > src_
static int getParentHadronFlag(const reco::GenParticleRef match)
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMap_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

const std::string CandMCMatchTableProducer::branchName_
protected

Definition at line 145 of file CandMCMatchTableProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<edm::Association<reco::GenParticleCollection> > CandMCMatchTableProducer::candMap_
protected

Definition at line 147 of file CandMCMatchTableProducer.cc.

Referenced by produce().

edm::EDGetTokenT<edm::Association<reco::GenParticleCollection> > CandMCMatchTableProducer::candMapVisTau_
protected

Definition at line 148 of file CandMCMatchTableProducer.cc.

Referenced by CandMCMatchTableProducer(), and produce().

const std::string CandMCMatchTableProducer::doc_
protected

Definition at line 145 of file CandMCMatchTableProducer.cc.

Referenced by produce().

std::string CandMCMatchTableProducer::flavDoc_
protected

Definition at line 150 of file CandMCMatchTableProducer.cc.

Referenced by CandMCMatchTableProducer(), and produce().

const std::string CandMCMatchTableProducer::objName_
protected

Definition at line 145 of file CandMCMatchTableProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<reco::CandidateView> CandMCMatchTableProducer::src_
protected

Definition at line 146 of file CandMCMatchTableProducer.cc.

Referenced by produce().

enum CandMCMatchTableProducer::MatchType CandMCMatchTableProducer::type_
protected