CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GenVisTauProducer.cc
Go to the documentation of this file.
15 
16 #include <vector>
17 #include <iostream>
18 
20 public:
22  : src_(consumes<reco::GenJetCollection>(params.getParameter<edm::InputTag>("src"))),
23  srcGenParticles_(consumes<reco::GenParticleCollection>(params.getParameter<edm::InputTag>("srcGenParticles"))),
24  pTComparator_() {
25  produces<reco::GenParticleCollection>();
26  }
27 
28  ~GenVisTauProducer() override {}
29 
30  void produce(edm::StreamID id, edm::Event& evt, const edm::EventSetup& es) const override {
32  evt.getByToken(src_, genTauJets);
33 
35  evt.getByToken(srcGenParticles_, genParticles);
36  size_t numGenParticles = genParticles->size();
37 
38  auto genVisTaus = std::make_unique<reco::GenParticleCollection>();
39 
40  for (const auto& genTauJet : *genTauJets) {
41  std::string decayMode_string = JetMCTagUtils::genTauDecayMode(genTauJet);
42  // CV: store hadronic tau decays only
43  if (decayMode_string == "electron" || decayMode_string == "muon")
44  continue;
45  int decayMode = reco::PFTau::kNull;
46  if (decayMode_string == "oneProng0Pi0")
48  else if (decayMode_string == "oneProng1Pi0")
50  else if (decayMode_string == "oneProng2Pi0")
52  else if (decayMode_string == "threeProng0Pi0")
54  else if (decayMode_string == "threeProng1Pi0")
56  else
57  decayMode = reco::PFTau::kRareDecayMode;
58 
59  int pdgId = (genTauJet.charge() > 0) ? -15 : +15;
60 
61  // CV: store decayMode in status flag of GenParticle object
62  reco::GenParticle genVisTau(genTauJet.charge(), genTauJet.p4(), genTauJet.vertex(), pdgId, decayMode, true);
63 
64  // CV: find tau lepton "mother" particle
65  for (size_t idxGenParticle = 0; idxGenParticle < numGenParticles; ++idxGenParticle) {
66  const reco::GenParticle& genTau = (*genParticles)[idxGenParticle];
67  if (abs(genTau.pdgId()) == 15 && genTau.status() == 2) {
68  reco::Candidate::LorentzVector daughterVisP4;
69  for (const reco::GenParticleRef& daughter : genTau.daughterRefVector()) {
70  int abs_pdgId = abs(daughter->pdgId());
71  // CV: skip neutrinos
72  if (abs_pdgId == 12 || abs_pdgId == 14 || abs_pdgId == 16)
73  continue;
74  daughterVisP4 += daughter->p4();
75  }
76  double dR2 = deltaR2(daughterVisP4, genVisTau);
77  if (dR2 < 1.e-4) {
78  genVisTau.addMother(reco::GenParticleRef(genParticles, idxGenParticle));
79  break;
80  }
81  }
82  }
83 
84  genVisTaus->push_back(genVisTau);
85  }
86 
87  std::sort(genVisTaus->begin(), genVisTaus->end(), pTComparator_);
88  evt.put(std::move(genVisTaus));
89  }
90 
91  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
93  desc.add<edm::InputTag>("src")->setComment("collection of visible gen taus (as reco::GenJetCollection)");
94  desc.add<edm::InputTag>("srcGenParticles")->setComment("collections of gen particles");
95  descriptions.add("genVisTaus", desc);
96  }
97 
98 private:
102 };
103 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
std::string genTauDecayMode(const reco::CompositePtrCandidate &c)
Definition: JetMCTag.cc:70
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< GenJet > GenJetCollection
collection of GenJet objects
int status() const final
status word
const daughters & daughterRefVector() const
references to daughtes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int pdgId() const final
PDG identifier.
GenVisTauProducer(const edm::ParameterSet &params)
void produce(edm::StreamID id, edm::Event &evt, const edm::EventSetup &es) const override
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDGetTokenT< reco::GenParticleCollection > srcGenParticles_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void add(std::string const &label, ParameterSetDescription const &psetDescription)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< reco::GenJetCollection > src_
~GenVisTauProducer() override
const GreaterByPt< reco::GenParticle > pTComparator_
tuple genVisTaus
Definition: taus_cff.py:192