CMS 3D CMS Logo

GenVisTauProducer.cc
Go to the documentation of this file.
14 
15 #include <vector>
16 #include <iostream>
17 
19 {
20  public:
22  : src_(consumes<reco::GenJetCollection>(params.getParameter<edm::InputTag>("src")))
23  , srcGenParticles_(consumes<reco::GenParticleCollection>(params.getParameter<edm::InputTag>("srcGenParticles")))
24  {
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
31  {
33  evt.getByToken(src_, genTauJets);
34 
36  evt.getByToken(srcGenParticles_, genParticles);
37  size_t numGenParticles = genParticles->size();
38 
39  auto genVisTaus = std::make_unique<reco::GenParticleCollection>();
40 
41  for (const auto & genTauJet : *genTauJets) {
42  std::string decayMode_string = JetMCTagUtils::genTauDecayMode(genTauJet);
43  // CV: store hadronic tau decays only
44  if ( decayMode_string == "electron" || decayMode_string == "muon" ) continue;
46  if ( decayMode_string == "oneProng0Pi0" ) decayMode = reco::PFTau::kOneProng0PiZero;
47  else if ( decayMode_string == "oneProng1Pi0" ) decayMode = reco::PFTau::kOneProng1PiZero;
48  else if ( decayMode_string == "oneProng2Pi0" ) decayMode = reco::PFTau::kOneProng2PiZero;
49  else if ( decayMode_string == "threeProng0Pi0" ) decayMode = reco::PFTau::kThreeProng0PiZero;
50  else if ( decayMode_string == "threeProng1Pi0" ) decayMode = reco::PFTau::kThreeProng1PiZero;
51  else decayMode = reco::PFTau::kRareDecayMode;
52 
53  int pdgId = ( genTauJet.charge() > 0 ) ? -15 : +15;
54 
55  // CV: store decayMode in status flag of GenParticle object
56  reco::GenParticle genVisTau(genTauJet.charge(), genTauJet.p4(), genTauJet.vertex(), pdgId, decayMode, true);
57 
58  // CV: find tau lepton "mother" particle
59  for ( size_t idxGenParticle = 0; idxGenParticle < numGenParticles; ++idxGenParticle ) {
60  const reco::GenParticle & genTau = (*genParticles)[idxGenParticle];
61  if ( abs(genTau.pdgId()) == 15 && genTau.status() == 2 ) {
62  reco::Candidate::LorentzVector daughterVisP4;
63  for (const reco::GenParticleRef & daughter : genTau.daughterRefVector()) {
64  int abs_pdgId = abs(daughter->pdgId());
65  // CV: skip neutrinos
66  if ( abs_pdgId == 12 || abs_pdgId == 14 || abs_pdgId == 16 ) continue;
67  daughterVisP4 += daughter->p4();
68  }
69  double dR2 = deltaR2(daughterVisP4, genVisTau);
70  if ( dR2 < 1.e-4 ) {
71  genVisTau.addMother(reco::GenParticleRef(genParticles, idxGenParticle));
72  break;
73  }
74  }
75  }
76 
77  genVisTaus->push_back(genVisTau);
78  }
79 
80  evt.put(std::move(genVisTaus));
81  }
82 
83  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
85  desc.add<edm::InputTag>("src")->setComment("collection of visible gen taus (as reco::GenJetCollection)");
86  desc.add<edm::InputTag>("srcGenParticles")->setComment("collections of gen particles");
87  descriptions.add("genVisTaus", desc);
88  }
89 
90 
91  private:
94 };
95 
98 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
int pdgId() const final
PDG identifier.
std::string genTauDecayMode(const reco::CompositePtrCandidate &c)
Definition: JetMCTag.cc:81
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
void produce(edm::StreamID id, edm::Event &evt, const edm::EventSetup &es) const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< GenJet > GenJetCollection
collection of GenJet objects
const daughters & daughterRefVector() const
references to daughtes
genVisTaus
Definition: taus_cff.py:79
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
GenVisTauProducer(const edm::ParameterSet &params)
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_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
fixed size matrix
HLT enums.
int status() const final
status word
const edm::EDGetTokenT< reco::GenJetCollection > src_
~GenVisTauProducer() override
def move(src, dest)
Definition: eostools.py:510