CMS 3D CMS Logo

GenVisTauProducer.cc
Go to the documentation of this file.
15 
16 #include <vector>
17 #include <iostream>
18 
20 {
21  public:
23  : src_(consumes<reco::GenJetCollection>(params.getParameter<edm::InputTag>("src")))
24  , srcGenParticles_(consumes<reco::GenParticleCollection>(params.getParameter<edm::InputTag>("srcGenParticles")))
25  , pTComparator_()
26  {
27  produces<reco::GenParticleCollection>();
28  }
29 
30  ~GenVisTauProducer() override {}
31 
32  void produce(edm::StreamID id, edm::Event& evt, const edm::EventSetup& es) const override
33  {
35  evt.getByToken(src_, genTauJets);
36 
38  evt.getByToken(srcGenParticles_, genParticles);
39  size_t numGenParticles = genParticles->size();
40 
41  auto genVisTaus = std::make_unique<reco::GenParticleCollection>();
42 
43  for (const auto & genTauJet : *genTauJets) {
44  std::string decayMode_string = JetMCTagUtils::genTauDecayMode(genTauJet);
45  // CV: store hadronic tau decays only
46  if ( decayMode_string == "electron" || decayMode_string == "muon" ) continue;
48  if ( decayMode_string == "oneProng0Pi0" ) decayMode = reco::PFTau::kOneProng0PiZero;
49  else if ( decayMode_string == "oneProng1Pi0" ) decayMode = reco::PFTau::kOneProng1PiZero;
50  else if ( decayMode_string == "oneProng2Pi0" ) decayMode = reco::PFTau::kOneProng2PiZero;
51  else if ( decayMode_string == "threeProng0Pi0" ) decayMode = reco::PFTau::kThreeProng0PiZero;
52  else if ( decayMode_string == "threeProng1Pi0" ) decayMode = reco::PFTau::kThreeProng1PiZero;
53  else decayMode = reco::PFTau::kRareDecayMode;
54 
55  int pdgId = ( genTauJet.charge() > 0 ) ? -15 : +15;
56 
57  // CV: store decayMode in status flag of GenParticle object
58  reco::GenParticle genVisTau(genTauJet.charge(), genTauJet.p4(), genTauJet.vertex(), pdgId, decayMode, true);
59 
60  // CV: find tau lepton "mother" particle
61  for ( size_t idxGenParticle = 0; idxGenParticle < numGenParticles; ++idxGenParticle ) {
62  const reco::GenParticle & genTau = (*genParticles)[idxGenParticle];
63  if ( abs(genTau.pdgId()) == 15 && genTau.status() == 2 ) {
64  reco::Candidate::LorentzVector daughterVisP4;
65  for (const reco::GenParticleRef & daughter : genTau.daughterRefVector()) {
66  int abs_pdgId = abs(daughter->pdgId());
67  // CV: skip neutrinos
68  if ( abs_pdgId == 12 || abs_pdgId == 14 || abs_pdgId == 16 ) continue;
69  daughterVisP4 += daughter->p4();
70  }
71  double dR2 = deltaR2(daughterVisP4, genVisTau);
72  if ( dR2 < 1.e-4 ) {
73  genVisTau.addMother(reco::GenParticleRef(genParticles, idxGenParticle));
74  break;
75  }
76  }
77  }
78 
79  genVisTaus->push_back(genVisTau);
80  }
81 
82  std::sort(genVisTaus->begin(), genVisTaus->end(), pTComparator_);
83  evt.put(std::move(genVisTaus));
84  }
85 
86  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
88  desc.add<edm::InputTag>("src")->setComment("collection of visible gen taus (as reco::GenJetCollection)");
89  desc.add<edm::InputTag>("srcGenParticles")->setComment("collections of gen particles");
90  descriptions.add("genVisTaus", desc);
91  }
92 
93 
94  private:
98 };
99 
102 
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:125
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:517
std::vector< GenJet > GenJetCollection
collection of GenJet objects
const daughters & daughterRefVector() const
references to daughtes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
GenVisTauProducer(const edm::ParameterSet &params)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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:37
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
fixed size matrix
HLT enums.
int status() const final
status word
const edm::EDGetTokenT< reco::GenJetCollection > src_
~GenVisTauProducer() override
const GreaterByPt< reco::GenParticle > pTComparator_
def move(src, dest)
Definition: eostools.py:511