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
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () 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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~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 &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
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
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
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::ProducerBase
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 declare what type of product will make and with which optional label More...
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 14 of file CandMCMatchTableProducer.cc.

Member Enumeration Documentation

◆ MatchType

Enumerator
MMuon 
MElectron 
MTau 
MPhoton 
MOther 

Definition at line 194 of file CandMCMatchTableProducer.cc.

Constructor & Destructor Documentation

◆ CandMCMatchTableProducer()

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

Definition at line 16 of file CandMCMatchTableProducer.cc.

17  : objName_(params.getParameter<std::string>("objName")),
18  branchName_(params.getParameter<std::string>("branchName")),
19  doc_(params.getParameter<std::string>("docString")),
20  src_(consumes<reco::CandidateView>(params.getParameter<edm::InputTag>("src"))),
22  produces<nanoaod::FlatTable>();
23  const std::string& type = params.getParameter<std::string>("objType");
24  if (type == "Muon")
25  type_ = MMuon;
26  else if (type == "Electron")
27  type_ = MElectron;
28  else if (type == "Tau")
29  type_ = MTau;
30  else if (type == "Photon")
31  type_ = MPhoton;
32  else if (type == "Other")
33  type_ = MOther;
34  else
35  throw cms::Exception("Configuration", "Unsupported objType '" + type + "'\n");
36 
37  switch (type_) {
38  case MMuon:
39  flavDoc_ =
40  "1 = prompt muon (including gamma*->mu mu), 15 = muon from prompt tau, " // continues below
41  "5 = muon from b, 4 = muon from c, 3 = muon from light or unknown, 0 = unmatched";
42  break;
43  case MElectron:
44  flavDoc_ =
45  "1 = prompt electron (including gamma*->mu mu), 15 = electron from prompt tau, 22 = prompt photon (likely "
46  "conversion), " // continues below
47  "5 = electron from b, 4 = electron from c, 3 = electron from light or unknown, 0 = unmatched";
48  break;
49  case MPhoton:
50  flavDoc_ = "1 = prompt photon, 11 = prompt electron, 0 = unknown or unmatched";
51  break;
52  case MTau:
53  flavDoc_ =
54  "1 = prompt electron, 2 = prompt muon, 3 = tau->e decay, 4 = tau->mu decay, 5 = hadronic tau decay, 0 = "
55  "unknown or unmatched";
56  break;
57  case MOther:
58  flavDoc_ = "1 = from hard scatter, 0 = unknown or unmatched";
59  break;
60  }
61 
62  if (type_ == MTau) {
64  consumes<edm::Association<reco::GenParticleCollection>>(params.getParameter<edm::InputTag>("mcMapVisTau"));
65  }
66  }

References candMapVisTau_, Exception, flavDoc_, MElectron, MMuon, MOther, MPhoton, MTau, CalibrationSummaryClient_cfi::params, AlCaHLTBitMon_QueryRunRegistry::string, and type_.

◆ ~CandMCMatchTableProducer()

CandMCMatchTableProducer::~CandMCMatchTableProducer ( )
inlineoverride

Definition at line 68 of file CandMCMatchTableProducer.cc.

68 {}

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 170 of file CandMCMatchTableProducer.cc.

170  {
172  desc.add<std::string>("objName")->setComment("name of the nanoaod::FlatTable to extend with this table");
173  desc.add<std::string>("branchName")
174  ->setComment(
175  "name of the column to write (the final branch in the nanoaod will be <objName>_<branchName>Idx and "
176  "<objName>_<branchName>Flav");
177  desc.add<std::string>("docString")->setComment("documentation to forward to the output");
178  desc.add<edm::InputTag>("src")->setComment(
179  "physics object collection for the reconstructed objects (e.g. leptons)");
180  desc.add<edm::InputTag>("mcMap")->setComment(
181  "tag to an edm::Association<GenParticleCollection> mapping src to gen, such as the one produced by MCMatcher");
182  desc.add<std::string>("objType")->setComment(
183  "type of object to match (Muon, Electron, Tau, Photon, Other), taylors what's in t Flav branch");
184  desc.addOptional<edm::InputTag>("mcMapVisTau")
185  ->setComment("as mcMap, but pointing to the visible gen taus (only if objType == Tau)");
186  descriptions.add("candMcMatchTable", desc);
187  }

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ getParentHadronFlag()

static int CandMCMatchTableProducer::getParentHadronFlag ( const reco::GenParticleRef  match)
inlinestatic

Definition at line 147 of file CandMCMatchTableProducer.cc.

147  {
148  bool has4 = false;
149  for (unsigned int im = 0, nm = match->numberOfMothers(); im < nm; ++im) {
150  reco::GenParticleRef mom = match->motherRef(im);
151  assert(mom.isNonnull() && mom.isAvailable()); // sanity
152  if (mom.key() >= match.key())
153  continue; // prevent circular refs
154  int id = std::abs(mom->pdgId());
155  if (id / 1000 == 5 || id / 100 == 5 || id == 5)
156  return 5;
157  if (id / 1000 == 4 || id / 100 == 4 || id == 4)
158  has4 = true;
159  if (mom->status() == 2) {
160  id = getParentHadronFlag(mom);
161  if (id == 5)
162  return 5;
163  else if (id == 4)
164  has4 = true;
165  }
166  }
167  return has4 ? 4 : 3;
168  }

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

Referenced by produce().

◆ produce()

void CandMCMatchTableProducer::produce ( edm::StreamID  id,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
inlineoverridevirtual

Implements edm::global::EDProducerBase.

Definition at line 70 of file CandMCMatchTableProducer.cc.

70  {
72  iEvent.getByToken(src_, cands);
73  unsigned int ncand = cands->size();
74 
75  auto tab = std::make_unique<nanoaod::FlatTable>(ncand, objName_, false, true);
76 
78  iEvent.getByToken(candMap_, map);
79 
81  if (type_ == MTau) {
82  iEvent.getByToken(candMapVisTau_, mapVisTau);
83  }
84 
85  std::vector<int> key(ncand, -1), flav(ncand, 0);
86  for (unsigned int i = 0; i < ncand; ++i) {
87  //std::cout << "cand #" << i << ": pT = " << cands->ptrAt(i)->pt() << ", eta = " << cands->ptrAt(i)->eta() << ", phi = " << cands->ptrAt(i)->phi() << std::endl;
88  reco::GenParticleRef match = (*map)[cands->ptrAt(i)];
89  reco::GenParticleRef matchVisTau;
90  if (type_ == MTau) {
91  matchVisTau = (*mapVisTau)[cands->ptrAt(i)];
92  }
93  if (match.isNonnull())
94  key[i] = match.key();
95  else if (matchVisTau.isNonnull())
96  key[i] = matchVisTau.key();
97  else
98  continue;
99  switch (type_) {
100  case MMuon:
101  if (match->isPromptFinalState())
102  flav[i] = 1; // prompt
103  else if (match->isDirectPromptTauDecayProductFinalState())
104  flav[i] = 15; // tau
105  else
106  flav[i] = getParentHadronFlag(match); // 3 = light, 4 = charm, 5 = b
107  break;
108  case MElectron:
109  if (match->isPromptFinalState())
110  flav[i] = (match->pdgId() == 22 ? 22 : 1); // prompt electron or photon
111  else if (match->isDirectPromptTauDecayProductFinalState())
112  flav[i] = 15; // tau
113  else
114  flav[i] = getParentHadronFlag(match); // 3 = light, 4 = charm, 5 = b
115  break;
116  case MPhoton:
117  if (match->isPromptFinalState() && match->pdgId() == 22)
118  flav[i] = 1; // prompt photon
119  else if ((match->isPromptFinalState() || match->isDirectPromptTauDecayProductFinalState()) &&
120  abs(match->pdgId()) == 11)
121  flav[i] = 11; // prompt electron
122  break;
123  case MTau:
124  // CV: assignment of status codes according to https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsToTauTauWorking2016#MC_Matching
125  if (match.isNonnull() && match->statusFlags().isPrompt() && abs(match->pdgId()) == 11)
126  flav[i] = 1;
127  else if (match.isNonnull() && match->statusFlags().isPrompt() && abs(match->pdgId()) == 13)
128  flav[i] = 2;
129  else if (match.isNonnull() && match->isDirectPromptTauDecayProductFinalState() && abs(match->pdgId()) == 11)
130  flav[i] = 3;
131  else if (match.isNonnull() && match->isDirectPromptTauDecayProductFinalState() && abs(match->pdgId()) == 13)
132  flav[i] = 4;
133  else if (matchVisTau.isNonnull())
134  flav[i] = 5;
135  break;
136  default:
137  flav[i] = match->statusFlags().fromHardProcess();
138  };
139  }
140 
141  tab->addColumn<int>(branchName_ + "Idx", key, "Index into genParticle list for " + doc_);
142  tab->addColumn<uint8_t>(branchName_ + "Flav", flav, "Flavour of genParticle for " + doc_ + ": " + flavDoc_);
143 
144  iEvent.put(std::move(tab));
145  }

References funct::abs(), branchName_, candMap_, candMapVisTau_, HLT_FULL_cff::cands, doc_, flavDoc_, getParentHadronFlag(), mps_fire::i, iEvent, 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_, src_, and type_.

Member Data Documentation

◆ branchName_

const std::string CandMCMatchTableProducer::branchName_
protected

Definition at line 190 of file CandMCMatchTableProducer.cc.

Referenced by produce().

◆ candMap_

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

Definition at line 192 of file CandMCMatchTableProducer.cc.

Referenced by produce().

◆ candMapVisTau_

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

Definition at line 193 of file CandMCMatchTableProducer.cc.

Referenced by CandMCMatchTableProducer(), and produce().

◆ doc_

const std::string CandMCMatchTableProducer::doc_
protected

Definition at line 190 of file CandMCMatchTableProducer.cc.

Referenced by produce().

◆ flavDoc_

std::string CandMCMatchTableProducer::flavDoc_
protected

Definition at line 195 of file CandMCMatchTableProducer.cc.

Referenced by CandMCMatchTableProducer(), and produce().

◆ objName_

const std::string CandMCMatchTableProducer::objName_
protected

Definition at line 190 of file CandMCMatchTableProducer.cc.

Referenced by produce().

◆ src_

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

Definition at line 191 of file CandMCMatchTableProducer.cc.

Referenced by produce().

◆ type_

enum CandMCMatchTableProducer::MatchType CandMCMatchTableProducer::type_
protected
mps_fire.i
i
Definition: mps_fire.py:428
CandMCMatchTableProducer::MPhoton
Definition: CandMCMatchTableProducer.cc:194
CandMCMatchTableProducer::candMap_
const edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMap_
Definition: CandMCMatchTableProducer.cc:192
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::Ref::isAvailable
bool isAvailable() const
Definition: Ref.h:537
CandMCMatchTableProducer::src_
const edm::EDGetTokenT< reco::CandidateView > src_
Definition: CandMCMatchTableProducer.cc:191
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
cms::cuda::assert
assert(be >=bs)
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< GenParticleCollection >
CandMCMatchTableProducer::flavDoc_
std::string flavDoc_
Definition: CandMCMatchTableProducer.cc:195
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
CandMCMatchTableProducer::type_
enum CandMCMatchTableProducer::MatchType type_
CandMCMatchTableProducer::branchName_
const std::string branchName_
Definition: CandMCMatchTableProducer.cc:190
CandMCMatchTableProducer::MElectron
Definition: CandMCMatchTableProducer.cc:194
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15142
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::Association
Definition: Association.h:18
CandMCMatchTableProducer::objName_
const std::string objName_
Definition: CandMCMatchTableProducer.cc:190
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
CandMCMatchTableProducer::getParentHadronFlag
static int getParentHadronFlag(const reco::GenParticleRef match)
Definition: CandMCMatchTableProducer.cc:147
CandMCMatchTableProducer::candMapVisTau_
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > candMapVisTau_
Definition: CandMCMatchTableProducer.cc:193
Exception
Definition: hltDiff.cc:246
CandMCMatchTableProducer::MTau
Definition: CandMCMatchTableProducer.cc:194
CandMCMatchTableProducer::doc_
const std::string doc_
Definition: CandMCMatchTableProducer.cc:190
CandMCMatchTableProducer::MOther
Definition: CandMCMatchTableProducer.cc:194
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:153
crabWrapper.key
key
Definition: crabWrapper.py:19
CandMCMatchTableProducer::MMuon
Definition: CandMCMatchTableProducer.cc:194
edm::InputTag
Definition: InputTag.h:15